KiCad PCB EDA Suite
Loading...
Searching...
No Matches
orcad_orient.h
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 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * Based on the dsn2kicad reference implementation and on OrCAD file format
7 * documentation from the OpenOrCadParser project (MIT licensed).
8 *
9 * This program is free software: you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the
11 * Free Software Foundation, either version 3 of the License, or (at your
12 * option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 */
22
23
24#ifndef ORCAD_ORIENT_H_
25#define ORCAD_ORIENT_H_
26
27#include <cstdint>
28
29#include <math/vector2d.h>
30
31
35{
36 int angle;
37 char mirror;
38 int8_t txSel;
39 int8_t tySel;
40 int8_t a;
41 int8_t b;
42 int8_t c;
43 int8_t d;
44};
45
46
49 { 0, 0, 0, 0, 1, 0, 0, 1 }, { 90, 0, 0, 1, 0, 1, -1, 0 }, { 180, 0, 1, 2, -1, 0, 0, -1 },
50 { 270, 0, 2, 0, 0, -1, 1, 0 }, { 0, 'y', 1, 0, -1, 0, 0, 1 }, { 90, 'x', 0, 0, 0, 1, 1, 0 },
51 { 0, 'x', 0, 2, 1, 0, 0, -1 }, { 270, 'x', 2, 1, 0, -1, -1, 0 }
52};
53
54
56inline int OrcadOrientOf( int aRotation, bool aMirror )
57{
58 return ( aRotation & 3 ) | ( aMirror ? 0x4 : 0 );
59}
60
61
62inline int OrcadOrientDim( int aSelector, int aWidth, int aHeight )
63{
64 return aSelector == 1 ? aWidth : aSelector == 2 ? aHeight : 0;
65}
66
67
69inline VECTOR2I OrcadOrientOffset( int aOrient, int aWidth, int aHeight )
70{
71 const ORCAD_ORIENT_ENTRY& e = ORCAD_ORIENT_TABLE[aOrient & 7];
72 return VECTOR2I( OrcadOrientDim( e.txSel, aWidth, aHeight ), OrcadOrientDim( e.tySel, aWidth, aHeight ) );
73}
74
75
77inline VECTOR2I OrcadTransformPoint( int aOrient, int aWidth, int aHeight, int aBaseX, int aBaseY, int aPx, int aPy )
78{
79 const ORCAD_ORIENT_ENTRY& e = ORCAD_ORIENT_TABLE[aOrient & 7];
80 VECTOR2I t = OrcadOrientOffset( aOrient, aWidth, aHeight );
81
82 return VECTOR2I( aBaseX + t.x + e.a * aPx + e.b * aPy, aBaseY + t.y + e.c * aPx + e.d * aPy );
83}
84
85#endif // ORCAD_ORIENT_H_
constexpr ORCAD_ORIENT_ENTRY ORCAD_ORIENT_TABLE[8]
Indexed by orientation bits: angle, mirror, offset selectors, then matrix coefficients.
VECTOR2I OrcadTransformPoint(int aOrient, int aWidth, int aHeight, int aBaseX, int aBaseY, int aPx, int aPy)
Parts use the instance anchor as the base.
int OrcadOrientDim(int aSelector, int aWidth, int aHeight)
int OrcadOrientOf(int aRotation, bool aMirror)
Compose the 3-bit orientation code from the rotation bits and mirror bit.
VECTOR2I OrcadOrientOffset(int aOrient, int aWidth, int aHeight)
Bbox re-anchoring offset for the given orientation and body size (DBU).
OrCAD rotates about the bounding box; KiCad rotates about the anchor.
char mirror
0 = none, 'x' or 'y' = KiCad mirror axis
int8_t tySel
Y offset selector.
int8_t c
int8_t a
int angle
KiCad placement angle in degrees (0/90/180/270, CCW)
int8_t d
int8_t txSel
X offset selector.
int8_t b
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:708