Salome HOME
Fix for the correct update of the extrusion created on sketch on lateral face of...
[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) const
11 {
12   bool aValid = false;
13   AttributeSelectionPtr aSelectionAttr = std::dynamic_pointer_cast<ModelAPI_AttributeSelection>
14                                                                 (theAttribute);
15   if (aSelectionAttr.get() == NULL)
16     return aValid;
17
18   ResultPtr aResult = aSelectionAttr->context();
19   GeomShapePtr aShape = aSelectionAttr->value();
20   // global selection should be ignored, the filter processes only selected sub-shapes
21   // that means, that the shape of the context result is equal to the shape value
22   ///*ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theSelectedObject);
23   if (aResult.get() != NULL) {
24     GeomShapePtr aShapePtr = aResult->shape();
25     // it is important to call isEqual of the shape of result.
26     // It is a GeomAPI_Vertex shape for the point. The shape of the parameter is 
27     // GeomAPI_Shape. It is important to use the realization of the isEqual method from
28     // GeomAPI_Vertex class
29     if (aShape.get()) {
30       aValid = aShapePtr.get() != NULL && aShapePtr->isEqual(aShape);
31     }
32     else {
33       // an empty shape is used in attribute selection if the shape of the result is equal to
34       // the selected shape, so according to the upper condifition, the result is true
35       aValid = true;
36     }
37   }
38   if (!aValid) {
39     ResultConstructionPtr aConstr =
40                             std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aResult);
41     if (aConstr != NULL) {
42       // it provides selection only on compositie features, construction without composite
43       // feature is not selectable
44       FeaturePtr aFeature = ModelAPI_Feature::feature(aConstr);
45       CompositeFeaturePtr aComposite = 
46                              std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aFeature);
47       aValid = aComposite && aComposite->numberOfSubs() > 0;
48     }
49     else {
50       // non-construction results should be accepted by this filter, e.g. body results
51       aValid = true;
52     }
53   }
54   return aValid;
55 }