git-svn-id: svn://db.shs.com.ru/libs@176 a8b55f48-bf90-11e4-a774-851b48703e85

This commit is contained in:
2017-04-05 16:12:45 +00:00
parent 81d21c2084
commit d38009ba51
5 changed files with 75 additions and 20 deletions

View File

@@ -218,7 +218,7 @@ void BlockBusItem::simplify(bool full) {
else sp[i] = pol[segments[segs[i]].first];
}
QLineF l0(sp[0], cp), l1(cp, sp[1]);
if (l0.angle() != l1.angle()) continue;
if (qAbs(l0.angle() - l1.angle()) > 0.1) continue;
if (segments[s0].first == p) {
if (segments[s1].first == p) segments[s0].first = segments[s1].second;
else segments[s0].first = segments[s1].first;
@@ -313,6 +313,22 @@ BlockBusItem * BlockBusItem::copy() const {
}
void BlockBusItem::saveState() {
segments_s = segments;
ends_ind_s = ends_ind;
ends_s = ends;
pol_s = pol;
}
void BlockBusItem::restoreState() {
segments = segments_s;
ends_ind = ends_ind_s;
ends = ends_s;
pol = pol_s;
}
void BlockBusItem::updateGeometry() {
ends = endpoints();
ends_ind.clear();
@@ -359,21 +375,25 @@ QVector<int> BlockBusItem::endpoints() const {
}
QVector<int> BlockBusItem::endpointLine(int ep) const {
QVector<int> BlockBusItem::endpointLine(int ep, double angle) const {
QVector<int> ret;
int seg = -1;
int np = segmentPointPair(ep, &seg), pp = np;
if (ep < 0 || np < 0) return ret;
if (pol[np] == pol[ep]) return ret;
QPointF sp = pol[np] - pol[ep];
bool sdir = (qAbs(sp.x()) >= qAbs(sp.y()));
//QPointF sp = pol[np] - pol[ep];
QLineF l(pol[ep], pol[np]);
//qDebug() << "first" << l.angle() << angle << (l.angle() != angle);
if (qAbs(l.angle() - angle) > 0.1) return ret;
//qDebug() << "check next" << segments.size();
for (int i = 0; i < segments.size(); ++i) {
//qDebug() << i << np << pointSegmentsCount(np);
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;
QLineF l(pol[pp], pol[np]);
//qDebug() << i << l.angle() << angle;
if (qAbs(l.angle() - angle) > 0.1) break;
}
ret << np;
pp = np;

View File

@@ -62,6 +62,9 @@ public:
QByteArray save() const;
void load(const QByteArray & data);
BlockBusItem * copy() const;
void saveState();
void restoreState();
enum {Type = UserType + 2};
@@ -72,7 +75,7 @@ protected:
void checkDelete();
void emitAction(BlockItemBase::Action a);
QVector<int> endpoints() const;
QVector<int> endpointLine(int ep) const;
QVector<int> endpointLine(int ep, double angle) const;
int pointSegmentsCount(int point, QList<int> * segs = 0) const;
int neighborSegmentPoint(int point, int * seg) const;
int type() const {return Type;}
@@ -90,11 +93,11 @@ protected:
QPen p_, ph, pu, pa, pr, pn;
QBrush b_, bh, bu, ba, br;
QString tt, bus_name;
QList<QPair<int, int> > segments, ends_ind;
QList<QPair<int, int> > segments, ends_ind, segments_s, ends_ind_s;
QMap<int, BlockItemPin * > connections_;
QVector<int> ends;
QVector<int> ends, ends_s;
QImage im_bus, im_end;
QPolygonF pol, bpol;
QPolygonF pol, bpol, pol_s;
Qt::KeyboardModifiers mm_mods;
bool temp_;
double pen_width, grid_step;

View File

@@ -316,8 +316,10 @@ bool BlockView::eventFilter(QObject * o, QEvent * e) {
if (mm_cancel) return true;
if (me->buttons().testFlag(Qt::LeftButton)) {
if (!mm_drag) {
if ((screen_point - me->screenPos()).manhattanLength() >= QApplication::startDragDistance())
if ((screen_point - me->screenPos()).manhattanLength() >= QApplication::startDragDistance()) {
mm_drag = fmm_drag = true;
saveBusesState();
}
} else {
if (tmp_bus.isVisible()) {
mil = scene_->items(me->scenePos());
@@ -956,6 +958,20 @@ void BlockView::saveSelState() {
}
void BlockView::saveBusesState() {
QList<BlockBusItem*> bl = buses();
foreach (BlockBusItem * b, bl)
b->saveState();
}
void BlockView::restoreBusesState() {
QList<BlockBusItem*> bl = buses();
foreach (BlockBusItem * b, bl)
b->restoreState();
}
void BlockView::applySelRect(QGraphicsSceneMouseEvent * me) {
QList<QGraphicsItem*> ci = sel_rect.collidingItems(Qt::IntersectsItemBoundingRect);
QList<QGraphicsItem*> gi = scene_->items();
@@ -1218,7 +1234,7 @@ void BlockView::moveBuses(const QList<QGraphicsItem * > & items, QPointF dp) {
QList<QGraphicsItem * > gi = scene_->items();
QVector<BlockItemPin * > pins;
QList<BlockBusItem * > buses;
//qDebug() << "move";
//qDebug() << "move" << dp;
foreach (QGraphicsItem * i, items)
if (i->data(1006) == "item" && i->flags().testFlag(QGraphicsItem::ItemIsMovable))
pins << qgraphicsitem_cast<BlockItem*>(i)->pins();
@@ -1255,9 +1271,15 @@ void BlockView::moveBuses(const QList<QGraphicsItem * > & items, QPointF dp) {
}
}*/
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]);
double ang = 0.;
switch (p->alignment()) {
case Qt::AlignRight : pdp.setX(0.); ang = 0.; break;
case Qt::AlignTop : pdp.setY(0.); ang = 90.; break;
case Qt::AlignLeft : pdp.setX(0.); ang = 180.; break;
case Qt::AlignBottom: pdp.setY(0.); ang = 270.; break;
default: break;
}
QVector<int> epl = b->endpointLine(ends[i], ang);
foreach (int e, epl)
b->movePoint(e, pdp);
b->movePoint(ends[i], dp);

View File

@@ -90,6 +90,8 @@ protected:
void thumbShow();
void restoreSelState();
void saveSelState();
void saveBusesState();
void restoreBusesState();
void applySelRect(QGraphicsSceneMouseEvent * me);
void applyGridStep();
void trace(QPointF scene_pos_from, QPointF scene_pos_to, BlockBusItem * bus);

View File

@@ -87,16 +87,24 @@ void SessionManager::load(bool onlyMainwindow) {
checks[i].second->setChecked(sr.getValue(checks[i].first, checks[i].second->isChecked()));
for (int i = 0; i < lines.size(); ++i)
lines[i].second->setText(sr.getValue(lines[i].first, lines[i].second->text()));
for (int i = 0; i < combos.size(); ++i)
combos[i].second->setCurrentIndex(sr.getValue(combos[i].first, combos[i].second->currentIndex()));
for (int i = 0; i < combos.size(); ++i) {
QComboBox * c = combos[i].second;
int v = sr.getValue(combos[i].first, c->currentIndex());
if (v >= 0 && v < c->count())
c->setCurrentIndex(v);
}
for (int i = 0; i < dspins.size(); ++i)
dspins[i].second->setValue(sr.getValue(dspins[i].first, dspins[i].second->value()));
for (int i = 0; i < spins.size(); ++i)
spins[i].second->setValue(sr.getValue(spins[i].first, spins[i].second->value()));
for (int i = 0; i < spinsliders.size(); ++i)
spinsliders[i].second->setValue(sr.getValue(spinsliders[i].first, spinsliders[i].second->value()));
for (int i = 0; i < tabs.size(); ++i)
tabs[i].second->setCurrentIndex(sr.getValue(tabs[i].first, tabs[i].second->currentIndex()));
for (int i = 0; i < tabs.size(); ++i) {
QTabWidget * t = tabs[i].second;
int v = sr.getValue(tabs[i].first, t->currentIndex());
if (v >= 0 && v < t->count())
t->setCurrentIndex(v);
}
for (int i = 0; i < actions.size(); ++i)
actions[i].second->setChecked(sr.getValue(actions[i].first, actions[i].second->isChecked()));
for (int i = 0; i < stringlists.size(); ++i)