]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
[bos #29479] Show edges directions CR29479
authorvsv <vsv@opencascade.com>
Thu, 9 Jun 2022 08:52:13 +0000 (11:52 +0300)
committervsv <vsv@opencascade.com>
Thu, 9 Jun 2022 08:52:13 +0000 (11:52 +0300)
Optimize visualization

src/ModuleBase/CMakeLists.txt
src/ModuleBase/ModuleBase_ResultPrs.cpp
src/ModuleBase/ModuleBase_ResultPrs.h
src/XGUI/XGUI_ContextMenuMgr.cpp
src/XGUI/XGUI_Displayer.cpp
src/XGUI/XGUI_Selection.cpp
src/XGUI/XGUI_Workshop.cpp
src/XGUI/XGUI_Workshop.h
src/XGUI/XGUI_pictures.qrc
src/XGUI/pictures/edges_dir.png [new file with mode: 0644]

index 84bf06cd3ca2082767f05cc44775958cd211f336..e4161f97b44472f7a0219025dda03d7dfff02e53 100644 (file)
@@ -65,7 +65,6 @@ SET(PROJECT_HEADERS
   ModuleBase_ParamSpinBox.h
   ModuleBase_Preferences.h
   ModuleBase_ResultPrs.h
-  ModuleBase_ArrowPrs.h
   ModuleBase_SelectionValidator.h
   ModuleBase_ToolBox.h
   ModuleBase_Tools.h
@@ -191,7 +190,6 @@ SET(PROJECT_SOURCES
   ModuleBase_ParamSpinBox.cpp
   ModuleBase_Preferences.cpp
   ModuleBase_ResultPrs.cpp
-  ModuleBase_ArrowPrs.cpp
   ModuleBase_ToolBox.cpp
   ModuleBase_Tools.cpp
   ModuleBase_ViewerFilters.cpp
index 81f55c806dc748ad9ba66cffd6f10a535e1fa300..ccba3a2071f008092dd64616e85add91ddb700c8 100644 (file)
 #include <StdPrs_ShadedShape.hxx>
 #include <StdSelect_BRepSelectionTool.hxx>
 #include <TColStd_ListIteratorOfListOfInteger.hxx>
-#include <TopExp.hxx>
 #include <TopExp_Explorer.hxx>
 #include <TopoDS.hxx>
 #include <TopoDS_Builder.hxx>
 #include <TopoDS_Edge.hxx>
 #include <BRepMesh_IncrementalMesh.hxx>
 #include <Standard_Version.hxx>
+#include <Prs3d_Arrow.hxx>
+#include <GeomAdaptor_Curve.hxx>
+#include <TopExp.hxx>
+#include <GCPnts_AbscissaPoint.hxx>
 
 #if OCC_VERSION_HEX > 0x070400
 #include <StdPrs_ToolTriangulatedShape.hxx>
@@ -297,11 +300,53 @@ void ModuleBase_ResultPrs::Compute(
   // change deviation coefficient to provide more precise circle
   try {
     AIS_Shape::Compute(thePresentationManager, thePresentation, theMode);
-    AddRemoveEdgesDir(GetContext()->CurrentViewer());
   }
   catch (...) {
     return;
   }
+  if (myResult.get() && ModelAPI_Tools::isShowEdgesDirection(myResult))
+  {
+    TopExp_Explorer Exp(myshape, TopAbs_EDGE);
+    for (; Exp.More(); Exp.Next()) {
+      TopoDS_Edge anEdgeE = TopoDS::Edge(Exp.Current());
+      if (anEdgeE.IsNull())
+        continue;
+
+      // draw curve direction (issue 0021087)
+      anEdgeE.Orientation(TopAbs_FORWARD);
+
+      TopoDS_Vertex aV1, aV2;
+      TopExp::Vertices(anEdgeE, aV1, aV2);
+      gp_Pnt aP1 = BRep_Tool::Pnt(aV1);
+      gp_Pnt aP2 = BRep_Tool::Pnt(aV2);
+
+      double fp, lp;
+      gp_Vec aDirVec;
+      Handle(Geom_Curve) C = BRep_Tool::Curve(anEdgeE, fp, lp);
+
+      if (C.IsNull()) continue;
+
+      if (anEdgeE.Orientation() == TopAbs_FORWARD)
+        C->D1(lp, aP2, aDirVec);
+      else {
+        C->D1(fp, aP1, aDirVec);
+        aP2 = aP1;
+      }
+      GeomAdaptor_Curve aAdC;
+      aAdC.Load(C, fp, lp);
+      Standard_Real aDist = GCPnts_AbscissaPoint::Length(aAdC, fp, lp);
+
+      if (aDist > gp::Resolution()) {
+        gp_Dir aDir;
+        if (anEdgeE.Orientation() == TopAbs_FORWARD)
+          aDir = aDirVec;
+        else
+          aDir = -aDirVec;
+
+        Prs3d_Arrow::Draw(thePresentation->CurrentGroup(), aP2, aDir, M_PI / 180.*5., aDist / 10.);
+      }
+    }
+  }
 
   // visualize hidden sub-shapes transparent
   if (myResult.get()) {
@@ -540,49 +585,3 @@ void ModuleBase_ResultPrs::updateIsoLines()
   myUIsoAspect->SetNumber(aIsoValues[0]);
   myVIsoAspect->SetNumber(aIsoValues[1]);
 }
-
-bool ModuleBase_ResultPrs::AddRemoveEdgesDir(const Handle(V3d_Viewer)& theViewer)
-{
-  bool isShow = ModelAPI_Tools::isShowEdgesDirection(myResult);
-  if (isShow) {
-    std::list<GeomShapePtr> aSubEdges = myResult->shape()->subShapes(GeomAPI_Shape::EDGE);
-
-    for (auto anEdgeIter = aSubEdges.begin(); anEdgeIter != aSubEdges.end(); ++anEdgeIter) {
-      GeomEdgePtr anEdgePtr = (*anEdgeIter)->edge();
-      if (myEdgesDirection.find(anEdgePtr) != myEdgesDirection.end()) {
-        myEdgesDirection.at(anEdgePtr)->DrawArrow(Presentation(), Quantity_NOC_BLACK);
-      }
-      else {
-        Handle(ModuleBase_ArrowPrs) anArrowPrs = new ModuleBase_ArrowPrs(theViewer, anEdgePtr);
-        myEdgesDirection.insert(EdgeDirection(anEdgePtr, anArrowPrs));
-        anArrowPrs->DrawArrow(Presentation(), Quantity_NOC_BLACK);
-      }
-    }
-  }
-  else
-    myEdgesDirection.clear();
-
-  GetContext()->UpdateCurrentViewer();
-  return isShow;
-}
-
-Standard_EXPORT void ModuleBase_ResultPrs::UpdateEdgesDir()
-{
-  TopoDS_Shape aSelectedShape = GetContext()->SelectedShape();
-  for (auto anEdgeDir = myEdgesDirection.begin(); anEdgeDir != myEdgesDirection.end(); ++anEdgeDir) {
-    TopoDS_Edge anEdge = anEdgeDir->first->impl<TopoDS_Edge>();
-    bool isSelect = false;
-    TopExp_Explorer Exp(aSelectedShape, TopAbs_EDGE);
-    for (; Exp.More(); Exp.Next()) {
-      if (TopoDS::Edge(Exp.Current()).IsSame(anEdge)) {
-        isSelect = true;
-        break;
-      }
-    }
-    if(isSelect)
-      anEdgeDir->second->DrawArrow(Presentation(), Quantity_NOC_WHITE);
-    else
-      anEdgeDir->second->DrawArrow(Presentation(), Quantity_NOC_BLACK);
-  }
-  GetContext()->UpdateCurrentViewer();
-}
index 5eddec23cb20587e85680376f156d44c86701a9b..5607c2bb08437a54cc6c4e1ee6b24326916a3fd6 100644 (file)
@@ -22,8 +22,6 @@
 
 #include "ModuleBase.h"
 
-#include "ModuleBase_ArrowPrs.h"
-
 #include <ModelAPI_Result.h>
 #include <ModelAPI_ResultField.h>
 
@@ -123,10 +121,6 @@ public:
 
   Standard_EXPORT void updateIsoLines();
 
-  Standard_EXPORT bool AddRemoveEdgesDir(const Handle(V3d_Viewer)& theViewer);
-
-  Standard_EXPORT void UpdateEdgesDir();
-
   DEFINE_STANDARD_RTTIEXT(ModuleBase_ResultPrs, ViewerData_AISShape)
 
 protected:
@@ -184,9 +178,6 @@ private:
 
   Handle(Prs3d_IsoAspect) myUIsoAspect;
   Handle(Prs3d_IsoAspect) myVIsoAspect;
-
-
-  EdgesDirectionMap myEdgesDirection;
 };
 
 
index 97e58c22f5b2ee694df83e66124d1bcaf6d89122..e42131d55865497631ec136d9cc1000517deb9ba 100644 (file)
@@ -157,14 +157,15 @@ void XGUI_ContextMenuMgr::createActions()
                                            aDesktop);
   addAction("WIREFRAME_CMD", anAction);
 
-  anAction = ModuleBase_Tools::createAction(QIcon(":pictures/iso_lines.png"), tr("Define Isos..."),
+  anAction = ModuleBase_Tools::createAction(QIcon(":pictures/edges_dir.png"), tr("Show edges direction"),
                                            aDesktop);
-  addAction("ISOLINES_CMD", anAction);
-
-  anAction = ModuleBase_Tools::createAction(QIcon(), tr("Show edges direction"), aDesktop);
   anAction->setCheckable(true);
   addAction("SHOW_EDGES_DIRECTION_CMD", anAction);
 
+  anAction = ModuleBase_Tools::createAction(QIcon(":pictures/iso_lines.png"), tr("Define Isos..."),
+                                           aDesktop);
+  addAction("ISOLINES_CMD", anAction);
+
   anAction = ModuleBase_Tools::createAction(QIcon(), tr("Show Isos"), aDesktop);
   anAction->setCheckable(true);
   addAction("SHOW_ISOLINES_CMD", anAction);
@@ -346,6 +347,7 @@ void XGUI_ContextMenuMgr::updateObjectBrowserMenu()
           }
           action("SHOW_EDGES_DIRECTION_CMD")->setEnabled(true);
           action("SHOW_EDGES_DIRECTION_CMD")->setChecked(ModelAPI_Tools::isShowEdgesDirection(aResult));
+
           action("SHOW_ISOLINES_CMD")->setEnabled(true);
           action("SHOW_ISOLINES_CMD")->setChecked(ModelAPI_Tools::isShownIsoLines(aResult));
           action("ISOLINES_CMD")->setEnabled(true);
@@ -595,11 +597,12 @@ void XGUI_ContextMenuMgr::updateViewerMenu()
         if (aPrsList.size() == 1) {
           ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(aObject);
           if (aResult.get()) {
-            action("SHOW_EDGES_DIRECTION_CMD")->setEnabled(true);
-            action("SHOW_EDGES_DIRECTION_CMD")->setChecked(
-                ModelAPI_Tools::isShowEdgesDirection(aResult));
             action("SHOW_ISOLINES_CMD")->setEnabled(true);
             action("SHOW_ISOLINES_CMD")->setChecked(ModelAPI_Tools::isShownIsoLines(aResult));
+
+            action("SHOW_EDGES_DIRECTION_CMD")->setEnabled(true);
+            action("SHOW_EDGES_DIRECTION_CMD")->setChecked(
+              ModelAPI_Tools::isShowEdgesDirection(aResult));
           }
         }
       }
@@ -731,6 +734,7 @@ void XGUI_ContextMenuMgr::buildObjBrowserMenu()
   aList.clear();
   aList.append(action("WIREFRAME_CMD"));
   aList.append(action("SHADING_CMD"));
+  aList.append(action("SHOW_EDGES_DIRECTION_CMD"));
   aList.append(mySeparator1); // this separator is not shown as this action is added after show only
   // qt list container contains only one instance of the same action
   aList.append(action("SHOW_CMD"));
index 87bc8aae261f12d55dcd216327f304198758ee61..b9be6db91d79f0761591c15155c0553c28f23ff2 100644 (file)
@@ -327,10 +327,8 @@ bool XGUI_Displayer::redisplay(ObjectPtr theObject, bool theUpdateViewer)
 
       // Set Iso-Lines
       Handle(ModuleBase_ResultPrs) aResPrs = Handle(ModuleBase_ResultPrs)::DownCast(aAISIO);
-      if (!aResPrs.IsNull()) {
+      if (!aResPrs.IsNull())
         aResPrs->updateIsoLines();
-        aResPrs->AddRemoveEdgesDir(AISContext()->CurrentViewer());
-      }
     }
     //myWorkshop->module()->storeSelection();
 
