Salome HOME
Issue #2079 : Select parent feature for default Constructions. Disable popup menu...
[modules/shaper.git] / src / GeomValidators / GeomValidators_FeatureKind.cpp
index edf205f05874a1709037a78aaaa53f8be654db91..25fcc90cee45abaada8f2c30e2ebd6ad5ced9d8c 100755 (executable)
@@ -6,19 +6,22 @@
 
 #include "GeomValidators_FeatureKind.h"
 
+#include <Events_InfoMessage.h>
+
 #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
 
 bool GeomValidators_FeatureKind::isValid(const AttributePtr& theAttribute,
                                       const std::list<std::string>& theArguments,
-                                      std::string& theError) const
+                                      Events_InfoMessage& theError) const
 {
   bool isSketchEntities = true;
   std::set<std::string> anEntityKinds;
@@ -33,7 +36,7 @@ bool GeomValidators_FeatureKind::isValid(const AttributePtr& theAttribute,
 
   std::string anAttributeType = theAttribute->attributeType();
   if (anAttributeType == ModelAPI_AttributeSelectionList::typeId()) {
-    AttributeSelectionListPtr aSelectionListAttr = 
+    AttributeSelectionListPtr aSelectionListAttr =
                       std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
     // all context objects should be sketch entities
     for (int i = 0, aSize = aSelectionListAttr->size(); i < aSize && isSketchEntities; i++) {
@@ -57,7 +60,7 @@ bool GeomValidators_FeatureKind::isValid(const AttributePtr& theAttribute,
     }
   }
   if (anAttributeType == ModelAPI_AttributeSelection::typeId()) {
-    AttributeSelectionPtr aSelectAttr = 
+    AttributeSelectionPtr aSelectAttr =
                       std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
     ObjectPtr anObject = aSelectAttr->context();
     // a context of the selection attribute is a feature result. It can be a case when the result
@@ -90,7 +93,7 @@ bool GeomValidators_FeatureKind::isValid(const AttributePtr& theAttribute,
     }
   }
   if (anAttributeType == ModelAPI_AttributeRefAttr::typeId()) {
-    std::shared_ptr<ModelAPI_AttributeRefAttr> aRef = 
+    std::shared_ptr<ModelAPI_AttributeRefAttr> aRef =
                      std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
     isSketchEntities = false;
     if (aRef->isObject()) {
@@ -102,6 +105,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;
   }