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