From: azv Date: Mon, 29 Jul 2019 14:50:24 +0000 (+0300) Subject: Issue #2949: "On geometry" filter correct name and selection mechanism X-Git-Tag: VEDF2019Lot4~78 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=506de25d5d7c9ecf1cdd770160983678cb06ccb9;p=modules%2Fshaper.git Issue #2949: "On geometry" filter correct name and selection mechanism Implement new validator to select shape types specified by the Group feature. --- diff --git a/src/FiltersPlugin/CMakeLists.txt b/src/FiltersPlugin/CMakeLists.txt index 5a52a8cfd..f4dd05839 100644 --- a/src/FiltersPlugin/CMakeLists.txt +++ b/src/FiltersPlugin/CMakeLists.txt @@ -34,6 +34,7 @@ SET(PROJECT_HEADERS FiltersPlugin_OppositeToEdge.h FiltersPlugin_RelativeToSolid.h FiltersPlugin_ExternalFaces.h + FiltersPlugin_Validators.h ) SET(PROJECT_SOURCES @@ -49,6 +50,7 @@ SET(PROJECT_SOURCES FiltersPlugin_OppositeToEdge.cpp FiltersPlugin_RelativeToSolid.cpp FiltersPlugin_ExternalFaces.cpp + FiltersPlugin_Validators.cpp ) SET(PROJECT_LIBRARIES @@ -57,6 +59,7 @@ SET(PROJECT_LIBRARIES Config GeomAPI GeomAlgoAPI + GeomValidators ) SET(PROJECT_PYFILES @@ -87,6 +90,8 @@ INCLUDE_DIRECTORIES( ${PROJECT_SOURCE_DIR}/src/GeomAPI ${PROJECT_SOURCE_DIR}/src/GeomAlgoAPI ${PROJECT_SOURCE_DIR}/src/GeomDataAPI + ${PROJECT_SOURCE_DIR}/src/GeomValidators + ${PROJECT_SOURCE_DIR}/src/CollectionPlugin ) INSTALL(TARGETS Filters DESTINATION ${SHAPER_INSTALL_PLUGIN_FILES}) diff --git a/src/FiltersPlugin/FiltersPlugin_Plugin.cpp b/src/FiltersPlugin/FiltersPlugin_Plugin.cpp index 0ff5b5f69..e7bc6a9ad 100644 --- a/src/FiltersPlugin/FiltersPlugin_Plugin.cpp +++ b/src/FiltersPlugin/FiltersPlugin_Plugin.cpp @@ -29,6 +29,7 @@ #include "FiltersPlugin_OppositeToEdge.h" #include "FiltersPlugin_RelativeToSolid.h" #include "FiltersPlugin_ExternalFaces.h" +#include "FiltersPlugin_Validators.h" #include @@ -40,7 +41,7 @@ static FiltersPlugin_Plugin* MY_VIEWFILTERS_INSTANCE = new FiltersPlugin_Plugin( FiltersPlugin_Plugin::FiltersPlugin_Plugin() { - // register validators + // register filters SessionPtr aMgr = ModelAPI_Session::get(); ModelAPI_FiltersFactory* aFactory = aMgr->filters(); aFactory->registerFilter("HorizontalFaces", new FiltersPlugin_HorizontalFace); @@ -56,6 +57,11 @@ FiltersPlugin_Plugin::FiltersPlugin_Plugin() Config_ModuleReader::loadScript("FiltersPlugin_TopoConnectedFaces"); + // register validators + ModelAPI_ValidatorsFactory* aValidators = aMgr->validators(); + aValidators->registerValidator("FiltersPlugin_ShapeType", + new FiltersPlugin_ShapeTypeValidator); + ModelAPI_Session::get()->registerPlugin(this); } diff --git a/src/FiltersPlugin/FiltersPlugin_Validators.cpp b/src/FiltersPlugin/FiltersPlugin_Validators.cpp new file mode 100644 index 000000000..c03b9adff --- /dev/null +++ b/src/FiltersPlugin/FiltersPlugin_Validators.cpp @@ -0,0 +1,52 @@ +// Copyright (C) 2014-2019 CEA/DEN, EDF R&D +// +// 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_Validators.h" + +#include + +#include +#include + +bool FiltersPlugin_ShapeTypeValidator::isValid(const AttributePtr& theAttribute, + const std::list& theArguments, + Events_InfoMessage& theError) const +{ + if (!theAttribute) + return false; + FeaturePtr aFilterFeature = ModelAPI_Feature::feature(theAttribute->owner()); + if (!aFilterFeature) + return false; + + // iterate on groups and find the one having the current filters feature + DocumentPtr aCurDoc = ModelAPI_Session::get()->activeDocument(); + std::list aFeatList = aCurDoc->allFeatures(); + for (std::list::iterator anIt = aFeatList.begin(); anIt != aFeatList.end(); ++anIt) + if ((*anIt)->getKind() == CollectionPlugin_Group::ID()) { + AttributeSelectionListPtr aSelList = + (*anIt)->selectionList(CollectionPlugin_Group::LIST_ID()); + if (aSelList->filters() == aFilterFeature) { + TypeOfShape aType = shapeType(aSelList->selectionType()); + if (isValidAttribute(theAttribute, aType, theError)) + return true; + } + } + + return false; +} diff --git a/src/FiltersPlugin/FiltersPlugin_Validators.h b/src/FiltersPlugin/FiltersPlugin_Validators.h new file mode 100644 index 000000000..78921da97 --- /dev/null +++ b/src/FiltersPlugin/FiltersPlugin_Validators.h @@ -0,0 +1,44 @@ +// Copyright (C) 2014-2019 CEA/DEN, EDF R&D +// +// 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 +// + +#ifndef FILTERSPLUGIN_VALIDATORS_H_ +#define FILTERSPLUGIN_VALIDATORS_H_ + +#include "FiltersPlugin.h" + +#include + +/** + * Validates selection of "On geometry" filter to select only + * the shapes specified by the group type. + */ +class FiltersPlugin_ShapeTypeValidator : public GeomValidators_ShapeType +{ +public: + /// \return True if the attribute is valid. It checks whether the shape is a + /// body subshape. Does not allow select construction shapes. + /// \param[in] theAttribute an attribute to check + /// \param[in] theArguments a filter parameters + /// \param[out] theError error message. + FILTERS_EXPORT virtual bool isValid(const AttributePtr& theAttribute, + const std::list& theArguments, + Events_InfoMessage& theError) const; +}; + +#endif \ No newline at end of file diff --git a/src/FiltersPlugin/filter-OnGeometry.xml b/src/FiltersPlugin/filter-OnGeometry.xml index cd44c7ee2..80053d57e 100644 --- a/src/FiltersPlugin/filter-OnGeometry.xml +++ b/src/FiltersPlugin/filter-OnGeometry.xml @@ -1,8 +1,8 @@ - + diff --git a/src/GeomValidators/GeomValidators_ShapeType.cpp b/src/GeomValidators/GeomValidators_ShapeType.cpp index 963f53c9a..e748d9ac6 100644 --- a/src/GeomValidators/GeomValidators_ShapeType.cpp +++ b/src/GeomValidators/GeomValidators_ShapeType.cpp @@ -33,6 +33,7 @@ #include +#include #include #include @@ -46,18 +47,23 @@ GeomValidators_ShapeType::TypeOfShape if (MyShapeTypes.size() == 0) { MyShapeTypes["empty"] = Empty; MyShapeTypes["vertex"] = Vertex; + MyShapeTypes["vertices"] = Vertex; MyShapeTypes["edge"] = Edge; + MyShapeTypes["edges"] = Edge; MyShapeTypes["line"] = Line; MyShapeTypes["circle"] = Circle; MyShapeTypes["wire"] = Wire; MyShapeTypes["face"] = Face; + MyShapeTypes["faces"] = Face; MyShapeTypes["plane"] = Plane; MyShapeTypes["shell"] = Shell; MyShapeTypes["solid"] = Solid; + MyShapeTypes["solids"] = Solid; MyShapeTypes["compsolid"] = CompSolid; MyShapeTypes["compound"] = Compound; } std::string aType = std::string(theType.c_str()); + std::transform(aType.begin(), aType.end(), aType.begin(), ::tolower); if (MyShapeTypes.find(aType) != MyShapeTypes.end()) return MyShapeTypes[aType]; diff --git a/src/GeomValidators/GeomValidators_ShapeType.h b/src/GeomValidators/GeomValidators_ShapeType.h index d4f38cf5b..288af7439 100644 --- a/src/GeomValidators/GeomValidators_ShapeType.h +++ b/src/GeomValidators/GeomValidators_ShapeType.h @@ -66,12 +66,13 @@ class GeomValidators_ShapeType : public ModelAPI_AttributeValidator protected: /// Convert string to TypeOfShape value /// \param theType a string value - static TypeOfShape shapeType(const std::string& theType); + GEOMVALIDATORS_EXPORT static TypeOfShape shapeType(const std::string& theType); /// Returns true if the attibute's object type satisfies the argument value /// \param[in] theAttribute a checked attribute /// \param[in] theShapeType a type of shape /// \param[out] theError error message. + GEOMVALIDATORS_EXPORT bool isValidAttribute(const AttributePtr& theAttribute, const TypeOfShape theShapeType, Events_InfoMessage& theError) const;