Salome HOME
Merge branch 'Dev_1.1.0' of newgeom:newgeom.git into Dev_1.1.0
[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 <ModelAPI_Session.h>
11 #include <ModelAPI_Result.h>
12 #include <ModelAPI_Tools.h>
13 #include <ModelAPI_AttributeRefAttr.h>
14
15 bool SketchPlugin_ExternalValidator::isValid(const AttributePtr& theAttribute,
16                                           const std::list<std::string>& theArguments) const
17 {
18   if (theArguments.size() != 1)
19     return true;
20
21   // ask whether the feature of the attribute is external
22   bool isAttributeExternal = isExternalAttribute(theAttribute);
23
24   // ask whether the feature of the attribute by parameter identifier is external
25   std::string aFrontArgument = theArguments.front();
26   FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
27   bool isParameterExternal = isExternalAttribute(aFeature->attribute(aFrontArgument));
28
29   // it is not possible that both features, attribute and attribute in parameter, are external
30   if (isAttributeExternal && isParameterExternal)
31     return false;
32   return true;
33 }
34
35 bool SketchPlugin_ExternalValidator::isExternalAttribute(const AttributePtr& theAttribute) const
36 {
37   bool isExternal = false;
38   AttributeRefAttrPtr anAttribute = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
39
40   if (anAttribute.get() != NULL) {
41     FeaturePtr anArgumentFeature = ModelAPI_Feature::feature(anAttribute->object());
42     if (anArgumentFeature.get() != NULL) {
43       std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
44                                     std::dynamic_pointer_cast<SketchPlugin_Feature>(anArgumentFeature);
45       if (aSketchFeature.get() != NULL) {
46         isExternal = aSketchFeature->isExternal();
47       }
48     }
49   }
50   return isExternal;
51 }