X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FFiltersPlugin%2FFiltersPlugin_OnShapeName.cpp;fp=src%2FFiltersPlugin%2FFiltersPlugin_OnShapeName.cpp;h=a01d9cb01571df87904764ec6ead4fc1960df193;hb=cf856efc73193392c635d21694abf44a314db419;hp=0000000000000000000000000000000000000000;hpb=28d8344b06d71fd4878181bc1909084923cba4cb;p=modules%2Fshaper.git diff --git a/src/FiltersPlugin/FiltersPlugin_OnShapeName.cpp b/src/FiltersPlugin/FiltersPlugin_OnShapeName.cpp new file mode 100644 index 000000000..a01d9cb01 --- /dev/null +++ b/src/FiltersPlugin/FiltersPlugin_OnShapeName.cpp @@ -0,0 +1,75 @@ +// 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 +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include "FiltersPlugin_OnShapeName.h" +#include +#include + +#include +#include + + +bool FiltersPlugin_OnShapeName::isSupported(GeomAPI_Shape::ShapeType /*theType*/) const +{ + return true; +} + +//======================================================================= +bool FiltersPlugin_OnShapeName::isOk(const GeomShapePtr& theShape, const ResultPtr& theResult, + const ModelAPI_FiltersArgs& theArgs) const +{ + if (!theResult) + return false; + + AttributePtr anAttr = theArgs.argument("pattern"); + AttributeStringPtr aValue = std::dynamic_pointer_cast(anAttr); + if (!aValue || !anAttr->isInitialized()) + return false; + + std::regex aPattern(aValue->value()); + + ResultBodyPtr aBodyRes = std::dynamic_pointer_cast(theResult); + + for(; aBodyRes.get(); aBodyRes = ModelAPI_Tools::bodyOwner(aBodyRes)) + { + const DataPtr data = aBodyRes->data(); + if (data.get()) + { + const std::string aResName = Locale::Convert::toString(data->name()); + if(std::regex_search(aResName, aPattern)) + { + return true; + } + } + } + + return false; +} + +//======================================================================= +std::string FiltersPlugin_OnShapeName::xmlRepresentation() const +{ + return xmlFromFile("filter-OnShapeName.xml"); +} + +//======================================================================= +void FiltersPlugin_OnShapeName::initAttributes(ModelAPI_FiltersArgs& theArguments) +{ + theArguments.initAttribute("pattern", ModelAPI_AttributeString::typeId()); +}