2407 lines
93 KiB
C++
2407 lines
93 KiB
C++
#include "graphicsDataModel/fixedPortsModel.h"
|
||
#include "graphicsItem/graphicsBaseItem.h"
|
||
#include "graphicsItem/electricBayItem.h"
|
||
#include "graphicsItem/electricBayItem.h"
|
||
|
||
#include "graphicsItem/functionModelItem/electricFunctionModelSvgItemCB.h"
|
||
#include "graphicsItem/functionModelItem/electricFunctionModelPortItem.h"
|
||
#include "graphicsItem/functionModelItem/electricFunctionModelSvgItemBus.h"
|
||
#include "graphicsItem/functionModelItem/electricFunctionModelSvgGroupCT.h"
|
||
#include "graphicsItem/functionModelItem/electricFunctionModelSvgGroupPT.h"
|
||
#include "graphicsItem/functionModelItem/electricFunctionModelSvgItemDS.h"
|
||
#include "graphicsItem/functionModelItem/electricFunctionModelSvgItemES.h"
|
||
#include "graphicsItem/functionModelItem/electricFunctionModelSvgItemFES.h"
|
||
#include "graphicsItem/functionModelItem/electricFunctionModelSvgItemDTEDS.h"
|
||
#include "graphicsItem/functionModelItem/electricFunctionModelSvgItemPI.h"
|
||
#include "graphicsItem/functionModelItem/electricFunctionModelSvgItemLA.h"
|
||
#include "graphicsItem/functionModelItem/electricFunctionModelSvgItemCableTer.h"
|
||
#include "graphicsItem/functionModelItem/electricFunctionModelSvgItemCableEnd.h"
|
||
#include "graphicsItem/functionModelItem/electricFunctionModelSvgItem2wTransformer.h"
|
||
#include "graphicsItem/functionModelItem/electricFunctionModelSvgItem3wTransformer.h"
|
||
#include "graphicsItem/functionModelItem/electricFunctionModelConnectLineItem.h"
|
||
|
||
#include "graphicsItem/itemPort.h"
|
||
#include "designerScene.h"
|
||
#include "dataBase.h"
|
||
#include "httpInterface.h"
|
||
#include "itemPropertyDlg.h"
|
||
#include "dataManager.h"
|
||
#include "powerEntity.h"
|
||
#include "topologyManager.h"
|
||
#include "basePropertyManager.h"
|
||
#include "diagramCavas.h"
|
||
#include <QJsonArray>
|
||
#include <QMessageBox>
|
||
#include <QRandomGenerator>
|
||
#include <QJsonDocument>
|
||
#include <QMdiSubWindow>
|
||
#include <QCryptographicHash>
|
||
#include "baseProperty.h"
|
||
#include "bayManagerDlg.h"
|
||
#include "projectModelManager.h"
|
||
#include "projectIconSetting.h"
|
||
#include "monitorPanel.h"
|
||
#include "designerView.h"
|
||
#include "uiCommunicationBus.h"
|
||
#include "instance/dataAccessor.h"
|
||
#include "graphicsItem/handleText.h"
|
||
#include "bayMeasureDlg.h"
|
||
#include "basePannelPropertyProxy.h"
|
||
#include "common/core_model/types.h"
|
||
|
||
bool FixedPortsModel::_dataInitialised = false;
|
||
|
||
FixedPortsModel::FixedPortsModel(PowerEntity* pEntity)
|
||
:_scene(nullptr)
|
||
,_widget(nullptr)
|
||
,_Interface(nullptr)
|
||
,_pEntity(pEntity)
|
||
,m_projectIconSettingDlg(nullptr)
|
||
,m_pBayManager(nullptr)
|
||
,m_curPropertyDlg(nullptr)
|
||
,m_dataTimer(nullptr)
|
||
,m_bayMeasureDlg(nullptr)
|
||
{
|
||
_cavas = nullptr;
|
||
loadNodeDataFromDataBase();
|
||
ProjectModelManager::instance().initialHMISourcr();
|
||
_Interface = new HttpInterface(this);
|
||
_timer = new QTimer(this);
|
||
m_dataTimer = new QTimer(this);
|
||
|
||
_modelStateInfo = DataManager::instance().modelState();
|
||
_modelDataInfo = DataManager::instance().modelData();
|
||
initialPropertyDlg();
|
||
connect(_timer,SIGNAL(timeout()),this,SLOT(onTimeOut()));
|
||
connect(m_dataTimer,&QTimer::timeout,this,&FixedPortsModel::onDataTimerOut);
|
||
m_dataTimer->setInterval(2000);
|
||
connect(_Interface,&HttpInterface::sendPointData,this,&FixedPortsModel::onSignal_GetPointData);
|
||
}
|
||
|
||
FixedPortsModel::~FixedPortsModel()
|
||
{
|
||
_cavas.clear();
|
||
}
|
||
|
||
QMap<QUuid,ItemPageInfo> FixedPortsModel::allNodePos() const
|
||
{
|
||
QMap<QUuid,ItemPageInfo> map;
|
||
for(auto pItem:_nodeItem)
|
||
{
|
||
if(pItem->getItemType() != GIT_link){
|
||
ItemPageInfo info;
|
||
double dWidth = pItem->boundingRect().width();
|
||
double dHeight = pItem->boundingRect().height();
|
||
info.pos = pItem->scenePos()/*+QPointF(dWidth*0.5,dHeight*0.5)*/;
|
||
info.dWidth = dWidth;
|
||
info.dHeight = dHeight;
|
||
info.dRotate = pItem->rotation();
|
||
map.insert(pItem->itemId(),info);
|
||
}
|
||
}
|
||
return map;
|
||
}
|
||
|
||
QVector<ModelProperty*> FixedPortsModel::allConnectionProperty()
|
||
{
|
||
QVector<ModelProperty*> vec;
|
||
for(auto pItem:_nodeItem)
|
||
{
|
||
if(pItem->getItemType() == GIT_link)
|
||
{
|
||
auto pLine = dynamic_cast<ElectricFunctionModelConnectLineItem*>(pItem);
|
||
if(pLine)
|
||
{
|
||
ModelProperty* pPro = pLine->getProperty();
|
||
if(pPro){
|
||
vec.push_back(pPro);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
return vec;
|
||
}
|
||
|
||
QMap<QUuid,GraphicsFunctionModelItem*>& FixedPortsModel::allItems()
|
||
{
|
||
return _nodeItem;
|
||
}
|
||
|
||
GraphicsFunctionModelItem* FixedPortsModel::nodeItem(QUuid uuid)
|
||
{
|
||
return _nodeItem.value(uuid,nullptr);
|
||
}
|
||
|
||
bool FixedPortsModel::addNodeItem(QUuid uuid,GraphicsFunctionModelItem* pItem)
|
||
{
|
||
|
||
if(_nodeItem.contains(uuid))
|
||
return false;
|
||
else
|
||
{
|
||
pItem->setHandle(this);
|
||
_nodeItem.insert(uuid,pItem);
|
||
//connect(pItem,&GraphicsFunctionModelItem::ifExist,this,&FixedPortsModel::onSignal_ifExits);
|
||
connect(pItem,&GraphicsBaseItem::itemRotated,this,[this](GraphicsBaseItem* pBase){
|
||
if(pBase){
|
||
auto pPro = pBase->getProperty();
|
||
QUuid uid = pPro->uuid();
|
||
if(pPro->type() != 8){ //排除线
|
||
updateItemLinePort(uid,ModelFunctionType::ProjectModel); //hmi不改变拓扑结构,继续使用系统图的连接关系
|
||
}
|
||
}
|
||
});
|
||
return true;
|
||
}
|
||
}
|
||
|
||
QString FixedPortsModel::addNodeItem(QUuid id,QPointF pos,double width,double height,double rotate)
|
||
{
|
||
//todo:load图形时必有拓扑实体,关联到对应的entity
|
||
BaseProperty* pro = nullptr;
|
||
GraphicsFunctionModelItem* item = nullptr;
|
||
QMap<QUuid,BaseProperty*> mapData = BasePropertyManager::instance().getEntityData(); //加载的图形必定关联component(todo:完善判断条件,如判断拓扑节点)
|
||
|
||
if(mapData.contains(id))
|
||
{
|
||
pro = mapData.value(id);
|
||
if(pro)
|
||
{
|
||
int type = pro->graphicsType();
|
||
if(type == GIT_link) //连线对象外部处理
|
||
return QString("err");
|
||
QString sMeta = pro->metaModelName();
|
||
QString sProModel = pro->modelName();
|
||
|
||
ModelDataInfo mapValue = DataManager::instance().modelData()[sProModel];
|
||
PropertyValueInfo valueInfo; //属性组设置的数据 (ct,pt二次绕组)
|
||
if(mapValue.groupInfo.contains("base_extend"))
|
||
{
|
||
valueInfo = mapValue.groupInfo["base_extend"].mapInfo[id];
|
||
}
|
||
|
||
double dX = 0.0;
|
||
double dY = 0.0;
|
||
if(type == GIT_itemRect)
|
||
{
|
||
PropertyModel model = ProjectModelManager::instance().getData()[sMeta][sProModel];
|
||
QByteArray svg;
|
||
if(model.modelSetting.mapSvg.isEmpty()){
|
||
svg = DataBase::GetInstance()->ModelType()[3].icon;
|
||
}
|
||
else{
|
||
svg = ProjectModelManager::instance().getData()[sMeta][sProModel].modelSetting.mapUsedSvg["cb"];
|
||
}
|
||
|
||
if(width == 0 && height == 0){
|
||
dX = 30;
|
||
dY = 30;
|
||
}
|
||
else{
|
||
dX = width;
|
||
dY = height;
|
||
}
|
||
|
||
auto pCb = new ElectricFunctionModelSvgItemCB(QRect(-dX*0.5, -dY*0.5, dX, dY),false);
|
||
pCb->setItemType(GIT_itemRect);
|
||
pCb->loadSvg(svg);
|
||
item = pCb;
|
||
QJsonArray portArr = pro->context()["port"].toArray();
|
||
addPortsToItem_json(P_const,portArr,item);
|
||
}
|
||
else if(type == GIT_node)
|
||
{
|
||
auto pNode = new ElectricFunctionModelPortItem();
|
||
pNode->setItemType(GIT_node);
|
||
item = pNode;
|
||
|
||
QJsonArray portArr = pro->context()["port"].toArray();
|
||
addPortsToItem_json(p_movable,portArr,item);
|
||
}
|
||
else if(type == GIT_bus)
|
||
{
|
||
PropertyModel model = ProjectModelManager::instance().getData()[sMeta][sProModel];
|
||
QByteArray svg;
|
||
if(model.modelSetting.mapSvg.isEmpty()){
|
||
svg = DataBase::GetInstance()->ModelType()[1].icon;
|
||
}
|
||
else{
|
||
svg = ProjectModelManager::instance().getData()[sMeta][sProModel].modelSetting.mapUsedSvg["bus"];
|
||
}
|
||
|
||
if(width == 0 && height == 0){
|
||
dX = 200;
|
||
dY = 6;
|
||
}
|
||
else{
|
||
dX = width;
|
||
dY = height;
|
||
}
|
||
|
||
auto pBus = new ElectricFunctionModelSvgItemBus(QRect(0, 0, dX, dY));
|
||
pBus->setItemType(GIT_bus);
|
||
pBus->loadSvg(svg);
|
||
item = pBus;
|
||
|
||
QJsonArray portArr = pro->context()["port"].toArray();
|
||
addPortsToItem_json(p_movable,portArr,item);
|
||
}
|
||
else if(type == GIT_ctGroup)
|
||
{
|
||
PropertyModel model = ProjectModelManager::instance().getData()[sMeta][sProModel];
|
||
QByteArray svg;
|
||
if(model.modelSetting.mapSvg.isEmpty()){
|
||
svg = DataBase::GetInstance()->ModelType()[5].icon;
|
||
}
|
||
else{
|
||
svg = model.modelSetting.mapSvg.first();
|
||
}
|
||
|
||
if(width == 0 && height == 0){
|
||
dX = 20;
|
||
dY = 20;
|
||
}
|
||
else{
|
||
dX = width;
|
||
dY = height;
|
||
}
|
||
|
||
auto pCt = new ElectricFunctionModelSvgGroupCT(QRect(-dX*0.5, -dY*0.5, dX, dY));
|
||
pCt->updateMapSvg(ProjectModelManager::instance().getData()[sMeta][sProModel].modelSetting.mapUsedSvg);
|
||
pCt->setItemType(GIT_ctGroup);
|
||
item = pCt;
|
||
QJsonArray portArr = pro->context()["port"].toArray();
|
||
|
||
addPortsToItem_json(P_const,portArr,item);
|
||
if(!valueInfo.isEmpty()){ //使用设置的绕组数更新自己
|
||
int nCtSize = 0; //ct设置的个数
|
||
int nCtType = 0; //ct类型 1三相0零相
|
||
if(valueInfo.contains("ct_winding")){
|
||
PropertyStateInfo val = valueInfo.value("ct_winding");
|
||
|
||
QJsonDocument jsonDocument = QJsonDocument::fromJson(val.defaultValue.toString().toUtf8().data());
|
||
if(!jsonDocument.isNull()){
|
||
QJsonObject obj = jsonDocument.object();
|
||
if(obj.contains("winding")){
|
||
QJsonArray arr = obj["winding"].toArray();
|
||
nCtSize = arr.size();
|
||
}
|
||
}
|
||
}
|
||
if(valueInfo.contains("phase_num")){
|
||
PropertyStateInfo val = valueInfo.value("phase_num");
|
||
nCtType = val.defaultValue.toInt();
|
||
}
|
||
|
||
QPair<int,int> pair(nCtType,nCtSize);
|
||
QVariant var = QVariant::fromValue(pair);
|
||
pCt->setupFinish(var);
|
||
}
|
||
|
||
}
|
||
else if(type == GIT_ptGroup)
|
||
{
|
||
PropertyModel model = ProjectModelManager::instance().getData()[sMeta][sProModel];
|
||
QByteArray svg;
|
||
if(model.modelSetting.mapSvg.isEmpty()){
|
||
svg = DataBase::GetInstance()->ModelType()[6].icon;
|
||
}
|
||
else{
|
||
svg = model.modelSetting.mapSvg.first();
|
||
}
|
||
|
||
if(width == 0 && height == 0){
|
||
dX = 50;
|
||
dY = 50;
|
||
}
|
||
else{
|
||
dX = width;
|
||
dY = height;
|
||
}
|
||
|
||
auto pPt = new ElectricFunctionModelSvgGroupPT(QRect(-dX*0.5, -dY*0.5, dX, dY));
|
||
pPt->updateMapSvg(ProjectModelManager::instance().getData()[sMeta][sProModel].modelSetting.mapUsedSvg);
|
||
pPt->setItemType(GIT_ptGroup);
|
||
item = pPt;
|
||
QJsonArray portArr = pro->context()["port"].toArray();
|
||
|
||
addPortsToItem_json(P_const,portArr,item);
|
||
if(!valueInfo.isEmpty()){ //使用设置的绕组数更新自己
|
||
QList<int> lst; //二次绕组接法
|
||
if(valueInfo.contains("pt_sec_winding")){
|
||
PropertyStateInfo val = valueInfo.value("pt_sec_winding");
|
||
|
||
QJsonDocument jsonDocument = QJsonDocument::fromJson(val.defaultValue.toString().toUtf8().data());
|
||
if(!jsonDocument.isNull()){
|
||
QJsonObject obj = jsonDocument.object();
|
||
QJsonArray arr = obj["winding"].toArray();
|
||
for (QJsonValueRef jsonObj : arr)
|
||
{
|
||
QJsonObject node = jsonObj.toObject();
|
||
QString sWinding = node["windingConnectionMethod"].toString();
|
||
if(sWinding == "Y"){
|
||
lst.append(1);
|
||
}
|
||
else{
|
||
lst.append(0);
|
||
}
|
||
}
|
||
}
|
||
|
||
QVariant var = QVariant::fromValue(lst);
|
||
pPt->setupFinish(var);
|
||
}
|
||
}
|
||
}
|
||
else if(type == GIT_DS)
|
||
{
|
||
PropertyModel model = ProjectModelManager::instance().getData()[sMeta][sProModel];
|
||
QByteArray svg;
|
||
if(model.modelSetting.mapSvg.isEmpty()){
|
||
svg = DataBase::GetInstance()->ModelType()[7].icon;
|
||
}
|
||
else{
|
||
svg = ProjectModelManager::instance().getData()[sMeta][sProModel].modelSetting.mapUsedSvg["ds"];
|
||
}
|
||
|
||
if(width == 0 && height == 0){
|
||
dX = 30;
|
||
dY = 30;
|
||
}
|
||
else{
|
||
dX = width;
|
||
dY = height;
|
||
}
|
||
|
||
auto pDs = new ElectricFunctionModelSvgItemDS(QRect(-dX*0.5, -dY*0.5, dX, dY));
|
||
pDs->setItemType(GIT_DS);
|
||
pDs->loadSvg(svg);
|
||
item = pDs;
|
||
QJsonArray portArr = pro->context()["port"].toArray();
|
||
|
||
addPortsToItem_json(P_const,portArr,item);
|
||
}
|
||
else if(type == GIT_ES)
|
||
{
|
||
PropertyModel model = ProjectModelManager::instance().getData()[sMeta][sProModel];
|
||
QByteArray svg;
|
||
if(model.modelSetting.mapSvg.isEmpty()){
|
||
svg = DataBase::GetInstance()->ModelType()[8].icon;
|
||
}
|
||
else{
|
||
svg = ProjectModelManager::instance().getData()[sMeta][sProModel].modelSetting.mapUsedSvg["es"];
|
||
}
|
||
|
||
if(width == 0 && height == 0){
|
||
dX = 30;
|
||
dY = 60;
|
||
}
|
||
else{
|
||
dX = width;
|
||
dY = height;
|
||
}
|
||
|
||
auto pEs = new ElectricFunctionModelSvgItemES(QRect(-dX*0.5, -dY*0.5, dX, dY));
|
||
pEs->setItemType(GIT_ES);
|
||
pEs->loadSvg(svg);
|
||
item = pEs;
|
||
QJsonArray portArr = pro->context()["port"].toArray();
|
||
|
||
addPortsToItem_json(P_const,portArr,item);
|
||
}
|
||
else if(type == GIT_FES)
|
||
{
|
||
PropertyModel model = ProjectModelManager::instance().getData()[sMeta][sProModel];
|
||
QByteArray svg;
|
||
if(model.modelSetting.mapSvg.isEmpty()){
|
||
svg = DataBase::GetInstance()->ModelType()[9].icon;
|
||
}
|
||
else{
|
||
svg = ProjectModelManager::instance().getData()[sMeta][sProModel].modelSetting.mapUsedSvg["fes"];
|
||
}
|
||
|
||
if(width == 0 && height == 0){
|
||
dX = 30;
|
||
dY = 60;
|
||
}
|
||
else{
|
||
dX = width;
|
||
dY = height;
|
||
}
|
||
|
||
auto pFes = new ElectricFunctionModelSvgItemFES(QRect(-dX*0.5, -dY*0.5, dX, dY));
|
||
pFes->setItemType(GIT_FES);
|
||
pFes->loadSvg(svg);
|
||
item = pFes;
|
||
QJsonArray portArr = pro->context()["port"].toArray();
|
||
|
||
addPortsToItem_json(P_const,portArr,item);
|
||
}
|
||
else if(type == GIT_DTEDS)
|
||
{
|
||
PropertyModel model = ProjectModelManager::instance().getData()[sMeta][sProModel];
|
||
QByteArray svg;
|
||
if(model.modelSetting.mapSvg.isEmpty()){
|
||
svg = DataBase::GetInstance()->ModelType()[10].icon;
|
||
}
|
||
else{
|
||
svg = ProjectModelManager::instance().getData()[sMeta][sProModel].modelSetting.mapUsedSvg["dteds"];
|
||
}
|
||
|
||
if(width == 0 && height == 0){
|
||
dX = 60;
|
||
dY = 30;
|
||
}
|
||
else{
|
||
dX = width;
|
||
dY = height;
|
||
}
|
||
|
||
auto pDteds = new ElectricFunctionModelSvgItemDTEDS(QRect(-dX*0.5, -dY*0.5, dX, dY));
|
||
pDteds->setItemType(GIT_DTEDS);
|
||
pDteds->loadSvg(svg);
|
||
item = pDteds;
|
||
QJsonArray portArr = pro->context()["port"].toArray();
|
||
|
||
addPortsToItem_json(P_const,portArr,item);
|
||
}
|
||
else if(type == GIT_PI)
|
||
{
|
||
PropertyModel model = ProjectModelManager::instance().getData()[sMeta][sProModel];
|
||
QByteArray svg;
|
||
if(model.modelSetting.mapSvg.isEmpty()){
|
||
svg = DataBase::GetInstance()->ModelType()[11].icon;
|
||
}
|
||
else{
|
||
svg = ProjectModelManager::instance().getData()[sMeta][sProModel].modelSetting.mapUsedSvg["potential_indicator"];
|
||
}
|
||
|
||
if(width == 0 && height == 0){
|
||
dX = 30;
|
||
dY = 60;
|
||
}
|
||
else{
|
||
dX = width;
|
||
dY = height;
|
||
}
|
||
|
||
auto pPi = new ElectricFunctionModelSvgItemPI(QRect(-dX*0.5, -dY*0.5, dX, dY));
|
||
pPi->setItemType(GIT_PI);
|
||
pPi->loadSvg(svg);
|
||
item = pPi;
|
||
QJsonArray portArr = pro->context()["port"].toArray();
|
||
|
||
addPortsToItem_json(P_const,portArr,item);
|
||
}
|
||
else if(type == GIT_LA)
|
||
{
|
||
PropertyModel model = ProjectModelManager::instance().getData()[sMeta][sProModel];
|
||
QByteArray svg;
|
||
if(model.modelSetting.mapSvg.isEmpty()){
|
||
svg = DataBase::GetInstance()->ModelType()[12].icon;
|
||
}
|
||
else{
|
||
svg = ProjectModelManager::instance().getData()[sMeta][sProModel].modelSetting.mapUsedSvg["lightning_arrester"];
|
||
}
|
||
|
||
if(width == 0 && height == 0){
|
||
dX = 30;
|
||
dY = 60;
|
||
}
|
||
else{
|
||
dX = width;
|
||
dY = height;
|
||
}
|
||
|
||
auto pLa = new ElectricFunctionModelSvgItemLA(QRect(-dX*0.5, -dY*0.5, dX, dY));
|
||
pLa->setItemType(GIT_LA);
|
||
pLa->loadSvg(svg);
|
||
item = pLa;
|
||
QJsonArray portArr = pro->context()["port"].toArray();
|
||
|
||
addPortsToItem_json(P_const,portArr,item);
|
||
}
|
||
else if(type == GIT_cableTer)
|
||
{
|
||
PropertyModel model = ProjectModelManager::instance().getData()[sMeta][sProModel];
|
||
QByteArray svg;
|
||
if(model.modelSetting.mapSvg.isEmpty()){
|
||
svg = DataBase::GetInstance()->ModelType()[13].icon;
|
||
}
|
||
else{
|
||
svg = ProjectModelManager::instance().getData()[sMeta][sProModel].modelSetting.mapUsedSvg["cable_termination"];
|
||
}
|
||
|
||
if(width == 0 && height == 0){
|
||
dX = 20;
|
||
dY = 20;
|
||
}
|
||
else{
|
||
dX = width;
|
||
dY = height;
|
||
}
|
||
|
||
auto pCt = new ElectricFunctionModelSvgItemCableTer(QRect(-dX*0.5, -dY*0.5, dX, dY));
|
||
pCt->setItemType(GIT_cableTer);
|
||
pCt->loadSvg(svg);
|
||
item = pCt;
|
||
QJsonArray portArr = pro->context()["port"].toArray();
|
||
|
||
addPortsToItem_json(P_const,portArr,item);
|
||
}
|
||
else if(type == GIT_cableEnd)
|
||
{
|
||
PropertyModel model = ProjectModelManager::instance().getData()[sMeta][sProModel];
|
||
QByteArray svg;
|
||
if(model.modelSetting.mapSvg.isEmpty()){
|
||
svg = DataBase::GetInstance()->ModelType()[14].icon;
|
||
}
|
||
else{
|
||
svg = ProjectModelManager::instance().getData()[sMeta][sProModel].modelSetting.mapUsedSvg["cable_end"];
|
||
}
|
||
|
||
if(width == 0 && height == 0){
|
||
dX = 20;
|
||
dY = 20;
|
||
}
|
||
else{
|
||
dX = width;
|
||
dY = height;
|
||
}
|
||
|
||
auto pCe = new ElectricFunctionModelSvgItemCableEnd(QRect(-dX*0.5, -dY*0.5, dX, dY));
|
||
pCe->setItemType(GIT_cableEnd);
|
||
pCe->loadSvg(svg);
|
||
item = pCe;
|
||
QJsonArray portArr = pro->context()["port"].toArray();
|
||
|
||
addPortsToItem_json(P_const,portArr,item);
|
||
}
|
||
else if(type == GIT_2wTransformer)
|
||
{
|
||
PropertyModel model = ProjectModelManager::instance().getData()[sMeta][sProModel];
|
||
QByteArray svg;
|
||
if(model.modelSetting.mapSvg.isEmpty()){
|
||
svg = DataBase::GetInstance()->ModelType()[15].icon;
|
||
}
|
||
else{
|
||
svg = ProjectModelManager::instance().getData()[sMeta][sProModel].modelSetting.mapUsedSvg["transformer_2w"];
|
||
}
|
||
|
||
if(width == 0 && height == 0){
|
||
dX = 100;
|
||
dY = 100;
|
||
}
|
||
else{
|
||
dX = width;
|
||
dY = height;
|
||
}
|
||
|
||
auto p2w = new ElectricFunctionModelSvgItem2wTransformer(QRect(-dX*0.5, -dY*0.5, dX, dY));
|
||
p2w->setItemType(GIT_2wTransformer);
|
||
p2w->loadSvg(svg);
|
||
item = p2w;
|
||
QJsonArray portArr = pro->context()["port"].toArray();
|
||
|
||
addPortsToItem_json(P_const,portArr,item);
|
||
}
|
||
else if(type == GIT_3wTransformer)
|
||
{
|
||
PropertyModel model = ProjectModelManager::instance().getData()[sMeta][sProModel];
|
||
QByteArray svg;
|
||
if(model.modelSetting.mapSvg.isEmpty()){
|
||
svg = DataBase::GetInstance()->ModelType()[16].icon;
|
||
}
|
||
else{
|
||
svg = ProjectModelManager::instance().getData()[sMeta][sProModel].modelSetting.mapUsedSvg["transformer_3w"];
|
||
}
|
||
|
||
if(width == 0 && height == 0){
|
||
dX = 100;
|
||
dY = 100;
|
||
}
|
||
else{
|
||
dX = width;
|
||
dY = height;
|
||
}
|
||
|
||
auto p3w = new ElectricFunctionModelSvgItem3wTransformer(QRect(-dX*0.5, -dY*0.5, dX, dY));
|
||
p3w->setItemType(GIT_3wTransformer);
|
||
p3w->loadSvg(svg);
|
||
item = p3w;
|
||
QJsonArray portArr = pro->context()["port"].toArray();
|
||
|
||
addPortsToItem_json(P_const,portArr,item);
|
||
}
|
||
if(item)
|
||
{
|
||
item->setItemId(id);
|
||
item->editShape(0, pos);
|
||
item->setPos(pos);
|
||
item->setRotation(rotate);
|
||
_scene->addItem(item);
|
||
item->addPoint(pos);
|
||
item->setProperty(pro); //绑定模型
|
||
item->updateByProperty(); //使用模型更新自身
|
||
item->setHandle(this);
|
||
_nodeItem.insert(id,item);
|
||
//connect(item,&GraphicsFunctionModelItem::ifExist,this,&FixedPortsModel::onSignal_ifExits);
|
||
connect(item,&GraphicsBaseItem::itemRotated,this,[this](GraphicsBaseItem* pBase){
|
||
if(pBase){
|
||
auto pPro = pBase->getProperty();
|
||
QUuid uid = pPro->uuid();
|
||
if(pPro->type() != 8){ //排除线
|
||
updateItemLinePort(uid,ModelFunctionType::ProjectModel); //hmi不改变拓扑结构,继续使用系统图的连接关系
|
||
}
|
||
}
|
||
});
|
||
}
|
||
return pro->name();
|
||
}
|
||
}
|
||
return QString("err");
|
||
}
|
||
|
||
BaseProperty* FixedPortsModel::addNodeData(QUuid id,int type,QString name,QString modelName)
|
||
{
|
||
BaseProperty* pData = BasePropertyManager::instance().findEntityData(id); //已存在不不创建
|
||
if(pData != nullptr)
|
||
return pData;
|
||
|
||
VariableProperty* item = new VariableProperty();
|
||
//todo:关联到对应data
|
||
|
||
if(item)
|
||
{
|
||
item->setUuid(id);
|
||
item->setModelName(modelName);
|
||
item->setType(type);
|
||
GraphicsItemType localType = typeToProGraphic[type]; //将通用类型转换为工程模图元
|
||
item->setGraphicsType(localType);
|
||
item->setTag(name);
|
||
item->setName(name);
|
||
item->setDataChanged(true);
|
||
BasePropertyManager::instance().insertEntityData(id,item);
|
||
}
|
||
return item;
|
||
}
|
||
|
||
void FixedPortsModel::loadNodeDataFromDataBase()
|
||
{
|
||
if(!_dataInitialised)
|
||
{
|
||
QList<ComponentInfo> lst= DataBase::GetInstance()->getAllComponents();
|
||
for(auto &info:lst)
|
||
{
|
||
QString preTag = removeSuffix(info.tag);
|
||
QString prePath = removeSuffix(info.nspath);
|
||
BaseProperty* pData = addNodeData(info.uuid,info.type,info.name,info.modelName);
|
||
pData->setTag(preTag);
|
||
pData->setName(info.name);
|
||
pData->setPath(prePath);
|
||
pData->setDescription(info.description);
|
||
pData->setInService(info.inService);
|
||
pData->setState(info.state);
|
||
pData->setStatus(info.status);
|
||
pData->setConnectedBus(info.connected_bus);
|
||
pData->setLabel(info.label);
|
||
pData->setContext(info.context);
|
||
pData->setGrid(info.grid);
|
||
pData->setZone(info.zone);
|
||
pData->setStation(info.station);
|
||
pData->setBay(prePath);
|
||
pData->setDataChanged(false);
|
||
|
||
QString sMeta = info.context["metaModel"].toString();
|
||
pData->setMetaModelName(sMeta);
|
||
|
||
double dVoltage = info.context["extraInfo"].toDouble();
|
||
pData->setVoltageLevel(dVoltage);
|
||
|
||
QJsonArray nodesJsonArray = info.context["subList"].toArray();
|
||
QList<QPair<int, QUuid>> lst;
|
||
for (QJsonValueRef nodeJson : nodesJsonArray)
|
||
{
|
||
QJsonObject node = nodeJson.toObject();
|
||
int nCategory = node["category"].toInt();
|
||
QUuid uid = QUuid(node["uuid"].toString());
|
||
lst.append(qMakePair(nCategory,uid));
|
||
}
|
||
pData->setSubList(lst);
|
||
|
||
PowerEntity* pEntity = TopologyManager::instance().createEntity(EntityType::Component,info.uuid.toString(),info.name); //首先load所有data和entity,全局唯一
|
||
if(pEntity){
|
||
createTopoTerminalsByData(pEntity,info.context);
|
||
}
|
||
|
||
QList<MeasurementInfo> lstMeasure = DataBase::GetInstance()->getMeasurement(info.uuid); //添加设备量测
|
||
QMap<QString,MeasurementInfo> mapMeasure;
|
||
for(auto& info:lstMeasure)
|
||
{
|
||
info.tag = removeSuffix(info.tag);
|
||
mapMeasure.insert(info.name,info);
|
||
}
|
||
assignMeasureSymmetry(mapMeasure);
|
||
pData->setMeasurement(mapMeasure);
|
||
}
|
||
|
||
QList<TopologyInfo> lstTopo = DataBase::GetInstance()->getAllTopologics();
|
||
for(auto &info:lstTopo)
|
||
{
|
||
QString from_pin = info.context["from_pin"].toString();
|
||
QString to_pin = info.context["to_pin"].toString();
|
||
|
||
TopologyManager::instance().createConnection(QString::number(info.id),from_pin,to_pin,info.uuid_from.toString(),info.uuid_to.toString());
|
||
}
|
||
|
||
QList<BayInfo> lstBay = DataBase::GetInstance()->getAllBay();
|
||
for(auto& bay:lstBay)
|
||
{
|
||
QString showTag = removeSuffix(bay.tag);
|
||
BayProperty* pBay = addBayData(bay.uuid);
|
||
pBay->setName(bay.name);
|
||
pBay->setTag(showTag);
|
||
pBay->setType(bay.type);
|
||
pBay->setLstComponent(bay.components);
|
||
pBay->setVoltage(bay.unom);
|
||
pBay->setFla(bay.fla);
|
||
pBay->setCapacity(bay.capacity);
|
||
pBay->setInService(bay.inService);
|
||
auto fromLst = turnJsonArrToList(bay.fromUuid,"id","ids");
|
||
pBay->setLstFrom(fromLst);
|
||
auto toLst = turnJsonArrToList(bay.toUuid,"id","ids");
|
||
pBay->setLstTo(toLst);
|
||
auto proptecLst = turnJsonArrToList(bay.protect,"id","ids");
|
||
pBay->setLstProtect(proptecLst);
|
||
auto falRecLst = turnJsonArrToList(bay.faultRec,"id","ids");
|
||
pBay->setLstFaultRecord(falRecLst);
|
||
auto dynSenLst = turnJsonArrToList(bay.dynSense,"id","ids");
|
||
pBay->setLstDynSense(dynSenLst);
|
||
auto staLst = turnJsonArrToList(bay.status,"id","ids");
|
||
pBay->setLstStatus(staLst);
|
||
auto insLst = turnJsonArrToList(bay.instruct,"id","ids");
|
||
pBay->setLstInstruct(insLst);
|
||
auto etcLst = turnJsonArrToList(bay.etc,"id","ids");
|
||
pBay->setLstEtc(etcLst);
|
||
|
||
QMap<QString,MeasurementInfo> mapMeasure;
|
||
QList<MeasurementInfo> tempLst = DataBase::GetInstance()->getBayMeasurement(bay.uuid);
|
||
for(auto& info:tempLst){
|
||
if(info.componentUuid == QUuid("11111111-1111-1111-1111-111111111111")) //只处理间隔外量测
|
||
mapMeasure.insert(info.name,info);
|
||
}
|
||
pBay->setMeasurement(mapMeasure);
|
||
}
|
||
_dataInitialised = true;
|
||
}
|
||
else
|
||
{
|
||
//for(auto p:_nodeData)
|
||
{
|
||
int a = 1;
|
||
}
|
||
}
|
||
}
|
||
|
||
QString FixedPortsModel::addConnectLline(QUuid lineId,QUuid srcId,QUuid destId,QUuid srcPort,QUuid destPort)
|
||
{
|
||
GraphicsFunctionModelItem* src = nullptr;
|
||
if(_nodeItem.contains(srcId))
|
||
src = _nodeItem.value(srcId);
|
||
GraphicsFunctionModelItem* dest = nullptr;
|
||
if(_nodeItem.contains(destId))
|
||
dest = _nodeItem.value(destId);
|
||
QMap<QUuid,BaseProperty*> mapData = BasePropertyManager::instance().getEntityData();
|
||
if(mapData.contains(lineId))
|
||
{
|
||
BaseProperty* pPro = mapData.value(lineId);
|
||
if(src && dest && pPro)
|
||
{
|
||
ElectricFunctionModelConnectLineItem* pItem = new ElectricFunctionModelConnectLineItem();
|
||
pItem->setItemId(lineId);
|
||
pItem->setItemType(GIT_link);
|
||
_scene->addItem(pItem);
|
||
|
||
ItemPort* ptSrc = src->getPortById(srcPort.toString());
|
||
HandleType srcType = ptSrc->getType();
|
||
PortPos srcPos = ptSrc->portPos();
|
||
pItem->setStartPoint(ptSrc->scenePos());
|
||
ptSrc->setConnect(pItem);
|
||
|
||
ItemPort* ptDest = nullptr;
|
||
ptDest = dest->getPortById(destPort.toString());
|
||
pItem->setEndPoint(ptDest->scenePos());
|
||
|
||
if(ptDest != nullptr)
|
||
{
|
||
HandleType destType = ptDest->getType();
|
||
PortPos destPos = ptDest->portPos();
|
||
|
||
pItem->calculatePath();
|
||
|
||
pPro->setConnection(Connection(srcId,srcPort,srcType,srcPos,destId,destPort,destType,destPos));
|
||
ptDest->setConnect(pItem);
|
||
|
||
addNodeItem(pItem->itemId(),pItem);
|
||
pItem->setProperty(pPro);
|
||
}
|
||
|
||
return pPro->name();
|
||
}
|
||
}
|
||
return QString("err");
|
||
}
|
||
|
||
void FixedPortsModel::deleteNodeItem(GraphicsFunctionModelItem* pItem)
|
||
{
|
||
if(pItem->getItemType() == GIT_link)
|
||
{
|
||
auto pLine = dynamic_cast<ElectricFunctionModelConnectLineItem*>(pItem);
|
||
if(pLine)
|
||
{
|
||
QUuid conId = pLine->itemId();
|
||
TopologyManager::instance().removeConnection(conId.toString());
|
||
|
||
PowerConnection* pCon = TopologyManager::instance().connection(conId.toString());
|
||
if(pCon){
|
||
PowerEntity* itemFrom = TopologyManager::instance().getEntityByTerminal(pCon->fromTerminalId());
|
||
PowerEntity* itemTo = TopologyManager::instance().getEntityByTerminal(pCon->toTerminalId());
|
||
if(itemFrom && itemTo)
|
||
{
|
||
_nodeItem.value(QUuid(itemFrom->id()))->setItemChanged(true);
|
||
_nodeItem.value(QUuid(itemTo->id()))->setItemChanged(true);
|
||
}
|
||
}
|
||
|
||
_nodeItem.take(conId);
|
||
_scene->removeItem(pLine);
|
||
delete pLine;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
QUuid srcId = pItem->itemId();
|
||
QList<PowerConnection*> lstCon = TopologyManager::instance().getConnectionsFor(srcId.toString());
|
||
for(auto &con:lstCon)
|
||
{
|
||
PowerEntity* pFrom = TopologyManager::instance().getEntityByTerminal(con->fromTerminalId());
|
||
PowerEntity* pTo = TopologyManager::instance().getEntityByTerminal(con->toTerminalId());
|
||
if(pFrom && pTo)
|
||
{
|
||
if(srcId.toString() == pFrom->id()) //对象是srcItem
|
||
_nodeItem.value(QUuid(pTo->id()))->setItemChanged(true);
|
||
else //对象是toItem
|
||
_nodeItem.value(QUuid(pFrom->id()))->setItemChanged(true);
|
||
}
|
||
|
||
//TopologyManager::instance().removeConnection(con->id()); //删除entity时会同时删除相关连接,无需手动删除
|
||
}
|
||
TopologyManager::instance().deleteEntity(srcId.toString());
|
||
|
||
pItem->setItemChanged(true);
|
||
_nodeItem.take(srcId);
|
||
_scene->removeItem(pItem);
|
||
delete pItem;
|
||
}
|
||
}
|
||
|
||
void FixedPortsModel::saveNode(int nPageId)
|
||
{
|
||
QList<GridInfo> lstGrid = DataBase::GetInstance()->getAllGrid();
|
||
QList<ZoneInfo> lstZone = DataBase::GetInstance()->getAllZone();
|
||
QList<StationInfo> lstStation = DataBase::GetInstance()->getAllStation();
|
||
QMap<int,attributeGroup> groupMap = DataBase::GetInstance()->AttributeGroup(); //属性组名
|
||
bool bExist = DataBase::GetInstance()->componentExist(QUuid("11111111-1111-1111-1111-111111111111").toString());
|
||
bool bSaveFlag = false;
|
||
|
||
for(auto& bay:_bayItem)
|
||
{
|
||
AbstractProperty* pro = bay->getProperty(); //间隔
|
||
BayProperty* pBay = dynamic_cast<BayProperty*>(pro);
|
||
if(pBay){
|
||
bool val = DataBase::GetInstance()->ifBayExist(pBay->uuid());
|
||
QString tempTag = pBay->tag()+"_"+_pageName; //tag后加工程名保持全局唯一
|
||
if(!val){
|
||
QJsonObject objFrom = turnListToJson(pBay->getLstFrom(),"id","ids");
|
||
QJsonObject objTo= turnListToJson(pBay->getLstTo(),"id","ids");
|
||
QJsonObject objProtec= turnListToJson(pBay->getLstProtect(),"id","ids");
|
||
QJsonObject objFalRec= turnListToJson(pBay->getLstFaultRecord(),"id","ids");
|
||
QJsonObject objStatus= turnListToJson(pBay->getLstStatus(),"id","ids");
|
||
QJsonObject objDynSen= turnListToJson(pBay->getLstDynSense(),"id","ids");
|
||
QJsonObject objIns= turnListToJson(pBay->getLstInstruct(),"id","ids");
|
||
QJsonObject objEtc= turnListToJson(pBay->getLstEtc(),"id","ids");
|
||
|
||
DataBase::GetInstance()->insertBay(pBay->uuid(),pBay->name(),tempTag,pBay->getType(),pBay->getVoltage(),pBay->getFla(),pBay->getCapacity(),"1",pBay->getInService(),0,"1","1","1",QJsonObject(),objFrom,objTo,objProtec,objFalRec,objStatus,objDynSen,objIns,objEtc,pBay->getLstComponent(),QJsonObject());
|
||
}
|
||
else{
|
||
QJsonObject objFrom = turnListToJson(pBay->getLstFrom(),"id","ids");
|
||
QJsonObject objTo= turnListToJson(pBay->getLstTo(),"id","ids");
|
||
QJsonObject objProtec= turnListToJson(pBay->getLstProtect(),"id","ids");
|
||
QJsonObject objFalRec= turnListToJson(pBay->getLstFaultRecord(),"id","ids");
|
||
QJsonObject objStatus= turnListToJson(pBay->getLstStatus(),"id","ids");
|
||
QJsonObject objDynSen= turnListToJson(pBay->getLstDynSense(),"id","ids");
|
||
QJsonObject objIns= turnListToJson(pBay->getLstInstruct(),"id","ids");
|
||
QJsonObject objEtc= turnListToJson(pBay->getLstEtc(),"id","ids");
|
||
|
||
DataBase::GetInstance()->updateBay(pBay->uuid(),pBay->name(),tempTag,pBay->getVoltage(),pBay->getFla(),pBay->getCapacity(),"",pBay->getInService(),0,QJsonObject(),objFrom,objTo,objProtec,objFalRec,objStatus,objDynSen,objIns,objEtc,pBay->getLstComponent(),QJsonObject());
|
||
}
|
||
|
||
QString sGridTag;
|
||
QString sGridName;
|
||
QString sZoneTag;
|
||
QString sZoneName;
|
||
QString sStationTag;
|
||
QString sStationName;
|
||
QList<QUuid> lstId = pBay->getLstComponent(); //获取间隔下的所有item,取一个item所属的层级关系
|
||
if(!lstId.isEmpty()){
|
||
auto pItemData = BasePropertyManager::instance().findEntityData(lstId.first());
|
||
if(pItemData){
|
||
for(auto& gridInfo:lstGrid){
|
||
if(pItemData->grid() == gridInfo.tagname){
|
||
sGridTag= gridInfo.tagname;
|
||
sGridName= gridInfo.name;
|
||
break;
|
||
}
|
||
}
|
||
|
||
for(auto& zoneInfo:lstZone){
|
||
if(pItemData->zone() == zoneInfo.tagname){
|
||
sZoneTag = zoneInfo.tagname;
|
||
sZoneName = zoneInfo.name;
|
||
break;
|
||
}
|
||
}
|
||
|
||
for(auto& stationInfo:lstStation){
|
||
if(pItemData->station() == stationInfo.tagname){
|
||
sStationTag = stationInfo.tagname;
|
||
sStationName = stationInfo.name;
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
if(!bExist){
|
||
if(!bSaveFlag){
|
||
DataBase::GetInstance()->insertComponent(QUuid("11111111-1111-1111-1111-111111111111"),"","","","","","","",sStationTag,-1,false,-1,-1,QJsonObject(),QJsonObject(),QJsonObject(),1);
|
||
bSaveFlag = true;
|
||
}
|
||
}
|
||
|
||
QMap<QString,MeasurementInfo> mapMeasure = pBay->getMeasurement(); //量测
|
||
QList<ExtraProperty> lstTemp= DataBase::GetInstance()->getBayExtraProperty(tempTag); //component中的层级关系
|
||
QList<ExtraProperty> lstExtra;
|
||
for(auto& info:lstTemp){
|
||
if(info.component_uuid != QUuid("11111111-1111-1111-1111-111111111111")) //只判断设备外量测
|
||
continue;
|
||
info.bay_tag = removeSuffix(info.bay_tag);
|
||
lstExtra.append(info);
|
||
}
|
||
|
||
QList<MeasurementInfo> lstDataBase;
|
||
QList<MeasurementInfo> lstTempBase = DataBase::GetInstance()->getBayMeasurement(pBay->uuid()); //数据库中现有量测
|
||
for(auto& info:lstTempBase){
|
||
if(info.componentUuid != QUuid("11111111-1111-1111-1111-111111111111")) //只判断设备外量测
|
||
continue;
|
||
lstDataBase.append(info);
|
||
}
|
||
|
||
for(auto& info:mapMeasure)
|
||
{
|
||
int tpe = info.type; //todo:建立类型映射表
|
||
|
||
QJsonObject objDataSource;
|
||
QJsonObject objIoAddress;
|
||
if(info.nSource == 1){ //3611
|
||
objDataSource["type"] = 1;
|
||
objIoAddress["station"] = info.sStation;
|
||
objIoAddress["device"] = info.sDevice;
|
||
objIoAddress["channel"] = info.sChannel;
|
||
}
|
||
else if(info.nSource == 2){ //104
|
||
objDataSource["type"] = 2;
|
||
objIoAddress["station"] = info.sStation;
|
||
objIoAddress["packet"] = info.nPacket;
|
||
objIoAddress["offset"] = info.nOffset;
|
||
}
|
||
objDataSource["io_address"] = objIoAddress;
|
||
|
||
QJsonObject objEventPlan;
|
||
QJsonObject objCause;
|
||
QJsonObject objAction;
|
||
QJsonArray arrPara;
|
||
objEventPlan["enable"] = info.bEnable;
|
||
if(tpe == 0){ //遥测
|
||
for(auto iter = info.mapTE.begin();iter != info.mapTE.end();++iter){
|
||
objCause[iter.key()] = iter.value();
|
||
}
|
||
}
|
||
else if(tpe == 1){ //遥信
|
||
objCause["edge"] = info.sEdge;
|
||
}
|
||
objEventPlan["cause"] = objCause;
|
||
|
||
objAction["command"] = info.sCommand;
|
||
for(auto ¶:info.lstParameter){
|
||
arrPara.append(para);
|
||
}
|
||
objAction["parameters"] = arrPara;
|
||
objEventPlan["action"] = objAction;
|
||
|
||
QJsonObject objBinding;
|
||
if(!info.sWindType.isEmpty()){
|
||
QJsonObject objWind;
|
||
objWind["ratio"] = info.nRatio;
|
||
objWind["polarity"] = info.nPolarity;
|
||
objWind["index"] = info.nIndex;
|
||
objBinding[info.sWindType] = objWind;
|
||
}
|
||
|
||
QString tempMeasure = info.tag+"_"+_pageName; //tag后加工程名,保持全局唯一
|
||
|
||
bool val = DataBase::GetInstance()->ifBayMeasureExist(info.name,pBay->uuid());
|
||
if(val){
|
||
DataBase::GetInstance()->updateMeasurement(info.name,tpe,objDataSource,objEventPlan,objBinding,info.size,QUuid("11111111-1111-1111-1111-111111111111"));
|
||
}
|
||
else{
|
||
DataBase::GetInstance()->insertMeasurement(info.name,tempMeasure,tpe,objDataSource,objEventPlan,objBinding,info.size,info.bayUuid,QUuid("11111111-1111-1111-1111-111111111111"));
|
||
}
|
||
|
||
for(int i = 0;i < lstDataBase.size();++i) //从数据库记录中移除操作过的对象
|
||
{
|
||
if(lstDataBase[i].name == info.name){
|
||
lstDataBase.removeAt(i);
|
||
break;
|
||
}
|
||
}
|
||
|
||
for(int i = 0;i < lstExtra.size();++i){ //同步层级信息计数
|
||
if(lstExtra[i].name == info.name){
|
||
lstExtra.removeAt(i);
|
||
break;
|
||
}
|
||
}
|
||
|
||
ExtraProperty extraPro; //层级信息
|
||
extraPro.name = info.name;
|
||
extraPro.tag = tempMeasure;
|
||
extraPro.grid_tag = sGridTag;
|
||
extraPro.grid_name = sGridName;
|
||
extraPro.zone_tag = sZoneTag;
|
||
extraPro.zone_name = sZoneName;
|
||
extraPro.station_tag = sStationTag;
|
||
extraPro.station_name = sStationName;
|
||
|
||
extraPro.currentLevel = QString::number(pBay->getVoltage())+"kv";
|
||
extraPro.page_tag = _widget->pageName(); //暂时相同
|
||
extraPro.bay_name = pBay->name();
|
||
extraPro.bay_tag = tempTag;
|
||
extraPro.component_uuid = QUuid("11111111-1111-1111-1111-111111111111");
|
||
|
||
for(auto& groupInfo:groupMap){
|
||
if("bay" == groupInfo.groupType){
|
||
extraPro.group_name = groupInfo.groupName;
|
||
break;
|
||
}
|
||
}
|
||
|
||
if(tpe == 0){
|
||
extraPro.type_name = "遥测";
|
||
extraPro.type_tag = "telemetry";
|
||
}
|
||
else if(tpe == 1){
|
||
extraPro.type_name = "遥信";
|
||
extraPro.type_tag = "telesignal";
|
||
}
|
||
else if(tpe == 2){
|
||
extraPro.type_name = "遥控";
|
||
extraPro.type_tag = "telecontrol";
|
||
}
|
||
extraPro.code = extraPro.getFullName();
|
||
extraPro.sourceType = "measurement";
|
||
extraPro.connect_para = sGridTag+"."+sZoneTag+"."+sStationTag+"."+extraPro.bay_tag+"."+extraPro.tag;
|
||
//取data 量测tag
|
||
|
||
bool exist = DataBase::GetInstance()->ifExtraPropertyExist(extraPro.code);
|
||
if(exist)
|
||
DataBase::GetInstance()->updateExtraProperty(extraPro);
|
||
else
|
||
DataBase::GetInstance()->insertExtraProperty(extraPro);
|
||
}
|
||
|
||
for(auto& info:lstDataBase) //操作的记录小于数据库中的记录,删除库中多出的记录
|
||
{
|
||
DataBase::GetInstance()->delteMeasurement(info.name,info.componentUuid);
|
||
}
|
||
|
||
for(auto& info:lstExtra){ //删除库中多出的层级信息
|
||
DataBase::GetInstance()->deleteExtraProperty(info.code);
|
||
}
|
||
}
|
||
}
|
||
|
||
QMap<QUuid,GraphicsFunctionModelItem*> mapItems = allItems();
|
||
for(auto& pItem:mapItems)
|
||
{
|
||
BaseProperty* pData = dynamic_cast<BaseProperty*>(pItem->getProperty());
|
||
if(pData){
|
||
Connection con = pData->getConnection();
|
||
QString fromPin = con.nSrcPortId.toString();
|
||
QString toPin = con.nDestPortId.toString();
|
||
QJsonObject context;
|
||
context["from_pin"] = fromPin;
|
||
context["to_pin"] = toPin;
|
||
if(pData->prepareDelete())
|
||
{
|
||
DataBase::GetInstance()->deleteComponent(pData->uuid().toString());
|
||
if(pData->type() == 8){
|
||
PowerConnection* pCon = TopologyManager::instance().connection(fromPin,toPin);
|
||
if(pCon){
|
||
DataBase::GetInstance()->deleteTopologic(con.nSrcPortId,con.nDestPortId);
|
||
TopologyManager::instance().removeConnection(pCon->id());
|
||
}
|
||
}
|
||
continue;
|
||
}
|
||
if(pData->dataChanged())
|
||
{
|
||
pData->setDataChanged(false);
|
||
bool exist = DataBase::GetInstance()->componentExist(pData->uuid().toString());
|
||
VariableProperty* pVariable = dynamic_cast<VariableProperty*>(pData);
|
||
if(pVariable)
|
||
{
|
||
ModelDataInfo& dataInfo = pVariable->getPropertyValue();
|
||
QString tempTag = pData->tag()+"_"+_pageName; //tag后加工程名使得全局唯一
|
||
if(exist) //已存在更新
|
||
{
|
||
DataBase::GetInstance()->updateComponent(pData->uuid(),tempTag,pData->name(),pData->context(),pData->inService(),pData->state(),pData->status());
|
||
for(auto &val:dataInfo.groupInfo)
|
||
{
|
||
if(val.groupName == "component")
|
||
continue;
|
||
DataBase::GetInstance()->updateDynamicProperty(pData->uuid(),val);
|
||
if(val.mapInfo.contains(pData->uuid())){ //保存时将数据锁复原
|
||
auto& mapPro = val.mapInfo[pData->uuid()];
|
||
for(auto& pro:mapPro)
|
||
{
|
||
pro.lock = false;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
QString tempPath = pData->path()+"_"+_pageName;
|
||
DataBase::GetInstance()->insertComponent(pData->uuid(),pData->modelName(),tempPath,tempTag,pData->name(),pData->description(),pData->grid(),pData->zone(),pData->station(),pData->type(),true,pData->state(),pData->status(),pData->connectedBus(),pData->label(),pData->context(),1);
|
||
for(auto &val:dataInfo.groupInfo)
|
||
{
|
||
if(val.groupName == "component")
|
||
continue;
|
||
DataBase::GetInstance()->insertDynamicProperty(pData->uuid(),val);
|
||
if(val.mapInfo.contains(pData->uuid())){ //保存时将数据锁复原
|
||
auto& mapPro = val.mapInfo[pData->uuid()];
|
||
for(auto& pro:mapPro)
|
||
{
|
||
pro.lock = false;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
//层级关系与连接参数
|
||
BayProperty* bayPro = nullptr; //本data对应的bay
|
||
QMap<QUuid,ElectricBayItem*> mapBay = allBayItem();
|
||
for(auto& item:mapBay){
|
||
AbstractProperty* pPro = item->getProperty();
|
||
BayProperty* pBayPro = dynamic_cast<BayProperty*>(pPro);
|
||
if(pBayPro){
|
||
QList<QUuid> lstCompo = pBayPro->getLstComponent(); //获取间隔下的component,找到本component对应的间隔
|
||
for(auto& id:lstCompo){
|
||
if(id == pData->uuid()){
|
||
bayPro = pBayPro;
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
QString sGridTag;
|
||
QString sGridName;
|
||
QString sZoneTag;
|
||
QString sZoneName;
|
||
QString sStationTag;
|
||
QString sStationName;
|
||
for(auto& gridInfo:lstGrid){
|
||
if(pData->grid() == gridInfo.tagname){
|
||
sGridTag= gridInfo.tagname;
|
||
sGridName= gridInfo.name;
|
||
break;
|
||
}
|
||
}
|
||
|
||
for(auto& zoneInfo:lstZone){
|
||
if(pData->zone() == zoneInfo.tagname){
|
||
sZoneTag = zoneInfo.tagname;
|
||
sZoneName = zoneInfo.name;
|
||
break;
|
||
}
|
||
}
|
||
|
||
for(auto& stationInfo:lstStation){
|
||
if(pData->station() == stationInfo.tagname){
|
||
sStationTag = stationInfo.tagname;
|
||
sStationName = stationInfo.name;
|
||
break;
|
||
}
|
||
}
|
||
for(auto &val:dataInfo.groupInfo)
|
||
{
|
||
if(val.groupName == "component" || val.groupName == "bay")
|
||
continue;
|
||
if(val.mapInfo.contains(pData->uuid())){
|
||
auto mapPro = val.mapInfo[pData->uuid()];
|
||
for(auto& pro:mapPro)
|
||
{
|
||
ExtraProperty extraPro; //层级信息
|
||
extraPro.name = pro.name;
|
||
extraPro.tag = pro.tagName;
|
||
extraPro.grid_tag = sGridTag;
|
||
extraPro.grid_name = sGridName;
|
||
extraPro.zone_tag = sZoneTag;
|
||
extraPro.zone_name = sZoneName;
|
||
extraPro.station_tag = sStationTag;
|
||
extraPro.station_name = sStationName;
|
||
|
||
extraPro.currentLevel = QString::number(pData->getVoltageLevel())+"kv";
|
||
extraPro.page_tag = _widget->pageName(); //暂时相同
|
||
if(bayPro){
|
||
extraPro.bay_name = bayPro->name();
|
||
extraPro.bay_tag = bayPro->tag();
|
||
}
|
||
extraPro.component_name = pData->name();
|
||
extraPro.component_uuid = pData->uuid();
|
||
extraPro.component_tag = tempTag;
|
||
extraPro.group_tag = val.groupName;
|
||
|
||
for(auto& groupInfo:groupMap){
|
||
if(val.groupName == groupInfo.groupType){
|
||
extraPro.group_name = groupInfo.groupName;
|
||
break;
|
||
}
|
||
}
|
||
extraPro.type_name = "参量";
|
||
extraPro.type_tag = "parameter";
|
||
|
||
extraPro.code = extraPro.getFullName();
|
||
extraPro.sourceType = "property";
|
||
extraPro.sourceConfig.insert("modelName",pData->modelName());
|
||
extraPro.connect_para = sGridTag+"."+sZoneTag+"."+sStationTag+"."+extraPro.bay_tag+"."+tempTag+"."+extraPro.group_tag+"."+extraPro.tag;
|
||
//取data:模型.属性组.id.属性名
|
||
|
||
bool exist = DataBase::GetInstance()->ifExtraPropertyExist(extraPro.code);
|
||
if(exist)
|
||
DataBase::GetInstance()->updateExtraProperty(extraPro);
|
||
else
|
||
DataBase::GetInstance()->insertExtraProperty(extraPro);
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
QMap<QString,MeasurementInfo> mapMeasure = pData->getMeasurement(); //量测
|
||
QList<ExtraProperty> lstTemp= DataBase::GetInstance()->getCompoExtraProperty(pData->uuid()); //component中的层级关系
|
||
QList<ExtraProperty> lstExtra;
|
||
for(auto& info:lstTemp){
|
||
if(info.group_tag != "bay") //只对量测判断
|
||
continue;
|
||
info.bay_tag = removeSuffix(info.bay_tag);
|
||
lstExtra.append(info);
|
||
}
|
||
|
||
QList<MeasurementInfo> lstDataBase = DataBase::GetInstance()->getMeasurement(pData->uuid()); //数据库中现有量测
|
||
for(auto& info:mapMeasure)
|
||
{
|
||
int tpe = info.type; //todo:建立类型映射表
|
||
|
||
QJsonObject objDataSource;
|
||
QJsonObject objIoAddress;
|
||
if(info.nSource == 1){ //3611
|
||
objDataSource["type"] = 1;
|
||
objIoAddress["station"] = info.sStation;
|
||
objIoAddress["device"] = info.sDevice;
|
||
objIoAddress["channel"] = info.sChannel;
|
||
}
|
||
else if(info.nSource == 2){ //104
|
||
objDataSource["type"] = 2;
|
||
objIoAddress["station"] = info.sStation;
|
||
objIoAddress["packet"] = info.nPacket;
|
||
objIoAddress["offset"] = info.nOffset;
|
||
}
|
||
objDataSource["io_address"] = objIoAddress;
|
||
|
||
QJsonObject objEventPlan;
|
||
QJsonObject objCause;
|
||
QJsonObject objAction;
|
||
QJsonArray arrPara;
|
||
objEventPlan["enable"] = info.bEnable;
|
||
if(tpe == 0){ //遥测
|
||
for(auto iter = info.mapTE.begin();iter != info.mapTE.end();++iter){
|
||
objCause[iter.key()] = iter.value();
|
||
}
|
||
}
|
||
else if(tpe == 1){ //遥信
|
||
objCause["edge"] = info.sEdge;
|
||
}
|
||
objEventPlan["cause"] = objCause;
|
||
|
||
objAction["command"] = info.sCommand;
|
||
for(auto ¶:info.lstParameter){
|
||
arrPara.append(para);
|
||
}
|
||
objAction["parameters"] = arrPara;
|
||
objEventPlan["action"] = objAction;
|
||
|
||
QJsonObject objBinding;
|
||
if(!info.sWindType.isEmpty()){
|
||
QJsonObject objWind;
|
||
objWind["ratio"] = info.nRatio;
|
||
objWind["polarity"] = info.nPolarity;
|
||
objWind["index"] = info.nIndex;
|
||
objBinding[info.sWindType] = objWind;
|
||
}
|
||
|
||
QString tempMeasure = info.tag+"_"+_pageName; //tag后加工程名,保持全局唯一
|
||
|
||
bool val = DataBase::GetInstance()->ifMeasureExist(info.name,pData->uuid());
|
||
if(val){
|
||
DataBase::GetInstance()->updateMeasurement(info.name,tpe,objDataSource,objEventPlan,objBinding,info.size,pData->uuid());
|
||
}
|
||
else{
|
||
DataBase::GetInstance()->insertMeasurement(info.name,tempMeasure,tpe,objDataSource,objEventPlan,objBinding,info.size,info.bayUuid,info.componentUuid);
|
||
}
|
||
|
||
for(int i = 0;i < lstDataBase.size();++i) //从数据库记录中移除操作过的对象
|
||
{
|
||
if(lstDataBase[i].name == info.name){
|
||
lstDataBase.removeAt(i);
|
||
break;
|
||
}
|
||
}
|
||
|
||
for(int i = 0;i < lstExtra.size();++i){ //同步层级信息计数
|
||
if(lstExtra[i].name == info.name){
|
||
lstExtra.removeAt(i);
|
||
break;
|
||
}
|
||
}
|
||
|
||
ExtraProperty extraPro; //层级信息
|
||
extraPro.name = info.name;
|
||
extraPro.tag = tempMeasure;
|
||
extraPro.grid_tag = sGridTag;
|
||
extraPro.grid_name = sGridName;
|
||
extraPro.zone_tag = sZoneTag;
|
||
extraPro.zone_name = sZoneName;
|
||
extraPro.station_tag = sStationTag;
|
||
extraPro.station_name = sStationName;
|
||
|
||
extraPro.currentLevel = QString::number(pData->getVoltageLevel())+"kv";
|
||
extraPro.page_tag = _widget->pageName(); //暂时相同
|
||
if(bayPro){
|
||
extraPro.bay_name = bayPro->name();
|
||
extraPro.bay_tag = bayPro->tag();
|
||
}
|
||
extraPro.component_name = pData->name();
|
||
extraPro.component_uuid = pData->uuid();
|
||
extraPro.component_tag = tempTag;
|
||
extraPro.group_tag = "bay";
|
||
|
||
for(auto& groupInfo:groupMap){
|
||
if("bay" == groupInfo.groupType){
|
||
extraPro.group_name = groupInfo.groupName;
|
||
break;
|
||
}
|
||
}
|
||
|
||
if(tpe == 0){
|
||
extraPro.type_name = "遥测";
|
||
extraPro.type_tag = "telemetry";
|
||
}
|
||
else if(tpe == 1){
|
||
extraPro.type_name = "遥信";
|
||
extraPro.type_tag = "telesignal";
|
||
}
|
||
else if(tpe == 2){
|
||
extraPro.type_name = "遥控";
|
||
extraPro.type_tag = "telecontrol";
|
||
}
|
||
extraPro.code = extraPro.getFullName();
|
||
extraPro.sourceType = "measurement";
|
||
extraPro.connect_para = sGridTag+"."+sZoneTag+"."+sStationTag+"."+extraPro.bay_tag+"."+tempTag+"."+extraPro.group_tag+"."+extraPro.tag;
|
||
//取data 量测tag
|
||
|
||
bool exist = DataBase::GetInstance()->ifExtraPropertyExist(extraPro.code);
|
||
if(exist)
|
||
DataBase::GetInstance()->updateExtraProperty(extraPro);
|
||
else
|
||
DataBase::GetInstance()->insertExtraProperty(extraPro);
|
||
}
|
||
|
||
for(auto& info:lstDataBase) //操作的记录小于数据库中的记录,删除库中多出的记录
|
||
{
|
||
DataBase::GetInstance()->delteMeasurement(info.name,info.componentUuid);
|
||
}
|
||
|
||
for(auto& info:lstExtra){ //删除库中多出的层级信息
|
||
DataBase::GetInstance()->deleteExtraProperty(info.code);
|
||
}
|
||
}
|
||
|
||
if(pData->type() == 8){
|
||
PowerConnection* pCon = TopologyManager::instance().connection(fromPin,toPin);
|
||
if(pCon){
|
||
int id = DataBase::GetInstance()->topologicExist(con.nSrcNodeId,con.nDestNodeId);
|
||
if(id == -1)
|
||
DataBase::GetInstance()->insertTopologic(con.nSrcNodeId,con.nDestNodeId,context,0,"",0);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
void FixedPortsModel::onSignal_ifExits(QUuid id,const QString& str,int type,GraphicsFunctionModelItem* pitem)
|
||
{
|
||
bool exist = false;
|
||
BaseProperty* pData = nullptr;
|
||
QMap<QUuid,BaseProperty*> mapData = BasePropertyManager::instance().getEntityData();
|
||
for(auto pro:mapData)
|
||
{
|
||
if(pro->tag() == str)
|
||
{
|
||
pData = pro;
|
||
exist = true;
|
||
break;
|
||
}
|
||
}
|
||
if(exist) //已存在,将发出信号的item绑定到此data
|
||
{
|
||
if(_nodeItem.contains(id)) //发出信号对象id与data对象id相同,已绑定,不做响应
|
||
return;
|
||
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:
|
||
{
|
||
//todo:断开原来的连接关系
|
||
pitem->setProperty(pData);
|
||
pitem->setItemId(pData->uuid());
|
||
PowerEntity* pEntity = TopologyManager::instance().findEntity(pData->uuid().toString());
|
||
if(pEntity){
|
||
pitem->setEntity(pEntity); //item对象的逻辑接线点无需重复创建
|
||
}
|
||
_nodeItem.take(id);
|
||
_nodeItem.insert(pData->uuid(),pitem);
|
||
}
|
||
break;
|
||
case QMessageBox::Cancel:
|
||
// Cancel was clicked
|
||
break;
|
||
default:
|
||
// should never be reached
|
||
break;
|
||
}
|
||
}
|
||
else //创建新data并绑定
|
||
{
|
||
BaseProperty* pData = addNodeData(id,type,str,pitem->getModelName());
|
||
if(pData)
|
||
{
|
||
pitem->setProperty(pData);
|
||
pData->setDataChanged(true); //数据状态改变
|
||
}
|
||
|
||
PowerEntity* pEntity = TopologyManager::instance().createEntity(EntityType::Component,id.toString(),str);
|
||
if(pEntity)
|
||
pitem->setEntity(pEntity);
|
||
createTopoTerminalsByItem(pitem); //创建item对象的逻辑接线点
|
||
}
|
||
}
|
||
|
||
|
||
void FixedPortsModel::onTimeOut()
|
||
{
|
||
_Interface->getPointData("i");
|
||
_Interface->getPointData("v");
|
||
}
|
||
|
||
void FixedPortsModel::onSignal_GetPointData(QString type,QMap<qint64,double> map)
|
||
{
|
||
if(map.size() == 1) //实时数据
|
||
{
|
||
double d = map.first();
|
||
|
||
//for(auto pro:_nodeData) //demo版本只有一个数据
|
||
{
|
||
//int t = pro->type();
|
||
//if(t == GIT_itemRect)
|
||
{
|
||
//todo:根据id匹配数据
|
||
/*auto p = dynamic_cast<ElectricSvgItemRect_Property*>(pro);
|
||
if(p)
|
||
{
|
||
p->notifyUpdate(); //通知更新
|
||
}*/
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
void FixedPortsModel::onSignal_openBayManager()
|
||
{
|
||
if(m_pBayManager == nullptr){
|
||
m_pBayManager = new BayManagerDlg(_widget);
|
||
m_pBayManager->setModelController(this);
|
||
}
|
||
m_pBayManager->showDlg();
|
||
}
|
||
|
||
void FixedPortsModel::onDataTimerOut()
|
||
{
|
||
if(!_curRequestLst.isEmpty()){
|
||
auto pDataAccessor = _cavas->getDataAccessor();
|
||
if(pDataAccessor){
|
||
_curData = pDataAccessor->getTargetData(_curRequestLst);
|
||
if(!_curData.isEmpty())
|
||
updateMonitor(_curData);
|
||
}
|
||
}
|
||
}
|
||
|
||
void FixedPortsModel::onSelectionChanged()
|
||
{
|
||
QList<QGraphicsItem*> selectedItems = _scene->selectedItems();
|
||
if(_cavas){
|
||
if(selectedItems.count() != 1) {
|
||
if(_widget)
|
||
_cavas->onTargetSelected(_widget->getPropertyProxy());
|
||
return;
|
||
}
|
||
GraphicsBaseItem *item = static_cast<GraphicsBaseItem*>(selectedItems.first());
|
||
_cavas->onTargetSelected(item);
|
||
}
|
||
}
|
||
|
||
void FixedPortsModel::startHttpRequest()
|
||
{
|
||
if(_timer)
|
||
{
|
||
_timer->setInterval(1000);
|
||
_timer->start();
|
||
}
|
||
}
|
||
|
||
DiagramCavas* FixedPortsModel::getCavas()
|
||
{
|
||
if(_cavas)
|
||
return _cavas.data();;
|
||
return nullptr;
|
||
}
|
||
|
||
void FixedPortsModel::addPortsToItem_json(PortState sta,QJsonArray jArr,GraphicsBaseItem* pItem)
|
||
{
|
||
for(QJsonValueRef portJson:jArr)
|
||
{
|
||
QJsonObject portObj = portJson.toObject();
|
||
QString portId = portObj["portId"].toString();
|
||
double x = portObj["x"].toDouble();
|
||
double y = portObj["y"].toDouble();
|
||
if(sta == P_const){
|
||
HandleType tye = HandleType(portObj["portType"].toInt());
|
||
PortPos locate = PortPos(portObj["locate"].toInt());
|
||
double ratioX = 0.0;
|
||
double ratioY = 0.0;
|
||
if(portObj.contains("xRatio") || portObj.contains("yRatio")){
|
||
ratioX = portObj["xRatio"].toDouble();
|
||
ratioY = portObj["yRatio"].toDouble();
|
||
}
|
||
pItem->addPort(P_const,QPointF(x,y),portId,tye,locate,ratioX,ratioY);
|
||
}
|
||
else if(sta == p_movable){
|
||
pItem->addPort(p_movable,QPointF(x,y),portId);
|
||
}
|
||
}
|
||
}
|
||
|
||
void FixedPortsModel::autoSetModelName(GraphicsBaseModelItem* pItem)
|
||
{
|
||
ModelProperty* p = pItem->getProperty();
|
||
BaseModelProperty* pro = dynamic_cast<BaseModelProperty*>(p);
|
||
if(pro){
|
||
QString sMeta = pro->metaModelName();
|
||
QString sModel = sMeta+"_"+_pageName;
|
||
bool exist = ProjectModelManager::instance().getData()[sMeta].contains(sModel);
|
||
if(exist){
|
||
pro->setModelName(sModel);
|
||
pro->getModelProperty().modelSetting.modelName = sModel;
|
||
}
|
||
}
|
||
}
|
||
|
||
QString FixedPortsModel::removeSuffix(const QString& str)
|
||
{
|
||
int lastUnderscore = str.lastIndexOf('_');
|
||
if (lastUnderscore == -1) return str; // 没有下划线
|
||
|
||
return str.left(lastUnderscore);
|
||
}
|
||
|
||
ModelProperty* FixedPortsModel::getItemByUid(QList<GraphicsBaseItem*> lst,QUuid uid)
|
||
{
|
||
for(auto& item:lst){
|
||
auto pPro = item->getProperty();
|
||
if(pPro->uuid() == uid){
|
||
return pPro;
|
||
}
|
||
}
|
||
return nullptr;
|
||
}
|
||
|
||
void FixedPortsModel::updateMonitor(QMap<QString,QMap<quint64,double>> data)
|
||
{
|
||
for(auto iter = m_monitorPara.begin();iter != m_monitorPara.end();++iter){
|
||
for(auto &info:iter.value()){
|
||
//if(info.bSelected){
|
||
if(data.contains(info.sConnectPara)){
|
||
info.mapValue = data.value(info.sConnectPara);
|
||
}
|
||
//}
|
||
}
|
||
}
|
||
emit dataUpdated();
|
||
|
||
for(auto& item:_nodeItem){ //更新界面中的数据
|
||
QMap<QString,HandleText*> mapText = item->getDynamicText();
|
||
for(auto &pText:mapText){
|
||
QString sPara = pText->getPara();
|
||
if(data.contains(sPara)){
|
||
QString sVal= QString::number(data.value(sPara).last());
|
||
pText->setText(sVal);
|
||
pText->update();
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
void FixedPortsModel::assignMeasureSymmetry(QMap<QString, MeasurementInfo>& measurementMap)
|
||
{
|
||
// 用于存储每个键对应的tag
|
||
QMap<MeasurementKey, QString> keyToTagMap;
|
||
|
||
for (auto it = measurementMap.begin(); it != measurementMap.end(); ++it) {
|
||
MeasurementKey currentKey(it.value());
|
||
QString currentTag = it.key();
|
||
|
||
// 检查是否已经有相同的键
|
||
if (keyToTagMap.contains(currentKey)) {
|
||
QString otherTag = keyToTagMap[currentKey];
|
||
|
||
// 找到一对,互相设置sSymmetry
|
||
measurementMap[currentTag].sSymmetry = measurementMap[otherTag].name;
|
||
measurementMap[otherTag].sSymmetry = measurementMap[currentTag].name;
|
||
|
||
// 从map中移除,因为"有且仅有两个item"
|
||
keyToTagMap.remove(currentKey);
|
||
} else {
|
||
// 还没有配对的,添加到map中
|
||
keyToTagMap[currentKey] = currentTag;
|
||
}
|
||
}
|
||
}
|
||
|
||
QWidget* FixedPortsModel::getTopWidget()
|
||
{
|
||
return dynamic_cast<QWidget*>(_widget);
|
||
}
|
||
|
||
QPointF FixedPortsModel::getTerminalPos(const QString& sTerminalId)
|
||
{
|
||
PowerEntity* pParent = TopologyManager::instance().getEntityByTerminal(sTerminalId);
|
||
if(pParent)
|
||
{
|
||
for(auto &item:_nodeItem)
|
||
{
|
||
if(pParent->id() == item->itemId().toString()) //找到terminal父图元
|
||
{
|
||
for(auto &pPort:item->getPorts())
|
||
{
|
||
if(pPort->getId() == sTerminalId)
|
||
{
|
||
return pPort->scenePos();
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
return QPointF(0,0);
|
||
}
|
||
|
||
ElectricFunctionModelConnectLineItem* FixedPortsModel::getLineItemById(const QString& terminalId)
|
||
{
|
||
for(auto &iter:_nodeItem) //获取id所在的lineitem
|
||
{
|
||
auto item = dynamic_cast<GraphicsFunctionModelItem*>(iter);
|
||
if(item)
|
||
{
|
||
if(item->getItemType() == GIT_link)
|
||
{
|
||
PowerConnection* pCon = TopologyManager::instance().getConnectionContainsTerminal(terminalId);
|
||
if(pCon)
|
||
{
|
||
ModelProperty* pPro = item->getProperty();
|
||
if(pPro){
|
||
Connection con = pPro->getConnection();
|
||
if((pCon->fromTerminalId() == con.nSrcPortId.toString() && pCon->toTerminalId() == con.nDestPortId.toString())
|
||
|| (pCon->fromTerminalId() == con.nDestPortId.toString() && pCon->toTerminalId() == con.nSrcPortId.toString())){ //port相同为同一条线
|
||
return dynamic_cast<ElectricFunctionModelConnectLineItem*>(item);
|
||
}
|
||
}
|
||
//QUuid uid = item->itemId();
|
||
//QUuid conId = QUuid(pCon->id());
|
||
//if(uid == conId) /************load的拓扑没有uid,使用其他方式判断相等
|
||
}
|
||
}
|
||
}
|
||
}
|
||
return nullptr;
|
||
}
|
||
|
||
void FixedPortsModel::updateItemLinePort(QUuid uid,ModelFunctionType type)
|
||
{
|
||
QList<PowerConnection*> lstCon = TopologyManager::instance().getConnectionsFor(uid.toString(),type); //获取item的所有连接
|
||
for(auto &pCon:lstCon){
|
||
QString baseFromComponentId = pCon->fromComponent();
|
||
QString baseToComponentId = pCon->toComponent();
|
||
QString baseFromTerId = pCon->fromTerminalId();
|
||
QString baseToTerId = pCon->toTerminalId();
|
||
|
||
auto pLine = static_cast<ElectricFunctionModelConnectLineItem*>(nodeItem(QUuid(pCon->id())));
|
||
if(pLine){
|
||
if(uid.toString() == baseFromComponentId){
|
||
QPointF posFrom = getTerminalPos(baseFromTerId);
|
||
pLine->setStartPoint(posFrom);
|
||
pLine->calculatePath();
|
||
}
|
||
else if(uid.toString() == baseToComponentId){
|
||
QPointF posTo = getTerminalPos(baseToTerId);
|
||
pLine->setEndPoint(posTo);
|
||
pLine->calculatePath();
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
void FixedPortsModel::showModelDlg(const QString& sName,QUuid uuid,GraphicsFunctionModelItem* pItem)
|
||
{
|
||
ModelStateInfo stateInfo = _modelStateInfo[sName];
|
||
ModelDataMap mapData = DataManager::instance().modelData();
|
||
ItemPropertyDlg* pDlg = dynamic_cast<ItemPropertyDlg*>(stateInfo._PropertyDlg);
|
||
if(pDlg)
|
||
{
|
||
pDlg->showDlg(mapData[sName],uuid,pItem);
|
||
m_curPropertyDlg = pDlg;
|
||
}
|
||
else
|
||
qDebug()<<"showModelDlg err";
|
||
}
|
||
|
||
void FixedPortsModel::initialPropertyDlg()
|
||
{
|
||
for(auto &modelInfo:_modelStateInfo)
|
||
{
|
||
if(modelInfo._PropertyDlg == NULL)
|
||
{
|
||
generatePropertyDlg(modelInfo.modelName);
|
||
}
|
||
}
|
||
}
|
||
|
||
void FixedPortsModel::generatePropertyDlg(const QString& sModel)
|
||
{
|
||
ModelStateInfo info = _modelStateInfo[sModel];
|
||
if(info._PropertyDlg == NULL)
|
||
{
|
||
ItemPropertyDlg* dlg = new ItemPropertyDlg(_widget);
|
||
if(dlg)
|
||
{
|
||
dlg->setModelController(this);
|
||
dlg->loadGroupButton(info.groupInfo);
|
||
_modelStateInfo[sModel]._PropertyDlg = dlg;
|
||
}
|
||
}
|
||
}
|
||
|
||
ConfigurationDiagram* FixedPortsModel::getTopologyDiagram()
|
||
{
|
||
return dynamic_cast<ConfigurationDiagram*>(_pEntity);
|
||
}
|
||
|
||
void FixedPortsModel::createTopoTerminalsByData(PowerEntity* pParent,QJsonObject componentCon,ModelFunctionType funType)
|
||
{
|
||
QJsonArray portsArray = componentCon["port"].toArray();
|
||
for (QJsonValueRef portJson : portsArray) //每个属性的状态信息
|
||
{
|
||
QJsonObject node = portJson.toObject();
|
||
QString portId = node["portId"].toString();
|
||
int x = node["x"].toInt();
|
||
int y = node["y"].toInt();
|
||
PortPos locate = PortPos(node["locate"].toInt());
|
||
HandleType portType = HandleType(node["portType"].toInt());
|
||
|
||
TerminalType terType;
|
||
switch (portType) {
|
||
case T_lineIn:
|
||
terType = TerminalType::PowerInput;
|
||
break;
|
||
case T_lineOut:
|
||
terType = TerminalType::PowerOutput;
|
||
break;
|
||
case T_lineInOut:
|
||
terType = TerminalType::PowerConnect;
|
||
break;
|
||
case T_newTral:
|
||
terType = TerminalType::NewTral;
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
auto pTer = TopologyManager::instance().createTerminal(pParent->id(),terType,"",QPointF(x,y),portId,funType);
|
||
if(pTer)
|
||
pTer->setPortLocate(locate);
|
||
}
|
||
}
|
||
|
||
bool FixedPortsModel::isItemValid(GraphicsFunctionModelItem* pItem)
|
||
{
|
||
ModelProperty* pData = pItem->getProperty();
|
||
PowerEntity* pEntity = pItem->entity();
|
||
return (pData != nullptr && pEntity != nullptr)?true:false;
|
||
}
|
||
|
||
|
||
void FixedPortsModel::insertProjectModelName(QString uuid,QString name)
|
||
{
|
||
if(!_projectModelName.contains(uuid))
|
||
_projectModelName.insert(uuid,name);
|
||
}
|
||
|
||
void FixedPortsModel::showProjectIconSettingDlg(GraphicsFunctionModelItem* pItem)
|
||
{
|
||
if(m_projectIconSettingDlg == nullptr)
|
||
{
|
||
m_projectIconSettingDlg = new ProjectIconSetting(_widget);
|
||
m_projectIconSettingDlg->setController(this);
|
||
}
|
||
m_projectIconSettingDlg->showDlg(pItem);
|
||
}
|
||
|
||
void FixedPortsModel::updateItemIcon(QString sMeta,QString sModel,QMap<QString,QByteArray> mapData,QString sIndex,int type,int slot)
|
||
{
|
||
/*if(sIndex.isEmpty()) //此处不再修改系统图图标
|
||
ProjectModelManager::instance().getData()[sMeta][sModel].modelSetting.mapUsedSvg = mapData;
|
||
else{
|
||
ProjectModelManager::instance().getData()[sMeta][sModel].modelSetting.mapUsedSvg[sIndex] = mapData[sIndex];
|
||
}*/
|
||
|
||
if(mapData.size() == 1){ //单项设置
|
||
QByteArray sha256Hash = QCryptographicHash::hash(mapData.first(), QCryptographicHash::Sha256).toHex();
|
||
QMap<QByteArray,HMIImageInfo>& mapResource = ProjectModelManager::instance().getHMIimageMap(); //更新总HMI资源
|
||
if(!mapResource.contains(sha256Hash)){ //库中不存在则新建
|
||
HMIImageInfo imageInfo;
|
||
imageInfo.baseType = type;
|
||
imageInfo.imageName = mapData.firstKey();
|
||
imageInfo.hash256 = sha256Hash;
|
||
imageInfo.svgData = mapData.first();
|
||
mapResource.insert(sha256Hash,imageInfo);
|
||
}
|
||
updateHMIRef(QUuid(_widget->getEntity()->id()),sModel,sha256Hash,slot); //更新本页的资源引用
|
||
}
|
||
updateModelIcon(sMeta,sModel,mapData,sIndex);
|
||
}
|
||
|
||
void FixedPortsModel::updateModelIcon(QString sMeta,QString sModel,QMap<QString,QByteArray> mapData,QString sIndex)
|
||
{
|
||
for(auto &pItem:_nodeItem){
|
||
auto pro = pItem->getProperty();
|
||
QString sMe = pro->metaModelName();
|
||
QString sMo = pro->modelName();
|
||
if(/*sMeta == sMe &&*/sModel == sMo){
|
||
auto pI = dynamic_cast<ElectricFunctionModelSvgItem*>(pItem);
|
||
auto pG = dynamic_cast<ElectricFunctionModelSvgGroup*>(pItem);
|
||
if(pI){
|
||
pI->updateMapSvg(mapData,sIndex);
|
||
}
|
||
if(pG){
|
||
pG->updateMapSvg(mapData,sIndex);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
void FixedPortsModel::addBayItem(QUuid id,ModelFunctionType tpe)
|
||
{
|
||
if(tpe == ModelFunctionType::BaseModel){
|
||
QMap<QUuid,BayProperty*> mapData = BasePropertyManager::instance().getBaseBayData(); //加载的图形必定关联component(todo:完善判断条件,如判断拓扑节点)
|
||
if(mapData.contains(id))
|
||
{
|
||
BayProperty* pro = mapData.value(id);
|
||
if(pro)
|
||
{
|
||
addBayByData(pro,tpe);
|
||
}
|
||
}
|
||
}
|
||
else if(tpe == ModelFunctionType::ProjectModel)
|
||
{
|
||
QMap<QUuid,BayProperty*> mapData = BasePropertyManager::instance().getBayData(); //加载的图形必定关联component(todo:完善判断条件,如判断拓扑节点)
|
||
if(mapData.contains(id))
|
||
{
|
||
BayProperty* pro = mapData.value(id);
|
||
if(pro)
|
||
{
|
||
addBayByData(pro);
|
||
}
|
||
}
|
||
}
|
||
|
||
}
|
||
|
||
bool FixedPortsModel::addBayItem(QUuid id,ElectricBayItem* pBay,ModelFunctionType typ)
|
||
{
|
||
if(typ == ModelFunctionType::ProjectModel){
|
||
if(_bayItem.contains(id))
|
||
return false;
|
||
else
|
||
{
|
||
_bayItem.insert(id,pBay);
|
||
return true;
|
||
}
|
||
}
|
||
return false;
|
||
}
|
||
|
||
void FixedPortsModel::addItemsToBay(QList<GraphicsBaseItem*> lstItem,ElectricBayItem* pBay)
|
||
{
|
||
if(pBay == nullptr)
|
||
return;
|
||
BayProperty* proBay = dynamic_cast<BayProperty*>(pBay->getProperty());
|
||
if(proBay){
|
||
for(auto& item:lstItem){
|
||
if(item){
|
||
ModelProperty* p = item->getProperty();
|
||
auto lstCom = proBay->getLstComponent();
|
||
if(!lstCom.contains(p->uuid())){
|
||
proBay->getLstComponent().append(p->uuid());
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
BayProperty* FixedPortsModel::addBayData(QUuid uuid,ModelFunctionType typ)
|
||
{
|
||
if(typ == ModelFunctionType::BaseModel){
|
||
BayProperty* pData = BasePropertyManager::instance().findBaseBayData(uuid); //已存在不不创建
|
||
if(pData != nullptr)
|
||
return pData;
|
||
|
||
BayProperty* item = new BayProperty();
|
||
|
||
if(item)
|
||
{
|
||
item->setUuid(uuid);
|
||
BasePropertyManager::instance().insertBaseBayData(uuid,item);
|
||
}
|
||
return item;
|
||
}
|
||
else if(typ == ModelFunctionType::ProjectModel){
|
||
BayProperty* pData = BasePropertyManager::instance().findBayData(uuid); //已存在不不创建
|
||
if(pData != nullptr)
|
||
return pData;
|
||
|
||
BayProperty* item = new BayProperty();
|
||
|
||
if(item)
|
||
{
|
||
item->setUuid(uuid);
|
||
BasePropertyManager::instance().insertBayData(uuid,item);
|
||
}
|
||
return item;
|
||
}
|
||
return nullptr;
|
||
}
|
||
|
||
QMap<QUuid,ElectricBayItem*>& FixedPortsModel::allBayItem()
|
||
{
|
||
return _bayItem;
|
||
}
|
||
|
||
BayProperty* FixedPortsModel::generateBayData(BayProperty* pData,QList<BaseProperty*> lst)
|
||
{
|
||
BayProperty* p = addBayData(pData->uuid());
|
||
p->setTag(pData->tag());
|
||
p->setName(pData->name());
|
||
p->setType(pData->getType());
|
||
p->setVoltage(pData->getVoltage());
|
||
p->setFla(pData->getFla());
|
||
p->setCapacity(pData->getCapacity());
|
||
p->setInService(pData->getInService());
|
||
QList<QUuid> lstCompo = pData->getLstComponent();
|
||
QList<QUuid> lstNewCompo = getCorrespondId(lstCompo,lst); //将基模component替换为工程模component
|
||
p->setLstComponent(lstNewCompo);
|
||
|
||
QList<QUuid> lstFrom = pData->getLstFrom();
|
||
QList<QUuid> lstNewFrom = getCorrespondId(lstFrom,lst);
|
||
p->setLstFrom(lstNewFrom);
|
||
|
||
QList<QUuid> lstTo = pData->getLstTo();
|
||
QList<QUuid> lstNewTo = getCorrespondId(lstTo,lst);
|
||
p->setLstTo(lstNewTo);
|
||
|
||
QList<QUuid> lstProtect = pData->getLstProtect();
|
||
QList<QUuid> lstNewProtect = getCorrespondId(lstProtect,lst);
|
||
p->setLstProtect(lstNewProtect);
|
||
|
||
QList<QUuid> lstFaultRecord = pData->getLstFaultRecord();
|
||
QList<QUuid> lstNewFaultRecord = getCorrespondId(lstFaultRecord,lst);
|
||
p->setLstFaultRecord(lstNewFaultRecord);
|
||
|
||
QList<QUuid> lstDynSense = pData->getLstDynSense();
|
||
QList<QUuid> lstNewDynSense = getCorrespondId(lstDynSense,lst);
|
||
p->setLstDynSense(lstNewDynSense);
|
||
|
||
QList<QUuid> lstStatus = pData->getLstStatus();
|
||
QList<QUuid> lstNewStatus = getCorrespondId(lstStatus,lst);
|
||
p->setLstStatus(lstNewStatus);
|
||
|
||
QList<QUuid> lstInstruct = pData->getLstInstruct();
|
||
QList<QUuid> lstNewInstruct = getCorrespondId(lstInstruct,lst);
|
||
p->setLstInstruct(lstNewInstruct);
|
||
|
||
QList<QUuid> lstEtc = pData->getLstEtc();
|
||
QList<QUuid> lstNewEtc= getCorrespondId(lstEtc,lst);
|
||
p->setLstEtc(lstNewEtc);
|
||
return p;
|
||
}
|
||
|
||
QList<QUuid> FixedPortsModel::getCorrespondId(QList<QUuid> lstCompo,QList<BaseProperty*> lst)
|
||
{
|
||
QList<QUuid> lstNewCompo;
|
||
for(auto& uuid:lstCompo)
|
||
{
|
||
for(auto& basePro:lst)
|
||
{
|
||
if(basePro->getSourceItemId() == uuid.toString()){ //工程模sourceid等于基模存储的componentid,
|
||
lstNewCompo.append(basePro->uuid());
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
return lstNewCompo;
|
||
}
|
||
|
||
QRectF FixedPortsModel::calculateItemsBoundingRect(QList<GraphicsBaseItem*> items)
|
||
{
|
||
if (items.isEmpty())
|
||
return QRectF();
|
||
|
||
// 初始化矩形为第一个item的场景边界矩形
|
||
QRectF boundingRect = items.first()->sceneBoundingRect();
|
||
|
||
// 遍历剩余item,扩展矩形以包含所有item
|
||
for (int i = 1; i < items.size(); ++i) {
|
||
QGraphicsItem* item = items.at(i);
|
||
// 确保item在场景中且有效
|
||
if (item && item->scene()) {
|
||
boundingRect = boundingRect.united(item->sceneBoundingRect());
|
||
}
|
||
}
|
||
return boundingRect.adjusted(-10,-10,10,10);
|
||
}
|
||
|
||
void FixedPortsModel::addBayByData(BayProperty* pData,ModelFunctionType typ)
|
||
{
|
||
if(typ == ModelFunctionType::ProjectModel){
|
||
QList<GraphicsBaseItem*> items;
|
||
QList<QUuid> lstCompo = pData->getLstComponent();
|
||
for(auto& id:lstCompo){
|
||
if(_nodeItem.contains(id)){
|
||
items.append(_nodeItem.value(id));
|
||
}
|
||
}
|
||
|
||
QRectF rec = calculateItemsBoundingRect(items);
|
||
auto pBay = new ElectricBayItem(rec);
|
||
pBay->setItemType(GIT_bay);
|
||
pBay->setProperty(pData);
|
||
pBay->setText(pData->name());
|
||
addBayItem(pData->uuid(),pBay);
|
||
getScene()->addItem(pBay);
|
||
}
|
||
}
|
||
|
||
void FixedPortsModel::showBayMeasureDlg(BayProperty* pPro)
|
||
{
|
||
if(m_bayMeasureDlg == nullptr)
|
||
{
|
||
m_bayMeasureDlg = new BayMeasureDlg(_widget);
|
||
}
|
||
m_bayMeasureDlg->showDlg(pPro);
|
||
}
|
||
|
||
QJsonObject FixedPortsModel::turnListToJson(QList<QUuid> lst,QString sInerTag,QString sOutTag)
|
||
{
|
||
QJsonObject o;
|
||
QJsonArray arr;
|
||
if(lst.isEmpty())
|
||
return QJsonObject();
|
||
for(auto id:lst)
|
||
{
|
||
QJsonObject obj;
|
||
obj[sInerTag] = id.toString();
|
||
arr.push_back(obj);
|
||
}
|
||
o[sOutTag] = arr;
|
||
return o;
|
||
}
|
||
|
||
QList<QUuid> FixedPortsModel::turnJsonArrToList(QJsonObject object,QString sInner,QString sOut)
|
||
{
|
||
QJsonArray jsonArray = object[sOut].toArray();
|
||
|
||
QList<QUuid> lst;
|
||
for (QJsonValueRef nodeJson : jsonArray)
|
||
{
|
||
QJsonObject node = nodeJson.toObject();
|
||
QUuid uid = QUuid(node[sInner].toString());
|
||
lst.append(uid);
|
||
}
|
||
return lst;
|
||
}
|
||
|
||
void FixedPortsModel::generateMonitorConfig(MonitorPanel* pPanel)
|
||
{
|
||
auto itemData = DataManager::instance().modelData();
|
||
auto itemState = DataManager::instance().modelState();
|
||
for(auto& pItem:_nodeItem){
|
||
auto pBasePro = pItem->getProperty();
|
||
auto pPro = dynamic_cast<BaseProperty*>(pBasePro);
|
||
if(pPro){
|
||
QString sModel = pPro->modelName();
|
||
QUuid uid = pPro->uuid();
|
||
QList<MonitorItemAttributeInfo> lstInfo;
|
||
if(itemState.contains(sModel)){ //动态表字段数据使用modelState初始化(兼容无值情况)
|
||
auto mapData = itemState.value(sModel).groupInfo;
|
||
for(auto iter = mapData.begin();iter != mapData.end();++iter){
|
||
if(iter.value().isPublic == true) //公共属性组暂不显示
|
||
continue;
|
||
for(auto& attr: iter.value().info){
|
||
MonitorItemAttributeInfo info;
|
||
info.sGroup = iter.key();
|
||
info.sTag = attr.tagName;
|
||
info.sName = attr.name;
|
||
info.nConnectType = 0;
|
||
lstInfo.append(info);
|
||
}
|
||
}
|
||
}
|
||
|
||
if(itemData.contains(sModel)){ //量测数据使用modelData初始化
|
||
auto mapData = itemData.value(sModel).groupInfo;
|
||
for(auto iter = mapData.begin();iter != mapData.end();iter++){ //遍历所有属性组
|
||
if(iter.key() == "bay"){ //量测数据放到间隔组
|
||
auto mapMeasure = pPro->getMeasurement();
|
||
for(auto it = mapMeasure.begin(); it != mapMeasure.end();++it){
|
||
MonitorItemAttributeInfo info;
|
||
info.sGroup = iter.key();
|
||
info.sTag = it->name;
|
||
info.sName = it->tag;
|
||
info.nConnectType = 1;
|
||
lstInfo.append(info);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
if(!lstInfo.isEmpty()){
|
||
if(!pPanel->getModelController()->getMonitorPara().contains(uid)){
|
||
pPanel->getModelController()->getMonitorPara().insert(uid,lstInfo);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
void FixedPortsModel::monitorItemSelected(QUuid uid)
|
||
{
|
||
auto pMonitor = dynamic_cast<MonitorPanel*>(_widget);
|
||
if(pMonitor){
|
||
pMonitor->itemSelected(uid);
|
||
}
|
||
}
|
||
|
||
void FixedPortsModel::monitorItemDetailAttr(QUuid uid)
|
||
{
|
||
auto pMonitor = dynamic_cast<MonitorPanel*>(_widget);
|
||
if(pMonitor){
|
||
pMonitor->detailItemSelected(uid);
|
||
}
|
||
}
|
||
|
||
void FixedPortsModel::monitorItemSet(QUuid uid)
|
||
{
|
||
if(_nodeItem.contains(uid)){
|
||
QList<QString> lstAdd; //需要向item添加的动态数据
|
||
|
||
auto pItem = _nodeItem.value(uid);
|
||
auto lst = m_monitorPara.value(uid);
|
||
|
||
for(auto& info:lst){
|
||
if(info.bShowDiagram && info.bSelected){
|
||
lstAdd.append(info.sTag);
|
||
}
|
||
}
|
||
|
||
pItem->removeAllDynamicText();
|
||
|
||
for(auto& str:lstAdd){
|
||
for(auto& info:lst){
|
||
if(info.sTag == str){
|
||
pItem->addDynamicText(info.sTag,info.sConnectPara);
|
||
continue;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
void FixedPortsModel::updateMonitorDisplay()
|
||
{
|
||
for(auto& pItem:_nodeItem){
|
||
auto pPro = pItem->getProperty();
|
||
if(pPro){
|
||
QString sMeta = pPro->metaModelName();
|
||
for(auto iter = m_monitorDisplaySetting.begin();iter != m_monitorDisplaySetting.end();++iter){ //将设置的显示数据更新到item(显示数据不放入item的property)
|
||
if(iter.key().sTag == sMeta){
|
||
pItem->setMonitorDisplayInfo(iter.value());
|
||
pItem->updateCurState(MonitorItemState::Normal);
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
void FixedPortsModel::startAcceptData()
|
||
{
|
||
QStringList lstTarget; //待订阅的对象
|
||
for(auto& lst:m_monitorPara){
|
||
for(auto& para:lst){
|
||
if(para.bSelected && !para.sConnectPara.isEmpty()){
|
||
if(!lstTarget.contains(para.sConnectPara))
|
||
lstTarget.append(para.sConnectPara);
|
||
}
|
||
}
|
||
}
|
||
|
||
QJsonObject obj; //构建开始请求
|
||
obj["action"] = "start";
|
||
QJsonArray arrMeasure;
|
||
|
||
QJsonObject objMeasure;
|
||
objMeasure["interval"] = "2s";
|
||
QJsonArray arrTargets;
|
||
for(auto& strTarget:lstTarget){
|
||
arrTargets.append(strTarget);
|
||
}
|
||
objMeasure["targets"] = arrTargets;
|
||
|
||
arrMeasure.append(objMeasure);
|
||
obj["measurements"] = arrMeasure;
|
||
|
||
QString sPath = "/monitors/data/subscriptions";
|
||
|
||
QJsonDocument doc(obj);
|
||
QVariant variant = doc.toVariant();
|
||
UiCommunicationBus::instance()->sendHttpRequest(sPath,variant,"POST");
|
||
|
||
QList<QPair<QString,QString>> requestLst; //等待请求的队列
|
||
for(auto& str:lstTarget){
|
||
requestLst.append(qMakePair(str,"request"));
|
||
}
|
||
|
||
UiCommunicationBus::instance()->insertTempRequest(_pageName,requestLst);
|
||
_curRequestLst = lstTarget;
|
||
m_dataTimer->start();
|
||
}
|
||
|
||
void FixedPortsModel::stopAcceptData(QString page)
|
||
{
|
||
if(UiCommunicationBus::instance()->getSesstionMap().contains(page)){
|
||
auto& curSession = UiCommunicationBus::instance()->getSesstionMap()[page];
|
||
|
||
QJsonObject obj; //构建开始请求
|
||
obj["action"] = "stop";
|
||
obj["client_id"] = curSession.first;
|
||
QJsonArray arrMeasure;
|
||
|
||
QJsonObject objMeasure;
|
||
objMeasure["interval"] = "2s";
|
||
QJsonArray arrTargets;
|
||
for(auto& pairTarget:curSession.second){
|
||
arrTargets.append(pairTarget.first);
|
||
pairTarget.second = "closing";
|
||
}
|
||
objMeasure["targets"] = arrTargets;
|
||
|
||
arrMeasure.append(objMeasure);
|
||
obj["measurements"] = arrMeasure;
|
||
|
||
QString sPath = "/monitors/data/subscriptions";
|
||
|
||
QJsonDocument doc(obj);
|
||
QVariant variant = doc.toVariant();
|
||
UiCommunicationBus::instance()->sendHttpRequest(sPath,variant,"POST");
|
||
}
|
||
m_dataTimer->stop();
|
||
}
|
||
|
||
int FixedPortsModel::imageRefExist(QString model,QByteArray hash256)
|
||
{
|
||
for(auto& info:_HMIimageRef)
|
||
{
|
||
if(model == info.model && hash256 == info.hash256)
|
||
return _HMIimageRef.indexOf(info);
|
||
}
|
||
return -1;
|
||
}
|
||
|
||
void FixedPortsModel::updateHMIRef(QUuid hmiId,QString model,QByteArray hash256,int slot)
|
||
{
|
||
HMIImageRef ref;
|
||
ref.hmiId = hmiId;
|
||
ref.model = model;
|
||
ref.hash256 = hash256;
|
||
ref.slot = slot;
|
||
int index = imageRefExist(model,hash256);
|
||
if(index != -1){ //已存在,替换
|
||
_HMIimageRef[index] = ref;
|
||
}
|
||
else{ //新建
|
||
_HMIimageRef.append(ref);
|
||
}
|
||
}
|