]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Issue #276 - Names for selected topology
authornds <natalia.donis@opencascade.com>
Tue, 10 Feb 2015 08:18:47 +0000 (11:18 +0300)
committernds <natalia.donis@opencascade.com>
Tue, 10 Feb 2015 08:18:47 +0000 (11:18 +0300)
It avoids degenrated edges using in the Group control.

src/ModuleBase/CMakeLists.txt
src/ModuleBase/ModuleBase_FilterNoDegeneratedEdge.cpp [new file with mode: 0644]
src/ModuleBase/ModuleBase_FilterNoDegeneratedEdge.h [new file with mode: 0644]
src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp
src/ModuleBase/ModuleBase_WidgetMultiSelector.h

index 096e6eaaa0caa053d812baa90274c95cbfa65378..aea5e669a1fdb02c3487a7bed0714da7bfc3ad1e 100644 (file)
@@ -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 (file)
index 0000000..1fb5a57
--- /dev/null
@@ -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 <StdSelect_BRepOwner.hxx>
+#include <TopoDS.hxx>
+#include <TopoDS_Shape.hxx>
+#include <BRep_Tool.hxx>
+
+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 (file)
index 0000000..b61f001
--- /dev/null
@@ -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 <QStringList>
+
+#include <StdSelect_EdgeFilter.hxx>
+#include <SelectMgr_EntityOwner.hxx>
+
+/**
+* \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
index 5ee8ac64a38bd0bab91c132eb4b3a475fdebfac9..a11725988706e55c0ce67527a6d1ef867f5afe36 100644 (file)
@@ -9,8 +9,10 @@
 
 #include <ModuleBase_WidgetMultiSelector.h>
 #include <ModuleBase_WidgetShapeSelector.h>
+#include <ModuleBase_FilterNoDegeneratedEdge.h>
 #include <ModuleBase_ISelection.h>
 #include <ModuleBase_IWorkshop.h>
+#include <ModuleBase_IViewer.h>
 #include <ModuleBase_Tools.h>
 
 #include <ModelAPI_Data.h>
@@ -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);
+  }
 }
 
 //********************************************************************
index fa73d37590badcdc8f17d95f39031b73357c7837..8d8c9e2c87bd0e71778bd3d9873ad9fbfec20853 100644 (file)
@@ -12,6 +12,7 @@
 
 #include <ModuleBase.h>
 #include <ModuleBase_ModelWidget.h>
+#include <ModuleBase_FilterNoDegeneratedEdge.h>
 
 #include <GeomAPI_Shape.h>
 #include <ModelAPI_Result.h>
@@ -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_ */