Salome HOME
Copyright update 2022
[modules/shaper.git] / src / ParametersPlugin / ParametersPlugin_EvalListener.h
1 // Copyright (C) 2014-2022  CEA/DEN, EDF R&D
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #ifndef SRC_PARAMETERSPLUGIN_EVALLISTENER_H_
21 #define SRC_PARAMETERSPLUGIN_EVALLISTENER_H_
22
23 #include <ParametersPlugin.h>
24 #include <Events_Loop.h>
25
26 class ModelAPI_Attribute;
27 class ModelAPI_Document;
28 class ModelAPI_Feature;
29 class ModelAPI_ResultParameter;
30 class ParametersPlugin_Parameter;
31
32 /**
33  * \class ParametersPlugin_EvalListener
34  * \ingroup Plugins
35  * \brief Class which process the events from the event loop.
36  */
37 class ParametersPlugin_EvalListener : public Events_Listener
38 {
39   /// map of old names, that were valid for perameres, but now parameter name is changed to invalid
40   /// stored not shared pointers to features to avoid memory keeping on the feature delete
41   std::map<ParametersPlugin_Parameter*, std::wstring> myOldNames;
42  public:
43   PARAMETERSPLUGIN_EXPORT ParametersPlugin_EvalListener();
44   PARAMETERSPLUGIN_EXPORT virtual ~ParametersPlugin_EvalListener();
45
46   /// Reimplemented from Events_Listener::processEvent().
47   PARAMETERSPLUGIN_EXPORT
48     virtual void processEvent(const std::shared_ptr<Events_Message>& theMessage);
49
50  protected:
51   /// Processes ObjectRenamed event.
52   void processObjectRenamedEvent(const std::shared_ptr<Events_Message>& theMessage);
53   /// Processes ReplaceParameter event.
54   void processReplaceParameterEvent(const std::shared_ptr<Events_Message>& theMessage);
55
56   /// Renames theOldName in theExpression by theNewName.
57   std::wstring renameInPythonExpression(const std::wstring& theExpression,
58                                         const std::wstring& theOldName,
59                                         const std::wstring& theNewName);
60   /// Renames theOldName in the expression attribute of theParameter by theNewName.
61   void renameInParameter(std::shared_ptr<ParametersPlugin_Parameter> theParameter,
62                          const std::wstring& theOldName,
63                          const std::wstring& theNewName);
64   /// Renames theOldName in the text fields of theAttribute by theNewName.
65   void renameInAttribute(std::shared_ptr<ModelAPI_Attribute> theAttribute,
66                          const std::wstring& theOldName,
67                          const std::wstring& theNewName);
68   /// Renames theOldName in all dependents of theResultParameter by theNewName.
69   void renameInDependents(std::shared_ptr<ModelAPI_ResultParameter> theResultParameter,
70                           const std::wstring& theOldName,
71                           const std::wstring& theNewName);
72 };
73
74 #endif /* SRC_PARAMETERSPLUGIN_PARAMETERSPLUGIN_EVALLISTENER_H_ */