2025-02-06 16:36:50 +08:00
|
|
|
|
#include <QJsonArray>
|
|
|
|
|
|
#include "drawingPanel.h"
|
|
|
|
|
|
#include "ui_drawingPanel.h"
|
|
|
|
|
|
#include <QMessageBox>
|
2025-04-30 16:29:17 +08:00
|
|
|
|
#include <QCloseEvent>
|
2025-02-06 16:36:50 +08:00
|
|
|
|
#include "designerView.h"
|
|
|
|
|
|
#include "graphicsDataModel/fixedPortsModel.h"
|
2025-07-11 18:13:54 +08:00
|
|
|
|
#include "graphicsItem/graphicsBaseItem.h"
|
2025-02-06 16:36:50 +08:00
|
|
|
|
#include "util/selectorManager.h"
|
|
|
|
|
|
#include "statusBar.h"
|
|
|
|
|
|
#include "dataBase.h"
|
2025-04-30 16:29:17 +08:00
|
|
|
|
#include "powerEntity.h"
|
2025-05-16 19:20:46 +08:00
|
|
|
|
#include "topologyManager.h"
|
2025-06-27 19:17:04 +08:00
|
|
|
|
#include "projectDiagramNameInput.h"
|
2025-07-11 18:13:54 +08:00
|
|
|
|
#include "baseProperty.h"
|
2025-07-18 18:26:13 +08:00
|
|
|
|
#include "graphicsItem/electricBayItem.h"
|
2025-02-06 16:36:50 +08:00
|
|
|
|
|
2025-04-30 16:29:17 +08:00
|
|
|
|
DrawingPanel::DrawingPanel(PowerEntity* pEntity,QWidget *parent,DiagramMode mode)
|
2025-02-06 16:36:50 +08:00
|
|
|
|
: QWidget(parent)
|
|
|
|
|
|
, ui(new Ui::drawingPanel)
|
|
|
|
|
|
,_pModel(nullptr)
|
|
|
|
|
|
,_mode(mode)
|
2025-04-30 16:29:17 +08:00
|
|
|
|
,_pEntity(pEntity)
|
2025-06-27 19:17:04 +08:00
|
|
|
|
,m_pDiagramNameInputer(nullptr)
|
2025-02-06 16:36:50 +08:00
|
|
|
|
{
|
|
|
|
|
|
ui->setupUi(this);
|
|
|
|
|
|
|
2025-04-30 16:29:17 +08:00
|
|
|
|
_pModel = new FixedPortsModel(pEntity);
|
2025-02-06 16:36:50 +08:00
|
|
|
|
_pModel->setTopWidget(this);
|
2025-06-20 18:09:41 +08:00
|
|
|
|
if(mode == DM_edit || mode == DM_baseModel)
|
2025-02-06 16:36:50 +08:00
|
|
|
|
m_pSelectorManager = new SelectorManager(_pModel,this);
|
|
|
|
|
|
m_pGraphicsScene = new DesignerScene(_pModel,this);
|
|
|
|
|
|
//设置场景大小.前两个参数为scene的坐标远点,设置到view的中心点后,无论view如何缩放,secne的坐标原点都不会动,方便后续的位置计算
|
2025-09-26 18:50:21 +08:00
|
|
|
|
m_pGraphicsScene->setSceneRect(-g_dGriaphicsScene_Width, -g_dGriaphicsScene_Height, g_dGriaphicsScene_Width*2, g_dGriaphicsScene_Height*2);
|
2025-02-06 16:36:50 +08:00
|
|
|
|
m_pGraphicsScene->setGridVisible(true);
|
|
|
|
|
|
|
|
|
|
|
|
m_pGraphicsView = new DesignerView(this);
|
|
|
|
|
|
m_pGraphicsView->setScene(m_pGraphicsScene);
|
|
|
|
|
|
m_pGraphicsScene->setView(m_pGraphicsView);
|
|
|
|
|
|
ui->mainLayout->addWidget(m_pGraphicsView);
|
|
|
|
|
|
_pModel->setScene(m_pGraphicsScene);
|
|
|
|
|
|
|
|
|
|
|
|
m_pStatusBar = new StatusBar(this);
|
2025-06-27 19:17:04 +08:00
|
|
|
|
if(mode == DM_edit)
|
|
|
|
|
|
m_pStatusBar->setButtonVisible(false);
|
2025-02-06 16:36:50 +08:00
|
|
|
|
ui->mainLayout->addWidget(m_pStatusBar);
|
|
|
|
|
|
connect(m_pGraphicsView,&DesignerView::onScaleChanged,m_pStatusBar,&StatusBar::onScaleLevelChanged);
|
2025-06-27 19:17:04 +08:00
|
|
|
|
connect(m_pStatusBar,&StatusBar::generateDiagram,this,&DrawingPanel::onSignal_Generate);
|
2025-02-06 16:36:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DrawingPanel::~DrawingPanel()
|
|
|
|
|
|
{
|
|
|
|
|
|
delete ui;
|
|
|
|
|
|
if(_pModel)
|
|
|
|
|
|
delete _pModel;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QGraphicsScene* DrawingPanel::getQGraphicsScene()
|
|
|
|
|
|
{
|
|
|
|
|
|
return m_pGraphicsView->scene();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DesignerScene* DrawingPanel::getDesignerScene()
|
|
|
|
|
|
{
|
|
|
|
|
|
return m_pGraphicsScene;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DrawingPanel::grahpicsViewZoomIn()
|
|
|
|
|
|
{
|
|
|
|
|
|
m_pGraphicsView->zoomIn();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DrawingPanel::grahpicsViewZoomOut()
|
|
|
|
|
|
{
|
|
|
|
|
|
m_pGraphicsView->zoomOut();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DrawingPanel::grahpicsViewZoomFit()
|
|
|
|
|
|
{
|
|
|
|
|
|
m_pGraphicsView->zoomFit();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
GraphicsItemGroup* DrawingPanel::createItemGroup()
|
|
|
|
|
|
{
|
|
|
|
|
|
return m_pGraphicsScene->createGroup();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DrawingPanel::destroyItemGroup()
|
|
|
|
|
|
{
|
|
|
|
|
|
m_pGraphicsScene->destroyGroup();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SelectorManager* DrawingPanel::selectorManager() const
|
|
|
|
|
|
{
|
|
|
|
|
|
if(m_pSelectorManager)
|
|
|
|
|
|
return m_pSelectorManager;
|
|
|
|
|
|
else
|
|
|
|
|
|
return NULL;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DrawingPanel::closeEvent(QCloseEvent *closeEvent)
|
|
|
|
|
|
{
|
2025-06-13 19:00:05 +08:00
|
|
|
|
if(getMode() == DM_edit)
|
2025-02-06 16:36:50 +08:00
|
|
|
|
{
|
2025-06-13 19:00:05 +08:00
|
|
|
|
bool changed = false;
|
|
|
|
|
|
QMap<QUuid,GraphicsProjectModelItem*> map = _pModel->allItems();
|
|
|
|
|
|
if(_pModel)
|
2025-02-06 16:36:50 +08:00
|
|
|
|
{
|
2025-06-13 19:00:05 +08:00
|
|
|
|
for(auto pItem:map)
|
2025-02-06 16:36:50 +08:00
|
|
|
|
{
|
2025-06-13 19:00:05 +08:00
|
|
|
|
if(pItem->itemChanged())
|
|
|
|
|
|
{
|
|
|
|
|
|
changed = true;
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
2025-02-06 16:36:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-06-13 19:00:05 +08:00
|
|
|
|
if(changed)
|
2025-02-06 16:36:50 +08:00
|
|
|
|
{
|
2025-06-13 19:00:05 +08:00
|
|
|
|
QMessageBox msgBox;
|
|
|
|
|
|
msgBox.setText(QString::fromWCharArray(L"提示"));
|
|
|
|
|
|
msgBox.setInformativeText(QString::fromWCharArray(L"保存修改内容?"));
|
|
|
|
|
|
msgBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
|
|
|
|
|
|
msgBox.setDefaultButton(QMessageBox::Cancel);
|
|
|
|
|
|
int ret = msgBox.exec();
|
|
|
|
|
|
switch (ret) {
|
|
|
|
|
|
case QMessageBox::Ok:
|
2025-02-06 16:36:50 +08:00
|
|
|
|
{
|
2025-06-13 19:00:05 +08:00
|
|
|
|
for(auto pItem:map)
|
|
|
|
|
|
{
|
|
|
|
|
|
if(pItem->itemChanged())
|
|
|
|
|
|
pItem->updateConnectData();
|
|
|
|
|
|
}
|
|
|
|
|
|
if(DataBase::GetInstance()->getPageIdByName(_name) == -1) //不存在,创建
|
|
|
|
|
|
DataBase::GetInstance()->insertPage(_name,_name,QJsonObject(),getDiagramInfo(),QString("page"),1);
|
|
|
|
|
|
else
|
|
|
|
|
|
DataBase::GetInstance()->updatePage(_name,_name,getDiagramInfo());
|
|
|
|
|
|
int pageId = DataBase::GetInstance()->getPageIdByName(_name);
|
|
|
|
|
|
saveNodes(pageId);
|
|
|
|
|
|
//todo:同步图形数据到数据对象,保存到服务器
|
|
|
|
|
|
}
|
|
|
|
|
|
break;
|
|
|
|
|
|
case QMessageBox::Cancel:
|
|
|
|
|
|
{
|
|
|
|
|
|
//todo:取消保存,删除panel
|
2025-02-06 16:36:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
break;
|
2025-06-13 19:00:05 +08:00
|
|
|
|
default:
|
|
|
|
|
|
// should never be reached
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
2025-02-06 16:36:50 +08:00
|
|
|
|
}
|
2025-06-13 19:00:05 +08:00
|
|
|
|
emit panelDelete(_name);
|
2025-02-06 16:36:50 +08:00
|
|
|
|
}
|
2025-06-13 19:00:05 +08:00
|
|
|
|
else if(getMode() == DM_baseModel)
|
2025-02-06 16:36:50 +08:00
|
|
|
|
{
|
2025-06-13 19:00:05 +08:00
|
|
|
|
|
|
|
|
|
|
}
|
2025-02-06 16:36:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-03-28 18:08:21 +08:00
|
|
|
|
void DrawingPanel::onSignal_addGraphicsItem(modelStateInfo& info)
|
2025-02-06 16:36:50 +08:00
|
|
|
|
{
|
|
|
|
|
|
if(m_pSelectorManager)
|
|
|
|
|
|
{
|
|
|
|
|
|
m_pSelectorManager->setWorkingSelector(ST_cerating);
|
2025-03-28 18:08:21 +08:00
|
|
|
|
m_pSelectorManager->setDrawGraphicsItem(info);
|
2025-02-06 16:36:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-06-27 19:17:04 +08:00
|
|
|
|
void DrawingPanel::onSignal_Generate()
|
|
|
|
|
|
{
|
|
|
|
|
|
if(m_pDiagramNameInputer == nullptr){
|
|
|
|
|
|
m_pDiagramNameInputer = new ProjectDiagramNameInput(this);
|
|
|
|
|
|
m_pDiagramNameInputer->setModel(_pModel);
|
2025-07-04 18:47:49 +08:00
|
|
|
|
connect(m_pDiagramNameInputer,&ProjectDiagramNameInput::onGenerateClicked,_pModel,&FixedPortsModel::onSignal_generateDiagram);
|
2025-06-27 19:17:04 +08:00
|
|
|
|
}
|
|
|
|
|
|
m_pDiagramNameInputer->show();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-02-06 16:36:50 +08:00
|
|
|
|
QJsonObject DrawingPanel::getDiagramInfo() const
|
|
|
|
|
|
{
|
|
|
|
|
|
QJsonObject obj;
|
|
|
|
|
|
QJsonArray arr;
|
|
|
|
|
|
if(_pModel)
|
|
|
|
|
|
{
|
|
|
|
|
|
QMap<QUuid,QPointF> map = _pModel->allNodePos();
|
|
|
|
|
|
for(auto iter = map.begin();iter != map.end();++iter)
|
|
|
|
|
|
{
|
|
|
|
|
|
QJsonObject node;
|
|
|
|
|
|
node["id"] = iter.key().toString();
|
|
|
|
|
|
node["x"] = iter.value().x();
|
|
|
|
|
|
node["y"] = iter.value().y();
|
|
|
|
|
|
arr.append(node);
|
|
|
|
|
|
}
|
|
|
|
|
|
obj["nodes"] = arr;
|
|
|
|
|
|
|
|
|
|
|
|
QJsonArray arrConnect;
|
2025-07-11 18:13:54 +08:00
|
|
|
|
QVector<ModelProperty*> vec = _pModel->allConnectionProperty();
|
|
|
|
|
|
for(auto& pPro:vec){
|
|
|
|
|
|
Connection con = pPro->getConnection();
|
2025-02-06 16:36:50 +08:00
|
|
|
|
QJsonObject connect;
|
2025-07-11 18:13:54 +08:00
|
|
|
|
connect["id"] = pPro->uuid().toString();
|
|
|
|
|
|
connect["SrcNodeId"] = con.nSrcNodeId.toString();
|
|
|
|
|
|
connect["SrcPortId"] = con.nSrcPortId.toString();
|
|
|
|
|
|
connect["DestNodeId"] = con.nDestNodeId.toString();
|
|
|
|
|
|
connect["DestPortId"] = con.nDestPortId.toString();
|
2025-02-06 16:36:50 +08:00
|
|
|
|
arrConnect.append(connect);
|
|
|
|
|
|
}
|
|
|
|
|
|
obj["connections"] = arrConnect;
|
2025-07-18 18:26:13 +08:00
|
|
|
|
|
|
|
|
|
|
QJsonArray arrBay;
|
|
|
|
|
|
QMap<QUuid,ElectricBayItem*> mapBay = _pModel->allBayItem();
|
|
|
|
|
|
for(auto& bayItem:mapBay){
|
|
|
|
|
|
AbstractProperty* pPro = bayItem->getProperty();
|
|
|
|
|
|
BayProperty* pBay = dynamic_cast<BayProperty*>(pPro);
|
|
|
|
|
|
if(pBay)
|
|
|
|
|
|
{
|
|
|
|
|
|
QJsonObject bay;
|
|
|
|
|
|
bay["id"] = pBay->uuid().toString();
|
|
|
|
|
|
arrBay.append(bay);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
obj["bays"] = arrBay;
|
2025-02-06 16:36:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
return obj;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DrawingPanel::loadNodes(QJsonObject obj)
|
|
|
|
|
|
{
|
|
|
|
|
|
QJsonArray nodesJsonArray = obj["nodes"].toArray();
|
|
|
|
|
|
|
|
|
|
|
|
for (QJsonValueRef nodeJson : nodesJsonArray)
|
|
|
|
|
|
{
|
|
|
|
|
|
QJsonObject node = nodeJson.toObject();
|
|
|
|
|
|
QString uuid = node["id"].toString();
|
|
|
|
|
|
double dX = node["x"].toDouble();
|
|
|
|
|
|
double dY = node["y"].toDouble();
|
|
|
|
|
|
|
|
|
|
|
|
//componentInfo info =DataBase::GetInstance()->getComponentInfoByUuid(uuid);
|
|
|
|
|
|
if(_pModel)
|
|
|
|
|
|
{
|
|
|
|
|
|
_pModel->addNodeItem(QUuid(uuid)/*,info.type*/,QPointF(dX,dY));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QJsonArray connectArr = obj["connections"].toArray();
|
|
|
|
|
|
for(QJsonValueRef connectJson:connectArr)
|
|
|
|
|
|
{
|
|
|
|
|
|
QJsonObject connect = connectJson.toObject();
|
2025-07-11 18:13:54 +08:00
|
|
|
|
QUuid id = QUuid(connect["id"].toString()); //电缆线id,关联component中的电缆
|
2025-02-06 16:36:50 +08:00
|
|
|
|
QUuid srcId = QUuid(connect["SrcNodeId"].toString());
|
2025-05-16 19:20:46 +08:00
|
|
|
|
QUuid srcPortId = QUuid(connect["SrcPortId"].toString());
|
2025-02-06 16:36:50 +08:00
|
|
|
|
QUuid destId = QUuid(connect["DestNodeId"].toString());
|
2025-05-16 19:20:46 +08:00
|
|
|
|
QUuid destPortId = QUuid(connect["DestPortId"].toString());
|
2025-02-06 16:36:50 +08:00
|
|
|
|
|
2025-05-16 19:20:46 +08:00
|
|
|
|
PowerConnection* pCon = TopologyManager::instance().connection(srcPortId.toString(),destPortId.toString());
|
|
|
|
|
|
if(pCon)
|
|
|
|
|
|
{
|
|
|
|
|
|
QString srcItemId = pCon->fromComponent();
|
|
|
|
|
|
QString destItemId = pCon->toComponent();
|
|
|
|
|
|
//todo:从拓扑结构中查找port的id
|
|
|
|
|
|
if(_pModel)
|
|
|
|
|
|
{
|
2025-07-11 18:13:54 +08:00
|
|
|
|
_pModel->addConnectLline(id,QUuid(srcItemId),QUuid(destItemId),srcPortId,destPortId);
|
2025-05-16 19:20:46 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
2025-02-06 16:36:50 +08:00
|
|
|
|
{
|
2025-05-16 19:20:46 +08:00
|
|
|
|
//todo:提示拓扑结构已改变
|
2025-02-06 16:36:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-07-18 18:26:13 +08:00
|
|
|
|
QJsonArray bayArr = obj["bays"].toArray();
|
|
|
|
|
|
for(QJsonValueRef bayJson:bayArr)
|
|
|
|
|
|
{
|
|
|
|
|
|
QJsonObject bay = bayJson.toObject();
|
|
|
|
|
|
QUuid id = QUuid(bay["id"].toString());
|
|
|
|
|
|
if(_pModel)
|
|
|
|
|
|
{
|
|
|
|
|
|
_pModel->addBayItem(id);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-02-06 16:36:50 +08:00
|
|
|
|
if(_mode == DM_run)
|
|
|
|
|
|
{
|
|
|
|
|
|
if(_pModel)
|
|
|
|
|
|
_pModel->startHttpRequest();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DrawingPanel::saveNodes(int pageId)
|
|
|
|
|
|
{
|
|
|
|
|
|
if(_pModel)
|
|
|
|
|
|
_pModel->saveNode(pageId);
|
|
|
|
|
|
}
|