]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Union of validator and filter functionalities.
authornds <natalia.donis@opencascade.com>
Fri, 20 Mar 2015 14:57:28 +0000 (17:57 +0300)
committernds <natalia.donis@opencascade.com>
Fri, 20 Mar 2015 14:57:28 +0000 (17:57 +0300)
Validator for NoConstructionSubShape filter

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

index 44f6f0e94d6bca405d8c21adb68aea071d51113f..435a2e7b38242583d3debda97a558b9f9dcf111d 100644 (file)
@@ -8,14 +8,14 @@
         icon=":icons/point.png"
         tooltip="Select a first point"
         shape_types="vertex">
-        <selection_filter id="NoConstructionSubShapesFilter"/>
+        <validator id="ModuleBase_ValidatorNoConstructionSubShapes"/>
       </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"/>
+        <validator id="ModuleBase_ValidatorNoConstructionSubShapes"/>
         <validator id="PartSet_DifferentShapes"/>
       </shape_selector>
     </box>
index 0b76254af3ae6a28cab1ac9f95e24625c7526eea..5dcc4090847854c573fe73a7cb3cdbec443a0ad8 100644 (file)
@@ -40,6 +40,7 @@ SET(PROJECT_HEADERS
        ModuleBase_ValidatorFace.h
        ModuleBase_ValidatorLinearEdge.h
        ModuleBase_ValidatorLinearEdgeOrVertex.h
+       ModuleBase_ValidatorNoConstructionSubShapes.h
        ModuleBase_ViewerFilters.h
        ModuleBase_ResultPrs.h
        ModuleBase_IViewWindow.h
@@ -86,6 +87,7 @@ SET(PROJECT_SOURCES
        ModuleBase_ValidatorFace.cpp
        ModuleBase_ValidatorLinearEdge.cpp
        ModuleBase_ValidatorLinearEdgeOrVertex.cpp
+       ModuleBase_ValidatorNoConstructionSubShapes.cpp
        ModuleBase_ViewerFilters.cpp
        ModuleBase_ResultPrs.cpp
        ModuleBase_WidgetLabel.cpp
diff --git a/src/ModuleBase/ModuleBase_ValidatorNoConstructionSubShapes.cpp b/src/ModuleBase/ModuleBase_ValidatorNoConstructionSubShapes.cpp
new file mode 100644 (file)
index 0000000..7a6ab98
--- /dev/null
@@ -0,0 +1,48 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+#include "ModuleBase_ValidatorNoConstructionSubShapes.h"
+
+#include "ModelAPI_AttributeSelection.h"
+#include "ModelAPI_ResultConstruction.h"
+#include "ModelAPI_CompositeFeature.h"
+
+bool ModuleBase_ValidatorNoConstructionSubShapes::isValid(const AttributePtr& theAttribute,
+                                              const std::list<std::string>& theArguments) const
+{
+  bool aValid = false;
+  AttributeSelectionPtr aSelectionAttr = std::dynamic_pointer_cast<ModelAPI_AttributeSelection>
+                                                                (theAttribute);
+  if (aSelectionAttr.get() == NULL)
+    return aValid;
+
+  ResultPtr aResult = aSelectionAttr->context();
+  GeomShapePtr aShape = aSelectionAttr->value();
+  // global selection should be ignored, the filter processes only selected sub-shapes
+  // that means, that the shape of the context result is equal to the shape value
+  ///*ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theSelectedObject);
+  if (aResult.get() != NULL) {
+    GeomShapePtr aShapePtr = aResult->shape();
+    // it is important to call isEqual of the shape of result.
+    // It is a GeomAPI_Vertex shape for the point. The shape of the parameter is 
+    // GeomAPI_Shape. It is important to use the realization of the isEqual method from
+    // GeomAPI_Vertex class
+    aValid = aShapePtr.get() != NULL && aShapePtr->isEqual(aShape);
+  }
+  if (!aValid) {
+    ResultConstructionPtr aConstr =
+                            std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aResult);
+    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);
+      aValid = aComposite && aComposite->numberOfSubs() > 0;
+    }
+    else {
+      // non-construction results should be accepted by this filter, e.g. body results
+      aValid = true;
+    }
+  }
+  return aValid;
+}
diff --git a/src/ModuleBase/ModuleBase_ValidatorNoConstructionSubShapes.h b/src/ModuleBase/ModuleBase_ValidatorNoConstructionSubShapes.h
new file mode 100644 (file)
index 0000000..1338fce
--- /dev/null
@@ -0,0 +1,28 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File:        ModuleBase_ValidatorNoConstructionSubShapes.h
+// Created:     20 Mar 2015
+// Author:      Natalia ERMOLAEVA
+
+#ifndef ModuleBase_ValidatorNoConstructionSubShapes_H
+#define ModuleBase_ValidatorNoConstructionSubShapes_H
+
+#include "ModuleBase.h"
+#include "ModelAPI_AttributeValidator.h"
+
+/**
+* \ingroup Validators
+* A validator of selection
+*/
+class ModuleBase_ValidatorNoConstructionSubShapes : public ModelAPI_AttributeValidator
+{
+ public:
+   MODULEBASE_EXPORT ModuleBase_ValidatorNoConstructionSubShapes() {}
+  //! returns true if attribute is valid
+  //! \param theAttribute the checked attribute
+  //! \param theArguments arguments of the attribute
+  MODULEBASE_EXPORT virtual bool isValid(const AttributePtr& theAttribute,
+                                         const std::list<std::string>& theArguments) const;
+};
+
+#endif
index a5ddfb7047199767f5446cef01d431989333eb43..88c587aff5ee622c0b7db7bc3aa08ee678b2a07a 100644 (file)
@@ -106,17 +106,19 @@ bool ModuleBase_WidgetValidated::isValid(ObjectPtr theObj, GeomShapePtr theShape
   return isValid;
 }
 
