4 * PCB, interactive printed circuit board design
5 * Copyright (C) 1994,1995,1996 Thomas Nau
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 * Contact addresses for paper mail and Email:
22 * Thomas Nau, Schlehenweg 15, 88471 Baustetten, Germany
23 * Thomas.Nau@rz.uni-ulm.de
28 /* routines to update widgets and global settings
29 * (except output window and dialogs)
48 #include "crosshair.h"
57 #include "pcb-printf.h"
59 #ifdef HAVE_LIBDMALLOC
63 static int mode_position
= 0;
64 static int mode_stack
[MAX_MODESTACK_DEPTH
];
66 /* ---------------------------------------------------------------------------
67 * sets cursor grid with respect to grid offset values
70 SetGrid (Coord Grid
, bool align
)
73 if (Grid
>= 1 && Grid
<= MAX_GRID
)
77 PCB
->GridOffsetX
= Crosshair
.X
% Grid
;
78 PCB
->GridOffsetY
= Crosshair
.Y
% Grid
;
81 grid_string
= pcb_g_strdup_printf ("%mr", Grid
);
83 AttributePut (PCB
, "PCB::grid::size", grid_string
);
85 if (Settings
.DrawGrid
)
90 /* ---------------------------------------------------------------------------
91 * sets a new line thickness
94 SetLineSize (Coord Size
)
96 if (Size
>= MIN_LINESIZE
&& Size
<= MAX_LINESIZE
)
98 Settings
.LineThickness
= Size
;
99 if (TEST_FLAG (AUTODRCFLAG
, PCB
))
100 FitCrosshairIntoGrid (Crosshair
.X
, Crosshair
.Y
);
104 /* ---------------------------------------------------------------------------
105 * sets a new via thickness
108 SetViaSize (Coord Size
, bool Force
)
110 if (Force
|| (Size
<= MAX_PINORVIASIZE
&&
111 Size
>= MIN_PINORVIASIZE
&&
112 Size
>= Settings
.ViaDrillingHole
+ MIN_PINORVIACOPPER
))
114 Settings
.ViaThickness
= Size
;
118 /* ---------------------------------------------------------------------------
119 * sets a new via drilling hole
122 SetViaDrillingHole (Coord Size
, bool Force
)
124 if (Force
|| (Size
<= MAX_PINORVIASIZE
&&
125 Size
>= MIN_PINORVIAHOLE
&&
126 Size
<= Settings
.ViaThickness
- MIN_PINORVIACOPPER
))
128 Settings
.ViaDrillingHole
= Size
;
133 pcb_use_route_style (RouteStyleType
* rst
)
135 Settings
.LineThickness
= rst
->Thick
;
136 Settings
.ViaThickness
= rst
->Diameter
;
137 Settings
.ViaDrillingHole
= rst
->Hole
;
138 Settings
.Keepaway
= rst
->Keepaway
;
141 /* ---------------------------------------------------------------------------
142 * sets a keepaway width
145 SetKeepawayWidth (Coord Width
)
147 if (Width
<= MAX_LINESIZE
)
149 Settings
.Keepaway
= Width
;
153 /* ---------------------------------------------------------------------------
154 * sets a text scaling
157 SetTextScale (int Scale
)
159 if (Scale
<= MAX_TEXTSCALE
&& Scale
>= MIN_TEXTSCALE
)
161 Settings
.TextScale
= Scale
;
165 /* ---------------------------------------------------------------------------
166 * sets or resets changed flag and redraws status
169 SetChangedFlag (bool New
)
171 if (PCB
->Changed
!= New
)
178 /* ---------------------------------------------------------------------------
179 * sets the crosshair range to the current buffer extents
182 SetCrosshairRangeToBuffer (void)
184 if (Settings
.Mode
== PASTEBUFFER_MODE
)
186 SetBufferBoundingBox (PASTEBUFFER
);
187 SetCrosshairRange (PASTEBUFFER
->X
- PASTEBUFFER
->BoundingBox
.X1
,
188 PASTEBUFFER
->Y
- PASTEBUFFER
->BoundingBox
.Y1
,
190 (PASTEBUFFER
->BoundingBox
.X2
- PASTEBUFFER
->X
),
192 (PASTEBUFFER
->BoundingBox
.Y2
- PASTEBUFFER
->Y
));
196 /* ---------------------------------------------------------------------------
197 * sets a new buffer number
200 SetBufferNumber (int Number
)
202 if (Number
>= 0 && Number
< MAX_BUFFER
)
204 Settings
.BufferNumber
= Number
;
206 /* do an update on the crosshair range */
207 SetCrosshairRangeToBuffer ();
211 /* ---------------------------------------------------------------------------
217 mode_stack
[mode_position
] = Settings
.Mode
;
218 if (mode_position
< MAX_MODESTACK_DEPTH
- 1)
225 if (mode_position
== 0)
227 Message ("hace: underflow of restore mode\n");
230 SetMode (mode_stack
[--mode_position
]);
234 /* ---------------------------------------------------------------------------
235 * set a new mode and update X cursor
240 static bool recursing
= false;
241 /* protect the cursor while changing the mode
242 * perform some additional stuff depending on the new mode
243 * reset 'state' of attached objects
248 notify_crosshair_change (false);
250 Crosshair
.AttachedObject
.Type
= NO_TYPE
;
251 Crosshair
.AttachedObject
.State
= STATE_FIRST
;
252 Crosshair
.AttachedPolygon
.PointN
= 0;
255 if (Mode
== ARC_MODE
|| Mode
== RECTANGLE_MODE
||
256 Mode
== VIA_MODE
|| Mode
== POLYGON_MODE
||
257 Mode
== POLYGONHOLE_MODE
||
258 Mode
== TEXT_MODE
|| Mode
== INSERTPOINT_MODE
||
259 Mode
== THERMAL_MODE
)
261 Message (_("That mode is NOT allowed when drawing ratlines!\n"));
265 if (Settings
.Mode
== LINE_MODE
&& Mode
== ARC_MODE
&&
266 Crosshair
.AttachedLine
.State
!= STATE_FIRST
)
268 Crosshair
.AttachedLine
.State
= STATE_FIRST
;
269 Crosshair
.AttachedBox
.State
= STATE_SECOND
;
270 Crosshair
.AttachedBox
.Point1
.X
= Crosshair
.AttachedBox
.Point2
.X
=
271 Crosshair
.AttachedLine
.Point1
.X
;
272 Crosshair
.AttachedBox
.Point1
.Y
= Crosshair
.AttachedBox
.Point2
.Y
=
273 Crosshair
.AttachedLine
.Point1
.Y
;
274 AdjustAttachedObjects ();
276 else if (Settings
.Mode
== ARC_MODE
&& Mode
== LINE_MODE
&&
277 Crosshair
.AttachedBox
.State
!= STATE_FIRST
)
279 Crosshair
.AttachedBox
.State
= STATE_FIRST
;
280 Crosshair
.AttachedLine
.State
= STATE_SECOND
;
281 Crosshair
.AttachedLine
.Point1
.X
= Crosshair
.AttachedLine
.Point2
.X
=
282 Crosshair
.AttachedBox
.Point1
.X
;
283 Crosshair
.AttachedLine
.Point1
.Y
= Crosshair
.AttachedLine
.Point2
.Y
=
284 Crosshair
.AttachedBox
.Point1
.Y
;
285 Settings
.Mode
= Mode
;
286 AdjustAttachedObjects ();
288 /* Cancel rubberband move */
289 else if (Settings
.Mode
== MOVE_MODE
)
290 MoveObjectAndRubberband (Crosshair
.AttachedObject
.Type
,
291 Crosshair
.AttachedObject
.Ptr1
,
292 Crosshair
.AttachedObject
.Ptr2
,
293 Crosshair
.AttachedObject
.Ptr3
,
297 if (Settings
.Mode
== ARC_MODE
|| Settings
.Mode
== LINE_MODE
)
298 SetLocalRef (0, 0, false);
299 Crosshair
.AttachedBox
.State
= STATE_FIRST
;
300 Crosshair
.AttachedLine
.State
= STATE_FIRST
;
301 if (Mode
== LINE_MODE
&& TEST_FLAG (AUTODRCFLAG
, PCB
))
303 if (ClearFlagOnAllObjects (true, CONNECTEDFLAG
| FOUNDFLAG
))
305 IncrementUndoSerialNumber ();
311 Settings
.Mode
= Mode
;
313 if (Mode
== PASTEBUFFER_MODE
)
314 /* do an update on the crosshair range */
315 SetCrosshairRangeToBuffer ();
317 SetCrosshairRange (0, 0, PCB
->MaxWidth
, PCB
->MaxHeight
);
321 /* force a crosshair grid update because the valid range
324 FitCrosshairIntoGrid (Crosshair
.X
, Crosshair
.Y
);
325 notify_crosshair_change (true);
329 SetRouteStyle (char *name
)
335 if (name
&& NSTRCMP (name
, style
->Name
) == 0)
337 sprintf (num
, "%d", n
+ 1);
338 hid_actionl ("RouteStyle", num
, NULL
);
346 SetLocalRef (Coord X
, Coord Y
, bool Showing
)
349 static int count
= 0;
353 notify_mark_change (false);
358 Marked
.status
= true;
360 notify_mark_change (true);
364 notify_mark_change (false);
367 notify_mark_change (true);