From: mpv Date: Wed, 25 Jan 2017 07:25:58 +0000 (+0300) Subject: Extension of Parameters interface: to set/get double values of results X-Git-Tag: V_2.7.0~308 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=39aa2839a4269a2fc87cfe3b4487cce8f3df9a6f;p=modules%2Fshaper.git Extension of Parameters interface: to set/get double values of results --- diff --git a/src/Model/Model_AttributeBoolean.cpp b/src/Model/Model_AttributeBoolean.cpp index f7111f127..666b8bb23 100644 --- a/src/Model/Model_AttributeBoolean.cpp +++ b/src/Model/Model_AttributeBoolean.cpp @@ -10,7 +10,7 @@ void Model_AttributeBoolean::setValue(bool theValue) { - Standard_Boolean aValue = theValue ? Standard_True : Standard_False; + Standard_Integer aValue = theValue ? 1 : 0; if (!myIsInitialized || myBool->Get() != aValue) { if (myBool.IsNull()) myBool = TDataStd_Integer::Set(myLab, 0); @@ -21,7 +21,7 @@ void Model_AttributeBoolean::setValue(bool theValue) bool Model_AttributeBoolean::value() { - return myIsInitialized && myBool->Get() == Standard_True ; + return myIsInitialized && myBool->Get() == 1; } Model_AttributeBoolean::Model_AttributeBoolean(TDF_Label& theLabel) diff --git a/src/ParametersAPI/ParametersAPI_Parameter.cpp b/src/ParametersAPI/ParametersAPI_Parameter.cpp index b6b9374fe..f4047896e 100644 --- a/src/ParametersAPI/ParametersAPI_Parameter.cpp +++ b/src/ParametersAPI/ParametersAPI_Parameter.cpp @@ -10,6 +10,7 @@ //-------------------------------------------------------------------------------------- #include #include +#include //-------------------------------------------------------------------------------------- ParametersAPI_Parameter::ParametersAPI_Parameter( const std::shared_ptr & theFeature) @@ -35,6 +36,22 @@ ParametersAPI_Parameter::ParametersAPI_Parameter( } } +void ParametersAPI_Parameter::setValue(const double theValue) +{ + // convert value to the expression string + std::ostringstream aValueStr; + aValueStr<(feature()->firstResult()); + // it may raise an exception if result is invalid + return aRes->data()->real(ModelAPI_ResultParameter::VALUE())->value(); +} + ParametersAPI_Parameter::~ParametersAPI_Parameter() { } diff --git a/src/ParametersAPI/ParametersAPI_Parameter.h b/src/ParametersAPI/ParametersAPI_Parameter.h index e9122a107..82bfce5f0 100644 --- a/src/ParametersAPI/ParametersAPI_Parameter.h +++ b/src/ParametersAPI/ParametersAPI_Parameter.h @@ -47,6 +47,11 @@ public: ModelAPI_AttributeString, /** Comment */ ) + /// Just sets the numeric value to the parameter (it resets the previous expression) + PARAMETERSAPI_EXPORT void setValue(const double theValue); + /// Returns the current value of the parameter: the expression result. + PARAMETERSAPI_EXPORT double value(); + /// Dump wrapped feature PARAMETERSAPI_EXPORT virtual void dump(ModelHighAPI_Dumper& theDumper) const; diff --git a/src/PythonAPI/Test/TestSketcherAddArc.py b/src/PythonAPI/Test/TestSketcherAddArc.py index 11e74e46d..ddd01d973 100644 --- a/src/PythonAPI/Test/TestSketcherAddArc.py +++ b/src/PythonAPI/Test/TestSketcherAddArc.py @@ -7,7 +7,7 @@ from TestSketcher import SketcherTestCase class SketcherAddArc(SketcherTestCase): def test_arc_by_coords(self): - arc = self.sketch.addArc(0, 1, 0, 0, 1, 1, 0) + arc = self.sketch.addArc(0, 1, 0, 0, 1, 1, False) model.do() self.assertEqual(arc.startPoint().x(), 0) self.assertEqual(arc.startPoint().y(), 0) @@ -16,15 +16,15 @@ class SketcherAddArc(SketcherTestCase): center = geom.Pnt2d(0, 1) start = geom.Pnt2d(0, 0) end = geom.Pnt2d(1, 1) - arc = self.sketch.addArc(center, start, end, 0) + arc = self.sketch.addArc(center, start, end, False) model.do() self.assertEqual(arc.startPoint().x(), 0) self.assertEqual(arc.startPoint().y(), 0) def test_modify_arc(self): # Note: arc will modify startPoint and endPoint to be in circle - arc = self.sketch.addArc(0, 1, 0, 0, 1, 1, 0) - arc.setByCenterStartEnd(0, 0, 1, 1, -1, -1, 0) + arc = self.sketch.addArc(0, 1, 0, 0, 1, 1, False) + arc.setByCenterStartEnd(0, 0, 1, 1, -1, -1, False) model.do() self.assertEqual(arc.center().x(), 0) self.assertEqual(arc.center().y(), 0)