Salome HOME
rectangle: add AddRectangleCentered function to python
authorrraphael <raphael.raphael@c-s.fr>
Tue, 26 Jan 2021 17:38:09 +0000 (18:38 +0100)
committerrraphael <raphael.raphael@c-s.fr>
Tue, 26 Jan 2021 17:38:09 +0000 (18:38 +0100)
src/PythonAPI/Test/TestAddRectangle.py
src/SketchAPI/SketchAPI_Sketch.cpp
src/SketchAPI/SketchAPI_Sketch.h
src/SketchPlugin/doc/examples/rectangle.py
src/SketchPlugin/doc/images/Rectangle_center_end_panel.png [new file with mode: 0644]
src/SketchPlugin/doc/images/Rectangle_res2.png [new file with mode: 0644]
src/SketchPlugin/doc/images/Rectangle_start_end_panel.png [new file with mode: 0644]
src/SketchPlugin/doc/images/rectangle_center_end.png [new file with mode: 0644]
src/SketchPlugin/doc/images/rectangle_start_end.png [new file with mode: 0644]
src/SketchPlugin/doc/rectangleFeature.rst

index d22cc3a03160f0897116d4c1d22a673e1a3d0118..28427d22c7cac555dd3a21c424ae23485800b295 100644 (file)
@@ -39,6 +39,12 @@ endPoint2 = geom.Pnt2d(120, 75)
 rectangle_3 = sketch.addRectangle(centerPoint, endPoint2, True)
 rectangle_4 = sketch.addRectangle(10, 5, 25, 75, True)
 
+# rectangles from center and end points second version
+centerPoint2 = geom.Pnt2d(200, 180)
+endPoint3 = geom.Pnt2d(220, 175)
+rectangle_5 = sketch.addRectangleCentered(centerPoint2, endPoint3)
+rectangle_6 = sketch.addRectangleCentered(108, 59, 125, 175)
+
 model.end()
 
 
index 910beca82e82eac7e4dbdb3b87777a908777936c..cd9851de2390c562ee94e75e33d831751bed8bbd 100644 (file)
@@ -441,6 +441,22 @@ std::shared_ptr<SketchAPI_Rectangle> SketchAPI_Sketch::addRectangle(
   return RectanglePtr(new SketchAPI_Rectangle(aFeature, theFirstPoint, theEndPoint, isFirstPointCenter));
 }
 
