]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Issue #1369: Optimized validators for Build plug-in
authordbv <dbv@opencascade.com>
Tue, 19 Apr 2016 12:17:53 +0000 (15:17 +0300)
committerdbv <dbv@opencascade.com>
Tue, 19 Apr 2016 13:42:10 +0000 (16:42 +0300)
src/BuildPlugin/BuildPlugin_Plugin.cpp
src/BuildPlugin/BuildPlugin_Validators.cpp
src/BuildPlugin/BuildPlugin_Validators.h
src/BuildPlugin/CMakeLists.txt
src/BuildPlugin/vertex_widget.xml
src/BuildPlugin/wire_widget.xml

index 5df9e579a446021a1e087669c669029bc1eb6df1..3433f3b9e0bc5d09fe53b3d93b02a64ea3f1ac3d 100644 (file)
@@ -22,8 +22,8 @@ BuildPlugin_Plugin::BuildPlugin_Plugin()
   // Register validators.
   SessionPtr aMgr = ModelAPI_Session::get();
   ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
-  aFactory->registerValidator("BuildPlugin_ValidatorBaseForVertex",
-                              new BuildPlugin_ValidatorBaseForVertex());
+  aFactory->registerValidator("BuildPlugin_ValidatorBaseForBuild",
+                              new BuildPlugin_ValidatorBaseForBuild());
   aFactory->registerValidator("BuildPlugin_ValidatorBaseForWire",
                               new BuildPlugin_ValidatorBaseForWire());
 
index 285a03121fd95bf21083bd9eb36832b8b51f7a82..7706fe77a589f60f1748500304e6fdb5f3ec69f7 100644 (file)
 
 #include <GeomAlgoAPI_WireBuilder.h>
 
+#include <GeomValidators_ShapeType.h>
+
 #include <Events_Error.h>
 
 //=================================================================================================
