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 (Coord Grid
, bool align
)
74 if (Grid
>= 1 && Grid
<= MAX_GRID
)
78 PCB
->GridOffsetX
= Crosshair
.X
% Grid
;
79 PCB
->GridOffsetY
= Crosshair
.Y
% Grid
;
82 if (Settings
.DrawGrid
)
87 /* ---------------------------------------------------------------------------
88 * sets a new line thickness
91 SetLineSize (Coord Size
)
93 if (Size
>= MIN_LINESIZE
&& Size
<= MAX_LINESIZE
)
95 Settings
.LineThickness
= Size
;
96 if (TEST_FLAG (AUTODRCFLAG
, PCB
))
97 FitCrosshairIntoGrid (Crosshair
.X
, Crosshair
.Y
);
101 /* ---------------------------------------------------------------------------
102 * sets a new via thickness
105 SetViaSize (Coord Size
, bool Force
)
107 if (Force
|| (Size
<= MAX_PINORVIASIZE
&&
108 Size
>= MIN_PINORVIASIZE
&&
109 Size
>= Settings
.ViaDrillingHole
+ MIN_PINORVIACOPPER
))
111 Settings
.ViaThickness
= Size
;
115 /* ---------------------------------------------------------------------------
116 * sets a new via drilling hole
119 SetViaDrillingHole (Coord Size
, bool Force
)
121 if (Force
|| (Size
<= MAX_PINORVIASIZE
&&
122 Size
>= MIN_PINORVIAHOLE
&&
123 Size
<= Settings
.ViaThickness
- MIN_PINORVIACOPPER
))
125 Settings
.ViaDrillingHole
= Size
;
130 pcb_use_route_style (RouteStyleType
* rst
)
132 Settings
.LineThickness
= rst
->Thick
;
133 Settings
.ViaThickness
= rst
->Diameter
;
134 Settings
.ViaDrillingHole
= rst
->Hole
;
135 Settings
.Keepaway
= rst
->Keepaway
;
138 /* ---------------------------------------------------------------------------
139 * sets a keepaway width
142 SetKeepawayWidth (Coord Width
)
144 if (Width
<= MAX_LINESIZE
)
146 Settings
.Keepaway
= Width
;
150 /* ---------------------------------------------------------------------------
151 * sets a text scaling
154 SetTextScale (int Scale
)
156 if (Scale
<= MAX_TEXTSCALE
&& Scale
>= MIN_TEXTSCALE
)
158 Settings
.TextScale
= Scale
;
162 /* ---------------------------------------------------------------------------
163 * sets or resets changed flag and redraws status
166 SetChangedFlag (bool New
)
168 if (PCB
->Changed
!= New
)
175 /* ---------------------------------------------------------------------------
176 * sets the crosshair range to the current buffer extents
179 SetCrosshairRangeToBuffer (void)
181 if (Settings
.Mode
== PASTEBUFFER_MODE
)
183 SetBufferBoundingBox (PASTEBUFFER
);
184 SetCrosshairRange (PASTEBUFFER
->X
- PASTEBUFFER
->BoundingBox
.X1
,
185 PASTEBUFFER
->Y
- PASTEBUFFER
->BoundingBox
.Y1
,
187 (PASTEBUFFER
->BoundingBox
.X2
- PASTEBUFFER
->X
),
189 (PASTEBUFFER
->BoundingBox
.Y2
- PASTEBUFFER
->Y
));
193 /* ---------------------------------------------------------------------------
194 * sets a new buffer number
197 SetBufferNumber (int Number
)
199 if (Number
>= 0 && Number
< MAX_BUFFER
)
201 Settings
.BufferNumber
= Number
;
203 /* do an update on the crosshair range */
204 SetCrosshairRangeToBuffer ();
208 /* ---------------------------------------------------------------------------
214 mode_stack
[mode_position
] = Settings
.Mode
;
215 if (mode_position
< MAX_MODESTACK_DEPTH
- 1)
222 if (mode_position
== 0)
224 Message ("hace: underflow of restore mode\n");
227 SetMode (mode_stack
[--mode_position
]);
231 /* ---------------------------------------------------------------------------
232 * set a new mode and update X cursor
237 static bool recursing
= false;
238 /* protect the cursor while changing the mode
239 * perform some additional stuff depending on the new mode
240 * reset 'state' of attached objects
245 notify_crosshair_change (false);
247 Crosshair
.AttachedObject
.Type
= NO_TYPE
;
248 Crosshair
.AttachedObject
.State
= STATE_FIRST
;
249 Crosshair
.AttachedPolygon
.PointN
= 0;
252 if (Mode
== ARC_MODE
|| Mode
== RECTANGLE_MODE
||
253 Mode
== VIA_MODE
|| Mode
== POLYGON_MODE
||
254 Mode
== POLYGONHOLE_MODE
||
255 Mode
== TEXT_MODE
|| Mode
== INSERTPOINT_MODE
||
256 Mode
== THERMAL_MODE
)
258 Message (_("That mode is NOT allowed when drawing ratlines!\n"));
262 if (Settings
.Mode
== LINE_MODE
&& Mode
== ARC_MODE
&&
263 Crosshair
.AttachedLine
.State
!= STATE_FIRST
)
265 Crosshair
.AttachedLine
.State
= STATE_FIRST
;
266 Crosshair
.AttachedBox
.State
= STATE_SECOND
;
267 Crosshair
.AttachedBox
.Point1
.X
= Crosshair
.AttachedBox
.Point2
.X
=
268 Crosshair
.AttachedLine
.Point1
.X
;
269 Crosshair
.AttachedBox
.Point1
.Y
= Crosshair
.AttachedBox
.Point2
.Y
=
270 Crosshair
.AttachedLine
.Point1
.Y
;
271 AdjustAttachedObjects ();
273 else if (Settings
.Mode
== ARC_MODE
&& Mode
== LINE_MODE
&&
274 Crosshair
.AttachedBox
.State
!= STATE_FIRST
)
276 Crosshair
.AttachedBox
.State
= STATE_FIRST
;
277 Crosshair
.AttachedLine
.State
= STATE_SECOND
;
278 Crosshair
.AttachedLine
.Point1
.X
= Crosshair
.AttachedLine
.Point2
.X
=
279 Crosshair
.AttachedBox
.Point1
.X
;
280 Crosshair
.AttachedLine
.Point1
.Y
= Crosshair
.AttachedLine
.Point2
.Y
=
281 Crosshair
.AttachedBox
.Point1
.Y
;
282 Settings
.Mode
= Mode
;
283 AdjustAttachedObjects ();
287 if (Settings
.Mode
== ARC_MODE
|| Settings
.Mode
== LINE_MODE
)
288 SetLocalRef (0, 0, false);
289 Crosshair
.AttachedBox
.State
= STATE_FIRST
;
290 Crosshair
.AttachedLine
.State
= STATE_FIRST
;
291 if (Mode
== LINE_MODE
&& TEST_FLAG (AUTODRCFLAG
, PCB
))
293 if (ResetConnections (true))
295 IncrementUndoSerialNumber ();
301 Settings
.Mode
= Mode
;
303 if (Mode
== PASTEBUFFER_MODE
)
304 /* do an update on the crosshair range */
305 SetCrosshairRangeToBuffer ();
307 SetCrosshairRange (0, 0, PCB
->MaxWidth
, PCB
->MaxHeight
);
311 /* force a crosshair grid update because the valid range
314 MoveCrosshairRelative (0, 0);
315 notify_crosshair_change (true);
319 SetRouteStyle (char *name
)
325 if (name
&& NSTRCMP (name
, style
->Name
) == 0)
327 sprintf (num
, "%d", n
+ 1);
328 hid_actionl ("RouteStyle", num
, NULL
);
336 SetLocalRef (Coord X
, Coord Y
, bool Showing
)
339 static int count
= 0;
343 notify_mark_change (false);
348 Marked
.status
= true;
350 notify_mark_change (true);
354 notify_mark_change (false);
357 notify_mark_change (true);