]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
Set 2d mode for OCC viewer.
authornds <nds@opencascade.com>
Thu, 28 Nov 2013 14:26:20 +0000 (14:26 +0000)
committernds <nds@opencascade.com>
Thu, 28 Nov 2013 14:26:20 +0000 (14:26 +0000)
src/HYDROCurveCreator/CMakeLists.txt
src/HYDROCurveCreator/CurveCreator_Widget.cxx
src/HYDROCurveCreator/OCCViewer_Utilities.cxx [new file with mode: 0644]
src/HYDROCurveCreator/OCCViewer_Utilities.h [new file with mode: 0644]
src/HYDROGUI/HYDROGUI_Module.cxx
src/HYDROGUI/HYDROGUI_Tool.cxx
src/HYDROGUI/HYDROGUI_Tool.h

index ee2a4c9e92f823832e8ce13d2f9274a265d3e680..679e6ab098c6184b2fcfb4226b40c2a48d2bbe76 100644 (file)
@@ -62,6 +62,7 @@ IF(SALOME_BUILD_GUI)
     CurveCreator_TreeView.h
 #    CurveCreator_UndoOptsDlg.h
     CurveCreator_Widget.h
+    OCCViewer_Utilities.h
     OCCViewer_ViewWidget.h
   )
 ENDIF(SALOME_BUILD_GUI)
@@ -107,6 +108,7 @@ IF(SALOME_BUILD_GUI)
     CurveCreator_TreeView.cxx
 #    CurveCreator_UndoOptsDlg.cxx
     CurveCreator_Widget.cxx
+    OCCViewer_Utilities.cxx
     OCCViewer_ViewWidget.cxx
   )
 ENDIF(SALOME_BUILD_GUI)
index c2fb84ce44072adb6247cd0e409838a9c502afcf..7c0b180ec7d2a51c39003e0328228931423fadb5 100644 (file)
@@ -35,6 +35,7 @@
 #include <OCCViewer_ViewWindow.h>
 #include <OCCViewer_ViewManager.h>
 #include <OCCViewer_ViewPort3d.h>
+#include "OCCViewer_Utilities.h"
 
 #include <BRep_Tool.hxx>
 #include <TopoDS.hxx>
@@ -236,6 +237,8 @@ void CurveCreator_Widget::setOCCViewer( OCCViewer_Viewer* theViewer )
            this, SLOT( onMouseRelease( SUIT_ViewWindow*, QMouseEvent* ) ) );
     disconnect( aViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
            this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
+    // restore normal mode in the viewer
+    OCCViewer_Utilities::setViewer2DMode( myOCCViewer, OCCViewer_ViewWindow::No2dMode );
     // all local contexts should be closed if the viewer is not more used
     setLocalPointContext( false, true );
   }
@@ -250,6 +253,7 @@ void CurveCreator_Widget::setOCCViewer( OCCViewer_Viewer* theViewer )
            this, SLOT( onMouseRelease( SUIT_ViewWindow*, QMouseEvent* ) ) );
     connect( aViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
            this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
+    OCCViewer_Utilities::setViewer2DMode( theViewer, OCCViewer_ViewWindow::XYPlane );
   }
 }
 
