From: vsv Date: Thu, 9 Jun 2022 08:52:13 +0000 (+0300) Subject: [bos #29479] Show edges directions X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=refs%2Fheads%2FCR29479;p=modules%2Fshaper.git [bos #29479] Show edges directions Optimize visualization --- diff --git a/src/ModuleBase/CMakeLists.txt b/src/ModuleBase/CMakeLists.txt index 84bf06cd3..e4161f97b 100644 --- a/src/ModuleBase/CMakeLists.txt +++ b/src/ModuleBase/CMakeLists.txt @@ -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 diff --git a/src/ModuleBase/ModuleBase_ResultPrs.cpp b/src/ModuleBase/ModuleBase_ResultPrs.cpp index 81f55c806..ccba3a207 100644 --- a/src/ModuleBase/ModuleBase_ResultPrs.cpp +++ b/src/ModuleBase/ModuleBase_ResultPrs.cpp @@ -55,13 +55,16 @@ #include #include #include -#include #include #include #include #include #include #include +#include +#include +#include +#include #if OCC_VERSION_HEX > 0x070400 #include @@ -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 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(); - 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(); -} diff --git a/src/ModuleBase/ModuleBase_ResultPrs.h b/src/ModuleBase/ModuleBase_ResultPrs.h index 5eddec23c..5607c2bb0 100644 --- a/src/ModuleBase/ModuleBase_ResultPrs.h +++ b/src/ModuleBase/ModuleBase_ResultPrs.h @@ -22,8 +22,6 @@ #include "ModuleBase.h" -#include "ModuleBase_ArrowPrs.h" - #include #include @@ -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; }; diff --git a/src/XGUI/XGUI_ContextMenuMgr.cpp b/src/XGUI/XGUI_ContextMenuMgr.cpp index 97e58c22f..e42131d55 100644 --- a/src/XGUI/XGUI_ContextMenuMgr.cpp +++ b/src/XGUI/XGUI_ContextMenuMgr.cpp @@ -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(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")); diff --git a/src/XGUI/XGUI_Displayer.cpp b/src/XGUI/XGUI_Displayer.cpp index 87bc8aae2..b9be6db91 100644 --- a/src/XGUI/XGUI_Displayer.cpp +++ b/src/XGUI/XGUI_Displayer.cpp @@ -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(); diff --git a/src/XGUI/XGUI_Selection.cpp b/src/XGUI/XGUI_Selection.cpp index af8a65e48..5eb5498fa 100644 --- a/src/XGUI/XGUI_Selection.cpp +++ b/src/XGUI/XGUI_Selection.cpp @@ -72,17 +72,6 @@ QList XGUI_Selection::getSelected(const SelectionPlace& QList aPresentations; QList 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& 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()); - aResPrs->UpdateEdgesDir(); + if (!thePresentations.contains(aPrs)) // TODO: check whether the presentation in a list thePresentations.append(aPrs); } diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index 694283601..115e37e8e 100644 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -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(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 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(anObj); + if (aResult.get() != NULL) + { + bool aToShow = !ModelAPI_Tools::isShowEdgesDirection(aResult); + ResultBodyPtr aBodyResult = std::dynamic_pointer_cast(aResult); + if (aBodyResult.get() != NULL) { // change property for all sub-solids + std::list allRes; + ModelAPI_Tools::allSubs(aBodyResult, allRes); + std::list::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() { diff --git a/src/XGUI/XGUI_Workshop.h b/src/XGUI/XGUI_Workshop.h index 8b4f0ac36..ed77829a4 100644 --- a/src/XGUI/XGUI_Workshop.h +++ b/src/XGUI/XGUI_Workshop.h @@ -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); diff --git a/src/XGUI/XGUI_pictures.qrc b/src/XGUI/XGUI_pictures.qrc index 2b81d5e48..f598306b4 100644 --- a/src/XGUI/XGUI_pictures.qrc +++ b/src/XGUI/XGUI_pictures.qrc @@ -98,5 +98,6 @@ pictures/CrossCursor.png pictures/HandCursor.png pictures/iso_lines.png + pictures/edges_dir.png diff --git a/src/XGUI/pictures/edges_dir.png b/src/XGUI/pictures/edges_dir.png new file mode 100644 index 000000000..bff61628e Binary files /dev/null and b/src/XGUI/pictures/edges_dir.png differ