1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
2 // Name : ParametersAPI_Parameter.cpp
6 // 16/06/16 - Sergey POKHODENKO - Creation of the file
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)
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)
29 fillAttribute(theName, name());
30 fillAttribute(theExpression, expression());
31 if (!theComment.empty())
32 fillAttribute(theComment, comment());
38 ParametersAPI_Parameter::~ParametersAPI_Parameter()
42 void ParametersAPI_Parameter::dump(ModelHighAPI_Dumper& theDumper) const
44 FeaturePtr aBase = feature();
45 const std::string& aDocName = theDumper.name(aBase->document());
46 const std::string& aParamName = theDumper.name(aBase, false, true);
48 AttributeStringPtr anExpr = aBase->string(ParametersPlugin_Parameter::EXPRESSION_ID());
49 AttributeStringPtr aComment = aBase->string(ParametersPlugin_Parameter::COMMENT_ID());
51 theDumper << "model.addParameter(" << aDocName << ", \"" << aParamName << "\", " << anExpr;
52 if (aComment->isInitialized() && !aComment->value().empty())
53 theDumper << ", " << aComment;
54 theDumper << ")" << std::endl;
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)
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));