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_OnShapeName.h"
22 #include <ModelAPI_AttributeString.h>
23 // #include <Model_Data.h>
24 // #include <TDF_Label.hxx>
25 // #include <TNaming_Builder.hxx>
26 // #include <TNaming_NamedShape.hxx>
27 // #include <TDataStd_Name.hxx>
28 // #include <TNaming_Tool.hxx>
29 // #include <TopoDS_Shape.hxx>
31 #include <Locale_Convert.h>
32 #include <boost/algorithm/string.hpp>
34 bool FiltersPlugin_OnShapeName::isSupported(GeomAPI_Shape::ShapeType /*theType*/) const
39 static bool getShapesName(const GeomShapePtr& theShape,
40 ResultBodyPtr theResultBody,
41 std::string& theShapeName)
43 int nbSubRes = theResultBody->numberOfSubs();
44 if(theResultBody->shape()->isSame(theShape) || (nbSubRes == 0 && theResultBody->shape()->isSubShape(theShape)))
46 DataPtr data = theResultBody->data();
49 theShapeName = Locale::Convert::toString(data->name());
55 ResultBodyPtr subResult;
56 for (int i = 0; i < nbSubRes; i++)
58 subResult = theResultBody->subResult(i);
59 if(getShapesName(theShape, subResult, theShapeName))
69 bool FiltersPlugin_OnShapeName::isOk(const GeomShapePtr& theShape, const ResultPtr& theResult,
70 const ModelAPI_FiltersArgs& theArgs) const
72 AttributePtr anAttr = theArgs.argument("pattern");
73 AttributeStringPtr aValue = std::dynamic_pointer_cast<ModelAPI_AttributeString>(anAttr);
74 if (!aValue.get()|| !anAttr->isInitialized())
76 std::string aPattern= aValue->value();
79 ResultBodyPtr aBodyRes = std::dynamic_pointer_cast<ModelAPI_ResultBody>(theResult);
80 std::string aShapeName;
81 if(!getShapesName(theShape, aBodyRes, aShapeName))
86 //remove * from both sides of pattern
87 if(aPattern.back() == '*' && aPattern.front() == '*')
90 aPattern.erase(aPattern.begin());
94 if(aPattern.front() == '*')
96 aPattern.erase(aPattern.begin());
97 isFound = boost::algorithm::ends_with(aShapeName, aPattern);
99 else if(aPattern.back() == '*')
102 isFound = boost::algorithm::starts_with(aShapeName, aPattern);
106 isFound = (aShapeName.find(aPattern) != std::string::npos);
112 std::string FiltersPlugin_OnShapeName::xmlRepresentation() const
114 return xmlFromFile("filter-OnShapeName.xml");
117 void FiltersPlugin_OnShapeName::initAttributes(ModelAPI_FiltersArgs& theArguments)
119 theArguments.initAttribute("pattern", ModelAPI_AttributeString::typeId());