]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Issue #2922: Set viewer normally to selected face
authorvsv <vsv@opencascade.com>
Thu, 20 Jun 2019 14:54:56 +0000 (17:54 +0300)
committervsv <vsv@opencascade.com>
Thu, 20 Jun 2019 14:54:56 +0000 (17:54 +0300)
src/XGUI/XGUI_ContextMenuMgr.cpp
src/XGUI/XGUI_Workshop.cpp
src/XGUI/XGUI_Workshop.h
src/XGUI/XGUI_pictures.qrc
src/XGUI/pictures/normal-view-inversed.png [new file with mode: 0644]
src/XGUI/pictures/normal-view.png [new file with mode: 0644]

index c48b8a8ef7c12ce1525b71662db4351392b2f3bc..55006b4281b08d56ed0018b9884eacf54d72535e 100644 (file)
@@ -144,32 +144,25 @@ void XGUI_ContextMenuMgr::createActions()
   mySeparator3 = ModuleBase_Tools::createAction(QIcon(), "", aDesktop);
   mySeparator3->setSeparator(true);
 
-  //mySelectActions = new QActionGroup(this);
-  //mySelectActions->setExclusive(true);
-
   aAction = ModuleBase_Tools::createAction(QIcon(":pictures/vertex.png"), tr("Vertices"), aDesktop,
                                            this, SLOT(onShapeSelection(bool)));
   aAction->setCheckable(true);
   addAction("SELECT_VERTEX_CMD", aAction);
-  //mySelectActions->addAction(aAction);
 
   aAction = ModuleBase_Tools::createAction(QIcon(":pictures/edge.png"), tr("Edges"), aDesktop,
                                            this, SLOT(onShapeSelection(bool)));
   aAction->setCheckable(true);
   addAction("SELECT_EDGE_CMD", aAction);
-  //mySelectActions->addAction(aAction);
 
   aAction = ModuleBase_Tools::createAction(QIcon(":pictures/face.png"), tr("Faces"), aDesktop,
                                            this, SLOT(onShapeSelection(bool)));
   aAction->setCheckable(true);
   addAction("SELECT_FACE_CMD", aAction);
-  //mySelectActions->addAction(aAction);
 
   aAction = ModuleBase_Tools::createAction(QIcon(":pictures/result.png"), tr("Results"), aDesktop,
                                            this, SLOT(onResultSelection(bool)));
   aAction->setCheckable(true);
   addAction("SELECT_RESULT_CMD", aAction);
-  //mySelectActions->addAction(aAction);
 
   aAction->setChecked(true);
 
@@ -207,6 +200,14 @@ void XGUI_ContextMenuMgr::createActions()
                                            tr("Move out after the folder"), aDesktop);
   addAction("ADD_OUT_FOLDER_AFTER_CMD", aAction);
 
+  aAction = ModuleBase_Tools::createAction(QIcon(":pictures/normal-view-inversed.png"),
+                                           tr("Set view by inverted normal to face"), aDesktop);
+  addAction("SET_VIEW_INVERTEDNORMAL_CMD", aAction);
+
+  aAction = ModuleBase_Tools::createAction(QIcon(":pictures/normal-view.png"),
+                                           tr("Set view by normal to face"), aDesktop);
+  addAction("SET_VIEW_NORMAL_CMD", aAction);
+
   buildObjBrowserMenu();
   buildViewerMenu();
 }
@@ -500,16 +501,22 @@ void XGUI_ContextMenuMgr::updateViewerMenu()
     bool isVisible = false;
     bool isShading = false;
     bool canBeShaded = false;
+    bool hasPlanar = false;
     ObjectPtr aObject;
     foreach(ModuleBase_ViewerPrsPtr aPrs, aPrsList) {
       aObject = aPrs->object();
+      GeomShapePtr aShape = aPrs->shape();
       ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(aObject);
       if (aRes && aRes->isDisplayed()) {
         isVisible = true;
         canBeShaded = myWorkshop->displayer()->canBeShaded(aObject);
         isShading =
           (myWorkshop->displayer()->displayMode(aObject) == XGUI_Displayer::Shading);
-        break;
+      }
+      if (aShape.get()) {
+        if (aShape->isPlanar()) {
+          hasPlanar = true;
+        }
       }
     }
     if (isVisible) {
@@ -527,6 +534,9 @@ void XGUI_ContextMenuMgr::updateViewerMenu()
       action("HIDE_CMD")->setEnabled(true);
     } else
       action("SHOW_CMD")->setEnabled(true);
+
+    action("SET_VIEW_NORMAL_CMD")->setEnabled(hasPlanar);
+    action("SET_VIEW_INVERTEDNORMAL_CMD")->setEnabled(hasPlanar);
   }
   //issue #2159 Hide all incomplete behavior
 #ifdef HAVE_SALOME
@@ -679,12 +689,15 @@ void XGUI_ContextMenuMgr::buildViewerMenu()
 {
   QActionsList aList;
   // Result construction menu
-  aList.append(action("HIDE_CMD"));
-  aList.append(action("SHOW_ONLY_CMD"));
-  aList.append(mySeparator1);
   aList.append(action("COLOR_CMD"));
   aList.append(action("DEFLECTION_CMD"));
   aList.append(action("TRANSPARENCY_CMD"));
+  aList.append(mySeparator3);
+  aList.append(action("SET_VIEW_NORMAL_CMD"));
+  aList.append(action("SET_VIEW_INVERTEDNORMAL_CMD"));
+  aList.append(mySeparator1);
+  aList.append(action("SHOW_ONLY_CMD"));
+  aList.append(action("HIDE_CMD"));
   myViewerMenu[ModelAPI_ResultConstruction::group()] = aList;
   // Result part menu
   myViewerMenu[ModelAPI_ResultPart::group()] = aList;
@@ -693,13 +706,16 @@ void XGUI_ContextMenuMgr::buildViewerMenu()
   aList.clear();
   aList.append(action("WIREFRAME_CMD"));
   aList.append(action("SHADING_CMD"));
-  aList.append(mySeparator1);
-  aList.append(action("HIDE_CMD"));
-  aList.append(action("SHOW_ONLY_CMD"));
   aList.append(mySeparator2);
   aList.append(action("COLOR_CMD"));
   aList.append(action("DEFLECTION_CMD"));
   aList.append(action("TRANSPARENCY_CMD"));
+  aList.append(mySeparator3);
+  aList.append(action("SET_VIEW_NORMAL_CMD"));
+  aList.append(action("SET_VIEW_INVERTEDNORMAL_CMD"));
+  aList.append(mySeparator1);
+  aList.append(action("SHOW_ONLY_CMD"));
+  aList.append(action("HIDE_CMD"));
   myViewerMenu[ModelAPI_ResultBody::group()] = aList;
   // Group menu
   myViewerMenu[ModelAPI_ResultGroup::group()] = aList;
@@ -790,14 +806,15 @@ void XGUI_ContextMenuMgr::addViewerMenu(QMenu* theMenu) const
         aActions = myViewerMenu[aName];
     }
   } else if (aSelected > 1) {
+    aActions.append(action("COLOR_CMD"));
+    aActions.append(action("DEFLECTION_CMD"));
+    aActions.append(action("TRANSPARENCY_CMD"));
+    aActions.append(mySeparator1);
     aActions.append(action("SHOW_ONLY_CMD"));
     aActions.append(action("HIDE_CMD"));
   }
   // hide all is shown always even if selection in the viewer is empty
   aActions.append(action("HIDEALL_CMD"));
-  aActions.append(action("COLOR_CMD"));
-  aActions.append(action("DEFLECTION_CMD"));
-  aActions.append(action("TRANSPARENCY_CMD"));
   theMenu->addActions(aActions);
 
   QMap<int, QAction*> aMenuActions;
index 6a3e370350bec353c9ec482f364bd304b566ca44..1f5794a970fddc2ecfe07c912387e65f5dc45ed2 100644 (file)
@@ -86,6 +86,8 @@
 #include <Events_InfoMessage.h>
 #include <Events_LongOp.h>
 
