-
Notifications
You must be signed in to change notification settings - Fork 1
/
Area.h
146 lines (114 loc) · 4.09 KB
/
Area.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
/*
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 AREA_H
#define AREA_H
#include <QSet>
#include "global.h"
#include "PCBObject.h"
#include "Polygon.h"
class PartPin;
class Vertex;
class TraceList;
class PCBDoc;
class QXmlStreamReader;
class QXmlStreamWriter;
/// A copper area.
/// Area describes a copper area. Areas can either be unconnected,
/// or they can be assigned to a net. In the latter case, the area will
/// automatically connect to any vertices, vias, or pins that are within its
/// boundaries. Areas are internally represented as a Polygon object (the area
/// outline, with any cutouts, drawn by the user). For drawing and DRC, a PolygonList
/// is computed by subtracting all pad/trace clearances from the master polygon.
class Area : public PCBObject
{
Q_OBJECT
public:
/// A list of the possible fill styles for the polygon when drawing.
enum HatchStyle { NO_HATCH, ///< No hatch lines; only the outline is drawn.
DIAGONAL_FULL, ///< The polygon is filled with diagonal hatch lines.
DIAGONAL_EDGE ///< Short diagonal hatch lines are drawn on the inside part of the edges.
};
Area(PCBDoc *doc);
~Area();
virtual void draw(QPainter *painter, const Layer& layer) const;
virtual QRect bbox() const;
virtual PCBObjState getState() const { return PCBObjState(new AreaState(*this)); }
virtual bool loadState(PCBObjState &state);
virtual bool testHit(QPoint pt, int distance,
const Layer& l) const;
/// Sets the polygon layer.
/// \param layer the new layer.
void setLayer( const Layer& layer ) { mLayer = layer; }
/// \returns the current polygon layer.
const Layer& layer() const {return mLayer;}
/// Gets the hatch style.
/// \returns the current hatch style
HatchStyle hatchStyle() const { return mHatchStyle; }
/// Sets the hatch style.
/// \param hatch the new hatch style.
void setHatchStyle( HatchStyle hatch ) { mHatchStyle = hatch; }
bool connSmt() { return mConnectSMT; }
QString net() { return mNet; }
Polygon& poly() { return mPoly; }
/// Check if a point is within the area boundaries.
/// \returns true if p is inside area.
bool pointInside(const QPoint &p) const;
static QSharedPointer<Area> newFromXML(QXmlStreamReader &reader, PCBDoc &doc);
void toXML(QXmlStreamWriter &writer);
private:
class AreaState : public PCBObjStateInternal
{
public:
virtual ~AreaState() {}
private:
friend class Area;
AreaState(const Area &a)
: mDoc(a.mDoc),
mNet(a.mNet),
mConnectSMT(a.mConnectSMT),
mPoly(a.mPoly),
mConnPins(a.mConnPins),
mConnVtx(a.mConnVtx),
mLayer(a.mLayer),
mHatchStyle(a.mHatchStyle)
{}
const PCBDoc* mDoc;
QString mNet;
bool mConnectSMT;
Polygon mPoly;
QList<QWeakPointer<PartPin> > mConnPins;
QSet<Vertex* > mConnVtx;
Layer mLayer;
HatchStyle mHatchStyle;
};
/// Compute list of connected pins and vertices
void findConnections();
/// Parent container
const PCBDoc* mDoc;
/// Net assigned to this area
QString mNet;
/// Whether to connect SMT pads to this area
bool mConnectSMT;
Polygon mPoly;
/// List of connected pins
QList<QWeakPointer<PartPin> > mConnPins;
/// List of connected vias and vertices
QSet<Vertex* > mConnVtx;
/// Layer this polygon is on.
Layer mLayer;
/// Hatch style for drawing this polygon
HatchStyle mHatchStyle;
};
#endif // AREA_H