From: dbv Date: Thu, 9 Jun 2016 15:55:37 +0000 (+0300) Subject: CPP API for SketchPlugin_Circle X-Git-Tag: V_2.4.0~91^2~62 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=6818377f7ba4581d1c5bca434ac59b0ada3853d6;p=modules%2Fshaper.git CPP API for SketchPlugin_Circle --- diff --git a/src/FeaturesAPI/CMakeLists.txt b/src/FeaturesAPI/CMakeLists.txt index 1bf3b9f6c..440b777d8 100644 --- a/src/FeaturesAPI/CMakeLists.txt +++ b/src/FeaturesAPI/CMakeLists.txt @@ -34,6 +34,7 @@ INCLUDE_DIRECTORIES( INCLUDE_DIRECTORIES( ${PROJECT_SOURCE_DIR}/src/GeomAPI ${PROJECT_SOURCE_DIR}/src/GeomAlgoAPI + ${PROJECT_SOURCE_DIR}/src/GeomDataAPI ${PROJECT_SOURCE_DIR}/src/FeaturesPlugin ) diff --git a/src/SketchAPI/CMakeLists.txt b/src/SketchAPI/CMakeLists.txt index 4a62c018a..261c4e4db 100644 --- a/src/SketchAPI/CMakeLists.txt +++ b/src/SketchAPI/CMakeLists.txt @@ -4,12 +4,14 @@ INCLUDE(Common) SET(PROJECT_HEADERS SketchAPI.h + SketchAPI_Circle.h SketchAPI_Line.h SketchAPI_Sketch.h SketchAPI_SketchEntity.h ) SET(PROJECT_SOURCES + SketchAPI_Circle.cpp SketchAPI_Line.cpp SketchAPI_Sketch.cpp SketchAPI_SketchEntity.cpp diff --git a/src/SketchAPI/SketchAPI.i b/src/SketchAPI/SketchAPI.i index 854d74fbd..d0d566de4 100644 --- a/src/SketchAPI/SketchAPI.i +++ b/src/SketchAPI/SketchAPI.i @@ -20,11 +20,13 @@ %include "std_shared_ptr.i" // shared pointers +%shared_ptr(SketchAPI_Circle) %shared_ptr(SketchAPI_Line) %shared_ptr(SketchAPI_Sketch) %shared_ptr(SketchAPI_SketchEntity) // all supported interfaces +%include "SketchAPI_Circle.h" %include "SketchAPI_Line.h" %include "SketchAPI_Sketch.h" %include "SketchAPI_SketchEntity.h" diff --git a/src/SketchAPI/SketchAPI_Circle.cpp b/src/SketchAPI/SketchAPI_Circle.cpp new file mode 100644 index 000000000..e05e76708 --- /dev/null +++ b/src/SketchAPI/SketchAPI_Circle.cpp @@ -0,0 +1,237 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D --> + +// File: SketchAPI_Circle.cpp +// Created: 09 June 2016 +// Author: Dmitry Bobylev + +#include "SketchAPI_Circle.h" + +#include + +#include +#include +#include + +//================================================================================================== +SketchAPI_Circle::SketchAPI_Circle(const std::shared_ptr & theFeature) +: SketchAPI_SketchEntity(theFeature) +{ + initialize(); +} + +//================================================================================================== +SketchAPI_Circle::SketchAPI_Circle(const std::shared_ptr& theFeature, + double theCenterX, + double theCenterY, + double theRadius) +: SketchAPI_SketchEntity(theFeature) +{ + if(initialize()) { + setByCenterAndRadius(theCenterX, theCenterY, theRadius); + } +} + +//================================================================================================== +SketchAPI_Circle::SketchAPI_Circle(const std::shared_ptr& theFeature, + const std::shared_ptr& theCenter, + double theRadius) +: SketchAPI_SketchEntity(theFeature) +{ + if(initialize()) { + setByCenterAndRadius(theCenter, theRadius); + } +} + +//================================================================================================== +SketchAPI_Circle::SketchAPI_Circle(const std::shared_ptr& theFeature, + double theX1, double theY1, + double theX2, double theY2, + double theX3, double theY3) +: SketchAPI_SketchEntity(theFeature) +{ + if (initialize()) { + setByThreePoints(theX1, theY1, theX2, theY2, theX3, theY3); + } +} + +//================================================================================================== +SketchAPI_Circle::SketchAPI_Circle(const std::shared_ptr& theFeature, + const std::shared_ptr& thePoint1, + const std::shared_ptr& thePoint2, + const std::shared_ptr& thePoint3) +: SketchAPI_SketchEntity(theFeature) +{ + if (initialize()) { + setByThreePoints(thePoint1, thePoint2, thePoint3); + } +} + +//================================================================================================== +SketchAPI_Circle::SketchAPI_Circle(const std::shared_ptr& theFeature, + const ModelHighAPI_Selection& theExternal) +: SketchAPI_SketchEntity(theFeature) +{ + if (initialize()) { + setByExternal(theExternal); + } +} + +//================================================================================================== +SketchAPI_Circle::SketchAPI_Circle(const std::shared_ptr& theFeature, + const std::string& theExternalName) +: SketchAPI_SketchEntity(theFeature) +{ + if (initialize()) { + setByExternalName(theExternalName); + } +} + +//================================================================================================== +SketchAPI_Circle::~SketchAPI_Circle() +{ + +} + +//================================================================================================== +void SketchAPI_Circle::setByCenterAndRadius(double theCenterX, double theCenterY, double theRadius) +{ + fillAttribute(SketchPlugin_Circle::CIRCLE_TYPE_CENTER_AND_RADIUS(), mycircleType); + fillAttribute(center(), theCenterX, theCenterY); + fillAttribute(ModelHighAPI_Double(theRadius), myradius); + + execute(); +} + +//================================================================================================== +void SketchAPI_Circle::setByCenterAndRadius(const std::shared_ptr& theCenter, + double theRadius) +{ + fillAttribute(SketchPlugin_Circle::CIRCLE_TYPE_CENTER_AND_RADIUS(), mycircleType); + fillAttribute(theCenter, mycenter); + fillAttribute(ModelHighAPI_Double(theRadius), myradius); + + execute(); +} + +//================================================================================================== +void SketchAPI_Circle::setByThreePoints(double theX1, double theY1, + double theX2, double theY2, + double theX3, double theY3) +{ + fillAttribute(SketchPlugin_Circle::CIRCLE_TYPE_THREE_POINTS(), mycircleType); + fillAttribute(firstPoint(), theX1, theY1); + fillAttribute(secondPoint(), theX2, theY2); + fillAttribute(thirdPoint(), theX3, theY3); + + execute(); +} + +//================================================================================================== +void SketchAPI_Circle::setByThreePoints(const std::shared_ptr& thePoint1, + const std::shared_ptr& thePoint2, + const std::shared_ptr& thePoint3) +{ + fillAttribute(SketchPlugin_Circle::CIRCLE_TYPE_THREE_POINTS(), mycircleType); + fillAttribute(thePoint1, myfirstPoint); + fillAttribute(thePoint2, mysecondPoint); + fillAttribute(thePoint3, mythirdPoint); + + execute(); +} + +//================================================================================================== +void SketchAPI_Circle::setByExternal(const ModelHighAPI_Selection & theExternal) +{ + fillAttribute(theExternal, external()); + + execute(); +} + +//================================================================================================== +void SketchAPI_Circle::setByExternalName(const std::string & theExternalName) +{ + fillAttribute(ModelHighAPI_Selection("EDGE", theExternalName), external()); + + execute(); +} + +//================================================================================================== +void SketchAPI_Circle::setCenter(double theX, double theY) +{ + fillAttribute(SketchPlugin_Circle::CIRCLE_TYPE_CENTER_AND_RADIUS(), mycircleType); + fillAttribute(center(), theX, theY); + + execute(); +} + +//================================================================================================== +void SketchAPI_Circle::setCenter(const std::shared_ptr & theCenter) +{ + fillAttribute(SketchPlugin_Circle::CIRCLE_TYPE_CENTER_AND_RADIUS(), mycircleType); + fillAttribute(theCenter, mycenter); + + execute(); +} + +//================================================================================================== +void SketchAPI_Circle::setRadius(double theRadius) +{ + fillAttribute(SketchPlugin_Circle::CIRCLE_TYPE_CENTER_AND_RADIUS(), mycircleType); + fillAttribute(ModelHighAPI_Double(theRadius), myradius); + + execute(); +} + +//================================================================================================== +void SketchAPI_Circle::setFirstPoint(double theX, double theY) +{ + fillAttribute(SketchPlugin_Circle::CIRCLE_TYPE_THREE_POINTS(), mycircleType); + fillAttribute(firstPoint(), theX, theY); + + execute(); +} + +//================================================================================================== +void SketchAPI_Circle::setFirstPoint(const std::shared_ptr& thePoint) +{ + fillAttribute(SketchPlugin_Circle::CIRCLE_TYPE_THREE_POINTS(), mycircleType); + fillAttribute(thePoint, myfirstPoint); + + execute(); +} + +//================================================================================================== +void SketchAPI_Circle::setSecondPoint(double theX, double theY) +{ + fillAttribute(SketchPlugin_Circle::CIRCLE_TYPE_THREE_POINTS(), mycircleType); + fillAttribute(secondPoint(), theX, theY); + + execute(); +} + +//================================================================================================== +void SketchAPI_Circle::setSecondPoint(const std::shared_ptr& thePoint) +{ + fillAttribute(SketchPlugin_Circle::CIRCLE_TYPE_THREE_POINTS(), mycircleType); + fillAttribute(thePoint, mysecondPoint); + + execute(); +} + +//================================================================================================== +void SketchAPI_Circle::setThirdPoint(double theX, double theY) +{ + fillAttribute(SketchPlugin_Circle::CIRCLE_TYPE_THREE_POINTS(), mycircleType); + fillAttribute(thirdPoint(), theX, theY); + + execute(); +} + +//================================================================================================== +void SketchAPI_Circle::setThirdPoint(const std::shared_ptr& thePoint) +{ + fillAttribute(SketchPlugin_Circle::CIRCLE_TYPE_THREE_POINTS(), mycircleType); + fillAttribute(thePoint, mythirdPoint); + + execute(); +} diff --git a/src/SketchAPI/SketchAPI_Circle.h b/src/SketchAPI/SketchAPI_Circle.h new file mode 100644 index 000000000..70af08f01 --- /dev/null +++ b/src/SketchAPI/SketchAPI_Circle.h @@ -0,0 +1,147 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D --> + +// File: SketchAPI_Circle.h +// Created: 09 June 2016 +// Author: Dmitry Bobylev + +#ifndef SketchAPI_Circle_H_ +#define SketchAPI_Circle_H_ + +#include "SketchAPI.h" +#include "SketchAPI_SketchEntity.h" + +#include + +#include + +class ModelHighAPI_Selection; + +/// \class FeaturesAPI_Boolean +/// \ingroup CPPHighAPI +/// \brief Interface for Circle feature. +class SketchAPI_Circle: public SketchAPI_SketchEntity +{ +public: + /// Constructor without values. + SKETCHAPI_EXPORT + explicit SketchAPI_Circle(const std::shared_ptr& theFeature); + + /// Constructor with values. + SKETCHAPI_EXPORT + SketchAPI_Circle(const std::shared_ptr& theFeature, + double theCenterX, + double theCenterY, + double theRadius); + + /// Constructor with values. + SKETCHAPI_EXPORT + SketchAPI_Circle(const std::shared_ptr& theFeature, + const std::shared_ptr& theCenter, + double theRadius); + + /// Constructor with values. + SKETCHAPI_EXPORT + SketchAPI_Circle(const std::shared_ptr& theFeature, + double theX1, double theY1, + double theX2, double theY2, + double theX3, double theY3); + + /// Constructor with values. + SKETCHAPI_EXPORT + SketchAPI_Circle(const std::shared_ptr& theFeature, + const std::shared_ptr& thePoint1, + const std::shared_ptr& thePoint2, + const std::shared_ptr& thePoint3); + + /// Constructor with values. + SKETCHAPI_EXPORT + SketchAPI_Circle(const std::shared_ptr& theFeature, + const ModelHighAPI_Selection& theExternal); + + /// Constructor with values. + SKETCHAPI_EXPORT + SketchAPI_Circle(const std::shared_ptr& theFeature, + const std::string& theExternalName); + + /// Destructor. + SKETCHAPI_EXPORT + virtual ~SketchAPI_Circle(); + + INTERFACE_7(SketchPlugin_Circle::ID(), + circleType, SketchPlugin_Circle::CIRCLE_TYPE(), ModelAPI_AttributeString, /** Circle type */, + center, SketchPlugin_Circle::CENTER_ID(), GeomDataAPI_Point2D, /** Center point */, + radius, SketchPlugin_Circle::RADIUS_ID(), ModelAPI_AttributeDouble, /** Radius */, + firstPoint, SketchPlugin_Circle::FIRST_POINT_ID(), GeomDataAPI_Point2D, /** First point */, + secondPoint, SketchPlugin_Circle::SECOND_POINT_ID(), GeomDataAPI_Point2D, /** Second point */, + thirdPoint, SketchPlugin_Circle::THIRD_POINT_ID(), GeomDataAPI_Point2D, /** Third point */, + external, SketchPlugin_Circle::EXTERNAL_ID(), ModelAPI_AttributeSelection, /** External */) + + /// Set by center and radius. + SKETCHAPI_EXPORT + void setByCenterAndRadius(double theCenterX, double theCenterY, double theRadius); + + /// Set by center and radius. + SKETCHAPI_EXPORT + void setByCenterAndRadius(const std::shared_ptr& theCenter, double theRadius); + + /// Set by three points. + SKETCHAPI_EXPORT + void setByThreePoints(double theX1, double theY1, + double theX2, double theY2, + double theX3, double theY3); + + /// Set by three points. + SKETCHAPI_EXPORT + void setByThreePoints(const std::shared_ptr& thePoint1, + const std::shared_ptr& thePoint2, + const std::shared_ptr& thePoint3); + + /// Set by external. + SKETCHAPI_EXPORT + void setByExternal(const ModelHighAPI_Selection& theExternal); + + /// Set by external name. + SKETCHAPI_EXPORT + void setByExternalName(const std::string& theExternalName); + + /// Set center. + SKETCHAPI_EXPORT + void setCenter(double theX, double theY); + + /// Set center. + SKETCHAPI_EXPORT + void setCenter(const std::shared_ptr & theCenter); + + /// Set radius. + SKETCHAPI_EXPORT + void setRadius(double theRadius); + + /// Set first point. + SKETCHAPI_EXPORT + void setFirstPoint(double theX, double theY); + + /// Set first point. + SKETCHAPI_EXPORT + void setFirstPoint(const std::shared_ptr& thePoint); + + /// Set second point. + SKETCHAPI_EXPORT + void setSecondPoint(double theX, double theY); + + /// Set second point. + SKETCHAPI_EXPORT + void setSecondPoint(const std::shared_ptr& thePoint); + + /// Set third point. + SKETCHAPI_EXPORT + void setThirdPoint(double theX, double theY); + + /// Set third point. + SKETCHAPI_EXPORT + void setThirdPoint(const std::shared_ptr& thePoint); +}; + +/// Pointer on Circle object. +typedef std::shared_ptr CirclePtr; + +#endif // SketchAPI_Circle_H_ diff --git a/src/SketchAPI/SketchAPI_swig.h b/src/SketchAPI/SketchAPI_swig.h index 67b27257f..c8829b3c5 100644 --- a/src/SketchAPI/SketchAPI_swig.h +++ b/src/SketchAPI/SketchAPI_swig.h @@ -10,6 +10,7 @@ #include #include "SketchAPI.h" + #include "SketchAPI_Circle.h" #include "SketchAPI_Line.h" #include "SketchAPI_Sketch.h" #include "SketchAPI_SketchEntity.h" diff --git a/src/SketchPlugin/SketchPlugin_Circle.cpp b/src/SketchPlugin/SketchPlugin_Circle.cpp index ac719a708..332909184 100644 --- a/src/SketchPlugin/SketchPlugin_Circle.cpp +++ b/src/SketchPlugin/SketchPlugin_Circle.cpp @@ -29,38 +29,12 @@ const double tolerance = 1e-7; namespace { - static const std::string& CIRCLE_TYPE_CENTER_AND_RADIUS() - { - static const std::string TYPE("CenterRadius"); - return TYPE; - } - static const std::string& CIRCLE_TYPE_THREE_POINTS() - { - static const std::string TYPE("ThreePoints"); - return TYPE; - } - - static const std::string& FIRST_POINT_ID() - { - static const std::string FIRST_PNT("FirstPoint"); - return FIRST_PNT; - } - static const std::string& SECOND_POINT_ID() - { - static const std::string SECOND_PNT("SecondPoint"); - return SECOND_PNT; - } - static const std::string& THIRD_POINT_ID() - { - static const std::string THIRD_PNT("ThirdPoint"); - return THIRD_PNT; - } static const std::string& POINT_ID(int theIndex) { switch (theIndex) { - case 1: return FIRST_POINT_ID(); - case 2: return SECOND_POINT_ID(); - case 3: return THIRD_POINT_ID(); + case 1: return SketchPlugin_Circle::FIRST_POINT_ID(); + case 2: return SketchPlugin_Circle::SECOND_POINT_ID(); + case 3: return SketchPlugin_Circle::THIRD_POINT_ID(); } static const std::string DUMMY; diff --git a/src/SketchPlugin/SketchPlugin_Circle.h b/src/SketchPlugin/SketchPlugin_Circle.h index d931beb9a..e183384d8 100644 --- a/src/SketchPlugin/SketchPlugin_Circle.h +++ b/src/SketchPlugin/SketchPlugin_Circle.h @@ -32,6 +32,20 @@ class SketchPlugin_Circle : public SketchPlugin_SketchEntity, public GeomAPI_IPr return TYPE; } + /// Creation method by center and radius. + inline static const std::string& CIRCLE_TYPE_CENTER_AND_RADIUS() + { + static const std::string TYPE("CenterRadius"); + return TYPE; + } + + /// Creation method by three points. + inline static const std::string& CIRCLE_TYPE_THREE_POINTS() + { + static const std::string TYPE("ThreePoints"); + return TYPE; + } + /// 2D point - center of the circle inline static const std::string& CENTER_ID() { @@ -46,6 +60,27 @@ class SketchPlugin_Circle : public SketchPlugin_SketchEntity, public GeomAPI_IPr return MY_CIRCLE_RADIUS_ID; } + /// First point id. + inline static const std::string& FIRST_POINT_ID() + { + static const std::string FIRST_PNT("FirstPoint"); + return FIRST_PNT; + } + + /// Second point id. + inline static const std::string& SECOND_POINT_ID() + { + static const std::string SECOND_PNT("SecondPoint"); + return SECOND_PNT; + } + + /// Third point id. + inline static const std::string& THIRD_POINT_ID() + { + static const std::string THIRD_PNT("ThirdPoint"); + return THIRD_PNT; + } + /// Returns the kind of a feature SKETCHPLUGIN_EXPORT virtual const std::string& getKind() {