#include "ZxBaseUtil.h" #include "zxLogInstance.h" #include #include "ZxPlot.h" #include "ZxSubAxisX.h" #include "ZxSubAxisY.h" #include "iGuiPlot.h" #include "nmObjBase.h" #include "nmObjPointTool.h" #include "nmObjLineTool.h" #include "nmObjPolygonTool.h" #include "nmObjPolygonOutlineTool.h" #include "nmObjLineCrackTool.h" #include "nmObjLineFaultTool.h" #include "nmObjLineMeasuringScaleTool.h" #include "nmObjPointWellTool.h" #include "nmObjLineMeasureTool.h" #include "nmGuiPlot.h" #include "nmGuiPlotCmdHelper.h" #include "nmDataLogFile.h" #include "nmObjRectTool.h" #include "nmObjRectOutlineTool.h" #include "nmObjRoundTool.h" #include "nmObjRoundOutlineTool.h" #include "nmObjRegionTool.h" #include "nmObjDeleteTool.h" #include "nmPlotDialogContext.h" #include "nmPlotDialogContextProvider.h" #include "nmObjRegionMarkTool.h" #include "nmDataAnalyzeManager.h" nmGuiPlotCmdHelper::nmGuiPlotCmdHelper(iGuiPlot* p) : iGuiPlotCmdHelper(p) { } nmGuiPlotCmdHelper::~nmGuiPlotCmdHelper() { } bool nmGuiPlotCmdHelper::runAction(QString sAction) { Q_ASSERT (NULL != m_pGuiPlot); ZxPlot* pPlot = m_pGuiPlot->m_pPlot; Q_ASSERT (NULL != pPlot); // 清除图元选中状态 nmGuiPlot* pNmPlot = static_cast(m_pGuiPlot); pNmPlot->clearPlotsSelectStates(); // 添加之前先激活所有图元对象的可见性 // 边界 pNmPlot->setContourVisibility(true); // TODO:位图 // 断层 pNmPlot->setAllFaultsVisible(true); // 井 pNmPlot->setAllWellsVisible(true); // 裂缝 pNmPlot->setAllFracturesVisible(true); // 区域 pNmPlot->setAllRegionsVisible(true); // 区域标记 pNmPlot->setAllRegionMarksVisible(true); // 同时将显示界面的父节点更新为选中 nmDataAnalyzeManager::getCurrentInstance()->setAllCategoriesRootVisibility(true); // 清除上次的工具 foreach (nmObjToolBase* oldTool, m_activeTools.values()) { pPlot->removeTools(oldTool); } m_activeTools.clear(); // 确保只有一个边界 if (sAction == "nmInsertObjPolygonOutline" || \ sAction == "nmInsertObjRectOutline" || \ sAction == "nmInsertObjRoundOutline" ) { int objCount = pPlot->getObjCount(); for(int i = 0; i < objCount; i++) { ZxObjBase* obj = pPlot->getObjByIndex(i); if (obj == NULL) { continue; } nmObjBase* nmObj = dynamic_cast(obj); if (nmObj == NULL) { continue; } // 检查是否为矩形轮廓 if (_isSame("nObjRectOutline", nmObj->getTagName())) { nmPlotDialogContextProvider* pDialogProvider = nmPlotDialogContext::provider(); if (pDialogProvider != nullptr && pDialogProvider->confirmSwitchOutline()) { // 删除图元 pPlot->removeObjByName(nmObj->getName()); nmObj->removeData(); } else { return false; } } // 检查是否为多边形轮廓 if (_isSame("nObjPolygonOutline", nmObj->getTagName())) { nmPlotDialogContextProvider* pDialogProvider = nmPlotDialogContext::provider(); if (pDialogProvider != nullptr && pDialogProvider->confirmSwitchOutline()) { // 删除图元 pPlot->removeObjByName(nmObj->getName()); nmObj->removeData(); } else { return false; } } // 检查是否为圆形轮廓 if (_isSame("nObjRoundOutline", nmObj->getTagName())) { nmPlotDialogContextProvider* pDialogProvider = nmPlotDialogContext::provider(); if (pDialogProvider != nullptr && pDialogProvider->confirmSwitchOutline()) { // 删除图元 pPlot->removeObjByName(nmObj->getName()); nmObj->removeData(); } else { return false; } } } } nmDataLogFile::getInstance()->writeLog(" cmdHelper " + sAction); // 鼠标交互,插入数值试井绘图对象 的例子:点、线、多边形 if (_isSame(sAction, "nmInsertObjPoint")) { nmObjToolBase* pObjTool = new nmObjPointTool(); Q_ASSERT (NULL != pObjTool); pPlot->appendTools(pObjTool); connect(pObjTool, SIGNAL(sigPtsFinished(QVector&)), \ this, SLOT(slotObjPtsFinished(QVector&))); return true; } else if (_isSame(sAction, "nmInsertObjPointWell")) { nmObjToolBase* pObjTool = new nmObjPointWellTool(); nmDataLogFile::getInstance()->writeLog("in nmGuiPlotCmdHelper " + QString::number(pObjTool->getNOT())); Q_ASSERT (NULL != pObjTool); pPlot->appendTools(pObjTool); connect(pObjTool, SIGNAL(sigPtsFinished(QVector&)), \ this, SLOT(slotObjPtsFinished(QVector&))); return true; } else if (_isSame(sAction, "nmInsertObjLine")) { nmObjToolBase* pObjTool = new nmObjLineTool(); Q_ASSERT (NULL != pObjTool); pPlot->appendTools(pObjTool); connect(pObjTool, SIGNAL(sigPtsFinished(QVector&)), \ this, SLOT(slotObjPtsFinished(QVector&))); return true; } else if (_isSame(sAction, "nmInsertObjPolygon")) { nmObjToolBase* pObjTool = new nmObjPolygonTool(); Q_ASSERT (NULL != pObjTool); pPlot->appendTools(pObjTool); connect(pObjTool, SIGNAL(sigPtsFinished(QVector&)), \ this, SLOT(slotObjPtsFinished(QVector&))); return true; } else if (_isSame(sAction, "nmInsertObjPolygonOutline")) { nmObjToolBase* pObjTool = new nmObjPolygonOutlineTool(); Q_ASSERT (NULL != pObjTool); pPlot->appendTools(pObjTool); connect(pObjTool, SIGNAL(sigPtsFinished(QVector&)), \ this, SLOT(slotObjPtsFinished(QVector&))); return true; } else if (_isSame(sAction, "nmInsertObjRect")) { nmObjToolBase* pObjTool = new nmObjRectTool(); //矩形对象工具类 Q_ASSERT (NULL != pObjTool); pPlot->appendTools(pObjTool); connect(pObjTool, SIGNAL(sigPtsFinished(QVector&)), \ this, SLOT(slotObjPtsFinished(QVector&))); return true; } else if (_isSame(sAction, "nmInsertObjRectOutline")) { nmObjToolBase* pObjTool = new nmObjRectOutlineTool(); //矩形边界工具类 Q_ASSERT (NULL != pObjTool); pPlot->appendTools(pObjTool); connect(pObjTool, SIGNAL(sigPtsFinished(QVector&)), \ this, SLOT(slotObjPtsFinished(QVector&))); return true; } else if (_isSame(sAction, "nmInsertObjRound")) { nmObjToolBase* pObjTool = new nmObjRoundTool(); //圆形对象工具类 Q_ASSERT (NULL != pObjTool); pPlot->appendTools(pObjTool); connect(pObjTool, SIGNAL(sigPtsFinished(QVector&)), \ this, SLOT(slotObjPtsFinished(QVector&))); return true; } else if (_isSame(sAction, "nmInsertObjRoundOutline")) { nmObjToolBase* pObjTool = new nmObjRoundOutlineTool(); //圆形边界工具类 Q_ASSERT (NULL != pObjTool); pPlot->appendTools(pObjTool); connect(pObjTool, SIGNAL(sigPtsFinished(QVector&)), \ this, SLOT(slotObjPtsFinished(QVector&))); return true; } else if (_isSame(sAction, "nmInsertObjLineCrack")) { nmObjToolBase* pObjTool = new nmObjLineCrackTool(); nmDataLogFile::getInstance()->writeLog("in nmGuiPlotCmdHelper " + QString::number(pObjTool->getNOT())); Q_ASSERT(NULL != pObjTool); pPlot->appendTools(pObjTool); connect(pObjTool, SIGNAL(sigPtsFinished(QVector&)), this, SLOT(slotObjPtsFinished(QVector&))); m_activeTools.insert(NMOT_Line_Fracture, pObjTool); return true; } else if (_isSame(sAction, "nmInsertObjLineFault")) { nmObjToolBase* pObjTool = new nmObjLineFaultTool(); nmDataLogFile::getInstance()->writeLog("in nmGuiPlotCmdHelper " + QString::number(pObjTool->getNOT())); Q_ASSERT(NULL != pObjTool); pPlot->appendTools(pObjTool); connect(pObjTool, SIGNAL(sigPtsFinished(QVector&)), this, SLOT(slotObjPtsFinished(QVector&))); m_activeTools.insert(NMOT_Line_Fault, pObjTool); return true; } else if (_isSame(sAction, "nmInsertObjRegion")) { nmObjToolBase* pObjTool = new nmObjRegionTool(); nmDataLogFile::getInstance()->writeLog("in nmGuiPlotCmdHelper " + QString::number(pObjTool->getNOT())); Q_ASSERT(NULL != pObjTool); pPlot->appendTools(pObjTool); connect(pObjTool, SIGNAL(sigPtsFinished(QVector&)), this, SLOT(slotObjPtsFinished(QVector&))); m_activeTools.insert(NMOT_Region, pObjTool); return true; } else if (_isSame(sAction, "nmInsertObjLineMeasuringScale")) { nmObjToolBase* pObjTool = new nmObjLineMeasuringScaleTool(); nmDataLogFile::getInstance()->writeLog("in nmGuiPlotCmdHelper " + QString::number(pObjTool->getNOT())); Q_ASSERT(NULL != pObjTool); pPlot->appendTools(pObjTool); connect(pObjTool, SIGNAL(sigPtsFinished(QVector&)), this, SLOT(slotObjPtsFinished(QVector&))); m_activeTools.insert(NMOT_Line_MeasuringScale, pObjTool); return true; } else if (_isSame(sAction, "nmInsertObjLineMeasure")) { nmObjToolBase* pExistingTool = m_activeTools.value(NMOT_Line_Measure, nullptr); if(pExistingTool) { return true; } nmObjLineMeasureTool* pMeasureTool = new nmObjLineMeasureTool(); nmObjToolBase* pObjTool = pMeasureTool; nmDataLogFile::getInstance()->writeLog("in nmGuiPlotCmdHelper " + QString::number(pObjTool->getNOT())); Q_ASSERT(NULL != pObjTool); pPlot->appendTools(pObjTool); connect(pObjTool, SIGNAL(sigPtsFinished(QVector&)), \ this, SLOT(slotObjPtsFinished(QVector&))); connect(pMeasureTool, SIGNAL(sigMeasureStarted()), \ pNmPlot, SLOT(clearPreviousMeasure())); connect(pMeasureTool, SIGNAL(sigMeasureStarted()), \ this, SIGNAL(sigMeasureStarted())); m_activeTools.insert(NMOT_Line_Measure, pObjTool); return true; } else if (_isSame(sAction, "nmDeleteOneObj")) { nmObjToolBase* pObjTool = new nmObjDeleteTool(pPlot); nmDataLogFile::getInstance()->writeLog("in nmGuiPlotCmdHelper " + QString::number(pObjTool->getNOT())); Q_ASSERT (NULL != pObjTool); pPlot->appendTools(pObjTool); connect(pObjTool, SIGNAL(sigPtsFinished(QVector&)), \ this, SLOT(slotObjPtsFinished(QVector&))); m_activeTools.insert(NMOT_Delete, pObjTool); return true; } else if (_isSame(sAction, "nmInsertRegionMark")) { nmObjToolBase* pObjTool = new nmObjRegionMarkTool(pPlot); nmDataLogFile::getInstance()->writeLog("in nmGuiPlotCmdHelper " + QString::number(pObjTool->getNOT())); Q_ASSERT(NULL != pObjTool); pPlot->appendTools(pObjTool); connect(pObjTool, SIGNAL(sigPtsFinished(QVector&)), this, SLOT(slotObjPtsFinished(QVector&))); m_activeTools.insert(NMOT_RegionMark, pObjTool); return true; } else { // 其它Action } return iGuiPlotCmdHelper::runAction(sAction); } void nmGuiPlotCmdHelper::slotObjPtsFinished(QVector& vec) { nmObjToolBase* pTool = dynamic_cast(sender()); if (NULL == pTool) { return; } nmGuiPlot* pWxPlot = dynamic_cast(m_pGuiPlot); if (NULL == pWxPlot) { return; } ZxPlot* pPlot = pWxPlot->m_pPlot; Q_ASSERT (NULL != pPlot); // 如果不为测量工具则移除 if (pTool->getNOT() != NMOT_Line_Measure) { pPlot->removeTools(pTool); // 从活跃 map 里清除它 m_activeTools.remove(pTool->getNOT()); } QString sName = tr("nmObj"); // 默认名称 // 根据类型设置绘图对象名称 if (pTool->getNOT() == NMOT_Point) { sName = tr("Point"); } else if (pTool->getNOT() == NMOT_Point_Well) { sName = tr("Well"); } else if (pTool->getNOT() == NMOT_Line) { sName = tr("Line"); } else if (pTool->getNOT() == NMOT_Polygon) { sName = tr("Polygon"); } else if (pTool->getNOT() == NMOT_PolygonOutline) { sName = tr("PolygonOutline"); } else if (pTool->getNOT() == NMOT_Line_Fracture) { sName = tr("Fracture"); } else if (pTool->getNOT() == NMOT_Line_Fault) { sName = tr("Fault"); } else if (pTool->getNOT() == NMOT_Line_MeasuringScale) { sName = tr("MeasuringScale"); } else if (pTool->getNOT() == NMOT_Line_Measure) { sName = tr("Measure"); } else if (pTool->getNOT() == NMOT_Rect) { sName = tr("Rectangle"); } else if (pTool->getNOT() == NMOT_RectOutline) { sName = tr("RectangleOutline"); } else if (pTool->getNOT() == NMOT_Round) { sName = tr("Circle"); } else if (pTool->getNOT() == NMOT_RoundOutline) { sName = tr("CircleOutline"); } else if (pTool->getNOT() == NMOT_Region) { sName = tr("Limit"); } else if (pTool->getNOT() == NMOT_Delete) { sName = tr("Delete"); } else if (pTool->getNOT() == NMOT_RegionMark) { sName = tr("Region"); } nmObjBase* pObj = pWxPlot->appendOneObj(pTool->getNOT(), sName, vec); pObj->afterCreated(); } void nmGuiPlotCmdHelper::finishMeasure() { nmGuiPlot* pWxPlot = dynamic_cast(m_pGuiPlot); if(pWxPlot == nullptr || pWxPlot->m_pPlot == nullptr) { return; } nmObjToolBase* pMeasureTool = m_activeTools.value(NMOT_Line_Measure, nullptr); if(pMeasureTool) { pWxPlot->m_pPlot->removeTools(pMeasureTool); m_activeTools.remove(NMOT_Line_Measure); } pWxPlot->deleteMeasureObjects(); } // 插入背景 void nmGuiPlotCmdHelper::insertBkImg() { QString sLastDir = ZxBaseUtil::getLastDir(); QString sFilter = QString(tr("Image file (*.png;*.jpg;*.bmp)")); QString sFile = ZxBaseUtil::getOpenFileName(NULL, tr("Open File"), sLastDir, sFilter); if (!QFile::exists(sFile)) { return; } QFileInfo fi(sFile); ZxBaseUtil::setLastDir(fi.absolutePath()); Q_ASSERT (NULL != m_pGuiPlot); ZxPlot* pPlot = m_pGuiPlot->m_pPlot; Q_ASSERT (NULL != pPlot); { pPlot->setBkImgFile(sFile); QImage* pBkImg = pPlot->getBkImg(); Q_ASSERT (NULL != pBkImg); int w = pBkImg->width(); int h = pBkImg->height(); if (w > 0 && h > 0) { pPlot->getMainAxisX()->setRangeMinMax(0, w, true); pPlot->getMainAxisY()->setRangeMinMax(0, h, true); } // pPlot->setMinimizeAxisX(true); // pPlot->setMinimizeAxisY(true); } } // 插入井点 void nmGuiPlotCmdHelper::insertOneWell() { }