forked from rpelorosso/pcb-tracer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConnectionAnalyzer.cpp
More file actions
76 lines (59 loc) · 2.2 KB
/
Copy pathConnectionAnalyzer.cpp
File metadata and controls
76 lines (59 loc) · 2.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include <QGraphicsScene>
#include <QDebug>
#include <QDialog>
#include <QTextEdit>
#include <QVBoxLayout>
#include <QPushButton>
#include "ConnectionAnalyzer.h"
#include "Editor.h"
void ConnectionAnalyzer::showResultDialog(const QString& result)
{
QDialog dialog(Editor::instance());
dialog.setWindowTitle("Connection Analysis Results");
dialog.setMinimumSize(400, 300);
QVBoxLayout* layout = new QVBoxLayout(&dialog);
QTextEdit* textEdit = new QTextEdit(&dialog);
textEdit->setReadOnly(true);
layout->addWidget(textEdit);
QPushButton* closeButton = new QPushButton("Close", &dialog);
layout->addWidget(closeButton);
QObject::connect(closeButton, &QPushButton::clicked, &dialog, &QDialog::accept);
textEdit->setText(result);
dialog.exec();
}
void ConnectionAnalyzer::getConnections()
{
// Map to store each graph_id and its associated Pad nodes
QMap<int, QList<Pad*>> graphIdToPads;
auto scene = Editor::instance()->getScene();
for (QGraphicsItem* item : scene->items()) {
Link* link = dynamic_cast<Link*>(item);
if (link) {
int graphId = link->m_graphId;
// Get nodes from each link's fromNode() and toNode()
Node* fromNode = link->fromNode();
Node* toNode = link->toNode();
// Check if the nodes are of class Pad, and add them to the list for the graph_id
Pad* fromPad = dynamic_cast<Pad*>(fromNode);
if (fromPad && !graphIdToPads[graphId].contains(fromPad)) {
graphIdToPads[graphId].append(fromPad);
}
Pad* toPad = dynamic_cast<Pad*>(toNode);
if (toPad && !graphIdToPads[graphId].contains(toPad)) {
graphIdToPads[graphId].append(toPad);
}
}
}
QString resultText;
for (auto it = graphIdToPads.constBegin(); it != graphIdToPads.constEnd(); ++it) {
int graphId = it.key();
const QList<Pad*>& pads = it.value();
QStringList padNames;
for (const Pad* pad : pads) {
padNames << pad->m_name;
}
QString result = padNames.join(" | ");
resultText += result + "\n";
}
showResultDialog(resultText);
}