1 // Copyright (C) 2005 OPEN CASCADE
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.
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.
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
17 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
19 // Author : OPEN CASCADE
22 // File: GLViewer_BaseDrawers.cxx
23 // Created: November, 2004
25 //#include <GLViewerAfx.h>
26 #include "GLViewer_BaseDrawers.h"
27 #include "GLViewer_Object.h"
28 #include "GLViewer_Text.h"
29 #include "GLViewer_AspectLine.h"
30 #include "GLViewer_BaseObjects.h"
36 GLfloat sin_table[SEGMENTS];
37 GLfloat cos_table[SEGMENTS];
42 GLViewer_MarkerDrawer::GLViewer_MarkerDrawer()
46 for ( int i = 0; i < SEGMENTS; i++ )
48 sin_table[i] = sin( angle );
49 cos_table[i] = cos( angle );
50 angle += float( STEP );
52 myObjectType = "GLViewer_MarkerSet";
58 GLViewer_MarkerDrawer::~GLViewer_MarkerDrawer()
62 /*! Draws object in GLViewer
63 \param xScale - current scale along X-direction
64 \param yScale - current scale along Y-direction
65 \param onlyUpdate - = true if only update highlight-select information
67 void GLViewer_MarkerDrawer::create( float xScale, float yScale, bool onlyUpdate )
69 QValueList<int>::Iterator it;
70 QValueList<int>::Iterator EndIt;
71 QValueList<GLViewer_Object*>::Iterator anObjectIt = myObjects.begin();
72 QValueList<GLViewer_Object*>::Iterator anEndObjectIt = myObjects.end();
77 QColor colorN, colorH, colorS;
79 GLViewer_MarkerSet* aMarkerSet = NULL;
80 GLViewer_AspectLine* anAspectLine = NULL;
82 for( ; anObjectIt != anEndObjectIt; anObjectIt++ )
84 aMarkerSet = ( GLViewer_MarkerSet* )(*anObjectIt);
85 anAspectLine = aMarkerSet->getAspectLine();
86 anAspectLine->getLineColors( colorN, colorH, colorS );
88 float* aXCoord = aMarkerSet->getXCoord();
89 float* anYCoord = aMarkerSet->getYCoord();
90 float aRadius = aMarkerSet->getMarkerSize();
92 QValueList<int> aHNumbers, anUHNumbers, aSelNumbers, anUSelNumbers;
93 aMarkerSet->exportNumbers( aHNumbers, anUHNumbers, aSelNumbers, anUSelNumbers );
97 EndIt = anUHNumbers.end();
98 for( it = anUHNumbers.begin(); it != EndIt; ++it )
100 drawMarker( aXCoord[*it], anYCoord[*it], aRadius, colorN, anAspectLine );
103 EndIt = anUSelNumbers.end();
104 for( it = anUSelNumbers.begin(); it != EndIt; ++it )
105 drawMarker( aXCoord[*it], anYCoord[*it], aRadius, colorN, anAspectLine );
107 EndIt = aSelNumbers.end();
108 for( it = aSelNumbers.begin(); it != EndIt; ++it )
109 drawMarker( aXCoord[*it], anYCoord[*it], aRadius, colorS, anAspectLine );
111 EndIt = aHNumbers.end();
112 for( it = aHNumbers.begin(); it != EndIt; ++it )
114 drawMarker( aXCoord[*it], anYCoord[*it], aRadius, colorH, anAspectLine );
119 int aNumber = aMarkerSet->getNumMarkers();
120 for( int i = 0; i < aNumber; i++ )
121 drawMarker( aXCoord[i], anYCoord[i], aRadius, colorN, anAspectLine );
123 EndIt = anUSelNumbers.end();
124 for( it = anUSelNumbers.begin(); it != EndIt; ++it )
125 drawMarker( aXCoord[*it], anYCoord[*it], aRadius, colorN, anAspectLine );
127 EndIt = aSelNumbers.end();
128 for( it = aSelNumbers.begin(); it != EndIt; ++it )
129 drawMarker( aXCoord[*it], anYCoord[*it], aRadius, colorS, anAspectLine );
131 if( aMarkerSet->getGLText()->getText() != "" )
133 //float aXPos = 0, anYPos = 0;
134 //aMarkerSet->getGLText()->getPosition( aXPos, anYPos );
135 //drawText( aMarkerSet->getGLText()->getText(), aXPos, anYPos, colorN, &aMarkerSet->getGLText()->getFont(), aMarkerSet->getGLText()->getSeparator() );
136 drawText( aMarkerSet );
142 \param theXCoord - X position
143 \param theYCoord - Y position
144 \param theRadius - radius
145 \param theColor - color
146 \param theAspectLine - line aspect
148 void GLViewer_MarkerDrawer::drawMarker( float& theXCoord, float& theYCoord,
149 float& theRadius, QColor& theColor, GLViewer_AspectLine* theAspectLine )
151 glColor3f( ( GLfloat )theColor.red() / 255,
152 ( GLfloat )theColor.green() / 255,
153 ( GLfloat )theColor.blue() / 255 );
155 glLineWidth( theAspectLine->getLineWidth() );
157 if ( theAspectLine->getLineType() == 0 )
158 glBegin( GL_LINE_LOOP );
160 glBegin( GL_LINE_STRIP);
162 for ( int i = 0; i < SEGMENTS; i++ )
163 glVertex2f( theXCoord + cos_table[i] * theRadius / myXScale,
164 theYCoord + sin_table[i] * theRadius / myYScale );
172 GLViewer_PolylineDrawer::GLViewer_PolylineDrawer()
175 myObjectType = "GLViewer_Polyline";
181 GLViewer_PolylineDrawer::~GLViewer_PolylineDrawer()
185 /*! Draws object in GLViewer
186 \param xScale - current scale along X-direction
187 \param yScale - current scale along Y-direction
188 \param onlyUpdate - = true if only update highlight-select information
190 void GLViewer_PolylineDrawer::create( float xScale, float yScale, bool onlyUpdate )
192 QValueList<GLViewer_Object*>::Iterator aObjectIt = myObjects.begin();
193 QValueList<GLViewer_Object*>::Iterator aObjectEndIt = myObjects.end();
198 QColor color, colorN, colorH, colorS;
199 GLViewer_AspectLine* anAspect = NULL;
200 GLViewer_Polyline* aPolyline = NULL;
201 for( ; aObjectIt != aObjectEndIt; aObjectIt++ )
203 anAspect = (*aObjectIt)->getAspectLine();
204 aPolyline = (GLViewer_Polyline*)(*aObjectIt);
207 anAspect->getLineColors( colorN, colorH, colorS );
210 if( aPolyline->isHighlighted() )
212 else if( aPolyline->isSelected() )
219 if( aPolyline->isSelected() )
225 float* aXCoord = aPolyline->getXCoord();
226 float* anYCoord = aPolyline->getYCoord();
227 int aSize = aPolyline->getNumber();
229 glColor3f( ( GLfloat )color.red() / 255,
230 ( GLfloat )color.green() / 255,
231 ( GLfloat )color.blue() / 255 );
233 glLineWidth( anAspect->getLineWidth() );
235 if ( anAspect->getLineType() == 0 )
236 glBegin( GL_LINE_LOOP );
238 glBegin( GL_LINE_STRIP);
240 for( int i = 0; i < aSize ; i++ )
241 glVertex2f( aXCoord[ i ], anYCoord[ i ] );
243 if( aPolyline->isClosed() )
244 glVertex2f( aXCoord[ 0 ], anYCoord[ 0 ] );
248 if( aPolyline->getGLText()->getText() != "" )
250 //float aXPos = 0, anYPos = 0;
251 //aPolyline->getGLText()->getPosition( aXPos, anYPos );
252 //drawText( aPolyline->getGLText()->getText(), aXPos, anYPos, color, &aPolyline->getGLText()->getFont(), aPolyline->getGLText()->getSeparator() );
253 drawText( aPolyline );
261 GLViewer_TextDrawer::GLViewer_TextDrawer()
264 myObjectType = "GLViewer_TextObject";
270 GLViewer_TextDrawer::~GLViewer_TextDrawer()
274 /*! Draws object in GLViewer
275 \param xScale - current scale along X-direction
276 \param yScale - current scale along Y-direction
277 \param onlyUpdate - = true if only update highlight-select information
279 void GLViewer_TextDrawer::create( float xScale, float yScale, bool onlyUpdate )
281 QValueList<GLViewer_Object*>::Iterator aObjectIt = myObjects.begin();
282 QValueList<GLViewer_Object*>::Iterator aObjectEndIt = myObjects.end();
287 QColor color, colorN, colorH, colorS;
288 GLViewer_AspectLine* anAspect = NULL;
289 GLViewer_TextObject* anObject = NULL;
290 //float aXPos = 0, anYPos = 0;
291 for( ; aObjectIt != aObjectEndIt; aObjectIt++ )
293 anObject = (GLViewer_TextObject*)(*aObjectIt);
294 anAspect = anObject->getAspectLine();
296 anAspect->getLineColors( colorN, colorH, colorS );
299 if( anObject->isHighlighted() )
301 else if( anObject->isSelected() )
308 if( anObject->isSelected() )
314 //anObject->getGLText()->getPosition( aXPos, anYPos );
315 //drawText( anObject->getGLText()->getText(), aXPos, anYPos, color, &(anObject->getGLText()->getFont()), anObject->getGLText()->getSeparator() );
316 drawText( anObject );
321 Updates objects after updating font
323 void GLViewer_TextDrawer::updateObjects()
325 QValueList<GLViewer_Object*>::Iterator aObjectIt = myObjects.begin();
326 QValueList<GLViewer_Object*>::Iterator aObjectEndIt = myObjects.end();
327 for( ; aObjectIt != aObjectEndIt; aObjectIt++ )
328 (*aObjectIt)->compute();