diff --git a/Canvas.cpp b/Canvas.cpp index 0d4a45e..6bdf74d 100644 --- a/Canvas.cpp +++ b/Canvas.cpp @@ -92,6 +92,14 @@ void Canvas::zoomReset() Line* Canvas::findAt(QPointF& pos, qreal tolerance) { + //for (Curve* curve : curves) { + // if (Line* line = dynamic_cast(curve)) { + // if (line->contains(pos, tolerance)) { + // return line; + // } + // } + //} + for (Line* line : lines) { if (line->contains(pos, tolerance)) { return line; @@ -103,6 +111,19 @@ Line* Canvas::findAt(QPointF& pos, qreal tolerance) Point* Canvas::findPointAt(QPointF pos, qreal tolerance) { Point* temp = nullptr; + + //for (Curve* curve : curves) { + // if (Line* line = dynamic_cast(curve)) { + // QPointF p1(*line->p1.x, *line->p1.y); + // QPointF p2(*line->p2.x, *line->p2.y); + + // if (dist_P2P(p1, pos) <= tolerance) + // temp = line->start_ref; + // if (dist_P2P(p2, pos) <= tolerance) + // temp = line->end_ref; + // } + //} + for (Line* line : lines) { QPointF p1(*line->p1.x, *line->p1.y); QPointF p2(*line->p2.x, *line->p2.y); @@ -350,6 +371,7 @@ void Canvas::mousePressEvent(QMouseEvent* event) current_line->set_tag(obj_count++); // Завершаем создание линии lines.append(current_line); + curves.append(current_line); current_line = nullptr; mode = Mode::None; after_constraint = true; @@ -437,6 +459,16 @@ void Canvas::mousePressEvent(QMouseEvent* event) // Находим линии, к которым принадлежат точки Line* l1 = nullptr; Line* l2 = nullptr; + + //for (Curve* curve : curves) { + // if (Line* l = dynamic_cast(curve)) { + // if (l->start_ref == firstPoint || l->end_ref == firstPoint) + // l1 = l; + // if (l->start_ref == clickedPoint || l->end_ref == clickedPoint) + // l2 = l; + // } + //} + for (Line* l : lines) { if (l->start_ref == firstPoint || l->end_ref == firstPoint) l1 = l; @@ -610,6 +642,12 @@ void Canvas::paintEvent(QPaintEvent* event) p.drawLine(0, -5, 0, 5); // ====================== Отрисовка линий ====================== + + // for (Curve* curve : curve){ + // if (Line* line = dynamic_cast(curve)) { + // ... + // } + // } for (Line* line : lines) { bool isSelected = (mode == Mode::Parallel && line == current_line); @@ -803,6 +841,11 @@ void Canvas::solve_for_canvas() } else { sys.applySolution(); + // for (Curve* curve : curve){ + // if (Line* line = dynamic_cast(curve)) { + // ... + // } + // } for (Line* line : lines) { if (abs(*line->p1.x - *line->p2.x) < EPS && abs(*line->p1.y - *line->p2.y) < EPS && after_constraint) { sys.undoSolution(); @@ -811,13 +854,15 @@ void Canvas::solve_for_canvas() } } } - - if (flag) { + if (flag && after_constraint) { QMessageBox::warning(this, QString("Error!"), QString("Last constraint is unavailable!")); remove_constraint(constraints_count - 1); C_Info.erase(constraints_count - 1); constraints_count--; } + else if (flag) { + sys.undoSolution(); + } after_constraint = false; update(); } @@ -840,6 +885,10 @@ void Canvas::clearCanvas() delete pt; } + // for (Curve* curve : curve){ + // delete curve; + // } + for (Line* line : lines) { delete line; } @@ -848,6 +897,7 @@ void Canvas::clearCanvas() params.clear(); points.clear(); lines.clear(); + // curves.clear(); // Очистка контейнеров ограничений parallelPairs.clear(); diff --git a/Canvas.h b/Canvas.h index 3649af8..4df0b52 100644 --- a/Canvas.h +++ b/Canvas.h @@ -34,7 +34,8 @@ enum class Mode : int Coincedent = 3, ///< Режим задания совпадения точек Horizontal = 4, ///< Режим задания горизонтальности Vertical = 5, ///< Режим задания вертикальности - Perpendicular = 6 ///< Режим задания перпендикулярности + Perpendicular = 6, ///< Режим задания перпендикулярности + DrawingCircle = 7 ///< Режим рисования окружности }; /// Удобный тип для хранения пары параллельных линий (порядок не важен) @@ -255,6 +256,8 @@ private: // ====================== Данные геометрической системы ====================== System sys; ///< Геометрический солвер QVector lines; ///< Завершённые линии + QVector circles; ///< Завершённые окружности + QVector curves; QVector points; ///< Все точки сцены std::vector params; ///< Все параметры, передаваемые в солвер