-bool BuildPlugin_ValidatorBaseForVertex::isValid(const AttributePtr& theAttribute,
-                                                 const std::list<std::string>& theArguments,
-                                                 std::string& theError) const
+bool BuildPlugin_ValidatorBaseForBuild::isValid(const AttributePtr& theAttribute,
+                                                const std::list<std::string>& theArguments,
+                                                std::string& theError) const
 {
   // Get base objects list.
   if(theAttribute->attributeType() != ModelAPI_AttributeSelectionList::typeId()) {
@@ -59,13 +61,13 @@ bool BuildPlugin_ValidatorBaseForVertex::isValid(const AttributePtr& theAttribut
       return false;
     }
 
-    // Check that shape has acceptable type.
-    if(aShape->shapeType() != GeomAPI_Shape::VERTEX) {
-      theError = "Selected shape has wrong type. Only vertices acceptable.";
+    // Check that shapes has acceptable type.
+    GeomValidators_ShapeType aValidatorShapeType;
+    if(!aValidatorShapeType.isValid(aSelection, theArguments, theError)) {
       return false;
     }
 
-    // Check that it is vertex on sketch.
+    // Check that it is shape on sketch.
     ResultConstructionPtr aConstruction = std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aContext);
     if(aConstruction.get()) {
       if(aConstruction->isInfinite()) {
@@ -74,16 +76,17 @@ bool BuildPlugin_ValidatorBaseForVertex::isValid(const AttributePtr& theAttribut
       }
 
       std::shared_ptr<GeomAPI_PlanarEdges> anEdges = std::dynamic_pointer_cast<GeomAPI_PlanarEdges>(aContextShape);
-      if(!anEdges.get()) {
-        // It is not an edge on the sketch.
-        // Check that it is not local selection.
-        if(!aShape->isEqual(aContextShape)) {
-          // Local selection on body does not allowed.
-          theError = "Selected shape is in the local selection. Only global selection is allowed.";
-          return false;
-        }
+      if(anEdges.get() && !aShape->isEqual(aContextShape)) {
+        // It is local selection on sketch. Ok.
+        return true;
       }
     }
+
+    if(!aShape->isEqual(aContextShape)) {
+      // Local selection on body does not allowed.
+      theError = "Selected shape is in the local selection. Only global selection is allowed.";
+      return false;
+    }
   }
 
   return true;
@@ -95,71 +98,23 @@ bool BuildPlugin_ValidatorBaseForWire::isValid(const AttributePtr& theAttribute,
                                                std::string& theError) const
 {
   // Get base objects list.
-  if(theAttribute->attributeType() != ModelAPI_AttributeSelectionList::typeId()) {
-    Events_Error::send("Validator does not support attribute type \"" + theAttribute->attributeType()
-      + "\"\n Only \"" + ModelAPI_AttributeSelectionList::typeId() + "\" supported.");
-    return false;
-  }
-  AttributeSelectionListPtr aSelectionList = std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
-  if(!aSelectionList.get()) {
-    theError = "Could not get selection list.";
-    return false;
-  }
-  if(aSelectionList->size() == 0) {
-    theError = "Empty selection list.";
+  BuildPlugin_ValidatorBaseForBuild aValidatorBaseForBuild;
+  if(!aValidatorBaseForBuild.isValid(theAttribute, theArguments, theError)) {
     return false;
   }
 
   // Collect base shapes.
+  AttributeSelectionListPtr aSelectionList =
+    std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
   ListOfShape aListOfShapes;
   for(int anIndex = 0; anIndex < aSelectionList->size(); ++anIndex) {
     AttributeSelectionPtr aSelection = aSelectionList->value(anIndex);
-    if(!aSelection.get()) {
-      theError = "Could not get selection.";
-      return false;
-    }
     ResultPtr aContext = aSelection->context();
-    if(!aContext.get()) {
-      theError = "Attribute have empty context.";
-      return false;
-    }
-
     GeomShapePtr aShape = aSelection->value();
     GeomShapePtr aContextShape = aContext->shape();
     if(!aShape.get()) {
-      aShape = aContextShape;
-    }
-    if(!aShape.get()) {
-      theError = "Empty shape selected.";
-      return false;
-    }
-
-    // Check that shape has acceptable type.
-    if(aShape->shapeType() != GeomAPI_Shape::EDGE && aShape->shapeType() != GeomAPI_Shape::WIRE) {
-      theError = "Selected shape has wrong type. Only edges and wires acceptable.";
-      return false;
-    }
-
-    // Check that it is edge on sketch.
-    ResultConstructionPtr aConstruction = std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aContext);
-    if(aConstruction.get()) {
-      if(aConstruction->isInfinite()) {
-        theError = "Inifinte objects not acceptable.";
-        return false;
-      }
-
-      std::shared_ptr<GeomAPI_PlanarEdges> anEdges = std::dynamic_pointer_cast<GeomAPI_PlanarEdges>(aContextShape);
-      if(!anEdges.get()) {
-        // It is not an edge on the sketch.
-        // Check that it is not local selection.
-        if(!aShape->isEqual(aContextShape)) {
-          // Local selection on body does not allowed.
-          theError = "Selected shape is in the local selection. Only global selection is allowed.";
-          return false;
-        }
-      }
+      aShape = aSelection->context()->shape();
     }
-
     aListOfShapes.push_back(aShape);
   }
 
index eb698b21ad9e50b8fcfed386c7387ea260426c67..b7c2420d94c2cb78ce6ed866d70828a9ca253475 100644 (file)
 #include <ModelAPI_AttributeValidator.h>
 #include <ModelAPI_FeatureValidator.h>
 
-/// \class BuildPlugin_ValidatorBaseForVertex
+/// \class BuildPlugin_ValidatorBaseForBuild
 /// \ingroup Validators
-/// \brief A validator for selection base shapes for vertex. Allows to select vertices on sketch and
-/// vertex objects.
-class BuildPlugin_ValidatorBaseForVertex: public ModelAPI_AttributeValidator
+/// \brief A validator for selection base shapes for build features. Allows to select shapes on sketch and
+/// whole objects with allowed type.
+class BuildPlugin_ValidatorBaseForBuild: public ModelAPI_AttributeValidator
 {
 public:
   //! Returns true if attribute is ok.
index 7a49953a1bfc59cd7528cd35abc41bea3e192732..39e728f775623ea7ea72c2e1d37f52bace3b3c85 100644 (file)
@@ -8,6 +8,7 @@ INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/src/Events
                     ${PROJECT_SOURCE_DIR}/src/ModelAPI
                     ${PROJECT_SOURCE_DIR}/src/GeomAPI
                     ${PROJECT_SOURCE_DIR}/src/GeomAlgoAPI
+                    ${PROJECT_SOURCE_DIR}/src/GeomValidators
 )
 
 SET(PROJECT_HEADERS
@@ -37,6 +38,7 @@ SET(PROJECT_LIBRARIES
     ModelAPI
     GeomAPI
     GeomAlgoAPI
+    GeomValidators
 )
 
 ADD_DEFINITIONS(-DBUILDPLUGIN_EXPORTS)
index 04d0603f84b9ea3a1074be0adaa5db37183d6b72..bc9b7f318b45934e630172db217313e48611d69f 100644 (file)
@@ -4,7 +4,7 @@
   <multi_selector id="base_objects"
                   label="Vertices:"
                   tooltip="Select a vertices on sketch or vertex objects."
-                  type_choice="vertex objects">
-    <validator id="BuildPlugin_ValidatorBaseForVertex"/>
+                  type_choice="vertices objects">
+    <validator id="BuildPlugin_ValidatorBaseForBuild" parameters="vertex"/>
   </multi_selector>
 </source>
index 967ba23fba8ab10c4cca681554cf448c7c04e8a0..e2843b4378726dc2843410e30d943cd324d57ea9 100644 (file)
@@ -5,7 +5,7 @@
                   label="Segments and wires:"
                   tooltip="Select an edges on sketch or wires objects."
                   type_choice="edges objects">
-    <validator id="BuildPlugin_ValidatorBaseForWire"/>
+    <validator id="BuildPlugin_ValidatorBaseForWire" parameters="edge,wire"/>
   </multi_selector>
   <action id="add_contour"
           label="Add contour"