Skip to content

Commit 59accec

Browse files
committed
[kicad:model] Transformed Pin::direction to 360 angle to match with new Kicad format
1 parent 3c038b2 commit 59accec

7 files changed

Lines changed: 93 additions & 54 deletions

File tree

src/kicad/model/component.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,7 @@ void Component::reorganizeToPackageStyle()
563563
{
564564
Pin *pin = _pins[i];
565565

566-
pin->setDirection(Pin::Right);
566+
pin->setAngle(0);
567567
pin->setPos(pos);
568568
pos += QPoint(0, 100);
569569
}
@@ -572,7 +572,7 @@ void Component::reorganizeToPackageStyle()
572572
{
573573
Pin *pin = _pins[i];
574574

575-
pin->setDirection(Pin::Left);
575+
pin->setAngle(180);
576576
pin->setPos(pos);
577577
pos += QPoint(0, -100);
578578
}

src/kicad/model/pin.cpp

Lines changed: 48 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@
2121
#include <utility>
2222

2323
Pin::Pin()
24-
: _direction(Pin::Right),
25-
_pinType(Pin::Normal),
24+
: _pinType(Pin::Normal),
2625
_electricalType(Pin::Input)
2726
{
27+
_angle = 0;
2828
_unit = 1;
2929
_length = 300;
3030
_textNameSize = 50;
@@ -35,10 +35,10 @@ Pin::Pin()
3535
Pin::Pin(const QString &name, const QString &padName)
3636
: _name(name),
3737
_padName(padName),
38-
_direction(Pin::Right),
3938
_pinType(Pin::Normal),
4039
_electricalType(Pin::Input)
4140
{
41+
_angle = 0;
4242
_unit = 1;
4343
_length = 300;
4444
_textNameSize = 50;
@@ -56,7 +56,7 @@ Pin::Pin(const Pin &other)
5656
_name = other._name;
5757
_pos = other._pos;
5858
_padName = other._padName;
59-
_direction = other._direction;
59+
_angle = other._angle;
6060
_pinType = other._pinType;
6161
_electricalType = other._electricalType;
6262
_unit = other._unit;
@@ -91,24 +91,60 @@ void Pin::setPos(int x, int y)
9191
_pos = QPoint(x, y);
9292
}
9393

94-
QString Pin::padName() const
94+
Pin::Direction Pin::direction() const
9595
{
96-
return _padName;
96+
if (_angle > 315 || _angle <= 45)
97+
{
98+
return Right;
99+
}
100+
if (_angle > 45 && _angle <= 135)
101+
{
102+
return Up;
103+
}
104+
if (_angle > 135 && _angle <= 225)
105+
{
106+
return Left;
107+
}
108+
return Down;
97109
}
98110

99-
void Pin::setPadName(const QString &padname)
111+
void Pin::setDirection(Direction direction)
100112
{
101-
_padName = padname;
113+
switch (direction)
114+
{
115+
case Right:
116+
_angle = 0;
117+
break;
118+
case Up:
119+
_angle = 90;
120+
break;
121+
case Left:
122+
_angle = 180;
123+
break;
124+
case Down:
125+
_angle = 270;
126+
break;
127+
}
102128
}
103129

104-
Pin::Direction Pin::direction() const
130+
int Pin::angle() const
105131
{
106-
return _direction;
132+
return _angle;
107133
}
108134

109-
void Pin::setDirection(Direction direction)
135+
void Pin::setAngle(int angle)
136+
{
137+
_angle = angle;
138+
}
139+
140+
QString Pin::padName() const
110141
{
111-
_direction = direction;
142+
return _padName;
143+
}
144+
145+
void Pin::setPadName(const QString &padname)
146+
{
147+
_padName = padname;
112148
}
113149

114150
Pin::PinType Pin::pinType() const

src/kicad/model/pin.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,14 @@ class KICAD_EXPORT Pin
7878
void setPos(const QPoint &pos);
7979
void setPos(int x, int y);
8080

81+
int angle() const;
82+
void setAngle(int angle);
83+
Direction direction() const;
84+
void setDirection(Pin::Direction direction);
85+
8186
QString padName() const;
8287
void setPadName(const QString &padname);
8388

84-
// replace by angle
85-
Direction direction() const;
86-
void setDirection(Direction direction);
87-
8889
PinType pinType() const;
8990
static QString pinTypeDesc(Pin::PinType pinType);
9091
void setPinType(const PinType &pinType);
@@ -117,8 +118,8 @@ class KICAD_EXPORT Pin
117118
private:
118119
QString _name;
119120
QPoint _pos;
121+
int _angle;
120122
QString _padName;
121-
Direction _direction;
122123
PinType _pinType;
123124
ElectricalType _electricalType;
124125
int _textNameSize;

src/kicad/parser/kicadlibparser.cpp

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ void KicadLibParser::writePin(Pin *pin)
225225
_stream << " " << pin->padName() << " " // pad name
226226
<< pin->pos().x() << " " << -pin->pos().y() << " " // x y position
227227
<< pin->length() << " " // lenght
228-
<< pinDirectionString(pin->direction()) << " " // pin direction (up/down/left/right)
228+
<< pinDirectionString(pin->angle()) << " " // pin direction (up/down/left/right)
229229
<< "50"
230230
<< " " // name text size
231231
<< "50"
@@ -623,7 +623,7 @@ Pin *KicadLibParser::readPin()
623623
char directionChar;
624624
_stream.skipWhiteSpace();
625625
_stream >> directionChar;
626-
pin->setDirection(pinDirection(directionChar));
626+
pin->setAngle(pinAngle(directionChar));
627627

628628
// text size
629629
int textNameSize;
@@ -939,20 +939,21 @@ DrawText *KicadLibParser::readLabel()
939939
return draw;
940940
}
941941

