Horizontal and vertical points
Теперь можно обе точки при ограничении дёргать
This commit is contained in:
35
Canvas.cpp
35
Canvas.cpp
@@ -7,7 +7,7 @@ static double dist_P2P(QPointF p1, QPointF p2) {
|
|||||||
template <typename T, typename A, typename B>
|
template <typename T, typename A, typename B>
|
||||||
T makeOrderedPair(A* obj1, B* obj2)
|
T makeOrderedPair(A* obj1, B* obj2)
|
||||||
{
|
{
|
||||||
return (obj1->get_tag() < obj2->get_tag()) ? std::make_pair(obj1, obj2) : std::make_pair(obj2, obj1);
|
return (obj1 < obj2) ? std::make_pair(obj1, obj2) : std::make_pair(obj2, obj1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Canvas::changeMode(Mode _mode)
|
void Canvas::changeMode(Mode _mode)
|
||||||
@@ -46,9 +46,18 @@ bool Canvas::areCoincident(Point* p1, Point* p2)
|
|||||||
return P2Ppairs.count(makeOrderedPair<PointPair>(p1, p2));
|
return P2Ppairs.count(makeOrderedPair<PointPair>(p1, p2));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// False - Horizonta, True - Vertical
|
||||||
|
bool Canvas::areHorizontalVertical(Point* p1, Point* p2, bool mode)
|
||||||
|
{
|
||||||
|
if (!mode)
|
||||||
|
return HORIZ_pairs.count(makeOrderedPair<PointPair>(p1, p2));
|
||||||
|
else
|
||||||
|
return VERT_pairs.count(makeOrderedPair<PointPair>(p1, p2));
|
||||||
|
}
|
||||||
|
|
||||||
bool Canvas::areAlreadyParallel(Line* l1, Line* l2)
|
bool Canvas::areAlreadyParallel(Line* l1, Line* l2)
|
||||||
{
|
{
|
||||||
return parallelPairs.count(makeOrderedPair<LinePair>(l1, l2)) > 0;
|
return parallelPairs.count(makeOrderedPair<LinePair>(l1, l2));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Canvas::mousePressEvent(QMouseEvent* event)
|
void Canvas::mousePressEvent(QMouseEvent* event)
|
||||||
@@ -71,10 +80,14 @@ void Canvas::mousePressEvent(QMouseEvent* event)
|
|||||||
Line* found = findAt(scene);
|
Line* found = findAt(scene);
|
||||||
|
|
||||||
if (found) {
|
if (found) {
|
||||||
if (mode == Mode::Horizontal)
|
if (mode == Mode::Horizontal) {
|
||||||
sys.addConstraintHorizontal(*found, constraints_count++);
|
sys.addConstraintHorizontal(*found, constraints_count++);
|
||||||
else
|
HORIZ_pairs.insert(makeOrderedPair<PointPair>(found->start_ref, found->end_ref));
|
||||||
|
}
|
||||||
|
else {
|
||||||
sys.addConstraintVertical(*found, constraints_count++);
|
sys.addConstraintVertical(*found, constraints_count++);
|
||||||
|
VERT_pairs.insert(makeOrderedPair<PointPair>(found->start_ref, found->end_ref));
|
||||||
|
}
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
mode = Mode::None;
|
mode = Mode::None;
|
||||||
@@ -244,6 +257,12 @@ void Canvas::mouseMoveEvent(QMouseEvent* event)
|
|||||||
*pair->x = pos.x();
|
*pair->x = pos.x();
|
||||||
*pair->y = pos.y();
|
*pair->y = pos.y();
|
||||||
}
|
}
|
||||||
|
if (areHorizontalVertical(draggedPoint, pair, true)) {
|
||||||
|
*pair->x = pos.x();
|
||||||
|
}
|
||||||
|
if (areHorizontalVertical(draggedPoint, pair, false)) {
|
||||||
|
*pair->y = pos.y();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
*draggedPoint->x = pos.x();
|
*draggedPoint->x = pos.x();
|
||||||
*draggedPoint->y = pos.y();
|
*draggedPoint->y = pos.y();
|
||||||
@@ -311,18 +330,10 @@ void Canvas::paintEvent(QPaintEvent*)
|
|||||||
|
|
||||||
// === Текущая рисуемая линия (DrawingLine) ===
|
// === Текущая рисуемая линия (DrawingLine) ===
|
||||||
if (current_line && mode == Mode::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.setBrush(Qt::blue);
|
||||||
p.setPen(Qt::NoPen);
|
p.setPen(Qt::NoPen);
|
||||||
p.drawEllipse(QPointF(*current_line->p1.x, *current_line->p1.y), 6, 6);
|
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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
3
Canvas.h
3
Canvas.h
@@ -53,6 +53,7 @@ private:
|
|||||||
Line* findAt(QPointF&); // ищет линию под курсором
|
Line* findAt(QPointF&); // ищет линию под курсором
|
||||||
Point* findPointAt(QPointF, qreal tolerance = 5.0);
|
Point* findPointAt(QPointF, qreal tolerance = 5.0);
|
||||||
bool areCoincident(Point*, Point*);
|
bool areCoincident(Point*, Point*);
|
||||||
|
bool areHorizontalVertical(Point*, Point*, bool);
|
||||||
// ====================== Параллельность ======================
|
// ====================== Параллельность ======================
|
||||||
bool areAlreadyParallel(Line* l1, Line* l2); // проверка на дубликат
|
bool areAlreadyParallel(Line* l1, Line* l2); // проверка на дубликат
|
||||||
|
|
||||||
@@ -68,6 +69,8 @@ private:
|
|||||||
|
|
||||||
std::set<LinePair> parallelPairs; // уже запараллеленные пары (защита от дублей)
|
std::set<LinePair> parallelPairs; // уже запараллеленные пары (защита от дублей)
|
||||||
std::set<PointPair> P2Ppairs;
|
std::set<PointPair> P2Ppairs;
|
||||||
|
std::set<PointPair> HORIZ_pairs;
|
||||||
|
std::set<PointPair> VERT_pairs;
|
||||||
|
|
||||||
Line* current_line{ nullptr };
|
Line* current_line{ nullptr };
|
||||||
Point* firstPoint{ nullptr };
|
Point* firstPoint{ nullptr };
|
||||||
|
|||||||
Reference in New Issue
Block a user