diff --git a/src/HYDROCurveCreator/OCCViewer_Utilities.cxx b/src/HYDROCurveCreator/OCCViewer_Utilities.cxx
new file mode 100644 (file)
index 0000000..425179f
--- /dev/null
@@ -0,0 +1,59 @@
+
+#include "OCCViewer_Utilities.h"
+
+#include <OCCViewer_ViewFrame.h>
+#include <OCCViewer_ViewModel.h>
+#include <SUIT_ViewManager.h>
+
+#include <QtxActionToolMgr.h>
+
+#include <QAction>
+
+void OCCViewer_Utilities::setViewer2DMode( OCCViewer_Viewer* theViewer,
+                                           const OCCViewer_ViewWindow::Mode2dType& theMode )
+{
+  OCCViewer_ViewFrame* aFrame = dynamic_cast<OCCViewer_ViewFrame*>
+                                     ( theViewer->getViewManager()->getActiveView() );
+  OCCViewer_ViewWindow* aView = aFrame ? aFrame->getView( OCCViewer_ViewFrame::MAIN_VIEW ) : 0;
+  if ( !aView )
+    return;
+
+  // set a view mode
+  aView->set2dMode( theMode );
+  bool is2dMode = theMode != OCCViewer_ViewWindow::No2dMode;
+
+  // enable/disable view actions
+  QList<int> aNo2dActions;
+  aNo2dActions << OCCViewer_ViewWindow::ChangeRotationPointId
+               << OCCViewer_ViewWindow::RotationId
+               << OCCViewer_ViewWindow::FrontId
+               << OCCViewer_ViewWindow::BackId
+               << OCCViewer_ViewWindow::TopId
+               << OCCViewer_ViewWindow::BottomId
+               << OCCViewer_ViewWindow::LeftId
+               << OCCViewer_ViewWindow::RightId
+               << OCCViewer_ViewWindow::AntiClockWiseId
+               << OCCViewer_ViewWindow::ClockWiseId
+               << OCCViewer_ViewWindow::ResetId;
+
+  QtxActionToolMgr* aToolMgr = aView->toolMgr();
+  QAction* anAction;
+  for ( int i = 0, aNb = aNo2dActions.size(); i < aNb; i++ ) {
+    anAction = aToolMgr->action( aNo2dActions[i] );
+    if ( anAction )
+      anAction->setEnabled( !is2dMode );
+  }
+
+  // change view position
+  switch ( theMode ) {
+    case OCCViewer_ViewWindow::XYPlane:
+      aView->onTopView();
+      break;
+    case OCCViewer_ViewWindow::XZPlane:
+      aView->onLeftView();
+      break;
+    case OCCViewer_ViewWindow::YZPlane:
+      aView->onFrontView();
+      break;
+  }
+}
diff --git a/src/HYDROCurveCreator/OCCViewer_Utilities.h b/src/HYDROCurveCreator/OCCViewer_Utilities.h
new file mode 100644 (file)
index 0000000..c89eb45
--- /dev/null
@@ -0,0 +1,28 @@
+#ifndef OCCVIEWER_UTILITIES_H
+#define OCCVIEWER_UTILITIES_H
+
+#include "CurveCreator_Macro.hxx"
+
+#include <OCCViewer_ViewWindow.h>
+
+class OCCViewer_Viewer;
+
+#ifdef WIN32
+#pragma warning ( disable:4251 )
+#endif
+
+class CURVECREATOR_EXPORT OCCViewer_Utilities
+{
+public:
+
+  /*!
+   * Set 2D mode for the viewer. Hide or show 3D actions.
+   * \param theViewer an OCC viewer
+   * \param theMode OCC view window mode
+   */
+  static void setViewer2DMode( OCCViewer_Viewer* theViewer,
+                               const OCCViewer_ViewWindow::Mode2dType& theMode );
+
+};
+
+#endif
index c92f41b4718c3bb54e845a6e2d3c41010daadaa4..36b56ec1efd0c3c04888c8acfbbea805c2481bc8 100644 (file)
@@ -153,6 +153,8 @@ bool HYDROGUI_Module::activateModule( SUIT_Study* theStudy )
   connect( anApp, SIGNAL( operationFinished( const QString&, const QString&, const QStringList& ) ), 
            this, SLOT( onExternalOperationFinished( const QString&, const QString&, const QStringList& ) ) );
 
+  HYDROGUI_Tool::setOCCActionShown( this, OCCViewer_ViewWindow::MaximizedId, false );
+
   return aRes;
 }
 
@@ -179,6 +181,8 @@ bool HYDROGUI_Module::deactivateModule( SUIT_Study* theStudy )
   disconnect( getApp(), SIGNAL( operationFinished( const QString&, const QString&, const QStringList& ) ), 
               this, SLOT( onExternalOperationFinished( const QString&, const QString&, const QStringList& ) ) );
 
+  HYDROGUI_Tool::setOCCActionShown( this, OCCViewer_ViewWindow::MaximizedId, true );
+
   return LightApp_Module::deactivateModule( theStudy );
 }
 
