Blockview changes:
1) Теперь для создания сегмента не надо держать Shift, а перемешение шины теперь с нажатой клавишей Shift 2) Режим трассировки шин теперь пытается проложить маршрут с возможностью пересечения шины под прямым углом 3) Теперь рисуются точки соединения сегментов если их больше 2х 4) Обновлена подсказка в tooltip p.s. update pip)
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
BlockViewWavetrace::BlockViewWavetrace(int width, int height) {
|
||||
max_steps = 512;
|
||||
resize(width, height);
|
||||
setPreferredDirection(BlockViewWavetrace::Horizontal);
|
||||
setPreferredDirection(Horizontal);
|
||||
}
|
||||
|
||||
|
||||
@@ -40,6 +40,10 @@ void BlockViewWavetrace::fill(const QRect & rect, short val) {
|
||||
field[i][j] = val;
|
||||
}
|
||||
|
||||
void BlockViewWavetrace::fill(int px, int py, short val) {
|
||||
field[px][py] = val;
|
||||
}
|
||||
|
||||
|
||||
bool BlockViewWavetrace::trace(const QPoint & start, const QPoint & finish) {
|
||||
st = start;
|
||||
@@ -48,12 +52,24 @@ bool BlockViewWavetrace::trace(const QPoint & start, const QPoint & finish) {
|
||||
//qDebug() << "trace" << start << finish;
|
||||
//return true;
|
||||
int cx, cy;
|
||||
short cl = 0, empty = (short)BlockViewWavetrace::Empty;
|
||||
short cl = 0;
|
||||
QRect frect(0, 0, wid - 1, hei - 1);
|
||||
QVector<QPoint> cpnts, npnts;
|
||||
fill(st, cl);
|
||||
cpnts.push_back(st);
|
||||
if (field[fn.x()][fn.y()] == (short)BlockViewWavetrace::Blocked)
|
||||
jumps.clear();
|
||||
cpnts.append(st);
|
||||
auto checkAndFill = [this, &npnts, &frect](int x, int y, short c) {
|
||||
if (!frect.contains(x, y)) return;
|
||||
short p = field[x][y];
|
||||
if (p == (short)Empty || p == (short)Jump) {
|
||||
npnts.append(QPoint(x, y));
|
||||
fill(x, y, c);
|
||||
}
|
||||
if (p == (short)Jump) {
|
||||
jumps.append(QPoint(x, y));
|
||||
}
|
||||
};
|
||||
if (field[fn.x()][fn.y()] < (short)Empty)
|
||||
return false;
|
||||
while (cpnts.size() > 0) {
|
||||
npnts.clear();
|
||||
@@ -65,34 +81,14 @@ bool BlockViewWavetrace::trace(const QPoint & start, const QPoint & finish) {
|
||||
}
|
||||
cx = cpnts[i].x() - 1;
|
||||
cy = cpnts[i].y();
|
||||
if (frect.contains(cx, cy)) {
|
||||
if (field[cx][cy] == empty) {
|
||||
npnts.push_back(QPoint(cx, cy));
|
||||
fill(cx, cy, cl);
|
||||
}
|
||||
}
|
||||
checkAndFill(cx, cy, cl);
|
||||
cx = cpnts[i].x() + 1;
|
||||
if (frect.contains(cx, cy)) {
|
||||
if (field[cx][cy] == empty) {
|
||||
npnts.push_back(QPoint(cx, cy));
|
||||
fill(cx, cy, cl);
|
||||
}
|
||||
}
|
||||
checkAndFill(cx, cy, cl);
|
||||
cx = cpnts[i].x();
|
||||
cy = cpnts[i].y() - 1;
|
||||
if (frect.contains(cx, cy)) {
|
||||
if (field[cx][cy] == empty) {
|
||||
npnts.push_back(QPoint(cx, cy));
|
||||
fill(cx, cy, cl);
|
||||
}
|
||||
}
|
||||
checkAndFill(cx, cy, cl);
|
||||
cy = cpnts[i].y() + 1;
|
||||
if (frect.contains(cx, cy)) {
|
||||
if (field[cx][cy] == empty) {
|
||||
npnts.push_back(QPoint(cx, cy));
|
||||
fill(cx, cy, cl);
|
||||
}
|
||||
}
|
||||
checkAndFill(cx, cy, cl);
|
||||
}
|
||||
cpnts = npnts;
|
||||
//qDebug() << cl << ": " << cpnts.size();
|
||||
@@ -108,68 +104,48 @@ void BlockViewWavetrace::gatherPath() {
|
||||
path_.push_front(st);
|
||||
return;
|
||||
}
|
||||
int cx, cy;
|
||||
int pa = -1, ca = -1;
|
||||
bool first = true;
|
||||
short cl = field[fn.x()][fn.y()];
|
||||
QRect frect(0, 0, wid, hei);
|
||||
QPoint cpnt = fn;
|
||||
//cout << "start from " << cl << endl;
|
||||
auto checkAndStep = [this, &cpnt, &first, &frect] (int & dir, short c, int & ca_, int pa_)->bool {
|
||||
int cx = cpnt.x() + dps[dir].x();
|
||||
int cy = cpnt.y() + dps[dir].y();
|
||||
dir++;
|
||||
if (frect.contains(cx, cy)) {
|
||||
if (field[cx][cy] == c) {
|
||||
if (jumps.contains(QPoint(cx, cy))) {
|
||||
int jx = cx - 1;
|
||||
int jy = cy;
|
||||
if (jumps.contains(QPoint(jx, jy))) fill(jx, jy, (short)Jump);
|
||||
jx = cx + 1;
|
||||
if (jumps.contains(QPoint(jx, jy))) fill(jx, jy, (short)Jump);
|
||||
jx = cx;
|
||||
jy = cy - 1;
|
||||
if (jumps.contains(QPoint(jx, jy))) fill(jx, jy, (short)Jump);
|
||||
jy = cy + 1;
|
||||
if (jumps.contains(QPoint(jx, jy))) fill(jx, jy, (short)Jump);
|
||||
}
|
||||
ca_ = QLineF(QPointF(cx, cy), cpnt).angle();
|
||||
if (ca_ != pa_ && !first)
|
||||
path_.push_front(cpnt);
|
||||
cpnt = QPoint(cx, cy);
|
||||
first = false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
};
|
||||
while (cl > 0) {
|
||||
cl--;
|
||||
pa = ca;
|
||||
int dir = 0;
|
||||
cx = cpnt.x() + dps[dir].x();
|
||||
cy = cpnt.y() + dps[dir].y();
|
||||
dir++;
|
||||
if (frect.contains(cx, cy)) {
|
||||
if (field[cx][cy] == cl) {
|
||||
ca = QLineF(QPointF(cx, cy), cpnt).angle();
|
||||
if (ca != pa && !first)
|
||||
path_.push_front(cpnt);
|
||||
cpnt = QPoint(cx, cy);
|
||||
first = false;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
cx = cpnt.x() + dps[dir].x();
|
||||
cy = cpnt.y() + dps[dir].y();
|
||||
dir++;
|
||||
if (frect.contains(cx, cy)) {
|
||||
if (field[cx][cy] == cl) {
|
||||
ca = QLineF(QPointF(cx, cy), cpnt).angle();
|
||||
if (ca != pa && !first)
|
||||
path_.push_front(cpnt);
|
||||
cpnt = QPoint(cx, cy);
|
||||
first = false;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
cx = cpnt.x() + dps[dir].x();
|
||||
cy = cpnt.y() + dps[dir].y();
|
||||
dir++;
|
||||
if (frect.contains(cx, cy)) {
|
||||
if (field[cx][cy] == cl) {
|
||||
ca = QLineF(QPointF(cx, cy), cpnt).angle();
|
||||
if (ca != pa && !first)
|
||||
path_.push_front(cpnt);
|
||||
cpnt = QPoint(cx, cy);
|
||||
first = false;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
cx = cpnt.x() + dps[dir].x();
|
||||
cy = cpnt.y() + dps[dir].y();
|
||||
if (frect.contains(cx, cy)) {
|
||||
if (field[cx][cy] == cl) {
|
||||
ca = QLineF(QPointF(cx, cy), cpnt).angle();
|
||||
if (ca != pa && !first)
|
||||
path_.push_front(cpnt);
|
||||
cpnt = QPoint(cx, cy);
|
||||
first = false;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (checkAndStep(dir, cl, ca, pa)) continue;
|
||||
if (checkAndStep(dir, cl, ca, pa)) continue;
|
||||
if (checkAndStep(dir, cl, ca, pa)) continue;
|
||||
if (checkAndStep(dir, cl, ca, pa)) continue;
|
||||
}
|
||||
path_.push_front(st);
|
||||
//cout << path_.size() << endl;
|
||||
@@ -178,13 +154,13 @@ void BlockViewWavetrace::gatherPath() {
|
||||
|
||||
void BlockViewWavetrace::setPreferredDirection(BlockViewWavetrace::Direction dir) {
|
||||
dir_ = dir;
|
||||
if (dir == BlockViewWavetrace::Horizontal) {
|
||||
if (dir == Horizontal) {
|
||||
dps[0] = QPoint(0, -1);
|
||||
dps[1] = QPoint(0, 1);
|
||||
dps[2] = QPoint(-1, 0);
|
||||
dps[3] = QPoint(1, 0);
|
||||
}
|
||||
if (dir == BlockViewWavetrace::Vertical) {
|
||||
if (dir == Vertical) {
|
||||
dps[2] = QPoint(0, -1);
|
||||
dps[3] = QPoint(0, 1);
|
||||
dps[0] = QPoint(-1, 0);
|
||||
|
||||
Reference in New Issue
Block a user