1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 #include "GeomValidators_ConstructionComposite.h"
5 #include <Events_InfoMessage.h>
7 #include "ModelAPI_AttributeSelection.h"
8 #include "ModelAPI_ResultConstruction.h"
9 #include "ModelAPI_CompositeFeature.h"
11 bool GeomValidators_ConstructionComposite::isValid(const AttributePtr& theAttribute,
12 const std::list<std::string>& theArguments,
13 Events_InfoMessage& theError) const
16 if (theAttribute->attributeType() != ModelAPI_AttributeSelection::typeId()) {
18 theError = "The attribute with the %1 type is not processed";
19 theError.arg(theAttribute->attributeType());
23 AttributeSelectionPtr aSelectionAttr = std::dynamic_pointer_cast<ModelAPI_AttributeSelection>
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);
31 theError = "The result is empty";
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
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
46 if (aShapePtr->isEqual(aShape)) {
50 ResultConstructionPtr aConstr =
51 std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aResult);
53 // non-construction results should be accepted by this filter, e.g. body results
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;
64 theError = "Uses composite construction feature without sub-features.";