From 4cebb8d552803b62e1be96e2e50a6370b330c2cc Mon Sep 17 00:00:00 2001 From: Tanner Collin Date: Tue, 3 Mar 2026 16:25:59 -0700 Subject: [PATCH] fix: Adapt RectangleTool to updated Open CASCADE ElCLib API Co-authored-by: aider (gemini/gemini-2.5-pro) --- src/RectangleTool.cpp | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/src/RectangleTool.cpp b/src/RectangleTool.cpp index 038f156..f046550 100644 --- a/src/RectangleTool.cpp +++ b/src/RectangleTool.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #include RectangleTool::RectangleTool(ViewportWidget* viewport) @@ -82,8 +83,8 @@ void RectangleTool::mousePressEvent(QMouseEvent *event) QVector3D mousePosQ = m_viewport->unproject(event->pos(), plane); gp_Pnt mousePos(mousePosQ.x(), mousePosQ.y(), mousePosQ.z()); - gp_Pnt2d startPos2d = ElCLib::To2d(startPos, plane); - gp_Pnt2d mousePos2d = ElCLib::To2d(mousePos, plane); + gp_Pnt2d startPos2d(gp_Vec(plane.Location(), startPos).Dot(plane.XDirection()), gp_Vec(plane.Location(), startPos).Dot(plane.YDirection())); + gp_Pnt2d mousePos2d(gp_Vec(plane.Location(), mousePos).Dot(plane.XDirection()), gp_Vec(plane.Location(), mousePos).Dot(plane.YDirection())); double current_w = qAbs(mousePos2d.X() - startPos2d.X()); double current_h = qAbs(mousePos2d.Y() - startPos2d.Y()); @@ -95,7 +96,7 @@ void RectangleTool::mousePressEvent(QMouseEvent *event) int signY = (mousePos2d.Y() >= startPos2d.Y()) ? 1 : -1; gp_Pnt2d endPos2d(startPos2d.X() + signX * rect_w, startPos2d.Y() + signY * rect_h); - gp_Pnt endPos3d = ElCLib::To3d(endPos2d, plane); + gp_Pnt endPos3d = ElCLib::To3d(plane, endPos2d); worldPosQ = QVector3D(endPos3d.X(), endPos3d.Y(), endPos3d.Z()); } else { if (m_viewport->isSnappingOrigin()) { @@ -147,8 +148,8 @@ void RectangleTool::finalizeCreation() QVector3D mousePosQ = m_viewport->unproject(m_viewport->currentMousePos(), plane); gp_Pnt mousePos(mousePosQ.x(), mousePosQ.y(), mousePosQ.z()); - gp_Pnt2d startPos2d = ElCLib::To2d(startPos, plane); - gp_Pnt2d mousePos2d = ElCLib::To2d(mousePos, plane); + gp_Pnt2d startPos2d(gp_Vec(plane.Location(), startPos).Dot(plane.XDirection()), gp_Vec(plane.Location(), startPos).Dot(plane.YDirection())); + gp_Pnt2d mousePos2d(gp_Vec(plane.Location(), mousePos).Dot(plane.XDirection()), gp_Vec(plane.Location(), mousePos).Dot(plane.YDirection())); double current_w = qAbs(mousePos2d.X() - startPos2d.X()); double current_h = qAbs(mousePos2d.Y() - startPos2d.Y()); @@ -160,7 +161,7 @@ void RectangleTool::finalizeCreation() int signY = (mousePos2d.Y() >= startPos2d.Y()) ? 1 : -1; gp_Pnt2d endPos2d(startPos2d.X() + signX * rect_w, startPos2d.Y() + signY * rect_h); - gp_Pnt endPos3d = ElCLib::To3d(endPos2d, plane); + gp_Pnt endPos3d = ElCLib::To3d(plane, endPos2d); worldPosQ = QVector3D(endPos3d.X(), endPos3d.Y(), endPos3d.Z()); } else { worldPosQ = m_viewport->unproject(m_viewport->currentMousePos(), plane); @@ -205,8 +206,8 @@ void RectangleTool::paintGL() gp_Pnt mousePos(mousePosQ.x(), mousePosQ.y(), mousePosQ.z()); if (widthFromInput || heightFromInput) { - gp_Pnt2d startPos2d = ElCLib::To2d(startPos, plane); - gp_Pnt2d mousePos2d = ElCLib::To2d(mousePos, plane); + gp_Pnt2d startPos2d(gp_Vec(plane.Location(), startPos).Dot(plane.XDirection()), gp_Vec(plane.Location(), startPos).Dot(plane.YDirection())); + gp_Pnt2d mousePos2d(gp_Vec(plane.Location(), mousePos).Dot(plane.XDirection()), gp_Vec(plane.Location(), mousePos).Dot(plane.YDirection())); double current_w = qAbs(mousePos2d.X() - startPos2d.X()); double current_h = qAbs(mousePos2d.Y() - startPos2d.Y()); @@ -218,7 +219,7 @@ void RectangleTool::paintGL() int signY = (mousePos2d.Y() >= startPos2d.Y()) ? 1 : -1; gp_Pnt2d endPos2d(startPos2d.X() + signX * rect_w, startPos2d.Y() + signY * rect_h); - gp_Pnt endPos3d = ElCLib::To3d(endPos2d, plane); + gp_Pnt endPos3d = ElCLib::To3d(plane, endPos2d); worldPosQ = QVector3D(endPos3d.X(), endPos3d.Y(), endPos3d.Z()); } else { worldPosQ = mousePosQ; @@ -232,14 +233,14 @@ void RectangleTool::paintGL() gp_Pnt p1_3d = startPos; gp_Pnt p3_3d(worldPosQ.x(), worldPosQ.y(), worldPosQ.z()); - gp_Pnt2d p1_2d = ElCLib::To2d(p1_3d, plane); - gp_Pnt2d p3_2d = ElCLib::To2d(p3_3d, plane); + gp_Pnt2d p1_2d(gp_Vec(plane.Location(), p1_3d).Dot(plane.XDirection()), gp_Vec(plane.Location(), p1_3d).Dot(plane.YDirection())); + gp_Pnt2d p3_2d(gp_Vec(plane.Location(), p3_3d).Dot(plane.XDirection()), gp_Vec(plane.Location(), p3_3d).Dot(plane.YDirection())); 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); + gp_Pnt p2_3d = ElCLib::To3d(plane, p2_2d); + gp_Pnt p4_3d = ElCLib::To3d(plane, p4_2d); vertices << p1_3d.X() << p1_3d.Y() << p1_3d.Z(); vertices << p2_3d.X() << p2_3d.Y() << p2_3d.Z(); @@ -287,8 +288,8 @@ void RectangleTool::paint2D(QPainter& painter, const QMatrix4x4& modelView, cons gp_Pnt mousePos(mousePosQ.x(), mousePosQ.y(), mousePosQ.z()); if (widthFromInput || heightFromInput) { - gp_Pnt2d startPos2d = ElCLib::To2d(p1_3d, plane); - gp_Pnt2d mousePos2d = ElCLib::To2d(mousePos, plane); + gp_Pnt2d startPos2d(gp_Vec(plane.Location(), p1_3d).Dot(plane.XDirection()), gp_Vec(plane.Location(), p1_3d).Dot(plane.YDirection())); + gp_Pnt2d mousePos2d(gp_Vec(plane.Location(), mousePos).Dot(plane.XDirection()), gp_Vec(plane.Location(), mousePos).Dot(plane.YDirection())); double current_w = qAbs(mousePos2d.X() - startPos2d.X()); double current_h = qAbs(mousePos2d.Y() - startPos2d.Y()); @@ -299,7 +300,7 @@ void RectangleTool::paint2D(QPainter& painter, const QMatrix4x4& modelView, cons int signY = (mousePos2d.Y() >= startPos2d.Y()) ? 1 : -1; gp_Pnt2d endPos2d(startPos2d.X() + signX * rect_w, startPos2d.Y() + signY * rect_h); - gp_Pnt endPos3d = ElCLib::To3d(endPos2d, plane); + gp_Pnt endPos3d = ElCLib::To3d(plane, endPos2d); worldPosQ = QVector3D(endPos3d.X(), endPos3d.Y(), endPos3d.Z()); } else { worldPosQ = mousePosQ; @@ -313,10 +314,10 @@ void RectangleTool::paint2D(QPainter& painter, const QMatrix4x4& modelView, cons gp_Pnt p3_3d(worldPosQ.x(), worldPosQ.y(), worldPosQ.z()); gp_Pnt p2_3d, p4_3d; - gp_Pnt2d p1_2d = ElCLib::To2d(p1_3d, plane); - gp_Pnt2d p3_2d = ElCLib::To2d(p3_3d, plane); + gp_Pnt2d p1_2d(gp_Vec(plane.Location(), p1_3d).Dot(plane.XDirection()), gp_Vec(plane.Location(), p1_3d).Dot(plane.YDirection())); + gp_Pnt2d p3_2d(gp_Vec(plane.Location(), p3_3d).Dot(plane.XDirection()), gp_Vec(plane.Location(), p3_3d).Dot(plane.YDirection())); gp_Pnt2d p2_2d(p3_2d.X(), p1_2d.Y()); - p2_3d = ElCLib::To3d(p2_2d, plane); + p2_3d = ElCLib::To3d(plane, p2_2d); double w = qAbs(p3_2d.X() - p1_2d.X()); double h = qAbs(p3_2d.Y() - p1_2d.Y());