summaryrefslogtreecommitdiffstats
path: root/kpovmodeler/pmcontrolpoint.h
blob: dbc52c6d689a1e42f619687701fef776131df345 (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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
//-*-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 PMCONTROLPOINT_H
#define PMCONTROLPOINT_H

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include "pmvector.h"
#include <tqptrlist.h>
#include <tqstring.h>

class KConfig;

/**
 * Interface between the graphical views and the PMObject.
 *
 * PMControlPoint is the interface between graphical view and PMObjects that
 * can be changed graphically with the mouse. A @ref PMObject has a
 * PMControlPoint for each changeable attribute.
 *
 * There is one subclass for each change behavior like 3dpoint, normal vector,
 * radius, rotation ...
 *
 * Each control point has an id to be indentified by the PMObject. The id has
 * to be unique within a PMObject.
 */

class PMControlPoint
{
public:
   /**
    * Creates a PMControlPoint with an id and a description.
    */
   PMControlPoint( int id, const TQString& description );
   /**
    * Deletes the PMControlPoint
    */
   virtual ~PMControlPoint( );
   
   /**
    * Starts a graphical change at 3d cursor position startPoint. viewNormal
    * is the normal vector of the view
    */
   void startChange( const PMVector& startPoint, const PMVector& viewNormal );
   /**
    * Graphical change with 3d end cursor position endPoint
    */
   void change( const PMVector& endPoint );
   /**
    * Snaps the control point to the grid
    */
   virtual void snapToGrid( ) = 0;
   
   /**
    * 3d coordinates of the control point for rendering*/
   virtual PMVector position( ) const { return PMVector( ); }
   /**
    * Returns true if the point should be displayed (rendered)
    */
   virtual bool display( ) const { return true; }
   /**
    * Returns the id of the control point
    */
   int id( ) const { return m_id; }
   /**
    * Type of the control point
    *
    * CPPoint: The control point is displayed as point, the mouse cursor
    * has to be over the control point to be active (e.g. 3DControlPoint)
    *
    * CPCross: The control point is displayed as cross, the control point
    * can be changed with the mouse in the whole view (e.g. Translation)
    */
   enum PMCPDisplayType { CPPoint = 0, CPCross = 1 };
   /**
    * Returns the type of the control point (see @ref PMCPDisplayType)
    */
   virtual PMCPDisplayType displayType( ) const { return CPPoint; };
   /**
    * Returns the description
    */
   TQString description( ) const { return m_description; }
   /**
    * Selects/deselects the control point
    */
   void setSelected( bool yes ) { m_bSelected = yes; }
   /**
    * Returns true if the control point is selected
    */
   bool selected( ) const { return m_bSelected; }

   /**
    * Returns true, if the control point was changed and sets the
    * changed flag to false.
    */
   bool changed( );

   /**
    * Returns true if an extra line should be displayed in addition to
    * the view structure
    */
   virtual bool hasExtraLine( ) const { return false; }
   /**
    * Returns the start point of the extra line
    */
   virtual PMVector extraLineStart( ) const { return PMVector( 0, 0, 0 ); }
   /**
    * Returns the end point of the extra line
    */
   virtual PMVector extraLineEnd( ) const { return PMVector( 0, 0, 0 ); }
   
   /**
    * Returns the grid distance for 3d points, vectors and movements
    */
   static double moveGrid( ) { return s_moveGrid; }
   /**
    * Sets the grid distance
    */
   static void setMoveGrid( double d );
   /**
    * Returns the grid distance rotations
    */
   static double rotateGrid( ) { return s_rotateGrid; }
   /**
    * Sets the grid distance
    */
   static void setRotateGrid( double d );
   /**
    * Returns the grid distance for scales
    */
   static double scaleGrid( ) { return s_scaleGrid; }
   /**
    * Sets the grid distance
    */
   static void setScaleGrid( double d );
   
   static void saveConfig( KConfig* cfg );
   static void restoreConfig( KConfig* cfg );
   
protected:
   /**
    * Called when a graphical change was started
    */
   virtual void graphicalChangeStarted( ) = 0;
   /**
    * Called when the control point was changed
    */
   virtual void graphicalChange( const PMVector& startPoint,
                                 const PMVector& viewNormal,
                                 const PMVector& endPoint ) = 0;
   /**
    * Sets the changed flag
    */
   void setChanged( ) { m_bChanged = true; }
private:
   int m_id;
   PMVector m_startPoint;
   PMVector m_normalVector;
   bool m_bChanged;
   bool m_bSelected;
   TQString m_description;

   static double s_moveGrid;
   static double s_rotateGrid;
   static double s_scaleGrid;
};

typedef TQPtrList<PMControlPoint> PMControlPointList;
typedef TQPtrListIterator<PMControlPoint> PMControlPointListIterator;

#endif