Salome HOME
Add error descriptions for some feture and attribute validators
[modules/shaper.git] / src / GeomValidators / GeomValidators_ConstructionComposite.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 #include "GeomValidators_ConstructionComposite.h"
4
5 #include "ModelAPI_AttributeSelection.h"
6 #include "ModelAPI_ResultConstruction.h"
7 #include "ModelAPI_CompositeFeature.h"
8
9 bool GeomValidators_ConstructionComposite::isValid(const AttributePtr& theAttribute,
10                                                    const std::list<std::string>& theArguments,
11                                                    std::string& theError) const
12 {
13   bool aValid = false;
14   AttributeSelectionPtr aSelectionAttr = std::dynamic_pointer_cast<ModelAPI_AttributeSelection>
15                                                                 (theAttribute);
16   if (aSelectionAttr.get() == NULL) {
17     theError = "Is not a selection attribute.";
18     return aValid;
19   }
20
21   ResultPtr aResult = aSelectionAttr->context();
22   GeomShapePtr aShape = aSelectionAttr->value();
23   // global selection should be ignored, the filter processes only selected sub-shapes
24   // that means, that the shape of the context result is equal to the shape value
25   ///*ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theSelectedObject);
26   if (aResult.get() != NULL) {
27     GeomShapePtr aShapePtr = aResult->shape();
28     // it is important to call isEqual of the shape of result.
29     // It is a GeomAPI_Vertex shape for the point. The shape of the parameter is 
30     // GeomAPI_Shape. It is important to use the realization of the isEqual method from
31     // GeomAPI_Vertex class
32     if (aShape.get()) {
33       aValid = aShapePtr.get() != NULL && aShapePtr->isEqual(aShape);
34     }
35     else {
36       // an empty shape is used in attribute selection if the shape of the result is equal to
37       // the selected shape, so according to the upper condition, the result is true
38       aValid = true;
39     }
40   }
41   if (!aValid) {
42     ResultConstructionPtr aConstr =
43                             std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aResult);
44     if (aConstr != NULL) {
45       // it provides selection only on composite features, construction without composite
46       // feature is not selectable
47       FeaturePtr aFeature = ModelAPI_Feature::feature(aConstr);
48       CompositeFeaturePtr aComposite = 
49                              std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aFeature);
50       aValid = aComposite && aComposite->numberOfSubs() > 0;
51     }
52     else {
53       // non-construction results should be accepted by this filter, e.g. body results
54       aValid = true;
55     }
56   }
57   return aValid;
58 }