From: dish Date: Tue, 9 Jan 2024 16:11:49 +0000 (+0000) Subject: [bos #35151][EDF](2023-T1) Centered rectangle. X-Git-Tag: V9_13_0a1~9 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=782cb1f92bf82c5b10c912d523e004ef0cf6b8a3;p=modules%2Fshaper.git [bos #35151][EDF](2023-T1) Centered rectangle. Return std::pair of rectangle and sketch point on creation of centered rectangle instead of just rectangle. --- diff --git a/src/PythonAddons/Test/TestRectangleCentered.py b/src/PythonAddons/Test/TestRectangleCentered.py index ae1fdbb26..89bde85fa 100755 --- a/src/PythonAddons/Test/TestRectangleCentered.py +++ b/src/PythonAddons/Test/TestRectangleCentered.py @@ -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() diff --git a/src/SketchAPI/SketchAPI.i b/src/SketchAPI/SketchAPI.i index 3aa4dd53c..e756dd638 100644 --- a/src/SketchAPI/SketchAPI.i +++ b/src/SketchAPI/SketchAPI.i @@ -95,6 +95,9 @@ // std::pair -> [] %template(PointRefAttrPair) std::pair, ModelHighAPI_RefAttr>; +%template(RectangleAndPoint) std::pair, std::shared_ptr>; + + %typecheck(SWIG_TYPECHECK_POINTER) std::shared_ptr, const std::shared_ptr & { std::shared_ptr * temp_feature; std::shared_ptr * temp_interface; diff --git a/src/SketchAPI/SketchAPI_Rectangle.cpp b/src/SketchAPI/SketchAPI_Rectangle.cpp index cd1e2c233..a04d7c6db 100644 --- a/src/SketchAPI/SketchAPI_Rectangle.cpp +++ b/src/SketchAPI/SketchAPI_Rectangle.cpp @@ -20,6 +20,7 @@ #include "SketchAPI_Rectangle.h" //-------------------------------------------------------------------------------------- #include +#include "SketchAPI_Point.h" //-------------------------------------------------------------------------------------- #include #include @@ -34,7 +35,7 @@ SketchAPI_Rectangle::SketchAPI_Rectangle( } SketchAPI_Rectangle::SketchAPI_Rectangle(const std::shared_ptr & 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 } } -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 & 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 > SketchAPI_Rectangle::lines() aFeatures.push_back(ModelAPI_Feature::feature(*anIt)); return SketchAPI_SketchEntity::wrap(aFeatures); } + +std::shared_ptr SketchAPI_Rectangle::centerSketchPoint() const +{ + auto aFeature = ModelAPI_Feature::feature(centerPointRef()->object()); + return std::shared_ptr(new SketchAPI_Point(aFeature)); +} diff --git a/src/SketchAPI/SketchAPI_Rectangle.h b/src/SketchAPI/SketchAPI_Rectangle.h index c570ddeb2..5e655125f 100644 --- a/src/SketchAPI/SketchAPI_Rectangle.h +++ b/src/SketchAPI/SketchAPI_Rectangle.h @@ -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 & 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 & 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 > lines() const; + + SKETCHAPI_EXPORT std::shared_ptr centerSketchPoint() const; }; //! Pointer on Rectangle object diff --git a/src/SketchAPI/SketchAPI_Sketch.cpp b/src/SketchAPI/SketchAPI_Sketch.cpp index b3b5b2251..09668c82b 100644 --- a/src/SketchAPI/SketchAPI_Sketch.cpp +++ b/src/SketchAPI/SketchAPI_Sketch.cpp @@ -558,7 +558,7 @@ static std::shared_ptr pointCoordinates( std::shared_ptr SketchAPI_Sketch::addRectangle( const std::pair, ModelHighAPI_RefAttr> & theStartPoint, - const std::pair, ModelHighAPI_RefAttr> & theEndPoint) + const std::pair, ModelHighAPI_RefAttr> & theEndPoint) { std::shared_ptr aFeature = compositeFeature()->addFeature(SketchAPI_Rectangle::ID()); RectanglePtr aRect(new SketchAPI_Rectangle(aFeature)); @@ -568,14 +568,14 @@ std::shared_ptr 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_Sketch::addRectangle( return aRect; } -std::shared_ptr SketchAPI_Sketch::addRectangleCentered( +std::pair, std::shared_ptr> SketchAPI_Sketch::addRectangleCentered( const std::pair, ModelHighAPI_RefAttr> & theCenter, const std::pair, ModelHighAPI_RefAttr> & theCorner) { @@ -595,7 +595,7 @@ std::shared_ptr 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_Sketch::addRectangleCentered( AttributePtr aEndPnt = aLine->attribute(SketchPlugin_Line::START_ID()); setCoincident(ModelHighAPI_RefAttr(aEndPnt), theCorner.second); } - return aRect; + return std::pair, std::shared_ptr>(aRect, aRect->centerSketchPoint()); } -std::shared_ptr SketchAPI_Sketch::addRectangleCentered( - double theCenterX, double theCenterY, +std::pair, std::shared_ptr> SketchAPI_Sketch::addRectangleCentered( + double theCenterX, double theCenterY, double theCornerX, double theCornerY ) { std::shared_ptr 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>(aRect, aRect->centerSketchPoint()); } //-------------------------------------------------------------------------------------- diff --git a/src/SketchAPI/SketchAPI_Sketch.h b/src/SketchAPI/SketchAPI_Sketch.h index fffa685ca..2df07ffa2 100644 --- a/src/SketchAPI/SketchAPI_Sketch.h +++ b/src/SketchAPI/SketchAPI_Sketch.h @@ -24,6 +24,7 @@ #include "SketchAPI.h" #include +#include #include #include @@ -180,16 +181,16 @@ public: SKETCHAPI_EXPORT std::shared_ptr addRectangle( const std::pair, ModelHighAPI_RefAttr> & theStartPoint, - const std::pair, ModelHighAPI_RefAttr> & theEndPoint); + const std::pair, ModelHighAPI_RefAttr> & theEndPoint); /// Add rectangle SKETCHAPI_EXPORT - std::shared_ptr addRectangleCentered( + std::pair, std::shared_ptr> addRectangleCentered( const std::pair, ModelHighAPI_RefAttr> & theCenter, const std::pair, ModelHighAPI_RefAttr> & theCorner); /// Add rectangle SKETCHAPI_EXPORT - std::shared_ptr addRectangleCentered( - double theCenterX, double theCenterY, + std::pair, std::shared_ptr> addRectangleCentered( + double theCenterX, double theCenterY, double theCornerX, double theCornerY ); diff --git a/src/SketchPlugin/doc/examples/rectangle.py b/src/SketchPlugin/doc/examples/rectangle.py index 596e076b6..4f39bc653 100644 --- a/src/SketchPlugin/doc/examples/rectangle.py +++ b/src/SketchPlugin/doc/examples/rectangle.py @@ -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()