1 // Copyright (C) 2014-2017 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 #include "GeomValidators_ConstructionComposite.h"
23 #include <Events_InfoMessage.h>
25 #include "ModelAPI_AttributeSelection.h"
26 #include "ModelAPI_ResultConstruction.h"
27 #include "ModelAPI_CompositeFeature.h"
29 bool GeomValidators_ConstructionComposite::isValid(const AttributePtr& theAttribute,
30 const std::list<std::string>& theArguments,
31 Events_InfoMessage& theError) const
34 if (theAttribute->attributeType() != ModelAPI_AttributeSelection::typeId()) {
36 theError = "The attribute with the %1 type is not processed";
37 theError.arg(theAttribute->attributeType());
41 AttributeSelectionPtr aSelectionAttr = std::dynamic_pointer_cast<ModelAPI_AttributeSelection>
43 ResultPtr aResult = aSelectionAttr->context();
44 // global selection should be ignored, the filter processes only selected sub-shapes
45 // that means, that the shape of the context result is equal to the shape value
46 ///*ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theSelectedObject);
49 theError = "The result is empty";
52 GeomShapePtr aShape = aSelectionAttr->value();
53 GeomShapePtr aShapePtr = aResult->shape();
54 // it is important to call isEqual of the shape of result.
55 // It is a GeomAPI_Vertex shape for the point. The shape of the parameter is
56 // GeomAPI_Shape. It is important to use the realization of the isEqual method from
57 // GeomAPI_Vertex class
59 // an empty shape is used in attribute selection if the shape of the result is equal to
60 // the selected shape, so according to the upper condition, the result is true
64 if (aShapePtr->isEqual(aShape)) {
68 ResultConstructionPtr aConstr =
69 std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aResult);
71 // non-construction results should be accepted by this filter, e.g. body results
75 // it provides selection only on composite features, construction without composite
76 // feature is not selectable.
77 FeaturePtr aFeature = ModelAPI_Feature::feature(aConstr);
78 CompositeFeaturePtr aComposite =
79 std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aFeature);
80 aValid = aComposite && aComposite->numberOfSubs() > 0;
82 theError = "Uses composite construction feature without sub-features.";