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.
nmWATI/Src/nmNum/nmPlot/nmObjPolygonOutline.cpp

164 lines
4.8 KiB
C++

#include <QPainter>
#include <ZxSerializer.h>
#include "IxPtyPano.h"
#include "ZxSubAxisX.h"
#include "ZxSubAxisY.h"
#include "nmObjPolygonOutlineTool.h"
#include "nmObjPolygonOutline.h"
#include "nmDataLogFile.h"
ZX_DEFINE_DYNAMIC(nObjPolygonOutline, nmObjPolygonOutline)
nmObjPolygonOutline::nmObjPolygonOutline()
{
m_sObjTag = "nObjPolygonOutline";
init("", NULL, NULL);
}
nmObjPolygonOutline::nmObjPolygonOutline(const QString& sName, \
ZxSubAxisX* pAxisX, \
ZxSubAxisY* pAxisY)
{
m_sObjTag = "nObjPolygonOutline";
init(sName, pAxisX, pAxisY);
}
nmObjPolygonOutline::~nmObjPolygonOutline()
{
}
void nmObjPolygonOutline::init(const QString& sName, \
ZxSubAxisX* pAxisX, \
ZxSubAxisY* pAxisY)
{
nmObjPolygon::init(sName, pAxisX, pAxisY);
}
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") << tr("Unknow");
QList<QVariant> listIndexes;
listIndexes << 0 << 1 << 2;
pProp->getPtyPano();
pProp->setOptions(listTags, listIndexes);
}
}
void nmObjPolygonOutline::onSerialize(ZxSerializer* ser)
{
nmObjPolygon::onSerialize(ser);
// ser->write("BackgrdColor", m_clrBackgrd);
// TODO序列化 边界类型数据
ser->write("FlowTypeList", m_vFlowTypeList);
}
void nmObjPolygonOutline::onDeserialize(ZxSerializer* ser)
{
nmObjPolygon::onDeserialize(ser);
// ser->read("BackgrdColor", m_clrBackgrd);
// TODO序列化 边界类型数据
ser->read("FlowTypeList", m_vFlowTypeList);
}
void nmObjPolygonOutline::onSaveTempl(ZxSerializer* ser)
{
nmObjPolygon::onSaveTempl(ser);
// ser->write("BackgrdColor", m_clrBackgrd);
ser->write("FlowTypeList", m_vFlowTypeList);
}
void nmObjPolygonOutline::setAllPos(QVector<QPointF> vecPoss, QVector<int> *pVecIndexes)
{
nmObjPolygon::setAllPos(vecPoss, pVecIndexes);
// 根据点数确定边数以此来初始化m_vFlowTypeList
// TODO会不会覆盖从数据库读取的边界类型值
for (int i = 0; i < vecPoss.count(); i++) {
m_vFlowTypeList.append(NM_OIL_RESERVOIR_OUTLINE_TYPE::OIL_Reservoir_Outline_No_Flow);
}
}
void nmObjPolygonOutline::onLoadTempl(ZxSerializer* ser)
{
nmObjPolygon::onLoadTempl(ser);
// ser->read("BackgrdColor", m_clrBackgrd);
ser->read("FlowTypeList", m_vFlowTypeList);
}
void nmObjPolygonOutline::paintBack(QPainter* painter, const ZxPaintParam& param)
{
nmObjPolygon::paintBack(painter, param);
QVector<QPointF> pts = getPosOf(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_nHitIndex == i && m_oHitOption == OHO_Bound) {
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->setPen(QColor(0, 0, 128));
// painter->drawRect(rect);
}
}
}
painter->restore();
}
void nmObjPolygonOutline::setCurOutlineFlowType(int flowType)
{
if (m_oHitOption == OHO_Bound) {
m_vFlowTypeList[m_nHitIndex] = flowType;
}
}
int nmObjPolygonOutline::getCurOutlineFlowType()
{
if (m_oHitOption == OHO_Bound) {
return m_vFlowTypeList[m_nHitIndex];
}
return (int)NM_OIL_RESERVOIR_OUTLINE_TYPE::OIL_Reservoir_Outline_UNKNOW;
}