Salome HOME
Issue #1369: Validator for selection base objects for "Face" feature. Modified BuildP...
authordbv <dbv@opencascade.com>
Wed, 20 Apr 2016 15:55:22 +0000 (18:55 +0300)
committerdbv <dbv@opencascade.com>
Fri, 22 Apr 2016 11:07:40 +0000 (14:07 +0300)
src/BuildPlugin/BuildPlugin_Validators.cpp
src/BuildPlugin/BuildPlugin_Validators.h
src/BuildPlugin/wire_widget.xml

index 9aa7c8acd4e975622447c9a5b819ed41727472df..7204aebce1f05fd0f784cde8ee740f70e75a3960 100644 (file)
@@ -11,6 +11,7 @@
 
 #include <GeomAPI_PlanarEdges.h>
 
+#include <GeomAlgoAPI_CompoundBuilder.h>
 #include <GeomAlgoAPI_WireBuilder.h>
 
 #include <GeomValidators_ShapeType.h>
@@ -24,7 +25,7 @@ bool BuildPlugin_ValidatorBaseForBuild::isValid(const AttributePtr& theAttribute
 {
   // Get base objects list.
   if(theAttribute->attributeType() != ModelAPI_AttributeSelectionList::typeId()) {
-    Events_Error::send("Validator does not support attribute type \"" + theAttribute->attributeType()
+    Events_Error::send("Error: BuildPlugin_ValidatorBaseForBuild does not support attribute type \"" + theAttribute->attributeType()
       + "\"\n Only \"" + ModelAPI_AttributeSelectionList::typeId() + "\" supported.");
     return false;
   }
@@ -93,25 +94,33 @@ bool BuildPlugin_ValidatorBaseForBuild::isValid(const AttributePtr& theAttribute
 }
 
 //=================================================================================================
-bool BuildPlugin_ValidatorBaseForWire::isValid(const AttributePtr& theAttribute,
+bool BuildPlugin_ValidatorBaseForWire::isValid(const std::shared_ptr<ModelAPI_Feature>& theFeature,
                                                const std::list<std::string>& theArguments,
                                                std::string& theError) const
 {
-  // Get base objects list.
+  // Get attribute.
+  if(theArguments.size() != 1) {
+    Events_Error::send("Error: BuildPlugin_ValidatorBaseForWire should be used only with 1 parameter (ID of base objects list)");
+    return false;
+  }
+  AttributePtr anAttribute = theFeature->attribute(theArguments.front());
+
+  // Check base objects list.
   BuildPlugin_ValidatorBaseForBuild aValidatorBaseForBuild;
-  if(!aValidatorBaseForBuild.isValid(theAttribute, theArguments, theError)) {
+  std::list<std::string> anArguments;
+  anArguments.push_back("edge");
+  anArguments.push_back("wire");
+  if(!aValidatorBaseForBuild.isValid(anAttribute, anArguments, theError)) {
     return false;
   }
 
   // Collect base shapes.
   AttributeSelectionListPtr aSelectionList =
-    std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
+    std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(anAttribute);
   ListOfShape aListOfShapes;
   for(int anIndex = 0; anIndex < aSelectionList->size(); ++anIndex) {
     AttributeSelectionPtr aSelection = aSelectionList->value(anIndex);
-    ResultPtr aContext = aSelection->context();
     GeomShapePtr aShape = aSelection->value();
-    GeomShapePtr aContextShape = aContext->shape();
     if(!aShape.get()) {
       aShape = aSelection->context()->shape();
     }
@@ -127,3 +136,42 @@ bool BuildPlugin_ValidatorBaseForWire::isValid(const AttributePtr& theAttribute,
 
   return true;
 }
+
+//=================================================================================================
+bool BuildPlugin_ValidatorBaseForWireisNotObligatory(std::string theFeature, std::string theAttribute)
+{
+  return false;
+}
+
+//=================================================================================================
+bool BuildPlugin_ValidatorBaseForFace::isValid(const AttributePtr& theAttribute,
+                                               const std::list<std::string>& theArguments,
+                                               std::string& theError) const
+{
+  // Get base objects list.
+  BuildPlugin_ValidatorBaseForBuild aValidatorBaseForBuild;
+  std::list<std::string> anArguments;
+  anArguments.push_back("edge");
+  anArguments.push_back("wire");
+  if(!aValidatorBaseForBuild.isValid(theAttribute, anArguments, 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);
+    GeomShapePtr aShape = aSelection->value();
+    if(!aShape.get()) {
+      aShape = aSelection->context()->shape();
+    }
+    aListOfShapes.push_back(aShape);
+  }
+
+  // Check that they are planar.
+  GeomShapePtr aCompound = GeomAlgoAPI_CompoundBuilder::compound(aListOfShapes);
+
+  return aCompound->isPlanar();
+}
index b7c2420d94c2cb78ce6ed866d70828a9ca253475..8792c42ce9b4af7bcac37a0f63dee1360affaca6 100644 (file)
@@ -30,7 +30,26 @@ public:
 /// \ingroup Validators
 /// \brief A validator for selection base shapes for wire. Allows to select edges on sketch and
 /// wires objects that are connected to already selected shapes.
-class BuildPlugin_ValidatorBaseForWire: public ModelAPI_AttributeValidator
+class BuildPlugin_ValidatorBaseForWire: public ModelAPI_FeatureValidator
+{
+public:
+  //! Returns true if attributes is ok.
+  //! \param theFeature the checked feature.
+  //! \param theArguments arguments of the feature.
+  //! \param theError error message.
+  virtual bool isValid(const std::shared_ptr<ModelAPI_Feature>& theFeature,
+                       const std::list<std::string>& theArguments,
+                       std::string& theError) const;
+
+  /// \return true if the attribute in feature is not obligatory for the feature execution
+  virtual bool isNotObligatory(std::string theFeature, std::string theAttribute);
+};
+
+/// \class BuildPlugin_ValidatorBaseForFace
+/// \ingroup Validators
+/// \brief A validator for selection base shapes for face. Allows to select sketch edges, edges and
+/// wires objects that lie in the same plane.
+class BuildPlugin_ValidatorBaseForFace: public ModelAPI_AttributeValidator
 {
 public:
   //! Returns true if attribute is ok.
index e2843b4378726dc2843410e30d943cd324d57ea9..696c5fb9ad8357adfa478eb969d8bedecc5763da 100644 (file)
@@ -5,10 +5,11 @@
                   label="Segments and wires:"
                   tooltip="Select an edges on sketch or wires objects."
                   type_choice="edges objects">
-    <validator id="BuildPlugin_ValidatorBaseForWire" parameters="edge,wire"/>
+    <validator id="BuildPlugin_ValidatorBaseForBuild" parameters="edge,wire"/>
   </multi_selector>
   <action id="add_contour"
           label="Add contour"
           tooltip="Adds to the list of segments other segments of the sketcher
                    connected to the already selected ones to create a closed contour."/>
+  <validator id="BuildPlugin_ValidatorBaseForWire" parameters="base_objects"/>
 </source>