Salome HOME
Issue #353 constraint on 2 segments from not acive sketches
[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 FeaturePtr& theFeature,
17                                                   const std::list<std::string>& theArguments,
18                                                   const ObjectPtr& theObject,
19                                                   const AttributePtr& theAttribute,
20                                                   const GeomShapePtr& theShape) const
21 {
22   ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
23   std::shared_ptr<GeomAPI_Shape> aShape = ModelAPI_Tools::shape(aResult);
24
25   // if the shapes are equal, that means that the given shape is a result.
26   // if the result is selected, the 
27   if (aShape->isEqual(theShape))
28     return true;
29
30   // found a non-external argument on the feature
31   std::list<std::string>::const_iterator anIt = theArguments.begin(), aLast = theArguments.end();
32   bool aHasNullParam = false;
33   bool aHasNonExternalParams = false;
34   for (; anIt != aLast; anIt++) {
35     std::string aParamA = *anIt;
36     std::shared_ptr<ModelAPI_AttributeRefAttr> anAttr = std::dynamic_pointer_cast<
37           ModelAPI_AttributeRefAttr>(theFeature->data()->attribute(aParamA));
38     if (anAttr) {
39       FeaturePtr anOtherFeature = ModelAPI_Feature::feature(anAttr->object());
40       if (anOtherFeature.get() != NULL) {
41         std::shared_ptr<SketchPlugin_Feature> aSketchFeature = 
42           std::dynamic_pointer_cast<SketchPlugin_Feature>(anOtherFeature);
43         if (aSketchFeature) {
44           aHasNonExternalParams = !aSketchFeature->isExternal();
45         }
46       }
47       else
48         aHasNullParam = true;
49     }
50   }
51   if (aHasNullParam || aHasNonExternalParams)
52     return true;
53   return false;
54 }