diff --git a/pip b/pip index 31f0d88..9834ac1 160000 --- a/pip +++ b/pip @@ -1 +1 @@ -Subproject commit 31f0d881570880a73b6b4bdef5708de58570651d +Subproject commit 9834ac177bfae3f0bfa14c083e3857560ec59b38 diff --git a/qad/application/aboutwindow.ui b/qad/application/aboutwindow.ui index cd926fd..3167f51 100644 --- a/qad/application/aboutwindow.ui +++ b/qad/application/aboutwindow.ui @@ -28,6 +28,9 @@ + + QPainter::SmoothPixmapTransform|QPainter::TextAntialiasing + diff --git a/qad/blockview/blockbusitem.cpp b/qad/blockview/blockbusitem.cpp index 7c7bb51..0a7231f 100644 --- a/qad/blockview/blockbusitem.cpp +++ b/qad/blockview/blockbusitem.cpp @@ -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; diff --git a/qad/blockview/blockbusitem.h b/qad/blockview/blockbusitem.h index 61eed85..54a5e45 100644 --- a/qad/blockview/blockbusitem.h +++ b/qad/blockview/blockbusitem.h @@ -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));} diff --git a/qad/blockview/blockeditor/CMakeLists.txt b/qad/blockview/blockeditor/CMakeLists.txt index b003eff..d69d9d8 100644 --- a/qad/blockview/blockeditor/CMakeLists.txt +++ b/qad/blockview/blockeditor/CMakeLists.txt @@ -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() diff --git a/qad/blockview/blockeditor/icons/blockview.png b/qad/blockview/blockeditor/icons/blockview.png new file mode 100644 index 0000000..44f65d7 Binary files /dev/null and b/qad/blockview/blockeditor/icons/blockview.png differ diff --git a/qad/blockview/blockeditor/resource_win_icon.rc b/qad/blockview/blockeditor/resource_win_icon.rc deleted file mode 100644 index 09b2a10..0000000 --- a/qad/blockview/blockeditor/resource_win_icon.rc +++ /dev/null @@ -1,43 +0,0 @@ -# if defined(UNDER_CE) -# include -# else -# include -# 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 diff --git a/qad/blockview/blockview.cpp b/qad/blockview/blockview.cpp index 418c5f7..4f804ac 100644 --- a/qad/blockview/blockview.cpp +++ b/qad/blockview/blockview.cpp @@ -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; } diff --git a/qad/blockview/blockviewwavetrace.cpp b/qad/blockview/blockviewwavetrace.cpp index 72b597c..79be7fd 100644 --- a/qad/blockview/blockviewwavetrace.cpp +++ b/qad/blockview/blockviewwavetrace.cpp @@ -1,5 +1,4 @@ #include "blockviewwavetrace.h" -#include 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 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); diff --git a/qad/blockview/blockviewwavetrace.h b/qad/blockview/blockviewwavetrace.h index f95a8c7..c8d0f90 100644 --- a/qad/blockview/blockviewwavetrace.h +++ b/qad/blockview/blockviewwavetrace.h @@ -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 & 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 > field; + QVector > field; QVector path_; QVector jumps; QPoint dps[4], st, fn; diff --git a/qad/widgets/image_view.cpp b/qad/widgets/image_view.cpp index f50c0cd..516dc22 100644 --- a/qad/widgets/image_view.cpp +++ b/qad/widgets/image_view.cpp @@ -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); + } diff --git a/qad/widgets/image_view.h b/qad/widgets/image_view.h index 81ecadb..dbed10d 100644 --- a/qad/widgets/image_view.h +++ b/qad/widgets/image_view.h @@ -52,6 +52,7 @@ private: QByteArray im_data; QPoint prev_pos; bool autofit_; + QPixmap map; public slots: