1 // Copyright (C) 2014-2020 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
32 return theType >= GeomAPI_Shape::SHELL;
35 bool FiltersPlugin_RelativeToSolid::isOk(const GeomShapePtr& theShape, const ResultPtr&,
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 std::string FiltersPlugin_RelativeToSolid::xmlRepresentation() const
77 return xmlFromFile("filter-RelativeToSolid.xml");
80 void FiltersPlugin_RelativeToSolid::initAttributes(ModelAPI_FiltersArgs& theArguments)
82 theArguments.initAttribute("Solid", ModelAPI_AttributeSelection::typeId());
83 theArguments.initAttribute("Location", ModelAPI_AttributeString::typeId());