Merge pull request 'master' (#65) from master into release
All checks were successful
SHS Gitea/libs/pipeline/head This commit looks good

Reviewed-on: https://git.shs.tools/SHS/libs/pulls/65
This commit was merged in pull request #65.
This commit is contained in:
2020-08-18 17:09:38 +03:00
12 changed files with 107 additions and 117 deletions

2
pip

Submodule pip updated: 31f0d88157...9834ac177b

View File

@@ -28,6 +28,9 @@
</color>
</brush>
</property>
<property name="renderHints">
<set>QPainter::SmoothPixmapTransform|QPainter::TextAntialiasing</set>
</property>
</widget>
</item>
<item>

View File

@@ -483,16 +483,16 @@ int BlockBusItem::neighborSegmentPoint(int point, int * seg) const {
}
void BlockBusItem::testPoint(QPointF pos, int * sel_point, int * sel_segment) {
void BlockBusItem::testPoint(QPointF pos, int * sel_point, int * sel_segment, bool for_trace) {
for (int i = 0; i < pol.size(); ++i) {
if ((pol[i] - pos).manhattanLength() <= 10.) { // Point
if ((pol[i] - pos).manhattanLength() <= (for_trace ? 5. : 10.)) { // Point
*sel_point = i;
*sel_segment = -1;
return;
}
}
for (int i = 0; i < segments.size(); ++i) {
if (distPointToLine(pol[segments[i].first], pol[segments[i].second], pos) <= 7.) { // Segment
if (distPointToLine(pol[segments[i].first], pol[segments[i].second], pos) <= (for_trace ? 5. : 7.)) { // Segment
*sel_point = -1;
*sel_segment = i;
return;

View File

@@ -46,7 +46,7 @@ public:
double endpointImageScale() const {return im_end_scale;}
void appendPoint(const QPointF & p);
void appendPoint(qreal x, qreal y);
void testPoint(QPointF pos, int * sel_point, int * sel_segment);
void testPoint(QPointF pos, int * sel_point, int * sel_segment, bool for_trace = false);
void clear();
/*void setStart(const QPointF & p) {pol[0] = p; scene()->update();}
void setStart(qreal x, qreal y) {setStart(QPointF(x, y));}

View File

@@ -1,8 +1,26 @@
project(blockeditor)
import_version(${PROJECT_NAME} QAD)
find_qt(${QtVersions} Core Gui Widgets)
if (Qt5_FOUND)
import_version(${PROJECT_NAME}5 ${PROJECT_NAME})
import_deploy_properties(${PROJECT_NAME}5 ${PROJECT_NAME})
endif()
set_deploy_property(${PROJECT_NAME}
LABEL ${PROJECT_NAME}
FULLNAME "${_QAD_DOMAIN}.${PROJECT_NAME}"
COMPANY ${_QAD_COMPANY}
INFO "Editor for BlockView Blocks")
if(APPLE)
#set_deploy_property(${PROJECT_NAME} ICON "icons/blockview.icns")
elseif(WIN32)
set_deploy_property(${PROJECT_NAME} ICON "icons/blockview.ico")
else()
set_deploy_property(${PROJECT_NAME} ICON "icons/blockview.png")
endif()
make_rc(${PROJECT_NAME} out_RC)
qt_sources(SRC)
qt_wrap(${SRC} CPPS out_CPP QMS out_QM)
qt_add_executable(${PROJECT_NAME} WIN32 out_CPP)
qt_wrap(${SRC} HDRS out_HDR CPPS out_CPP QMS out_QM)
qt_add_executable(${PROJECT_NAME} WIN32 out_CPP ${out_RC})
qt_target_link_libraries(${PROJECT_NAME} qad_utils qad_widgets qad_blockview)
message(STATUS "Building ${PROJECT_NAME}")
if(LIB)
@@ -18,5 +36,7 @@ if(LIB)
#message(STATUS "Install ${PROJECT_NAME} to system \"${CMAKE_INSTALL_PREFIX}\"")
else()
qt_install(TARGETS ${PROJECT_NAME} DESTINATION bin)
#message(STATUS "Install ${PROJECT_NAME} to local \"bin\"")
endif()
if (Qt5_FOUND)
deploy_target(${PROJECT_NAME}5 VERBOSE DEPLOY_DIR ${CMAKE_CURRENT_BINARY_DIR} DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/../release)
endif()

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

View File

@@ -1,43 +0,0 @@
# if defined(UNDER_CE)
# include <winbase.h>
# else
# include <winver.h>
# endif
1 ICON icons/blockview.ico
VS_VERSION_INFO VERSIONINFO
FILEVERSION 1,0,0,0
PRODUCTVERSION 1,0,0,0
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x9L
#else
FILEFLAGS 0x8L
#endif
FILEOS 0x40004L
FILETYPE 0x2L
FILESUBTYPE 0x0L
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "040904b0"
BEGIN
VALUE "Comments", "\0"
VALUE "CompanyName", "BMSTU SM5\0"
VALUE "FileDescription", "Block Editor\0"
VALUE "FileVersion", "1,0,0,0\0"
VALUE "InternalName", "Block Editor\0"
VALUE "LegalTrademarks", "\0"
VALUE "OriginalFilename", "blockeditor.exe\0"
VALUE "PrivateBuild", "1\0"
VALUE "ProductName", "Block Editor\0"
VALUE "ProductVersion", "1, 0, 0, 0\0"
VALUE "SpecialBuild", "\0"
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x409, 1200
END
END

View File

@@ -1264,23 +1264,26 @@ void BlockView::trace(QPointF scene_pos_from, QPointF scene_pos_to, BlockBusItem
double signx = (p1.x() >= p0.x() ? 1. : -1.), signy = (p1.y() >= p0.y() ? 1. : -1.);
int steps(0);
if ((dx + dy) < grid_step) continue;
BlockViewWavetrace::CellState cs = BlockViewWavetrace::Blocked;
if (dx >= dy) { // by x
sx = grid_step;
sy = sx * dy / dx;
steps = qRound(dx / grid_step);
cs = BlockViewWavetrace::HorizontalBus;
} else {
sy = grid_step;
sx = sy * dx / dy;
steps = qRound(dy / grid_step);
cs = BlockViewWavetrace::VerticalBus;
}
sx *= signx;
sy *= signy;
//qDebug() << "fill" << p0 << "->" << p1 << "in" << steps << sx << sy;
for (int j = 0; j < steps; ++j) {
for (int j = 0; j <= steps; ++j) {
QPoint tp = quantize(cp, grid_step).toPoint() / grid_step + dp;
if (tp != qpt)
wavetrace.fill(tp, BlockViewWavetrace::Jump);
//qDebug() << " set" << cp;
wavetrace.fill(tp, (j > 0 && j < steps) ? cs : BlockViewWavetrace::Blocked);
//qDebug() << " set" << cp << ((j > 0 && j < steps) ? cs : BlockViewWavetrace::Blocked);
cp += QPointF(sx, sy);
}
}
@@ -1346,7 +1349,7 @@ void BlockView::matchBus() {
//qDebug() << "1" << buses.size() << tmp_bus.pol;
for (int i = 0; i < buses.size(); ++i) {
b = buses[i];
b->testPoint(point, &sp, &ss);
b->testPoint(point, &sp, &ss, true);
//qDebug() << i << sp << ss;
if (sp >= 0 || ss >= 0) break;
}

View File

@@ -1,5 +1,4 @@
#include "blockviewwavetrace.h"
#include <QTime>
BlockViewWavetrace::BlockViewWavetrace(int width, int height) {
@@ -17,14 +16,13 @@ void BlockViewWavetrace::resize(int width, int height) {
for (int i = 0; i < wid; ++i) {
if (field[i].size() != hei) {
field[i].resize(hei);
field[i].fill(-1);
field[i].fill(Cell());
}
}
}
void BlockViewWavetrace::fill(short val) {
QTime tm; tm.restart();
for (int i = 0; i < wid; ++i) {
if (i == 0)
field[i].fill(val);
@@ -37,11 +35,18 @@ void BlockViewWavetrace::fill(short val) {
void BlockViewWavetrace::fill(const QRect & rect, short val) {
for (int i = rect.left(); i <= rect.right(); ++i)
for (int j = rect.top(); j <= rect.bottom(); ++j)
field[i][j] = val;
field[i][j].value = field[i][j].direction = val;
}
void BlockViewWavetrace::fill(int px, int py, short val) {
field[px][py] = val;
short p = field[px][py].value;
if ((val == HorizontalBus && p == VerticalBus ) ||
(val == VerticalBus && p == HorizontalBus))
field[px][py].value = Blocked;
else
field[px][py].value = val;
field[px][py].direction = field[px][py].value;
}
@@ -51,44 +56,33 @@ bool BlockViewWavetrace::trace(const QPoint & start, const QPoint & finish) {
if (dir_ == NoTrace) return true;
//qDebug() << "trace" << start << finish;
//return true;
int cx, cy;
short cl = 0;
QRect frect(0, 0, wid - 1, hei - 1);
QVector<QPoint> cpnts, npnts;
fill(st, cl);
jumps.clear();
cpnts.append(st);
auto checkAndFill = [this, &npnts, &frect](int x, int y, short c) {
cpnts.push_back(st);
if (field[fn.x()][fn.y()].value == (short)Blocked)
return false;
auto checkAndFill = [this, &npnts, &frect](int x, int y, short acc_dir, 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));
short p = field[x][y].value;
if (p == (short)Empty || p == acc_dir) {
npnts.push_back(QPoint(x, y));
field[x][y].value = c;
}
};
if (field[fn.x()][fn.y()] < (short)Empty)
return false;
while (cpnts.size() > 0) {
npnts.clear();
cl++;
if (cl >= max_steps) return false;
if (cl >= max_steps)
return false;
for (int i = 0; i < cpnts.size(); ++i) {
if (cpnts[i] == fn) {
if (cpnts[i] == fn)
return true;
}
cx = cpnts[i].x() - 1;
cy = cpnts[i].y();
checkAndFill(cx, cy, cl);
cx = cpnts[i].x() + 1;
checkAndFill(cx, cy, cl);
cx = cpnts[i].x();
cy = cpnts[i].y() - 1;
checkAndFill(cx, cy, cl);
cy = cpnts[i].y() + 1;
checkAndFill(cx, cy, cl);
checkAndFill(cpnts[i].x() - 1, cpnts[i].y() , (short)VerticalBus , cl);
checkAndFill(cpnts[i].x() + 1, cpnts[i].y() , (short)VerticalBus , cl);
checkAndFill(cpnts[i].x() , cpnts[i].y() - 1, (short)HorizontalBus, cl);
checkAndFill(cpnts[i].x() , cpnts[i].y() + 1, (short)HorizontalBus, cl);
}
cpnts = npnts;
//qDebug() << cl << ": " << cpnts.size();
@@ -106,27 +100,21 @@ void BlockViewWavetrace::gatherPath() {
}
int pa = -1, ca = -1;
bool first = true;
short cl = field[fn.x()][fn.y()];
short cl = field[fn.x()][fn.y()].value;
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 {
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);
const Cell & cell(field[cx][cy]);
if (cell.value == c) {
if (cell.direction == HorizontalBus || cell.direction == VerticalBus) {
if (dps[dir].x() == 0 && cell.direction == VerticalBus)
return false;
if (dps[dir].y() == 0 && cell.direction == HorizontalBus)
return false;
}
ca_ = QLineF(QPointF(cx, cy), cpnt).angle();
if (ca_ != pa_ && !first)
@@ -141,11 +129,12 @@ void BlockViewWavetrace::gatherPath() {
while (cl > 0) {
cl--;
pa = ca;
int dir = 0;
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;
if (checkAndStep(0, cl, ca, pa)) continue;
if (checkAndStep(1, cl, ca, pa)) continue;
if (checkAndStep(2, cl, ca, pa)) continue;
if (checkAndStep(3, cl, ca, pa)) continue;
}
path_.push_front(st);
//cout << path_.size() << endl;
@@ -154,13 +143,13 @@ void BlockViewWavetrace::gatherPath() {
void BlockViewWavetrace::setPreferredDirection(BlockViewWavetrace::Direction dir) {
dir_ = dir;
if (dir == Horizontal) {
if (dir == BlockViewWavetrace::Horizontal) {
dps[0] = QPoint(0, -1);
dps[1] = QPoint(0, 1);
dps[2] = QPoint(-1, 0);
dps[3] = QPoint(1, 0);
}
if (dir == Vertical) {
if (dir == BlockViewWavetrace::Vertical) {
dps[2] = QPoint(0, -1);
dps[3] = QPoint(0, 1);
dps[0] = QPoint(-1, 0);

View File

@@ -27,7 +27,7 @@ class QAD_EXPORT BlockViewWavetrace {
public:
BlockViewWavetrace(int width = 1, int height = 1);
enum CellState {Empty = -1, Blocked = -2, Jump = -3};
enum CellState {Empty = -1, Blocked = -2, HorizontalBus = -3, VerticalBus = -4};
enum Direction {NoTrace, Horizontal, Vertical};
int width() const {return wid;}
@@ -36,7 +36,7 @@ public:
void resize(const QSize & sz) {resize(sz.width(), sz.height());}
void fill(short val = -1);
void fill(const QRect & rect, short val = -1);
void fill(const QPoint & point, short val = -1) {field[point.x()][point.y()] = val;}
void fill(const QPoint & point, short val = -1) {fill(point.x(), point.y(), val);}
void fill(int px, int py, short val);
void fill(BlockViewWavetrace::CellState val = Empty) {fill((short)val);}
void fill(const QRect & rect, BlockViewWavetrace::CellState val = Empty) {fill(rect, (short)val);}
@@ -52,9 +52,15 @@ public:
const QVector<QPoint> & path() const;
private:
struct Cell {
Cell(short v = Empty): value(v), direction(0) {}
short value;
short direction;
};
int wid, hei, max_steps;
Direction dir_;
QVector<QVector<short> > field;
QVector<QVector<Cell> > field;
QVector<QPoint> path_;
QVector<QPoint> jumps;
QPoint dps[4], st, fn;

View File

@@ -14,8 +14,10 @@ ImageView::ImageView(QWidget * parent): QGraphicsView(parent) {
setDragMode(QGraphicsView::NoDrag);
setTransformationAnchor(QGraphicsView::AnchorUnderMouse);
setScene(new QGraphicsScene());
setRenderHint(QPainter::Antialiasing, true);
setRenderHint(QPainter::SmoothPixmapTransform, true);
item.setTransformationMode(Qt::SmoothTransformation);
item.setFlags(0);
item.setFlags(QGraphicsItem::GraphicsItemFlags());
scene()->addItem(&item);
viewport()->setAutoFillBackground(false);
viewport()->installEventFilter(this);
@@ -28,12 +30,12 @@ ImageView::~ImageView() {
QPixmap ImageView::pixmap() const {
return item.pixmap();
return map;
}
void ImageView::setPixmap(QPixmap pixmap) {
item.setPixmap(pixmap);
map = pixmap;
adjustView();
}
@@ -42,12 +44,13 @@ void ImageView::setImage(const QImage & i) {
im_data.clear();
if (i.isNull()) {
item.setPixmap(QPixmap());
map = QPixmap();
return;
}
QBuffer b(&im_data); b.open(QIODevice::ReadWrite);
i.save(&b, "png");
b.close();
item.setPixmap(QPixmap::fromImage(i));
map = QPixmap::fromImage(i);
adjustView();
}
@@ -56,17 +59,18 @@ void ImageView::setImage(const QByteArray & i) {
im_data = i;
if (i.isEmpty()) {
item.setPixmap(QPixmap());
map = QPixmap();
return;
}
item.setPixmap(QPixmap::fromImage(QImage::fromData(i)));
map = QPixmap::fromImage(QImage::fromData(i));
adjustView();
}
void ImageView::clear() {
im_data.clear();
item.setPixmap(QPixmap());
map = QPixmap();
}
@@ -121,10 +125,17 @@ bool ImageView::eventFilter(QObject * o, QEvent * e) {
void ImageView::adjustView() {
qreal mp = map.width() / map.size().boundedTo(size()).width();
if (mp > 1) {
item.setPixmap(map.scaled(map.size()/mp, Qt::KeepAspectRatio, Qt::SmoothTransformation));
} else {
item.setPixmap(map);
}
if (!autofit_) return;
setSceneRect(item.boundingRect());
fitInView(&item, Qt::KeepAspectRatio);
centerOn(&item);
}

View File

@@ -52,6 +52,7 @@ private:
QByteArray im_data;
QPoint prev_pos;
bool autofit_;
QPixmap map;
public slots: