|
|
|
|
@@ -5,6 +5,7 @@
|
|
|
|
|
#include <QApplication>
|
|
|
|
|
#include <QAction>
|
|
|
|
|
#include <QShortcut>
|
|
|
|
|
#include <QVector2D>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
BlockView::BlockView(QWidget * parent): QGraphicsView(parent), tmp_bus(true) {
|
|
|
|
|
@@ -280,7 +281,7 @@ bool BlockView::eventFilter(QObject * o, QEvent * e) {
|
|
|
|
|
if (mm_ci) {
|
|
|
|
|
if (mm_ci->data(1004) == "pin" && m_connect) {
|
|
|
|
|
if (qgraphicsitem_cast<BlockItemPin*>(mm_ci)->state() == BlockItemPin::Hover) {
|
|
|
|
|
trace_from = mm_ci->mapToScene(QPointF());
|
|
|
|
|
trace_from = mm_ci->scenePos();
|
|
|
|
|
qgraphicsitem_cast<BlockItemPin*>(mm_ci)->clearStateStack();
|
|
|
|
|
tmp_bus.setBusType(qgraphicsitem_cast<BlockItemPin*>(mm_ci)->busType());
|
|
|
|
|
tmp_bus.setEndpointsNumber(3);
|
|
|
|
|
@@ -764,7 +765,7 @@ QList<BlockBusItem * > BlockView::wrongConnectedBuses() const {
|
|
|
|
|
QVector<BlockItemPin * > pins = b->pins();
|
|
|
|
|
foreach (BlockItemPin * p, pins)
|
|
|
|
|
if (p->state() == BlockItemPin::Reject) {
|
|
|
|
|
QPointF pp = p->mapToScene(QPointF());
|
|
|
|
|
QPointF pp = p->scenePos();
|
|
|
|
|
foreach (BlockBusItem * s, sl)
|
|
|
|
|
if (s->pol.contains(pp))
|
|
|
|
|
if (!ret.contains(s))
|
|
|
|
|
@@ -807,6 +808,71 @@ QList<BlockBusItem * > BlockView::connectionBuses(BlockItem * b0, BlockItem * b1
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool BlockView::connectPins(BlockItemPin * p0, BlockItemPin * p1) {
|
|
|
|
|
if (!p0 || !p1) return false;
|
|
|
|
|
if (p0->busType() != p1->busType()) return false;
|
|
|
|
|
QList<BlockBusItem * > bl0 = p0->connectedBuses(), bl1 = p1->connectedBuses();
|
|
|
|
|
if (!(bl0.toSet() & bl1.toSet()).isEmpty()) return true;
|
|
|
|
|
BlockBusItem * nb = new BlockBusItem();
|
|
|
|
|
nb->setBusType(p0->busType());
|
|
|
|
|
//nb->setEndpointsNumber(3);
|
|
|
|
|
loadBus(nb);
|
|
|
|
|
if (!bl0.isEmpty() && !bl1.isEmpty()) { // connect two existing buses
|
|
|
|
|
} else {
|
|
|
|
|
if ((bl0.isEmpty() && !bl1.isEmpty()) || (bl1.isEmpty() && !bl0.isEmpty())) { // connect empty pin to existing bus
|
|
|
|
|
BlockItemPin * ep = 0;
|
|
|
|
|
BlockBusItem * eb = 0;
|
|
|
|
|
if (bl0.isEmpty()) {ep = p0; eb = bl1[0];}
|
|
|
|
|
else {ep = p1; eb = bl0[0];}
|
|
|
|
|
double md = -1; int mi = -1;
|
|
|
|
|
QPointF sp = ep->scenePos();
|
|
|
|
|
if (eb->pol.size() == 2) {
|
|
|
|
|
eb->selSegment = 0;
|
|
|
|
|
eb->addPoint((eb->pol[0] + eb->pol[1]) / 2.);
|
|
|
|
|
eb->selPoint = -1;
|
|
|
|
|
mi = 2;
|
|
|
|
|
} else {
|
|
|
|
|
for (int i = 0; i < eb->pol.size(); ++i) {
|
|
|
|
|
if (eb->ends.contains(i)) continue;
|
|
|
|
|
double cd = QVector2D(sp - eb->pol[i]).lengthSquared();
|
|
|
|
|
if (md < 0 || md > cd) {
|
|
|
|
|
md = cd;
|
|
|
|
|
mi = i;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (mi < 0) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
trace(ep->scenePos(), eb->pol[mi], nb);
|
|
|
|
|
if (nb->pol.size() < 2) {
|
|
|
|
|
delete nb;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
nb->pol.pop_back();
|
|
|
|
|
int lp = eb->pol.size();
|
|
|
|
|
eb->pol << nb->pol;
|
|
|
|
|
for (int i = 0; i < nb->pol.size() - 1; ++i)
|
|
|
|
|
eb->segments << QPair<int, int>(lp + i, lp + i + 1);
|
|
|
|
|
eb->segments << QPair<int, int>(mi, lp + nb->pol.size() - 1);
|
|
|
|
|
eb->updateGeometry();
|
|
|
|
|
delete nb;
|
|
|
|
|
} else { // connect two empty pins
|
|
|
|
|
trace(p0->scenePos(), p1->scenePos(), nb);
|
|
|
|
|
if (nb->pol.isEmpty()) {
|
|
|
|
|
delete nb;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
addItem(nb);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
reconnectAll();
|
|
|
|
|
emit actionEvent(BlockItemBase::BusAdd, QList<QGraphicsItem*>() << nb);
|
|
|
|
|
emit connectionsChanged();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void BlockView::restoreSelState() {
|
|
|
|
|
foreach (QGraphicsItem * i, sel_items) {
|
|
|
|
|
i->setPos(i->data(1001).toPointF());
|
|
|
|
|
@@ -874,8 +940,8 @@ void BlockView::trace(QPointF scene_pos_from, QPointF scene_pos_to, BlockBusItem
|
|
|
|
|
wavetrace.fill(QRect(ir.topLeft() / grid_step + dp, ir.bottomRight() / grid_step + dp), BlockViewWavetrace::Blocked);
|
|
|
|
|
QVector<BlockItemPin * > pins = qgraphicsitem_cast<BlockItem * >(i)->pins();
|
|
|
|
|
foreach (BlockItemPin * p, pins) {
|
|
|
|
|
if (p->busType() == tmp_bus.busType())
|
|
|
|
|
wavetrace.fill(quantize(p->mapToScene(QPointF()), grid_step).toPoint() / grid_step + dp, BlockViewWavetrace::Empty);
|
|
|
|
|
if (p->busType() == bus->busType())
|
|
|
|
|
wavetrace.fill(quantize(p->scenePos(), grid_step).toPoint() / grid_step + dp, BlockViewWavetrace::Empty);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (m_trace_with_buses) {
|
|
|
|
|
@@ -963,7 +1029,7 @@ void BlockView::matchBus() {
|
|
|
|
|
if (m_pin_mc) {
|
|
|
|
|
foreach (BlockItem * b_, blockl)
|
|
|
|
|
foreach (BlockItemPin * p_, b_->pins())
|
|
|
|
|
if (p_->mapToScene(QPointF()) == point) {
|
|
|
|
|
if (p_->scenePos() == point) {
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
@@ -1257,7 +1323,7 @@ void BlockView::reconnectAll() {
|
|
|
|
|
QPointF cp = b->pol[conns[c]];
|
|
|
|
|
for (int j = 0; j < pins.size(); ++j) {
|
|
|
|
|
if (!pins[j]->isVisible()) continue;
|
|
|
|
|
QPointF pp = pins[j]->mapToScene(QPointF());
|
|
|
|
|
QPointF pp = pins[j]->scenePos();
|
|
|
|
|
if (cp == pp) {
|
|
|
|
|
//qDebug() << "found";
|
|
|
|
|
if (b->busType() == pins[j]->busType()) {
|
|
|
|
|
|