Готовая окружность
Пока без наложения базовых ограничений
This commit is contained in:
94
Canvas.cpp
94
Canvas.cpp
@@ -98,6 +98,16 @@ Curve* Canvas::findAt(QPointF& pos, qreal tolerance)
|
||||
return line;
|
||||
}
|
||||
}
|
||||
else if (Circle* circle = dynamic_cast<Circle*>(curve)) {
|
||||
QPointF center(*circle->center.x, *circle->center.y);
|
||||
double radius = *circle->rad;
|
||||
|
||||
double distToCenter = dist_P2P(center, pos);
|
||||
// Проверяем, лежит ли точка вблизи окружности (с допуском)
|
||||
if (std::abs(distToCenter - radius) <= tolerance) {
|
||||
return circle;
|
||||
}
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
@@ -240,7 +250,7 @@ void Canvas::mousePressEvent(QMouseEvent* event)
|
||||
|
||||
Line* found = dynamic_cast<Line*>(findAt(scene));
|
||||
if (found) {
|
||||
draggedLine = found;
|
||||
draggedCurve = found;
|
||||
QPointF lineCenter(
|
||||
(*found->p1.x + *found->p2.x) / 2.0,
|
||||
(*found->p1.y + *found->p2.y) / 2.0
|
||||
@@ -251,7 +261,9 @@ void Canvas::mousePressEvent(QMouseEvent* event)
|
||||
|
||||
Circle* found_circle = dynamic_cast<Circle*>(findAt(scene));
|
||||
if (found_circle) {
|
||||
// TODO
|
||||
draggedCurve = found_circle;
|
||||
QPointF center(*found_circle->center.x, *found_circle->center.y);
|
||||
dragOffset = scene - center;
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -401,6 +413,7 @@ void Canvas::mousePressEvent(QMouseEvent* event)
|
||||
mode = Mode::None;
|
||||
}
|
||||
solve_for_canvas();
|
||||
return;
|
||||
}
|
||||
// ====================== Режим Parallel: задание параллельности ======================
|
||||
else if (mode == Mode::Parallel) {
|
||||
@@ -581,45 +594,60 @@ void Canvas::mouseMoveEvent(QMouseEvent* event)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
solve_for_canvas();
|
||||
}
|
||||
|
||||
// ====================== Перемещение линии ======================
|
||||
else if (draggedLine) {
|
||||
QPointF newCenter = UCS_POSITION - dragOffset;
|
||||
QPointF oldCenter(
|
||||
(*draggedLine->p1.x + *draggedLine->p2.x) / 2.0,
|
||||
(*draggedLine->p1.y + *draggedLine->p2.y) / 2.0
|
||||
);
|
||||
else if (draggedCurve) {
|
||||
if (Line* draggedLine = dynamic_cast<Line*>(draggedCurve)) {
|
||||
QPointF newCenter = UCS_POSITION - dragOffset;
|
||||
QPointF oldCenter(
|
||||
(*draggedLine->p1.x + *draggedLine->p2.x) / 2.0,
|
||||
(*draggedLine->p1.y + *draggedLine->p2.y) / 2.0
|
||||
);
|
||||
|
||||
// Вычисляем смещение
|
||||
double dx = newCenter.x() - oldCenter.x();
|
||||
double dy = newCenter.y() - oldCenter.y();
|
||||
// Вычисляем смещение
|
||||
double dx = newCenter.x() - oldCenter.x();
|
||||
double dy = newCenter.y() - oldCenter.y();
|
||||
|
||||
// Перемещаем обе точки линии
|
||||
Point* linePoints[2] = { draggedLine->start_ref, draggedLine->end_ref };
|
||||
// Перемещаем обе точки линии
|
||||
Point* linePoints[2] = { draggedLine->start_ref, draggedLine->end_ref };
|
||||
|
||||
for (int i = 0; i < 2; i++) {
|
||||
Point* currentPoint = linePoints[i];
|
||||
for (int i = 0; i < 2; i++) {
|
||||
Point* currentPoint = linePoints[i];
|
||||
|
||||
*currentPoint->x += dx;
|
||||
*currentPoint->y += dy;
|
||||
*currentPoint->x += dx;
|
||||
*currentPoint->y += dy;
|
||||
|
||||
// Обновляем совпадающие точки
|
||||
for (Point* pair : points) {
|
||||
if (pair != currentPoint && areCoincident(currentPoint, pair)) {
|
||||
*pair->x = *currentPoint->x;
|
||||
*pair->y = *currentPoint->y;
|
||||
// Обновляем совпадающие точки
|
||||
for (Point* pair : points) {
|
||||
if (pair != currentPoint && areCoincident(currentPoint, pair)) {
|
||||
*pair->x = *currentPoint->x;
|
||||
*pair->y = *currentPoint->y;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (Circle* circle = dynamic_cast<Circle*>(draggedCurve)) {
|
||||
QPointF newCenter = UCS_POSITION - dragOffset;
|
||||
*circle->center.x = newCenter.x();
|
||||
*circle->center.y = newCenter.y();
|
||||
*circle->center_ref->x = newCenter.x();
|
||||
*circle->center_ref->y = newCenter.y();
|
||||
|
||||
// Также обновляем все совпадающие точки (если центр совпадает с другими точками через P2P)
|
||||
for (Point* other : points) {
|
||||
if (other != circle->center_ref && areCoincident(circle->center_ref, other)) {
|
||||
*other->x = newCenter.x();
|
||||
*other->y = newCenter.y();
|
||||
}
|
||||
}
|
||||
}
|
||||
solve_for_canvas();
|
||||
}
|
||||
#ifdef _DEBUG
|
||||
else
|
||||
showObjectTag(WIDGET_POSITION);
|
||||
#endif
|
||||
solve_for_canvas();
|
||||
}
|
||||
|
||||
void Canvas::mouseReleaseEvent(QMouseEvent* event)
|
||||
@@ -631,8 +659,8 @@ void Canvas::mouseReleaseEvent(QMouseEvent* event)
|
||||
solve_for_canvas();
|
||||
}
|
||||
|
||||
if (draggedLine) {
|
||||
draggedLine = nullptr;
|
||||
if (draggedCurve) {
|
||||
draggedCurve = nullptr;
|
||||
solve_for_canvas();
|
||||
}
|
||||
|
||||
@@ -681,16 +709,16 @@ void Canvas::paintEvent(QPaintEvent* event)
|
||||
p.drawEllipse(QPointF(*line->p2.x, *line->p2.y), 5, 5);
|
||||
}
|
||||
else if (Circle* circle = dynamic_cast<Circle*>(curve)) {
|
||||
p.setPen(QPen(Qt::black, 2));
|
||||
p.setBrush(Qt::NoBrush);
|
||||
|
||||
// Настройка пера для линии
|
||||
QPen linePen = QPen(Qt::black, 2);
|
||||
p.setPen(linePen);
|
||||
p.drawEllipse(QPointF(*circle->center.x, *circle->center.y),
|
||||
*circle->rad, *circle->rad);
|
||||
|
||||
p.drawEllipse(QPointF(*circle->center.x, *circle->center.y), *circle->rad, *circle->rad);
|
||||
QBrush pointBrush = QBrush(Qt::darkBlue);
|
||||
p.setBrush(pointBrush);
|
||||
p.setBrush(QBrush(Qt::darkBlue));
|
||||
p.setPen(Qt::NoPen);
|
||||
p.drawEllipse(QPointF(*circle->center.x, *circle->center.y), 5, 5);
|
||||
p.setBrush(Qt::NoBrush);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user