1 // Copyright (C) 2014-2019 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 email : webmaster.salome@opencascade.com
20 #include "FiltersPlugin_RelativeToSolid.h"
22 #include <GeomAPI_Solid.h>
24 #include <GeomAlgoAPI_SolidClassifier.h>
26 #include <ModelAPI_AttributeSelection.h>
27 #include <ModelAPI_AttributeString.h>
30 bool FiltersPlugin_RelativeToSolid::isSupported(GeomAPI_Shape::ShapeType theType) const
35 bool FiltersPlugin_RelativeToSolid::isOk(const GeomShapePtr& theShape,
36 const ModelAPI_FiltersArgs& theArgs) const
38 AttributePtr anAttr = theArgs.argument("Solid");
39 AttributeSelectionPtr aSel = std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(anAttr);
43 anAttr = theArgs.argument("Location");
44 AttributeStringPtr aLocAttr = std::dynamic_pointer_cast<ModelAPI_AttributeString>(anAttr);
47 std::string aLocString = aLocAttr->value();
49 GeomShapePtr aSolidSelected = aSel->value();
50 if (!aSolidSelected && aSel->context())
51 aSolidSelected = aSel->context()->shape();
52 GeomSolidPtr aSolid = aSolidSelected ? aSolidSelected->solid() : GeomSolidPtr();
56 GeomAlgoAPI_SolidClassifier aClassifier(aSolid, theShape);
57 GeomAlgoAPI_SolidClassifier::State aState = aClassifier.state();
60 if (aLocString == "in")
61 isOK = aState == GeomAlgoAPI_SolidClassifier::State_IN;
62 else if (aLocString == "out")
63 isOK = aState == GeomAlgoAPI_SolidClassifier::State_OUT;
64 else if (aLocString == "on")
65 isOK = aState == GeomAlgoAPI_SolidClassifier::State_ON;
66 else if (aLocString == "not_on")
67 isOK = !(aState & GeomAlgoAPI_SolidClassifier::State_ON);
68 else if (aLocString == "not_out")
69 isOK = !(aState & GeomAlgoAPI_SolidClassifier::State_OUT);
70 else if (aLocString == "not_in")
71 isOK = !(aState & GeomAlgoAPI_SolidClassifier::State_IN);
75 static std::string XMLRepresentation =
76 "<filter id = \"RelativeToSolid\">"
77 " <shape_selector id=\"RelativeToSolid__Solid\""
79 " tooltip=\"Select a solid.\""
80 " shape_types=\"solids\">"
81 " <validator id=\"GeomValidators_ShapeType\" parameters=\"solid\"/>"
83 " <switch id=\"RelativeToSolid__Location\" label=\"Algorithm:\">"
84 " <case id=\"in\" title=\"In\"/>"
85 " <case id=\"out\" title=\"Out\"/>"
86 " <case id=\"on\" title=\"On\"/>"
87 " <case id=\"not_on\" title=\"Not On\"/>"
88 " <case id=\"not_out\" title=\"In and On\"/>"
89 " <case id=\"not_in\" title=\"On and Out\"/>"
94 std::string FiltersPlugin_RelativeToSolid::xmlRepresentation() const
96 return XMLRepresentation;
99 void FiltersPlugin_RelativeToSolid::initAttributes(ModelAPI_FiltersArgs& theArguments)
101 theArguments.initAttribute("Solid", ModelAPI_AttributeSelection::typeId());
102 theArguments.initAttribute("Location", ModelAPI_AttributeString::typeId());