Salome HOME
Issue #1860: fix end lines with spaces
[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 <Events_InfoMessage.h>
6
7 #include "ModelAPI_AttributeSelection.h"
8 #include "ModelAPI_ResultConstruction.h"
9 #include "ModelAPI_CompositeFeature.h"
10
11 bool GeomValidators_ConstructionComposite::isValid(const AttributePtr& theAttribute,
12                                                    const std::list<std::string>& theArguments,
13                                                    Events_InfoMessage& theError) const
14 {
15   bool aValid = true;
16   if (theAttribute->attributeType() != ModelAPI_AttributeSelection::typeId()) {
17     aValid = false;
18     theError = "The attribute with the %1 type is not processed";
19     theError.arg(theAttribute->attributeType());
20     return aValid;
21   }
22
23   AttributeSelectionPtr aSelectionAttr = std::dynamic_pointer_cast<ModelAPI_AttributeSelection>
24                                                                 (theAttribute);
25   ResultPtr aResult = aSelectionAttr->context();
26   // global selection should be ignored, the filter processes only selected sub-shapes
27   // that means, that the shape of the context result is equal to the shape value
28   ///*ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theSelectedObject);
29   if (!aResult.get()) {
30     aValid = false;
31     theError = "The result is empty";
32   }
33   else {
34     GeomShapePtr aShape = aSelectionAttr->value();
35     GeomShapePtr aShapePtr = aResult->shape();
36     // it is important to call isEqual of the shape of result.
37     // It is a GeomAPI_Vertex shape for the point. The shape of the parameter is
38     // GeomAPI_Shape. It is important to use the realization of the isEqual method from
39     // GeomAPI_Vertex class
40     if (!aShape.get()) {
41       // an empty shape is used in attribute selection if the shape of the result is equal to
42       // the selected shape, so according to the upper condition, the result is true
43       aValid = true;
44     }
45     else {
46       if (aShapePtr->isEqual(aShape)) {
47         aValid = true;
48       }
49       else {
50         ResultConstructionPtr aConstr =
51           std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aResult);
52         if (!aConstr.get()) {
53           // non-construction results should be accepted by this filter, e.g. body results
54           aValid = true;
55         }
56         else {
57           // it provides selection only on composite features, construction without composite
58           // feature is not selectable.
59           FeaturePtr aFeature = ModelAPI_Feature::feature(aConstr);
60           CompositeFeaturePtr aComposite =
61             std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aFeature);
62           aValid = aComposite && aComposite->numberOfSubs() > 0;
63           if (!aValid)
64             theError = "Uses composite construction feature without sub-features.";
65         }
66       }
67     }
68   }
69   return aValid;
70 }