27
static char *rcsid = "$Id: set.c,v 1.6 1998/02/24 22:54:47 cad Exp $";
29
30
/* routines to update widgets and global settings
30
31
* (except output window and dialogs)
35
40
#include <stdlib.h>
36
42
#include <string.h>
38
45
#include "global.h"
40
47
#include "action.h"
41
48
#include "buffer.h"
42
50
#include "crosshair.h"
43
51
#include "control.h"
48
59
#include "output.h"
51
#include <X11/cursorfont.h>
52
#include <X11/Xaw3d/Form.h>
63
#ifdef HAVE_LIBDMALLOC
67
RCSID("$Id: set.c,v 1.24 2005/01/21 22:25:27 danmc Exp $");
72
static int mode_position = 0;
73
static int mode_stack[MAX_MODESTACK_DEPTH];
54
75
/* ---------------------------------------------------------------------------
55
76
* output of cursor position
57
void SetCursorStatusLine(void)
79
SetCursorStatusLine (void)
62
sprintf(text, "%-i,%-i <%-i,%-i> (%-.1f,%-.1f)",Crosshair.X, Crosshair.Y,
63
Crosshair.X - Marked.X, Crosshair.Y - Marked.Y,
64
sqrt(SQUARE(Crosshair.X - Marked.X) + SQUARE(Crosshair.Y - Marked.Y)),
65
RAD_TO_DEG * atan2(Crosshair.Y - Marked.Y, Marked.X - Crosshair.X));
67
sprintf(text, "%-i,%-i", Crosshair.X, Crosshair.Y);
68
XtVaSetValues(Output.CursorPosition, XtNlabel, text, NULL);
85
"%-i.%02d, %-i.%02d <%-li.%02d, %-li.%02d> (%-.3fmm, %-.3fmm)",
86
Crosshair.X / 100, abs(Crosshair.X % 100), Crosshair.Y / 100,
87
abs(Crosshair.Y % 100), (Crosshair.X - Marked.X) / 100,
88
abs(Crosshair.X - Marked.X) % 100, (Crosshair.Y - Marked.Y) / 100,
89
abs(Crosshair.Y - Marked.Y) % 100,
90
COOR_TO_MM * (Crosshair.X - Marked.X),
91
COOR_TO_MM * (Crosshair.Y - Marked.Y));
93
sprintf (text, "%-i.%02d,%-i.%02d (%-.3fmm, %-.3fmm)",
94
Crosshair.X / 100, abs(Crosshair.X % 100),
95
Crosshair.Y / 100, abs(Crosshair.Y % 100),
96
COOR_TO_MM*Crosshair.X,
97
COOR_TO_MM*Crosshair.Y);
98
SetOutputLabel (Output.CursorPosition, text);
71
101
/* ---------------------------------------------------------------------------
72
102
* output of status line
74
void SetStatusLine(void)
79
sprintf(text, "%c %s,%s,%s%s, grid=%i:%i, zoom=%-i:%-i, line=%-i, via=%-i(%-i), text=%i%%, buffer=#%-i, name: ",
80
PCB->Changed ? '*' : ' ',
81
Settings.ShowSolderSide ? "solder" : "component",
82
TEST_FLAG(ABSOLUTEFLAG, PCB) ? "abs" : "rel",
83
TEST_FLAG(ALLDIRECTIONFLAG, PCB) ? "all" :
84
(PCB->Clipping == 0 ? "45" : (PCB->Clipping == 1 ?
86
TEST_FLAG(RUBBERBANDFLAG, PCB) ? ",R" : " ",
87
(int) PCB->Grid, (int) Settings.GridFactor,
88
(int) (TO_SCREEN(1) ? TO_SCREEN(1) : 1),
89
(int) (TO_PCB(1) ? TO_PCB(1) : 1),
90
(int) Settings.LineThickness,
91
(int) Settings.ViaThickness, (int) Settings.ViaDrillingHole,
92
(int) Settings.TextScale,
93
Settings.BufferNumber+1);
95
/* append the name of the layout */
96
length = sizeof(text) -1 -strlen(text);
97
strncat(text, UNKNOWN(PCB->Name), length);
98
text[sizeof(text) -1] = '\0';
99
XtVaSetValues(Output.StatusLine, XtNlabel, text, NULL);
110
if (PCB->Grid == (int) PCB->Grid)
112
"%c %s, grid=%i.%02i:%i,%s%sline=%i.%02i, via=%i.%02i(%i.%02i),\n"
113
" clearance=%i.%02i, text=%i%%, buffer=#%li, name: ",
114
PCB->Changed ? '*' : ' ',
115
Settings.ShowSolderSide ? "solder" : "component",
116
(int) PCB->Grid / 100, (int) (PCB->Grid) % 100,
117
(int) Settings.GridFactor,
118
TEST_FLAG (ALLDIRECTIONFLAG,
119
PCB) ? "all" : (PCB->Clipping ==
120
0 ? "45" : (PCB->Clipping ==
121
1 ? "45_/" : "45\\_")),
122
TEST_FLAG (RUBBERBANDFLAG, PCB) ? ",R, " : ", ",
123
Settings.LineThickness / 100, Settings.LineThickness % 100,
124
Settings.ViaThickness / 100, Settings.ViaThickness % 100,
125
Settings.ViaDrillingHole / 100, Settings.ViaDrillingHole % 100,
126
Settings.Keepaway / 100, Settings.Keepaway % 100,
127
Settings.TextScale, Settings.BufferNumber + 1);
130
"%c %s, grid=%5.3fmm:%i,%s%sline=%i.%02i, via=%i.%02i(%i.%02i),\n"
131
" clearance=%i.%02i, text=%i%%, buffer=#%li, name: ",
132
PCB->Changed ? '*' : ' ',
133
Settings.ShowSolderSide ? "solder" : "component",
134
PCB->Grid * COOR_TO_MM, (int) Settings.GridFactor,
135
TEST_FLAG (ALLDIRECTIONFLAG,
136
PCB) ? "all" : (PCB->Clipping ==
137
0 ? "45" : (PCB->Clipping ==
138
1 ? "45_/" : "45\\_")),
139
TEST_FLAG (RUBBERBANDFLAG, PCB) ? ",R, " : ", ",
140
Settings.LineThickness / 100, Settings.LineThickness % 100,
141
Settings.ViaThickness / 100, Settings.ViaThickness % 100,
142
Settings.ViaDrillingHole / 100, Settings.ViaDrillingHole % 100,
143
Settings.Keepaway / 100, Settings.Keepaway % 100,
144
Settings.TextScale, Settings.BufferNumber + 1);
146
/* append the name of the layout */
147
length = sizeof (text) - 1 - strlen (text);
148
strncat (text, UNKNOWN (PCB->Name), length);
149
text[sizeof (text) - 1] = '\0';
150
SetOutputLabel (Output.StatusLine, text);
102
153
/* ---------------------------------------------------------------------------
103
154
* sets cursor grid with respect to grid offset values
105
void SetGrid(int Grid)
157
SetGrid (float Grid, Boolean align)
107
if (Grid >= 1 && Grid <= MAX_GRID)
159
if (Grid >= 1 && Grid <= MAX_GRID)
109
/* set offset relative to current location or absolute
110
* to (0,0) depending on resource
111
* DrawGrid() uses XOR mode
113
PCB->GridOffsetX= TEST_FLAG(ABSOLUTEFLAG, PCB) ? 0 : Crosshair.X % Grid;
114
PCB->GridOffsetY= TEST_FLAG(ABSOLUTEFLAG, PCB) ? 0 : Crosshair.Y % Grid;
116
if (Settings.DrawGrid)
164
Crosshair.X - (int) (Crosshair.X / Grid) * Grid + 0.5;
166
Crosshair.Y - (int) (Crosshair.Y / Grid) * Grid + 0.5;
169
if (Settings.DrawGrid)
122
175
/* ---------------------------------------------------------------------------
123
176
* sets new zoom factor, adapts size of viewport and centers the cursor
125
void SetZoom(int Zoom)
127
static String cmd[] = {"MovePointer", "0", "0"};
130
if (MAX(PCB->MaxWidth, PCB->MaxHeight) > (1 << 14))
132
else if (MAX(PCB->MaxWidth, PCB->MaxHeight) > (1 << 13))
133
localMin = MIN_ZOOM - 1;
135
localMin = MIN_ZOOM - 2;
136
Zoom = MAX(localMin, Zoom);
137
Zoom = MIN(MAX_ZOOM, Zoom);
139
/* redraw only if zoom has changed */
140
if (PCB->Zoom != Zoom)
143
ScaleOutput(Output.Width, Output.Height);
144
Pan(TO_SCREEN_X(Crosshair.X) - Output.Width/2 - Xorig,
145
TO_SCREEN_Y(Crosshair.Y) - Output.Height/2 - Yorig, False, True);
147
/* move the pointer to the same relative location */
148
XtCallActionProc(Output.Output, cmd[0], NULL, &cmd[1], 2);
151
/* always redraw status line (used for init sequence) */
183
/* special argument of 1000 zooms to extents plus 10 percent */
186
BoxTypePtr box = GetDataBoundingBox (PCB->Data);
190
logf (0.011 * (float) (box->X2 - box->X1) / Output.Width) / LN_2_OVER_2;
192
MAX (Zoom, logf (0.011 * (float) (box->Y2 - box->Y1) / Output.Height) /
194
Crosshair.X = (box->X1 + box->X2) / 2;
195
Crosshair.Y = (box->Y1 + box->Y2) / 2;
196
old_x = Output.Width / 2;
197
old_y = Output.Height / 2;
201
old_x = TO_SCREEN_X (Crosshair.X);
202
old_y = TO_SCREEN_Y (Crosshair.Y);
204
Zoom = MAX (MIN_ZOOM, Zoom);
205
Zoom = MIN (MAX_ZOOM, Zoom);
206
Zoom_Multiplier = 0.01/expf(Zoom * LN_2_OVER_2);
208
/* redraw only if something changed */
209
if (PCB->Zoom != Zoom)
212
RedrawZoom (old_x, old_y);
217
RedrawZoom (Position old_x, Position old_y)
219
ScaleOutput (Output.Width, Output.Height);
220
if (CoalignScreen (old_x, old_y, Crosshair.X, Crosshair.Y))
224
/* always redraw status line (used for init sequence) */
155
228
/* ---------------------------------------------------------------------------
156
229
* sets a new line thickness
158
void SetLineSize(Dimension Size)
232
SetLineSize (BDimension Size)
160
if (Size >= MIN_LINESIZE && Size <= MAX_LINESIZE)
162
Settings.LineThickness = Size;
234
if (Size >= MIN_LINESIZE && Size <= MAX_LINESIZE)
236
Settings.LineThickness = Size;
237
if (TEST_FLAG (AUTODRCFLAG, PCB))
238
FitCrosshairIntoGrid (Crosshair.X, Crosshair.Y);
167
243
/* ---------------------------------------------------------------------------
168
244
* sets a new via thickness
170
void SetViaSize(Dimension Size, Boolean Force)
247
SetViaSize (BDimension Size, Boolean Force)
172
if (Force || (Size <= MAX_PINORVIASIZE &&
249
if (Force || (Size <= MAX_PINORVIASIZE &&
173
250
Size >= MIN_PINORVIASIZE &&
174
Size >= Settings.ViaDrillingHole +MIN_PINORVIACOPPER))
176
Settings.ViaThickness = Size;
251
Size >= Settings.ViaDrillingHole + MIN_PINORVIACOPPER))
253
Settings.ViaThickness = Size;
181
258
/* ---------------------------------------------------------------------------
182
259
* sets a new via drilling hole
184
void SetViaDrillingHole(Dimension Size, Boolean Force)
262
SetViaDrillingHole (BDimension Size, Boolean Force)
186
if (Force || (Size <= MAX_PINORVIASIZE &&
264
if (Force || (Size <= MAX_PINORVIASIZE &&
187
265
Size >= MIN_PINORVIAHOLE &&
188
Size <= Settings.ViaThickness -MIN_PINORVIACOPPER))
190
Settings.ViaDrillingHole = Size;
266
Size <= Settings.ViaThickness - MIN_PINORVIACOPPER))
268
Settings.ViaDrillingHole = Size;
273
/* ---------------------------------------------------------------------------
274
* sets a keepaway width
277
SetKeepawayWidth (BDimension Width)
279
if (Width <= MAX_LINESIZE && Width >= MIN_LINESIZE)
281
Settings.Keepaway = Width;
195
286
/* ---------------------------------------------------------------------------
196
287
* sets a text scaling
198
void SetTextScale(Dimension Scale)
290
SetTextScale (Dimension Scale)
200
if (Scale <= MAX_TEXTSCALE && Scale >= MIN_TEXTSCALE)
202
Settings.TextScale = Scale;
292
if (Scale <= MAX_TEXTSCALE && Scale >= MIN_TEXTSCALE)
294
Settings.TextScale = Scale;
207
299
/* ---------------------------------------------------------------------------
208
300
* sets or resets changed flag and redraws status
210
void SetChangedFlag(Boolean New)
303
SetChangedFlag (Boolean New)
305
if (PCB->Changed != New)
216
312
/* ---------------------------------------------------------------------------
217
313
* sets the crosshair range to the current buffer extents
219
void SetCrosshairRangeToBuffer(void)
316
SetCrosshairRangeToBuffer (void)
221
if (Settings.Mode == PASTEBUFFER_MODE)
223
SetBufferBoundingBox(PASTEBUFFER);
225
PASTEBUFFER->X -PASTEBUFFER->BoundingBox.X1,
226
PASTEBUFFER->Y -PASTEBUFFER->BoundingBox.Y1,
228
(PASTEBUFFER->BoundingBox.X2 -PASTEBUFFER->X),
230
(PASTEBUFFER->BoundingBox.Y2 -PASTEBUFFER->Y));
318
if (Settings.Mode == PASTEBUFFER_MODE)
320
SetBufferBoundingBox (PASTEBUFFER);
321
SetCrosshairRange (PASTEBUFFER->X - PASTEBUFFER->BoundingBox.X1,
322
PASTEBUFFER->Y - PASTEBUFFER->BoundingBox.Y1,
324
(PASTEBUFFER->BoundingBox.X2 - PASTEBUFFER->X),
326
(PASTEBUFFER->BoundingBox.Y2 - PASTEBUFFER->Y));
234
330
/* ---------------------------------------------------------------------------
235
331
* sets a new buffer number
237
void SetBufferNumber(int Number)
334
SetBufferNumber (int Number)
239
if (Number >= 0 && Number < MAX_BUFFER)
241
Settings.BufferNumber = Number;
336
if (Number >= 0 && Number < MAX_BUFFER)
338
Settings.BufferNumber = Number;
243
/* do an update on the crosshair range */
244
SetCrosshairRangeToBuffer();
340
/* do an update on the crosshair range */
341
SetCrosshairRangeToBuffer ();
249
346
/* ---------------------------------------------------------------------------
250
347
* updates all widgets like status, cursor position ... on screen
252
void UpdateSettingsOnScreen(void)
255
SetCursorStatusLine();
256
UpdateControlPanel();
350
UpdateSettingsOnScreen (void)
353
SetCursorStatusLine ();
354
UpdateControlPanel ();
360
mode_stack[mode_position] = Settings.Mode;
361
if (mode_position < MAX_MODESTACK_DEPTH -1)
368
if (mode_position == 0)
370
Message("hace: underflow of restore mode\n");
373
SetMode(mode_stack[--mode_position]);
260
377
/* ---------------------------------------------------------------------------
261
378
* set a new mode and update X cursor
263
void SetMode(int Mode)
265
static Boolean recursing = False;
266
/* protect the cursor while changing the mode
267
* perform some additional stuff depending on the new mode
268
* reset 'state' of attached objects
275
Crosshair.AttachedObject.Type = NO_TYPE;
276
Crosshair.AttachedObject.State = STATE_FIRST;
277
Crosshair.AttachedPolygon.PointN = 0;
278
if (Settings.Mode == LINE_MODE && Mode == ARC_MODE &&
279
Crosshair.AttachedLine.State != STATE_FIRST)
281
Crosshair.AttachedLine.State = STATE_FIRST;
282
Crosshair.AttachedBox.State = STATE_SECOND;
283
Crosshair.AttachedBox.Point1.X = Crosshair.AttachedBox.Point2.X =
284
Crosshair.AttachedLine.Point1.X;
285
Crosshair.AttachedBox.Point1.Y = Crosshair.AttachedBox.Point2.Y =
286
Crosshair.AttachedLine.Point1.Y;
288
else if (Settings.Mode == ARC_MODE && Mode == LINE_MODE &&
289
Crosshair.AttachedBox.State != STATE_FIRST)
291
Crosshair.AttachedBox.State = STATE_FIRST;
292
Crosshair.AttachedLine.State = STATE_SECOND;
293
Crosshair.AttachedLine.Point1.X = Crosshair.AttachedLine.Point2.X =
294
Crosshair.AttachedBox.Point1.X;
295
Crosshair.AttachedLine.Point1.Y = Crosshair.AttachedLine.Point2.Y =
296
Crosshair.AttachedBox.Point1.Y;
297
Settings.Mode = Mode;
298
AdjustAttachedObjects();
302
Crosshair.AttachedBox.State = STATE_FIRST;
303
Crosshair.AttachedLine.State = STATE_FIRST;
306
/* reset 'valid' cursor area to maximum;
307
* some modes force a change in the 'case' statement
309
SetCrosshairRange(0, 0, PCB->MaxWidth, PCB->MaxHeight);
311
Settings.Mode = Mode;
315
SetOutputXCursor(XC_crosshair);
319
SetOutputXCursor(XC_arrow);
323
SetOutputXCursor(XC_pencil);
327
SetOutputXCursor(XC_question_arrow);
331
SetOutputXCursor(XC_left_ptr);
335
SetOutputXCursor(XC_sb_up_arrow);
338
case PASTEBUFFER_MODE:
339
SetOutputXCursor(XC_hand1);
341
/* do an update on the crosshair range */
342
SetCrosshairRangeToBuffer();
346
SetOutputXCursor(XC_xterm);
350
SetOutputXCursor(XC_ul_angle);
354
SetOutputXCursor(XC_iron_cross);
358
SetOutputXCursor(XC_pirate);
362
SetOutputXCursor(XC_exchange);
367
SetOutputXCursor(XC_crosshair);
370
case INSERTPOINT_MODE:
371
SetOutputXCursor(XC_dotbox);
374
UpdateModeSelection();
377
/* force a crosshair grid update because the valid range
380
MoveCrosshairRelative(0, 0);
381
RestoreCrosshair(True);
384
void SetRouteStyle(char *name)
389
for (i = 0; i < NUM_STYLES; i++)
390
if (name && strcmp(name, PCB->RouteStyle[i].Name) == 0)
393
sprintf(num,"%d", i+1);
394
XtCallActionProc(Output.Output, "RouteStyle", NULL, &arg, 1);
383
static Boolean recursing = False;
384
/* protect the cursor while changing the mode
385
* perform some additional stuff depending on the new mode
386
* reset 'state' of attached objects
391
HideCrosshair (True);
393
Crosshair.AttachedObject.Type = NO_TYPE;
394
Crosshair.AttachedObject.State = STATE_FIRST;
395
Crosshair.AttachedPolygon.PointN = 0;
398
if (Mode == ARC_MODE || Mode == RECTANGLE_MODE ||
399
Mode == VIA_MODE || Mode == POLYGON_MODE ||
400
Mode == TEXT_MODE || Mode == INSERTPOINT_MODE ||
401
Mode == THERMAL_MODE)
403
Message ("That mode is NOT allowed when drawing " "ratlines!\n");
407
if (Settings.Mode == LINE_MODE && Mode == ARC_MODE &&
408
Crosshair.AttachedLine.State != STATE_FIRST)
410
Crosshair.AttachedLine.State = STATE_FIRST;
411
Crosshair.AttachedBox.State = STATE_SECOND;
412
Crosshair.AttachedBox.Point1.X = Crosshair.AttachedBox.Point2.X =
413
Crosshair.AttachedLine.Point1.X;
414
Crosshair.AttachedBox.Point1.Y = Crosshair.AttachedBox.Point2.Y =
415
Crosshair.AttachedLine.Point1.Y;
416
AdjustAttachedObjects ();
418
else if (Settings.Mode == ARC_MODE && Mode == LINE_MODE &&
419
Crosshair.AttachedBox.State != STATE_FIRST)
421
Crosshair.AttachedBox.State = STATE_FIRST;
422
Crosshair.AttachedLine.State = STATE_SECOND;
423
Crosshair.AttachedLine.Point1.X = Crosshair.AttachedLine.Point2.X =
424
Crosshair.AttachedBox.Point1.X;
425
Crosshair.AttachedLine.Point1.Y = Crosshair.AttachedLine.Point2.Y =
426
Crosshair.AttachedBox.Point1.Y;
427
Settings.Mode = Mode;
428
AdjustAttachedObjects ();
432
if (Settings.Mode == ARC_MODE || Settings.Mode == LINE_MODE)
433
SetLocalRef(0, 0, False);
434
Crosshair.AttachedBox.State = STATE_FIRST;
435
Crosshair.AttachedLine.State = STATE_FIRST;
436
if (Mode == LINE_MODE && TEST_FLAG (AUTODRCFLAG, PCB))
438
SaveUndoSerialNumber ();
439
ResetFoundPinsViasAndPads (True);
440
RestoreUndoSerialNumber ();
441
ResetFoundLinesAndPolygons (True);
442
IncrementUndoSerialNumber();
446
Settings.Mode = Mode;
448
if (Mode == PASTEBUFFER_MODE)
449
/* do an update on the crosshair range */
450
SetCrosshairRangeToBuffer ();
452
SetCrosshairRange (0, 0, PCB->MaxWidth, PCB->MaxHeight);
454
UpdateModeSelection ();
457
/* force a crosshair grid update because the valid range
460
MoveCrosshairRelative (0, 0);
461
RestoreCrosshair (True);
465
SetRouteStyle (char *name)
471
if (name && NSTRCMP (name, style->Name) == 0)
474
sprintf (num, "%d", n + 1);
475
CallActionProc (Output.Output, "RouteStyle", NULL, &arg, 1);
483
SetLocalRef (LocationType X, LocationType Y, Boolean Showing)
486
static int count = 0;
490
HideCrosshair (True);
495
Marked.status = True;
497
RestoreCrosshair (False);
501
HideCrosshair (False);
504
RestoreCrosshair (False);