]> SALOME platform Git repositories - modules/gui.git/commitdiff
Salome HOME
Implementation of the "21317: EDF 1614 ALL: Trihedron size preference" issue.
authorrnv <rnv@opencascade.com>
Mon, 3 Oct 2011 13:22:02 +0000 (13:22 +0000)
committerrnv <rnv@opencascade.com>
Mon, 3 Oct 2011 13:22:02 +0000 (13:22 +0000)
doc/salome/gui/images/pref12.png
doc/salome/gui/input/salome_preferences.doc
src/LightApp/LightApp_Application.cxx
src/LightApp/resources/LightApp.xml
src/OCCViewer/OCCViewer_ViewManager.cxx
src/OCCViewer/OCCViewer_ViewModel.cxx
src/OCCViewer/OCCViewer_ViewModel.h
src/OCCViewer/OCCViewer_ViewPort3d.cxx
src/OCCViewer/OCCViewer_ViewPort3d.h
src/SOCC/SOCC_ViewModel.cxx
src/SOCC/SOCC_ViewModel.h

index 94e04818ecea641847c0351dfd90a9e484b9aa9f..e7f696fea7c53a51ef9ac43cd49479a699112834 100755 (executable)
Binary files a/doc/salome/gui/images/pref12.png and b/doc/salome/gui/images/pref12.png differ
index d72507dffaf5862b11532b864f5124c42e05cc01..920183e0f8a353505262a2d5b389c6be9759df3e 100644 (file)
@@ -90,6 +90,8 @@ dialog box press the &quot;<b>...</b>&quot; button(see the picture below).
 - <b>OCC Viewer 3d</b>
   - <b>Trihedron size</b> - this submenu allows to set the size of
   coordinate axes displayed in the viewer.
+    - <b>Relative size</b> - if checked in, trihedron axes scale to fit the
+    size of the area displayed in 3D Viewer.
   - <b>Navigation</b> - this option allows to choose one of the
   modes of work with mouse in OCC and VTK 3D viewers.
     - <b>Salome Standard Controls</b> - allows to manipulate objects in the
@@ -112,6 +114,8 @@ dialog box press the &quot;<b>...</b>&quot; button(see the picture below).
     relatively to its center.
     - <b>Relative to the cursor</b> - allows to zoom the view
     relatively to the current cursor position.
+  - <b>Show static trihedron</b> - allows to show/hide the static trihedron
+  located in the bottom-left corner of the viewer.
 - <b>VTK Viewer 3d</b>
   - <b>Projection mode</b> - allows choosing between \b Orthogonal and
   \b Perspective projection mode.
index f79040d064c132b279b319cd46fdb41c9a665b85..d6fc2e5517ee3a510ceef5473dfe4efb3723c58b 100644 (file)
@@ -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<SUIT_ViewManager*> lst;
     viewManagers( OCCViewer_Viewer::Type(), lst );
     QListIterator<SUIT_ViewManager*> 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<SUIT_ViewManager*> lst;
+    viewManagers( OCCViewer_Viewer::Type(), lst );
+    QListIterator<SUIT_ViewManager*> it( lst );
+    while ( it.hasNext() )
+    {
+      SUIT_ViewModel* vm = it.next()->getViewModel();
+      if ( !vm || !vm->inherits( "OCCViewer_Viewer" ) )
+        continue;
+
+      OCCViewer_Viewer* occVM = dynamic_cast<OCCViewer_Viewer*>( vm );
+      if( occVM )
+      {
+        occVM->setStaticTrihedronDisplayed( isVisible );
+      }
+    }
+  }
+#endif
+
 #ifndef DISABLE_OCCVIEWER
   if ( sec == QString( "OCCViewer" ) && param == QString( "navigation_mode" ) )
   {
index 58aed5a52dc972c605a6b1f0479d5e2fe79a7068..3bb43ac566470f9fea86607493477316f6cb6560 100644 (file)
     <parameter name="trihedron_size" value="100" />
     <parameter name="navigation_mode" value="0" />
     <parameter name="zooming_mode"   value="0" />
+    <parameter name="show_static_trihedron" value="true"/>
+    <parameter name="relative_size"                    value="true"/>    
  </section>
  <section name="VTKViewer" >
     <!-- VTK viewer preferences -->
index 9e186e87c8bc247a220fc191f6a01adf10292ceb..f8344d108dd0ea380610142ae4fe2bd4452b199c 100755 (executable)
@@ -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" ) );
 }
 
index 35c81ac3f2f6e6649faecd543d93aa6891ae2407..25709f0a4fab0245d63bd36d193de35d6dfdd0cd 100755 (executable)
@@ -29,6 +29,7 @@
 #include "SUIT_ViewManager.h"
 #include "SUIT_Desktop.h"
 #include "SUIT_Session.h"
+#include "SUIT_ResourceMgr.h"
 
 #include "QtxActionToolMgr.h"
 
 #include <Prs3d_AngleAspect.hxx>
 #include <Prs3d_TextAspect.hxx>
 
+#include <Visual3d_View.hxx>
+
 /*!
   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);
+  }
+}
index 4e27361eedca8434a0a65fc53d06b86f6478efc8..8f08f28c6efe36b9b696f17d7605151744e7d3c4 100755 (executable)
@@ -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<QColor>                 myColors;
 };
 
index 946378e9efbc515bb0aa857b4685f911a5ba06c1..79d470ae5afe8837940d208ae3c60daa05b37270 100755 (executable)
@@ -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<OCCViewer_ViewWindow*>( parentWidget()->parentWidget()->parentWidget() );
+  if ( aVW ) {
+    OCCViewer_Viewer* aViewModel = dynamic_cast<OCCViewer_Viewer*>( 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();
+    }
+  } 
+}
index 4ea26c854d3b406179bcb44c90ee994e467ea0ae..92261f9b687f9cb100ba264d54dc624eb1c0c9b3 100755 (executable)
@@ -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* );
 
index e921d21659e3eeb29ae7703e8ea00f054a3fa1e1..89beb3b1c68a1e0e0d284af9ef0bc0046421f0da 100755 (executable)
@@ -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
index c089dfcf6b90947acf5833255d568e91626ee29a..0d77fcb030edc1dc6a5ccc6afb32db0c07f948a6 100755 (executable)
@@ -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<Handle(AIS_InteractiveObject)> > entry2aisobjects;
 };