1 // Copyright (C) 2007-2013 CEA/DEN, EDF R&D, 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.salome-platform.org/ or email : webmaster.salome@opencascade.com
26 #include "OCCViewer_Trihedron.h"
29 #include <SUIT_ResourceMgr.h>
30 #include <SUIT_Session.h>
32 #include <Graphic3d_AspectFillArea3d.hxx>
33 #include <Graphic3d_Group.hxx>
34 #include <Graphic3d_MaterialAspect.hxx>
35 #include <Prs3d_Presentation.hxx>
36 #include <Prs3d_Root.hxx>
37 #include <PrsMgr_PresentationManager3d.hxx>
46 #define PI 3.14159265359
48 IMPLEMENT_STANDARD_HANDLE( OCCViewer_Trihedron, AIS_InteractiveObject )
49 IMPLEMENT_STANDARD_RTTIEXT( OCCViewer_Trihedron, AIS_InteractiveObject )
54 OCCViewer_Trihedron::OCCViewer_Trihedron( const PrsMgr_TypeOfPresentation3d t )
55 : AIS_InteractiveObject( t ),
63 OCCViewer_Trihedron::~OCCViewer_Trihedron()
66 glDeleteLists( myTextList, 256 );
70 * Sets the bounding box (MinMax values).
72 void OCCViewer_Trihedron::bounds( Graphic3d_CBounds& aMinMax ) const
74 Standard_Real aXMin = -1, aYMin = -1, aZMin = -1;
75 Standard_Real aXMax = 1, aYMax = 1, aZMax = 1;
77 if( aMinMax.XMin > aXMin ) aMinMax.XMin = aXMin;
78 if( aMinMax.YMin > aYMin ) aMinMax.YMin = aYMin;
79 if( aMinMax.ZMin > aZMin ) aMinMax.ZMin = aZMin;
80 if( aMinMax.XMax < aXMax ) aMinMax.XMax = aXMax;
81 if( aMinMax.YMax < aYMax ) aMinMax.YMax = aYMax;
82 if( aMinMax.ZMax < aZMax ) aMinMax.ZMax = aZMax;
86 * Redefined method. Calculates the object presentation.
88 void OCCViewer_Trihedron::Compute( const Handle( PrsMgr_PresentationManager3d )&,
89 const Handle( Prs3d_Presentation )& aPrs,
90 const Standard_Integer aMode )
95 Handle( Graphic3d_Group ) aGroup = Prs3d_Root::CurrentGroup( aPrs );
96 aGroup->UserDraw( this );
100 * Redefined method. Does nothing.
102 void OCCViewer_Trihedron::ComputeSelection( const Handle( SelectMgr_Selection )& theSelection,
103 const Standard_Integer theMode )
108 * Generates text list.
110 GLuint generateTextList()
113 GLuint aList = glGenLists( 256 );
116 HGLRC hglrc = wglGetCurrentContext();
119 HDC hdc = ::wglGetCurrentDC();
120 HFONT font = CreateFont( -12, 0, 0, 0,
127 FF_DONTCARE | DEFAULT_PITCH,
129 HFONT oldFont = (HFONT)SelectObject( hdc, font );
131 ok = ::wglUseFontBitmaps( hdc, 0, 256, aList );
132 SelectObject( hdc, oldFont );
133 DeleteObject( font );
136 Display* dpy = glXGetCurrentDisplay();
140 char** aFontList = XListFonts( dpy, "*-courier-*", 1, &aFontCount );
143 //XFontStruct* fontInfo = XLoadQueryFont( dpy, "-*-courier-*-r-*-*-14-*-*-*-m-*-*-*" );
144 Font aFont = XLoadFont( dpy, aFontList[0] );
145 glXUseXFont( aFont, 0, 256, aList );
146 XUnloadFont( dpy, aFont );
149 XFreeFontNames( aFontList );
154 glDeleteLists( aList, 256 );
162 void drawText( GLuint theTextList, const char* theText, GLdouble thePosition[3], GLfloat theColor[3] )
164 glColor3fv( theColor );
165 glRasterPos3dv( thePosition );
166 glListBase( theTextList );
167 glCallLists( strlen( theText ), GL_UNSIGNED_BYTE, (GLubyte*)theText );
171 * Displays trihedron.
173 void OCCViewer_Trihedron::display()
175 GLdouble TriedronOrigin[3] = { 0.0, 0.0, 0.0 };
177 GLdouble TriedronAxeX[3] = { 1.0, 0.0, 0.0 };
178 GLdouble TriedronAxeY[3] = { 0.0, 1.0, 0.0 };
179 GLdouble TriedronAxeZ[3] = { 0.0, 0.0, 1.0 };
181 GLfloat TriedronColorX[3] = { 1.0, 0.0, 0.0 };
182 GLfloat TriedronColorY[3] = { 0.0, 1.0, 0.0 };
183 GLfloat TriedronColorZ[3] = { 0.0, 0.0, 1.0 };
185 GLfloat TriedronLetterColorX[3] = { 1.0, 1.0, 1.0 };
186 GLfloat TriedronLetterColorY[3] = { 1.0, 1.0, 1.0 };
187 GLfloat TriedronLetterColorZ[3] = { 1.0, 1.0, 1.0 };
189 GLfloat TriedronLineWidth = 2.0;
190 GLdouble TriedronScale = 0.15;
192 GLdouble U, V, minUV;
194 glGetIntegerv(GL_VIEWPORT, aViewPort);
203 GLdouble L = minUV * TriedronScale;
205 TriedronOrigin[0]= 0.0;
206 TriedronOrigin[1]= 0.0;
207 TriedronOrigin[2]= 0.0;
209 TriedronAxeX[0] = TriedronOrigin[0] + L;
210 TriedronAxeX[1] = TriedronOrigin[1] + 0.0;
211 TriedronAxeX[2] = TriedronOrigin[2] + 0.0;
213 TriedronAxeY[0] = TriedronOrigin[0] + 0.0;
214 TriedronAxeY[1] = TriedronOrigin[1] + L;
215 TriedronAxeY[2] = TriedronOrigin[2] + 0.0;
217 TriedronAxeZ[0] = TriedronOrigin[0] + 0.0;
218 TriedronAxeZ[1] = TriedronOrigin[1] + 0.0;
219 TriedronAxeZ[2] = TriedronOrigin[2] + L;
221 glPushAttrib( GL_CURRENT_BIT | GL_ENABLE_BIT | GL_LIGHTING_BIT | GL_LINE_BIT | GL_VIEWPORT_BIT );
223 glDepthRange( 0, 0 );
224 glDisable( GL_LIGHTING );
225 glDisable( GL_COLOR_MATERIAL );
226 for( int i = 0; i < GL_MAX_CLIP_PLANES; i++ )
227 glDisable( GL_CLIP_PLANE0 + i );
229 glLineWidth( TriedronLineWidth );
231 glColor3fv( TriedronColorX );
233 glVertex3dv( TriedronOrigin );
234 glVertex3dv( TriedronAxeX );
237 glColor3fv( TriedronColorY );
239 glVertex3dv( TriedronOrigin );
240 glVertex3dv( TriedronAxeY );
243 glColor3fv( TriedronColorZ );
245 glVertex3dv( TriedronOrigin );
246 glVertex3dv( TriedronAxeZ );
249 GLdouble l = L - L/4.;
250 GLdouble rayon = L/20.;
251 GLint ii, NbFacettes = 12;
252 GLdouble Angle = 2. * PI / NbFacettes;
253 GLdouble TriedronCoord[3] = { 1.0, 0.0, 0.0 };
255 if( myTextList == 0 )
256 myTextList = generateTextList();
258 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
260 glColor3fv( TriedronColorX );
261 glBegin( GL_TRIANGLE_FAN );
262 glVertex3dv( TriedronAxeX );
263 TriedronCoord[0] = TriedronOrigin[0] + l ;
266 TriedronCoord[1] = TriedronOrigin[1] + ( rayon * sin(ii * Angle) );
267 TriedronCoord[2] = TriedronOrigin[2] + ( rayon * cos(ii * Angle) );
268 glVertex3dv( TriedronCoord );
273 drawText( myTextList, "X", TriedronAxeX, TriedronLetterColorX );
275 glColor3fv( TriedronColorY );
276 glBegin( GL_TRIANGLE_FAN );
277 glVertex3dv( TriedronAxeY );
278 TriedronCoord[1] = TriedronOrigin[1] + l ;
281 TriedronCoord[0] = TriedronOrigin[0] + (rayon * cos(ii * Angle) );
282 TriedronCoord[2] = TriedronOrigin[2] + (rayon * sin(ii * Angle) );
283 glVertex3dv( TriedronCoord );
288 drawText( myTextList, "Y", TriedronAxeY, TriedronLetterColorY );
290 glColor3fv( TriedronColorZ );
291 glBegin( GL_TRIANGLE_FAN );
292 glVertex3dv( TriedronAxeZ );
293 TriedronCoord[2] = TriedronOrigin[2] + l ;
296 TriedronCoord[0] = TriedronOrigin[0] + ( rayon * sin(ii * Angle) );
297 TriedronCoord[1] = TriedronOrigin[1] + ( rayon * cos(ii * Angle) );
298 glVertex3dv( TriedronCoord );
303 drawText( myTextList, "Z", TriedronAxeZ, TriedronLetterColorZ );