1 // Copyright (C) 2007-2008 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.
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
28 #include "OCCViewer_Trihedron.h"
31 #include <SUIT_ResourceMgr.h>
32 #include <SUIT_Session.h>
34 #include <Graphic3d_AspectFillArea3d.hxx>
35 #include <Graphic3d_Group.hxx>
36 #include <Graphic3d_MaterialAspect.hxx>
37 #include <Prs3d_Presentation.hxx>
38 #include <Prs3d_Root.hxx>
39 #include <PrsMgr_PresentationManager3d.hxx>
48 #define PI 3.14159265359
50 IMPLEMENT_STANDARD_HANDLE( OCCViewer_Trihedron, AIS_InteractiveObject )
51 IMPLEMENT_STANDARD_RTTIEXT( OCCViewer_Trihedron, AIS_InteractiveObject )
56 OCCViewer_Trihedron::OCCViewer_Trihedron( const PrsMgr_TypeOfPresentation3d t )
57 : AIS_InteractiveObject( t ),
65 OCCViewer_Trihedron::~OCCViewer_Trihedron()
68 glDeleteLists( myTextList, 256 );
72 * Sets the bounding box (MinMax values).
74 void OCCViewer_Trihedron::bounds( Graphic3d_CBounds& aMinMax ) const
76 Standard_Real aXMin = -1, aYMin = -1, aZMin = -1;
77 Standard_Real aXMax = 1, aYMax = 1, aZMax = 1;
79 if( aMinMax.XMin > aXMin ) aMinMax.XMin = aXMin;
80 if( aMinMax.YMin > aYMin ) aMinMax.YMin = aYMin;
81 if( aMinMax.ZMin > aZMin ) aMinMax.ZMin = aZMin;
82 if( aMinMax.XMax < aXMax ) aMinMax.XMax = aXMax;
83 if( aMinMax.YMax < aYMax ) aMinMax.YMax = aYMax;
84 if( aMinMax.ZMax < aZMax ) aMinMax.ZMax = aZMax;
88 * Redefined method. Calculates the object presentation.
90 void OCCViewer_Trihedron::Compute( const Handle( PrsMgr_PresentationManager3d )&,
91 const Handle( Prs3d_Presentation )& aPrs,
92 const Standard_Integer aMode )
97 Handle( Graphic3d_Group ) aGroup = Prs3d_Root::CurrentGroup( aPrs );
98 aGroup->UserDraw( this );
102 * Redefined method. Does nothing.
104 void OCCViewer_Trihedron::ComputeSelection( const Handle( SelectMgr_Selection )& theSelection,
105 const Standard_Integer theMode )
110 * Generates text list.
112 GLuint generateTextList()
115 GLuint aList = glGenLists( 256 );
118 HGLRC hglrc = wglGetCurrentContext();
121 HDC hdc = ::wglGetCurrentDC();
122 HFONT font = CreateFont( -12, 0, 0, 0,
129 FF_DONTCARE | DEFAULT_PITCH,
131 HFONT oldFont = (HFONT)SelectObject( hdc, font );
133 ok = ::wglUseFontBitmaps( hdc, 0, 256, aList );
134 SelectObject( hdc, oldFont );
135 DeleteObject( font );
138 Display* dpy = glXGetCurrentDisplay();
142 char** aFontList = XListFonts( dpy, "*-courier-*", 1, &aFontCount );
145 //XFontStruct* fontInfo = XLoadQueryFont( dpy, "-*-courier-*-r-*-*-14-*-*-*-m-*-*-*" );
146 Font aFont = XLoadFont( dpy, aFontList[0] );
147 glXUseXFont( aFont, 0, 256, aList );
148 XUnloadFont( dpy, aFont );
151 XFreeFontNames( aFontList );
156 glDeleteLists( aList, 256 );
164 void drawText( GLuint theTextList, const char* theText, GLdouble thePosition[3], GLfloat theColor[3] )
166 glColor3fv( theColor );
167 glRasterPos3dv( thePosition );
168 glListBase( theTextList );
169 glCallLists( strlen( theText ), GL_UNSIGNED_BYTE, (GLubyte*)theText );
173 * Displays trihedron.
175 void OCCViewer_Trihedron::display()
177 GLdouble TriedronOrigin[3] = { 0.0, 0.0, 0.0 };
179 GLdouble TriedronAxeX[3] = { 1.0, 0.0, 0.0 };
180 GLdouble TriedronAxeY[3] = { 0.0, 1.0, 0.0 };
181 GLdouble TriedronAxeZ[3] = { 0.0, 0.0, 1.0 };
183 GLfloat TriedronColorX[3] = { 1.0, 0.0, 0.0 };
184 GLfloat TriedronColorY[3] = { 0.0, 1.0, 0.0 };
185 GLfloat TriedronColorZ[3] = { 0.0, 0.0, 1.0 };
187 GLfloat TriedronLetterColorX[3] = { 1.0, 1.0, 1.0 };
188 GLfloat TriedronLetterColorY[3] = { 1.0, 1.0, 1.0 };
189 GLfloat TriedronLetterColorZ[3] = { 1.0, 1.0, 1.0 };
191 GLfloat TriedronLineWidth = 2.0;
192 GLdouble TriedronScale = 0.15;
194 GLdouble U, V, minUV;
196 glGetIntegerv(GL_VIEWPORT, aViewPort);
205 GLdouble L = minUV * TriedronScale;
207 TriedronOrigin[0]= 0.0;
208 TriedronOrigin[1]= 0.0;
209 TriedronOrigin[2]= 0.0;
211 TriedronAxeX[0] = TriedronOrigin[0] + L;
212 TriedronAxeX[1] = TriedronOrigin[1] + 0.0;
213 TriedronAxeX[2] = TriedronOrigin[2] + 0.0;
215 TriedronAxeY[0] = TriedronOrigin[0] + 0.0;
216 TriedronAxeY[1] = TriedronOrigin[1] + L;
217 TriedronAxeY[2] = TriedronOrigin[2] + 0.0;
219 TriedronAxeZ[0] = TriedronOrigin[0] + 0.0;
220 TriedronAxeZ[1] = TriedronOrigin[1] + 0.0;
221 TriedronAxeZ[2] = TriedronOrigin[2] + L;
223 glPushAttrib( GL_CURRENT_BIT | GL_ENABLE_BIT | GL_LIGHTING_BIT | GL_LINE_BIT | GL_VIEWPORT_BIT );
225 glDepthRange( 0, 0 );
226 glDisable( GL_LIGHTING );
227 glDisable( GL_COLOR_MATERIAL );
228 for( int i = 0; i < GL_MAX_CLIP_PLANES; i++ )
229 glDisable( GL_CLIP_PLANE0 + i );
231 glLineWidth( TriedronLineWidth );
233 glColor3fv( TriedronColorX );
235 glVertex3dv( TriedronOrigin );
236 glVertex3dv( TriedronAxeX );
239 glColor3fv( TriedronColorY );
241 glVertex3dv( TriedronOrigin );
242 glVertex3dv( TriedronAxeY );
245 glColor3fv( TriedronColorZ );
247 glVertex3dv( TriedronOrigin );
248 glVertex3dv( TriedronAxeZ );
251 GLdouble l = L - L/4.;
252 GLdouble rayon = L/20.;
253 GLint ii, NbFacettes = 12;
254 GLdouble Angle = 2. * PI / NbFacettes;
255 GLdouble TriedronCoord[3] = { 1.0, 0.0, 0.0 };
257 if( myTextList == 0 )
258 myTextList = generateTextList();
260 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
262 glColor3fv( TriedronColorX );
263 glBegin( GL_TRIANGLE_FAN );
264 glVertex3dv( TriedronAxeX );
265 TriedronCoord[0] = TriedronOrigin[0] + l ;
268 TriedronCoord[1] = TriedronOrigin[1] + ( rayon * sin(ii * Angle) );
269 TriedronCoord[2] = TriedronOrigin[2] + ( rayon * cos(ii * Angle) );
270 glVertex3dv( TriedronCoord );
275 drawText( myTextList, "X", TriedronAxeX, TriedronLetterColorX );
277 glColor3fv( TriedronColorY );
278 glBegin( GL_TRIANGLE_FAN );
279 glVertex3dv( TriedronAxeY );
280 TriedronCoord[1] = TriedronOrigin[1] + l ;
283 TriedronCoord[0] = TriedronOrigin[0] + (rayon * cos(ii * Angle) );
284 TriedronCoord[2] = TriedronOrigin[2] + (rayon * sin(ii * Angle) );
285 glVertex3dv( TriedronCoord );
290 drawText( myTextList, "Y", TriedronAxeY, TriedronLetterColorY );
292 glColor3fv( TriedronColorZ );
293 glBegin( GL_TRIANGLE_FAN );
294 glVertex3dv( TriedronAxeZ );
295 TriedronCoord[2] = TriedronOrigin[2] + l ;
298 TriedronCoord[0] = TriedronOrigin[0] + ( rayon * sin(ii * Angle) );
299 TriedronCoord[1] = TriedronOrigin[1] + ( rayon * cos(ii * Angle) );
300 glVertex3dv( TriedronCoord );
305 drawText( myTextList, "Z", TriedronAxeZ, TriedronLetterColorZ );