From: spo Date: Thu, 16 Jun 2016 12:08:35 +0000 (+0300) Subject: Add Rectangle X-Git-Tag: V_2.4.0~91^2~23 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=0aa15e9db3dea292ee9e57c32992e9c480ef8232;p=modules%2Fshaper.git Add Rectangle --- diff --git a/src/SketchAPI/CMakeLists.txt b/src/SketchAPI/CMakeLists.txt index e0ab0cfa2..12918c991 100644 --- a/src/SketchAPI/CMakeLists.txt +++ b/src/SketchAPI/CMakeLists.txt @@ -13,6 +13,7 @@ SET(PROJECT_HEADERS SketchAPI_SketchEntity.h SketchAPI_Point.h SketchAPI_Projection.h + SketchAPI_Rectangle.h SketchAPI_Rotation.h SketchAPI_Translation.h ) @@ -27,6 +28,7 @@ SET(PROJECT_SOURCES SketchAPI_SketchEntity.cpp SketchAPI_Point.cpp SketchAPI_Projection.cpp + SketchAPI_Rectangle.cpp SketchAPI_Rotation.cpp SketchAPI_Translation.cpp ) diff --git a/src/SketchAPI/SketchAPI.i b/src/SketchAPI/SketchAPI.i index 955249b70..5c4c63534 100644 --- a/src/SketchAPI/SketchAPI.i +++ b/src/SketchAPI/SketchAPI.i @@ -29,6 +29,7 @@ %shared_ptr(SketchAPI_SketchEntity) %shared_ptr(SketchAPI_Point) %shared_ptr(SketchAPI_Projection) +%shared_ptr(SketchAPI_Rectangle) %shared_ptr(SketchAPI_Rotation) %shared_ptr(SketchAPI_Translation) @@ -109,5 +110,6 @@ %include "SketchAPI_Projection.h" %include "SketchAPI_Mirror.h" %include "SketchAPI_Translation.h" +%include "SketchAPI_Rectangle.h" %include "SketchAPI_Rotation.h" %include "SketchAPI_Sketch.h" diff --git a/src/SketchAPI/SketchAPI_Rectangle.cpp b/src/SketchAPI/SketchAPI_Rectangle.cpp new file mode 100644 index 000000000..3da59f0ff --- /dev/null +++ b/src/SketchAPI/SketchAPI_Rectangle.cpp @@ -0,0 +1,68 @@ +// Name : SketchAPI_Rectangle.cpp +// Purpose: +// +// History: +// 17/06/16 - Sergey POKHODENKO - Creation of the file + +//-------------------------------------------------------------------------------------- +#include "SketchAPI_Rectangle.h" +//-------------------------------------------------------------------------------------- +#include +//-------------------------------------------------------------------------------------- +#include +#include +//-------------------------------------------------------------------------------------- +SketchAPI_Rectangle::SketchAPI_Rectangle( + const std::shared_ptr & theFeature) +: SketchAPI_SketchEntity(theFeature) +{ + initialize(); +} + +SketchAPI_Rectangle::SketchAPI_Rectangle( + const std::shared_ptr & theFeature, + double theX1, double theY1, double theX2, double theY2) +: SketchAPI_SketchEntity(theFeature) +{ + if (initialize()) { + setByCoordinates(theX1, theY1, theX2, theY2); + } +} + +SketchAPI_Rectangle::SketchAPI_Rectangle( + const std::shared_ptr & theFeature, + const std::shared_ptr & theStartPoint, + const std::shared_ptr & theEndPoint) +: SketchAPI_SketchEntity(theFeature) +{ + if (initialize()) { + setByPoints(theStartPoint, theEndPoint); + } +} + +SketchAPI_Rectangle::~SketchAPI_Rectangle() +{ +} + +//-------------------------------------------------------------------------------------- +void SketchAPI_Rectangle::setByCoordinates( + double theX1, double theY1, double theX2, double theY2) +{ + fillAttribute(startPoint(), theX1, theY1); + fillAttribute(endPoint(), theX2, theY2); + + execute(); +} + +void SketchAPI_Rectangle::setByPoints( + const std::shared_ptr & theStartPoint, + const std::shared_ptr & theEndPoint) +{ + fillAttribute(theStartPoint, startPoint()); + fillAttribute(theEndPoint, endPoint()); + + execute(); +} + +//-------------------------------------------------------------------------------------- + diff --git a/src/SketchAPI/SketchAPI_Rectangle.h b/src/SketchAPI/SketchAPI_Rectangle.h new file mode 100644 index 000000000..455d33bdf --- /dev/null +++ b/src/SketchAPI/SketchAPI_Rectangle.h @@ -0,0 +1,61 @@ +// Name : SketchAPI_Rectangle.h +// Purpose: +// +// History: +// 17/06/16 - Sergey POKHODENKO - Creation of the file + +#ifndef SRC_SKETCHAPI_SKETCHAPI_RECTANGLE_H_ +#define SRC_SKETCHAPI_SKETCHAPI_RECTANGLE_H_ + +//-------------------------------------------------------------------------------------- +#include "SketchAPI.h" + +#include "SketchAPI_SketchEntity.h" +//-------------------------------------------------------------------------------------- +class ModelHighAPI_Selection; +//-------------------------------------------------------------------------------------- +/**\class SketchAPI_Rectangle + * \ingroup CPPHighAPI + * \brief Interface for Rectangle feature + */ +class SketchAPI_Rectangle : public SketchAPI_SketchEntity +{ +public: + /// Constructor without values + SKETCHAPI_EXPORT + explicit SketchAPI_Rectangle(const std::shared_ptr & theFeature); + /// Constructor with values + SKETCHAPI_EXPORT + SketchAPI_Rectangle(const std::shared_ptr & theFeature, + double theX1, double theY1, double theX2, double theY2); + /// Constructor with values + SKETCHAPI_EXPORT + SketchAPI_Rectangle(const std::shared_ptr & theFeature, + const std::shared_ptr & theStartPoint, + const std::shared_ptr & theEndPoint); + /// Destructor + SKETCHAPI_EXPORT + virtual ~SketchAPI_Rectangle(); + + INTERFACE_3("SketchRectangle", + startPoint, "RectStartPoint", GeomDataAPI_Point2D, /** Start point */, + endPoint, "RectEndPoint", GeomDataAPI_Point2D, /** End point */, + linesList, "RectangleList", ModelAPI_AttributeRefList, /** Lines list */ + ) + + /// Set by coordinates + SKETCHAPI_EXPORT + void setByCoordinates(double theX1, double theY1, double theX2, double theY2); + + /// Set by points + SKETCHAPI_EXPORT + void setByPoints(const std::shared_ptr & theStartPoint, + const std::shared_ptr & theEndPoint); +}; + +//! Pointer on Rectangle object +typedef std::shared_ptr RectanglePtr; + +//-------------------------------------------------------------------------------------- +//-------------------------------------------------------------------------------------- +#endif /* SRC_SKETCHAPI_SKETCHAPI_RECTANGLE_H_ */ diff --git a/src/SketchAPI/SketchAPI_Sketch.cpp b/src/SketchAPI/SketchAPI_Sketch.cpp index bf97b9809..c19290dbf 100644 --- a/src/SketchAPI/SketchAPI_Sketch.cpp +++ b/src/SketchAPI/SketchAPI_Sketch.cpp @@ -38,6 +38,7 @@ #include "SketchAPI_Mirror.h" #include "SketchAPI_Point.h" #include "SketchAPI_Projection.h" +#include "SketchAPI_Rectangle.h" #include "SketchAPI_Rotation.h" #include "SketchAPI_Translation.h" //-------------------------------------------------------------------------------------- @@ -216,6 +217,20 @@ std::shared_ptr SketchAPI_Sketch::addLine(const std::string & th return LinePtr(new SketchAPI_Line(aFeature, theExternalName)); } +//-------------------------------------------------------------------------------------- +std::shared_ptr SketchAPI_Sketch::addRectangle(double theX1, double theY1, double theX2, double theY2) +{ + std::shared_ptr aFeature = compositeFeature()->addFeature(SketchAPI_Rectangle::ID()); + return RectanglePtr(new SketchAPI_Rectangle(aFeature, theX1, theY1, theX2, theY2)); +} +std::shared_ptr SketchAPI_Sketch::addRectangle( + const std::shared_ptr & theStartPoint, + const std::shared_ptr & theEndPoint) +{ + std::shared_ptr aFeature = compositeFeature()->addFeature(SketchAPI_Rectangle::ID()); + return RectanglePtr(new SketchAPI_Rectangle(aFeature, theStartPoint, theEndPoint)); +} + //-------------------------------------------------------------------------------------- std::shared_ptr SketchAPI_Sketch::addCircle(double theCenterX, double theCenterY, diff --git a/src/SketchAPI/SketchAPI_Sketch.h b/src/SketchAPI/SketchAPI_Sketch.h index 9fd874bc9..8fa4e6752 100644 --- a/src/SketchAPI/SketchAPI_Sketch.h +++ b/src/SketchAPI/SketchAPI_Sketch.h @@ -31,6 +31,7 @@ class SketchAPI_Line; class SketchAPI_Mirror; class SketchAPI_Point; class SketchAPI_Projection; +class SketchAPI_Rectangle; class SketchAPI_Rotation; class SketchAPI_Translation; //-------------------------------------------------------------------------------------- @@ -114,6 +115,16 @@ public: SKETCHAPI_EXPORT std::shared_ptr addLine(const std::string & theExternalName); + /// Add rectangle + SKETCHAPI_EXPORT + std::shared_ptr addRectangle( + double theX1, double theY1, double theX2, double theY2); + /// Add rectangle + SKETCHAPI_EXPORT + std::shared_ptr addRectangle( + const std::shared_ptr & theStartPoint, + const std::shared_ptr & theEndPoint); + /// Add circle SKETCHAPI_EXPORT std::shared_ptr addCircle( diff --git a/src/SketchAPI/SketchAPI_swig.h b/src/SketchAPI/SketchAPI_swig.h index a8b2bfbc5..34c00398f 100644 --- a/src/SketchAPI/SketchAPI_swig.h +++ b/src/SketchAPI/SketchAPI_swig.h @@ -19,6 +19,7 @@ #include "SketchAPI_SketchEntity.h" #include "SketchAPI_Point.h" #include "SketchAPI_Projection.h" + #include "SketchAPI_Rectangle.h" #include "SketchAPI_Rotation.h" #include "SketchAPI_Translation.h"