Salome HOME
334563466dbd8bafac243bd779f0a6a8b27d931b
[modules/gui.git] / src / GLViewer / GLViewer_Object.h
1 // File:      GLViewer_Object.h
2 // Created:   November, 2004
3 // Author:    OCC team
4 // Copyright (C) CEA 2004
5
6 #ifndef GLVIEWER_OBJECT_H
7 #define GLVIEWER_OBJECT_H
8
9 #ifdef WNT
10 #include <windows.h>
11 #endif
12
13 #include "GLViewer.h"
14 #include "GLViewer_Defs.h"
15 #include "GLViewer_Geom.h"
16
17 #include <SUIT_DataOwner.h>
18
19 #include <GL/gl.h>
20
21 #include <qfile.h>
22 #include <qstring.h>
23 #include <qrect.h>
24
25 #ifdef WNT
26 #pragma warning( disable:4251 )
27 #endif
28
29 /*! 
30  * Class GLViewer_Object
31  * Base Object for GLViewer
32  */
33 class GLViewer_Drawer;
34 class GLViewer_AspectLine;
35 class GLViewer_Group;
36 class GLViewer_CoordSystem;
37 class GLViewer_Text;
38 class GLViewer_Owner;
39
40 class GLVIEWER_API GLViewer_Object
41 {
42 public:
43   //! A constructor
44   GLViewer_Object();
45   //! A destructor
46   virtual ~GLViewer_Object();
47   
48   //! Main method. Computes all needed information about object for presentation in drawer
49   virtual void              compute() = 0;
50   //! Creates correspond drawer
51   virtual GLViewer_Drawer*  createDrawer() = 0;
52
53   //! Installing already exist drawer with same type
54   virtual void              setDrawer( GLViewer_Drawer* theDrawer ) { myDrawer = theDrawer; }
55   //! Returns current drawer
56   GLViewer_Drawer*          getDrawer() const { return myDrawer; }
57   
58   //! Computes highlight presentation
59   /*!
60    *\param x        - x coord
61    *\param y        - y coord
62    *\param tol      - tolerance of detecting
63    *\param isCircle - = true if sensitive area of detection is round
64   */
65   virtual GLboolean         highlight( GLfloat x,
66                                        GLfloat y,
67                                        GLfloat tol,
68                                        GLboolean isCircle = GL_FALSE ) = 0;
69   //! Clears all highlight information
70   virtual GLboolean         unhighlight() = 0;
71
72   //! Computes select presentation
73   /*!
74    *\param x        - x coord
75    *\param y        - y coord
76    *\param tol      - tolerance of detecting
77    *\param rect     - Non empty for rectangle selection
78    *\param isFull   - = true if
79    *\param isCircle - = true if sensitive area of detection is round
80    *\param isShift  - = true if selection exec with append option
81   */
82   virtual GLboolean         select( GLfloat x,
83                                     GLfloat y,
84                                     GLfloat tol,
85                                     GLViewer_Rect rect,
86                                     GLboolean isFull = GL_FALSE,
87                                     GLboolean isCircle = GL_FALSE,
88                                     GLboolean isShift = GL_FALSE ) = 0;
89   //! Clears all select information
90   virtual GLboolean         unselect() = 0;
91   
92   //! Returns if theRect inside object
93   virtual GLboolean         isInside( GLViewer_Rect theRect);
94   
95   //!\warning It is for ouv
96   virtual bool              portContains( GLViewer_Pnt ) { return false; }
97   //!\warning It is for ouv
98   virtual bool              startPulling( GLViewer_Pnt ) { return false; }
99   //!\warning It is for ouv
100   virtual void              pull( GLViewer_Pnt, GLViewer_Object* ) {}
101   //!\warning It is for ouv
102   virtual void              finishPulling() {}
103   //!\warning It is for ouv
104   virtual bool              isPulling() { return false; }
105   //!\warning It is for ouv
106   virtual GLViewer_Rect     getPullingRect() const { return GLViewer_Rect(
107                                 myRect->left(), myRect->right(), myRect->top(), myRect->bottom() ); }
108   
109   //! Installs object rectangle
110   virtual void              setRect( GLViewer_Rect* rect) { myRect = rect; }
111   //! Returns object rectungle
112   virtual GLViewer_Rect*    getRect() const { return myRect; }
113   //! Returns update object rectangle
114   /*! Does not equal getRect() if object have a persistence to some viewer transformations*/
115   virtual GLViewer_Rect*    getUpdateRect() = 0;
116   
117   //! Installs scale factors
118   virtual void              setScale( GLfloat xScale, GLfloat yScale ) { myXScale = xScale; myYScale = yScale; }
119   //! Returns scale factors
120   virtual void              getScale( GLfloat& xScale, GLfloat& yScale ) const { xScale = myXScale; yScale = myYScale;}
121
122   //!\warning It is for ouv
123   virtual GLboolean         setZoom( GLfloat zoom, bool recompute, bool fromGroup = false );
124   //!\warning It is for ouv
125   virtual GLfloat           getZoom() const { return myZoom; }
126   //!\warning It is for ouv
127   virtual GLboolean         updateZoom( bool zoomIn );
128   
129   //! Returns true if object is highlighted
130   virtual GLboolean         isHighlighted() const { return myIsHigh; }
131   //! Returns true if object is selected
132   virtual GLboolean         isSelected() const { return myIsSel; }
133   //! Installs select status to object
134   virtual void              setSelected( GLboolean state ) { myIsSel = state; }
135   
136   //! Installs GLText to object
137   void                      setGLText( GLViewer_Text* glText ) { myGLText = glText; }
138   //! Returns object GLText
139   GLViewer_Text*            getGLText() const { return myGLText; }
140   
141   //! Installs acpect line for object presentation
142   virtual void                 setAspectLine ( GLViewer_AspectLine* aspect ) { myAspectLine = aspect; }
143   //! Returns acpect line of object presentation
144   virtual GLViewer_AspectLine* getAspectLine() const { return myAspectLine; }
145   
146   //! Returns  object type
147   /*! Needs for GLViewer_Drawer*/
148   QString                   getObjectType() const { return myType; } 
149   
150   //! Installs object name
151   void                      setName( QString name ) { myName = name; } 
152   //! Returns object name
153   QString                   getName() const { return myName; } 
154   
155   //! Returns object priority
156   virtual int               getPriority() const;
157
158   //! Moves object per by recomputing
159   /*!
160    *\param dx        - moving along X coord
161    *\param dy        - moving along Y coord
162    *\param fromGroup - = true if this method called from group
163   */  
164   virtual void              moveObject( float dx, float dy, bool fromGroup = false ) = 0;
165   //! Finaly recomputing object after moving
166   virtual bool              finishMove() { return true; }
167   
168   //! Returns visible object status
169   bool                      getVisible() const { return myIsVisible; }
170   //! Installs visible object status
171   virtual void              setVisible( bool theStatus ) { myIsVisible = theStatus; }
172   
173   //! Installs onject tool tip text
174   void                      setToolTipText( QString str ){ myToolTipText = str; }
175   //! Returns onject tool tip text
176   virtual QString           getToolTipText(){ return myToolTipText; }
177   
178   //! Returns true if tool tip contains HTML tags
179   bool                      isTooTipHTML() const { return isToolTipHTML; }
180   //! Installs tool tip supporting of HTML tags
181   void                      setToolTipFormat( bool isHTML ) { isToolTipHTML = isHTML; }
182   
183   //! A function for coding object to the byte copy
184   /*! A function is used for copy-past technollogy in copy method */
185   virtual QByteArray        getByteCopy();
186   //! A function for decoding object from the byte copy
187   /*! A function is used for copy-past technollogy in past method */
188   virtual bool              initializeFromByteCopy( QByteArray );
189   
190   //! A function translate object in to PostScript file on disk
191   /*!
192    *\param hFile     the name of PostScript file chosen by user
193    *\param aViewerCS the GLViewer_CoordSystem of window
194    *\param aPSCS     the GLViewer_CoordSystem of PostScript page
195   */
196   virtual bool              translateToPS( QFile& hFile, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aPSCS ) = 0;
197   //! A function translate object in to HPGL file on disk
198   /*!
199    *\param hFile     the name of PostScript file chosen by user
200    *\param aViewerCS the GLViewer_CoordSystem of window
201    *\param aHPGLCS   the GLViewer_CoordSystem of PostScript page
202   */
203   virtual bool              translateToHPGL( QFile& hFile, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aHPGLCS ) = 0;  
204   
205 #ifdef WIN32
206   //! A function translate object in to EMF file on disk
207   /*!
208    *\warning WIN32 only
209    *
210    *\param dc        the name of HDC associated with file chosen by user
211    *\param aViewerCS the GLViewer_CoordSystem of window
212    *\param aEMFCS    the GLViewer_CoordSystem of EMF page
213   */
214   virtual bool              translateToEMF( HDC dc, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aEMFCS ) = 0;
215 #endif
216   //!\warning It is for ouv
217   GLViewer_Owner*           owner() const { return myOwner; }
218   //!\warning It is for ouv
219   void                      setOwner( GLViewer_Owner* owner ) { myOwner = owner; }
220   
221   //! Adds object to group theGroup
222   void                      setGroup( GLViewer_Group* theGroup );
223   //! Returns object group
224   GLViewer_Group*           getGroup() const;
225   
226   //!\warning It is for ouv
227   virtual GLViewer_Object*  getOwner() { return this; }
228
229   //! Returns true if object can be selected
230   virtual bool              isSelectable() { return true; }
231   //!\warning It is for ouv
232   virtual bool              isScalable() { return true; }
233   
234 protected:
235   //! Object name
236   QString                   myName;
237   //! Object type
238   QString                   myType;
239
240   //! Object base rect
241   GLViewer_Rect*            myRect;
242   //! Update object rect (after some viewer transformations)
243   GLViewer_Rect*            myUpdateRect;
244   //! Object GLText
245   GLViewer_Text*            myGLText;
246
247   //! X scale factor
248   GLfloat                   myXScale;
249   //! Y scale factor
250   GLfloat                   myYScale;
251   //! Gap for X direction of rect
252   GLfloat                   myXGap;
253   //! Gap for Y direction of rect
254   GLfloat                   myYGap;
255
256   //!\warning It is for ouv
257   GLfloat                   myZoom;
258
259   //! Highlight status
260   /*! = true after right highlighting*/
261   GLboolean                 myIsHigh;
262   //! Selectt status
263   /*! = true after right selection*/
264   GLboolean                 myIsSel;
265   
266   //! Object drawer 
267   GLViewer_Drawer*          myDrawer;
268   //! Line aspect for object presentation
269   GLViewer_AspectLine*      myAspectLine;
270   
271   //! Objet tool tip text
272   QString                   myToolTipText;
273   //! HTML object tool tip status
274   /*! = true if tool tip text contains HTML tags */
275   bool                      isToolTipHTML;
276
277   //! Object visibke status
278   bool                      myIsVisible;
279
280   //!\warning It is for ouv
281   GLViewer_Owner*           myOwner;
282
283   //! Object Group
284   GLViewer_Group*           myGroup;
285 };
286
287
288 //!\warning It is for ouv
289 class GLVIEWER_API GLViewer_Owner : public SUIT_DataOwner
290 {
291 public:
292   //!\warning It is for ouv
293   GLViewer_Owner() : SUIT_DataOwner() {}
294   //!\warning It is for ouv
295   ~GLViewer_Owner() {}
296
297 protected:
298
299 };
300
301 #ifdef WNT
302 #pragma warning ( default:4251 )
303 #endif
304
305 #endif