|
|
#include <QPainter>
|
|
|
|
|
|
#include "nmObjRegionMark.h"
|
|
|
#include "nmObjRegionMarkTool.h"
|
|
|
#include "nmObjRegion.h"
|
|
|
|
|
|
#include "ZxSerializer.h"
|
|
|
#include "IxPtyPano.h"
|
|
|
|
|
|
#include "ZxSubAxisX.h"
|
|
|
#include "ZxSubAxisY.h"
|
|
|
|
|
|
#include "nmObjRegion.h"
|
|
|
#include "nmObjRegionTool.h"
|
|
|
|
|
|
#include "ZxBaseUtil.h"
|
|
|
#include "ZxPlot.h"
|
|
|
#include "ZxRenderView.h"
|
|
|
#include <QtCore/qnumeric.h>
|
|
|
|
|
|
#include "nmPlotGraphicBinder.h"
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
// 返回以锚点 ptPos 为中心的图标范围;坐标与画布绘制使用同一坐标系。
|
|
|
QRectF regionMarkIconRect(const QPointF& ptPos)
|
|
|
{
|
|
|
const double iconSize = 6.0;
|
|
|
return QRectF(ptPos.x() - iconSize / 2, ptPos.y() - iconSize / 2,
|
|
|
iconSize, iconSize);
|
|
|
}
|
|
|
|
|
|
// 返回图标正上方、水平居中的名称范围;绘制和包围框计算共用此布局。
|
|
|
QRectF regionMarkTextRect(const QPointF& ptPos)
|
|
|
{
|
|
|
const QRectF iconRect = regionMarkIconRect(ptPos);
|
|
|
const double textWidth = 100.0;
|
|
|
return QRectF(ptPos.x() - textWidth / 2, iconRect.top() - iconRect.height(),
|
|
|
textWidth, iconRect.height());
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
ZX_DEFINE_DYNAMIC(nObjRegionMark, nmObjRegionMark)
|
|
|
|
|
|
nmObjRegionMark::nmObjRegionMark()
|
|
|
: m_bSelectRegion(false)
|
|
|
, m_iColorIndex(0)
|
|
|
, m_reservoirType(0)
|
|
|
, m_comKr(1.0)
|
|
|
, m_comW(1.0)
|
|
|
, m_netToGross(1.0)
|
|
|
, m_pGraphicBinder(nullptr)
|
|
|
{
|
|
|
m_sObjTag = "nObjRegionMark";
|
|
|
nmObjRegionMark::init("", NULL, NULL);
|
|
|
|
|
|
}
|
|
|
|
|
|
nmObjRegionMark::nmObjRegionMark(const QString& sName, \
|
|
|
ZxSubAxisX* pAxisX, \
|
|
|
ZxSubAxisY* pAxisY, \
|
|
|
int RegionMarkCount)
|
|
|
: m_bSelectRegion(false)
|
|
|
, m_iColorIndex(RegionMarkCount)
|
|
|
, m_reservoirType(0)
|
|
|
, m_comKr(1.0)
|
|
|
, m_comW(1.0)
|
|
|
, m_netToGross(1.0)
|
|
|
, m_pGraphicBinder(nullptr)
|
|
|
{
|
|
|
m_sObjTag = "nObjRegionMark";
|
|
|
nmObjRegionMark::init(sName, pAxisX, pAxisY);
|
|
|
this->m_iColorIndex = RegionMarkCount;
|
|
|
m_clrBackgrd = generateColor(m_iColorIndex);
|
|
|
}
|
|
|
|
|
|
nmObjRegionMark::~nmObjRegionMark()
|
|
|
{
|
|
|
}
|
|
|
|
|
|
QColor nmObjRegionMark::generateColor(int index)
|
|
|
{
|
|
|
int hue = (index % 6) * 60; // 色相,每6个标记循环一次,每次加60度
|
|
|
int saturation = 255; // 饱和度,最大值
|
|
|
int value = 255; // 亮度,最大值
|
|
|
int alpha = 128; // 透明度,半透明,可根据需要调整
|
|
|
|
|
|
return QColor::fromHsv(hue, saturation, value, alpha); // 返回带透明度的颜色
|
|
|
}
|
|
|
|
|
|
void nmObjRegionMark::init(const QString& sName, \
|
|
|
ZxSubAxisX* pAxisX, \
|
|
|
ZxSubAxisY* pAxisY)
|
|
|
{
|
|
|
nmObjBase::init(sName, pAxisX, pAxisY);
|
|
|
nmObjRegionMark::initFlags();
|
|
|
|
|
|
m_bSelectRegion = false;
|
|
|
|
|
|
m_pGraphicBinder = nullptr;
|
|
|
|
|
|
m_icon = QPixmap(ZxBaseUtil::getDirOf(s_Dir_Res, "Icon") + "Anchor.png");
|
|
|
|
|
|
loadTempl();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
void nmObjRegionMark::initTools()
|
|
|
{
|
|
|
m_pTool = new nmObjRegionMarkTool();
|
|
|
nmObjBase::initTools();
|
|
|
}
|
|
|
|
|
|
void nmObjRegionMark::setResevoirType(int newResevoirType)
|
|
|
{
|
|
|
if (m_reservoirType != newResevoirType) {
|
|
|
m_reservoirType = newResevoirType;
|
|
|
emit sigResevoirTypeChanged(newResevoirType);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
int nmObjRegionMark::getResevoirType()
|
|
|
{
|
|
|
return m_reservoirType;
|
|
|
}
|
|
|
|
|
|
void nmObjRegionMark::setComKr(double newComkr)
|
|
|
{
|
|
|
if (m_comKr != newComkr) {
|
|
|
m_comKr = newComkr;
|
|
|
emit sigComKrChanged(newComkr);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
double nmObjRegionMark::getComKr()
|
|
|
{
|
|
|
return m_comKr;
|
|
|
}
|
|
|
|
|
|
void nmObjRegionMark::setComW(double newComW)
|
|
|
{
|
|
|
if (m_comW != newComW) {
|
|
|
m_comW = newComW;
|
|
|
emit sigComWChanged(newComW);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
double nmObjRegionMark::getComW()
|
|
|
{
|
|
|
return m_comW;
|
|
|
}
|
|
|
|
|
|
void nmObjRegionMark::setNetToGross(double newNetToGross)
|
|
|
{
|
|
|
if (m_netToGross != newNetToGross) {
|
|
|
m_netToGross = newNetToGross;
|
|
|
emit sigNetToGrossChanged(newNetToGross);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
double nmObjRegionMark::getNetToGross()
|
|
|
{
|
|
|
return m_netToGross;
|
|
|
}
|
|
|
|
|
|
void nmObjRegionMark::onSerialize(ZxSerializer* ser)
|
|
|
{
|
|
|
nmObjBase::onSerialize(ser);
|
|
|
|
|
|
ser->write("ResevoirType", m_reservoirType);
|
|
|
ser->write("dComKr", m_comKr);
|
|
|
ser->write("dComW", m_comW);
|
|
|
ser->write("NetToGross", m_netToGross);
|
|
|
}
|
|
|
|
|
|
void nmObjRegionMark::onDeserialize(ZxSerializer* ser)
|
|
|
{
|
|
|
nmObjBase::onDeserialize(ser);
|
|
|
int resevoirType;
|
|
|
double comKr;
|
|
|
double comW;
|
|
|
double netToGross;
|
|
|
ser->read("ResevoirType", resevoirType);
|
|
|
ser->read("dComKr", comKr);
|
|
|
ser->read("dComW", comW);
|
|
|
ser->read("NetToGross", netToGross);
|
|
|
|
|
|
m_reservoirType = resevoirType;
|
|
|
m_comKr = comKr;
|
|
|
m_comW = comW;
|
|
|
m_netToGross = netToGross;
|
|
|
}
|
|
|
|
|
|
void nmObjRegionMark::onSaveTempl(ZxSerializer* ser)
|
|
|
{
|
|
|
nmObjBase::onSaveTempl(ser);
|
|
|
|
|
|
ser->write("ResevoirType", m_reservoirType);
|
|
|
ser->write("dComKr", m_comKr);
|
|
|
ser->write("dComW", m_comW);
|
|
|
ser->write("NetToGross", m_netToGross);
|
|
|
}
|
|
|
|
|
|
void nmObjRegionMark::onLoadTempl(ZxSerializer* ser)
|
|
|
{
|
|
|
nmObjBase::onLoadTempl(ser);
|
|
|
int resevoirType;
|
|
|
double comKr;
|
|
|
double comW;
|
|
|
double netToGross;
|
|
|
ser->read("ResevoirType", resevoirType);
|
|
|
ser->read("dComKr", comKr);
|
|
|
ser->read("dComW", comW);
|
|
|
ser->read("NetToGross", netToGross);
|
|
|
|
|
|
m_reservoirType = resevoirType;
|
|
|
m_comKr = comKr;
|
|
|
m_comW = comW;
|
|
|
m_netToGross = netToGross;
|
|
|
}
|
|
|
|
|
|
void nmObjRegionMark::fillPtyPano(IxPtyPano* sheet)
|
|
|
{
|
|
|
nmObjBase::fillPtyPano(sheet);
|
|
|
|
|
|
IxPtyItem* pProp = ZX_PROP("ObjRegionMark.ResevoirType", getResevoirType, setResevoirType);
|
|
|
|
|
|
if(NULL != pProp) {
|
|
|
QStringList listTags;
|
|
|
listTags << tr("Homogeneous") << tr("Dual porosity pseudo steady state");
|
|
|
QList<QVariant> listIndexes;
|
|
|
listIndexes << 0 << 1;
|
|
|
pProp->getPtyPano();
|
|
|
pProp->setOptions(listTags, listIndexes);
|
|
|
}
|
|
|
|
|
|
ZX_PROP("ObjRegionMark.dComKr", getComKr, setComKr);
|
|
|
ZX_PROP("ObjRegionMark.dComW", getComW, setComW);
|
|
|
ZX_PROP("ObjRegionMark.NetToGross", getNetToGross, setNetToGross);
|
|
|
}
|
|
|
|
|
|
void nmObjRegionMark::initFlags()
|
|
|
{
|
|
|
setLockPos(false);
|
|
|
setLockSize(false);
|
|
|
setReadOnly(false);
|
|
|
}
|
|
|
|
|
|
bool nmObjRegionMark::hitTest(const QPointF& pt)
|
|
|
{
|
|
|
return nmObjBase::hitTest(pt);
|
|
|
}
|
|
|
|
|
|
bool nmObjRegionMark::_runHitTest(const QPointF& pt, int& nOption, int& nSubIndex)
|
|
|
{
|
|
|
if (!nmObjBase::_runHitTest(pt, nOption, nSubIndex)) {
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
nOption = OHO_None;
|
|
|
nSubIndex = -1;
|
|
|
ZxRenderView* view = getView();
|
|
|
if (view == nullptr || m_pAxisX == nullptr || m_pAxisY == nullptr || m_vecPoints.isEmpty()) {
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
const QPointF mousePos = view->mapFromScene(pt);
|
|
|
const QPointF anchor = getPosOf(m_vecPoints.first());
|
|
|
const QRectF iconRect = view->mapFromScene(regionMarkIconRect(anchor)).normalized();
|
|
|
if (!qIsFinite(mousePos.x()) || !qIsFinite(mousePos.y()) ||
|
|
|
!qIsFinite(iconRect.left()) || !qIsFinite(iconRect.right()) ||
|
|
|
!qIsFinite(iconRect.top()) || !qIsFinite(iconRect.bottom())) {
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
// 命中区覆盖完整图标并留出像素余量,缩小时也保留最小点击范围。
|
|
|
const qreal paddingPixels = 2.0;
|
|
|
const qreal paddingX = qMax(paddingPixels, NodeHitRadiusPixels - iconRect.width() / 2);
|
|
|
const qreal paddingY = qMax(paddingPixels, NodeHitRadiusPixels - iconRect.height() / 2);
|
|
|
if (!iconRect.adjusted(-paddingX, -paddingY, paddingX, paddingY).contains(mousePos)) {
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
nOption = OHO_Point;
|
|
|
nSubIndex = 0;
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
bool nmObjRegionMark::calculateMoveAnchor(const QPointF& start, const QPointF& end,
|
|
|
QPointF& anchor) const
|
|
|
{
|
|
|
if (isReadOnly() || isLockPos() || m_vecPoints.isEmpty() ||
|
|
|
m_pAxisX == nullptr || m_pAxisY == nullptr ||
|
|
|
m_pAxisX->getRangeMin() == m_pAxisX->getRangeMax() ||
|
|
|
m_pAxisY->getRangeMin() == m_pAxisY->getRangeMax()) {
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
anchor = getPosOf(m_vecPoints.first()) + (end - start);
|
|
|
return qIsFinite(anchor.x()) && qIsFinite(anchor.y());
|
|
|
}
|
|
|
|
|
|
bool nmObjRegionMark::runMove(const QPointF& pt1, const QPointF& pt2)
|
|
|
{
|
|
|
QPointF anchor;
|
|
|
if (m_oHitOption != OHO_Point || m_nHitIndex != 0 ||
|
|
|
!calculateMoveAnchor(pt1, pt2, anchor)) {
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
QVector<QPointF> positions = getAllPos();
|
|
|
positions[0] = anchor;
|
|
|
resetBrotherOffset();
|
|
|
if (!moveToPos(positions)) {
|
|
|
return false;
|
|
|
}
|
|
|
if (m_pGraphicBinder != nullptr) {
|
|
|
m_pGraphicBinder->syncRegionMarkMove(this);
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
|
|
|
void nmObjRegionMark::resetBounds()
|
|
|
{
|
|
|
if(m_vecPoints.isEmpty() || m_pAxisX == nullptr || m_pAxisY == nullptr) {
|
|
|
nmObjBase::resetBounds();
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
// 单点本身没有面积,需包含图标和文字,避免在子图元绘制时被裁剪跳过。
|
|
|
setBounds(getBounds4Update());
|
|
|
// 显示范围可以扩展,业务坐标范围仍按原始锚点计算。
|
|
|
m_rtBoundVs = calValueBounds();
|
|
|
resetOthers();
|
|
|
}
|
|
|
|
|
|
QRectF nmObjRegionMark::getBounds4Update()
|
|
|
{
|
|
|
if(m_vecPoints.isEmpty() || m_pAxisX == nullptr || m_pAxisY == nullptr) {
|
|
|
return QRectF();
|
|
|
}
|
|
|
|
|
|
const QPointF ptPos = getPosOf(m_vecPoints[0]);
|
|
|
// 合并图标和文字范围,并为边缘绘制留白,确保局部刷新覆盖完整标记。
|
|
|
return regionMarkIconRect(ptPos).united(regionMarkTextRect(ptPos))
|
|
|
.adjusted(-1.0, -1.0, 1.0, 1.0);
|
|
|
}
|
|
|
|
|
|
void nmObjRegionMark::paintBack(QPainter* painter, const ZxPaintParam& param)
|
|
|
{
|
|
|
if(m_vecPoints.isEmpty() || NULL == m_pAxisX || NULL == m_pAxisY || \
|
|
|
m_pAxisX->getRangeMin() == m_pAxisX->getRangeMax() || \
|
|
|
m_pAxisY->getRangeMin() == m_pAxisY->getRangeMax()) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
const QPointF ptPos = getPosOf(m_vecPoints[0]);
|
|
|
|
|
|
ZxPlot* m_pCurPlot = dynamic_cast<ZxPlot*>(this->getParent());
|
|
|
if (m_pCurPlot == nullptr) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
// 获取当前图表的对象数
|
|
|
int objCount = m_pCurPlot->getObjCount();
|
|
|
|
|
|
for(int i = 0; i < objCount; i++) {
|
|
|
ZxObjBase* obj = m_pCurPlot->getObjByIndex(i);
|
|
|
if (obj == nullptr) {
|
|
|
continue;
|
|
|
}
|
|
|
QVector<QPointF> pts = obj->getAllPos();
|
|
|
|
|
|
if(_isSame("nObjRegion", obj->getTagName())) {
|
|
|
// 获取区域的多边形点
|
|
|
QPolygonF regionPolygon(pts);
|
|
|
nmObjRegion* region = static_cast<nmObjRegion*>(obj);
|
|
|
|
|
|
// 判断 RegionMark 是否在该区域内
|
|
|
if(regionPolygon.containsPoint(ptPos, Qt::OddEvenFill)) {
|
|
|
// 判断该区域是否已经被标记
|
|
|
if(region->getRegionMark() == nullptr) {
|
|
|
// 仅在 Binder 已绑定时才关联(避免加载数据前 paintBack 误设)
|
|
|
if (m_pGraphicBinder) {
|
|
|
region->setRegionMark(this);
|
|
|
region->setBackgrdColor(this->m_clrBackgrd);
|
|
|
this->setSelectRegion(true);
|
|
|
}
|
|
|
} else {
|
|
|
// 如果区域已被标记
|
|
|
int index = region->getRegionMark()->getColorIndex();
|
|
|
|
|
|
// 判断大小
|
|
|
if(this->m_iColorIndex < index) {
|
|
|
region->setRegionMark(this);
|
|
|
region->setBackgrdColor(this->m_clrBackgrd);
|
|
|
this->setSelectRegion(true);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 通过 Binder 同步名称、位置、颜色、选中状态到数据(paintBack 兜底同步)
|
|
|
if (m_pGraphicBinder) {
|
|
|
m_pGraphicBinder->syncRegionMarkData(this);
|
|
|
}
|
|
|
|
|
|
paintMarker(painter, ptPos);
|
|
|
}
|
|
|
|
|
|
void nmObjRegionMark::paintMarker(QPainter* painter, const QPointF& anchor) const
|
|
|
{
|
|
|
painter->save();
|
|
|
|
|
|
// 设置字体
|
|
|
QFont ft = qApp->font();
|
|
|
ft.setPointSize(8);
|
|
|
painter->setFont(ft);
|
|
|
painter->setPen(Qt::black);
|
|
|
|
|
|
const QRectF iconRect = regionMarkIconRect(anchor);
|
|
|
painter->drawPixmap(iconRect, m_icon, m_icon.rect());
|
|
|
|
|
|
// 计算文本的矩形区域,位于图标上方
|
|
|
const QRectF textRect = regionMarkTextRect(anchor);
|
|
|
ZxDrawHelper::drawText(painter, textRect, Qt::AlignCenter, m_sName);
|
|
|
|
|
|
painter->restore();
|
|
|
}
|
|
|
|
|
|
void nmObjRegionMark::setColorIndex(int newIndex)
|
|
|
{
|
|
|
m_iColorIndex = newIndex;
|
|
|
}
|
|
|
|
|
|
int nmObjRegionMark::getColorIndex() const
|
|
|
{
|
|
|
return m_iColorIndex;
|
|
|
}
|
|
|
|
|
|
void nmObjRegionMark::setSelectRegion(bool select)
|
|
|
{
|
|
|
m_bSelectRegion = select;
|
|
|
}
|
|
|
|
|
|
bool nmObjRegionMark::getSelectRegion() const
|
|
|
{
|
|
|
return m_bSelectRegion;
|
|
|
}
|
|
|
|
|
|
QColor nmObjRegionMark::getBackgrdColor() const
|
|
|
{
|
|
|
return m_clrBackgrd;
|
|
|
}
|
|
|
|
|
|
void nmObjRegionMark::setBackgrdColor(QColor color)
|
|
|
{
|
|
|
if(m_clrBackgrd != color) {
|
|
|
m_clrBackgrd = color;
|
|
|
update();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
void nmObjRegionMark::afterCreated()
|
|
|
{
|
|
|
if (m_pGraphicBinder) {
|
|
|
m_pGraphicBinder->createRegionMarkForGraphic(this);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
void nmObjRegionMark::removeData()
|
|
|
{
|
|
|
if (m_pGraphicBinder) {
|
|
|
m_pGraphicBinder->removeRegionMarkBinding(this);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 通过 Binder 查询关联的数据对象(供 nmObjRegion 使用)
|