-// Copyright (C) 2014-2019 CEA/DEN, EDF R&D
+// Copyright (C) 2014-2023 CEA, EDF
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
#include "FiltersPlugin_RelativeToSolid.h"
+#include <GeomAPI_Solid.h>
+
+#include <GeomAlgoAPI_SolidClassifier.h>
+
#include <ModelAPI_AttributeSelection.h>
#include <ModelAPI_AttributeString.h>
bool FiltersPlugin_RelativeToSolid::isSupported(GeomAPI_Shape::ShapeType theType) const
{
- return true;
+ return theType >= GeomAPI_Shape::SHELL;
}
-bool FiltersPlugin_RelativeToSolid::isOk(const GeomShapePtr& theShape,
+bool FiltersPlugin_RelativeToSolid::isOk(const GeomShapePtr& theShape, const ResultPtr&,
const ModelAPI_FiltersArgs& theArgs) const
{
- return false;
-}
+ AttributePtr anAttr = theArgs.argument("Solid");
+ AttributeSelectionPtr aSel = std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(anAttr);
+ if (!aSel)
+ return false;
-static std::string XMLRepresentation =
-"<filter id = \"RelativeToSolid\">"
-" <shape_selector id=\"RelativeToSolid__Solid\""
-" label=\"Solid:\""
-" tooltip=\"Select a solid.\""
-" shape_types=\"solids\">"
-" <validator id=\"GeomValidators_ShapeType\" parameters=\"solid\"/>"
-" </shape_selector>"
-" <switch id=\"RelativeToSolid__Location\" label=\"Algorithm:\">"
-" <case id=\"in\" title=\"In\"/>"
-" <case id=\"out\" title=\"Out\"/>"
-" <case id=\"on\" title=\"On\"/>"
-" <case id=\"noton\" title=\"Not On\"/>"
-" <case id=\"inon\" title=\"In & On\"/>"
-" <case id=\"outon\" title=\"On & Out\"/>"
-" </switch>"
-"</filter>";
+ anAttr = theArgs.argument("Location");
+ AttributeStringPtr aLocAttr = std::dynamic_pointer_cast<ModelAPI_AttributeString>(anAttr);
+ if (!aLocAttr)
+ return false;
+ std::string aLocString = aLocAttr->value();
+ GeomShapePtr aSolidSelected = aSel->value();
+ if (!aSolidSelected && aSel->context())
+ aSolidSelected = aSel->context()->shape();
+ GeomSolidPtr aSolid = aSolidSelected ? aSolidSelected->solid() : GeomSolidPtr();
+ if (!aSolid)
+ return false;
+
+ GeomAlgoAPI_SolidClassifier aClassifier(aSolid, theShape);
+ GeomAlgoAPI_SolidClassifier::State aState = aClassifier.state();
+
+ bool isOK = false;
+ if (aLocString == "in")
+ isOK = aState == GeomAlgoAPI_SolidClassifier::State_IN;
+ else if (aLocString == "out")
+ isOK = aState == GeomAlgoAPI_SolidClassifier::State_OUT;
+ else if (aLocString == "on")
+ isOK = aState == GeomAlgoAPI_SolidClassifier::State_ON;
+ else if (aLocString == "not_on")
+ isOK = !(aState & GeomAlgoAPI_SolidClassifier::State_ON);
+ else if (aLocString == "not_out")
+ isOK = !(aState & GeomAlgoAPI_SolidClassifier::State_OUT);
+ else if (aLocString == "not_in")
+ isOK = !(aState & GeomAlgoAPI_SolidClassifier::State_IN);
+ return isOK;
+}
std::string FiltersPlugin_RelativeToSolid::xmlRepresentation() const
{
- return XMLRepresentation;
+ return xmlFromFile("filter-RelativeToSolid.xml");
}
void FiltersPlugin_RelativeToSolid::initAttributes(ModelAPI_FiltersArgs& theArguments)