Salome HOME
Dump Python in the High Level Parameterized Geometry API (issue #1648)
[modules/shaper.git] / src / ParametersAPI / ParametersAPI_Parameter.cpp
1 // Name   : ParametersAPI_Parameter.cpp
2 // Purpose: 
3 //
4 // History:
5 // 16/06/16 - Sergey POKHODENKO - Creation of the file
6
7 //--------------------------------------------------------------------------------------
8 #include "ParametersAPI_Parameter.h"
9 //--------------------------------------------------------------------------------------
10 #include <ModelHighAPI_Dumper.h>
11 #include <ModelHighAPI_Tools.h>
12 //--------------------------------------------------------------------------------------
13 ParametersAPI_Parameter::ParametersAPI_Parameter(
14     const std::shared_ptr<ModelAPI_Feature> & theFeature)
15 : ModelHighAPI_Interface(theFeature)
16 {
17   initialize();
18 }
19
20 ParametersAPI_Parameter::ParametersAPI_Parameter(
21     const std::shared_ptr<ModelAPI_Feature> & theFeature,
22     const std::string & theName,
23     const std::string & theExpression,
24     const std::string & theComment)
25 : ModelHighAPI_Interface(theFeature)
26 {
27   if (initialize()) {
28     fillAttribute(theName, name());
29     fillAttribute(theExpression, expression());
30     fillAttribute(theComment, comment());
31
32     execute();
33   }
34 }
35
36 ParametersAPI_Parameter::~ParametersAPI_Parameter()
37 {
38 }
39
40 void ParametersAPI_Parameter::dump(ModelHighAPI_Dumper& theDumper) const
41 {
42   FeaturePtr aBase = feature();
43   const std::string& aDocName = theDumper.name(aBase->document());
44   const std::string& aParamName = theDumper.name(aBase);
45
46   AttributeStringPtr anExpr   = aBase->string(ParametersPlugin_Parameter::EXPRESSION_ID());
47   AttributeStringPtr aComment = aBase->string(ParametersPlugin_Parameter::COMMENT_ID());
48
49   theDumper << "model.addParameter(" << aDocName << ", \"" << aParamName << "\", " << anExpr;
50   if (aComment->isInitialized() && !aComment->value().empty())
51     theDumper << ", " << aComment;
52   theDumper << ")" << std::endl;
53 }
54
55 //--------------------------------------------------------------------------------------
56 ParameterPtr addParameter(const std::shared_ptr<ModelAPI_Document> & thePart,
57                           const std::string & theName,
58                           const std::string & theExpression,
59                           const std::string & theComment)
60 {
61   // TODO(spo): check that thePart is not empty
62   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ParametersAPI_Parameter::ID());
63   return ParameterPtr(new ParametersAPI_Parameter(aFeature, theName, theExpression, theComment));
64 }