Files
unnamed-cad-software/src/ViewportWidget.h
Tanner Collin af121ce6eb refactor: Extract camera logic to Camera class
Co-authored-by: aider (gemini/gemini-2.5-pro) <aider@aider.chat>
2026-02-15 12:03:41 -07:00

94 lines
2.5 KiB
C++

#ifndef VIEWPORTWIDGET_H
#define VIEWPORTWIDGET_H
#include <QOpenGLWidget>
#include <QOpenGLFunctions>
#include <QMatrix4x4>
#include <QPoint>
#include <QVector3D>
#include <QRect>
#include <gp_Pnt.hxx>
#include <QMap>
class QSvgRenderer;
class ViewCube;
class SketchGrid;
class Document;
class FeatureBrowser;
class SketchFeature;
class Camera;
class ViewportWidget : public QOpenGLWidget, protected QOpenGLFunctions
{
Q_OBJECT
public:
enum class SketchPlane {
NONE,
XY,
XZ,
YZ
};
explicit ViewportWidget(QWidget *parent = nullptr);
~ViewportWidget();
void setDocument(Document* document);
public slots:
void onSketchModeStarted(SketchPlane plane);
void onSketchModeEnded();
void onPlaneSelectionModeStarted();
void onActiveToolChanged(int tool);
signals:
void lineAdded(const gp_Pnt& start, const gp_Pnt& end);
void planeSelected(SketchPlane plane);
protected:
void initializeGL() override;
void paintGL() override;
void resizeGL(int w, int h) override;
void mousePressEvent(QMouseEvent *event) override;
void mouseMoveEvent(QMouseEvent *event) override;
void wheelEvent(QWheelEvent *event) override;
void keyPressEvent(QKeyEvent *event) override;
private:
QVector3D project(const QVector3D& worldCoord, const QMatrix4x4& modelView, const QMatrix4x4& projection, const QRect& viewport);
QVector3D unproject(const QPoint& screenPos, SketchPlane plane);
void drawAxisLabels(QPainter& painter, const QMatrix4x4& modelView, const QMatrix4x4& projection);
void drawSketch(const SketchFeature* sketch);
void drawSelectionPlanes();
ViewportWidget::SketchPlane checkPlaneSelection(const QPoint& screenPos);
QMatrix4x4 projection;
Camera* m_camera = nullptr;
ViewCube* m_viewCube;
SketchGrid* m_sketchGrid = nullptr;
FeatureBrowser* m_featureBrowser = nullptr;
Document* m_document = nullptr;
SketchPlane m_currentPlane = SketchPlane::NONE;
bool m_isSelectingPlane = false;
SketchPlane m_highlightedPlane = SketchPlane::NONE;
int m_activeTool = 0;
bool m_isDefiningLine = false;
gp_Pnt m_firstLinePoint;
QPoint m_currentMousePos;
bool m_isSnappingOrigin = false;
bool m_isSnappingVertex = false;
gp_Pnt m_snapVertex;
bool m_isSnappingHorizontal = false;
bool m_isSnappingVertical = false;
QMap<int, QSvgRenderer*> m_toolIcons;
QSvgRenderer* m_cursorRenderer = nullptr;
QPoint lastPos;
};
#endif // VIEWPORTWIDGET_H