1 // Copyright (C) 2014-2022 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_EdgeSize.h"
22 #include <ModelAPI_AttributeString.h>
23 #include <ModelAPI_AttributeDouble.h>
24 #include <ModelAPI_ResultBody.h>
25 #include <ModelAPI_Tools.h>
27 #include <GeomAPI_Edge.h>
28 #include <GeomAPI_Shape.h>
29 #include <GeomAPI_Wire.h>
31 #include <GeomAlgoAPI_ShapeTools.h>
33 #include <Precision.hxx>
38 //=================================================================================================
39 bool FiltersPlugin_EdgeSize::isSupported(GeomAPI_Shape::ShapeType theType) const
41 return theType == GeomAPI_Shape::EDGE;
44 //=================================================================================================
45 bool FiltersPlugin_EdgeSize::isOk(const GeomShapePtr& theShape, const ResultPtr&,
46 const ModelAPI_FiltersArgs& theArgs) const
48 AttributePtr anAttr = theArgs.argument("value");
49 AttributeDoublePtr aValue = std::dynamic_pointer_cast<ModelAPI_AttributeDouble>(anAttr);
50 if (!aValue.get()|| !anAttr->isInitialized() )
52 double aVal = aValue->value();
54 anAttr = theArgs.argument("valueMax");
55 aValue = std::dynamic_pointer_cast<ModelAPI_AttributeDouble>(anAttr);
56 if (!aValue.get()|| !anAttr->isInitialized() )
58 double aValMax = aValue->value();
64 switch (theShape->shapeType()) {
65 case GeomAPI_Shape::EDGE:
66 anEdge = GeomEdgePtr(new GeomAPI_Edge(theShape));
68 case GeomAPI_Shape::WIRE:
69 anEdge = GeomAlgoAPI_ShapeTools::wireToEdge(
70 GeomWirePtr(new GeomAPI_Wire(theShape)));
76 double aLength = anEdge->length();
78 anAttr = theArgs.argument("comparatorType");
79 AttributeStringPtr aCompAttr = std::dynamic_pointer_cast<ModelAPI_AttributeString>(anAttr);
82 std::string aCompString = aCompAttr->value();
85 if (aCompString == "inf")
86 isOK = aLength < aVal - Precision::Confusion();
87 else if (aCompString == "infEq")
88 isOK = aLength < aVal + Precision::Confusion();
89 else if (aCompString == "sup")
90 isOK = aLength > aVal + Precision::Confusion();
91 else if (aCompString == "supEq")
92 isOK = aLength > aVal - Precision::Confusion();
93 else if (aCompString == "isBetween")
94 isOK = aVal <= aValMax
95 && aLength > aVal - Precision::Confusion()
96 && aLength < aValMax + Precision::Confusion();
97 else if (aCompString == "isStrictlyBetween")
98 isOK = aVal <= aValMax
99 && aLength > aVal + Precision::Confusion()
100 && aLength < aValMax - Precision::Confusion();
104 //=================================================================================================
105 std::string FiltersPlugin_EdgeSize::xmlRepresentation() const
107 return xmlFromFile("filter-EdgeSize.xml");
110 //=================================================================================================
111 void FiltersPlugin_EdgeSize::initAttributes(ModelAPI_FiltersArgs& theArguments)
113 theArguments.initAttribute("comparatorType", ModelAPI_AttributeString::typeId());
114 theArguments.initAttribute("value", ModelAPI_AttributeDouble::typeId());
115 theArguments.initAttribute("valueMax", ModelAPI_AttributeDouble::typeId());