@@ -987,6 +991,8 @@ void HYDROGUI_Module::onViewCreated( SUIT_ViewWindow* theViewWindow )
     if( OCCViewer_ViewFrame* aViewFrame = dynamic_cast<OCCViewer_ViewFrame*>( theViewWindow ) )
     {
       aViewFrame->onTopView();
+
+      HYDROGUI_Tool::setOCCActionShown( aViewFrame, OCCViewer_ViewWindow::MaximizedId, false );
     }
   }
 }
index 51126a3c04a9d9798fa10ce24975839f1710125a..0f2b7c2c8d93f3c07917c6cb8121ca3ee5cf4730 100644 (file)
 #include <LightApp_SelectionMgr.h>
 
 #include <OCCViewer_ViewModel.h>
+#include <OCCViewer_ViewFrame.h>
 
 #include <QtxWorkstack.h>
+#include <QtxActionToolMgr.h>
 
 #include <STD_TabDesktop.h>
 
@@ -461,6 +463,41 @@ QList<size_t> HYDROGUI_Tool::GetOCCViewIdList( HYDROGUI_Module* theModule )
   return getViewIdList( theModule, OCCViewer_Viewer::Type() );
 }
 
+void HYDROGUI_Tool::setOCCActionShown( OCCViewer_ViewFrame* theViewFrame,
+                                       const int theActionId,
+                                       const bool isShown )
+{
+  if ( !theViewFrame )
+    return;
+
+  OCCViewer_ViewWindow* aView = theViewFrame->getView( OCCViewer_ViewFrame::MAIN_VIEW );
+  if ( aView ) {
+    aView->toolMgr()->setShown( theActionId, isShown );
+    if ( theActionId == OCCViewer_ViewWindow::MaximizedId )
+      theViewFrame->onMaximizedView( aView, true );
+  }
+}
+
+void HYDROGUI_Tool::setOCCActionShown( HYDROGUI_Module* theModule,
+                                       const int theActionId,
+                                       const bool isShown )
+{
+  QList<size_t> aList;
+  ViewManagerList aViewMgrs;
+  theModule->getApp()->viewManagers( OCCViewer_Viewer::Type(), aViewMgrs );
+  QListIterator<SUIT_ViewManager*> anIter( aViewMgrs );
+  while( anIter.hasNext() )
+  {
+    if( SUIT_ViewManager* aViewMgr = anIter.next() )
+    {
+      OCCViewer_ViewFrame* aViewFrame = dynamic_cast<OCCViewer_ViewFrame*>
+                                                           ( aViewMgr->getActiveView() );
+      if ( aViewFrame )
+        setOCCActionShown( aViewFrame, theActionId, isShown );
+    }
+  }
+}
+
 void HYDROGUI_Tool::GetObjectReferences( const Handle(HYDROData_Image)& theImage,
                                          HYDROData_SequenceOfObjects& theRefObjects,
                                          QStringList& theRefNames )
index 7a77b3af51efe00c0ca0c58a53ade409b7e6b32b..ec6f207528ff16b7837708f1a2f9335c718a172f 100644 (file)
@@ -34,6 +34,7 @@
 #include <TCollection_HExtendedString.hxx>
 
 class SUIT_ViewManager;
+class OCCViewer_ViewFrame;
 
 class HYDROGUI_DataModel;
 class HYDROGUI_Module;
@@ -240,6 +241,26 @@ public:
    */
   static QList<size_t>            GetOCCViewIdList( HYDROGUI_Module* theModule );
 
+
+  /**
+   * \brief Change OCC viewer action visibility.
+   * \param theViewFrame OCC viewer frame
+   * \param theActionId an action index, which state should be changed
+   * \param isShown the action visibility state
+   */
+  static void                     setOCCActionShown( OCCViewer_ViewFrame* theViewFrame,
+                                                     const int theActionId,
+                                                     const bool isShown );
+
+  /**
+   * \brief Change OCC viewer action visibility for all opened views.
+   * \param theActionId an action index, which state should be changed
+   * \param isShown the action visibility state
+   */
+  static void                     setOCCActionShown( HYDROGUI_Module* theModule,
+                                                     const int theActionId,
+                                                     const bool isShown );
+
   /**
    * \brief Get the list of references (recursively) for the specified image object
    * \param theImage image data object