add editor endpoint special process
This commit is contained in:
parent
1da45b24e6
commit
df8de12160
|
|
@ -69,11 +69,12 @@ private:
|
|||
const LayoutConfig& config,
|
||||
Context& context,
|
||||
bool isOrder,
|
||||
int polarity);
|
||||
int polarity,double sizeFacotr = 1.0);
|
||||
// 组件相关
|
||||
Direction determineBranchDirection(const DiagramEditorComponentInfo& currentNode,
|
||||
Direction preferredDir,
|
||||
Context& context);
|
||||
Context& context,
|
||||
int forward = 1);
|
||||
QPoint getComponentPosition(const QString& componentName,
|
||||
Context& context);
|
||||
void updateComponent(DiagramEditorComponentInfo& compo,
|
||||
|
|
@ -102,6 +103,9 @@ private:
|
|||
Direction getRouteDirection(const QString& routeName,const QMap<QString, DiagramEditorRouteInfo>& routes);
|
||||
int getComponentTotalOccupiedDirections(const QString& compoName, Context& context); //从总占用表中获取元件占用方向
|
||||
int getComponentDirectionFromCache(const QString& compoName,const QString& routeId,Context& context); //从缓存获取方向占用
|
||||
QMap<int, QList<QString>> getCommonDirectionNode(QMap<QString, DiagramEditorRouteInfo>& routes,Context& context); //获取占位相同的异线node(父节点相邻且非主线末节点)
|
||||
void updateConfilicNode(QMap<QString, DiagramEditorRouteInfo>& routes,Context& context,const LayoutConfig& config,QMap<int, QList<QString>>); //处理冲突的node
|
||||
void relayoutTargetRoute(const QString& obj,QMap<QString, DiagramEditorRouteInfo>& routes,Context& context,const LayoutConfig& config); //重新布局目标元件所在线路
|
||||
QString getDirectionName(int dirBit) {
|
||||
switch (dirBit) {
|
||||
case 8: return "上";
|
||||
|
|
|
|||
|
|
@ -179,39 +179,11 @@ protected:
|
|||
class GraphicsBaseItem :public QObject, public AbstractShapeType<QGraphicsItem>
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
enum RotateAngle {
|
||||
Angle_0 = 0,
|
||||
Angle_90 = 90,
|
||||
Angle_180 = 180,
|
||||
Angle_270 = 270
|
||||
};
|
||||
Q_ENUM(RotateAngle);
|
||||
|
||||
Q_PROPERTY(QString Name READ getName WRITE setName)
|
||||
Q_PROPERTY(QPointF Position READ getPosition WRITE setPosition NOTIFY posChanged)
|
||||
Q_PROPERTY(QRectF Size READ getSize WRITE setSize)
|
||||
Q_PROPERTY(RotateAngle Rotation READ getRotateAngle WRITE setRotateAngle)
|
||||
Q_PROPERTY(QFileInfo Image READ getImage_1 WRITE setImage_1)
|
||||
public:
|
||||
GraphicsBaseItem(QGraphicsItem *parent);
|
||||
GraphicsBaseItem(const GraphicsBaseItem&);
|
||||
virtual ~GraphicsBaseItem();
|
||||
virtual GraphicsBaseItem* clone() const = 0;
|
||||
signals:
|
||||
void itemRotated(GraphicsBaseItem*);
|
||||
void posChanged();
|
||||
public:
|
||||
virtual QString getName() const;
|
||||
virtual void setName(QString);
|
||||
virtual QPointF getPosition() const;
|
||||
virtual void setPosition(QPointF);
|
||||
virtual QRectF getSize() const;
|
||||
virtual void setSize(QRectF);
|
||||
virtual RotateAngle getRotateAngle() const;
|
||||
virtual void setRotateAngle(RotateAngle);
|
||||
virtual QFileInfo getImage_1() const;
|
||||
virtual void setImage_1(QFileInfo);
|
||||
public:
|
||||
int addPort(PortState typ,QPointF vec,QString id = "",HandleType hType = T_lineInOut,PortPos pos = P_top,double dXPercent = 0,double dYPercent = 0); //新建,返回-1失败
|
||||
virtual void movePort(QString id,QPointF vec); //移动可动点
|
||||
|
|
@ -587,8 +559,34 @@ class GraphicsProjectModelItem : public GraphicsBaseItem //工程模item
|
|||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
Q_PROPERTY(DataSourceType DataSourceType READ getDataSourceType WRITE setDataSourceType)
|
||||
enum RotateAngle {
|
||||
Angle_0 = 0,
|
||||
Angle_90 = 90,
|
||||
Angle_180 = 180,
|
||||
Angle_270 = 270
|
||||
};
|
||||
Q_ENUM(RotateAngle);
|
||||
|
||||
Q_PROPERTY(QString Name READ getName WRITE setName)
|
||||
Q_PROPERTY(QPointF Position READ getPosition WRITE setPosition NOTIFY posChanged)
|
||||
Q_PROPERTY(QRectF Size READ getSize WRITE setSize)
|
||||
Q_PROPERTY(RotateAngle Rotation READ getRotateAngle WRITE setRotateAngle)
|
||||
Q_PROPERTY(QFileInfo Image READ getImage_1 WRITE setImage_1)
|
||||
Q_PROPERTY(DataSourceType DataSourceType READ getDataSourceType WRITE setDataSourceType)
|
||||
signals:
|
||||
void itemRotated(GraphicsBaseItem*);
|
||||
void posChanged();
|
||||
public:
|
||||
virtual QString getName() const;
|
||||
virtual void setName(QString);
|
||||
virtual QPointF getPosition() const;
|
||||
virtual void setPosition(QPointF);
|
||||
virtual QRectF getSize() const;
|
||||
virtual void setSize(QRectF);
|
||||
virtual RotateAngle getRotateAngle() const;
|
||||
virtual void setRotateAngle(RotateAngle);
|
||||
virtual QFileInfo getImage_1() const;
|
||||
virtual void setImage_1(QFileInfo);
|
||||
public:
|
||||
GraphicsProjectModelItem(QGraphicsItem *parent);
|
||||
GraphicsProjectModelItem(const GraphicsProjectModelItem&);
|
||||
|
|
|
|||
|
|
@ -83,15 +83,28 @@ void ElectricBaseModelLineItem::setEndPoint(const QPointF& p)
|
|||
|
||||
QPainterPath ElectricBaseModelLineItem::shape() const
|
||||
{
|
||||
QPainterPath path;
|
||||
//path.addPath(m_points);
|
||||
path.addPath(m_pointsBoundingRect);
|
||||
return path;
|
||||
// 使用路径的轮廓
|
||||
if (m_points.isEmpty()) {
|
||||
return QPainterPath();
|
||||
}
|
||||
|
||||
QPainterPathStroker stroker;
|
||||
stroker.setWidth(8.0); // 选择区域宽度
|
||||
|
||||
QPainterPath shape = stroker.createStroke(m_points);
|
||||
return shape;
|
||||
}
|
||||
|
||||
QRectF ElectricBaseModelLineItem::boundingRect() const
|
||||
{
|
||||
return m_boundingRect;
|
||||
QRectF rect = shape().boundingRect();
|
||||
|
||||
// 如果shape为空,使用路径边界
|
||||
if (rect.isNull() && !m_points.isEmpty()) {
|
||||
rect = m_points.boundingRect().adjusted(-5, -5, 5, 5);
|
||||
}
|
||||
|
||||
return rect;
|
||||
}
|
||||
|
||||
void ElectricBaseModelLineItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
|
||||
|
|
@ -102,7 +115,10 @@ void ElectricBaseModelLineItem::paint(QPainter* painter, const QStyleOptionGraph
|
|||
}
|
||||
else
|
||||
{
|
||||
painter->setPen(m_pen);
|
||||
if(_stateMask)
|
||||
painter->setPen(Qt::red);
|
||||
else
|
||||
painter->setPen(m_pen);
|
||||
GraphicsBaseModelItem::paint(painter,option,widget);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@
|
|||
#include "diagramEditor/diagramEditorWizard.h"
|
||||
#include "include/instance/baseTypeManager.h"
|
||||
#include "titleBar.h"
|
||||
#include "graphicsDataModel/diagramEditorModel.h"
|
||||
#include <QSizeGrip>
|
||||
|
||||
DiagramEditorBayDetailAddDlg::DiagramEditorBayDetailAddDlg(QWidget *parent)
|
||||
|
|
@ -263,8 +264,21 @@ void DiagramEditorBayDetailAddDlg::showDlg()
|
|||
show();
|
||||
auto pCompo = _pParent->getComponentModel();
|
||||
auto pRoute = _pParent->getRouteModel();
|
||||
int n = pRoute->rowCount();
|
||||
ui->le_routeName->setText("线路"+QString::number(n+1));
|
||||
//int n = pRoute->rowCount();
|
||||
//ui->le_routeName->setText("线路"+QString::number(n+1));
|
||||
|
||||
int maxNo = 0;
|
||||
for (int i = 0; i < pRoute->rowCount(); ++i)
|
||||
{
|
||||
QString name = pRoute->item(i, 0)->text(); // 假设线路名在第一列
|
||||
if (name.startsWith("线路"))
|
||||
{
|
||||
int no = name.mid(2).toInt(); // 取“线路X”里的数字
|
||||
maxNo = qMax(maxNo, no);
|
||||
}
|
||||
}
|
||||
ui->le_routeName->setText("线路" + QString::number(maxNo + 1));
|
||||
|
||||
ui->tableView_items->setModel(pCompo);
|
||||
//ui->label->setText("新建线路");
|
||||
m_titleBar->setTitle("新增线路");
|
||||
|
|
@ -629,6 +643,7 @@ void DiagramEditorBayDetailAddDlg::onOkClicked()
|
|||
}
|
||||
}
|
||||
if(_pParent){
|
||||
_pParent->getModel()->clearCurPreview();
|
||||
_pParent->showPreview();
|
||||
}
|
||||
hide();
|
||||
|
|
|
|||
|
|
@ -202,6 +202,43 @@ void DiagramEditorBayDetailSettingDlg::onOkClicked()
|
|||
bool changePos = false;
|
||||
if(_curOperateObj){
|
||||
|
||||
// ✅ 2. 设置布局参数
|
||||
int nLayout = ui->cb_layout->currentData().toInt();
|
||||
_curBayInfo.nLayout = nLayout;
|
||||
|
||||
int nLocate = ui->cb_locate->currentData().toInt();
|
||||
if(_curBayInfo.nLocate != nLocate){
|
||||
//位置发生变动
|
||||
_curOperateObj->getCurContainer()->changeBlockLocate(_curOperateObj,_curBayInfo.nLocate,nLocate);
|
||||
_curBayInfo.nLocate = nLocate;
|
||||
_curOperateObj->setBayLocate(nLocate);
|
||||
//emit _pWizard->wizardFinish();
|
||||
changePos = true;
|
||||
}
|
||||
|
||||
// ✅ 3. 执行布局(唯一正确时机)
|
||||
int nDir = (nLayout == 0) ? 41 : 14;
|
||||
getModel()->clearCompoDir(
|
||||
_curBayInfo.mapRoute,
|
||||
_curBayInfo.mapComponent,
|
||||
_curBayInfo.directionOccupancyMap,
|
||||
_curBayInfo.routeDirectionMap,
|
||||
0);
|
||||
|
||||
QRectF recBounding =
|
||||
getModel()->updateTarget(
|
||||
_curBayInfo.mapRoute,
|
||||
_curBayInfo.mapComponent,
|
||||
_curBayInfo.directionOccupancyMap,
|
||||
_curBayInfo.routeDirectionMap,
|
||||
nDir,
|
||||
0,
|
||||
false); // ✅ 结果写回 mapComponent
|
||||
|
||||
// ✅ 4. 保存“已经算好的正确数据”
|
||||
if (_curOperateObj->getRecSize().isEmpty())
|
||||
_curOperateObj->setRecSize(recBounding);
|
||||
|
||||
QMap<QString, DiagramEditorComponentInfo> tempComponents;
|
||||
int nRowCount = _compoModel->rowCount();
|
||||
for (int i = 0; i < nRowCount; ++i) {
|
||||
|
|
@ -242,44 +279,7 @@ void DiagramEditorBayDetailSettingDlg::onOkClicked()
|
|||
info.nRotate = nRotate;
|
||||
tempComponents.insert(info.sName, info);
|
||||
}
|
||||
|
||||
// ✅ 2. 设置布局参数
|
||||
int nLayout = ui->cb_layout->currentData().toInt();
|
||||
_curBayInfo.nLayout = nLayout;
|
||||
_curBayInfo.mapComponent = tempComponents; // ✅ 仅存非布局数据
|
||||
|
||||
int nLocate = ui->cb_locate->currentData().toInt();
|
||||
if(_curBayInfo.nLocate != nLocate){
|
||||
//位置发生变动
|
||||
_curOperateObj->getCurContainer()->changeBlockLocate(_curOperateObj,_curBayInfo.nLocate,nLocate);
|
||||
_curBayInfo.nLocate = nLocate;
|
||||
_curOperateObj->setBayLocate(nLocate);
|
||||
//emit _pWizard->wizardFinish();
|
||||
changePos = true;
|
||||
}
|
||||
|
||||
// ✅ 3. 执行布局(唯一正确时机)
|
||||
int nDir = (nLayout == 0) ? 41 : 14;
|
||||
getModel()->clearCompoDir(
|
||||
_curBayInfo.mapRoute,
|
||||
_curBayInfo.mapComponent,
|
||||
_curBayInfo.directionOccupancyMap,
|
||||
_curBayInfo.routeDirectionMap,
|
||||
0);
|
||||
|
||||
QRectF recBounding =
|
||||
getModel()->updateTarget(
|
||||
_curBayInfo.mapRoute,
|
||||
_curBayInfo.mapComponent,
|
||||
_curBayInfo.directionOccupancyMap,
|
||||
_curBayInfo.routeDirectionMap,
|
||||
nDir,
|
||||
0,
|
||||
false); // ✅ 结果写回 mapComponent
|
||||
|
||||
// ✅ 4. 保存“已经算好的正确数据”
|
||||
if (_curOperateObj->getRecSize().isEmpty())
|
||||
_curOperateObj->setRecSize(recBounding);
|
||||
_curBayInfo.mapComponent = tempComponents;
|
||||
|
||||
_curOperateObj->setBayInfo(_curBayInfo); // ✅ 此时 mapComponent 是正确的
|
||||
|
||||
|
|
|
|||
|
|
@ -45,6 +45,11 @@ QRectF DiagramLayoutEngine::executeLayout(
|
|||
layoutBranchRoute(*it, config, context);
|
||||
}
|
||||
|
||||
auto mapSameDirNode = getCommonDirectionNode(routes,context); //获取相同占位的点(特殊处理)
|
||||
if(!mapSameDirNode.isEmpty()){
|
||||
updateConfilicNode(routes,context,config,mapSameDirNode);
|
||||
}
|
||||
|
||||
// ✅ 3. 所有布局完成之后,才更新 components
|
||||
if (!context.saveToModel) {
|
||||
for(auto& compo:components){ //从compo缓存中读取计算过的数据
|
||||
|
|
@ -309,7 +314,7 @@ void DiagramLayoutEngine::layoutBranchRoute(
|
|||
|
||||
// 4. 布局反序序列
|
||||
if (route.lstReverse.size() > 1) {
|
||||
layoutBranchSequence(route.lstReverse, route.preferDirection,
|
||||
layoutBranchSequence(route.lstReverse, DirectionManager::getOpposite(route.preferDirection),
|
||||
config, context, false, -1);
|
||||
}
|
||||
|
||||
|
|
@ -356,7 +361,8 @@ void DiagramLayoutEngine::layoutBranchSequence(
|
|||
const LayoutConfig& config,
|
||||
Context& context,
|
||||
bool isOrder,
|
||||
int polarity) {
|
||||
int polarity,
|
||||
double sizeFacotr) {
|
||||
|
||||
if (sequence.size() < 2) return;
|
||||
|
||||
|
|
@ -367,14 +373,16 @@ void DiagramLayoutEngine::layoutBranchSequence(
|
|||
int spacing = isVertical
|
||||
? config.verticalSpacing()
|
||||
: config.horizontalSpacing();
|
||||
spacing *= sizeFacotr;
|
||||
|
||||
|
||||
for (int i = 0; i < sequence.size(); ++i) {
|
||||
|
||||
DiagramEditorComponentInfo& compo = sequence[i];
|
||||
// ✅ 当前元件作为“起点”
|
||||
QPoint basePos = getComponentPosition(sequence[i].sName, context);
|
||||
Direction dir =
|
||||
determineBranchDirection(sequence[i], branchDir, context);
|
||||
determineBranchDirection(sequence[i], branchDir, context, polarity);
|
||||
|
||||
// ✅ 如果后面还有元件,才计算偏移
|
||||
if (i + 1 < sequence.size()) {
|
||||
|
|
@ -392,14 +400,18 @@ void DiagramLayoutEngine::layoutBranchSequence(
|
|||
QPoint deltaPos = nextPos - basePos;
|
||||
Direction nextConnectionDir =
|
||||
DirectionManager::getOpposite(dir);
|
||||
int rotate =
|
||||
int nextRotate =
|
||||
DirectionManager::getRotationAngle(dir);
|
||||
|
||||
int curRotate = nextRotate; //当前元件旋转,默认与下个相同
|
||||
//if(i == 0 && (compo.nType == 11 || compo.nType == 12)) //单port元件队首反向(避雷器,带电指示器)
|
||||
// curRotate = DirectionManager::getRotationAngle(DirectionManager::getOpposite(dir));
|
||||
|
||||
updateComponent(sequence[i], int(dir),
|
||||
basePos, rotate, context);
|
||||
basePos, curRotate, context);
|
||||
|
||||
updateComponent(next, int(nextConnectionDir),
|
||||
nextPos, rotate, context);
|
||||
nextPos, nextRotate, context);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -408,7 +420,8 @@ void DiagramLayoutEngine::layoutBranchSequence(
|
|||
Direction DiagramLayoutEngine::determineBranchDirection(
|
||||
const DiagramEditorComponentInfo& currentNode,
|
||||
Direction preferredDir,
|
||||
Context& context) {
|
||||
Context& context,
|
||||
int forward) {
|
||||
|
||||
int usedDirections = getComponentDirection(currentNode.sName, context);
|
||||
bool horizontal = DirectionManager::isHorizontal(preferredDir);
|
||||
|
|
@ -515,11 +528,9 @@ void DiagramLayoutEngine::updateComponent(
|
|||
if (context.saveToModel) {
|
||||
QStandardItem* item = getNameItem(compo.sName, context);
|
||||
if (item) {
|
||||
//int currentDir = item->data().toInt();
|
||||
//int newDir = DirectionManager::markDirectionOccupied(currentDir, dir);
|
||||
//item->setData(QString::number(newDir));
|
||||
//int nUsedDir = item->data().toInt();
|
||||
//item->setData(dir | nUsedDir);
|
||||
auto it = context.componentsCache.find(compo.sName);
|
||||
if(it != context.componentsCache.end())
|
||||
item->setData(it->nUsedDirection, Qt::UserRole + 1); //同步占用到standardModel
|
||||
item->setData(position, Qt::UserRole + 2);
|
||||
item->setData(rotate, Qt::UserRole + 5);
|
||||
}
|
||||
|
|
@ -858,6 +869,171 @@ int DiagramLayoutEngine::getComponentDirectionFromCache(const QString& compoName
|
|||
return 0;
|
||||
}
|
||||
|
||||
QMap<int, QList<QString>> DiagramLayoutEngine::getCommonDirectionNode(QMap<QString, DiagramEditorRouteInfo>& routes,Context& context)
|
||||
{
|
||||
QMap<int, QList<QString>> directionToNames;
|
||||
QList<QString> lstMain; //主线设备
|
||||
for(auto& route:routes){
|
||||
if(!route.bMainRoute)
|
||||
continue;
|
||||
for(auto& compo:route.lstCompo){
|
||||
lstMain.append(compo.sName);
|
||||
}
|
||||
}
|
||||
|
||||
for (auto it = context.componentsCache.constBegin(); //寻找相同方位占用的node
|
||||
it != context.componentsCache.constEnd();
|
||||
++it)
|
||||
{
|
||||
const DiagramEditorComponentInfo& info = it.value();
|
||||
|
||||
//if (info.nCategory != 1) //新建时catch中分类无信息
|
||||
// continue;
|
||||
|
||||
directionToNames[info.nUsedDirection].append(it.key());
|
||||
}
|
||||
|
||||
|
||||
//从 directionToNames 中移除出现在 lstMain 的node
|
||||
for (auto it = directionToNames.begin(); it != directionToNames.end(); )
|
||||
{
|
||||
QList<QString>& nameList = it.value();
|
||||
|
||||
// 移除在 lstMain 中出现的node
|
||||
nameList.erase(
|
||||
std::remove_if(nameList.begin(), nameList.end(),
|
||||
[&](const QString& name) {
|
||||
return lstMain.contains(name);
|
||||
}),
|
||||
nameList.end()
|
||||
);
|
||||
|
||||
// 如果该方向已无设备,删除该方向
|
||||
if (nameList.isEmpty())
|
||||
it = directionToNames.erase(it);
|
||||
else
|
||||
++it;
|
||||
}
|
||||
|
||||
QSet<int> invalidDirections = {
|
||||
8, 4, 2, 1, // 单方向
|
||||
12, 3 // 直线组合
|
||||
};
|
||||
// 只保留拐角node
|
||||
for (auto it = directionToNames.begin(); it != directionToNames.end(); )
|
||||
{
|
||||
int dir = it.key();
|
||||
|
||||
if(it.value().size() == 1){ //删除孤立数据
|
||||
it = directionToNames.erase(it);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (invalidDirections.contains(dir) || it.value().isEmpty())
|
||||
it = directionToNames.erase(it);
|
||||
else
|
||||
++it;
|
||||
}
|
||||
|
||||
return directionToNames;
|
||||
}
|
||||
|
||||
void DiagramLayoutEngine::updateConfilicNode(QMap<QString, DiagramEditorRouteInfo>& routes,Context& context,const LayoutConfig& config,QMap<int, QList<QString>> directionToNames)
|
||||
{
|
||||
QMap<int, QList<QPair<QString, QString>>> directionConflicts;
|
||||
QList<QString> lstMain; //主线设备
|
||||
QMap<QString,QList<QString>> mapSub; //支线设备
|
||||
for(auto& route:routes){
|
||||
if(!route.bMainRoute)
|
||||
{
|
||||
QList<QString> lstSub;
|
||||
|
||||
for(auto& compo:route.lstCompo){
|
||||
lstSub.append(compo.sName);
|
||||
}
|
||||
mapSub.insert(route.sRouteName,lstSub);
|
||||
continue;
|
||||
}
|
||||
for(auto& compo:route.lstCompo){
|
||||
lstMain.append(compo.sName);
|
||||
}
|
||||
}
|
||||
|
||||
// 遍历 directionToNames 的每个方向分支
|
||||
for (auto dirIt = directionToNames.constBegin();
|
||||
dirIt != directionToNames.constEnd();
|
||||
++dirIt)
|
||||
{
|
||||
int direction = dirIt.key();
|
||||
const QList<QString>& devList = dirIt.value();
|
||||
|
||||
QList<QPair<QString, QString>> conflicts;
|
||||
|
||||
// 遍历当前方向分支中的每个设备
|
||||
for (const QString& dev : devList)
|
||||
{
|
||||
// 遍历所有 sub 线路
|
||||
for (const QList<QString>& subDevs : mapSub)
|
||||
{
|
||||
if (!subDevs.contains(dev))
|
||||
continue;
|
||||
|
||||
// 查找 lstMain 中同时存在于该 sub 的设备
|
||||
for (const QString& mainDev : lstMain)
|
||||
{
|
||||
if (subDevs.contains(mainDev))
|
||||
{
|
||||
conflicts.append(qMakePair(dev, mainDev));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!conflicts.isEmpty() &&
|
||||
conflicts.last().first == dev)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!conflicts.isEmpty())
|
||||
directionConflicts[direction] = conflicts;
|
||||
}
|
||||
|
||||
if(!directionConflicts.isEmpty()){
|
||||
for(auto& lstPair:directionConflicts){
|
||||
if(lstPair.size() > 1){ //默认处理倒数第2个
|
||||
QString sObj = lstPair[lstPair.size()-2].first;
|
||||
relayoutTargetRoute(sObj,routes,context,config);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DiagramLayoutEngine::relayoutTargetRoute(const QString& obj,QMap<QString, DiagramEditorRouteInfo>& routes,Context& context,const LayoutConfig& config)
|
||||
{
|
||||
for(auto& route:routes){ //对包含本node的线路重绘制
|
||||
bool containObj = false;
|
||||
for(auto& compo:route.lstCompo){
|
||||
if(obj == compo.sName){
|
||||
containObj = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(containObj){
|
||||
clearRouteDirectionOccupancy(route.sRouteName,context); //重构时先移除占用
|
||||
if (route.lstOrder.size() > 1) {
|
||||
layoutBranchSequence(route.lstOrder, route.preferDirection,
|
||||
config, context, true, 1, 2.0);
|
||||
}
|
||||
if (route.lstReverse.size() > 1) {
|
||||
layoutBranchSequence(route.lstReverse, DirectionManager::getOpposite(route.preferDirection),
|
||||
config, context, false, -1, 2.0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool DiagramLayoutEngine::clearRouteDirectionOccupancy(const QString& routeId,Context& context) {
|
||||
|
||||
// 1. 查找要清理的线路
|
||||
|
|
|
|||
|
|
@ -1016,6 +1016,13 @@ void DiagramEditorModel::generateItemByModel(QStandardItemModel* pModel,DiagramE
|
|||
if(isOrigin)
|
||||
originPos = pItem->scenePos();
|
||||
}
|
||||
else
|
||||
{
|
||||
auto pI = _tempItem.value(uid);
|
||||
pI->setPos(pos);
|
||||
if(isOrigin)
|
||||
originPos = pI->scenePos();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -148,7 +148,7 @@ bool FixedPortsModel::addNodeItem(QUuid uuid,GraphicsProjectModelItem* pItem)
|
|||
pItem->setHandle(this);
|
||||
_nodeItem.insert(uuid,pItem);
|
||||
connect(pItem,&GraphicsProjectModelItem::ifExist,this,&FixedPortsModel::onSignal_ifExits);
|
||||
connect(pItem,&GraphicsBaseItem::itemRotated,this,[this](GraphicsBaseItem* pBase){
|
||||
connect(pItem,&GraphicsProjectModelItem::itemRotated,this,[this](GraphicsBaseItem* pBase){
|
||||
if(pBase){
|
||||
auto pPro = pBase->getProperty();
|
||||
QUuid uid = pPro->uuid();
|
||||
|
|
@ -688,7 +688,7 @@ QString FixedPortsModel::addNodeItem(QUuid id,QPointF pos,double width,double he
|
|||
item->setHandle(this);
|
||||
_nodeItem.insert(id,item);
|
||||
connect(item,&GraphicsProjectModelItem::ifExist,this,&FixedPortsModel::onSignal_ifExits);
|
||||
connect(item,&GraphicsBaseItem::itemRotated,this,[this](GraphicsBaseItem* pBase){
|
||||
connect(item,&GraphicsProjectModelItem::itemRotated,this,[this](GraphicsBaseItem* pBase){
|
||||
if(pBase){
|
||||
auto pPro = pBase->getProperty();
|
||||
QUuid uid = pPro->uuid();
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@ void ElectricSvgGroupCT::setImage_1(QFileInfo info)
|
|||
|
||||
if(_pHandle && !sMeta.isEmpty() && !sModel.isEmpty())
|
||||
_pHandle->updateItemIcon(sMeta,sModel,mapData,"ct");
|
||||
GraphicsBaseItem::setImage_1(info);
|
||||
GraphicsProjectModelItem::setImage_1(info);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ void ElectricSvgGroupPT::setImage_1(QFileInfo info)
|
|||
|
||||
if(_pHandle && !sMeta.isEmpty() && !sModel.isEmpty())
|
||||
_pHandle->updateItemIcon(sMeta,sModel,mapData,"pt");
|
||||
GraphicsBaseItem::setImage_1(info);
|
||||
GraphicsProjectModelItem::setImage_1(info);
|
||||
}
|
||||
|
||||
void ElectricSvgGroupPT::setupFinish(QVariant var)
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@ void ElectricSvgItem2wTransformer::setImage_1(QFileInfo info)
|
|||
if(_pHandle && !sMeta.isEmpty() && !sModel.isEmpty())
|
||||
_pHandle->updateItemIcon(sMeta,sModel,mapData,"transformer_2w");
|
||||
|
||||
GraphicsBaseItem::setImage_1(info);
|
||||
GraphicsProjectModelItem::setImage_1(info);
|
||||
}
|
||||
|
||||
void ElectricSvgItem2wTransformer::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@ void ElectricSvgItem3wTransformer::setImage_1(QFileInfo info)
|
|||
if(_pHandle && !sMeta.isEmpty() && !sModel.isEmpty())
|
||||
_pHandle->updateItemIcon(sMeta,sModel,mapData,"transformer_3w");
|
||||
|
||||
GraphicsBaseItem::setImage_1(info);
|
||||
GraphicsProjectModelItem::setImage_1(info);
|
||||
}
|
||||
|
||||
void ElectricSvgItem3wTransformer::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@ void ElectricSvgItemBus::setImage_1(QFileInfo info)
|
|||
if(_pHandle && !sMeta.isEmpty() && !sModel.isEmpty())
|
||||
_pHandle->updateItemIcon(sMeta,sModel,mapData,"bus");
|
||||
|
||||
GraphicsBaseItem::setImage_1(info);
|
||||
GraphicsProjectModelItem::setImage_1(info);
|
||||
}
|
||||
|
||||
void ElectricSvgItemBus::updateHandles()
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@ void ElectricSvgItemCableEnd::setImage_1(QFileInfo info)
|
|||
if(_pHandle && !sMeta.isEmpty() && !sModel.isEmpty())
|
||||
_pHandle->updateItemIcon(sMeta,sModel,mapData,"cable_end");
|
||||
|
||||
GraphicsBaseItem::setImage_1(info);
|
||||
GraphicsProjectModelItem::setImage_1(info);
|
||||
}
|
||||
|
||||
void ElectricSvgItemCableEnd::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@ void ElectricSvgItemCableTer::setImage_1(QFileInfo info)
|
|||
if(_pHandle && !sMeta.isEmpty() && !sModel.isEmpty())
|
||||
_pHandle->updateItemIcon(sMeta,sModel,mapData,"cable_termination");
|
||||
|
||||
GraphicsBaseItem::setImage_1(info);
|
||||
GraphicsProjectModelItem::setImage_1(info);
|
||||
}
|
||||
|
||||
void ElectricSvgItemCableTer::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@ void ElectricSvgItemDS::setImage_1(QFileInfo info)
|
|||
if(_pHandle && !sMeta.isEmpty() && !sModel.isEmpty())
|
||||
_pHandle->updateItemIcon(sMeta,sModel,mapData,"ds");
|
||||
|
||||
GraphicsBaseItem::setImage_1(info);
|
||||
GraphicsProjectModelItem::setImage_1(info);
|
||||
}
|
||||
|
||||
void ElectricSvgItemDS::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@ void ElectricSvgItemDTEDS::setImage_1(QFileInfo info)
|
|||
if(_pHandle && !sMeta.isEmpty() && !sModel.isEmpty())
|
||||
_pHandle->updateItemIcon(sMeta,sModel,mapData,"dteds");
|
||||
|
||||
GraphicsBaseItem::setImage_1(info);
|
||||
GraphicsProjectModelItem::setImage_1(info);
|
||||
}
|
||||
|
||||
void ElectricSvgItemDTEDS::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@ void ElectricSvgItemES::setImage_1(QFileInfo info)
|
|||
if(_pHandle && !sMeta.isEmpty() && !sModel.isEmpty())
|
||||
_pHandle->updateItemIcon(sMeta,sModel,mapData,"es");
|
||||
|
||||
GraphicsBaseItem::setImage_1(info);
|
||||
GraphicsProjectModelItem::setImage_1(info);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@ void ElectricSvgItemFES::setImage_1(QFileInfo info)
|
|||
if(_pHandle && !sMeta.isEmpty() && !sModel.isEmpty())
|
||||
_pHandle->updateItemIcon(sMeta,sModel,mapData,"fes");
|
||||
|
||||
GraphicsBaseItem::setImage_1(info);
|
||||
GraphicsProjectModelItem::setImage_1(info);
|
||||
}
|
||||
|
||||
void ElectricSvgItemFES::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@ void ElectricSvgItemLA::setImage_1(QFileInfo info)
|
|||
if(_pHandle && !sMeta.isEmpty() && !sModel.isEmpty())
|
||||
_pHandle->updateItemIcon(sMeta,sModel,mapData,"lightning_arrester");
|
||||
|
||||
GraphicsBaseItem::setImage_1(info);
|
||||
GraphicsProjectModelItem::setImage_1(info);
|
||||
}
|
||||
|
||||
void ElectricSvgItemLA::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@ void ElectricSvgItemPI::setImage_1(QFileInfo info)
|
|||
if(_pHandle && !sMeta.isEmpty() && !sModel.isEmpty())
|
||||
_pHandle->updateItemIcon(sMeta,sModel,mapData,"potential_indicator");
|
||||
|
||||
GraphicsBaseItem::setImage_1(info);
|
||||
GraphicsProjectModelItem::setImage_1(info);
|
||||
}
|
||||
|
||||
void ElectricSvgItemPI::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@ void ElectricSvgItemRect::setImage_1(QFileInfo info)
|
|||
if(_pHandle && !sMeta.isEmpty() && !sModel.isEmpty())
|
||||
_pHandle->updateItemIcon(sMeta,sModel,mapData,"cb");
|
||||
|
||||
GraphicsBaseItem::setImage_1(info);
|
||||
GraphicsProjectModelItem::setImage_1(info);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -72,79 +72,6 @@ GraphicsBaseItem::~GraphicsBaseItem()
|
|||
}
|
||||
}
|
||||
|
||||
QString GraphicsBaseItem::getName() const
|
||||
{
|
||||
if(_property)
|
||||
return _property->name();
|
||||
return QString();
|
||||
}
|
||||
|
||||
void GraphicsBaseItem::setName(QString str)
|
||||
{
|
||||
if(_property)
|
||||
_property->setName(str);
|
||||
}
|
||||
|
||||
QPointF GraphicsBaseItem::getPosition() const
|
||||
{
|
||||
return pos();
|
||||
}
|
||||
|
||||
void GraphicsBaseItem::setPosition(QPointF pos)
|
||||
{
|
||||
setPos(pos);
|
||||
}
|
||||
|
||||
QRectF GraphicsBaseItem::getSize() const
|
||||
{
|
||||
return m_boundingRect;
|
||||
}
|
||||
|
||||
void GraphicsBaseItem::setSize(QRectF rec)
|
||||
{
|
||||
prepareGeometryChange();
|
||||
m_boundingRect = rec;
|
||||
update();
|
||||
}
|
||||
|
||||
GraphicsBaseItem::RotateAngle GraphicsBaseItem::getRotateAngle() const
|
||||
{
|
||||
int nRotate = rotation();
|
||||
|
||||
// 标准化角度到 0-360 范围
|
||||
nRotate = nRotate % 360;
|
||||
if (nRotate < 0) nRotate += 360;
|
||||
|
||||
// 映射到最近的 90 度倍数
|
||||
int normalized = ((nRotate + 45) / 90) * 90 % 360;
|
||||
|
||||
QMetaEnum metaEnum = QMetaEnum::fromType<RotateAngle>();
|
||||
|
||||
// 检查标准化后的角度是否是有效的枚举值
|
||||
if (metaEnum.valueToKey(normalized) != nullptr) {
|
||||
return static_cast<RotateAngle>(normalized);
|
||||
}
|
||||
|
||||
return RotateAngle::Angle_0;
|
||||
}
|
||||
|
||||
void GraphicsBaseItem::setRotateAngle(RotateAngle angle)
|
||||
{
|
||||
int nAngle = static_cast<int>(angle);
|
||||
setRotation(nAngle);
|
||||
emit itemRotated(this);
|
||||
}
|
||||
|
||||
QFileInfo GraphicsBaseItem::getImage_1() const
|
||||
{
|
||||
return QFileInfo(m_bgImagePath);
|
||||
}
|
||||
|
||||
void GraphicsBaseItem::setImage_1(QFileInfo info)
|
||||
{
|
||||
m_bgImagePath = info.absoluteFilePath();
|
||||
}
|
||||
|
||||
int GraphicsBaseItem::addPort(PortState typ,QPointF vec,QString id,HandleType hType,PortPos pos,double dXPercent,double dYPercent)
|
||||
{
|
||||
int ntagId = -1;
|
||||
|
|
@ -475,9 +402,11 @@ void GraphicsBaseModelItem::paint(QPainter* painter, const QStyleOptionGraphicsI
|
|||
if(_stateMask){
|
||||
if(getProperty()->modelName().isEmpty())
|
||||
{
|
||||
painter->setPen(QColor(255,0,0,80));
|
||||
painter->setBrush(QColor(255,0,0,80));
|
||||
painter->drawRoundedRect(m_boundingRect,10,10);
|
||||
if(getProperty()->type() != 8){
|
||||
painter->setPen(QColor(255,0,0,80));
|
||||
painter->setBrush(QColor(255,0,0,80));
|
||||
painter->drawRoundedRect(m_boundingRect,10,10);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -648,6 +577,79 @@ GraphicsProjectModelItem* GraphicsProjectModelItem::clone() const
|
|||
return new GraphicsProjectModelItem(*this);
|
||||
}
|
||||
|
||||
QString GraphicsProjectModelItem::getName() const
|
||||
{
|
||||
if(_property)
|
||||
return _property->name();
|
||||
return QString();
|
||||
}
|
||||
|
||||
void GraphicsProjectModelItem::setName(QString str)
|
||||
{
|
||||
if(_property)
|
||||
_property->setName(str);
|
||||
}
|
||||
|
||||
QPointF GraphicsProjectModelItem::getPosition() const
|
||||
{
|
||||
return pos();
|
||||
}
|
||||
|
||||
void GraphicsProjectModelItem::setPosition(QPointF pos)
|
||||
{
|
||||
setPos(pos);
|
||||
}
|
||||
|
||||
QRectF GraphicsProjectModelItem::getSize() const
|
||||
{
|
||||
return m_boundingRect;
|
||||
}
|
||||
|
||||
void GraphicsProjectModelItem::setSize(QRectF rec)
|
||||
{
|
||||
prepareGeometryChange();
|
||||
m_boundingRect = rec;
|
||||
update();
|
||||
}
|
||||
|
||||
GraphicsProjectModelItem::RotateAngle GraphicsProjectModelItem::getRotateAngle() const
|
||||
{
|
||||
int nRotate = rotation();
|
||||
|
||||
// 标准化角度到 0-360 范围
|
||||
nRotate = nRotate % 360;
|
||||
if (nRotate < 0) nRotate += 360;
|
||||
|
||||
// 映射到最近的 90 度倍数
|
||||
int normalized = ((nRotate + 45) / 90) * 90 % 360;
|
||||
|
||||
QMetaEnum metaEnum = QMetaEnum::fromType<RotateAngle>();
|
||||
|
||||
// 检查标准化后的角度是否是有效的枚举值
|
||||
if (metaEnum.valueToKey(normalized) != nullptr) {
|
||||
return static_cast<RotateAngle>(normalized);
|
||||
}
|
||||
|
||||
return RotateAngle::Angle_0;
|
||||
}
|
||||
|
||||
void GraphicsProjectModelItem::setRotateAngle(RotateAngle angle)
|
||||
{
|
||||
int nAngle = static_cast<int>(angle);
|
||||
setRotation(nAngle);
|
||||
emit itemRotated(this);
|
||||
}
|
||||
|
||||
QFileInfo GraphicsProjectModelItem::getImage_1() const
|
||||
{
|
||||
return QFileInfo(m_bgImagePath);
|
||||
}
|
||||
|
||||
void GraphicsProjectModelItem::setImage_1(QFileInfo info)
|
||||
{
|
||||
m_bgImagePath = info.absoluteFilePath();
|
||||
}
|
||||
|
||||
void GraphicsProjectModelItem::createOperationCopy()
|
||||
{
|
||||
m_pOperationCopy = new QGraphicsPathItem(this->shape());
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@
|
|||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>800</width>
|
||||
<height>600</height>
|
||||
<height>560</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="font">
|
||||
|
|
|
|||
|
|
@ -80,6 +80,10 @@ QList<EditorBaseSettingInfo> ProjectManager::getBaseSettingsByProject(const QStr
|
|||
if(info.projectName == strPro)
|
||||
lst.append(info);
|
||||
}
|
||||
std::sort(lst.begin(), lst.end(),
|
||||
[](const EditorBaseSettingInfo& a, const EditorBaseSettingInfo& b) {
|
||||
return a.ts < b.ts;
|
||||
});
|
||||
return lst;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue