add diagram editor bay pteview
This commit is contained in:
parent
d1deb0c1a0
commit
5231c342fe
|
|
@ -38,7 +38,10 @@ enum GraphicsItemType
|
|||
GIT_baseNode = QGraphicsItem::UserType + 199,
|
||||
GIT_baseBus = QGraphicsItem::UserType + 200,
|
||||
GIT_baseLine = QGraphicsItem::UserType + 201,
|
||||
GIT_baseBreaker = QGraphicsItem::UserType + 202
|
||||
GIT_baseBreaker = QGraphicsItem::UserType + 202,
|
||||
GIT_baseCT = QGraphicsItem::UserType + 203,
|
||||
GIT_basePT = QGraphicsItem::UserType + 204,
|
||||
GIT_baseDS = QGraphicsItem::UserType + 205,
|
||||
};
|
||||
|
||||
enum AbstractItemType //工程模关联的对象类型
|
||||
|
|
@ -454,6 +457,9 @@ struct DiagramEditorComponentInfo //组态设备信息
|
|||
QStringList sUsedRoute; //使用设备的线路名
|
||||
int nUsedDirection = 0; //被占用的方向 8421 上下左右
|
||||
QPoint deltaPos = QPoint(0,0); //相对坐标(相对间隔)
|
||||
QUuid uid;
|
||||
int nFlag = 0; //标志0未使用1新建2修改
|
||||
int nRotate = 0; //旋转角
|
||||
};
|
||||
|
||||
struct DiagramEditorBayRouteInfo //间隔中单条线路信息
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ private:
|
|||
DiagramEditorBayPreviewDlg* _pPreviewDlg;
|
||||
DiagramEditorWizard* _pWizard;
|
||||
DiagramEditorBayBlock* _curOperateObj; //当前加载的block对象
|
||||
QStandardItemModel* _compoModel; //设备库model name中的data:1为占用方向,2为相对坐标,3为uuid,4为item创建标志位,5旋转角度
|
||||
QStandardItemModel* _compoModel; //设备库model name中的data:1为占用方向,2为相对坐标,3为uuid,4为item标志位(1新建2修改),5旋转角度
|
||||
QStandardItemModel* _routeModel; //所有线路model
|
||||
QMap<QString,DiagramEditorBayRouteInfo> _mapRouteInfo; //所有线路信息
|
||||
DiagramEditorModel* _pModel;
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ public:
|
|||
~DiagramEditorBayPreviewDlg();
|
||||
|
||||
void initial();
|
||||
void showDlg();
|
||||
void setParent(DiagramEditorBayDetailSettingDlg* p) {_pParent = p;}
|
||||
void updateModelData(); //根据设置更新data中布局、方向
|
||||
private:
|
||||
|
|
|
|||
|
|
@ -20,6 +20,13 @@ public:
|
|||
void createTopoTerminalsByItem(GraphicsBaseItem*,ModelFunctionType funType = ModelFunctionType::ProjectModel); //通过图形对象创建port接线点(新建)
|
||||
QPointF calculateBusPortPos(GraphicsBaseItem* pBus,GraphicsBaseItem* item); //计算母线上接线点位置
|
||||
template<typename TypeLine> void establishConnection(GraphicsBaseItem*,GraphicsBaseItem*,TypeLine*,ModelFunctionType); //在两个item之间建立连接
|
||||
double distanceBetweenItems(QGraphicsItem* item1, QGraphicsItem* item2) {
|
||||
QPointF center1 = item1->mapToScene(item1->boundingRect().center());
|
||||
QPointF center2 = item2->mapToScene(item2->boundingRect().center());
|
||||
|
||||
QPointF diff = center1 - center2;
|
||||
return qSqrt(diff.x() * diff.x() + diff.y() * diff.y());
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ class GraphicsBaseModelItem;
|
|||
class DiagramEditorItemProperty;
|
||||
class GraphicsBaseItem;
|
||||
class EditPreviewScene;
|
||||
class ElectricBaseModelLineItem;
|
||||
|
||||
class DiagramEditorModel : public BaseModel
|
||||
{
|
||||
|
|
@ -19,7 +20,8 @@ public:
|
|||
void createTopoTerminalsByItem(GraphicsBaseItem*,ModelFunctionType funType = ModelFunctionType::ProjectModel); //通过图形对象创建port接线点(新建)
|
||||
void generateTempBay(); //通过设置生成间隔预览对象
|
||||
void generateTempComponent(QUuid uid,QString sName,int nCategory,int nType,QPoint pos,int nRotate = 0); //生成设备 uid,分类(设备、逻辑点),类型,旋转
|
||||
void generateTempLine(QUuid uid,QString sName); //生成连线
|
||||
ElectricBaseModelLineItem* generateTempLine(QUuid uid,QString sName); //生成连线
|
||||
void clearCurPreview();
|
||||
|
||||
void setCurBayRouteModel(QStandardItemModel* p) {_pCurBayRoute = p;}
|
||||
QStandardItemModel* getCurBayRouteModel() {return _pCurBayRoute;}
|
||||
|
|
|
|||
|
|
@ -166,7 +166,7 @@ public:
|
|||
virtual ItemControlHandle* getHandlePtr(int) const;
|
||||
virtual QMap<QString,ItemPort*> getPorts() {return m_mapPort;}
|
||||
//virtual GraphicsBaseItem*
|
||||
virtual void initialPortsByDatabase(); //从数据库初始化port信息
|
||||
virtual void initialPortsByDatabase(int nComponentTypeId); //从数据库初始化port信息,component_type中的id
|
||||
virtual void setLastPoint(QPointF p) {m_lastPoint = p;}
|
||||
virtual void setTouched(bool b){m_touched = b;}
|
||||
|
||||
|
|
|
|||
|
|
@ -22,6 +22,8 @@ public:
|
|||
PowerEntity* findEntity(const QString& id,ModelFunctionType = ModelFunctionType::ProjectModel) const;
|
||||
bool deleteEntity(const QString& id,ModelFunctionType = ModelFunctionType::ProjectModel);
|
||||
QList<PowerEntity*> getEntitiesByBlock(const QString&); //通过名称返回entity中的实体(blockEditor中)
|
||||
void moveTempBlockData(); //blockEditor中将临时数据转为全局数据
|
||||
void clearGlobalBlockData(const QString&); //清除全局数据中的blockdata(block修改时)
|
||||
|
||||
// 连接管理
|
||||
PowerConnection* createConnection(const QString& uuid,const QString& fromTerId, const QString& toTerId,const QString& fromId,const QString& toId,ModelFunctionType tpe = ModelFunctionType::ProjectModel);
|
||||
|
|
@ -33,6 +35,7 @@ public:
|
|||
QList<PowerConnection*> getConnectionsFor(const QString& entityId,ModelFunctionType tpe = ModelFunctionType::ProjectModel) const;
|
||||
PowerConnection* connection(const QString& conId,ModelFunctionType tpe = ModelFunctionType::ProjectModel) const;
|
||||
PowerConnection* connection(const QString& fromPin,const QString& toPin,ModelFunctionType tpe = ModelFunctionType::ProjectModel);
|
||||
PowerConnection* ifConnection(const QString& entityId1,const QString& entityId2,ModelFunctionType tpe = ModelFunctionType::ProjectModel); //返回两个item之间的连接
|
||||
QHash<QString,PowerConnection*> getAllConnections(ModelFunctionType tpe = ModelFunctionType::ProjectModel);
|
||||
|
||||
PowerEntity* getEntity(const QString& id,ModelFunctionType tpe = ModelFunctionType::ProjectModel) const;
|
||||
|
|
@ -108,7 +111,6 @@ private:
|
|||
QHash<QString, QList<PowerTerminal*>> m_blockTerminalsByEntity; // 实体ID到接线点列表(模块编辑)
|
||||
|
||||
QHash<QString, QSet<QString>> m_blockEntityConnections; // <entityId, Set<connectionId>>(模块编辑)
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -36,6 +36,8 @@ void DiagramEditorBayDetailAddDlg::initial()
|
|||
connect(ui->tableView_selected, &QTableView::customContextMenuRequested, this, &DiagramEditorBayDetailAddDlg::onRouteRbtnClicked);
|
||||
connect(ui->tableView_items, &QTableView::customContextMenuRequested, this, &DiagramEditorBayDetailAddDlg::onComponentRbtnClicked);
|
||||
|
||||
ui->cb_category->addItem("电气设备",0);
|
||||
ui->cb_category->addItem("连接关系",1);
|
||||
ui->cb_type->addItem("母线",1);
|
||||
ui->cb_type->addItem("异步电动机",2);
|
||||
ui->cb_type->addItem("断路器",3);
|
||||
|
|
@ -197,7 +199,7 @@ void DiagramEditorBayDetailAddDlg::onAddClicked()
|
|||
if (sourceItem) {
|
||||
// 创建深拷贝(重要!)
|
||||
if(col == 4){ //线路引用,特殊处理
|
||||
QString strAllRoute;
|
||||
QString strAllRoute = sourceItem->text();
|
||||
QString strCurRoute = ui->le_routeName->text();
|
||||
|
||||
if(!strAllRoute.contains(strCurRoute)){ //第一个引用不加符号
|
||||
|
|
@ -227,6 +229,7 @@ void DiagramEditorBayDetailAddDlg::onDeleteClicked()
|
|||
void DiagramEditorBayDetailAddDlg::onSaveClicked()
|
||||
{
|
||||
QString sCategory = ui->cb_category->currentText();
|
||||
int nCate = ui->cb_category->currentData().toInt();
|
||||
QString sName = ui->le_name->text();
|
||||
QString sType = ui->cb_type->currentText();
|
||||
int nType = ui->cb_type->currentData().toInt();
|
||||
|
|
@ -254,7 +257,6 @@ void DiagramEditorBayDetailAddDlg::onSaveClicked()
|
|||
QStandardItem *itemRoute = pCompoModel->item(i, 4);
|
||||
|
||||
item->setData(0); //覆盖时初始化方向占用
|
||||
item->setData(QUuid::createUuid(),Qt::UserRole+3); //初始化时赋予uuid
|
||||
itemCate->setText(sCategory);
|
||||
itemType->setText(sType);
|
||||
itemType->setData(nType);
|
||||
|
|
@ -278,8 +280,10 @@ void DiagramEditorBayDetailAddDlg::onSaveClicked()
|
|||
QStandardItem *itemObj = new QStandardItem();
|
||||
QStandardItem *itemRoute = new QStandardItem();
|
||||
itemCate->setText(sCategory);
|
||||
itemCate->setData(nCate);
|
||||
itemName->setText(sName);
|
||||
itemName->setData(0); //初始化方向占用
|
||||
itemName->setData(QUuid::createUuid(),Qt::UserRole+3); //初始化时赋予uuid
|
||||
itemType->setText(sType);
|
||||
itemType->setData(nType);
|
||||
itemObj->setText(sBindObj);
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@
|
|||
#include "ui_diagramEditorBayDetailSettingDlg.h"
|
||||
#include "diagramEditor/diagramEditorBaseBlock.h"
|
||||
#include "graphicsDataModel/diagramEditorModel.h"
|
||||
#include "topologyManager.h"
|
||||
|
||||
DiagramEditorBayDetailSettingDlg::DiagramEditorBayDetailSettingDlg(QWidget *parent)
|
||||
: QDialog(parent)
|
||||
|
|
@ -193,8 +194,11 @@ void DiagramEditorBayDetailSettingDlg::onOkClicked()
|
|||
QStandardItem *itemType = _compoModel->item(i, 2);
|
||||
QStandardItem *itemBind = _compoModel->item(i, 3);
|
||||
QStandardItem *itemRoute = _compoModel->item(i, 4);
|
||||
int nDir = itemName->data(Qt::UserRole+1).toInt();
|
||||
QPoint deltaPos = itemName->data(Qt::UserRole+2).toPoint();
|
||||
int nDir = itemName->data(Qt::UserRole+1).toInt(); //连接方向
|
||||
QPoint deltaPos = itemName->data(Qt::UserRole+2).toPoint(); //相对位置
|
||||
QUuid uid = itemName->data(Qt::UserRole+3).toUuid(); //uid
|
||||
int nVal = itemName->data(Qt::UserRole+4).toInt(); //标志
|
||||
int nRotate = itemName->data(Qt::UserRole+5).toInt(); //旋转角度
|
||||
|
||||
DiagramEditorComponentInfo compoInfo;
|
||||
if(itemCate->text() == "电气设备"){
|
||||
|
|
@ -209,6 +213,9 @@ void DiagramEditorBayDetailSettingDlg::onOkClicked()
|
|||
compoInfo.sUsedRoute = itemRoute->text().split(",");
|
||||
compoInfo.nUsedDirection = nDir;
|
||||
compoInfo.deltaPos = deltaPos;
|
||||
compoInfo.uid = uid;
|
||||
compoInfo.nFlag = nVal;
|
||||
compoInfo.nRotate = nRotate;
|
||||
|
||||
mapComponents.insert(compoInfo.sName,compoInfo);
|
||||
}
|
||||
|
|
@ -216,6 +223,10 @@ void DiagramEditorBayDetailSettingDlg::onOkClicked()
|
|||
_curOperateObj = nullptr;
|
||||
}
|
||||
hide();
|
||||
_pModel->clearCurPreview(); //关闭时清除预览Item
|
||||
//todo:清除mainPanel中的对应item(如果存在)
|
||||
TopologyManager::instance().clearGlobalBlockData(_curOperateObj->getName());
|
||||
TopologyManager::instance().moveTempBlockData();
|
||||
}
|
||||
|
||||
void DiagramEditorBayDetailSettingDlg::onCancelClicked()
|
||||
|
|
@ -310,19 +321,13 @@ void DiagramEditorBayDetailSettingDlg::onPreviewClicked()
|
|||
{
|
||||
if(_pPreviewDlg == nullptr){
|
||||
_pPreviewDlg = new DiagramEditorBayPreviewDlg(this);
|
||||
_pPreviewDlg->setParent(this);
|
||||
_pModel->setCurBayComponentModel(_compoModel);
|
||||
_pModel->setCurBayRouteModel(_routeModel);
|
||||
}
|
||||
if(!_pPreviewDlg->isVisible()){
|
||||
|
||||
/*int rowCount = _routeModel->rowCount();
|
||||
for(int i = 0;i < rowCount;++i){
|
||||
QStandardItem *itemComps = _routeModel->item(i, 1);
|
||||
QString str = itemComps->text();
|
||||
QStringList lstComps = str.split(",");
|
||||
for(auto& sCompName:lstComps){
|
||||
QStandardItem* pItemName = _pModel->getNameItem(sCompName);
|
||||
}
|
||||
}*/
|
||||
|
||||
_pPreviewDlg->showDlg();
|
||||
_pModel->generateTempBay();
|
||||
}
|
||||
else
|
||||
_pPreviewDlg->hide();
|
||||
|
|
|
|||
|
|
@ -30,7 +30,15 @@ void DiagramEditorBayPreviewDlg::initial()
|
|||
_pScene = new EditPreviewScene(this);
|
||||
_pScene->setSceneRect(-g_dGriaphicsScene_Width / 2, -g_dGriaphicsScene_Height / 2, g_dGriaphicsScene_Width, g_dGriaphicsScene_Height);
|
||||
_pView->setScene(_pScene);
|
||||
}
|
||||
|
||||
void DiagramEditorBayPreviewDlg::showDlg()
|
||||
{
|
||||
if(_pParent){
|
||||
_pParent->getModel()->setCurPreviewScene(_pScene);
|
||||
}
|
||||
show();
|
||||
updateModelData();
|
||||
}
|
||||
|
||||
void DiagramEditorBayPreviewDlg::updateModelData()
|
||||
|
|
@ -123,11 +131,10 @@ void DiagramEditorBayPreviewDlg::updateModelData()
|
|||
auto pItem = _pParent->getModel()->getNameItem(route.lstOrder[i].sName);
|
||||
int nVal = pItem->data().toInt();
|
||||
QPoint deltaP = pItem->data(Qt::UserRole+2).toPoint();
|
||||
|
||||
auto pNextItem = _pParent->getModel()->getNameItem(route.lstOrder[i+1].sName); //下一个item
|
||||
nOrderFirstDeltaY = deltaP.y();
|
||||
int nNextVal = pNextItem->data().toInt();
|
||||
if(i == 0){ //首节点
|
||||
nOrderFirstDeltaY = deltaP.y();
|
||||
if(((nVal & 2) == 1) && ((nVal & 1) == 1)){
|
||||
qDebug()<<QString("point %1 full of connection").arg(route.lstOrder[i].sName);
|
||||
}
|
||||
|
|
@ -136,36 +143,26 @@ void DiagramEditorBayPreviewDlg::updateModelData()
|
|||
pItem->setData(QString::number(nVal | 1));
|
||||
pNextItem->setData(QString::number(nNextVal | 2)); //同时连接下个点的一侧占用
|
||||
nOrderPolarity = 1;
|
||||
pNextItem->setData(-90,Qt::UserRole+5);
|
||||
}
|
||||
else if((nVal & 1) == 1){
|
||||
//右被占用,左空
|
||||
pItem->setData(QString::number(nVal | 2));
|
||||
pNextItem->setData(QString::number(nNextVal | 1));
|
||||
nOrderPolarity = -1;
|
||||
pNextItem->setData(90,Qt::UserRole+5);
|
||||
}
|
||||
else{ //左右都没被占,默认放到左边
|
||||
pItem->setData(QString::number(nVal | 1));
|
||||
pNextItem->setData(QString::number(nNextVal | 2));
|
||||
nOrderPolarity = 1;
|
||||
pNextItem->setData(-90,Qt::UserRole+5);
|
||||
}
|
||||
int deltaX = nXOrderIndex*nOrderPolarity*g_nHDiagramSpacing;
|
||||
pNextItem->setData(QPoint(deltaX,nOrderFirstDeltaY),Qt::UserRole + 2);
|
||||
continue;
|
||||
}
|
||||
/*if(i == 0){ //首节点特殊处理
|
||||
if(((nVal & 8) == 1) && ((nVal & 4) == 1)){ //上下都被占,在中间
|
||||
|
||||
}
|
||||
else if((nVal & 8) == 1 ){ //上被占,在末尾
|
||||
|
||||
}
|
||||
else if((nVal & 4) == 1 ){ //下被占,在头部
|
||||
|
||||
}
|
||||
}
|
||||
else{
|
||||
|
||||
}*/
|
||||
|
||||
int deltaX = nXOrderIndex*nOrderPolarity*g_nHDiagramSpacing;
|
||||
if(((nVal & 2) == 1) && ((nVal & 1) == 1)){
|
||||
qDebug()<<QString("point %1 full of connection").arg(route.lstOrder[i].sName);
|
||||
}
|
||||
|
|
@ -183,47 +180,54 @@ void DiagramEditorBayPreviewDlg::updateModelData()
|
|||
pItem->setData(QString::number(nVal | 1));
|
||||
pNextItem->setData(QString::number(nNextVal | 2));
|
||||
}
|
||||
int deltaX = nXOrderIndex*nOrderPolarity*g_nHDiagramSpacing;
|
||||
pNextItem->setData(QPoint(deltaX,nOrderFirstDeltaY),Qt::UserRole + 2);
|
||||
nXOrderIndex += 1;
|
||||
}
|
||||
}
|
||||
|
||||
int nReverseFirstDeltaY = 0; //首节点y偏移量(假设后续节点与头节点水平)
|
||||
int nXReverseIndex = 1; //横向计数
|
||||
int nReversePolarity = 1; //方向 1右 -1左
|
||||
if(route.lstOrder.size() > 1){
|
||||
for(int i = 0;i < route.lstOrder.size()-1;++i){ //遍历以节点为首的队列
|
||||
auto pItem = _pParent->getModel()->getNameItem(route.lstOrder[i].sName);
|
||||
if(route.lstReverse.size() > 1){
|
||||
for(int i = 0;i < route.lstReverse.size()-1;++i){ //遍历以节点为首的队列
|
||||
auto pItem = _pParent->getModel()->getNameItem(route.lstReverse[i].sName);
|
||||
int nVal = pItem->data().toInt();
|
||||
QPoint deltaP = pItem->data(Qt::UserRole+2).toPoint();
|
||||
|
||||
auto pNextItem = _pParent->getModel()->getNameItem(route.lstOrder[i+1].sName); //下一个item
|
||||
auto pNextItem = _pParent->getModel()->getNameItem(route.lstReverse[i+1].sName); //下一个item
|
||||
nReverseFirstDeltaY = deltaP.y();
|
||||
|
||||
int nNextVal = pNextItem->data().toInt();
|
||||
if(i == 0){ //首节点
|
||||
nReverseFirstDeltaY = deltaP.y();
|
||||
if(((nVal & 2) == 1) && ((nVal & 1) == 1)){
|
||||
qDebug()<<QString("point %1 full of connection").arg(route.lstOrder[i].sName);
|
||||
qDebug()<<QString("point %1 full of connection").arg(route.lstReverse[i].sName);
|
||||
}
|
||||
else if((nVal & 2) == 1){
|
||||
//左被占用,右空
|
||||
pItem->setData(QString::number(nVal | 1));
|
||||
pNextItem->setData(QString::number(nNextVal | 2)); //同时连接下个点的一侧占用
|
||||
nReversePolarity = 1;
|
||||
pNextItem->setData(-90,Qt::UserRole+5);
|
||||
}
|
||||
else if((nVal & 1) == 1){
|
||||
//右被占用,左空
|
||||
pItem->setData(QString::number(nVal | 2));
|
||||
pNextItem->setData(QString::number(nNextVal | 1));
|
||||
nReversePolarity = -1;
|
||||
pNextItem->setData(90,Qt::UserRole+5);
|
||||
}
|
||||
else{ //左右都没被占,默认放到左边
|
||||
pItem->setData(QString::number(nVal | 1));
|
||||
pNextItem->setData(QString::number(nNextVal | 2));
|
||||
nReversePolarity = 1;
|
||||
pNextItem->setData(-90,Qt::UserRole+5);
|
||||
}
|
||||
int deltaX = nXReverseIndex*nReversePolarity*g_nHDiagramSpacing;
|
||||
pNextItem->setData(QPoint(deltaX,nReverseFirstDeltaY),Qt::UserRole + 2);
|
||||
continue;
|
||||
}
|
||||
|
||||
int deltaX = nXReverseIndex*nReversePolarity*g_nHDiagramSpacing;
|
||||
if(((nVal & 2) == 1) && ((nVal & 1) == 1)){
|
||||
qDebug()<<QString("point %1 full of connection").arg(route.lstOrder[i].sName);
|
||||
}
|
||||
|
|
@ -241,7 +245,9 @@ void DiagramEditorBayPreviewDlg::updateModelData()
|
|||
pItem->setData(QString::number(nVal | 1));
|
||||
pNextItem->setData(QString::number(nNextVal | 2));
|
||||
}
|
||||
int deltaX = nXReverseIndex*nReversePolarity*g_nHDiagramSpacing;
|
||||
pNextItem->setData(QPoint(deltaX,nReverseFirstDeltaY),Qt::UserRole + 2);
|
||||
nXReverseIndex += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -383,6 +383,7 @@ void EditPanel::onItemDbClicked(QPointer<DiagramEditorBaseBlock> pBlock)
|
|||
if(pBlock->getType() == 2){ //间隔
|
||||
if(_bayDetailSetting == nullptr){
|
||||
_bayDetailSetting = new DiagramEditorBayDetailSettingDlg(this);
|
||||
_bayDetailSetting->setModelDelegate(_pModel);
|
||||
}
|
||||
auto pBay = dynamic_cast<DiagramEditorBayBlock*>(pBlock.data());
|
||||
if(pBay)
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ template<typename TypeLine> void BaseModel::establishConnection(GraphicsBaseItem
|
|||
int nTypeSrc = pSrc->getProperty()->type();
|
||||
int nTypeDest = pDest->getProperty()->type();
|
||||
//if(pSrc->getItemType() == GIT_baseBus)
|
||||
if(nTypeSrc == 1 || nTypeSrc == 14) //母线或节点
|
||||
if((nTypeSrc == 1 || nTypeSrc == 0) && (nTypeDest != 1 && nTypeDest != 0)) //母线或节点
|
||||
{
|
||||
int index = 0;
|
||||
if(nTypeSrc == 1 )
|
||||
|
|
@ -60,19 +60,23 @@ template<typename TypeLine> void BaseModel::establishConnection(GraphicsBaseItem
|
|||
pSrcPort = pSrc->getPortPtr(index);
|
||||
|
||||
QMap<QString,ItemPort*> mapPorts = pDest->getPorts();
|
||||
double minDis = 999;
|
||||
|
||||
for(auto& port:mapPorts)
|
||||
for(auto& port:mapPorts) //与母线或节点连接时,连接最近接线点
|
||||
{
|
||||
if(port->getType() == T_lineIn)
|
||||
double dis = distanceBetweenItems(port,pDest);
|
||||
if(dis < minDis){
|
||||
minDis = dis;
|
||||
pDestPort = port;
|
||||
}
|
||||
/*if(port->getType() == T_lineIn)
|
||||
{
|
||||
pDestPort = port;
|
||||
break;
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
}
|
||||
//else if(pDest->getItemType() == GIT_baseBus)
|
||||
else if(nTypeDest == 1 || nTypeDest == 14) //母线或节点
|
||||
else if((nTypeDest == 1 || nTypeDest == 0) && (nTypeSrc != 1 && nTypeSrc != 0))
|
||||
{
|
||||
int index = 0;
|
||||
if(nTypeDest == 1 )
|
||||
|
|
@ -83,16 +87,39 @@ template<typename TypeLine> void BaseModel::establishConnection(GraphicsBaseItem
|
|||
pDestPort = pDest->getPortPtr(index);
|
||||
|
||||
QMap<QString,ItemPort*> mapPorts = pSrc->getPorts();
|
||||
double minDis = 999;
|
||||
|
||||
for(auto& port:mapPorts)
|
||||
for(auto& port:mapPorts) //与母线或节点连接时,连接最近接线点
|
||||
{
|
||||
if(port->getType() == T_lineOut)
|
||||
double dis = distanceBetweenItems(port,pDest);
|
||||
if(dis < minDis){
|
||||
minDis = dis;
|
||||
pSrcPort = port;
|
||||
}
|
||||
/*if(port->getType() == T_lineOut)
|
||||
{
|
||||
pSrcPort = port;
|
||||
break;
|
||||
}
|
||||
}*/
|
||||
}
|
||||
}
|
||||
else if((nTypeSrc == 1 || nTypeSrc == 0) && (nTypeDest == 1 || nTypeDest == 0)){ //两个都是母线或节点
|
||||
int index = 0;
|
||||
if(nTypeSrc == 1 )
|
||||
index = pSrc->addPort(p_movable,pSrc->mapFromScene(calculateBusPortPos(pSrc,pDest)));
|
||||
else
|
||||
index = pSrc->addPort(p_movable,QPoint(0,0)); //节点port与自身坐标重合
|
||||
createTopoTerminalsByItem(pSrc,nType);
|
||||
pSrcPort = pSrc->getPortPtr(index);
|
||||
|
||||
index = 0;
|
||||
if(nTypeDest == 1 )
|
||||
index = pDest->addPort(p_movable,pDest->mapFromScene(calculateBusPortPos(pDest,pSrc)));
|
||||
else
|
||||
index = pDest->addPort(p_movable,QPoint(0,0)); //节点port与自身坐标重合
|
||||
createTopoTerminalsByItem(pDest,nType);
|
||||
pDestPort = pDest->getPortPtr(index);
|
||||
}
|
||||
else
|
||||
{
|
||||
QMap<QString,ItemPort*> mapSrc = pSrc->getPorts();
|
||||
|
|
|
|||
|
|
@ -105,31 +105,50 @@ void DiagramEditorModel::generateTempBay()
|
|||
QModelIndex indexType = index.sibling(index.row(),2);
|
||||
if(!pItem->data(Qt::UserRole+4).isValid()){ //未初始化,新建item
|
||||
pItem->setData(1,Qt::UserRole+4);
|
||||
int nCate = indexCate.data().toInt(); //0设备1连接
|
||||
int nType = indexType.data().toInt();
|
||||
int nCate = indexCate.data(Qt::UserRole+1).toInt(); //0设备1连接
|
||||
int nType = indexType.data(Qt::UserRole+1).toInt();
|
||||
int nDir = pItem->data().toInt();
|
||||
int nRotate = 0;
|
||||
if(nDir == 12 || nDir == 8 || nDir == 4){ //垂直连接
|
||||
pItem->setData(0,Qt::UserRole+5); //垂直不旋转
|
||||
nRotate = 0;
|
||||
}
|
||||
else if(nDir == 2 || nDir == 1){ //水平
|
||||
pItem->setData(90,Qt::UserRole+5); //水平的item旋转
|
||||
nRotate = 90;
|
||||
}
|
||||
else{
|
||||
pItem->setData(0,Qt::UserRole+5); //全被连不旋转
|
||||
nRotate = 0;
|
||||
}
|
||||
if(pItem->data(Qt::UserRole+5).isValid())
|
||||
nRotate = pItem->data(Qt::UserRole+5).toInt();
|
||||
QPoint pos = pItem->data(Qt::UserRole+2).toPoint();
|
||||
QUuid uid = pItem->data(Qt::UserRole+3).toUuid();
|
||||
generateTempComponent(uid,name,nCate,nType,pos,nRotate);
|
||||
if(!_tempItem.contains(uid))
|
||||
generateTempComponent(uid,name,nCate,nType,pos,nRotate);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for(int i = 0;i < lst.size() -1;++i){
|
||||
if(lst.size() > 1){
|
||||
for(int i = 0;i < lst.size() -1;++i){
|
||||
QStandardItem* pItemFirst = getNameItem(lst[i]);
|
||||
QStandardItem* pItemSecond = getNameItem(lst[i+1]);
|
||||
|
||||
if(pItemFirst && pItemSecond){
|
||||
QUuid uid1 = pItemFirst->data(Qt::UserRole+3).toUuid();
|
||||
QUuid uid2 = pItemSecond->data(Qt::UserRole+3).toUuid();
|
||||
|
||||
if(_tempItem.contains(uid1) && _tempItem.contains(uid2)){
|
||||
GraphicsBaseModelItem* p1 = _tempItem.value(uid1);
|
||||
GraphicsBaseModelItem* p2 = _tempItem.value(uid2);
|
||||
auto pLineData = TopologyManager::instance().ifConnection(uid1.toString(),uid2.toString()); //判断两个item是否有连接
|
||||
if(pLineData != nullptr){
|
||||
if(!_tempItem.contains(QUuid(pLineData->id()))){ //connectdata已存在,item未绘制
|
||||
auto pLine = generateTempLine(QUuid(pLineData->id()),""); //重新绘制
|
||||
if(pLine)
|
||||
establishConnection(p1,p2,pLine,ModelFunctionType::BaseModel);
|
||||
}
|
||||
else{ //已绘制,略过
|
||||
}
|
||||
}
|
||||
else{ //connectdata不存在,新建
|
||||
auto pLine = generateTempLine(QUuid::createUuid(),"");
|
||||
if(pLine)
|
||||
establishConnection(p1,p2,pLine,ModelFunctionType::BaseModel);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -144,24 +163,44 @@ void DiagramEditorModel::generateTempComponent(QUuid uid,QString sName,int nCate
|
|||
byte = DataBase::GetInstance()->ModelType()[nType].icon;
|
||||
auto pBus = new ElectricBaseModelSvgBus(QRect(-200, -3, 400, 6));
|
||||
pBus->loadSvg(byte);
|
||||
pItem = pBus;
|
||||
pItem->setItemType(GIT_baseBus);
|
||||
}
|
||||
else if(nType == 2){ //异步电动机
|
||||
}
|
||||
else if(nType == 3){ //断路器
|
||||
byte = DataBase::GetInstance()->ModelType()[nType].icon;
|
||||
byte = DataBase::GetInstance()->ModelType()[nType].icon; //注意modelType表与componentType表不一致!
|
||||
auto pBreaker = new ElectricBaseModelSvgItem(QRect(-15, -15, 30, 30));
|
||||
pBreaker->loadSvg(byte);
|
||||
pItem = pBreaker;
|
||||
pItem->setItemType(GIT_baseBreaker);
|
||||
pItem->initialPortsByDatabase();
|
||||
pItem->initialPortsByDatabase(3);
|
||||
}
|
||||
else if(nType == 4){ //电缆
|
||||
}
|
||||
else if(nType == 5){ //电流互感器
|
||||
byte = DataBase::GetInstance()->ModelType()[nType].icon; //注意modelType表与componentType表不一致!
|
||||
auto pBreaker = new ElectricBaseModelSvgItem(QRect(-10, -10, 20, 20));
|
||||
pBreaker->loadSvg(byte);
|
||||
pItem = pBreaker;
|
||||
pItem->setItemType(GIT_baseCT);
|
||||
pItem->initialPortsByDatabase(4);
|
||||
}
|
||||
else if(nType == 6){ //电压互感器
|
||||
byte = DataBase::GetInstance()->ModelType()[nType].icon; //注意modelType表与componentType表不一致!
|
||||
auto pBreaker = new ElectricBaseModelSvgItem(QRect(-25, -25, 50, 50));
|
||||
pBreaker->loadSvg(byte);
|
||||
pItem = pBreaker;
|
||||
pItem->setItemType(GIT_basePT);
|
||||
pItem->initialPortsByDatabase(5);
|
||||
}
|
||||
else if(nType == 7){ //隔离开关
|
||||
byte = DataBase::GetInstance()->ModelType()[nType].icon; //注意modelType表与componentType表不一致!
|
||||
auto pBreaker = new ElectricBaseModelSvgItem(QRect(-15, -15, 30, 30));
|
||||
pBreaker->loadSvg(byte);
|
||||
pItem = pBreaker;
|
||||
pItem->setItemType(GIT_baseDS);
|
||||
pItem->initialPortsByDatabase(9);
|
||||
}
|
||||
else if(nType == 8){ //接地开关
|
||||
}
|
||||
|
|
@ -211,12 +250,12 @@ void DiagramEditorModel::generateTempComponent(QUuid uid,QString sName,int nCate
|
|||
}
|
||||
}
|
||||
|
||||
void DiagramEditorModel::generateTempLine(QUuid uid,QString sName)
|
||||
ElectricBaseModelLineItem* DiagramEditorModel::generateTempLine(QUuid uid,QString sName)
|
||||
{
|
||||
ElectricBaseModelLineItem* pLine = new ElectricBaseModelLineItem();
|
||||
pLine->setItemId(uid);
|
||||
pLine->setItemType(GIT_baseLine);
|
||||
DiagramEditorItemProperty* pData = addTempPreviewData(uid,4,sName,DataBase::GetInstance()->ModelType()[4].modelType);
|
||||
DiagramEditorItemProperty* pData = addTempPreviewData(uid,8,sName,DataBase::GetInstance()->ModelType()[4].modelType);
|
||||
pData->setGraphicsType(GIT_baseLine);
|
||||
if(pData)
|
||||
{
|
||||
|
|
@ -226,6 +265,13 @@ void DiagramEditorModel::generateTempLine(QUuid uid,QString sName)
|
|||
addTempPreviewItem(uid,pLine);
|
||||
//establishConnection(pBreaker,pBus,pLine,ModelFunctionType::BaseModel);
|
||||
_pCurPreviewScene->addItem(pLine);
|
||||
return pLine;
|
||||
}
|
||||
|
||||
void DiagramEditorModel::clearCurPreview()
|
||||
{
|
||||
if(_pCurPreviewScene)
|
||||
_pCurPreviewScene->clear();
|
||||
}
|
||||
|
||||
QStandardItem* DiagramEditorModel::getNameItem(const QString& sName)
|
||||
|
|
|
|||
|
|
@ -1359,7 +1359,7 @@ void FixedPortsModel::addTestData()
|
|||
if(pBreakerData)
|
||||
{
|
||||
pBreaker->setProperty(pBreakerData);
|
||||
pBreaker->initialPortsByDatabase();
|
||||
pBreaker->initialPortsByDatabase(3);
|
||||
createTopoTerminalsByItem(pBreaker,ModelFunctionType::BaseModel);
|
||||
pBreakerData->setDataChanged(true); //数据状态改变
|
||||
}
|
||||
|
|
|
|||
|
|
@ -163,17 +163,13 @@ void GraphicsBaseItem::onUpdateData()
|
|||
updateByProperty();
|
||||
}
|
||||
|
||||
void GraphicsBaseItem::initialPortsByDatabase()
|
||||
void GraphicsBaseItem::initialPortsByDatabase(int nComponentTypeId)
|
||||
{
|
||||
QMap<int,componentTypeInfo> mapType = DataBase::GetInstance()->getAllComponentType();
|
||||
|
||||
if(_property == nullptr){
|
||||
qDebug()<<"item property null";
|
||||
return;
|
||||
}
|
||||
if(mapType.contains(_property->type()))
|
||||
if(mapType.contains(nComponentTypeId))
|
||||
{
|
||||
QJsonArray nodesJsonArray = mapType[_property->type()].config["port"].toArray();
|
||||
QJsonArray nodesJsonArray = mapType[nComponentTypeId].config["port"].toArray();
|
||||
|
||||
for (QJsonValueRef nodeJson : nodesJsonArray)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -45,6 +45,14 @@ void TopologyManager::clearAllData()
|
|||
qDeleteAll(m_editorEntities);
|
||||
m_editorEntities.clear();
|
||||
m_editorAllTerminals.clear(); //端点由父亲entity释放
|
||||
|
||||
qDeleteAll(m_blockConnections);
|
||||
m_blockConnections.clear();
|
||||
m_blockConnectionIndex.clear();
|
||||
// 删除所有实体(自动删除子对象)
|
||||
qDeleteAll(m_blockEntities);
|
||||
m_blockEntities.clear();
|
||||
m_blockAllTerminals.clear(); //端点由父亲entity释放
|
||||
}
|
||||
|
||||
PowerEntity* TopologyManager::createEntity(EntityType type,const QString& uuid, const QString& name,ModelFunctionType funType,const QString& block)
|
||||
|
|
@ -244,6 +252,35 @@ QList<PowerEntity*> TopologyManager::getEntitiesByBlock(const QString& str)
|
|||
return lst;
|
||||
}
|
||||
|
||||
void TopologyManager::moveTempBlockData()
|
||||
{
|
||||
auto tempEntities = std::move(m_blockEntities);
|
||||
m_editorEntities.insert(tempEntities);
|
||||
|
||||
auto tempConnections = std::move(m_blockConnections);
|
||||
m_editorConnections.insert(tempConnections);
|
||||
|
||||
auto tempConIndex = std::move(m_blockConnectionIndex);
|
||||
m_editorConnectionIndex.unite(tempConIndex);
|
||||
|
||||
auto tempTer = std::move(m_blockAllTerminals);
|
||||
m_editorAllTerminals.insert(tempTer);
|
||||
|
||||
auto tempEntityTer = std::move(m_blockTerminalsByEntity);
|
||||
m_editorTerminalsByEntity.insert(tempEntityTer);
|
||||
|
||||
auto tempEntityCon = std::move(m_blockEntityConnections);
|
||||
m_editorEntityConnections.insert(tempEntityCon);
|
||||
}
|
||||
|
||||
void TopologyManager::clearGlobalBlockData(const QString& sName)
|
||||
{
|
||||
QList<PowerEntity*> lst = getEntitiesByBlock(sName);
|
||||
for(auto p:lst){
|
||||
deleteEntity(p->id(),ModelFunctionType::EditorModel);
|
||||
}
|
||||
}
|
||||
|
||||
PowerConnection* TopologyManager::createConnection(const QString& connId,const QString& fromTerId, const QString& toTerId,const QString& fromId,const QString& toId,ModelFunctionType funType)
|
||||
{
|
||||
PowerConnection* conn = nullptr;
|
||||
|
|
@ -583,6 +620,37 @@ PowerConnection* TopologyManager::connection(const QString& fromPin,const QStrin
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
PowerConnection* TopologyManager::ifConnection(const QString& entityId1,const QString& entityId2,ModelFunctionType funType)
|
||||
{
|
||||
QList<PowerConnection*> lst1;
|
||||
QList<PowerConnection*> lst2;
|
||||
|
||||
QList<PowerTerminal*> lstTerminal1 = getTerminalsForEntity(entityId1,funType);
|
||||
for(auto &terminal:lstTerminal1)
|
||||
{
|
||||
PowerConnection* con = getConnectionContainsTerminal(terminal->id(),funType);
|
||||
if(con)
|
||||
lst1.append(con);
|
||||
}
|
||||
|
||||
QList<PowerTerminal*> lstTerminal2 = getTerminalsForEntity(entityId2,funType);
|
||||
for(auto &terminal:lstTerminal2)
|
||||
{
|
||||
PowerConnection* con = getConnectionContainsTerminal(terminal->id(),funType);
|
||||
if(con)
|
||||
lst2.append(con);
|
||||
}
|
||||
|
||||
for(auto pCon1:lst1){
|
||||
for(auto pCon2:lst2){
|
||||
if(pCon1->id() == pCon2->id()){ //两个item的连接有重合,返回该连接
|
||||
return pCon1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
QHash<QString,PowerConnection*> TopologyManager::getAllConnections(ModelFunctionType funType)
|
||||
{
|
||||
if(funType == ModelFunctionType::ProjectModel)
|
||||
|
|
|
|||
|
|
@ -150,18 +150,7 @@
|
|||
</widget>
|
||||
</item>
|
||||
<item row="0" column="2">
|
||||
<widget class="QComboBox" name="cb_category">
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>电气设备</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>连接关系</string>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
<widget class="QComboBox" name="cb_category"/>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_2">
|
||||
|
|
|
|||
Loading…
Reference in New Issue