1 // File: GLViewer_BaseDrawers.cxx
2 // Created: November, 2004
4 // Copyright (C) CEA 2004
6 //#include <GLViewerAfx.h>
7 #include "GLViewer_BaseDrawers.h"
8 #include "GLViewer_Object.h"
9 #include "GLViewer_Text.h"
10 #include "GLViewer_AspectLine.h"
11 #include "GLViewer_BaseObjects.h"
17 /***************************************************************************
18 ** Class: GLViewer_MarkerDrawer
19 ** Descr: Drawer for GLViewer_MarkerSet
21 ** Created: UI team, 03.10.01
22 ****************************************************************************/
24 GLfloat sin_table[SEGMENTS];
25 GLfloat cos_table[SEGMENTS];
27 GLViewer_MarkerDrawer::GLViewer_MarkerDrawer()
31 for ( int i = 0; i < SEGMENTS; i++ )
33 sin_table[i] = sin( angle );
34 cos_table[i] = cos( angle );
35 angle += float( STEP );
37 myObjectType = "GLViewer_MarkerSet";
40 GLViewer_MarkerDrawer::~GLViewer_MarkerDrawer()
44 void GLViewer_MarkerDrawer::create( float xScale, float yScale, bool onlyUpdate )
46 QValueList<int>::Iterator it;
47 QValueList<int>::Iterator EndIt;
48 QValueList<GLViewer_Object*>::Iterator anObjectIt = myObjects.begin();
49 QValueList<GLViewer_Object*>::Iterator anEndObjectIt = myObjects.end();
54 QColor colorN, colorH, colorS;
56 GLViewer_MarkerSet* aMarkerSet = NULL;
57 GLViewer_AspectLine* anAspectLine = NULL;
59 for( ; anObjectIt != anEndObjectIt; anObjectIt++ )
61 aMarkerSet = ( GLViewer_MarkerSet* )(*anObjectIt);
62 anAspectLine = aMarkerSet->getAspectLine();
63 anAspectLine->getLineColors( colorN, colorH, colorS );
65 float* aXCoord = aMarkerSet->getXCoord();
66 float* anYCoord = aMarkerSet->getYCoord();
67 float aRadius = aMarkerSet->getMarkerSize();
69 QValueList<int> aHNumbers, anUHNumbers, aSelNumbers, anUSelNumbers;
70 aMarkerSet->exportNumbers( aHNumbers, anUHNumbers, aSelNumbers, anUSelNumbers );
74 EndIt = anUHNumbers.end();
75 for( it = anUHNumbers.begin(); it != EndIt; ++it )
77 drawMarker( aXCoord[*it], anYCoord[*it], aRadius, colorN, anAspectLine );
80 EndIt = anUSelNumbers.end();
81 for( it = anUSelNumbers.begin(); it != EndIt; ++it )
82 drawMarker( aXCoord[*it], anYCoord[*it], aRadius, colorN, anAspectLine );
84 EndIt = aSelNumbers.end();
85 for( it = aSelNumbers.begin(); it != EndIt; ++it )
86 drawMarker( aXCoord[*it], anYCoord[*it], aRadius, colorS, anAspectLine );
88 EndIt = aHNumbers.end();
89 for( it = aHNumbers.begin(); it != EndIt; ++it )
91 drawMarker( aXCoord[*it], anYCoord[*it], aRadius, colorH, anAspectLine );
96 int aNumber = aMarkerSet->getNumMarkers();
97 for( int i = 0; i < aNumber; i++ )
98 drawMarker( aXCoord[i], anYCoord[i], aRadius, colorN, anAspectLine );
100 EndIt = anUSelNumbers.end();
101 for( it = anUSelNumbers.begin(); it != EndIt; ++it )
102 drawMarker( aXCoord[*it], anYCoord[*it], aRadius, colorN, anAspectLine );
104 EndIt = aSelNumbers.end();
105 for( it = aSelNumbers.begin(); it != EndIt; ++it )
106 drawMarker( aXCoord[*it], anYCoord[*it], aRadius, colorS, anAspectLine );
108 if( aMarkerSet->getGLText()->getText() != "" )
110 //float aXPos = 0, anYPos = 0;
111 //aMarkerSet->getGLText()->getPosition( aXPos, anYPos );
112 //drawText( aMarkerSet->getGLText()->getText(), aXPos, anYPos, colorN, &aMarkerSet->getGLText()->getFont(), aMarkerSet->getGLText()->getSeparator() );
113 drawText( aMarkerSet );
118 void GLViewer_MarkerDrawer::drawMarker( float& theXCoord, float& theYCoord,
119 float& theRadius, QColor& theColor, GLViewer_AspectLine* theAspectLine )
121 glColor3f( ( GLfloat )theColor.red() / 255,
122 ( GLfloat )theColor.green() / 255,
123 ( GLfloat )theColor.blue() / 255 );
125 glLineWidth( theAspectLine->getLineWidth() );
127 if ( theAspectLine->getLineType() == 0 )
128 glBegin( GL_LINE_LOOP );
130 glBegin( GL_LINE_STRIP);
132 for ( int i = 0; i < SEGMENTS; i++ )
133 glVertex2f( theXCoord + cos_table[i] * theRadius / myXScale,
134 theYCoord + sin_table[i] * theRadius / myYScale );
138 /***************************************************************************
139 ** Class: GLViewer_PolylineDrawer
140 ** Descr: Drawer for GLViewer_Polyline
142 ** Created: UI team, 03.10.01
143 ****************************************************************************/
145 GLViewer_PolylineDrawer::GLViewer_PolylineDrawer()
148 myObjectType = "GLViewer_Polyline";
151 GLViewer_PolylineDrawer::~GLViewer_PolylineDrawer()
155 void GLViewer_PolylineDrawer::create( float xScale, float yScale, bool onlyUpdate )
157 QValueList<GLViewer_Object*>::Iterator aObjectIt = myObjects.begin();
158 QValueList<GLViewer_Object*>::Iterator aObjectEndIt = myObjects.end();
163 QColor color, colorN, colorH, colorS;
164 GLViewer_AspectLine* anAspect = NULL;
165 GLViewer_Polyline* aPolyline = NULL;
166 for( ; aObjectIt != aObjectEndIt; aObjectIt++ )
168 anAspect = (*aObjectIt)->getAspectLine();
169 aPolyline = (GLViewer_Polyline*)(*aObjectIt);
172 anAspect->getLineColors( colorN, colorH, colorS );
175 if( aPolyline->isHighlighted() )
177 else if( aPolyline->isSelected() )
184 if( aPolyline->isSelected() )
190 float* aXCoord = aPolyline->getXCoord();
191 float* anYCoord = aPolyline->getYCoord();
192 int aSize = aPolyline->getNumber();
194 glColor3f( ( GLfloat )color.red() / 255,
195 ( GLfloat )color.green() / 255,
196 ( GLfloat )color.blue() / 255 );
198 glLineWidth( anAspect->getLineWidth() );
200 if ( anAspect->getLineType() == 0 )
201 glBegin( GL_LINE_LOOP );
203 glBegin( GL_LINE_STRIP);
205 for( int i = 0; i < aSize ; i++ )
206 glVertex2f( aXCoord[ i ], anYCoord[ i ] );
208 if( aPolyline->isClosed() )
209 glVertex2f( aXCoord[ 0 ], anYCoord[ 0 ] );
213 if( aPolyline->getGLText()->getText() != "" )
215 //float aXPos = 0, anYPos = 0;
216 //aPolyline->getGLText()->getPosition( aXPos, anYPos );
217 //drawText( aPolyline->getGLText()->getText(), aXPos, anYPos, color, &aPolyline->getGLText()->getFont(), aPolyline->getGLText()->getSeparator() );
218 drawText( aPolyline );
223 /***************************************************************************
224 ** Class: GLViewer_TextDrawer
227 ** Created: UI team, 27.02.04
228 ****************************************************************************/
230 GLViewer_TextDrawer::GLViewer_TextDrawer()
233 myObjectType = "GLViewer_TextObject";
236 GLViewer_TextDrawer::~GLViewer_TextDrawer()
240 void GLViewer_TextDrawer::create( float xScale, float yScale, bool onlyUpdate )
242 QValueList<GLViewer_Object*>::Iterator aObjectIt = myObjects.begin();
243 QValueList<GLViewer_Object*>::Iterator aObjectEndIt = myObjects.end();
248 QColor color, colorN, colorH, colorS;
249 GLViewer_AspectLine* anAspect = NULL;
250 GLViewer_TextObject* anObject = NULL;
251 //float aXPos = 0, anYPos = 0;
252 for( ; aObjectIt != aObjectEndIt; aObjectIt++ )
254 anObject = (GLViewer_TextObject*)(*aObjectIt);
255 anAspect = anObject->getAspectLine();
257 anAspect->getLineColors( colorN, colorH, colorS );
260 if( anObject->isHighlighted() )
262 else if( anObject->isSelected() )
269 if( anObject->isSelected() )
275 //anObject->getGLText()->getPosition( aXPos, anYPos );
276 //drawText( anObject->getGLText()->getText(), aXPos, anYPos, color, &(anObject->getGLText()->getFont()), anObject->getGLText()->getSeparator() );
277 drawText( anObject );
281 void GLViewer_TextDrawer::updateObjects()
283 QValueList<GLViewer_Object*>::Iterator aObjectIt = myObjects.begin();
284 QValueList<GLViewer_Object*>::Iterator aObjectEndIt = myObjects.end();
285 for( ; aObjectIt != aObjectEndIt; aObjectIt++ )
286 (*aObjectIt)->compute();