]> SALOME platform Git repositories - modules/shaper.git/blob - src/SketchPlugin/SketchPlugin_ExternalValidator.cpp
Salome HOME
Revert change for MacroArc attribute names
[modules/shaper.git] / src / SketchPlugin / SketchPlugin_ExternalValidator.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
2
3 // File:        Model_ResultValidators.cpp
4 // Created:     27 Feb 2015
5 // Author:      Natalia ERMOLAEVA
6
7 #include "SketchPlugin_ExternalValidator.h"
8 #include "SketchPlugin_Feature.h"
9
10 #include <Events_InfoMessage.h>
11
12 #include <ModelAPI_Session.h>
13 #include <ModelAPI_Result.h>
14 #include <ModelAPI_Tools.h>
15 #include <ModelAPI_AttributeRefAttr.h>
16
17 bool SketchPlugin_ExternalValidator::isValid(const AttributePtr& theAttribute,
18                                              const std::list<std::string>& theArguments,
19                                              Events_InfoMessage& theError) const
20 {
21   if (theArguments.size() != 1)
22     return true;
23
24   // ask whether the feature of the attribute is external
25   bool isAttributeExternal = isExternalAttribute(theAttribute);
26
27   // ask whether the feature of the attribute by parameter identifier is external
28   std::string aFrontArgument = theArguments.front();
29   FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
30   bool isParameterExternal = isExternalAttribute(aFeature->attribute(aFrontArgument));
31
32   // it is not possible that both features, attribute and attribute in parameter, are external
33   if (isAttributeExternal && isParameterExternal) {
34     theError = "Both features, attribute and attribute in parameter, are external.";
35     return false;
36   }
37   return true;
38 }
39
40 bool SketchPlugin_ExternalValidator::isExternalAttribute(const AttributePtr& theAttribute) const
41 {
42   bool isExternal = false;
43   AttributeRefAttrPtr anAttribute =
44     std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
45
46   if (anAttribute.get() != NULL) {
47     FeaturePtr anArgumentFeature = ModelAPI_Feature::feature(anAttribute->object());
48     if (anArgumentFeature.get() != NULL) {
49       std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
50                         std::dynamic_pointer_cast<SketchPlugin_Feature>(anArgumentFeature);
51       if (aSketchFeature.get() != NULL) {
52         isExternal = aSketchFeature->isExternal();
53       }
54     }
55   }
56   return isExternal;
57 }