6 * PCB, interactive printed circuit board design
7 * Copyright (C) 1994,1995,1996 Thomas Nau
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 * Contact addresses for paper mail and Email:
24 * Thomas Nau, Schlehenweg 15, 88471 Baustetten, Germany
25 * Thomas.Nau@rz.uni-ulm.de
30 /* routines to update widgets and global settings
31 * (except output window and dialogs)
50 #include "crosshair.h"
59 #ifdef HAVE_LIBDMALLOC
65 static int mode_position
= 0;
66 static int mode_stack
[MAX_MODESTACK_DEPTH
];
68 /* ---------------------------------------------------------------------------
69 * sets cursor grid with respect to grid offset values
72 SetGrid (float Grid
, Boolean align
)
74 if (Grid
>= 1 && Grid
<= MAX_GRID
)
79 Crosshair
.X
- (int) (Crosshair
.X
/ Grid
) * Grid
+ 0.5;
81 Crosshair
.Y
- (int) (Crosshair
.Y
/ Grid
) * Grid
+ 0.5;
84 if (Settings
.DrawGrid
)
89 /* ---------------------------------------------------------------------------
90 * sets a new line thickness
93 SetLineSize (BDimension Size
)
95 if (Size
>= MIN_LINESIZE
&& Size
<= MAX_LINESIZE
)
97 Settings
.LineThickness
= Size
;
98 if (TEST_FLAG (AUTODRCFLAG
, PCB
))
99 FitCrosshairIntoGrid (Crosshair
.X
, Crosshair
.Y
);
103 /* ---------------------------------------------------------------------------
104 * sets a new via thickness
107 SetViaSize (BDimension Size
, Boolean Force
)
109 if (Force
|| (Size
<= MAX_PINORVIASIZE
&&
110 Size
>= MIN_PINORVIASIZE
&&
111 Size
>= Settings
.ViaDrillingHole
+ MIN_PINORVIACOPPER
))
113 Settings
.ViaThickness
= Size
;
117 /* ---------------------------------------------------------------------------
118 * sets a new via drilling hole
121 SetViaDrillingHole (BDimension Size
, Boolean Force
)
123 if (Force
|| (Size
<= MAX_PINORVIASIZE
&&
124 Size
>= MIN_PINORVIAHOLE
&&
125 Size
<= Settings
.ViaThickness
- MIN_PINORVIACOPPER
))
127 Settings
.ViaDrillingHole
= Size
;
132 pcb_use_route_style (RouteStyleType
* rst
)
134 Settings
.LineThickness
= rst
->Thick
;
135 Settings
.ViaThickness
= rst
->Diameter
;
136 Settings
.ViaDrillingHole
= rst
->Hole
;
137 Settings
.Keepaway
= rst
->Keepaway
;
140 /* ---------------------------------------------------------------------------
141 * sets a keepaway width
144 SetKeepawayWidth (BDimension Width
)
146 if (Width
<= MAX_LINESIZE
&& Width
>= MIN_LINESIZE
)
148 Settings
.Keepaway
= Width
;
152 /* ---------------------------------------------------------------------------
153 * sets a text scaling
156 SetTextScale (Dimension Scale
)
158 if (Scale
<= MAX_TEXTSCALE
&& Scale
>= MIN_TEXTSCALE
)
160 Settings
.TextScale
= Scale
;
164 /* ---------------------------------------------------------------------------
165 * sets or resets changed flag and redraws status
168 SetChangedFlag (Boolean New
)
170 if (PCB
->Changed
!= New
)
177 /* ---------------------------------------------------------------------------
178 * sets the crosshair range to the current buffer extents
181 SetCrosshairRangeToBuffer (void)
183 if (Settings
.Mode
== PASTEBUFFER_MODE
)
185 SetBufferBoundingBox (PASTEBUFFER
);
186 SetCrosshairRange (PASTEBUFFER
->X
- PASTEBUFFER
->BoundingBox
.X1
,
187 PASTEBUFFER
->Y
- PASTEBUFFER
->BoundingBox
.Y1
,
189 (PASTEBUFFER
->BoundingBox
.X2
- PASTEBUFFER
->X
),
191 (PASTEBUFFER
->BoundingBox
.Y2
- PASTEBUFFER
->Y
));
195 /* ---------------------------------------------------------------------------
196 * sets a new buffer number
199 SetBufferNumber (int Number
)
201 if (Number
>= 0 && Number
< MAX_BUFFER
)
203 Settings
.BufferNumber
= Number
;
205 /* do an update on the crosshair range */
206 SetCrosshairRangeToBuffer ();
210 /* ---------------------------------------------------------------------------
216 mode_stack
[mode_position
] = Settings
.Mode
;
217 if (mode_position
< MAX_MODESTACK_DEPTH
- 1)
224 if (mode_position
== 0)
226 Message ("hace: underflow of restore mode\n");
229 SetMode (mode_stack
[--mode_position
]);
233 /* ---------------------------------------------------------------------------
234 * set a new mode and update X cursor
239 static Boolean recursing
= False
;
240 /* protect the cursor while changing the mode
241 * perform some additional stuff depending on the new mode
242 * reset 'state' of attached objects
247 HideCrosshair (True
);
249 Crosshair
.AttachedObject
.Type
= NO_TYPE
;
250 Crosshair
.AttachedObject
.State
= STATE_FIRST
;
251 Crosshair
.AttachedPolygon
.PointN
= 0;
254 if (Mode
== ARC_MODE
|| Mode
== RECTANGLE_MODE
||
255 Mode
== VIA_MODE
|| Mode
== POLYGON_MODE
||
256 Mode
== TEXT_MODE
|| Mode
== INSERTPOINT_MODE
||
257 Mode
== THERMAL_MODE
)
259 Message (_("That mode is NOT allowed when drawing ratlines!\n"));
263 if (Settings
.Mode
== LINE_MODE
&& Mode
== ARC_MODE
&&
264 Crosshair
.AttachedLine
.State
!= STATE_FIRST
)
266 Crosshair
.AttachedLine
.State
= STATE_FIRST
;
267 Crosshair
.AttachedBox
.State
= STATE_SECOND
;
268 Crosshair
.AttachedBox
.Point1
.X
= Crosshair
.AttachedBox
.Point2
.X
=
269 Crosshair
.AttachedLine
.Point1
.X
;
270 Crosshair
.AttachedBox
.Point1
.Y
= Crosshair
.AttachedBox
.Point2
.Y
=
271 Crosshair
.AttachedLine
.Point1
.Y
;
272 AdjustAttachedObjects ();
274 else if (Settings
.Mode
== ARC_MODE
&& Mode
== LINE_MODE
&&
275 Crosshair
.AttachedBox
.State
!= STATE_FIRST
)
277 Crosshair
.AttachedBox
.State
= STATE_FIRST
;
278 Crosshair
.AttachedLine
.State
= STATE_SECOND
;
279 Crosshair
.AttachedLine
.Point1
.X
= Crosshair
.AttachedLine
.Point2
.X
=
280 Crosshair
.AttachedBox
.Point1
.X
;
281 Crosshair
.AttachedLine
.Point1
.Y
= Crosshair
.AttachedLine
.Point2
.Y
=
282 Crosshair
.AttachedBox
.Point1
.Y
;
283 Settings
.Mode
= Mode
;
284 AdjustAttachedObjects ();
288 if (Settings
.Mode
== ARC_MODE
|| Settings
.Mode
== LINE_MODE
)
289 SetLocalRef (0, 0, False
);
290 Crosshair
.AttachedBox
.State
= STATE_FIRST
;
291 Crosshair
.AttachedLine
.State
= STATE_FIRST
;
292 if (Mode
== LINE_MODE
&& TEST_FLAG (AUTODRCFLAG
, PCB
))
294 SaveUndoSerialNumber ();
295 ResetFoundPinsViasAndPads (True
);
296 RestoreUndoSerialNumber ();
297 ResetFoundLinesAndPolygons (True
);
298 IncrementUndoSerialNumber ();
302 Settings
.Mode
= Mode
;
304 if (Mode
== PASTEBUFFER_MODE
)
305 /* do an update on the crosshair range */
306 SetCrosshairRangeToBuffer ();
308 SetCrosshairRange (0, 0, PCB
->MaxWidth
, PCB
->MaxHeight
);
312 /* force a crosshair grid update because the valid range
315 MoveCrosshairRelative (0, 0);
316 RestoreCrosshair (True
);
320 SetRouteStyle (char *name
)
326 if (name
&& NSTRCMP (name
, style
->Name
) == 0)
328 sprintf (num
, "%d", n
+ 1);
329 hid_actionl ("RouteStyle", num
, NULL
);
337 SetLocalRef (LocationType X
, LocationType Y
, Boolean Showing
)
340 static int count
= 0;
344 HideCrosshair (True
);
349 Marked
.status
= True
;
351 RestoreCrosshair (False
);
355 HideCrosshair (False
);
358 RestoreCrosshair (False
);