KiCad PCB EDA Suite
Loading...
Searching...
No Matches
symb_transforms_utils.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Author Jean-Pierre Charras, jp.charras at wanadoo.fr
5 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software: you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation, either version 3 of the License, or (at your
10 * option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
22
23#include <lib_symbol.h>
24#include <sch_symbol.h>
25
27{
28 int flag;
29 int n_rots;
32};
33
34
35// symbols_orientations_list is the list of possible orientation+mirror values
36// like returned by SCH_SYMBOL::GetOrientation()
37// Some transforms are equivalent, like rotation 180 + mirror X = mirror Y
38
40{
41 { SYM_ORIENT_0, 0, 0, 0 },
42 { SYM_ORIENT_90, 1, 0, 0 },
43 { SYM_ORIENT_180, 2, 0, 0 },
44 { SYM_ORIENT_270, 3, 0, 0 },
45 { SYM_MIRROR_X + SYM_ORIENT_0, 0, 1, 0 },
46 { SYM_MIRROR_X + SYM_ORIENT_90, 1, 1, 0 },
47 { SYM_MIRROR_Y, 0, 0, 1 },
48 { SYM_MIRROR_X + SYM_ORIENT_270, 3, 1, 0 },
49 { SYM_MIRROR_Y + SYM_ORIENT_0, 0, 0, 1 },
50 { SYM_MIRROR_Y + SYM_ORIENT_90, 1, 0, 1 },
51 { SYM_MIRROR_Y + SYM_ORIENT_180, 2, 0, 1 },
52 { SYM_MIRROR_Y + SYM_ORIENT_270, 3, 0, 1 }
53};
54
55
56void OrientAndMirrorSymbolItems( LIB_SYMBOL* aSymbol, int aOrientation )
57{
59
61 {
62 if( i.flag == aOrientation )
63 {
64 o = i;
65 break;
66 }
67 }
68
69 for( SCH_ITEM& item : aSymbol->GetDrawItems() )
70 {
71 for( int i = 0; i < o.n_rots; i++ )
72 item.Rotate( VECTOR2I( 0, 0 ), true );
73
74 if( o.mirror_x )
75 item.MirrorVertically( 0 );
76
77 if( o.mirror_y )
78 item.MirrorHorizontally( 0 );
79 }
80}
81
82
83
84void RotateAndMirrorPin( SCH_PIN& aPin, int aOrientMirror )
85{
87
89 {
90 if( i.flag == aOrientMirror )
91 {
92 o = i;
93 break;
94 }
95 }
96
97 for( int i = 0; i < o.n_rots; i++ )
98 aPin.RotatePin( VECTOR2I( 0, 0 ), true );
99
100 if( o.mirror_x )
101 aPin.MirrorVerticallyPin( 0 );
102
103 if( o.mirror_y )
104 aPin.MirrorHorizontallyPin( 0 );
105}
106
107
108SPIN_STYLE GetPinSpinStyle( const SCH_PIN& aPin, const SCH_SYMBOL& aSymbol )
109{
111
113 ret = SPIN_STYLE::LEFT;
114 else if( aPin.GetOrientation() == PIN_ORIENTATION::PIN_LEFT )
115 ret = SPIN_STYLE::RIGHT;
116 else if( aPin.GetOrientation() == PIN_ORIENTATION::PIN_UP )
117 ret = SPIN_STYLE::BOTTOM;
118 else if( aPin.GetOrientation() == PIN_ORIENTATION::PIN_DOWN )
119 ret = SPIN_STYLE::UP;
120
121 switch( static_cast<SYMBOL_ORIENTATION_T>( aSymbol.GetOrientation()
122 & ( ~( SYM_MIRROR_X | SYM_MIRROR_Y ) ) ) )
123 {
125 case SYM_ORIENT_90:
126 if( ret == SPIN_STYLE::UP )
127 ret = SPIN_STYLE::LEFT;
128 else if( ret == SPIN_STYLE::BOTTOM )
129 ret = SPIN_STYLE::RIGHT;
130 else if( ret == SPIN_STYLE::LEFT )
131 ret = SPIN_STYLE::BOTTOM;
132 else if( ret == SPIN_STYLE::RIGHT )
133 ret = SPIN_STYLE::UP;
134
135 if( aSymbol.GetOrientation() & SYM_MIRROR_X )
136 {
137 if( ret == SPIN_STYLE::UP )
138 ret = SPIN_STYLE::BOTTOM;
139 else if( ret == SPIN_STYLE::BOTTOM )
140 ret = SPIN_STYLE::UP;
141 }
142
143 if( aSymbol.GetOrientation() & SYM_MIRROR_Y )
144 {
145 if( ret == SPIN_STYLE::LEFT )
146 ret = SPIN_STYLE::RIGHT;
147 else if( ret == SPIN_STYLE::RIGHT )
148 ret = SPIN_STYLE::LEFT;
149 }
150
151 break;
152
154 case SYM_ORIENT_270:
155 if( ret == SPIN_STYLE::UP )
156 ret = SPIN_STYLE::RIGHT;
157 else if( ret == SPIN_STYLE::BOTTOM )
158 ret = SPIN_STYLE::LEFT;
159 else if( ret == SPIN_STYLE::LEFT )
160 ret = SPIN_STYLE::UP;
161 else if( ret == SPIN_STYLE::RIGHT )
162 ret = SPIN_STYLE::BOTTOM;
163
164 if( aSymbol.GetOrientation() & SYM_MIRROR_X )
165 {
166 if( ret == SPIN_STYLE::UP )
167 ret = SPIN_STYLE::BOTTOM;
168 else if( ret == SPIN_STYLE::BOTTOM )
169 ret = SPIN_STYLE::UP;
170 }
171
172 if( aSymbol.GetOrientation() & SYM_MIRROR_Y )
173 {
174 if( ret == SPIN_STYLE::LEFT )
175 ret = SPIN_STYLE::RIGHT;
176 else if( ret == SPIN_STYLE::RIGHT )
177 ret = SPIN_STYLE::LEFT;
178 }
179
180 break;
181
182 case SYM_ORIENT_180:
183 if( ret == SPIN_STYLE::UP )
184 ret = SPIN_STYLE::BOTTOM;
185 else if( ret == SPIN_STYLE::BOTTOM )
186 ret = SPIN_STYLE::UP;
187 else if( ret == SPIN_STYLE::LEFT )
188 ret = SPIN_STYLE::RIGHT;
189 else if( ret == SPIN_STYLE::RIGHT )
190 ret = SPIN_STYLE::LEFT;
191
192 if( aSymbol.GetOrientation() & SYM_MIRROR_X )
193 {
194 if( ret == SPIN_STYLE::UP )
195 ret = SPIN_STYLE::BOTTOM;
196 else if( ret == SPIN_STYLE::BOTTOM )
197 ret = SPIN_STYLE::UP;
198 }
199
200 if( aSymbol.GetOrientation() & SYM_MIRROR_Y )
201 {
202 if( ret == SPIN_STYLE::LEFT )
203 ret = SPIN_STYLE::RIGHT;
204 else if( ret == SPIN_STYLE::RIGHT )
205 ret = SPIN_STYLE::LEFT;
206 }
207
208 break;
209
210 case SYM_ORIENT_0:
211 case SYM_NORMAL:
212 default:
213 if( aSymbol.GetOrientation() & SYM_MIRROR_X )
214 {
215 if( ret == SPIN_STYLE::UP )
216 ret = SPIN_STYLE::BOTTOM;
217 else if( ret == SPIN_STYLE::BOTTOM )
218 ret = SPIN_STYLE::UP;
219 }
220
221 if( aSymbol.GetOrientation() & SYM_MIRROR_Y )
222 {
223 if( ret == SPIN_STYLE::LEFT )
224 ret = SPIN_STYLE::RIGHT;
225 else if( ret == SPIN_STYLE::RIGHT )
226 ret = SPIN_STYLE::LEFT;
227 }
228
229 break;
230 }
231
232 return ret;
233}
Define a library symbol object.
Definition: lib_symbol.h:84
LIB_ITEMS_CONTAINER & GetDrawItems()
Return a reference to the draw item list.
Definition: lib_symbol.h:531
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:167
void MirrorVerticallyPin(int aCenter)
Definition: sch_pin.cpp:1471
PIN_ORIENTATION GetOrientation() const
Definition: sch_pin.cpp:256
void RotatePin(const VECTOR2I &aCenter, bool aRotateCCW=true)
Definition: sch_pin.cpp:1491
void MirrorHorizontallyPin(int aCenter)
These transforms have always effects.
Definition: sch_pin.cpp:1451
Schematic symbol object.
Definition: sch_symbol.h:77
int GetOrientation() const override
Get the display symbol orientation.
@ PIN_UP
The pin extends upwards from the connection point: Probably on the bottom side of the symbol.
@ PIN_RIGHT
The pin extends rightwards from the connection point.
@ PIN_LEFT
The pin extends leftwards from the connection point: Probably on the right side of the symbol.
@ PIN_DOWN
The pin extends downwards from the connection: Probably on the top side of the symbol.
static ORIENT_MIRROR symbols_orientations_list[]
SPIN_STYLE GetPinSpinStyle(const SCH_PIN &aPin, const SCH_SYMBOL &aSymbol)
Get the spin style for a pin's label, taking into account the pin's orientation, as well as the given...
void OrientAndMirrorSymbolItems(LIB_SYMBOL *aSymbol, int aOrientation)
Rotate and/or mirror graphic objects of LIB_SYMBOL aSymbol according to aOrientMirror.
void RotateAndMirrorPin(SCH_PIN &aPin, int aOrientMirror)
Rotate and/or mirror a SCH_PIN according to aOrientMirror.
SYMBOL_ORIENTATION_T
enum used in RotationMiroir()
Definition: symbol.h:35
@ SYM_ORIENT_270
Definition: symbol.h:42
@ SYM_ROTATE_CLOCKWISE
Definition: symbol.h:37
@ SYM_ROTATE_COUNTERCLOCKWISE
Definition: symbol.h:38
@ SYM_MIRROR_Y
Definition: symbol.h:44
@ SYM_ORIENT_180
Definition: symbol.h:41
@ SYM_MIRROR_X
Definition: symbol.h:43
@ SYM_NORMAL
Definition: symbol.h:36
@ SYM_ORIENT_90
Definition: symbol.h:40
@ SYM_ORIENT_0
Definition: symbol.h:39