diff --git a/Canvas.cpp b/Canvas.cpp index ae57dc5..0b12250 100644 --- a/Canvas.cpp +++ b/Canvas.cpp @@ -84,26 +84,29 @@ void Canvas::mousePressEvent(QMouseEvent* event) current_line = nullptr; mode = Mode::None; obj_count++; + } update(); return; } - } else if (mode == Mode::Parallel) { Line* found = findAt(scene); if (!found) { current_line = nullptr; + update(); return; } if (!current_line) { current_line = found; + update(); return; } if (found == current_line){ current_line = nullptr; + update(); return; } @@ -111,9 +114,9 @@ void Canvas::mousePressEvent(QMouseEvent* event) sys.addConstraintParallel(*found, *current_line, constraints_count++); parallelPairs.insert(makeOrderedPair(found, current_line)); current_line = nullptr; + update(); mode = Mode::None; } - else { #ifdef _DEBUG @@ -125,6 +128,7 @@ void Canvas::mousePressEvent(QMouseEvent* event) QMessageBox::Ok ); current_line = nullptr; + update(); return; } @@ -136,16 +140,19 @@ void Canvas::mousePressEvent(QMouseEvent* event) if (!clickedPoint) { firstPoint = nullptr; + update(); return; } if (!firstPoint) { firstPoint = clickedPoint; + update(); return; } if (clickedPoint == firstPoint) { firstPoint = nullptr; + update(); return; } @@ -158,6 +165,7 @@ void Canvas::mousePressEvent(QMouseEvent* event) if (l1 == l2) { QMessageBox::warning(this, QString("NO!"), QString("P2P failed")); firstPoint = nullptr; + update(); return; } @@ -172,23 +180,66 @@ void Canvas::mousePressEvent(QMouseEvent* event) void Canvas::paintEvent(QPaintEvent*) { QPainter p(this); - p.setRenderHint(QPainter::Antialiasing); + p.setRenderHint(QPainter::Antialiasing, true); + + // === Решаем систему один раз === if (!params.empty()) { int res = sys.solve(params); - if (res == SolveStatus::Success) { + if (res == SolveStatus::Success || res == SolveStatus::Converged) { sys.applySolution(); } else { - #ifdef _DEBUG - qDebug() << "INVAILD LAST CONSTRAINT. REMOVE HIM"; - #endif sys.removeConstraint(sys.get_last_constraint()); + constraints_count--; } } + for (Line* line : lines) { - line->draw(p); + bool isSelected = (mode == Mode::Parallel && line == current_line); + + QPen linePen = isSelected ? QPen(Qt::red, 4) : QPen(Qt::black, 2); + p.setPen(linePen); + + // Рисуем саму линию + p.drawLine(QPointF(*line->p1.x, *line->p1.y), + QPointF(*line->p2.x, *line->p2.y)); + + // Рисуем концы — с учётом выделения + QBrush pointBrush = isSelected ? QBrush(Qt::red) : QBrush(Qt::darkBlue); + p.setBrush(pointBrush); + p.setPen(Qt::NoPen); // убираем обводку у кружков + + p.drawEllipse(QPointF(*line->p1.x, *line->p1.y), 5, 5); + p.drawEllipse(QPointF(*line->p2.x, *line->p2.y), 5, 5); + } + + // === Подсветка выбранной точки в режиме Coincident === + if (mode == Mode::Coincedent && firstPoint) { + QPointF pt(*firstPoint->x, *firstPoint->y); + p.setPen(Qt::NoPen); + p.setBrush(Qt::red); + p.drawEllipse(pt, 12, 12); + p.setBrush(Qt::white); + p.drawEllipse(pt, 8, 8); + p.setBrush(Qt::red); + p.drawEllipse(pt, 4, 4); // маленький центр + } + + // === Текущая рисуемая линия (DrawingLine) === + if (current_line && mode == Mode::DrawingLine) { + QPen pen(Qt::blue, 3, Qt::DashLine); + p.setPen(pen); + p.setBrush(Qt::transparent); + + p.drawLine(QPointF(*current_line->p1.x, *current_line->p1.y), + QPointF(*current_line->p2.x, *current_line->p2.y)); + + // Концы текущей линии — синие точки + p.setBrush(Qt::blue); + p.setPen(Qt::NoPen); + p.drawEllipse(QPointF(*current_line->p1.x, *current_line->p1.y), 6, 6); + p.drawEllipse(QPointF(*current_line->p2.x, *current_line->p2.y), 6, 6); } - return; } Canvas::Canvas(QWidget *parent) diff --git a/GCS/GCS.h b/GCS/GCS.h index 5bb24ab..420bb91 100644 --- a/GCS/GCS.h +++ b/GCS/GCS.h @@ -250,6 +250,10 @@ public: void clearByTag(int tagId, bool is_fixed_point = false); int addConstraint(Constraint* constr); void removeConstraint(Constraint* constr); + + std::vector get_clist(){ + return clist; + } Constraint* get_last_constraint() { return clist[clist.size() - 1]; } diff --git a/GCS/Geo.cpp b/GCS/Geo.cpp index ff477ef..c3a7683 100644 --- a/GCS/Geo.cpp +++ b/GCS/Geo.cpp @@ -218,17 +218,6 @@ Line* Line::Copy() return crv; } -void Line::draw(QPainter& p, bool highlight){ - QPen pen = highlight ? QPen(Qt::red, 4) : QPen(Qt::black, 2); - p.setPen(pen); - p.drawLine(QPointF(p1.get_X(), p1.get_Y()), QPointF(p2.get_X(), p2.get_Y())); - - p.setBrush(highlight ? Qt::red : Qt::blue); - p.drawEllipse(QPointF(p1.get_X(), p1.get_Y()), 4, 4); - p.drawEllipse(QPointF(p2.get_X(), p2.get_Y()), 4, 4); -} - - //---------------circle DeriVector2 Circle::CalculateNormal(const Point& p, const double* derivparam) const diff --git a/GCS/Geo.h b/GCS/Geo.h index 1a7ec0d..e49c1fb 100644 --- a/GCS/Geo.h +++ b/GCS/Geo.h @@ -226,7 +226,6 @@ public: void ReconstructOnNewPvec(VEC_pD& pvec, int& cnt) override; Line* Copy() override; - void draw(QPainter& p, bool highlight = false); void set_tag(int); bool contains(QPointF, qreal tol = 10.0) const; };