From bae2c0f9a9f1c1adbaa371b938feb25ccdfd61ac Mon Sep 17 00:00:00 2001 From: azv Date: Wed, 19 Jun 2019 16:30:26 +0300 Subject: [PATCH] Separate classes related to Filters in Model/ModelAPI --- src/FiltersPlugin/CMakeLists.txt | 8 +- src/FiltersPlugin/FiltersPlugin_Plugin.cpp | 2 +- src/FiltersPlugin/FiltersPlugin_Selection.cpp | 3 +- src/FiltersPlugin/FiltersPlugin_Selection.h | 3 +- src/Model/CMakeLists.txt | 20 +-- ...el_Filter.cpp => Model_FiltersFactory.cpp} | 2 +- ...{Model_Filter.h => Model_FiltersFactory.h} | 8 +- src/ModelAPI/CMakeLists.txt | 9 +- src/ModelAPI/ModelAPI_Filter.h | 116 +----------------- src/ModelAPI/ModelAPI_FiltersArgs.h | 67 ++++++++++ src/ModelAPI/ModelAPI_FiltersFactory.h | 61 +++++++++ src/ModelAPI/ModelAPI_FiltersFeature.h | 63 ++++++++++ .../ModuleBase_WidgetSelectionFilter.cpp | 1 + .../ModuleBase_WidgetSelectionFilter.h | 2 +- 14 files changed, 223 insertions(+), 142 deletions(-) rename src/Model/{Model_Filter.cpp => Model_FiltersFactory.cpp} (99%) rename src/Model/{Model_Filter.h => Model_FiltersFactory.h} (93%) create mode 100644 src/ModelAPI/ModelAPI_FiltersArgs.h create mode 100644 src/ModelAPI/ModelAPI_FiltersFactory.h create mode 100644 src/ModelAPI/ModelAPI_FiltersFeature.h 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_FiltersFactory.cpp similarity index 99% rename from src/Model/Model_Filter.cpp rename to src/Model/Model_FiltersFactory.cpp index 549bed4da..f0a7c9242 100644 --- a/src/Model/Model_Filter.cpp +++ b/src/Model/Model_FiltersFactory.cpp @@ -17,7 +17,7 @@ // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // -#include "Model_Filter.h" +#include "Model_FiltersFactory.h" #include "ModelAPI_AttributeBoolean.h" #include "ModelAPI_AttributeSelectionList.h" diff --git a/src/Model/Model_Filter.h b/src/Model/Model_FiltersFactory.h similarity index 93% rename from src/Model/Model_Filter.h rename to src/Model/Model_FiltersFactory.h index 2ccec584c..3672516f8 100644 --- a/src/Model/Model_Filter.h +++ b/src/Model/Model_FiltersFactory.h @@ -17,17 +17,17 @@ // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // -#ifndef Model_Filter_H_ -#define Model_Filter_H_ +#ifndef Model_FiltersFactory_H_ +#define Model_FiltersFactory_H_ #include "Model.h" -#include +#include #include -/**\class Model_ValidatorsFactory +/**\class Model_FiltersFactory * \ingroup DataModel * \brief Manages registering of filters */ 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 -- 2.39.2