]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Issue #336 Create/Edit Line -filter for first and last point fields
authornds <natalia.donis@opencascade.com>
Tue, 20 Jan 2015 12:18:25 +0000 (15:18 +0300)
committernds <natalia.donis@opencascade.com>
Tue, 20 Jan 2015 12:18:25 +0000 (15:18 +0300)
It creates a new custom filter to ignore the global selected construction results with an exception of the sketch feature(a composite feature).

src/ConstructionPlugin/axis_widget.xml
src/ModuleBase/CMakeLists.txt
src/ModuleBase/ModuleBase_FilterCustom.cpp [new file with mode: 0644]
src/ModuleBase/ModuleBase_FilterCustom.h [new file with mode: 0644]
src/ModuleBase/ModuleBase_FilterNoConsructionSubShapes.cpp [new file with mode: 0644]
src/ModuleBase/ModuleBase_FilterNoConsructionSubShapes.h [new file with mode: 0644]
src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp
src/PartSet/PartSet_Module.cpp

index 7729b2a9e51d5ede7286f932ff9046706a44e046..364fa2b3c9cef75ee7cbd00e7986fadd163c6ae0 100644 (file)
@@ -6,11 +6,13 @@
     icon=":icons/point.png"
     tooltip="Select a first point"
     shape_types="vertex">
+    <selection_filter id="NoConstructionSubShapesFilter"/>
   </shape_selector>
   <shape_selector id="secondPoint"
     label="Second point"
     icon=":icons/point.png"
     tooltip="Select a second point"
     shape_types="vertex">
+    <selection_filter id="NoConstructionSubShapesFilter"/>
   </shape_selector>
 </source>
