-
Notifications
You must be signed in to change notification settings - Fork 1
/
NetlistDialog.cpp
127 lines (114 loc) · 3.29 KB
/
NetlistDialog.cpp
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/*
Copyright (C) 2010-2011 Igor Izyumin
This file is part of xpcb.
xpcb is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
xpcb is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with xpcb. If not, see <http://www.gnu.org/licenses/>.
*/
#include "NetlistDialog.h"
#include "Net.h"
#include "Document.h"
#include <QPixmap>
#include <QPair>
#include <QSettings>
#include <QTreeWidgetItem>
#include <QTableWidgetItem>
NetlistDialog::NetlistDialog(QWidget *parent, QSharedPointer<Netlist> netlist,
PCBDoc* doc) :
QDialog(parent),
mNetlist(netlist),
mDoc(doc),
mYesIcon(":/Resources/icon-yes.png"),
mNoIcon(":/Resources/icon-no.png"),
mErrIcon(":/Resources/icon-error.png"),
mWarnIcon(":/Resources/icon-warning.png")
{
setupUi(this);
populateLists();
loadGeom();
}
void NetlistDialog::populateLists()
{
foreach(const NLPart& part, mNetlist->parts())
{
QTreeWidgetItem *partItem = new QTreeWidgetItem(this->partsTree);
partItem->setFlags(Qt::ItemIsEnabled |
Qt::ItemIsSelectable);
partItem->setText(0, part.refdes());
partItem->setText(1, part.value());
partItem->setText(2, part.footprint());
switch(part.checkPart(mDoc))
{
case NLPart::OK:
partItem->setIcon(3, mYesIcon);
break;
case NLPart::Missing:
partItem->setIcon(3, mNoIcon);
break;
case NLPart::Mismatch:
partItem->setIcon(3, mWarnIcon);
break;
default:
partItem->setIcon(3, mErrIcon);
break;
}
}
foreach(const NLNet& net, mNetlist->nets())
{
addItemsForNet(net);
}
}
void NetlistDialog::addItemsForNet(const NLNet &net)
{
// add tree widget item for net
QTreeWidgetItem *netItem = new QTreeWidgetItem(this->netsTree);
netItem->setFlags(Qt::ItemIsUserCheckable |
Qt::ItemIsEnabled |
Qt::ItemIsSelectable);
netItem->setText(0, net.name());
netItem->setCheckState(1, Qt::Checked);
netItem->setIcon(2, mYesIcon);
// add pins
foreach(NLPin p, net.pins())
{
QTreeWidgetItem *pinItem = new QTreeWidgetItem(netItem);
pinItem->setFlags(Qt::ItemIsEnabled |
Qt::ItemIsSelectable);
pinItem->setText(0, p.refdes() + "." + p.pinName());
pinItem->setIcon(2, mYesIcon);
}
}
void NetlistDialog::closeEvent(QCloseEvent *e)
{
saveGeom();
QDialog::closeEvent(e);
}
void NetlistDialog::hideEvent(QHideEvent *e)
{
saveGeom();
QDialog::hideEvent(e);
}
void NetlistDialog::saveGeom()
{
QSettings s;
s.setValue("netlistdlg/geometry", QVariant(saveGeometry()));
s.setValue("netlistdlg/netsHeaderState", QVariant(netsTree->
header()->saveState()));
s.setValue("netlistdlg/partsHeaderState", QVariant(partsTree->
header()->saveState()));
}
void NetlistDialog::loadGeom()
{
QSettings s;
restoreGeometry(s.value("netlistdlg/geometry").toByteArray());
netsTree->header()->restoreState(s.value("netlistdlg/netsHeaderState").toByteArray());
partsTree->header()->restoreState(
s.value("netlistdlg/partsHeaderState").toByteArray());
}