Return std::pair of rectangle and sketch point on creation of centered rectangle instead of just rectangle.
assert (areConnected(aLine0, aLine1))
assert (areConnected(aLine1, aLine2))
assert (areConnected(aLine2, aLine3))
- assert (areConnected(aLine3, aLine0))
+ assert (areConnected(aLine3, aLine0))
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()
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()
// 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;
#include "SketchAPI_Rectangle.h"
//--------------------------------------------------------------------------------------
#include <GeomAPI_Pnt2d.h>
+#include "SketchAPI_Point.h"
//--------------------------------------------------------------------------------------
#include <ModelHighAPI_Selection.h>
#include <ModelHighAPI_Tools.h>
}
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)
}
}
-SketchAPI_Rectangle::~SketchAPI_Rectangle()
-{
-}
-
//--------------------------------------------------------------------------------------
void SketchAPI_Rectangle::setByCoordinates(
double theX1, double theY1, double theX2, double theY2)
}
void SketchAPI_Rectangle::setByCenterAndCornerCoords(
- double theCenterX, double theCenterY,
+ double theCenterX, double theCenterY,
double theCornerX, double theCornerY
) {
fillAttribute("RectangleTypeCentered", type());
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));
+}
//--------------------------------------------------------------------------------------
class ModelHighAPI_Selection;
+class SketchAPI_Point;
//--------------------------------------------------------------------------------------
/**\class SketchAPI_Rectangle
* \ingroup CPPHighAPI
/// 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
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,
/// Set by coordinates
SKETCHAPI_EXPORT
void setByCenterAndCornerCoords(
- double theCenterX, double theCenterY,
+ double theCenterX, double theCenterY,
double theCornerX, double theCornerY
);
/// 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
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));
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);
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)
{
fillAttribute(theCenter.second, aRect->centerPointRef());
else
fillAttribute(pointCoordinates(theCenter), aRect->centerPoint());
-
+
fillAttribute(pointCoordinates(theCorner), aRect->cornerPoint());
aRect->execute();
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());
}
//--------------------------------------------------------------------------------------
#include "SketchAPI.h"
#include <list>
+#include <utility>
#include <SketchPlugin_Sketch.h>
#include <SketchPlugin_SketchEntity.h>
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
);
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)
############################################################
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()