Salome HOME
Correct dump of default name of results
[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     if (!theComment.empty())
31       fillAttribute(theComment, comment());
32
33     execute();
34   }
35 }
36
37 ParametersAPI_Parameter::~ParametersAPI_Parameter()
38 {
39 }
40
41 void ParametersAPI_Parameter::dump(ModelHighAPI_Dumper& theDumper) const
42 {
43   FeaturePtr aBase = feature();
44   const std::string& aDocName = theDumper.name(aBase->document());
45   const std::string& aParamName = theDumper.name(aBase, false, true);
46
47   AttributeStringPtr anExpr   = aBase->string(ParametersPlugin_Parameter::EXPRESSION_ID());
48   AttributeStringPtr aComment = aBase->string(ParametersPlugin_Parameter::COMMENT_ID());
49
50   theDumper << "model.addParameter(" << aDocName << ", \"" << aParamName << "\", " << anExpr;
51   if (aComment->isInitialized() && !aComment->value().empty())
52     theDumper << ", " << aComment;
53   theDumper << ")" << std::endl;
54 }
55
56 //--------------------------------------------------------------------------------------
57 ParameterPtr addParameter(const std::shared_ptr<ModelAPI_Document> & thePart,
58                           const std::string & theName,
59                           const std::string & theExpression,
60                           const std::string & theComment)
61 {
62   // TODO(spo): check that thePart is not empty
63   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ParametersAPI_Parameter::ID());
64   return ParameterPtr(new ParametersAPI_Parameter(aFeature, theName, theExpression, theComment));
65 }