|
|
|
|
|
#include <QPainter>
|
|
|
|
|
|
|
|
|
|
|
|
#include <ZxSerializer.h>
|
|
|
|
|
|
#include "IxPtyPano.h"
|
|
|
|
|
|
|
|
|
|
|
|
#include "ZxSubAxisX.h"
|
|
|
|
|
|
#include "ZxSubAxisY.h"
|
|
|
|
|
|
|
|
|
|
|
|
#include "nmObjPolygonOutlineTool.h"
|
|
|
|
|
|
#include "nmObjPolygonOutline.h"
|
|
|
|
|
|
|
|
|
|
|
|
#include "nmPlotGraphicBinder.h"
|
|
|
|
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
|
|
|
|
// 识别只插入一个节点且原点序不变的整组更新;不把拖动或整组替换误认为插点。
|
|
|
|
|
|
// 返回新节点下标,失败返回 -1;交换参数后也可识别单节点删除。
|
|
|
|
|
|
int findInsertedPoint(const QVector<QPointF>& before, const QVector<QPointF>& after)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (after.count() != before.count() + 1) return -1;
|
|
|
|
|
|
int index = 0;
|
|
|
|
|
|
while (index < before.count() && before[index] == after[index]) ++index;
|
|
|
|
|
|
for (int i = index; i < before.count(); ++i) {
|
|
|
|
|
|
if (before[i] != after[i + 1]) return -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
return index;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
|
|
|
|
ZX_DEFINE_DYNAMIC(nObjPolygonOutline, nmObjPolygonOutline)
|
|
|
|
|
|
|
|
|
|
|
|
nmObjPolygonOutline::nmObjPolygonOutline()
|
|
|
|
|
|
{
|
|
|
|
|
|
m_sObjTag = "nObjPolygonOutline";
|
|
|
|
|
|
m_pGraphicBinder = nullptr;
|
|
|
|
|
|
nmObjPolygonOutline::init("", NULL, NULL);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nmObjPolygonOutline::nmObjPolygonOutline(const QString& sName, \
|
|
|
|
|
|
ZxSubAxisX* pAxisX, \
|
|
|
|
|
|
ZxSubAxisY* pAxisY)
|
|
|
|
|
|
{
|
|
|
|
|
|
m_sObjTag = "nObjPolygonOutline";
|
|
|
|
|
|
m_pGraphicBinder = nullptr;
|
|
|
|
|
|
nmObjPolygonOutline::init(sName, pAxisX, pAxisY);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nmObjPolygonOutline::~nmObjPolygonOutline()
|
|
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void nmObjPolygonOutline::init(const QString& sName, \
|
|
|
|
|
|
ZxSubAxisX* pAxisX, \
|
|
|
|
|
|
ZxSubAxisY* pAxisY)
|
|
|
|
|
|
{
|
|
|
|
|
|
nmObjPolygon::init(sName, pAxisX, pAxisY);
|
|
|
|
|
|
m_pGraphicBinder = nullptr;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void nmObjPolygonOutline::initTools()
|
|
|
|
|
|
{
|
|
|
|
|
|
m_pTool = new nmObjPolygonOutlineTool();
|
|
|
|
|
|
nmObjBase::initTools();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool nmObjPolygonOutline::hitTest(const QPointF& pt)
|
|
|
|
|
|
{
|
|
|
|
|
|
return nmObjPolygon::hitTest(pt);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool nmObjPolygonOutline::_runHitTest(const QPointF& pt, int& nOption, int& nSubIndex)
|
|
|
|
|
|
{
|
|
|
|
|
|
return nmObjPolygon::_runHitTest(pt, nOption, nSubIndex);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool nmObjPolygonOutline::runMove(const QPointF& pt1,
|
|
|
|
|
|
const QPointF& pt2)
|
|
|
|
|
|
{
|
|
|
|
|
|
return nmObjPolygon::runMove(pt1, pt2);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void nmObjPolygonOutline::fillPtyPano(IxPtyPano* sheet)
|
|
|
|
|
|
{
|
|
|
|
|
|
nmObjPolygon::fillPtyPano(sheet);
|
|
|
|
|
|
// TODO,设置边界类型的
|
|
|
|
|
|
IxPtyItem* pProp = ZX_PROP("ObjPolygonOutline.Type", getCurOutlineFlowType, setCurOutlineFlowType);
|
|
|
|
|
|
|
|
|
|
|
|
if(NULL != pProp) {
|
|
|
|
|
|
QStringList listTags;
|
|
|
|
|
|
listTags << tr("No Flow") << tr("Constant Pressure");
|
|
|
|
|
|
QList<QVariant> listIndexes;
|
|
|
|
|
|
listIndexes << 0 << 1;
|
|
|
|
|
|
pProp->getPtyPano();
|
|
|
|
|
|
pProp->setOptions(listTags, listIndexes);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void nmObjPolygonOutline::onSerialize(ZxSerializer* ser)
|
|
|
|
|
|
{
|
|
|
|
|
|
nmObjPolygon::onSerialize(ser);
|
|
|
|
|
|
ser->write("FlowTypeList", m_vFlowTypeList);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void nmObjPolygonOutline::onDeserialize(ZxSerializer* ser)
|
|
|
|
|
|
{
|
|
|
|
|
|
nmObjPolygon::onDeserialize(ser);
|
|
|
|
|
|
ser->read("FlowTypeList", m_vFlowTypeList);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void nmObjPolygonOutline::onSaveTempl(ZxSerializer* ser)
|
|
|
|
|
|
{
|
|
|
|
|
|
nmObjPolygon::onSaveTempl(ser);
|
|
|
|
|
|
ser->write("FlowTypeList", m_vFlowTypeList);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void nmObjPolygonOutline::setAllPos(QVector<QPointF> vecPoss, QVector<int>* pVecIndexes)
|
|
|
|
|
|
{
|
|
|
|
|
|
const QVector<QPointF> oldPoints = getAllPos();
|
|
|
|
|
|
const int oldCount = oldPoints.count();
|
|
|
|
|
|
const int defaultType = NM_OIL_RESERVOIR_OUTLINE_TYPE::OIL_Reservoir_Outline_No_Flow;
|
|
|
|
|
|
|
|
|
|
|
|
// 每个类型对应“当前顶点 -> 下一顶点”的边,先补齐旧数据可能缺少的条目。
|
|
|
|
|
|
while (m_vFlowTypeList.count() < oldCount) m_vFlowTypeList.append(defaultType);
|
|
|
|
|
|
if (oldCount > 0 && m_vFlowTypeList.count() > oldCount) m_vFlowTypeList.resize(oldCount);
|
|
|
|
|
|
|
|
|
|
|
|
if (pVecIndexes == nullptr && oldCount > 0) {
|
|
|
|
|
|
const int insertedIndex = findInsertedPoint(oldPoints, vecPoss);
|
|
|
|
|
|
const int removedIndex = findInsertedPoint(vecPoss, oldPoints);
|
|
|
|
|
|
if (insertedIndex >= 0) {
|
|
|
|
|
|
// 拆开一条边时,两段都继承原边类型;也覆盖最后一条闭合边。
|
|
|
|
|
|
const int splitType = m_vFlowTypeList[(insertedIndex + oldCount - 1) % oldCount];
|
|
|
|
|
|
m_vFlowTypeList.insert(insertedIndex, splitType);
|
|
|
|
|
|
} else if (removedIndex >= 0) {
|
|
|
|
|
|
// 合并时保留前一条边的类型,其余边仍与原顶点对应。
|
|
|
|
|
|
m_vFlowTypeList.remove(removedIndex);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nmObjPolygon::setAllPos(vecPoss, pVecIndexes);
|
|
|
|
|
|
// 局部坐标更新的参数只含被改节点,必须按图元最终总点数维护边类型。
|
|
|
|
|
|
const int pointCount = getAllPos().count();
|
|
|
|
|
|
while (m_vFlowTypeList.count() < pointCount) m_vFlowTypeList.append(defaultType);
|
|
|
|
|
|
if (m_vFlowTypeList.count() > pointCount) m_vFlowTypeList.resize(pointCount);
|
|
|
|
|
|
emit sigOutlinePointsChanged();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void nmObjPolygonOutline::onLoadTempl(ZxSerializer* ser)
|
|
|
|
|
|
{
|
|
|
|
|
|
nmObjPolygon::onLoadTempl(ser);
|
|
|
|
|
|
ser->read("FlowTypeList", m_vFlowTypeList);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void nmObjPolygonOutline::paintBack(QPainter* painter, const ZxPaintParam& param)
|
|
|
|
|
|
{
|
|
|
|
|
|
// 基类统一绘制轮廓和固定像素节点框,派生类只补充当前边的高亮。
|
|
|
|
|
|
const QRectF plotRect = getOuterRect();
|
|
|
|
|
|
painter->save();
|
|
|
|
|
|
painter->setClipRect(plotRect, Qt::IntersectClip);
|
|
|
|
|
|
nmObjPolygon::paintBack(painter, param);
|
|
|
|
|
|
painter->restore();
|
|
|
|
|
|
|
|
|
|
|
|
// 名称同步:setName 不发信号,在绘制时通过 Binder 同步到数据中心。
|
|
|
|
|
|
if (m_pGraphicBinder) {
|
|
|
|
|
|
m_pGraphicBinder->syncOutlineName(this);
|
|
|
|
|
|
m_pGraphicBinder->syncOutlineVisual(this);
|
|
|
|
|
|
}
|
|
|
|
|
|
if (!isSelected() || m_oHitOption != OHO_Bound ||
|
|
|
|
|
|
m_pAxisX == nullptr || m_pAxisY == nullptr ||
|
|
|
|
|
|
m_pAxisX->getRangeMin() == m_pAxisX->getRangeMax() ||
|
|
|
|
|
|
m_pAxisY->getRangeMin() == m_pAxisY->getRangeMax()) return;
|
|
|
|
|
|
|
|
|
|
|
|
const QVector<QPointF> points = getAllPos();
|
|
|
|
|
|
if (points.count() < 2 || m_nHitIndex < 0 || m_nHitIndex >= points.count()) return;
|
|
|
|
|
|
|
|
|
|
|
|
painter->save();
|
|
|
|
|
|
painter->setClipRect(plotRect, Qt::IntersectClip);
|
|
|
|
|
|
QPen pen(Qt::green);
|
|
|
|
|
|
pen.setWidth(0); // 使用屏幕细线,缩放时不遮住节点框。
|
|
|
|
|
|
painter->setPen(pen);
|
|
|
|
|
|
painter->drawLine(points[m_nHitIndex], points[(m_nHitIndex + 1) % points.count()]);
|
|
|
|
|
|
painter->restore();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void nmObjPolygonOutline::setCurOutlineFlowType(int flowType)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (m_oHitOption == OHO_Bound && m_nHitIndex >= 0 &&
|
|
|
|
|
|
m_nHitIndex < m_vFlowTypeList.count()) {
|
|
|
|
|
|
m_vFlowTypeList[m_nHitIndex] = flowType;
|
|
|
|
|
|
emit sigOutlineFlowTypeChanged();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int nmObjPolygonOutline::getCurOutlineFlowType()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (m_oHitOption == OHO_Bound && m_nHitIndex >= 0 &&
|
|
|
|
|
|
m_nHitIndex < m_vFlowTypeList.count()) {
|
|
|
|
|
|
return m_vFlowTypeList[m_nHitIndex];
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return (int)NM_OIL_RESERVOIR_OUTLINE_TYPE::OIL_Reservoir_Outline_UNKNOW;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void nmObjPolygonOutline::afterCreated() {
|
|
|
|
|
|
if (m_pGraphicBinder) {
|
|
|
|
|
|
m_pGraphicBinder->createOutlineForGraphic(this);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void nmObjPolygonOutline::removeData() {
|
|
|
|
|
|
if (m_pGraphicBinder) {
|
|
|
|
|
|
m_pGraphicBinder->removeOutlineBinding(this);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|