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

185 lines
4.9 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 "nmObjPolygonOutlineTool.h"
#include "nmObjPolygonOutline.h"
#include "nmPlotGraphicBinder.h"
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)
{
nmObjPolygon::setAllPos(vecPoss, pVecIndexes);
// 根据点数确定边数以此来初始化m_vFlowTypeList
// 仅在列表不足时补充默认值,不阻止信号发射
while(m_vFlowTypeList.count() < vecPoss.count()) {
m_vFlowTypeList.append(NM_OIL_RESERVOIR_OUTLINE_TYPE::OIL_Reservoir_Outline_No_Flow);
}
emit sigOutlinePointsChanged();
}
void nmObjPolygonOutline::onLoadTempl(ZxSerializer* ser)
{
nmObjPolygon::onLoadTempl(ser);
ser->read("FlowTypeList", m_vFlowTypeList);
}
void nmObjPolygonOutline::paintBack(QPainter* painter, const ZxPaintParam& param)
{
nmObjPolygon::paintBack(painter, param);
QVector<QPointF> pts = getPosOf(m_vecPoints);
// 名称同步setName 不发信号,在绘制时通过 Binder 同步到数据中心
if (m_pGraphicBinder) {
m_pGraphicBinder->syncOutlineName(this);
m_pGraphicBinder->syncOutlineVisual(this);
}
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) {
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();
}
void nmObjPolygonOutline::setCurOutlineFlowType(int flowType)
{
if(m_oHitOption == OHO_Bound) {
m_vFlowTypeList[m_nHitIndex] = flowType;
emit sigOutlineFlowTypeChanged();
}
}
int nmObjPolygonOutline::getCurOutlineFlowType()
{
if(m_oHitOption == OHO_Bound) {
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);
}
}