diff --git a/3part/RsaCrypto/include/lpsingleton.h b/3part/RsaCrypto/include/lpsingleton.h new file mode 100644 index 0000000..43c815f --- /dev/null +++ b/3part/RsaCrypto/include/lpsingleton.h @@ -0,0 +1,54 @@ +#ifndef _H_LPSINGLETON_H_ +#define _H_LPSINGLETON_H_ + +#include +#include + +template +class lpsingleton +{ +public: + static T* instance() + { + T *sin = s_this.load(std::memory_order_acquire); + + if (!sin) { + std::lock_guard locker(s_mutex); + sin = s_this.load(std::memory_order_relaxed); + if (!sin) { + sin = new T; + s_this.store(sin, std::memory_order_release); + } + } + + return sin; + } + + static void uninstance() + { + T *sin = s_this.load(std::memory_order_relaxed); + if (sin) { + std::lock_guard locker(s_mutex); + delete sin; + sin = nullptr; + } + } + +protected: + lpsingleton() = default; + virtual ~lpsingleton() = default; +private: + lpsingleton(const T&) = delete; + T& operator=(const T&) = delete; + + static std::atomic s_this; + static std::mutex s_mutex; +}; + +template +std::atomic lpsingleton::s_this; + +template +std::mutex lpsingleton::s_mutex; + +#endif \ No newline at end of file diff --git a/runner17/lpMaind.dll b/runner17/lpMaind.dll index cac22b5..7c29e08 100644 Binary files a/runner17/lpMaind.dll and b/runner17/lpMaind.dll differ diff --git a/src/lpMain/Resource/toolBar/attachment6.png b/src/lpMain/Resource/toolBar/attachment6.png new file mode 100644 index 0000000..5c8c7b4 Binary files /dev/null and b/src/lpMain/Resource/toolBar/attachment6.png differ diff --git a/src/lpMain/Resource/toolBar/help.png b/src/lpMain/Resource/toolBar/help.png index f781626..9ce78bc 100644 Binary files a/src/lpMain/Resource/toolBar/help.png and b/src/lpMain/Resource/toolBar/help.png differ diff --git a/src/lpMain/Resource/toolBar/meter3.png b/src/lpMain/Resource/toolBar/meter3.png new file mode 100644 index 0000000..19c7b25 Binary files /dev/null and b/src/lpMain/Resource/toolBar/meter3.png differ diff --git a/src/lpMain/Resource/toolBar/pen38.png b/src/lpMain/Resource/toolBar/pen38.png new file mode 100644 index 0000000..5a91172 Binary files /dev/null and b/src/lpMain/Resource/toolBar/pen38.png differ diff --git a/src/lpMain/Resource/toolBar/tape_measure.png b/src/lpMain/Resource/toolBar/tape_measure.png new file mode 100644 index 0000000..4ae0e3e Binary files /dev/null and b/src/lpMain/Resource/toolBar/tape_measure.png differ diff --git a/src/lpMain/WfCtrl.cpp b/src/lpMain/WfCtrl.cpp index 02d427b..644d1ee 100644 --- a/src/lpMain/WfCtrl.cpp +++ b/src/lpMain/WfCtrl.cpp @@ -142,6 +142,8 @@ bool CWfCtrl::initStation() QStringList lstModels = pSolution->GetAllTaskNames(); for each (QString var in lstModels) { + if(var.toUpper() == "TEMPLATE") + continue; pStation->addModel(var); } } diff --git a/src/lpMain/algela/AngelaCommon.h b/src/lpMain/algela/AngelaCommon.h new file mode 100644 index 0000000..8b851b7 --- /dev/null +++ b/src/lpMain/algela/AngelaCommon.h @@ -0,0 +1,15 @@ +#ifndef __AngelaCommon_h_ +#define __AngelaCommon_h_ + +#ifdef ANGELA +#define ANGELA_DLLSPEC Q_DECL_EXPORT +#elif defined(ANGELA_LIB) +#define ANGELA_DLLSPEC +#else +#define ANGELA_DLLSPEC Q_DECL_IMPORT +#endif + +#include +#include "AngelaEnum.h" + +#endif diff --git a/src/lpMain/algela/AngelaEnum.h b/src/lpMain/algela/AngelaEnum.h new file mode 100644 index 0000000..83be67c --- /dev/null +++ b/src/lpMain/algela/AngelaEnum.h @@ -0,0 +1,36 @@ +/*! + * \file AngelaEnum.h + * \date 2018/07/06 + * + * \author Lin, Chi + * Contact: lin.chi@hzleaper.com + * + * + * \note +*/ + +#ifndef __AngelaEnum_h_ +#define __AngelaEnum_h_ + +enum AwesomeRoiType { + AwsRoiReserved = 0, + + AwsRoiRect, + AwsRoiAffine, + AwsRoiPoint, + + AwsRoiLast +}; + +enum DataVizType { + DataVizReserved = 0, + + DataVizLine, + DataVizBar, + DataVizDistribute, + + DataVizLast +}; + +#endif // AngelaEnum_h_ + diff --git a/src/lpMain/algela/AwesomeAffineRoi.cpp b/src/lpMain/algela/AwesomeAffineRoi.cpp new file mode 100644 index 0000000..935ba1c --- /dev/null +++ b/src/lpMain/algela/AwesomeAffineRoi.cpp @@ -0,0 +1,280 @@ +/*! + * \file AwesomeAffineRoi.cpp + * \date 2018/07/05 + * + * \author Lin, Chi + * Contact: lin.chi@hzleaper.com + * + * + * \note +*/ + +#include "AwesomeRoi.h" +#include "qtUtils.h" +#include +#include + +AwesomeAffineRoi::AwesomeAffineRoi(AwesomeRoiCommonProps* pProps, const AffineRect& arect, QGraphicsItem* parent) + : AwesomeRoiBase(pProps, AwesomeRoiType::AwsRoiAffine), QGraphicsPolygonItem(parent), + mEnablePerspective(true) +{ + setAffineRect(arect); + setAcceptHoverEvents(true); + updateZValue(); +} + +void AwesomeAffineRoi::setAffineRect(const AffineRect& arect) +{ + mRealPoly.clear(); + mRealPoly << arect[0] << arect[1] << arect[2] << arect[3] << arect[0]; // close it + qreal shink = getSenseRng() / 4; + QPolygonF outterPoly = affineRectToPoly(arect, -shink); + mInnerPoly = affineRectToPoly(arect, shink); + mBorderLeftPoly = affineBorderToPoly(arect[0], arect[3], shink, true); + mBorderRightPoly = affineBorderToPoly(arect[1], arect[2], shink, true); + mBorderTopPoly = affineBorderToPoly(arect[0], arect[1], shink, false); + mBorderBottomPoly = affineBorderToPoly(arect[2], arect[3], shink, false); + + prepareGeometryChange(); + setPolygon(outterPoly); + mRealAffineRect = arect; + setTransformOriginPoint(getPolygonCenter(mInnerPoly)); +} + +void AwesomeAffineRoi::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) +{ + PaintScopeGuard psg(painter); // ensure painter is not ruined by our changes in this pain function + QColor c = getPaintColor(widget); + qreal roiWidth = getRoiWidth(); + painter->setPen(QPen(c, roiWidth, Qt::SolidLine)); + painter->setBrush(Qt::NoBrush); + painter->drawPolygon(mRealPoly); + if (doRichPaint()) { + painter->setPen(QPen(c.lighter(), roiWidth * 2, Qt::SolidLine)); + for (int i = 0; i < 4; ++i) { + painter->drawPoint(mRealAffineRect[i]); + painter->drawPoint((mRealAffineRect[i] + mRealAffineRect[i == 3 ? 0 : i + 1]) / 2); + } + } +} + +QPainterPath AwesomeAffineRoi::shape() const +{ + return QGraphicsPolygonItem::shape(); + QPainterPath path; + path.setFillRule(Qt::WindingFill); + if (isRoiActive()) + path.addPolygon(polygon()); + else + { + path.addPolygon(mBorderLeftPoly); + path.addPolygon(mBorderRightPoly); + path.addPolygon(mBorderTopPoly); + path.addPolygon(mBorderBottomPoly); + } + return path; +} + +void AwesomeAffineRoi::mouseMoveEvent(QGraphicsSceneMouseEvent* e) +{ + if (mAffineDir.any()) { + if (mAffineDir.target == AffineDirections::Corner) { + // for corner case, we need to decide the true direction using delta mouse movement + qreal xmove = abs(e->pos().x() - mPreMPos.x()); + qreal ymove = abs(e->pos().y() - mPreMPos.y()); + AffineDirections dir = mAffineDir; + dir.decideCorner(ymove > xmove); + adjustAffine(mAdjBaseAffineRect, + e->pos().x() - mAdjBaseAffineRect[mAffineDir.cornerIdx].x(), + e->pos().y() - mAdjBaseAffineRect[mAffineDir.cornerIdx].y(), dir); + } + else { + adjustAffine(mRealAffineRect, e->pos().x() - mPreMPos.x(), + e->pos().y() - mPreMPos.y(), mAffineDir); + + mPreMPos = e->pos(); + } + emit roiChanged(); + } + else { + QGraphicsPolygonItem::mouseMoveEvent(e); + } +} + +void AwesomeAffineRoi::mousePressEvent(QGraphicsSceneMouseEvent* e) +{ + Qt::KeyboardModifiers k = QApplication::queryKeyboardModifiers(); + bool newSelected = k.testFlag(Qt::ShiftModifier) || k.testFlag(Qt::ControlModifier) ? !isRoiPicked() : true; + setRoiPicked(newSelected); + + const QPointF& mpos = e->pos(); + mAffineDir = getAffineDir(mpos.x(), mpos.y()); + mPreMPos = e->pos(); + + if (!mAffineDir.any()) { + QGraphicsPolygonItem::mousePressEvent(e); + } + else { + mAdjBaseAffineRect = mRealAffineRect; + } +} + +void AwesomeAffineRoi::mouseReleaseEvent(QGraphicsSceneMouseEvent* e) +{ + mAffineDir.reset(); + QGraphicsPolygonItem::mouseReleaseEvent(e); +} + + +void AwesomeAffineRoi::hoverMoveEvent(QGraphicsSceneHoverEvent* e) +{ + if (!mAffineDir.any()) { + const QPointF& mpos = e->pos(); + updateCursor(mpos.x(), mpos.y()); + setRoiActive(true); + } +} + +void AwesomeAffineRoi::hoverLeaveEvent(QGraphicsSceneHoverEvent* e) +{ + setSceneCursor(scene(), Qt::ArrowCursor); + setRoiActive(false); +} + +QList AwesomeAffineRoi::getVertex() const +{ + QList ret; + ret << mRealAffineRect[0] << mRealAffineRect[1] << mRealAffineRect[2] << mRealAffineRect[3]; + return ret; +} + +void AwesomeAffineRoi::updateSenseRng() +{ + setAffineRect(mRealAffineRect); +} + +QPolygonF AwesomeAffineRoi::affineRectToPoly(const AffineRect& affineRect, qreal shink) +{ + QPolygonF ret; + ret << affineRect[0] + QPointF(shink, shink) << affineRect[1] + QPointF(-shink, shink) + << affineRect[2] + QPointF(-shink, -shink) << affineRect[3] + QPointF(shink, -shink) + << affineRect[0] + QPointF(shink, shink); // close it + return ret; +} + +QPolygonF AwesomeAffineRoi::affineBorderToPoly(const QPointF& p1, const QPointF& p2, qreal shink, bool vertical) +{ + QPolygonF ret; + if (vertical) { + ret << p1 + QPointF(-shink, 0) << p1 + QPointF(shink, 0) + << p2 + QPointF(shink, 0) << p2 + QPointF(-shink, 0) << p1 + QPointF(-shink, 0); + } + else { + ret << p1 + QPointF(0, -shink) << p1 + QPointF(0, shink) + << p2 + QPointF(0, shink) << p2 + QPointF(0, -shink) << p1 + QPointF(0, -shink); + } + return ret; +} + +AffineDirections AwesomeAffineRoi::getAffineDir(qreal x, qreal y) +{ + QPointF mpos(x, y); + AffineDirections affineDir; + if (mInnerPoly.containsPoint(mpos, Qt::WindingFill)) + return affineDir; + + if (mEnablePerspective) { + for (int i = 0; i < 4; i++) { + QPointF& c = mRealAffineRect[i]; + qreal cx = c.x(), cy = c.y(); + qreal s = getSenseRng(); + if (x >= cx - s && x <= cx + s && + y >= cy - s && y <= cy + s) { + // at the corner + affineDir.mode = AffineDirections::Sym; + affineDir.target = AffineDirections::Corner; + affineDir.cornerIdx = i; + return affineDir; + } + } + } + + // left border + if (mBorderLeftPoly.containsPoint(mpos, Qt::WindingFill)) { + affineDir.mode = AffineDirections::Cut; + affineDir.target = AffineDirections::Left; + affineDir.cornerIdx = 0; + } + else if (mBorderRightPoly.containsPoint(mpos, Qt::WindingFill)) { + affineDir.mode = AffineDirections::Cut; + affineDir.target = AffineDirections::Right; + affineDir.cornerIdx = 1; + } + else if (mBorderTopPoly.containsPoint(mpos, Qt::WindingFill)) { + affineDir.mode = AffineDirections::Cut; + affineDir.target = AffineDirections::Top; + affineDir.cornerIdx = 0; + } + else if (mBorderBottomPoly.containsPoint(mpos, Qt::WindingFill)) { + affineDir.mode = AffineDirections::Cut; + affineDir.target = AffineDirections::Bottom; + affineDir.cornerIdx = 3; + } + + return affineDir; +} + +void AwesomeAffineRoi::updateCursor(qreal x, qreal y) +{ + AffineDirections affineDir = getAffineDir(x, y); + setSceneCursor(scene(), affineDir.getCursorShape()); +} + +void AwesomeAffineRoi::adjustAffine(const AffineRect& baseAffineRect, qreal deltaX, qreal deltaY, AffineDirections dir) +{ + qreal sin, cos, len; + qreal expand; + int coorIdx; + bool isShink = false; + if (dir.target == AffineDirections::Top) { + prepareCosSin(baseAffineRect[0], baseAffineRect[1], cos, sin, len); + expand = deltaX; + coorIdx = 1 - dir.cornerIdx; + isShink = (dir.cornerIdx == 0 && expand > 0) || (dir.cornerIdx == 1 && expand < 0); + } + else if (dir.target == AffineDirections::Bottom) { + prepareCosSin(baseAffineRect[3], baseAffineRect[2], cos, sin, len); + expand = deltaX; + coorIdx = 5 - dir.cornerIdx; + isShink = (dir.cornerIdx == 3 && expand > 0) || (dir.cornerIdx == 2 && expand < 0); + } + else if (dir.target == AffineDirections::Left) { + prepareCosSin(baseAffineRect[0], baseAffineRect[3], cos, sin, len); + expand = deltaY; + coorIdx = 3 - dir.cornerIdx; + isShink = (dir.cornerIdx == 0 && expand > 0) || (dir.cornerIdx == 3 && expand < 0); + } + else { + Q_ASSERT(dir.target == AffineDirections::Right); + prepareCosSin(baseAffineRect[1], baseAffineRect[2], cos, sin, len); + expand = deltaY; + coorIdx = 3 - dir.cornerIdx; + isShink = (dir.cornerIdx == 1 && expand > 0) || (dir.cornerIdx == 2 && expand < 0); + } + + len -= 2; + if (dir.mode == AffineDirections::Sym) { + if (isShink && abs(expand * 2) > len) + expand = expand > 0 ? len / 2. : -len / 2.; + } + + qreal expand_x = expand * cos; + qreal expand_y = expand * sin; + AffineRect ar = baseAffineRect; + ar[dir.cornerIdx] += QPointF(expand_x, expand_y); + if (dir.mode == AffineDirections::Sym) + ar[coorIdx] += QPointF(-expand_x, -expand_y); + else + ar[coorIdx] += QPointF(expand_x, expand_y); + setAffineRect(ar); +} diff --git a/src/lpMain/algela/AwesomeImgViewer.cpp b/src/lpMain/algela/AwesomeImgViewer.cpp new file mode 100644 index 0000000..234e128 --- /dev/null +++ b/src/lpMain/algela/AwesomeImgViewer.cpp @@ -0,0 +1,797 @@ +/*! + * \file AwesomeImgViewer.cpp + * \date 2018/06/26 + * + * \author Lin, Chi + * Contact: lin.chi@hzleaper.com + * + * + * \note +*/ + +#include "AwesomeImgViewer.h" +#include "AwesomeRoi.h" +#include "qtUtils.h" +#include +#include +#include + +AwesomeImgViewer::AwesomeImgViewer(QWidget* parent) + : lpImgViewer(parent), mOpState(Reserved), mRoiCounter(0), mRestrictMode(false), mHasImg(false), + mpMaskImgItem(nullptr), mpMaskImg(nullptr) +{ + setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + setRenderHint(QPainter::HighQualityAntialiasing); +} + +QGraphicsPixmapItem* AwesomeImgViewer::setImg(QImage& img) +{ + QGraphicsPixmapItem* ret = lpImgViewer::setImg(img); + mHasImg = true; + mpImgItem->setFlag(QGraphicsItem::ItemIsMovable, true); + + refreshSenseRng(); + + // refresh restrict area + if (mRestrictMode) { + for(QMap::iterator it = mMapRoiItems.begin();it!=mMapRoiItems.end();++it) + { + (*it)->setRestricArea(mpImgItem->boundingRect().adjusted(1, 1, -1, -1)); + } + } + + return ret; +} + +QGraphicsPixmapItem* AwesomeImgViewer::setMaskImg(QImage& maskImg) +{ + if (mpMaskImg) + delete mpMaskImg; + mpMaskImg = new QImage(maskImg); + + if (!mpMaskImgItem) + mpMaskImgItem = scene()->addPixmap(QPixmap::fromImage(maskImg, Qt::NoFormatConversion)); + else + mpMaskImgItem->setPixmap(QPixmap::fromImage(maskImg, Qt::NoFormatConversion)); + + mpMaskImgItem->setParentItem(mpImgItem); + mpMaskImgItem->setOffset(mpImgItem->offset()); + + return mpMaskImgItem; +} + +void AwesomeImgViewer::addRectRoi( + const QPointF& pos, + const QSizeF& size, + double angle, + const QString& label, + const QColor& color, + const QColor& activeColor) +{ + QPointF offset = mpImgItem ? mpImgItem->offset() : QPointF(); + + AwesomeRectRoi* rectRoi = new AwesomeRectRoi(&mCommonProps, QSizeF(abs(size.width()), abs(size.height())), mpImgItem); + if (size.width() < 0 || size.height() < 0) + rectRoi->setRoiSift(true); + rectRoi->setPos(pos + offset); + addRoiCommon(rectRoi, label, color, activeColor); + rectRoi->getGraphicsItem()->setRotation(angle); // should be the last one + //rectRoi->setRoiPicked(false); +} + +void AwesomeImgViewer::addAffineRoi(const QPointF& tl, const QPointF& tr, const QPointF& br, const QPointF& bl, + const QString& label, const QColor& color, const QColor& activeColor) +{ + AffineRect ar = {tl, tr, br, bl}; + AwesomeAffineRoi* affineRoi = new AwesomeAffineRoi(&mCommonProps, ar, mpImgItem); + addRoiCommon(affineRoi, label, color, activeColor); +} + +void AwesomeImgViewer::addPointRoi(const QPointF& pos, double r, double angle, + const QString& label, const QColor& color, const QColor& activeColor) +{ + AwesomePointRoi* pointRoi = new AwesomePointRoi(&mCommonProps, abs(r), mpImgItem); + if (r < 0) pointRoi->setRoiSift(true); + pointRoi->setPos(pos); + if (angle != DBL_MAX) + pointRoi->setAngle(angle); + addRoiCommon(pointRoi, label, color, activeColor); +} + +void AwesomeImgViewer::mousePressEvent(QMouseEvent* e) +{ + setCursor(Qt::PointingHandCursor); + { + if (mOpState == Reserved && mHasImg) { + QPoint curpos = (mpImgItem->mapFromScene(this->mapToScene(e->pos())) + + QPointF(mImgOriSize.width() / 2.0, mImgOriSize.height() / 2.0) + QPointF(-0.5, -0.5)).toPoint(); + if (curpos.x() >= 0 && curpos.x() < mImgOriSize.width() && curpos.y() >= 0 && curpos.y() < mImgOriSize.height()) { + // report pixel clicked when it's inside the image + emit pixelClicked(curpos); + } + } + } + if (mOpState == Prepared) { + addMousePos2AddingPnt(e, 0); + mOpState = Adding; + clearSelection(); + } + else if (mOpState == Picking && mHasImg) { + QPoint curpos = (mpImgItem->mapFromScene(this->mapToScene(e->pos())) + + QPointF(mImgOriSize.width() / 2.0, mImgOriSize.height() / 2.0) + QPointF(-0.5, -0.5)).toPoint(); + if (curpos.x() >= 0 && curpos.x() < mImgOriSize.width() && curpos.y() >= 0 && curpos.y() < mImgOriSize.height()) { + // report pixel clicked when it's inside the image + emit pixelClicked(curpos); + } + } + else { + // clear selection if click on empty place + QPointF mpos = getMousePos(e); + bool doClear = true; + for (QMap::iterator roiItem = mMapRoiItems.begin(); roiItem != mMapRoiItems.end(); ++roiItem) + { + QGraphicsItem* pItem = (*roiItem)->getGraphicsItem(); + if ((*roiItem)->senseRect().contains(pItem->mapFromParent(mpos))) { + doClear = false; + if (mCommonProps.siftMode) { + setCursor(Qt::PointingHandCursor); + mCommonProps.isSifting = (*roiItem)->isRoiPicked() ? -1 : 1; + (*roiItem)->setRoiPicked(!(*roiItem)->isRoiPicked()); + } + break; + } + } + if (doClear) + clearSelection(); + + lpImgViewer::mousePressEvent(e); + } +} + +void AwesomeImgViewer::mouseMoveEvent(QMouseEvent* e) +{ + if (mOpState == Adding) { + addMousePos2AddingPnt(e, 1); + } + else if (mCommonProps.isSifting != 0) { + QPointF mpos = getMousePos(e); + bool doPicked = mCommonProps.isSifting > 0; + for (QMap::iterator roiItem = mMapRoiItems.begin(); roiItem != mMapRoiItems.end(); ++roiItem) + { + QGraphicsItem* gItem = (*roiItem)->getGraphicsItem(); + if ((*roiItem)->isRoiPicked() != doPicked && gItem->boundingRect().contains(gItem->mapFromParent(mpos))) { + (*roiItem)->setRoiPicked(doPicked); + } + } + } + else { + lpImgViewer::mouseMoveEvent(e); + } +} + +void AwesomeImgViewer::mouseReleaseEvent(QMouseEvent* e) +{ + if (mOpState == Adding) { + addMousePos2AddingPnt(e, 1); + if (mAddingType == AwsRoiRect) + addRectRoi((mAddingPnts[0] + mAddingPnts[1]) / 2, + QSizeF(abs(mAddingPnts[0].x() - mAddingPnts[1].x()), abs(mAddingPnts[0].y() - mAddingPnts[1].y()))); + else if (mAddingType == AwsRoiAffine) { + qreal l = std::min(mAddingPnts[0].x(), mAddingPnts[1].x()); + qreal r = std::max(mAddingPnts[0].x(), mAddingPnts[1].x()); + qreal t = std::min(mAddingPnts[0].y(), mAddingPnts[1].y()); + qreal b = std::max(mAddingPnts[0].y(), mAddingPnts[1].y()); + addAffineRoi(QPointF(l, t), QPointF(r, t), QPointF(r, b), QPointF(l, b)); + } + else if (mAddingType == AwsRoiPoint) { + QPointF away = getMousePos(e) - mAddingPnts.front(); + if (abs(away.x()) + abs(away.y()) < 4) { + addPointRoi(mAddingPnts.front(), 2); + } + } + resetAdding(); + } + else if (mCommonProps.isSifting != 0) { + setCursor(Qt::ArrowCursor); + mCommonProps.isSifting = 0; + } + else if (mOpState != Picking) { + setIsAddingRoi(false); + } + + lpImgViewer::mouseReleaseEvent(e); +} + +void AwesomeImgViewer::wheelEvent(QWheelEvent* e) +{ + lpImgViewer::wheelEvent(e); + refreshSenseRng(); +} + +void AwesomeImgViewer::keyPressEvent(QKeyEvent* e) +{ + if (e->key() == Qt::Key_A && e->modifiers() == Qt::ControlModifier) { + for (QMap::iterator roiItem = mMapRoiItems.begin(); roiItem != mMapRoiItems.end(); ++roiItem) + { + (*roiItem)->setRoiPicked(true); + } + } + else if (e->key() == Qt::Key_Delete) { + onBtnDeleteClicked(); + } + else if (e->key() == Qt::Key_Insert) { + + } + else if (e->key() == Qt::Key_Escape && mOpState != Reserved) { + resetAdding(); + } + else { + lpImgViewer::keyPressEvent(e); + } +} + +void AwesomeImgViewer::getAllRoiVertex(QVector& allRoiInfo) +{ + for (QMap::iterator roiItem = mMapRoiItems.begin(); roiItem != mMapRoiItems.end(); ++roiItem) + { + AwesomeRoiInfo* pRoiInfo = allRoiInfo.insert(allRoiInfo.end(), AwesomeRoiInfo()); + getRoiInfo((*roiItem), *pRoiInfo); + } +} + +void AwesomeImgViewer::getDetectVertex(AwesomeRoiInfo& detectRoiInfo) +{ + for (QMap::iterator roiItem = mMapRoiItems.begin(); roiItem != mMapRoiItems.end(); ++roiItem) + { + if ((*roiItem)->objectName().contains("Detect")) + { + getRoiInfo((*roiItem), detectRoiInfo); + break; + } + } +} + +void AwesomeImgViewer::getAllFilterVertex(QList& allFilterRoiInfo) +{ + for (QMap::iterator roiItem = mMapRoiItems.begin(); roiItem != mMapRoiItems.end(); ++roiItem) + { + if ((*roiItem)->objectName().contains("Detect")) + continue; + AwesomeRoiInfo roiInfo; + getRoiInfo((*roiItem), roiInfo); + allFilterRoiInfo.append(roiInfo); + } +} + + +QMap> AwesomeImgViewer::getAllFilterVectorMap() +{ + QMap> rlt; + for (QMap::iterator roiItem = mMapRoiItems.begin(); roiItem != mMapRoiItems.end(); ++roiItem) + { + QString strID = (*roiItem)->objectName(); + if (strID.contains("Detect")) + continue; + + AwesomeRoiInfo roiInfo; + getRoiInfo((*roiItem), roiInfo); + QVector polygon; + for (int i = 0; i < roiInfo.vertex.size(); i++) { + polygon.append(roiInfo.vertex.at(i).toPoint()); + } + rlt.insert(strID, polygon); + } + return rlt; +} + +QStringList AwesomeImgViewer::getAllSiftRois() const +{ + QStringList allSiftRoiNames; +// foreach(AwesomeRoiBase* roiItem, mRoiItems) { +// if (roiItem->isRoiSift()) { +// allSiftRoiNames.append(roiItem->getLabel()); +// } +// } + return allSiftRoiNames; +} + +void AwesomeImgViewer::enableSingleDetectRoi(bool enable, const QPointF& centerpos, const QSizeF& size, qreal angle, const QString& label) +{ + enableSingleMode(enable);//清除所有ROI + if (enable) { + if (centerpos.isNull() || size.isEmpty()) { + QPixmap img = mpImgItem->pixmap(); + int w = std::max(std::max(100, img.width() / 5), std::max(100, img.height() / 5)); + addRectRoi(QPointF(w / 2. - 1, w / 2. - 1), QSizeF(w, w), angle, label, QColor(0, 200,0), QColor(0, 200, 111)); + } + else { + addRectRoi(centerpos, size, angle, label, QColor(0, 200, 0), QColor(0, 200, 111)); + } + } + m_detectRoiAngle = angle; +} + +void AwesomeImgViewer::enableSingleAffineRoiMode(bool enable, + const QPointF& tl, const QPointF& tr, const QPointF& br, const QPointF& bl, const QString& label) +{ + enableSingleMode(enable); + if (enable) { + QPixmap img = mpImgItem->pixmap(); + qreal x = img.width() / 2., y = img.height() / 2.; + addAffineRoi(tl.isNull() ? QPointF(-x, -y) : tl, tr.isNull() ? QPointF(x, -y) : tr, + br.isNull() ? QPointF(x, y) : br, bl.isNull() ? QPointF(-x, y) : bl, label); + } +} + +void AwesomeImgViewer::changeRoiRect(const QPointF& pos /*= QPointF()*/, const QSizeF& size /*= QSizeF()*/, const QString& label /*= ""*/) +{ + for (QMap::iterator it = mMapRoiItems.begin(); it != mMapRoiItems.end(); ++it) + { + if (it.key().contains("Detect")) + { + ((AwesomeRectRoi*)*it)->setPos(pos); + ((AwesomeRectRoi*)*it)->setRealRect(QRectF(-size.width() / 2, -size.height() / 2, size.width(), size.height())); + break; + } + } +} + +void AwesomeImgViewer::changeFilterRoiRect(const QPointF& pos /*= QPointF()*/, const QSizeF& size /*= QSizeF()*/, const QString& strName /*= ""*/) +{ + for (QMap::iterator it = mMapRoiItems.begin(); it != mMapRoiItems.end(); ++it) + { + if (it.key() == strName) + { + ((AwesomeRectRoi*)*it)->setPos(pos); + ((AwesomeRectRoi*)*it)->setRealRect(QRectF(-size.width() / 2, -size.height() / 2, size.width(), size.height())); + break; + } + } +} + +QStringList AwesomeImgViewer::getAllFilterNames() +{ + QStringList filterNames; + for (QMap::iterator roiItem = mMapRoiItems.begin(); roiItem != mMapRoiItems.end(); ++roiItem) + { + QString strObjName = (*roiItem)->objectName(); + if (strObjName.contains("Detect")) + continue; + filterNames.append(strObjName); + } + return filterNames; +} + +void AwesomeImgViewer::setFilterROISelect(QString strName) +{ + for (QMap::iterator roiItem = mMapRoiItems.begin(); roiItem != mMapRoiItems.end(); ++roiItem) + { + QString strN = (*roiItem)->objectName(); + if(strName == strN) + (*roiItem)->setRoiPicked(true); + else + (*roiItem)->setRoiPicked(false); + } +} + +void AwesomeImgViewer::changeRoiRectAngle(qreal angle /*= 0*/, const QString& label /*= ""*/) +{ + for (QMap::iterator it = mMapRoiItems.begin(); it != mMapRoiItems.end(); ++it) + { + if (it.key().contains("Detect")) + { + ((AwesomeRectRoi*)*it)->getGraphicsItem()->setRotation(angle); + m_detectRoiAngle = angle; + } + else { + ((AwesomeRectRoi*)*it)->getGraphicsItem()->setRotation(angle); + } + } +} + +void AwesomeImgViewer::enableSiftMode(bool enable) +{ + mCommonProps.siftMode = enable; + if (mCommonProps.siftMode) { + for (QMap::iterator roiItem = mMapRoiItems.begin(); roiItem != mMapRoiItems.end(); ++roiItem) + { + (*roiItem)->getGraphicsItem()->setFlag(QGraphicsItem::ItemIsMovable, false); + } + } +} + +void AwesomeImgViewer::enablePickMode(bool enable) +{ + if (!mHasImg) return; + + if (enable) { + mpImgItem->setFlag(QGraphicsItem::ItemIsMovable, false); + static QPixmap pipettePixmap(":/cursor_pipette.png"); + setCursor(QCursor(pipettePixmap, 4, 26)); + mOpState = OpState::Picking; + } + else { + mpImgItem->setFlag(QGraphicsItem::ItemIsMovable, true); + setCursor(Qt::ArrowCursor); + mOpState = OpState::Reserved; + } +} + +void AwesomeImgViewer::setLabelVisible(bool visible) +{ + if (visible) { + for (QMap::iterator roiItem = mMapRoiItems.begin(); roiItem != mMapRoiItems.end(); ++roiItem) + { + (*roiItem)->showLabel(); + } + } + else { + for (QMap::iterator roiItem = mMapRoiItems.begin(); roiItem != mMapRoiItems.end(); ++roiItem) + { + (*roiItem)->hideLabel(); + } + } +} + +void AwesomeImgViewer::enableRoiCtrl(bool enable, const QList& enableRoiTypes) +{ +// ui->wgtRoiCtrl->setVisible(enable); +// mpCtrlBar->adjustSize(); +// if (enableRoiTypes.size() > 0) { +// int c = ui->comboRoiType->count(); +// for (int i = c - 1; i >= 0; --i) { +// int t = ui->comboRoiType->itemData(i).toInt(); +// if (enableRoiTypes.indexOf(static_cast(t)) < 0) { +// ui->comboRoiType->removeItem(i); +// } +// } +// } +} + +void AwesomeImgViewer::clear() +{ + lpImgViewer::clear(); + mMapRoiItems.clear(); + mAddingPnts.clear(); + mAddingType = AwsRoiReserved; + + // set null image to init the root image item + QImage img_root = QImage(":/imagena.png"); + setImg(img_root); + + mpAddingPath = new QGraphicsPathItem(mpImgItem); + mpAddingPath->setPen(QPen(QColor(20, 20, 20), 1, Qt::DashLine)); + + mHasImg = false; + mpImgItem->setFlag(QGraphicsItem::ItemIsMovable, false); // disable moving placeholder image + + mpMaskImgItem = nullptr; + if (mpMaskImg) { + delete mpMaskImg; + mpMaskImg = nullptr; + } +} + +void AwesomeImgViewer::onResetView() +{ + scaleImg2(1.0); + setIsAutoResetTransform(true); +} + +void AwesomeImgViewer::onSetScale(qreal val) +{ + scaleImg2(1.0); +} + +void AwesomeImgViewer::onClearAllROI() +{ + enableSingleMode(true); +} + +void AwesomeImgViewer::onAddFilterROI(const QPointF& pos /*= QPointF()*/, const QSizeF& size /*= QSizeF()*/, qreal angle /*= 0*/, const QString& label /*= ""*/) +{ + angle = m_detectRoiAngle; + if (pos.isNull() || size.isEmpty()) { + QPixmap img = mpImgItem->pixmap(); + int w = std::min(std::max(50, img.width()), std::max(50, img.height())); + addRectRoi(QPointF(w / 2. - 1, w / 2. - 1), QSizeF(w, w), angle, label, QColor(230, 200, 0), QColor(230, 200, 111)); + } + else { + addRectRoi(pos, size, angle, label, QColor(230, 200, 0), QColor(230, 200, 111)); + } +} + +void AwesomeImgViewer::onClearFilterROIs(const QString& label /*= "Filter"*/) +{ + QStringList lstName; + for (QMap::iterator roiItem = mMapRoiItems.begin(); roiItem != mMapRoiItems.end(); ++roiItem) + { + QString strName = (*roiItem)->objectName(); + if (!strName.contains("Filter")) + continue; + scene()->removeItem((*roiItem)->getGraphicsItem()); + delete (*roiItem); + lstName.append(strName); + } + foreach(QString var, lstName) + { + mMapRoiItems.remove(var); + } +} + +void AwesomeImgViewer::onBtnAddClicked(bool isChecked) +{ + // no add op in single roi mode + if (mCommonProps.singleRoiMode) return; + + if (mCommonProps.siftMode) { + for (QMap::iterator roiItem = mMapRoiItems.begin(); roiItem != mMapRoiItems.end(); ++roiItem) + { + if ((*roiItem)->isRoiPicked()) { + (*roiItem)->setRoiSift(false); + (*roiItem)->setRoiPicked(false); // un-pick + (*roiItem)->setRoiActive(false); // un-active + } + } + } + else + { +// mAddingType = static_cast(ui->comboRoiType->currentData().toInt()); +// if (mAddingType <= AwsRoiReserved || mAddingType >= AwsRoiLast) return; +// setIsAddingRoi(isChecked); + } +} + +void AwesomeImgViewer::onBtnDeleteClicked() +{ + // no delete op in single roi mode +// if (mCommonProps.singleRoiMode || mCommonProps.siftMode) return; +// +// for (int i = mRoiItems.size() - 1; i >= 0; i--) { +// AwesomeRoiBase* roiItem = mRoiItems[i]; +// if (roiItem->isRoiPicked()) { +// mRoiItems.remove(i); +// scene()->removeItem(roiItem->getGraphicsItem()); +// delete roiItem; +// } +// } +// unsetCursor(); +} + +void AwesomeImgViewer::onBtnSubClicked(bool isChecked) +{ + // no add op in single roi mode +// if (mCommonProps.singleRoiMode) return; +// +// if (mCommonProps.siftMode) { +// foreach(AwesomeRoiBase* roiItem, mRoiItems) { +// if (roiItem->isRoiPicked()) { +// roiItem->setRoiSift(true); +// roiItem->setRoiPicked(false); // un-pick +// roiItem->setRoiActive(false); // un-active +// } +// } +// } +} + +void AwesomeImgViewer::onBtnHideRoiPressed() +{ + // hide all roi + for (QMap::iterator roiItem = mMapRoiItems.begin(); roiItem != mMapRoiItems.end(); ++roiItem) + { + (*roiItem)->getGraphicsItem()->hide(); + } +} + +void AwesomeImgViewer::onBtnHideRoiReleased() +{ + // show all roi + for (QMap::iterator roiItem = mMapRoiItems.begin(); roiItem != mMapRoiItems.end(); ++roiItem) + { + (*roiItem)->getGraphicsItem()->show(); + } +} + +void AwesomeImgViewer::onRoiSelected(bool isSelected) +{ + if (isSelected && mCommonProps.isSifting == 0) { + Qt::KeyboardModifiers k = QApplication::queryKeyboardModifiers(); + if (!k.testFlag(Qt::ShiftModifier) && !k.testFlag(Qt::ControlModifier)) { + // not multi-select, clear other selection + clearSelection(sender()); + } + } +} + +void AwesomeImgViewer::onRoiChanged() +{ + AwesomeRoiInfo roiInfo; + AwesomeRoiBase* roiItem = qobject_cast(sender()); + if (roiItem&&roiItem->objectName().contains("Detect")) { + getRoiInfo(roiItem, roiInfo); + emit roiChanged(roiInfo); + } + else + { + getRoiInfo(roiItem, roiInfo); + QString strObj = roiItem->objectName(); + emit filterroiChanged(roiInfo, strObj); + } +} + +void AwesomeImgViewer::onRoiLockIng() +{ + AwesomeRoiBase* roiItem = qobject_cast(sender()); + QString strName = roiItem->objectName(); + emit roiLockIng(strName); +} + +void AwesomeImgViewer::addRoiCommon( + AwesomeRoiBase* roiItem, + const QString& label, + const QColor& color, + const QColor& activeColor +) +{ + if (color.isValid()) + roiItem->setNormalColor(color); + else if (mDefaultColor.isValid()) + roiItem->setNormalColor(mDefaultColor); + if (activeColor.isValid()) + roiItem->setActiveColor(activeColor); + else if (mDefaultActiveColor.isValid()) + roiItem->setActiveColor(mDefaultActiveColor); + + mRoiCounter++; + if (label.isNull()) + roiItem->setLabel(QString::number(mRoiCounter)); + else + roiItem->setLabel(label); + QString strObjname = QString("%1").arg(label); + roiItem->setObjectName(strObjname); + if (mRestrictMode) + roiItem->setRestricArea(mpImgItem->boundingRect().adjusted(1, 1, -1, -1)); + + connect(roiItem, SIGNAL(toggledPick(bool)), this, SLOT(onRoiSelected(bool))); + connect(roiItem, SIGNAL(roiChanged()), this, SLOT(onRoiChanged())); + connect(roiItem, SIGNAL(roiLockIng()), this, SLOT(onRoiLockIng())); + + mMapRoiItems.insert(strObjname, roiItem); +} + +void AwesomeImgViewer::setIsAddingRoi(bool isAddingRoi) +{ + mOpState = isAddingRoi ? Prepared : Reserved; + if (isAddingRoi) + { + setCursor(Qt::CrossCursor); + for (QMap::iterator roiItem = mMapRoiItems.begin(); roiItem != mMapRoiItems.end(); ++roiItem) + { + QGraphicsItem* gItem = (*roiItem)->getGraphicsItem(); + gItem->setEnabled(false); + } + } + else + { + setCursor(Qt::ArrowCursor); + for (QMap::iterator roiItem = mMapRoiItems.begin(); roiItem != mMapRoiItems.end(); ++roiItem) + { + QGraphicsItem* gItem = (*roiItem)->getGraphicsItem(); + gItem->setEnabled(true); + } + } +} + +QPointF AwesomeImgViewer::getMousePos(QMouseEvent* e) +{ + if (mpImgItem) + return mpImgItem->mapFromScene(this->mapToScene(e->pos())); + return QPointF(); +} + +void AwesomeImgViewer::addMousePos2AddingPnt(QMouseEvent* e, int idx) +{ + if (mAddingPnts.size() <= idx || idx == -1) + mAddingPnts.append(getMousePos(e)); + else + mAddingPnts[idx] = getMousePos(e); + updateAddingPath(); +} + +void AwesomeImgViewer::updateAddingPath() +{ + if (mAddingPnts.size() == 0) + mpAddingPath->setPath(QPainterPath()); + else + { + QPainterPath p; + if ((mAddingType == AwsRoiRect || mAddingType == AwsRoiAffine) && mAddingPnts.size() >= 2) { + p.addRect(std::min(mAddingPnts[0].x(), mAddingPnts[1].x()), + std::min(mAddingPnts[0].y(), mAddingPnts[1].y()), + abs(mAddingPnts[0].x() - mAddingPnts[1].x()), + abs(mAddingPnts[0].y() - mAddingPnts[1].y())); + } + else if (mAddingType == AwsRoiPoint && mAddingPnts.size() >= 1) { + p.addEllipse(mAddingPnts.front(), 2, 2); + } + mpAddingPath->setPath(p); + } +} + +void AwesomeImgViewer::resetAdding() +{ + mOpState = Reserved; + mAddingPnts.clear(); + updateAddingPath(); +} + +void AwesomeImgViewer::clearSelection(QObject* excludeObj) +{ + for (QMap::iterator roiItem = mMapRoiItems.begin(); roiItem != mMapRoiItems.end(); ++roiItem) + { + if ((*roiItem) != excludeObj) + (*roiItem)->setRoiPicked(false); + } +} + +void AwesomeImgViewer::getRoiOnImg(AwesomeRoiBase* roiItem, QList& roiOnImg) +{ + const QList& pnts = roiItem->getVertex(); + QGraphicsItem* gItem = roiItem->getGraphicsItem(); + foreach(const QPointF& pnt, pnts) { + roiOnImg.append(gItem->mapToParent(pnt) - mpImgItem->offset()); // roi item's parent is the image. + } +} + +void AwesomeImgViewer::getRoiInfo(AwesomeRoiBase* roiItem, AwesomeRoiInfo& roiInfo) +{ + roiInfo.type = roiItem->getRoiType(); + roiInfo.label = roiItem->getLabel(); + getRoiOnImg(roiItem, roiInfo.vertex); +} + +void AwesomeImgViewer::enableSingleMode(bool enable) +{ + mCommonProps.singleRoiMode = enable; + if (enable) { + // delete all roi + for (QMap::iterator roiItem = mMapRoiItems.begin(); roiItem != mMapRoiItems.end(); ++roiItem) + { + scene()->removeItem((*roiItem)->getGraphicsItem()); + delete (*roiItem); + } + mMapRoiItems.clear(); + } +} + +float AwesomeImgViewer::getSenseRng() +{ + QPointF a = mapToScene(QPoint(0, 15)); + QPointF b = mapToScene(QPoint(0, 0)); + return abs(a.y() - b.y()); +} + +void AwesomeImgViewer::refreshSenseRng() +{ + if (mpImgItem) { + mCommonProps.senseRng = getSenseRng(); + mCommonProps.labelFont = QApplication::font(); + QFontMetricsF metrics(mCommonProps.labelFont); + float factor = (mCommonProps.senseRng - 0.5) / metrics.height(); + mCommonProps.labelFont.setPointSizeF(mCommonProps.labelFont.pointSizeF() * factor); + + for (QMap::iterator roiItem = mMapRoiItems.begin(); roiItem != mMapRoiItems.end(); ++roiItem) + { + (*roiItem)->updateSenseRng(); + } + } +} + +void AwesomeImgViewer::setLockAll(bool bLock) +{ + for (QMap::iterator roiItem = mMapRoiItems.begin(); roiItem != mMapRoiItems.end(); ++roiItem) + { + (*roiItem)->onSetLock(bLock); + } +} \ No newline at end of file diff --git a/src/lpMain/algela/AwesomeImgViewer.h b/src/lpMain/algela/AwesomeImgViewer.h new file mode 100644 index 0000000..71795e2 --- /dev/null +++ b/src/lpMain/algela/AwesomeImgViewer.h @@ -0,0 +1,183 @@ +/*! + * \file AwesomeImgViewer.h + * \date 2018/06/26 + * + * \author Lin, Chi + * Contact: lin.chi@hzleaper.com + * + * + * \note +*/ + +#ifndef __AwesomeImgViewer_h_ +#define __AwesomeImgViewer_h_ + +#include "AngelaEnum.h" +#include "lpImgViewer.h" +#include "AngelaEnum.h" +#include +#include + +struct AwesomeRoiInfo { + QString label; + QList vertex; + AwesomeRoiType type; +}; + +struct AwesomeRoiCommonProps +{ + qreal senseRng; + QFont labelFont; + bool singleRoiMode; + bool siftMode; + int isSifting; // 0: not sifting; 1: select; -1: unselect + AwesomeRoiCommonProps() : senseRng(8), singleRoiMode(false), + siftMode(false), isSifting(0) {} +}; + +class Ui_AwesomeImgViewerBar; +class AwesomeRoiBase; +class QPushButton; +class QGraphicsItem; +class AwesomeImgViewer : public lpImgViewer +{ + Q_OBJECT + +public: + AwesomeImgViewer(QWidget* parent = nullptr); + + QGraphicsPixmapItem* setImg(QImage& img); + + QGraphicsPixmapItem* setMaskImg(QImage& maskImg); + + void setDefaultColor(const QColor& color, const QColor& activeColor = QColor()) { + mDefaultColor = color; + mDefaultActiveColor = activeColor; + } + + void addRectRoi(const QPointF& pos, + const QSizeF& size = QSizeF(), + double angle = 0, + const QString& label = QString(), + const QColor& color = QColor(), + const QColor& activeColor = QColor()); + void addAffineRoi(const QPointF& tl, + const QPointF& tr, + const QPointF& br, + const QPointF& bl, + const QString& label = QString(), + const QColor& color = QColor(), + const QColor& activeColor = QColor()); + void addPointRoi(const QPointF& pos, + double r, + double angle = DBL_MAX, + const QString& label = QString(), + const QColor& color = QColor(), + const QColor& activeColor = QColor()); + + virtual void mousePressEvent(QMouseEvent* e); + virtual void mouseMoveEvent(QMouseEvent* e); + virtual void mouseReleaseEvent(QMouseEvent* e); + virtual void wheelEvent(QWheelEvent* e); + + virtual void keyPressEvent(QKeyEvent* e); + + void getAllRoiVertex(QVector& allRoiInfo); + void getDetectVertex(AwesomeRoiInfo& detectRoiInfo); + void getAllFilterVertex(QList& allFilterRoiInfo); + QMap> getAllFilterVectorMap(); + QStringList getAllSiftRois() const; + + void enableSingleDetectRoi(bool enable, + const QPointF& pos = QPointF(), + const QSizeF& size = QSizeF(), + qreal angle = 0, + const QString& label = "Detect"); + void enableSingleAffineRoiMode(bool enable, + const QPointF& tl = QPointF(), + const QPointF& tr = QPointF(), + const QPointF& br = QPointF(), + const QPointF& bl = QPointF(), + const QString& label = ""); + + void enableRestricMode(bool enable) { + mRestrictMode = enable; + } + + void changeRoiRect(const QPointF& pos = QPointF(), const QSizeF& size = QSizeF(), const QString& label = ""); + void changeFilterRoiRect(const QPointF& pos /*= QPointF()*/, const QSizeF& size /*= QSizeF()*/, const QString& strName /*= ""*/); + + QStringList getAllFilterNames(); + + void setFilterROISelect(QString strName); + + void changeRoiRectAngle(qreal angle = 0, const QString& label = ""); + void enableSiftMode(bool enable); + void enablePickMode(bool enable); + void setLabelVisible(bool visible); + + void enableRoiCtrl(bool enable, const QList& enableRoiTypes = QList()); + + virtual void clear(); + void onResetView(); + void onSetScale(qreal val); + + void onClearAllROI();//清除所有ROI + + void onAddFilterROI( + const QPointF& pos = QPointF(), + const QSizeF& size = QSizeF(), + qreal angle = 0, + const QString& label = "Filter"); + void onClearFilterROIs(const QString& label = "Filter"); + + void setLockAll(bool bLock); +signals: + void roiChanged(const AwesomeRoiInfo& roiInfo); + void filterroiChanged(const AwesomeRoiInfo& roiInfo,QString strID); + void imgRefreshClicked(); + void pixelClicked(QPoint pos); // when mouse press on this pixel + void roiLockIng(QString strID); +private slots: + void onBtnAddClicked(bool isChecked); + void onBtnDeleteClicked(); + void onBtnSubClicked(bool isChecked); + void onBtnHideRoiPressed(); + void onBtnHideRoiReleased(); + void onRoiSelected(bool isSelected); + void onRoiChanged(); + void onRoiLockIng(); +private: + void addRoiCommon(AwesomeRoiBase* roiItem, const QString& label, const QColor& color, const QColor& activeColor); + void setIsAddingRoi(bool isAddingRoi); + QPointF getMousePos(QMouseEvent* e); + void addMousePos2AddingPnt(QMouseEvent* e, int idx); + void updateAddingPath(); + void resetAdding(); + void clearSelection(QObject* excludeObj = nullptr); + void getRoiOnImg(AwesomeRoiBase* roiItem, QList& roiOnImg); + void getRoiInfo(AwesomeRoiBase* roiItem, AwesomeRoiInfo& roiInfo); + void enableSingleMode(bool enable); + float getSenseRng(); + void refreshSenseRng(); +private: + bool mHasImg; + QColor mDefaultColor; + QColor mDefaultActiveColor; + QMap mMapRoiItems; + enum OpState { Reserved, Prepared, Adding, Picking }; + OpState mOpState; + QList mAddingPnts; + AwesomeRoiType mAddingType; + QGraphicsPathItem* mpAddingPath; + + int mRoiCounter; + bool mRestrictMode; + AwesomeRoiCommonProps mCommonProps; + QGraphicsPixmapItem* mpMaskImgItem; + QImage* mpMaskImg{ nullptr }; + double m_detectRoiAngle{ 0.0 }; +}; + +#endif // AwesomeImgViewer_h_ + diff --git a/src/lpMain/algela/AwesomeImgViewerBar.ui b/src/lpMain/algela/AwesomeImgViewerBar.ui new file mode 100644 index 0000000..8afa449 --- /dev/null +++ b/src/lpMain/algela/AwesomeImgViewerBar.ui @@ -0,0 +1,231 @@ + + + AwesomeImgViewerBar + + + + 0 + 0 + 236 + 28 + + + + #AwesomeImgViewerBar{ +background-color:palette(window) +} + + + + 2 + + + 2 + + + 2 + + + 2 + + + 2 + + + + + + 2 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 50 + 22 + + + + + 60 + 22 + + + + + Rect + + + + + + + + + 0 + 0 + + + + + 24 + 24 + + + + + 24 + 24 + + + + Add + + + + + + + + 15 + 15 + + + + true + + + f067,white + + + f067 + + + + + + + + 0 + 0 + + + + + 24 + 24 + + + + + 24 + 24 + + + + Subtract + + + - + + + + 15 + 15 + + + + f068 + + + + + + + + 24 + 24 + + + + + 24 + 24 + + + + Delete + + + D + + + + 15 + 15 + + + + f2ed + + + + + + + + 24 + 24 + + + + + 24 + 24 + + + + Hide + + + H + + + + 14 + 14 + + + + true + + + f06e + + + f070,white + + + f070,gray + + + + + + + + + + + diff --git a/src/lpMain/algela/AwesomePointRoi.cpp b/src/lpMain/algela/AwesomePointRoi.cpp new file mode 100644 index 0000000..d3dfe42 --- /dev/null +++ b/src/lpMain/algela/AwesomePointRoi.cpp @@ -0,0 +1,178 @@ +/*! + * \file AwesomePointRoi.cpp + * \date 2018/11/29 + * + * \author Lin, Chi + * Contact: lin.chi@hzleaper.com + * + * + * \note +*/ + +#include "AwesomeRoi.h" + +#include +#include +#include +#include +#include +#include +#include +#include + +AwesomePointRoi::AwesomePointRoi(AwesomeRoiCommonProps* pProps, qreal r, QGraphicsItem* parent) + : AwesomeRoiBase(pProps, AwesomeRoiType::AwsRoiPoint), QGraphicsEllipseItem(parent), + mEnableRotate(false) +{ + setFlags(QGraphicsItem::ItemIsMovable); + setRealSize(r); + setAcceptHoverEvents(true); + updateZValue(); +} + +void AwesomePointRoi::setRealSize(qreal r) +{ + prepareGeometryChange(); + mRealCircle = QRectF(-r, -r, r * 2, r * 2); + setRect(mRealCircle); + setTransformOriginPoint(mRealCircle.center()); +} + +void AwesomePointRoi::setAngle(qreal angle) +{ + setRotation(angle); + mEnableRotate = true; +} + +void AwesomePointRoi::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) +{ + PaintScopeGuard psg(painter); // ensure painter is not ruined by our changes in this pain function + QColor c = getPaintColor(widget); + qreal roiWidth = getRoiWidth(); + painter->setPen(QPen(c, roiWidth, Qt::SolidLine)); + painter->setBrush(Qt::NoBrush); + painter->drawEllipse(mRealCircle); + + paintLabel2(painter, widget); + //qDebug() << "drawPoint"<setPen(QPen(c, roiWidth / 2, Qt::SolidLine)); + painter->drawLine(QPointF(0, -r), QPointF(0, r)); + painter->drawLine(QPointF(-r, 0), QPointF(r, 0)); + } +} + +void AwesomePointRoi::paintLabel2(QPainter* painter, QWidget* widget) +{ + if (!mShowLabel || mLabel.isEmpty()) return; + + QRectF r = getLabelRect2(); + QColor c = getPaintColor(widget); + painter->setBrush(QBrush(painter->pen().color(), Qt::SolidPattern)); + //painter->drawRect(r); + painter->setPen(QPen(c)); + //painter->setFont(getLabelFont()); + painter->drawText(r, Qt::AlignLeft | Qt::AlignVCenter, mLabel); +} + +QRectF AwesomePointRoi::getLabelRect2() const +{ + if (!mShowLabel || mLabel.isEmpty()) return QRectF(); + + QList vertexes = getVertex(); + QPointF basePnt; + if (vertexes.size() > 0) { + basePnt = vertexes[0]; + } + + QFontMetricsF metrics(getLabelFont()); + QRectF br = getGraphicsItem()->boundingRect(); + QSizeF s = metrics.size(Qt::TextSingleLine, mLabel); + qreal w = std::min(s.width(), br.right() - 0.5 - basePnt.x()); + qreal h = std::min(s.height(), basePnt.y() - 0.5 - br.top()); + + return QRectF(QPointF(basePnt.x(), basePnt.y()), QSizeF(15, 15)); +} +QPainterPath AwesomePointRoi::shape() const +{ + QPainterPath path; + path.addEllipse(rect()); + return path; +} + +QRectF AwesomePointRoi::boundingRect() const +{ + qreal roiWidth = getRoiWidth(); + qreal r = mRealCircle.width(); + return QRectF(QPointF(-r/2, -r), QSizeF(r, r*2)).adjusted(-roiWidth, -roiWidth, roiWidth, roiWidth); +} + +QList AwesomePointRoi::getVertex() const +{ + return QList() << mRealCircle.center(); +} + +void AwesomePointRoi::updateSenseRng() +{ + setRealSize(mRealCircle.width() / 2.); +} + +void AwesomePointRoi::mouseMoveEvent(QGraphicsSceneMouseEvent* e) +{ + if (mIsLock == true) + { + emit roiLockIng(); + return; + } + QGraphicsEllipseItem::mouseMoveEvent(e); + adjustToRestrict(); + emit roiChanged(); +} + +void AwesomePointRoi::mousePressEvent(QGraphicsSceneMouseEvent* e) +{ + Qt::KeyboardModifiers k = QApplication::queryKeyboardModifiers(); + bool newSelected = k.testFlag(Qt::ShiftModifier) || k.testFlag(Qt::ControlModifier) ? !isRoiPicked() : true; + setRoiPicked(newSelected); + + QGraphicsEllipseItem::mousePressEvent(e); +} + +void AwesomePointRoi::mouseReleaseEvent(QGraphicsSceneMouseEvent* e) +{ + QGraphicsEllipseItem::mouseReleaseEvent(e); +} + +void AwesomePointRoi::hoverMoveEvent(QGraphicsSceneHoverEvent* e) +{ + const QPointF& mpos = e->pos(); + updateCursor(mpos.x(), mpos.y()); + setRoiActive(true); +} + +void AwesomePointRoi::hoverLeaveEvent(QGraphicsSceneHoverEvent* e) +{ + setSceneCursor(scene(), Qt::ArrowCursor); + setRoiActive(false); +} + +void AwesomePointRoi::updateCursor(qreal x, qreal y) +{ + if (flags().testFlag(QGraphicsItem::ItemIsMovable)) + setSceneCursor(scene(), Qt::SizeAllCursor); +} + +bool AwesomePointRoi::adjustToRestrict() +{ + if (mRestritArea.isNull() || !mRestritArea.isValid()) return true; + + QPointF pnt = mapToParent(mRealCircle.center()); + QPointF shift = shiftToRestrict(pnt); + if (!shift.isNull()) { + moveBy(shift.x(), shift.y()); + return false; + } + + return true; +} diff --git a/src/lpMain/algela/AwesomeRectRoi.cpp b/src/lpMain/algela/AwesomeRectRoi.cpp new file mode 100644 index 0000000..3f4dc85 --- /dev/null +++ b/src/lpMain/algela/AwesomeRectRoi.cpp @@ -0,0 +1,321 @@ +/*! + * \file AwesomeRectRoi.cpp + * \date 2018/06/27 + * + * \author Lin, Chi + * Contact: lin.chi@hzleaper.com + * + * + * \note +*/ + +#include "AwesomeRoi.h" +#include + +#include +#include +#include +#include +#include +#include + +AwesomeRectRoi::AwesomeRectRoi(AwesomeRoiCommonProps* pProps, const QSizeF& s, QGraphicsItem* parent) + : AwesomeRoiBase(pProps, AwsRoiRect), QGraphicsRectItem(parent), mDoRotate(false) +{ + setFlags(QGraphicsItem::ItemIsMovable); + setRealRect(QRectF(-s.width()/2, -s.height()/2, s.width(), s.height())); + setAcceptHoverEvents(true); + //updateGraphicItemProps(this); + updateZValue(); +} + +void AwesomeRectRoi::updateSenseRng() +{ + setRealRect(mRealRect); +} + +void AwesomeRectRoi::setRealRect(const QRectF& r) +{ + prepareGeometryChange(); + qreal s = getSenseRng(); + setRect(r.adjusted(-s, -s, s, s)); + mRealRect = r; + qreal resizeSenseRng = s / 4; + mResizeInnerRect = r.adjusted(resizeSenseRng, resizeSenseRng, -resizeSenseRng, -resizeSenseRng); + mResizeOutterRect = r.adjusted(-resizeSenseRng, -resizeSenseRng, resizeSenseRng, resizeSenseRng); + setTransformOriginPoint(mRealRect.center()); +} + +void AwesomeRectRoi::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, + QWidget* widget) +{ + PaintScopeGuard psg(painter); // ensure painter is not ruined by our changes in this pain function + QColor c = getPaintColor(widget); + qreal roiWidth = 5;// getRoiWidth(); + painter->setPen(QPen(c, roiWidth, Qt::SolidLine)); + painter->setBrush(Qt::NoBrush); + painter->drawRect(mRealRect); +// if (mIsLock == true) +// return; + paintLabel(painter, widget); + if (doRichPaint()/*&& */) { + painter->setPen(QPen(c.lighter(), roiWidth*2, Qt::SolidLine)); + std::array pnts = { + mRealRect.topLeft(), mRealRect.topRight(), mRealRect.bottomRight(), mRealRect.bottomLeft(), + }; + for (int i = 0; i < 4; ++i) { + painter->drawPoint(pnts[i]); + painter->drawPoint((pnts[i] + pnts[i == 3 ? 0 : i + 1]) / 2); + } + painter->setPen(QPen(c.lighter(), roiWidth, Qt::SolidLine)); + painter->drawLine(mRealRect.center(), mRealRect.center() + QPointF(4, 0)); + painter->drawLine(mRealRect.center(), mRealRect.center() + QPointF(0, -4)); + painter->setPen(QPen(c.lighter(), roiWidth, Qt::DotLine)); + painter->drawLine(mRealRect.center(), mRealRect.center() + QPointF(-4, 0)); + painter->drawLine(mRealRect.center(), mRealRect.center() + QPointF(0, 4)); + } + if (isSingleMode() && !mRestritArea.isNull()) { + painter->setPen(Qt::NoPen); + QColor c2 = c; + c2.setAlpha(50); + painter->setBrush(c2); + QPainterPath path; + path.addPolygon(mapFromParent(mRestritArea)); + path.addRect(mRealRect); + painter->drawPath(path); + } +} + +QPainterPath AwesomeRectRoi::shape() const +{ + QPainterPath path; + path.setFillRule(Qt::WindingFill); + QRectF r = rect(); + if (isRoiActive() || isRoiPicked()) + path.addRect(r); + else + { + int senseRng2 = getSenseRng() * 2; + path.addRect(r.left(), r.top(), r.width(), senseRng2); + path.addRect(r.left(), r.bottom() - senseRng2, r.width(), senseRng2); + path.addRect(r.left(), r.top(), senseRng2, r.height()); + path.addRect(r.right() - senseRng2, r.top(), senseRng2, r.height()); + } + return path; +} + +QRectF AwesomeRectRoi::boundingRect() const +{ + if (isSingleMode() && !mRestritArea.isNull()) + return mapFromParent(mRestritArea).boundingRect(); + else return rect(); +} + +QRectF AwesomeRectRoi::senseRect() const +{ + return rect(); +} + +QList AwesomeRectRoi::getVertex() const +{ + return QList() << mRealRect.topLeft() << mRealRect.topRight() + << mRealRect.bottomRight() << mRealRect.bottomLeft(); +} + +void AwesomeRectRoi::mouseMoveEvent(QGraphicsSceneMouseEvent* e) +{ + if (mIsLock == true) + return; + + if (mResizeDir.any()) { + resizeRect(e->pos().x(), e->pos().y(), mResizeDir); + } + else if (mDoRotate) { + float a = getAngle(e->pos().x(), e->pos().y()); + float a0 = getAngle(e->lastPos().x(), e->lastPos().y()); + float deltaAngle = (a - a0) / 3.1416 * 180; + setRotation(rotation() + deltaAngle); + updateCursor(e->pos().x(), e->pos().y()); + } + else { + QGraphicsRectItem::mouseMoveEvent(e); + } + + adjustToRestrict(); + + emit roiChanged(); +} + +void AwesomeRectRoi::mousePressEvent(QGraphicsSceneMouseEvent* e) +{ + Qt::KeyboardModifiers k = QApplication::queryKeyboardModifiers(); + bool newSelected = k.testFlag(Qt::ShiftModifier) || k.testFlag(Qt::ControlModifier) ? !isRoiPicked() : true; + setRoiPicked(newSelected); + + const QPointF& mpos = e->pos(); + mResizeDir = getResizeDir(mpos.x(), mpos.y()); + + if (!mResizeDir.any()) + { + if (!mResizeOutterRect.contains(mpos.x(), mpos.y())) // rotation + mDoRotate = true; + else + QGraphicsRectItem::mousePressEvent(e); + } +} + +void AwesomeRectRoi::mouseReleaseEvent(QGraphicsSceneMouseEvent* e) +{ + mResizeDir.reset(); + mDoRotate = false; + QGraphicsRectItem::mouseReleaseEvent(e); +} + +void AwesomeRectRoi::hoverMoveEvent(QGraphicsSceneHoverEvent* e) +{ + if (!mResizeDir.any()) { + const QPointF& mpos = e->pos(); + updateCursor(mpos.x(), mpos.y()); + setRoiActive(true); + } +} + +void AwesomeRectRoi::hoverLeaveEvent(QGraphicsSceneHoverEvent* e) +{ + setSceneCursor(scene(), Qt::ArrowCursor); + setRoiActive(false); +} + +ResizeDirections AwesomeRectRoi::getResizeDir(qreal x, qreal y) +{ + ResizeDirections resizeDir; + if (!mResizeOutterRect.contains(x, y)) + return resizeDir; + + if (x < mResizeInnerRect.left()) + resizeDir.horizontal = ResizeDirections::Left; + else if (x > mResizeInnerRect.right()) + resizeDir.horizontal = ResizeDirections::Right; + + if (y < mResizeInnerRect.top()) + resizeDir.vertical = ResizeDirections::Top; + else if (y > mResizeInnerRect.bottom()) + resizeDir.vertical = ResizeDirections::Bottom; + + return resizeDir; +} + +void AwesomeRectRoi::resizeRect(qreal x, qreal y, ResizeDirections dir) +{ + qreal l = mRealRect.left(), r = mRealRect.right(), t = mRealRect.top(), b = mRealRect.bottom(); + + if (dir.horizontal == ResizeDirections::Left) + l = x; + else if (dir.horizontal == ResizeDirections::Right) + r = x; + + if (dir.vertical == ResizeDirections::Top) + t = y; + else if (dir.vertical == ResizeDirections::Bottom) + b = y; + + qreal w = std::max(1., r - l), h = std::max(1., b - t); + QRectF newRealRect(-w/2, -h/2, w, h); + if (newRealRect != mRealRect) { + if (dir.horizontal == ResizeDirections::Right && dir.vertical == ResizeDirections::Top) + setPos(mapToParent(mRealRect.bottomLeft() - newRealRect.bottomLeft())); + else if (dir.horizontal == ResizeDirections::Left && dir.vertical == ResizeDirections::Bottom) + setPos(mapToParent(mRealRect.topRight() - newRealRect.topRight())); + else if (dir.horizontal == ResizeDirections::Right || dir.vertical == ResizeDirections::Bottom) + setPos(mapToParent(mRealRect.topLeft() - newRealRect.topLeft())); + else + setPos(mapToParent(mRealRect.bottomRight() - newRealRect.bottomRight())); + setRealRect(newRealRect); + } +} + +int AwesomeRectRoi::getRotateCursorIdx(qreal x, qreal y) +{ + if (x < mRealRect.left()) { + if (y < mRealRect.top()) return 5; + else if (y > mRealRect.bottom()) return 3; + else return 4; + } + else if (x > mRealRect.right()) { + if (y < mRealRect.top()) return 7; + else if (y > mRealRect.bottom()) return 1; + else return 0; + } + else if (y < mRealRect.top()) { + return 6; + } + else { // y > mRealRect.bottom() + return 2; + } +} + +float AwesomeRectRoi::getAngle(qreal x, qreal y) +{ + qreal cx = transformOriginPoint().x(), cy = transformOriginPoint().y(); + return std::atan2(y - cy, x - cx); +} + +void AwesomeRectRoi::updateCursor(qreal x, qreal y) +{ + ResizeDirections resizeDir = getResizeDir(x, y); + float curRotation = fmod(rotation(), 360); + if (curRotation < 0) curRotation += 360; + int rotIdx = curRotation >= 337.5 || curRotation <= 22.5 ? 0 : ceil((curRotation - 22.5) / 45); + if (resizeDir.any() && !mDoRotate) + setSceneCursor(scene(), resizeDir.getCursorShape(rotIdx)); + else if (!mResizeOutterRect.contains(x, y) || mDoRotate) // rotation + setSceneCursor(scene(), getRotateCursor(getRotateCursorIdx(x, y) + rotIdx)); + else + setSceneCursor(scene(), Qt::SizeAllCursor); +} + +bool AwesomeRectRoi::adjustToRestrict() +{ + if (mRestritArea.isNull() || !mRestritArea.isValid()) return true; + + QVector vetexes; + vetexes << mRealRect.topLeft() << mRealRect.topRight() + << mRealRect.bottomLeft() << mRealRect.bottomRight(); + + bool nochange = true; + + // move inside restrict area + foreach(const QPointF& vetex, vetexes) { + QPointF pnt = mapToParent(vetex); + QPointF shift = shiftToRestrict(pnt); + if (!shift.isNull()) { + moveBy(shift.x(), shift.y()); + nochange = false; + } + } + + // shrink to restrict area + for (int i = 0; i < 4; i++) + { + QPointF vetex; + if (i == 0) vetex = mRealRect.topLeft(); + else if (i == 1) vetex = mRealRect.topRight(); + else if (i == 2) vetex = mRealRect.bottomLeft(); + else vetex = mRealRect.bottomRight(); + + QPointF pnt = mapToParent(vetex); + QPointF shift = shiftToRestrict(pnt); + if (!shift.isNull()) { + QPointF npnt = mapFromParent(pnt + shift); + ResizeDirections dir; + if (i == 0 || i == 1) dir.vertical = ResizeDirections::Top; + else dir.vertical = ResizeDirections::Bottom; + if (i == 0 || i == 2) dir.horizontal = ResizeDirections::Left; + else dir.horizontal = ResizeDirections::Right; + resizeRect(npnt.x(), npnt.y(), dir); + nochange = false; + } + } + + return nochange; +} diff --git a/src/lpMain/algela/AwesomeRoi.h b/src/lpMain/algela/AwesomeRoi.h new file mode 100644 index 0000000..03e09b6 --- /dev/null +++ b/src/lpMain/algela/AwesomeRoi.h @@ -0,0 +1,330 @@ +/*! + * \file AwesomeRoi.h + * \date 2018/06/27 + * + * \author Lin, Chi + * Contact: lin.chi@hzleaper.com + * + * + * \note +*/ + +#ifndef __AwesomeRoi_h_ +#define __AwesomeRoi_h_ + +#include +#include +#include +#include +#include +#include +#include +#include "AngelaEnum.h" + +class QGraphicsPixmapItem; + +struct ResizeDirections +{ + enum { HNone = 0, Left, Right } horizontal; + enum { VNone = 0, Top, Bottom } vertical; + bool any() { return horizontal || vertical; } + + ResizeDirections() : horizontal(HNone), vertical(VNone) {} + void reset() { horizontal = HNone; vertical = VNone; } + + Qt::CursorShape getCursorShape(int rotIdx) + { + static const Qt::CursorShape cResizeCursorShape[4] = { + Qt::SizeHorCursor, Qt::SizeFDiagCursor, Qt::SizeVerCursor, Qt::SizeBDiagCursor, + }; + + int idx = 0; + if ((horizontal == Left && vertical == Top) || (horizontal == Right && vertical == Bottom)) + idx = 1; + else if ((horizontal == Left && vertical == Bottom) || (horizontal == Right && vertical == Top)) + idx = 3; + else if (horizontal) // vertical == VNone + idx = 0; + else if (vertical) // horizontal == HNone + idx = 2; + else return Qt::ArrowCursor; + + return cResizeCursorShape[(idx + rotIdx) % 4]; + } +}; + +struct AwesomeRoiCommonProps; +class AwesomeRoiBase : public QObject +{ + Q_OBJECT + +public: + AwesomeRoiBase(AwesomeRoiCommonProps* pProps, AwesomeRoiType type = AwsRoiReserved); + + // every derived roi should implement this and return this + // usually it could be casted from this + // so just write DEFINE_AWESOME_ROI + virtual QGraphicsItem* getGraphicsItem() const = 0; + +#define DEFINE_AWESOME_ROI \ +public: QGraphicsItem* getGraphicsItem() const { return (QGraphicsItem*)this; } + +public: + AwesomeRoiType getRoiType() const { return mRoiType; } + // Note: ensure you return the vertexes in clockwise. + virtual QList getVertex() const { return QList(); } + virtual void updateSenseRng() {} + + void setNormalColor(const QColor& c) { mNormalColor = c; } + void setActiveColor(const QColor& c) { mActiveColor = c; } + + void setRoiActive(bool isActive); + bool isRoiActive() const { return mIsActive; } + + void setRoiPicked(bool isPicked); + bool isRoiPicked() const { return mIsPicked; } + + void setRoiSift(bool isSift); + bool isRoiSift() const { return mIsSift; } + + bool doRichPaint() const; + + void setLabel(const QString& str) { mLabel = str; } + const QString& getLabel() const { return mLabel; } + + // return false if it was invalid + bool setRestricArea(const QRectF& area); + + static QCursor getRotateCursor(int idx); + + static void setSceneCursor(QGraphicsScene* scene, const QCursor& cursor); + + static void updateLabelFontAndSenseRng(qreal senseRng); + + void showLabel() { mShowLabel = true; } + void hideLabel() { mShowLabel = false; } + + virtual QRectF senseRect() const; + virtual void onSetLock(bool bLock) { mIsLock = bLock; } +signals: + void toggledPick(bool isSelected); + void roiChanged(); + void roiLockIng();//被锁住提示 +protected: + const QColor& getNormalColor(QWidget* widget = nullptr) const; + const QColor& getActiveColor(QWidget* widget = nullptr) const; + QColor getPaintColor(QWidget* widget = nullptr) const; + + virtual bool adjustToRestrict() { return true; }; // return false if it's ever changed + virtual void updateZValue(); + + qreal getSenseRng() const; + QFont getLabelFont() const; + bool isSingleMode() const; + bool isSiftMode() const; + + qreal getRoiWidth() const { + qreal s = getSenseRng(); + qreal w = s >= 24 ? s / 24. + 1 : 1; + if (isRoiActive() || isRoiPicked()) w *= 1.5; + return w; + } + + QRectF getLabelRect() const; + void paintLabel(QPainter* painter, QWidget* widget = nullptr); + void prepareCosSin(const QPointF& tl, const QPointF& br, qreal& cos, qreal& sin, qreal& len); + + QPointF shiftToRestrict(const QPointF& pnt); + +protected: + AwesomeRoiType mRoiType; + + QColor mNormalColor; + QColor mActiveColor; + + QString mLabel; // nice to be unique + + QRectF mRestritArea; + + class PaintScopeGuard + { + public: + PaintScopeGuard(QPainter* painter); + ~PaintScopeGuard(); + private: + QPainter* mPainter; + }; + + bool mShowLabel; + + AwesomeRoiCommonProps* mpCommonProps; + +private: + bool mIsActive; + bool mIsPicked; + bool mIsSift; +protected: + + bool mIsLock{ false }; +}; + +class AwesomeRectRoi : public AwesomeRoiBase, public QGraphicsRectItem +{ + Q_OBJECT + DEFINE_AWESOME_ROI + +public: + AwesomeRectRoi(AwesomeRoiCommonProps* pProps, const QSizeF& s, QGraphicsItem* parent = nullptr); + void setRealRect(const QRectF& r); + + virtual void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = nullptr); + virtual QPainterPath shape() const; + virtual QRectF boundingRect() const; + + QList getVertex() const; + void updateSenseRng(); + + virtual QRectF senseRect() const; + +protected: + virtual void mouseMoveEvent(QGraphicsSceneMouseEvent* e); + virtual void mousePressEvent(QGraphicsSceneMouseEvent* e); + virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent* e); + virtual void hoverMoveEvent(QGraphicsSceneHoverEvent* e); + virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent* e); + +private: + ResizeDirections getResizeDir(qreal x, qreal y); + void resizeRect(qreal x, qreal y, ResizeDirections dir); + int getRotateCursorIdx(qreal x, qreal y); + float getAngle(qreal x, qreal y); + void updateCursor(qreal x, qreal y); + + bool adjustToRestrict(); + +private: + QRectF mRealRect; + QRectF mResizeInnerRect; + QRectF mResizeOutterRect; + + ResizeDirections mResizeDir; + bool mDoRotate; +}; + +struct AffineDirections +{ + enum { MNone = 0, Sym, Cut } mode; + enum { TNone = 0, Top, Bottom, Left, Right, Corner } target; + int cornerIdx; + bool any() { return mode && target; } + + AffineDirections() : mode(MNone), target(TNone), cornerIdx(-1) {} + void reset() { mode = MNone; target = TNone; cornerIdx = -1; } + + Qt::CursorShape getCursorShape() { + if (any()) return Qt::PointingHandCursor; + else return Qt::ArrowCursor; + } + + void decideCorner(bool vertical) { + if (cornerIdx == 0) target = vertical ? Left : Top; + else if (cornerIdx == 1) target = vertical ? Right : Top; + else if (cornerIdx == 2) target = vertical ? Right : Bottom; + else if (cornerIdx == 3) target = vertical ? Left : Bottom; + Q_ASSERT(target != Corner); + } +}; + +// 4 corner of the affine rect, in order top-left, top-right, bottom-right, bottom-left +typedef std::array AffineRect; +class AwesomeAffineRoi : public AwesomeRoiBase, public QGraphicsPolygonItem +{ + Q_OBJECT + DEFINE_AWESOME_ROI + +public: + AwesomeAffineRoi(AwesomeRoiCommonProps* pProps, const AffineRect& arect, QGraphicsItem* parent = nullptr); + void setAffineRect(const AffineRect& arect); + + void setPixmapItem(QGraphicsPixmapItem* item) { mPixItem = item; } + + virtual void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = nullptr); + virtual QPainterPath shape() const; + + QList getVertex() const; + void updateSenseRng(); + + void enablePerspectiveTransform(bool enable) { mEnablePerspective = enable; } + +protected: + virtual void mouseMoveEvent(QGraphicsSceneMouseEvent* e); + virtual void mousePressEvent(QGraphicsSceneMouseEvent* e); + virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent* e); + virtual void hoverMoveEvent(QGraphicsSceneHoverEvent* e); + virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent* e); + +private: + QPolygonF affineRectToPoly(const AffineRect& affineRect, qreal shink); + QPolygonF affineBorderToPoly(const QPointF& p1, const QPointF& p2, qreal shink, bool vertical); + + AffineDirections getAffineDir(qreal x, qreal y); + void updateCursor(qreal x, qreal y); + + void adjustAffine(const AffineRect& baseAffineRect, qreal deltaX, qreal deltaY, AffineDirections dir); + +private: + AffineRect mRealAffineRect; + QPolygonF mRealPoly; + QPolygonF mInnerPoly; + QPolygonF mBorderLeftPoly; + QPolygonF mBorderRightPoly; + QPolygonF mBorderTopPoly; + QPolygonF mBorderBottomPoly; + + QGraphicsPixmapItem* mPixItem; + + AffineDirections mAffineDir; + AffineRect mAdjBaseAffineRect; + QPointF mPreMPos; + + bool mEnablePerspective; +}; + +class AwesomePointRoi : public AwesomeRoiBase, public QGraphicsEllipseItem +{ + Q_OBJECT + DEFINE_AWESOME_ROI + +public: + AwesomePointRoi(AwesomeRoiCommonProps* pProps, qreal r, QGraphicsItem* parent = nullptr); + void setRealSize(qreal r); + void setAngle(qreal angle); + + virtual void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = nullptr); + void paintLabel2(QPainter* painter, QWidget* widget); + QRectF getLabelRect2() const; + virtual QPainterPath shape() const; + virtual QRectF boundingRect() const; + + QList getVertex() const; + void updateSenseRng(); + +protected: + virtual void mouseMoveEvent(QGraphicsSceneMouseEvent* e); + virtual void mousePressEvent(QGraphicsSceneMouseEvent* e); + virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent* e); + virtual void hoverMoveEvent(QGraphicsSceneHoverEvent* e); + virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent* e); + +private: + void updateCursor(qreal x, qreal y); + bool adjustToRestrict(); + +private: + QRectF mRealCircle; + bool mEnableRotate; +}; + + +#endif // AwesomeRoi_h_ + diff --git a/src/lpMain/algela/AwesomeRoiBase.cpp b/src/lpMain/algela/AwesomeRoiBase.cpp new file mode 100644 index 0000000..1986321 --- /dev/null +++ b/src/lpMain/algela/AwesomeRoiBase.cpp @@ -0,0 +1,228 @@ +/*! + * \file AwesomeRoiBase.cpp + * \date 2018/07/05 + * + * \author Lin, Chi + * Contact: lin.chi@hzleaper.com + * + * + * \note +*/ + +#include "AwesomeRoi.h" +#include "AwesomeImgViewer.h" +#include +#include +#include +#include + +AwesomeRoiBase::AwesomeRoiBase(AwesomeRoiCommonProps* pProps, AwesomeRoiType type) + : QObject(), mRoiType(type), mIsActive(false), mIsPicked(false), + mShowLabel(false), mIsSift(false), mpCommonProps(pProps) +{ +} + +void AwesomeRoiBase::setRoiActive(bool isActive) +{ + if (mIsActive != isActive) { + mIsActive = isActive; + updateZValue(); + } +} + +void AwesomeRoiBase::setRoiPicked(bool isPicked) +{ + if (mIsPicked != isPicked) + { + mIsPicked = isPicked; + updateZValue(); + emit toggledPick(mIsPicked); + } +} + +void AwesomeRoiBase::setRoiSift(bool isSift) +{ + if (mIsSift != isSift) { + mIsSift = isSift; + updateZValue(); + } +} + +bool AwesomeRoiBase::doRichPaint() const +{ + return isRoiActive() || isRoiPicked(); +} + +bool AwesomeRoiBase::setRestricArea(const QRectF& area) +{ + mRestritArea = area; + return adjustToRestrict(); +} + +const QColor& AwesomeRoiBase::getNormalColor(QWidget* widget) const +{ + static const QColor cDefaultNormalColor(0, 200, 0); + if (mNormalColor.isValid()) return mNormalColor; + else if (widget) return widget->palette().color(QPalette::Text); + else return cDefaultNormalColor; +} + +const QColor& AwesomeRoiBase::getActiveColor(QWidget* widget) const +{ + static const QColor cDefaultActiveColor(200, 0, 0); + if (mActiveColor.isValid()) return mActiveColor; + else if (widget) return widget->palette().color(QPalette::Highlight); + else return cDefaultActiveColor; +} + +QColor AwesomeRoiBase::getPaintColor(QWidget* widget) const +{ + QColor c; + if (isRoiPicked()) { + c = getActiveColor(widget); + } + else if (isRoiActive()) { + c = getNormalColor(widget).lighter(); + } + else { + c = getNormalColor(widget); + } + + if (mIsSift) + c.setAlpha(30); + + return c; +} + +void AwesomeRoiBase::updateZValue() +{ + if (mIsPicked) getGraphicsItem()->setZValue(3); + else if (mIsActive) getGraphicsItem()->setZValue(1); + else if (!mIsSift) getGraphicsItem()->setZValue(0); + else getGraphicsItem()->setZValue(2); +} + +qreal AwesomeRoiBase::getSenseRng() const +{ + if (!mpCommonProps) return 8; + return mpCommonProps->senseRng; +} + +QFont AwesomeRoiBase::getLabelFont() const +{ + if (!mpCommonProps) return QApplication::font(); + return mpCommonProps->labelFont; +} + +bool AwesomeRoiBase::isSingleMode() const +{ + if (!mpCommonProps) return false; + return mpCommonProps->singleRoiMode; +} + +bool AwesomeRoiBase::isSiftMode() const +{ + if (!mpCommonProps) return false; + return mpCommonProps->siftMode; +} + + +QRectF AwesomeRoiBase::getLabelRect() const +{ + if (!mShowLabel || mLabel.isEmpty()) return QRectF(); + + QList vertexes = getVertex(); + QPointF basePnt; + if (vertexes.size() > 0) { + basePnt = vertexes[0]; + } + + QFontMetricsF metrics(getLabelFont()); + QRectF br = getGraphicsItem()->boundingRect(); + QSizeF s = metrics.size(Qt::TextSingleLine, mLabel); + qreal w = std::min(s.width(), br.right() - 0.5 - basePnt.x()); + qreal h = std::min(s.height(), basePnt.y() - 0.5 - br.top()); + + return QRectF(QPointF(basePnt.x()+15, basePnt.y() - 7), QSizeF(15, 15)); +} + +void AwesomeRoiBase::paintLabel(QPainter* painter, QWidget* widget) +{ + if (!mShowLabel || mLabel.isEmpty()) return; + + QRectF r = getLabelRect(); + QColor c = getPaintColor(widget); + //painter->setBrush(QBrush(painter->pen().color(), Qt::SolidPattern)); + //painter->drawRect(r); + + painter->setPen(QPen(c)); + + //painter->setFont(getLabelFont()); + painter->drawText(r, Qt::AlignLeft | Qt::AlignVCenter, mLabel); +} + +QCursor AwesomeRoiBase::getRotateCursor(int idx) +{ + static const QPixmap cRotateCursorsPix[8] = { + QPixmap(":/cursor_rotate_0.png"), QPixmap(":/cursor_rotate_45.png"), + QPixmap(":/cursor_rotate_90.png"), QPixmap(":/cursor_rotate_135.png"), + QPixmap(":/cursor_rotate_180.png"), QPixmap(":/cursor_rotate_225.png"), + QPixmap(":/cursor_rotate_270.png"), QPixmap(":/cursor_rotate_315.png"), + }; + + return QCursor(cRotateCursorsPix[idx % 8]); +} + +void AwesomeRoiBase::setSceneCursor(QGraphicsScene* scene, const QCursor& cursor) +{ + QList views = scene->views(); + if (views.count() > 0) { + QGraphicsView * view = views.first(); + view->setCursor(cursor); + } +} + +QRectF AwesomeRoiBase::senseRect() const +{ + QGraphicsItem* item = getGraphicsItem(); + if (!item) return QRectF(); + return item->boundingRect(); +} + +void AwesomeRoiBase::prepareCosSin(const QPointF& tl, const QPointF& br, qreal& cos, qreal& sin, qreal& len) +{ + qreal x = br.x() - tl.x(), y = br.y() - tl.y(); + len = sqrt(pow(x, 2) + pow(y, 2)); + cos = x / len; + sin = y / len; +} + +QPointF AwesomeRoiBase::shiftToRestrict(const QPointF& pnt) +{ + qreal x = pnt.x(), y = pnt.y(); + qreal shift_x = 0, shift_y = 0; + + if (x < mRestritArea.left()) + shift_x = abs(x - mRestritArea.left()); // outside of the left, move right + else if (x > mRestritArea.right()) + shift_x = -abs(mRestritArea.right() - x); // outside of the right, move left + + if (y < mRestritArea.top()) // outside of the top, move down + shift_y = abs(y - mRestritArea.top()); + else if (y > mRestritArea.bottom()) // outside of the bottom, move up + shift_y = -abs(mRestritArea.bottom() - y); + + return QPointF(shift_x, shift_y); +} + +AwesomeRoiBase::PaintScopeGuard::PaintScopeGuard(QPainter* painter) +{ + painter->save(); + mPainter = painter; +} + +AwesomeRoiBase::PaintScopeGuard::~PaintScopeGuard() +{ + // note: set everything back to original, to avoid rendering artifacts + mPainter->restore(); +} diff --git a/src/lpMain/algela/RoiImgViewer.cpp b/src/lpMain/algela/RoiImgViewer.cpp index 35d1508..5b082aa 100644 --- a/src/lpMain/algela/RoiImgViewer.cpp +++ b/src/lpMain/algela/RoiImgViewer.cpp @@ -1,670 +1,666 @@ #include "RoiImgViewer.h" #include -//#include "qtUtils.h" #include #include - - //#define DEBUG_PRINT - - RoiImgViewer::RoiImgViewer(QWidget* parent /*= 0*/) - : lpImgViewer(parent) - , mMouseCaptureStatus(MouseCaptureNone) - , mDrawStatus(DrawNone) - , mMouseCaptureDistance(10) - , mpDrawingLineItem(NULL) - , mpDrawingRectItem(NULL) - , mpSelectedRoiNode(NULL) +RoiImgViewer::RoiImgViewer(QWidget* parent /*= 0*/) + : lpImgViewer(parent) + , mMouseCaptureStatus(MouseCaptureNone) + , mDrawStatus(DrawNone) + , mMouseCaptureDistance(10) + , mpDrawingLineItem(NULL) + , mpDrawingRectItem(NULL) + , mpSelectedRoiNode(NULL) +{ + connect(scene(), SIGNAL(selectionChanged()), this, SLOT(updateSelectedRoiNode())); +} + +QGraphicsPixmapItem* RoiImgViewer::setImg(QImage& img) +{ + if (lpImgViewer::setImg(img)) { - connect(scene(), SIGNAL(selectionChanged()), this, SLOT(updateSelectedRoiNode())); + mpImgItem->setFlag(QGraphicsItem::ItemIsMovable, false); + return mpImgItem; } - - QGraphicsPixmapItem* RoiImgViewer::setImg(QImage& img) + else { - if (lpImgViewer::setImg(img)) - { - mpImgItem->setFlag(QGraphicsItem::ItemIsMovable, false); - return mpImgItem; - } - else - { - return NULL; - } + return NULL; } +} - QGraphicsItem* RoiImgViewer::firstSelectedItem() +QGraphicsItem* RoiImgViewer::firstSelectedItem() +{ + auto selectedItemList = scene()->selectedItems(); + if (selectedItemList.size()) { - auto selectedItemList = scene()->selectedItems(); - if (selectedItemList.size()) - { - return selectedItemList.front(); - } - else - { - return NULL; - } + return selectedItemList.front(); } - - void RoiImgViewer::setDrawStatus(DrawStatus s) + else { - - mDrawStatus = s; - // if(mpImgItem){ - // if(DrawNone == s){ - // mpImgItem->setFlag(QGraphicsItem::ItemIsMovable, true); - // printf("RoiImgViewer::setDrawStatus true\n"); - // } - // else{ - // mpImgItem->setFlag(QGraphicsItem::ItemIsMovable, false); - // printf("RoiImgViewer::setDrawStatus false\n"); - // } - // } + return NULL; } - - void RoiImgViewer::clearRois(int type /*= -1*/) +} + +void RoiImgViewer::setDrawStatus(DrawStatus s) +{ + + mDrawStatus = s; + // if(mpImgItem){ + // if(DrawNone == s){ + // mpImgItem->setFlag(QGraphicsItem::ItemIsMovable, true); + // printf("RoiImgViewer::setDrawStatus true\n"); + // } + // else{ + // mpImgItem->setFlag(QGraphicsItem::ItemIsMovable, false); + // printf("RoiImgViewer::setDrawStatus false\n"); + // } + // } +} + +void RoiImgViewer::clearRois(int type /*= -1*/) +{ + QGraphicsScene* pScene = scene(); + if (type < 0) { - QGraphicsScene* pScene = scene(); - if (type < 0) - { - foreach(auto itemList, mRoiItemMap) - { - foreach(auto pItem, itemList) - { - pScene->removeItem(pItem); - delete pItem; - } - } - mRoiItemMap.clear(); - } - else + foreach(auto itemList, mRoiItemMap) { - auto iterItem = mRoiItemMap.find(type); - if (iterItem != mRoiItemMap.end()) + foreach(auto pItem, itemList) { - foreach(auto pItem, mRoiItemMap[type]) - { - pScene->removeItem(pItem); - delete pItem; - } - mRoiItemMap.erase(iterItem); + pScene->removeItem(pItem); + delete pItem; } } - - if (type < 0 || type == QGraphicsRectItem::Type) - { - mRoiNodeList.clear(); - mpSelectedRoiNode = NULL; - } - - rejectDrawingItem(); + mRoiItemMap.clear(); } - - void RoiImgViewer::clearExistRois() + else { - QGraphicsScene* pScene = scene(); - - foreach(auto itemList, mRoiItemMap) + auto iterItem = mRoiItemMap.find(type); + if (iterItem != mRoiItemMap.end()) { - foreach(auto pItem, itemList) + foreach(auto pItem, mRoiItemMap[type]) { pScene->removeItem(pItem); delete pItem; } + mRoiItemMap.erase(iterItem); } - mRoiItemMap.clear(); + } + + if (type < 0 || type == QGraphicsRectItem::Type) + { mRoiNodeList.clear(); mpSelectedRoiNode = NULL; } - void RoiImgViewer::addRoiRect(QRectF rect, qreal scale, QString channelName, QString id, bool isTemplate /*= true*/, QColor nonTmplColor /*= Qt::yellow*/) - { - DrawStatus backupDrawStatus = mDrawStatus; - QString backupChannelName = getChannel(); + rejectDrawingItem(); +} - setChannel(channelName); - setDrawStatus(DrawRect); - mDrawingRect = rect; - createDrawingItem(); +void RoiImgViewer::clearExistRois() +{ + QGraphicsScene* pScene = scene(); - qreal backupFixedSizeScale = fixedSizeScale(); - setFixedSizeScale(scale); - acceptDrawingItem(); - lastRectRoi()->id = id; - lastRectRoi()->isTemplate = isTemplate; - if (!isTemplate) + foreach(auto itemList, mRoiItemMap) + { + foreach(auto pItem, itemList) { - //setPenColor(lastRectRoi()->pItem, nonTmplColor); - QPen pen = lastRectRoi()->pItem->pen(); - pen.setColor(nonTmplColor); - lastRectRoi()->pItem->setPen(pen); + pScene->removeItem(pItem); + delete pItem; } - setFixedSizeScale(backupFixedSizeScale); - - mDrawStatus = backupDrawStatus; - setChannel(backupChannelName); } - - void RoiImgViewer::addRoiRect(QRectF rect, qreal scale, QString id) + mRoiItemMap.clear(); + mRoiNodeList.clear(); + mpSelectedRoiNode = NULL; +} + +void RoiImgViewer::addRoiRect(QRectF rect, qreal scale, QString channelName, QString id, bool isTemplate /*= true*/, QColor nonTmplColor /*= Qt::yellow*/) +{ + DrawStatus backupDrawStatus = mDrawStatus; + QString backupChannelName = getChannel(); + + setChannel(channelName); + setDrawStatus(DrawRect); + mDrawingRect = rect; + createDrawingItem(); + + qreal backupFixedSizeScale = fixedSizeScale(); + setFixedSizeScale(scale); + acceptDrawingItem(); + lastRectRoi()->id = id; + lastRectRoi()->isTemplate = isTemplate; + if (!isTemplate) { - setDrawStatus(DrawRect); - // QPolygonF qrect = mapToScene(rect.toRect()); - // mDrawingRect = qrect.boundingRect(); - mDrawingRect = rect; - createDrawingItem(); - updateDrawingItem(); - //setFixedSizeScale(scale); - acceptDrawingItem(); - lastRectRoi()->id = id; + //setPenColor(lastRectRoi()->pItem, nonTmplColor); + QPen pen = lastRectRoi()->pItem->pen(); + pen.setColor(nonTmplColor); + lastRectRoi()->pItem->setPen(pen); } - - void RoiImgViewer::addRoiLine(QLineF line, QString id) + setFixedSizeScale(backupFixedSizeScale); + + mDrawStatus = backupDrawStatus; + setChannel(backupChannelName); +} + +void RoiImgViewer::addRoiRect(QRectF rect, qreal scale, QString id) +{ + setDrawStatus(DrawRect); + // QPolygonF qrect = mapToScene(rect.toRect()); + // mDrawingRect = qrect.boundingRect(); + mDrawingRect = rect; + createDrawingItem(); + updateDrawingItem(); + //setFixedSizeScale(scale); + acceptDrawingItem(); + lastRectRoi()->id = id; +} + +void RoiImgViewer::addRoiLine(QLineF line, QString id) +{ + setDrawStatus(DrawLine); + mDrawingLine = line; + createDrawingItem(); + updateDrawingItem(); + acceptDrawingItem(); + //lastRectRoi()->id = id; + setDrawStatus(DrawNone); +} + +LP_ROI_NODE* RoiImgViewer::lastRectRoi() +{ + if (mRoiNodeList.size()) { - setDrawStatus(DrawLine); - mDrawingLine = line; - createDrawingItem(); - updateDrawingItem(); - acceptDrawingItem(); - //lastRectRoi()->id = id; - setDrawStatus(DrawNone); + return &mRoiNodeList.last(); } - - LP_ROI_NODE* RoiImgViewer::lastRectRoi() + else { - if (mRoiNodeList.size()) - { - return &mRoiNodeList.last(); - } - else - { - return NULL; - } + return NULL; } +} - void RoiImgViewer::mousePressEvent(QMouseEvent *event) +void RoiImgViewer::mousePressEvent(QMouseEvent *event) +{ + QGraphicsItem* pItem = firstSelectedItem(); + if (!pItem) { - QGraphicsItem* pItem = firstSelectedItem(); - if (!pItem) - { - lpImgViewer::mousePressEvent(event); - pItem = firstSelectedItem(); - } + lpImgViewer::mousePressEvent(event); + pItem = firstSelectedItem(); + } - QPoint mousePos = event->pos(); - QPointF scenePos = mapToScene(mousePos); + QPoint mousePos = event->pos(); + QPointF scenePos = mapToScene(mousePos); - if (event->button() == Qt::LeftButton) - { + if (event->button() == Qt::LeftButton) + { - if (!pItem) + if (!pItem) + { + // nothing is selected, start drawing + switch (mDrawStatus) { - // nothing is selected, start drawing - switch (mDrawStatus) - { - case DrawLine: - mDrawingLine.setP1(scenePos); - mDrawingLine.setP2(scenePos); - break; - case DrawRect: - mDrawingRect.setTopLeft(scenePos); - mDrawingRect.setBottomRight(scenePos); - break; - default: - break; - } - createDrawingItem(); - return; + case DrawLine: + mDrawingLine.setP1(scenePos); + mDrawingLine.setP2(scenePos); + break; + case DrawRect: + mDrawingRect.setTopLeft(scenePos); + mDrawingRect.setBottomRight(scenePos); + break; + default: + break; } - else - { - // something is selected + createDrawingItem(); + return; + } + else + { + // something is selected - // map pos to selected item's local coordinates - QPointF itemMousePos = pItem->mapFromScene(scenePos); + // map pos to selected item's local coordinates + QPointF itemMousePos = pItem->mapFromScene(scenePos); #ifdef DEBUG_PRINT - printf("viewer mouse press pos %d %d\n", mousePos.x(), mousePos.y()); - printf("scene mouse press pos %f %f\n", scenePos.x(), scenePos.y()); - printf("item mouse press pos %f %f\n", itemMousePos.x(), itemMousePos.y()); + printf("viewer mouse press pos %d %d\n", mousePos.x(), mousePos.y()); + printf("scene mouse press pos %f %f\n", scenePos.x(), scenePos.y()); + printf("item mouse press pos %f %f\n", itemMousePos.x(), itemMousePos.y()); #endif - QGraphicsRectItem* pRectItem = dynamic_cast(pItem); - if (pRectItem) - { - QRectF r = pRectItem->rect(); + QGraphicsRectItem* pRectItem = dynamic_cast(pItem); + if (pRectItem) + { + QRectF r = pRectItem->rect(); #ifdef DEBUG_PRINT - printf("item rect %f %f %f %f\n", r.x(), r.y(), r.width(), r.height()); + printf("item rect %f %f %f %f\n", r.x(), r.y(), r.width(), r.height()); #endif - mMouseCaptureStatus = decideMouseCaptureStatus(r, itemMousePos, mMouseCaptureDistance); + mMouseCaptureStatus = decideMouseCaptureStatus(r, itemMousePos, mMouseCaptureDistance); - if (mMouseCaptureStatus != MouseCaptureNone) - { - pRectItem->setFlag(QGraphicsItem::ItemIsMovable, false); - return; - } - } - QGraphicsLineItem* pLineItem = dynamic_cast(pItem); - if (pLineItem) + if (mMouseCaptureStatus != MouseCaptureNone) { - QLineF l = pLineItem->line(); + pRectItem->setFlag(QGraphicsItem::ItemIsMovable, false); + return; + } + } + QGraphicsLineItem* pLineItem = dynamic_cast(pItem); + if (pLineItem) + { + QLineF l = pLineItem->line(); - mMouseCaptureStatus = decideMouseCaptureStatus(l, itemMousePos, mMouseCaptureDistance); + mMouseCaptureStatus = decideMouseCaptureStatus(l, itemMousePos, mMouseCaptureDistance); - if (mMouseCaptureStatus != MouseCaptureNone) - { - pLineItem->setFlag(QGraphicsItem::ItemIsMovable, false); - return; - } + if (mMouseCaptureStatus != MouseCaptureNone) + { + pLineItem->setFlag(QGraphicsItem::ItemIsMovable, false); + return; } } } - - lpImgViewer::mousePressEvent(event); } - void RoiImgViewer::mouseMoveEvent(QMouseEvent *evt) - { - lpImgViewer::mouseMoveEvent(evt); + lpImgViewer::mousePressEvent(event); +} - QGraphicsItem* pItem = dynamic_cast( - firstSelectedItem()); +void RoiImgViewer::mouseMoveEvent(QMouseEvent *evt) +{ + lpImgViewer::mouseMoveEvent(evt); - QPoint mousePos = evt->pos(); - QPointF scenePos = mapToScene(mousePos); + QGraphicsItem* pItem = dynamic_cast( + firstSelectedItem()); - if (!pItem) + QPoint mousePos = evt->pos(); + QPointF scenePos = mapToScene(mousePos); + + if (!pItem) + { + if (evt->buttons() == Qt::LeftButton) { - if (evt->buttons() == Qt::LeftButton) + switch (mDrawStatus) { - switch (mDrawStatus) - { - case DrawLine: - mDrawingLine.setP2(scenePos); - break; - case DrawRect: - mDrawingRect.setBottomRight(scenePos); - break; - default: - break; - } - updateDrawingItem(); + case DrawLine: + mDrawingLine.setP2(scenePos); + break; + case DrawRect: + mDrawingRect.setBottomRight(scenePos); + break; + default: + break; } + updateDrawingItem(); } - else - { - QPointF itemMousePos = pItem->mapFromScene(scenePos); + } + else + { + QPointF itemMousePos = pItem->mapFromScene(scenePos); - if (pItem->type() == QGraphicsRectItem().type()) - { - QGraphicsRectItem* pRectItem = qgraphicsitem_cast(pItem); - // map pos to selected item's local coordinates + if (pItem->type() == QGraphicsRectItem().type()) + { + QGraphicsRectItem* pRectItem = qgraphicsitem_cast(pItem); + // map pos to selected item's local coordinates - QRectF r = pRectItem->rect(); + QRectF r = pRectItem->rect(); #ifdef DEBUG_PRINT - printf("item rect %f %f %f %f\n", r.x(), r.y(), r.width(), r.height()); - printf("viewer mouse move pos %d %d\n", evt->pos().x(), evt->pos().y()); - printf("scene mouse move pos %f %f\n", scenePos.x(), scenePos.y()); - printf("item mouse move pos %f %f\n", itemMousePos.x(), itemMousePos.y()); - printf("mouse capture status %d\n", mMouseCaptureStatus); + printf("item rect %f %f %f %f\n", r.x(), r.y(), r.width(), r.height()); + printf("viewer mouse move pos %d %d\n", evt->pos().x(), evt->pos().y()); + printf("scene mouse move pos %f %f\n", scenePos.x(), scenePos.y()); + printf("item mouse move pos %f %f\n", itemMousePos.x(), itemMousePos.y()); + printf("mouse capture status %d\n", mMouseCaptureStatus); #endif - if (evt->buttons() == Qt::LeftButton) + if (evt->buttons() == Qt::LeftButton) + { + QRectF oriRect = r; + switch (mMouseCaptureStatus) { - QRectF oriRect = r; - switch (mMouseCaptureStatus) - { - case MouseCaptureLeft: - r.setLeft(itemMousePos.x()); - r.setWidth(oriRect.right() - r.left()); - break; - case MouseCaptureRight: - r.setRight(itemMousePos.x()); - r.setWidth(r.right() - oriRect.left()); - break; - case MouseCaptureTop: - r.setTop(itemMousePos.y()); - r.setHeight(oriRect.bottom() - r.top()); - break; - case MouseCaptureBottom: - r.setBottom(itemMousePos.y()); - r.setHeight(r.bottom() - oriRect.top()); - break; - default: - case MouseCaptureNone: - break; - } - pRectItem->setRect(r); + case MouseCaptureLeft: + r.setLeft(itemMousePos.x()); + r.setWidth(oriRect.right() - r.left()); + break; + case MouseCaptureRight: + r.setRight(itemMousePos.x()); + r.setWidth(r.right() - oriRect.left()); + break; + case MouseCaptureTop: + r.setTop(itemMousePos.y()); + r.setHeight(oriRect.bottom() - r.top()); + break; + case MouseCaptureBottom: + r.setBottom(itemMousePos.y()); + r.setHeight(r.bottom() - oriRect.top()); + break; + default: + case MouseCaptureNone: + break; } + pRectItem->setRect(r); + } - MouseCaptureStatus s = decideMouseCaptureStatus(r, itemMousePos, mMouseCaptureDistance); + MouseCaptureStatus s = decideMouseCaptureStatus(r, itemMousePos, mMouseCaptureDistance); #ifdef DEBUG_PRINT - printf("cur mouse status %d\n", s); + printf("cur mouse status %d\n", s); #endif - if (s == MouseCaptureLeft || s == MouseCaptureRight) - { - setCursor(Qt::SizeHorCursor); - } - else if (s == MouseCaptureTop || s == MouseCaptureBottom) - { - setCursor(Qt::SizeVerCursor); - } - else - { - setCursor(Qt::ArrowCursor); - } + if (s == MouseCaptureLeft || s == MouseCaptureRight) + { + setCursor(Qt::SizeHorCursor); } - else if (pItem->type() == QGraphicsLineItem().type()) + else if (s == MouseCaptureTop || s == MouseCaptureBottom) { - QGraphicsLineItem* pLineItem = qgraphicsitem_cast(pItem); - + setCursor(Qt::SizeVerCursor); + } + else + { + setCursor(Qt::ArrowCursor); } } + else if (pItem->type() == QGraphicsLineItem().type()) + { + QGraphicsLineItem* pLineItem = qgraphicsitem_cast(pItem); + } } - void RoiImgViewer::mouseReleaseEvent(QMouseEvent *event) +} + +void RoiImgViewer::mouseReleaseEvent(QMouseEvent *event) +{ + if (event->button() == Qt::LeftButton) { - if (event->button() == Qt::LeftButton) - { - mMouseCaptureStatus = MouseCaptureNone; + mMouseCaptureStatus = MouseCaptureNone; - QGraphicsItem* pItem = firstSelectedItem(); - if (!pItem) - { - // draw - switch (mDrawStatus) - { - case DrawLine: - if (mpDrawingLineItem) - { - emit roiAdded(mpDrawingLineItem); - } - break; - case DrawRect: - if (mpDrawingRectItem) - { - emit roiAdded(mpDrawingRectItem); - } - break; - default: - break; - } - acceptDrawingItem(); - } - else + QGraphicsItem* pItem = firstSelectedItem(); + if (!pItem) + { + // draw + switch (mDrawStatus) { - // edit - pItem->setFlag(QGraphicsItem::ItemIsMovable, true); - - int itemType = pItem->type(); - if (itemType == QGraphicsRectItem().type()) + case DrawLine: + if (mpDrawingLineItem) { - QGraphicsRectItem* pRectItem = qgraphicsitem_cast(pItem); + emit roiAdded(mpDrawingLineItem); } - else if (itemType == QGraphicsLineItem().type()) + break; + case DrawRect: + if (mpDrawingRectItem) { - QGraphicsLineItem* pLineItem = qgraphicsitem_cast(pItem); + emit roiAdded(mpDrawingRectItem); } + break; + default: + break; + } + acceptDrawingItem(); + } + else + { + // edit + pItem->setFlag(QGraphicsItem::ItemIsMovable, true); - emit roiChanged(pItem); + int itemType = pItem->type(); + if (itemType == QGraphicsRectItem().type()) + { + QGraphicsRectItem* pRectItem = qgraphicsitem_cast(pItem); + } + else if (itemType == QGraphicsLineItem().type()) + { + QGraphicsLineItem* pLineItem = qgraphicsitem_cast(pItem); } + + emit roiChanged(pItem); } - lpImgViewer::mouseReleaseEvent(event); } + lpImgViewer::mouseReleaseEvent(event); +} - void RoiImgViewer::wheelEvent(QWheelEvent *evt) +void RoiImgViewer::wheelEvent(QWheelEvent *evt) +{ + lpImgViewer::wheelEvent(evt); + + if (!mpSelectedRoiNode) { - lpImgViewer::wheelEvent(evt); + return; + } - if (!mpSelectedRoiNode) + mpSelectedRoiNode->fScale = mFixedSizeScale; +} + +void RoiImgViewer::keyPressEvent(QKeyEvent *event) +{ + if (mpSelectedRoiNode && Qt::Key_Delete == event->key()) { + QGraphicsScene* pScene = scene(); + + foreach(auto itemList, mRoiItemMap) { - return; - } + foreach(auto pItem, itemList) + { + if (pItem == mpSelectedRoiNode->pItem) { + pScene->removeItem(pItem); - mpSelectedRoiNode->fScale = mFixedSizeScale; - } + auto i1 = std::find_if(itemList.begin(), itemList.end(), [&](QGraphicsItem* pi) + { + return pi == pItem; + }); + itemList.erase(i1); - void RoiImgViewer::keyPressEvent(QKeyEvent *event) - { - if (mpSelectedRoiNode && Qt::Key_Delete == event->key()) { - QGraphicsScene* pScene = scene(); + auto i2 = std::find_if(mRoiNodeList.begin(), mRoiNodeList.end(), [&](LP_ROI_NODE& roiNode) + { + return roiNode.pItem == pItem; + }); + mRoiNodeList.erase(i2); - foreach(auto itemList, mRoiItemMap) - { - foreach(auto pItem, itemList) - { - if (pItem == mpSelectedRoiNode->pItem) { - pScene->removeItem(pItem); - - auto i1 = std::find_if(itemList.begin(), itemList.end(), [&](QGraphicsItem* pi) - { - return pi == pItem; - }); - itemList.erase(i1); - - auto i2 = std::find_if(mRoiNodeList.begin(), mRoiNodeList.end(), [&](LP_ROI_NODE& roiNode) - { - return roiNode.pItem == pItem; - }); - mRoiNodeList.erase(i2); - - delete pItem; - mpSelectedRoiNode = NULL; - return; - } + delete pItem; + mpSelectedRoiNode = NULL; + return; } } } } +} + +QRectF extRect(const QRectF& r, float w) +{ + return QRectF(r.x() - w, r.y() - w, r.width() + 2.0 * w, r.height() + 2.0*w); +} - QRectF extRect(const QRectF& r, float w) +RoiImgViewer::MouseCaptureStatus RoiImgViewer::decideMouseCaptureStatus(const QRectF r, QPointF p, float capDis /*= 10*/) +{ + MouseCaptureStatus ret = MouseCaptureNone; + + QRectF validRect = extRect(r, capDis); + if (!validRect.contains(p)) { - return QRectF(r.x() - w, r.y() - w, r.width() + 2.0 * w, r.height() + 2.0*w); + return ret; } - RoiImgViewer::MouseCaptureStatus RoiImgViewer::decideMouseCaptureStatus(const QRectF r, QPointF p, float capDis /*= 10*/) + if (abs(p.x() - r.left()) < capDis) { - MouseCaptureStatus ret = MouseCaptureNone; + ret = MouseCaptureLeft; + } + else if (abs(p.x() - r.right()) < capDis) + { + ret = MouseCaptureRight; + } + else if (abs(p.y() - r.top()) < capDis) + { + ret = MouseCaptureTop; + } + else if (abs(p.y() - r.bottom()) < capDis) + { + ret = MouseCaptureBottom; + } - QRectF validRect = extRect(r, capDis); - if (!validRect.contains(p)) - { - return ret; - } + return ret; +} + +RoiImgViewer::MouseCaptureStatus RoiImgViewer::decideMouseCaptureStatus(const QLineF l, QPointF p, float capDis /*= 10*/) +{ + return MouseCaptureNone; +} + +void RoiImgViewer::updateSelectedRoiNode() +{ + QGraphicsItem* pItem = firstSelectedItem(); - if (abs(p.x() - r.left()) < capDis) + LP_ROI_NODE *pRoiNode = findRoiNode(pItem); + if (pRoiNode != mpSelectedRoiNode) + { + mpSelectedRoiNode = pRoiNode; + emit roiSelectionChanged(mpSelectedRoiNode); + } +} + +void RoiImgViewer::updateDrawingItem() +{ + switch (mDrawStatus) + { + case DrawLine: + if (mpDrawingLineItem) { - ret = MouseCaptureLeft; + QPen pen = mpDrawingLineItem->pen(); + pen.setColor(Qt::yellow); + pen.setWidth(5); + mpDrawingLineItem->setPen(pen); + mpDrawingLineItem->setLine(mDrawingLine); } - else if (abs(p.x() - r.right()) < capDis) + else { - ret = MouseCaptureRight; + qWarning() << tr("line item is not created"); } - else if (abs(p.y() - r.top()) < capDis) + break; + case DrawRect: + if (mpDrawingRectItem) { - ret = MouseCaptureTop; + QPen pen = mpDrawingRectItem->pen(); + pen.setColor(Qt::yellow); + pen.setWidth(5); + mpDrawingRectItem->setPen(pen); + mpDrawingRectItem->setRect(mDrawingRect); } - else if (abs(p.y() - r.bottom()) < capDis) + else { - ret = MouseCaptureBottom; + qWarning() << tr("line item is not created"); } - - return ret; + break; + default: + break; } +} - RoiImgViewer::MouseCaptureStatus RoiImgViewer::decideMouseCaptureStatus(const QLineF l, QPointF p, float capDis /*= 10*/) +void RoiImgViewer::createDrawingItem() +{ + switch (mDrawStatus) { - return MouseCaptureNone; - } - - void RoiImgViewer::updateSelectedRoiNode() - { - QGraphicsItem* pItem = firstSelectedItem(); - - LP_ROI_NODE *pRoiNode = findRoiNode(pItem); - if (pRoiNode != mpSelectedRoiNode) + case DrawLine: + if (!mpDrawingLineItem) { - mpSelectedRoiNode = pRoiNode; - emit roiSelectionChanged(mpSelectedRoiNode); + mpDrawingLineItem = scene()->addLine(mDrawingLine); + mpDrawingLineItem->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable); } - } - - void RoiImgViewer::updateDrawingItem() - { - switch (mDrawStatus) + else { - case DrawLine: - if (mpDrawingLineItem) - { - QPen pen = mpDrawingLineItem->pen(); - pen.setColor(Qt::yellow); - pen.setWidth(5); - mpDrawingLineItem->setPen(pen); - mpDrawingLineItem->setLine(mDrawingLine); - } - else - { - qWarning() << tr("line item is not created"); - } - break; - case DrawRect: - if (mpDrawingRectItem) - { - QPen pen = mpDrawingRectItem->pen(); - pen.setColor(Qt::yellow); - pen.setWidth(5); - mpDrawingRectItem->setPen(pen); - mpDrawingRectItem->setRect(mDrawingRect); - } - else - { - qWarning() << tr("line item is not created"); - } - break; - default: - break; + qWarning() << tr("line item is already created"); } - } - - void RoiImgViewer::createDrawingItem() - { - switch (mDrawStatus) + break; + case DrawRect: + if (!mpDrawingRectItem) { - case DrawLine: - if (!mpDrawingLineItem) - { - mpDrawingLineItem = scene()->addLine(mDrawingLine); - mpDrawingLineItem->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable); - } - else - { - qWarning() << tr("line item is already created"); - } - break; - case DrawRect: - if (!mpDrawingRectItem) - { - mpDrawingRectItem = scene()->addRect(mDrawingRect); - mpDrawingRectItem->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable); - } - else - { - qWarning() << tr("rect item is already created"); - } - break; - default: - break; + mpDrawingRectItem = scene()->addRect(mDrawingRect); + mpDrawingRectItem->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable); } - } - - void RoiImgViewer::acceptDrawingItem() - { - //clearExistRois(); - switch (mDrawStatus) + else { - case DrawLine: - if (mpDrawingLineItem) - { - acceptRoiItem(mpDrawingLineItem); - mpDrawingLineItem = NULL; - } - break; - case DrawRect: - if (mpDrawingRectItem) - { - acceptRoiItem(mpDrawingRectItem); - mpDrawingRectItem = NULL; - } - break; - default: - break; + qWarning() << tr("rect item is already created"); } + break; + default: + break; } +} - void RoiImgViewer::rejectDrawingItem() +void RoiImgViewer::acceptDrawingItem() +{ + //clearExistRois(); + switch (mDrawStatus) { - switch (mDrawStatus) + case DrawLine: + if (mpDrawingLineItem) { - case DrawLine: - scene()->removeItem(mpDrawingLineItem); + acceptRoiItem(mpDrawingLineItem); mpDrawingLineItem = NULL; - break; - case DrawRect: - scene()->removeItem(mpDrawingRectItem); + } + break; + case DrawRect: + if (mpDrawingRectItem) + { + acceptRoiItem(mpDrawingRectItem); mpDrawingRectItem = NULL; - break; - default: - break; } + break; + default: + break; } +} - void RoiImgViewer::resetAllDrawingItems() +void RoiImgViewer::rejectDrawingItem() +{ + switch (mDrawStatus) { + case DrawLine: + scene()->removeItem(mpDrawingLineItem); mpDrawingLineItem = NULL; + break; + case DrawRect: + scene()->removeItem(mpDrawingRectItem); mpDrawingRectItem = NULL; + break; + default: + break; + } +} + +void RoiImgViewer::resetAllDrawingItems() +{ + mpDrawingLineItem = NULL; + mpDrawingRectItem = NULL; +} + +void RoiImgViewer::acceptRoiItem(QGraphicsItem* pItem) +{ + int type = pItem->type(); + if (mRoiItemMap.contains(type)) + { + mRoiItemMap[type].append(pItem); + } + else + { + QList itemList; + itemList << pItem; + mRoiItemMap.insert(type, itemList); } - void RoiImgViewer::acceptRoiItem(QGraphicsItem* pItem) + if (type == QGraphicsRectItem::Type) { - int type = pItem->type(); - if (mRoiItemMap.contains(type)) - { - mRoiItemMap[type].append(pItem); - } - else - { - QList itemList; - itemList << pItem; - mRoiItemMap.insert(type, itemList); - } + LP_ROI_NODE roi_node; + roi_node.fScale = fixedSizeScale(); + roi_node.szChannel = getChannel(); + roi_node.pItem = qgraphicsitem_cast(pItem); - if (type == QGraphicsRectItem::Type) - { - LP_ROI_NODE roi_node; - roi_node.fScale = fixedSizeScale(); - roi_node.szChannel = getChannel(); - roi_node.pItem = qgraphicsitem_cast(pItem); + //roi_node.id = uniqueTimeID(); + qint64 msecs = QDateTime::currentMSecsSinceEpoch(); + roi_node.id = QString::number(msecs, 16); - //roi_node.id = uniqueTimeID(); - qint64 msecs = QDateTime::currentMSecsSinceEpoch(); - roi_node.id = QString::number(msecs, 16); + roi_node.isTemplate = true; + mRoiNodeList.append(roi_node); + } - roi_node.isTemplate = true; - mRoiNodeList.append(roi_node); - } +} +LP_ROI_NODE* RoiImgViewer::findRoiNode(QGraphicsItem* pItem) +{ + auto i = std::find_if(mRoiNodeList.begin(), mRoiNodeList.end(), [&](LP_ROI_NODE& roiNode) + { + return roiNode.pItem == pItem; + }); + if (i == mRoiNodeList.end()) + { + return NULL; } - - LP_ROI_NODE* RoiImgViewer::findRoiNode(QGraphicsItem* pItem) + else { - auto i = std::find_if(mRoiNodeList.begin(), mRoiNodeList.end(), [&](LP_ROI_NODE& roiNode) - { - return roiNode.pItem == pItem; - }); - if (i == mRoiNodeList.end()) - { - return NULL; - } - else - { - return &(*i); - } + return &(*i); } +} diff --git a/src/lpMain/algela/RoiImgViewer.h b/src/lpMain/algela/RoiImgViewer.h index c21ddca..032f7a3 100644 --- a/src/lpMain/algela/RoiImgViewer.h +++ b/src/lpMain/algela/RoiImgViewer.h @@ -1,4 +1,5 @@ -#pragma once +#ifndef _H_ROIIMGVIEWER_H_ +#define _H_ROIIMGVIEWER_H_ #include "lpImgViewer.h" #include @@ -13,97 +14,94 @@ typedef struct tagLP_ROI_NODE { Q_DECLARE_METATYPE(LP_ROI_NODE*) - typedef QMap > RoiItemMap; - - class RoiImgViewer : public lpImgViewer - { - Q_OBJECT - - public: - enum MouseCaptureStatus - { - MouseCaptureLeft, - MouseCaptureRight, - MouseCaptureTop, - MouseCaptureBottom, - MouseCaptureNone - }; - - enum DrawStatus - { - DrawLine, - DrawRect, - DrawNone - }; - - public: - RoiImgViewer(QWidget* parent = 0); - ~RoiImgViewer() {}; - - virtual void wheelEvent(QWheelEvent *evt); - - QGraphicsPixmapItem* setImg(QImage& img); - - QGraphicsItem* firstSelectedItem(); - - void setDrawStatus(DrawStatus s); - - void clearRois(int type = -1); - void clearExistRois(); - - float getMouseCaptureDistance() const { return mMouseCaptureDistance; } - void setMouseCaptureDistance(float val) { mMouseCaptureDistance = val; } - - void addRoiRect(QRectF rect, qreal scale, QString channelName, QString id, bool isTemplate = true, QColor nonTmplColor = Qt::yellow); - void addRoiRect(QRectF rect, qreal scale, QString id); - - void addRoiLine(QLineF line, QString id); - - QList getRectROIs() const { return mRoiNodeList; } - LP_ROI_NODE* lastRectRoi(); - - protected: - void mousePressEvent(QMouseEvent *event); - void mouseMoveEvent(QMouseEvent *evt); - void mouseReleaseEvent(QMouseEvent *event); - void keyPressEvent(QKeyEvent *event); - - MouseCaptureStatus decideMouseCaptureStatus(const QRectF r, - QPointF p, float capDis = 10); - MouseCaptureStatus decideMouseCaptureStatus(const QLineF l, - QPointF p, float capDis = 10); - - protected slots: - void updateSelectedRoiNode(); - - protected: - float mMouseCaptureDistance; - - MouseCaptureStatus mMouseCaptureStatus; - - DrawStatus mDrawStatus; - QLineF mDrawingLine; - QRectF mDrawingRect; - QGraphicsLineItem* mpDrawingLineItem; - QGraphicsRectItem* mpDrawingRectItem; - void updateDrawingItem(); - void createDrawingItem(); - void acceptDrawingItem(); - void rejectDrawingItem(); - void resetAllDrawingItems(); - - void acceptRoiItem(QGraphicsItem* pItem); - LP_ROI_NODE* findRoiNode(QGraphicsItem* pItem); - RoiItemMap mRoiItemMap; - QList mRoiNodeList; - LP_ROI_NODE* mpSelectedRoiNode; - - signals: - void roiChanged(QGraphicsItem* pItem); - void roiAdded(QGraphicsItem* pItem); - void roiSelectionChanged(LP_ROI_NODE* pSelectedRoiNode); - - private: - - }; +typedef QMap > RoiItemMap; + +class RoiImgViewer : public lpImgViewer +{ + Q_OBJECT + +public: + enum MouseCaptureStatus + { + MouseCaptureLeft, + MouseCaptureRight, + MouseCaptureTop, + MouseCaptureBottom, + MouseCaptureNone + }; + + enum DrawStatus + { + DrawLine, + DrawRect, + DrawNone + }; + +public: + RoiImgViewer(QWidget* parent = 0); + ~RoiImgViewer() {}; + + virtual void wheelEvent(QWheelEvent *evt); + + QGraphicsPixmapItem* setImg(QImage& img); + + QGraphicsItem* firstSelectedItem(); + + void setDrawStatus(DrawStatus s); + + void clearRois(int type = -1); + void clearExistRois(); + + float getMouseCaptureDistance() const { return mMouseCaptureDistance; } + void setMouseCaptureDistance(float val) { mMouseCaptureDistance = val; } + + void addRoiRect(QRectF rect, qreal scale, QString channelName, QString id, bool isTemplate = true, QColor nonTmplColor = Qt::yellow); + void addRoiRect(QRectF rect, qreal scale, QString id); + + void addRoiLine(QLineF line, QString id); + + QList getRectROIs() const { return mRoiNodeList; } + LP_ROI_NODE* lastRectRoi(); + +protected: + void mousePressEvent(QMouseEvent *event); + void mouseMoveEvent(QMouseEvent *evt); + void mouseReleaseEvent(QMouseEvent *event); + void keyPressEvent(QKeyEvent *event); + + MouseCaptureStatus decideMouseCaptureStatus(const QRectF r, + QPointF p, float capDis = 10); + MouseCaptureStatus decideMouseCaptureStatus(const QLineF l, + QPointF p, float capDis = 10); + +protected slots: + void updateSelectedRoiNode(); +signals: + void roiChanged(QGraphicsItem* pItem); + void roiAdded(QGraphicsItem* pItem); + void roiSelectionChanged(LP_ROI_NODE* pSelectedRoiNode); +protected: + float mMouseCaptureDistance; + + MouseCaptureStatus mMouseCaptureStatus; + + DrawStatus mDrawStatus; + QLineF mDrawingLine; + QRectF mDrawingRect; + QGraphicsLineItem* mpDrawingLineItem; + QGraphicsRectItem* mpDrawingRectItem; + void updateDrawingItem(); + void createDrawingItem(); + void acceptDrawingItem(); + void rejectDrawingItem(); + void resetAllDrawingItems(); + + void acceptRoiItem(QGraphicsItem* pItem); + LP_ROI_NODE* findRoiNode(QGraphicsItem* pItem); + RoiItemMap mRoiItemMap; + QList mRoiNodeList; + LP_ROI_NODE* mpSelectedRoiNode; +}; + +#endif diff --git a/src/lpMain/algela/lpImgViewer.cpp b/src/lpMain/algela/lpImgViewer.cpp index 0832500..a054191 100644 --- a/src/lpMain/algela/lpImgViewer.cpp +++ b/src/lpMain/algela/lpImgViewer.cpp @@ -1,235 +1,248 @@ -#include "lpImgViewer.h" +#include "lpImgViewer.h" #include #include #include #include #include +lpImgViewer::lpImgViewer(QWidget* parent /*= 0*/) + : QGraphicsView(parent), mpImgItem(NULL), mpInfoLabel(NULL), mpImg(NULL), m_scale(1.0), mMinScaleThre(0.01), + mIsFixedSizeScale(false), mFixedSizeScale(1.0), mImgScaleFunc(NULL), mIsAutoResetTransform(false) +{ + QGraphicsScene* lpScene = new QGraphicsScene; + setScene(lpScene); + setResizeAnchor(QGraphicsView::AnchorUnderMouse); + setTransformationAnchor(QGraphicsView::AnchorUnderMouse); +} + +lpImgViewer::lpImgViewer(QGraphicsScene *scene, QWidget *parent /*= 0*/) + : QGraphicsView(scene, parent), mpImgItem(NULL), mpInfoLabel(NULL), mpImg(NULL), m_scale(1.0), + mIsFixedSizeScale(false), mFixedSizeScale(1.0), mImgScaleFunc(NULL), mIsAutoResetTransform(false) +{ + setResizeAnchor(QGraphicsView::AnchorUnderMouse); + setTransformationAnchor(QGraphicsView::AnchorUnderMouse); +} + +void lpImgViewer::setInitScale(qreal val) +{ + scaleImg2(val); +} + +QGraphicsPixmapItem* lpImgViewer::setImg(QImage& img) +{ + scene()->setBackgroundBrush(Qt::darkGray); + + if (mpImg) + delete mpImg; + mpImg = new QImage(img); + + if (!mpImgItem) + { + mpImgItem = scene()->addPixmap(QPixmap::fromImage(img, Qt::NoFormatConversion)); + + } + else + mpImgItem->setPixmap(QPixmap::fromImage(img, Qt::NoFormatConversion)); + QPointF mpos = mpImgItem->pos(); + if (mpos.x() == 0 && mpos.y() == 0) + { + mpImgItem->setPos(scene()->width() / 2, scene()->height() / 2); + } + mpImgItem->setOffset(-img.width() / 2.0, -img.height() / 2.0); + scene()->setSceneRect(QRectF(0, 0, img.width(), img.height())); + mImgOriSize = img.size(); + mMinScaleThre = 1.0 / std::min(mImgOriSize.width(), mImgOriSize.height()); + //qreal scale = std::min((qreal)size().width() / img.width(), (qreal)size().height() / img.height()); + + if (isAutoResetTransform()) + { + mpImgItem->setPos(0, 0); + qreal scale = 1.0f; + scaleImg2(scale); + this->centerOn(0, 0); + } + mpImgItem->setFlags(QGraphicsItem::ItemIsMovable); + + return mpImgItem; +} + +void lpImgViewer::setResetCenter() +{ + if(mpImgItem) + mpImgItem->setPos(scene()->width() /2, scene()->height()/2); +} + +void lpImgViewer::wheelEvent(QWheelEvent *evt) +{ + if (mpImgItem) + { + qreal numDegrees = evt->angleDelta().y() / 120; + + if (!isFixedSizeScale()) + { + qreal newScale = transform().m11(); + if (numDegrees > 0) + newScale *= std::pow(1.1, numDegrees); + else if (numDegrees < 0) + newScale *= std::pow(0.9, -numDegrees); + + mpImgItem->setTransformOriginPoint(0, 0); + scaleImg2(newScale); + emit sgImageScale(newScale); + } + else + { + qreal newScale = fixedSizeScale(); + if (numDegrees > 0) + newScale *= std::pow(1.2, numDegrees); + else if (numDegrees < 0) + newScale *= std::pow(0.8, -numDegrees); + if (newScale > 1.0) + newScale = 1.0; + if (newScale < mMinScaleThre) + newScale = mMinScaleThre; - lpImgViewer::lpImgViewer(QWidget* parent /*= 0*/) - : QGraphicsView(parent), mpImgItem(NULL), mpInfoLabel(NULL), mpImg(NULL), m_scale(1.0), mMinScaleThre(0.01), - mIsFixedSizeScale(false), mFixedSizeScale(1.0), mImgScaleFunc(NULL), mIsAutoResetTransform(false) - { - QGraphicsScene* lpScene = new QGraphicsScene; - setScene(lpScene); - setResizeAnchor(QGraphicsView::AnchorUnderMouse); - setTransformationAnchor(QGraphicsView::AnchorUnderMouse); - } + setFixedSizeScale(newScale); - lpImgViewer::lpImgViewer(QGraphicsScene *scene, QWidget *parent /*= 0*/) - : QGraphicsView(scene, parent), mpImgItem(NULL), mpInfoLabel(NULL), mpImg(NULL), m_scale(1.0), - mIsFixedSizeScale(false), mFixedSizeScale(1.0), mImgScaleFunc(NULL), mIsAutoResetTransform(false) - { - setResizeAnchor(QGraphicsView::AnchorUnderMouse); - setTransformationAnchor(QGraphicsView::AnchorUnderMouse); - } - - - void lpImgViewer::setInitScale(qreal val) - { - scaleImg2(val); + scaleImageWithFixedViewSize(); + } } +} - - - - - QGraphicsPixmapItem* lpImgViewer::setImg(QImage& img) +void lpImgViewer::mouseMoveEvent(QMouseEvent *evt) +{ + if (mpImgItem) { - if (mpImg) - delete mpImg; - mpImg = new QImage(img); + QPoint curpos = (mpImgItem->mapFromScene(this->mapToScene(evt->pos())) + + QPointF(mImgOriSize.width() / 2.0, mImgOriSize.height() / 2.0)+ QPointF(-0.5, -0.5)).toPoint(); - if (!mpImgItem) - mpImgItem = scene()->addPixmap(QPixmap::fromImage(img, Qt::NoFormatConversion)); + if (mpInfoLabel)//��ʾ����ֵ + selectPixel(curpos); else - mpImgItem->setPixmap(QPixmap::fromImage(img, Qt::NoFormatConversion)); - - mpImgItem->setOffset(-img.width() / 2.0, -img.height() / 2.0); - - mImgOriSize = img.size(); - mMinScaleThre = 1.0 / std::min(mImgOriSize.width(), mImgOriSize.height()); - //qreal scale = std::min((qreal)size().width() / img.width(), (qreal)size().height() / img.height()); - - if (isAutoResetTransform()) - { - mpImgItem->setPos(0, 0); - qreal scale = 1.0f; - scaleImg2(scale); - this->centerOn(0, 0); - } - mpImgItem->setFlags(QGraphicsItem::ItemIsMovable); - - return mpImgItem; + emit pixelSelected(curpos); } - void lpImgViewer::wheelEvent(QWheelEvent *evt) + if (mpImgItem && mpImgItem->isSelected()) { - if (mpImgItem) - { - qreal numDegrees = evt->angleDelta().y() / 120; - - if (!isFixedSizeScale()) - { - qreal newScale = transform().m11(); - if (numDegrees > 0) - newScale *= std::pow(1.1, numDegrees); - else if (numDegrees < 0) - newScale *= std::pow(0.9, -numDegrees); - - mpImgItem->setTransformOriginPoint(0, 0); - scaleImg2(newScale); - } - else - { - qreal newScale = fixedSizeScale(); - if (numDegrees > 0) - newScale *= std::pow(1.2, numDegrees); - else if (numDegrees < 0) - newScale *= std::pow(0.8, -numDegrees); - - if (newScale > 1.0) newScale = 1.0; - if (newScale < mMinScaleThre) newScale = mMinScaleThre; - - setFixedSizeScale(newScale); - - scaleImageWithFixedViewSize(); - } - } + QPointF pos = mpImgItem->scenePos(); + qDebug() << pos; + emit imgMoved(pos); } - void lpImgViewer::mouseMoveEvent(QMouseEvent *evt) - { - if (mpImgItem) - { - QPoint curpos = (mpImgItem->mapFromScene(this->mapToScene(evt->pos())) + - QPointF(mImgOriSize.width() / 2.0, mImgOriSize.height() / 2.0) + QPointF(-0.5, -0.5)).toPoint(); + QGraphicsView::mouseMoveEvent(evt); +} - if (mpInfoLabel) - selectPixel(curpos); - else - emit pixelSelected(curpos); - } +void lpImgViewer::resizeEvent(QResizeEvent* evt) +{ + QGraphicsView::resizeEvent(evt); +} - if (mpImgItem && mpImgItem->isSelected()) - { - QPointF pos = mpImgItem->scenePos(); - qDebug() << pos; - emit imgMoved(pos); - } +void lpImgViewer::mouseReleaseEvent(QMouseEvent *evt) +{ + QGraphicsView::mouseReleaseEvent(evt); + if (mpImgItem) + mpImgItem->setSelected(false); +} - QGraphicsView::mouseMoveEvent(evt); - } +void lpImgViewer::closeEvent(QCloseEvent *evt) +{ + deleteLater(); +} - void lpImgViewer::resizeEvent(QResizeEvent* evt) - { - QGraphicsView::resizeEvent(evt); - } +void lpImgViewer::moveImg(QPointF pos) +{ + if (mpImgItem) + mpImgItem->setPos(pos); +} - void lpImgViewer::mouseReleaseEvent(QMouseEvent *evt) +QString lpImgViewer::pixelInfoStr(QPoint pos, QRgb _rgb) +{ + QColor rgb(_rgb); + QColor hsv = rgb.toHsv(); + QString infoStr("Position:[%1, %2] Color(RGB):[%3, %4, %5] (HSV):[%6, %7, %8]"); + infoStr = infoStr.arg(pos.x()).arg(pos.y()) + .arg(rgb.red()).arg(rgb.green()).arg(rgb.blue()) + .arg(hsv.hue() / 2).arg(hsv.saturation()).arg(hsv.value()); + return infoStr; +} + +void lpImgViewer::selectPixel(QPoint pos) +{ + if (pos.x() < 0 || pos.y() < 0 || pos.x() > mImgOriSize.width() || pos.y() > mImgOriSize.height()) { - QGraphicsView::mouseReleaseEvent(evt); - if (mpImgItem) - mpImgItem->setSelected(false); + mpInfoLabel->setText(QString("out of image...")); + return; } - void lpImgViewer::closeEvent(QCloseEvent *evt) + if (!mpImgItem) { - deleteLater(); + return; } - void lpImgViewer::moveImg(QPointF pos) + QImage img = mpImgItem->pixmap().toImage(); + QRgb pixel = img.pixel(pos); + + mpInfoLabel->setText(pixelInfoStr(pos, pixel)); +} + +void lpImgViewer::scaleImageWithFixedViewSize() +{ + if (!mpImg) { - if (mpImgItem) - mpImgItem->setPos(pos); + return; } - - QString lpImgViewer::pixelInfoStr(QPoint pos, QRgb _rgb) + QImage scaledImage; + if (!imgScaleFunc()) { - QColor rgb(_rgb); - QColor hsv = rgb.toHsv(); - QString infoStr("Position:[%1, %2] Color(RGB):[%3, %4, %5] (HSV):[%6, %7, %8]"); - infoStr = infoStr.arg(pos.x()).arg(pos.y()) - .arg(rgb.red()).arg(rgb.green()).arg(rgb.blue()) - .arg(hsv.hue() / 2).arg(hsv.saturation()).arg(hsv.value()); - return infoStr; + scaledImage = mpImg->scaled(mpImg->width()*mFixedSizeScale, mpImg->height()*mFixedSizeScale, + Qt::IgnoreAspectRatio, Qt::SmoothTransformation); + mpImgItem->setPixmap(QPixmap::fromImage(scaledImage.scaled(mpImg->width(), + mpImg->height()), Qt::NoFormatConversion)); } - - void lpImgViewer::selectPixel(QPoint pos) + else { - if (pos.x() < 0 || pos.y() < 0 || pos.x() > mImgOriSize.width() || pos.y() > mImgOriSize.height()) - { - mpInfoLabel->setText(QString("out of image...")); - return; - } - - if (!mpImgItem) - { - return; - } - - QImage img = mpImgItem->pixmap().toImage(); - QRgb pixel = img.pixel(pos); - - mpInfoLabel->setText(pixelInfoStr(pos, pixel)); + scaledImage = mImgScaleFunc(*mpImg, mFixedSizeScale, Qt::SmoothTransformation); + mpImgItem->setPixmap(QPixmap::fromImage(mImgScaleFunc(scaledImage, + 1.0 / mFixedSizeScale, Qt::FastTransformation), Qt::NoFormatConversion)); } - void lpImgViewer::scaleImageWithFixedViewSize() - { - if (!mpImg) - { - return; - } - QImage scaledImage; - if (!imgScaleFunc()) - { - scaledImage = mpImg->scaled(mpImg->width()*mFixedSizeScale, mpImg->height()*mFixedSizeScale, - Qt::IgnoreAspectRatio, Qt::SmoothTransformation); - mpImgItem->setPixmap(QPixmap::fromImage(scaledImage.scaled(mpImg->width(), - mpImg->height()), Qt::NoFormatConversion)); - } - else - { - scaledImage = mImgScaleFunc(*mpImg, mFixedSizeScale, Qt::SmoothTransformation); - mpImgItem->setPixmap(QPixmap::fromImage(mImgScaleFunc(scaledImage, - 1.0 / mFixedSizeScale, Qt::FastTransformation), Qt::NoFormatConversion)); - } + emit imgScaledWithFixedSize(fixedSizeScale()); +} - emit imgScaledWithFixedSize(fixedSizeScale()); - } +void lpImgViewer::scaleImg(QTransform tf, QPointF center) +{ + this->resetTransform(); + this->setTransform(tf); + this->centerOn(center); +} - void lpImgViewer::scaleImg(QTransform tf, QPointF center) - { - this->resetTransform(); - this->setTransform(tf); - this->centerOn(center); - } +void lpImgViewer::scaleImg2(qreal scale) +{ + if (scale < 0.01) + return; + m_scale = scale; + QTransform t; + t.scale(scale, scale); + this->setTransform(t); - void lpImgViewer::scaleImg2(qreal scale) - { - m_scale = scale; - QTransform t; - t.scale(scale, scale); - this->setTransform(t); + QPointF center = this->mapToScene(width() / 2, height() / 2); - QPointF center = this->mapToScene(width() / 2, height() / 2); + emit imgScaled(this->transform(), center); +} - emit imgScaled(this->transform(), center); - } +void lpImgViewer::clear() +{ + m_scale = 1.0f; + m_channel = ""; + scene()->clear(); + mpImgItem = NULL; - void lpImgViewer::clear() + if (mpImg) { - m_scale = 1.0f; - m_channel = ""; - scene()->clear(); - mpImgItem = NULL; - - if (mpImg) - { - delete mpImg; - mpImg = NULL; - } + delete mpImg; + mpImg = NULL; } +} diff --git a/src/lpMain/algela/lpImgViewer.h b/src/lpMain/algela/lpImgViewer.h index ab63cec..773a9e5 100644 --- a/src/lpMain/algela/lpImgViewer.h +++ b/src/lpMain/algela/lpImgViewer.h @@ -1,4 +1,5 @@ -#pragma once +#ifndef _H_LPIMGVIEWER_H_ +#define _H_LPIMGVIEWER_H_ #include #include @@ -23,6 +24,7 @@ public: virtual QGraphicsPixmapItem* setImg(QImage& img); void setInfoLabel(QLabel* ipLabel){ mpInfoLabel = ipLabel; } + void setResetCenter(); const QImage* img() { return mpImg; } QGraphicsPixmapItem* imgItem() { return mpImgItem; } @@ -54,7 +56,7 @@ signals: void imgMoved(QPointF pos); void pixelSelected(QPoint pos); void imgScaledWithFixedSize(qreal scale); - + void sgImageScale(qreal); public slots: void scaleImg(QTransform tf, QPointF center); void moveImg(QPointF pos); @@ -62,11 +64,11 @@ public slots: void scaleImageWithFixedViewSize(); protected: - QGraphicsPixmapItem* mpImgItem; + QGraphicsPixmapItem* mpImgItem{ nullptr }; QSize mImgOriSize; qreal mMinScaleThre; - QLabel* mpInfoLabel; - QImage* mpImg; + QLabel* mpInfoLabel{ nullptr }; + QImage* mpImg{ nullptr }; void scaleImg2(qreal scale); qreal m_scale; @@ -79,3 +81,5 @@ protected: ImageScaleFun mImgScaleFunc; }; + +#endif diff --git a/src/lpMain/algela/qtUtils.cpp b/src/lpMain/algela/qtUtils.cpp new file mode 100644 index 0000000..dfdbf25 --- /dev/null +++ b/src/lpMain/algela/qtUtils.cpp @@ -0,0 +1,627 @@ +#include "qtUtils.h" +#include "QFileInfo" +#include "QTextStream" +#include "QFileDialog" +#include +#include +#include +//#include "QtUiTools/QUiLoader" +#include +#include + +using std::cout; +using std::endl; + +QString uniqueTimeID() +{ + qint64 msecs = QDateTime::currentMSecsSinceEpoch(); + return QString::number(msecs, 16); +} + +void assignGridLayoutProperties(QGridLayout* pSrc, QGridLayout* pDst) +{ + int horizontalSpace = pSrc->horizontalSpacing(); + int verticalSpace = pSrc->verticalSpacing(); + QMargins margins = pSrc->contentsMargins(); + + pDst->setHorizontalSpacing(horizontalSpace); + pDst->setVerticalSpacing(verticalSpace); + pDst->setContentsMargins(margins); +} + +//static QUiLoader sCloneLoader; + +// QWidget* cloneWidgetProperties(const QWidget* pSrc, const QString& namePostfix) +// { +// if (pSrc == nullptr) return nullptr; +// auto moSrc = pSrc->metaObject(); +// +// // init a same widget +// QWidget* pDst = qobject_cast(moSrc->newInstance(nullptr)); +// if (pDst == nullptr) { +// QString cn = moSrc->className(); +// pDst = sCloneLoader.createWidget(cn); +// } +// +// if (pDst) +// { +// QString n = pSrc->objectName() + namePostfix; +// pDst->setObjectName(n); +// +// QList nws; +// foreach(QObject* o, pSrc->children()) +// { +// QWidget* w = qobject_cast(o); +// if (w) { +// QWidget* nw = cloneWidgetProperties(w, namePostfix); +// nw->setParent(pDst); +// nws.push_back(nw); +// } +// } +// +// QLayout* layoutSrc = pSrc->layout(); +// QLayout* layoutDst = nullptr; +// if (layoutSrc) { +// layoutDst = cloneLayoutProperties(layoutSrc, pDst, &nws); +// } +// +// for (int i = moSrc->propertyOffset(); i < moSrc->propertyCount(); ++i) +// { +// QMetaProperty p = moSrc->property(i); +// if (p.isWritable()) +// { +// #ifdef _DEBUG +// const char* pn = p.name(); +// QVariant val = p.read(pSrc); +// #endif // _DEBUG +// bool ret = pDst->setProperty(p.name(), p.read(pSrc)); +// #ifdef _DEBUG +// QVariant val2 = pDst->property(p.name()); +// if (val != val2) { +// std::cout << "cannot clone: " << p.name() << "\n"; +// } +// #endif // _DEBUG +// } +// } +// +// pDst->setMinimumSize(pSrc->minimumSize()); +// pDst->setMaximumSize(pSrc->maximumSize()); +// pDst->setSizePolicy(pSrc->sizePolicy()); +// pDst->setBaseSize(pSrc->baseSize()); +// +// pDst->setStyleSheet(pSrc->styleSheet()); +// } +// +// return pDst; +// } +// +// /*ANGELA_DLLSPEC*/ QLayout* cloneLayoutProperties(const QLayout* pSrc, QWidget* pDstParent, QList* pDstWgts) +// { +// if (!pSrc || !pDstParent || !pDstWgts) return nullptr; +// auto moSrc = pSrc->metaObject(); +// +// // init a same layout +// QLayout* pDst = qobject_cast(moSrc->newInstance(nullptr)); +// QString cn = moSrc->className(); +// if (!pDst) { +// pDst = sCloneLoader.createLayout(cn, pDstParent); +// } +// +// if (pDst) +// { +// int srcCount = pSrc->count(); +// for (int i = 0, wIdx = 0; i < srcCount; ++i) +// { +// QLayoutItem* item = pSrc->itemAt(i); +// +// QSpacerItem* sp = dynamic_cast(item); +// if (sp) { +// QSpacerItem* nsp = new QSpacerItem(*sp); +// pDst->addItem(nsp); +// } +// +// QWidgetItem* wi = dynamic_cast(item); +// if (wi) { +// pDst->addWidget(pDstWgts->at(wIdx)); +// wIdx++; +// } +// } +// +// // can't get property out of meta object for layout +// // do it manually +// pDst->setContentsMargins(pSrc->contentsMargins()); +// pDst->setSpacing(pSrc->spacing()); +// pDst->setSizeConstraint(pSrc->sizeConstraint()); +// +// if (cn == QLatin1String("QGridLayout")) { +// const QGridLayout* p0 = qobject_cast(pSrc); +// QGridLayout* p1 = qobject_cast(pDst); +// p1->setHorizontalSpacing(p0->horizontalSpacing()); +// p1->setVerticalSpacing(p0->verticalSpacing()); +// } +// else if (cn == QLatin1String("QHBoxLayout") || cn == QLatin1String("QVBoxLayout")) +// { +// const QBoxLayout* bSrc = dynamic_cast(pSrc); +// QBoxLayout* bDst = dynamic_cast(pDst); +// int itemcount = pDst->count(); +// for (int i = 0; i < itemcount; ++i) +// { +// bDst->setStretch(i, bSrc->stretch(i)); +// } +// } +// } +// +// return pDst; +// } + +void clearQPixmap(QPixmap& pixmap, QColor color) +{ + QPixmap& canvas = pixmap; + QPainter p(&canvas); + QPen pen; + pen.setColor(color); + p.setPen(pen); + QBrush brush; + brush.setStyle(Qt::SolidPattern); + brush.setColor(color); + p.setBrush(brush); + p.drawRect(0, 0, canvas.width(), canvas.height()); +} + +QString truncate2BaseName(QString filePath) +{ + QFileInfo fio(filePath); + return fio.baseName(); +} + +bool isAnyContainedIn(QStringList strList, QString str) +{ + foreach(QString s, strList) + { + if (str.contains(s)) + { + return true; + } + } + return false; +} + +bool isContainedInAny(QString str, QStringList strList) +{ + foreach(QString s, strList) + { + if (s.contains(str)) + { + return true; + } + } + return false; +} + +QStringList str2list(QString str) +{ + QTextStream ts(&str); + QStringList strLst; + while (!ts.atEnd()) + { + QString str; + ts >> str; + strLst << str; + } + return strLst; +} + +QString dirPath2Name(QString str) +{ + QFileInfo fio(str); + return fio.baseName(); +} + +void loadPixmaps(QStringList imgPaths, QList& pixmapList) +{ + foreach(QString fp, imgPaths) + { + QPixmap pixmap; + if (!pixmap.load(fp)) + { + continue; + } + pixmapList.append(pixmap); + } +} + +QString rect2str(QRectF rect) +{ + return QString("%1, %2, %3, %4").arg(rect.x()).arg(rect.y()).arg(rect.width()).arg(rect.height()); +} + +bool syncComboBoxSelectedIdx(QComboBox* pSrc, QComboBox* pDst) +{ + int srcIdx = pSrc->currentIndex(); + int dstCount = pDst->count(); + if (srcIdx >= 0 && srcIdx < dstCount) + { + pDst->setCurrentIndex(srcIdx); + return true; + } + else + { + return false; + } +} + +bool syncComboBoxSelectedText(QComboBox* pSrc, QComboBox* pDst) +{ + QString srcText = pSrc->currentText(); + int dstIdx = pDst->findText(srcText); + if (dstIdx >= 0 && dstIdx < pDst->count()) + { + pDst->setCurrentIndex(dstIdx); + return true; + } + else + { + return false; + } +} + +bool changeComboBoxSelection(QComboBox* pSrc, QString text, Qt::MatchFlags flags /*= static_cast(Qt::MatchExactly | Qt::MatchCaseSensitive)*/) +{ + int idx = pSrc->findText(text, flags); + if (idx >= 0 && idx < pSrc->count()) + { + pSrc->setCurrentIndex(idx); + return true; + } + else + { + return false; + } +} + +void addListItem(QListWidget* pListWidget, const QList& pixmapList) +{ + foreach(QPixmap pixmap, pixmapList) + { + QListWidgetItem* pItem = new QListWidgetItem; + QIcon icon(pixmap); + pItem->setIcon(QIcon(pixmap)); + pListWidget->addItem(pItem); + } +} + +void updateThumbList(QListWidget* pListWidget, const QList& pixmapList) +{ + pListWidget->clear(); + + addListItem(pListWidget, pixmapList); +} + +void getListWidgetItems(const QListWidget* pListWidget, const QList& idxList, QList& itemList) +{ + if (!pListWidget) + { + return; + } + foreach(int idx, idxList) + { + if (idx < 0 || idx >= pListWidget->count()) + { + continue; + } + QListWidgetItem* pItem = pListWidget->item(idx); + itemList.append(pItem); + } +} + +void setListWidgetItemBackgroundColor(const QList& itemList, QColor color) +{ + foreach(QListWidgetItem* pItem, itemList) + { + pItem->setBackgroundColor(color); + } +} + +void setListWidgetItemBackgroundColor(QListWidget* pListWidget, const QList& itemIdxList, QColor color) +{ + QList itemList; + getListWidgetItems(pListWidget, itemIdxList, itemList); + setListWidgetItemBackgroundColor(itemList, color); +} + +int changeSelectedItemInListWidget(QListWidget* pListWidget, QList& preSelectedItems) +{ + if (!pListWidget) + { + return -1; + } + setListWidgetItemBackgroundColor(preSelectedItems, Qt::white); + QList selectedItems = pListWidget->selectedItems(); + if (selectedItems.isEmpty()) + { + return -1; + } + QListWidgetItem* pFirstItem = selectedItems.front(); + if (!pFirstItem) + { + return -1; + } + pFirstItem->setBackgroundColor(Qt::blue); + preSelectedItems.clear(); + preSelectedItems.append(pFirstItem); + int itemIdx = pListWidget->row(pFirstItem); + + return itemIdx; +} + +int changeSelectedItemInListWidget(QListWidget* pListWidget, QList& preSelectedItemIdxs) +{ + if (!pListWidget) + { + return -1; + } + setListWidgetItemBackgroundColor(pListWidget, preSelectedItemIdxs, Qt::white); + QList selectedItems = pListWidget->selectedItems(); + if (selectedItems.isEmpty()) + { + return -1; + } + QListWidgetItem* pFirstItem = selectedItems.front(); + if (!pFirstItem) + { + return -1; + } + pFirstItem->setBackgroundColor(Qt::blue); + preSelectedItemIdxs.clear(); + int itemIdx = pListWidget->row(pFirstItem); + preSelectedItemIdxs.append(itemIdx); + + return itemIdx; +} + +int firstSelectedItemIdx(QListWidget* pListWidget) +{ + auto items = pListWidget->selectedItems(); + if (!items.size()) + { + return -1; + } + + QListWidgetItem* pItem = items.front(); + return pListWidget->row(pItem); +} + +void setListWidgetItemSelected(QListWidget* pListWidget, const QList& itemList) +{ + foreach(QListWidgetItem* pItem, itemList) + { + pListWidget->setItemSelected(pItem, true); + } +} + +QTableWidgetItem* newAndGetTableItem(QTableWidget* pTable, int row, int col) +{ + QTableWidgetItem* pItem = pTable->item(row, col); + if (!pItem) + { + pItem = new QTableWidgetItem; + pTable->setItem(row, col, pItem); + } + return pItem; +} + +QGraphicsItem * firstSelectedItem(const QGraphicsView *pView) +{ + if (!pView) + { + return NULL; + } + + QGraphicsScene *pScene = pView->scene(); + return firstSelectedItem(pScene); +} + +QListWidgetItem * firstSelectedItem(QListWidget *pListWidget) +{ + auto items = pListWidget->selectedItems(); + if (!items.size()) + { + return NULL; + } + + return items.front(); +} + +QGraphicsItem* firstSelectedItem(const QGraphicsScene* pScene) +{ + QList selectedItems = pScene->selectedItems(); + if (selectedItems.isEmpty()) return nullptr; + return selectedItems.front(); +} + +void setPenColor(QAbstractGraphicsShapeItem *pShapeItem, QColor color) +{ + if (!pShapeItem) + { + return; + } + QPen pen = pShapeItem->pen(); + pen.setColor(color); + pShapeItem->setPen(pen); +} + +QFileInfoList recursiveEntryInfoList(QDir dir, const QStringList& nameFilters, + QDir::Filters filters /*= QDir::NoFilter*/) +{ + QList dirList; + dirList.append(dir); + QFileInfoList ret; + filters |= QDir::AllDirs | QDir::NoDotAndDotDot; + while (dirList.size()) + { + QDir dir(dirList.front()); + dirList.pop_front(); + + cout << "find dir " << dir.path().toLocal8Bit().data() << endl; + + QFileInfoList fioList = dir.entryInfoList(nameFilters, filters); + + foreach(QFileInfo fio, fioList) + { + if (fio.isDir()) + { + dirList.append(QDir(fio.filePath())); + } + else + { + ret.append(fio); + } + } + } + return ret; +} + +int changeSelectedItemInListWidget(QListWidget* pListWidget, const QList& selectedItemIdxs, + QList& preSelectedItemIdxs) +{ + if (!pListWidget) + { + return -1; + } + QList selectedItemList; + getListWidgetItems(pListWidget, selectedItemIdxs, selectedItemList); + setListWidgetItemSelected(pListWidget, selectedItemList); + return changeSelectedItemInListWidget(pListWidget, preSelectedItemIdxs); +} + +void insertToLayout(QLayout* l, int index, QWidget* w, int stretch, Qt::Alignment align) +{ + if (l == nullptr) return; + + // horizontal or vertical layout + QBoxLayout* bl = dynamic_cast(l); + if (bl) { + bl->insertWidget(index, w, stretch, align); + return; + } + + // grid layout + QGridLayout* gl = dynamic_cast(l); + if (gl) { + gl->addWidget(w, 0, index, align); + return; + } + + // others + l->addWidget(w); +} + +void insertToLayout(QLayout* l, int index, QLayout* nl, int stretch, Qt::Alignment align) +{ + if (l == nullptr) return; + + // horizontal or vertical layout + QBoxLayout* bl = dynamic_cast(l); + if (bl) { + bl->insertLayout(index, nl, stretch); + return; + } + + // grid layout + QGridLayout* gl = dynamic_cast(l); + if (gl) { + gl->addLayout(nl, 0, index, align); + return; + } + + // others + l->addItem(nl); +} + +void insertToLayout(QLayout* l, int index, QLayoutItem* item, int stretch, Qt::Alignment align) +{ + if (l == nullptr) return; + + // horizontal or vertical layout + QBoxLayout* bl = dynamic_cast(l); + if (bl) { + bl->insertItem(index, item); + bl->insertStretch(index, stretch); + return; + } + + // grid layout + QGridLayout* gl = dynamic_cast(l); + if (gl) { + gl->addItem(item, 0, index); + return; + } + + // others + l->addItem(item); +} + +QLayout* getOrCreateBoxLayout(QWidget* w, bool isVertical, int margin, int space) +{ + if (!w) return nullptr; + + QLayout* l = w->layout(); + if (l) return l; // already have a layout; + + if (isVertical) + l = new QVBoxLayout(w); + else l = new QHBoxLayout(w); + + l->setMargin(margin); + l->setSpacing(space); + + return l; +} + +int findWidgetInLayout(QLayout* l, QWidget* w, QLayout** ol) +{ + if (!l || !w || !ol) return -1; + *ol = nullptr; + + int idx = l->indexOf(w); + if (idx != -1) { + *ol = l; + return idx; + } + + int itemCount = l->count(); + for (int i = 0; i < itemCount; ++i) + { + QLayoutItem* lItem = l->itemAt(i); + QLayout* nestl = dynamic_cast(lItem); + if (nestl) { + QLayout* retl = nullptr; + int nestIdx = findWidgetInLayout(nestl, w, &retl); + if (nestIdx != -1) { + *ol = retl; + return nestIdx; + } + } + } + + return -1; +} + +void moveWgtToDesktopCenter(QWidget* wgt) +{ + const QRect& desktopRect = QApplication::desktop()->availableGeometry(); + QRect rt = wgt->geometry(); + rt.moveCenter(desktopRect.center()); + wgt->setGeometry(rt); +} + +QPointF getPolygonCenter(const QPolygonF& poly) +{ + QPointF cen; + foreach(const QPointF& pnt, poly) { + cen += pnt; + } + cen /= poly.size(); + return cen; +} + diff --git a/src/lpMain/algela/qtUtils.h b/src/lpMain/algela/qtUtils.h new file mode 100644 index 0000000..3e9f586 --- /dev/null +++ b/src/lpMain/algela/qtUtils.h @@ -0,0 +1,174 @@ +#ifndef _qtUtils_h_ +#define _qtUtils_h_ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "AngelaCommon.h" + +QString uniqueTimeID(); + +void assignGridLayoutProperties(QGridLayout* pSrc, QGridLayout* pDst); + +void clearQPixmap(QPixmap& pixmap, QColor color); + +QString truncate2BaseName(QString filePath); + +bool isAnyContainedIn(QStringList strList, QString str); +bool isContainedInAny(QString str, QStringList strList); + +QStringList str2list(QString str); + +template +QString list2Str(const QList<_Ty>& l, QString sep = " ") +{ + QString s; + QTextStream ts(&s); + foreach(const _Ty& v, l) + { + ts << v << sep; + } + return s; +} + +QString dirPath2Name(QString str); + +void loadPixmaps(QStringList imgPaths, QList& pixmapList); + +QString rect2str(QRectF rect); + +/************************************************************************/ +/* QList Utilities */ +/************************************************************************/ + +// element at index idx is not included +template +QList<_T> listRightOf(const QList<_T>& l, int idx) +{ + if (idx < 0 || idx >= l.size()) + { + return l; + } + + return l.mid(idx + 1, l.size() - idx - 1); +} + +// element with value val is not included +template +QList<_T> listRightOf(const QList<_T>& l, const _T& val) +{ + int idx = l.indexOf(val); + return listRightOf(l, idx); +} + +/************************************************************************/ +/* QComboBox Utilities */ +/************************************************************************/ + +template +void addElements2ComboBox(_It si, _It ei, QComboBox* pComboBox) +{ + while (si != ei) + { + QString str; + QTextStream ts(&str); + ts << *si; + pComboBox->addItem(str); + ++si; + } +} + +bool syncComboBoxSelectedIdx(QComboBox* pSrc, QComboBox* pDst); + +bool syncComboBoxSelectedText(QComboBox* pSrc, QComboBox* pDst); + +bool changeComboBoxSelection(QComboBox* pSrc, QString text, + Qt::MatchFlags flags = static_cast(Qt::MatchExactly | Qt::MatchCaseSensitive)); + +/************************************************************************/ +/* QListWidget Utilities */ +/************************************************************************/ + +void addListItem(QListWidget* pListWidget, const QList& pixmapList); + +void updateThumbList(QListWidget* pListWidget, const QList& pixmapList); + +void getListWidgetItems(const QListWidget* pListWidget, const QList& idxList, QList& itemList); + +void setListWidgetItemBackgroundColor(const QList& itemList, QColor color); +void setListWidgetItemBackgroundColor(QListWidget* pListWidget, const QList& itemIdxList, QColor color); + +int changeSelectedItemInListWidget(QListWidget* pListWidget, + QList& preSelectedItems); +int changeSelectedItemInListWidget(QListWidget* pListWidget, + QList& preSelectedItemIdxs); +int changeSelectedItemInListWidget(QListWidget* pListWidget, const QList& selectedItemIdxs, + QList& preSelectedItemIdxs); + +int firstSelectedItemIdx(QListWidget* pListWidget); +QListWidgetItem *firstSelectedItem(QListWidget *pListWidget); + +void setListWidgetItemSelected(QListWidget* pListWidget, const QList& itemList); + +/************************************************************************/ +/* QTableWidget Utilities */ +/************************************************************************/ + +QTableWidgetItem* newAndGetTableItem(QTableWidget* pTable, int row, int col); + +/************************************************************************/ +/* QGraphicsView Utilities */ +/************************************************************************/ + +QGraphicsItem *firstSelectedItem(const QGraphicsView *pView); +QGraphicsItem* firstSelectedItem(const QGraphicsScene* pScene); + +/************************************************************************/ +/* QAbstractGraphicsShapeItem Utilities */ +/************************************************************************/ + +void setPenColor(QAbstractGraphicsShapeItem *pShapeItem, QColor color); + +/************************************************************************/ +/* QDir Utilities */ +/************************************************************************/ + +QFileInfoList recursiveEntryInfoList(QDir dir, const QStringList& nameFilters, + QDir::Filters filters = QDir::NoFilter); + +/************************************************************************/ +/* QLayout Utilities */ +/************************************************************************/ +/*ANGELA_DLLSPEC*/ void insertToLayout(QLayout* l, int index, QWidget* w, + int stretch = 0, Qt::Alignment align = Qt::AlignCenter); + +/*ANGELA_DLLSPEC*/ void insertToLayout(QLayout* l, int index, QLayout* nl, + int stretch = 0, Qt::Alignment align = Qt::AlignCenter); + +/*ANGELA_DLLSPEC*/ void insertToLayout(QLayout* l, int index, QLayoutItem* item, + int stretch = 0, Qt::Alignment align = Qt::AlignCenter); + +/*ANGELA_DLLSPEC*/ QLayout* getOrCreateBoxLayout(QWidget* w, bool isVertical = false, + int margin = 0, int space = 0); + + +/*ANGELA_DLLSPEC*/ int findWidgetInLayout(QLayout* l, QWidget* w, QLayout** ol); + +/************************************************************************/ +/* QWidget Utilities */ +/************************************************************************/ +/*ANGELA_DLLSPEC*/ void moveWgtToDesktopCenter(QWidget* wgt); + +/****************************************************************************/ +/* Qt Graphics Utilities */ +/****************************************************************************/ +QPointF getPolygonCenter(const QPolygonF& poly); + +#endif // _qtUtils_h_ diff --git a/src/lpMain/cryptokey/QCryptokeyUI.cpp b/src/lpMain/cryptokey/QCryptokeyUI.cpp new file mode 100644 index 0000000..00c274b --- /dev/null +++ b/src/lpMain/cryptokey/QCryptokeyUI.cpp @@ -0,0 +1,64 @@ +#include "QCryptokeyUI.h" +#include "lpGlobalData.h" +#include "lpCryptokey.h" +#include +#pragma execution_character_set("utf-8") +QCryptokeyUI::QCryptokeyUI(QWidget *parent) + : QWidget(parent) +{ + ui.setupUi(this); + connect(ui.pushButton, SIGNAL(clicked()), this, SLOT(onButtonClicked())); + connect(ui.pushButton_2, SIGNAL(clicked()), this, SLOT(onButtonClicked())); +} + +QCryptokeyUI::~QCryptokeyUI() +{ +} + +void QCryptokeyUI::setInfo(QString strSerialNo, bool bCheck) +{ + ui.m_lineEdit_Serial->setText(strSerialNo); + if (bCheck == false) + { + ui.m_label_Active->setText("未激活"); + ui.m_label_Active->setStyleSheet("color:rgb(255, 10, 10)"); + } + else { + ui.m_label_Active->setText("已激活"); + ui.m_label_Active->setStyleSheet("color:rgb(10, 201, 10)"); + } + ui.textEdit->clear(); +} + +Q_SLOT void QCryptokeyUI::onButtonClicked() +{ + QString strObj = sender()->objectName(); + if (strObj == "pushButton") + { + QString strKey = ui.textEdit->toPlainText(); + if (strKey.isEmpty()) + { + QMessageBox::information(this, tr("提示"), "请输入注册码"); + return; + } + QString strSerialNo = ui.m_lineEdit_Serial->text(); + bool check = lpCheckKey::instance()->checkLinese(strSerialNo, strKey); + + if (check == false) + { + QMessageBox::information(this, tr("提示"), "注册码不匹配,请重新输入"); + return; + } + else + { + ui.m_label_Active->setText("已激活"); + ui.m_label_Active->setStyleSheet("color:rgb(10, 201, 10)"); + emit sgRegisterFinish(true); + QMessageBox::information(this, tr("提示"), "系统激活完成"); + } + } + else if (strObj == "pushButton_2") + { + close(); + } +} diff --git a/src/lpMain/cryptokey/QCryptokeyUI.h b/src/lpMain/cryptokey/QCryptokeyUI.h new file mode 100644 index 0000000..945076f --- /dev/null +++ b/src/lpMain/cryptokey/QCryptokeyUI.h @@ -0,0 +1,29 @@ +/*! + *FileName: QCryptokeyUI.h + *Author: Pan Yingdong + *Email: bob.pan@hzleaper.com + *Created:2021/3/5 15:23 + *Note: +*/ +#ifndef _H_QCRYPTOKEYUI_H_ +#define _H_QCRYPTOKEYUI_H_ + +#include +#include "ui_QCryptokeyUI.h" + +class QCryptokeyUI : public QWidget +{ + Q_OBJECT + +public: + QCryptokeyUI(QWidget *parent = Q_NULLPTR); + ~QCryptokeyUI(); + + void setInfo(QString strSerialNo, bool bCheck); +signals: + void sgRegisterFinish(bool bCheck); +private: + Q_SLOT void onButtonClicked(); + Ui::QCryptokeyUI ui; +}; +#endif \ No newline at end of file diff --git a/src/lpMain/cryptokey/QCryptokeyUI.ui b/src/lpMain/cryptokey/QCryptokeyUI.ui new file mode 100644 index 0000000..2ea501e --- /dev/null +++ b/src/lpMain/cryptokey/QCryptokeyUI.ui @@ -0,0 +1,169 @@ + + + QCryptokeyUI + + + + 0 + 0 + 648 + 334 + + + + 注册 + + + + + + + 100 + 0 + + + + + 20 + + + + color:rgb(52, 101, 164) + + + 退出 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + 20 + + + + color:rgb(52, 101, 164) + + + 机器码: + + + + + + + + 20 + + + + color:rgb(52, 101, 164) + + + Qt::AlignCenter + + + true + + + + + + + + 20 + + + + color:rgb(52, 101, 164) + + + 注册码: + + + + + + + + 20 + + + + color:rgb(52, 101, 164) + + + 激活 + + + + + + + + 12 + + + + 请输入注册码 + + + + + + + + 20 + + + + color:rgb(52, 101, 164) + + + 激活状态: + + + + + + + + 20 + + + + color:rgb(52, 101, 164) + + + 未激活 + + + + + + + + + + + + + diff --git a/src/lpMain/cryptokey/lpCryptokey.cpp b/src/lpMain/cryptokey/lpCryptokey.cpp new file mode 100644 index 0000000..ff66ae0 --- /dev/null +++ b/src/lpMain/cryptokey/lpCryptokey.cpp @@ -0,0 +1,142 @@ +#include "lpCryptokey.h" +#include +#include "lpHardwareInfo.h" +#include + +namespace lpCryptokey +{ + const QString ComponyKey = "hzleaper"; + QString genSerialNumber(const QString& mac) + { + unsigned long long ulMacTmp = 0; + QString newMac = mac + ComponyKey; + std::string mStrMac = newMac.toStdString(); + mStrMac.erase(std::remove(mStrMac.begin(), mStrMac.end(), ':'), mStrMac.end()); + mStrMac.erase(std::remove(mStrMac.begin(), mStrMac.end(), '-'), mStrMac.end()); + + for (int i = 0; i < mStrMac.size(); i++) + { + ulMacTmp = ulMacTmp << 4; + char cStr = mStrMac.at(i); + if (cStr >= '0'&&cStr <= '9') + ulMacTmp += (int)(mStrMac.at(i) - '0'); + else if (cStr >= 'a'&&cStr <= 'f') + ulMacTmp += (int)(mStrMac.at(i) - 'a' + 10); + else if (cStr >= 'A'&&cStr <= 'F') + ulMacTmp += (int)(mStrMac.at(i) - 'A' + 10); + else + ulMacTmp += 0; + } + QString serial = QString("%1").arg(ulMacTmp); + QString key = QString("%1").arg(serial.mid(serial.size()-9,-1).toInt(),9,10, QLatin1Char('0')); + return key; + } + + QString genEncryption(const QString& serial) + { + QByteArray byte; + byte.append(serial + ComponyKey); + QByteArray MD5byte = QCryptographicHash::hash(byte, QCryptographicHash::Md4); + QString str = MD5byte.toHex().toUpper(); + int size = 20; + int kNum = 4; + QString strKey; + for (int n = 0; n < size / kNum; n++) { + strKey += str.mid(n * kNum, kNum); + if (n < (size / kNum) - 1) + strKey += "-"; + } + return strKey; + } + + bool compareCrypto(const QString& serial, const QString& key) + { + QString tmpKey = genEncryption(serial); + if (tmpKey == key) + return true; + return false; + } + +} + +lpCheckKey::lpCheckKey() +{ + lpHardwareInfo::instance()->init(); + rsa_op.set_params(); + rsa_op.open_prikey_pubkey(); + rsa_op.open_pubkey(); +} + +lpCheckKey::~lpCheckKey() +{ + +} +//检查linese是否匹配 +bool lpCheckKey::checkLinese() +{ + std::string hardDriveID = lpHardwareInfo::instance()->getHardDrive(); + std::string cpuID = lpHardwareInfo::instance()->getCpuID(); + std::string BoardID = lpHardwareInfo::instance()->getMotherBoardID(); + std::string macID = lpHardwareInfo::instance()->getMacAddress(); + if (hardDriveID.size() > 0) + { + m_SerialNo = lpCryptokey::genSerialNumber(QString(hardDriveID.c_str()) + QString(cpuID.c_str())); + } + else { + m_SerialNo = lpCryptokey::genSerialNumber(QString(BoardID.c_str()) + QString(macID.c_str())); + } + QSettings settingKey("Leaper_Register"); + QString strKey = settingKey.value("key").toString(); + bool bRegister = settingKey.value("register", false).toBool(); + QString serialNo = settingKey.value("serialNo").toString(); + if (m_SerialNo != serialNo) + { + if (bRegister == true) + { + return true; + } + } + + QByteArray lineseData = genLinese(m_SerialNo.toLatin1()); + if (lineseData == strKey) + return true; + else + return false; +} + +bool lpCheckKey::checkLinese(QString serialNo, QString linese) +{ + QByteArray lineseData = genLinese(serialNo.toLatin1()); + if (QString(lineseData) == linese) + { + QSettings settingKey("Leaper_Register"); + settingKey.setValue("key", linese); + settingKey.setValue("register", true); + settingKey.setValue("serialNo", serialNo); + return true; + } + else + return false; +} + +QString lpCheckKey::getSerialNo() const +{ + return m_SerialNo; +} + +QByteArray lpCheckKey::genLinese(QByteArray serialNo) +{ + QByteArray character = serialNo; + if (character.length() >= 116) + { + character = character.mid(0, 116); + } + + int enc_len = 0; + unsigned char *enc_data = NULL; + unsigned char *enc_data2 = NULL; + rsa_op.prikey_encrypt((BYTE*)character.data(), character.length() + 1, (unsigned char **)&enc_data, enc_len); + QByteArray licenseKey((char*)enc_data, enc_len); + QByteArray licenseKeyForHex = licenseKey.toHex(); + return licenseKeyForHex; +} diff --git a/src/lpMain/cryptokey/lpCryptokey.h b/src/lpMain/cryptokey/lpCryptokey.h new file mode 100644 index 0000000..f9e4143 --- /dev/null +++ b/src/lpMain/cryptokey/lpCryptokey.h @@ -0,0 +1,32 @@ +#ifndef _H_LPCRYPTOKEY_H_ +#define _H_LPCRYPTOKEY_H_ + +#include +#include +#include "QTpRsaCrypto.h" +#include "lpsingleton.h" + +namespace lpCryptokey +{ + //通过mac或其他字符串生成序列号 + QString genSerialNumber(const QString& mac = "11-22-33-44-55-67");// + //通过序列号生成密钥 + QString genEncryption(const QString& serial); + //通过序列号和密钥进行比较匹配,返回false表示匹配失败 + bool compareCrypto(const QString& serial, const QString& key); +} + +class lpCheckKey:public lpsingleton +{ +public: + lpCheckKey(); + ~lpCheckKey(); + bool checkLinese(); + bool checkLinese(QString serialNo, QString linese); + QString getSerialNo() const; +private: + QByteArray genLinese(QByteArray serialNo); + QString m_SerialNo; + QTpRsaCrypto rsa_op; +}; +#endif diff --git a/src/lpMain/cryptokey/lpHardwareInfo.cpp b/src/lpMain/cryptokey/lpHardwareInfo.cpp new file mode 100644 index 0000000..2f86d7d --- /dev/null +++ b/src/lpMain/cryptokey/lpHardwareInfo.cpp @@ -0,0 +1,293 @@ +#include "lpHardwareInfo.h" + +#include +#include + +#pragma comment (lib, "comsuppw.lib") +#pragma comment (lib, "wbemuuid.lib") + +lpHardwareInfo::lpHardwareInfo() + : mpLoc(NULL) + , mpSvc(NULL) + , mbCoInited(false) + , msCpuID("") + , msMotherBoardID("") + , msBiosID("") + , msMacAddress("") + , mbIsDesktop(false) +{ + +} + +lpHardwareInfo::~lpHardwareInfo() +{ + +} + +void lpHardwareInfo::Close() +{ + deinit(); + delete this; +} + +int lpHardwareInfo::init() +{ + HRESULT hres; + hres = CoInitialize(NULL); + if (FAILED(hres)) { + return QUERY_ERROR_WMI_CONNECT_FAILED; + } + + hres = CoInitializeSecurity( + NULL, + -1, + NULL, + NULL, + RPC_C_AUTHN_LEVEL_DEFAULT, + RPC_C_IMP_LEVEL_IMPERSONATE, + NULL, + EOAC_NONE, + NULL + ); + if (FAILED(hres)) + { + CoUninitialize(); + return QUERY_ERROR_WMI_CONNECT_FAILED; + } + + hres = CoCreateInstance( + CLSID_WbemLocator, + NULL, + CLSCTX_INPROC_SERVER, + IID_IWbemLocator, + reinterpret_cast(&mpLoc) + ); + if (FAILED(hres)) + { + CoUninitialize(); + return QUERY_ERROR_WMI_CONNECT_FAILED; + } + + hres = mpLoc->ConnectServer( + _bstr_t(L"ROOT\\CIMV2"), + NULL, + NULL, + NULL, + 0, + NULL, + NULL, + &mpSvc + ); + if (FAILED(hres)) + { + mpLoc->Release(); + CoUninitialize(); + return QUERY_ERROR_WMI_CONNECT_FAILED; + } + + hres = CoSetProxyBlanket( + mpSvc, + RPC_C_AUTHN_WINNT, + RPC_C_AUTHZ_NONE, + NULL, + RPC_C_AUTHN_LEVEL_CALL, + RPC_C_IMP_LEVEL_IMPERSONATE, + NULL, + EOAC_NONE + ); + if (FAILED(hres)) + { + mpSvc->Release(); + mpLoc->Release(); + CoUninitialize(); + return QUERY_ERROR_WMI_CONNECT_FAILED; + } + + mbCoInited = true; + deviceQuery(); + return 0; +} + +void lpHardwareInfo::deinit() +{ + if (mbCoInited) + { + mpSvc->Release(); + mpLoc->Release(); + CoUninitialize(); + } +} + +void lpHardwareInfo::deviceQuery() +{ + // WMIصAPIĵ + // https://msdn.microsoft.com/en-us/library/aa394132(v=vs.85).aspx + + + //CPU ID + CHAR* szSelect = "SELECT * FROM Win32_Processor WHERE (ProcessorId IS NOT NULL)"; + WCHAR* szProperty = L"ProcessorId"; + deviceQuery(szSelect, szProperty, msCpuID); + + //MotherBoard ID + szSelect = "SELECT * FROM Win32_BaseBoard WHERE (SerialNumber IS NOT NULL)"; + szProperty = L"SerialNumber"; + deviceQuery(szSelect, szProperty, msMotherBoardID); + + //BIOS ID + szSelect = "SELECT * FROM Win32_BIOS WHERE (SerialNumber IS NOT NULL)"; + szProperty = L"SerialNumber"; + deviceQuery(szSelect, szProperty, msBiosID); + + //MAC Address only Physical and not [virtual, vpn, usb, ...] + msMacAddress = ""; + //szSelect = "SELECT * FROM Win32_NetworkAdapter WHERE PhysicalAdapter = true \ + // and NOT Name LIKE '%vpn%' and NOT Name LIKE '%virtual%' \ + // and NOT Name LIKE '%usb%' and NOT Name LIKE '%Bluetooth%'"; + szSelect = "SELECT * FROM Win32_NetworkAdapter WHERE PhysicalAdapter = true \ + and ( Name LIKE '%pci%' or PNPDeviceID LIKE '%pci%')"; + szProperty = L"MACAddress"; + deviceQuery(szSelect, szProperty, msMacAddress); + + //hard disk only "Fixed hard disk media" + msHardDrive = ""; + szSelect = "SELECT * FROM Win32_DiskDrive WHERE MediaType LIKE '%Fixed%'"; + szProperty = L"SerialNumber"; + deviceQuery(szSelect, szProperty, msHardDrive); + + //Desktop or laptop + queryIsDesktop(); +} + +void lpHardwareInfo::deviceQuery(CHAR* szSelect, WCHAR* szProperty, std::string& strRslt) +{ + HRESULT hres; + DEVICE_PROPERTY dpRst; + + // TCHAT to std::string + auto tc2string = [&](TCHAR* ts) -> std::string { + int iLen = WideCharToMultiByte(CP_ACP, 0, ts, -1, NULL, 0, NULL, NULL); + + char* chRtn = new char[iLen * sizeof(char)]; + + WideCharToMultiByte(CP_ACP, 0, ts, -1, chRtn, iLen, NULL, NULL); + + std::string str(chRtn); + delete[] chRtn; + + return str; + }; + + // trim string + auto strTrim = [&](std::string& text) -> std::string& { + if (!text.empty()) { + text.erase(0, text.find_first_not_of(" \n\r\t")); + text.erase(text.find_last_not_of(" \n\r\t") + 1); + } + return text; + }; + + //find sub string case insensitive + auto findStrInCase = [&](std::string& text, std::string& sub) -> bool { + auto it = std::search( + text.begin(), text.end(), + sub.begin(), sub.end(), + [](char ch1, char ch2) { return std::tolower(ch1) == std::tolower(ch2); } + ); + + return (it != text.end()); + }; + + IEnumWbemClassObject *pEnumerator = NULL; + hres = mpSvc->ExecQuery(bstr_t("WQL"), bstr_t(szSelect), + WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY, NULL, &pEnumerator); + if (SUCCEEDED(hres) && pEnumerator != NULL) { + IWbemClassObject *pclsObj = NULL; + ULONG uReturn = 0; + while (pEnumerator) { + pEnumerator->Next(WBEM_INFINITE, 1, &pclsObj, &uReturn); + if (0 == uReturn || !pclsObj) break; + + VARIANT vtProperty; + VariantInit(&vtProperty); + + hres = pclsObj->Get(szProperty, 0, &vtProperty, NULL, NULL); + if (vtProperty.bstrVal != NULL) { + StringCchCopy(dpRst.szProperty, PROPERTY_MAX_LEN, W2T(vtProperty.bstrVal)); + strRslt += strTrim(tc2string(dpRst.szProperty)) + "#"; + } + VariantClear(&vtProperty); + pclsObj->Release(); + + } + pEnumerator->Release(); + } + + //remove last # + size_t pos = strRslt.find_last_of("#"); + if (pos == strRslt.length() - 1) { + strRslt.erase(strRslt.length() - 1); + } +} + +void lpHardwareInfo::queryIsDesktop() +{ + HRESULT hres; + DEVICE_PROPERTY dpRst; + + CHAR* szSelect = "SELECT * FROM Win32_SystemEnclosure"; + WCHAR* szProperty = L"ChassisTypes"; + + IEnumWbemClassObject *pEnumerator = NULL; + hres = mpSvc->ExecQuery(bstr_t("WQL"), bstr_t(szSelect), + WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY, NULL, &pEnumerator); + if (SUCCEEDED(hres) && pEnumerator != NULL) { + IWbemClassObject *pclsObj = NULL; + ULONG uReturn = 0; + while (pEnumerator) { + pEnumerator->Next(WBEM_INFINITE, 1, &pclsObj, &uReturn); + if (0 == uReturn || !pclsObj) break; + + VARIANT vtProperty; + VariantInit(&vtProperty); + pclsObj->Get(szProperty, 0, &vtProperty, NULL, NULL); + + SAFEARRAY* parrValues = NULL; + if (vtProperty.vt & VT_ARRAY) { + if (VT_BYREF & vtProperty.vt) + parrValues = *vtProperty.pparray; + else + parrValues = vtProperty.parray; + } + + if (parrValues != NULL) { + SAFEARRAYBOUND arrayBounds[1]; + arrayBounds[0].lLbound = 0; + arrayBounds[0].cElements = 0; + + SafeArrayGetLBound(parrValues, 1, &arrayBounds[0].lLbound); + SafeArrayGetUBound(parrValues, 1, (long*)&arrayBounds[0].cElements); + arrayBounds[0].cElements -= arrayBounds[0].lLbound; + arrayBounds[0].cElements += 1; + + if (arrayBounds[0].cElements > 0) { + for (ULONG i = 0; i < arrayBounds[0].cElements; i++) { + LONG lIndex = (LONG)i; + INT item; + + HRESULT hr = ::SafeArrayGetElement(parrValues, &lIndex, &item); + if (SUCCEEDED(hr)) { + if (3 == item) { + mbIsDesktop = true; + } + } + } + } + } + VariantClear(&vtProperty); + pclsObj->Release(); + + } + pEnumerator->Release(); + } +} diff --git a/src/lpMain/cryptokey/lpHardwareInfo.h b/src/lpMain/cryptokey/lpHardwareInfo.h new file mode 100644 index 0000000..399e510 --- /dev/null +++ b/src/lpMain/cryptokey/lpHardwareInfo.h @@ -0,0 +1,72 @@ +#ifndef QTPHARDWAREINFO_H__ +#define QTPHARDWAREINFO_H__ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "lp_singleton_base.h" + +#define PROPERTY_MAX_LEN 128 // ֶ󳤶 +typedef struct tagDEVICE_PROPERTY +{ + TCHAR szProperty[PROPERTY_MAX_LEN]; +} DEVICE_PROPERTY; + +typedef enum WQL_QUERY_TYPE +{ + QUERY_CPU_ID = 0, + QUERY_MOTHERBOARD_ID = 1, + QUERY_BIOS_ID = 2, +}; + +typedef enum WQL_QUERY_ERRORCODE +{ + QUERY_ERROR_DEVICE_NOT_SUPPORT = -1, + QUERY_ERROR_WMI_CONNECT_FAILED = -2, + QUERY_ERROR_SQL_SYNTAX_ERROR = -3, +}; + +class lpHardwareInfo : public lp_singleton_base +{ +public: + lpHardwareInfo(); + virtual ~lpHardwareInfo(); + virtual void Close(); + + int init(); + const std::string& getCpuID() const { return msCpuID; } + const std::string& getMotherBoardID() const { return msMotherBoardID; } + const std::string& getBiosID() const { return msBiosID; } + const std::string& getMacAddress() const { return msMacAddress; } + const std::string& getHardDrive() const { return msHardDrive; } + bool isDesktop() const { return mbIsDesktop; } +private: + void deinit(); + + void deviceQuery(); + void deviceQuery(CHAR* szSelect, WCHAR* szProperty, std::string& strRslt); + void queryIsDesktop(); +private: + + IWbemLocator *mpLoc; + IWbemServices *mpSvc; + + bool mbCoInited; + + std::string msCpuID; + std::string msMotherBoardID; + std::string msBiosID; + std::string msMacAddress; // probably is list, separated by # + std::string msHardDrive; // probably is list, separated by # + bool mbIsDesktop; +}; + +#endif //QTPHARDWAREINFO_H__ diff --git a/src/lpMain/lpImageCaliUI.cpp b/src/lpMain/lpImageCaliUI.cpp new file mode 100644 index 0000000..e10e62c --- /dev/null +++ b/src/lpMain/lpImageCaliUI.cpp @@ -0,0 +1,436 @@ +#include "lpImageCaliUI.h" +#include "QFileDialog" +#include "lpGlobalConfig.h" +#include + +#pragma execution_character_set("utf-8") + +lpImageCaliUI::lpImageCaliUI(QWidget *parent) + : QWidget(parent) +{ + ui.setupUi(this); + { + m_srcImgView_1 = replaceWidget(ui.widget); + connect(m_srcImgView_1, SIGNAL(filterroiChanged(const AwesomeRoiInfo& , QString)), this, SLOT(onROIChange(const AwesomeRoiInfo&, QString))); + connect(m_srcImgView_1, SIGNAL(pixelClicked(QPoint)), this, SLOT(onPixelClicked(QPoint))); + connect(m_srcImgView_1, SIGNAL(roiLockIng(QString)), this, SLOT(onRoiLockIng(QString))); + connect(m_srcImgView_1, SIGNAL(sgImageScale(qreal)), this, SLOT(onImageScale(qreal))); + + connect(ui.m_pbLoadImg, SIGNAL(clicked()), this, SLOT(onButtonClicked())); + connect(ui.m_pbApply, SIGNAL(clicked()), this, SLOT(onButtonClicked())); + //connect(ui.m_pbExit, SIGNAL(clicked()), this, SLOT(onButtonClicked())); + connect(ui.m_pbLock, SIGNAL(clicked()), this, SLOT(onButtonClicked())); + } + { + m_srcImgView_2 = replaceWidget(ui.widget_2); + connect(m_srcImgView_2, SIGNAL(filterroiChanged(const AwesomeRoiInfo&, QString)), this, SLOT(onROIChange(const AwesomeRoiInfo&, QString))); + connect(m_srcImgView_2, SIGNAL(pixelClicked(QPoint)), this, SLOT(onPixelClicked(QPoint))); + connect(m_srcImgView_2, SIGNAL(roiLockIng(QString)), this, SLOT(onRoiLockIng(QString))); + connect(m_srcImgView_2, SIGNAL(sgImageScale(qreal)), this, SLOT(onImageScale(qreal))); + + connect(ui.m_pbLoadImg_2, SIGNAL(clicked()), this, SLOT(onButtonClicked())); + connect(ui.m_pbApply_2, SIGNAL(clicked()), this, SLOT(onButtonClicked())); + //connect(ui.m_pbExit, SIGNAL(clicked()), this, SLOT(onButtonClicked())); + connect(ui.m_pbLock_2, SIGNAL(clicked()), this, SLOT(onButtonClicked())); + } + + QString strPath = QApplication::applicationDirPath() + "/showImg.ini";//图像展示比例的参数 + QSettings setting(strPath, QSettings::IniFormat); + double nScale_1 = setting.value("ShowImg/Scale_Standard_1", 0.53).toDouble(); + m_srcImgView_1->setInitScale(nScale_1); + double nScale_2 = setting.value("ShowImg/Scale_Standard_2", 0.53).toDouble(); + m_srcImgView_2->setInitScale(nScale_2); +} + +lpImageCaliUI::~lpImageCaliUI() +{ + if (m_srcImgView_1) { + delete m_srcImgView_1; + m_srcImgView_1 = nullptr; + } + if (m_srcImgView_2) { + delete m_srcImgView_2; + m_srcImgView_2 = nullptr; + } +} + +template +_Widget* lpImageCaliUI::replaceWidget(QWidget* pSrcWidget) +{ + if (!pSrcWidget) { + return nullptr; + } + QWidget* pParent = qobject_cast(pSrcWidget->parent()); + if (!pParent) { + return nullptr; + } + _Widget* pDstWidget = new _Widget; + auto *pFrom = pParent->layout()->replaceWidget(pSrcWidget, pDstWidget); + delete pFrom; + delete pSrcWidget; + return pDstWidget; +} + +void lpImageCaliUI::showEvent(QShowEvent *event) +{ + { + ui.m_lineEdit_P1X->setText(QString("%1").arg(lpGlobalConfig::instance()->point1_1.x())); + ui.m_lineEdit_P1Y->setText(QString("%1").arg(lpGlobalConfig::instance()->point1_1.y())); + ui.m_lineEdit_P2X->setText(QString("%1").arg(lpGlobalConfig::instance()->point2_1.x())); + ui.m_lineEdit_P2Y->setText(QString("%1").arg(lpGlobalConfig::instance()->point2_1.y())); + + ui.m_lineEdit_Xoffset->setText(QString("%1").arg(lpGlobalConfig::instance()->m_StationXOffset_1)); + ui.m_lineEdit_Yoffset->setText(QString("%1").arg(lpGlobalConfig::instance()->m_StationYOffset_1)); + + m_point1_1 = lpGlobalConfig::instance()->point1_1; + m_point2_1 = lpGlobalConfig::instance()->point2_1; + + double pixlen = CalLength(m_point1_1, m_point2_1); + ui.m_lineEdit_pixlength->setText(QString("%1").arg(pixlen)); + ui.m_lineEdit_length->setText(QString("%1").arg(lpGlobalConfig::instance()->fLength_1)); + ui.m_lineEdit_scale->setText(QString("%1").arg(lpGlobalConfig::instance()->m_StationScale_1)); + if (m_srcImgView_1) + { + m_srcImgView_1->onClearAllROI(); + QString DstPath = QApplication::applicationDirPath() + "\\user\\StandImage_1.jpg"; + QImage img; + img.load(DstPath); + + m_imageH_1 = img.height(); + m_imageW_1 = img.width(); + m_srcImgView_1->setImg(img); + + AddPoint(m_point1_1, "P1"); + AddPoint(m_point2_1, "P2"); + m_srcImgView_1->setLabelVisible(true); + m_srcImgView_1->setLockAll(true); + } + ui.m_pbLock->setText(tr("解锁")); + } + { + ui.m_lineEdit_P1X_2->setText(QString("%1").arg(lpGlobalConfig::instance()->point1_2.x())); + ui.m_lineEdit_P1Y_2->setText(QString("%1").arg(lpGlobalConfig::instance()->point1_2.y())); + ui.m_lineEdit_P2X_2->setText(QString("%1").arg(lpGlobalConfig::instance()->point2_2.x())); + ui.m_lineEdit_P2Y_2->setText(QString("%1").arg(lpGlobalConfig::instance()->point2_2.y())); + + ui.m_lineEdit_Xoffset_2->setText(QString("%1").arg(lpGlobalConfig::instance()->m_StationXOffset_2)); + ui.m_lineEdit_Yoffset_2->setText(QString("%1").arg(lpGlobalConfig::instance()->m_StationYOffset_2)); + + m_point1_2 = lpGlobalConfig::instance()->point1_2; + m_point2_2 = lpGlobalConfig::instance()->point2_2; + + double pixlen = CalLength(m_point1_2, m_point2_2); + ui.m_lineEdit_pixlength_2->setText(QString("%1").arg(pixlen)); + ui.m_lineEdit_length_2->setText(QString("%1").arg(lpGlobalConfig::instance()->fLength_2)); + ui.m_lineEdit_scale_2->setText(QString("%1").arg(lpGlobalConfig::instance()->m_StationScale_2)); + if (m_srcImgView_2) + { + m_srcImgView_2->onClearAllROI(); + QString DstPath = QApplication::applicationDirPath() + "\\user\\StandImage_2.jpg"; + QImage img; + img.load(DstPath); + + m_imageH_2 = img.height(); + m_imageW_2 = img.width(); + m_srcImgView_2->setImg(img); + + AddPoint_2(m_point1_2, "P1"); + AddPoint_2(m_point2_2, "P2"); + m_srcImgView_2->setLabelVisible(true); + m_srcImgView_2->setLockAll(true); + } + ui.m_pbLock_2->setText(tr("解锁")); + } +} + +void lpImageCaliUI::changeEvent(QEvent *event) +{ + if (event->type() == QEvent::LanguageChange) + { + ui.retranslateUi(this); + } +} + +Q_SLOT void lpImageCaliUI::onButtonClicked() +{ + QString strObj = sender()->objectName(); + if (strObj == "m_pbLoadImg") + { + QString fileName = QFileDialog::getOpenFileName(this, tr("选择标定图"), "/home/jana", tr("Image Files (*.png *.jpg *.bmp)")); + if (!fileName.isEmpty()) + { + QString DstPath = QApplication::applicationDirPath() + "\\user\\StandImage_1.jpg"; + QString sourcePath = fileName; + DstPath.replace("\\", "/"); + if (sourcePath == DstPath) { + } + if (!QFile::exists(sourcePath)) { + } + QDir *createfile = new QDir; + bool exist = createfile->exists(DstPath); + if (exist) { + createfile->remove(DstPath); + } + QImage img; + img.load(fileName); + img.save(DstPath); + if (m_srcImgView_1) { + m_imageH_1 = img.height(); + m_imageW_1 = img.width(); + m_srcImgView_1->setImg(img); + m_srcImgView_1->onClearAllROI(); + AddPoint(m_point1_1, "P1"); + AddPoint(m_point2_1, "P2"); + m_srcImgView_1->setLabelVisible(true); + m_srcImgView_1->setLockAll(true); + ui.m_pbLock->setText(tr("解锁")); + } + delete createfile; + createfile = nullptr; + } + } + if (strObj == "m_pbLoadImg_2") + { + QString fileName = QFileDialog::getOpenFileName(this, tr("选择标定图"), "/home/jana", tr("Image Files (*.png *.jpg *.bmp)")); + if (!fileName.isEmpty()) + { + QString DstPath = QApplication::applicationDirPath() + "\\user\\StandImage_2.jpg"; + QString sourcePath = fileName; + DstPath.replace("\\", "/"); + if (sourcePath == DstPath) { + } + if (!QFile::exists(sourcePath)) { + } + QDir *createfile = new QDir; + bool exist = createfile->exists(DstPath); + if (exist) { + createfile->remove(DstPath); + } + QImage img; + img.load(fileName); + img.save(DstPath); + if (m_srcImgView_2) { + m_imageH_2 = img.height(); + m_imageW_2 = img.width(); + m_srcImgView_2->setImg(img); + m_srcImgView_2->onClearAllROI(); + AddPoint_2(m_point1_2, "P1"); + AddPoint_2(m_point2_2, "P2"); + m_srcImgView_2->setLabelVisible(true); + m_srcImgView_2->setLockAll(true); + ui.m_pbLock_2->setText(tr("解锁")); + } + delete createfile; + createfile = nullptr; + } + } + else if("m_pbApply" == strObj) + { + double pixlength = ui.m_lineEdit_pixlength->text().toDouble(); + double length = ui.m_lineEdit_length->text().toDouble(); + double scale = length * 1.0 / ( pixlength > 0 ? pixlength:length); + ui.m_lineEdit_scale->setText(QString("%1").arg(scale)); + lpGlobalConfig::instance()->m_StationXOffset_1 = ui.m_lineEdit_Xoffset->text().toInt(); + lpGlobalConfig::instance()->m_StationYOffset_1 = ui.m_lineEdit_Yoffset->text().toInt(); + lpGlobalConfig::instance()->point1_1 = m_point1_1; + lpGlobalConfig::instance()->point2_1 = m_point2_1; + lpGlobalConfig::instance()->fLength_1 = length; + lpGlobalConfig::instance()->m_StationScale_1 = scale; + lpGlobalConfig::instance()->writeConfig(); + } + else if ("m_pbApply_2" == strObj) + { + double pixlength = ui.m_lineEdit_pixlength_2->text().toDouble(); + double length = ui.m_lineEdit_length_2->text().toDouble(); + double scale = length * 1.0 / (pixlength > 0 ? pixlength : length); + ui.m_lineEdit_scale_2->setText(QString("%1").arg(scale)); + lpGlobalConfig::instance()->m_StationXOffset_2 = ui.m_lineEdit_Xoffset_2->text().toInt(); + lpGlobalConfig::instance()->m_StationYOffset_2 = ui.m_lineEdit_Yoffset_2->text().toInt(); + lpGlobalConfig::instance()->point1_2 = m_point1_2; + lpGlobalConfig::instance()->point2_2 = m_point2_2; + lpGlobalConfig::instance()->fLength_2 = length; + lpGlobalConfig::instance()->m_StationScale_2 = scale; + lpGlobalConfig::instance()->writeConfig(); + } + else if("m_pbExit" == strObj) + { + close(); + } + else if("m_pbLock" == strObj) + { + QString str = ui.m_pbLock->text(); + if (str == tr("解锁")) { + ui.m_pbLock->setText(tr("上锁")); + if (m_srcImgView_1) + { + m_srcImgView_1->setLockAll(false); + } + } + else { + if (m_srcImgView_1) + { + m_srcImgView_1->setLockAll(true); + } + ui.m_pbLock->setText(tr("解锁")); + } + } + else if ("m_pbLock_2" == strObj) + { + QString str = ui.m_pbLock_2->text(); + if (str == tr("解锁")) { + ui.m_pbLock_2->setText(tr("上锁")); + if (m_srcImgView_2) + { + m_srcImgView_2->setLockAll(false); + } + } + else { + if (m_srcImgView_2) + { + m_srcImgView_2->setLockAll(true); + } + ui.m_pbLock_2->setText(tr("解锁")); + } + } +} + + +Q_SLOT void lpImageCaliUI::onROIChange(const AwesomeRoiInfo& roiInfo, QString strID) +{ + if (sender() == m_srcImgView_1) + { + if (strID == "P1") + { + QPointF p = roiInfo.vertex.at(0); + m_point1_1.setX(p.x()); + m_point1_1.setY(p.y()); + ui.m_lineEdit_P1X->setText(QString("%1").arg(m_point1_1.x())); + ui.m_lineEdit_P1Y->setText(QString("%1").arg(m_point1_1.y())); + + } + else if (strID == "P2") + { + QPointF p = roiInfo.vertex.at(0); + m_point2_1.setX(p.x()); + m_point2_1.setY(p.y()); + ui.m_lineEdit_P2X->setText(QString("%1").arg(m_point2_1.x())); + ui.m_lineEdit_P2Y->setText(QString("%1").arg(m_point2_1.y())); + } + + double pixlen = CalLength(m_point1_1, m_point2_1); + ui.m_lineEdit_pixlength->setText(QString("%1").arg(pixlen)); + } + else if (sender() == m_srcImgView_2) + { + if (strID == "P1") + { + QPointF p = roiInfo.vertex.at(0); + m_point1_2.setX(p.x()); + m_point1_2.setY(p.y()); + ui.m_lineEdit_P1X_2->setText(QString("%1").arg(m_point1_2.x())); + ui.m_lineEdit_P1Y_2->setText(QString("%1").arg(m_point1_2.y())); + + } + else if (strID == "P2") + { + QPointF p = roiInfo.vertex.at(0); + m_point2_2.setX(p.x()); + m_point2_2.setY(p.y()); + ui.m_lineEdit_P2X_2->setText(QString("%1").arg(m_point2_2.x())); + ui.m_lineEdit_P2Y_2->setText(QString("%1").arg(m_point2_2.y())); + } + + double pixlen = CalLength(m_point1_2, m_point2_2); + ui.m_lineEdit_pixlength_2->setText(QString("%1").arg(pixlen)); + } +} + +Q_SLOT void lpImageCaliUI::onPixelClicked(QPoint point) +{ + int a = 0; +} + +Q_SLOT void lpImageCaliUI::onImageScale(qreal value) +{ + if (sender() == m_srcImgView_1) + { + QString strPath = QApplication::applicationDirPath() + "/showImg.ini"; + QSettings setting(strPath, QSettings::IniFormat); + QObject *obj = sender(); + setting.setValue("ShowImg/Scale_Standard_1", value); + } + else if (sender() == m_srcImgView_2) + { + QString strPath = QApplication::applicationDirPath() + "/showImg.ini"; + QSettings setting(strPath, QSettings::IniFormat); + QObject *obj = sender(); + setting.setValue("ShowImg/Scale_Standard_2", value); + } +} + +double lpImageCaliUI::CalLength(QPoint &p1, QPoint &p2) +{ + double pixLen = sqrt(pow(p1.x() - p2.x(), 2) + pow(p1.y() - p2.y(), 2)); + return pixLen; +} + +void lpImageCaliUI::AddPoint(QPoint &p,QString strName) +{ + if (m_srcImgView_1) + { + int x = p.x(); + int y = p.y(); + int xp = (x - m_imageW_1 / 2); + int yp = (y - m_imageH_1 / 2); + m_srcImgView_1->addPointRoi(QPointF(xp, yp), lpGlobalConfig::instance()->pointCircle, 0, strName, QColor(0, 255, 0), QColor(255, 0, 255)); + } +} + +void lpImageCaliUI::AddPoint_2(QPoint &p, QString strName) +{ + if (m_srcImgView_2) + { + int x = p.x(); + int y = p.y(); + int xp = (x - m_imageW_2 / 2); + int yp = (y - m_imageH_2 / 2); + m_srcImgView_2->addPointRoi(QPointF(xp, yp), lpGlobalConfig::instance()->pointCircle, 0, strName, QColor(0, 255, 0), QColor(255, 0, 255)); + } +} + +Q_SLOT void lpImageCaliUI::onRoiLockIng(QString strName) +{ + if (sender() == m_srcImgView_1) + { + ui.label_info->setText("不能操作,请解锁"); + ui.label_info->setStyleSheet("background-color: rgb(255, 68, 55);"); + if (m_timerID == 0) + { + m_timerID = startTimer(1000); + } + } + else if (sender() == m_srcImgView_2) + { + ui.label_info_2->setText("不能操作,请解锁"); + ui.label_info_2->setStyleSheet("background-color: rgb(255, 68, 55);"); + if (m_timerID == 0) + { + m_timerID = startTimer(1000); + } + } +} + +void lpImageCaliUI::timerEvent(QTimerEvent *event) +{ + if (m_timerID == event->timerId()) + { + killTimer(m_timerID); + m_timerID = 0; + ui.label_info->setText(""); + ui.label_info->setStyleSheet(""); + ui.label_info_2->setText(""); + ui.label_info_2->setStyleSheet(""); + } +} + + diff --git a/src/lpMain/lpImageCaliUI.h b/src/lpMain/lpImageCaliUI.h new file mode 100644 index 0000000..edb97f1 --- /dev/null +++ b/src/lpMain/lpImageCaliUI.h @@ -0,0 +1,59 @@ +#ifndef _LPIMAGECALIUI_H_ +#define _LPIMAGECALIUI_H_ + +#include +#include "ui_lpImageCaliUI.h" +#include "AwesomeImgViewer.h" + +class lpImageCaliUI : public QWidget +{ + Q_OBJECT + +public: + lpImageCaliUI(QWidget *parent = Q_NULLPTR); + ~lpImageCaliUI(); + + template + _Widget* replaceWidget(QWidget* pSrcWidget); + + +protected: + double CalLength(QPoint &p1, QPoint &p2); + void AddPoint(QPoint &p, QString strName); + void AddPoint_2(QPoint &p, QString strName); + Q_SLOT void onButtonClicked(); + Q_SLOT void onROIChange(const AwesomeRoiInfo& roiInfo, QString strID); + Q_SLOT void onPixelClicked(QPoint point); + Q_SLOT void onImageScale(qreal scale); + Q_SLOT void onRoiLockIng(QString strName); +protected: + virtual void showEvent(QShowEvent *event); + virtual void changeEvent(QEvent *event); + virtual void timerEvent(QTimerEvent *event); +private: + Ui::lpImageCaliUI ui; + + //1 + AwesomeImgViewer *m_srcImgView_1{ nullptr }; + int m_imageH_1{0}; + int m_imageW_1{0}; + + QPoint m_point1_1; + QPoint m_point2_1; + double m_length_1; + double m_scale_1; + + //2 + AwesomeImgViewer *m_srcImgView_2{ nullptr }; + int m_imageH_2{ 0 }; + int m_imageW_2{ 0 }; + + QPoint m_point1_2; + QPoint m_point2_2; + double m_length_2; + double m_scale_2; + // + int m_timerID{ 0 }; +}; + +#endif diff --git a/src/lpMain/lpImageCaliUI.ui b/src/lpMain/lpImageCaliUI.ui new file mode 100644 index 0000000..d2ac58d --- /dev/null +++ b/src/lpMain/lpImageCaliUI.ui @@ -0,0 +1,610 @@ + + + lpImageCaliUI + + + + 0 + 0 + 917 + 569 + + + + 相机视场标定 + + + + + + + 12 + + + + 0 + + + + 工位1相机视场标定 + + + + + + + 9 + 0 + + + + background-color: rgb(197, 197, 197); + + + + + + + + + + 0 + 0 + + + + + 12 + + + + + + + + + 12 + + + + + + + + + + + + + + + 3 + 0 + + + + + 12 + + + + 操作 + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 12 + + + + 选择标定图像 + + + + + + + + + + + + + + + + + P1_X: + + + + + + + P1_Y: + + + + + + + P2_Y: + + + + + + + + 70 + 0 + + + + 1200 + + + + + + + 1200 + + + + + + + 1200 + + + + + + + + 70 + 0 + + + + 1200 + + + + + + + P2_X: + + + + + + + + + + + 两点实际距离mm: + + + + + + + + + + 两点像素距离px: + + + + + + + + + + 像素比例值(mm/px): + + + + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + 解锁 + + + + + + + + + + + 物理X方向偏移: + + + + + + + + + + + + + + 物理Y方向偏移: + + + + + + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + 应用 + + + + + + + + + + + 工位2相机视场标定 + + + + + + + 9 + 0 + + + + background-color: rgb(212, 212, 212); + + + + + + + + + + 0 + 0 + + + + + 12 + + + + + + + + + 12 + + + + + + + + + + + + + + + 3 + 0 + + + + + 12 + + + + 操作 + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 12 + + + + 选择标定图像 + + + + + + + + + + + + + + + + + P1_X: + + + + + + + P1_Y: + + + + + + + P2_Y: + + + + + + + + 70 + 0 + + + + 1200 + + + + + + + 1200 + + + + + + + 1200 + + + + + + + + 70 + 0 + + + + 1200 + + + + + + + P2_X: + + + + + + + + + + + 两点实际距离mm: + + + + + + + + + + 两点像素距离px: + + + + + + + + + + 像素比例值(mm/px): + + + + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + 解锁 + + + + + + + + + + + 物理X方向偏移: + + + + + + + + + + + + + + 物理Y方向偏移: + + + + + + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + 应用 + + + + + + + + + + + + + + + + diff --git a/src/lpMain/lpMain.qrc b/src/lpMain/lpMain.qrc index f619ec9..a317cf5 100644 --- a/src/lpMain/lpMain.qrc +++ b/src/lpMain/lpMain.qrc @@ -14,6 +14,9 @@ Resource/toolBar/setting.png Resource/toolBar/test.png Resource/toolBar/messenger.png + Resource/toolBar/attachment6.png + Resource/toolBar/meter3.png + Resource/toolBar/pen38.png Resource/app.png diff --git a/src/lpMain/lpRawTcp/lpRawTcpClientSession.cpp b/src/lpMain/lpRawTcp/lpRawTcpClientSession.cpp new file mode 100644 index 0000000..37d7c96 --- /dev/null +++ b/src/lpMain/lpRawTcp/lpRawTcpClientSession.cpp @@ -0,0 +1,80 @@ +#include "lpRawTcpClientSession.h" +#include + +#include +#pragma execution_character_set("utf-8") +lpRawClientSession::lpRawClientSession(int ID, QObject *parent) + : QObject(parent), + socket_descriptor_(ID) +{ + psocket_ = new QTcpSocket(this); + psocket_->setSocketDescriptor(socket_descriptor_); + + connect(psocket_, SIGNAL(readyRead()), this, SLOT(on_ready_read())); + connect(psocket_, SIGNAL(disconnected()), this, SLOT(on_disconnect())); + +} + +lpRawClientSession::~lpRawClientSession() +{ + if (psocket_) { + //psocket_->abort(); + psocket_->close(); + delete psocket_; + psocket_ = nullptr; + } +} + +void lpRawClientSession::on_ready_read() +{ + QByteArray data_recv; + data_recv = psocket_->readAll(); + QSharedPointer data_ptr = QSharedPointer + (new QByteArray(data_recv.constData(), data_recv.size())); + + if (_func) + { + _func(data_recv); + } + emit data_received(socket_descriptor_, data_ptr); +} + +void lpRawClientSession::force_close() +{ + psocket_->disconnect(); + //psocket_->disconnectFromHost(); +} + +void lpRawClientSession::on_disconnect() +{ + emit sess_disconnected(socket_descriptor_); + + socket_close(); +} + +void lpRawClientSession::on_data_to_send(int sess_id, QSharedPointer data) +{ + if (sess_id != socket_descriptor_) return; + psocket_->write(data->constData(), data->size()); +} + +QString lpRawClientSession::getClientIP() +{ + return psocket_->peerAddress().toString(); +} + +int lpRawClientSession::getClientPort() +{ + return psocket_->peerPort(); +} + +void lpRawClientSession::socket_close() +{ + + if (psocket_->isOpen()) + { + psocket_->abort(); + psocket_->close(); + } +} + diff --git a/src/lpMain/lpRawTcp/lpRawTcpClientSession.h b/src/lpMain/lpRawTcp/lpRawTcpClientSession.h new file mode 100644 index 0000000..01c3bc4 --- /dev/null +++ b/src/lpMain/lpRawTcp/lpRawTcpClientSession.h @@ -0,0 +1,44 @@ +#ifndef __TP_RAW_CLIENTSESSION_H__ +#define __TP_RAW_CLIENTSESSION_H__ + +#include +#include +#include +#include + +typedef std::function RecvDataFunc; + +class lpRawClientSession : public QObject +{ + Q_OBJECT +public: + lpRawClientSession(int ID, QObject *parent = 0); + ~lpRawClientSession(); + + void setRecvCallBackFunc(RecvDataFunc func) { _func = func; }; + void force_close(); + Q_SLOT void on_data_to_send(int sess_id, QSharedPointer); + QString getClientIP(); + int getClientPort(); + + void setClientID(QString strID) { + m_strID = strID; + }; + QString getClientID()const { + return m_strID; + }; +signals: + void data_received(int, QSharedPointer); + void sess_disconnected(int); +private: + void socket_close(); + + Q_SLOT void on_ready_read(); + Q_SLOT void on_disconnect(); +private: + QTcpSocket *psocket_{ nullptr }; + int socket_descriptor_; + RecvDataFunc _func; + QString m_strID; +}; +#endif //__TP_RAW_CLIENTSESSION_H__ diff --git a/src/lpMain/lpRawTcp/lptkRawTcpServer.cpp b/src/lpMain/lpRawTcp/lptkRawTcpServer.cpp new file mode 100644 index 0000000..6d4f6a3 --- /dev/null +++ b/src/lpMain/lpRawTcp/lptkRawTcpServer.cpp @@ -0,0 +1,158 @@ +#include +#include "lpRawTcpClientSession.h" +#include "lptkRawTcpServer.h" +#pragma execution_character_set("utf-8") +lptkRawTcpServer::lptkRawTcpServer(QObject *parent /*= NULL*/) + : QTcpServer(parent) +{ + qRegisterMetaType>(); + client_sessions_.clear(); +} + +lptkRawTcpServer::~lptkRawTcpServer() +{ + server_end(); +} + +bool lptkRawTcpServer::server_begin(const QString &strIP, quint16 nPort) +{ + QHostAddress listen_addr_ = QHostAddress::Any; + QString ip_addr = strIP; + quint16 listen_port_ = nPort; + ip_addr.trimmed(); + if (ip_addr != "*") + { + listen_addr_.setAddress(ip_addr); + } + if (!this->listen(listen_addr_, nPort)) + { + qWarning() << "Could not start server. Error: " << this->errorString() + << __FUNCTION__; + return false; + } + else + { + qDebug() << "Server started. Listening to port " << nPort << __FUNCTION__; + + return true; + } +} + +void lptkRawTcpServer::server_end() +{ + close(); + //close all connected session + auto it = client_sessions_.begin(); + while (it != client_sessions_.end()) + { + TP_RAW_CLIENT_SESS cli_sess = it.value(); + disconnect(cli_sess.pSess_); + cli_sess.pSess_->force_close(); + + cli_sess.pThrd_->quit(); + cli_sess.pThrd_->wait(); + if (cli_sess.pThrd_->isRunning()) { + cli_sess.pThrd_->exit(0); + } + delete cli_sess.pThrd_;// ->deleteLater(); + delete cli_sess.pSess_; + client_sessions_.erase(it++); + } + + client_sessions_.clear(); + + //stop listening + +} + +void lptkRawTcpServer::incomingConnection(qintptr socketDescriptor) +{ + lpRawClientSession *pclientSess = nullptr; + + pclientSess = new lpRawClientSession(socketDescriptor); + + QThread *pThrd = new QThread(); + pclientSess->moveToThread(pThrd); + + TP_RAW_CLIENT_SESS cli_sess; + cli_sess.pThrd_ = pThrd; + cli_sess.pSess_ = pclientSess; + if (_func) + { + pclientSess->setRecvCallBackFunc(_func); + } + + //connect(pThrd, &QThread::finished, pclientSess, &QObject::deleteLater); + connect(pclientSess, &lpRawClientSession::data_received, this, &lptkRawTcpServer::on_data_received); + connect(pclientSess, &lpRawClientSession::sess_disconnected, this, &lptkRawTcpServer::on_sess_disconnected); + + connect(this, &lptkRawTcpServer::data_to_send, pclientSess, &lpRawClientSession::on_data_to_send); + client_sessions_[socketDescriptor] = cli_sess; + + pThrd->start(); + QString strIP = pclientSess->getClientIP(); + int n = strIP.lastIndexOf(":"); + strIP = strIP.mid(n).remove(":"); + int port = pclientSess->getClientPort(); + QString strID = QString("%1:%2").arg(strIP).arg(port); + pclientSess->setClientID(strID); + emit client_status_changed(socketDescriptor, TCPSERVER_ON_CLIENT_CONNECTED); + emit client_connect_status(strID, TCPSERVER_ON_CLIENT_CONNECTED); +} + +void lptkRawTcpServer::on_data_received(int sess_id, QSharedPointer data_ptr) +{ + auto it = client_sessions_.find(sess_id); + if (it == client_sessions_.end()) + { + qDebug() << "Invalid session ID : " << sess_id << __FUNCTION__; + return; + } + + emit data_received(sess_id, data_ptr); +} + +void lptkRawTcpServer::on_sess_disconnected(int sess_id) +{ + auto it = client_sessions_.find(sess_id); + if (it != client_sessions_.end()) + { + TP_RAW_CLIENT_SESS cli_sess = it.value(); + cli_sess.pSess_->force_close(); + cli_sess.pThrd_->quit(); + cli_sess.pThrd_->wait(); + if (cli_sess.pThrd_->isRunning()) { + cli_sess.pThrd_->exit(0); + } + + QString strID = cli_sess.pSess_->getClientID(); + emit client_connect_status(strID, TCPSERVER_ON_CLIENT_DISCONNECTED); + + delete cli_sess.pThrd_; + delete cli_sess.pSess_; + client_sessions_.erase(it); + } + + emit client_status_changed(sess_id, TCPSERVER_ON_CLIENT_DISCONNECTED); +} + +void lptkRawTcpServer::send_data(int sess_id, QSharedPointer data_ptr) +{ + auto it = client_sessions_.find(sess_id); + if (it != client_sessions_.end()) + { + TP_RAW_CLIENT_SESS cli_sess = it.value(); + emit data_to_send(it.key(), data_ptr); + } +} + +void lptkRawTcpServer::broadcast_send_data(QSharedPointer data_ptr) +{ + auto it = client_sessions_.begin(); + while (it != client_sessions_.end()) + { + TP_RAW_CLIENT_SESS cli_sess = it.value(); + emit data_to_send(it.key(), data_ptr); + it++; + } +} diff --git a/src/lpMain/lpRawTcp/lptkRawTcpServer.h b/src/lpMain/lpRawTcp/lptkRawTcpServer.h new file mode 100644 index 0000000..ab57b77 --- /dev/null +++ b/src/lpMain/lpRawTcp/lptkRawTcpServer.h @@ -0,0 +1,67 @@ +#ifndef TP_RAW_TCPSERVER_H +#define TP_RAW_TCPSERVER_H + +#include +#include +#include +#include +#include "lpRawTcpClientSession.h" + + +typedef struct tagTP_RAW_CLIENT_SESS { + QThread *pThrd_; + lpRawClientSession *pSess_; +}TP_RAW_CLIENT_SESS; +typedef QMap RawClientsSessionMap; +typedef enum emServerStatus +{ + TCPSERVER_ON_RUNNING = 0, + TCPSERVER_ON_SHUTDOWN, + TCPSERVER_ON_CLIENT_CONNECTED, + TCPSERVER_ON_CLIENT_DISCONNECTED, +}ServerStatus; + +class lptkRawTcpServer : public QTcpServer +{ + + Q_OBJECT + +public: + lptkRawTcpServer(QObject *parent = NULL); + ~lptkRawTcpServer(); + + bool server_begin(const QString &strIP, quint16 nPort); + void server_end(); + + void broadcast_send_data(QSharedPointer data_ptr); + void send_data(int sess_id, QSharedPointer data_ptr); + + void setRecvCallFunc(RecvDataFunc func) { + _func = func; + }; +signals: + void client_status_changed(int, ServerStatus); + void data_received(int, QSharedPointer); + void data_to_send(int, QSharedPointer); + void client_connect_status(QString strID, ServerStatus); +public slots: + void on_sess_disconnected(int); + + void on_data_received(int, QSharedPointer); +protected: + void incomingConnection(qintptr socketDescriptor); + +private: + RawClientsSessionMap client_sessions_; + + RecvDataFunc _func; +}; +#ifndef LPQSHAREDPOINTERQBYTEARRAY +#define LPQSHAREDPOINTERQBYTEARRAY +Q_DECLARE_METATYPE(QSharedPointer) +#endif +#ifndef LPTKSERVERSTATUS +#define LPTKSERVERSTATUS +Q_DECLARE_METATYPE(ServerStatus) +#endif +#endif // TP_RAW_TCPSERVER_H diff --git a/tpvs17/lpMain/CMainWin.cpp b/tpvs17/lpMain/CMainWin.cpp index e0a9561..a9d1fa6 100644 --- a/tpvs17/lpMain/CMainWin.cpp +++ b/tpvs17/lpMain/CMainWin.cpp @@ -1,16 +1,21 @@ #include "CMainWin.h" #include -#include "lpSysLog.h" + #include #include #include -#include "quserinfo_global.h" -#include "Serialport_global.h" #include -#include "lpSysConfig.h" #include +#include + +#include "quserinfo_global.h" +#include "Serialport_global.h" #include "WfCtrl.h" #include "lpGlobalConfig.h" +#include "lpGlobalData.h" +#include "lpSysConfig.h" +#include "lpSysLog.h" +#include "lpCryptokey.h" #define LEAPER_LOGO ":/leaper/Resource/app.png" #define WINDOWS_ICON ":/leaper/Resource/app.png" @@ -75,7 +80,7 @@ CMainWin::CMainWin(QWidget *parent) : QMainWindow(parent) { ui.setupUi(this); - + setWindowIcon(QIcon(LEAPER_LOGO)); onInitCoreCtrl(); onInitSerial(); @@ -123,6 +128,16 @@ CMainWin::CMainWin(QWidget *parent) m_pWfCtrl->ISelModel(lpGlobalConfig::instance()->m_StationSolution_1, lpGlobalConfig::instance()->m_StationRunModel_1); m_pWfCtrl->ISelModel(lpGlobalConfig::instance()->m_StationSolution_2, lpGlobalConfig::instance()->m_StationRunModel_2); + + m_pImageCaliUI = new lpImageCaliUI();//图像标定页面 + + lpGlobalData::instance()->m_bCheckLinese = lpCheckKey::instance()->checkLinese(); + m_pCheckLineseUI = new QCryptokeyUI(); + connect(m_pCheckLineseUI, SIGNAL(sgRegisterFinish(bool)), this, SLOT(onLineseCheck(bool))); + + onLineseCheck(lpGlobalData::instance()->m_bCheckLinese); + + m_TimerID_Status = startTimer(1000); } CMainWin::~CMainWin() @@ -170,6 +185,42 @@ CMainWin::~CMainWin() delete m_pWfCtrl; m_pWfCtrl = nullptr; } + if (m_pLabelInfo) + { + delete m_pLabelInfo; + m_pLabelInfo = nullptr; + } + if (m_pLbCurrentTime) + { + delete m_pLbCurrentTime; + m_pLbCurrentTime = nullptr; + } + + if (m_pLbOnLine) + { + delete m_pLbOnLine; + m_pLbOnLine = nullptr; + } + if (m_pLbUser) + { + delete m_pLbUser; + m_pLbUser = nullptr; + } + if (m_pLbConnect) + { + delete m_pLbConnect; + m_pLbConnect = nullptr; + } + if (m_pImageCaliUI) + { + delete m_pImageCaliUI; + m_pImageCaliUI = nullptr; + } + if (m_pCheckLineseUI) + { + delete m_pCheckLineseUI; + m_pCheckLineseUI = nullptr; + } lpSysConfig::uninstance(); rmTranslator(); lpSysLog::uninstance(); @@ -211,64 +262,6 @@ void CMainWin::INewCameraImage(const QString& camKey, QImage img) //算法结果接收 void CMainWin::IVariantMapToUI(const QString& camKey, const QVariantMap& vMap) { - -/* QVariantMap mMap = vMap.value("algoRlt").toMap(); - IStation *pStation = m_pWfCtrl->IGetStationByKey(camKey); - if (pStation) - { - QImage image = vMap.value("image").value(); - int nSize = image.height(); - if (!vMap.contains("angle")) { - qWarning() << "no angle result"; - } - QImage srcImg = vMap.value("originImage").value(); - double dAngle = vMap.contains("angle") ? vMap.value("angle").toDouble() : 365; - int errorType = vMap.contains("error") ? vMap.value("error").toInt() : 16; - double matchScore = vMap.value("score").toDouble() * 100; - - QString str = vMap.value("resultTip").toString(); - QStringList strList = str.split("/"); - QString strRusltTip = strList.first(); - QString threshBenchMark = strList.last(); - //QString strImgPath = vMap.value("imageName").toString(); - - QString strResult = QTime::currentTime().toString("hh:mm:ss zzz:") + strList.first(); - strResult += "angle result : " + QString::number(dAngle, 'f', 3); - pStation->setSerialPortPtr(m_pSerialPort); - if (dAngle >= 361) - dAngle = 361.0; - pStation->sendResult(dAngle); - if (image.isNull()) - int b = 0; - SYSLOG_STATUS << QString("◎工位%1收到算法结果,当前型号为[%2],发送角度为:%3").arg(pStation->stationId()).arg(pStation->currentRunningModel()).arg(dAngle); - emit sgShowImg(pStation->stationId(),image); - emit sgShowLog(pStation->stationId(), strResult); - pStation->revResult(); - - QString str2 = pStation->currentRunningModel(); - int ID = pStation->stationId(); - QString strModelName = QString("%1_%2").arg(ID).arg(str2); - QString strImgPath; - - if((lpSysConfig::instance()->m_bSaveRltImg_st1 == true && pStation->stationId() == 1) - ||(lpSysConfig::instance()->m_bSaveRltImg_st2 == true && pStation->stationId() == 2)) - strImgPath = genSavePath(strModelName, image); - - if((lpSysConfig::instance()->m_bSaveSrcImg_st1 == true&&pStation->stationId()==1) - || (lpSysConfig::instance()->m_bSaveSrcImg_st2 == true && pStation->stationId() == 2)) - genSaveSrcImgPath(strModelName, srcImg); - Struct2SaveData nStructData; - nStructData.dAngle = dAngle; - nStructData.errorType = errorType; - nStructData.matchScore = matchScore; - nStructData.threshBenchMark = threshBenchMark; - nStructData.resultTip = strRusltTip; - nStructData.stationName = pStation->stationShowName(); - nStructData.value1 = strImgPath; - nStructData.value2 = str2; - m_db->addData2DB(nStructData); - } - */ } QVariant CMainWin::IGetVariantById(int id) @@ -319,6 +312,8 @@ Q_SLOT void CMainWin::onAppanalysis(SComFrame frame) if (0x43 == nCmd)//心跳 型号切换 { onHeartComm(frame); + m_heartTimeOut = 0; + m_bPLCConnect = true; return; } else if (0x50 == nCmd) {//触发相机 @@ -414,11 +409,6 @@ void CMainWin::onHeartComm(SComFrame &frame) static int nS1 = -1; static int nS2 = -1; - if (m_pWfCtrl) - m_pWfCtrl->registerConnect(); - else - return; - if (lpGlobalConfig::instance()->m_bOnlineMode == true) { int nSta1 = frame.data1; @@ -585,7 +575,7 @@ Q_SLOT void CMainWin::onActionClicked() #endif process.startDetached(strTaskName); } - else if ("action" == strObj) {//系统参数设置 + else if ("actionSystem" == strObj) {//系统参数设置 m_devMgrWid.setParent(this); m_devMgrWid.setWindowIcon(QIcon(LEAPER_LOGO)); m_devMgrWid.setWindowFlags(Qt::Dialog | Qt::WindowCloseButtonHint); @@ -634,6 +624,29 @@ Q_SLOT void CMainWin::onActionClicked() infobox.exec(); } } + else if ("actionStandard" == strObj) { + if (m_pImageCaliUI) { + m_pImageCaliUI->setParent(this); + m_pImageCaliUI->setWindowTitle(tr("图像标定")); + m_pImageCaliUI->setWindowFlags(Qt::Dialog | Qt::WindowCloseButtonHint); + m_pImageCaliUI->setWindowIcon(QIcon(WINDOWS_ICON)); + m_pImageCaliUI->setWindowModality(Qt::ApplicationModal); + m_pImageCaliUI->setAttribute(Qt::WA_ShowModal, true); + m_pImageCaliUI->show(); + } + } + else if ("actionRegister" == strObj) { + if (m_pCheckLineseUI) { + m_pCheckLineseUI->setInfo(lpCheckKey::instance()->getSerialNo(), lpGlobalData::instance()->m_bCheckLinese); + m_pCheckLineseUI->setParent(this); + m_pCheckLineseUI->setWindowTitle(tr("注册")); + m_pCheckLineseUI->setWindowFlags(Qt::Dialog | Qt::WindowCloseButtonHint); + m_pCheckLineseUI->setWindowIcon(QIcon(WINDOWS_ICON)); + m_pCheckLineseUI->setWindowModality(Qt::ApplicationModal); + m_pCheckLineseUI->setAttribute(Qt::WA_ShowModal, true); + m_pCheckLineseUI->show(); + } + } } void CMainWin::timerEvent(QTimerEvent *event) @@ -672,60 +685,65 @@ void CMainWin::changeEvent(QEvent *event) //初始化状态栏 void CMainWin::onInitStatus() { - const int c_nWidth = 170; m_pLbCurrentTime = new QLabel(QObject::tr("系统时间")); m_pLbCurrentTime->setMinimumHeight(40); - m_pLbCurrentTime->setMinimumWidth(c_nWidth); - - m_pLbOnLine = new class QLabel(QObject::tr("模式:")); - m_pLbOnLine->setMinimumWidth(c_nWidth); - - m_pLbUser = new class QLabel(QObject::tr("用户:无")); - m_pLbUser->setMinimumWidth(c_nWidth); - - m_pLbConnect = new class QLabel(QObject::tr("连接状态:")); - m_pLbConnect->setMinimumWidth(c_nWidth); - - //m_pLbDiskSpace = new class QLabel(QObject::tr("硬盘剩余空间:xxx.xG")); - //m_pLbDiskSpace->setMinimumWidth(c_nWidth); - - ui.statusBar->addWidget(m_pLbOnLine); - ui.statusBar->addWidget(m_pLbConnect); - ui.statusBar->addWidget(m_pLbUser); - ui.statusBar->addWidget(m_pLbCurrentTime); - //ui.statusBar->addWidget(m_pLbDiskSpace); + m_pLbOnLine = new QLabel(QObject::tr("模式:")); + m_pLbUser = new QLabel(QObject::tr("用户:无")); + m_pLbConnect = new QLabel(QObject::tr("连接状态:")); + + m_pLbOnLine->setAlignment(Qt::AlignCenter); + m_pLbConnect->setAlignment(Qt::AlignCenter); + m_pLbUser->setAlignment(Qt::AlignCenter); + m_pLbCurrentTime->setAlignment(Qt::AlignCenter); + + ui.statusBar->addWidget(m_pLbConnect,50); + ui.statusBar->addWidget(m_pLbOnLine,50); + ui.statusBar->addWidget(m_pLbUser,50); + ui.statusBar->addPermanentWidget(m_pLbCurrentTime,50); } void CMainWin::onUpdateStatus() { -/* if (m_pLbCurrentTime) { - QString m_currentTimerString = QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss"); - m_pLbCurrentTime->setText(QObject::tr("系统时间: ") + m_currentTimerString + " "); - //m_pLbCurrentTime->setStyleSheet("font: 14px;"); + m_tickCount++; + m_heartTimeOut++; + if (m_heartTimeOut > 5)//统计心跳超时次数 用于判断连接是否超时 + { + m_bPLCConnect = false; + m_heartTimeOut = 0; } - if (m_pLbOnLine && m_pWfCtrl) { + if (m_pLbCurrentTime) { + QString currentTime = QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss"); + QString strlong = SecondTimeString(m_tickCount); + QString strTimeTitle = tr("运行时长:"); + QString strShow = QString("%1 %2 %3").arg(currentTime).arg(strTimeTitle).arg(strlong); + m_pLbCurrentTime->setText(strShow); + m_pLbCurrentTime->setStyleSheet("font: 14px;"); + } + + if (m_pLbOnLine) { QString strOnlineState = QString(QObject::tr("检测模式:")) - + (m_pWfCtrl->IOnlineMode() == true ? QObject::tr("在线模式") : QObject::tr("离线模式")); + + (lpGlobalConfig::instance()->m_bOnlineMode == true ? QObject::tr("在线模式") : QObject::tr("离线模式")); m_pLbOnLine->setText(strOnlineState); - // m_pLbOnLine->setStyleSheet("font: bold 14px;"); + m_pLbOnLine->setStyleSheet("font: 14px;"); } - if (m_pLbConnect && m_pWfCtrl) { + if (m_pLbConnect) { QString strOnlineState = QString(QObject::tr("连接状态:")) - + (m_pWfCtrl->IConnectStatus() == true ? QObject::tr("连接正常") : QObject::tr("连接异常")); + + (m_bPLCConnect == true ? QObject::tr("连接正常") : QObject::tr("连接异常")); m_pLbConnect->setText(strOnlineState); + if (m_bPLCConnect == true) + { + m_pLbConnect->setStyleSheet("font: 14px;background-color: rgb(63, 170, 24);"); + } + else { + m_pLbConnect->setStyleSheet("font: 14px;background-color: rgb(200, 10, 10);"); + } } if (m_pLbUser) { m_pLbUser->setText(QObject::tr("用户: %1").arg(m_strUserName.isEmpty()==true?QObject::tr("未登录"):m_strUserName)); } -// if (m_pLbDiskSpace) -// { -// QString strDiskSpace = QString(QObject::tr("硬盘剩余空间:%1G")).arg(100 / 1024.0); -// m_pLbDiskSpace->setText(strDiskSpace); -// } -*/ } bool CMainWin::onInitCoreCtrl() @@ -869,25 +887,61 @@ void CMainWin::onInitSerial() void CMainWin::onInitUI() { + QFont font; + //工具栏菜单 + QMenu *pToolMenu = new QMenu(this); + pToolMenu->addAction(ui.actionStandard);//系统配置 + pToolMenu->addAction(ui.actionSystem);//测试调试 + pToolMenu->addAction(ui.actionTest); + + QToolButton* pbutton = new QToolButton(this); + pbutton->setMenu(pToolMenu); + pbutton->setIcon(QIcon(":/toolbar/Resource/toolBar/setting.png")); + pbutton->setText(tr("工具")); + pbutton->setToolTip(tr("工具")); + pbutton->setToolButtonStyle(Qt::ToolButtonTextUnderIcon); + pbutton->setPopupMode(QToolButton::InstantPopup); + font.setBold(false); + font.setPixelSize(16); + pbutton->setFont(font); + ui.mainToolBar->addWidget(pbutton); + + QMenu *pHelpMenu = new QMenu(this); + pHelpMenu->addAction(ui.actionHelp); + pHelpMenu->addAction(ui.actionRegister); + QToolButton* pHelptool = new QToolButton(this); + pHelptool->setMenu(pHelpMenu); + pHelptool->setIcon(QIcon(":/toolbar/Resource/toolBar/help.png")); + pHelptool->setText(tr("帮助")); + pHelptool->setToolTip(tr("帮助")); + pHelptool->setFont(font); + pHelptool->setToolButtonStyle(Qt::ToolButtonTextUnderIcon); + pHelptool->setPopupMode(QToolButton::InstantPopup); + ui.mainToolBar->addWidget(pHelptool); + ui.mainToolBar->addSeparator(); + m_pLabelInfo = new QLabel(this); + m_pLabelInfo->setText(tr("本系统未注册激活")); + m_pLabelInfo->setStyleSheet("font: bold 14px; color: red;"); + ui.mainToolBar->addWidget(m_pLabelInfo); + //工具栏按钮事件绑定 connect(ui.actionSetting, SIGNAL(triggered()), this, SLOT(onActionClicked())); connect(ui.actionManage, SIGNAL(triggered()), this, SLOT(onActionClicked())); connect(ui.actionTest, SIGNAL(triggered()), this, SLOT(onActionClicked())); connect(ui.actionHelp, SIGNAL(triggered()), this, SLOT(onActionClicked())); connect(ui.action_Check, SIGNAL(triggered()), this, SLOT(onActionClicked())); - connect(ui.action, SIGNAL(triggered()), this, SLOT(onActionClicked())); + connect(ui.actionSystem, SIGNAL(triggered()), this, SLOT(onActionClicked())); connect(ui.main_Login_action, SIGNAL(triggered()), this, SLOT(onActionClicked())); connect(ui.main_action_userManager, SIGNAL(triggered()), this, SLOT(onActionClicked())); + connect(ui.actionStandard, SIGNAL(triggered()), this, SLOT(onActionClicked())); + connect(ui.actionRegister, SIGNAL(triggered()), this, SLOT(onActionClicked())); //图像结果展示 connect(this, SIGNAL(sgShowImg(int, QImage)), this, SLOT(onShowImage(int, QImage))); connect(this, SIGNAL(sgSelModel(int, QString)), this, SLOT(onSelModel(int, QString))); connect(this, SIGNAL(sgShowLog(int, QString)), this, SLOT(onShowLog(int, QString))); - m_TimerID_Status = startTimer(1000); ui.main_action_userManager->setVisible(false); - //ui.action->setVisible(false); - QTextDocument *pDoc = ui.wf_text_edit_result_1->document(); pDoc->setMaximumBlockCount(200); pDoc = ui.wf_text_edit_result_2->document(); @@ -898,8 +952,8 @@ void CMainWin::onInitUI() ui.wf_lb_image_show_2->setContextMenuPolicy(Qt::CustomContextMenu); connect(ui.wf_lb_image_show_2, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(onPopMenu(const QPoint&))); - connect(this, SIGNAL(sgShowSrcImg(QString, QImage)), &m_camSetWid, SLOT(onShowImage(QString, QImage))); + } //======系统翻译相关 @@ -1007,7 +1061,7 @@ Q_SLOT void CMainWin::onMainFrameClose() { } - +//相机触发 Q_SLOT void CMainWin::onSnapImage(int nCamera /*= -1*/) { if (nCamera == 1) @@ -1041,12 +1095,12 @@ Q_SLOT void CMainWin::onChangeUI(QString strUsr, int nLevel) case 7: case 6: ui.main_action_userManager->setVisible(true); - ui.action->setEnabled(true); + ui.actionSystem->setEnabled(true); ui.actionTest->setEnabled(true); break; case 5: ui.main_action_userManager->setVisible(true); - ui.action->setEnabled(true); + ui.actionSystem->setEnabled(true); ui.actionTest->setEnabled(true); break; case 4: @@ -1055,7 +1109,7 @@ Q_SLOT void CMainWin::onChangeUI(QString strUsr, int nLevel) case 1: case 0: ui.main_action_userManager->setVisible(false); - ui.action->setEnabled(false); + ui.actionSystem->setEnabled(false); ui.actionTest->setEnabled(false); break; default: @@ -1141,9 +1195,13 @@ Q_SLOT void CMainWin::onShowName(QString ID, QString strName) Q_SLOT void CMainWin::onShowLog(int nID, QString strMsg) { if (nID == 1) { + if (ui.wf_text_edit_result_1->toPlainText().size() > 50000) + ui.wf_text_edit_result_1->clear(); ui.wf_text_edit_result_1->append(strMsg); } else if (nID == 2) { + if (ui.wf_text_edit_result_2->toPlainText().size() > 50000) + ui.wf_text_edit_result_2->clear(); ui.wf_text_edit_result_2->append(strMsg); } } @@ -1173,7 +1231,7 @@ Q_SLOT void CMainWin::onPopMenu(const QPoint& pt) } QMenu menu; - QAction *pSetAction = menu.addAction(tr("相机属性配置")); + QAction *pSetAction = menu.addAction(tr("相机配置")); pSetAction->setObjectName("setAction"); QAction *pSelect = menu.exec(QCursor::pos()); @@ -1228,48 +1286,29 @@ Q_SLOT void CMainWin::onSlotDelOldModel(QString strName) void CMainWin::IEngineResult(QVariantMap vMap) { QImage srcImg = vMap.value("originImage").value(); - bool taskCali = vMap.value("taskCali").toBool(); + bool taskCali = vMap.value("taskCali").toBool();//标定标志位 使用有标定图来判断 QString solutionName = vMap.value("solutionName").toString(); + QString taskName = vMap.value("taskName").toString(); if (taskCali == false)//模板未标定 { -// ui.main_value_Result->setText("该型号未标定"); -// ui.main_value_Result->setStyleSheet("background-color: rgb(255, 212, 83);"); -// ui.main_label_angle->setText("-"); -// ui.main_value_Center_point->setText("-"); -// ui.main_value_DetectTime->setText("-"); -// ui.main_value_Score->setText("-"); - //获取图像 保存到当天NG图 - -// ValueResult valueRlt; -// valueRlt.angle = 361; -// valueRlt.strModel = "NG"; -// valueRlt.score = 0; -// valueRlt.strRunState = "no Cali"; -// valueRlt.pixmap = QPixmap::fromImage(srcImg); -// valueRlt.resultType = 2;//识别出型号 但未标定 -// onSaveValveResult(valueRlt); + int stationID = 0; + if (solutionName == lpGlobalConfig::instance()->m_StationSolution_1) + { + stationID = 1; + } + else if (solutionName == lpGlobalConfig::instance()->m_StationSolution_2) + { + stationID = 2; + } + QString strResult = QTime::currentTime().toString("hh:mm:ss zzz:") + taskName; + strResult += " No Cali!!!"; + emit sgShowLog(stationID, strResult); + sendResult(stationID, 361, 0, 0); return; } //不包含算法检测结果,表示没有相关task if (!vMap.contains("AlgoResult")) { -// ui.main_value_Result->setText("没有找到相关task"); -// ui.main_value_Result->setStyleSheet("background-color: rgb(255, 212, 83);"); -// ui.main_label_angle->setText("-"); -// ui.main_value_Center_point->setText("-"); -// ui.main_value_DetectTime->setText("-"); -// ui.main_value_Score->setText("-"); - //获取图像 保存到当天NG图 - -// ValueResult valueRlt; -// valueRlt.angle = 361; -// valueRlt.strModel = "NG"; -// valueRlt.score = 0; -// valueRlt.strRunState = "no task"; -// valueRlt.pixmap = QPixmap::fromImage(srcImg); -// valueRlt.resultType = 3;//识别出型号 但未标定 -// onSaveValveResult(valueRlt); - int stationID = 0; if (solutionName == lpGlobalConfig::instance()->m_StationSolution_1) { @@ -1280,6 +1319,11 @@ void CMainWin::IEngineResult(QVariantMap vMap) stationID = 2; } onShowImage(stationID, srcImg); + + QString strResult = QTime::currentTime().toString("hh:mm:ss zzz:") + taskName; + strResult += " No Task!!!"; + emit sgShowLog(stationID, strResult); + sendResult(stationID, 361, 0, 0); } else { QVariantMap algResult = vMap.value("AlgoResult").toMap(); @@ -1287,66 +1331,33 @@ void CMainWin::IEngineResult(QVariantMap vMap) double dAngle = algResult.contains("angle") ? algResult.value("angle").toDouble() : 365; int errorType = algResult.contains("error") ? algResult.value("error").toInt() : 16; double matchScore = algResult.value("score").toDouble() * 100; - QImage maskImg = algResult.value("image").value(); + QImage rltImg = algResult.value("image").value(); QString str = algResult.value("resultTip").toString(); QPointF centerPoint = algResult.value("centerPoint").toPointF(); QString taskName = vMap.value("taskName").toString(); double taskTime = vMap.value("tasktime").toDouble(); + double centerX = 0.0; + double centerY = 0.0; if (solutionName == lpGlobalConfig::instance()->m_StationSolution_1) { - double centerX = centerPoint.x() * lpGlobalConfig::instance()->m_StationScale_1 + lpGlobalConfig::instance()->m_StationXOffset_1; - double centerY = centerPoint.y() * lpGlobalConfig::instance()->m_StationScale_1 + lpGlobalConfig::instance()->m_StationYOffset_1; - sendResult(1,dAngle, centerX, centerY); + centerX = centerPoint.x() * lpGlobalConfig::instance()->m_StationScale_1 + lpGlobalConfig::instance()->m_StationXOffset_1; + centerY = centerPoint.y() * lpGlobalConfig::instance()->m_StationScale_1 + lpGlobalConfig::instance()->m_StationYOffset_1; + sendResult(1, dAngle, centerX, centerY); } else if (solutionName == lpGlobalConfig::instance()->m_StationSolution_2) { - double centerX = centerPoint.x() * lpGlobalConfig::instance()->m_StationScale_2 + lpGlobalConfig::instance()->m_StationXOffset_2; - double centerY = centerPoint.y() * lpGlobalConfig::instance()->m_StationScale_2 + lpGlobalConfig::instance()->m_StationYOffset_2; + centerX = centerPoint.x() * lpGlobalConfig::instance()->m_StationScale_2 + lpGlobalConfig::instance()->m_StationXOffset_2; + centerY = centerPoint.y() * lpGlobalConfig::instance()->m_StationScale_2 + lpGlobalConfig::instance()->m_StationYOffset_2; sendResult(2, dAngle, centerX, centerY); } -// ui.main_label_angle->setText(QString("%1").arg(dAngle)); -// -// ValueResult valueRlt; -// valueRlt.angle = dAngle; -// valueRlt.strModel = taskName; -// valueRlt.centerPix = centerPoint; -// -// valueRlt.score = matchScore; -// valueRlt.errorCode = errorType; -// valueRlt.runtime = taskTime; -// valueRlt.pixmap = QPixmap::fromImage(maskImg); -// valueRlt.strRunState = "run Alg success"; -// /*中心坐标偏移值计算*/ -// int centerX = centerPoint.x() * lpGlobalConfig::instance()->fScale + lpGlobalConfig::instance()->pointXOffset; -// int centerY = centerPoint.y() * lpGlobalConfig::instance()->fScale + lpGlobalConfig::instance()->pointYOffset; -// valueRlt.center.setX(centerX); -// valueRlt.center.setY(centerY); - -// if (dAngle >= 361)//NG -// { -// ui.main_value_Result->setStyleSheet("background-color: rgb(250, 0, 0);"); -// ui.main_value_Result->setText("找不到气门芯"); -// ui.main_value_Center_point->setText("-"); -// ui.main_value_Score->setText(QString("%1").arg(matchScore)); -// valueRlt.strModel = "NG"; -// valueRlt.resultType = 1;//识别出型号 但未标定 -// } -// else {//OK -// ui.main_value_Result->setStyleSheet("background-color: rgb(0, 250, 0);"); -// ui.main_value_Result->setText("定位成功"); -// ui.main_value_Center_point->setText(QString("(%1,%2)").arg(centerPoint.x()).arg(centerPoint.y())); -// ui.main_value_Score->setText(QString("%1").arg(matchScore)); -// valueRlt.resultType = 0;//识别出型号 但未标定 -// } + + /******保存数据********/ + // onSaveValveResult(valueRlt); -// /*展示结果*/ -// ui.main_value_DetectTime->setText(QString("%1s").arg(taskTime)); -// if (m_ImgViewer) -// { -// if (!maskImg.isNull()) -// m_ImgViewer->setImg(maskImg); -// } + + + /*展示结果*/ int stationID = 0; if (solutionName == lpGlobalConfig::instance()->m_StationSolution_1) { @@ -1356,7 +1367,21 @@ void CMainWin::IEngineResult(QVariantMap vMap) { stationID = 2; } - onShowImage(stationID, maskImg); + onShowImage(stationID, rltImg); + + /********打印检测结果到ui上*********/ + QString strResult = QTime::currentTime().toString("hh:mm:ss zzz:") + taskName; + strResult += " angle result : " + QString::number(dAngle, 'f', 3); + + if (dAngle >= 361) + { + dAngle = 361.0; + strResult += " no found Value"; + } + else { + strResult += tr(" center:(%1,%2)").arg(centerX).arg(centerY); + } + emit sgShowLog(stationID, strResult); } } @@ -1371,10 +1396,22 @@ bool CMainWin::sendResult(int nID, double angleValue, double centerX, double cen } unsigned short data[c_nDataNum] = { 0 }; - data[2] = int(angleValue); + + data[2] = int(angleValue);//角度整数部分 double tmp = angleValue - int(angleValue); tmp *= 1000.0; - data[3] = int(tmp); + data[3] = int(tmp);//角度小数部分 + + data[4] = int(centerX); + double tmpX = centerX - int(centerX); + tmpX *= 1000.0; + data[5] = int(tmpX); + + data[6] = int(centerY); + double tmpY = centerY - int(centerY); + tmpY *= 1000.0; + data[7] = int(tmpY); + SComFrame sendFram; int nCmd = (nID == 1 ? 0x46 : 0x47);//stion1 0x46 /station2 0x47 sendFram.cmd = nCmd; @@ -1411,5 +1448,50 @@ bool CMainWin::sendResult(int nID, double angleValue, double centerX, double cen return true; } +QString CMainWin::SecondTimeString(quint64 value) +{ + QString strTime; + int seconds = value % 60; + int minutes = value / 60; + QString strDay = tr("天"); + QString strHour = tr("时"); + QString strMinute = tr("分"); + QString strSecond = tr("秒"); + strTime = QString("%1%2%3%4").arg(minutes).arg(strMinute).arg(seconds).arg(strSecond); + if (minutes >= 60) { + minutes = (value / 60) % 60; + int hours = (value / 60) / 60; + strTime = QString("%1%2%3%4%5%6").arg(hours).arg(strHour).arg(minutes).arg(strMinute).arg(seconds).arg(strSecond); + if (hours >= 24) { + hours = ((value / 60) / 60) % 24; + int day = ((value / 60) / 60) / 24; + strTime = QString("%1%2%3%4%5%6%7%8").arg(day).arg(strDay).arg(hours).arg(strHour).arg(minutes).arg(strMinute).arg(seconds).arg(strSecond); + } + } + return strTime; +} - +//根据注册状态启用相关功能 +Q_SLOT void CMainWin::onLineseCheck(bool bFlag) +{ + ui.actionSetting->setDisabled(!bFlag); + ui.actionManage->setDisabled(!bFlag); + ui.actionTest->setDisabled(!bFlag); + ui.action_Check->setDisabled(!bFlag); + ui.actionSystem->setDisabled(!bFlag); + ui.main_Login_action->setDisabled(!bFlag); + ui.actionStandard->setDisabled(!bFlag); + if (m_pLabelInfo) + { + if (bFlag) + { + m_pLabelInfo->setText(tr("")); + m_pLabelInfo->setStyleSheet(""); + } + else + { + m_pLabelInfo->setText(tr("本系统未注册激活")); + m_pLabelInfo->setStyleSheet("font: bold 14px; color: red;"); + } + } +} diff --git a/tpvs17/lpMain/CMainWin.h b/tpvs17/lpMain/CMainWin.h index 41219b6..1edc1f8 100644 --- a/tpvs17/lpMain/CMainWin.h +++ b/tpvs17/lpMain/CMainWin.h @@ -20,6 +20,8 @@ #include "QCameraMgrUI.h" #include "lpdesigner.h" #include "CDllDesigner.h" +#include "QCryptokeyUI.h" +#include "lpImageCaliUI.h" struct StationInfo { @@ -44,6 +46,7 @@ public: //Engine㷨ص void IEngineResult(QVariantMap vMap); bool sendResult(int nID, double angleValue, double centerX, double centerY); + public: Q_SLOT void onAppanalysis(SComFrame frame); void onHeartComm(SComFrame &frame); @@ -69,6 +72,9 @@ protected: void onInitUser(); void onInitSerial(); void onInitUI(); + + QString SecondTimeString(quint64 value); + Q_SLOT void onLineseCheck(bool bFlag); signals: void sgSelModel(int, QString); void sgSendChangeUI(QString, QString); @@ -108,14 +114,16 @@ private: //status ״̬ int m_TimerID_Status{ 0 }; - class QLabel *m_pLbCurrentTime; - class QLabel *m_pLbOnLine; - class QLabel *m_pLbConnect; - class QLabel *m_pLbUser; - class QLabel *m_pLbDiskSpace; + QLabel *m_pLbCurrentTime{ nullptr }; + QLabel *m_pLbOnLine{ nullptr }; + QLabel *m_pLbConnect{ nullptr }; + QLabel *m_pLbUser{ nullptr }; + QLabel *m_pLbDiskSpace{ nullptr }; IUserCtrl *m_pUserCtrl{ nullptr };//û¼ ISerialPortTool *m_pSerialPort{ nullptr };//ͨѶģ + + QLabel* m_pLabelInfo{ nullptr }; private: //ͼģ CDllCoreCtrl* m_pDllCoreCtrl{nullptr}; @@ -142,6 +150,13 @@ private: QCameraMgrUI m_CamMgrUI; class IWfCtrl *m_pWfCtrl{ nullptr }; + + quint64 m_tickCount{ 0 }; + int m_heartTimeOut{ 0 }; + bool m_bPLCConnect{ false }; + + QCryptokeyUI *m_pCheckLineseUI{ nullptr }; + lpImageCaliUI* m_pImageCaliUI{ nullptr }; }; #endif diff --git a/tpvs17/lpMain/CMainWin.ui b/tpvs17/lpMain/CMainWin.ui index 2732dd8..6e7120d 100644 --- a/tpvs17/lpMain/CMainWin.ui +++ b/tpvs17/lpMain/CMainWin.ui @@ -68,7 +68,6 @@ - 宋体 22 @@ -132,8 +131,7 @@ - 微软雅黑 - 10 + 12 @@ -193,8 +191,7 @@ - 微软雅黑 - 10 + 12 @@ -242,11 +239,6 @@ - - - 12 - - Qt::ToolButtonTextUnderIcon @@ -258,21 +250,32 @@ - + - - - - + + + + 12 + + + :/toolbar/Resource/toolBar/cali.png:/toolbar/Resource/toolBar/cali.png - 标定 + 模型标定 + + + 模型标定 + + + + 12 + @@ -283,6 +286,11 @@ 模型管理 + + + 12 + + @@ -292,6 +300,11 @@ 测试 + + + 12 + + @@ -301,6 +314,11 @@ 帮助 + + + 12 + + @@ -310,18 +328,28 @@ 查询记录 + + + 12 + + - + :/toolbar/Resource/toolBar/setting.png:/toolbar/Resource/toolBar/setting.png - 工位配置 + 系统配置 系统配置 + + + 12 + + @@ -331,6 +359,11 @@ 登 录 + + + 12 + + @@ -340,6 +373,42 @@ 用户管理 + + + 12 + + + + + + + :/toolbar/Resource/toolBar/pen38.png:/toolbar/Resource/toolBar/pen38.png + + + 视场标定 + + + 视场标定 + + + + 12 + + + + + + + :/toolbar/Resource/toolBar/attachment6.png:/toolbar/Resource/toolBar/attachment6.png + + + 注册 + + + + 12 + + diff --git a/tpvs17/lpMain/QModelMangerUI.cpp b/tpvs17/lpMain/QModelMangerUI.cpp index b5391b9..4c9b771 100644 --- a/tpvs17/lpMain/QModelMangerUI.cpp +++ b/tpvs17/lpMain/QModelMangerUI.cpp @@ -14,6 +14,7 @@ QModelMangerUI::QModelMangerUI(QWidget *parent) : QWidget(parent) { ui.setupUi(this); + ui.wf_model_mod_button->setVisible(false); connect(ui.wf_model_select_button, SIGNAL(clicked()), this, SLOT(onButtonClicked())); connect(ui.wf_model_add_button, SIGNAL(clicked()), this, SLOT(onButtonClicked())); connect(ui.wf_model_mod_button, SIGNAL(clicked()), this, SLOT(onButtonClicked())); @@ -173,17 +174,21 @@ Q_SLOT bool QModelMangerUI::OnCellDoubleClicked(const QModelIndex &index) Q_SLOT void QModelMangerUI::onCheckBoxChange(int state) { -// if (state > 0) -// { -// ui.wf_model_select_button->setDisabled(true); + if (state > 0) + { + ui.wf_model_select_button->setDisabled(true); // if (m_pCtrl) // m_pCtrl->ISetOnlineModel(true); -// } -// else { -// ui.wf_model_select_button->setDisabled(false); + lpGlobalConfig::instance()->m_bOnlineMode = true; + lpGlobalConfig::instance()->writeConfig(); + } + else { + ui.wf_model_select_button->setDisabled(false); // if (m_pCtrl) // m_pCtrl->ISetOnlineModel(false); -// } + lpGlobalConfig::instance()->m_bOnlineMode = false; + lpGlobalConfig::instance()->writeConfig(); + } } // IStation * QModelMangerUI::getStation(int nIndex) @@ -199,15 +204,15 @@ Q_SLOT void QModelMangerUI::onCheckBoxChange(int state) void QModelMangerUI::showEvent(QShowEvent *event) { -// if (m_pCtrl) { -// if (m_pCtrl->IOnlineMode() == true) -// { -// ui.wf_chkbox_read_mode_from_plc->setChecked(true); -// } -// else { -// ui.wf_chkbox_read_mode_from_plc->setChecked(false); -// } -// } + if (m_pCtrl) { + if (lpGlobalConfig::instance()->m_bOnlineMode == true) + { + ui.wf_chkbox_read_mode_from_plc->setChecked(true); + } + else { + ui.wf_chkbox_read_mode_from_plc->setChecked(false); + } + } } void QModelMangerUI::closeEvent(QCloseEvent *event) @@ -231,7 +236,10 @@ void QModelMangerUI::onInitModelList(IWfCtrl *pCtrl) QStringList lst = pCtrl->IGetStationKeys(); int nIndex = 0; for each (QString var in lst) { + QFont font; + font.setPixelSize(18); QTableView *pW = new QTableView(ui.tabWidgetStation); + pW->setFont(font); pW->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch); pW->setEditTriggers(QAbstractItemView::NoEditTriggers); pW->setSelectionBehavior(QAbstractItemView::SelectRows); diff --git a/tpvs17/lpMain/lpGlobalConfig.cpp b/tpvs17/lpMain/lpGlobalConfig.cpp index 247b80b..fb8b922 100644 --- a/tpvs17/lpMain/lpGlobalConfig.cpp +++ b/tpvs17/lpMain/lpGlobalConfig.cpp @@ -40,10 +40,30 @@ void lpGlobalConfig::readConfig() m_bOnlineMode = rootObj.value("onlineMode").toBool(false); + int p1x_1 = rootObj.value("point1_x_1").toInt(0); + int p1y_1 = rootObj.value("point1_y_1").toInt(0); + int p2x_1 = rootObj.value("point2_x_1").toInt(100); + int p2y_1 = rootObj.value("point2_y_1").toInt(100); + double length_1 = rootObj.value("length_1").toDouble(1000); + point1_1.setX(p1x_1); + point1_1.setY(p1y_1); + point2_1.setX(p2x_1); + point2_1.setY(p2y_1); + fLength_1 = length_1; m_StationScale_1 = rootObj.value("StationScale_1").toDouble(1.0); m_StationXOffset_1 = rootObj.value("StationXOffset_1").toDouble(0.0); m_StationYOffset_1 = rootObj.value("StationYOffset_1").toDouble(0.0); + int p1x_2 = rootObj.value("point1_x_2").toInt(0); + int p1y_2 = rootObj.value("point1_y_2").toInt(0); + int p2x_2 = rootObj.value("point2_x_2").toInt(100); + int p2y_2 = rootObj.value("point2_y_2").toInt(100); + double length_2 = rootObj.value("length_2").toDouble(1000); + point1_2.setX(p1x_2); + point1_2.setY(p1y_2); + point2_2.setX(p2x_2); + point2_2.setY(p2y_2); + fLength_2 = length_2; m_StationScale_2 = rootObj.value("StationScale_2").toDouble(1.0); m_StationXOffset_2 = rootObj.value("StationXOffset_2").toDouble(0.0); m_StationYOffset_2 = rootObj.value("StationYOffset_2").toDouble(0.0); @@ -68,10 +88,22 @@ void lpGlobalConfig::writeConfig() rootObj.insert("onlineMode", m_bOnlineMode); + rootObj.insert("point1_x_1", point1_1.x()); + rootObj.insert("point1_y_1", point1_1.y()); + rootObj.insert("point2_x_1", point2_1.x()); + rootObj.insert("point2_y_1", point2_1.y()); + rootObj.insert("length_1", fLength_1); + rootObj.insert("StationScale_1",m_StationScale_1); rootObj.insert("StationXOffset_1",m_StationXOffset_1); rootObj.insert("StationYOffset_1",m_StationYOffset_1); + rootObj.insert("point1_x_2", point1_2.x()); + rootObj.insert("point1_y_2", point1_2.y()); + rootObj.insert("point2_x_2", point2_2.x()); + rootObj.insert("point2_y_2", point2_2.y()); + rootObj.insert("length_2", fLength_2); + rootObj.insert("StationScale_2",m_StationScale_2); rootObj.insert("StationXOffset_2",m_StationXOffset_2); rootObj.insert("StationYOffset_2",m_StationYOffset_2); diff --git a/tpvs17/lpMain/lpGlobalConfig.h b/tpvs17/lpMain/lpGlobalConfig.h index 0b82784..2eebdc6 100644 --- a/tpvs17/lpMain/lpGlobalConfig.h +++ b/tpvs17/lpMain/lpGlobalConfig.h @@ -4,6 +4,8 @@ #include #include "lp_singleton_base.h" #include +#include + class lpGlobalConfig : public QObject, public lp_singleton_base { Q_OBJECT @@ -23,14 +25,24 @@ public: QString m_StationRunModel_1; QString m_StationRunModel_2; - - double m_StationScale_1{ 1.0 }; - double m_StationXOffset_1{ 0.0 }; - double m_StationYOffset_1{ 0.0 }; - + + //궨 λA + QPoint point1_1;//궨 1 + QPoint point2_1;//궨 2 + double fLength_1{ 1000.0 };//궨㳤 + double m_StationScale_1{ 1.0 };// / + double m_StationXOffset_1{ 0.0 };//ƫ + double m_StationYOffset_1{ 0.0 };//ƫ + + //궨 λB + QPoint point1_2;//궨 1 + QPoint point2_2;//궨 2 + double fLength_2{ 1000.0 };//궨㳤 double m_StationScale_2{ 1.0 }; double m_StationXOffset_2{ 0.0 }; double m_StationYOffset_2{ 0.0 }; + + int pointCircle{ 20 };//궨 ֱ bool m_bOnlineMode{ false };//ģʽ QString m_rootPath; diff --git a/tpvs17/lpMain/lpGlobalData.h b/tpvs17/lpMain/lpGlobalData.h index a20e98c..b8a359d 100644 --- a/tpvs17/lpMain/lpGlobalData.h +++ b/tpvs17/lpMain/lpGlobalData.h @@ -10,10 +10,12 @@ class lpGlobalData : public QObject,public lp_singleton_base Q_OBJECT public: - lpGlobalData(QObject *parent); + lpGlobalData(QObject *parent = nullptr); ~lpGlobalData(); QString m_curStationModel1; QString m_curStationModel2; + + bool m_bCheckLinese{ false }; }; #endif diff --git a/tpvs17/lpMain/lpMain.vcxproj b/tpvs17/lpMain/lpMain.vcxproj index caedac9..b178ee5 100644 --- a/tpvs17/lpMain/lpMain.vcxproj +++ b/tpvs17/lpMain/lpMain.vcxproj @@ -54,7 +54,7 @@ true UNICODE;_UNICODE;WIN32;WIN64;LPMAIN_LIB;%(PreprocessorDefinitions) - .\GeneratedFiles;.;$(QTDIR)\include;$(QTDIR)\include\QtCore;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtWidgets;$(QTDIR)\include\QtSql;.\GeneratedFiles\$(ConfigurationName);..\..\3part\SerialPortTool\include;..\..\src\lpMain;..\..\src\lpMain\algela;..\..\src\lpMain\QDiskCleanThread;..\..\src\lpMain\sqliteDB;..\..\src\lpMain\UI;..\..\3part\opencv3.4.1\include;..\..\3part\opencv3.4.1\include\opencv;..\..\3part\opencv3.4.1\include\opencv2;..\..\3part\libzkq\include;..\..\3part\lpSyslog\inc;..\..\src\userCtrl;..\..\src\lpMain\CoreCtrl;..\..\3part\tadpole\include\tpBase;..\..\src\lpMain\view;%(AdditionalIncludeDirectories) + .\GeneratedFiles;.;$(QTDIR)\include;$(QTDIR)\include\QtCore;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtWidgets;$(QTDIR)\include\QtSql;.\GeneratedFiles\$(ConfigurationName);..\..\3part\SerialPortTool\include;..\..\src\lpMain;..\..\src\lpMain\algela;..\..\src\lpMain\QDiskCleanThread;..\..\src\lpMain\sqliteDB;..\..\src\lpMain\UI;..\..\3part\opencv3.4.1\include;..\..\3part\opencv3.4.1\include\opencv;..\..\3part\opencv3.4.1\include\opencv2;..\..\3part\libzkq\include;..\..\3part\lpSyslog\inc;..\..\src\userCtrl;..\..\src\lpMain\CoreCtrl;..\..\3part\tadpole\include\tpBase;..\..\src\lpMain\view;..\..\src\lpMain\cryptokey;..\..\3part\RsaCrypto\include;F:\ValueProject\newValve\3part\openssl-1.0.2n\vs13\include;%(AdditionalIncludeDirectories) Disabled ProgramDatabase MultiThreadedDebugDLL @@ -63,13 +63,13 @@ Windows $(SolutionDir)..\runner17\$(TargetName)$(TargetExt) - $(QTDIR)\lib;..\..\3part\opencv3.4.1\x64\vc15\lib;..\..\3part\lpSyslog\lib;..\..\3part\libzkq\lib;%(AdditionalLibraryDirectories) + $(QTDIR)\lib;..\..\3part\opencv3.4.1\x64\vc15\lib;..\..\3part\lpSyslog\lib;..\..\3part\libzkq\lib;..\..\3part\RsaCrypto\lib;..\..\3part\openssl-1.0.2n\vs13\lib\x64;%(AdditionalLibraryDirectories) true - qtmaind.lib;Qt5Cored.lib;Qt5Guid.lib;Qt5Widgetsd.lib;Qt5Sqld.lib;opencv_world341d.lib;lpSyslogd.lib;libzkqd.lib;%(AdditionalDependencies) + qtmaind.lib;Qt5Cored.lib;Qt5Guid.lib;Qt5Widgetsd.lib;Qt5Sqld.lib;opencv_world341d.lib;lpSyslogd.lib;libzkqd.lib;lpRsaCryptod.lib;libeay32.lib;ssleay32.lib;%(AdditionalDependencies) UNICODE;_UNICODE;WIN32;WIN64;LPMAIN_LIB;%(PreprocessorDefinitions) - .\GeneratedFiles;.;$(QTDIR)\include;$(QTDIR)\include\QtCore;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtWidgets;$(QTDIR)\include\QtSql;.\GeneratedFiles\$(ConfigurationName);..\..\3part\SerialPortTool\include;..\..\src\lpMain;..\..\src\lpMain\algela;..\..\src\lpMain\QDiskCleanThread;..\..\src\lpMain\sqliteDB;..\..\src\lpMain\UI;..\..\3part\opencv3.4.1\include;..\..\3part\opencv3.4.1\include\opencv;..\..\3part\opencv3.4.1\include\opencv2;..\..\3part\libzkq\include;..\..\3part\lpSyslog\inc;..\..\src\userCtrl;..\..\src\lpMain\CoreCtrl;..\..\3part\tadpole\include\tpBase;..\..\src\lpMain\view;%(AdditionalIncludeDirectories) + .\GeneratedFiles;.;$(QTDIR)\include;$(QTDIR)\include\QtCore;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtWidgets;$(QTDIR)\include\QtSql;.\GeneratedFiles\$(ConfigurationName);..\..\3part\SerialPortTool\include;..\..\src\lpMain;..\..\src\lpMain\algela;..\..\src\lpMain\QDiskCleanThread;..\..\src\lpMain\sqliteDB;..\..\src\lpMain\UI;..\..\3part\opencv3.4.1\include;..\..\3part\opencv3.4.1\include\opencv;..\..\3part\opencv3.4.1\include\opencv2;..\..\3part\libzkq\include;..\..\3part\lpSyslog\inc;..\..\src\userCtrl;..\..\src\lpMain\CoreCtrl;..\..\3part\tadpole\include\tpBase;..\..\src\lpMain\view;..\..\src\lpMain\cryptokey;..\..\3part\RsaCrypto\include;F:\ValueProject\newValve\3part\openssl-1.0.2n\vs13\include;%(AdditionalIncludeDirectories) .\GeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp Moc'ing %(Identity)... @@ -115,13 +115,23 @@ + + + + + + + + + + @@ -159,6 +169,9 @@ + + + @@ -220,6 +233,27 @@ .\GeneratedFiles;.;$(QTDIR)\include;$(QTDIR)\include\QtCore;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtWidgets;$(QTDIR)\include\QtSql;.\GeneratedFiles\$(ConfigurationName);.\..\..\3part\SerialPortTool\include;.\..\..\src\lpMain;.\..\..\src\lpMain\algela;.\..\..\src\lpMain\QDiskCleanThread;.\..\..\src\lpMain\sqliteDB;.\..\..\src\lpMain\UI;.\..\..\3part\opencv3.4.1\include;.\..\..\3part\opencv3.4.1\include\opencv;.\..\..\3part\opencv3.4.1\include\opencv2;.\..\..\3part\libzkq\include;.\..\..\3part\lpSyslog\inc;.\..\..\src\userCtrl;.\..\..\src\lpMain\CoreCtrl;.\..\..\3part\tadpole\include\tpBase;.\..\..\src\lpMain\view .\GeneratedFiles;.;$(QTDIR)\include;$(QTDIR)\include\QtCore;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtWidgets;$(QTDIR)\include\QtSql;.\GeneratedFiles\$(ConfigurationName);.\..\..\3part\SerialPortTool\include;.\..\..\src\lpMain;.\..\..\src\lpMain\algela;.\..\..\src\lpMain\QDiskCleanThread;.\..\..\src\lpMain\sqliteDB;.\..\..\src\lpMain\UI;.\..\..\3part\opencv3.4.1\include;.\..\..\3part\opencv3.4.1\include\opencv;.\..\..\3part\opencv3.4.1\include\opencv2;.\..\..\3part\libzkq\include;.\..\..\3part\lpSyslog\inc;.\..\..\src\userCtrl;.\..\..\src\lpMain\CoreCtrl;.\..\..\3part\tadpole\include\tpBase;.\..\..\src\lpMain\view + + + + .\GeneratedFiles;.;$(QTDIR)\include;$(QTDIR)\include\QtCore;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtWidgets;$(QTDIR)\include\QtSql;.\GeneratedFiles\$(ConfigurationName);.\..\..\3part\SerialPortTool\include;.\..\..\src\lpMain;.\..\..\src\lpMain\algela;.\..\..\src\lpMain\QDiskCleanThread;.\..\..\src\lpMain\sqliteDB;.\..\..\src\lpMain\UI;.\..\..\3part\opencv3.4.1\include;.\..\..\3part\opencv3.4.1\include\opencv;.\..\..\3part\opencv3.4.1\include\opencv2;.\..\..\3part\libzkq\include;.\..\..\3part\lpSyslog\inc;.\..\..\src\userCtrl;.\..\..\src\lpMain\CoreCtrl;.\..\..\3part\tadpole\include\tpBase;.\..\..\src\lpMain\view;.\..\..\src\lpMain\cryptokey;.\..\..\3part\RsaCrypto\include;F:\ValueProject\newValve\3part\openssl-1.0.2n\vs13\include + .\GeneratedFiles;.;$(QTDIR)\include;$(QTDIR)\include\QtCore;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtWidgets;$(QTDIR)\include\QtSql;.\GeneratedFiles\$(ConfigurationName);.\..\..\3part\SerialPortTool\include;.\..\..\src\lpMain;.\..\..\src\lpMain\algela;.\..\..\src\lpMain\QDiskCleanThread;.\..\..\src\lpMain\sqliteDB;.\..\..\src\lpMain\UI;.\..\..\3part\opencv3.4.1\include;.\..\..\3part\opencv3.4.1\include\opencv;.\..\..\3part\opencv3.4.1\include\opencv2;.\..\..\3part\libzkq\include;.\..\..\3part\lpSyslog\inc;.\..\..\src\userCtrl;.\..\..\src\lpMain\CoreCtrl;.\..\..\3part\tadpole\include\tpBase;.\..\..\src\lpMain\view + + + .\GeneratedFiles;.;$(QTDIR)\include;$(QTDIR)\include\QtCore;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtWidgets;$(QTDIR)\include\QtSql;.\GeneratedFiles\$(ConfigurationName);.\..\..\3part\SerialPortTool\include;.\..\..\src\lpMain;.\..\..\src\lpMain\algela;.\..\..\src\lpMain\QDiskCleanThread;.\..\..\src\lpMain\sqliteDB;.\..\..\src\lpMain\UI;.\..\..\3part\opencv3.4.1\include;.\..\..\3part\opencv3.4.1\include\opencv;.\..\..\3part\opencv3.4.1\include\opencv2;.\..\..\3part\libzkq\include;.\..\..\3part\lpSyslog\inc;.\..\..\src\userCtrl;.\..\..\src\lpMain\CoreCtrl;.\..\..\3part\tadpole\include\tpBase;.\..\..\src\lpMain\view;.\..\..\src\lpMain\cryptokey;.\..\..\3part\RsaCrypto\include;F:\ValueProject\newValve\3part\openssl-1.0.2n\vs13\include + .\GeneratedFiles;.;$(QTDIR)\include;$(QTDIR)\include\QtCore;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtWidgets;$(QTDIR)\include\QtSql;.\GeneratedFiles\$(ConfigurationName);.\..\..\3part\SerialPortTool\include;.\..\..\src\lpMain;.\..\..\src\lpMain\algela;.\..\..\src\lpMain\QDiskCleanThread;.\..\..\src\lpMain\sqliteDB;.\..\..\src\lpMain\UI;.\..\..\3part\opencv3.4.1\include;.\..\..\3part\opencv3.4.1\include\opencv;.\..\..\3part\opencv3.4.1\include\opencv2;.\..\..\3part\libzkq\include;.\..\..\3part\lpSyslog\inc;.\..\..\src\userCtrl;.\..\..\src\lpMain\CoreCtrl;.\..\..\3part\tadpole\include\tpBase;.\..\..\src\lpMain\view + + + + + + .\GeneratedFiles;.;$(QTDIR)\include;$(QTDIR)\include\QtCore;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtWidgets;$(QTDIR)\include\QtSql;.\GeneratedFiles\$(ConfigurationName);.\..\..\3part\SerialPortTool\include;.\..\..\src\lpMain;.\..\..\src\lpMain\algela;.\..\..\src\lpMain\QDiskCleanThread;.\..\..\src\lpMain\sqliteDB;.\..\..\src\lpMain\UI;.\..\..\3part\opencv3.4.1\include;.\..\..\3part\opencv3.4.1\include\opencv;.\..\..\3part\opencv3.4.1\include\opencv2;.\..\..\3part\libzkq\include;.\..\..\3part\lpSyslog\inc;.\..\..\src\userCtrl;.\..\..\src\lpMain\CoreCtrl;.\..\..\3part\tadpole\include\tpBase;.\..\..\src\lpMain\view;.\..\..\src\lpMain\cryptokey + .\GeneratedFiles;.;$(QTDIR)\include;$(QTDIR)\include\QtCore;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtWidgets;$(QTDIR)\include\QtSql;.\GeneratedFiles\$(ConfigurationName);.\..\..\3part\SerialPortTool\include;.\..\..\src\lpMain;.\..\..\src\lpMain\algela;.\..\..\src\lpMain\QDiskCleanThread;.\..\..\src\lpMain\sqliteDB;.\..\..\src\lpMain\UI;.\..\..\3part\opencv3.4.1\include;.\..\..\3part\opencv3.4.1\include\opencv;.\..\..\3part\opencv3.4.1\include\opencv2;.\..\..\3part\libzkq\include;.\..\..\3part\lpSyslog\inc;.\..\..\src\userCtrl;.\..\..\src\lpMain\CoreCtrl;.\..\..\3part\tadpole\include\tpBase;.\..\..\src\lpMain\view + + + .\GeneratedFiles;.;$(QTDIR)\include;$(QTDIR)\include\QtCore;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtWidgets;$(QTDIR)\include\QtSql;.\GeneratedFiles\$(ConfigurationName);.\..\..\3part\SerialPortTool\include;.\..\..\src\lpMain;.\..\..\src\lpMain\algela;.\..\..\src\lpMain\QDiskCleanThread;.\..\..\src\lpMain\sqliteDB;.\..\..\src\lpMain\UI;.\..\..\3part\opencv3.4.1\include;.\..\..\3part\opencv3.4.1\include\opencv;.\..\..\3part\opencv3.4.1\include\opencv2;.\..\..\3part\libzkq\include;.\..\..\3part\lpSyslog\inc;.\..\..\src\userCtrl;.\..\..\src\lpMain\CoreCtrl;.\..\..\3part\tadpole\include\tpBase;.\..\..\src\lpMain\view;.\..\..\src\lpMain\cryptokey;.\..\..\3part\RsaCrypto\include;F:\ValueProject\newValve\3part\openssl-1.0.2n\vs13\include + .\GeneratedFiles;.;$(QTDIR)\include;$(QTDIR)\include\QtCore;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtWidgets;$(QTDIR)\include\QtSql;.\GeneratedFiles\$(ConfigurationName);.\..\..\3part\SerialPortTool\include;.\..\..\src\lpMain;.\..\..\src\lpMain\algela;.\..\..\src\lpMain\QDiskCleanThread;.\..\..\src\lpMain\sqliteDB;.\..\..\src\lpMain\UI;.\..\..\3part\opencv3.4.1\include;.\..\..\3part\opencv3.4.1\include\opencv;.\..\..\3part\opencv3.4.1\include\opencv2;.\..\..\3part\libzkq\include;.\..\..\3part\lpSyslog\inc;.\..\..\src\userCtrl;.\..\..\src\lpMain\CoreCtrl;.\..\..\3part\tadpole\include\tpBase;.\..\..\src\lpMain\view + diff --git a/tpvs17/lpMain/lpMain.vcxproj.filters b/tpvs17/lpMain/lpMain.vcxproj.filters index 3be7aa6..63c96fd 100644 --- a/tpvs17/lpMain/lpMain.vcxproj.filters +++ b/tpvs17/lpMain/lpMain.vcxproj.filters @@ -52,6 +52,12 @@ ts false + + {0cebe5c0-1170-4f3a-9e0f-8b707e64c004} + + + {d14394a4-d4ae-4d47-b726-613b27aa46e7} + @@ -168,6 +174,36 @@ Source Files + + cryptokey + + + cryptokey + + + cryptokey + + + ImageStandardUI + + + lpMain\algela + + + lpMain\algela + + + lpMain\algela + + + lpMain\algela + + + lpMain\algela + + + lpMain\algela + @@ -278,6 +314,18 @@ Header Files + + cryptokey + + + ImageStandardUI + + + lpMain\algela + + + lpMain\algela + @@ -313,6 +361,15 @@ Form Files + + cryptokey + + + ImageStandardUI + + + lpMain\algela + @@ -339,6 +396,21 @@ Header Files + + cryptokey + + + cryptokey + + + lpMain\algela + + + lpMain\algela + + + lpMain\algela +