index af8a65e4868c2b546d000ee1dcfc781046623bfc..5eb5498fad36110fe75a6b47478c22432098a69c 100644 (file)
@@ -72,17 +72,6 @@ QList<ModuleBase_ViewerPrsPtr> XGUI_Selection::getSelected(const SelectionPlace&
   QList<ModuleBase_ViewerPrsPtr> aPresentations;
   QList<ModuleBase_ViewerPrsPtr> aToRemove;
 
-  Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
-  if (!aContext.IsNull()) {
-    AIS_ListOfInteractive aListOfObjects;
-    aContext->DisplayedObjects(aListOfObjects);
-    for (auto anObject = aListOfObjects.begin(); anObject != aListOfObjects.end(); ++anObject) {
-      Handle(ModuleBase_ResultPrs) aResPrs = Handle(ModuleBase_ResultPrs)::DownCast(*anObject);
-      if(aResPrs.get())
-        aResPrs->UpdateEdgesDir();
-    }
-  }
-
   switch (thePlace) {
     case Browser:
       getSelectedInBrowser(aPresentations);
@@ -184,10 +173,7 @@ void XGUI_Selection::getSelectedInViewer(QList<ModuleBase_ViewerPrsPtr>& thePres
       aSelectedIds.append((size_t)anOwner.get());
 
       fillPresentation(aPrs, anOwner);
-      AISObjectPtr anAISObject = myWorkshop->displayer()->getAISObject(aPrs->object());
-      Handle(ModuleBase_ResultPrs) aResPrs = Handle(ModuleBase_ResultPrs)::DownCast(anAISObject->
-                                                                 impl<Handle(AIS_InteractiveObject)>());
-      aResPrs->UpdateEdgesDir();
+
       if (!thePresentations.contains(aPrs)) // TODO: check whether the presentation in a list
         thePresentations.append(aPrs);
     }
index 69428360133977f603ae3de16d65b5ac8979318b..115e37e8edfa6c686539fa6deb29a4a343483579 100644 (file)
@@ -1822,6 +1822,8 @@ void XGUI_Workshop::onContextMenuCommand(const QString& theId, bool isChecked)
     setDisplayMode(anObjects, XGUI_Displayer::Shading);
   else if (theId == "WIREFRAME_CMD")
     setDisplayMode(anObjects, XGUI_Displayer::Wireframe);
+  else if (theId == "SHOW_EDGES_DIRECTION_CMD")
+    toggleEdgesDirection(anObjects);
   else if (theId == "HIDEALL_CMD") {
     QObjectPtrList aList = myDisplayer->displayedObjects();
     foreach (ObjectPtr aObj, aList) {
@@ -1866,15 +1868,6 @@ void XGUI_Workshop::onContextMenuCommand(const QString& theId, bool isChecked)
   } else if (theId == "SET_VIEW_INVERTEDNORMAL_CMD") {
     setNormalView(true);
   }
-  else if (theId == "SHOW_EDGES_DIRECTION_CMD") {
-    foreach(ObjectPtr aObj, anObjects) {
-      ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(aObj);
-      if (aResult.get())
-        ModelAPI_Tools::showEdgesDirection(aResult, !ModelAPI_Tools::isShowEdgesDirection(aResult));
-    }
-    mySelector->clearSelection();
-    Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
-  }
 #ifdef TINSPECTOR
   else if (theId == "TINSPECTOR_VIEW") {
     std::shared_ptr<Model_Session> aSession =
@@ -3015,6 +3008,32 @@ void XGUI_Workshop::setDisplayMode(const QObjectPtrList& theList, int theMode)
     myDisplayer->updateViewer();
 }
 
+//**************************************************************
+void XGUI_Workshop::toggleEdgesDirection(const QObjectPtrList& theList)
+{
+  foreach(ObjectPtr anObj, theList) {
+    ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
+    if (aResult.get() != NULL)
+    {
+      bool aToShow = !ModelAPI_Tools::isShowEdgesDirection(aResult);
+      ResultBodyPtr aBodyResult = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aResult);
+      if (aBodyResult.get() != NULL) { // change property for all sub-solids
+        std::list<ResultPtr> allRes;
+        ModelAPI_Tools::allSubs(aBodyResult, allRes);
+        std::list<ResultPtr>::iterator aRes;
+        for (aRes = allRes.begin(); aRes != allRes.end(); aRes++) {
+          ModelAPI_Tools::showEdgesDirection(*aRes, aToShow);
+          myDisplayer->redisplay(*aRes, false);
+        }
+      }
+      ModelAPI_Tools::showEdgesDirection(aResult, aToShow);
+      myDisplayer->redisplay(anObj, false);
+    }
+  }
+  if (theList.size() > 0)
+    myDisplayer->updateViewer();
+}
+
 //**************************************************************
 void XGUI_Workshop::closeDocument()
 {
index 8b4f0ac362ee478f2caeb1bd2698a1b1a893db5b..ed77829a4ad9a19c6fd0789899f6a91cd901f063 100644 (file)
@@ -236,6 +236,9 @@ Q_OBJECT
   /// \param theMode a mode to set (see \ref XGUI_Displayer)
   void setDisplayMode(const QObjectPtrList& theList, int theMode);
 
+  /// Toggle visualisation of edges direction
+  void toggleEdgesDirection(const QObjectPtrList& theList);
+
   /// Set selection mode in viewer. If theMode=-1 then activate default mode
   /// \param theMode the selection mode (according to TopAbs_ShapeEnum)
   void setViewerSelectionMode(int theMode);
index 2b81d5e48f9dfedc886df9855a9fb1bfbe32cfd8..f598306b4f82b193e297ddc6b88dbc2c3ac2bf1d 100644 (file)
@@ -98,5 +98,6 @@
      <file>pictures/CrossCursor.png</file>
      <file>pictures/HandCursor.png</file>
      <file>pictures/iso_lines.png</file>
+     <file>pictures/edges_dir.png</file>
  </qresource>
  </RCC>
diff --git a/src/XGUI/pictures/edges_dir.png b/src/XGUI/pictures/edges_dir.png
new file mode 100644 (file)
index 0000000..bff6162
Binary files /dev/null and b/src/XGUI/pictures/edges_dir.png differ