-
Notifications
You must be signed in to change notification settings - Fork 1
/
Footprint.h
382 lines (307 loc) · 10.9 KB
/
Footprint.h
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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
/*
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/>.
*/
#ifndef FOOTPRINT_H
#define FOOTPRINT_H
#include <QHash>
#include <QXmlStreamReader>
#include <QXmlStreamWriter>
#include <QUuid>
#include "PCBObject.h"
#include "Text.h"
#include "Line.h"
class Footprint;
class Pin;
/// A pad is a padstack component; it describes the
/// shape of a pad on a given layer of the padstack.
class Pad
{
public:
// pad shapes
enum PADSHAPE {
PAD_NONE = 0,
PAD_DEFAULT,
PAD_ROUND,
PAD_SQUARE,
PAD_RECT,
PAD_RRECT,
PAD_OBROUND,
PAD_OCTAGON,
};
/// Describes how to connect a pad to copper areas.
enum PADCONNTYPE {
CONN_DEFAULT = 0, ///< use global setting
CONN_NEVER, ///< never connect pad to area
CONN_THERMAL, ///< connect pad using a thermal structure
CONN_NOTHERMAL ///< flood pad with copper
};
Pad(PADSHAPE shape = PAD_NONE, int width = 0, int length = 0, int radius = 0, PADCONNTYPE connType = CONN_DEFAULT);
bool operator==(const Pad &p) const;
bool isNull() const { return mShape == PAD_NONE; }
bool isDefault() const { return mShape == PAD_DEFAULT; }
static Pad newFromXML(QXmlStreamReader &reader);
void toXML(QXmlStreamWriter &writer) const;
PADSHAPE shape() {return mShape;}
int width() {return mWidth;}
int length() {return mLength;}
int radius() {return mRadius;}
PADCONNTYPE connFlag() {return mConnFlag;}
void setConnFlag(PADCONNTYPE flag) { mConnFlag = flag; }
bool testHit( const QPoint & pt, int dist );
QRect bbox() const;
void draw(QPainter *painter) const;
private:
PADSHAPE mShape;
int mWidth, mLength, mRadius;
PADCONNTYPE mConnFlag;
};
/// A padstack is a collection of pads and a hole.
/// Padstacks are used for component pins as well as vias.
/// A padstack is shared between all physically identical pins.
class Padstack
{
public:
Padstack();
// bool operator==(const Padstack &p) const;
static QSharedPointer<Padstack> newFromXML(QXmlStreamReader &reader);
void toXML(QXmlStreamWriter &writer) const;
QString name() const {return mName; }
void setName(QString name) { mName = name; }
int holeSize() const {return hole_size;}
void setHoleSize(int size) { hole_size = size; }
Pad& startPad() {return start;}
Pad& endPad() {return end;}
Pad& innerPad() {return inner;}
Pad& startMask() {return start_mask;}
Pad& endMask() {return end_mask; }
Pad& startPaste() {return start_paste;}
Pad& endPaste() {return end_paste;}
bool isSmt() const {return hole_size == 0;}
QRect bbox() const;
void draw(QPainter *painter, const Layer& layer) const;
QUuid uuid() const { return mUuid; }
private:
/// Padstack name; optional; only used for library padstacks
/// (i.e. VIA_15MIL)
QString mName;
int hole_size; // 0 = no hole (i.e SMT)
Pad start, start_mask, start_paste;
Pad end, end_mask, end_paste;
Pad inner;
QUuid mUuid;
};
class Footprint : public PCBObject
{
Q_OBJECT
public:
Footprint(QObject *parent = NULL);
enum FP_DRAW_LAYER { LAY_START, LAY_INNER, LAY_END };
virtual void draw(QPainter *, const Layer& ) const {}
void draw(QPainter *painter, FP_DRAW_LAYER layer) const;
QRect bbox() const;
QString name() const { return mName; }
void setName(QString name) { mName = name; }
QString author() const { return mAuthor; }
void setAuthor(QString author) { mAuthor = author; }
QString source() const { return mSource; }
void setSource(QString src) { mSource = src; }
QString desc() const { return mDesc; }
void setDesc(QString desc) { mDesc = desc; }
QList<QSharedPointer<Padstack> > padstacks() { return mPadstacks; }
void addPadstack(QSharedPointer<Padstack> ps) { mPadstacks.append(ps); }
void removePadstack(QSharedPointer<Padstack> ps);
QSharedPointer<Padstack> padstack(QUuid uuid) const;
int numPins() const;
QSharedPointer<Pin> pin(const QString & pin) const;
QSharedPointer<Pin> pin(int i) {return mPins.at(i);}
const QList<QSharedPointer<Pin> > pins() { return mPins; }
void addPin(QSharedPointer<Pin> p) { mPins.append(p); }
void removePin(QSharedPointer<Pin> p) { mPins.removeOne(p); }
const QList<QSharedPointer<Text> > texts() { return mTexts; }
void addText(QSharedPointer<Text> t) { mTexts.append(t); }
void removeText(QSharedPointer<Text> t) { mTexts.removeOne(t); }
const QList<QSharedPointer<Line> > lines() { return mOutlineLines; }
void addLine(QSharedPointer<Line> l) { mOutlineLines.append(l); }
void removeLine(QSharedPointer<Line> l) { mOutlineLines.removeOne(l); }
QRect getPinBounds() const;
QSharedPointer<Text> refText() {return mRefText;}
QSharedPointer<Text> valueText() {return mValueText;}
QPoint centroid() {return mCentroid;}
bool isCustomCentroid() {return mCustomCentroid;}
XPcb::UNIT units() {return mUnits; }
static QSharedPointer<Footprint> newFromXML(QXmlStreamReader &reader);
void toXML(QXmlStreamWriter &writer) const;
const QUuid& uuid() const { return mUuid; }
virtual PCBObjState getState() const { return PCBObjState(); }
virtual bool loadState(PCBObjState &) { return false; }
private:
// Footprint(const Footprint& other);
/// Assignment operator (disabled)
Footprint& operator=(Footprint& other);
/// Computes the default centroid (center of all pins)
QPoint getDefaultCentroid();
/// Footprint name (i.e. DIP20)
QString mName;
/// Footprint author
QString mAuthor;
/// Source document used to create footprint (i.e. mfg datasheet)
QString mSource;
/// Description of footprint
QString mDesc;
/// Units used to draw the footprint
XPcb::UNIT mUnits;
/// Reference designator text
QSharedPointer<Text> mRefText;
/// Value text
QSharedPointer<Text> mValueText;
/// Centroid point; can be automatic or user-defined
QPoint mCentroid;
/// If false, centroid is automatically set to the center of all pins
/// If true, centroid is user-defined
bool mCustomCentroid;
/// Footprint padstacks
QList<QSharedPointer<Padstack> > mPadstacks;
/// Footprint pins
QList<QSharedPointer<Pin> > mPins;
/// Silkscreen lines (used for part outline)
QList<QSharedPointer<Line> > mOutlineLines;
/// Silkscreen text
QList<QSharedPointer<Text> > mTexts;
/// UUID for this footprint
QUuid mUuid;
};
/// A pin is an instance of a padstack associated with a footprint.
/// It stores the name, coordinates, rotation, and the associated padstack
/// of each pin within a footprint.
class Pin : public PCBObject
{
Q_OBJECT
public:
Pin(Footprint* fp) : PCBObject(fp), mAngle(0), mIsDirty(true), mFootprint(fp) {}
int angle() const { return mAngle; }
QPoint pos() const { return mPos; }
QSharedPointer<Padstack> padstack() const { return mPadstack; }
QString name() const { return mName; }
void setName(QString name) { mName = name; }
void setPos(QPoint pos) { mPos = pos; markDirty(); }
void setAngle(int angle) { mAngle = angle; markDirty(); }
void setPadstack(QSharedPointer<Padstack> ps) { mPadstack = ps; }
virtual void draw(QPainter *painter, const Layer& layer) const;
virtual QRect bbox() const;
virtual PCBObjState getState() const;
virtual bool loadState(PCBObjState &state);
virtual bool testHit(QPoint pt, int dist, const Layer& layer) const;
static QSharedPointer<Pin> newFromXML(QXmlStreamReader &reader, const QHash<int, QSharedPointer<Padstack> > &padstacks, Footprint* fp);
void toXML(QXmlStreamWriter &writer) const;
Pad getPadOnLayer(const Layer& layer) const;
virtual QTransform transform() const { return mFpTransform; }
private:
class PinState : public PCBObjStateInternal
{
public:
virtual ~PinState() {}
private:
friend class Pin;
PinState(const Pin &p)
: name(p.name()), pos(p.pos()), angle(p.angle()),
ps(p.padstack())
{}
QString name;
QPoint pos;
int angle;
QSharedPointer<Padstack> ps;
};
// disabled copy constructor
Pin(const Pin& other);
// disabled assignment operator
Pin& operator=(const Pin& other);
void updateTransform() const;
void markDirty() const { mIsDirty = true; }
/// Pin name (i.e. "1", "B2", "GATE")
QString mName;
/// Position relative to parent footprint
QPoint mPos;
/// Rotation angle (CW)
int mAngle;
/// Transform to part coordinates
mutable QTransform mFpTransform;
mutable bool mIsDirty;
/// Padstack used for this pin
QSharedPointer<Padstack> mPadstack;
/// Parent footprint
Footprint* mFootprint;
};
class FPDBFile;
class FPDBFolder;
/// The FPDatabase class is a singleton that is responsible for maintaining a database of available footprints.
/// It searches the configured footprint directories for footprint files and adds them to a tree structure.
class FPDatabase
{
public:
static FPDatabase& instance();
QList<QSharedPointer<FPDBFolder> > rootFolders() const { return mRootFolders; }
QSharedPointer<const FPDBFile> getByUuid(QUuid uuid) const { return mUuidHash.value(uuid); }
QSharedPointer<const FPDBFile> getByName(QString name) const { return mNameHash.value(name); }
private:
FPDatabase();
static FPDatabase* mInst;
QList<QSharedPointer<FPDBFolder> > mRootFolders;
QHash<QUuid, QSharedPointer<FPDBFile> > mUuidHash;
QHash<QString, QSharedPointer<FPDBFile> > mNameHash;
QSharedPointer<FPDBFolder> createFolder(QString path, bool fullName = false);
QSharedPointer<FPDBFile> createFile(QString path);
};
class FPDBFile
{
public:
FPDBFile(QString path, QString name, QString author, QString source,
QString desc, QUuid uuid);
QString path() const { return mFpPath; }
QString name() const { return mName; }
QString author() const { return mAuthor; }
QString source() const { return mSource; }
QString desc() const { return mDesc; }
QUuid uuid() const { return mUuid; }
QSharedPointer<Footprint> loadFootprint() const;
void setParent(FPDBFolder* parent) { mParent = parent; }
FPDBFolder* parent() const { return mParent; }
private:
/// Absolute path to footprint file
QString mFpPath;
/// Footprint name
QString mName;
QString mAuthor;
QString mSource;
QString mDesc;
QUuid mUuid;
/// Parent folder
FPDBFolder* mParent;
};
class FPDBFolder
{
public:
FPDBFolder(QString name, QList<QSharedPointer<FPDBFolder> > folders,
QList<QSharedPointer<FPDBFile> > files);
void setParent(FPDBFolder* parent) { mParent = parent; }
FPDBFolder* parent() const { return mParent; }
QString name() const { return mName; }
QList<QSharedPointer<FPDBFolder> > folders() const { return mFolders; }
QList<QSharedPointer<FPDBFile> > items() const { return mFiles; }
private:
QString mName;
QList<QSharedPointer<FPDBFolder> > mFolders;
QList<QSharedPointer<FPDBFile> > mFiles;
FPDBFolder* mParent;
};
#endif