Важный фикс
Наконец-то можно двигать нормально вершины без риска блокировки
This commit is contained in:
64
Canvas.cpp
64
Canvas.cpp
@@ -2,6 +2,8 @@
|
||||
#define WIDGET_POSITION event->pos()
|
||||
#define UCS_POSITION screenToLogical(WIDGET_POSITION)
|
||||
|
||||
std::set<Point*> groups;
|
||||
|
||||
// ===================================================================
|
||||
// Вспомогательные функции
|
||||
// ===================================================================
|
||||
@@ -185,6 +187,7 @@ void Canvas::mousePressEvent(QMouseEvent* event)
|
||||
Point* p = findPointAt(scene);
|
||||
if (p) {
|
||||
draggedPoint = p;
|
||||
getCoincidentGroup(draggedPoint);
|
||||
dragOffset = scene - QPointF(*p->x, *p->y);
|
||||
return;
|
||||
}
|
||||
@@ -480,25 +483,12 @@ void Canvas::mouseMoveEvent(QMouseEvent* event)
|
||||
// ====================== Перемещение точки ======================
|
||||
if (draggedPoint) {
|
||||
QPointF pos = UCS_POSITION - dragOffset;
|
||||
|
||||
*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) {
|
||||
for (Point* pt : groups) {
|
||||
*pt->x = pos.x();
|
||||
*pt->y = pos.y();
|
||||
}
|
||||
|
||||
for (Point* basePt : coincidentGroup) {
|
||||
for (Point* basePt : groups) {
|
||||
for (Point* other : points) {
|
||||
if (areHorizontalVertical(basePt, other, true)) {
|
||||
*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();
|
||||
}
|
||||
|
||||
@@ -571,6 +552,8 @@ void Canvas::mouseReleaseEvent(QMouseEvent* event)
|
||||
draggedLine = nullptr;
|
||||
solve_for_canvas();
|
||||
}
|
||||
|
||||
groups.clear();
|
||||
}
|
||||
|
||||
// ===================================================================
|
||||
@@ -683,19 +666,17 @@ void Canvas::keyPressEvent(QKeyEvent* event)
|
||||
mode = Mode::None;
|
||||
current_line = nullptr;
|
||||
firstPoint = nullptr;
|
||||
groups.clear();
|
||||
update();
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case Qt::Key_Z: {
|
||||
if (event->modifiers() & Qt::ControlModifier) {
|
||||
// Ctrl+Z - отмена последнего ограничения
|
||||
if (constraints_count > 0) {
|
||||
remove_constraint(constraints_count - 1);
|
||||
constraints_count--;
|
||||
solve_for_canvas();
|
||||
}
|
||||
if (constraints_count > 0) {
|
||||
remove_constraint(constraints_count - 1);
|
||||
constraints_count--;
|
||||
solve_for_canvas();
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -741,17 +722,23 @@ QPointF Canvas::screenToLogical(const QPointF& screenPos) const
|
||||
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) {
|
||||
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()
|
||||
@@ -775,6 +762,7 @@ void Canvas::solve_for_canvas()
|
||||
if (flag) {
|
||||
QMessageBox::warning(this, QString("Error!"), QString("Last constraint is unavailable!"));
|
||||
remove_constraint(constraints_count - 1);
|
||||
C_Info.erase(constraints_count - 1);
|
||||
constraints_count--;
|
||||
}
|
||||
after_constraint = false;
|
||||
@@ -841,4 +829,6 @@ void Canvas::clearCanvas()
|
||||
|
||||
// Обновление отображения
|
||||
update();
|
||||
|
||||
groups.clear();
|
||||
}
|
||||
Reference in New Issue
Block a user