]> SALOME platform Git repositories - modules/shaper.git/blobdiff - src/FeaturesPlugin/FeaturesPlugin_Validators.cpp
Salome HOME
added new Sewing feature
[modules/shaper.git] / src / FeaturesPlugin / FeaturesPlugin_Validators.cpp
index 8878e2d921140a3423b4f44970733103c83fc250..c92dd6f896af12f5b94d42c93ece8ff02c01f1ff 100644 (file)
@@ -2097,3 +2097,69 @@ bool FeaturesPlugin_ValidatorDefeaturingSelection::isValid(
 
   return true;
 }
+
+
+//---------------------------------------------------------
+// #define USE_DEBUG
+// #define DEBUG
+// static const char *dbg_class = "FeaturesPlugin_ValidatorSewingSelection";
+// #include "MBDebug.h"
+// #include "MBModel.h"
+// #include "MBGeom.h"
+//---------------------------------------------------------
+
+//==================================================================================================
+bool FeaturesPlugin_ValidatorSewingSelection::isValid(const AttributePtr& theAttribute,
+                                                      const std::list<std::string>& theArguments,
+                                                      Events_InfoMessage& theError) const
+{
+  // DBG_FUN();
+  // ARG(theAttribute);
+
+  AttributeSelectionListPtr anAttrSelectionList =
+      std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
+  if (!anAttrSelectionList.get()) {
+    theError = "Error: This validator can only work with selection list attributes.";
+    return false;
+  }
+
+  // Check selected entities are of valid types
+  for (int anIndex = 0; anIndex < anAttrSelectionList->size(); ++anIndex) {
+    AttributeSelectionPtr anAttrSelection = anAttrSelectionList->value(anIndex);
+    if (!anAttrSelection.get()) {
+      theError = "Error: Empty attribute selection.";
+      return false;
+    }
+    ResultPtr aContext = anAttrSelection->context();
+    if (!aContext.get()) {
+      theError = "Error: Empty selection context.";
+      return false;
+    }
+    if (aContext->groupName() != ModelAPI_ResultBody::group()) {
+      theError = "Error: Not a result body.";
+      return false;
+    }
+
+    GeomShapePtr aContextShape = aContext->shape();
+    if (!aContextShape.get()) {
+      theError = "Error: Empty shape.";
+      return false;
+    }
+
+    GeomAPI_Shape::ShapeType aShapeType = aContextShape->shapeType();
+    std::set<GeomAPI_Shape::ShapeType> anAllowedTypes;
+    anAllowedTypes.insert(GeomAPI_Shape::FACE);
+    anAllowedTypes.insert(GeomAPI_Shape::SHELL);
+    anAllowedTypes.insert(GeomAPI_Shape::SOLID);
+    anAllowedTypes.insert(GeomAPI_Shape::COMPSOLID);
+    anAllowedTypes.insert(GeomAPI_Shape::COMPOUND);
+    if (anAllowedTypes.find(aShapeType) == anAllowedTypes.end()) {
+      theError = "Error: Selected shape has the wrong type.";
+      return false;
+    }
+
+  }
+
+  // MSGEL("...selection is VALID.");
+  return true;
+}