fix #29, you can`t move selected blocks in place which causes bus segment deletion
This commit is contained in:
@@ -304,6 +304,14 @@ void BlockBusItem::simplify(bool full) {
|
||||
}
|
||||
|
||||
|
||||
bool BlockBusItem::hasNullSegment() const {
|
||||
for (int s = 0; s < segments.size(); ++s) {
|
||||
if (pol[segments[s].first] == pol[segments[s].second]) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void BlockBusItem::adjustLine() {}
|
||||
|
||||
|
||||
|
||||
@@ -91,6 +91,7 @@ public:
|
||||
void markAsOutput();
|
||||
void unmark();
|
||||
void simplify(bool full = true);
|
||||
bool hasNullSegment() const;
|
||||
void adjustLine();
|
||||
int endpointCount() const;
|
||||
bool isBusSelected() const { return selSegment >= 0 || selPoint >= 0; }
|
||||
|
||||
@@ -464,9 +464,14 @@ bool BlockView::eventFilter(QObject * o, QEvent * e) {
|
||||
}
|
||||
if (!mm_mods.testFlag(Qt::ControlModifier) && !mm_mods.testFlag(Qt::ShiftModifier)) {
|
||||
if (!mdp.isNull()) moved = true;
|
||||
foreach(QGraphicsItem * i, sel_items)
|
||||
bool is_correct = true;
|
||||
if (!me->modifiers().testFlag(Qt::AltModifier)) is_correct = moveBuses(sel_items, mdp);
|
||||
if (is_correct) {
|
||||
for (auto * i: sel_items)
|
||||
if (i->flags().testFlag(QGraphicsItem::ItemIsMovable)) i->setPos(i->pos() + mdp);
|
||||
if (!me->modifiers().testFlag(Qt::AltModifier)) moveBuses(sel_items, mdp);
|
||||
} else {
|
||||
scene_point -= mdp;
|
||||
}
|
||||
setCursor(Qt::ClosedHandCursor);
|
||||
}
|
||||
return true;
|
||||
@@ -1487,28 +1492,42 @@ void BlockView::simplifyBuses() {
|
||||
}
|
||||
|
||||
|
||||
void BlockView::moveBuses(const QList<QGraphicsItem *> & items, QPointF dp) {
|
||||
if (dp.isNull()) return;
|
||||
bool BlockView::moveBuses(const QList<QGraphicsItem *> & items, QPointF dp) {
|
||||
if (dp.isNull()) return true;
|
||||
QList<QGraphicsItem *> gi = scene_->items();
|
||||
QVector<BlockItemPin *> pins;
|
||||
QList<BlockBusItem *> buses;
|
||||
QList<BlockBusItem *> buses_m_part, buses_m_all;
|
||||
QMap<BlockBusItem *, QPolygonF> saved_pols;
|
||||
// qDebug() << "move" << dp;
|
||||
foreach(QGraphicsItem * i, items)
|
||||
for (auto * i: items)
|
||||
if ((i->data(bvidType).toInt() == bvitBlock) && i->flags().testFlag(QGraphicsItem::ItemIsMovable))
|
||||
pins << qgraphicsitem_cast<BlockItem *>(i)->pins();
|
||||
foreach(QGraphicsItem * i, gi)
|
||||
if (i->data(bvidType).toInt() == bvitBus) buses << qgraphicsitem_cast<BlockBusItem *>(i);
|
||||
foreach(BlockBusItem * b, buses) {
|
||||
QList<BlockItemPin *> bpins = b->connections_.values();
|
||||
if (!bpins.isEmpty()) {
|
||||
foreach(BlockItemPin * p, pins)
|
||||
for (auto * i: gi) {
|
||||
if (i->data(bvidType).toInt() == bvitBus) {
|
||||
auto * b = qgraphicsitem_cast<BlockBusItem *>(i);
|
||||
QList<BlockItemPin *> bpins = b->connectedPins();
|
||||
if (bpins.isEmpty()) continue;
|
||||
bool affect = false;
|
||||
for (auto * i: pins) {
|
||||
if (bpins.contains(i)) {
|
||||
affect = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!affect) continue;
|
||||
for (auto * p: pins)
|
||||
bpins.removeAll(p);
|
||||
if (bpins.isEmpty()) {
|
||||
b->movePolyline(dp);
|
||||
continue;
|
||||
if (bpins.isEmpty())
|
||||
buses_m_all << b;
|
||||
else {
|
||||
buses_m_part << b;
|
||||
saved_pols[b] = b->pol;
|
||||
}
|
||||
}
|
||||
foreach(BlockItemPin * p, pins) {
|
||||
}
|
||||
bool incorrect_move = false;
|
||||
for (auto * b: buses_m_part) {
|
||||
for (auto * p: pins) {
|
||||
QList<int> ends = b->connections_.keys(p);
|
||||
for (int i = 0; i < ends.size(); ++i) {
|
||||
QPointF pdp = dp;
|
||||
@@ -1533,12 +1552,26 @@ void BlockView::moveBuses(const QList<QGraphicsItem *> & items, QPointF dp) {
|
||||
default: break;
|
||||
}
|
||||
QVector<int> epl = b->endpointLine(ends[i], ang);
|
||||
foreach(int e, epl)
|
||||
for (int e: epl)
|
||||
b->movePoint(e, pdp);
|
||||
b->movePoint(ends[i], dp);
|
||||
if (b->hasNullSegment()) {
|
||||
incorrect_move = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (incorrect_move) break;
|
||||
}
|
||||
if (incorrect_move) break;
|
||||
}
|
||||
if (incorrect_move) {
|
||||
for (auto * b: buses_m_part)
|
||||
b->pol = saved_pols.value(b);
|
||||
return false;
|
||||
}
|
||||
for (auto * b: buses_m_all)
|
||||
b->movePolyline(dp);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -158,7 +158,7 @@ protected:
|
||||
void hoverAcceptedPin(BlockItemPin * pin, bool hover);
|
||||
void unhoverPins(BlockItemPin * excl_pin = 0);
|
||||
void simplifyBuses();
|
||||
void moveBuses(const QList<QGraphicsItem *> & items, QPointF dp);
|
||||
bool moveBuses(const QList<QGraphicsItem *> & items, QPointF dp);
|
||||
QList<BlockBusItem *> internalBuses(const QList<BlockItem *> & items);
|
||||
QList<BlockItemPin *> nearPins(BlockItemPin * pin, Qt::KeyboardModifiers km);
|
||||
BlockItemPin * getPin(const QList<QGraphicsItem *> & list) const;
|
||||
|
||||
Reference in New Issue
Block a user