]> SALOME platform Git repositories - modules/gui.git/commitdiff
Salome HOME
Copy utilities from GEOM module
authorskv <skv@opencascade.com>
Mon, 8 Sep 2014 10:13:26 +0000 (14:13 +0400)
committerskv <skv@opencascade.com>
Mon, 8 Sep 2014 10:13:26 +0000 (14:13 +0400)
src/OCCViewer/CMakeLists.txt
src/OCCViewer/OCCViewer_Utilities.cxx [new file with mode: 0644]
src/OCCViewer/OCCViewer_Utilities.h [new file with mode: 0644]

index de1434512b49f4ef916ac6fd542115c0e5747c71..a7cc4289c97b762e21f19a14615f9c0e5d21ab25 100755 (executable)
@@ -76,6 +76,7 @@ SET(_other_HEADERS
   OCCViewer.h
   OCCViewer_ClipPlane.h
   OCCViewer_Trihedron.h 
+  OCCViewer_Utilities.h
   OCCViewer_VService.h
 )
 
@@ -152,6 +153,7 @@ SET(_other_SOURCES
   OCCViewer_SetRotationPointDlg.cxx
   OCCViewer_ToolTip.cxx
   OCCViewer_Trihedron.cxx
+  OCCViewer_Utilities.cxx
   OCCViewer_VService.cxx
   OCCViewer_ViewFrame.cxx
   OCCViewer_ViewManager.cxx
diff --git a/src/OCCViewer/OCCViewer_Utilities.cxx b/src/OCCViewer/OCCViewer_Utilities.cxx
new file mode 100644 (file)
index 0000000..1fe25f4
--- /dev/null
@@ -0,0 +1,64 @@
+
+#include "OCCViewer_Utilities.h"
+#include "OCCViewer_ViewFrame.h"
+#include "OCCViewer_ViewModel.h"
+#include "OCCViewer_ViewPort3d.h"
+
+#include "SUIT_ViewManager.h"
+#include "QtxActionToolMgr.h"
+
+#include <V3d_View.hxx>
+
+#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
+  Handle(V3d_View) aView3d = aView->getViewPort()->getView();
+  if ( !aView3d.IsNull() ) {
+    switch ( theMode ) {
+      case OCCViewer_ViewWindow::XYPlane:
+        aView3d->SetProj (V3d_Zpos);
+        break;
+      case OCCViewer_ViewWindow::XZPlane:
+        aView3d->SetProj (V3d_Yneg);
+        break;
+      case OCCViewer_ViewWindow::YZPlane:
+        aView3d->SetProj (V3d_Xpos);
+        break;
+    }
+  }
+}
diff --git a/src/OCCViewer/OCCViewer_Utilities.h b/src/OCCViewer/OCCViewer_Utilities.h
new file mode 100644 (file)
index 0000000..8460f3c
--- /dev/null
@@ -0,0 +1,27 @@
+#ifndef OCCVIEWER_UTILITIES_H
+#define OCCVIEWER_UTILITIES_H
+
+#include "OCCViewer.h"
+#include "OCCViewer_ViewWindow.h"
+
+class OCCViewer_Viewer;
+
+#ifdef WIN32
+#pragma warning ( disable:4251 )
+#endif
+
+class OCCVIEWER_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