]> SALOME platform Git repositories - modules/shaper.git/blobdiff - src/GeomValidators/GeomValidators_BodyShapes.cpp
Salome HOME
Issue #1834: Fix length of lines
[modules/shaper.git] / src / GeomValidators / GeomValidators_BodyShapes.cpp
index 734938ecc3cfffa39d853182b4d21efbf79ce0c4..56068837aa9a90bc81e791632ceef4c410506bdf 100644 (file)
@@ -6,31 +6,47 @@
 
 #include "GeomValidators_BodyShapes.h"
 
+#include <Events_InfoMessage.h>
+
 #include <ModelAPI_AttributeSelectionList.h>
 #include <ModelAPI_Object.h>
+#include <ModelAPI_ResultConstruction.h>
 
 bool GeomValidators_BodyShapes::isValid(const AttributePtr& theAttribute,
-                                      const std::list<std::string>& theArguments,
-                                      std::string& theError) const
+                                        const std::list<std::string>& theArguments,
+                                        Events_InfoMessage& theError) const
 {
   std::string anAttributeType = theAttribute->attributeType();
-  if (anAttributeType == ModelAPI_AttributeSelectionList::typeId()) {
-    AttributeSelectionListPtr aSelectionListAttr = 
-                      std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
-    // all context objects should not be sketch entities
-    for(int i = 0, aSize = aSelectionListAttr->size(); i < aSize; i++) {
-      AttributeSelectionPtr aSelectAttr = aSelectionListAttr->value(i);
-      ObjectPtr anObject = aSelectAttr->context();
-      if (!anObject.get())
+  if(anAttributeType == ModelAPI_AttributeSelection::typeId()) {
+    AttributeSelectionPtr anAttrSelection =
+      std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
+    ResultPtr aContext = anAttrSelection->context();
+    if(!aContext.get()) {
+      theError = "Error: Context is empty.";
+      return false;
+    }
+
+    ResultConstructionPtr aResultConstruction =
+      std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aContext);
+    if(aResultConstruction.get()) {
+      theError = "Error: Result construction selected.";
+      return false;
+    }
+  } else if(anAttributeType == ModelAPI_AttributeSelectionList::typeId()) {
+    AttributeSelectionListPtr anAttrSelectionList =
+      std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
+
+    // All objects should not be result constructions.
+    for(int anIndex = 0, aSize = anAttrSelectionList->size(); anIndex < aSize; ++anIndex) {
+      AttributeSelectionPtr anAttrSelection = anAttrSelectionList->value(anIndex);
+      if(!isValid(anAttrSelection, theArguments, theError)) {
         return false;
-      else {
-        FeaturePtr aFeature = ModelAPI_Feature::feature(anObject);
-        std::string aFeatureKind = aFeature->getKind();
-        if(aFeatureKind == "Sketch") {
-          return false;
-        }
       }
     }
+  } else {
+    theError = "Error: Attribute \"%1\" does not supported by this validator.";
+    theError.arg(anAttributeType);
+    return false;
   }
 
   return true;