From: azv Date: Wed, 19 Jun 2019 13:30:26 +0000 (+0300) Subject: Separate classes related to Filters in Model/ModelAPI X-Git-Tag: VEDF2019Lot4~101^2~25 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=bae2c0f9a9f1c1adbaa371b938feb25ccdfd61ac;p=modules%2Fshaper.git Separate classes related to Filters in Model/ModelAPI --- diff --git a/src/FiltersPlugin/CMakeLists.txt b/src/FiltersPlugin/CMakeLists.txt index 9cb138019..a764abe5e 100644 --- a/src/FiltersPlugin/CMakeLists.txt +++ b/src/FiltersPlugin/CMakeLists.txt @@ -25,8 +25,8 @@ SET(PROJECT_HEADERS FiltersPlugin_Selection.h FiltersPlugin_HorizontalFace.h FiltersPlugin_VerticalFace.h - FiltersPlugin_BelongsTo.h - FiltersPlugin_OnPlane.h + FiltersPlugin_BelongsTo.h + FiltersPlugin_OnPlane.h ) SET(PROJECT_SOURCES @@ -34,8 +34,8 @@ SET(PROJECT_SOURCES FiltersPlugin_Selection.cpp FiltersPlugin_HorizontalFace.cpp FiltersPlugin_VerticalFace.cpp - FiltersPlugin_BelongsTo.cpp - FiltersPlugin_OnPlane.cpp + FiltersPlugin_BelongsTo.cpp + FiltersPlugin_OnPlane.cpp ) SET(PROJECT_LIBRARIES diff --git a/src/FiltersPlugin/FiltersPlugin_Plugin.cpp b/src/FiltersPlugin/FiltersPlugin_Plugin.cpp index 92ff9b1a1..6f0b9886c 100644 --- a/src/FiltersPlugin/FiltersPlugin_Plugin.cpp +++ b/src/FiltersPlugin/FiltersPlugin_Plugin.cpp @@ -25,7 +25,7 @@ #include "FiltersPlugin_OnPlane.h" #include -#include +#include // the only created instance of this plugin static FiltersPlugin_Plugin* MY_VIEWFILTERS_INSTANCE = new FiltersPlugin_Plugin(); diff --git a/src/FiltersPlugin/FiltersPlugin_Selection.cpp b/src/FiltersPlugin/FiltersPlugin_Selection.cpp index 2a98fc4ff..fde5dda29 100644 --- a/src/FiltersPlugin/FiltersPlugin_Selection.cpp +++ b/src/FiltersPlugin/FiltersPlugin_Selection.cpp @@ -19,9 +19,10 @@ #include "FiltersPlugin_Selection.h" -#include #include #include +#include +#include // identifier of the reverse flag of a filter static const std::string kReverseAttrID(""); diff --git a/src/FiltersPlugin/FiltersPlugin_Selection.h b/src/FiltersPlugin/FiltersPlugin_Selection.h index a9e62517f..8fe3850a7 100644 --- a/src/FiltersPlugin/FiltersPlugin_Selection.h +++ b/src/FiltersPlugin/FiltersPlugin_Selection.h @@ -21,8 +21,7 @@ #define FILTERSPLUGIN_SELECTION_H_ #include "FiltersPlugin.h" -#include -#include +#include /**\class FiltersPlugin_Selection * \ingroup DataModel diff --git a/src/Model/CMakeLists.txt b/src/Model/CMakeLists.txt index cd1dcb5d1..554b8c03a 100644 --- a/src/Model/CMakeLists.txt +++ b/src/Model/CMakeLists.txt @@ -41,20 +41,20 @@ SET(PROJECT_HEADERS Model_AttributeSelection.h Model_AttributeSelectionList.h Model_AttributeTables.h + Model_AttributeValidator.h Model_BodyBuilder.h Model_Events.h Model_Expression.h - Model_Update.h - Model_Validator.h + Model_FeatureValidator.h + Model_FiltersFactory.h Model_ResultBody.h Model_ResultConstruction.h Model_ResultPart.h Model_ResultField.h Model_ResultGroup.h Model_ResultParameter.h - Model_FeatureValidator.h - Model_AttributeValidator.h - Model_Filter.h + Model_Update.h + Model_Validator.h ) SET(PROJECT_SOURCES @@ -78,20 +78,20 @@ SET(PROJECT_SOURCES Model_AttributeSelection.cpp Model_AttributeSelectionList.cpp Model_AttributeTables.cpp + Model_AttributeValidator.cpp Model_BodyBuilder.cpp Model_Events.cpp Model_Expression.cpp - Model_Update.cpp - Model_Validator.cpp + Model_FeatureValidator.cpp + Model_FiltersFactory.cpp Model_ResultBody.cpp Model_ResultConstruction.cpp Model_ResultPart.cpp Model_ResultField.cpp Model_ResultGroup.cpp Model_ResultParameter.cpp - Model_FeatureValidator.cpp - Model_AttributeValidator.cpp - Model_Filter.cpp + Model_Update.cpp + Model_Validator.cpp ) SET(PROJECT_LIBRARIES diff --git a/src/Model/Model_Filter.cpp b/src/Model/Model_Filter.cpp deleted file mode 100644 index 549bed4da..000000000 --- a/src/Model/Model_Filter.cpp +++ /dev/null @@ -1,126 +0,0 @@ -// 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 "Model_Filter.h" - -#include "ModelAPI_AttributeBoolean.h" -#include "ModelAPI_AttributeSelectionList.h" -#include - - -void Model_FiltersFactory::registerFilter(const std::string& theID, ModelAPI_Filter* theFilter) -{ - if (myFilters.find(theID) != myFilters.end()) { - Events_InfoMessage("Model_FiltersFactory", "Filter %1 is already registered").arg(theID).send(); - } - else { - myFilters[theID] = FilterPtr(theFilter); - } -} - -struct FilterArgs { - FilterPtr myFilter; - bool myReverse; - std::string myFilterID; -}; - -bool Model_FiltersFactory::isValid(FeaturePtr theFiltersFeature, GeomShapePtr theShape) -{ - // check that the shape type corresponds to the attribute list type - AttributePtr aBase = - std::dynamic_pointer_cast(theFiltersFeature)->baseAttribute(); - if (aBase.get()) { - std::shared_ptr aList = - std::dynamic_pointer_cast(aBase); - std::string aStrType = aList->selectionType(); - GeomAPI_Shape::ShapeType aType = GeomAPI_Shape::shapeTypeByStr(aStrType); - if (theShape->shapeType() != aType) - return false; - } - // prepare all filters args - ModelAPI_FiltersArgs anArgs; - std::list aFilters; /// all filters and the reverse values - - std::list aGroups; - theFiltersFeature->data()->allGroups(aGroups); - for(std::list::iterator aGIter = aGroups.begin(); aGIter != aGroups.end(); aGIter++) - { - if (myFilters.find(*aGIter) == myFilters.end()) - continue; - std::list > anAttrs; - theFiltersFeature->data()->attributesOfGroup(*aGIter, anAttrs); - std::list >::iterator anAttrIter = anAttrs.begin(); - for(; anAttrIter != anAttrs.end(); anAttrIter++) { - std::string anArgID = (*anAttrIter)->id().substr((*aGIter).length() + 2); - if (anArgID.empty()) { // reverse flag - std::shared_ptr aReverse = - std::dynamic_pointer_cast(*anAttrIter); - FilterArgs aFArgs = { myFilters[*aGIter] , aReverse->value() , *aGIter }; - aFilters.push_back(aFArgs); - - } else { - anArgs.add(*anAttrIter); - } - } - } - - // iterate filters and check shape for validity for all of them - std::list::iterator aFilter = aFilters.begin(); - for(; aFilter != aFilters.end(); aFilter++) { - anArgs.setFilter(aFilter->myFilterID); - bool aResult = aFilter->myFilter->isOk(theShape, anArgs); - if (aFilter->myReverse) - aResult = !aResult; - if (!aResult) // one filter is failed => exit immediately - return false; - } - // all filters are passed - return true; -} - -/// Returns list of filters for the given shape type -/// \param theType a shape type -std::list Model_FiltersFactory::filters(GeomAPI_Shape::ShapeType theType) -{ - std::list aResult; - std::map::const_iterator anIt; - std::list aTypes; - std::list::const_iterator aTIt; - for (anIt = myFilters.cbegin(); anIt != myFilters.cend(); anIt++) { - if (anIt->second->isSupported(theType)) - aResult.push_back(anIt->second); - } - return aResult; -} - -FilterPtr Model_FiltersFactory::filter(std::string theID) -{ - std::map::iterator aFound = myFilters.find(theID); - return aFound == myFilters.end() ? FilterPtr() : aFound->second; -} - -std::string Model_FiltersFactory::id(FilterPtr theFilter) -{ - std::map::iterator anIter = myFilters.begin(); - for(; anIter != myFilters.end(); anIter++) { - if (anIter->second == theFilter) - return anIter->first; - } - return ""; // unknown case -} diff --git a/src/Model/Model_Filter.h b/src/Model/Model_Filter.h deleted file mode 100644 index 2ccec584c..000000000 --- a/src/Model/Model_Filter.h +++ /dev/null @@ -1,67 +0,0 @@ -// 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 Model_Filter_H_ -#define Model_Filter_H_ - -#include "Model.h" - -#include - -#include - - -/**\class Model_ValidatorsFactory -* \ingroup DataModel -* \brief Manages registering of filters -*/ -class Model_FiltersFactory : public ModelAPI_FiltersFactory -{ -public: - /// Register an instance of a filter - /// \param theID unique identifier of the filter, not necessary equal to the name of filter - /// \param theFilter the filter's instance - virtual void registerFilter(const std::string& theID, ModelAPI_Filter* theFilter); - - /// Returns true if all filters of the Filters feature are ok for the Shape (taking into account - /// the Reversed states). - /// \param theFiltersFeature feature that contains all information about the filters - /// \param theShape the checked shape - virtual bool isValid(FeaturePtr theFiltersFeature, GeomShapePtr theShape); - - /// Returns the filters that support the given shape type - virtual std::list filters(GeomAPI_Shape::ShapeType theType); - - /// Returns a filter by ID - virtual FilterPtr filter(std::string theID); - - /// Returns a filter ID by the filter pointer - virtual std::string id(FilterPtr theFilter); - -protected: - /// Get instance from Session - Model_FiltersFactory() {} - -private: - std::map myFilters; ///< map from ID to registered filters - - friend class Model_Session; -}; - -#endif \ No newline at end of file diff --git a/src/Model/Model_FiltersFactory.cpp b/src/Model/Model_FiltersFactory.cpp new file mode 100644 index 000000000..f0a7c9242 --- /dev/null +++ b/src/Model/Model_FiltersFactory.cpp @@ -0,0 +1,126 @@ +// 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 "Model_FiltersFactory.h" + +#include "ModelAPI_AttributeBoolean.h" +#include "ModelAPI_AttributeSelectionList.h" +#include + + +void Model_FiltersFactory::registerFilter(const std::string& theID, ModelAPI_Filter* theFilter) +{ + if (myFilters.find(theID) != myFilters.end()) { + Events_InfoMessage("Model_FiltersFactory", "Filter %1 is already registered").arg(theID).send(); + } + else { + myFilters[theID] = FilterPtr(theFilter); + } +} + +struct FilterArgs { + FilterPtr myFilter; + bool myReverse; + std::string myFilterID; +}; + +bool Model_FiltersFactory::isValid(FeaturePtr theFiltersFeature, GeomShapePtr theShape) +{ + // check that the shape type corresponds to the attribute list type + AttributePtr aBase = + std::dynamic_pointer_cast(theFiltersFeature)->baseAttribute(); + if (aBase.get()) { + std::shared_ptr aList = + std::dynamic_pointer_cast(aBase); + std::string aStrType = aList->selectionType(); + GeomAPI_Shape::ShapeType aType = GeomAPI_Shape::shapeTypeByStr(aStrType); + if (theShape->shapeType() != aType) + return false; + } + // prepare all filters args + ModelAPI_FiltersArgs anArgs; + std::list aFilters; /// all filters and the reverse values + + std::list aGroups; + theFiltersFeature->data()->allGroups(aGroups); + for(std::list::iterator aGIter = aGroups.begin(); aGIter != aGroups.end(); aGIter++) + { + if (myFilters.find(*aGIter) == myFilters.end()) + continue; + std::list > anAttrs; + theFiltersFeature->data()->attributesOfGroup(*aGIter, anAttrs); + std::list >::iterator anAttrIter = anAttrs.begin(); + for(; anAttrIter != anAttrs.end(); anAttrIter++) { + std::string anArgID = (*anAttrIter)->id().substr((*aGIter).length() + 2); + if (anArgID.empty()) { // reverse flag + std::shared_ptr aReverse = + std::dynamic_pointer_cast(*anAttrIter); + FilterArgs aFArgs = { myFilters[*aGIter] , aReverse->value() , *aGIter }; + aFilters.push_back(aFArgs); + + } else { + anArgs.add(*anAttrIter); + } + } + } + + // iterate filters and check shape for validity for all of them + std::list::iterator aFilter = aFilters.begin(); + for(; aFilter != aFilters.end(); aFilter++) { + anArgs.setFilter(aFilter->myFilterID); + bool aResult = aFilter->myFilter->isOk(theShape, anArgs); + if (aFilter->myReverse) + aResult = !aResult; + if (!aResult) // one filter is failed => exit immediately + return false; + } + // all filters are passed + return true; +} + +/// Returns list of filters for the given shape type +/// \param theType a shape type +std::list Model_FiltersFactory::filters(GeomAPI_Shape::ShapeType theType) +{ + std::list aResult; + std::map::const_iterator anIt; + std::list aTypes; + std::list::const_iterator aTIt; + for (anIt = myFilters.cbegin(); anIt != myFilters.cend(); anIt++) { + if (anIt->second->isSupported(theType)) + aResult.push_back(anIt->second); + } + return aResult; +} + +FilterPtr Model_FiltersFactory::filter(std::string theID) +{ + std::map::iterator aFound = myFilters.find(theID); + return aFound == myFilters.end() ? FilterPtr() : aFound->second; +} + +std::string Model_FiltersFactory::id(FilterPtr theFilter) +{ + std::map::iterator anIter = myFilters.begin(); + for(; anIter != myFilters.end(); anIter++) { + if (anIter->second == theFilter) + return anIter->first; + } + return ""; // unknown case +} diff --git a/src/Model/Model_FiltersFactory.h b/src/Model/Model_FiltersFactory.h new file mode 100644 index 000000000..3672516f8 --- /dev/null +++ b/src/Model/Model_FiltersFactory.h @@ -0,0 +1,67 @@ +// 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 Model_FiltersFactory_H_ +#define Model_FiltersFactory_H_ + +#include "Model.h" + +#include + +#include + + +/**\class Model_FiltersFactory +* \ingroup DataModel +* \brief Manages registering of filters +*/ +class Model_FiltersFactory : public ModelAPI_FiltersFactory +{ +public: + /// Register an instance of a filter + /// \param theID unique identifier of the filter, not necessary equal to the name of filter + /// \param theFilter the filter's instance + virtual void registerFilter(const std::string& theID, ModelAPI_Filter* theFilter); + + /// Returns true if all filters of the Filters feature are ok for the Shape (taking into account + /// the Reversed states). + /// \param theFiltersFeature feature that contains all information about the filters + /// \param theShape the checked shape + virtual bool isValid(FeaturePtr theFiltersFeature, GeomShapePtr theShape); + + /// Returns the filters that support the given shape type + virtual std::list filters(GeomAPI_Shape::ShapeType theType); + + /// Returns a filter by ID + virtual FilterPtr filter(std::string theID); + + /// Returns a filter ID by the filter pointer + virtual std::string id(FilterPtr theFilter); + +protected: + /// Get instance from Session + Model_FiltersFactory() {} + +private: + std::map myFilters; ///< map from ID to registered filters + + friend class Model_Session; +}; + +#endif \ No newline at end of file diff --git a/src/ModelAPI/CMakeLists.txt b/src/ModelAPI/CMakeLists.txt index 58249a221..2884d106b 100644 --- a/src/ModelAPI/CMakeLists.txt +++ b/src/ModelAPI/CMakeLists.txt @@ -45,11 +45,16 @@ SET(PROJECT_HEADERS ModelAPI_CompositeFeature.h ModelAPI_Data.h ModelAPI_Document.h + ModelAPI_Entity.h ModelAPI_EventReentrantMessage.h ModelAPI_Events.h ModelAPI_Expression.h ModelAPI_Feature.h ModelAPI_FeatureValidator.h + ModelAPI_Filter.h + ModelAPI_FiltersArgs.h + ModelAPI_FiltersFactory.h + ModelAPI_FiltersFeature.h ModelAPI_Folder.h ModelAPI_IReentrant.h ModelAPI_Object.h @@ -64,8 +69,6 @@ SET(PROJECT_HEADERS ModelAPI_Session.h ModelAPI_Tools.h ModelAPI_Validator.h - ModelAPI_Entity.h - ModelAPI_Filter.h ) SET(PROJECT_SOURCES @@ -85,6 +88,7 @@ SET(PROJECT_SOURCES ModelAPI_AttributeString.cpp ModelAPI_AttributeStringArray.cpp ModelAPI_AttributeTables.cpp + ModelAPI_AttributeValidator.cpp ModelAPI_BodyBuilder.cpp ModelAPI_CompositeFeature.cpp ModelAPI_Data.cpp @@ -107,7 +111,6 @@ SET(PROJECT_SOURCES ModelAPI_ResultParameter.cpp ModelAPI_Session.cpp ModelAPI_Tools.cpp - ModelAPI_AttributeValidator.cpp ) SET(PROJECT_LIBRARIES diff --git a/src/ModelAPI/ModelAPI_Filter.h b/src/ModelAPI/ModelAPI_Filter.h index 08bb82d1e..0e5d5b9df 100644 --- a/src/ModelAPI/ModelAPI_Filter.h +++ b/src/ModelAPI/ModelAPI_Filter.h @@ -20,91 +20,10 @@ #ifndef ModelAPI_Filter_H_ #define ModelAPI_Filter_H_ -#include "ModelAPI.h" -#include "ModelAPI_Attribute.h" -#include "ModelAPI_Feature.h" - -#include "ModelAPI_Data.h" +#include "ModelAPI_FiltersArgs.h" #include -#include - -/// separator between the filter name and the filter attribute ID -static const std::string kFilterSeparator = "__"; - -/**\class ModelAPI_FiltersFeature -* \ingroup DataModel -* \brief An interface for working with filters in the feature. A filters feature must inherit it -* in order to allow management of filters in the feature data structure. -*/ -class ModelAPI_FiltersFeature: public ModelAPI_Feature -{ -public: - /// Adds a filter to the feature. Also initializes arguments of this filter. - virtual void addFilter(const std::string theFilterID) = 0; - - /// Removes an existing filter from the feature. - virtual void removeFilter(const std::string theFilterID) = 0; - - /// Returns the list of existing filters in the feature. - virtual std::list filters() const = 0; - /// Stores the reversed flag for the filter. - virtual void setReversed(const std::string theFilterID, const bool theReversed) = 0; - - /// Returns the reversed flag value for the filter. - virtual bool isReversed(const std::string theFilterID) = 0; - - /// Returns the ordered list of attributes related to the filter. - virtual std::list filterArgs(const std::string theFilterID) const = 0; - - /// Sets the attribute (not-persistent field) that contains this filters feature. - /// The filter feature may make synchronization by this method call. - virtual void setAttribute(const AttributePtr& theAttr) = 0; - - /// Returns the attribute (not-persistent field) that contains this filters feature. - virtual const AttributePtr& baseAttribute() const = 0; -}; - -typedef std::shared_ptr FiltersFeaturePtr; - - -/// definition of arguments of filters: id of the argument to attributes -class ModelAPI_FiltersArgs { - /// a map from the FilterID+AttributeID -> attribute - std::map myMap; - std::string myCurrentFilter; ///< ID of the filter that will take attributes now - FiltersFeaturePtr myFeature; ///< the feature is stored to minimize initAttribute interface -public: - ModelAPI_FiltersArgs() {} - - /// Sets the current filter ID - void setFilter(const std::string& theFilterID) { - myCurrentFilter = theFilterID; - } - - /// Sets the current feature - void setFeature(const FiltersFeaturePtr theFeature) { - myFeature = theFeature; - } - - /// Appends an argument of a filter - void add(AttributePtr theAttribute) { - myMap[theAttribute->id()] = theAttribute; - } - - /// returns the argument of the current filter by the argument id - AttributePtr argument(const std::string& theID) const { - return myMap.find(myCurrentFilter + kFilterSeparator + theID)->second; - } - /// adds an attribute of the filter - std::shared_ptr initAttribute( - const std::string& theID, const std::string theAttrType) { - AttributePtr aR = myFeature->data()->addFloatingAttribute(theID, theAttrType, myCurrentFilter); - aR->setIsArgument(false); // to avoid parametric update - return aR; - } -}; /**\class ModelAPI_ViewFilter * \ingroup DataModel @@ -138,37 +57,4 @@ private: typedef std::shared_ptr FilterPtr; - -/**\class ModelAPI_FiltersFactory -* \ingroup DataModel -* \brief Manages registering of filters -*/ -class ModelAPI_FiltersFactory -{ -public: - /// Register an instance of a filter - /// \param theID unique identifier of the filter, not necessary equal to the name of filter - /// \param theFilter the filter's instance - virtual void registerFilter(const std::string& theID, ModelAPI_Filter* theFilter) = 0; - - /// Returns true if all filters of the Filters feature are ok for the Shape (taking into account - /// the Reversed states). - /// \param theFiltersFeature feature that contains all information about the filters - /// \param theShape the checked shape - virtual bool isValid(FeaturePtr theFiltersFeature, GeomShapePtr theShape) = 0; - - /// Returns the filters that support the given shape type - virtual std::list filters(GeomAPI_Shape::ShapeType theType) = 0; - - /// Returns a filter by ID - virtual FilterPtr filter(std::string theID) = 0; - - /// Returns a filter ID by the filter pointer - virtual std::string id(FilterPtr theFilter) = 0; - -protected: - /// Get instance from Session - ModelAPI_FiltersFactory() {} -}; - #endif \ No newline at end of file diff --git a/src/ModelAPI/ModelAPI_FiltersArgs.h b/src/ModelAPI/ModelAPI_FiltersArgs.h new file mode 100644 index 000000000..0140fdf70 --- /dev/null +++ b/src/ModelAPI/ModelAPI_FiltersArgs.h @@ -0,0 +1,67 @@ +// 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 ModelAPI_FiltersArgs_H_ +#define ModelAPI_FiltersArgs_H_ + +#include "ModelAPI_FiltersFeature.h" + +#include + +/// separator between the filter name and the filter attribute ID +static const std::string kFilterSeparator = "__"; + +/// definition of arguments of filters: id of the argument to attributes +class ModelAPI_FiltersArgs { + /// a map from the FilterID+AttributeID -> attribute + std::map myMap; + std::string myCurrentFilter; ///< ID of the filter that will take attributes now + FiltersFeaturePtr myFeature; ///< the feature is stored to minimize initAttribute interface +public: + ModelAPI_FiltersArgs() {} + + /// Sets the current filter ID + void setFilter(const std::string& theFilterID) { + myCurrentFilter = theFilterID; + } + + /// Sets the current feature + void setFeature(const FiltersFeaturePtr theFeature) { + myFeature = theFeature; + } + + /// Appends an argument of a filter + void add(AttributePtr theAttribute) { + myMap[theAttribute->id()] = theAttribute; + } + + /// returns the argument of the current filter by the argument id + AttributePtr argument(const std::string& theID) const { + return myMap.find(myCurrentFilter + kFilterSeparator + theID)->second; + } + /// adds an attribute of the filter + std::shared_ptr initAttribute( + const std::string& theID, const std::string theAttrType) { + AttributePtr aR = myFeature->data()->addFloatingAttribute(theID, theAttrType, myCurrentFilter); + aR->setIsArgument(false); // to avoid parametric update + return aR; + } +}; + +#endif \ No newline at end of file diff --git a/src/ModelAPI/ModelAPI_FiltersFactory.h b/src/ModelAPI/ModelAPI_FiltersFactory.h new file mode 100644 index 000000000..bc24d0d3e --- /dev/null +++ b/src/ModelAPI/ModelAPI_FiltersFactory.h @@ -0,0 +1,61 @@ +// 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 ModelAPI_FiltersFactory_H_ +#define ModelAPI_FiltersFactory_H_ + +#include "ModelAPI_Feature.h" +#include "ModelAPI_Filter.h" + +#include + + +/**\class ModelAPI_FiltersFactory +* \ingroup DataModel +* \brief Manages registering of filters +*/ +class ModelAPI_FiltersFactory +{ +public: + /// Register an instance of a filter + /// \param theID unique identifier of the filter, not necessary equal to the name of filter + /// \param theFilter the filter's instance + virtual void registerFilter(const std::string& theID, ModelAPI_Filter* theFilter) = 0; + + /// Returns true if all filters of the Filters feature are ok for the Shape (taking into account + /// the Reversed states). + /// \param theFiltersFeature feature that contains all information about the filters + /// \param theShape the checked shape + virtual bool isValid(FeaturePtr theFiltersFeature, GeomShapePtr theShape) = 0; + + /// Returns the filters that support the given shape type + virtual std::list filters(GeomAPI_Shape::ShapeType theType) = 0; + + /// Returns a filter by ID + virtual FilterPtr filter(std::string theID) = 0; + + /// Returns a filter ID by the filter pointer + virtual std::string id(FilterPtr theFilter) = 0; + +protected: + /// Get instance from Session + ModelAPI_FiltersFactory() {} +}; + +#endif \ No newline at end of file diff --git a/src/ModelAPI/ModelAPI_FiltersFeature.h b/src/ModelAPI/ModelAPI_FiltersFeature.h new file mode 100644 index 000000000..b47909943 --- /dev/null +++ b/src/ModelAPI/ModelAPI_FiltersFeature.h @@ -0,0 +1,63 @@ +// 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 ModelAPI_FiltersFeature_H_ +#define ModelAPI_FiltersFeature_H_ + +#include "ModelAPI_Attribute.h" +#include "ModelAPI_Feature.h" + + +/**\class ModelAPI_FiltersFeature +* \ingroup DataModel +* \brief An interface for working with filters in the feature. A filters feature must inherit it +* in order to allow management of filters in the feature data structure. +*/ +class ModelAPI_FiltersFeature: public ModelAPI_Feature +{ +public: + /// Adds a filter to the feature. Also initializes arguments of this filter. + virtual void addFilter(const std::string theFilterID) = 0; + + /// Removes an existing filter from the feature. + virtual void removeFilter(const std::string theFilterID) = 0; + + /// Returns the list of existing filters in the feature. + virtual std::list filters() const = 0; + + /// Stores the reversed flag for the filter. + virtual void setReversed(const std::string theFilterID, const bool theReversed) = 0; + + /// Returns the reversed flag value for the filter. + virtual bool isReversed(const std::string theFilterID) = 0; + + /// Returns the ordered list of attributes related to the filter. + virtual std::list filterArgs(const std::string theFilterID) const = 0; + + /// Sets the attribute (not-persistent field) that contains this filters feature. + /// The filter feature may make synchronization by this method call. + virtual void setAttribute(const AttributePtr& theAttr) = 0; + + /// Returns the attribute (not-persistent field) that contains this filters feature. + virtual const AttributePtr& baseAttribute() const = 0; +}; + +typedef std::shared_ptr FiltersFeaturePtr; + +#endif \ No newline at end of file diff --git a/src/ModuleBase/ModuleBase_WidgetSelectionFilter.cpp b/src/ModuleBase/ModuleBase_WidgetSelectionFilter.cpp index 54e99f1d2..1ddaaac2a 100644 --- a/src/ModuleBase/ModuleBase_WidgetSelectionFilter.cpp +++ b/src/ModuleBase/ModuleBase_WidgetSelectionFilter.cpp @@ -32,6 +32,7 @@ #include #include #include +#include #include #include diff --git a/src/ModuleBase/ModuleBase_WidgetSelectionFilter.h b/src/ModuleBase/ModuleBase_WidgetSelectionFilter.h index 45b6ec6b6..3c76e55dc 100644 --- a/src/ModuleBase/ModuleBase_WidgetSelectionFilter.h +++ b/src/ModuleBase/ModuleBase_WidgetSelectionFilter.h @@ -24,7 +24,7 @@ #include "ModuleBase_ModelWidget.h" #include "ModuleBase_ViewerPrs.h" -#include +#include #include #include