1 // Copyright (C) 2007-2016 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, or (at your option) any later version.
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 #if OCC_VERSION_LARGE > 0x06070100 // for OCC-6.7.2 and higher version
73 void OCCViewer_Trihedron::bounds( Graphic3d_BndBox4f& theMinMax ) const
75 Graphic3d_Vec4 aMinPt (-1.f, -1.f, -1.f, 1.f);
76 Graphic3d_Vec4 aMaxPt (1.f, 1.f, 1.f, 1.f);
78 theMinMax.Add (aMinPt);
79 theMinMax.Add (aMaxPt);
82 void OCCViewer_Trihedron::bounds( Graphic3d_CBounds& aMinMax ) const
84 Standard_Real aXMin = -1, aYMin = -1, aZMin = -1;
85 Standard_Real aXMax = 1, aYMax = 1, aZMax = 1;
87 if( aMinMax.XMin > aXMin ) aMinMax.XMin = aXMin;
88 if( aMinMax.YMin > aYMin ) aMinMax.YMin = aYMin;
89 if( aMinMax.ZMin > aZMin ) aMinMax.ZMin = aZMin;
90 if( aMinMax.XMax < aXMax ) aMinMax.XMax = aXMax;
91 if( aMinMax.YMax < aYMax ) aMinMax.YMax = aYMax;
92 if( aMinMax.ZMax < aZMax ) aMinMax.ZMax = aZMax;
97 * Redefined method. Calculates the object presentation.
99 void OCCViewer_Trihedron::Compute( const Handle( PrsMgr_PresentationManager3d )&,
100 const Handle( Prs3d_Presentation )& aPrs,
101 const Standard_Integer aMode )
106 Handle( Graphic3d_Group ) aGroup = Prs3d_Root::CurrentGroup( aPrs );
107 aGroup->UserDraw( this );
111 * Redefined method. Does nothing.
113 void OCCViewer_Trihedron::ComputeSelection( const Handle( SelectMgr_Selection )& theSelection,
114 const Standard_Integer theMode )
119 * Generates text list.
121 GLuint generateTextList()
124 GLuint aList = glGenLists( 256 );
127 HGLRC hglrc = wglGetCurrentContext();
130 HDC hdc = ::wglGetCurrentDC();
131 HFONT font = CreateFont( -12, 0, 0, 0,
138 FF_DONTCARE | DEFAULT_PITCH,
140 HFONT oldFont = (HFONT)SelectObject( hdc, font );
142 ok = ::wglUseFontBitmaps( hdc, 0, 256, aList );
143 SelectObject( hdc, oldFont );
144 DeleteObject( font );
147 Display* dpy = glXGetCurrentDisplay();
151 char** aFontList = XListFonts( dpy, "*-courier-*", 1, &aFontCount );
154 //XFontStruct* fontInfo = XLoadQueryFont( dpy, "-*-courier-*-r-*-*-14-*-*-*-m-*-*-*" );
155 Font aFont = XLoadFont( dpy, aFontList[0] );
156 glXUseXFont( aFont, 0, 256, aList );
157 XUnloadFont( dpy, aFont );
160 XFreeFontNames( aFontList );
165 glDeleteLists( aList, 256 );
173 void drawText( GLuint theTextList, const char* theText, GLdouble thePosition[3], GLfloat theColor[3] )
175 glColor3fv( theColor );
176 glRasterPos3dv( thePosition );
177 glListBase( theTextList );
178 glCallLists( strlen( theText ), GL_UNSIGNED_BYTE, (GLubyte*)theText );
182 * Displays trihedron.
184 void OCCViewer_Trihedron::display()
186 GLdouble TriedronOrigin[3] = { 0.0, 0.0, 0.0 };
188 GLdouble TriedronAxeX[3] = { 1.0, 0.0, 0.0 };
189 GLdouble TriedronAxeY[3] = { 0.0, 1.0, 0.0 };
190 GLdouble TriedronAxeZ[3] = { 0.0, 0.0, 1.0 };
192 GLfloat TriedronColorX[3] = { 1.0, 0.0, 0.0 };
193 GLfloat TriedronColorY[3] = { 0.0, 1.0, 0.0 };
194 GLfloat TriedronColorZ[3] = { 0.0, 0.0, 1.0 };
196 GLfloat TriedronLetterColorX[3] = { 1.0, 1.0, 1.0 };
197 GLfloat TriedronLetterColorY[3] = { 1.0, 1.0, 1.0 };
198 GLfloat TriedronLetterColorZ[3] = { 1.0, 1.0, 1.0 };
200 GLfloat TriedronLineWidth = 2.0;
201 GLdouble TriedronScale = 0.15;
203 GLdouble U, V, minUV;
205 glGetIntegerv(GL_VIEWPORT, aViewPort);
214 GLdouble L = minUV * TriedronScale;
216 TriedronOrigin[0]= 0.0;
217 TriedronOrigin[1]= 0.0;
218 TriedronOrigin[2]= 0.0;
220 TriedronAxeX[0] = TriedronOrigin[0] + L;
221 TriedronAxeX[1] = TriedronOrigin[1] + 0.0;
222 TriedronAxeX[2] = TriedronOrigin[2] + 0.0;
224 TriedronAxeY[0] = TriedronOrigin[0] + 0.0;
225 TriedronAxeY[1] = TriedronOrigin[1] + L;
226 TriedronAxeY[2] = TriedronOrigin[2] + 0.0;
228 TriedronAxeZ[0] = TriedronOrigin[0] + 0.0;
229 TriedronAxeZ[1] = TriedronOrigin[1] + 0.0;
230 TriedronAxeZ[2] = TriedronOrigin[2] + L;
232 glPushAttrib( GL_CURRENT_BIT | GL_ENABLE_BIT | GL_LIGHTING_BIT | GL_LINE_BIT | GL_VIEWPORT_BIT );
234 glDepthRange( 0, 0 );
235 glDisable( GL_LIGHTING );
236 glDisable( GL_COLOR_MATERIAL );
237 for( int i = 0; i < GL_MAX_CLIP_PLANES; i++ )
238 glDisable( GL_CLIP_PLANE0 + i );
240 glLineWidth( TriedronLineWidth );
242 glColor3fv( TriedronColorX );
244 glVertex3dv( TriedronOrigin );
245 glVertex3dv( TriedronAxeX );
248 glColor3fv( TriedronColorY );
250 glVertex3dv( TriedronOrigin );
251 glVertex3dv( TriedronAxeY );
254 glColor3fv( TriedronColorZ );
256 glVertex3dv( TriedronOrigin );
257 glVertex3dv( TriedronAxeZ );
260 GLdouble l = L - L/4.;
261 GLdouble rayon = L/20.;
262 GLint ii, NbFacettes = 12;
263 GLdouble Angle = 2. * PI / NbFacettes;
264 GLdouble TriedronCoord[3] = { 1.0, 0.0, 0.0 };
266 if( myTextList == 0 )
267 myTextList = generateTextList();
269 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
271 glColor3fv( TriedronColorX );
272 glBegin( GL_TRIANGLE_FAN );
273 glVertex3dv( TriedronAxeX );
274 TriedronCoord[0] = TriedronOrigin[0] + l ;
277 TriedronCoord[1] = TriedronOrigin[1] + ( rayon * sin(ii * Angle) );
278 TriedronCoord[2] = TriedronOrigin[2] + ( rayon * cos(ii * Angle) );
279 glVertex3dv( TriedronCoord );
284 drawText( myTextList, "X", TriedronAxeX, TriedronLetterColorX );
286 glColor3fv( TriedronColorY );
287 glBegin( GL_TRIANGLE_FAN );
288 glVertex3dv( TriedronAxeY );
289 TriedronCoord[1] = TriedronOrigin[1] + l ;
292 TriedronCoord[0] = TriedronOrigin[0] + (rayon * cos(ii * Angle) );
293 TriedronCoord[2] = TriedronOrigin[2] + (rayon * sin(ii * Angle) );
294 glVertex3dv( TriedronCoord );
299 drawText( myTextList, "Y", TriedronAxeY, TriedronLetterColorY );
301 glColor3fv( TriedronColorZ );
302 glBegin( GL_TRIANGLE_FAN );
303 glVertex3dv( TriedronAxeZ );
304 TriedronCoord[2] = TriedronOrigin[2] + l ;
307 TriedronCoord[0] = TriedronOrigin[0] + ( rayon * sin(ii * Angle) );
308 TriedronCoord[1] = TriedronOrigin[1] + ( rayon * cos(ii * Angle) );
309 glVertex3dv( TriedronCoord );
314 drawText( myTextList, "Z", TriedronAxeZ, TriedronLetterColorZ );