From d6e61c2018b8e8664ee66262c6b55709a7965f07 Mon Sep 17 00:00:00 2001 From: spo Date: Wed, 15 Jun 2016 11:47:47 +0300 Subject: [PATCH] Add SketchAPI_Point --- src/PythonAPI/Test/TestSketcherAddPoint.py | 21 ++--- src/SketchAPI/CMakeLists.txt | 2 + src/SketchAPI/SketchAPI.i | 8 +- src/SketchAPI/SketchAPI_Point.cpp | 98 ++++++++++++++++++++++ src/SketchAPI/SketchAPI_Point.h | 78 +++++++++++++++++ src/SketchAPI/SketchAPI_Sketch.cpp | 25 ++++++ src/SketchAPI/SketchAPI_Sketch.h | 18 +++- src/SketchAPI/SketchAPI_swig.h | 1 + 8 files changed, 234 insertions(+), 17 deletions(-) create mode 100644 src/SketchAPI/SketchAPI_Point.cpp create mode 100644 src/SketchAPI/SketchAPI_Point.h diff --git a/src/PythonAPI/Test/TestSketcherAddPoint.py b/src/PythonAPI/Test/TestSketcherAddPoint.py index 284d37764..8adf1574d 100644 --- a/src/PythonAPI/Test/TestSketcherAddPoint.py +++ b/src/PythonAPI/Test/TestSketcherAddPoint.py @@ -2,24 +2,19 @@ import unittest import model from TestSketcher import SketcherTestCase -class SketcherAddPoint(SketcherTestCase): +class SketcherAddPoint(SketcherTestCase): def test_add_point(self): point = self.sketch.addPoint(0, 1) model.do() - self.assertEqual(point.pointData().x(), 0.0) - self.assertEqual(point.pointData().y(), 1.0) - + self.assertEqual(point.coordinates().x(), 0.0) + self.assertEqual(point.coordinates().y(), 1.0) + def test_modify_point(self): point = self.sketch.addPoint(0, 1) - point.setValue(1, 2) + point.setCoordinates(1, 2) model.do() - self.assertEqual(point.pointData().x(), 1.0) - self.assertEqual(point.pointData().y(), 2.0) - - def test_empty_args(self): - with self.assertRaises(TypeError): - self.sketch.addPoint() - - + self.assertEqual(point.coordinates().x(), 1.0) + self.assertEqual(point.coordinates().y(), 2.0) + if __name__ == "__main__": unittest.main(verbosity=2) \ No newline at end of file diff --git a/src/SketchAPI/CMakeLists.txt b/src/SketchAPI/CMakeLists.txt index 206eee1c1..57792bb13 100644 --- a/src/SketchAPI/CMakeLists.txt +++ b/src/SketchAPI/CMakeLists.txt @@ -9,6 +9,7 @@ SET(PROJECT_HEADERS SketchAPI_Line.h SketchAPI_Sketch.h SketchAPI_SketchEntity.h + SketchAPI_Point.h ) SET(PROJECT_SOURCES @@ -17,6 +18,7 @@ SET(PROJECT_SOURCES SketchAPI_Line.cpp SketchAPI_Sketch.cpp SketchAPI_SketchEntity.cpp + SketchAPI_Point.cpp ) SET(PROJECT_LIBRARIES diff --git a/src/SketchAPI/SketchAPI.i b/src/SketchAPI/SketchAPI.i index 7aad3d4de..7cbd61f4c 100644 --- a/src/SketchAPI/SketchAPI.i +++ b/src/SketchAPI/SketchAPI.i @@ -25,6 +25,7 @@ %shared_ptr(SketchAPI_Line) %shared_ptr(SketchAPI_Sketch) %shared_ptr(SketchAPI_SketchEntity) +%shared_ptr(SketchAPI_Point) // fix compilarion error: ‘res2’ was not declared in this scope %typemap(freearg) const std::list & {} @@ -54,9 +55,10 @@ } } -// all supported interfaces (the order is very important: base class first) +// all supported interfaces (the order is very important according dependencies: base class first) %include "SketchAPI_SketchEntity.h" -%include "SketchAPI_Arc.h" -%include "SketchAPI_Circle.h" +%include "SketchAPI_Point.h" %include "SketchAPI_Line.h" +%include "SketchAPI_Circle.h" +%include "SketchAPI_Arc.h" %include "SketchAPI_Sketch.h" diff --git a/src/SketchAPI/SketchAPI_Point.cpp b/src/SketchAPI/SketchAPI_Point.cpp new file mode 100644 index 000000000..c133a74c0 --- /dev/null +++ b/src/SketchAPI/SketchAPI_Point.cpp @@ -0,0 +1,98 @@ +// Name : SketchAPI_Point.cpp +// Purpose: +// +// History: +// 15/06/16 - Sergey POKHODENKO - Creation of the file + +//-------------------------------------------------------------------------------------- +#include "SketchAPI_Point.h" +//-------------------------------------------------------------------------------------- +#include +//-------------------------------------------------------------------------------------- +#include +#include +//-------------------------------------------------------------------------------------- +SketchAPI_Point::SketchAPI_Point( + const std::shared_ptr & theFeature) +: SketchAPI_SketchEntity(theFeature) +{ + initialize(); +} + +SketchAPI_Point::SketchAPI_Point( + const std::shared_ptr & theFeature, + double theX, double theY) +: SketchAPI_SketchEntity(theFeature) +{ + if (initialize()) { + setCoordinates(theX, theY); + } +} + +SketchAPI_Point::SketchAPI_Point( + const std::shared_ptr & theFeature, + const std::shared_ptr & thePoint) +: SketchAPI_SketchEntity(theFeature) +{ + if (initialize()) { + setCoordinates(thePoint); + } +} + +SketchAPI_Point::SketchAPI_Point( + const std::shared_ptr & theFeature, + const ModelHighAPI_Selection & theExternal ) +: SketchAPI_SketchEntity(theFeature) +{ + if (initialize()) { + setByExternal(theExternal); + } +} + +SketchAPI_Point::SketchAPI_Point( + const std::shared_ptr & theFeature, + const std::string & theExternalName ) +: SketchAPI_SketchEntity(theFeature) +{ + if (initialize()) { + setByExternalName(theExternalName); + } +} + +SketchAPI_Point::~SketchAPI_Point() +{ + +} + +//-------------------------------------------------------------------------------------- +void SketchAPI_Point::setCoordinates( + double theX, double theY) +{ + fillAttribute(coordinates(), theX, theY); + + execute(); +} + +void SketchAPI_Point::setCoordinates( + const std::shared_ptr & thePoint) +{ + fillAttribute(thePoint, coordinates()); + + execute(); +} + +void SketchAPI_Point::setByExternal(const ModelHighAPI_Selection & theExternal) +{ + fillAttribute(theExternal, external()); + + execute(); +} + +void SketchAPI_Point::setByExternalName(const std::string & theExternalName) +{ + fillAttribute(ModelHighAPI_Selection("VERTEX", theExternalName), external()); + + execute(); +} + +//-------------------------------------------------------------------------------------- diff --git a/src/SketchAPI/SketchAPI_Point.h b/src/SketchAPI/SketchAPI_Point.h new file mode 100644 index 000000000..1596b0f9b --- /dev/null +++ b/src/SketchAPI/SketchAPI_Point.h @@ -0,0 +1,78 @@ +// Name : SketchAPI_Point.h +// Purpose: +// +// History: +// 15/06/16 - Sergey POKHODENKO - Creation of the file + +#ifndef SRC_SKETCHAPI_SKETCHAPI_POINT_H_ +#define SRC_SKETCHAPI_SKETCHAPI_POINT_H_ + +//-------------------------------------------------------------------------------------- +#include "SketchAPI.h" + +#include + +#include + +#include "SketchAPI_SketchEntity.h" +//-------------------------------------------------------------------------------------- +class ModelHighAPI_Selection; +//-------------------------------------------------------------------------------------- +/**\class SketchAPI_Point + * \ingroup CPPHighAPI + * \brief Interface for Point feature + */ +class SketchAPI_Point : public SketchAPI_SketchEntity +{ +public: + /// Constructor without values + SKETCHAPI_EXPORT + explicit SketchAPI_Point(const std::shared_ptr & theFeature); + /// Constructor with values + SKETCHAPI_EXPORT + SketchAPI_Point(const std::shared_ptr & theFeature, + double theX, double theY); + /// Constructor with values + SKETCHAPI_EXPORT + SketchAPI_Point(const std::shared_ptr & theFeature, + const std::shared_ptr & thePoint); + /// Constructor with values + SKETCHAPI_EXPORT + SketchAPI_Point(const std::shared_ptr & theFeature, + const ModelHighAPI_Selection & theExternal); + /// Constructor with values + SKETCHAPI_EXPORT + SketchAPI_Point(const std::shared_ptr & theFeature, + const std::string & theExternalName); + /// Destructor + SKETCHAPI_EXPORT + virtual ~SketchAPI_Point(); + + INTERFACE_2(SketchPlugin_Point::ID(), + coordinates, SketchPlugin_Point::COORD_ID(), GeomDataAPI_Point2D, /** Point coordinates */, + external, SketchPlugin_Point::EXTERNAL_ID(), ModelAPI_AttributeSelection, /** External */ + ) + + /// Set by coordinates + SKETCHAPI_EXPORT + void setCoordinates(double theX, double theY); + + /// Set by points + SKETCHAPI_EXPORT + void setCoordinates(const std::shared_ptr & thePoint); + + /// Set by external + SKETCHAPI_EXPORT + void setByExternal(const ModelHighAPI_Selection & theExternal); + + /// Set by external name + SKETCHAPI_EXPORT + void setByExternalName(const std::string & theExternalName); +}; + +//! Pointer on Point object +typedef std::shared_ptr PointPtr; + +//-------------------------------------------------------------------------------------- +//-------------------------------------------------------------------------------------- +#endif /* SRC_SKETCHAPI_SKETCHAPI_POINT_H_ */ diff --git a/src/SketchAPI/SketchAPI_Sketch.cpp b/src/SketchAPI/SketchAPI_Sketch.cpp index 8d24c1534..cdac5d4c5 100644 --- a/src/SketchAPI/SketchAPI_Sketch.cpp +++ b/src/SketchAPI/SketchAPI_Sketch.cpp @@ -34,6 +34,7 @@ #include "SketchAPI_Arc.h" #include "SketchAPI_Circle.h" #include "SketchAPI_Line.h" +#include "SketchAPI_Point.h" //-------------------------------------------------------------------------------------- SketchAPI_Sketch::SketchAPI_Sketch( const std::shared_ptr & theFeature) @@ -147,6 +148,30 @@ SketchPtr addSketch(const std::shared_ptr & thePart, return SketchPtr(new SketchAPI_Sketch(aFeature, ModelHighAPI_Selection("FACE", theExternalName))); } +//-------------------------------------------------------------------------------------- +std::shared_ptr SketchAPI_Sketch::addPoint( + double theX, double theY) +{ + std::shared_ptr aFeature = compositeFeature()->addFeature(SketchPlugin_Point::ID()); + return PointPtr(new SketchAPI_Point(aFeature, theX, theY)); +} +std::shared_ptr SketchAPI_Sketch::addPoint( + const std::shared_ptr & thePoint) +{ + std::shared_ptr aFeature = compositeFeature()->addFeature(SketchPlugin_Point::ID()); + return PointPtr(new SketchAPI_Point(aFeature, thePoint)); +} +std::shared_ptr SketchAPI_Sketch::addPoint(const ModelHighAPI_Selection & theExternal) +{ + std::shared_ptr aFeature = compositeFeature()->addFeature(SketchPlugin_Point::ID()); + return PointPtr(new SketchAPI_Point(aFeature, theExternal)); +} +std::shared_ptr SketchAPI_Sketch::addPoint(const std::string & theExternalName) +{ + std::shared_ptr aFeature = compositeFeature()->addFeature(SketchPlugin_Point::ID()); + return PointPtr(new SketchAPI_Point(aFeature, theExternalName)); +} + //-------------------------------------------------------------------------------------- std::shared_ptr SketchAPI_Sketch::addLine(double theX1, double theY1, double theX2, double theY2) { diff --git a/src/SketchAPI/SketchAPI_Sketch.h b/src/SketchAPI/SketchAPI_Sketch.h index a1433e99e..8108524ab 100644 --- a/src/SketchAPI/SketchAPI_Sketch.h +++ b/src/SketchAPI/SketchAPI_Sketch.h @@ -25,6 +25,7 @@ class ModelHighAPI_Selection; class SketchAPI_Arc; class SketchAPI_Circle; class SketchAPI_Line; +class SketchAPI_Point; //-------------------------------------------------------------------------------------- /**\class SketchAPI_Sketch * \ingroup CPPHighAPI @@ -66,7 +67,22 @@ public: SKETCHAPI_EXPORT void setExternal(const ModelHighAPI_Selection & theExternal); - // TODO(spo): addPoint + // TODO(spo): addIntersection + + /// Add point + SKETCHAPI_EXPORT + std::shared_ptr addPoint( + double theX, double theY); + /// Add point + SKETCHAPI_EXPORT + std::shared_ptr addPoint( + const std::shared_ptr & thePoint); + /// Add point + SKETCHAPI_EXPORT + std::shared_ptr addPoint(const ModelHighAPI_Selection & theExternal); + /// Add point + SKETCHAPI_EXPORT + std::shared_ptr addPoint(const std::string & theExternalName); /// Add line SKETCHAPI_EXPORT diff --git a/src/SketchAPI/SketchAPI_swig.h b/src/SketchAPI/SketchAPI_swig.h index 6ce00f715..32a60738e 100644 --- a/src/SketchAPI/SketchAPI_swig.h +++ b/src/SketchAPI/SketchAPI_swig.h @@ -15,5 +15,6 @@ #include "SketchAPI_Line.h" #include "SketchAPI_Sketch.h" #include "SketchAPI_SketchEntity.h" + #include "SketchAPI_Point.h" #endif /* SRC_SKETCHAPI_SKETCHAPI_SWIG_H_ */ -- 2.39.2