Salome HOME
Add Rectangle
authorspo <sergey.pokhodenko@opencascade.com>
Thu, 16 Jun 2016 12:08:35 +0000 (15:08 +0300)
committerspo <sergey.pokhodenko@opencascade.com>
Fri, 17 Jun 2016 11:41:11 +0000 (14:41 +0300)
src/SketchAPI/CMakeLists.txt
src/SketchAPI/SketchAPI.i
src/SketchAPI/SketchAPI_Rectangle.cpp [new file with mode: 0644]
src/SketchAPI/SketchAPI_Rectangle.h [new file with mode: 0644]
src/SketchAPI/SketchAPI_Sketch.cpp
src/SketchAPI/SketchAPI_Sketch.h
src/SketchAPI/SketchAPI_swig.h

index e0ab0cfa2ab5f5c9eb4b732432e77614c07b04ab..12918c9917f84533de9dfe035e4986663eefdd1f 100644 (file)
@@ -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
 )
index 955249b70b921ec48453eb172a3be98e505e7247..5c4c6353479e9e806237e65fecd5dd2e021a582e 100644 (file)
@@ -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)
 
 %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 (file)
index 0000000..3da59f0
--- /dev/null
@@ -0,0 +1,68 @@
+// Name   : SketchAPI_Rectangle.cpp
+// Purpose: 
+//
+// History:
+// 17/06/16 - Sergey POKHODENKO - Creation of the file
+
+//--------------------------------------------------------------------------------------
+#include "SketchAPI_Rectangle.h"
+//--------------------------------------------------------------------------------------
+#include <GeomAPI_Pnt2d.h>
+//--------------------------------------------------------------------------------------
+#include <ModelHighAPI_Selection.h>
+#include <ModelHighAPI_Tools.h>
+//--------------------------------------------------------------------------------------
+SketchAPI_Rectangle::SketchAPI_Rectangle(
+    const std::shared_ptr<ModelAPI_Feature> & theFeature)
+: SketchAPI_SketchEntity(theFeature)
+{
+  initialize();
+}
+
+SketchAPI_Rectangle::SketchAPI_Rectangle(
+    const std::shared_ptr<ModelAPI_Feature> & 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<ModelAPI_Feature> & theFeature,
+    const std::shared_ptr<GeomAPI_Pnt2d> & theStartPoint,
+    const std::shared_ptr<GeomAPI_Pnt2d> & 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<GeomAPI_Pnt2d> & theStartPoint,
+    const std::shared_ptr<GeomAPI_Pnt2d> & 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 (file)
index 0000000..455d33b
--- /dev/null
@@ -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<ModelAPI_Feature> & theFeature);
+  /// Constructor with values
+  SKETCHAPI_EXPORT
+  SketchAPI_Rectangle(const std::shared_ptr<ModelAPI_Feature> & theFeature,
+                      double theX1, double theY1, double theX2, double theY2);
+  /// Constructor with values
+  SKETCHAPI_EXPORT
+  SketchAPI_Rectangle(const std::shared_ptr<ModelAPI_Feature> & theFeature,
+                      const std::shared_ptr<GeomAPI_Pnt2d> & theStartPoint,
+                      const std::shared_ptr<GeomAPI_Pnt2d> & 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<GeomAPI_Pnt2d> & theStartPoint,
+                   const std::shared_ptr<GeomAPI_Pnt2d> & theEndPoint);
+};
+
+//! Pointer on Rectangle object
+typedef std::shared_ptr<SketchAPI_Rectangle> RectanglePtr;
+
+//--------------------------------------------------------------------------------------
+//--------------------------------------------------------------------------------------
+#endif /* SRC_SKETCHAPI_SKETCHAPI_RECTANGLE_H_ */
index bf97b9809011030a37a957999334819de804989a..c19290dbf4090dbdb2bd6d82317c1442c791d9f2 100644 (file)
@@ -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_Line> SketchAPI_Sketch::addLine(const std::string & th
   return LinePtr(new SketchAPI_Line(aFeature, theExternalName));
 }
 
+//--------------------------------------------------------------------------------------
+std::shared_ptr<SketchAPI_Rectangle> SketchAPI_Sketch::addRectangle(double theX1, double theY1, double theX2, double theY2)
+{
+  std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchAPI_Rectangle::ID());
+  return RectanglePtr(new SketchAPI_Rectangle(aFeature, theX1, theY1, theX2, theY2));
+}
+std::shared_ptr<SketchAPI_Rectangle> SketchAPI_Sketch::addRectangle(
+    const std::shared_ptr<GeomAPI_Pnt2d> & theStartPoint,
+    const std::shared_ptr<GeomAPI_Pnt2d> & theEndPoint)
+{
+  std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchAPI_Rectangle::ID());
+  return RectanglePtr(new SketchAPI_Rectangle(aFeature, theStartPoint, theEndPoint));
+}
+
 //--------------------------------------------------------------------------------------
 std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(double theCenterX,
                                                               double theCenterY,
index 9fd874bc9564a0c227c8356cf79ea557a7ccf51b..8fa4e6752d43fd41938dbc1ff5683cad5c4b1808 100644 (file)
@@ -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<SketchAPI_Line> addLine(const std::string & theExternalName);
 
+  /// Add rectangle
+  SKETCHAPI_EXPORT
+  std::shared_ptr<SketchAPI_Rectangle> addRectangle(
+      double theX1, double theY1, double theX2, double theY2);
+  /// Add rectangle
+  SKETCHAPI_EXPORT
+  std::shared_ptr<SketchAPI_Rectangle> addRectangle(
+      const std::shared_ptr<GeomAPI_Pnt2d> & theStartPoint,
+      const std::shared_ptr<GeomAPI_Pnt2d> & theEndPoint);
+
   /// Add circle
   SKETCHAPI_EXPORT
   std::shared_ptr<SketchAPI_Circle> addCircle(
index a8b2bfbc53287e5adc2c44ac50fe977a11117193..34c00398f46f3324a79ad3393943103a86420efa 100644 (file)
@@ -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"