index 149ae47970144176f6e8d610b843808e4009e629..6d7fc7cf2afa9aa7dd63e79f81c563f5c42459f1 100644 (file)
@@ -6,11 +6,13 @@ SET(CMAKE_AUTOMOC ON)
 SET(PROJECT_HEADERS
        ModuleBase.h
        ModuleBase_Filter.h
+       ModuleBase_FilterCustom.h
        ModuleBase_FilterFace.h
        ModuleBase_FilterFactory.h
        ModuleBase_FilterLinearEdge.h
-    ModuleBase_FilterMulti.h
-    ModuleBase_FilterShapeType.h
+       ModuleBase_FilterMulti.h
+       ModuleBase_FilterNoConsructionSubShapes.h
+       ModuleBase_FilterShapeType.h
        ModuleBase_Tools.h
        ModuleBase_IModule.h
        ModuleBase_Operation.h
@@ -44,11 +46,13 @@ SET(PROJECT_HEADERS
 
 SET(PROJECT_SOURCES
        ModuleBase_Filter.cpp
+       ModuleBase_FilterCustom.cpp
        ModuleBase_FilterFace.cpp
        ModuleBase_FilterFactory.cpp
        ModuleBase_FilterLinearEdge.cpp
-    ModuleBase_FilterMulti.cpp
-    ModuleBase_FilterShapeType.cpp
+       ModuleBase_FilterMulti.cpp
+       ModuleBase_FilterNoConsructionSubShapes.cpp
+       ModuleBase_FilterShapeType.cpp
        ModuleBase_Tools.cpp
        ModuleBase_IModule.cpp
        ModuleBase_IWorkshop.cpp
@@ -73,11 +77,11 @@ SET(PROJECT_SOURCES
 )
 
 SET(PROJECT_LIBRARIES
-    Config
-    ModelAPI
+       Config
+       ModelAPI
        GeomAPI
        GeomAlgoAPI
-    ${QT_LIBRARIES}
+       ${QT_LIBRARIES}
        ${CAS_VIEWER}
        ${CAS_KERNEL}
        ${CAS_SHAPE}
diff --git a/src/ModuleBase/ModuleBase_FilterCustom.cpp b/src/ModuleBase/ModuleBase_FilterCustom.cpp
new file mode 100644 (file)
index 0000000..49ea31e
--- /dev/null
@@ -0,0 +1,30 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File:        ModuleBase_FilterCustom.cpp
+// Created:     10 Dec 2014
+// Author:      Natalia ERMOLAEVA
+
+
+#include "ModuleBase_FilterCustom.h"
+
+#include <StdSelect_EdgeFilter.hxx>
+#include <StdSelect_TypeOfEdge.hxx>
+
+#include <Events_Error.h>
+
+#include <QString>
+#include <QMap>
+
+ModuleBase_FilterCustom::ModuleBase_FilterCustom(Handle(SelectMgr_Filter) theFilter)
+: ModuleBase_Filter()
+{
+  myFilter = theFilter;
+}
+
+void ModuleBase_FilterCustom::createFilter()
+{
+}
+
+void ModuleBase_FilterCustom::setArguments(const std::list<std::string>& theArguments)
+{
+}
diff --git a/src/ModuleBase/ModuleBase_FilterCustom.h b/src/ModuleBase/ModuleBase_FilterCustom.h
new file mode 100644 (file)
index 0000000..6683207
--- /dev/null
@@ -0,0 +1,44 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File:        ModuleBase_FilterCustom.h
+// Created:     10 Dec 2014
+// Author:      Natalia ERMOLAEVA
+
+#ifndef ModuleBase_FilterCustom_H
+#define ModuleBase_FilterCustom_H
+
+#include "ModuleBase.h"
+
+#include "ModuleBase_Filter.h"
+
+/**
+* This is a child of ModuleBase_Filter to be used in the factory of filters. Despite of other
+* child it does not create the internal filter itself, it get it from the constructor argument.
+* This is useful for custom filters, which are not the standard OCC filters. It is not necessary
+* to redefine the ModuleBase_Filter. The filter is realized and put here as the class parameter.
+*/
+
+class ModuleBase_FilterCustom: public ModuleBase_Filter
+{
+public:
+  /**
+   * Constructor
+   * \param theFilter an OCC filter to be used in the parent base filter
+   */
+  MODULEBASE_EXPORT ModuleBase_FilterCustom(Handle(SelectMgr_Filter) theFilter); 
+
+  /**
+   * Sets the arguments to the filter. Currently it is not used in this filter.
+   * \param theArguments a list of arguments
+   */
+  MODULEBASE_EXPORT virtual void setArguments(const std::list<std::string>& theArguments);
+
+protected:
+  /**
+   * It creates an OCC filter. The realization is empty because the filter is set through the constructor
+   */
+  virtual void createFilter();
+
+};
+
+#endif //ModuleBase_FilterCustom
diff --git a/src/ModuleBase/ModuleBase_FilterNoConsructionSubShapes.cpp b/src/ModuleBase/ModuleBase_FilterNoConsructionSubShapes.cpp
new file mode 100644 (file)
index 0000000..feaac1c
--- /dev/null
@@ -0,0 +1,63 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File:        ModuleBase_ViewerFilters.cpp
+// Created:     07 Okt 2014
+// Author:      Vitaly SMETANNIKOV
+
+
+#include "ModuleBase_FilterNoConsructionSubShapes.h"
+#include "ModuleBase_IWorkshop.h"
+
+#include <ModelAPI_Session.h>
+#include <ModelAPI_Document.h>
+#include <ModelAPI_ResultConstruction.h>
+
+#include <AIS_InteractiveObject.hxx>
+#include <AIS_Shape.hxx>
+
+#include <StdSelect_BRepOwner.hxx>
+
+#include <BRep_Tool.hxx>
+#include <TopoDS.hxx>
+#include <TopoDS_Edge.hxx>
+#include <Geom_Curve.hxx>
+
+#include <ModelAPI_CompositeFeature.h>
+#include <GeomAPI_ICustomPrs.h>
+
+
+IMPLEMENT_STANDARD_HANDLE(ModuleBase_FilterNoConsructionSubShapes, SelectMgr_Filter);
+IMPLEMENT_STANDARD_RTTIEXT(ModuleBase_FilterNoConsructionSubShapes, SelectMgr_Filter);
+
+Standard_Boolean ModuleBase_FilterNoConsructionSubShapes::IsOk(const Handle(SelectMgr_EntityOwner)& theOwner) const
+{
+  // global selection should be ignored, the filter processes only selected sub-shapes
+  Handle(StdSelect_BRepOwner) aShapeOwner = Handle(StdSelect_BRepOwner)::DownCast(theOwner);
+  if (!aShapeOwner.IsNull()) {
+    if (!aShapeOwner->ComesFromDecomposition())
+      return Standard_True;
+  }
+
+  if (theOwner->HasSelectable()) {
+    Handle(AIS_InteractiveObject) aAisObj = 
+      Handle(AIS_InteractiveObject)::DownCast(theOwner->Selectable());
+    if (!aAisObj.IsNull()) {
+      std::shared_ptr<GeomAPI_AISObject> aAISObj = AISObjectPtr(new GeomAPI_AISObject());
+      aAISObj->setImpl(new Handle(AIS_InteractiveObject)(aAisObj));
+      ObjectPtr aObj = myWorkshop->findPresentedObject(aAISObj);
+
+      ResultConstructionPtr aConstr = 
+        std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aObj);
+      if (aConstr != NULL) {
+        // it provides selection only on compositie features, construction without composite
+        // feature is not selectable
+        FeaturePtr aFeature = ModelAPI_Feature::feature(aConstr);
+        CompositeFeaturePtr aComposite = 
+          std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aFeature);
+        return aComposite && aComposite->numberOfSubs() > 0;
+      }
+    }
+  }
+  return Standard_False;
+}
+
diff --git a/src/ModuleBase/ModuleBase_FilterNoConsructionSubShapes.h b/src/ModuleBase/ModuleBase_FilterNoConsructionSubShapes.h
new file mode 100644 (file)
index 0000000..49b1127
--- /dev/null
@@ -0,0 +1,44 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File:        ModuleBase_ViewerFilters.h
+// Created:     07 Okt 2014
+// Author:      Vitaly SMETANNIKOV
+
+
+#ifndef ModuleBase_FilterNoConsructionSubShapes_H
+#define ModuleBase_FilterNoConsructionSubShapes_H
+
+#include <QStringList>
+
+#include <SelectMgr_Filter.hxx>
+#include <SelectMgr_EntityOwner.hxx>
+
+class ModuleBase_IWorkshop;
+
+/**
+* A filter which provides filtering of selection in 3d viewer.
+* Installing of this filter lets to select objects which belong to 
+* currently active document or to global document
+*/
+DEFINE_STANDARD_HANDLE(ModuleBase_FilterNoConsructionSubShapes, SelectMgr_Filter);
+class ModuleBase_FilterNoConsructionSubShapes: public SelectMgr_Filter
+{
+public:
+  Standard_EXPORT ModuleBase_FilterNoConsructionSubShapes(ModuleBase_IWorkshop* theWorkshop):
+      SelectMgr_Filter(), myWorkshop(theWorkshop) {}
+
+  /**
+   * 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_FilterNoConsructionSubShapes)
+
+protected:
+  ModuleBase_IWorkshop* myWorkshop;
+};
+
+#endif
\ No newline at end of file
index e576407459fedd22def8f9d20f01b8eb83f5caab..361f6383d8507a66b94c38457a95eab6c878f4f5 100644 (file)
@@ -366,11 +366,15 @@ bool ModuleBase_WidgetShapeSelector::acceptObjectType(const ObjectPtr theObject)
 void ModuleBase_WidgetShapeSelector::updateSelectionName()
 {
   DataPtr aData = myFeature->data();
-  AttributeSelectionPtr aSelect = aData->selection(attributeID());
-  if (aSelect) {
-    myTextLine->setText(QString::fromStdString(aSelect->namingName()));
+  bool isNameUpdated = false;
+  if (aData.get() != NULL) {
+    AttributeSelectionPtr aSelect = aData->selection(attributeID());
+    if (aSelect) {
+      myTextLine->setText(QString::fromStdString(aSelect->namingName()));
+      isNameUpdated = true;
+    }
   }
-  else {
+  if (!isNameUpdated) {
     if (mySelectedObject) {
       std::string aName = mySelectedObject->data()->name();
       myTextLine->setText(QString::fromStdString(aName));
index d5f96e489e9d191e8fed9c98b59fe79e9642ca0c..797fcd11602a123fecb98dfdaa01720fccb55adb 100644 (file)
@@ -18,7 +18,8 @@
 #include <ModuleBase_FilterLinearEdge.h>
 #include <ModuleBase_FilterFace.h>
 #include <ModuleBase_FilterMulti.h>
-
+#include <ModuleBase_FilterCustom.h>
+#include <ModuleBase_FilterNoConsructionSubShapes.h>
 
 #include <ModelAPI_Object.h>
 #include <ModelAPI_Events.h>
@@ -126,6 +127,9 @@ void PartSet_Module::registerFilters()
   aFactory->registerFilter("EdgeFilter", new ModuleBase_FilterLinearEdge);
   aFactory->registerFilter("FaceFilter", new ModuleBase_FilterFace);
   aFactory->registerFilter("MultiFilter", new ModuleBase_FilterMulti);
+  Handle(SelectMgr_Filter) aSelectFilter = new ModuleBase_FilterNoConsructionSubShapes(workshop());
+  aFactory->registerFilter("NoConstructionSubShapesFilter",
+            new ModuleBase_FilterCustom(aSelectFilter));
 }
 
 void PartSet_Module::operationCommitted(ModuleBase_Operation* theOperation)