summaryrefslogtreecommitdiffstats
path: root/kpovmodeler/pmline.h
blob: 399555ea10541beb98732adb854d364f9b466b81 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
//-*-C++-*-
/*
**************************************************************************
                                 description
                             --------------------
    copyright            : (C) 2000-2001 by Andreas Zehender
    email                : zehender@kde.org
**************************************************************************

**************************************************************************
*                                                                        *
*  This program is free software; you can redistribute it and/or modify  *
*  it under the terms of the GNU General Public License as published by  *
*  the Free Software Foundation; either version 2 of the License, or     *
*  (at your option) any later version.                                   *
*                                                                        *
**************************************************************************/


#ifndef PMLINES_H
#define PMLINES_H

#include <qptrlist.h>
#include <GL/gl.h>
#include "pmdebug.h"

/**
 * Line to display with index of start and end point.
 *
 * Line of a @ref PMViewStructure. Only the indices in a @ref PMPointArray
 * are stored.
 *
 * Optimized for OpenGL
 */
class PMLine
{
public:
   /**
    * Default constructor
    */
   PMLine( )
   {
      m_start = 0;
      m_end = 0;
   }
   /**
    * Creates a line with start point si and end point ei. If si is greater
    * than ei, si and ei are swapped.
    */
   PMLine( const GLuint si, const GLuint ei )
   { m_start = si; m_end = ei; checkPoints( ); }

   /**
    * Sets the start point.
    */
   void setStartPoint( GLuint si ) { m_start = si; checkPoints( ); }
   /**
    * Sets the end point.
    */
   void setEndPoint( GLuint ei ) { m_end = ei; checkPoints( ); }
   /**
    * Returns the start point.
    */
   GLuint startPoint( ) const { return m_start; }
   /**
    * Returns the end point.
    */
   GLuint endPoint( ) const { return m_end; }

private:
   /**
    * Swaps the two points.
    */
   void swapPoints( ) { GLuint help = m_start; m_start = m_end; m_end = help; }
   /**
    * Checks, if si < ei and swaps the two points if necessary
    */
   void checkPoints( )
   {
      if( m_start == m_end ) kdError( PMArea ) << "Start index = end index in PMLine" << "\n";
      if( m_start > m_end ) swapPoints( );
   }
   /**
    * The start and end points (indices!)
    *
    * THESE MEMBERS HAVE TO BE THE ONLY ONE (for rendering with OpenGl)
    */
   GLuint m_start, m_end;
};

typedef QPtrListIterator<PMLine> PMLineListIterator;

/**
 * A list of @ref PMLine objects.
 *
 * This class stores all lines of a @ref PMViewStructure. A line is
 * described by a start and end point. Only the indices in a @ref PMPointArray
 * are stored.
 */
typedef QMemArray<PMLine> PMLineArray;

#endif