fix: Move line tool specific logic from ViewportWidget to LineTool
Co-authored-by: aider (gemini/gemini-2.5-pro) <aider@aider.chat>
This commit is contained in:
@@ -153,7 +153,39 @@ void LineTool::mousePressEvent(QMouseEvent *event)
|
||||
|
||||
void LineTool::mouseMoveEvent(QMouseEvent *event)
|
||||
{
|
||||
// To be implemented
|
||||
bool oldIsSnappingHorizontal = m_viewport->isSnappingHorizontal();
|
||||
bool oldIsSnappingVertical = m_viewport->isSnappingVertical();
|
||||
m_viewport->setSnappingHorizontal(false);
|
||||
m_viewport->setSnappingVertical(false);
|
||||
|
||||
if (m_isDefiningLine && !m_viewport->isSnappingOrigin() && !m_viewport->isSnappingVertex()) {
|
||||
QVector3D worldPos = m_viewport->unproject(m_viewport->currentMousePos(), m_viewport->currentPlane());
|
||||
QVector3D startPos(m_firstLinePoint.X(), m_firstLinePoint.Y(), m_firstLinePoint.Z());
|
||||
QVector3D delta = worldPos - startPos;
|
||||
|
||||
if (delta.length() > 1e-6) {
|
||||
const double snapAngleThreshold = qDegreesToRadians(2.0);
|
||||
double angle = 0;
|
||||
|
||||
if (m_viewport->currentPlane() == ViewportWidget::SketchPlane::XY) {
|
||||
angle = atan2(delta.z(), delta.x());
|
||||
} else if (m_viewport->currentPlane() == ViewportWidget::SketchPlane::XZ) {
|
||||
angle = atan2(delta.y(), delta.x());
|
||||
} else if (m_viewport->currentPlane() == ViewportWidget::SketchPlane::YZ) {
|
||||
angle = atan2(delta.z(), delta.y());
|
||||
}
|
||||
|
||||
if (qAbs(sin(angle)) < sin(snapAngleThreshold)) {
|
||||
m_viewport->setSnappingHorizontal(true);
|
||||
} else if (qAbs(cos(angle)) < sin(snapAngleThreshold)) {
|
||||
m_viewport->setSnappingVertical(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (oldIsSnappingHorizontal != m_viewport->isSnappingHorizontal() || oldIsSnappingVertical != m_viewport->isSnappingVertical()) {
|
||||
m_viewport->update();
|
||||
}
|
||||
}
|
||||
|
||||
void LineTool::keyPressEvent(QKeyEvent *event)
|
||||
|
||||
@@ -385,38 +385,8 @@ void ViewportWidget::mouseMoveEvent(QMouseEvent *event)
|
||||
update();
|
||||
}
|
||||
|
||||
bool oldIsSnappingHorizontal = m_isSnappingHorizontal;
|
||||
bool oldIsSnappingVertical = m_isSnappingVertical;
|
||||
m_isSnappingHorizontal = false;
|
||||
m_isSnappingVertical = false;
|
||||
|
||||
if (m_isDefiningLine && !m_isSnappingOrigin && !m_isSnappingVertex) {
|
||||
QVector3D worldPos = unproject(m_currentMousePos, m_currentPlane);
|
||||
QVector3D startPos(m_firstLinePoint.X(), m_firstLinePoint.Y(), m_firstLinePoint.Z());
|
||||
QVector3D delta = worldPos - startPos;
|
||||
|
||||
if (delta.length() > 1e-6) {
|
||||
const double snapAngleThreshold = qDegreesToRadians(2.0);
|
||||
double angle = 0;
|
||||
|
||||
if (m_currentPlane == SketchPlane::XY) {
|
||||
angle = atan2(delta.z(), delta.x());
|
||||
} else if (m_currentPlane == SketchPlane::XZ) {
|
||||
angle = atan2(delta.y(), delta.x());
|
||||
} else if (m_currentPlane == SketchPlane::YZ) {
|
||||
angle = atan2(delta.z(), delta.y());
|
||||
}
|
||||
|
||||
if (qAbs(sin(angle)) < sin(snapAngleThreshold)) {
|
||||
m_isSnappingHorizontal = true;
|
||||
} else if (qAbs(cos(angle)) < sin(snapAngleThreshold)) {
|
||||
m_isSnappingVertical = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (oldIsSnappingHorizontal != m_isSnappingHorizontal || oldIsSnappingVertical != m_isSnappingVertical) {
|
||||
update();
|
||||
if (m_activeSketchTool) {
|
||||
m_activeSketchTool->mouseMoveEvent(event);
|
||||
}
|
||||
|
||||
if (event->buttons() & Qt::MiddleButton) {
|
||||
@@ -465,6 +435,16 @@ void ViewportWidget::deactivateActiveTool()
|
||||
emit toolDeactivated();
|
||||
}
|
||||
|
||||
void ViewportWidget::setSnappingHorizontal(bool snapping)
|
||||
{
|
||||
m_isSnappingHorizontal = snapping;
|
||||
}
|
||||
|
||||
void ViewportWidget::setSnappingVertical(bool snapping)
|
||||
{
|
||||
m_isSnappingVertical = snapping;
|
||||
}
|
||||
|
||||
bool ViewportWidget::focusNextPrevChild(bool next)
|
||||
{
|
||||
if (m_activeTool != static_cast<int>(ApplicationController::ToolType::None)) {
|
||||
@@ -650,7 +630,6 @@ void ViewportWidget::onActiveToolChanged(int tool)
|
||||
}
|
||||
|
||||
m_activeTool = tool;
|
||||
m_isDefiningLine = false;
|
||||
|
||||
if (m_sketchTools.contains(tool)) {
|
||||
m_activeSketchTool = m_sketchTools.value(tool);
|
||||
|
||||
@@ -52,6 +52,8 @@ public:
|
||||
const gp_Pnt& snapVertex() const { return m_snapVertex; }
|
||||
bool isSnappingHorizontal() const { return m_isSnappingHorizontal; }
|
||||
bool isSnappingVertical() const { return m_isSnappingVertical; }
|
||||
void setSnappingHorizontal(bool snapping);
|
||||
void setSnappingVertical(bool snapping);
|
||||
|
||||
void addLine(const gp_Pnt& start, const gp_Pnt& end);
|
||||
void deactivateActiveTool();
|
||||
|
||||
Reference in New Issue
Block a user