1 // Copyright (C) 2014-2023 CEA, EDF
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_FaceSize.h"
22 #include <ModelAPI_AttributeString.h>
23 #include <ModelAPI_AttributeDouble.h>
24 #include <GeomAlgoAPI_ShapeTools.h>
25 #include <ModelAPI_Tools.h>
27 #include <GeomAPI_Edge.h>
28 #include <GeomAPI_Shape.h>
29 #include <GeomAPI_Wire.h>
31 #include <Precision.hxx>
36 //=================================================================================================
37 bool FiltersPlugin_FaceSize::isSupported(GeomAPI_Shape::ShapeType theType) const
39 return theType == GeomAPI_Shape::FACE;
42 //=================================================================================================
43 bool FiltersPlugin_FaceSize::isOk(const GeomShapePtr& theShape, const ResultPtr&,
44 const ModelAPI_FiltersArgs& theArgs) const
46 AttributePtr anAttr = theArgs.argument("value");
47 AttributeDoublePtr aValue = std::dynamic_pointer_cast<ModelAPI_AttributeDouble>(anAttr);
48 if (!aValue.get()|| !anAttr->isInitialized() )
50 double aVal = aValue->value();
52 anAttr = theArgs.argument("valueMax");
53 aValue = std::dynamic_pointer_cast<ModelAPI_AttributeDouble>(anAttr);
54 if (!aValue.get()|| !anAttr->isInitialized() )
56 double aValMax = aValue->value();
61 double aSurfArea = GeomAlgoAPI_ShapeTools::area(theShape);
63 anAttr = theArgs.argument("comparatorType");
64 AttributeStringPtr aCompAttr = std::dynamic_pointer_cast<ModelAPI_AttributeString>(anAttr);
67 std::string aCompString = aCompAttr->value();
70 if (aCompString == "inf")
71 isOK = aSurfArea < aVal - Precision::Confusion();
72 else if (aCompString == "infEq")
73 isOK = aSurfArea < aVal + Precision::Confusion();
74 else if (aCompString == "sup")
75 isOK = aSurfArea > aVal + Precision::Confusion();
76 else if (aCompString == "supEq")
77 isOK = aSurfArea > aVal - Precision::Confusion();
78 else if (aCompString == "isBetween")
79 isOK = aVal <= aValMax
80 && aSurfArea > aVal - Precision::Confusion()
81 && aSurfArea < aValMax + Precision::Confusion();
82 else if (aCompString == "isStrictlyBetween")
83 isOK = aVal <= aValMax
84 && aSurfArea > aVal + Precision::Confusion()
85 && aSurfArea < aValMax - Precision::Confusion();
89 //=================================================================================================
90 std::string FiltersPlugin_FaceSize::xmlRepresentation() const
92 return xmlFromFile("filter-FaceSize.xml");
95 //=================================================================================================
96 void FiltersPlugin_FaceSize::initAttributes(ModelAPI_FiltersArgs& theArguments)
98 theArguments.initAttribute("comparatorType", ModelAPI_AttributeString::typeId());
99 theArguments.initAttribute("value", ModelAPI_AttributeDouble::typeId());
100 theArguments.initAttribute("valueMax", ModelAPI_AttributeDouble::typeId());