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