feat: Add interactive sketch line drawing to viewport

Co-authored-by: aider (gemini/gemini-2.5-pro) <aider@aider.chat>
This commit is contained in:
2026-02-14 19:19:13 -07:00
parent a1cfbc2e3f
commit 8e1ab54cb5
4 changed files with 144 additions and 4 deletions

View File

@@ -7,11 +7,13 @@
#include <QPoint>
#include <QVector3D>
#include <QRect>
#include <gp_Pnt.hxx>
class ViewCube;
class SketchGrid;
class Document;
class FeatureBrowser;
class SketchFeature;
class ViewportWidget : public QOpenGLWidget, protected QOpenGLFunctions
{
@@ -39,6 +41,7 @@ public:
public slots:
void onSketchModeStarted(SketchPlane plane);
void onSketchModeEnded();
void onActiveToolChanged(int tool);
float xRotation() const;
void setXRotation(float angle);
@@ -55,6 +58,9 @@ public slots:
float panY() const;
void setPanY(float value);
signals:
void lineAdded(const gp_Pnt& start, const gp_Pnt& end);
protected:
void initializeGL() override;
void paintGL() override;
@@ -66,14 +72,22 @@ protected:
private:
QVector3D project(const QVector3D& worldCoord, const QMatrix4x4& modelView, const QMatrix4x4& projection, const QRect& viewport);
QVector3D unproject(const QPoint& screenPos);
void drawAxisLabels(QPainter& painter, const QMatrix4x4& modelView, const QMatrix4x4& projection);
void drawSketch(const SketchFeature* sketch);
QMatrix4x4 projection;
ViewCube* m_viewCube;
SketchGrid* m_sketchGrid = nullptr;
FeatureBrowser* m_featureBrowser = nullptr;
Document* m_document = nullptr;
SketchPlane m_currentPlane = SketchPlane::NONE;
int m_activeTool = 0;
bool m_isDefiningLine = false;
gp_Pnt m_firstLinePoint;
QPoint m_currentMousePos;
float m_xRot = 35.264f * 16.0f; // Default to isometric view
float m_yRot = -45.0f * 16.0f; // Default to isometric view
float m_zoom = -5.0f;