From 9963bedc9a2216b5cf6fddb33d3a8c476d2f4d08 Mon Sep 17 00:00:00 2001 From: ouv Date: Wed, 30 Jul 2008 12:08:11 +0000 Subject: [PATCH] Feature 0016551: EDF PAL 501: To add a second trihedron always visible and with constant size --- src/OCCViewer/Makefile.am | 9 +- src/OCCViewer/OCCViewer.cxx | 100 +++++++++ src/OCCViewer/OCCViewer_Trihedron.cxx | 296 ++++++++++++++++++++++++++ src/OCCViewer/OCCViewer_Trihedron.h | 59 +++++ src/OCCViewer/OCCViewer_ViewModel.cxx | 27 +-- src/SOCC/SOCC_ViewModel.cxx | 5 +- 6 files changed, 470 insertions(+), 26 deletions(-) create mode 100644 src/OCCViewer/OCCViewer.cxx create mode 100755 src/OCCViewer/OCCViewer_Trihedron.cxx create mode 100644 src/OCCViewer/OCCViewer_Trihedron.h diff --git a/src/OCCViewer/Makefile.am b/src/OCCViewer/Makefile.am index 3e6a522ed..fa15a4b65 100755 --- a/src/OCCViewer/Makefile.am +++ b/src/OCCViewer/Makefile.am @@ -38,9 +38,11 @@ salomeinclude_HEADERS= \ OCCViewer.h \ OCCViewer_ClippingDlg.h \ OCCViewer_AxialScaleDlg.h \ - OCCViewer_SetRotationPointDlg.h + OCCViewer_SetRotationPointDlg.h \ + OCCViewer_Trihedron.h dist_libOCCViewer_la_SOURCES= \ + OCCViewer.cxx \ OCCViewer_AISSelector.cxx \ OCCViewer_ViewManager.cxx \ OCCViewer_ViewModel.cxx \ @@ -52,7 +54,8 @@ dist_libOCCViewer_la_SOURCES= \ OCCViewer_CreateRestoreViewDlg.cxx \ OCCViewer_SetRotationPointDlg.cxx \ OCCViewer_ClippingDlg.cxx \ - OCCViewer_AxialScaleDlg.cxx + OCCViewer_AxialScaleDlg.cxx \ + OCCViewer_Trihedron.cxx MOC_FILES= \ OCCViewer_AISSelector_moc.cxx \ @@ -99,5 +102,5 @@ nodist_salomeres_DATA = \ libOCCViewer_la_CPPFLAGS=$(QT_INCLUDES) $(OGL_INCLUDES) $(CAS_CPPFLAGS) \ -I$(srcdir)/../SUIT -I$(srcdir)/../Qtx -libOCCViewer_la_LDFLAGS=$(OGL_LIBS) $(QT_MT_LIBS) $(CAS_KERNEL) $(CAS_VIEWER) +libOCCViewer_la_LDFLAGS=$(OGL_LIBS) $(QT_MT_LIBS) $(CAS_KERNEL) $(CAS_VIEWER) -lTKOpenGl libOCCViewer_la_LIBADD=../Qtx/libqtx.la ../SUIT/libsuit.la diff --git a/src/OCCViewer/OCCViewer.cxx b/src/OCCViewer/OCCViewer.cxx new file mode 100644 index 000000000..14640ffa3 --- /dev/null +++ b/src/OCCViewer/OCCViewer.cxx @@ -0,0 +1,100 @@ +// Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include + +#include +#include + +void OCCViewer_Init(); + +extern "C" +{ +#ifdef WNT /* disable MS VC++ warning on C-style function returning C++ object */ +#pragma warning(push) +#pragma warning(disable:4190) +#endif + Standard_EXPORT Handle( Graphic3d_GraphicDriver ) MetaGraphicDriverFactory( const Standard_CString AShrName ) + { + OCCViewer_Init(); + Handle( OpenGl_GraphicDriver ) aDriver = new OpenGl_GraphicDriver( AShrName ); + return aDriver; + } +#ifdef WNT +#pragma warning(pop) +#endif + +#include +#include +#include +#include +#include + + TStatus OCCViewer_DisplayTrihedron ( TSM_ELEM_DATA, Tint, cmn_key* ); + TStatus OCCViewer_AddTrihedron ( TSM_ELEM_DATA, Tint, cmn_key* ); + TStatus OCCViewer_DeleteTrihedron ( TSM_ELEM_DATA, Tint, cmn_key* ); +} + + +TStatus OCCViewer_AddTrihedron( TSM_ELEM_DATA d, Tint n, cmn_key* k ) +{ + // Retrieve the userdraw structure + Graphic3d_CUserDraw *userdraw = ( Graphic3d_CUserDraw* )( k[0]->data.pdata ); + if ( !userdraw ) + return TFailure; + + // Retrieve the user structure + OCCViewer_Trihedron* userdata = ( OCCViewer_Trihedron* )( userdraw->Data ); + if ( !userdata ) + return TFailure; + + ( ( tsm_elem_data )( d.pdata ) )->pdata = ( void* )userdata; + + // Evaluate minmax if needed + if( userdraw->Bounds && userdata ) + userdata->bounds( *( userdraw->Bounds ) ); + + return TSuccess; +} + +TStatus OCCViewer_DeleteTrihedron( TSM_ELEM_DATA d, Tint n, cmn_key* k ) +{ + delete ( OCCViewer_Trihedron* )( d.pdata ); + return TSuccess; +} + +TStatus OCCViewer_DisplayTrihedron( TSM_ELEM_DATA d, Tint n, cmn_key* k ) +{ + ( ( OCCViewer_Trihedron* )( d.pdata ) )->display(); + return TSuccess; +} + +void OCCViewer_Init() +{ + //PickTraverse=0 + //DisplayTraverse=1 + //Add=2 + //Delete=3 + //Print=4 + //Inquire=5 + MtblPtr theCallbacks = GetCallbackTable(); + theCallbacks[DisplayTraverse] = OCCViewer_DisplayTrihedron; + theCallbacks[Add] = OCCViewer_AddTrihedron; + theCallbacks[Delete] = OCCViewer_DeleteTrihedron; +} diff --git a/src/OCCViewer/OCCViewer_Trihedron.cxx b/src/OCCViewer/OCCViewer_Trihedron.cxx new file mode 100755 index 000000000..fc35bb360 --- /dev/null +++ b/src/OCCViewer/OCCViewer_Trihedron.cxx @@ -0,0 +1,296 @@ +// Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include + +#include +#include + +#include +#include +#include +#include +#include +#include + +#ifndef WNT +#include +#endif + +#define PI 3.14159265359 + +IMPLEMENT_STANDARD_HANDLE( OCCViewer_Trihedron, AIS_InteractiveObject ) +IMPLEMENT_STANDARD_RTTIEXT( OCCViewer_Trihedron, AIS_InteractiveObject ) + +/*! + * Constructor + */ +OCCViewer_Trihedron::OCCViewer_Trihedron( const PrsMgr_TypeOfPresentation3d t ) + : AIS_InteractiveObject( t ), + myTextList( 0 ) +{ +} + +/*! + * Destructor + */ +OCCViewer_Trihedron::~OCCViewer_Trihedron() +{ + if( myTextList ) + glDeleteLists( myTextList, 256 ); +} + +/*! + * Sets the bounding box (MinMax values). + */ +void OCCViewer_Trihedron::bounds( Graphic3d_CBounds& aMinMax ) const +{ + Standard_Real aXMin = -1, aYMin = -1, aZMin = -1; + Standard_Real aXMax = 1, aYMax = 1, aZMax = 1; + + if( aMinMax.XMin > aXMin ) aMinMax.XMin = aXMin; + if( aMinMax.YMin > aYMin ) aMinMax.YMin = aYMin; + if( aMinMax.ZMin > aZMin ) aMinMax.ZMin = aZMin; + if( aMinMax.XMax < aXMax ) aMinMax.XMax = aXMax; + if( aMinMax.YMax < aYMax ) aMinMax.YMax = aYMax; + if( aMinMax.ZMax < aZMax ) aMinMax.ZMax = aZMax; +} + +/*! + * Redefined method. Calculates the object presentation. + */ +void OCCViewer_Trihedron::Compute( const Handle( PrsMgr_PresentationManager3d )&, + const Handle( Prs3d_Presentation )& aPrs, + const Standard_Integer aMode ) +{ + if( aPrs.IsNull() ) + return; + + Handle( Graphic3d_Group ) aGroup = Prs3d_Root::CurrentGroup( aPrs ); + aGroup->UserDraw( this ); +} + +/*! + * Redefined method. Does nothing. + */ +void OCCViewer_Trihedron::ComputeSelection( const Handle( SelectMgr_Selection )& theSelection, + const Standard_Integer theMode ) +{ +} + +/*! + * Generates text list. + */ +GLuint generateTextList() +{ + bool ok = false; + GLuint aList = glGenLists( 256 ); + +#ifdef WIN32 + HGLRC hglrc = ::wglGetCurrentContext(); + if( hglrc ) + { + HDC hdc = ::wglGetCurrentDC(); + HFONT font = CreateFont( -12, 0, 0, 0, + FW_BOLD, + 0, 0, 0, + ANSI_CHARSET, + OUT_TT_PRECIS, + CLIP_DEFAULT_PRECIS, + ANTIALIASED_QUALITY, + FF_DONTCARE | DEFAULT_PITCH, + "Courier New" ); + HFONT oldFont = (HFONT)SelectObject( hdc, font ); + + ok = ::wglUseFontBitmaps( hdc, 0, 256, aList ); + SelectObject( hdc, oldFont ); + DeleteObject( font ); + } +#else // X Window + Display* dpy = glXGetCurrentDisplay(); + if( dpy ) + { + int aFontCount = 0; + char** aFontList = XListFonts( dpy, "*-courier-*", 1, &aFontCount ); + if( aFontCount > 0 ) + { + //XFontStruct* fontInfo = XLoadQueryFont( dpy, "-*-courier-*-r-*-*-14-*-*-*-m-*-*-*" ); + Font aFont = XLoadFont( dpy, aFontList[0] ); + glXUseXFont( aFont, 0, 256, aList ); + XUnloadFont( dpy, aFont ); + ok = true; + } + XFreeFontNames( aFontList ); + } +#endif + + if( !ok ) + glDeleteLists( aList, 256 ); + + return aList; +} + +/*! + * Draws text string. + */ +void drawText( GLuint theTextList, const char* theText, GLdouble thePosition[3], GLfloat theColor[3] ) +{ + glColor3fv( theColor ); + glRasterPos3dv( thePosition ); + glListBase( theTextList ); + glCallLists( strlen( theText ), GL_UNSIGNED_BYTE, (GLubyte*)theText ); +} + +/*! + * Displays trihedron. + */ +void OCCViewer_Trihedron::display() +{ + GLdouble TriedronOrigin[3] = { 0.0, 0.0, 0.0 }; + + GLdouble TriedronAxeX[3] = { 1.0, 0.0, 0.0 }; + GLdouble TriedronAxeY[3] = { 0.0, 1.0, 0.0 }; + GLdouble TriedronAxeZ[3] = { 0.0, 0.0, 1.0 }; + + GLfloat TriedronColorX[3] = { 1.0, 0.0, 0.0 }; + GLfloat TriedronColorY[3] = { 0.0, 1.0, 0.0 }; + GLfloat TriedronColorZ[3] = { 0.0, 0.0, 1.0 }; + + GLfloat TriedronLetterColorX[3] = { 1.0, 1.0, 1.0 }; + GLfloat TriedronLetterColorY[3] = { 1.0, 1.0, 1.0 }; + GLfloat TriedronLetterColorZ[3] = { 1.0, 1.0, 1.0 }; + + GLfloat TriedronLineWidth = 2.0; + GLdouble TriedronScale = 0.15; + + GLdouble U, V, minUV; + GLint aViewPort[4]; + glGetIntegerv(GL_VIEWPORT, aViewPort); + U = aViewPort[2]; + V = aViewPort[3]; + + if( U < V ) + minUV = U; + else + minUV = V; + + GLdouble L = minUV * TriedronScale; + + TriedronOrigin[0]= 0.0; + TriedronOrigin[1]= 0.0; + TriedronOrigin[2]= 0.0; + + TriedronAxeX[0] = TriedronOrigin[0] + L; + TriedronAxeX[1] = TriedronOrigin[1] + 0.0; + TriedronAxeX[2] = TriedronOrigin[2] + 0.0; + + TriedronAxeY[0] = TriedronOrigin[0] + 0.0; + TriedronAxeY[1] = TriedronOrigin[1] + L; + TriedronAxeY[2] = TriedronOrigin[2] + 0.0; + + TriedronAxeZ[0] = TriedronOrigin[0] + 0.0; + TriedronAxeZ[1] = TriedronOrigin[1] + 0.0; + TriedronAxeZ[2] = TriedronOrigin[2] + L; + + glPushAttrib( GL_CURRENT_BIT | GL_ENABLE_BIT | GL_LIGHTING_BIT | GL_LINE_BIT | GL_VIEWPORT_BIT ); + + glDepthRange( 0, 0 ); + glDisable( GL_LIGHTING ); + glDisable( GL_COLOR_MATERIAL ); + for( int i = 0; i < GL_MAX_CLIP_PLANES; i++ ) + glDisable( GL_CLIP_PLANE0 + i ); + + glLineWidth( TriedronLineWidth ); + + glColor3fv( TriedronColorX ); + glBegin( GL_LINES ); + glVertex3dv( TriedronOrigin ); + glVertex3dv( TriedronAxeX ); + glEnd(); + + glColor3fv( TriedronColorY ); + glBegin( GL_LINES ); + glVertex3dv( TriedronOrigin ); + glVertex3dv( TriedronAxeY ); + glEnd(); + + glColor3fv( TriedronColorZ ); + glBegin( GL_LINES ); + glVertex3dv( TriedronOrigin ); + glVertex3dv( TriedronAxeZ ); + glEnd(); + + GLdouble l = L - L/4.; + GLdouble rayon = L/20.; + GLint ii, NbFacettes = 12; + GLdouble Angle = 2. * PI / NbFacettes; + GLdouble TriedronCoord[3] = { 1.0, 0.0, 0.0 }; + + if( myTextList == 0 ) + myTextList = generateTextList(); + + glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); + + glColor3fv( TriedronColorX ); + glBegin( GL_TRIANGLE_FAN ); + glVertex3dv( TriedronAxeX ); + TriedronCoord[0] = TriedronOrigin[0] + l ; + ii = NbFacettes; + while (ii >= 0 ) { + TriedronCoord[1] = TriedronOrigin[1] + ( rayon * sin(ii * Angle) ); + TriedronCoord[2] = TriedronOrigin[2] + ( rayon * cos(ii * Angle) ); + glVertex3dv( TriedronCoord ); + ii--; + } + glEnd(); + + drawText( myTextList, "X", TriedronAxeX, TriedronLetterColorX ); + + glColor3fv( TriedronColorY ); + glBegin( GL_TRIANGLE_FAN ); + glVertex3dv( TriedronAxeY ); + TriedronCoord[1] = TriedronOrigin[1] + l ; + ii = NbFacettes; + while (ii >= 0 ) { + TriedronCoord[0] = TriedronOrigin[0] + (rayon * cos(ii * Angle) ); + TriedronCoord[2] = TriedronOrigin[2] + (rayon * sin(ii * Angle) ); + glVertex3dv( TriedronCoord ); + ii--; + } + glEnd(); + + drawText( myTextList, "Y", TriedronAxeY, TriedronLetterColorY ); + + glColor3fv( TriedronColorZ ); + glBegin( GL_TRIANGLE_FAN ); + glVertex3dv( TriedronAxeZ ); + TriedronCoord[2] = TriedronOrigin[2] + l ; + ii = NbFacettes; + while (ii >= 0 ) { + TriedronCoord[0] = TriedronOrigin[0] + ( rayon * sin(ii * Angle) ); + TriedronCoord[1] = TriedronOrigin[1] + ( rayon * cos(ii * Angle) ); + glVertex3dv( TriedronCoord ); + ii--; + } + glEnd(); + + drawText( myTextList, "Z", TriedronAxeZ, TriedronLetterColorZ ); + + glPopAttrib(); +} diff --git a/src/OCCViewer/OCCViewer_Trihedron.h b/src/OCCViewer/OCCViewer_Trihedron.h new file mode 100644 index 000000000..915285970 --- /dev/null +++ b/src/OCCViewer/OCCViewer_Trihedron.h @@ -0,0 +1,59 @@ +// Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +#ifndef OCCVIEWER_TRIHEDRON_H +#define OCCVIEWER_TRIHEDRON_H + +#include + +#include +#include +#include + +#include + +/*! + * \class OCCViewer_Trihedron + * The class for the presentation of the UserDraw object. +*/ +class OCCVIEWER_EXPORT OCCViewer_Trihedron : public AIS_InteractiveObject +{ +public: + OCCViewer_Trihedron( const PrsMgr_TypeOfPresentation3d = PrsMgr_TOP_AllView ); + virtual ~OCCViewer_Trihedron(); + + virtual void Compute( const Handle(PrsMgr_PresentationManager3d)&, + const Handle(Prs3d_Presentation)&, + const Standard_Integer ); + + virtual void ComputeSelection( const Handle( SelectMgr_Selection )&, + const Standard_Integer ); + + virtual void bounds( Graphic3d_CBounds& ) const; + + virtual void display(); + + DEFINE_STANDARD_RTTI( OCCViewer_Trihedron ) + +private: + GLuint myTextList; +}; + +DEFINE_STANDARD_HANDLE( OCCViewer_Trihedron, AIS_InteractiveObject ) + +#endif diff --git a/src/OCCViewer/OCCViewer_ViewModel.cxx b/src/OCCViewer/OCCViewer_ViewModel.cxx index b65c14d0a..93768a832 100755 --- a/src/OCCViewer/OCCViewer_ViewModel.cxx +++ b/src/OCCViewer/OCCViewer_ViewModel.cxx @@ -21,6 +21,7 @@ #include "OCCViewer_ViewWindow.h" #include "OCCViewer_VService.h" #include "OCCViewer_ViewPort3d.h" +#include "OCCViewer_Trihedron.h" #include "SUIT_ViewWindow.h" #include "SUIT_ViewManager.h" @@ -114,28 +115,10 @@ myBgColor( Qt::black ) /* create static trihedron (16551: EDF PAL 501) */ if( DisplayStaticTrihedron ) { - Handle(Geom_Axis2Placement) anAxis = new Geom_Axis2Placement(gp::XOY()); - Handle(AIS_Trihedron) aStaticTrihedron = new AIS_Trihedron(anAxis); - aStaticTrihedron->SetInfiniteState( Standard_True ); - - Quantity_Color Col(193/255., 205/255., 193/255., Quantity_TOC_RGB); - aStaticTrihedron->SetArrowColor( Col.Name() ); - aStaticTrihedron->SetSize(100); - Handle(AIS_Drawer) drawer = aStaticTrihedron->Attributes(); - if (drawer->HasDatumAspect()) { - Handle(Prs3d_DatumAspect) daspect = drawer->DatumAspect(); - daspect->FirstAxisAspect()->SetColor(Quantity_Color(1.0, 0.0, 0.0, Quantity_TOC_RGB)); - daspect->FirstAxisAspect()->SetWidth(2); - daspect->SecondAxisAspect()->SetColor(Quantity_Color(0.0, 1.0, 0.0, Quantity_TOC_RGB)); - daspect->SecondAxisAspect()->SetWidth(2); - daspect->ThirdAxisAspect()->SetColor(Quantity_Color(0.0, 0.0, 1.0, Quantity_TOC_RGB)); - daspect->ThirdAxisAspect()->SetWidth(2); - } - - myAISContext->Display(aStaticTrihedron); - myAISContext->Deactivate(aStaticTrihedron); - - aStaticTrihedron->SetTransformPersistence(Graphic3d_TMF_TriedronPers, gp_Pnt( -1, -1, 200 )); + Handle(OCCViewer_Trihedron) aTrihedron = new OCCViewer_Trihedron(); + myAISContext->Display(aTrihedron); + myAISContext->Deactivate(aTrihedron); + aTrihedron->SetTransformPersistence(Graphic3d_TMF_TriedronPers, gp_Pnt(-1, -1, 200)); } // selection diff --git a/src/SOCC/SOCC_ViewModel.cxx b/src/SOCC/SOCC_ViewModel.cxx index fd046f662..de439dbcf 100755 --- a/src/SOCC/SOCC_ViewModel.cxx +++ b/src/SOCC/SOCC_ViewModel.cxx @@ -21,6 +21,8 @@ #include "SOCC_Prs.h" #include "SOCC_ViewWindow.h" +#include "OCCViewer_Trihedron.h" + #include "SUIT_Session.h" #include "SUIT_ResourceMgr.h" //#include "SUIT_Application.h" @@ -502,7 +504,8 @@ void SOCC_Viewer::EraseAll( const bool forced ) ic->DisplayedObjects( aList ); AIS_ListIteratorOfListOfInteractive anIter( aList ); for ( ; anIter.More(); anIter.Next() ) { - if ( isTrihedronDisplayed && anIter.Value()->DynamicType() == STANDARD_TYPE( AIS_Trihedron ) ) + if ( isTrihedronDisplayed && anIter.Value()->DynamicType() == STANDARD_TYPE( AIS_Trihedron ) || + anIter.Value()->DynamicType() == STANDARD_TYPE( OCCViewer_Trihedron )) continue; // erase an object -- 2.39.2