-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPartPlacer.cpp
More file actions
118 lines (103 loc) · 2.88 KB
/
PartPlacer.cpp
File metadata and controls
118 lines (103 loc) · 2.88 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
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
/*
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 <QSettings>
#include "PartPlacer.h"
#include "Controller.h"
#include "Document.h"
PartPlacer::PartPlacer(QWidget *parent, Controller* ctrl) :
QDockWidget(parent),
mCtrl(ctrl),
mYesIcon(":/Resources/icon-yes.png"),
mNoIcon(":/Resources/icon-no.png"),
mErrIcon(":/Resources/icon-error.png"),
mWarnIcon(":/Resources/icon-warning.png")
{
setupUi(this);
populateItems();
loadGeom();
}
void PartPlacer::closeEvent(QCloseEvent *e)
{
saveGeom();
QDockWidget::closeEvent(e);
}
void PartPlacer::hideEvent(QHideEvent *e)
{
saveGeom();
QDockWidget::hideEvent(e);
}
void PartPlacer::saveGeom()
{
QSettings s;
s.setValue("partPlacer/geometry", QVariant(saveGeometry()));
s.setValue("partPlacer/headerState",
QVariant(partsTree->header()->saveState()));
}
void PartPlacer::loadGeom()
{
QSettings s;
restoreGeometry(s.value("partPlacer/geometry").toByteArray());
partsTree->header()->restoreState(
s.value("partPlacer/headerState").toByteArray());
}
void PartPlacer::populateItems()
{
partsTree->clear();
PCBDoc* doc = dynamic_cast<PCBDoc*>(mCtrl->doc());
if (!doc) return;
foreach(const NLPart& part, doc->netlist()->parts())
{
QTreeWidgetItem *partItem = new QTreeWidgetItem(this->partsTree);
partItem->setText(1, part.refdes());
partItem->setText(2, part.footprint());
switch(part.checkPart(doc))
{
case NLPart::OK:
partItem->setIcon(0, mYesIcon);
partItem->setFlags(Qt::ItemIsEnabled);
break;
case NLPart::Missing:
partItem->setIcon(0, mNoIcon);
partItem->setFlags(Qt::ItemIsEnabled |
Qt::ItemIsSelectable);
break;
case NLPart::Mismatch:
partItem->setIcon(0, mWarnIcon);
partItem->setFlags(Qt::ItemIsEnabled);
break;
default:
partItem->setIcon(0, mErrIcon);
partItem->setFlags(0);
break;
}
}
}
void PartPlacer::updateList()
{
populateItems();
}
void PartPlacer::on_placeBtn_clicked()
{
PCBDoc* doc = dynamic_cast<PCBDoc*>(mCtrl->doc());
if (!doc) return;
QList<NLPart> parts;
foreach(QTreeWidgetItem* item, partsTree->selectedItems())
{
parts.append(doc->netlist()->part(item->data(1, Qt::DisplayRole).toString()));
}
if (parts.isEmpty()) return;
mCtrl->clearSelection();
mCtrl->installEditor(EditorFactory::instance().placePartEditor(mCtrl, parts));
}