git-svn-id: svn://db.shs.com.ru/libs@173 a8b55f48-bf90-11e4-a774-851b48703e85
This commit is contained in:
@@ -86,11 +86,18 @@ int BlockBusItem::addPoint(const QPointF & point, bool update) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int BlockBusItem::segmentPointPair(int point) const {
|
int BlockBusItem::segmentPointPair(int point, int * seg) const {
|
||||||
for (int i = 0; i < segments.size(); ++i) {
|
for (int i = 0; i < segments.size(); ++i) {
|
||||||
if (segments[i].first == point) return segments[i].second;
|
if (segments[i].first == point) {
|
||||||
if (segments[i].second == point) return segments[i].first;
|
if (seg) *seg = i;
|
||||||
|
return segments[i].second;
|
||||||
|
}
|
||||||
|
if (segments[i].second == point) {
|
||||||
|
if (seg) *seg = i;
|
||||||
|
return segments[i].first;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
if (seg) *seg = -1;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -186,24 +193,51 @@ void BlockBusItem::unmark() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void BlockBusItem::simplify() {
|
void BlockBusItem::simplify(bool full) {
|
||||||
int pcnt = pol.size();
|
int pcnt = pol.size();
|
||||||
for (int i = 0; i < pol.size() - 1; ++i) {
|
for (int s = 0; s < segments.size(); ++s) {
|
||||||
if (pol[i] == pol[i + 1])
|
if (pol[segments[s].first] != pol[segments[s].second]) continue;
|
||||||
pol.remove(i--);
|
int ti = segments[s].first, fi = segments[s].second;
|
||||||
|
segments.removeAt(s);
|
||||||
|
pol.remove(fi);
|
||||||
|
for (int i = 0; i < segments.size(); ++i) {
|
||||||
|
if (segments[i].first == fi) segments[i].first = ti;
|
||||||
|
if (segments[i].second == fi) segments[i].second = ti;
|
||||||
|
if (segments[i].first > fi) segments[i].first--;
|
||||||
|
if (segments[i].second > fi) segments[i].second--;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (pol.size() < 3) return;
|
if (full) {
|
||||||
//PIMathVectorT2d cl, pl;
|
/*QList<int> segs;
|
||||||
for (int i = 0; i < pol.size() - 2; ++i) {
|
for (int p = 0; p < pol.size(); ++p) {
|
||||||
//pl = Q2PIVector2(pol[i]) - Q2PIVector2(pol[i + 1]);
|
if (pointSegmentsCount(p, &segs) != 2) continue;
|
||||||
//cl = Q2PIVector2(pol[i + 1]) - Q2PIVector2(pol[i + 2]);
|
QPointF cp = pol[p], sp[2];
|
||||||
//if (pl.turnTo<3, double>() || cl.turnTo<3, double>())
|
for (int i = 0; i < 2; ++i) {
|
||||||
// pol.remove(i-- + 1);
|
if (segments[segs[i]].first == p) sp[i] = pol[segments[segs[i]].second];
|
||||||
|
else sp[i] = pol[segments[segs[i]].first];
|
||||||
|
}
|
||||||
|
qDebug() << p << segs;
|
||||||
|
QLineF l0(sp[0], cp), l1(cp, sp[1]);
|
||||||
|
if (l0.angle() != l1.angle()) continue;
|
||||||
|
if (segments[segs[0]].first == p) {
|
||||||
|
if (segments[segs[1]].first == p) segments[segs[0]].second = segments[segs[1]].second;
|
||||||
|
else segments[segs[0]].second = segments[segs[1]].first;
|
||||||
|
} else {
|
||||||
|
if (segments[segs[1]].first == p) segments[segs[0]].first = segments[segs[1]].second;
|
||||||
|
else segments[segs[0]].first = segments[segs[1]].first;
|
||||||
|
}
|
||||||
|
segments.removeAt(segs[1]);
|
||||||
|
pol.remove(p);
|
||||||
|
for (int i = 0; i < segments.size(); ++i) {
|
||||||
|
if (segments[i].first > p) segments[i].first--;
|
||||||
|
if (segments[i].second > p) segments[i].second--;
|
||||||
|
}
|
||||||
|
p = -1;
|
||||||
|
}*/
|
||||||
}
|
}
|
||||||
if (pcnt == pol.size()) return;
|
if (pcnt == pol.size()) return;
|
||||||
//GBFrom->emitAddToHistory(History::ConnectionSimplify, "");
|
|
||||||
updateGeometry();
|
updateGeometry();
|
||||||
if (scene() != 0) scene()->update();
|
//if (scene()) scene()->update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -325,13 +359,51 @@ QVector<int> BlockBusItem::endpoints() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int BlockBusItem::pointSegments(int point) const {
|
QVector<int> BlockBusItem::endpointLine(int ep) const {
|
||||||
int ret = 0;
|
QVector<int> ret;
|
||||||
for (int i = 0; i < segments.size(); ++i)
|
int seg = -1;
|
||||||
if (segments[i].first == point ||
|
int np = segmentPointPair(ep, &seg), pp = np;
|
||||||
segments[i].second == point)
|
if (ep < 0 || np < 0) return ret;
|
||||||
ret++;
|
if (pol[np] == pol[ep]) return ret;
|
||||||
|
QPointF sp = pol[np] - pol[ep];
|
||||||
|
bool sdir = (qAbs(sp.x()) >= qAbs(sp.y()));
|
||||||
|
for (int i = 0; i < segments.size(); ++i) {
|
||||||
|
if (np < 0) break;
|
||||||
|
if (pointSegmentsCount(np) != 2) break;
|
||||||
|
if (i > 0) {
|
||||||
|
sp = pol[np] - pol[pp];
|
||||||
|
bool idir = (qAbs(sp.x()) >= qAbs(sp.y()));
|
||||||
|
if (sdir != idir) break;
|
||||||
|
}
|
||||||
|
ret << np;
|
||||||
|
pp = np;
|
||||||
|
np = neighborSegmentPoint(np, &seg);
|
||||||
|
}
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int BlockBusItem::pointSegmentsCount(int point, QList<int> * segs) const {
|
||||||
|
int ret = 0;
|
||||||
|
if (segs) segs->clear();
|
||||||
|
for (int i = 0; i < segments.size(); ++i)
|
||||||
|
if (segments[i].first == point || segments[i].second == point) {
|
||||||
|
ret++;
|
||||||
|
if (segs) segs->append(i);
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int BlockBusItem::neighborSegmentPoint(int point, int * seg) const {
|
||||||
|
if (point < 0 || !seg) return -1;
|
||||||
|
for (int i = 0; i < segments.size(); ++i) {
|
||||||
|
if (i == *seg) continue;
|
||||||
|
if (segments[i].first == point) {*seg = i; return segments[i].second;}
|
||||||
|
if (segments[i].second == point) {*seg = i; return segments[i].first ;}
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -443,7 +515,7 @@ void BlockBusItem::mousePressEvent(QGraphicsSceneMouseEvent * e) {
|
|||||||
}
|
}
|
||||||
if (max_ep >= 2) {
|
if (max_ep >= 2) {
|
||||||
if (endpointCount() >= max_ep)
|
if (endpointCount() >= max_ep)
|
||||||
if (pointSegments(selPoint) >= 2 || selSegment >= 0)
|
if (pointSegmentsCount(selPoint) >= 2 || selSegment >= 0)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
QMetaObject::invokeMethod(scene()->views().back(), "newBranch", Q_ARG(BlockBusItem * , this));
|
QMetaObject::invokeMethod(scene()->views().back(), "newBranch", Q_ARG(BlockBusItem * , this));
|
||||||
@@ -458,11 +530,13 @@ void BlockBusItem::mousePressEvent(QGraphicsSceneMouseEvent * e) {
|
|||||||
if (e->buttons().testFlag(Qt::RightButton)) {
|
if (e->buttons().testFlag(Qt::RightButton)) {
|
||||||
if (selPoint >= 0 && selPoint <= pol.size() - 1) {
|
if (selPoint >= 0 && selPoint <= pol.size() - 1) {
|
||||||
removePoint(selPoint);
|
removePoint(selPoint);
|
||||||
|
simplify();
|
||||||
emitAction(BlockItemBase::BusPointRemove);
|
emitAction(BlockItemBase::BusPointRemove);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (selSegment >= 0 && selSegment <= segments.size() - 1) {
|
if (selSegment >= 0 && selSegment <= segments.size() - 1) {
|
||||||
removeSegment(selSegment);
|
removeSegment(selSegment);
|
||||||
|
simplify();
|
||||||
emitAction(BlockItemBase::BusSegmentRemove);
|
emitAction(BlockItemBase::BusSegmentRemove);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -527,6 +601,7 @@ void BlockBusItem::mouseReleaseEvent(QGraphicsSceneMouseEvent * e) {
|
|||||||
selPoint = selSegment = -1;
|
selPoint = selSegment = -1;
|
||||||
}
|
}
|
||||||
if (moved) {
|
if (moved) {
|
||||||
|
simplify(false);
|
||||||
reconnect();
|
reconnect();
|
||||||
emitAction(lm_point ? BlockItemBase::BusPointMove : BlockItemBase::BusSegmentMove);
|
emitAction(lm_point ? BlockItemBase::BusPointMove : BlockItemBase::BusSegmentMove);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,13 +42,13 @@ public:
|
|||||||
void setWidth(const double & w) {pen_width = w; update();}
|
void setWidth(const double & w) {pen_width = w; update();}
|
||||||
void setColor(const QColor & c) {pu.setColor(c); bu.setColor(c); update();}
|
void setColor(const QColor & c) {pu.setColor(c); bu.setColor(c); update();}
|
||||||
int addPoint(const QPointF & point, bool update = true);
|
int addPoint(const QPointF & point, bool update = true);
|
||||||
int segmentPointPair(int point) const;
|
int segmentPointPair(int point, int * seg = 0) const;
|
||||||
void removePoint(int index);
|
void removePoint(int index);
|
||||||
void removeSegment(int index);
|
void removeSegment(int index);
|
||||||
void markAsInput();
|
void markAsInput();
|
||||||
void markAsOutput();
|
void markAsOutput();
|
||||||
void unmark();
|
void unmark();
|
||||||
void simplify();
|
void simplify(bool full = true);
|
||||||
void adjustLine();
|
void adjustLine();
|
||||||
int endpointCount() const;
|
int endpointCount() const;
|
||||||
bool isBusSelected() const {return selSegment >= 0 || selPoint >= 0;}
|
bool isBusSelected() const {return selSegment >= 0 || selPoint >= 0;}
|
||||||
@@ -72,7 +72,9 @@ protected:
|
|||||||
void checkDelete();
|
void checkDelete();
|
||||||
void emitAction(BlockItemBase::Action a);
|
void emitAction(BlockItemBase::Action a);
|
||||||
QVector<int> endpoints() const;
|
QVector<int> endpoints() const;
|
||||||
int pointSegments(int point) const;
|
QVector<int> endpointLine(int ep) const;
|
||||||
|
int pointSegmentsCount(int point, QList<int> * segs = 0) const;
|
||||||
|
int neighborSegmentPoint(int point, int * seg) const;
|
||||||
int type() const {return Type;}
|
int type() const {return Type;}
|
||||||
QRectF boundingRect() const;
|
QRectF boundingRect() const;
|
||||||
bool sceneEvent(QEvent * e);
|
bool sceneEvent(QEvent * e);
|
||||||
|
|||||||
@@ -499,6 +499,7 @@ bool BlockView::eventFilter(QObject * o, QEvent * e) {
|
|||||||
foreach (QGraphicsItem * b, sel_items)
|
foreach (QGraphicsItem * b, sel_items)
|
||||||
if (b->data(1006) == "item")
|
if (b->data(1006) == "item")
|
||||||
ci << b;
|
ci << b;
|
||||||
|
simplifyBuses();
|
||||||
emitActionEvent(BlockItemBase::BlockMove, ci);
|
emitActionEvent(BlockItemBase::BlockMove, ci);
|
||||||
reconnectAll();
|
reconnectAll();
|
||||||
}
|
}
|
||||||
@@ -1114,16 +1115,16 @@ void BlockView::matchBus() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (sp >= 0) {
|
if (sp >= 0) {
|
||||||
if (b->endpointCount() + b->pointSegments(sp) - 2 >= b->max_ep) {
|
if (b->endpointCount() + b->pointSegmentsCount(sp) - 2 >= b->max_ep) {
|
||||||
b->setBusState(false);
|
b->setBusState(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
int sep = b->endpointCount() + bus_from->endpointCount();
|
int sep = b->endpointCount() + bus_from->endpointCount();
|
||||||
if (b->pointSegments(sp) == 1) sep--;
|
if (b->pointSegmentsCount(sp) == 1) sep--;
|
||||||
if (bus_from->selPoint >= 0)
|
if (bus_from->selPoint >= 0)
|
||||||
if (bus_from->pointSegments(bus_from->selPoint) == 1) sep--;
|
if (bus_from->pointSegmentsCount(bus_from->selPoint) == 1) sep--;
|
||||||
if (sep > b->max_ep) {
|
if (sep > b->max_ep) {
|
||||||
b->setBusState(false);
|
b->setBusState(false);
|
||||||
return;
|
return;
|
||||||
@@ -1205,6 +1206,13 @@ void BlockView::unhoverPins() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void BlockView::simplifyBuses() {
|
||||||
|
QList<BlockBusItem*> bl = buses();
|
||||||
|
foreach (BlockBusItem * b, bl)
|
||||||
|
b->simplify();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void BlockView::moveBuses(const QList<QGraphicsItem * > & items, QPointF dp) {
|
void BlockView::moveBuses(const QList<QGraphicsItem * > & items, QPointF dp) {
|
||||||
if (dp.isNull()) return;
|
if (dp.isNull()) return;
|
||||||
QList<QGraphicsItem * > gi = scene_->items();
|
QList<QGraphicsItem * > gi = scene_->items();
|
||||||
@@ -1230,7 +1238,7 @@ void BlockView::moveBuses(const QList<QGraphicsItem * > & items, QPointF dp) {
|
|||||||
foreach (BlockItemPin * p, pins) {
|
foreach (BlockItemPin * p, pins) {
|
||||||
QList<int> ends = b->connections_.keys(p);
|
QList<int> ends = b->connections_.keys(p);
|
||||||
for (int i = 0; i < ends.size(); ++i) {
|
for (int i = 0; i < ends.size(); ++i) {
|
||||||
int isp = b->segmentPointPair(ends[i]);
|
/*int isp = b->segmentPointPair(ends[i]);
|
||||||
QPointF sdp;
|
QPointF sdp;
|
||||||
if (isp >= 0 && b->pol.size() > 2) {
|
if (isp >= 0 && b->pol.size() > 2) {
|
||||||
sdp = b->pol[isp] - b->pol[ends[i]];
|
sdp = b->pol[isp] - b->pol[ends[i]];
|
||||||
@@ -1245,7 +1253,13 @@ void BlockView::moveBuses(const QList<QGraphicsItem * > & items, QPointF dp) {
|
|||||||
if (p->alignment() == Qt::AlignLeft || p->alignment() == Qt::AlignRight)
|
if (p->alignment() == Qt::AlignLeft || p->alignment() == Qt::AlignRight)
|
||||||
b->movePoint(isp, QPointF(0., dp.y()));
|
b->movePoint(isp, QPointF(0., dp.y()));
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
|
QPointF pdp = dp;
|
||||||
|
if (p->alignment() == Qt::AlignTop || p->alignment() == Qt::AlignBottom) pdp.setY(0.);
|
||||||
|
if (p->alignment() == Qt::AlignLeft || p->alignment() == Qt::AlignRight) pdp.setX(0.);
|
||||||
|
QVector<int> epl = b->endpointLine(ends[i]);
|
||||||
|
foreach (int e, epl)
|
||||||
|
b->movePoint(e, pdp);
|
||||||
b->movePoint(ends[i], dp);
|
b->movePoint(ends[i], dp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -100,6 +100,7 @@ protected:
|
|||||||
void unmarkPins(bool to_normal = false);
|
void unmarkPins(bool to_normal = false);
|
||||||
void hoverAcceptedPin(BlockItemPin * pin);
|
void hoverAcceptedPin(BlockItemPin * pin);
|
||||||
void unhoverPins();
|
void unhoverPins();
|
||||||
|
void simplifyBuses();
|
||||||
void moveBuses(const QList<QGraphicsItem * > & items, QPointF dp);
|
void moveBuses(const QList<QGraphicsItem * > & items, QPointF dp);
|
||||||
QList<BlockBusItem * > internalBuses(const QList<BlockItem * > & items);
|
QList<BlockBusItem * > internalBuses(const QList<BlockItem * > & items);
|
||||||
QList<BlockItem * > selectedBlocks() const;
|
QList<BlockItem * > selectedBlocks() const;
|
||||||
|
|||||||
Reference in New Issue
Block a user