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#include "lib_symbol.h"
21#include "sch_symbol.h"
22#include "sch_pin.h"
23
25{
26 int flag;
27 int n_rots;
30};
31
32
33// symbols_orientations_list is the list of possible orientation+mirror values
34// like returned by SCH_SYMBOL::GetOrientation()
35// Some transforms are equivalent, like rotation 180 + mirror X = mirror Y
36
38{
39 { SYM_ORIENT_0, 0, 0, 0 },
40 { SYM_ORIENT_90, 1, 0, 0 },
41 { SYM_ORIENT_180, 2, 0, 0 },
42 { SYM_ORIENT_270, 3, 0, 0 },
43 { SYM_MIRROR_X + SYM_ORIENT_0, 0, 1, 0 },
44 { SYM_MIRROR_X + SYM_ORIENT_90, 1, 1, 0 },
45 { SYM_MIRROR_Y, 0, 0, 1 },
46 { SYM_MIRROR_X + SYM_ORIENT_270, 3, 1, 0 },
47 { SYM_MIRROR_Y + SYM_ORIENT_0, 0, 0, 1 },
48 { SYM_MIRROR_Y + SYM_ORIENT_90, 1, 0, 1 },
49 { SYM_MIRROR_Y + SYM_ORIENT_180, 2, 0, 1 },
50 { SYM_MIRROR_Y + SYM_ORIENT_270, 3, 0, 1 }
51};
52
53
54void OrientAndMirrorSymbolItems( LIB_SYMBOL* aSymbol, int aOrientation )
55{
57
59 {
60 if( i.flag == aOrientation )
61 {
62 o = i;
63 break;
64 }
65 }
66
67 for( SCH_ITEM& item : aSymbol->GetDrawItems() )
68 {
69 for( int i = 0; i < o.n_rots; i++ )
70 item.Rotate( VECTOR2I( 0, 0 ), true );
71
72 if( o.mirror_x )
73 item.MirrorVertically( 0 );
74
75 if( o.mirror_y )
76 item.MirrorHorizontally( 0 );
77 }
78}
79
80
81
82// Rotate and/or mirror a SCH_PIN according to aOrientMirror.
83// aOrientMirror is the orientation/mirror of the parent symbol.
84// The modified pin orientation is the actual pin orientation/mirror
85// when the parent symbol is drawn.
86void RotateAndMirrorPin( SCH_PIN& aPin, int aOrientMirror )
87{
89
91 {
92 if( i.flag == aOrientMirror )
93 {
94 o = i;
95 break;
96 }
97 }
98
99 for( int i = 0; i < o.n_rots; i++ )
100 aPin.RotatePin( VECTOR2I( 0, 0 ), true );
101
102 if( o.mirror_x )
103 aPin.MirrorVerticallyPin( 0 );
104
105 if( o.mirror_y )
106 aPin.MirrorHorizontallyPin( 0 );
107}
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:1402
void RotatePin(const VECTOR2I &aCenter, bool aRotateCCW=true)
Definition: sch_pin.cpp:1422
void MirrorHorizontallyPin(int aCenter)
these transforms have always effects
Definition: sch_pin.cpp:1382
@ SYM_ORIENT_270
Definition: sch_symbol.h:84
@ SYM_MIRROR_Y
Definition: sch_symbol.h:86
@ SYM_ORIENT_180
Definition: sch_symbol.h:83
@ SYM_MIRROR_X
Definition: sch_symbol.h:85
@ SYM_ORIENT_90
Definition: sch_symbol.h:82
@ SYM_ORIENT_0
Definition: sch_symbol.h:81
static ORIENT_MIRROR symbols_orientations_list[]
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.