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 /***************************************************************************
37 ** Class: GLViewer_MarkerDrawer
38 ** Descr: Drawer for GLViewer_MarkerSet
40 ** Created: UI team, 03.10.01
41 ****************************************************************************/
43 GLfloat sin_table[SEGMENTS];
44 GLfloat cos_table[SEGMENTS];
46 GLViewer_MarkerDrawer::GLViewer_MarkerDrawer()
50 for ( int i = 0; i < SEGMENTS; i++ )
52 sin_table[i] = sin( angle );
53 cos_table[i] = cos( angle );
54 angle += float( STEP );
56 myObjectType = "GLViewer_MarkerSet";
59 GLViewer_MarkerDrawer::~GLViewer_MarkerDrawer()
63 void GLViewer_MarkerDrawer::create( float xScale, float yScale, bool onlyUpdate )
65 QValueList<int>::Iterator it;
66 QValueList<int>::Iterator EndIt;
67 QValueList<GLViewer_Object*>::Iterator anObjectIt = myObjects.begin();
68 QValueList<GLViewer_Object*>::Iterator anEndObjectIt = myObjects.end();
73 QColor colorN, colorH, colorS;
75 GLViewer_MarkerSet* aMarkerSet = NULL;
76 GLViewer_AspectLine* anAspectLine = NULL;
78 for( ; anObjectIt != anEndObjectIt; anObjectIt++ )
80 aMarkerSet = ( GLViewer_MarkerSet* )(*anObjectIt);
81 anAspectLine = aMarkerSet->getAspectLine();
82 anAspectLine->getLineColors( colorN, colorH, colorS );
84 float* aXCoord = aMarkerSet->getXCoord();
85 float* anYCoord = aMarkerSet->getYCoord();
86 float aRadius = aMarkerSet->getMarkerSize();
88 QValueList<int> aHNumbers, anUHNumbers, aSelNumbers, anUSelNumbers;
89 aMarkerSet->exportNumbers( aHNumbers, anUHNumbers, aSelNumbers, anUSelNumbers );
93 EndIt = anUHNumbers.end();
94 for( it = anUHNumbers.begin(); it != EndIt; ++it )
96 drawMarker( aXCoord[*it], anYCoord[*it], aRadius, colorN, anAspectLine );
99 EndIt = anUSelNumbers.end();
100 for( it = anUSelNumbers.begin(); it != EndIt; ++it )
101 drawMarker( aXCoord[*it], anYCoord[*it], aRadius, colorN, anAspectLine );
103 EndIt = aSelNumbers.end();
104 for( it = aSelNumbers.begin(); it != EndIt; ++it )
105 drawMarker( aXCoord[*it], anYCoord[*it], aRadius, colorS, anAspectLine );
107 EndIt = aHNumbers.end();
108 for( it = aHNumbers.begin(); it != EndIt; ++it )
110 drawMarker( aXCoord[*it], anYCoord[*it], aRadius, colorH, anAspectLine );
115 int aNumber = aMarkerSet->getNumMarkers();
116 for( int i = 0; i < aNumber; i++ )
117 drawMarker( aXCoord[i], anYCoord[i], aRadius, colorN, anAspectLine );
119 EndIt = anUSelNumbers.end();
120 for( it = anUSelNumbers.begin(); it != EndIt; ++it )
121 drawMarker( aXCoord[*it], anYCoord[*it], aRadius, colorN, anAspectLine );
123 EndIt = aSelNumbers.end();
124 for( it = aSelNumbers.begin(); it != EndIt; ++it )
125 drawMarker( aXCoord[*it], anYCoord[*it], aRadius, colorS, anAspectLine );
127 if( aMarkerSet->getGLText()->getText() != "" )
129 //float aXPos = 0, anYPos = 0;
130 //aMarkerSet->getGLText()->getPosition( aXPos, anYPos );
131 //drawText( aMarkerSet->getGLText()->getText(), aXPos, anYPos, colorN, &aMarkerSet->getGLText()->getFont(), aMarkerSet->getGLText()->getSeparator() );
132 drawText( aMarkerSet );
137 void GLViewer_MarkerDrawer::drawMarker( float& theXCoord, float& theYCoord,
138 float& theRadius, QColor& theColor, GLViewer_AspectLine* theAspectLine )
140 glColor3f( ( GLfloat )theColor.red() / 255,
141 ( GLfloat )theColor.green() / 255,
142 ( GLfloat )theColor.blue() / 255 );
144 glLineWidth( theAspectLine->getLineWidth() );
146 if ( theAspectLine->getLineType() == 0 )
147 glBegin( GL_LINE_LOOP );
149 glBegin( GL_LINE_STRIP);
151 for ( int i = 0; i < SEGMENTS; i++ )
152 glVertex2f( theXCoord + cos_table[i] * theRadius / myXScale,
153 theYCoord + sin_table[i] * theRadius / myYScale );
157 /***************************************************************************
158 ** Class: GLViewer_PolylineDrawer
159 ** Descr: Drawer for GLViewer_Polyline
161 ** Created: UI team, 03.10.01
162 ****************************************************************************/
164 GLViewer_PolylineDrawer::GLViewer_PolylineDrawer()
167 myObjectType = "GLViewer_Polyline";
170 GLViewer_PolylineDrawer::~GLViewer_PolylineDrawer()
174 void GLViewer_PolylineDrawer::create( float xScale, float yScale, bool onlyUpdate )
176 QValueList<GLViewer_Object*>::Iterator aObjectIt = myObjects.begin();
177 QValueList<GLViewer_Object*>::Iterator aObjectEndIt = myObjects.end();
182 QColor color, colorN, colorH, colorS;
183 GLViewer_AspectLine* anAspect = NULL;
184 GLViewer_Polyline* aPolyline = NULL;
185 for( ; aObjectIt != aObjectEndIt; aObjectIt++ )
187 anAspect = (*aObjectIt)->getAspectLine();
188 aPolyline = (GLViewer_Polyline*)(*aObjectIt);
191 anAspect->getLineColors( colorN, colorH, colorS );
194 if( aPolyline->isHighlighted() )
196 else if( aPolyline->isSelected() )
203 if( aPolyline->isSelected() )
209 float* aXCoord = aPolyline->getXCoord();
210 float* anYCoord = aPolyline->getYCoord();
211 int aSize = aPolyline->getNumber();
213 glColor3f( ( GLfloat )color.red() / 255,
214 ( GLfloat )color.green() / 255,
215 ( GLfloat )color.blue() / 255 );
217 glLineWidth( anAspect->getLineWidth() );
219 if ( anAspect->getLineType() == 0 )
220 glBegin( GL_LINE_LOOP );
222 glBegin( GL_LINE_STRIP);
224 for( int i = 0; i < aSize ; i++ )
225 glVertex2f( aXCoord[ i ], anYCoord[ i ] );
227 if( aPolyline->isClosed() )
228 glVertex2f( aXCoord[ 0 ], anYCoord[ 0 ] );
232 if( aPolyline->getGLText()->getText() != "" )
234 //float aXPos = 0, anYPos = 0;
235 //aPolyline->getGLText()->getPosition( aXPos, anYPos );
236 //drawText( aPolyline->getGLText()->getText(), aXPos, anYPos, color, &aPolyline->getGLText()->getFont(), aPolyline->getGLText()->getSeparator() );
237 drawText( aPolyline );
242 /***************************************************************************
243 ** Class: GLViewer_TextDrawer
246 ** Created: UI team, 27.02.04
247 ****************************************************************************/
249 GLViewer_TextDrawer::GLViewer_TextDrawer()
252 myObjectType = "GLViewer_TextObject";
255 GLViewer_TextDrawer::~GLViewer_TextDrawer()
259 void GLViewer_TextDrawer::create( float xScale, float yScale, bool onlyUpdate )
261 QValueList<GLViewer_Object*>::Iterator aObjectIt = myObjects.begin();
262 QValueList<GLViewer_Object*>::Iterator aObjectEndIt = myObjects.end();
267 QColor color, colorN, colorH, colorS;
268 GLViewer_AspectLine* anAspect = NULL;
269 GLViewer_TextObject* anObject = NULL;
270 //float aXPos = 0, anYPos = 0;
271 for( ; aObjectIt != aObjectEndIt; aObjectIt++ )
273 anObject = (GLViewer_TextObject*)(*aObjectIt);
274 anAspect = anObject->getAspectLine();
276 anAspect->getLineColors( colorN, colorH, colorS );
279 if( anObject->isHighlighted() )
281 else if( anObject->isSelected() )
288 if( anObject->isSelected() )
294 //anObject->getGLText()->getPosition( aXPos, anYPos );
295 //drawText( anObject->getGLText()->getText(), aXPos, anYPos, color, &(anObject->getGLText()->getFont()), anObject->getGLText()->getSeparator() );
296 drawText( anObject );
300 void GLViewer_TextDrawer::updateObjects()
302 QValueList<GLViewer_Object*>::Iterator aObjectIt = myObjects.begin();
303 QValueList<GLViewer_Object*>::Iterator aObjectEndIt = myObjects.end();
304 for( ; aObjectIt != aObjectEndIt; aObjectIt++ )
305 (*aObjectIt)->compute();