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
29 /* functions used to copy pins, elements ...
30 * it's necessary to copy data by calling create... since the base pointer
31 * may change cause of dynamic memory allocation
56 #ifdef HAVE_LIBDMALLOC
62 /* ---------------------------------------------------------------------------
63 * some local prototypes
65 static void *CopyVia (PinTypePtr
);
66 static void *CopyLine (LayerTypePtr
, LineTypePtr
);
67 static void *CopyArc (LayerTypePtr
, ArcTypePtr
);
68 static void *CopyText (LayerTypePtr
, TextTypePtr
);
69 static void *CopyPolygon (LayerTypePtr
, PolygonTypePtr
);
70 static void *CopyElement (ElementTypePtr
);
72 /* ---------------------------------------------------------------------------
73 * some local identifiers
75 static LocationType DeltaX
, DeltaY
; /* movement vector */
76 static ObjectFunctionType CopyFunctions
= {
91 /* ---------------------------------------------------------------------------
92 * copies data from one polygon to another
96 CopyPolygonLowLevel (PolygonTypePtr Dest
, PolygonTypePtr Src
)
101 for (n
= 0; n
< Src
->PointN
; n
++)
103 if (hole
< Src
->HoleIndexN
&& n
== Src
->HoleIndex
[hole
])
105 CreateNewHoleInPolygon (Dest
);
108 CreateNewPointInPolygon (Dest
, Src
->Points
[n
].X
, Src
->Points
[n
].Y
);
110 SetPolygonBoundingBox (Dest
);
111 Dest
->Flags
= Src
->Flags
;
112 CLEAR_FLAG (FOUNDFLAG
, Dest
);
116 /* ---------------------------------------------------------------------------
117 * copies data from one element to another and creates the destination
121 CopyElementLowLevel (DataTypePtr Data
, ElementTypePtr Dest
,
122 ElementTypePtr Src
, bool uniqueName
, LocationType dx
,
126 /* release old memory if necessary */
128 FreeElementMemory (Dest
);
130 /* both coordinates and flags are the same */
131 Dest
= CreateNewElement (Data
, Dest
, &PCB
->Font
,
132 MaskFlags (Src
->Flags
, FOUNDFLAG
),
133 DESCRIPTION_NAME (Src
), NAMEONPCB_NAME (Src
),
134 VALUE_NAME (Src
), DESCRIPTION_TEXT (Src
).X
+ dx
,
135 DESCRIPTION_TEXT (Src
).Y
+ dy
,
136 DESCRIPTION_TEXT (Src
).Direction
,
137 DESCRIPTION_TEXT (Src
).Scale
,
138 MaskFlags (DESCRIPTION_TEXT (Src
).Flags
,
139 FOUNDFLAG
), uniqueName
);
145 ELEMENTLINE_LOOP (Src
);
147 CreateNewLineInElement (Dest
, line
->Point1
.X
+ dx
,
148 line
->Point1
.Y
+ dy
, line
->Point2
.X
+ dx
,
149 line
->Point2
.Y
+ dy
, line
->Thickness
);
154 CreateNewPin (Dest
, pin
->X
+ dx
, pin
->Y
+ dy
, pin
->Thickness
,
155 pin
->Clearance
, pin
->Mask
, pin
->DrillingHole
,
156 pin
->Name
, pin
->Number
, MaskFlags (pin
->Flags
, FOUNDFLAG
));
161 CreateNewPad (Dest
, pad
->Point1
.X
+ dx
, pad
->Point1
.Y
+ dy
,
162 pad
->Point2
.X
+ dx
, pad
->Point2
.Y
+ dy
, pad
->Thickness
,
163 pad
->Clearance
, pad
->Mask
, pad
->Name
, pad
->Number
,
164 MaskFlags (pad
->Flags
, FOUNDFLAG
));
169 CreateNewArcInElement (Dest
, arc
->X
+ dx
, arc
->Y
+ dy
, arc
->Width
,
170 arc
->Height
, arc
->StartAngle
, arc
->Delta
,
175 for (i
=0; i
<Src
->Attributes
.Number
; i
++)
176 CreateNewAttribute (& Dest
->Attributes
,
177 Src
->Attributes
.List
[i
].name
,
178 Src
->Attributes
.List
[i
].value
);
180 Dest
->MarkX
= Src
->MarkX
+ dx
;
181 Dest
->MarkY
= Src
->MarkY
+ dy
;
183 SetElementBoundingBox (Data
, Dest
, &PCB
->Font
);
187 /* ---------------------------------------------------------------------------
191 CopyVia (PinTypePtr Via
)
195 via
= CreateNewVia (PCB
->Data
, Via
->X
+ DeltaX
, Via
->Y
+ DeltaY
,
196 Via
->Thickness
, Via
->Clearance
, Via
->Mask
,
197 Via
->DrillingHole
, Via
->Name
,
198 MaskFlags (Via
->Flags
, FOUNDFLAG
));
202 AddObjectToCreateUndoList (VIA_TYPE
, via
, via
, via
);
206 /* ---------------------------------------------------------------------------
210 CopyLine (LayerTypePtr Layer
, LineTypePtr Line
)
214 line
= CreateDrawnLineOnLayer (Layer
, Line
->Point1
.X
+ DeltaX
,
215 Line
->Point1
.Y
+ DeltaY
,
216 Line
->Point2
.X
+ DeltaX
,
217 Line
->Point2
.Y
+ DeltaY
, Line
->Thickness
,
219 MaskFlags (Line
->Flags
, FOUNDFLAG
));
223 line
->Number
= strdup (Line
->Number
);
224 DrawLine (Layer
, line
, 0);
225 AddObjectToCreateUndoList (LINE_TYPE
, Layer
, line
, line
);
229 /* ---------------------------------------------------------------------------
233 CopyArc (LayerTypePtr Layer
, ArcTypePtr Arc
)
237 arc
= CreateNewArcOnLayer (Layer
, Arc
->X
+ DeltaX
,
238 Arc
->Y
+ DeltaY
, Arc
->Width
, Arc
->Height
, Arc
->StartAngle
,
239 Arc
->Delta
, Arc
->Thickness
, Arc
->Clearance
,
240 MaskFlags (Arc
->Flags
, FOUNDFLAG
));
243 DrawArc (Layer
, arc
, 0);
244 AddObjectToCreateUndoList (ARC_TYPE
, Layer
, arc
, arc
);
248 /* ---------------------------------------------------------------------------
252 CopyText (LayerTypePtr Layer
, TextTypePtr Text
)
256 text
= CreateNewText (Layer
, &PCB
->Font
, Text
->X
+ DeltaX
,
257 Text
->Y
+ DeltaY
, Text
->Direction
,
258 Text
->Scale
, Text
->TextString
,
259 MaskFlags (Text
->Flags
, FOUNDFLAG
));
260 DrawText (Layer
, text
, 0);
261 AddObjectToCreateUndoList (TEXT_TYPE
, Layer
, text
, text
);
265 /* ---------------------------------------------------------------------------
269 CopyPolygon (LayerTypePtr Layer
, PolygonTypePtr Polygon
)
271 PolygonTypePtr polygon
;
273 polygon
= CreateNewPolygon (Layer
, NoFlags ());
274 CopyPolygonLowLevel (polygon
, Polygon
);
275 MovePolygonLowLevel (polygon
, DeltaX
, DeltaY
);
276 if (!Layer
->polygon_tree
)
277 Layer
->polygon_tree
= r_create_tree (NULL
, 0, 0);
278 r_insert_entry (Layer
->polygon_tree
, (BoxTypePtr
) polygon
, 0);
279 InitClip (PCB
->Data
, Layer
, polygon
);
280 DrawPolygon (Layer
, polygon
, 0);
281 AddObjectToCreateUndoList (POLYGON_TYPE
, Layer
, polygon
, polygon
);
285 /* ---------------------------------------------------------------------------
286 * copies an element onto the PCB. Then does a draw.
289 CopyElement (ElementTypePtr Element
)
293 printf("Entered CopyElement, trying to copy element %s\n",
294 Element
->Name
[1].TextString
);
297 bool didDraw
= false;
298 ElementTypePtr element
= CopyElementLowLevel (PCB
->Data
,
300 TEST_FLAG (UNIQUENAMEFLAG
,
304 /* this call clears the polygons */
305 AddObjectToCreateUndoList (ELEMENT_TYPE
, element
, element
, element
);
306 if (PCB
->ElementOn
&& (FRONT (element
) || PCB
->InvisibleObjectsOn
))
308 DrawElementName (element
, 0);
309 DrawElementPackage (element
, 0);
314 DrawElementPinsAndPads (element
, 0);
318 printf(" ... Leaving CopyElement.\n");
323 /* ---------------------------------------------------------------------------
324 * pastes the contents of the buffer to the layout. Only visible objects
325 * are handled by the routine.
328 CopyPastebufferToLayout (LocationType X
, LocationType Y
)
331 bool changed
= false;
334 printf("Entering CopyPastebufferToLayout.....\n");
337 /* set movement vector */
338 DeltaX
= X
- PASTEBUFFER
->X
, DeltaY
= Y
- PASTEBUFFER
->Y
;
340 /* paste all layers */
341 for (i
= 0; i
< max_copper_layer
+ 2; i
++)
343 LayerTypePtr sourcelayer
= &PASTEBUFFER
->Data
->Layer
[i
],
344 destlayer
= LAYER_PTR (i
);
349 (sourcelayer
->LineN
!= 0) ||
350 (sourcelayer
->ArcN
!= 0) ||
351 (sourcelayer
->PolygonN
!= 0) || (sourcelayer
->TextN
!= 0);
352 LINE_LOOP (sourcelayer
);
354 CopyLine (destlayer
, line
);
357 ARC_LOOP (sourcelayer
);
359 CopyArc (destlayer
, arc
);
362 TEXT_LOOP (sourcelayer
);
364 CopyText (destlayer
, text
);
367 POLYGON_LOOP (sourcelayer
);
369 CopyPolygon (destlayer
, polygon
);
376 if (PCB
->PinOn
&& PCB
->ElementOn
)
378 ELEMENT_LOOP (PASTEBUFFER
->Data
);
381 printf("In CopyPastebufferToLayout, pasting element %s\n",
382 element
->Name
[1].TextString
);
384 if (FRONT (element
) || PCB
->InvisibleObjectsOn
)
386 CopyElement (element
);
393 /* finally the vias */
396 changed
|= (PASTEBUFFER
->Data
->ViaN
!= 0);
397 VIA_LOOP (PASTEBUFFER
->Data
);
407 IncrementUndoSerialNumber ();
411 printf(" .... Leaving CopyPastebufferToLayout.\n");
417 /* ---------------------------------------------------------------------------
418 * copies the object identified by its data pointers and the type
419 * the new objects is moved by DX,DY
420 * I assume that the appropriate layer ... is switched on
423 CopyObject (int Type
, void *Ptr1
, void *Ptr2
, void *Ptr3
,
424 LocationType DX
, LocationType DY
)
428 /* setup movement vector */
432 /* the subroutines add the objects to the undo-list */
433 ptr
= ObjectOperation (&CopyFunctions
, Type
, Ptr1
, Ptr2
, Ptr3
);
434 IncrementUndoSerialNumber ();