Salome HOME
This file is given from DESCARTES project
[modules/gui.git] / src / GLViewer / GLViewer_BaseObjects.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_BaseObjects.h
23 // Created:   November, 2004
24
25 #ifndef GLVIEWER_BASEOBJECTS_H
26 #define GLVIEWER_BASEOBJECTS_H
27
28 #include "GLViewer.h"
29 #include "GLViewer_Object.h"
30
31 #include <qcolor.h>
32 #include <qvaluelist.h>
33
34 #include <TColStd_SequenceOfInteger.hxx>
35
36 #ifdef WNT
37 #pragma warning( disable:4251 )
38 #endif
39
40 /*! 
41  * Class GLViewer_MarkerSet
42  * OpenGL MarkerSet
43  */
44
45 class GLVIEWER_API GLViewer_MarkerSet : public GLViewer_Object
46 {
47 public:
48   //! A constructor
49   GLViewer_MarkerSet( int number = 1, float size = 5.0, const QString& toolTip = "GLMarker" );
50   //! A destructor
51   ~GLViewer_MarkerSet();
52
53   // redefined  methods
54   virtual void             compute();
55   virtual GLViewer_Drawer* createDrawer();
56   
57   virtual GLboolean        highlight( GLfloat x, GLfloat y, GLfloat tol = 15.0, GLboolean isCircle = GL_FALSE );
58   virtual GLboolean        unhighlight();
59   virtual GLboolean        select( GLfloat x, GLfloat y, GLfloat tol, GLViewer_Rect rect, GLboolean isFull = GL_FALSE,
60     GLboolean isCircle = GL_FALSE, GLboolean isShift = GL_FALSE );
61   virtual GLboolean        unselect();
62   
63   virtual GLViewer_Rect*   getUpdateRect();
64   
65   virtual void             moveObject( float, float, bool fromGroup = false );
66   
67   virtual QByteArray       getByteCopy();
68   virtual bool             initializeFromByteCopy( QByteArray );
69   
70   virtual bool             translateToPS( QFile& hFile, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aPSCS );
71   virtual bool             translateToHPGL( QFile& hFile, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aHPGLCS );    
72   
73 #ifdef WIN32
74   virtual bool             translateToEMF( HDC dc, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aEMFCS );
75 #endif
76
77   //! Sets array of x coords of markers
78   void                     setXCoord( GLfloat* xCoord, int size );
79   //! Sets array of y coords of markers
80   void                     setYCoord( GLfloat* yCoord, int size );
81   //! Returns x coords
82   GLfloat*                 getXCoord() const { return myXCoord; }
83   //! Returns y coords
84   GLfloat*                 getYCoord() const { return myYCoord; }
85   
86   //! Sets markers number
87   void                     setNumMarkers( GLint );
88   //! returns markers number
89   GLint                    getNumMarkers() const { return myNumber; };
90   //! Sets merker radius
91   void                     setMarkerSize( const float size ) { myMarkerSize = size; }
92   //! Returns merker radius
93   float                    getMarkerSize() const { return myMarkerSize; }
94   
95   //! Export numbers of heghlighted/selected markers
96   void                     exportNumbers( QValueList<int>& high, QValueList<int>& unhigh,
97                                           QValueList<int>& sel, QValueList<int>& unsel );
98   
99   //! Returns selected numbers
100   QValueList<int>          getSelectedElements() { return mySelNumbers; }
101   //! Adds or remove selected number
102   bool                     addOrRemoveSelected( int index );
103   //! Adds selected numbers
104   void                     addSelected( const TColStd_SequenceOfInteger& );
105   //! Sets selected nembers
106   void                     setSelected( const TColStd_SequenceOfInteger& );
107
108 protected:
109   GLint                   myNumber;
110   GLfloat*                myXCoord;
111   GLfloat*                myYCoord;    
112   GLfloat                 myMarkerSize;
113   QValueList<int>         myHNumbers;
114   QValueList<int>         myUHNumbers;
115   QValueList<int>         mySelNumbers;
116   QValueList<int>         myCurSelNumbers;
117   QValueList<int>         myUSelNumbers;
118   QValueList<int>         myPrevHNumbers;
119   TColStd_SequenceOfInteger mySelectedIndexes;
120 };
121
122 /*! 
123  * Class  GLViewer_Polyline
124  * OpenGL Polyline
125  */
126
127 class GLVIEWER_API GLViewer_Polyline: public GLViewer_Object
128 {
129 public:
130   GLViewer_Polyline( int number = 1, float size = 5.0, const QString& toolTip = "GLPolyline" );
131  ~GLViewer_Polyline();
132   
133   // redefined  methods
134   virtual void            compute();
135   virtual GLViewer_Drawer* createDrawer();
136   
137   virtual GLboolean       highlight( GLfloat x, GLfloat y, GLfloat tol = 15.0, GLboolean isCircle = GL_FALSE );
138   virtual GLboolean       unhighlight();
139   virtual GLboolean       select( GLfloat x, GLfloat y, GLfloat tol,  GLViewer_Rect rect, GLboolean isFull = GL_FALSE,
140     GLboolean isCircle = GL_FALSE, GLboolean isShift = GL_FALSE );
141   virtual GLboolean       unselect();
142   
143   virtual GLViewer_Rect*  getUpdateRect();
144   
145   virtual void            moveObject( float, float, bool fromGroup = false );
146   
147   virtual QByteArray      getByteCopy();
148   virtual bool            initializeFromByteCopy( QByteArray );
149   
150   virtual bool            translateToPS( QFile& hFile, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aPSCS );
151   virtual bool            translateToHPGL( QFile& hFile, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aHPGLCS );    
152   
153 #ifdef WIN32
154   virtual bool            translateToEMF( HDC dc, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aEMFCS );
155 #endif
156   
157   //! Sets array of x coords of points
158   void                     setXCoord( GLfloat* xCoord, int size );
159   //! Sets array of y coords of points
160   void                     setYCoord( GLfloat* yCoord, int size );
161   //! Returns x coords
162   GLfloat*                 getXCoord() const { return myXCoord; }
163   //! Returns y coords
164   GLfloat*                 getYCoord() const { return myYCoord; }
165
166   //! SetS number of points
167   void                    setNumber( GLint );
168   //! Returns number of points
169   GLint                   getNumber() const { return myNumber; };
170   
171   //! On/off closed status of polyline
172   void                    setClosed( GLboolean closed ) { myIsClosed = closed; }
173   //! Checks closed status of polyline
174   GLboolean               isClosed() const { return myIsClosed; }
175   
176   //! On/off highlight as whole object status
177   void                    setHighSelAll( GLboolean highSelAll ) { myHighSelAll = highSelAll; }
178   //! Checks highlight as whole object status
179   GLboolean               isHighSelAll() const { return myHighSelAll; }
180   
181   //! Export numbers of heghlighted/selected lines
182   void                     exportNumbers( QValueList<int>& high, QValueList<int>& unhigh,
183                                           QValueList<int>& sel, QValueList<int>& unsel );
184
185   //! Returns numbers of selected lines
186   QValueList<int>         getSelectedElements() { return mySelNumbers; }
187
188 protected:
189   GLfloat*                myXCoord;
190   GLfloat*                myYCoord;
191   GLint                   myNumber;
192   GLboolean               myIsClosed;
193   GLboolean               myHighSelAll;
194   
195   QValueList<int>         myHNumbers;
196   QValueList<int>         myUHNumbers;
197   QValueList<int>         mySelNumbers;
198   QValueList<int>         myUSelNumbers;
199   QValueList<int>         myCurSelNumbers;
200   QValueList<int>         myPrevHNumbers;
201   TColStd_SequenceOfInteger mySelectedIndexes;
202   
203   GLboolean               myHighFlag;
204 };
205
206 // Class:   GLViewer_TextObject
207 // Descr:   Text as Object for OpenGL
208
209 class GLVIEWER_API GLViewer_TextObject : public GLViewer_Object
210 {
211 public:  
212   GLViewer_TextObject( const QString&, float xPos = 0, float yPos = 0, 
213     const QColor& color = QColor( 0, 255, 0 ), const QString& toolTip = "GLText" );
214   ~GLViewer_TextObject();
215   
216   virtual void              compute();
217   virtual GLViewer_Drawer*  createDrawer();
218   
219   virtual void              setDrawer( GLViewer_Drawer* theDrawer );
220   
221   virtual GLboolean         highlight( GLfloat x, GLfloat y, GLfloat tol, GLboolean isCircle = GL_FALSE );
222   virtual GLboolean         unhighlight();
223   virtual GLboolean         select( GLfloat x, GLfloat y, GLfloat tol, GLViewer_Rect rect, GLboolean isFull = GL_FALSE,
224     GLboolean isCircle = GL_FALSE, GLboolean isShift = GL_FALSE );
225   virtual GLboolean         unselect();
226   
227   virtual GLViewer_Rect*    getUpdateRect();
228   
229   virtual void              moveObject( float, float, bool fromGroup = false );
230   
231   virtual QByteArray        getByteCopy();
232   virtual bool              initializeFromByteCopy( QByteArray );
233   
234   virtual bool              translateToPS( QFile& hFile, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aPSCS );
235   virtual bool              translateToHPGL( QFile& hFile, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aHPGLCS );  
236   
237 #ifdef WIN32
238   virtual bool              translateToEMF( HDC dc, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aEMFCS );
239 #endif
240   
241   int                       getWidth(){ return myWidth; }
242   int                       getHeight(){ return myWidth; }
243   void                      setWidth( int w ){ myWidth=w; }
244   void                      setHeight( int h ){ myHeight=h; }
245   
246 protected:
247   bool                      myHighFlag;
248   int                       myWidth;
249   int                       myHeight;
250 };
251
252 #ifdef WNT
253 #pragma warning ( default:4251 )
254 #endif
255
256 #endif