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