]> SALOME platform Git repositories - modules/shaper.git/blob - src/SketchPlugin/SketchPlugin_ShapeValidator.cpp
Salome HOME
Multi-selection widget to be used in the extrusion feature.
[modules/shaper.git] / src / SketchPlugin / SketchPlugin_ShapeValidator.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_ShapeValidator.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 #include <ModelAPI_ResultValidator.h>
15
16 bool SketchPlugin_ShapeValidator::isValid(const AttributePtr& theAttribute,
17                                           const std::list<std::string>& theArguments) const
18 {
19   if (theArguments.size() != 1)
20     return true;
21
22   // ask whether the feature of the attribute is external
23   //std::shared_ptr<SketchPlugin_Feature> aSketchFeature = 
24   //AttributeRefAttrPtr anAttribute = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
25   //                               std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
26   bool isAttributeExternal = isExternalAttribute(theAttribute);
27
28   // ask whether the feature of the attribute by parameter identifier is external
29   std::string aFrontArgument = theArguments.front();
30   FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
31   bool isParameterExternal = isExternalAttribute(aFeature->attribute(aFrontArgument));
32
33   // it is not possible that both features, attribute and attribute in parameter, are external
34   if (isAttributeExternal && isParameterExternal)
35     return false;
36   return true;
37 }
38
39 bool SketchPlugin_ShapeValidator::isExternalAttribute(const AttributePtr& theAttribute) const
40 {
41   bool isExternal = false;
42   AttributeRefAttrPtr anAttribute = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
43
44   if (anAttribute.get() != NULL) {
45     FeaturePtr anArgumentFeature = ModelAPI_Feature::feature(anAttribute->object());
46     if (anArgumentFeature.get() != NULL) {
47       std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
48                                     std::dynamic_pointer_cast<SketchPlugin_Feature>(anArgumentFeature);
49       if (aSketchFeature.get() != NULL) {
50         isExternal = aSketchFeature->isExternal();
51       }
52     }
53   }
54   return isExternal;
55 }