refactor: Introduce SketchTool base class and derived tool skeletons
Co-authored-by: aider (gemini/gemini-2.5-pro) <aider@aider.chat>
This commit is contained in:
51
src/LineTool.cpp
Normal file
51
src/LineTool.cpp
Normal file
@@ -0,0 +1,51 @@
|
||||
#include "LineTool.h"
|
||||
#include "ViewportWidget.h"
|
||||
#include <QMouseEvent>
|
||||
#include <QKeyEvent>
|
||||
#include <QPainter>
|
||||
|
||||
LineTool::LineTool(ViewportWidget* viewport)
|
||||
: SketchTool(viewport)
|
||||
{
|
||||
}
|
||||
|
||||
void LineTool::activate()
|
||||
{
|
||||
m_isDefiningLine = false;
|
||||
m_viewport->setProperty("dimensionInput", "");
|
||||
m_viewport->setProperty("angleInput", "");
|
||||
m_viewport->setProperty("dimensionEditMode", "length");
|
||||
m_viewport->setProperty("isChainedLine", false);
|
||||
}
|
||||
|
||||
void LineTool::deactivate()
|
||||
{
|
||||
m_isDefiningLine = false;
|
||||
m_viewport->setProperty("dimensionInput", "");
|
||||
m_viewport->setProperty("angleInput", "");
|
||||
}
|
||||
|
||||
void LineTool::mousePressEvent(QMouseEvent *event)
|
||||
{
|
||||
// To be implemented
|
||||
}
|
||||
|
||||
void LineTool::mouseMoveEvent(QMouseEvent *event)
|
||||
{
|
||||
// To be implemented
|
||||
}
|
||||
|
||||
void LineTool::keyPressEvent(QKeyEvent *event)
|
||||
{
|
||||
// To be implemented
|
||||
}
|
||||
|
||||
void LineTool::paintGL()
|
||||
{
|
||||
// To be implemented
|
||||
}
|
||||
|
||||
void LineTool::paint2D(QPainter& painter, const QMatrix4x4& modelView, const QMatrix4x4& projection)
|
||||
{
|
||||
// To be implemented
|
||||
}
|
||||
28
src/LineTool.h
Normal file
28
src/LineTool.h
Normal file
@@ -0,0 +1,28 @@
|
||||
#ifndef LINETOOL_H
|
||||
#define LINETOOL_H
|
||||
|
||||
#include "SketchTool.h"
|
||||
#include <gp_Pnt.hxx>
|
||||
|
||||
class LineTool : public SketchTool
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit LineTool(ViewportWidget* viewport);
|
||||
|
||||
void mousePressEvent(QMouseEvent *event) override;
|
||||
void mouseMoveEvent(QMouseEvent *event) override;
|
||||
void keyPressEvent(QKeyEvent *event) override;
|
||||
|
||||
void paintGL() override;
|
||||
void paint2D(QPainter& painter, const QMatrix4x4& modelView, const QMatrix4x4& projection) override;
|
||||
|
||||
void activate() override;
|
||||
void deactivate() override;
|
||||
|
||||
private:
|
||||
bool m_isDefiningLine = false;
|
||||
gp_Pnt m_firstLinePoint;
|
||||
};
|
||||
|
||||
#endif // LINETOOL_H
|
||||
50
src/RectangleTool.cpp
Normal file
50
src/RectangleTool.cpp
Normal file
@@ -0,0 +1,50 @@
|
||||
#include "RectangleTool.h"
|
||||
#include "ViewportWidget.h"
|
||||
#include <QMouseEvent>
|
||||
#include <QKeyEvent>
|
||||
#include <QPainter>
|
||||
|
||||
RectangleTool::RectangleTool(ViewportWidget* viewport)
|
||||
: SketchTool(viewport)
|
||||
{
|
||||
}
|
||||
|
||||
void RectangleTool::activate()
|
||||
{
|
||||
m_isDefiningRectangle = false;
|
||||
m_viewport->setProperty("widthInput", "");
|
||||
m_viewport->setProperty("heightInput", "");
|
||||
m_viewport->setProperty("dimensionEditMode", "height");
|
||||
}
|
||||
|
||||
void RectangleTool::deactivate()
|
||||
{
|
||||
m_isDefiningRectangle = false;
|
||||
m_viewport->setProperty("widthInput", "");
|
||||
m_viewport->setProperty("heightInput", "");
|
||||
}
|
||||
|
||||
void RectangleTool::mousePressEvent(QMouseEvent *event)
|
||||
{
|
||||
// To be implemented
|
||||
}
|
||||
|
||||
void RectangleTool::mouseMoveEvent(QMouseEvent *event)
|
||||
{
|
||||
// To be implemented
|
||||
}
|
||||
|
||||
void RectangleTool::keyPressEvent(QKeyEvent *event)
|
||||
{
|
||||
// To be implemented
|
||||
}
|
||||
|
||||
void RectangleTool::paintGL()
|
||||
{
|
||||
// To be implemented
|
||||
}
|
||||
|
||||
void RectangleTool::paint2D(QPainter& painter, const QMatrix4x4& modelView, const QMatrix4x4& projection)
|
||||
{
|
||||
// To be implemented
|
||||
}
|
||||
28
src/RectangleTool.h
Normal file
28
src/RectangleTool.h
Normal file
@@ -0,0 +1,28 @@
|
||||
#ifndef RECTANGLETOOL_H
|
||||
#define RECTANGLETOOL_H
|
||||
|
||||
#include "SketchTool.h"
|
||||
#include <gp_Pnt.hxx>
|
||||
|
||||
class RectangleTool : public SketchTool
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit RectangleTool(ViewportWidget* viewport);
|
||||
|
||||
void mousePressEvent(QMouseEvent *event) override;
|
||||
void mouseMoveEvent(QMouseEvent *event) override;
|
||||
void keyPressEvent(QKeyEvent *event) override;
|
||||
|
||||
void paintGL() override;
|
||||
void paint2D(QPainter& painter, const QMatrix4x4& modelView, const QMatrix4x4& projection) override;
|
||||
|
||||
void activate() override;
|
||||
void deactivate() override;
|
||||
|
||||
private:
|
||||
bool m_isDefiningRectangle = false;
|
||||
gp_Pnt m_firstRectanglePoint;
|
||||
};
|
||||
|
||||
#endif // RECTANGLETOOL_H
|
||||
15
src/SketchTool.cpp
Normal file
15
src/SketchTool.cpp
Normal file
@@ -0,0 +1,15 @@
|
||||
#include "SketchTool.h"
|
||||
#include "ViewportWidget.h"
|
||||
|
||||
SketchTool::SketchTool(ViewportWidget* viewport)
|
||||
: QObject(viewport), m_viewport(viewport)
|
||||
{
|
||||
}
|
||||
|
||||
void SketchTool::activate()
|
||||
{
|
||||
}
|
||||
|
||||
void SketchTool::deactivate()
|
||||
{
|
||||
}
|
||||
34
src/SketchTool.h
Normal file
34
src/SketchTool.h
Normal file
@@ -0,0 +1,34 @@
|
||||
#ifndef SKETCHTOOL_H
|
||||
#define SKETCHTOOL_H
|
||||
|
||||
#include <QObject>
|
||||
|
||||
class QMouseEvent;
|
||||
class QKeyEvent;
|
||||
class ViewportWidget;
|
||||
class QOpenGLShaderProgram;
|
||||
class QPainter;
|
||||
class QMatrix4x4;
|
||||
|
||||
class SketchTool : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit SketchTool(ViewportWidget* viewport);
|
||||
virtual ~SketchTool() = default;
|
||||
|
||||
virtual void mousePressEvent(QMouseEvent *event) = 0;
|
||||
virtual void mouseMoveEvent(QMouseEvent *event) = 0;
|
||||
virtual void keyPressEvent(QKeyEvent *event) = 0;
|
||||
|
||||
virtual void paintGL() = 0;
|
||||
virtual void paint2D(QPainter& painter, const QMatrix4x4& modelView, const QMatrix4x4& projection) = 0;
|
||||
|
||||
virtual void activate();
|
||||
virtual void deactivate();
|
||||
|
||||
protected:
|
||||
ViewportWidget* m_viewport;
|
||||
};
|
||||
|
||||
#endif // SKETCHTOOL_H
|
||||
@@ -20,6 +20,7 @@ class Document;
|
||||
class FeatureBrowser;
|
||||
class SketchFeature;
|
||||
class Camera;
|
||||
class SketchTool;
|
||||
|
||||
class ViewportWidget : public QOpenGLWidget, protected QOpenGLFunctions
|
||||
{
|
||||
@@ -90,10 +91,8 @@ private:
|
||||
SketchPlane m_highlightedPlane = SketchPlane::NONE;
|
||||
|
||||
int m_activeTool = 0;
|
||||
bool m_isDefiningLine = false;
|
||||
gp_Pnt m_firstLinePoint;
|
||||
bool m_isDefiningRectangle = false;
|
||||
gp_Pnt m_firstRectanglePoint;
|
||||
SketchTool* m_activeSketchTool = nullptr;
|
||||
QMap<int, SketchTool*> m_sketchTools;
|
||||
QPoint m_currentMousePos;
|
||||
bool m_isSnappingOrigin = false;
|
||||
bool m_isSnappingVertex = false;
|
||||
|
||||
Reference in New Issue
Block a user