1 // File: GLViewer_Object.h
2 // Created: November, 2004
4 // Copyright (C) CEA 2004
6 #ifndef GLVIEWER_OBJECT_H
7 #define GLVIEWER_OBJECT_H
14 #include "GLViewer_Defs.h"
24 #include <qvaluelist.h>
26 #include <TColStd_SequenceOfInteger.hxx>
31 #pragma warning( disable:4251 )
34 class GLVIEWER_EXPORT GLViewer_Pnt
37 GLViewer_Pnt() : myX( 0. ), myY( 0. ) {}
38 GLViewer_Pnt( GLfloat theX, GLfloat theY ) : myX( theX ), myY( theY ) {}
40 GLfloat x() const { return myX; }
41 GLfloat y() const { return myY; }
42 void setX( GLfloat theX ) { myX = theX; }
43 void setY( GLfloat theY ) { myY = theY; }
44 void setXY( GLfloat theX, GLfloat theY ) { myX = theX; myY = theY; }
45 void move( GLfloat theDX, GLfloat theDY ) { myX += theDX; myY += theDY; }
52 typedef QValueList<GLViewer_Pnt> GLViewer_PntList;
54 /***************************************************************************
55 ** Class: GLViewer_Rect
56 ** Descr: Substitution of QRect for OpenGL
58 ** Created: UI team, 19.04.04
59 ****************************************************************************/
60 class GLVIEWER_EXPORT GLViewer_Rect
63 GLViewer_Rect(): myLeft(0.0), myRight(0.0), myTop(0.0), myBottom(0.0){}
64 GLViewer_Rect( float theLeft, float theRight, float theTop, float theBottom )
65 : myLeft(theLeft), myRight(theRight), myTop(theTop), myBottom(theBottom) {}
66 GLViewer_Rect( QRect theRect ) {
67 myLeft = ( float )theRect.left(); myRight = ( float )theRect.right();
68 myTop = ( float )theRect.top(); myBottom = ( float )theRect.bottom(); }
71 float left() const { return myLeft; }
72 float right() const { return myRight; }
73 float top() const { return myTop; }
74 float bottom() const { return myBottom; }
76 void setLeft( float theLeft ) { myLeft = theLeft; }
77 void setRight( float theRight ) { myRight = theRight; }
78 void setTop( float theTop ) { myTop = theTop; }
79 void setBottom( float theBottom ) { myBottom = theBottom; }
81 void setCoords( float theLeft, float theRight, float theTop, float theBottom )
82 { myLeft = theLeft; myRight = theRight; myTop = theTop; myBottom = theBottom; }
84 QRect* toQRect() { return new QRect( ( int )myLeft, ( int )myBottom,
85 ( int )( myRight - myLeft ), ( int )( myTop - myBottom ) ); }
87 bool isNull() const { return myLeft == myRight || myTop == myBottom; }
88 bool isValid() const { return !( myLeft > myRight || myTop < myBottom ); }
90 bool contains( GLViewer_Pnt pnt ) { return ( pnt.x() > left() &&
93 pnt.y() < bottom() ); }
102 /***************************************************************************
103 ** Class: GLViewer_Text
104 ** Descr: Substitution of Prs3d_Text for OpenGL
106 ** Created: UI team, 10.07.03
107 ****************************************************************************/
108 class GLVIEWER_EXPORT GLViewer_Text
111 GLViewer_Text( const QString&, float xPos = 0.0, float yPos = 0.0, const QColor& color = QColor( 0, 255, 0 ) );
112 GLViewer_Text( const QString&, float xPos, float yPos, const QColor& , QFont, int );
115 void setText( const QString& text ) { myText = text; }
116 QString getText() const { return myText; }
118 void setPosition( float xPos, float yPos ) { myXPos = xPos; myYPos = yPos; }
119 void getPosition( float& xPos, float& yPos ) { xPos = myXPos; yPos = myYPos; }
121 void setColor( const QColor& color ) { myColor = color; }
122 QColor getColor() const { return myColor; }
124 void setFont( const QFont theQFont) { myQFont = theQFont; }
125 QFont getFont() const { return myQFont; }
127 int getSeparator(){ return mySeparator; }
128 void setSeparator( int theSep ){ mySeparator = theSep; }
133 QByteArray getByteCopy() const;
135 static GLViewer_Text* fromByteCopy( QByteArray );
137 DisplayTextFormat getDisplayTextFormat() const { return myDTF; }
138 void setTextDisplayFormat( DisplayTextFormat theDTF ) { myDTF = theDTF; }
147 DisplayTextFormat myDTF;
150 /***************************************************************************
151 ** Class: GLViewer_CoordSystem
154 ** Created: UI team, 02.09.02
155 ****************************************************************************/
156 class GLVIEWER_EXPORT GLViewer_CoordSystem
159 enum CSType { Cartesian, Polar };
162 double myX0, myY0; //The coordinates of origin in the reference CS
163 double myXUnit, myYUnit; //The lengths of axis units in the reference unit
164 double myRotation; //The rotation in radians relative to reference CS
166 //!!! In the polar CS myYUnit is ignored, but myXUnit is the unit of polar radius
171 GLViewer_CoordSystem( CSType aType, double X0 = 0.0, double Y0 = 0.0,
172 double XUnit = 1.0, double YUnit = 1.0,
173 double Rotation = 0.0 );
175 void getOrigin( double& x, double& y ) const;
176 void setOrigin( double x, double y );
178 void getUnits( double& x, double& y ) const;
179 void setUnits( double x, double y );
181 double getRotation() const;
182 void setRotation( double rotation );
184 CSType getType() const;
185 void setType( CSType type );
187 void transform( GLViewer_CoordSystem& aSystem, double& x, double& y );
188 //Transform the coordinates x, y from current CS to aSystem
190 virtual void getStretching( GLViewer_CoordSystem& aSystem, double& theX, double& theY );
191 //Return how many times line width in aSystem system bigger than in current
194 virtual void toReference( double& x, double& y );
195 virtual void fromReference( double& x, double& y );
198 /***************************************************************************
199 ** Class: GLViewer_Object
200 ** Descr: OpenGL Object
202 ** Created: UI team, 02.09.02
203 ****************************************************************************/
208 class GLViewer_Drawer;
209 class GLViewer_AspectLine;
210 class GLViewer_Owner;
211 class GLViewer_Group;
213 class GLVIEWER_EXPORT GLViewer_Object : public QObject
219 virtual ~GLViewer_Object();
221 virtual void compute() = 0;
222 virtual GLViewer_Drawer* createDrawer() = 0;
223 GLViewer_Drawer* getDrawer(){ return myDrawer; }
224 virtual void setDrawer( GLViewer_Drawer* theDrawer ) { myDrawer = theDrawer; }
226 virtual GLboolean highlight( GLfloat x, GLfloat y, GLfloat tol, GLboolean isCircle = GL_FALSE ) = 0;
227 virtual GLboolean unhighlight() = 0;
228 virtual GLboolean select( GLfloat x, GLfloat y, GLfloat tol, GLViewer_Rect rect, GLboolean isFull = GL_FALSE,
229 GLboolean isCircle = GL_FALSE, GLboolean isShift = GL_FALSE ) = 0;
230 virtual GLboolean unselect() = 0;
232 virtual GLboolean isInside( GLViewer_Rect );
234 virtual bool portContains( GLViewer_Pnt ) { return false; }
235 virtual bool startPulling( GLViewer_Pnt ) { return false; }
236 virtual void pull( GLViewer_Pnt, GLViewer_Object* ) {}
237 virtual void finishPulling() {}
238 virtual bool isPulling() { return false; }
240 virtual void setRect( GLViewer_Rect* rect) { myRect = rect; }
241 virtual GLViewer_Rect* getRect() const { return myRect; }
242 virtual GLViewer_Rect* getUpdateRect() = 0;
244 virtual void setScale( GLfloat xScale, GLfloat yScale ) { myXScale = xScale; myYScale = yScale; }
245 virtual void getScale( GLfloat& xScale, GLfloat& yScale ) const { xScale = myXScale; yScale = myYScale;}
247 virtual GLboolean setZoom( GLfloat zoom, GLboolean = GL_FALSE );
248 virtual GLfloat getZoom() const { return myZoom; }
249 virtual GLboolean updateZoom( bool zoomIn );
251 virtual GLboolean isHighlighted() const { return myIsHigh; }
252 virtual GLboolean isSelected() const { return myIsSel; }
253 virtual void setSelected( GLboolean state ) { myIsSel = state; }
255 void setGLText( GLViewer_Text* glText ) { myGLText = glText; }
256 GLViewer_Text* getGLText() const { return myGLText; }
258 virtual void setAspectLine ( GLViewer_AspectLine* aspect ) { myAspectLine = aspect; }
259 virtual GLViewer_AspectLine* getAspectLine() const { return myAspectLine; }
261 QString getObjectType() const { return myType; }
263 void setName( QString name ) { myName = name; }
264 QString getName() const { return myName; }
266 virtual void moveObject( float, float, bool fromGroup = false ) = 0;
267 virtual void finishMove() {}
269 bool getVisible(){ return myIsVisible; }
270 void setVisible( bool theStatus ){ myIsVisible = theStatus; }
272 void setToolTipText( QString str ){ myToolTipText = str; }
273 virtual QString getToolTipText(){ return myToolTipText; }
275 bool isTooTipHTML() const { return isToolTipHTML; }
276 void setToolTipFormat( bool isHTML ) { isToolTipHTML = isHTML; }
278 virtual QByteArray getByteCopy();
279 virtual bool initializeFromByteCopy( QByteArray );
281 virtual bool translateToPS( QFile& hFile, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aPSCS ) = 0;
282 virtual bool translateToHPGL( QFile& hFile, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aHPGLCS ) = 0;
285 virtual bool translateToEMF( HDC dc, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aEMFCS ) = 0;
288 GLViewer_Owner* owner() const;
289 void setOwner( GLViewer_Owner* );
291 void setGroup( GLViewer_Group* );
292 GLViewer_Group* getGroup() const;
298 GLViewer_Rect* myRect;
308 GLViewer_Text* myGLText;
310 GLViewer_Drawer* myDrawer;
311 GLViewer_AspectLine* myAspectLine;
312 QString myToolTipText;
316 GLViewer_Owner* myOwner;
317 GLViewer_Group* myGroup;
320 /***************************************************************************
321 ** Class: GLViewer_Owner
324 ** Created: UI team, 15.12.04
325 ****************************************************************************/
326 #include <SUIT_DataOwner.h>
328 class GLVIEWER_EXPORT GLViewer_Owner: public SUIT_DataOwner
331 GLViewer_Owner():SUIT_DataOwner() {};
332 ~GLViewer_Owner() {};
335 int getIndex() const { return myIndex; }
341 /***************************************************************************
342 ** Class: GLViewer_MarkerSet
343 ** Descr: OpenGL MarkerSet
345 ** Created: UI team, 03.09.02
346 ****************************************************************************/
347 class GLVIEWER_EXPORT GLViewer_MarkerSet: public GLViewer_Object
352 GLViewer_MarkerSet( int number = 1, float size = 5.0, const QString& toolTip = "GLMarker" );
353 ~GLViewer_MarkerSet();
355 virtual void compute();
356 virtual GLViewer_Drawer* createDrawer();
358 virtual GLboolean highlight( GLfloat x, GLfloat y, GLfloat tol = 15.0, GLboolean isCircle = GL_FALSE );
359 virtual GLboolean unhighlight();
360 virtual GLboolean select( GLfloat x, GLfloat y, GLfloat tol, GLViewer_Rect rect, GLboolean isFull = GL_FALSE,
361 GLboolean isCircle = GL_FALSE, GLboolean isShift = GL_FALSE );
362 virtual GLboolean unselect();
364 virtual GLViewer_Rect* getUpdateRect();
366 void setXCoord( GLfloat* xCoord, int size );
367 void setYCoord( GLfloat* yCoord, int size );
368 GLfloat* getXCoord() const { return myXCoord; }
369 GLfloat* getYCoord() const { return myYCoord; }
370 void setNumMarkers( GLint );
371 GLint getNumMarkers() const { return myNumber; };
373 void setMarkerSize( const float size ) { myMarkerSize = size; }
374 float getMarkerSize() const { return myMarkerSize; }
376 void exportNumbers( QValueList<int>&, QValueList<int>& , QValueList<int>&, QValueList<int>& );
378 QValueList<int> getSelectedElements() { return mySelNumbers; }
379 bool addOrRemoveSelected( int index );
380 void addSelected( const TColStd_SequenceOfInteger& );
381 void setSelected( const TColStd_SequenceOfInteger& );
383 virtual void moveObject( float, float, bool fromGroup = false );
385 virtual QByteArray getByteCopy();
386 virtual bool initializeFromByteCopy( QByteArray );
388 virtual bool translateToPS( QFile& hFile, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aPSCS );
389 virtual bool translateToHPGL( QFile& hFile, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aHPGLCS );
392 virtual bool translateToEMF( HDC dc, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aEMFCS );
396 void onSelectionDone( bool );
397 void onSelectionCancel();
400 void dvMarkersSelected( const TColStd_SequenceOfInteger& );
406 GLfloat myMarkerSize;
407 QValueList<int> myHNumbers;
408 QValueList<int> myUHNumbers;
409 QValueList<int> mySelNumbers;
410 QValueList<int> myCurSelNumbers;
411 QValueList<int> myUSelNumbers;
412 QValueList<int> myPrevHNumbers;
413 TColStd_SequenceOfInteger mySelectedIndexes;
416 /***************************************************************************
417 ** Class: GLViewer_Polyline
418 ** Descr: OpenGL Polyline
420 ** Created: UI team, 03.09.02
421 ****************************************************************************/
422 class GLVIEWER_EXPORT GLViewer_Polyline: public GLViewer_Object
427 GLViewer_Polyline( int number = 1, float size = 5.0, const QString& toolTip = "GLPolyline" );
428 ~GLViewer_Polyline();
430 virtual void compute();
431 virtual GLViewer_Drawer* createDrawer();
433 virtual GLboolean highlight( GLfloat x, GLfloat y, GLfloat tol = 15.0, GLboolean isCircle = GL_FALSE );
434 virtual GLboolean unhighlight();
435 virtual GLboolean select( GLfloat x, GLfloat y, GLfloat tol, GLViewer_Rect rect, GLboolean isFull = GL_FALSE,
436 GLboolean isCircle = GL_FALSE, GLboolean isShift = GL_FALSE );
437 virtual GLboolean unselect();
439 virtual GLViewer_Rect* getUpdateRect();
441 void setXCoord( GLfloat* xCoord, int size );
442 void setYCoord( GLfloat* yCoord, int size );
443 GLfloat* getXCoord() const { return myXCoord; }
444 GLfloat* getYCoord() const { return myYCoord; }
445 void setNumber( GLint );
446 GLint getNumber() const { return myNumber; };
448 void setClosed( GLboolean closed ) { myIsClosed = closed; }
449 GLboolean isClosed() const { return myIsClosed; }
451 void setHighSelAll( GLboolean highSelAll ) { myHighSelAll = highSelAll; }
452 GLboolean isHighSelAll() const { return myHighSelAll; }
454 void exportNumbers( QValueList<int>&, QValueList<int>& , QValueList<int>&, QValueList<int>& );
456 QValueList<int> getSelectedElements() { return mySelNumbers; }
458 virtual void moveObject( float, float, bool fromGroup = false );
460 virtual QByteArray getByteCopy();
461 virtual bool initializeFromByteCopy( QByteArray );
463 virtual bool translateToPS( QFile& hFile, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aPSCS );
464 virtual bool translateToHPGL( QFile& hFile, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aHPGLCS );
467 virtual bool translateToEMF( HDC dc, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aEMFCS );
471 void onSelectionDone( bool );
472 void onSelectionCancel();
478 GLboolean myIsClosed;
479 GLboolean myHighSelAll;
481 QValueList<int> myHNumbers;
482 QValueList<int> myUHNumbers;
483 QValueList<int> mySelNumbers;
484 QValueList<int> myUSelNumbers;
485 QValueList<int> myCurSelNumbers;
486 QValueList<int> myPrevHNumbers;
487 TColStd_SequenceOfInteger mySelectedIndexes;
489 GLboolean myHighFlag;
493 /***************************************************************************
494 ** Class: GLViewer_TextObject
495 ** Descr: Text as Object for OpenGL
497 ** Created: UI team, 27.02.04
498 ****************************************************************************/
499 class GLVIEWER_EXPORT GLViewer_TextObject : public GLViewer_Object
504 GLViewer_TextObject( const QString&, float xPos = 0, float yPos = 0,
505 const QColor& color = QColor( 0, 255, 0 ), const QString& toolTip = "GLText" );
506 ~GLViewer_TextObject();
508 virtual void compute();
509 virtual GLViewer_Drawer* createDrawer();
511 virtual void setDrawer( GLViewer_Drawer* theDrawer );
513 virtual GLboolean highlight( GLfloat x, GLfloat y, GLfloat tol, GLboolean isCircle = GL_FALSE );
514 virtual GLboolean unhighlight();
515 virtual GLboolean select( GLfloat x, GLfloat y, GLfloat tol, GLViewer_Rect rect, GLboolean isFull = GL_FALSE,
516 GLboolean isCircle = GL_FALSE, GLboolean isShift = GL_FALSE );
517 virtual GLboolean unselect();
519 virtual GLViewer_Rect* getUpdateRect();
521 virtual void moveObject( float, float, bool fromGroup = false );
523 virtual QByteArray getByteCopy();
524 virtual bool initializeFromByteCopy( QByteArray );
526 virtual bool translateToPS( QFile& hFile, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aPSCS );
527 virtual bool translateToHPGL( QFile& hFile, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aHPGLCS );
530 virtual bool translateToEMF( HDC dc, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aEMFCS );
533 int getWidth(){ return myWidth; }
534 int getHeight(){ return myWidth; }
535 void setWidth( int w ){ myWidth=w; }
536 void setHeight( int h ){ myHeight=h; }
545 /***************************************************************************
546 ** Class: GLViewer_AspectLine
547 ** Descr: Substitution of Prs2d_AspectLine for OpenGL
549 ** Created: UI team, 05.11.02
550 ****************************************************************************/
551 class GLVIEWER_EXPORT GLViewer_AspectLine
554 GLViewer_AspectLine();
555 GLViewer_AspectLine( int, float );
556 ~GLViewer_AspectLine();
558 void setLineColors( QColor nc = QColor( 0, 0, 0 ),
559 QColor hc = QColor( 0, 255, 255 ),
560 QColor sc = QColor( 255, 0, 0 ) );
561 int setLineWidth( const float );
562 int setLineType( const int );
564 void getLineColors( QColor&, QColor&, QColor& ) const;
565 float getLineWidth() const { return myLineWidth; };
566 int getLineType() const { return myLineType; };
568 QByteArray getByteCopy() const;
570 static GLViewer_AspectLine* fromByteCopy( QByteArray );
577 int myLineType; // 0 - normal, 1 - strip (not support in markers)
580 /***************************************************************************
581 ** Class: GLViewer_MimeSource
582 ** Descr: Needs for a work with QClipboard
584 ** Created: UI team, 22.03.04
585 ****************************************************************************/
586 class GLVIEWER_EXPORT GLViewer_MimeSource: public QMimeSource
589 GLViewer_MimeSource():QMimeSource(){};
590 ~GLViewer_MimeSource();
592 bool setObjects( QValueList<GLViewer_Object*> );
593 static QValueList<GLViewer_Object*> getObjects( QByteArray, QString );
594 static GLViewer_Object* getObject( QByteArray, QString );
596 virtual const char* format( int theIndex = 0 ) const;
597 virtual QByteArray encodedData( const char* ) const;
600 QByteArray myByteArray;
604 #pragma warning ( default:4251 )
607 #endif // GLVIEWER_OBJECT_H