-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathEditPinDialog.cpp
More file actions
193 lines (169 loc) · 4.72 KB
/
EditPinDialog.cpp
File metadata and controls
193 lines (169 loc) · 4.72 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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
/*
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 "EditPinDialog.h"
#include "Document.h"
#include "ManagePadstacksDialog.h"
#include "Footprint.h"
#include <QMessageBox>
Q_DECLARE_METATYPE(QSharedPointer<Padstack>);
EditPinDialog::EditPinDialog(QWidget *parent, Document *doc) :
QDialog(parent), mInMM(false), mPin(NULL), mDoc(doc)
{
setupUi(this);
updatePsList();
}
void EditPinDialog::init(QSharedPointer<Pin> p)
{
mPin = p;
if (mPin)
{
// name
pinName->setText(mPin->name());
// padstack
QSharedPointer<Padstack> ps = mPin->padstack();
psList->setCurrentIndex(psList->findData(QVariant::fromValue(ps)));
// position
this->setPosRadio->setChecked(true);
xPosBox->setValue(toUnits(mPin->pos().x()));
yPosBox->setValue(toUnits(mPin->pos().y()));
angleBox->setCurrentIndex(mPin->angle() / 90);
// disable add row checkbox
addRowCheck->setChecked(false);
addRowCheck->setEnabled(false);
}
}
void EditPinDialog::on_unitsBox_currentIndexChanged(const QString &s)
{
mInMM = (s == "mm");
updateUnits();
}
void EditPinDialog::updateUnits()
{
const int numBoxes = 3;
QDoubleSpinBox* const boxes[] = { xPosBox, yPosBox, spacingBox };
for(int i = 0; i < numBoxes; i++)
{
if (!mInMM)
{
boxes[i]->setValue(XPcb::pcbToMil(XPcb::mmToPcb(boxes[i]->value())));
boxes[i]->setDecimals(0);
boxes[i]->setSuffix(" mil");
}
else
{
boxes[i]->setDecimals(3);
boxes[i]->setValue(XPcb::pcbToMm(XPcb::milToPcb(boxes[i]->value())));
boxes[i]->setSuffix(" mm");
}
}
}
void EditPinDialog::updatePsList()
{
psList->clear();
foreach(QSharedPointer<Padstack> p, mDoc->padstacks())
{
psList->addItem(p->name(), QVariant::fromValue(p));
}
}
void EditPinDialog::on_manageBtn_clicked()
{
ManagePadstacksDialog d(this, mDoc);
d.exec();
updatePsList();
}
QList<QSharedPointer<Pin> > EditPinDialog::makePins(QSharedPointer<Footprint> fp)
{
// initial position
QPoint firstPos(0, 0);
int firstAngle = 0;
// get padstack from list
QSharedPointer<Padstack> ps = padstack();
Q_ASSERT(ps);
// set initial position to user value if set
if (!dragToPos())
{
firstPos = pos();
firstAngle = angle();
}
// make first pin
QSharedPointer<Pin> first(new Pin(fp.data()));
QString name = this->name();
first->setName(name);
first->setPadstack(ps);
first->setPos(firstPos);
first->setAngle(firstAngle);
// return just this pin if box is not checked
QList<QSharedPointer<Pin> > list;
list.append(first);
if (!addRowCheck->isChecked())
return list;
// split the name into the basename and number components
// for example: pin name = A1B2C5
// basename = A1B2C
// number = 5
QRegExp re("^((?:.*\\D)?)(\\d*)$");
if (!re.exactMatch(name))
Q_ASSERT(false);
QString baseName = re.cap(1);
int startNum = 0;
if (re.cap(2) != "")
startNum = re.cap(2).toInt();
QPoint delta;
if (orientBox->currentIndex() == 0) // horizontal
delta.setX(toPcb(spacingBox->value()));
else
delta.setY(toPcb(spacingBox->value()));
// add other pins
for(int i = 1; i < numPinsBox->value(); i++)
{
QSharedPointer<Pin> p(new Pin(fp.data()));
p->setName(baseName + QString::number(startNum + i*incrementBox->value()));
p->setPadstack(ps);
p->setAngle(firstAngle);
p->setPos(firstPos + delta * i);
list.append(p);
}
return list;
}
int EditPinDialog::toPcb(double unit) const
{
if (mInMM) return XPcb::mmToPcb(unit);
else return XPcb::milToPcb(unit);
}
double EditPinDialog::toUnits(int pcbu) const
{
if (mInMM) return XPcb::pcbToMm(pcbu);
else return XPcb::pcbToMil(pcbu);
}
QSharedPointer<Padstack> EditPinDialog::padstack() const
{
return psList->itemData(psList->currentIndex()).value<QSharedPointer<Padstack> >();
}
void EditPinDialog::accept()
{
if (!this->padstack())
{
QMessageBox mb(QMessageBox::Warning, "No padstack selected", "You have not selected a padstack for this pin. Please select a padstack and try again.", QMessageBox::Ok, this);
mb.exec();
return;
}
if (this->name().isEmpty())
{
QMessageBox mb(QMessageBox::Warning, "No name entered", "You have not entered a name for this pin. Please enter a name and try again.", QMessageBox::Ok, this);
mb.exec();
return;
}
QDialog::accept();
}