diff --git a/src/ApplicationController.cpp b/src/ApplicationController.cpp index 2f9c2e3..e48d38d 100644 --- a/src/ApplicationController.cpp +++ b/src/ApplicationController.cpp @@ -13,6 +13,13 @@ #include "SketchCircle.h" #include "MainWindow.h" +#include +#include +#include +#include +#include +#include + #include #include #include @@ -146,6 +153,10 @@ void ApplicationController::addLine(const gp_Pnt& start, const gp_Pnt& end) { if (m_activeSketch) { m_activeSketch->addObject(new SketchLine(start, end)); + + Handle(Geom_TrimmedCurve) segment = GC_MakeSegment(start, end); + TopoDS_Edge edge = BRepBuilderAPI_MakeEdge(segment); + m_activeSketch->addShape(edge); } } @@ -153,6 +164,29 @@ void ApplicationController::addRectangle(const gp_Pnt& corner1, const gp_Pnt& co { if (m_activeSketch) { m_activeSketch->addObject(new SketchRectangle(corner1, corner2)); + + gp_Pnt c2, c4; + auto plane = m_activeSketch->plane(); + if (plane == SketchFeature::SketchPlane::XY) { + c2.SetX(corner2.X()); c2.SetY(corner1.Y()); c2.SetZ(corner1.Z()); + c4.SetX(corner1.X()); c4.SetY(corner2.Y()); c4.SetZ(corner1.Z()); + } else if (plane == SketchFeature::SketchPlane::XZ) { + c2.SetX(corner2.X()); c2.SetY(corner1.Y()); c2.SetZ(corner1.Z()); + c4.SetX(corner1.X()); c4.SetY(corner1.Y()); c4.SetZ(corner2.Z()); + } else { // YZ + c2.SetX(corner1.X()); c2.SetY(corner2.Y()); c2.SetZ(corner1.Z()); + c4.SetX(corner1.X()); c4.SetY(corner1.Y()); c4.SetZ(corner2.Z()); + } + + TopoDS_Edge e1 = BRepBuilderAPI_MakeEdge(corner1, c2); + TopoDS_Edge e2 = BRepBuilderAPI_MakeEdge(c2, corner2); + TopoDS_Edge e3 = BRepBuilderAPI_MakeEdge(corner2, c4); + TopoDS_Edge e4 = BRepBuilderAPI_MakeEdge(c4, corner1); + + BRepBuilderAPI_MakeWire wireMaker(e1, e2, e3, e4); + if (wireMaker.IsDone()) { + m_activeSketch->addShape(wireMaker.Wire()); + } } } @@ -160,6 +194,20 @@ void ApplicationController::addCircle(const gp_Pnt& center, double radius) { if (m_activeSketch) { m_activeSketch->addObject(new SketchCircle(center, radius)); + + gp_Ax2 axis; + auto plane = m_activeSketch->plane(); + if (plane == SketchFeature::SketchPlane::XY) { + axis = gp_Ax2(center, gp::DZ()); + } else if (plane == SketchFeature::SketchPlane::XZ) { + axis = gp_Ax2(center, gp::DY()); + } else { // YZ + axis = gp_Ax2(center, gp::DX()); + } + + gp_Circ circle(axis, radius); + TopoDS_Edge edge = BRepBuilderAPI_MakeEdge(circle); + m_activeSketch->addShape(edge); } } diff --git a/src/SketchFeature.cpp b/src/SketchFeature.cpp index 481c523..af3b069 100644 --- a/src/SketchFeature.cpp +++ b/src/SketchFeature.cpp @@ -10,11 +10,18 @@ #include "SketchLine.h" #include "SketchRectangle.h" +#include +#include + #include SketchFeature::SketchFeature(const QString& name) : Feature(name) { + BRep_Builder builder; + TopoDS_Compound compound; + builder.MakeCompound(compound); + m_shape = compound; } SketchFeature::~SketchFeature() @@ -42,6 +49,12 @@ const TopoDS_Shape& SketchFeature::shape() const return m_shape; } +void SketchFeature::addShape(const TopoDS_Shape& shape) +{ + BRep_Builder builder; + builder.Add(m_shape, shape); +} + void SketchFeature::addObject(SketchObject* object) { m_objects.append(object); diff --git a/src/SketchFeature.h b/src/SketchFeature.h index 67a708b..5189dd0 100644 --- a/src/SketchFeature.h +++ b/src/SketchFeature.h @@ -32,6 +32,7 @@ public: SketchPlane plane() const; const TopoDS_Shape& shape() const; + void addShape(const TopoDS_Shape& shape); void addObject(SketchObject* object); const QList& objects() const;