-
Notifications
You must be signed in to change notification settings - Fork 0
/
gerberimporter.h
256 lines (206 loc) · 7.48 KB
/
gerberimporter.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
#ifndef GERBERIMPORTER_H
#define GERBERIMPORTER_H
#include <QString>
#include <QStringList>
#include <gmpxx.h>
#include <QGraphicsItem>
#include <QPlainTextEdit>
#include <vtkAssembly.h>
#include <vtkSmartPointer.h>
#include <vtkDataObject.h>
enum Unit {mm,in};
//! \internal
class ApertureMacro_internalRep
{
public:
enum Operator {value,plus,minus,mul,div};
public:
ApertureMacro_internalRep();
ApertureMacro_internalRep( mpq_class value );
ApertureMacro_internalRep( Operator op );
mpq_class m_value;
Operator m_operator;
};
class ApertureMacro
{
public:
ApertureMacro();
ApertureMacro( QStringList primitives );
QList<QList<mpq_class> > calc( QList<mpq_class> arguments ) const;
protected:
QStringList m_primitives;
QList<ApertureMacro_internalRep> calc_convertIntoInternalRep( QString term, QList<mpq_class> arguments ) const;
QList<ApertureMacro_internalRep> calc_canonicalize( QList<ApertureMacro_internalRep> temp ) const;
mpq_class calc_processInternalRep( QList<ApertureMacro_internalRep> temp ) const;
//mpq_class calc_intern1( QString term, QList<mpq_class> arguments ) const;
};
class Aperture
{
public:
enum Type {invalid,circle,rectangle,oval,polygon,macro};
enum HoleType {noHole,circularHole,rectangularHole};
public:
Aperture();
Aperture( Unit unit );
void setCircle( mpq_class diameter, mpq_class x_hole_dimension = -1, mpq_class y_hole_dimension = -1 );
void setCircle( QList<mpq_class> arguments );
void setOval( mpq_class x_length, mpq_class y_length, mpq_class x_hole_dimension = -1, mpq_class y_hole_dimension = -1 );
void setOval( QList<mpq_class> arguments );
void setRectangle( QList<mpq_class> arguments );
void setPolygon( QList<mpq_class> arguments );
void setMacro( ApertureMacro macro, QList<mpq_class> arguments );
Type type() const {return m_type;}
mpq_class diameter() const {return m_arguments.value(0);}
QGraphicsItem* getGraphicsItem() const;
protected:
Type m_type;
HoleType m_hole;
QList<mpq_class> m_arguments;
ApertureMacro m_macro;
Unit m_unit;
mpq_class m_unitFactor;
};
class Object
{
public:
Object();
virtual QGraphicsItem* getGraphicsItem() const;
virtual vtkSmartPointer<vtkProp3D> getVtkProp3D(double thickness) const;
virtual vtkSmartPointer<vtkDataObject> getVtkDataObject(double thickness) const;
};
class Line : public Object
{
public:
Line( mpq_class x1, mpq_class y1, mpq_class x2, mpq_class y2, Aperture aperture );
virtual QGraphicsItem* getGraphicsItem() const;
virtual vtkSmartPointer<vtkProp3D> getVtkProp3D( double thickness ) const;
virtual vtkSmartPointer<vtkDataObject> getVtkDataObject(double thickness) const;
protected:
mpq_class m_x1, m_y1, m_x2, m_y2;
Aperture m_aperture;
};
class Line_cw_ccw : public Object
{
public:
Line_cw_ccw( mpq_class x1, mpq_class y1, mpq_class x2, mpq_class y2, mpq_class i, mpq_class j, Aperture aperture );
virtual QGraphicsItem* getGraphicsItem( bool ccw ) const;
protected:
mpq_class m_x1, m_y1, m_x2, m_y2, m_i, m_j;
Aperture m_aperture;
};
class Line_cw : public Line_cw_ccw
{
public:
Line_cw( mpq_class x1, mpq_class y1, mpq_class x2, mpq_class y2, mpq_class i, mpq_class j, Aperture aperture );
virtual QGraphicsItem* getGraphicsItem() const;
};
class Line_ccw : public Line_cw_ccw
{
public:
Line_ccw( mpq_class x1, mpq_class y1, mpq_class x2, mpq_class y2, mpq_class i, mpq_class j, Aperture aperture );
virtual QGraphicsItem* getGraphicsItem() const;
};
class Flash : public Object
{
public:
Flash( mpq_class x, mpq_class y, Aperture aperture );
virtual QGraphicsItem* getGraphicsItem() const;
protected:
mpq_class m_x, m_y;
Aperture m_aperture;
};
class FilledOutline : public Object
{
public:
FilledOutline( QList<QPair<mpq_class, mpq_class> > points );
virtual QGraphicsItem* getGraphicsItem() const;
virtual vtkSmartPointer<vtkProp3D> getVtkProp3D( double thickness ) const;
protected:
QList< QPair<mpq_class,mpq_class> > m_points;
};
class Layer
{
public:
enum ImagePolarity {positive, negative};
enum DrawMode {on,off,flash};
enum OutlineFillMode {fillOn,fillOff};
enum InterpolationMode {linear,clockwise,counterclockwise};
public:
Layer( QHash<int,Aperture> apertures );
~Layer();
void setImagePolarity( ImagePolarity p ) {m_imagePolarity = p;}
ImagePolarity imagePolarity() const {return m_imagePolarity;}
void setName( QString name ) {m_name = name;}
QString name() const {return m_name;}
bool isEmpty() const {return m_objects.isEmpty();}
void setInterpolationMode( InterpolationMode interpolationMode ) {m_interpolationMode = interpolationMode;}
InterpolationMode interpolationMode() const {return m_interpolationMode;}
void setDrawMode( DrawMode drawMode ) {m_drawMode = drawMode;}
DrawMode drawMode() const {return m_drawMode;}
void setAperture( int aperture ) {m_aperture = aperture;}
int aperture() const {return m_aperture;}
void draw( mpq_class x, mpq_class y, mpq_class i, mpq_class j, Unit unit );
void setX( mpq_class x ) {m_current_x = x;}
mpq_class x() const {return m_current_x;}
void setY( mpq_class y ) {m_current_y = y;}
mpq_class y() const {return m_current_y;}
void defineAperture( int num, Aperture aperture );
void startOutlineFill();
void stopOutlineFill();
QList<Object*> getObjects() const {return m_objects;}
vtkSmartPointer<vtkProp3D> getVtkProp3D( double thickness ) const;
vtkSmartPointer<vtkDataObject> getVtkDataObject( double thickness ) const;
protected:
mpq_class m_current_x;
mpq_class m_current_y;
ImagePolarity m_imagePolarity;
QString m_name;
QList<Object*> m_objects;
InterpolationMode m_interpolationMode;
DrawMode m_drawMode;
int m_aperture;
OutlineFillMode m_outlineFillMode;
QList< QPair<mpq_class,mpq_class> > m_outlineFillPoints;
QHash<int,Aperture> m_apertures; //!< Layer specific apertures
void drawFilledOutline( QList< QPair<mpq_class,mpq_class> > points );
};
class GerberImporter
{
public:
GerberImporter();
bool import( QString filename );
QList<Layer>& getLayers() {return m_layers;}
QRectF getDimensionsF() const;
QPolygonF getOutlineF() const;
void setLogWidget( QPlainTextEdit* widget );
protected:
bool processDataBlock( QString dataBlock );
void processParameterBlock( QString parameterBlock, bool finished );
void parameterFS( QString parameterBlock );
void parameterMO( QString parameterBlock );
void parameterLN( QString parameterBlock );
void parameterAD( QString parameterBlock );
void parameterAM( QString collect_parameter_AM );
void drawG01( QString dataBlock );
void drawG02( QString dataBlock );
void drawG03( QString dataBlock );
void draw( QString dataBlock );
void setDCode( QString dataBlock );
void startOutlineFill();
void stopOutlineFill();
mpq_class makeCoordinate( QString str );
void log( QString msg );
Layer& newLayer();
Layer& currentLayer();
QStringList m_deprecated_parameters;
QList<Layer> m_layers;
QHash<int,Aperture> m_apertures; //!< global defined apertures; available to all layers
QHash<QString,ApertureMacro> m_apertureMacros;
QPlainTextEdit* m_logWidget;
// current graphics state
int m_FS_integer, m_FS_decimals, m_FS_decimals10;
enum {omit_leading, omit_trailing} m_FS_zero;
Unit m_MO;
int m_currentAperture; //!< 10-999: aperture
};
#endif // GERBERIMPORTER_H