Salome HOME
[bos #35151][EDF](2023-T1) Centered rectangle.
[modules/shaper.git] / src / SketchAPI / SketchAPI_Rectangle.cpp
index 36aeee360e30dc5fba28d090e49fe688df6a4e01..cd1e2c233caf59c6fc5518b0daebb79e3ae5d544 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2021  CEA/DEN, EDF R&D
+// Copyright (C) 2014-2024  CEA, EDF
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 //--------------------------------------------------------------------------------------
 #include <ModelHighAPI_Selection.h>
 #include <ModelHighAPI_Tools.h>
+#include <ModelHighAPI_Dumper.h>
+
 //--------------------------------------------------------------------------------------
 SketchAPI_Rectangle::SketchAPI_Rectangle(
     const std::shared_ptr<ModelAPI_Feature> & theFeature)
-: SketchAPI_SketchEntity(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)
+SketchAPI_Rectangle::SketchAPI_Rectangle(const std::shared_ptr<ModelAPI_Feature> & theFeature,
+                                         double theX1, double theY1, 
+                                         double theX2, double theY2,
+                                         bool theCreateByCenterAndCorner)
+  : SketchAPI_SketchEntity(theFeature)
 {
   if (initialize()) {
-    setByCoordinates(theX1, theY1, theX2, theY2);
+    theCreateByCenterAndCorner ? setByCenterAndCornerCoords(theX1, theY1, theX2, theY2) : 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)
+SketchAPI_Rectangle::SketchAPI_Rectangle(const std::shared_ptr<ModelAPI_Feature> & theFeature,
+                                         const std::shared_ptr<GeomAPI_Pnt2d> & thePoint1,
+                                         const std::shared_ptr<GeomAPI_Pnt2d> & thePoint2,
+                                         bool theCreateByCenterAndCorner)
+  : SketchAPI_SketchEntity(theFeature)
 {
   if (initialize()) {
-    setByPoints(theStartPoint, theEndPoint);
+    theCreateByCenterAndCorner ? setByCenterAndCornerPoints(thePoint1, thePoint2) : setByPoints(thePoint1, thePoint2);
   }
 }
 
@@ -60,19 +63,38 @@ SketchAPI_Rectangle::~SketchAPI_Rectangle()
 void SketchAPI_Rectangle::setByCoordinates(
     double theX1, double theY1, double theX2, double theY2)
 {
+  fillAttribute("RectangleTypeByCorners", type());
   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)
+void SketchAPI_Rectangle::setByPoints(const std::shared_ptr<GeomAPI_Pnt2d> & theFirstPoint,
+                                      const std::shared_ptr<GeomAPI_Pnt2d> & theSecondPoint)
 {
-  fillAttribute(theStartPoint, startPoint());
-  fillAttribute(theEndPoint, endPoint());
+  fillAttribute("RectangleTypeByCorners", type());
+  fillAttribute(theFirstPoint, startPoint());
+  fillAttribute(theSecondPoint, endPoint());
+  execute();
+}
+
+void SketchAPI_Rectangle::setByCenterAndCornerCoords(
+  double theCenterX, double theCenterY, 
+  double theCornerX, double theCornerY
+) {
+  fillAttribute("RectangleTypeCentered", type());
+  fillAttribute(centerPoint(), theCenterX, theCenterY);
+  fillAttribute(cornerPoint(), theCornerX, theCornerY);
+  execute();
+}
 
+void SketchAPI_Rectangle::setByCenterAndCornerPoints(
+  const std::shared_ptr<GeomAPI_Pnt2d> & theCenterPoint,
+  const std::shared_ptr<GeomAPI_Pnt2d> & theCornerPoint
+) {
+  fillAttribute("RectangleTypeCentered", type());
+  fillAttribute(theCenterPoint, centerPoint());
+  fillAttribute(theCornerPoint, cornerPoint());
   execute();
 }