Salome HOME
Issue #1428: Find referenced feature by parameters recursive
[modules/shaper.git] / src / ParametersPlugin / ParametersPlugin_Parameter.h
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
2
3 // File:        ParametersPlugin_Parameter.h
4 // Created:     23 MArch 2015
5 // Author:      sbh
6
7 #ifndef PARAMETERSPLUGIN_PARAMETER_H_
8 #define PARAMETERSPLUGIN_PARAMETER_H_
9
10 #include "ParametersPlugin.h"
11 #include <ModelAPI_Feature.h>
12
13 #include <memory>
14
15 class ParametersPlugin_PyInterp;
16
17 /**
18  * \class ParametersPlugin_Parameter
19  * \ingroup Plugins
20  * \brief Feature for parameter.
21  */
22 class ParametersPlugin_Parameter : public ModelAPI_Feature
23 {
24  public:
25   virtual ~ParametersPlugin_Parameter();
26
27   /// Feature kind
28   inline static const std::string& ID()
29   {
30     static const std::string MY_PARAMETER_ID("Parameter");
31     return MY_PARAMETER_ID;
32   }
33   /// attribute of parameter name
34   inline static const std::string& VARIABLE_ID()
35   {
36     static const std::string MY_VARIABLE_ID("variable");
37     return MY_VARIABLE_ID;
38   }
39   /// attribute of parameter expression
40   inline static const std::string& EXPRESSION_ID()
41   {
42     static const std::string MY_EXPRESSION_ID("expression");
43     return MY_EXPRESSION_ID;
44   }
45   /// attribute of parameter expression error
46   inline static const std::string& EXPRESSION_ERROR_ID()
47   {
48     static const std::string MY_EXPRESSION_ERROR_ID("ExpressionError");
49     return MY_EXPRESSION_ERROR_ID;
50   }
51   /// list of references to the arguments of this expression
52   inline static const std::string& ARGUMENTS_ID()
53   {
54     static const std::string MY_ARGUMENTS_ID("arguments");
55     return MY_ARGUMENTS_ID;
56   }
57
58   /// return comment attribute Id
59   inline static const std::string& COMMENT_ID()
60   {
61     static const std::string MY_COMMENT_ID("comment");
62     return MY_COMMENT_ID;
63   }
64
65   /// Returns the kind of a feature
66   PARAMETERSPLUGIN_EXPORT virtual const std::string& getKind()
67   {
68     static std::string MY_KIND = ParametersPlugin_Parameter::ID();
69     return MY_KIND;
70   }
71
72   /// Pre-execution is not needed for parameter
73   PARAMETERSPLUGIN_EXPORT virtual bool isPreviewNeeded() const;
74
75   /// Creates a parameter in document
76   PARAMETERSPLUGIN_EXPORT virtual void execute();
77
78   /// Request for initialization of data model of the feature: adding all attributes
79   PARAMETERSPLUGIN_EXPORT virtual void initAttributes();
80
81   /// Reimplemented from ModelAPI_Feature::isInHistory(). Returns false.
82   PARAMETERSPLUGIN_EXPORT virtual bool isInHistory();
83
84   /// Reimplemented from ModelAPI_Feature::isInHistory().
85   PARAMETERSPLUGIN_EXPORT virtual void attributeChanged(const std::string& theID);
86
87   /// Use plugin manager for features creation
88   ParametersPlugin_Parameter();
89
90  protected:
91   /// Evaluates theExpression and returns its value.
92   double evaluate(const std::string& theExpression, std::string& theError);
93   /// Updates name of the parameter
94   void updateName();
95   /// Updates expression of the parameter
96   bool updateExpression();
97
98  private:
99   std::shared_ptr<ParametersPlugin_PyInterp> myInterp;
100 };
101
102 #endif