Salome HOME
Issue #1806 : evaluation of expressions if no parameters defined.
[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 /**
16  * \class ParametersPlugin_Parameter
17  * \ingroup Plugins
18  * \brief Feature for parameter.
19  */
20 class ParametersPlugin_Parameter : public ModelAPI_Feature
21 {
22  public:
23   virtual ~ParametersPlugin_Parameter();
24
25   /// Feature kind
26   inline static const std::string& ID()
27   {
28     static const std::string MY_PARAMETER_ID("Parameter");
29     return MY_PARAMETER_ID;
30   }
31   /// attribute of parameter name
32   inline static const std::string& VARIABLE_ID()
33   {
34     static const std::string MY_VARIABLE_ID("variable");
35     return MY_VARIABLE_ID;
36   }
37   /// attribute of parameter expression
38   inline static const std::string& EXPRESSION_ID()
39   {
40     static const std::string MY_EXPRESSION_ID("expression");
41     return MY_EXPRESSION_ID;
42   }
43   /// attribute of parameter expression error
44   inline static const std::string& EXPRESSION_ERROR_ID()
45   {
46     static const std::string MY_EXPRESSION_ERROR_ID("ExpressionError");
47     return MY_EXPRESSION_ERROR_ID;
48   }
49   /// list of references to the arguments of this expression
50   inline static const std::string& ARGUMENTS_ID()
51   {
52     static const std::string MY_ARGUMENTS_ID("arguments");
53     return MY_ARGUMENTS_ID;
54   }
55
56   /// return comment attribute Id
57   inline static const std::string& COMMENT_ID()
58   {
59     static const std::string MY_COMMENT_ID("comment");
60     return MY_COMMENT_ID;
61   }
62
63   /// Returns the kind of a feature
64   PARAMETERSPLUGIN_EXPORT virtual const std::string& getKind()
65   {
66     static std::string MY_KIND = ParametersPlugin_Parameter::ID();
67     return MY_KIND;
68   }
69
70   /// Pre-execution is not needed for parameter
71   PARAMETERSPLUGIN_EXPORT virtual bool isPreviewNeeded() const;
72
73   /// Creates a parameter in document
74   PARAMETERSPLUGIN_EXPORT virtual void execute();
75
76   /// Request for initialization of data model of the feature: adding all attributes
77   PARAMETERSPLUGIN_EXPORT virtual void initAttributes();
78
79   /// Reimplemented from ModelAPI_Feature::isInHistory(). Returns false.
80   PARAMETERSPLUGIN_EXPORT virtual bool isInHistory();
81
82   /// Reimplemented from ModelAPI_Feature::isInHistory().
83   PARAMETERSPLUGIN_EXPORT virtual void attributeChanged(const std::string& theID);
84
85   /// Use plugin manager for features creation
86   ParametersPlugin_Parameter();
87
88  protected:
89   /// Evaluates theExpression and returns its value.
90   double evaluate(const std::string& theExpression, std::string& theError);
91   /// Updates name of the parameter
92   void updateName();
93   /// Updates expression of the parameter
94   bool updateExpression();
95 };
96
97 #endif