refactor: Use gp_Ax2 for sketch plane definition and drawing
Co-authored-by: aider (gemini/gemini-2.5-pro) <aider@aider.chat>
This commit is contained in:
+30
-39
@@ -33,6 +33,8 @@
|
||||
#include <QApplication>
|
||||
#include <cmath>
|
||||
#include <QtMath>
|
||||
#include <ElCLib.hxx>
|
||||
#include <gp_Pnt2d.hxx>
|
||||
#include <QOpenGLShaderProgram>
|
||||
#include <QVector>
|
||||
#include <map>
|
||||
@@ -538,20 +540,11 @@ void ViewportWidget::drawSketch(const SketchFeature* sketch)
|
||||
|
||||
const int numSegments = 64;
|
||||
QVector3D u_axis, v_axis;
|
||||
switch (sketch->plane()) {
|
||||
case SketchFeature::SketchPlane::XY: // Top
|
||||
u_axis = QVector3D(1, 0, 0);
|
||||
v_axis = QVector3D(0, 1, 0);
|
||||
break;
|
||||
case SketchFeature::SketchPlane::XZ: // Front
|
||||
u_axis = QVector3D(1, 0, 0);
|
||||
v_axis = QVector3D(0, 0, 1);
|
||||
break;
|
||||
case SketchFeature::SketchPlane::YZ: // Right
|
||||
u_axis = QVector3D(0, 1, 0);
|
||||
v_axis = QVector3D(0, 0, 1);
|
||||
break;
|
||||
}
|
||||
const auto& plane = sketch->plane();
|
||||
const auto& xDir = plane.XDirection();
|
||||
const auto& yDir = plane.YDirection();
|
||||
u_axis = QVector3D(xDir.X(), xDir.Y(), xDir.Z());
|
||||
v_axis = QVector3D(yDir.X(), yDir.Y(), yDir.Z());
|
||||
|
||||
for (int i = 0; i < numSegments; ++i) {
|
||||
double angle1 = 2.0 * M_PI * double(i) / double(numSegments);
|
||||
@@ -565,34 +558,32 @@ void ViewportWidget::drawSketch(const SketchFeature* sketch)
|
||||
}
|
||||
} else if (obj->type() == SketchObject::ObjectType::Rectangle) {
|
||||
auto rect = static_cast<const SketchRectangle*>(obj);
|
||||
const auto& p1 = rect->corner1();
|
||||
const auto& p3 = rect->corner2();
|
||||
const auto& plane = sketch->plane();
|
||||
const auto& p1_3d = rect->corner1();
|
||||
const auto& p3_3d = rect->corner2();
|
||||
|
||||
gp_Pnt p2, p4;
|
||||
if (sketch->plane() == SketchFeature::SketchPlane::XY) {
|
||||
p2.SetCoord(p3.X(), p1.Y(), p1.Z());
|
||||
p4.SetCoord(p1.X(), p3.Y(), p1.Z());
|
||||
} else if (sketch->plane() == SketchFeature::SketchPlane::XZ) {
|
||||
p2.SetCoord(p3.X(), p1.Y(), p1.Z());
|
||||
p4.SetCoord(p1.X(), p1.Y(), p3.Z());
|
||||
} else if (sketch->plane() == SketchFeature::SketchPlane::YZ) {
|
||||
p2.SetCoord(p1.X(), p3.Y(), p1.Z());
|
||||
p4.SetCoord(p1.X(), p1.Y(), p3.Z());
|
||||
}
|
||||
gp_Pnt2d p1_2d = ElCLib::To2d(p1_3d, plane);
|
||||
gp_Pnt2d p3_2d = ElCLib::To2d(p3_3d, plane);
|
||||
|
||||
lineVertices << p1.X() << p1.Y() << p1.Z();
|
||||
lineVertices << p2.X() << p2.Y() << p2.Z();
|
||||
lineVertices << p2.X() << p2.Y() << p2.Z();
|
||||
lineVertices << p3.X() << p3.Y() << p3.Z();
|
||||
lineVertices << p3.X() << p3.Y() << p3.Z();
|
||||
lineVertices << p4.X() << p4.Y() << p4.Z();
|
||||
lineVertices << p4.X() << p4.Y() << p4.Z();
|
||||
lineVertices << p1.X() << p1.Y() << p1.Z();
|
||||
gp_Pnt2d p2_2d(p3_2d.X(), p1_2d.Y());
|
||||
gp_Pnt2d p4_2d(p1_2d.X(), p3_2d.Y());
|
||||
|
||||
vertexCounts[p1] += 2;
|
||||
vertexCounts[p2] += 2;
|
||||
vertexCounts[p3] += 2;
|
||||
vertexCounts[p4] += 2;
|
||||
gp_Pnt p2_3d = ElCLib::To3d(p2_2d, plane);
|
||||
gp_Pnt p4_3d = ElCLib::To3d(p4_2d, plane);
|
||||
|
||||
lineVertices << p1_3d.X() << p1_3d.Y() << p1_3d.Z();
|
||||
lineVertices << p2_3d.X() << p2_3d.Y() << p2_3d.Z();
|
||||
lineVertices << p2_3d.X() << p2_3d.Y() << p2_3d.Z();
|
||||
lineVertices << p3_3d.X() << p3_3d.Y() << p3_3d.Z();
|
||||
lineVertices << p3_3d.X() << p3_3d.Y() << p3_3d.Z();
|
||||
lineVertices << p4_3d.X() << p4_3d.Y() << p4_3d.Z();
|
||||
lineVertices << p4_3d.X() << p4_3d.Y() << p4_3d.Z();
|
||||
lineVertices << p1_3d.X() << p1_3d.Y() << p1_3d.Z();
|
||||
|
||||
vertexCounts[p1_3d] += 2;
|
||||
vertexCounts[p2_3d] += 2;
|
||||
vertexCounts[p3_3d] += 2;
|
||||
vertexCounts[p4_3d] += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user