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