+#include <GeomAPI_Pnt.h>
+
 #include <ModuleBase_IModule.h>
 #include <ModuleBase_IViewer.h>
 #include <ModuleBase_Operation.h>
@@ -1630,6 +1632,10 @@ void XGUI_Workshop::onContextMenuCommand(const QString& theId, bool isChecked)
     highlightResults(aObjects);
   } else if (theId == "SHOW_FEATURE_CMD") {
     highlightFeature(aObjects);
+  } else if (theId == "SET_VIEW_NORMAL_CMD") {
+    setNormalView();
+  } else if (theId == "SET_VIEW_INVERTEDNORMAL_CMD") {
+    setNormalView(true);
   }
 #ifdef TINSPECTOR
   else if (theId == "TINSPECTOR_VIEW") {
@@ -2533,6 +2539,40 @@ void XGUI_Workshop::showOnlyObjects(const QObjectPtrList& theList)
   myObjectBrowser->updateAllIndexes();
 }
 
+//**************************************************************
+void XGUI_Workshop::setNormalView(bool toInvert)
+{
+  QList<ModuleBase_ViewerPrsPtr> aPrsList =
+    mySelector->selection()->getSelected(ModuleBase_ISelection::Viewer);
+  GeomShapePtr aPlanarFace;
+  foreach(ModuleBase_ViewerPrsPtr aPrs, aPrsList) {
+    GeomShapePtr aShape = aPrs->shape();
+    if (aShape.get() && aShape->isPlanar()) {
+      aPlanarFace = aShape;
+      break;
+    }
+  }
+  if (aPlanarFace.get()) {
+    GeomFacePtr aFace(new GeomAPI_Face(aPlanarFace));
+    GeomPlanePtr aPlane = aFace->getPlane();
+    GeomDirPtr aNormal = aPlane->direction();
+    if (toInvert)
+      aNormal->reverse();
+    GeomPointPtr aPos = aPlane->location();
+
+    double aXmin, aYmin, aZmin, aXmax, aYmax, aZmax;
+    aFace->computeSize(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax);
+
+    Handle(V3d_View) aView = myViewerProxy->activeView();
+    double aScale = aView->Scale();
+    aView->SetAt(aPos->x(), aPos->y(), aPos->z());
+    aView->SetProj(aNormal->x(), aNormal->y(), aNormal->z());
+    Bnd_Box aBox;
+    aBox.Update(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax);
+    aView->FitAll(aBox);
+  }
+}
+
 //**************************************************************
 void XGUI_Workshop::registerValidators() const
 {
index 525d99ae9bb237f525bb5f2fe42b3605fe1a272e..50f266eeef7d26b2945efaf0c3abe545891b8145 100644 (file)
@@ -516,6 +516,10 @@ private:
   /// Clear content of temporary directory
   void clearTemporaryDir();
 
+  /// Set current point of view normal to selected planar face
+  /// \param toInvert invert the normal vector
+  void setNormalView(bool toInvert = false);
+
 private:
 #ifndef HAVE_SALOME
   AppElements_MainWindow* myMainWindow; ///< desktop window
index 4520529f1d7589cc97492240e2d63ce8e59c722e..2e088049613466b3ac2faddf9a58d61b66706b8b 100644 (file)
@@ -84,5 +84,7 @@
      <file>pictures/arrow-down.png</file>
      <file>pictures/configure_toolbars.png</file>
      <file>pictures/color.png</file>
+     <file>pictures/normal-view-inversed.png</file>
+     <file>pictures/normal-view.png</file>
  </qresource>
  </RCC>
diff --git a/src/XGUI/pictures/normal-view-inversed.png b/src/XGUI/pictures/normal-view-inversed.png
new file mode 100644 (file)
index 0000000..078ec14
Binary files /dev/null and b/src/XGUI/pictures/normal-view-inversed.png differ
diff --git a/src/XGUI/pictures/normal-view.png b/src/XGUI/pictures/normal-view.png
new file mode 100644 (file)
index 0000000..9b39078
Binary files /dev/null and b/src/XGUI/pictures/normal-view.png differ