You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
nmWTAI-Platform/Src/nmNum/nmPlot/nmGuiPlotCmdHelper.cpp

480 lines
17 KiB
C++

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#include "ZxBaseUtil.h"
#include "zxLogInstance.h"
#include <QWidget>
#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 "nmObjLineCrack.h"
#include "nmObjLineFaultTool.h"
#include "nmObjLineFault.h"
#include "nmObjLineMeasuringScaleTool.h"
#include "nmObjPointWellTool.h"
#include "nmObjPointWell.h"
#include "nmObjLineMeasureTool.h"
#include "nmObjLineMeasure.h"
#include "nmGuiPlot.h"
#include "nmGuiPlotCmdHelper.h"
#include "nmPlotGraphicBinder.h"
#include "nmDataLogFile.h"
#include "nmObjRectTool.h"
#include "nmObjRectOutlineTool.h"
#include "nmObjRectOutline.h"
#include "nmObjRoundTool.h"
#include "nmObjRoundOutlineTool.h"
#include "nmObjRoundOutline.h"
#include "nmObjPolygonOutline.h"
#include "nmObjRegionMark.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<nmGuiPlot*>(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<nmObjBase*>(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<QPointF>&)), \
this, SLOT(slotObjPtsFinished(QVector<QPointF>&)));
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<QPointF>&)), \
this, SLOT(slotObjPtsFinished(QVector<QPointF>&)));
return true;
} else if (_isSame(sAction, "nmInsertObjLine")) {
nmObjToolBase* pObjTool = new nmObjLineTool();
Q_ASSERT (NULL != pObjTool);
pPlot->appendTools(pObjTool);
connect(pObjTool, SIGNAL(sigPtsFinished(QVector<QPointF>&)), \
this, SLOT(slotObjPtsFinished(QVector<QPointF>&)));
return true;
} else if (_isSame(sAction, "nmInsertObjPolygon")) {
nmObjToolBase* pObjTool = new nmObjPolygonTool();
Q_ASSERT (NULL != pObjTool);
pPlot->appendTools(pObjTool);
connect(pObjTool, SIGNAL(sigPtsFinished(QVector<QPointF>&)), \
this, SLOT(slotObjPtsFinished(QVector<QPointF>&)));
return true;
} else if (_isSame(sAction, "nmInsertObjPolygonOutline")) {
nmObjToolBase* pObjTool = new nmObjPolygonOutlineTool();
Q_ASSERT (NULL != pObjTool);
pPlot->appendTools(pObjTool);
connect(pObjTool, SIGNAL(sigPtsFinished(QVector<QPointF>&)), \
this, SLOT(slotObjPtsFinished(QVector<QPointF>&)));
return true;
} else if (_isSame(sAction, "nmInsertObjRect")) {
nmObjToolBase* pObjTool = new nmObjRectTool(); //矩形对象工具类
Q_ASSERT (NULL != pObjTool);
pPlot->appendTools(pObjTool);
connect(pObjTool, SIGNAL(sigPtsFinished(QVector<QPointF>&)), \
this, SLOT(slotObjPtsFinished(QVector<QPointF>&)));
return true;
} else if (_isSame(sAction, "nmInsertObjRectOutline")) {
nmObjToolBase* pObjTool = new nmObjRectOutlineTool(); //矩形边界工具类
Q_ASSERT (NULL != pObjTool);
pPlot->appendTools(pObjTool);
connect(pObjTool, SIGNAL(sigPtsFinished(QVector<QPointF>&)), \
this, SLOT(slotObjPtsFinished(QVector<QPointF>&)));
return true;
} else if (_isSame(sAction, "nmInsertObjRound")) {
nmObjToolBase* pObjTool = new nmObjRoundTool(); //圆形对象工具类
Q_ASSERT (NULL != pObjTool);
pPlot->appendTools(pObjTool);
connect(pObjTool, SIGNAL(sigPtsFinished(QVector<QPointF>&)), \
this, SLOT(slotObjPtsFinished(QVector<QPointF>&)));
return true;
} else if (_isSame(sAction, "nmInsertObjRoundOutline")) {
nmObjToolBase* pObjTool = new nmObjRoundOutlineTool(); //圆形边界工具类
Q_ASSERT (NULL != pObjTool);
pPlot->appendTools(pObjTool);
connect(pObjTool, SIGNAL(sigPtsFinished(QVector<QPointF>&)), \
this, SLOT(slotObjPtsFinished(QVector<QPointF>&)));
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<QPointF>&)),
this, SLOT(slotObjPtsFinished(QVector<QPointF>&)));
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<QPointF>&)),
this, SLOT(slotObjPtsFinished(QVector<QPointF>&)));
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<QPointF>&)),
this, SLOT(slotObjPtsFinished(QVector<QPointF>&)));
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<QPointF>&)),
this, SLOT(slotObjPtsFinished(QVector<QPointF>&)));
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<QPointF>&)), \
this, SLOT(slotObjPtsFinished(QVector<QPointF>&)));
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<QPointF>&)), \
this, SLOT(slotObjPtsFinished(QVector<QPointF>&)));
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<QPointF>&)),
this, SLOT(slotObjPtsFinished(QVector<QPointF>&)));
m_activeTools.insert(NMOT_RegionMark, pObjTool);
return true;
} else {
// 其它Action
}
return iGuiPlotCmdHelper::runAction(sAction);
}
void nmGuiPlotCmdHelper::slotObjPtsFinished(QVector<QPointF>& vec) {
nmObjToolBase* pTool = dynamic_cast<nmObjToolBase*>(sender());
if (NULL == pTool) {
return;
}
nmGuiPlot* pWxPlot = dynamic_cast<nmGuiPlot*>(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);
// 断层/裂缝/边界创建逻辑已改由 Binder 负责(创建数据 + 建立信号连接)
if (pTool->getNOT() == NMOT_Line_Fault) {
nmObjLineFault* pFault = dynamic_cast<nmObjLineFault*>(pObj);
if (pFault && pWxPlot->graphicBinder()) {
pWxPlot->graphicBinder()->createFaultForGraphic(pFault);
}
} else if (pTool->getNOT() == NMOT_Line_Fracture) {
nmObjLineCrack* pCrack = dynamic_cast<nmObjLineCrack*>(pObj);
if (pCrack && pWxPlot->graphicBinder()) {
pWxPlot->graphicBinder()->createCrackForGraphic(pCrack);
}
} else if (pTool->getNOT() == NMOT_RectOutline ||
pTool->getNOT() == NMOT_RoundOutline ||
pTool->getNOT() == NMOT_PolygonOutline) {
// 先执行 afterCreated矩形边界会在其中 reorderPoints
pObj->afterCreated();
// 再通过 Binder 创建数据并建立绑定
if (pWxPlot->graphicBinder()) {
nmObjRoundOutline* pRound = dynamic_cast<nmObjRoundOutline*>(pObj);
nmObjRectOutline* pRect = dynamic_cast<nmObjRectOutline*>(pObj);
nmObjPolygonOutline* pPolygon = dynamic_cast<nmObjPolygonOutline*>(pObj);
if (pRound) {
pWxPlot->graphicBinder()->createOutlineForGraphic(pRound);
} else if (pRect) {
pWxPlot->graphicBinder()->createOutlineForGraphic(pRect);
} else if (pPolygon) {
pWxPlot->graphicBinder()->createOutlineForGraphic(pPolygon);
}
}
} else if (pTool->getNOT() == NMOT_Line_Measure) {
// 先执行 afterCreated设置锁定、只读等属性
pObj->afterCreated();
// 再通过 Binder 创建数据并建立绑定
nmObjLineMeasure* pMeasure = dynamic_cast<nmObjLineMeasure*>(pObj);
if (pMeasure && pWxPlot->graphicBinder()) {
pWxPlot->graphicBinder()->createMeasureForGraphic(pMeasure);
}
} else if (pTool->getNOT() == NMOT_RegionMark) {
// 先执行 afterCreated图元内部初始化
pObj->afterCreated();
// 再通过 Binder 创建数据并建立绑定
nmObjRegionMark* pRegionMark = dynamic_cast<nmObjRegionMark*>(pObj);
if (pRegionMark && pWxPlot->graphicBinder()) {
pWxPlot->graphicBinder()->createRegionMarkForGraphic(pRegionMark);
}
} else if (pTool->getNOT() == NMOT_Region) {
// 先执行 afterCreated图元内部初始化点排序
pObj->afterCreated();
// 再通过 Binder 创建数据并建立绑定
nmObjRegion* pRegion = dynamic_cast<nmObjRegion*>(pObj);
if (pRegion && pWxPlot->graphicBinder()) {
pWxPlot->graphicBinder()->createRegionForGraphic(pRegion);
}
} else if (pTool->getNOT() == NMOT_Point_Well) {
// 井图元:先设置 Binder再执行 afterCreated内部通过 Binder 创建井数据)
nmObjPointWell* pWell = dynamic_cast<nmObjPointWell*>(pObj);
if (pWell && pWxPlot->graphicBinder()) {
pWell->setGraphicBinder(pWxPlot->graphicBinder());
}
pObj->afterCreated();
} else {
pObj->afterCreated();
}
}
void nmGuiPlotCmdHelper::finishMeasure()
{
nmGuiPlot* pWxPlot = dynamic_cast<nmGuiPlot*>(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() {
}