Salome HOME
Added CPP High API for FeaturesPlugin_Pipe
[modules/shaper.git] / src / GeomValidators / GeomValidators_FeatureKind.cpp
index edf205f05874a1709037a78aaaa53f8be654db91..9c663a1f7984925943fc3daa2b6c2f2a256ac018 100755 (executable)
@@ -9,9 +9,10 @@
 #include <ModelAPI_AttributeSelectionList.h>
 #include <ModelAPI_AttributeRefList.h>
 #include <ModelAPI_AttributeRefAttr.h>
+#include <ModelAPI_AttributeReference.h>
 #include <ModelAPI_Object.h>
 
-//#define DEBUG_EXTRUSION_INVALID_SKETCH
+#define DEBUG_EXTRUSION_INVALID_SKETCH
 #ifdef DEBUG_EXTRUSION_INVALID_SKETCH
   #include <ModelAPI_CompositeFeature.h>
 #endif
@@ -102,6 +103,21 @@ bool GeomValidators_FeatureKind::isValid(const AttributePtr& theAttribute,
       }
     }
   }
+  if (anAttributeType == ModelAPI_AttributeReference::typeId()) {
+    AttributeReferencePtr aRefAttr = 
+                      std::dynamic_pointer_cast<ModelAPI_AttributeReference>(theAttribute);
+    ObjectPtr anObject = aRefAttr->value();
+    // a context of the selection attribute is a feature result. It can be a case when the result
+    // of the feature is null, e.g. the feature is modified and has not been executed yet.
+    // The validator returns an invalid result here. The case is an extrusion built on a sketch
+    // feature. A new sketch element creation leads to an empty result.
+    if (!anObject.get())
+      isSketchEntities = false;
+    else {
+      FeaturePtr aFeature = ModelAPI_Feature::feature(anObject);
+      isSketchEntities = anEntityKinds.find(aFeature->getKind()) != anEntityKinds.end();
+    }
+  }
   if (!isSketchEntities) {
     theError = "It refers to feature, which kind is not in the list: " + anEntityKindsStr;
   }