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