@@ -284,6 +284,29 @@ QRectF Datasheet::toGlobalPos(const QRectF &rect, Poppler::Page *page, int pageN
284284 return rect;
285285}
286286
287+ // use lowercase letters in when extending the map!
288+ QMap <QString, Pin::ElectricalType> Datasheet::_pinDirectionToElectricalPinTypeMap = {
289+ {QStringLiteral (" nc" ), Pin::NotConnected},
290+ {QStringLiteral (" n/c" ), Pin::NotConnected},
291+ {QStringLiteral (" oe" ), Pin::OpenEmitter},
292+ {QStringLiteral (" open-emitter" ), Pin::OpenEmitter},
293+ {QStringLiteral (" oc" ), Pin::OpenCollector},
294+ {QStringLiteral (" open-collector" ), Pin::OpenCollector},
295+ {QStringLiteral (" od" ), Pin::OpenCollector},
296+ {QStringLiteral (" open-drain" ), Pin::OpenCollector},
297+ {QStringLiteral (" tris" ), Pin::Tristate},
298+ {QStringLiteral (" sup" ), Pin::PowerIn},
299+ {QStringLiteral (" p" ), Pin::Passive},
300+ {QStringLiteral (" pas" ), Pin::Passive},
301+ {QStringLiteral (" passive" ), Pin::Passive},
302+ {QStringLiteral (" io" ), Pin::Bidir},
303+ {QStringLiteral (" i/o" ), Pin::Bidir},
304+ {QStringLiteral (" i" ), Pin::Input},
305+ {QStringLiteral (" in" ), Pin::Input},
306+ {QStringLiteral (" o" ), Pin::Output},
307+ {QStringLiteral (" out" ), Pin::Output},
308+ };
309+
287310QList<DatasheetPin *> Datasheet::extractPins (int numPage)
288311{
289312 QList<DatasheetPin *> pins;
@@ -426,7 +449,7 @@ QList<DatasheetPin *> Datasheet::extractPins(int numPage)
426449 DatasheetPin *pin = new DatasheetPin ();
427450 qreal dist = 999999999999 ;
428451 QPointF center = number->pos .center ();
429- DatasheetBox *assocLabel = NULL ;
452+ DatasheetBox *pinNameLabel = nullptr ;
430453
431454 for (int i = 0 ; i < _labels.count (); i++)
432455 {
@@ -445,27 +468,65 @@ QList<DatasheetPin *> Datasheet::extractPins(int numPage)
445468 if (newdist < dist)
446469 {
447470 dist = newdist;
448- assocLabel = label;
471+ pinNameLabel = label;
449472 }
450473 }
451474
452- if (assocLabel )
475+ if (pinNameLabel )
453476 {
454- assocLabel ->associated = true ;
477+ pinNameLabel ->associated = true ;
455478 number->associated = true ;
456479
457480 pin->pin = number->text .toInt ();
458481 pin->numPos = number->pos ;
459482 pin->numberBox = number;
460483
461- pin->name = assocLabel ->text ;
484+ pin->name = pinNameLabel ->text ;
462485 pin->name .remove (QRegExp (" \\ ([0-9]+\\ )" ));
463486 pin->name .remove (QRegExp (" +" ));
464- pin->nameBox = assocLabel ;
487+ pin->nameBox = pinNameLabel ;
465488
466489 pin->page = number->page ;
467- pin->pos = number->pos .united (assocLabel->pos );
490+ pin->pos = number->pos .united (pinNameLabel->pos );
491+
492+ dist = 999999999999 ;
493+ center = pinNameLabel->pos .center ();
494+ DatasheetBox *directionLabel = nullptr ;
495+ // loop over the labels to see if there is a pin direction label
496+ // in the following columns
497+ for (DatasheetBox *label : _labels) {
498+ if (label == pinNameLabel)
499+ continue ;
500+
501+ if (label->page != number->page )
502+ continue ;
503+
504+ // look for the closest text to the pin name
505+ qreal newdist = label->distanceToPoint (center);
506+ if (newdist < dist)
507+ {
508+ dist = newdist;
509+
510+ if (!DatasheetBox::isAlign (*label, *number)
511+ || !DatasheetBox::isAlign (*label, *pinNameLabel))
512+ continue ;
513+
514+ if (!_pinDirectionToElectricalPinTypeMap.contains (label->text .toLower ()))
515+ continue ;
468516
517+ if (label->associated )
518+ continue ;
519+
520+ if (label == number)
521+ continue ;
522+ directionLabel = label;
523+ }
524+ }
525+
526+ if (directionLabel) {
527+ directionLabel->associated = true ;
528+ pin->electricalType = _pinDirectionToElectricalPinTypeMap.value (directionLabel->text .toLower ());
529+ }
469530 pins.push_back (pin);
470531 }
471532 }
0 commit comments