1 // Copyright (C) 2007-2016 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"
37 #if !defined(WIN32) && !defined(__APPLE__)
41 GLfloat sin_table[SEGMENTS];
42 GLfloat cos_table[SEGMENTS];
47 GLViewer_MarkerDrawer::GLViewer_MarkerDrawer()
51 for ( int i = 0; i < SEGMENTS; i++ )
53 sin_table[i] = sin( angle );
54 cos_table[i] = cos( angle );
55 angle += float( STEP );
57 myObjectType = "GLViewer_MarkerSet";
63 GLViewer_MarkerDrawer::~GLViewer_MarkerDrawer()
67 /*! Draws object in GLViewer
68 \param xScale - current scale along X-direction
69 \param yScale - current scale along Y-direction
70 \param onlyUpdate - = true if only update highlight-select information
72 void GLViewer_MarkerDrawer::create( float xScale, float yScale, bool onlyUpdate )
74 QList<int>::Iterator it;
75 QList<int>::Iterator EndIt;
76 QList<GLViewer_Object*>::Iterator anObjectIt = myObjects.begin();
77 QList<GLViewer_Object*>::Iterator anEndObjectIt = myObjects.end();
82 QColor colorN, colorH, colorS;
84 GLViewer_MarkerSet* aMarkerSet = NULL;
85 GLViewer_AspectLine* anAspectLine = NULL;
87 for( ; anObjectIt != anEndObjectIt; anObjectIt++ )
89 aMarkerSet = ( GLViewer_MarkerSet* )(*anObjectIt);
90 anAspectLine = aMarkerSet->getAspectLine();
91 anAspectLine->getLineColors( colorN, colorH, colorS );
93 float* aXCoord = aMarkerSet->getXCoord();
94 float* anYCoord = aMarkerSet->getYCoord();
95 float aRadius = aMarkerSet->getMarkerSize();
97 QList<int> aHNumbers, anUHNumbers, aSelNumbers, anUSelNumbers;
98 aMarkerSet->exportNumbers( aHNumbers, anUHNumbers, aSelNumbers, anUSelNumbers );
102 EndIt = anUHNumbers.end();
103 for( it = anUHNumbers.begin(); it != EndIt; ++it )
105 drawMarker( aXCoord[*it], anYCoord[*it], aRadius, colorN, anAspectLine );
108 EndIt = anUSelNumbers.end();
109 for( it = anUSelNumbers.begin(); it != EndIt; ++it )
110 drawMarker( aXCoord[*it], anYCoord[*it], aRadius, colorN, anAspectLine );
112 EndIt = aSelNumbers.end();
113 for( it = aSelNumbers.begin(); it != EndIt; ++it )
114 drawMarker( aXCoord[*it], anYCoord[*it], aRadius, colorS, anAspectLine );
116 EndIt = aHNumbers.end();
117 for( it = aHNumbers.begin(); it != EndIt; ++it )
119 drawMarker( aXCoord[*it], anYCoord[*it], aRadius, colorH, anAspectLine );
124 int aNumber = aMarkerSet->getNumMarkers();
125 for( int i = 0; i < aNumber; i++ )
126 drawMarker( aXCoord[i], anYCoord[i], aRadius, colorN, anAspectLine );
128 EndIt = anUSelNumbers.end();
129 for( it = anUSelNumbers.begin(); it != EndIt; ++it )
130 drawMarker( aXCoord[*it], anYCoord[*it], aRadius, colorN, anAspectLine );
132 EndIt = aSelNumbers.end();
133 for( it = aSelNumbers.begin(); it != EndIt; ++it )
134 drawMarker( aXCoord[*it], anYCoord[*it], aRadius, colorS, anAspectLine );
136 if( aMarkerSet->getGLText()->getText() != "" )
138 //float aXPos = 0, anYPos = 0;
139 //aMarkerSet->getGLText()->getPosition( aXPos, anYPos );
140 //drawText( aMarkerSet->getGLText()->getText(), aXPos, anYPos, colorN, &aMarkerSet->getGLText()->getFont(), aMarkerSet->getGLText()->getSeparator() );
141 drawText( aMarkerSet );
147 \param theXCoord - X position
148 \param theYCoord - Y position
149 \param theRadius - radius
150 \param theColor - color
151 \param theAspectLine - line aspect
153 void GLViewer_MarkerDrawer::drawMarker( float& theXCoord, float& theYCoord,
154 float& theRadius, QColor& theColor, GLViewer_AspectLine* theAspectLine )
156 glColor3f( ( GLfloat )theColor.red() / 255,
157 ( GLfloat )theColor.green() / 255,
158 ( GLfloat )theColor.blue() / 255 );
160 glLineWidth( theAspectLine->getLineWidth() );
162 if ( theAspectLine->getLineType() == 0 )
163 glBegin( GL_LINE_LOOP );
165 glBegin( GL_LINE_STRIP);
167 for ( int i = 0; i < SEGMENTS; i++ )
168 glVertex2f( theXCoord + cos_table[i] * theRadius / myXScale,
169 theYCoord + sin_table[i] * theRadius / myYScale );
177 GLViewer_PolylineDrawer::GLViewer_PolylineDrawer()
180 myObjectType = "GLViewer_Polyline";
186 GLViewer_PolylineDrawer::~GLViewer_PolylineDrawer()
190 /*! Draws object in GLViewer
191 \param xScale - current scale along X-direction
192 \param yScale - current scale along Y-direction
193 \param onlyUpdate - = true if only update highlight-select information
195 void GLViewer_PolylineDrawer::create( float xScale, float yScale, bool onlyUpdate )
197 QList<GLViewer_Object*>::Iterator aObjectIt = myObjects.begin();
198 QList<GLViewer_Object*>::Iterator aObjectEndIt = myObjects.end();
203 QColor color, colorN, colorH, colorS;
204 GLViewer_AspectLine* anAspect = NULL;
205 GLViewer_Polyline* aPolyline = NULL;
206 for( ; aObjectIt != aObjectEndIt; aObjectIt++ )
208 anAspect = (*aObjectIt)->getAspectLine();
209 aPolyline = (GLViewer_Polyline*)(*aObjectIt);
212 anAspect->getLineColors( colorN, colorH, colorS );
215 if( aPolyline->isHighlighted() )
217 else if( aPolyline->isSelected() )
224 if( aPolyline->isSelected() )
230 float* aXCoord = aPolyline->getXCoord();
231 float* anYCoord = aPolyline->getYCoord();
232 int aSize = aPolyline->getNumber();
234 glColor3f( ( GLfloat )color.red() / 255,
235 ( GLfloat )color.green() / 255,
236 ( GLfloat )color.blue() / 255 );
238 glLineWidth( anAspect->getLineWidth() );
240 if ( anAspect->getLineType() == 0 )
241 glBegin( GL_LINE_LOOP );
243 glBegin( GL_LINE_STRIP);
245 for( int i = 0; i < aSize ; i++ )
246 glVertex2f( aXCoord[ i ], anYCoord[ i ] );
248 if( aPolyline->isClosed() )
249 glVertex2f( aXCoord[ 0 ], anYCoord[ 0 ] );
253 if( aPolyline->getGLText()->getText() != "" )
255 //float aXPos = 0, anYPos = 0;
256 //aPolyline->getGLText()->getPosition( aXPos, anYPos );
257 //drawText( aPolyline->getGLText()->getText(), aXPos, anYPos, color, &aPolyline->getGLText()->getFont(), aPolyline->getGLText()->getSeparator() );
258 drawText( aPolyline );
266 GLViewer_TextDrawer::GLViewer_TextDrawer()
269 myObjectType = "GLViewer_TextObject";
275 GLViewer_TextDrawer::~GLViewer_TextDrawer()
279 /*! Draws object in GLViewer
280 \param xScale - current scale along X-direction
281 \param yScale - current scale along Y-direction
282 \param onlyUpdate - = true if only update highlight-select information
284 void GLViewer_TextDrawer::create( float xScale, float yScale, bool onlyUpdate )
286 QList<GLViewer_Object*>::Iterator aObjectIt = myObjects.begin();
287 QList<GLViewer_Object*>::Iterator aObjectEndIt = myObjects.end();
292 QColor color, colorN, colorH, colorS;
293 GLViewer_AspectLine* anAspect = NULL;
294 GLViewer_TextObject* anObject = NULL;
295 //float aXPos = 0, anYPos = 0;
296 for( ; aObjectIt != aObjectEndIt; aObjectIt++ )
298 anObject = (GLViewer_TextObject*)(*aObjectIt);
299 anAspect = anObject->getAspectLine();
301 anAspect->getLineColors( colorN, colorH, colorS );
304 if( anObject->isHighlighted() )
306 else if( anObject->isSelected() )
313 if( anObject->isSelected() )
319 //anObject->getGLText()->getPosition( aXPos, anYPos );
320 //drawText( anObject->getGLText()->getText(), aXPos, anYPos, color, &(anObject->getGLText()->getFont()), anObject->getGLText()->getSeparator() );
321 drawText( anObject );
326 Updates objects after updating font
328 void GLViewer_TextDrawer::updateObjects()
330 QList<GLViewer_Object*>::Iterator aObjectIt = myObjects.begin();
331 QList<GLViewer_Object*>::Iterator aObjectEndIt = myObjects.end();
332 for( ; aObjectIt != aObjectEndIt; aObjectIt++ )
333 (*aObjectIt)->compute();