1 // Copyright (C) 2007-2014 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, or (at your option) any later version.
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
23 // Author : OPEN CASCADE
24 // File: GLViewer_BaseDrawers.cxx
25 // Created: November, 2004
26 //#include <GLViewerAfx.h>
28 #include "GLViewer_BaseDrawers.h"
29 #include "GLViewer_Object.h"
30 #include "GLViewer_Text.h"
31 #include "GLViewer_AspectLine.h"
32 #include "GLViewer_BaseObjects.h"
42 GLfloat sin_table[SEGMENTS];
43 GLfloat cos_table[SEGMENTS];
48 GLViewer_MarkerDrawer::GLViewer_MarkerDrawer()
52 for ( int i = 0; i < SEGMENTS; i++ )
54 sin_table[i] = sin( angle );
55 cos_table[i] = cos( angle );
56 angle += float( STEP );
58 myObjectType = "GLViewer_MarkerSet";
64 GLViewer_MarkerDrawer::~GLViewer_MarkerDrawer()
68 /*! Draws object in GLViewer
69 \param xScale - current scale along X-direction
70 \param yScale - current scale along Y-direction
71 \param onlyUpdate - = true if only update highlight-select information
73 void GLViewer_MarkerDrawer::create( float xScale, float yScale, bool onlyUpdate )
75 QList<int>::Iterator it;
76 QList<int>::Iterator EndIt;
77 QList<GLViewer_Object*>::Iterator anObjectIt = myObjects.begin();
78 QList<GLViewer_Object*>::Iterator anEndObjectIt = myObjects.end();
83 QColor colorN, colorH, colorS;
85 GLViewer_MarkerSet* aMarkerSet = NULL;
86 GLViewer_AspectLine* anAspectLine = NULL;
88 for( ; anObjectIt != anEndObjectIt; anObjectIt++ )
90 aMarkerSet = ( GLViewer_MarkerSet* )(*anObjectIt);
91 anAspectLine = aMarkerSet->getAspectLine();
92 anAspectLine->getLineColors( colorN, colorH, colorS );
94 float* aXCoord = aMarkerSet->getXCoord();
95 float* anYCoord = aMarkerSet->getYCoord();
96 float aRadius = aMarkerSet->getMarkerSize();
98 QList<int> aHNumbers, anUHNumbers, aSelNumbers, anUSelNumbers;
99 aMarkerSet->exportNumbers( aHNumbers, anUHNumbers, aSelNumbers, anUSelNumbers );
103 EndIt = anUHNumbers.end();
104 for( it = anUHNumbers.begin(); it != EndIt; ++it )
106 drawMarker( aXCoord[*it], anYCoord[*it], aRadius, colorN, anAspectLine );
109 EndIt = anUSelNumbers.end();
110 for( it = anUSelNumbers.begin(); it != EndIt; ++it )
111 drawMarker( aXCoord[*it], anYCoord[*it], aRadius, colorN, anAspectLine );
113 EndIt = aSelNumbers.end();
114 for( it = aSelNumbers.begin(); it != EndIt; ++it )
115 drawMarker( aXCoord[*it], anYCoord[*it], aRadius, colorS, anAspectLine );
117 EndIt = aHNumbers.end();
118 for( it = aHNumbers.begin(); it != EndIt; ++it )
120 drawMarker( aXCoord[*it], anYCoord[*it], aRadius, colorH, anAspectLine );
125 int aNumber = aMarkerSet->getNumMarkers();
126 for( int i = 0; i < aNumber; i++ )
127 drawMarker( aXCoord[i], anYCoord[i], aRadius, colorN, anAspectLine );
129 EndIt = anUSelNumbers.end();
130 for( it = anUSelNumbers.begin(); it != EndIt; ++it )
131 drawMarker( aXCoord[*it], anYCoord[*it], aRadius, colorN, anAspectLine );
133 EndIt = aSelNumbers.end();
134 for( it = aSelNumbers.begin(); it != EndIt; ++it )
135 drawMarker( aXCoord[*it], anYCoord[*it], aRadius, colorS, anAspectLine );
137 if( aMarkerSet->getGLText()->getText() != "" )
139 //float aXPos = 0, anYPos = 0;
140 //aMarkerSet->getGLText()->getPosition( aXPos, anYPos );
141 //drawText( aMarkerSet->getGLText()->getText(), aXPos, anYPos, colorN, &aMarkerSet->getGLText()->getFont(), aMarkerSet->getGLText()->getSeparator() );
142 drawText( aMarkerSet );
148 \param theXCoord - X position
149 \param theYCoord - Y position
150 \param theRadius - radius
151 \param theColor - color
152 \param theAspectLine - line aspect
154 void GLViewer_MarkerDrawer::drawMarker( float& theXCoord, float& theYCoord,
155 float& theRadius, QColor& theColor, GLViewer_AspectLine* theAspectLine )
157 glColor3f( ( GLfloat )theColor.red() / 255,
158 ( GLfloat )theColor.green() / 255,
159 ( GLfloat )theColor.blue() / 255 );
161 glLineWidth( theAspectLine->getLineWidth() );
163 if ( theAspectLine->getLineType() == 0 )
164 glBegin( GL_LINE_LOOP );
166 glBegin( GL_LINE_STRIP);
168 for ( int i = 0; i < SEGMENTS; i++ )
169 glVertex2f( theXCoord + cos_table[i] * theRadius / myXScale,
170 theYCoord + sin_table[i] * theRadius / myYScale );
178 GLViewer_PolylineDrawer::GLViewer_PolylineDrawer()
181 myObjectType = "GLViewer_Polyline";
187 GLViewer_PolylineDrawer::~GLViewer_PolylineDrawer()
191 /*! Draws object in GLViewer
192 \param xScale - current scale along X-direction
193 \param yScale - current scale along Y-direction
194 \param onlyUpdate - = true if only update highlight-select information
196 void GLViewer_PolylineDrawer::create( float xScale, float yScale, bool onlyUpdate )
198 QList<GLViewer_Object*>::Iterator aObjectIt = myObjects.begin();
199 QList<GLViewer_Object*>::Iterator aObjectEndIt = myObjects.end();
204 QColor color, colorN, colorH, colorS;
205 GLViewer_AspectLine* anAspect = NULL;
206 GLViewer_Polyline* aPolyline = NULL;
207 for( ; aObjectIt != aObjectEndIt; aObjectIt++ )
209 anAspect = (*aObjectIt)->getAspectLine();
210 aPolyline = (GLViewer_Polyline*)(*aObjectIt);
213 anAspect->getLineColors( colorN, colorH, colorS );
216 if( aPolyline->isHighlighted() )
218 else if( aPolyline->isSelected() )
225 if( aPolyline->isSelected() )
231 float* aXCoord = aPolyline->getXCoord();
232 float* anYCoord = aPolyline->getYCoord();
233 int aSize = aPolyline->getNumber();
235 glColor3f( ( GLfloat )color.red() / 255,
236 ( GLfloat )color.green() / 255,
237 ( GLfloat )color.blue() / 255 );
239 glLineWidth( anAspect->getLineWidth() );
241 if ( anAspect->getLineType() == 0 )
242 glBegin( GL_LINE_LOOP );
244 glBegin( GL_LINE_STRIP);
246 for( int i = 0; i < aSize ; i++ )
247 glVertex2f( aXCoord[ i ], anYCoord[ i ] );
249 if( aPolyline->isClosed() )
250 glVertex2f( aXCoord[ 0 ], anYCoord[ 0 ] );
254 if( aPolyline->getGLText()->getText() != "" )
256 //float aXPos = 0, anYPos = 0;
257 //aPolyline->getGLText()->getPosition( aXPos, anYPos );
258 //drawText( aPolyline->getGLText()->getText(), aXPos, anYPos, color, &aPolyline->getGLText()->getFont(), aPolyline->getGLText()->getSeparator() );
259 drawText( aPolyline );
267 GLViewer_TextDrawer::GLViewer_TextDrawer()
270 myObjectType = "GLViewer_TextObject";
276 GLViewer_TextDrawer::~GLViewer_TextDrawer()
280 /*! Draws object in GLViewer
281 \param xScale - current scale along X-direction
282 \param yScale - current scale along Y-direction
283 \param onlyUpdate - = true if only update highlight-select information
285 void GLViewer_TextDrawer::create( float xScale, float yScale, bool onlyUpdate )
287 QList<GLViewer_Object*>::Iterator aObjectIt = myObjects.begin();
288 QList<GLViewer_Object*>::Iterator aObjectEndIt = myObjects.end();
293 QColor color, colorN, colorH, colorS;
294 GLViewer_AspectLine* anAspect = NULL;
295 GLViewer_TextObject* anObject = NULL;
296 //float aXPos = 0, anYPos = 0;
297 for( ; aObjectIt != aObjectEndIt; aObjectIt++ )
299 anObject = (GLViewer_TextObject*)(*aObjectIt);
300 anAspect = anObject->getAspectLine();
302 anAspect->getLineColors( colorN, colorH, colorS );
305 if( anObject->isHighlighted() )
307 else if( anObject->isSelected() )
314 if( anObject->isSelected() )
320 //anObject->getGLText()->getPosition( aXPos, anYPos );
321 //drawText( anObject->getGLText()->getText(), aXPos, anYPos, color, &(anObject->getGLText()->getFont()), anObject->getGLText()->getSeparator() );
322 drawText( anObject );
327 Updates objects after updating font
329 void GLViewer_TextDrawer::updateObjects()
331 QList<GLViewer_Object*>::Iterator aObjectIt = myObjects.begin();
332 QList<GLViewer_Object*>::Iterator aObjectEndIt = myObjects.end();
333 for( ; aObjectIt != aObjectEndIt; aObjectIt++ )
334 (*aObjectIt)->compute();