|
|
|
|
@ -1,6 +1,8 @@
|
|
|
|
|
#include "ZxBaseUtil.h"
|
|
|
|
|
#include "zxLogInstance.h"
|
|
|
|
|
#include <QLineF>
|
|
|
|
|
#include <QWidget>
|
|
|
|
|
#include <QtCore/qnumeric.h>
|
|
|
|
|
|
|
|
|
|
#include "ZxPlot.h"
|
|
|
|
|
#include "ZxSubAxisX.h"
|
|
|
|
|
@ -283,11 +285,8 @@ bool nmGuiPlotCmdHelper::runAction(QString sAction) {
|
|
|
|
|
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);
|
|
|
|
|
pMeasureTool->beginCreationCursor();
|
|
|
|
|
return true;
|
|
|
|
|
} else if (_isSame(sAction, "nmDeleteOneObj")) {
|
|
|
|
|
nmObjToolBase* pObjTool = new nmObjDeleteTool(pPlot);
|
|
|
|
|
@ -359,13 +358,17 @@ void nmGuiPlotCmdHelper::slotObjPtsFinished(QVector<QPointF>& vec) {
|
|
|
|
|
ZxPlot* pPlot = pWxPlot->m_pPlot;
|
|
|
|
|
Q_ASSERT (NULL != pPlot);
|
|
|
|
|
|
|
|
|
|
// 如果不为测量工具则移除
|
|
|
|
|
if (pTool->getNOT() != NMOT_Line_Measure) {
|
|
|
|
|
pTool->resetInteractionCursor();
|
|
|
|
|
pPlot->removeTools(pTool);
|
|
|
|
|
// 从活跃 map 里清除它
|
|
|
|
|
m_activeTools.remove(pTool->getNOT());
|
|
|
|
|
// 连续测量保留工具。已退出的工具不能通过延迟到达的松手事件提交。
|
|
|
|
|
const NM_Obj_Type type = pTool->getNOT();
|
|
|
|
|
if (type == NMOT_Line_Measure) {
|
|
|
|
|
if (m_activeTools.value(type, nullptr) == pTool) {
|
|
|
|
|
commitMeasure(pWxPlot, vec);
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
pTool->resetInteractionCursor();
|
|
|
|
|
pPlot->removeTools(pTool);
|
|
|
|
|
m_activeTools.remove(type);
|
|
|
|
|
|
|
|
|
|
QString sName = tr("nmObj"); // 默认名称
|
|
|
|
|
|
|
|
|
|
@ -386,8 +389,6 @@ void nmGuiPlotCmdHelper::slotObjPtsFinished(QVector<QPointF>& vec) {
|
|
|
|
|
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) {
|
|
|
|
|
@ -448,14 +449,6 @@ void nmGuiPlotCmdHelper::slotObjPtsFinished(QVector<QPointF>& vec) {
|
|
|
|
|
binder->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();
|
|
|
|
|
@ -484,6 +477,44 @@ void nmGuiPlotCmdHelper::slotObjPtsFinished(QVector<QPointF>& vec) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void nmGuiPlotCmdHelper::commitMeasure(nmGuiPlot* plot, QVector<QPointF>& points)
|
|
|
|
|
{
|
|
|
|
|
ZxPlot* chart = plot->m_pPlot;
|
|
|
|
|
nmPlotGraphicBinder* binder = plot->graphicBinder();
|
|
|
|
|
if (chart == nullptr || binder == nullptr || plot->boundDataManager() == nullptr ||
|
|
|
|
|
points.count() != 2) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const ZxSubAxisX* axisX = chart->getMainAxisX();
|
|
|
|
|
const ZxSubAxisY* axisY = chart->getMainAxisY();
|
|
|
|
|
if (axisX == nullptr || axisY == nullptr ||
|
|
|
|
|
axisX->getRangeMin() == axisX->getRangeMax() ||
|
|
|
|
|
axisY->getRangeMin() == axisY->getRangeMax()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 首次单击仍可选取拟合参考点。已有测量时,只允许有效线段替换。
|
|
|
|
|
const bool singlePoint = points[0] == points[1];
|
|
|
|
|
if (singlePoint && !plot->getObjsByTag("nObjLineMeasure").isEmpty()) return;
|
|
|
|
|
|
|
|
|
|
const QVector<QPointF> values = chart->getValueForPos(points);
|
|
|
|
|
if (values.count() != 2) return;
|
|
|
|
|
const qreal length = QLineF(values[0], values[1]).length();
|
|
|
|
|
if (!qIsFinite(length) || (!singlePoint && length <= 0.0)) return;
|
|
|
|
|
|
|
|
|
|
QString name = tr("Measure");
|
|
|
|
|
nmObjLineMeasure* measure = static_cast<nmObjLineMeasure*>(
|
|
|
|
|
plot->appendOneObj(NMOT_Line_Measure, name, points));
|
|
|
|
|
if (measure == nullptr) return;
|
|
|
|
|
|
|
|
|
|
// 新线已创建,先断开旧线绑定,再写入供面板监听的同一个数据对象。
|
|
|
|
|
plot->removeMeasureGraphics(measure);
|
|
|
|
|
measure->afterCreated();
|
|
|
|
|
binder->createMeasureForGraphic(measure);
|
|
|
|
|
emit sigMeasureCommitted();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void nmGuiPlotCmdHelper::finishMeasure()
|
|
|
|
|
{
|
|
|
|
|
nmGuiPlot* pWxPlot = dynamic_cast<nmGuiPlot*>(m_pGuiPlot);
|
|
|
|
|
@ -493,8 +524,10 @@ void nmGuiPlotCmdHelper::finishMeasure()
|
|
|
|
|
|
|
|
|
|
nmObjToolBase* pMeasureTool = m_activeTools.value(NMOT_Line_Measure, nullptr);
|
|
|
|
|
if(pMeasureTool) {
|
|
|
|
|
pWxPlot->m_pPlot->removeTools(pMeasureTool);
|
|
|
|
|
m_activeTools.remove(NMOT_Line_Measure);
|
|
|
|
|
pMeasureTool->cancelInteraction();
|
|
|
|
|
pMeasureTool->resetInteractionCursor();
|
|
|
|
|
pWxPlot->m_pPlot->removeTools(pMeasureTool);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pWxPlot->deleteMeasureObjects();
|
|
|
|
|
|