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:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user