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
)
99 POLYGONPOINT_LOOP (Src
);
101 CreateNewPointInPolygon (Dest
, point
->X
, point
->Y
);
104 SetPolygonBoundingBox (Dest
);
105 Dest
->Flags
= Src
->Flags
;
106 CLEAR_FLAG (FOUNDFLAG
, Dest
);
110 /* ---------------------------------------------------------------------------
111 * copies data from one element to another and creates the destination
115 CopyElementLowLevel (DataTypePtr Data
, ElementTypePtr Dest
,
116 ElementTypePtr Src
, bool uniqueName
, LocationType dx
,
120 /* release old memory if necessary */
122 FreeElementMemory (Dest
);
124 /* both coordinates and flags are the same */
125 Dest
= CreateNewElement (Data
, Dest
, &PCB
->Font
,
126 MaskFlags (Src
->Flags
, FOUNDFLAG
),
127 DESCRIPTION_NAME (Src
), NAMEONPCB_NAME (Src
),
128 VALUE_NAME (Src
), DESCRIPTION_TEXT (Src
).X
+ dx
,
129 DESCRIPTION_TEXT (Src
).Y
+ dy
,
130 DESCRIPTION_TEXT (Src
).Direction
,
131 DESCRIPTION_TEXT (Src
).Scale
,
132 MaskFlags (DESCRIPTION_TEXT (Src
).Flags
,
133 FOUNDFLAG
), uniqueName
);
139 ELEMENTLINE_LOOP (Src
);
141 CreateNewLineInElement (Dest
, line
->Point1
.X
+ dx
,
142 line
->Point1
.Y
+ dy
, line
->Point2
.X
+ dx
,
143 line
->Point2
.Y
+ dy
, line
->Thickness
);
148 CreateNewPin (Dest
, pin
->X
+ dx
, pin
->Y
+ dy
, pin
->Thickness
,
149 pin
->Clearance
, pin
->Mask
, pin
->DrillingHole
,
150 pin
->Name
, pin
->Number
, MaskFlags (pin
->Flags
, FOUNDFLAG
));
155 CreateNewPad (Dest
, pad
->Point1
.X
+ dx
, pad
->Point1
.Y
+ dy
,
156 pad
->Point2
.X
+ dx
, pad
->Point2
.Y
+ dy
, pad
->Thickness
,
157 pad
->Clearance
, pad
->Mask
, pad
->Name
, pad
->Number
,
158 MaskFlags (pad
->Flags
, FOUNDFLAG
));
163 CreateNewArcInElement (Dest
, arc
->X
+ dx
, arc
->Y
+ dy
, arc
->Width
,
164 arc
->Height
, arc
->StartAngle
, arc
->Delta
,
169 for (i
=0; i
<Src
->Attributes
.Number
; i
++)
170 CreateNewAttribute (& Dest
->Attributes
,
171 Src
->Attributes
.List
[i
].name
,
172 Src
->Attributes
.List
[i
].value
);
174 Dest
->MarkX
= Src
->MarkX
+ dx
;
175 Dest
->MarkY
= Src
->MarkY
+ dy
;
177 SetElementBoundingBox (Data
, Dest
, &PCB
->Font
);
181 /* ---------------------------------------------------------------------------
185 CopyVia (PinTypePtr Via
)
189 via
= CreateNewVia (PCB
->Data
, Via
->X
+ DeltaX
, Via
->Y
+ DeltaY
,
190 Via
->Thickness
, Via
->Clearance
, Via
->Mask
,
191 Via
->DrillingHole
, Via
->Name
,
192 MaskFlags (Via
->Flags
, FOUNDFLAG
));
196 AddObjectToCreateUndoList (VIA_TYPE
, via
, via
, via
);
200 /* ---------------------------------------------------------------------------
204 CopyLine (LayerTypePtr Layer
, LineTypePtr Line
)
208 line
= CreateDrawnLineOnLayer (Layer
, Line
->Point1
.X
+ DeltaX
,
209 Line
->Point1
.Y
+ DeltaY
,
210 Line
->Point2
.X
+ DeltaX
,
211 Line
->Point2
.Y
+ DeltaY
, Line
->Thickness
,
213 MaskFlags (Line
->Flags
, FOUNDFLAG
));
217 line
->Number
= MyStrdup (Line
->Number
, "CopyLine");
218 DrawLine (Layer
, line
, 0);
219 AddObjectToCreateUndoList (LINE_TYPE
, Layer
, line
, line
);
223 /* ---------------------------------------------------------------------------
227 CopyArc (LayerTypePtr Layer
, ArcTypePtr Arc
)
231 arc
= CreateNewArcOnLayer (Layer
, Arc
->X
+ DeltaX
,
232 Arc
->Y
+ DeltaY
, Arc
->Width
, Arc
->Height
, Arc
->StartAngle
,
233 Arc
->Delta
, Arc
->Thickness
, Arc
->Clearance
,
234 MaskFlags (Arc
->Flags
, FOUNDFLAG
));
237 DrawArc (Layer
, arc
, 0);
238 AddObjectToCreateUndoList (ARC_TYPE
, Layer
, arc
, arc
);
242 /* ---------------------------------------------------------------------------
246 CopyText (LayerTypePtr Layer
, TextTypePtr Text
)
250 text
= CreateNewText (Layer
, &PCB
->Font
, Text
->X
+ DeltaX
,
251 Text
->Y
+ DeltaY
, Text
->Direction
,
252 Text
->Scale
, Text
->TextString
,
253 MaskFlags (Text
->Flags
, FOUNDFLAG
));
254 DrawText (Layer
, text
, 0);
255 AddObjectToCreateUndoList (TEXT_TYPE
, Layer
, text
, text
);
259 /* ---------------------------------------------------------------------------
263 CopyPolygon (LayerTypePtr Layer
, PolygonTypePtr Polygon
)
265 PolygonTypePtr polygon
;
267 polygon
= CreateNewPolygon (Layer
, NoFlags ());
268 CopyPolygonLowLevel (polygon
, Polygon
);
269 MovePolygonLowLevel (polygon
, DeltaX
, DeltaY
);
270 if (!Layer
->polygon_tree
)
271 Layer
->polygon_tree
= r_create_tree (NULL
, 0, 0);
272 r_insert_entry (Layer
->polygon_tree
, (BoxTypePtr
) polygon
, 0);
273 InitClip (PCB
->Data
, Layer
, polygon
);
274 DrawPolygon (Layer
, polygon
, 0);
275 AddObjectToCreateUndoList (POLYGON_TYPE
, Layer
, polygon
, polygon
);
279 /* ---------------------------------------------------------------------------
280 * copies an element onto the PCB. Then does a draw.
283 CopyElement (ElementTypePtr Element
)
287 printf("Entered CopyElement, trying to copy element %s\n",
288 Element
->Name
[1].TextString
);
291 bool didDraw
= false;
292 ElementTypePtr element
= CopyElementLowLevel (PCB
->Data
,
294 TEST_FLAG (UNIQUENAMEFLAG
,
298 /* this call clears the polygons */
299 AddObjectToCreateUndoList (ELEMENT_TYPE
, element
, element
, element
);
300 if (PCB
->ElementOn
&& (FRONT (element
) || PCB
->InvisibleObjectsOn
))
302 DrawElementName (element
, 0);
303 DrawElementPackage (element
, 0);
308 DrawElementPinsAndPads (element
, 0);
312 printf(" ... Leaving CopyElement.\n");
317 /* ---------------------------------------------------------------------------
318 * pastes the contents of the buffer to the layout. Only visible objects
319 * are handled by the routine.
322 CopyPastebufferToLayout (LocationType X
, LocationType Y
)
325 bool changed
= false;
328 printf("Entering CopyPastebufferToLayout.....\n");
331 /* set movement vector */
332 DeltaX
= X
- PASTEBUFFER
->X
, DeltaY
= Y
- PASTEBUFFER
->Y
;
334 /* paste all layers */
335 for (i
= 0; i
< max_layer
+ 2; i
++)
337 LayerTypePtr sourcelayer
= &PASTEBUFFER
->Data
->Layer
[i
],
338 destlayer
= LAYER_PTR (i
);
343 (sourcelayer
->LineN
!= 0) ||
344 (sourcelayer
->ArcN
!= 0) ||
345 (sourcelayer
->PolygonN
!= 0) || (sourcelayer
->TextN
!= 0);
346 LINE_LOOP (sourcelayer
);
348 CopyLine (destlayer
, line
);
351 ARC_LOOP (sourcelayer
);
353 CopyArc (destlayer
, arc
);
356 TEXT_LOOP (sourcelayer
);
358 CopyText (destlayer
, text
);
361 POLYGON_LOOP (sourcelayer
);
363 CopyPolygon (destlayer
, polygon
);
370 if (PCB
->PinOn
&& PCB
->ElementOn
)
372 ELEMENT_LOOP (PASTEBUFFER
->Data
);
375 printf("In CopyPastebufferToLayout, pasting element %s\n",
376 element
->Name
[1].TextString
);
378 if (FRONT (element
) || PCB
->InvisibleObjectsOn
)
380 CopyElement (element
);
387 /* finally the vias */
390 changed
|= (PASTEBUFFER
->Data
->ViaN
!= 0);
391 VIA_LOOP (PASTEBUFFER
->Data
);
401 IncrementUndoSerialNumber ();
405 printf(" .... Leaving CopyPastebufferToLayout.\n");
411 /* ---------------------------------------------------------------------------
412 * copies the object identified by its data pointers and the type
413 * the new objects is moved by DX,DY
414 * I assume that the appropriate layer ... is switched on
417 CopyObject (int Type
, void *Ptr1
, void *Ptr2
, void *Ptr3
,
418 LocationType DX
, LocationType DY
)
422 /* setup movement vector */
426 /* the subroutines add the objects to the undo-list */
427 ptr
= ObjectOperation (&CopyFunctions
, Type
, Ptr1
, Ptr2
, Ptr3
);
428 IncrementUndoSerialNumber ();