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

353 lines
10 KiB
C++

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#include <QPainter>
#include <ZxSerializer.h>
#include "IxPtyPano.h"
#include "ZxSubAxisX.h"
#include "ZxSubAxisY.h"
#include "nmObjRectOutlineTool.h"
#include "nmObjRectOutline.h"
#include "nmDataLogFile.h"
#include "nmDataAnalyzeManager.h"
ZX_DEFINE_DYNAMIC(nObjRectOutline, nmObjRectOutline)
nmObjRectOutline::nmObjRectOutline()
: m_eChangeOutlineType(RBP_Unknown)
, m_outlineData(nullptr)
{
m_sObjTag = "nObjRectOutline";
nmObjRectOutline::init("", NULL, NULL);
}
nmObjRectOutline::nmObjRectOutline(const QString& sName, \
ZxSubAxisX* pAxisX, \
ZxSubAxisY* pAxisY)
: m_eChangeOutlineType(RBP_Unknown)
, m_outlineData(nullptr)
{
m_sObjTag = "nObjRectOutline";
nmObjRectOutline::init(sName, pAxisX, pAxisY);
}
nmObjRectOutline::~nmObjRectOutline()
{
if(m_outlineData != nullptr) {
delete m_outlineData;
m_outlineData = nullptr;
}
}
void nmObjRectOutline::init(const QString& sName, \
ZxSubAxisX* pAxisX, \
ZxSubAxisY* pAxisY)
{
nmObjRect::init(sName, pAxisX, pAxisY);
m_outlineData = nullptr;
// 连接图元可见性信号和槽
connect(this, SIGNAL(sigObjVisibleChanged(bool)),
this, SLOT(onObjVisibleChanged(bool)));
}
void nmObjRectOutline::initTools()
{
m_pTool = new nmObjRectOutlineTool();
nmObjBase::initTools();
}
bool nmObjRectOutline::hitTest(const QPointF& pt)
{
return nmObjRect::hitTest(pt);
}
bool nmObjRectOutline::_runHitTest(const QPointF& pt, int& nOption, int& nSubIndex)
{
return nmObjRect::_runHitTest(pt, nOption, nSubIndex);
}
void nmObjRectOutline::fillPtyPano(IxPtyPano* sheet)
{
nmObjRect::fillPtyPano(sheet);
// 设置边界类型,依次为上边界、右边界、下边界、左边界
IxPtyItem* pPropTop = ZX_PROP("ObjRectOutline.TopOutline", getTopOutlineFlowType, setTopOutlineFlowType);
IxPtyItem* pPropRight = ZX_PROP("ObjRectOutline.RightOutline", getRightOutlineFlowType, setRightOutlineFlowType);
IxPtyItem* pPropBottom = ZX_PROP("ObjRectOutline.BottomOutline", getBottomOutlineFlowType, setBottomOutlineFlowType);
IxPtyItem* pPropLeft = ZX_PROP("ObjRectOutline.LeftOutline", getLeftOutlineFlowType, setLeftOutlineFlowType);
if(NULL != pPropTop) {
QStringList listTags;
listTags << tr("No Flow") << tr("Constant Pressure");
QList<QVariant> listIndexes;
listIndexes << 0 << 1;
pPropTop->getPtyPano();
pPropTop->setOptions(listTags, listIndexes);
}
if(NULL != pPropRight) {
QStringList listTags;
listTags << tr("No Flow") << tr("Constant Pressure");
QList<QVariant> listIndexes;
listIndexes << 0 << 1;
pPropRight->getPtyPano();
pPropRight->setOptions(listTags, listIndexes);
}
if(NULL != pPropBottom) {
QStringList listTags;
listTags << tr("No Flow") << tr("Constant Pressure");
QList<QVariant> listIndexes;
listIndexes << 0 << 1;
pPropBottom->getPtyPano();
pPropBottom->setOptions(listTags, listIndexes);
}
if(NULL != pPropLeft) {
QStringList listTags;
listTags << tr("No Flow") << tr("Constant Pressure");
QList<QVariant> listIndexes;
listIndexes << 0 << 1;
pPropLeft->getPtyPano();
pPropLeft->setOptions(listTags, listIndexes);
}
}
void nmObjRectOutline::onSerialize(ZxSerializer* ser)
{
nmObjRect::onSerialize(ser);
// ser->write("BackgrdColor", m_clrBackgrd);
// TODO序列化 边界类型数据
ser->write("FlowTypeList", m_vFlowTypeList);
}
void nmObjRectOutline::onDeserialize(ZxSerializer* ser)
{
nmObjRect::onDeserialize(ser);
// ser->read("BackgrdColor", m_clrBackgrd);
// TODO序列化 边界类型数据
ser->read("FlowTypeList", m_vFlowTypeList);
}
void nmObjRectOutline::onLoadTempl(ZxSerializer* ser)
{
nmObjRect::onLoadTempl(ser);
// ser->read("BackgrdColor", m_clrBackgrd);
ser->read("FlowTypeList", m_vFlowTypeList);
}
void nmObjRectOutline::onSaveTempl(ZxSerializer* ser)
{
nmObjRect::onSaveTempl(ser);
// ser->write("BackgrdColor", m_clrBackgrd);
ser->write("FlowTypeList", m_vFlowTypeList);
}
void nmObjRectOutline::setAllPos(QVector<QPointF> vecPoss, QVector<int> *pVecIndexes)
{
nmObjRect::setAllPos(vecPoss, pVecIndexes);
// 根据点数确定边数以此来初始化m_vFlowTypeList
// TODO会不会覆盖从数据库读取的边界类型值
for(int i = 0; i < vecPoss.count(); i++) {
if(m_vFlowTypeList.count() > i) {
return;
}
m_vFlowTypeList.append(NM_OIL_RESERVOIR_OUTLINE_TYPE::OIL_Reservoir_Outline_No_Flow);
}
}
void nmObjRectOutline::paintBack(QPainter* painter, const ZxPaintParam& param)
{
// 更新m_vecPoints点的顺序
this->reorderPoints(m_vecPoints);
nmObjRect::paintBack(painter, param);
QVector<QPointF> pts = getPosOf(m_vecPoints);
if(m_outlineData != nullptr) {
// 动态更新当前边界数据
m_outlineData->setName(m_sName);
m_outlineData->setOutlinePoints(m_vecPoints);
}
if(isSelected()) { // 选中状态下
QPen pen(QBrush(Qt::black), 0.0f, Qt::DotLine);
painter->setPen(pen);
painter->drawPolygon(&pts[0], pts.count());
for(int i = 0; i < pts.count(); i++) {
float w = 2.2f;
QPointF pt = pts[i];
QRectF rect(pt.x() - w * 0.5f, pt.y() - w * 0.5f, w, w);
// 渲染节点
painter->setPen(QColor(0, 0, 128));
painter->drawRect(rect);
// 如果是选中的边,则显示绿色
/*
if((m_oHitPos == RBP_Top || m_oHitPos == RBP_Right || m_oHitPos == RBP_Bottom || m_oHitPos == RBP_Left) && m_nRectHitIndex== i) {
nmDataLogFile::getInstance()->writeLog("select line " + QString::number(i));
QPen pen;
pen.setWidth(1);
pen.setColor(Qt::green);
painter->setPen(pen);
painter->drawLine(pts[i], pts[i == pts.count() - 1 ? 0 : i + 1]);
}
*/
}
}
painter->restore();
}
nmDataOutline* nmObjRectOutline::getOutlineData() const
{
return m_outlineData;
}
void nmObjRectOutline::setOutlineData(nmDataOutline* newOutlineData)
{
m_outlineData = newOutlineData;
}
void nmObjRectOutline::afterCreated()
{
m_outlineData = nmDataAnalyzeManager::getCurrentInstance()->createOutline();
m_outlineData->setName(m_sName);
m_outlineData->setFlowTypeList(m_vFlowTypeList);
// 更新m_vecPoints点的顺序
this->reorderPoints(m_vecPoints);
m_outlineData->setOutlinePoints(m_vecPoints);
m_outlineData->setOutlineType(NM_Data_Outline_Type::NM_Rect_Outline_Type);
nmDataAnalyzeManager::getCurrentInstance()->notifyDataChanged();
}
void nmObjRectOutline::removeData()
{
if(m_outlineData) {
// 从数据中心移除该数据
nmDataAnalyzeManager::getCurrentInstance()->removeOutlineData();
m_outlineData = nullptr;
}
}
void nmObjRectOutline::reorderPoints(QVector<QPointF>& points)
{
if(points.size() != 4) {
// 如果点的数量不是4个直接返回
return;
}
// 找到所有点的最小和最大坐标
double minX = points[0].x();
double maxX = points[0].x();
double minY = points[0].y();
double maxY = points[0].y();
for(int i = 1; i < 4; ++i) {
if(points[i].x() < minX) minX = points[i].x();
if(points[i].x() > maxX) maxX = points[i].x();
if(points[i].y() < minY) minY = points[i].y();
if(points[i].y() > maxY) maxY = points[i].y();
}
// 初始化四个角的点
QPointF leftTop, rightTop, rightBottom, leftBottom;
// 遍历点,确定每个点的位置
for(int i = 0; i < 4; ++i) {
const QPointF& pt = points[i];
if(pt.x() == minX && pt.y() == maxY) {
leftTop = pt; // 左上角
} else if(pt.x() == maxX && pt.y() == maxY) {
rightTop = pt; // 右上角
} else if(pt.x() == maxX && pt.y() == minY) {
rightBottom = pt; // 右下角
} else if(pt.x() == minX && pt.y() == minY) {
leftBottom = pt; // 左下角
}
}
// 按照左上角、右上角、右下角、左下角的顺序重新排列
points.clear();
points.push_back(leftTop);
points.push_back(rightTop);
points.push_back(rightBottom);
points.push_back(leftBottom);
}
// 上边界流动类型
void nmObjRectOutline::setTopOutlineFlowType(int newValue)
{
// 先获取之前的边界类型
QVector<int> vecFlowTypeList = m_outlineData->getFlowTypeList();
vecFlowTypeList[0] = newValue;
// 设置上边界流动类型
m_outlineData->setFlowTypeList(vecFlowTypeList);
}
int nmObjRectOutline::getTopOutlineFlowType()
{
return m_outlineData->getFlowTypeList()[0];
}
// 右边界流动类型
void nmObjRectOutline::setRightOutlineFlowType(int newValue)
{
// 先获取之前的边界类型
QVector<int> vecFlowTypeList = m_outlineData->getFlowTypeList();
vecFlowTypeList[1] = newValue; // 设置右边界流动类型
m_outlineData->setFlowTypeList(vecFlowTypeList);
}
int nmObjRectOutline::getRightOutlineFlowType()
{
return m_outlineData->getFlowTypeList()[1];
}
// 下边界流动类型
void nmObjRectOutline::setBottomOutlineFlowType(int newValue)
{
// 先获取之前的边界类型
QVector<int> vecFlowTypeList = m_outlineData->getFlowTypeList();
vecFlowTypeList[2] = newValue; // 设置下边界流动类型
m_outlineData->setFlowTypeList(vecFlowTypeList);
}
int nmObjRectOutline::getBottomOutlineFlowType()
{
return m_outlineData->getFlowTypeList()[2];
}
// 左边界流动类型
void nmObjRectOutline::setLeftOutlineFlowType(int newValue)
{
// 先获取之前的边界类型
QVector<int> vecFlowTypeList = m_outlineData->getFlowTypeList();
vecFlowTypeList[3] = newValue; // 设置左边界流动类型
m_outlineData->setFlowTypeList(vecFlowTypeList);
}
int nmObjRectOutline::getLeftOutlineFlowType()
{
return m_outlineData->getFlowTypeList()[3];
}
void nmObjRectOutline::onObjVisibleChanged(bool bIsVisible)
{
if(m_outlineData != nullptr) {
m_outlineData->setPlotVisible(bIsVisible);
}
}