+std::shared_ptr<SketchAPI_Rectangle> SketchAPI_Sketch::addRectangleCentered(
+    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, true));
+}
+std::shared_ptr<SketchAPI_Rectangle> SketchAPI_Sketch::addRectangleCentered(
+    const std::shared_ptr<GeomAPI_Pnt2d> & theFirstPoint,
+    const std::shared_ptr<GeomAPI_Pnt2d> & theEndPoint)
+{
+  std::shared_ptr<ModelAPI_Feature> aFeature =
+    compositeFeature()->addFeature(SketchAPI_Rectangle::ID());
+  return RectanglePtr(new SketchAPI_Rectangle(aFeature, theFirstPoint, theEndPoint, true));
+}
+
 //--------------------------------------------------------------------------------------
 std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(double theCenterX,
                                                               double theCenterY,
index 3f77ba084436c0afeaefd27af859123405ebbf83..866986e72ca9600bc2bc630dc23f690ad1f12b92 100644 (file)
@@ -188,7 +188,15 @@ public:
   std::shared_ptr<SketchAPI_Rectangle> addRectangle(
       const std::shared_ptr<GeomAPI_Pnt2d> & theFirstPoint,
       const std::shared_ptr<GeomAPI_Pnt2d> & theEndPoint,  bool isFirstPointCenter);
-
+  /// Add rectangle
+  SKETCHAPI_EXPORT
+  std::shared_ptr<SketchAPI_Rectangle> addRectangleCentered(
+      double theX1, double theY1, double theX2, double theY2);
+  /// Add rectangle
+  SKETCHAPI_EXPORT
+  std::shared_ptr<SketchAPI_Rectangle> addRectangleCentered(
+      const std::shared_ptr<GeomAPI_Pnt2d> & theFirstPoint,
+      const std::shared_ptr<GeomAPI_Pnt2d> & theEndPoint);
   /// Add circle
   SKETCHAPI_EXPORT
   std::shared_ptr<SketchAPI_Circle> addCircle(
index 1795cf62c376b06387bf84204e60e04fd07824b0..4cb5b4d89eaa5b3d87c40b96280a8bc88265d003 100644 (file)
@@ -6,5 +6,8 @@ Part_1 = model.addPart(partSet)
 Part_1_doc = Part_1.document()
 Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOY"))
 Rectangle_1 = Sketch_1.addRectangle(5.5, 8.5, 31.3, 78.9)
+# rectangle from center and end points 
+rectangle_2 = sketch.addRectangleCentered(10, 5, 25, 75)
+
 model.do()
 model.end()
diff --git a/src/SketchPlugin/doc/images/Rectangle_center_end_panel.png b/src/SketchPlugin/doc/images/Rectangle_center_end_panel.png
new file mode 100644 (file)
index 0000000..ea400e5
Binary files /dev/null and b/src/SketchPlugin/doc/images/Rectangle_center_end_panel.png differ
diff --git a/src/SketchPlugin/doc/images/Rectangle_res2.png b/src/SketchPlugin/doc/images/Rectangle_res2.png
new file mode 100644 (file)
index 0000000..fd0666c
Binary files /dev/null and b/src/SketchPlugin/doc/images/Rectangle_res2.png differ
diff --git a/src/SketchPlugin/doc/images/Rectangle_start_end_panel.png b/src/SketchPlugin/doc/images/Rectangle_start_end_panel.png
new file mode 100644 (file)
index 0000000..2f8e29b
Binary files /dev/null and b/src/SketchPlugin/doc/images/Rectangle_start_end_panel.png differ
diff --git a/src/SketchPlugin/doc/images/rectangle_center_end.png b/src/SketchPlugin/doc/images/rectangle_center_end.png
new file mode 100644 (file)
index 0000000..4472811
Binary files /dev/null and b/src/SketchPlugin/doc/images/rectangle_center_end.png differ
diff --git a/src/SketchPlugin/doc/images/rectangle_start_end.png b/src/SketchPlugin/doc/images/rectangle_start_end.png
new file mode 100644 (file)
index 0000000..095af86
Binary files /dev/null and b/src/SketchPlugin/doc/images/rectangle_start_end.png differ
index c2a9abef88c960c34d7d60cc7102d8da4a9d1061..7244dc9ecf5af1d3f6d53b213bbb56b39892e9c5 100644 (file)
@@ -15,9 +15,26 @@ To add a new Rectangle to the Sketch:
 #. select in the Main Menu *Sketch - > Rectangle* item  or
 #. click |rectangle.icon| **Rectangle** button in Sketch toolbar:
 
-The following property panel appears:
+There are 2 algorithms for creation of a Rectangle:
 
-.. figure:: images/Rectangle_panel.png
+.. figure:: images/rectangle_start_end.png
+   :align: left
+   :height: 24px
+
+**By start and end points** creates a rectangle with the given two corners points.
+
+.. figure:: images/rectangle_center_end.png
+   :align: left
+   :height: 24px
+
+**By center and end point** creates a rectangle with center and end point as corner.
+
+-------------------------------------------------------------------------------------------
+
+By start and end points
+""""""""""""""""""""""""""
+
+.. figure:: images/Rectangle_start_end_panel.png
    :align: center
 
    Rectangle
@@ -31,10 +48,33 @@ Start and end points coordinates are displayed in the property panel.
 
 .. py:function:: Sketch_1.addRectangle(X1, Y1, X2, Y2)
 
-    :param real: X1 value.
-    :param real: Y1 value.
-    :param real: X2 value.
-    :param real: Y2 value.
+    :param real: X1 corner X value.
+    :param real: Y1 corner Y value.
+    :param real: X2 opposite corner X value.
+    :param real: Y2 opposite corner Y value.
+    :return: Result object.
+
+By center and end point
+""""""""""""""""""""""""""
+
+.. figure:: images/Rectangle_center_end_panel.png
+   :align: center
+
+   Rectangle
+
+Click in the view once to set the center, then move the mouse and click a second time to set the corner.
+If an existing object is clicked, a constraint for the point will be created automatically.
+
+Center and end points coordinates are displayed in the property panel.
+
+**TUI Command**:
+
+.. py:function:: Sketch_1.addRectangleCentered(X1, Y1, X2, Y2)
+
+    :param real: X1 center X value.
+    :param real: Y1 center Y value.
+    :param real: X2 corner X value.
+    :param real: Y2 corner Y value.
     :return: Result object.
 
 Result
@@ -42,9 +82,9 @@ Result
 
 Created rectangle appears in the view.
 
-.. figure:: images/Rectangle_res.png
+.. figure:: images/Rectangle_res2.png
    :align: center
 
-   Rectangle created
+   Rectangles created
 
 **See Also** a sample TUI Script of :ref:`tui_create_rectangle` operation.