42
47
#include "polygon.h"
44
49
#include "remove.h"
45
51
#include "search.h"
46
52
#include "select.h"
56
#ifdef HAVE_LIBDMALLOC
60
RCSID("$Id: remove.c,v 1.13 2004/08/30 02:52:04 danmc Exp $");
50
63
/* ---------------------------------------------------------------------------
51
64
* some local prototypes
53
static void *DestroyVia(PinTypePtr);
54
static void *DestroyRat(RatTypePtr);
55
static void *DestroyLine(LayerTypePtr, LineTypePtr);
56
static void *DestroyArc(LayerTypePtr, ArcTypePtr);
57
static void *DestroyText(LayerTypePtr, TextTypePtr);
58
static void *DestroyPolygon(LayerTypePtr, PolygonTypePtr);
59
static void *DestroyElement(ElementTypePtr);
60
static void *RemoveVia(PinTypePtr);
61
static void *RemoveRat(RatTypePtr);
62
static void *DestroyPolygonPoint(LayerTypePtr, PolygonTypePtr,
64
static void *RemovePolygonPoint(LayerTypePtr, PolygonTypePtr,
66
static void *RemoveLinePoint(LayerTypePtr, LineTypePtr,
66
static void *DestroyVia (PinTypePtr);
67
static void *DestroyRat (RatTypePtr);
68
static void *DestroyLine (LayerTypePtr, LineTypePtr);
69
static void *DestroyArc (LayerTypePtr, ArcTypePtr);
70
static void *DestroyText (LayerTypePtr, TextTypePtr);
71
static void *DestroyPolygon (LayerTypePtr, PolygonTypePtr);
72
static void *DestroyElement (ElementTypePtr);
73
static void *RemoveVia (PinTypePtr);
74
static void *RemoveRat (RatTypePtr);
75
static void *DestroyPolygonPoint (LayerTypePtr, PolygonTypePtr, PointTypePtr);
76
static void *RemovePolygonPoint (LayerTypePtr, PolygonTypePtr, PointTypePtr);
77
static void *RemoveLinePoint (LayerTypePtr, LineTypePtr, PointTypePtr);
69
79
/* ---------------------------------------------------------------------------
72
static ObjectFunctionType RemoveFunctions = {
85
static ObjectFunctionType DestroyFunctions = {
98
static DataTypePtr DestroyTarget;
99
static Boolean Bulk = False;
82
static ObjectFunctionType RemoveFunctions = {
96
static ObjectFunctionType DestroyFunctions = {
110
static DataTypePtr DestroyTarget;
111
static Boolean Bulk = False;
101
113
/* ---------------------------------------------------------------------------
104
void RemovePCB(PCBTypePtr Ptr)
117
RemovePCB (PCBTypePtr Ptr)
119
ClearUndoList (True);
111
124
/* ---------------------------------------------------------------------------
114
static void *DestroyVia(PinTypePtr Via)
128
DestroyVia (PinTypePtr Via)
116
*Via = DestroyTarget->Via[--DestroyTarget->ViaN];
117
memset(&DestroyTarget->Via[DestroyTarget->ViaN], 0, sizeof(PinType));
130
r_delete_entry (DestroyTarget->via_tree, (BoxTypePtr) Via);
132
*Via = DestroyTarget->Via[--DestroyTarget->ViaN];
133
r_substitute (DestroyTarget->via_tree, (BoxTypePtr)
134
(BoxType *) & DestroyTarget->Via[DestroyTarget->ViaN],
136
memset (&DestroyTarget->Via[DestroyTarget->ViaN], 0, sizeof (PinType));
122
140
/* ---------------------------------------------------------------------------
123
141
* destroys a line from a layer
125
static void *DestroyLine(LayerTypePtr Layer, LineTypePtr Line)
144
DestroyLine (LayerTypePtr Layer, LineTypePtr Line)
127
*Line = Layer->Line[--Layer->LineN];
128
memset(&Layer->Line[Layer->LineN], 0, sizeof(LineType));
146
r_delete_entry (Layer->line_tree, (BoxTypePtr) Line);
147
MyFree (&Line->Number);
148
*Line = Layer->Line[--Layer->LineN];
149
/* tricky - line pointers are moved around */
150
r_substitute (Layer->line_tree, (BoxType *) & Layer->Line[Layer->LineN],
152
memset (&Layer->Line[Layer->LineN], 0, sizeof (LineType));
132
156
/* ---------------------------------------------------------------------------
133
157
* destroys an arc from a layer
135
static void *DestroyArc(LayerTypePtr Layer, ArcTypePtr Arc)
160
DestroyArc (LayerTypePtr Layer, ArcTypePtr Arc)
137
*Arc = Layer->Arc[--Layer->ArcN];
138
memset(&Layer->Arc[Layer->ArcN], 0, sizeof(ArcType));
162
r_delete_entry (Layer->arc_tree, (BoxTypePtr) Arc);
163
*Arc = Layer->Arc[--Layer->ArcN];
164
r_substitute (Layer->arc_tree, (BoxType *) & Layer->Arc[Layer->ArcN],
166
memset (&Layer->Arc[Layer->ArcN], 0, sizeof (ArcType));
142
170
/* ---------------------------------------------------------------------------
143
171
* destroys a rectangle from a layer
145
static void *DestroyPolygon(LayerTypePtr Layer, PolygonTypePtr Polygon)
174
DestroyPolygon (LayerTypePtr Layer, PolygonTypePtr Polygon)
147
FreePolygonMemory(Polygon);
148
*Polygon = Layer->Polygon[--Layer->PolygonN];
149
memset(&Layer->Polygon[Layer->PolygonN], 0, sizeof(PolygonType));
176
FreePolygonMemory (Polygon);
177
*Polygon = Layer->Polygon[--Layer->PolygonN];
178
memset (&Layer->Polygon[Layer->PolygonN], 0, sizeof (PolygonType));
153
182
/* ---------------------------------------------------------------------------
154
183
* removes a polygon-point from a polygon and destroys the data
156
static void *DestroyPolygonPoint(LayerTypePtr Layer,
157
PolygonTypePtr Polygon, PointTypePtr Point)
186
DestroyPolygonPoint (LayerTypePtr Layer,
187
PolygonTypePtr Polygon, PointTypePtr Point)
159
return(RemovePolygonPoint(Layer, Polygon, Point));
191
for (ptr = Point + 1; ptr != &Polygon->Points[Polygon->PointN]; ptr++)
197
SetPolygonBoundingBox (Polygon);
198
UpdatePIPFlags (NULL, NULL, Layer, True);
162
202
/* ---------------------------------------------------------------------------
163
203
* destroys a text from a layer
165
static void *DestroyText(LayerTypePtr Layer, TextTypePtr Text)
206
DestroyText (LayerTypePtr Layer, TextTypePtr Text)
167
SaveFree(Text->TextString);
168
*Text = Layer->Text[--Layer->TextN];
169
memset(&Layer->Text[Layer->TextN], 0, sizeof(TextType));
208
MyFree (&Text->TextString);
209
r_delete_entry (Layer->text_tree, (BoxTypePtr) Text);
210
*Text = Layer->Text[--Layer->TextN];
211
r_substitute (Layer->text_tree, (BoxType *) & Layer->Text[Layer->TextN],
213
memset (&Layer->Text[Layer->TextN], 0, sizeof (TextType));
173
217
/* ---------------------------------------------------------------------------
174
218
* destroys a element
176
static void *DestroyElement(ElementTypePtr Element)
221
DestroyElement (ElementTypePtr Element)
178
FreeElementMemory(Element);
179
*Element = DestroyTarget->Element[--DestroyTarget->ElementN];
180
memset(&DestroyTarget->Element[DestroyTarget->ElementN], 0, sizeof(ElementType));
223
if (DestroyTarget->element_tree)
224
r_delete_entry (DestroyTarget->element_tree, (BoxType *) Element);
225
if (DestroyTarget->pin_tree)
229
r_delete_entry (DestroyTarget->pin_tree, (BoxType *) pin);
233
if (DestroyTarget->pad_tree)
237
r_delete_entry (DestroyTarget->pad_tree, (BoxType *) pad);
241
ELEMENTTEXT_LOOP (Element);
243
if (DestroyTarget->name_tree[n])
244
r_delete_entry (DestroyTarget->name_tree[n], (BoxType *) text);
247
FreeElementMemory (Element);
248
*Element = DestroyTarget->Element[--DestroyTarget->ElementN];
249
/* deal with changed element pointer */
250
r_substitute (DestroyTarget->element_tree,
251
(BoxType *) & DestroyTarget->Element[DestroyTarget->ElementN],
252
(BoxType *) Element);
255
pin->Element = Element;
260
pad->Element = Element;
263
ELEMENTTEXT_LOOP (Element);
265
r_substitute (DestroyTarget->name_tree[n],
266
(BoxType *) & DestroyTarget->Element[DestroyTarget->
269
text->Element = Element;
272
memset (&DestroyTarget->Element[DestroyTarget->ElementN], 0,
273
sizeof (ElementType));
184
277
/* ---------------------------------------------------------------------------
187
static void *DestroyRat(RatTypePtr Rat)
281
DestroyRat (RatTypePtr Rat)
189
*Rat = DestroyTarget->Rat[--DestroyTarget->RatN];
190
memset(&DestroyTarget->Rat[DestroyTarget->RatN], 0, sizeof(RatType));
283
if (DestroyTarget->rat_tree)
284
r_delete_entry (DestroyTarget->rat_tree, &Rat->BoundingBox);
285
*Rat = DestroyTarget->Rat[--DestroyTarget->RatN];
286
r_substitute (DestroyTarget->rat_tree,
287
&DestroyTarget->Rat[DestroyTarget->RatN].BoundingBox,
289
memset (&DestroyTarget->Rat[DestroyTarget->RatN], 0, sizeof (RatType));
195
294
/* ---------------------------------------------------------------------------
198
static void *RemoveVia(PinTypePtr Via)
298
RemoveVia (PinTypePtr Via)
200
/* erase from screen and memory */
207
MoveObjectToRemoveUndoList(VIA_TYPE, Via, Via, Via);
300
/* erase from screen and memory */
307
MoveObjectToRemoveUndoList (VIA_TYPE, Via, Via, Via);
211
311
/* ---------------------------------------------------------------------------
214
static void *RemoveRat(RatTypePtr Rat)
315
RemoveRat (RatTypePtr Rat)
216
/* erase from screen and memory */
223
MoveObjectToRemoveUndoList(RATLINE_TYPE, Rat, Rat, Rat);
317
/* erase from screen and memory */
324
MoveObjectToRemoveUndoList (RATLINE_TYPE, Rat, Rat, Rat);
227
328
/* ---------------------------------------------------------------------------
228
329
* removes a line point
230
static void *RemoveLinePoint(LayerTypePtr Layer, LineTypePtr Line, PointTypePtr Point)
332
RemoveLinePoint (LayerTypePtr Layer, LineTypePtr Line, PointTypePtr Point)
234
if (&Line->Point1 == Point)
235
oldPoint = Line->Point2;
237
oldPoint = Line->Point1;
241
if ((line->Point1.X == Point->X) && (line->Point1.Y == Point->Y))
243
SaveUndoSerialNumber();
244
MoveObject(LINEPOINT_TYPE, Layer, line, &line->Point1,
245
oldPoint.X - line->Point1.X, oldPoint.Y - line->Point1.Y);
246
RestoreUndoSerialNumber();
249
if ((line->Point2.X == Point->X) && (line->Point2.Y == Point->Y))
251
SaveUndoSerialNumber();
252
MoveObject(LINEPOINT_TYPE, Layer, line, &line->Point2,
253
oldPoint.X - line->Point2.X, oldPoint.Y - line->Point2.Y);
254
RestoreUndoSerialNumber();
258
return(RemoveLine(Layer, Line));
336
if (&Line->Point1 == Point)
337
oldPoint = Line->Point2;
339
oldPoint = Line->Point1;
344
if ((line->Point1.X == Point->X) && (line->Point1.Y == Point->Y))
346
MoveObject (LINEPOINT_TYPE, Layer, line, &line->Point1,
347
oldPoint.X - line->Point1.X, oldPoint.Y - line->Point1.Y);
350
if ((line->Point2.X == Point->X) && (line->Point2.Y == Point->Y))
352
MoveObject (LINEPOINT_TYPE, Layer, line, &line->Point2,
353
oldPoint.X - line->Point2.X, oldPoint.Y - line->Point2.Y);
358
return (RemoveLine (Layer, Line));
261
361
/* ---------------------------------------------------------------------------
262
362
* removes a line from a layer
264
void *RemoveLine(LayerTypePtr Layer, LineTypePtr Line)
365
RemoveLine (LayerTypePtr Layer, LineTypePtr Line)
266
/* erase from screen */
273
MoveObjectToRemoveUndoList(LINE_TYPE, Layer, Line, Line);
367
/* erase from screen */
374
MoveObjectToRemoveUndoList (LINE_TYPE, Layer, Line, Line);
277
378
/* ---------------------------------------------------------------------------
278
379
* removes an arc from a layer
280
void *RemoveArc(LayerTypePtr Layer, ArcTypePtr Arc)
382
RemoveArc (LayerTypePtr Layer, ArcTypePtr Arc)
282
/* erase from screen */
289
MoveObjectToRemoveUndoList(ARC_TYPE, Layer, Arc, Arc);
384
/* erase from screen */
391
MoveObjectToRemoveUndoList (ARC_TYPE, Layer, Arc, Arc);
293
395
/* ---------------------------------------------------------------------------
294
396
* removes a text from a layer
296
void *RemoveText(LayerTypePtr Layer, TextTypePtr Text)
399
RemoveText (LayerTypePtr Layer, TextTypePtr Text)
298
/* erase from screen */
305
MoveObjectToRemoveUndoList(TEXT_TYPE, Layer, Text, Text);
401
/* erase from screen */
408
MoveObjectToRemoveUndoList (TEXT_TYPE, Layer, Text, Text);
309
412
/* ---------------------------------------------------------------------------
310
413
* removes a polygon from a layer
312
void *RemovePolygon(LayerTypePtr Layer, PolygonTypePtr Polygon)
416
RemovePolygon (LayerTypePtr Layer, PolygonTypePtr Polygon)
314
/* erase from screen */
317
ErasePolygon(Polygon);
321
MoveObjectToRemoveUndoList(POLYGON_TYPE, Layer, Polygon, Polygon);
322
UpdatePIPFlags(NULL, NULL, Layer, NULL, True);
418
/* erase from screen */
421
ErasePolygon (Polygon);
425
MoveObjectToRemoveUndoList (POLYGON_TYPE, Layer, Polygon, Polygon);
426
UpdatePIPFlags (NULL, NULL, Layer, True);
326
430
/* ---------------------------------------------------------------------------
327
431
* removes a polygon-point from a polygon
329
static void *RemovePolygonPoint(LayerTypePtr Layer,
330
PolygonTypePtr Polygon, PointTypePtr Point)
434
RemovePolygonPoint (LayerTypePtr Layer,
435
PolygonTypePtr Polygon, PointTypePtr Point)
335
/* insert the polygon-point into the undo list */
336
POLYGONPOINT_LOOP(Polygon,
342
AddObjectToRemovePointUndoList(POLYGONPOINT_TYPE, Layer, Polygon, index);
345
ErasePolygon(Polygon);
347
/* remove point from list, keep point order */
348
for (ptr = Point+1; ptr != &Polygon->Points[Polygon->PointN]; ptr++)
354
SetPolygonBoundingBox(Polygon);
355
RemoveExcessPolygonPoints(Layer, Polygon);
357
/* redraw polygon if necessary */
360
DrawPolygon(Layer, Polygon, 0);
440
/* insert the polygon-point into the undo list */
441
POLYGONPOINT_LOOP (Polygon);
450
AddObjectToRemovePointUndoList (POLYGONPOINT_TYPE, Layer, Polygon, index);
453
ErasePolygon (Polygon);
455
/* remove point from list, keep point order */
456
for (ptr = Point + 1; ptr != &Polygon->Points[Polygon->PointN]; ptr++)
462
SetPolygonBoundingBox (Polygon);
463
RemoveExcessPolygonPoints (Layer, Polygon);
464
UpdatePIPFlags (NULL, NULL, Layer, True);
465
/* redraw polygon if necessary */
468
DrawPolygon (Layer, Polygon, 0);
367
475
/* ---------------------------------------------------------------------------
368
476
* removes an element
370
void *RemoveElement(ElementTypePtr Element)
479
RemoveElement (ElementTypePtr Element)
372
/* erase from screen */
373
if ((PCB->ElementOn || PCB->PinOn) &&
374
(FRONT(Element) || PCB->InvisibleObjectsOn))
376
EraseElement(Element);
380
MoveObjectToRemoveUndoList(ELEMENT_TYPE, Element, Element, Element);
481
/* erase from screen */
482
if ((PCB->ElementOn || PCB->PinOn) &&
483
(FRONT (Element) || PCB->InvisibleObjectsOn))
485
EraseElement (Element);
489
MoveObjectToRemoveUndoList (ELEMENT_TYPE, Element, Element, Element);
384
493
/* ----------------------------------------------------------------------
385
494
* removes all selected and visible objects
386
495
* returns True if any objects have been removed
388
Boolean RemoveSelected(void)
498
RemoveSelected (void)
391
if (SelectedOperation(&RemoveFunctions, False))
393
IncrementUndoSerialNumber();
501
if (SelectedOperation (&RemoveFunctions, False, ALL_TYPES))
503
IncrementUndoSerialNumber ();
402
512
/* ---------------------------------------------------------------------------
403
513
* remove object as referred by pointers and type,
404
514
* allocated memory is passed to the 'remove undo' list
406
void *RemoveObject(int Type, void *Ptr1, void *Ptr2, void *Ptr3)
517
RemoveObject (int Type, void *Ptr1, void *Ptr2, void *Ptr3)
408
void *ptr = ObjectOperation(&RemoveFunctions, Type, Ptr1, Ptr2, Ptr3);
410
IncrementUndoSerialNumber();
519
void *ptr = ObjectOperation (&RemoveFunctions, Type, Ptr1, Ptr2, Ptr3);
414
523
/* ---------------------------------------------------------------------------
415
524
* DeleteRats - deletes rat lines only
416
525
* can delete all rat lines, or only selected one
419
Boolean DeleteRats(Boolean selected)
421
Boolean changed = False;
425
if ((!selected) || TEST_FLAG(SELECTEDFLAG, line))
435
IncrementUndoSerialNumber();
529
DeleteRats (Boolean selected)
531
Boolean changed = False;
534
RAT_LOOP (PCB->Data);
536
if ((!selected) || TEST_FLAG (SELECTEDFLAG, line))
547
IncrementUndoSerialNumber ();
440
552
/* ---------------------------------------------------------------------------
441
553
* remove object as referred by pointers and type
442
554
* allocated memory is destroyed assumed to already be erased
444
void *DestroyObject(DataTypePtr Target, int Type, void *Ptr1, void *Ptr2,
557
DestroyObject (DataTypePtr Target, int Type, void *Ptr1, void *Ptr2,
447
DestroyTarget = Target;
448
return(ObjectOperation(&DestroyFunctions, Type, Ptr1, Ptr2, Ptr3));
560
DestroyTarget = Target;
561
return (ObjectOperation (&DestroyFunctions, Type, Ptr1, Ptr2, Ptr3));