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 (C) 2024 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
84// Rotate and/or mirror a SCH_PIN according to aOrientMirror.
85// aOrientMirror is the orientation/mirror of the parent symbol.
86// The modified pin orientation is the actual pin orientation/mirror
87// when the parent symbol is drawn.
88void RotateAndMirrorPin( SCH_PIN& aPin, int aOrientMirror )
89{
91
93 {
94 if( i.flag == aOrientMirror )
95 {
96 o = i;
97 break;
98 }
99 }
100
101 for( int i = 0; i < o.n_rots; i++ )
102 aPin.RotatePin( VECTOR2I( 0, 0 ), true );
103
104 if( o.mirror_x )
105 aPin.MirrorVerticallyPin( 0 );
106
107 if( o.mirror_y )
108 aPin.MirrorHorizontallyPin( 0 );
109}
110
111SPIN_STYLE GetPinSpinStyle( const SCH_PIN& aPin, const SCH_SYMBOL& aSymbol )
112{
114
116 ret = SPIN_STYLE::LEFT;
117 else if( aPin.GetOrientation() == PIN_ORIENTATION::PIN_LEFT )
118 ret = SPIN_STYLE::RIGHT;
119 else if( aPin.GetOrientation() == PIN_ORIENTATION::PIN_UP )
120 ret = SPIN_STYLE::BOTTOM;
121 else if( aPin.GetOrientation() == PIN_ORIENTATION::PIN_DOWN )
122 ret = SPIN_STYLE::UP;
123
124 switch( static_cast<SYMBOL_ORIENTATION_T>( aSymbol.GetOrientation()
125 & ( ~( SYM_MIRROR_X | SYM_MIRROR_Y ) ) ) )
126 {
128 case SYM_ORIENT_90:
129 if( ret == SPIN_STYLE::UP )
130 ret = SPIN_STYLE::LEFT;
131 else if( ret == SPIN_STYLE::BOTTOM )
132 ret = SPIN_STYLE::RIGHT;
133 else if( ret == SPIN_STYLE::LEFT )
134 ret = SPIN_STYLE::BOTTOM;
135 else if( ret == SPIN_STYLE::RIGHT )
136 ret = SPIN_STYLE::UP;
137
138 if( aSymbol.GetOrientation() & SYM_MIRROR_X )
139 {
140 if( ret == SPIN_STYLE::UP )
141 ret = SPIN_STYLE::BOTTOM;
142 else if( ret == SPIN_STYLE::BOTTOM )
143 ret = SPIN_STYLE::UP;
144 }
145
146 if( aSymbol.GetOrientation() & SYM_MIRROR_Y )
147 {
148 if( ret == SPIN_STYLE::LEFT )
149 ret = SPIN_STYLE::RIGHT;
150 else if( ret == SPIN_STYLE::RIGHT )
151 ret = SPIN_STYLE::LEFT;
152 }
153 break;
155 case SYM_ORIENT_270:
156 if( ret == SPIN_STYLE::UP )
157 ret = SPIN_STYLE::RIGHT;
158 else if( ret == SPIN_STYLE::BOTTOM )
159 ret = SPIN_STYLE::LEFT;
160 else if( ret == SPIN_STYLE::LEFT )
161 ret = SPIN_STYLE::UP;
162 else if( ret == SPIN_STYLE::RIGHT )
163 ret = SPIN_STYLE::BOTTOM;
164
165 if( aSymbol.GetOrientation() & SYM_MIRROR_X )
166 {
167 if( ret == SPIN_STYLE::UP )
168 ret = SPIN_STYLE::BOTTOM;
169 else if( ret == SPIN_STYLE::BOTTOM )
170 ret = SPIN_STYLE::UP;
171 }
172
173 if( aSymbol.GetOrientation() & SYM_MIRROR_Y )
174 {
175 if( ret == SPIN_STYLE::LEFT )
176 ret = SPIN_STYLE::RIGHT;
177 else if( ret == SPIN_STYLE::RIGHT )
178 ret = SPIN_STYLE::LEFT;
179 }
180 break;
181 case SYM_ORIENT_180:
182 if( ret == SPIN_STYLE::UP )
183 ret = SPIN_STYLE::BOTTOM;
184 else if( ret == SPIN_STYLE::BOTTOM )
185 ret = SPIN_STYLE::UP;
186 else if( ret == SPIN_STYLE::LEFT )
187 ret = SPIN_STYLE::RIGHT;
188 else if( ret == SPIN_STYLE::RIGHT )
189 ret = SPIN_STYLE::LEFT;
190
191 if( aSymbol.GetOrientation() & SYM_MIRROR_X )
192 {
193 if( ret == SPIN_STYLE::UP )
194 ret = SPIN_STYLE::BOTTOM;
195 else if( ret == SPIN_STYLE::BOTTOM )
196 ret = SPIN_STYLE::UP;
197 }
198
199 if( aSymbol.GetOrientation() & SYM_MIRROR_Y )
200 {
201 if( ret == SPIN_STYLE::LEFT )
202 ret = SPIN_STYLE::RIGHT;
203 else if( ret == SPIN_STYLE::RIGHT )
204 ret = SPIN_STYLE::LEFT;
205 }
206 break;
207 case SYM_ORIENT_0:
208 case SYM_NORMAL:
209 default:
210 if( aSymbol.GetOrientation() & SYM_MIRROR_X )
211 {
212 if( ret == SPIN_STYLE::UP )
213 ret = SPIN_STYLE::BOTTOM;
214 else if( ret == SPIN_STYLE::BOTTOM )
215 ret = SPIN_STYLE::UP;
216 }
217
218 if( aSymbol.GetOrientation() & SYM_MIRROR_Y )
219 {
220 if( ret == SPIN_STYLE::LEFT )
221 ret = SPIN_STYLE::RIGHT;
222 else if( ret == SPIN_STYLE::RIGHT )
223 ret = SPIN_STYLE::LEFT;
224 }
225 break;
226 }
227
228 return ret;
229}
Define a library symbol object.
Definition: lib_symbol.h:78
LIB_ITEMS_CONTAINER & GetDrawItems()
Return a reference to the draw item list.
Definition: lib_symbol.h:499
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:166
void MirrorVerticallyPin(int aCenter)
Definition: sch_pin.cpp:1410
PIN_ORIENTATION GetOrientation() const
Definition: sch_pin.cpp:246
void RotatePin(const VECTOR2I &aCenter, bool aRotateCCW=true)
Definition: sch_pin.cpp:1430
void MirrorHorizontallyPin(int aCenter)
these transforms have always effects
Definition: sch_pin.cpp:1390
Schematic symbol object.
Definition: sch_symbol.h:104
int GetOrientation() const
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.
SYMBOL_ORIENTATION_T
enum used in RotationMiroir()
Definition: sch_symbol.h:76
@ SYM_ORIENT_270
Definition: sch_symbol.h:83
@ SYM_ROTATE_CLOCKWISE
Definition: sch_symbol.h:78
@ SYM_ROTATE_COUNTERCLOCKWISE
Definition: sch_symbol.h:79
@ SYM_MIRROR_Y
Definition: sch_symbol.h:85
@ SYM_ORIENT_180
Definition: sch_symbol.h:82
@ SYM_MIRROR_X
Definition: sch_symbol.h:84
@ SYM_NORMAL
Definition: sch_symbol.h:77
@ SYM_ORIENT_90
Definition: sch_symbol.h:81
@ SYM_ORIENT_0
Definition: sch_symbol.h:80
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.