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
27 /* functions used to copy pins, elements ...
28 * it's necessary to copy data by calling create... since the base pointer
29 * may change cause of dynamic memory allocation
54 #ifdef HAVE_LIBDMALLOC
58 /* ---------------------------------------------------------------------------
59 * some local prototypes
61 static void *CopyVia (PinType
*);
62 static void *CopyLine (LayerType
*, LineType
*);
63 static void *CopyArc (LayerType
*, ArcType
*);
64 static void *CopyText (LayerType
*, TextType
*);
65 static void *CopyPolygon (LayerType
*, PolygonType
*);
66 static void *CopyElement (ElementType
*);
68 /* ---------------------------------------------------------------------------
69 * some local identifiers
71 static Coord DeltaX
, DeltaY
; /* movement vector */
72 static ObjectFunctionType CopyFunctions
= {
87 /* ---------------------------------------------------------------------------
88 * copies data from one polygon to another
92 CopyPolygonLowLevel (PolygonType
*Dest
, PolygonType
*Src
)
97 for (n
= 0; n
< Src
->PointN
; n
++)
99 if (hole
< Src
->HoleIndexN
&& n
== Src
->HoleIndex
[hole
])
101 CreateNewHoleInPolygon (Dest
);
104 CreateNewPointInPolygon (Dest
, Src
->Points
[n
].X
, Src
->Points
[n
].Y
);
106 SetPolygonBoundingBox (Dest
);
107 Dest
->Flags
= Src
->Flags
;
108 CLEAR_FLAG (FOUNDFLAG
, Dest
);
112 /* ---------------------------------------------------------------------------
113 * copies data from one element to another and creates the destination
117 CopyElementLowLevel (DataType
*Data
, ElementType
*Dest
,
118 ElementType
*Src
, bool uniqueName
, Coord dx
,
119 Coord dy
, int mask_flags
)
122 /* release old memory if necessary */
124 FreeElementMemory (Dest
);
126 /* both coordinates and flags are the same */
127 Dest
= CreateNewElement (Data
, Dest
, &PCB
->Font
,
128 MaskFlags (Src
->Flags
, mask_flags
),
129 DESCRIPTION_NAME (Src
), NAMEONPCB_NAME (Src
),
130 VALUE_NAME (Src
), DESCRIPTION_TEXT (Src
).X
+ dx
,
131 DESCRIPTION_TEXT (Src
).Y
+ dy
,
132 DESCRIPTION_TEXT (Src
).Direction
,
133 DESCRIPTION_TEXT (Src
).Scale
,
134 MaskFlags (DESCRIPTION_TEXT (Src
).Flags
,
135 mask_flags
), uniqueName
);
141 ELEMENTLINE_LOOP (Src
);
143 CreateNewLineInElement (Dest
, line
->Point1
.X
+ dx
,
144 line
->Point1
.Y
+ dy
, line
->Point2
.X
+ dx
,
145 line
->Point2
.Y
+ dy
, line
->Thickness
);
150 CreateNewPin (Dest
, pin
->X
+ dx
, pin
->Y
+ dy
, pin
->Thickness
,
151 pin
->Clearance
, pin
->Mask
, pin
->DrillingHole
,
152 pin
->Name
, pin
->Number
, MaskFlags (pin
->Flags
, mask_flags
));
157 CreateNewPad (Dest
, pad
->Point1
.X
+ dx
, pad
->Point1
.Y
+ dy
,
158 pad
->Point2
.X
+ dx
, pad
->Point2
.Y
+ dy
, pad
->Thickness
,
159 pad
->Clearance
, pad
->Mask
, pad
->Name
, pad
->Number
,
160 MaskFlags (pad
->Flags
, mask_flags
));
165 CreateNewArcInElement (Dest
, arc
->X
+ dx
, arc
->Y
+ dy
, arc
->Width
,
166 arc
->Height
, arc
->StartAngle
, arc
->Delta
,
171 for (i
=0; i
<Src
->Attributes
.Number
; i
++)
172 CreateNewAttribute (& Dest
->Attributes
,
173 Src
->Attributes
.List
[i
].name
,
174 Src
->Attributes
.List
[i
].value
);
176 Dest
->MarkX
= Src
->MarkX
+ dx
;
177 Dest
->MarkY
= Src
->MarkY
+ dy
;
179 SetElementBoundingBox (Data
, Dest
, &PCB
->Font
);
183 /* ---------------------------------------------------------------------------
187 CopyVia (PinType
*Via
)
191 via
= CreateNewVia (PCB
->Data
, Via
->X
+ DeltaX
, Via
->Y
+ DeltaY
,
192 Via
->Thickness
, Via
->Clearance
, Via
->Mask
,
193 Via
->DrillingHole
, Via
->Name
,
194 MaskFlags (Via
->Flags
, FOUNDFLAG
));
198 AddObjectToCreateUndoList (VIA_TYPE
, via
, via
, via
);
202 /* ---------------------------------------------------------------------------
206 CopyLine (LayerType
*Layer
, LineType
*Line
)
210 line
= CreateDrawnLineOnLayer (Layer
, Line
->Point1
.X
+ DeltaX
,
211 Line
->Point1
.Y
+ DeltaY
,
212 Line
->Point2
.X
+ DeltaX
,
213 Line
->Point2
.Y
+ DeltaY
, Line
->Thickness
,
215 MaskFlags (Line
->Flags
, FOUNDFLAG
));
219 line
->Number
= strdup (Line
->Number
);
220 DrawLine (Layer
, line
);
221 AddObjectToCreateUndoList (LINE_TYPE
, Layer
, line
, line
);
225 /* ---------------------------------------------------------------------------
229 CopyArc (LayerType
*Layer
, ArcType
*Arc
)
233 arc
= CreateNewArcOnLayer (Layer
, Arc
->X
+ DeltaX
,
234 Arc
->Y
+ DeltaY
, Arc
->Width
, Arc
->Height
, Arc
->StartAngle
,
235 Arc
->Delta
, Arc
->Thickness
, Arc
->Clearance
,
236 MaskFlags (Arc
->Flags
, FOUNDFLAG
));
239 DrawArc (Layer
, arc
);
240 AddObjectToCreateUndoList (ARC_TYPE
, Layer
, arc
, arc
);
244 /* ---------------------------------------------------------------------------
248 CopyText (LayerType
*Layer
, TextType
*Text
)
252 text
= CreateNewText (Layer
, &PCB
->Font
, Text
->X
+ DeltaX
,
253 Text
->Y
+ DeltaY
, Text
->Direction
,
254 Text
->Scale
, Text
->TextString
,
255 MaskFlags (Text
->Flags
, FOUNDFLAG
));
256 DrawText (Layer
, text
);
257 AddObjectToCreateUndoList (TEXT_TYPE
, Layer
, text
, text
);
261 /* ---------------------------------------------------------------------------
265 CopyPolygon (LayerType
*Layer
, PolygonType
*Polygon
)
267 PolygonType
*polygon
;
269 polygon
= CreateNewPolygon (Layer
, NoFlags ());
270 CopyPolygonLowLevel (polygon
, Polygon
);
271 MovePolygonLowLevel (polygon
, DeltaX
, DeltaY
);
272 if (!Layer
->polygon_tree
)
273 Layer
->polygon_tree
= r_create_tree (NULL
, 0, 0);
274 r_insert_entry (Layer
->polygon_tree
, (BoxType
*) polygon
, 0);
275 InitClip (PCB
->Data
, Layer
, polygon
);
276 DrawPolygon (Layer
, polygon
);
277 AddObjectToCreateUndoList (POLYGON_TYPE
, Layer
, polygon
, polygon
);
281 /* ---------------------------------------------------------------------------
282 * copies an element onto the PCB. Then does a draw.
285 CopyElement (ElementType
*Element
)
289 printf("Entered CopyElement, trying to copy element %s\n",
290 Element
->Name
[1].TextString
);
293 ElementType
*element
= CopyElementLowLevel (PCB
->Data
,
295 TEST_FLAG (UNIQUENAMEFLAG
,
299 /* this call clears the polygons */
300 AddObjectToCreateUndoList (ELEMENT_TYPE
, element
, element
, element
);
301 if (PCB
->ElementOn
&& (FRONT (element
) || PCB
->InvisibleObjectsOn
))
303 DrawElementName (element
);
304 DrawElementPackage (element
);
308 DrawElementPinsAndPads (element
);
311 printf(" ... Leaving CopyElement.\n");
316 /* ---------------------------------------------------------------------------
317 * pastes the contents of the buffer to the layout. Only visible objects
318 * are handled by the routine.
321 CopyPastebufferToLayout (Coord X
, Coord Y
)
324 bool changed
= false;
327 printf("Entering CopyPastebufferToLayout.....\n");
330 /* set movement vector */
331 DeltaX
= X
- PASTEBUFFER
->X
, DeltaY
= Y
- PASTEBUFFER
->Y
;
333 /* paste all layers */
334 for (i
= 0; i
< max_copper_layer
+ 2; i
++)
336 LayerType
*sourcelayer
= &PASTEBUFFER
->Data
->Layer
[i
];
337 LayerType
*destlayer
= LAYER_PTR (i
);
342 (sourcelayer
->LineN
!= 0) ||
343 (sourcelayer
->ArcN
!= 0) ||
344 (sourcelayer
->PolygonN
!= 0) || (sourcelayer
->TextN
!= 0);
345 LINE_LOOP (sourcelayer
);
347 CopyLine (destlayer
, line
);
350 ARC_LOOP (sourcelayer
);
352 CopyArc (destlayer
, arc
);
355 TEXT_LOOP (sourcelayer
);
357 CopyText (destlayer
, text
);
360 POLYGON_LOOP (sourcelayer
);
362 CopyPolygon (destlayer
, polygon
);
369 if (PCB
->PinOn
&& PCB
->ElementOn
)
371 ELEMENT_LOOP (PASTEBUFFER
->Data
);
374 printf("In CopyPastebufferToLayout, pasting element %s\n",
375 element
->Name
[1].TextString
);
377 if (FRONT (element
) || PCB
->InvisibleObjectsOn
)
379 CopyElement (element
);
386 /* finally the vias */
389 changed
|= (PASTEBUFFER
->Data
->ViaN
!= 0);
390 VIA_LOOP (PASTEBUFFER
->Data
);
400 IncrementUndoSerialNumber ();
404 printf(" .... Leaving CopyPastebufferToLayout.\n");
410 /* ---------------------------------------------------------------------------
411 * copies the object identified by its data pointers and the type
412 * the new objects is moved by DX,DY
413 * I assume that the appropriate layer ... is switched on
416 CopyObject (int Type
, void *Ptr1
, void *Ptr2
, void *Ptr3
,
421 /* setup movement vector */
425 /* the subroutines add the objects to the undo-list */
426 ptr
= ObjectOperation (&CopyFunctions
, Type
, Ptr1
, Ptr2
, Ptr3
);
427 IncrementUndoSerialNumber ();