|
|
|
|
#include <QPainter>
|
|
|
|
|
|
|
|
|
|
#include <ZxSerializer.h>
|
|
|
|
|
#include "IxPtyPano.h"
|
|
|
|
|
#include "ZxBaseUtil.h"
|
|
|
|
|
#include "ZxSubAxisX.h"
|
|
|
|
|
#include "ZxSubAxisY.h"
|
|
|
|
|
|
|
|
|
|
#include "nmObjLineTool.h"
|
|
|
|
|
#include "ZxPlot.h"
|
|
|
|
|
#include "ZxObjText.h"
|
|
|
|
|
|
|
|
|
|
#include "nmObjLine.h"
|
|
|
|
|
|
|
|
|
|
ZX_DEFINE_DYNAMIC(nObjLine, nmObjLine)
|
|
|
|
|
|
|
|
|
|
nmObjLine::nmObjLine()
|
|
|
|
|
{
|
|
|
|
|
m_sObjTag = "nObjLine";
|
|
|
|
|
nmObjLine("", NULL, NULL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nmObjLine::nmObjLine(const QString& sName, \
|
|
|
|
|
ZxSubAxisX* pAxisX, \
|
|
|
|
|
ZxSubAxisY* pAxisY)
|
|
|
|
|
: nmObjPoint(sName, pAxisX, pAxisY)
|
|
|
|
|
{
|
|
|
|
|
m_sObjTag = "nObjLine";
|
|
|
|
|
initFlags();
|
|
|
|
|
m_oDot = ZxDot(DTS_Circle, QColor(0, 255, 0), 0.5f, true);
|
|
|
|
|
m_oPen = QPen(QBrush(QColor(0, 255, 164)), \
|
|
|
|
|
0.5f, Qt::SolidLine);
|
|
|
|
|
m_vecPoints.clear();
|
|
|
|
|
m_vecPoints << QPointF(0.f, 0.f) << QPointF(0.f, 0.f);
|
|
|
|
|
loadTempl();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nmObjLine::~nmObjLine()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void nmObjLine::initTools()
|
|
|
|
|
{
|
|
|
|
|
m_pTool = new nmObjLineTool();
|
|
|
|
|
ZxObjBase::initTools();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void nmObjLine::initSubObjs()
|
|
|
|
|
{
|
|
|
|
|
nmObjPoint::initSubObjs();
|
|
|
|
|
setPointTag(tr("Line"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool nmObjLine::_runHitTest(const QPointF& pt, int& nOption, int& nSubIndex)
|
|
|
|
|
{
|
|
|
|
|
if (!ZxObjBase::_runHitTest(pt, nOption, nSubIndex)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
nOption = -1;
|
|
|
|
|
nSubIndex = 0;
|
|
|
|
|
float fDis = (2 + m_oPen.widthF() / 2);
|
|
|
|
|
QPointF ptStart = getPosOf(m_vecPoints[0]);
|
|
|
|
|
QRectF rtStart(ptStart.x() - fDis,
|
|
|
|
|
ptStart.y() - fDis,
|
|
|
|
|
2 * fDis,
|
|
|
|
|
2 * fDis);
|
|
|
|
|
QPointF ptEnd = getPosOf(m_vecPoints[1]);
|
|
|
|
|
QRectF rtEnd(ptEnd.x() - fDis,
|
|
|
|
|
ptEnd.y() - fDis,
|
|
|
|
|
2 * fDis,
|
|
|
|
|
2 * fDis);
|
|
|
|
|
if (rtStart.contains(pt)) {
|
|
|
|
|
nOption = (int)OHO_Point;
|
|
|
|
|
nSubIndex = 0;
|
|
|
|
|
return true;
|
|
|
|
|
} else if (rtEnd.contains(pt)) {
|
|
|
|
|
nOption = (int)OHO_Point;
|
|
|
|
|
nSubIndex = 1;
|
|
|
|
|
return true;
|
|
|
|
|
} else if (_isNearLine(pt, ptStart, ptEnd, 1.f * 3)) {
|
|
|
|
|
nOption = (int)OHO_Bound;
|
|
|
|
|
nSubIndex = 0;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
nOption = (int)OHO_None;
|
|
|
|
|
nSubIndex = -1;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool nmObjLine::hitTest(const QPointF& pt)
|
|
|
|
|
{
|
|
|
|
|
if (!ZxObjBase::hitTest(pt)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool nmObjLine::runMove(const QPointF& pt1,
|
|
|
|
|
const QPointF& pt2)
|
|
|
|
|
{
|
|
|
|
|
if (isLockPos()) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if (m_oHitOption != OHO_Bound && m_oHitOption != OHO_Point) {
|
|
|
|
|
m_oHitOption = OHO_None;
|
|
|
|
|
m_nHitIndex = -1;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
QPointF ptStart = getPosOf(m_vecPoints[0]);
|
|
|
|
|
QPointF ptEnd = getPosOf(m_vecPoints[1]);
|
|
|
|
|
ptStart = offsetPoint(ptStart, pt1, pt2);
|
|
|
|
|
ptEnd = offsetPoint(ptEnd, pt1, pt2);
|
|
|
|
|
QVector<QPointF> vec = getAllPos();
|
|
|
|
|
if (m_oHitOption == OHO_Point && m_nHitIndex == 0) {
|
|
|
|
|
vec[0] = ptStart;
|
|
|
|
|
} else if (m_oHitOption == OHO_Point && m_nHitIndex == 1) {
|
|
|
|
|
vec[1] = ptEnd;
|
|
|
|
|
} else if (m_oHitOption == OHO_Bound) {
|
|
|
|
|
vec[0] = ptStart;
|
|
|
|
|
vec[1] = ptEnd;
|
|
|
|
|
m_fOffsetX = pt2.x() - pt1.x();
|
|
|
|
|
m_fOffsetY = pt2.y() - pt1.y();
|
|
|
|
|
} else {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return moveToPos(vec);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void nmObjLine::paintBack(QPainter* painter, const ZxPaintParam& param)
|
|
|
|
|
{
|
|
|
|
|
Q_ASSERT (m_vecPoints.count() >= 2);
|
|
|
|
|
QPointF pt1 = getPosOf(m_vecPoints[0]);
|
|
|
|
|
QPointF pt2 = getPosOf(m_vecPoints[1]);
|
|
|
|
|
QLineF oLine = QLineF(pt1, pt2);
|
|
|
|
|
if (!drawLine(painter, oLine)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
drawSelStates(painter, oLine);
|
|
|
|
|
QPointF pt = oLine.pointAt(0.5f);
|
|
|
|
|
drawWellPos(painter, pt);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool nmObjLine::drawLine(QPainter* painter, QLineF& oLine)
|
|
|
|
|
{
|
|
|
|
|
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);
|
|
|
|
|
QPen pen = m_oPen;
|
|
|
|
|
painter->setPen(pen);
|
|
|
|
|
painter->drawLine(oLine);
|
|
|
|
|
painter->restore();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool nmObjLine::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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool nmObjLine::drawWellPos(QPainter* painter, QPointF pt)
|
|
|
|
|
{
|
|
|
|
|
return nmObjPoint::drawWellPos(painter, pt);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void nmObjLine::onSerialize(ZxSerializer* ser)
|
|
|
|
|
{
|
|
|
|
|
nmObjPoint::onSerialize(ser);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void nmObjLine::onDeserialize(ZxSerializer* ser)
|
|
|
|
|
{
|
|
|
|
|
nmObjPoint::onDeserialize(ser);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void nmObjLine::onSaveTempl(ZxSerializer* ser)
|
|
|
|
|
{
|
|
|
|
|
nmObjPoint::onSaveTempl(ser);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void nmObjLine::onLoadTempl(ZxSerializer* ser)
|
|
|
|
|
{
|
|
|
|
|
nmObjPoint::onLoadTempl(ser);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void nmObjLine::fillPtyPano(IxPtyPano* sheet)
|
|
|
|
|
{
|
|
|
|
|
nmObjPoint::fillPtyPano(sheet);
|
|
|
|
|
ZX_PROP("WmLine.Pen", getPen, setPen);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QPointF nmObjLine::getCenterPos()
|
|
|
|
|
{
|
|
|
|
|
QVector<QPointF> vec = getAllPos();
|
|
|
|
|
Q_ASSERT (vec.count() >= 2);
|
|
|
|
|
QLineF oLine = QLineF(vec[0], vec[1]);
|
|
|
|
|
return oLine.pointAt(0.5f);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void nmObjLine::resetBounds()
|
|
|
|
|
{
|
|
|
|
|
QPointF pt1 = getPosOf(m_vecPoints[0]);
|
|
|
|
|
QRectF rcClient(pt1.x() - (2 + m_oPen.widthF() / 2.0), \
|
|
|
|
|
pt1.y() - (2 + m_oPen.widthF() / 2.0), \
|
|
|
|
|
4 + m_oPen.widthF(), 4 + m_oPen.widthF());
|
|
|
|
|
setBounds(rcClient);
|
|
|
|
|
m_rtBoundVs = calValueBounds();
|
|
|
|
|
resetOthers();
|
|
|
|
|
}
|