1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 #include "GeomValidators_ConstructionComposite.h"
5 #include "ModelAPI_AttributeSelection.h"
6 #include "ModelAPI_ResultConstruction.h"
7 #include "ModelAPI_CompositeFeature.h"
9 bool GeomValidators_ConstructionComposite::isValid(const AttributePtr& theAttribute,
10 const std::list<std::string>& theArguments,
11 std::string& theError) const
14 AttributeSelectionPtr aSelectionAttr = std::dynamic_pointer_cast<ModelAPI_AttributeSelection>
16 if (aSelectionAttr.get() == NULL)
19 ResultPtr aResult = aSelectionAttr->context();
20 GeomShapePtr aShape = aSelectionAttr->value();
21 // global selection should be ignored, the filter processes only selected sub-shapes
22 // that means, that the shape of the context result is equal to the shape value
23 ///*ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theSelectedObject);
24 if (aResult.get() != NULL) {
25 GeomShapePtr aShapePtr = aResult->shape();
26 // it is important to call isEqual of the shape of result.
27 // It is a GeomAPI_Vertex shape for the point. The shape of the parameter is
28 // GeomAPI_Shape. It is important to use the realization of the isEqual method from
29 // GeomAPI_Vertex class
31 aValid = aShapePtr.get() != NULL && aShapePtr->isEqual(aShape);
34 // an empty shape is used in attribute selection if the shape of the result is equal to
35 // the selected shape, so according to the upper condifition, the result is true
40 ResultConstructionPtr aConstr =
41 std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aResult);
42 if (aConstr != NULL) {
43 // it provides selection only on compositie features, construction without composite
44 // feature is not selectable
45 FeaturePtr aFeature = ModelAPI_Feature::feature(aConstr);
46 CompositeFeaturePtr aComposite =
47 std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aFeature);
48 aValid = aComposite && aComposite->numberOfSubs() > 0;
51 // non-construction results should be accepted by this filter, e.g. body results