]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
[bos #35151][EDF](2023-T1) Centered rectangle. CR35151 18/head
authordish <dmitrii.shvydkoi@opencascade.com>
Tue, 9 Jan 2024 16:11:49 +0000 (16:11 +0000)
committerdish <dmitrii.shvydkoi@opencascade.com>
Thu, 9 May 2024 11:52:19 +0000 (11:52 +0000)
Return std::pair of rectangle and sketch point on creation of centered rectangle instead of just rectangle.

src/PythonAddons/Test/TestRectangleCentered.py
src/SketchAPI/SketchAPI.i
src/SketchAPI/SketchAPI_Rectangle.cpp
src/SketchAPI/SketchAPI_Rectangle.h
src/SketchAPI/SketchAPI_Sketch.cpp
src/SketchAPI/SketchAPI_Sketch.h
src/SketchPlugin/doc/examples/rectangle.py

index ae1fdbb26c7977fd49575c2ac454dd5d4814f111..89bde85fa593deeaeac04fa02098a432de2f582c 100755 (executable)
@@ -91,7 +91,7 @@ def checkIfArbitraryAlignedRectangle(theEdgeLines):
   assert (areConnected(aLine0, aLine1))
   assert (areConnected(aLine1, aLine2))
   assert (areConnected(aLine2, aLine3))
-  assert (areConnected(aLine3, aLine0))       
+  assert (areConnected(aLine3, aLine0))
 
 
 
@@ -103,7 +103,7 @@ centerPoint = geom.Pnt2d(50, 50)
 endPoint = geom.Pnt2d(100, 100)
 
 sketch = model.addSketch(part, model.defaultPlane("XOY"))
-rectangle_1 = sketch.addRectangleCentered(centerPoint, endPoint)
+rectangle_1, center_of_rectangle_1 = sketch.addRectangleCentered(centerPoint, endPoint)
 lines_1 = rectangle_1.lines()
 model.end()
 
@@ -113,14 +113,14 @@ model.begin()
 projection_1 = sketch.addProjection(model.selection("VERTEX", "PartSet/Origin"), False)
 point_1 = SketchAPI_Point(projection_1.createdFeature())
 
-rectangle_2 = sketch.addRectangleCentered(point_1.coordinates(), endPoint)
+rectangle_2, _ = sketch.addRectangleCentered(point_1.coordinates(), endPoint)
 lines_2 = rectangle_2.lines()
 model.end()
 
 checkRectangle(lines_2, geom.Pnt2d(0.0, 0.0), endPoint)
 
 model.begin()
-rectangle_3 = sketch.addRectangleCentered(SketchAPI_Line(lines_1[0]).startPoint(), SketchAPI_Line(lines_2[0]).endPoint())
+rectangle_3, _ = sketch.addRectangleCentered(SketchAPI_Line(lines_1[0]).startPoint(), SketchAPI_Line(lines_2[0]).endPoint())
 lines_3 = rectangle_3.lines()
 model.end()
 
index 3aa4dd53c8e829b10671ae52c43ccc1374a964ab..e756dd63840974c33182065f69721d2990b6c224 100644 (file)
@@ -95,6 +95,9 @@
 // std::pair -> []
 %template(PointRefAttrPair) std::pair<std::shared_ptr<GeomAPI_Pnt2d>, ModelHighAPI_RefAttr>;
 
+%template(RectangleAndPoint) std::pair<std::shared_ptr<SketchAPI_Rectangle>, std::shared_ptr<SketchAPI_Point>>;
+
+
 %typecheck(SWIG_TYPECHECK_POINTER) std::shared_ptr<ModelAPI_Feature>, const std::shared_ptr<ModelAPI_Feature> & {
   std::shared_ptr<ModelAPI_Feature> * temp_feature;
   std::shared_ptr<ModelHighAPI_Interface> * temp_interface;
index cd1e2c233caf59c6fc5518b0daebb79e3ae5d544..a04d7c6db42e0c693636dea078eadb685169c301 100644 (file)
@@ -20,6 +20,7 @@
 #include "SketchAPI_Rectangle.h"
 //--------------------------------------------------------------------------------------
 #include <GeomAPI_Pnt2d.h>
+#include "SketchAPI_Point.h"
 //--------------------------------------------------------------------------------------
 #include <ModelHighAPI_Selection.h>
 #include <ModelHighAPI_Tools.h>
@@ -34,7 +35,7 @@ SketchAPI_Rectangle::SketchAPI_Rectangle(
 }
 
 SketchAPI_Rectangle::SketchAPI_Rectangle(const std::shared_ptr<ModelAPI_Feature> & theFeature,
-                                         double theX1, double theY1, 
+                                         double theX1, double theY1,
                                          double theX2, double theY2,
                                          bool theCreateByCenterAndCorner)
   : SketchAPI_SketchEntity(theFeature)
@@ -55,10 +56,6 @@ SketchAPI_Rectangle::SketchAPI_Rectangle(const std::shared_ptr<ModelAPI_Feature>
   }
 }
 
-SketchAPI_Rectangle::~SketchAPI_Rectangle()
-{
-}
-
 //--------------------------------------------------------------------------------------
 void SketchAPI_Rectangle::setByCoordinates(
     double theX1, double theY1, double theX2, double theY2)
@@ -79,7 +76,7 @@ void SketchAPI_Rectangle::setByPoints(const std::shared_ptr<GeomAPI_Pnt2d> & the
 }
 
 void SketchAPI_Rectangle::setByCenterAndCornerCoords(
-  double theCenterX, double theCenterY, 
+  double theCenterX, double theCenterY,
   double theCornerX, double theCornerY
 ) {
   fillAttribute("RectangleTypeCentered", type());
@@ -109,3 +106,9 @@ std::list<std::shared_ptr<SketchAPI_SketchEntity> > SketchAPI_Rectangle::lines()
     aFeatures.push_back(ModelAPI_Feature::feature(*anIt));
   return SketchAPI_SketchEntity::wrap(aFeatures);
 }
+
+std::shared_ptr<SketchAPI_Point> SketchAPI_Rectangle::centerSketchPoint() const
+{
+  auto aFeature = ModelAPI_Feature::feature(centerPointRef()->object());
+  return std::shared_ptr<SketchAPI_Point>(new SketchAPI_Point(aFeature));
+}
index c570ddeb2f4db559320251cd6c624435bc66bcad..5e655125fe4ebfc65dbbdf177eaac04ce91fd932 100644 (file)
@@ -27,6 +27,7 @@
 
 //--------------------------------------------------------------------------------------
 class ModelHighAPI_Selection;
+class SketchAPI_Point;
 //--------------------------------------------------------------------------------------
 /**\class SketchAPI_Rectangle
  * \ingroup CPPHighAPI
@@ -41,8 +42,8 @@ public:
   /// Constructor with values
   SKETCHAPI_EXPORT
   SketchAPI_Rectangle(const std::shared_ptr<ModelAPI_Feature> & theFeature,
-                      double theX1, double theY1, 
-                      double theX2, double theY2, 
+                      double theX1, double theY1,
+                      double theX2, double theY2,
                       bool theCreateByCenterAndCorner = false);
   /// Constructor with values
   SKETCHAPI_EXPORT
@@ -51,11 +52,11 @@ public:
                       const std::shared_ptr<GeomAPI_Pnt2d> & thePoint2,
                       bool theCreateByCenterAndCorner = false);
 
-  
+
 
   /// Destructor
   SKETCHAPI_EXPORT
-  virtual ~SketchAPI_Rectangle();
+  virtual ~SketchAPI_Rectangle() = default;
 
   INTERFACE_7("SketchRectangle",
               type, "RectangleType", ModelAPI_AttributeString,
@@ -86,7 +87,7 @@ public:
   /// Set by coordinates
   SKETCHAPI_EXPORT
   void setByCenterAndCornerCoords(
-    double theCenterX, double theCenterY, 
+    double theCenterX, double theCenterY,
     double theCornerX, double theCornerY
   );
 
@@ -99,6 +100,8 @@ public:
 
   /// List of lines composing rectangle
   SKETCHAPI_EXPORT std::list<std::shared_ptr<SketchAPI_SketchEntity> > lines() const;
+
+  SKETCHAPI_EXPORT std::shared_ptr<SketchAPI_Point> centerSketchPoint() const;
 };
 
 //! Pointer on Rectangle object
index b3b5b2251304056ae406e5565d0a9b0694281d57..09668c82bfb51b23284cce87541a39614d083f8f 100644 (file)
@@ -558,7 +558,7 @@ static std::shared_ptr<GeomAPI_Pnt2d> pointCoordinates(
 
 std::shared_ptr<SketchAPI_Rectangle> SketchAPI_Sketch::addRectangle(
       const std::pair<std::shared_ptr<GeomAPI_Pnt2d>, ModelHighAPI_RefAttr> & theStartPoint,
-      const std::pair<std::shared_ptr<GeomAPI_Pnt2d>, ModelHighAPI_RefAttr> & theEndPoint) 
+      const std::pair<std::shared_ptr<GeomAPI_Pnt2d>, ModelHighAPI_RefAttr> & theEndPoint)
 {
   std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchAPI_Rectangle::ID());
   RectanglePtr aRect(new SketchAPI_Rectangle(aFeature));
@@ -568,14 +568,14 @@ std::shared_ptr<SketchAPI_Rectangle> SketchAPI_Sketch::addRectangle(
   aRect->execute();
 
   if (!theStartPoint.second.isEmpty() && aRect->linesList()->size() >= 1) {
-    // Get end point of the first line in rectangle and apply coincidence constraint
+    // Get end point of the first line of rectangle and apply coincidence constraint
     FeaturePtr aLine = ModelAPI_Feature::feature(aRect->linesList()->object(0));
     AttributePtr aLinePnt = aLine->attribute(SketchPlugin_Line::END_ID());
     setCoincident(ModelHighAPI_RefAttr(aLinePnt), theStartPoint.second);
   }
 
   if (!theEndPoint.second.isEmpty() && aRect->linesList()->size() >= 4) {
-    // Get start point of the last line in rectangle and apply coincidence constraint
+    // Get start point of the last line of rectangle and apply coincidence constraint
     FeaturePtr aLine = ModelAPI_Feature::feature(aRect->linesList()->object(3));
     AttributePtr aLinePnt = aLine->attribute(SketchPlugin_Line::START_ID());
     setCoincident(ModelHighAPI_RefAttr(aLinePnt), theEndPoint.second);
@@ -583,7 +583,7 @@ std::shared_ptr<SketchAPI_Rectangle> SketchAPI_Sketch::addRectangle(
   return aRect;
 }
 
-std::shared_ptr<SketchAPI_Rectangle> SketchAPI_Sketch::addRectangleCentered(
+std::pair<std::shared_ptr<SketchAPI_Rectangle>, std::shared_ptr<SketchAPI_Point>> SketchAPI_Sketch::addRectangleCentered(
     const std::pair<std::shared_ptr<GeomAPI_Pnt2d>, ModelHighAPI_RefAttr> & theCenter,
     const std::pair<std::shared_ptr<GeomAPI_Pnt2d>, ModelHighAPI_RefAttr> & theCorner)
 {
@@ -595,7 +595,7 @@ std::shared_ptr<SketchAPI_Rectangle> SketchAPI_Sketch::addRectangleCentered(
     fillAttribute(theCenter.second, aRect->centerPointRef());
   else
     fillAttribute(pointCoordinates(theCenter), aRect->centerPoint());
-  
+
   fillAttribute(pointCoordinates(theCorner), aRect->cornerPoint());
   aRect->execute();
 
@@ -605,15 +605,16 @@ std::shared_ptr<SketchAPI_Rectangle> SketchAPI_Sketch::addRectangleCentered(
     AttributePtr aEndPnt = aLine->attribute(SketchPlugin_Line::START_ID());
     setCoincident(ModelHighAPI_RefAttr(aEndPnt), theCorner.second);
   }
-  return aRect;
+  return std::pair<std::shared_ptr<SketchAPI_Rectangle>, std::shared_ptr<SketchAPI_Point>>(aRect, aRect->centerSketchPoint());
 }
 
-std::shared_ptr<SketchAPI_Rectangle> SketchAPI_Sketch::addRectangleCentered(
-      double theCenterX, double theCenterY, 
+std::pair<std::shared_ptr<SketchAPI_Rectangle>, std::shared_ptr<SketchAPI_Point>> SketchAPI_Sketch::addRectangleCentered(
+      double theCenterX, double theCenterY,
       double theCornerX, double theCornerY
 ) {
   std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchAPI_Rectangle::ID());
-  return RectanglePtr(new SketchAPI_Rectangle(aFeature, theCenterX, theCenterY, theCornerX, theCornerY, true));
+  auto aRect = RectanglePtr(new SketchAPI_Rectangle(aFeature, theCenterX, theCenterY, theCornerX, theCornerY, true));
+  return std::pair<std::shared_ptr<SketchAPI_Rectangle>, std::shared_ptr<SketchAPI_Point>>(aRect, aRect->centerSketchPoint());
 }
 
 //--------------------------------------------------------------------------------------
index fffa685caa26c138c01cee3e12bb6ee0d29e3d17..2df07ffa25a0094b780695b51f81fec1828a6b15 100644 (file)
@@ -24,6 +24,7 @@
 #include "SketchAPI.h"
 
 #include <list>
+#include <utility>
 
 #include <SketchPlugin_Sketch.h>
 #include <SketchPlugin_SketchEntity.h>
@@ -180,16 +181,16 @@ public:
   SKETCHAPI_EXPORT
   std::shared_ptr<SketchAPI_Rectangle> addRectangle(
       const std::pair<std::shared_ptr<GeomAPI_Pnt2d>, ModelHighAPI_RefAttr> & theStartPoint,
-      const std::pair<std::shared_ptr<GeomAPI_Pnt2d>, ModelHighAPI_RefAttr> & theEndPoint);    
+      const std::pair<std::shared_ptr<GeomAPI_Pnt2d>, ModelHighAPI_RefAttr> & theEndPoint);
   /// Add rectangle
   SKETCHAPI_EXPORT
-  std::shared_ptr<SketchAPI_Rectangle> addRectangleCentered(
+  std::pair<std::shared_ptr<SketchAPI_Rectangle>, std::shared_ptr<SketchAPI_Point>> addRectangleCentered(
       const std::pair<std::shared_ptr<GeomAPI_Pnt2d>, ModelHighAPI_RefAttr> & theCenter,
       const std::pair<std::shared_ptr<GeomAPI_Pnt2d>, ModelHighAPI_RefAttr> & theCorner);
   /// Add rectangle
   SKETCHAPI_EXPORT
-  std::shared_ptr<SketchAPI_Rectangle> addRectangleCentered(
-      double theCenterX, double theCenterY, 
+  std::pair<std::shared_ptr<SketchAPI_Rectangle>, std::shared_ptr<SketchAPI_Point>> addRectangleCentered(
+      double theCenterX, double theCenterY,
       double theCornerX, double theCornerY
   );
 
index 596e076b6a0cf5b0c450928e760b4da623e32e17..4f39bc6535ca43f10ba412965507214cfd2c84d1 100644 (file)
@@ -43,7 +43,7 @@ rectWithPnt2Ds = Sketch_1.addRectangle(Pnt2D_corner1, Pnt2D_corner2)
 Pnt2D_center = geom.Pnt2d(6.5 + 5, 5.5)
 Pnt2D_corner = geom.Pnt2d(8.0 + 5, 8.0)
 
-rectCenteredWithPnt2Ds = Sketch_1.addRectangleCentered(Pnt2D_center, Pnt2D_corner)
+rectCenteredWithPnt2Ds, rectCenteredWithPnt2DCenterSketchPoint = Sketch_1.addRectangleCentered(Pnt2D_center, Pnt2D_corner)
 ############################################################
 
 
@@ -51,12 +51,12 @@ rectCenteredWithPnt2Ds = Sketch_1.addRectangleCentered(Pnt2D_center, Pnt2D_corne
 SP_center = Sketch_1.addPoint(6.5, 5.5)
 SP_corner = Sketch_1.addPoint(8.0, 8.0)
 
-rectCenteredWithPnt2Ds = Sketch_1.addRectangleCentered(SP_center, SP_corner)
+rectCenteredWithPnt2Ds, _ = Sketch_1.addRectangleCentered(SP_center, SP_corner)
 ############################################################
 
 
 ### Rectangle by center and corner defined with doubles.
-rectCenteredWithDoubles = Sketch_1.addRectangleCentered(6.5, -5.5, 8.0, -8.0)
+rectCenteredWithDoubles, _ = Sketch_1.addRectangleCentered(6.5, -5.5, 8.0, -8.0)
 ############################################################
 
 model.do()