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 #include <ModelAPI_ResultParameter.h>
14 //--------------------------------------------------------------------------------------
15 ParametersAPI_Parameter::ParametersAPI_Parameter(
16 const std::shared_ptr<ModelAPI_Feature> & theFeature)
17 : ModelHighAPI_Interface(theFeature)
22 ParametersAPI_Parameter::ParametersAPI_Parameter(
23 const std::shared_ptr<ModelAPI_Feature> & theFeature,
24 const std::string & theName,
25 const std::string & theExpression,
26 const std::string & theComment)
27 : ModelHighAPI_Interface(theFeature)
30 fillAttribute(theName, name());
31 fillAttribute(theExpression, expression());
32 if (!theComment.empty())
33 fillAttribute(theComment, comment());
39 void ParametersAPI_Parameter::setValue(const double theValue)
41 // convert value to the expression string
42 std::ostringstream aValueStr;
44 fillAttribute(aValueStr.str(), expression());
48 double ParametersAPI_Parameter::value() {
49 ResultParameterPtr aRes =
50 std::dynamic_pointer_cast<ModelAPI_ResultParameter>(feature()->firstResult());
51 // it may raise an exception if result is invalid
52 return aRes->data()->real(ModelAPI_ResultParameter::VALUE())->value();
55 ParametersAPI_Parameter::~ParametersAPI_Parameter()
59 void ParametersAPI_Parameter::dump(ModelHighAPI_Dumper& theDumper) const
61 FeaturePtr aBase = feature();
62 const std::string& aDocName = theDumper.name(aBase->document());
63 const std::string& aParamName = theDumper.name(aBase, false, true);
65 AttributeStringPtr anExpr = aBase->string(ParametersPlugin_Parameter::EXPRESSION_ID());
66 AttributeStringPtr aComment = aBase->string(ParametersPlugin_Parameter::COMMENT_ID());
68 theDumper << "model.addParameter(" << aDocName << ", \"" << aParamName << "\", " << anExpr;
69 if (aComment->isInitialized() && !aComment->value().empty())
70 theDumper << ", " << aComment;
71 theDumper << ")" << std::endl;
74 //--------------------------------------------------------------------------------------
75 ParameterPtr addParameter(const std::shared_ptr<ModelAPI_Document> & thePart,
76 const std::string & theName,
77 const std::string & theExpression,
78 const std::string & theComment)
80 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ParametersAPI_Parameter::ID());
81 return ParameterPtr(new ParametersAPI_Parameter(aFeature, theName, theExpression, theComment));