+#define VALIDATOR_FILTER
 void ModuleBase_WidgetValidated::activateFilters(ModuleBase_IWorkshop* theWorkshop,
                                                  const bool toActivate) const
 {
   ModuleBase_IViewer* aViewer = theWorkshop->viewer();
 
+#ifdef VALIDATOR_FILTER
   Handle(SelectMgr_Filter) aSelFilter = theWorkshop->validatorFilter();
   if (toActivate)
     aViewer->addSelectionFilter(aSelFilter);
   else
     aViewer->removeSelectionFilter(aSelFilter);
-/*
+#else
   // apply filters loaded from the XML definition of the widget
   ModuleBase_FilterFactory* aFactory = theWorkshop->selectionFilters();
   SelectMgr_ListOfFilter aFactoryFilters;
@@ -130,7 +132,8 @@ void ModuleBase_WidgetValidated::activateFilters(ModuleBase_IWorkshop* theWorksh
       aViewer->addSelectionFilter(aSelFilter);
     else
       aViewer->removeSelectionFilter(aSelFilter);
-  }*/
+  }
+#endif
 }
 
 void ModuleBase_WidgetValidated::selectionFilters(ModuleBase_IWorkshop* theWorkshop,
index 8406ad191422b4c809b547077f28d78cc08e83cd..79d5b9664242dda853ff7b77a93f94f55f9fed1a 100644 (file)
@@ -24,6 +24,7 @@
 #include <ModuleBase_ValidatorLinearEdge.h>
 #include <ModuleBase_ValidatorLinearEdgeOrVertex.h>
 #include <ModuleBase_ValidatorFace.h>
+#include <ModuleBase_ValidatorNoConstructionSubShapes.h>
 
 #include <PartSet_FilterSketchEntity.h>
 
@@ -135,6 +136,9 @@ void PartSet_Module::registerValidators()
   aFactory->registerValidator("ModuleBase_ValidatorLinearEdgeOrVertex",
                               new ModuleBase_ValidatorLinearEdgeOrVertex);
   aFactory->registerValidator("ModuleBase_ValidatorFace", new ModuleBase_ValidatorFace);
+
+  aFactory->registerValidator("ModuleBase_ValidatorNoConstructionSubShapes",
+                              new ModuleBase_ValidatorNoConstructionSubShapes);
 }
 
 void PartSet_Module::registerFilters()