From 39aa2839a4269a2fc87cfe3b4487cce8f3df9a6f Mon Sep 17 00:00:00 2001 From: mpv Date: Wed, 25 Jan 2017 10:25:58 +0300 Subject: [PATCH] Extension of Parameters interface: to set/get double values of results --- src/Model/Model_AttributeBoolean.cpp | 4 ++-- src/ParametersAPI/ParametersAPI_Parameter.cpp | 17 +++++++++++++++++ src/ParametersAPI/ParametersAPI_Parameter.h | 5 +++++ src/PythonAPI/Test/TestSketcherAddArc.py | 8 ++++---- 4 files changed, 28 insertions(+), 6 deletions(-) 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) -- 2.39.2