From 2557a7fd1ab98d22d7be5e22ff8a4e24eba0ce26 Mon Sep 17 00:00:00 2001 From: dbv Date: Tue, 14 Jun 2016 11:53:11 +0300 Subject: [PATCH] Fixed Test/TestSketcherAddCircle.py --- src/PythonAPI/Test/TestSketcherAddCircle.py | 18 ++++---- src/SketchAPI/SketchAPI_Sketch.cpp | 46 +++++++++++++++++++++ src/SketchAPI/SketchAPI_Sketch.h | 33 ++++++++++++++- 3 files changed, 87 insertions(+), 10 deletions(-) diff --git a/src/PythonAPI/Test/TestSketcherAddCircle.py b/src/PythonAPI/Test/TestSketcherAddCircle.py index 9bc6e4c9d..6b1c3399e 100644 --- a/src/PythonAPI/Test/TestSketcherAddCircle.py +++ b/src/PythonAPI/Test/TestSketcherAddCircle.py @@ -2,24 +2,24 @@ import unittest import model from TestSketcher import SketcherTestCase -class SketcherAddCircle(SketcherTestCase): +class SketcherAddCircle(SketcherTestCase): def test_add_cricle(self): circle = self.sketch.addCircle(0, 10, 20) model.do() - self.assertEqual(circle.center().x(), 0.0) + self.assertEqual(circle.center().x(), 0.0) self.assertEqual(circle.center().y(), 10.0) - self.assertEqual(circle.radius(), 20.0) - + self.assertEqual(circle.radius().value(), 20.0) + def test_modify_circle(self): circle = self.sketch.addCircle(0, 10, 20) model.do() circle.setCenter(10, 10) circle.setRadius(30) model.do() - self.assertEqual(circle.center().x(), 10.0) + self.assertEqual(circle.center().x(), 10.0) self.assertEqual(circle.center().y(), 10.0) - self.assertEqual(circle.radius(), 30.0) - - + self.assertEqual(circle.radius().value(), 30.0) + + if __name__ == "__main__": - unittest.main(verbosity=2) \ No newline at end of file + unittest.main(verbosity=2) diff --git a/src/SketchAPI/SketchAPI_Sketch.cpp b/src/SketchAPI/SketchAPI_Sketch.cpp index 57c01c05d..ea8047d6c 100644 --- a/src/SketchAPI/SketchAPI_Sketch.cpp +++ b/src/SketchAPI/SketchAPI_Sketch.cpp @@ -28,6 +28,7 @@ //-------------------------------------------------------------------------------------- #include #include +#include "SketchAPI_Circle.h" #include "SketchAPI_Line.h" //-------------------------------------------------------------------------------------- SketchAPI_Sketch::SketchAPI_Sketch( @@ -127,6 +128,51 @@ std::shared_ptr SketchAPI_Sketch::addLine(const std::string & th return LinePtr(new SketchAPI_Line(aFeature, theExternalName)); } +//-------------------------------------------------------------------------------------- +std::shared_ptr SketchAPI_Sketch::addCircle(double theCenterX, + double theCenterY, + double theRadius) +{ + std::shared_ptr aFeature = compositeFeature()->addFeature(SketchPlugin_Circle::ID()); + return CirclePtr(new SketchAPI_Circle(aFeature, theCenterX, theCenterY, theRadius)); +} + +std::shared_ptr SketchAPI_Sketch::addCircle(const std::shared_ptr& theCenter, + double theRadius) +{ + std::shared_ptr aFeature = compositeFeature()->addFeature(SketchPlugin_Circle::ID()); + return CirclePtr(new SketchAPI_Circle(aFeature, theCenter, theRadius)); +} + +std::shared_ptr SketchAPI_Sketch::addCircle(double theX1, double theY1, + double theX2, double theY2, + double theX3, double theY3) +{ + std::shared_ptr aFeature = compositeFeature()->addFeature(SketchPlugin_Circle::ID()); + return CirclePtr(new SketchAPI_Circle(aFeature, theX1, theY1, theX2, theY2, theX3, theY3)); +} + +std::shared_ptr SketchAPI_Sketch::addCircle(const std::shared_ptr& thePoint1, + const std::shared_ptr& thePoint2, + const std::shared_ptr& thePoint3) +{ + std::shared_ptr aFeature = compositeFeature()->addFeature(SketchPlugin_Circle::ID()); + return CirclePtr(new SketchAPI_Circle(aFeature, thePoint1, thePoint2, thePoint3)); +} + +std::shared_ptr SketchAPI_Sketch::addCircle(const ModelHighAPI_Selection & theExternal) +{ + std::shared_ptr aFeature = compositeFeature()->addFeature(SketchPlugin_Line::ID()); + return CirclePtr(new SketchAPI_Circle(aFeature, theExternal)); +} + +std::shared_ptr SketchAPI_Sketch::addCircle(const std::string & theExternalName) +{ + // TODO(spo): Add constraint SketchConstraintRigid like in PythonAPI. Is it necessary? + std::shared_ptr aFeature = compositeFeature()->addFeature(SketchPlugin_Line::ID()); + return CirclePtr(new SketchAPI_Circle(aFeature, theExternalName)); +} + //-------------------------------------------------------------------------------------- std::shared_ptr SketchAPI_Sketch::setCoincident( const ModelHighAPI_RefAttr & thePoint1, diff --git a/src/SketchAPI/SketchAPI_Sketch.h b/src/SketchAPI/SketchAPI_Sketch.h index ecde2ce28..524c013c4 100644 --- a/src/SketchAPI/SketchAPI_Sketch.h +++ b/src/SketchAPI/SketchAPI_Sketch.h @@ -20,6 +20,7 @@ class ModelAPI_CompositeFeature; class ModelHighAPI_Double; class ModelHighAPI_RefAttr; class ModelHighAPI_Selection; +class SketchAPI_Circle; class SketchAPI_Line; //-------------------------------------------------------------------------------------- /**\class SketchAPI_Sketch @@ -80,7 +81,37 @@ public: SKETCHAPI_EXPORT std::shared_ptr addLine(const std::string & theExternalName); - // TODO(spo): addCircle + // Add circle. + SKETCHAPI_EXPORT + std::shared_ptr addCircle(double theCenterX, + double theCenterY, + double theRadius); + + // Add circle. + SKETCHAPI_EXPORT + std::shared_ptr addCircle(const std::shared_ptr& theCenter, + double theRadius); + + // Add circle. + SKETCHAPI_EXPORT + std::shared_ptr addCircle(double theX1, double theY1, + double theX2, double theY2, + double theX3, double theY3); + + // Add circle. + SKETCHAPI_EXPORT + std::shared_ptr addCircle(const std::shared_ptr& thePoint1, + const std::shared_ptr& thePoint2, + const std::shared_ptr& thePoint3); + + /// Add circle. + SKETCHAPI_EXPORT + std::shared_ptr addCircle(const ModelHighAPI_Selection & theExternal); + + /// Add circle. + SKETCHAPI_EXPORT + std::shared_ptr addCircle(const std::string & theExternalName); + // TODO(spo): addArc /// Set coincident -- 2.39.2