From c936f369280ecc020a87e46695df5d5c0ea235df Mon Sep 17 00:00:00 2001 From: nds Date: Tue, 10 Feb 2015 11:18:47 +0300 Subject: [PATCH] Issue #276 - Names for selected topology It avoids degenrated edges using in the Group control. --- src/ModuleBase/CMakeLists.txt | 2 + .../ModuleBase_FilterNoDegeneratedEdge.cpp | 36 ++++++++++++++++ .../ModuleBase_FilterNoDegeneratedEdge.h | 41 +++++++++++++++++++ .../ModuleBase_WidgetMultiSelector.cpp | 15 +++++++ .../ModuleBase_WidgetMultiSelector.h | 4 ++ 5 files changed, 98 insertions(+) create mode 100644 src/ModuleBase/ModuleBase_FilterNoDegeneratedEdge.cpp create mode 100644 src/ModuleBase/ModuleBase_FilterNoDegeneratedEdge.h diff --git a/src/ModuleBase/CMakeLists.txt b/src/ModuleBase/CMakeLists.txt index 096e6eaaa..aea5e669a 100644 --- a/src/ModuleBase/CMakeLists.txt +++ b/src/ModuleBase/CMakeLists.txt @@ -12,6 +12,7 @@ SET(PROJECT_HEADERS ModuleBase_FilterLinearEdge.h ModuleBase_FilterMulti.h ModuleBase_FilterNoConsructionSubShapes.h + ModuleBase_FilterNoDegeneratedEdge.h ModuleBase_FilterShapeType.h ModuleBase_Tools.h ModuleBase_IModule.h @@ -53,6 +54,7 @@ SET(PROJECT_SOURCES ModuleBase_FilterLinearEdge.cpp ModuleBase_FilterMulti.cpp ModuleBase_FilterNoConsructionSubShapes.cpp + ModuleBase_FilterNoDegeneratedEdge.cpp ModuleBase_FilterShapeType.cpp ModuleBase_Tools.cpp ModuleBase_IModule.cpp diff --git a/src/ModuleBase/ModuleBase_FilterNoDegeneratedEdge.cpp b/src/ModuleBase/ModuleBase_FilterNoDegeneratedEdge.cpp new file mode 100644 index 000000000..1fb5a5736 --- /dev/null +++ b/src/ModuleBase/ModuleBase_FilterNoDegeneratedEdge.cpp @@ -0,0 +1,36 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: ModuleBase_ViewerFilters.cpp +// Created: 10 Feb 2015 +// Author: Natalia ERMOLAEVA + + +#include "ModuleBase_FilterNoDegeneratedEdge.h" + +#include +#include +#include +#include + +IMPLEMENT_STANDARD_HANDLE(ModuleBase_FilterNoDegeneratedEdge, StdSelect_EdgeFilter); +IMPLEMENT_STANDARD_RTTIEXT(ModuleBase_FilterNoDegeneratedEdge, StdSelect_EdgeFilter); + +ModuleBase_FilterNoDegeneratedEdge::ModuleBase_FilterNoDegeneratedEdge() +: StdSelect_EdgeFilter(StdSelect_AnyEdge) +{ +} + +Standard_Boolean ModuleBase_FilterNoDegeneratedEdge::IsOk(const Handle(SelectMgr_EntityOwner)& theOwner) const +{ + bool isEdge = StdSelect_EdgeFilter::IsOk(theOwner); + if (isEdge) { + Handle(StdSelect_BRepOwner) anOwner = Handle(StdSelect_BRepOwner)::DownCast(theOwner); + if (!anOwner.IsNull() && anOwner->HasShape()) { + const TopoDS_Shape& aShape = anOwner->Shape(); + if (BRep_Tool::Degenerated(TopoDS::Edge(aShape))) + return Standard_False; + } + } + return isEdge; +} + diff --git a/src/ModuleBase/ModuleBase_FilterNoDegeneratedEdge.h b/src/ModuleBase/ModuleBase_FilterNoDegeneratedEdge.h new file mode 100644 index 000000000..b61f0017e --- /dev/null +++ b/src/ModuleBase/ModuleBase_FilterNoDegeneratedEdge.h @@ -0,0 +1,41 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: ModuleBase_ViewerFilters.h +// Created: 10 Feb 2015 +// Author: Natalia ERMOLAEVA + + +#ifndef ModuleBase_FilterNoDegeneratedEdge_H +#define ModuleBase_FilterNoDegeneratedEdge_H + +#include + +#include +#include + +/** +* \ingroup GUI +* \class ModuleBase_FilterNoDegeneratedEdge +* An edge filter, which additionally filters degenerative edges. +*/ +DEFINE_STANDARD_HANDLE(ModuleBase_FilterNoDegeneratedEdge, StdSelect_EdgeFilter); +class ModuleBase_FilterNoDegeneratedEdge: public StdSelect_EdgeFilter +{ +public: + /// Constructor + Standard_EXPORT ModuleBase_FilterNoDegeneratedEdge(); + + /** + * Returns true if the owner is computed from decomposition(it is global selection, not the sub-shapes) + * of if the selected result is a construction and the result feature is composite and has sub-elements. + * \param theOwner the result of selection + * \return whether the owner is selectable in the viewer + */ + Standard_EXPORT virtual Standard_Boolean IsOk(const Handle(SelectMgr_EntityOwner)& theOwner) const; + + DEFINE_STANDARD_RTTI(ModuleBase_FilterNoDegeneratedEdge) + +protected: +}; + +#endif \ No newline at end of file diff --git a/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp b/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp index 5ee8ac64a..a11725988 100644 --- a/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp +++ b/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp @@ -9,8 +9,10 @@ #include #include +#include #include #include +#include #include #include @@ -167,6 +169,8 @@ void ModuleBase_WidgetMultiSelector::activateSelection(bool toActivate) } else { disconnect(myWorkshop, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged())); myWorkshop->deactivateSubShapesSelection(); + + myWorkshop->viewer()->removeSelectionFilter(myEdgesTypeFilter); } } @@ -258,6 +262,17 @@ void ModuleBase_WidgetMultiSelector::activateShapeSelection() QIntList aList; aList.append(ModuleBase_WidgetShapeSelector::shapeType(aNewType)); myWorkshop->activateSubShapesSelection(aList); + + // it is necessary to filter the selected edges to be non-degenerated + // it is not possible to build naming name for such edges + if (aNewType == "Edges") { + myEdgesTypeFilter = new ModuleBase_FilterNoDegeneratedEdge(); + ModuleBase_IViewer* aViewer = myWorkshop->viewer(); + aViewer->addSelectionFilter(myEdgesTypeFilter); + } + else { + myWorkshop->viewer()->removeSelectionFilter(myEdgesTypeFilter); + } } //******************************************************************** diff --git a/src/ModuleBase/ModuleBase_WidgetMultiSelector.h b/src/ModuleBase/ModuleBase_WidgetMultiSelector.h index fa73d3759..8d8c9e2c8 100644 --- a/src/ModuleBase/ModuleBase_WidgetMultiSelector.h +++ b/src/ModuleBase/ModuleBase_WidgetMultiSelector.h @@ -12,6 +12,7 @@ #include #include +#include #include #include @@ -133,6 +134,9 @@ protected slots: /// An action for pop-up menu in a list control QAction* myCopyAction; + + /// A filter for the Edges type, which avoid the generated edges selection + Handle(ModuleBase_FilterNoDegeneratedEdge) myEdgesTypeFilter; }; #endif /* MODULEBASE_WIDGETFILESELECTOR_H_ */ -- 2.39.2