942-
QString KicadLibParser::pinDirectionString(Pin::Direction direction) const
942+
QString KicadLibParser::pinDirectionString(int angle) const
943943
{
944-
switch (direction)
944+
if (angle > 315 || angle <= 45)
945945
{
946-
case Pin::Down:
947-
return "D";
948-
case Pin::Left:
949-
return "L";
950-
case Pin::Up:
951-
return "U";
952-
case Pin::Right:
953-
return "R";
946+
return "R";
947+
}
948+
if (angle > 45 && angle <= 135)
949+
{
950+
return "U";
954951
}
955-
return "R";
952+
if (angle > 135 && angle <= 225)
953+
{
954+
return "L";
955+
}
956+
return "D";
956957
}
957958

958959
QString KicadLibParser::pinTypeString(Pin::PinType pinType) const
@@ -1013,25 +1014,26 @@ QString KicadLibParser::pinElectricalTypeString(Pin::ElectricalType electricalTy
10131014
return "I";
10141015
}
10151016

1016-
Pin::Direction KicadLibParser::pinDirection(char directionChar)
1017+
int KicadLibParser::pinAngle(char directionChar)
10171018
{
1018-
Pin::Direction direction;
1019+
int angle;
10191020
switch (directionChar)
10201021
{
1021-
case 'D':
1022-
direction = Pin::Down;
1023-
break;
1024-
case 'L':
1025-
direction = Pin::Left;
1022+
default:
1023+
case 'R':
1024+
angle = 0;
10261025
break;
10271026
case 'U':
1028-
direction = Pin::Up;
1027+
angle = 90;
10291028
break;
1030-
case 'R':
1031-
direction = Pin::Right;
1029+
case 'L':
1030+
angle = 180;
1031+
break;
1032+
case 'D':
1033+
angle = 270;
10321034
break;
10331035
}
1034-
return direction;
1036+
return angle;
10351037
}
10361038

10371039
Pin::PinType KicadLibParser::pinType(const QString &pinTypeString) const

src/kicad/parser/kicadlibparser.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,12 @@ class KICAD_EXPORT KicadLibParser : public AbstractLibParser
4747
Draw *readDraw(char c);
4848
DrawText *readLabel();
4949

50-
QString pinDirectionString(Pin::Direction direction) const;
50+
QString pinDirectionString(int angle) const;
5151
QString pinTypeString(Pin::PinType pinType) const;
5252
QString pinElectricalTypeString(Pin::ElectricalType electricalType) const;
5353
Pin::PinType pinType(const QString &pinTypeString) const;
5454
Pin::ElectricalType pinElectricalType(char electricalTypeChar) const;
55-
Pin::Direction pinDirection(char directionChar);
55+
int pinAngle(char directionChar);
5656
};
5757

5858
#endif // KICADLIBPARSER_H

src/kicad/pinruler/pinclass.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -193,36 +193,36 @@ void PinClass::setPos(const QPoint &basePos)
193193
QPoint pinPos = basePos;
194194
QPoint offset;
195195
QPoint translate;
196-
Pin::Direction direction;
196+
int angle;
197197

198198
switch (_position)
199199
{
200200
case ClassRule::PositionTop:
201-
direction = Pin::Down;
201+
angle = 270;
202202
offset = QPoint(100, 0);
203203
translate = QPoint(0, -_length);
204204
break;
205205
case ClassRule::PositionBottom:
206-
direction = Pin::Up;
206+
angle = 90;
207207
offset = QPoint(100, 0);
208208
translate = QPoint(0, _length);
209209
break;
210210
case ClassRule::PositionLeft:
211-
direction = Pin::Right;
211+
angle = 0;
212212
offset = QPoint(0, 100);
213213
translate = QPoint(-_length, 0);
214214
break;
215215
case ClassRule::PositionRight:
216216
case ClassRule::PositionASide:
217-
direction = Pin::Left;
217+
angle = 180;
218218
offset = QPoint(0, 100);
219219
translate = QPoint(_length, 0);
220220
break;
221221
}
222222
sortPins();
223223
for (PinClassItem *pinItem : _pins)
224224
{
225-
pinItem->pin()->setDirection(direction);
225+
pinItem->pin()->setAngle(angle);
226226
pinItem->pin()->setPos(pinPos + translate);
227227
pinItem->pin()->setLength(_length);
228228
if (visibilityValue() != VisibilityVisible)

src/test/test_libkicad.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,13 @@ void test_libkicad()
7373
if (pin->name() == "GND")
7474
{
7575
pin->setPos(gndpos);
76-
pin->setDirection(Pin::Left);
76+
pin->setAngle(180);
7777
gndpos += QPoint(0, 100);
7878
}
7979
else if (pin->name().startsWith("VCC"))
8080
{
8181
pin->setPos(vccpos);
82-
pin->setDirection(Pin::Left);
82+
pin->setAngle(180);
8383
vccpos += QPoint(0, 100);
8484
}
8585
else
@@ -88,7 +88,7 @@ void test_libkicad()
8888
if (bank >= 0 && bank < 8)
8989
{
9090
pin->setPos(points[bank]);
91-
pin->setDirection(Pin::Left);
91+
pin->setAngle(180);
9292
points[bank] += QPoint(0, 100);
9393
}
9494
}

0 commit comments

Comments
 (0)