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 (double Grid
, bool 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
, bool 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
, bool 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
)
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 (bool 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 bool 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 notify_crosshair_change (false);
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
== POLYGONHOLE_MODE
||
257 Mode
== TEXT_MODE
|| Mode
== INSERTPOINT_MODE
||
258 Mode
== THERMAL_MODE
)
260 Message (_("That mode is NOT allowed when drawing ratlines!\n"));
264 if (Settings
.Mode
== LINE_MODE
&& Mode
== ARC_MODE
&&
265 Crosshair
.AttachedLine
.State
!= STATE_FIRST
)
267 Crosshair
.AttachedLine
.State
= STATE_FIRST
;
268 Crosshair
.AttachedBox
.State
= STATE_SECOND
;
269 Crosshair
.AttachedBox
.Point1
.X
= Crosshair
.AttachedBox
.Point2
.X
=
270 Crosshair
.AttachedLine
.Point1
.X
;
271 Crosshair
.AttachedBox
.Point1
.Y
= Crosshair
.AttachedBox
.Point2
.Y
=
272 Crosshair
.AttachedLine
.Point1
.Y
;
273 AdjustAttachedObjects ();
275 else if (Settings
.Mode
== ARC_MODE
&& Mode
== LINE_MODE
&&
276 Crosshair
.AttachedBox
.State
!= STATE_FIRST
)
278 Crosshair
.AttachedBox
.State
= STATE_FIRST
;
279 Crosshair
.AttachedLine
.State
= STATE_SECOND
;
280 Crosshair
.AttachedLine
.Point1
.X
= Crosshair
.AttachedLine
.Point2
.X
=
281 Crosshair
.AttachedBox
.Point1
.X
;
282 Crosshair
.AttachedLine
.Point1
.Y
= Crosshair
.AttachedLine
.Point2
.Y
=
283 Crosshair
.AttachedBox
.Point1
.Y
;
284 Settings
.Mode
= Mode
;
285 AdjustAttachedObjects ();
289 if (Settings
.Mode
== ARC_MODE
|| Settings
.Mode
== LINE_MODE
)
290 SetLocalRef (0, 0, false);
291 Crosshair
.AttachedBox
.State
= STATE_FIRST
;
292 Crosshair
.AttachedLine
.State
= STATE_FIRST
;
293 if (Mode
== LINE_MODE
&& TEST_FLAG (AUTODRCFLAG
, PCB
))
295 if (ResetConnections (true))
297 IncrementUndoSerialNumber ();
303 Settings
.Mode
= Mode
;
305 if (Mode
== PASTEBUFFER_MODE
)
306 /* do an update on the crosshair range */
307 SetCrosshairRangeToBuffer ();
309 SetCrosshairRange (0, 0, PCB
->MaxWidth
, PCB
->MaxHeight
);
313 /* force a crosshair grid update because the valid range
316 MoveCrosshairRelative (0, 0);
317 notify_crosshair_change (true);
321 SetRouteStyle (char *name
)
327 if (name
&& NSTRCMP (name
, style
->Name
) == 0)
329 sprintf (num
, "%d", n
+ 1);
330 hid_actionl ("RouteStyle", num
, NULL
);
338 SetLocalRef (LocationType X
, LocationType Y
, bool Showing
)
341 static int count
= 0;
345 notify_mark_change (false);
350 Marked
.status
= true;
352 notify_mark_change (true);
356 notify_mark_change (false);
359 notify_mark_change (true);