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_NotSelfIntersected.h"
23 #include <GeomAPI_Shape.h>
25 #include <Events_InfoMessage.h>
27 #include <ModelAPI_AttributeSelection.h>
28 #include <ModelAPI_AttributeSelectionList.h>
29 #include <ModelAPI_Feature.h>
31 bool GeomValidators_NotSelfIntersected::isValid(const std::shared_ptr<ModelAPI_Feature>& theFeature,
32 const std::list<std::string>& theArguments,
33 Events_InfoMessage& theError) const
35 if (theArguments.empty()) {
36 theError = "Error: empty selection.";
40 for (std::list<std::string>::const_iterator anIt = theArguments.cbegin();
41 anIt != theArguments.cend();
44 std::string anArgument = *anIt;
45 AttributePtr anAttribute = theFeature->attribute(anArgument);
46 if (!anAttribute.get()) {
47 theError = std::string("Error: Feature does not contain attribute: ") + anArgument;
50 if (anAttribute->attributeType() == ModelAPI_AttributeSelectionList::typeId()) {
51 AttributeSelectionListPtr anAttrSelectionList =
52 std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(anAttribute);
53 for (int anIndex = 0; anIndex < anAttrSelectionList->size(); ++anIndex) {
54 AttributeSelectionPtr anAttrSelection = anAttrSelectionList->value(anIndex);
55 if (!anAttrSelection.get()) {
56 theError = "Error: Empty attribute selection.";
59 ResultPtr aContext = anAttrSelection->context();
60 if (!aContext.get()) {
61 FeaturePtr aContFeat = anAttrSelection->contextFeature();
62 if (!aContFeat.get() || !aContFeat->results().size()) {
63 theError = "Error: Empty selection context.";
67 std::shared_ptr<GeomAPI_Shape> aShape = anAttrSelection->value();
68 if (!aShape.get() && aContext.get()) {
69 GeomShapePtr aContextShape = aContext->shape();
70 aShape = aContextShape;
73 theError = "Error: Empty shape.";
77 /* optimization if (aShape->isSelfIntersected(4)) {
78 theError = "Error: One of selected shapes are self-intersected.";
83 theError = std::string("Error: validator does not support attribute with type: ")
84 + anAttribute->attributeType();
92 bool GeomValidators_NotSelfIntersected::isNotObligatory(std::string /*theFeature*/,
93 std::string /*theAttribute*/)