-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDisplayList.h
343 lines (297 loc) · 11.8 KB
/
DisplayList.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
// DisplayList.h : header file for CDisplayList class
//
#pragma once
#include <afxcoll.h>
#include <afxtempl.h>
#include "afxwin.h"
#include "ids.h"
#include "layers.h"
#include "LinkList.h"
#include "rgb.h"
//#define DL_MAX_LAYERS 32
#define DL_MAGIC 2674
#define PCBU_PER_WU 25400 // conversion from PCB units to world units
// graphics element types
enum
{
DL_NONE = 0,
DL_LINE, // line segment with round end-caps
DL_CIRC, // filled circle
DL_DONUT, // annulus
DL_SQUARE, // filled square
DL_RECT, // filled rectangle
DL_RRECT, // filled rounded rectangle
DL_OVAL, // filled oval
DL_OCTAGON, // filled octagon
DL_HOLE, // hole, shown as circle
DL_HOLLOW_CIRC, // circle outline
DL_HOLLOW_RECT, // rectangle outline
DL_HOLLOW_RRECT, // rounded rectangle outline
DL_HOLLOW_OVAL, // oval outline
DL_HOLLOW_OCTAGON, // octagon outline
DL_RECT_X, // rectangle outline with X
DL_ARC_CW, // arc with clockwise curve
DL_ARC_CCW, // arc with counter-clockwise curve
DL_CENTROID, // circle and X
DL_X // X
};
// dragging line shapes
enum
{
DS_NONE = 0,
DS_LINE_VERTEX, // vertex between two lines
DS_LINE, // line
DS_ARC_STRAIGHT, // straight line (used when drawing polylines)
DS_ARC_CW, // clockwise arc (used when drawing polylines)
DS_ARC_CCW, // counterclockwise arc (used when drawing polylines)
DS_SEGMENT // line segment (with rubber banding of linking segments)
};
// styles of line segment when dragging line or line vertex
enum
{
DSS_STRAIGHT = 100, // straight line
DSS_ARC_CW, // clockwise arc
DSS_ARC_CCW, // counterclockwise arc
DSS_NONE // piece is missing (used in Move Segment for missing final segment)
};
// inflection modes for DS_LINE and DS_LINE_VERTEX
enum
{
IM_NONE = 0,
IM_90_45,
IM_45_90,
IM_90
};
struct CDrawInfo
{
CDC *DC;
CDC *DC_Master;
CPen erase_pen;
CBrush erase_brush;
CPen line_pen;
CBrush fill_brush;
COLORREF layer_color[2];
int size_of_2_pixels;
mutable int nlines;
CDrawInfo() : nlines(0) {}
};
#include "DrawingElement.h"
#include "DrawingJob.h"
class CDisplayList
{
private:
friend dl_element;
// display-list parameters for each layer
CDLinkList m_LIST_job[MAX_LAYERS];
C_RGB m_rgb[MAX_LAYERS]; // layer colors
int m_layer_in_order[MAX_LAYERS]; // array of layers in draw order
int m_order_for_layer[MAX_LAYERS]; // draw order for each layer
// window parameters
int m_pcbu_per_wu; // i.e. nm per world unit
CRect m_client_r; // client rect (pixels)
CRect m_screen_r; // client rect (screen coords)
int m_pane_org_x; // left border of drawing pane (pixels)
int m_pane_org_y; // bottom border of drawing pane (pixels)
int m_bottom_pane_h; // height of bottom pane
CDC * memDC; // pointer to memory DC
public:
BOOL m_vis[MAX_LAYERS]; // layer visibility flags
double m_scale; // world units per pixel
int m_org_x; // world x-coord of left side of screen (world units)
int m_org_y; // world y-coord of bottom of screen (world units)
int m_max_x; // world x_coord of right side of screen (world units)
int m_max_y; // world y_coord of top of screen (world units)
private:
int w_ext_x, w_ext_y; // window extents (world units)
int v_ext_x, v_ext_y; // viewport extents (pixels)
double m_wu_per_pixel_x; // ratio w_ext_x/v_ext_x (world units per pixel)
double m_wu_per_pixel_y; // ratio w_ext_y/v_ext_y (world units per pixel)
double m_pcbu_per_pixel_x;
double m_pcbu_per_pixel_y;
int m_ratline_w;
// general dragging parameters
int m_drag_angle; // angle of rotation of selection rectangle (starts at 0)
int m_drag_side; // 0 = no change, 1 = switch to opposite
int m_drag_vert; // 1 if item being dragged is a vertical part
// parameters for dragging polyline sides and trace segments
// that can be modified while dragging
int m_drag_flag; // 1 if dragging something
int m_drag_shape; // shape
int m_last_drag_shape; // last shape drawn
int m_drag_x; // last cursor position for dragged shape
int m_drag_y;
int m_drag_xb; // start of rubberband drag line "before" selected line
int m_drag_yb;
int m_drag_xi; // start of rubberband drag line
int m_drag_yi;
int m_drag_xf; // end of rubberband drag line
int m_drag_yf;
int m_drag_xe; // start of rubberband drag line at end of trio
int m_drag_ye;
int m_drag_layer_0; // line layer
int m_drag_w0; // line width
int m_drag_style0; // line style
int m_drag_layer_1; // line layer
int m_drag_w1; // line width
int m_drag_style1; // line style
int m_inflection_mode; // inflection mode
int m_last_inflection_mode; // last mode drawn
// extra parameters when dragging vertex between 2 line segments
int m_drag_style2;
int m_drag_layer_2;
int m_drag_w2;
// parameters used to draw leading via if necessary
int m_drag_layer_no_via;
int m_drag_via_w;
int m_drag_via_holew;
int m_drag_via_drawn;
// arrays of lines and ratlines being dragged
// these can be rotated and flipped while being dragged
int m_drag_layer; // layer
int m_drag_max_lines; // max size of array for line segments
int m_drag_num_lines; // number of line segments to drag
CPoint * m_drag_line_pt; // array of relative coords for line endpoints
int m_drag_max_ratlines; // max size of ratline array
int m_drag_num_ratlines; // number of ratlines to drag
CPoint * m_drag_ratline_start_pt; // absolute coords for ratline start points
CPoint * m_drag_ratline_end_pt; // relative coords for ratline endpoints
int m_drag_ratline_width;
// cursor parameters
int m_cross_hairs; // 0 = none, 1 = cross-hairs, 2 = diagonals
CPoint m_cross_left, m_cross_right, m_cross_top, m_cross_bottom; // end-points
CPoint m_cross_topleft, m_cross_topright, m_cross_botleft, m_cross_botright;
// grid
int m_visual_grid_on;
double m_visual_grid_spacing; // in world units
dl_element * CreateDLE( int gtype );
public:
CDisplayList( int pcbu_per_wu );
~CDisplayList();
void SetVisibleGrid( BOOL on, double grid );
void SetMapping( CRect *client_r, CRect *screen_r, int pane_org_x, int pane_bottom_h, double scale, int org_x, int org_y );
void SetDCToWorldCoords( CDC * pDC, CDC * mDC, int pcbu_org_x, int pcbu_org_y );
void SetLayerRGB( int layer, C_RGB color );
void SetLayerVisible( int layer, BOOL vis );
void SetLayerDrawOrder( int layer, int order )
{ m_layer_in_order[order] = layer; m_order_for_layer[layer] = order; };
void Scale_pcbu_to_wu(CRect &rect);
void Scale_wu_to_pixels(CRect &rect);
dl_element * CreateDLE( id id, void * ptr, int layer, int gtype, int visible,
int w, int holew, int clearancew,
int x, int y, int xf, int yf, int xo, int yo, int radius,
int orig_layer );
dl_element * MorphDLE( dl_element *pFrom, int to_gtype );
// Get traces job
CDL_job_traces * GetJob_traces( int layer );
// Add a job
void Add( CDL_job *pDL_job, int layer );
// Create and add elements
dl_element * Add( id id, void * ptr, int glayer, int gtype, int visible,
int w, int holew, int clearancew,
int x, int y, int xf, int yf, int xo, int yo,
int radius=0,
int orig_layer=LAY_SELECTION );
dl_element * Add( CDL_job *pDL_job, id id, void * ptr, int glayer, int gtype, int visible,
int w, int holew, int clearancew,
int x, int y, int xf, int yf, int xo, int yo,
int radius=0 );
dl_element * AddSelector( id id, void * ptr, int glayer, int gtype, int visible,
int w, int holew,
int x, int y, int xf, int yf, int xo, int yo,
int radius=0 );
// Add elements
void Add( dl_element * element );
// Remove elements
void RemoveAll();
void RemoveAllFromLayer( int layer );
id Remove( dl_element * element );
void Draw( CDC * pDC );
int HighLight( int gtype, int x, int y, int xf, int yf, int w, int orig_layer=LAY_SELECTION );
int CancelHighLight();
int TestSelect( int x, int y,
CDL_job::HitInfo hit_info[], int max_hits, int &num_hits,
id * exclude_id = NULL, void * exclude_ptr = NULL,
id * include_id = NULL, int n_include_ids=0 );
int StartDraggingArray( CDC * pDC, int x, int y, int vert, int layer, int crosshair = 1 );
int StartDraggingRatLine( CDC * pDC, int x, int y, int xf, int yf, int layer,
int w, int crosshair = 1 );
int StartDraggingRectangle( CDC * pDC, int x, int y, int xi, int yi,
int xf, int yf, int vert, int layer );
int StartDraggingLineVertex( CDC * pDC, int x, int y, int xi, int yi,
int xf, int yf,
int layer1, int layer2, int w1, int w2,
int style1, int style2,
int layer_no_via, int via_w, int via_holew, int dir,
int crosshair );
int StartDraggingLineSegment( CDC * pDC, int x, int y,
int xb, int yb,
int xi, int yi,
int xf, int yf,
int xe, int ye,
int layer0, int layer1, int layer2,
int w0, int w1, int w2,
int style0, int style1, int style2,
int layer_no_via, int via_w, int via_holew,
int crosshair );
int StartDraggingLine( CDC * pDC, int x, int y, int xi, int yi, int layer1, int w,
int layer_no_via, int via_w, int via_holew,
int crosshair, int style, int inflection_mode );
int StartDraggingArc( CDC * pDC, int style, int x, int y, int xi, int yi,
int layer, int w, int crosshair );
void SetDragArcStyle( int style );
void Drag( CDC * pDC, int x, int y );
int StopDragging();
BOOL Dragging_third_segment() { return m_drag_style2 != DSS_NONE; };
void ChangeRoutingLayer( CDC * pDC, int layer1, int layer2, int w );
void IncrementDragAngle( CDC * pDC );
int MakeDragLineArray( int num_lines );
int MakeDragRatlineArray( int num_ratlines, int width );
int AddDragLine( CPoint pi, CPoint pf );
int AddDragRatline( CPoint pi, CPoint pf );
int GetDragAngle();
void FlipDragSide( CDC * pDC );
int GetDragSide();
void SetUpCrosshairs( int type, int x, int y );
void SetInflectionMode( int mode ){ m_inflection_mode = mode; };
CPoint ScreenToPCB( CPoint point );
CPoint PCBToScreen( CPoint point );
CPoint WindowToPCB( CPoint point );
void UpdateRatlineWidth( int width );
// set element parameters
void Set_visible( dl_element * el, int visible );
void Set_sel_vert( dl_element * el, int sel_vert );
void Set_w( dl_element * el, int w );
void Set_clearance( dl_element * el, int clearance );
void Set_holew( dl_element * el, int holew );
void Set_x_org( dl_element * el, int x_org );
void Set_y_org( dl_element * el, int y_org );
void Set_x( dl_element * el, int x );
void Set_y( dl_element * el, int y );
void Set_xf( dl_element * el, int xf );
void Set_yf( dl_element * el, int yf );
void Set_id( dl_element * el, id * id );
void Set_layer( dl_element * el, int layer );
void Set_radius( dl_element * el, int radius );
void Set_mode( dl_element * el, int mode );
void Set_pass( dl_element * el, int pass );
void Move( dl_element * el, int dx, int dy );
// get element parameters
void * Get_ptr( dl_element * el );
int Get_gtype( dl_element * el );
int Get_visible( dl_element * el );
int Get_sel_vert( dl_element * el );
int Get_w( dl_element * el );
int Get_holew( dl_element * el );
int Get_x_org( dl_element * el );
int Get_y_org( dl_element * el );
int Get_x( dl_element * el );
int Get_y( dl_element * el );
int Get_xf( dl_element * el );
int Get_yf( dl_element * el );
int Get_radius( dl_element * el );
int Get_layer( dl_element * el );
int Get_mode( dl_element * el );
int Get_pass( dl_element * el );
void Get_Endpoints(CPoint *cpi, CPoint *cpf);
id Get_id( dl_element * el );
};