1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // Author : OPEN CASCADE
23 // File: GLViewer_Geom.h
24 // Created: November, 2004
26 #ifndef GLVIEWER_GEOM_H
27 #define GLVIEWER_GEOM_H
35 //using namespace QGL;
38 #pragma warning( disable:4251 )
41 /*! Struct GLViewer_Pnt
42 * Substitution of QPoint for OpenGL
45 struct GLVIEWER_API GLViewer_Pnt
48 GLViewer_Pnt() : myX( 0. ), myY( 0. ) {};
49 GLViewer_Pnt( GLfloat theX, GLfloat theY ) : myX( theX ), myY( theY ) {}
51 GLfloat x() const { return myX; }
52 GLfloat y() const { return myY; }
53 void setX( GLfloat theX ) { myX = theX; }
54 void setY( GLfloat theY ) { myY = theY; }
55 void setXY( GLfloat theX, GLfloat theY ) { myX = theX; myY = theY; }
56 void move( GLfloat theDX, GLfloat theDY ) { myX += theDX; myY += theDY; }
63 typedef QList<GLViewer_Pnt> GLViewer_PntList;
65 /*! Class GLViewer_Rect
66 * Substitution of QRect for OpenGL
69 class GLVIEWER_API GLViewer_Rect
72 GLViewer_Rect(): myLeft(0.0), myRight(0.0), myTop(0.0), myBottom(0.0){}
73 GLViewer_Rect( float theLeft, float theRight, float theTop, float theBottom )
74 : myLeft(theLeft), myRight(theRight), myTop(theTop), myBottom(theBottom) {}
75 GLViewer_Rect( QRect theRect ) {
76 myLeft = ( float )theRect.left(); myRight = ( float )theRect.right();
77 myTop = ( float )theRect.top(); myBottom = ( float )theRect.bottom(); }
79 float left() const { return myLeft; }
80 float right() const { return myRight; }
81 float top() const { return myTop; }
82 float bottom() const { return myBottom; }
84 float width() const { return fabs( myRight - myLeft ); }
85 float height() const { return fabs( myTop - myBottom ); }
87 void setLeft( float theLeft ) { myLeft = theLeft; }
88 void setRight( float theRight ) { myRight = theRight; }
89 void setTop( float theTop ) { myTop = theTop; }
90 void setBottom( float theBottom ) { myBottom = theBottom; }
92 void setCoords( float theLeft, float theRight, float theBottom, float theTop )
93 { myLeft = theLeft; myRight = theRight; myBottom = theBottom; myTop = theTop; }
95 //! \warning This method translate only rect format
96 QRect toQRect() { return QRect( ( int )myLeft, ( int )myBottom,
97 ( int )( myRight - myLeft ),
98 ( int )( myTop - myBottom ) ); }
100 //! On/off empty status
101 void setIsEmpty( bool on ) { myIsEmpty = on; }
102 //! Checks empty status
103 bool isEmpty() const { return myIsEmpty; }
105 //! Checks null status
106 bool isNull() const { return myLeft == 0.0 && myRight == 0.0 && myBottom == 0.0 && myTop == 0.0; }
107 //! Checks valid status
108 bool isValid() const { return ( myLeft < myRight && myBottom < myTop ); }
110 //! Checks staus of contains point
111 bool contains( GLViewer_Pnt pnt ) { return ( pnt.x() > left() &&
113 pnt.y() > bottom() &&
116 void move( const float x, const float y )
133 /*! Class GLViewer_Segment
134 * Segment for 2d detection
137 class GLVIEWER_API GLViewer_Segment
140 GLViewer_Segment( const GLViewer_Pnt& thePnt1,
141 const GLViewer_Pnt& thePnt2 );
143 //! Ordinary segment construction
144 /*!Construction of a ray with given equation Ax + By + C = 0 */
146 GLViewer_Segment( const GLViewer_Pnt& thePnt,
149 const GLfloat theC );
152 bool HasIntersection( const GLViewer_Segment& theOther ) const;
153 // Detects intersection with another segment or ray
163 /*! Class GLViewer_Poly
164 * Polygon for 2d detection
167 class GLVIEWER_API GLViewer_Poly
170 GLViewer_Poly( const GLViewer_PntList* thePoints );
171 virtual ~GLViewer_Poly();
173 //! Adds point to polygon
174 void AddPoint( GLViewer_Pnt& pnt ) { myPoints->append( pnt ); }
176 //! Returns number of point
177 int Count() const { return myPoints->count(); }
179 //! Returns true if a point lies inside this polygon
180 virtual bool IsIn( const GLViewer_Pnt& thePnt ) const;
182 //! Returns true if a other polygon covers this polygon
183 virtual bool IsCovers( const GLViewer_Poly& thePoly ) const;
185 //! Likes the above function
186 virtual bool IsCovers( const GLViewer_Rect& theRect ) const;
188 // Returns true if intersection of this polygon with a segment or a ray not empty
189 virtual bool HasIntersection( const GLViewer_Segment& theSegment ) const;
192 GLViewer_PntList* myPoints;
196 #pragma warning ( default:4251 )