Salome HOME
Copyright update 2022
[modules/gui.git] / src / GLViewer / GLViewer_BaseObjects.h
1 // Copyright (C) 2007-2022  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_BaseObjects.h
25 // Created:   November, 2004
26 //
27 #ifndef GLVIEWER_BASEOBJECTS_H
28 #define GLVIEWER_BASEOBJECTS_H
29
30 #include "GLViewer.h"
31 #include "GLViewer_Object.h"
32
33 #include <QColor>
34
35 #include <TColStd_SequenceOfInteger.hxx>
36
37 #ifdef WIN32
38 #pragma warning( disable:4251 )
39 #endif
40
41 /*! 
42  \class GLViewer_MarkerSet
43  OpenGL MarkerSet
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( QList<int>& high, QList<int>& unhigh,
97                                           QList<int>& sel, QList<int>& unsel );
98   
99   //! Returns selected numbers
100   QList<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   QList<int>              myHNumbers;
114   QList<int>              myUHNumbers;
115   QList<int>              mySelNumbers;
116   QList<int>              myCurSelNumbers;
117   QList<int>              myUSelNumbers;
118   QList<int>              myPrevHNumbers;
119   TColStd_SequenceOfInteger mySelectedIndexes;
120 };
121
122 /*! 
123  \class  GLViewer_Polyline
124  OpenGL Polyline
125 */
126 class GLVIEWER_API GLViewer_Polyline: public GLViewer_Object
127 {
128 public:
129   GLViewer_Polyline( int number = 1, float size = 5.0, const QString& toolTip = "GLPolyline" );
130  ~GLViewer_Polyline();
131   
132   // redefined  methods
133   virtual void            compute();
134   virtual GLViewer_Drawer* createDrawer();
135   
136   virtual GLboolean       highlight( GLfloat x, GLfloat y, GLfloat tol = 15.0, GLboolean isCircle = GL_FALSE );
137   virtual GLboolean       unhighlight();
138   virtual GLboolean       select( GLfloat x, GLfloat y, GLfloat tol,  GLViewer_Rect rect, GLboolean isFull = GL_FALSE,
139     GLboolean isCircle = GL_FALSE, GLboolean isShift = GL_FALSE );
140   virtual GLboolean       unselect();
141   
142   virtual GLViewer_Rect*  getUpdateRect();
143   
144   virtual void            moveObject( float, float, bool fromGroup = false );
145   
146   virtual QByteArray      getByteCopy();
147   virtual bool            initializeFromByteCopy( QByteArray );
148   
149   virtual bool            translateToPS( QFile& hFile, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aPSCS );
150   virtual bool            translateToHPGL( QFile& hFile, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aHPGLCS );    
151   
152 #ifdef WIN32
153   virtual bool            translateToEMF( HDC dc, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aEMFCS );
154 #endif
155   
156   //! Sets array of x coords of points
157   void                     setXCoord( GLfloat* xCoord, int size );
158   //! Sets array of y coords of points
159   void                     setYCoord( GLfloat* yCoord, int size );
160   //! Returns x coords
161   GLfloat*                 getXCoord() const { return myXCoord; }
162   //! Returns y coords
163   GLfloat*                 getYCoord() const { return myYCoord; }
164
165   //! SetS number of points
166   void                    setNumber( GLint );
167   //! Returns number of points
168   GLint                   getNumber() const { return myNumber; };
169   
170   //! On/off closed status of polyline
171   void                    setClosed( GLboolean closed ) { myIsClosed = closed; }
172   //! Checks closed status of polyline
173   GLboolean               isClosed() const { return myIsClosed; }
174   
175   //! On/off highlight as whole object status
176   void                    setHighSelAll( GLboolean highSelAll ) { myHighSelAll = highSelAll; }
177   //! Checks highlight as whole object status
178   GLboolean               isHighSelAll() const { return myHighSelAll; }
179   
180   //! Export numbers of highlighted/selected lines
181   void                    exportNumbers( QList<int>& high, QList<int>& unhigh,
182                                          QList<int>& sel, QList<int>& unsel );
183
184   //! Returns numbers of selected lines
185   QList<int>              getSelectedElements() { return mySelNumbers; }
186
187 protected:
188   GLfloat*                myXCoord;
189   GLfloat*                myYCoord;
190   GLint                   myNumber;
191   GLboolean               myIsClosed;
192   GLboolean               myHighSelAll;
193   
194   QList<int>              myHNumbers;
195   QList<int>              myUHNumbers;
196   QList<int>              mySelNumbers;
197   QList<int>              myUSelNumbers;
198   QList<int>              myCurSelNumbers;
199   QList<int>              myPrevHNumbers;
200   TColStd_SequenceOfInteger mySelectedIndexes;
201   
202   GLboolean               myHighFlag;
203 };
204
205 /*!
206   \class GLViewer_TextObject
207   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 WIN32
253 #pragma warning ( default:4251 )
254 #endif
255
256 #endif