Важный фикс

Наконец-то можно двигать нормально вершины без риска блокировки
This commit is contained in:
2025-12-22 20:31:16 +03:00
parent 8a8e932626
commit eed4a3088d
2 changed files with 28 additions and 38 deletions

View File

@@ -2,6 +2,8 @@
#define WIDGET_POSITION event->pos() #define WIDGET_POSITION event->pos()
#define UCS_POSITION screenToLogical(WIDGET_POSITION) #define UCS_POSITION screenToLogical(WIDGET_POSITION)
std::set<Point*> groups;
// =================================================================== // ===================================================================
// Вспомогательные функции // Вспомогательные функции
// =================================================================== // ===================================================================
@@ -185,6 +187,7 @@ void Canvas::mousePressEvent(QMouseEvent* event)
Point* p = findPointAt(scene); Point* p = findPointAt(scene);
if (p) { if (p) {
draggedPoint = p; draggedPoint = p;
getCoincidentGroup(draggedPoint);
dragOffset = scene - QPointF(*p->x, *p->y); dragOffset = scene - QPointF(*p->x, *p->y);
return; return;
} }
@@ -480,25 +483,12 @@ void Canvas::mouseMoveEvent(QMouseEvent* event)
// ====================== Перемещение точки ====================== // ====================== Перемещение точки ======================
if (draggedPoint) { if (draggedPoint) {
QPointF pos = UCS_POSITION - dragOffset; QPointF pos = UCS_POSITION - dragOffset;
for (Point* pt : groups) {
*draggedPoint->x = pos.x();
*draggedPoint->y = pos.y();
// TODO
for (Point* pair : points) {
if (areCoincident(draggedPoint, pair)) {
*pair->x = pos.x();
*pair->y = pos.y();
}
}
auto coincidentGroup = getCoincidentGroup(draggedPoint);
for (Point* pt : coincidentGroup) {
*pt->x = pos.x(); *pt->x = pos.x();
*pt->y = pos.y(); *pt->y = pos.y();
} }
for (Point* basePt : coincidentGroup) { for (Point* basePt : groups) {
for (Point* other : points) { for (Point* other : points) {
if (areHorizontalVertical(basePt, other, true)) { if (areHorizontalVertical(basePt, other, true)) {
*other->x = pos.x(); *other->x = pos.x();
@@ -509,15 +499,6 @@ void Canvas::mouseMoveEvent(QMouseEvent* event)
} }
} }
for (Point* other : points) {
if (areHorizontalVertical(draggedPoint, other, true)) {
*other->x = pos.x();
}
if (areHorizontalVertical(draggedPoint, other, false)) {
*other->y = pos.y();
}
}
solve_for_canvas(); solve_for_canvas();
} }
@@ -571,6 +552,8 @@ void Canvas::mouseReleaseEvent(QMouseEvent* event)
draggedLine = nullptr; draggedLine = nullptr;
solve_for_canvas(); solve_for_canvas();
} }
groups.clear();
} }
// =================================================================== // ===================================================================
@@ -683,20 +666,18 @@ void Canvas::keyPressEvent(QKeyEvent* event)
mode = Mode::None; mode = Mode::None;
current_line = nullptr; current_line = nullptr;
firstPoint = nullptr; firstPoint = nullptr;
groups.clear();
update(); update();
} }
break; break;
} }
case Qt::Key_Z: { case Qt::Key_Z: {
if (event->modifiers() & Qt::ControlModifier) {
// Ctrl+Z - отмена последнего ограничения
if (constraints_count > 0) { if (constraints_count > 0) {
remove_constraint(constraints_count - 1); remove_constraint(constraints_count - 1);
constraints_count--; constraints_count--;
solve_for_canvas(); solve_for_canvas();
} }
}
break; break;
} }
@@ -741,17 +722,23 @@ QPointF Canvas::screenToLogical(const QPointF& screenPos) const
return logical; return logical;
} }
std::vector<Point*> Canvas::getCoincidentGroup(Point* p) void Canvas::getCoincidentGroup(Point* p)
{ {
std::vector<Point*> group;
group.push_back(p);
for (Point* other : points) { for (Point* other : points) {
if (other != p && areCoincident(p, other)) { if (other != p && areCoincident(p, other)) {
group.push_back(other); groups.insert(other);
break;
} }
} }
return group;
for (size_t i = 0; i < points.size(); ++i) {
for (size_t j = i + 1; j < points.size(); j++) {
if (*points[i] == *points[j] && groups.contains(points[j])) {
groups.insert(points[i]);
}
}
}
groups.insert(p);
} }
void Canvas::solve_for_canvas() void Canvas::solve_for_canvas()
@@ -775,6 +762,7 @@ void Canvas::solve_for_canvas()
if (flag) { if (flag) {
QMessageBox::warning(this, QString("Error!"), QString("Last constraint is unavailable!")); QMessageBox::warning(this, QString("Error!"), QString("Last constraint is unavailable!"));
remove_constraint(constraints_count - 1); remove_constraint(constraints_count - 1);
C_Info.erase(constraints_count - 1);
constraints_count--; constraints_count--;
} }
after_constraint = false; after_constraint = false;
@@ -841,4 +829,6 @@ void Canvas::clearCanvas()
// Обновление отображения // Обновление отображения
update(); update();
groups.clear();
} }

View File

@@ -70,7 +70,7 @@ private:
#endif #endif
QPointF screenToLogical(const QPointF& screenPos) const; QPointF screenToLogical(const QPointF& screenPos) const;
std::vector<Point*> getCoincidentGroup(Point* p); void getCoincidentGroup(Point* p);
// ====================== Методы поиска и выбора ====================== // ====================== Методы поиска и выбора ======================
/// Найти линию под указанной позицией /// Найти линию под указанной позицией