1 // Name : ParametersAPI_Parameter.cpp
5 // 16/06/16 - Sergey POKHODENKO - Creation of the file
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)
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)
28 fillAttribute(theName, name());
29 fillAttribute(theExpression, expression());
30 if (!theComment.empty())
31 fillAttribute(theComment, comment());
37 ParametersAPI_Parameter::~ParametersAPI_Parameter()
41 void ParametersAPI_Parameter::dump(ModelHighAPI_Dumper& theDumper) const
43 FeaturePtr aBase = feature();
44 const std::string& aDocName = theDumper.name(aBase->document());
45 const std::string& aParamName = theDumper.name(aBase, false, true);
47 AttributeStringPtr anExpr = aBase->string(ParametersPlugin_Parameter::EXPRESSION_ID());
48 AttributeStringPtr aComment = aBase->string(ParametersPlugin_Parameter::COMMENT_ID());
50 theDumper << "model.addParameter(" << aDocName << ", \"" << aParamName << "\", " << anExpr;
51 if (aComment->isInitialized() && !aComment->value().empty())
52 theDumper << ", " << aComment;
53 theDumper << ")" << std::endl;
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)
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));