From: rnv Date: Mon, 3 Oct 2011 13:22:02 +0000 (+0000) Subject: Implementation of the "21317: EDF 1614 ALL: Trihedron size preference" issue. X-Git-Tag: V6_4_0a1~51 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=33a184e62265a6734a3f0d4c705a075b980c3cba;p=modules%2Fgui.git Implementation of the "21317: EDF 1614 ALL: Trihedron size preference" issue. --- diff --git a/doc/salome/gui/images/pref12.png b/doc/salome/gui/images/pref12.png index 94e04818e..e7f696fea 100755 Binary files a/doc/salome/gui/images/pref12.png and b/doc/salome/gui/images/pref12.png differ diff --git a/doc/salome/gui/input/salome_preferences.doc b/doc/salome/gui/input/salome_preferences.doc index d72507dff..920183e0f 100644 --- a/doc/salome/gui/input/salome_preferences.doc +++ b/doc/salome/gui/input/salome_preferences.doc @@ -90,6 +90,8 @@ dialog box press the "..." button(see the picture below). - OCC Viewer 3d - Trihedron size - this submenu allows to set the size of coordinate axes displayed in the viewer. + - Relative size - if checked in, trihedron axes scale to fit the + size of the area displayed in 3D Viewer. - Navigation - this option allows to choose one of the modes of work with mouse in OCC and VTK 3D viewers. - Salome Standard Controls - allows to manipulate objects in the @@ -112,6 +114,8 @@ dialog box press the "..." button(see the picture below). relatively to its center. - Relative to the cursor - allows to zoom the view relatively to the current cursor position. + - Show static trihedron - allows to show/hide the static trihedron + located in the bottom-left corner of the viewer. - VTK Viewer 3d - Projection mode - allows choosing between \b Orthogonal and \b Perspective projection mode. diff --git a/src/LightApp/LightApp_Application.cxx b/src/LightApp/LightApp_Application.cxx index f79040d06..d6fc2e551 100644 --- a/src/LightApp/LightApp_Application.cxx +++ b/src/LightApp/LightApp_Application.cxx @@ -1361,7 +1361,7 @@ SUIT_ViewManager* LightApp_Application::createViewManager( const QString& vmType #ifndef DISABLE_SALOMEOBJECT vm = new SOCC_Viewer(); #else - vm = new OCCViewer_Viewer( true, resMgr->booleanValue( "OCCViewer", "static_trihedron", true ) ); + vm = new OCCViewer_Viewer( true ); #endif vm->setBackgroundColor( OCCViewer_ViewFrame::TOP_LEFT, resMgr->colorValue( "OCCViewer", "xz_background", vm->backgroundColor() ) ); @@ -1373,7 +1373,8 @@ SUIT_ViewManager* LightApp_Application::createViewManager( const QString& vmType vm->setBackgroundColor( OCCViewer_ViewFrame::BOTTOM_RIGHT, resMgr->colorValue( "OCCViewer", "background", vm->backgroundColor() ) ); - vm->setTrihedronSize( resMgr->doubleValue( "OCCViewer", "trihedron_size", vm->trihedronSize() ) ); + vm->setTrihedronSize( resMgr->doubleValue( "OCCViewer", "trihedron_size", vm->trihedronSize() ), + resMgr->booleanValue( "OCCViewer", "relative_size", vm->trihedronRelative() )); int u( 1 ), v( 1 ); vm->isos( u, v ); u = resMgr->integerValue( "OCCViewer", "iso_number_u", u ); @@ -1991,6 +1992,8 @@ void LightApp_Application::createPreferences( LightApp_Preferences* pref ) LightApp_Preferences::DblSpin, "OCCViewer", "trihedron_size" ); pref->setItemProperty( "min", 1.0E-06, occTS ); pref->setItemProperty( "max", 1000, occTS ); + + pref->addPreference( tr( "PREF_RELATIVE_SIZE" ), occGroup, LightApp_Preferences::Bool, "OCCViewer", "relative_size" ); int occStyleMode = pref->addPreference( tr( "PREF_NAVIGATION" ), occGroup, LightApp_Preferences::Selector, "OCCViewer", "navigation_mode" ); @@ -2040,6 +2043,8 @@ void LightApp_Application::createPreferences( LightApp_Preferences* pref ) pref->setItemProperty( "indexes", aModeIndexesList, occZoomingStyleMode ); #endif + pref->addPreference( tr( "PREF_SHOW_STATIC_TRIHEDRON" ), occGroup, LightApp_Preferences::Bool, "OCCViewer", "show_static_trihedron" ); + // VTK Viewer int vtkGen = pref->addPreference( "", vtkGroup, LightApp_Preferences::Frame ); pref->setItemProperty( "columns", 2, vtkGen ); @@ -2316,9 +2321,10 @@ void LightApp_Application::preferencesChanged( const QString& sec, const QString } #ifndef DISABLE_OCCVIEWER - if ( sec == QString( "OCCViewer" ) && param == QString( "trihedron_size" ) ) + if ( sec == QString( "OCCViewer" ) && (param == QString( "trihedron_size" ) || param == QString( "relative_size" ))) { - double sz = resMgr->doubleValue( sec, param, -1 ); + double sz = resMgr->doubleValue( sec, "trihedron_size", -1 ); + bool relative = resMgr->booleanValue( sec, "relative_size", true ); QList lst; viewManagers( OCCViewer_Viewer::Type(), lst ); QListIterator it( lst ); @@ -2329,12 +2335,34 @@ void LightApp_Application::preferencesChanged( const QString& sec, const QString continue; OCCViewer_Viewer* occVM = (OCCViewer_Viewer*)vm; - occVM->setTrihedronSize( sz ); + occVM->setTrihedronSize( sz, relative ); occVM->getAISContext()->UpdateCurrentViewer(); } } #endif +#ifndef DISABLE_OCCVIEWER + if ( sec == QString( "OCCViewer" ) && param == QString( "show_static_trihedron" ) ) + { + bool isVisible = resMgr->booleanValue( "OCCViewer", "show_static_trihedron", true ); + QList lst; + viewManagers( OCCViewer_Viewer::Type(), lst ); + QListIterator it( lst ); + while ( it.hasNext() ) + { + SUIT_ViewModel* vm = it.next()->getViewModel(); + if ( !vm || !vm->inherits( "OCCViewer_Viewer" ) ) + continue; + + OCCViewer_Viewer* occVM = dynamic_cast( vm ); + if( occVM ) + { + occVM->setStaticTrihedronDisplayed( isVisible ); + } + } + } +#endif + #ifndef DISABLE_OCCVIEWER if ( sec == QString( "OCCViewer" ) && param == QString( "navigation_mode" ) ) { diff --git a/src/LightApp/resources/LightApp.xml b/src/LightApp/resources/LightApp.xml index 58aed5a52..3bb43ac56 100644 --- a/src/LightApp/resources/LightApp.xml +++ b/src/LightApp/resources/LightApp.xml @@ -139,6 +139,8 @@ + +
diff --git a/src/OCCViewer/OCCViewer_ViewManager.cxx b/src/OCCViewer/OCCViewer_ViewManager.cxx index 9e186e87c..f8344d108 100755 --- a/src/OCCViewer/OCCViewer_ViewManager.cxx +++ b/src/OCCViewer/OCCViewer_ViewManager.cxx @@ -28,8 +28,8 @@ Constructor */ OCCViewer_ViewManager::OCCViewer_ViewManager( SUIT_Study* study, SUIT_Desktop* theDesktop, bool DisplayTrihedron ) -: SUIT_ViewManager( study, theDesktop, new OCCViewer_Viewer( DisplayTrihedron, false ) ) -{ +: SUIT_ViewManager( study, theDesktop, new OCCViewer_Viewer( DisplayTrihedron ) ) +{ setTitle( tr( "OCC_VIEW_TITLE" ) ); } diff --git a/src/OCCViewer/OCCViewer_ViewModel.cxx b/src/OCCViewer/OCCViewer_ViewModel.cxx index 35c81ac3f..25709f0a4 100755 --- a/src/OCCViewer/OCCViewer_ViewModel.cxx +++ b/src/OCCViewer/OCCViewer_ViewModel.cxx @@ -29,6 +29,7 @@ #include "SUIT_ViewManager.h" #include "SUIT_Desktop.h" #include "SUIT_Session.h" +#include "SUIT_ResourceMgr.h" #include "QtxActionToolMgr.h" @@ -56,14 +57,17 @@ #include #include +#include + /*! Constructor \param DisplayTrihedron - is trihedron displayed */ -OCCViewer_Viewer::OCCViewer_Viewer( bool DisplayTrihedron, bool DisplayStaticTrihedron ) +OCCViewer_Viewer::OCCViewer_Viewer( bool DisplayTrihedron) : SUIT_ViewModel(), - myShowStaticTrihedron( DisplayStaticTrihedron ), - myColors(4, Qt::black) + myColors(4, Qt::black), + myIsRelative(true), + myTrihedronSize(100) { // init CasCade viewers myV3dViewer = OCCViewer_VService::Viewer3d( "", (short*) "Viewer3d", "", 1000., @@ -124,6 +128,11 @@ OCCViewer_Viewer::OCCViewer_Viewer( bool DisplayTrihedron, bool DisplayStaticTri // selection mySelectionEnabled = true; myMultiSelectionEnabled = true; + + + SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr(); + if(resMgr) + myShowStaticTrihedron = resMgr->booleanValue( "OCCViewer", "show_static_trihedron", true ); } /*! @@ -709,10 +718,13 @@ double OCCViewer_Viewer::trihedronSize() const Changes trihedron size \param sz - new size */ -void OCCViewer_Viewer::setTrihedronSize( const double sz ) +void OCCViewer_Viewer::setTrihedronSize( const double sz, bool isRelative ) { - if ( !myTrihedron.IsNull() ) - myTrihedron->SetSize( sz ); + if ( myTrihedronSize != sz || isRelative != myIsRelative) { + myTrihedronSize = sz; + myIsRelative = isRelative; + updateTrihedron(); + } } /*! @@ -763,3 +775,84 @@ void OCCViewer_Viewer::setBackgroundColor( int theViewId, const QColor& theColor if ( theColor.isValid() && theViewId >= 0 && theViewId < myColors.count() ) myColors[theViewId] = theColor; } + + +/*! + Set the show static trihedron flag +*/ +void OCCViewer_Viewer::setStaticTrihedronDisplayed(const bool on) { + if(myShowStaticTrihedron != on) { + OCCViewer_ViewWindow* aView = (OCCViewer_ViewWindow*)(myViewManager->getActiveView()); + if(!aView) + return; + + OCCViewer_ViewPort3d* vp3d = aView->getViewPort(); + if(vp3d) { + myShowStaticTrihedron = on; + vp3d->updateStaticTriedronVisibility(); + } + } +} + +/*! + Get new and current trihedron size corresponding to the current model size +*/ +bool OCCViewer_Viewer::computeTrihedronSize( double& theNewSize, double& theSize ) +{ + theNewSize = 100; + theSize = 100; + + //SRN: BUG IPAL8996, a usage of method ActiveView without an initialization + Handle(V3d_Viewer) viewer = getViewer3d(); + viewer->InitActiveViews(); + if(!viewer->MoreActiveViews()) return false; + + Handle(V3d_View) view3d = viewer->ActiveView(); + //SRN: END of fix + + if ( view3d.IsNull() ) + return false; + + double Xmin = 0, Ymin = 0, Zmin = 0, Xmax = 0, Ymax = 0, Zmax = 0; + double aMaxSide; + + view3d->View()->MinMaxValues( Xmin, Ymin, Zmin, Xmax, Ymax, Zmax ); + + if ( Xmin == RealFirst() || Ymin == RealFirst() || Zmin == RealFirst() || + Xmax == RealLast() || Ymax == RealLast() || Zmax == RealLast() ) + return false; + + aMaxSide = Xmax - Xmin; + if ( aMaxSide < Ymax -Ymin ) aMaxSide = Ymax -Ymin; + if ( aMaxSide < Zmax -Zmin ) aMaxSide = Zmax -Zmin; + + // IPAL21687 + // The boundary box of the view may be initialized but nullified + // (case of infinite objects) + if ( aMaxSide < Precision::Confusion() ) + return false; + + float aSizeInPercents = SUIT_Session::session()->resourceMgr()->doubleValue("OCCViewer","trihedron_size", 100.); + + static float EPS = 5.0E-3; + theSize = getTrihedron()->Size(); + theNewSize = aMaxSide*aSizeInPercents / 100.0; + + return fabs( theNewSize - theSize ) > theSize * EPS || + fabs( theNewSize - theSize) > theNewSize * EPS; +} + +/*! + * Update the size of the trihedron + */ +void OCCViewer_Viewer::updateTrihedron() { + if(myIsRelative){ + double newSz, oldSz; + + if(computeTrihedronSize(newSz, oldSz)) + myTrihedron->SetSize(newSz); + + } else if(myTrihedron->Size() != myTrihedronSize) { + myTrihedron->SetSize(myTrihedronSize); + } +} diff --git a/src/OCCViewer/OCCViewer_ViewModel.h b/src/OCCViewer/OCCViewer_ViewModel.h index 4e27361ee..8f08f28c6 100755 --- a/src/OCCViewer/OCCViewer_ViewModel.h +++ b/src/OCCViewer/OCCViewer_ViewModel.h @@ -55,7 +55,7 @@ class OCCVIEWER_EXPORT OCCViewer_Viewer: public SUIT_ViewModel public: static QString Type() { return "OCCViewer"; } - OCCViewer_Viewer( bool DisplayTrihedron = true, bool DisplayStaticTrihedron = true ); + OCCViewer_Viewer( bool DisplayTrihedron = true); virtual ~OCCViewer_Viewer(); void update(); @@ -88,7 +88,15 @@ public: virtual void setTrihedronShown( const bool ); double trihedronSize() const; - virtual void setTrihedronSize( const double ); + virtual void setTrihedronSize( const double , bool isRelative = true); + + bool trihedronRelative() const {return myIsRelative; } + + // a utility function, used by SALOME_View_s methods + bool computeTrihedronSize( double& theNewSize, double& theSize ); + + void updateTrihedron(); + virtual OCCViewer_ViewWindow* createSubWindow(); @@ -111,7 +119,9 @@ public: bool isMultiSelectionEnabled() const { return myMultiSelectionEnabled; } int getSelectionCount() const { return (!myAISContext.IsNull())? myAISContext->NbSelected():0; } + bool isStaticTrihedronDisplayed() { return myShowStaticTrihedron; } + void setStaticTrihedronDisplayed(const bool on); /* Selection management */ bool highlight( const Handle(AIS_InteractiveObject)&, bool, bool=true ); @@ -157,12 +167,15 @@ private: bool mySelectionEnabled; bool myMultiSelectionEnabled; + bool myIsRelative; //QColor myBgColor; QPoint myStartPnt, myEndPnt; bool myShowStaticTrihedron; + double myTrihedronSize; + QVector myColors; }; diff --git a/src/OCCViewer/OCCViewer_ViewPort3d.cxx b/src/OCCViewer/OCCViewer_ViewPort3d.cxx index 946378e9e..79d470ae5 100755 --- a/src/OCCViewer/OCCViewer_ViewPort3d.cxx +++ b/src/OCCViewer/OCCViewer_ViewPort3d.cxx @@ -136,6 +136,8 @@ bool OCCViewer_ViewPort3d::mapView( const Handle(V3d_View)& view ) return true; } + + /*! Sets new CASCADE view on viewport. Returns the previous active view. [ public ] */ @@ -647,3 +649,21 @@ bool OCCViewer_ViewPort3d::synchronize( OCCViewer_ViewPort* view ) return ok; } +/* + * Show/Hide static triedron + */ +void OCCViewer_ViewPort3d::updateStaticTriedronVisibility() { + OCCViewer_ViewWindow* aVW = dynamic_cast( parentWidget()->parentWidget()->parentWidget() ); + if ( aVW ) { + OCCViewer_Viewer* aViewModel = dynamic_cast( aVW->getViewManager()->getViewModel() ); + Handle(V3d_View) aView = activeView(); + if ( aViewModel ){ + if(aViewModel->isStaticTrihedronDisplayed()) { + aView->TriedronDisplay( Aspect_TOTP_LEFT_LOWER, Quantity_NOC_WHITE, 0.05, V3d_ZBUFFER ); + } else { + aView->TriedronErase(); + } + aView->Update(); + } + } +} diff --git a/src/OCCViewer/OCCViewer_ViewPort3d.h b/src/OCCViewer/OCCViewer_ViewPort3d.h index 4ea26c854..92261f9b6 100755 --- a/src/OCCViewer/OCCViewer_ViewPort3d.h +++ b/src/OCCViewer/OCCViewer_ViewPort3d.h @@ -60,6 +60,8 @@ public: virtual QString backgroundImageFilename() const; virtual void setBackgroundImage( const QString& fileName , const Aspect_FillMethod& theFillMethod); + virtual void updateStaticTriedronVisibility(); + // void setActive( V3d_TypeOfView ); virtual bool syncronize( const OCCViewer_ViewPort3d* ); diff --git a/src/SOCC/SOCC_ViewModel.cxx b/src/SOCC/SOCC_ViewModel.cxx index e921d2165..89beb3b1c 100755 --- a/src/SOCC/SOCC_ViewModel.cxx +++ b/src/SOCC/SOCC_ViewModel.cxx @@ -385,7 +385,7 @@ void SOCC_Viewer::Display( const SALOME_OCCPrs* prs ) { Handle(AIS_Trihedron) aTrh = Handle(AIS_Trihedron)::DownCast( anAIS ); double aNewSize = 100, aSize = 100; - getTrihedronSize( aNewSize, aSize ); + computeTrihedronSize( aNewSize, aSize ); aTrh->SetSize( aTrh == getTrihedron() ? aNewSize : 0.5 * aNewSize ); } @@ -428,6 +428,7 @@ void SOCC_Viewer::Display( const SALOME_OCCPrs* prs ) ic->Deactivate( anAIS ); } } + updateTrihedron(); } @@ -479,6 +480,7 @@ void SOCC_Viewer::Erase( const SALOME_OCCPrs* prs, const bool forced ) //} } } + updateTrihedron(); } @@ -527,8 +529,9 @@ void SOCC_Viewer::EraseAll( const bool forced ) // } //} } - + Repaint(); + updateTrihedron(); } /*! @@ -619,53 +622,6 @@ void SOCC_Viewer::GlobalSelection( const bool update ) const } } -/*! - Get new and current trihedron size corresponding to the current model size -*/ -bool SOCC_Viewer::getTrihedronSize( double& theNewSize, double& theSize ) -{ - theNewSize = 100; - theSize = 100; - - //SRN: BUG IPAL8996, a usage of method ActiveView without an initialization - Handle(V3d_Viewer) viewer = getViewer3d(); - viewer->InitActiveViews(); - if(!viewer->MoreActiveViews()) return false; - - Handle(V3d_View) view3d = viewer->ActiveView(); - //SRN: END of fix - - if ( view3d.IsNull() ) - return false; - - double Xmin = 0, Ymin = 0, Zmin = 0, Xmax = 0, Ymax = 0, Zmax = 0; - double aMaxSide; - - view3d->View()->MinMaxValues( Xmin, Ymin, Zmin, Xmax, Ymax, Zmax ); - - if ( Xmin == RealFirst() || Ymin == RealFirst() || Zmin == RealFirst() || - Xmax == RealLast() || Ymax == RealLast() || Zmax == RealLast() ) - return false; - - aMaxSide = Xmax - Xmin; - if ( aMaxSide < Ymax -Ymin ) aMaxSide = Ymax -Ymin; - if ( aMaxSide < Zmax -Zmin ) aMaxSide = Zmax -Zmin; - - // IPAL21687 - // The boundary box of the view may be initialized but nullified - // (case of infinite objects) - if ( aMaxSide < Precision::Confusion() ) - return false; - - float aSizeInPercents = SUIT_Session::session()->resourceMgr()->doubleValue("Viewer","TrihedronSize", 105.); - - static float EPS = 5.0E-3; - theSize = getTrihedron()->Size(); - theNewSize = aMaxSide*aSizeInPercents / 100.0; - - return fabs( theNewSize - theSize ) > theSize * EPS || - fabs( theNewSize - theSize) > theNewSize * EPS; -} /*! \Collect objects visible in viewer diff --git a/src/SOCC/SOCC_ViewModel.h b/src/SOCC/SOCC_ViewModel.h index c089dfcf6..0d77fcb03 100755 --- a/src/SOCC/SOCC_ViewModel.h +++ b/src/SOCC/SOCC_ViewModel.h @@ -67,9 +67,6 @@ public: virtual void GetVisible( SALOME_ListIO& ); virtual void Repaint(); - // a utility function, used by SALOME_View_s methods - bool getTrihedronSize( double& theNewSize, double& theSize ); - //a map to store AIS objects associated to a SALOME entry std::map< std::string , std::vector > entry2aisobjects; };