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:
@@ -16,9 +16,11 @@
|
|||||||
#include <BRepBuilderAPI_MakeEdge.hxx>
|
#include <BRepBuilderAPI_MakeEdge.hxx>
|
||||||
#include <BRepBuilderAPI_MakeWire.hxx>
|
#include <BRepBuilderAPI_MakeWire.hxx>
|
||||||
#include <GC_MakeSegment.hxx>
|
#include <GC_MakeSegment.hxx>
|
||||||
|
#include <ElCLib.hxx>
|
||||||
#include <gp_Ax2.hxx>
|
#include <gp_Ax2.hxx>
|
||||||
#include <gp_Circ.hxx>
|
#include <gp_Circ.hxx>
|
||||||
#include <gp_Dir.hxx>
|
#include <gp_Dir.hxx>
|
||||||
|
#include <gp_Pnt2d.hxx>
|
||||||
|
|
||||||
#include <QInputDialog>
|
#include <QInputDialog>
|
||||||
#include <QFileDialog>
|
#include <QFileDialog>
|
||||||
@@ -124,26 +126,12 @@ void ApplicationController::beginSketchCreation()
|
|||||||
emit planeSelectionModeStarted();
|
emit planeSelectionModeStarted();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ApplicationController::onPlaneSelected(ViewportWidget::SketchPlane plane)
|
void ApplicationController::onPlaneSelected(const gp_Ax2& plane)
|
||||||
{
|
{
|
||||||
auto feature = new SketchFeature("Sketch");
|
auto feature = new SketchFeature("Sketch");
|
||||||
m_activeSketch = feature;
|
m_activeSketch = feature;
|
||||||
|
|
||||||
switch (plane) {
|
feature->setPlane(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;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_document->addFeature(feature);
|
m_document->addFeature(feature);
|
||||||
emit sketchModeStarted(plane);
|
emit sketchModeStarted(plane);
|
||||||
@@ -165,23 +153,21 @@ void ApplicationController::addRectangle(const gp_Pnt& corner1, const gp_Pnt& co
|
|||||||
if (m_activeSketch) {
|
if (m_activeSketch) {
|
||||||
m_activeSketch->addObject(new SketchRectangle(corner1, corner2));
|
m_activeSketch->addObject(new SketchRectangle(corner1, corner2));
|
||||||
|
|
||||||
gp_Pnt c2, c4;
|
const auto& plane = m_activeSketch->plane();
|
||||||
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);
|
gp_Pnt2d p1_2d = ElCLib::To2d(corner1, plane);
|
||||||
TopoDS_Edge e2 = BRepBuilderAPI_MakeEdge(c2, corner2);
|
gp_Pnt2d p3_2d = ElCLib::To2d(corner2, plane);
|
||||||
TopoDS_Edge e3 = BRepBuilderAPI_MakeEdge(corner2, c4);
|
|
||||||
TopoDS_Edge e4 = BRepBuilderAPI_MakeEdge(c4, corner1);
|
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);
|
BRepBuilderAPI_MakeWire wireMaker(e1, e2, e3, e4);
|
||||||
if (wireMaker.IsDone()) {
|
if (wireMaker.IsDone()) {
|
||||||
@@ -195,15 +181,8 @@ void ApplicationController::addCircle(const gp_Pnt& center, double radius)
|
|||||||
if (m_activeSketch) {
|
if (m_activeSketch) {
|
||||||
m_activeSketch->addObject(new SketchCircle(center, radius));
|
m_activeSketch->addObject(new SketchCircle(center, radius));
|
||||||
|
|
||||||
gp_Ax2 axis;
|
const auto& sketchPlane = m_activeSketch->plane();
|
||||||
auto plane = m_activeSketch->plane();
|
gp_Ax2 axis(center, sketchPlane.Direction());
|
||||||
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);
|
gp_Circ circle(axis, radius);
|
||||||
TopoDS_Edge edge = BRepBuilderAPI_MakeEdge(circle);
|
TopoDS_Edge edge = BRepBuilderAPI_MakeEdge(circle);
|
||||||
|
|||||||
@@ -9,8 +9,8 @@
|
|||||||
#define APPLICATIONCONTROLLER_H
|
#define APPLICATIONCONTROLLER_H
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include "ViewportWidget.h" // For SketchPlane enum
|
|
||||||
#include <gp_Pnt.hxx>
|
#include <gp_Pnt.hxx>
|
||||||
|
#include <gp_Ax2.hxx>
|
||||||
|
|
||||||
class Document;
|
class Document;
|
||||||
class MainWindow;
|
class MainWindow;
|
||||||
@@ -47,12 +47,12 @@ public slots:
|
|||||||
bool saveDocumentAs();
|
bool saveDocumentAs();
|
||||||
|
|
||||||
void beginSketchCreation();
|
void beginSketchCreation();
|
||||||
void onPlaneSelected(ViewportWidget::SketchPlane plane);
|
void onPlaneSelected(const gp_Ax2& plane);
|
||||||
void endSketch();
|
void endSketch();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void planeSelectionModeStarted();
|
void planeSelectionModeStarted();
|
||||||
void sketchModeStarted(ViewportWidget::SketchPlane plane);
|
void sketchModeStarted(const gp_Ax2& plane);
|
||||||
void sketchModeEnded();
|
void sketchModeEnded();
|
||||||
void currentFileChanged(const QString& path);
|
void currentFileChanged(const QString& path);
|
||||||
void activeToolChanged(ToolType tool);
|
void activeToolChanged(ToolType tool);
|
||||||
|
|||||||
Reference in New Issue
Block a user