refactor: Adopt gp_Ax2 for sketch plane and geometry definition

Co-authored-by: aider (gemini/gemini-2.5-pro) <aider@aider.chat>
This commit is contained in:
2026-03-03 15:46:26 -07:00
parent 577fb5f846
commit 0469853a2c
2 changed files with 23 additions and 44 deletions
+20 -41
View File
@@ -16,9 +16,11 @@
#include <BRepBuilderAPI_MakeEdge.hxx>
#include <BRepBuilderAPI_MakeWire.hxx>
#include <GC_MakeSegment.hxx>
#include <ElCLib.hxx>
#include <gp_Ax2.hxx>
#include <gp_Circ.hxx>
#include <gp_Dir.hxx>
#include <gp_Pnt2d.hxx>
#include <QInputDialog>
#include <QFileDialog>
@@ -124,26 +126,12 @@ void ApplicationController::beginSketchCreation()
emit planeSelectionModeStarted();
}
void ApplicationController::onPlaneSelected(ViewportWidget::SketchPlane plane)
void ApplicationController::onPlaneSelected(const gp_Ax2& plane)
{
auto feature = new SketchFeature("Sketch");
m_activeSketch = feature;
switch (plane) {
case ViewportWidget::SketchPlane::XY:
feature->setPlane(SketchFeature::SketchPlane::XY);
break;
case ViewportWidget::SketchPlane::XZ:
feature->setPlane(SketchFeature::SketchPlane::XZ);
break;
case ViewportWidget::SketchPlane::YZ:
feature->setPlane(SketchFeature::SketchPlane::YZ);
break;
case ViewportWidget::SketchPlane::NONE:
delete feature;
m_activeSketch = nullptr;
return;
}
feature->setPlane(plane);
m_document->addFeature(feature);
emit sketchModeStarted(plane);
@@ -165,23 +153,21 @@ 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());
}
const auto& plane = m_activeSketch->plane();
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);
gp_Pnt2d p1_2d = ElCLib::To2d(corner1, plane);
gp_Pnt2d p3_2d = ElCLib::To2d(corner2, plane);
gp_Pnt2d p2_2d(p3_2d.X(), p1_2d.Y());
gp_Pnt2d p4_2d(p1_2d.X(), p3_2d.Y());
gp_Pnt p2_3d = ElCLib::To3d(p2_2d, plane);
gp_Pnt p4_3d = ElCLib::To3d(p4_2d, plane);
TopoDS_Edge e1 = BRepBuilderAPI_MakeEdge(corner1, p2_3d);
TopoDS_Edge e2 = BRepBuilderAPI_MakeEdge(p2_3d, corner2);
TopoDS_Edge e3 = BRepBuilderAPI_MakeEdge(corner2, p4_3d);
TopoDS_Edge e4 = BRepBuilderAPI_MakeEdge(p4_3d, corner1);
BRepBuilderAPI_MakeWire wireMaker(e1, e2, e3, e4);
if (wireMaker.IsDone()) {
@@ -195,15 +181,8 @@ 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());
}
const auto& sketchPlane = m_activeSketch->plane();
gp_Ax2 axis(center, sketchPlane.Direction());
gp_Circ circle(axis, radius);
TopoDS_Edge edge = BRepBuilderAPI_MakeEdge(circle);
+3 -3
View File
@@ -9,8 +9,8 @@
#define APPLICATIONCONTROLLER_H
#include <QObject>
#include "ViewportWidget.h" // For SketchPlane enum
#include <gp_Pnt.hxx>
#include <gp_Ax2.hxx>
class Document;
class MainWindow;
@@ -47,12 +47,12 @@ public slots:
bool saveDocumentAs();
void beginSketchCreation();
void onPlaneSelected(ViewportWidget::SketchPlane plane);
void onPlaneSelected(const gp_Ax2& plane);
void endSketch();
signals:
void planeSelectionModeStarted();
void sketchModeStarted(ViewportWidget::SketchPlane plane);
void sketchModeStarted(const gp_Ax2& plane);
void sketchModeEnded();
void currentFileChanged(const QString& path);
void activeToolChanged(ToolType tool);