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/nmObjLineMeasure.cpp

161 lines
4.2 KiB
C++

#include <QPainter>
#include <ZxSerializer.h>
#include "IxPtyPano.h"
#include "ZxBaseUtil.h"
#include "ZxSubAxisX.h"
#include "ZxSubAxisY.h"
#include "nmObjLineMeasureTool.h"
#include "ZxPlot.h"
#include "ZxObjText.h"
#include "nmObjLineMeasure.h"
#include "nmDataAnalyzeManager.h"
#include "nmDataMeasure.h"
ZX_DEFINE_DYNAMIC(nObjLineMeasure, nmObjLineMeasure)
nmObjLineMeasure::nmObjLineMeasure()
: nmObjLine("", NULL, NULL)
{
m_dLength = 0.0;
m_pMeasureData = nmDataAnalyzeManager::getCurrentInstance()->getMeasureData();
m_sObjTag = "nObjLineMeasure";
nmObjPoint::initFlags();
m_oDot = ZxDot(DTS_Circle, QColor(255, 165, 0), 0.5f, true);
m_oPen = QPen(QBrush(QColor(255, 165, 0)), 0.5f, Qt::SolidLine);
m_vecPoints.clear();
m_vecPoints << QPointF(0.f, 0.f) << QPointF(0.f, 0.f);
loadTempl();
}
nmObjLineMeasure::nmObjLineMeasure(const QString& sName, \
ZxSubAxisX* pAxisX, \
ZxSubAxisY* pAxisY)
: nmObjLine(sName, pAxisX, pAxisY) {
m_dLength = 0.0;
m_pMeasureData = nmDataAnalyzeManager::getCurrentInstance()->getMeasureData();
m_sObjTag = "nObjLineMeasure";
nmObjPoint::initFlags();
m_oDot = ZxDot(DTS_Circle, QColor(255, 165, 0), 0.5f, true);
m_oPen = QPen(QBrush(QColor(255, 165, 0)), 0.5f, Qt::SolidLine);
m_vecPoints.clear();
m_vecPoints << QPointF(0.f, 0.f) << QPointF(0.f, 0.f);
loadTempl();
}
nmObjLineMeasure::~nmObjLineMeasure() {
}
void nmObjLineMeasure::initTools() {
m_pTool = new nmObjLineMeasureTool();
ZxObjBase::initTools();
}
void nmObjLineMeasure::initSubObjs() {
nmObjBase::initSubObjs();
}
void nmObjLineMeasure::paintBack(QPainter* painter, const ZxPaintParam& param) {
Q_ASSERT(m_vecPoints.count() >= 2);
m_vecPoints[0] = m_pMeasureData->getStartPoint();
m_vecPoints[1] = m_pMeasureData->getEndPoint();
QPointF pt1 = getPosOf(m_vecPoints[0]);
QPointF pt2 = getPosOf(m_vecPoints[1]);
QLineF oLine = QLineF(pt1, pt2);
if(!this->drawLine(painter, oLine)) {
return;
}
drawSelStates(painter, oLine);
QPointF pt = oLine.pointAt(0.5f);
drawWellPos(painter, pt);
}
bool nmObjLineMeasure::drawSelStates(QPainter* painter, QLineF& oLine) {
if(!isSelected()) {
return true;
}
Q_ASSERT(NULL != m_pAxisX);
Q_ASSERT(NULL != m_pAxisY);
if(m_pAxisX->getRangeMin() == m_pAxisX->getRangeMax() || \
m_pAxisY->getRangeMin() == m_pAxisY->getRangeMax()) {
return false;
}
painter->save();
QRectF rt = getOuterRect();
painter->setClipRect(rt);
QPointF pt1 = oLine.p1();
QPointF pt2 = oLine.p2();
QVector<QPointF> pts;
pts << pt1 << pt2;
for(int i = 0; i < pts.count(); i++) {
float w = 1.2f;
QPointF pt = pts[i];
QRectF rect(pt.x() - w * 0.5f, pt.y() - w * 0.5f, w, w);
if(m_nHitIndex == i && m_oHitOption == OHO_Point) {
QBrush br(Qt::red);
painter->fillRect(rect, br);
} else {
painter->setPen(QColor(0, 0, 128));
painter->drawRect(rect);
}
}
painter->restore();
return true;
}
void nmObjLineMeasure::afterCreated() {
// <20><><EFBFBD><EFBFBD><E3B3A4>
QPointF pStart = m_vecPoints[0];
QPointF pEnd = m_vecPoints[1];
double dLength = QLineF(pStart, pEnd).length();
if (m_pMeasureData != nullptr && pEnd != pStart) {
m_pMeasureData->setStartPoint(pStart);
m_pMeasureData->setEndPoint(pEnd);
nmDataAttribute lenAttr = m_pMeasureData->getLength();
lenAttr.setValue(dLength);
m_pMeasureData->setLength(lenAttr);
}
if (m_pMeasureData != nullptr && pEnd == pStart) {
m_pMeasureData->setCurrentPoint(pStart);
nmDataAttribute lenAttr = m_pMeasureData->getLength();
lenAttr.setValue(dLength);
m_pMeasureData->setLength(lenAttr);
}
this->setLockPos(true);
this->setReadOnly(true);
}
void nmObjLineMeasure::onSerialize(ZxSerializer* ser) {
nmObjLine::onSerialize(ser);
ser->write("Length", m_dLength);
}
void nmObjLineMeasure::onDeserialize(ZxSerializer* ser) {
nmObjLine::onDeserialize(ser);
ser->read("Length", m_dLength);
}
void nmObjLineMeasure::onSaveTempl(ZxSerializer* ser) {
nmObjLine::onSaveTempl(ser);
ser->write("Length", m_dLength);
}
void nmObjLineMeasure::onLoadTempl(ZxSerializer* ser) {
nmObjLine::onLoadTempl(ser);
ser->read("Length", m_dLength);
}
void nmObjLineMeasure::fillPtyPano(IxPtyPano* sheet) {
nmObjLine::fillPtyPano(sheet);
}