Salome HOME
Issue #2405: Fatal error when create Length constraint on axis
[modules/shaper.git] / src / SketchPlugin / SketchPlugin_Validators.cpp
index 3c6fcc3471828c096c8eab647290c5953d7dcec4..91728508f83ced9e58f1bb6d9221c842cdde3c34 100755 (executable)
@@ -1609,3 +1609,34 @@ bool SketchPlugin_ReplicationReferenceValidator::isValid(
 
   return true;
 }
+
+bool SketchPlugin_SketchFeatureValidator::isValid(const AttributePtr& theAttribute,
+                                                  const std::list<std::string>& theArguments,
+                                                  Events_InfoMessage& theError) const
+{
+  if (theAttribute->attributeType() != ModelAPI_AttributeRefAttr::typeId()) {
+    theError = "The attribute with the %1 type is not processed";
+    theError.arg(theAttribute->attributeType());
+    return false;
+  }
+
+  // check the attribute refers to a sketch feature
+  AttributeRefAttrPtr aRefAttr =
+      std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
+  bool isSketchFeature = aRefAttr->isObject();
+  if (isSketchFeature) {
+    FeaturePtr aFeature = ModelAPI_Feature::feature(aRefAttr->object());
+    isSketchFeature = aFeature;
+    if (isSketchFeature) {
+      std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
+          std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
+      isSketchFeature = aSketchFeature;
+    }
+  }
+
+  if (isSketchFeature)
+    return true;
+
+  theError = "The object selected is not a sketch feature";
+  return false;
+}