|
|
#include "ZxBaseUtil.h"
|
|
|
#include "zxLogInstance.h"
|
|
|
|
|
|
#include "ZxSubAxisX.h"
|
|
|
#include "ZxSubAxisY.h"
|
|
|
#include "ZxSubTitle.h"
|
|
|
|
|
|
#include "ZxPlot.h"
|
|
|
#include "ZxObjCurve.h"
|
|
|
#include "nmPlotScene.h"
|
|
|
#include "nmPlotView.h"
|
|
|
|
|
|
#include "nmObjPoint.h"
|
|
|
#include "nmObjLine.h"
|
|
|
#include "nmObjPolygon.h"
|
|
|
#include "nmObjPolygonOutline.h"
|
|
|
#include "nmObjLineCrack.h"
|
|
|
#include "nmObjLineFault.h"
|
|
|
#include "nmObjPointWell.h"
|
|
|
|
|
|
#include "nmGuiPlotCmdHelper.h"
|
|
|
#include "nmGuiPlot.h"
|
|
|
|
|
|
#include "nmDataLogFile.h"
|
|
|
#include "nmSingalCenter.h"
|
|
|
|
|
|
#include "ZxDataProject.h"
|
|
|
#include "TreeWxMain.h"
|
|
|
|
|
|
#include "Defines.h"
|
|
|
#include "zxSysUtils.h"
|
|
|
|
|
|
nmGuiPlot::nmGuiPlot(bool bUseBtns, QWidget *parent) :
|
|
|
iGuiPlot(bUseBtns, parent)
|
|
|
{
|
|
|
m_bUseBtns = bUseBtns;
|
|
|
if (NULL != m_pCmdHelper) {
|
|
|
delete m_pCmdHelper;
|
|
|
m_pCmdHelper = NULL;
|
|
|
}
|
|
|
m_pCmdHelper = new nmGuiPlotCmdHelper(this);
|
|
|
Q_ASSERT (NULL != m_pCmdHelper);
|
|
|
m_sChartCmdType = "NmDemo2DType";
|
|
|
setWindowTitle(tr("nmGuiPlot"));
|
|
|
nmSingalCenter* sCenter = nmSingalCenter::getInstance();
|
|
|
connect(sCenter, SIGNAL(sigDeleteWell(QString)), this, SLOT(slotDeleteWell(QString)));
|
|
|
}
|
|
|
|
|
|
nmGuiPlot::~nmGuiPlot()
|
|
|
{
|
|
|
}
|
|
|
|
|
|
void nmGuiPlot::initUI(QString sTitle,
|
|
|
QSize szDefault /*= QSize(265, 203)*/)
|
|
|
{
|
|
|
iGuiPlot::initUI(sTitle, szDefault);
|
|
|
}
|
|
|
|
|
|
void nmGuiPlot::initSheets()
|
|
|
{
|
|
|
// iGuiPlot::initSheets();
|
|
|
}
|
|
|
|
|
|
void nmGuiPlot::initMainLayout()
|
|
|
{
|
|
|
iGuiPlot::initMainLayout();
|
|
|
}
|
|
|
|
|
|
QWidget* nmGuiPlot::initChartLayout(QString sTitle, QSize szDefault)
|
|
|
{
|
|
|
return iGuiPlot::initChartLayout(sTitle, szDefault);
|
|
|
}
|
|
|
|
|
|
void nmGuiPlot::initChartView(QString sTitle, QSize szDefault)
|
|
|
{
|
|
|
// iGuiPlot::initChartView(sTitle, szDefault);
|
|
|
m_pPlotView = new nmPlotView();
|
|
|
Q_ASSERT (NULL != m_pPlotView);
|
|
|
m_pPlotScene = new nmPlotScene();
|
|
|
Q_ASSERT (NULL != m_pPlotScene);
|
|
|
m_pPlotView->setScene(m_pPlotScene);
|
|
|
m_pPlotScene->init(m_pPlotView, sTitle, szDefault);
|
|
|
//m_pPlotView->setSimpleMode(true);
|
|
|
m_pPlot = m_pPlotScene->m_pPlot;
|
|
|
m_pPlotView->setMargins(0, 0, 0, 0);
|
|
|
m_pPlotView->setZoomMode(ZxRenderView::eZoomFitWindow, true);
|
|
|
connectSignals();
|
|
|
}
|
|
|
|
|
|
void nmGuiPlot::connectSignals()
|
|
|
{
|
|
|
iGuiPlot::connectSignals();
|
|
|
// your owns
|
|
|
if (NULL != m_pPlot) {
|
|
|
// disconnect(m_pPlot, SIGNAL(sigUpdate()), \
|
|
|
// m_pPlotView->viewport(), SLOT(update()));
|
|
|
// connect(m_pPlot, SIGNAL(sigUpdate()), \
|
|
|
// m_pPlotView->viewport(), SLOT(update()));
|
|
|
}
|
|
|
}
|
|
|
|
|
|
void nmGuiPlot::runUpdate()
|
|
|
{
|
|
|
// iGuiPlot::updatePlots();
|
|
|
if (NULL != m_pPlot) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
bool nmGuiPlot::runAction(QString sAction)
|
|
|
{
|
|
|
Q_ASSERT (NULL != m_pCmdHelper);
|
|
|
return m_pCmdHelper->runAction(sAction);
|
|
|
}
|
|
|
|
|
|
nmObjBase* nmGuiPlot::appendOneObj(NM_Obj_Type o, QString& sName, QVector<QPointF>& vec)
|
|
|
{
|
|
|
nmObjBase* pObj = _createOneObj(o, sName);
|
|
|
if (NULL == pObj) {
|
|
|
return NULL;
|
|
|
}
|
|
|
pObj->setAllPos(vec);
|
|
|
pObj->select(true);
|
|
|
pObj->dealSelChanged(true); //
|
|
|
pObj->update();
|
|
|
pObj->afterCreated();
|
|
|
// emit sigObjCompleted(p);
|
|
|
setModified(true);
|
|
|
return pObj;
|
|
|
}
|
|
|
|
|
|
nmObjBase* nmGuiPlot::_createOneObj(NM_Obj_Type o, QString& sName)
|
|
|
{
|
|
|
Q_ASSERT (NULL != m_pPlot);
|
|
|
// 确保名称不重复
|
|
|
QStringList listOlds;
|
|
|
for (int i = 0; i < m_pPlot->getObjCount(); i++) {
|
|
|
listOlds << m_pPlot->getObjByIndex(i)->getName();
|
|
|
}
|
|
|
sName = ZxBaseUtil::getNextOneName(listOlds, sName);
|
|
|
nmDataLogFile::getInstance()->writeLog(sName + " ------ " + QString::number(o));
|
|
|
// 创建,此处代码为了简洁,作了非规范性书写
|
|
|
nmObjBase* pObj = NULL;
|
|
|
if (o == NOT_Point) {
|
|
|
pObj = new nmObjPoint(sName, NULL, NULL);
|
|
|
} else if (o == NOT_Point_Well) {
|
|
|
pObj = new nmObjPointWell(sName, NULL, NULL);
|
|
|
} else if (o == NOT_Line) {
|
|
|
pObj = new nmObjLine(sName, NULL, NULL);
|
|
|
} else if (o == NOT_Polygon) {
|
|
|
pObj = new nmObjPolygon(sName, NULL, NULL);
|
|
|
} else if (o == NOT_PolygonOutline) {
|
|
|
pObj = new nmObjPolygonOutline(sName, NULL, NULL);
|
|
|
} else if (o == NOT_Line_Crack) {
|
|
|
pObj = new nmObjLineCrack(sName, NULL, NULL);
|
|
|
} else if (o == NOT_Line_Fault) {
|
|
|
pObj = new nmObjLineFault(sName, NULL, NULL);
|
|
|
} else {
|
|
|
zxLogRunW(tr("Type '%1' not supported.").arg((int)o));
|
|
|
nmDataLogFile::getInstance()->writeLog(tr("Type '%1' not supported.").arg((int)o));
|
|
|
return NULL;
|
|
|
}
|
|
|
Q_ASSERT (NULL != pObj);
|
|
|
bindObjSignals(pObj);
|
|
|
m_pPlot->addOneObj(pObj);
|
|
|
return pObj;
|
|
|
}
|
|
|
|
|
|
void nmGuiPlot::bindObjSignals(ZxObjBase* pObj)
|
|
|
{
|
|
|
Q_ASSERT (NULL != pObj);
|
|
|
disconnect(pObj, SIGNAL(sigObjSelectionChanged(bool)), \
|
|
|
this, SLOT(slotObjSelChanged(bool)));
|
|
|
disconnect(pObj, SIGNAL(sigPtsChanged()), \
|
|
|
this, SLOT(slotObjPtsChanged()));
|
|
|
connect(pObj, SIGNAL(sigObjSelectionChanged(bool)), \
|
|
|
this, SLOT(slotObjSelChanged(bool)));
|
|
|
connect(pObj, SIGNAL(sigPtsChanged()), \
|
|
|
this, SLOT(slotObjPtsChanged()));
|
|
|
}
|
|
|
|
|
|
// Obj选择状态改变
|
|
|
void nmGuiPlot::slotObjSelChanged(bool b)
|
|
|
{
|
|
|
ZxObjBase* p = dynamic_cast<ZxObjBase*>(sender());
|
|
|
if (NULL != p) {
|
|
|
emit sigObjSelChanged(p, b);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// Obj数据发生了改变
|
|
|
void nmGuiPlot::slotObjPtsChanged()
|
|
|
{
|
|
|
ZxObjBase* p = dynamic_cast<ZxObjBase*>(sender());
|
|
|
if (NULL != p) {
|
|
|
emit sigObjPtsChanged(p);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
void nmGuiPlot::slotDeleteWell(QString wellID)
|
|
|
{
|
|
|
nmDataLogFile::getInstance()->writeLog(wellID + " ========");
|
|
|
// 找到要删除的图片
|
|
|
nmObjPointWell* obj = (nmObjPointWell*)this->getWellObjById(wellID);
|
|
|
Q_ASSERT(obj);
|
|
|
// // 创建一个QTimer对象
|
|
|
// QTimer* timer = new QTimer();
|
|
|
// // 创建一个要执行的单次任务
|
|
|
// QObject::connect(timer, &QTimer::timeout, []() {
|
|
|
// // 这里是你想要延迟执行的代码
|
|
|
// qDebug() << "任务执行了!";
|
|
|
// });
|
|
|
// // 设置延迟时间(单位毫秒)
|
|
|
// int delay = 2000; // 例如2000毫秒(2秒)
|
|
|
// timer->setSingleShot(true); // 设置为单次触发
|
|
|
// timer->start(delay); // 开始计时,时间到后执行timeout信号关联的任务
|
|
|
// 删除结构树里的对象
|
|
|
zxCurProject->removeChild(obj->getWellData());
|
|
|
// 删除图元
|
|
|
m_pPlot->removeObjByName(obj->getName());
|
|
|
}
|
|
|
|
|
|
void nmGuiPlot::onSerialize(ZxSerializer* ser)
|
|
|
{
|
|
|
iGuiPlot::onSerialize(ser);
|
|
|
}
|
|
|
|
|
|
void nmGuiPlot::onDeserialize(ZxSerializer* ser)
|
|
|
{
|
|
|
iGuiPlot::onDeserialize(ser);
|
|
|
}
|
|
|
|
|
|
void nmGuiPlot::resetAfterDeserialized()
|
|
|
{
|
|
|
iGuiPlot::resetAfterDeserialized();
|
|
|
if (NULL == m_pPlot) {
|
|
|
return;
|
|
|
}
|
|
|
connectSignals();
|
|
|
slotChangeSizeWithChangedXY();
|
|
|
setModified(false);
|
|
|
for (int i = 0; i < m_pPlot->getObjCount(); i++) {
|
|
|
nmObjBase* pObj = (nmObjBase*)m_pPlot->getObjByIndex(i);
|
|
|
if (NULL != pObj) {
|
|
|
// 建立信号
|
|
|
bindObjSignals(pObj);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
QVector<ZxObjBase *> nmGuiPlot::getObjsByTag(QString objTag)
|
|
|
{
|
|
|
QVector<ZxObjBase *> pObjVec;
|
|
|
int objCount = m_pPlot->getObjCount();
|
|
|
for (int i = 0; i < objCount; i++) {
|
|
|
ZxObjBase* obj = m_pPlot->getObjByIndex(i);
|
|
|
if (_isSame(objTag, obj->getTagName())) {
|
|
|
pObjVec.append(obj);
|
|
|
}
|
|
|
}
|
|
|
return pObjVec;
|
|
|
}
|
|
|
|
|
|
ZxObjBase *nmGuiPlot::getWellObjById(QString id)
|
|
|
{
|
|
|
int objCount = m_pPlot->getObjCount();
|
|
|
for (int i = 0; i < objCount; i++) {
|
|
|
ZxObjBase* obj = m_pPlot->getObjByIndex(i);
|
|
|
nmDataLogFile::getInstance()->writeLog(QString::fromStdString(obj->getTagName()) + " ======");
|
|
|
if (_isSame("nObjPointWell", obj->getTagName())) {
|
|
|
nmObjPointWell* pWellPlot = (nmObjPointWell* )obj;
|
|
|
if (_isSame(id, pWellPlot->getWellID())) {
|
|
|
return pWellPlot;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
return NULL;
|
|
|
}
|
|
|
|
|
|
void nmGuiPlot::paintEvent(QPaintEvent* e)
|
|
|
{
|
|
|
iGuiPlot::paintEvent(e);
|
|
|
}
|
|
|
|
|
|
#ifdef QT_DEBUG
|
|
|
|
|
|
ZxObjBase* nmGuiPlot::updatePlotObjBy(QString sName, \
|
|
|
VecFloat& vecX, VecFloat& vecY, \
|
|
|
bool bPressureLike /*= true*/, \
|
|
|
bool bUseY2 /*= false*/, \
|
|
|
bool bClearAll /*= false*/)
|
|
|
{
|
|
|
if (vecX.count() < 2 || vecX.count() != vecY.count()) {
|
|
|
return NULL;
|
|
|
}
|
|
|
ZxPlot* pPlot = m_pPlot;
|
|
|
Q_ASSERT (NULL != pPlot);
|
|
|
// 移除先前图上已经有的曲线
|
|
|
int n = pPlot->getObjCount();
|
|
|
for (int i = n - 1; i >= 0; i--) {
|
|
|
ZxObjBase* pObj = pPlot->getObjByIndex(i);
|
|
|
if (NULL == pObj) {
|
|
|
continue;
|
|
|
}
|
|
|
if (bClearAll) {
|
|
|
pPlot->removeObjByIndex(i);
|
|
|
} else if (_isSame(sName, pObj->getName())) {
|
|
|
pPlot->removeObjByIndex(i);
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
ZxObjCurve* pObj = NULL;
|
|
|
if (bPressureLike) {
|
|
|
pObj = appendSeriesP(vecX, vecY, sName, bUseY2);
|
|
|
} else {
|
|
|
pObj = appendSeriesF(vecX, vecY, sName, bUseY2);
|
|
|
}
|
|
|
if (NULL != pObj) {
|
|
|
setPenAndDot(pObj, !bPressureLike);
|
|
|
bindObjSignals(pObj);
|
|
|
}
|
|
|
return pObj;
|
|
|
}
|
|
|
|
|
|
#endif
|