1 /*!
2  * \file src/mirror.c
3  *
4  * \brief Functions used to change the mirror flag of an object.
5  *
6  * An undo operation is not implemented because it's easy to
7  * recover an object.
8  *
9  * <hr>
10  *
11  * <h1><b>Copyright.</b></h1>\n
12  *
13  * PCB, interactive printed circuit board design
14  *
15  * Copyright (C) 1994,1995,1996 Thomas Nau
16  *
17  * This program is free software; you can redistribute it and/or modify
18  * it under the terms of the GNU General Public License as published by
19  * the Free Software Foundation; either version 2 of the License, or
20  * (at your option) any later version.
21  *
22  * This program is distributed in the hope that it will be useful,
23  * but WITHOUT ANY WARRANTY; without even the implied warranty of
24  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
25  * GNU General Public License for more details.
26  *
27  * You should have received a copy of the GNU General Public License along
28  * with this program; if not, write to the Free Software Foundation, Inc.,
29  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
30  *
31  * Contact addresses for paper mail and Email:
32  *
33  * Thomas Nau, Schlehenweg 15, 88471 Baustetten, Germany
34  *
35  * Thomas.Nau@rz.uni-ulm.de
36  */
37 
38 #ifdef HAVE_CONFIG_H
39 #include "config.h"
40 #endif
41 
42 #include <stdlib.h>
43 
44 #include "global.h"
45 
46 #include "data.h"
47 #include "draw.h"
48 #include "mirror.h"
49 #include "misc.h"
50 #include "polygon.h"
51 #include "search.h"
52 #include "select.h"
53 #include "set.h"
54 
55 #ifdef HAVE_LIBDMALLOC
56 #include <dmalloc.h>
57 #endif
58 
59 /*!
60  * \brief Mirrors the coordinates of an element.
61  *
62  * An additional offset is passed.
63  */
64 void
MirrorElementCoordinates(DataType * Data,ElementType * Element,Coord yoff)65 MirrorElementCoordinates (DataType *Data, ElementType *Element,
66 			  Coord yoff)
67 {
68   r_delete_element (Data, Element);
69   ELEMENTLINE_LOOP (Element);
70   {
71     line->Point1.X = SWAP_X (line->Point1.X);
72     line->Point1.Y = SWAP_Y (line->Point1.Y) + yoff;
73     line->Point2.X = SWAP_X (line->Point2.X);
74     line->Point2.Y = SWAP_Y (line->Point2.Y) + yoff;
75   }
76   END_LOOP;
77   PIN_LOOP (Element);
78   {
79     RestoreToPolygon (Data, PIN_TYPE, Element, pin);
80     pin->X = SWAP_X (pin->X);
81     pin->Y = SWAP_Y (pin->Y) + yoff;
82   }
83   END_LOOP;
84   PAD_LOOP (Element);
85   {
86     Coord X1,X2,Y1,Y2;
87     RestoreToPolygon (Data, PAD_TYPE, Element, pad);
88     X1 = SWAP_X (pad->Point1.X);
89     Y1 = SWAP_Y (pad->Point1.Y) + yoff;
90     X2 = SWAP_X (pad->Point2.X);
91     Y2 = SWAP_Y (pad->Point2.Y) + yoff;
92     /* copy values */
93     if (X1 > X2 || (X1 == X2 && Y1 > Y2))
94     {
95       pad->Point1.X = X2;
96       pad->Point1.Y = Y2;
97       pad->Point2.X = X1;
98       pad->Point2.Y = Y1;
99     }
100     else
101     {
102       pad->Point1.X = X1;
103       pad->Point1.Y = Y1;
104       pad->Point2.X = X2;
105       pad->Point2.Y = Y2;
106     }
107     TOGGLE_FLAG (ONSOLDERFLAG, pad);
108   }
109   END_LOOP;
110   ARC_LOOP (Element);
111   {
112     arc->X = SWAP_X (arc->X);
113     arc->Y = SWAP_Y (arc->Y) + yoff;
114     arc->StartAngle = SWAP_ANGLE (arc->StartAngle);
115     arc->Delta = SWAP_DELTA (arc->Delta);
116   }
117   END_LOOP;
118   ELEMENTTEXT_LOOP (Element);
119   {
120     text->X = SWAP_X (text->X);
121     text->Y = SWAP_Y (text->Y) + yoff;
122     TOGGLE_FLAG (ONSOLDERFLAG, text);
123   }
124   END_LOOP;
125   Element->MarkX = SWAP_X (Element->MarkX);
126   Element->MarkY = SWAP_Y (Element->MarkY) + yoff;
127 
128   /* now toggle the solder-side flag */
129   TOGGLE_FLAG (ONSOLDERFLAG, Element);
130   /* this inserts all of the rtree data too */
131   SetElementBoundingBox (Data, Element, &PCB->Font);
132   ClearFromPolygon (Data, ELEMENT_TYPE, Element, Element);
133 }
134