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.
378 lines
9.8 KiB
C++
378 lines
9.8 KiB
C++
#include <QPainter>
|
|
|
|
#include "nmObjRegionMark.h"
|
|
#include "nmObjRegionMarkTool.h"
|
|
|
|
#include "ZxSerializer.h"
|
|
#include "IxPtyPano.h"
|
|
|
|
#include "ZxSubAxisX.h"
|
|
#include "ZxSubAxisY.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_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)
|
|
: 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);
|
|
}
|
|
|
|
nmObjRegionMark::~nmObjRegionMark()
|
|
{
|
|
}
|
|
|
|
void nmObjRegionMark::init(const QString& sName, \
|
|
ZxSubAxisX* pAxisX, \
|
|
ZxSubAxisY* pAxisY)
|
|
{
|
|
nmObjBase::init(sName, pAxisX, pAxisY);
|
|
nmObjRegionMark::initFlags();
|
|
|
|
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 (!commitPointPositions(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;
|
|
}
|
|
|
|
if (m_pGraphicBinder) {
|
|
m_pGraphicBinder->syncRegionMarkData(this);
|
|
}
|
|
paintMarker(painter, getPosOf(m_vecPoints.first()));
|
|
}
|
|
|
|
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::afterCreated()
|
|
{
|
|
if (m_pGraphicBinder) {
|
|
m_pGraphicBinder->createRegionMarkForGraphic(this);
|
|
}
|
|
}
|
|
|
|
void nmObjRegionMark::removeData()
|
|
{
|
|
if (m_pGraphicBinder) {
|
|
m_pGraphicBinder->removeRegionMarkBinding(this);
|
|
}
|
|
}
|
|
|
|
// 通过 Binder 查询关联的数据对象(供 nmObjRegion 使用)
|