Added mapping for old german footprint names to new english ones.

This commit is contained in:
Jan Böhmer 2023-01-09 21:46:05 +01:00
parent eddf956f63
commit 4032e7ffe3
2 changed files with 146 additions and 0 deletions

View file

@ -22,6 +22,7 @@ declare(strict_types=1);
namespace App\Services\Attachments;
use FontLib\Table\Type\maxp;
use const DIRECTORY_SEPARATOR;
use Symfony\Component\Filesystem\Filesystem;
@ -131,6 +132,12 @@ class AttachmentPathResolver
//Older path entries are given via %BASE% which was the project root
$count = 0;
//When path is a footprint we have to first run the string through our lecagy german mapping functions
if (strpos($placeholder_path, '%FOOTPRINTS%') !== false) {
$placeholder_path = $this->convertOldFootprintPath($placeholder_path);
}
$placeholder_path = preg_replace($this->placeholders_regex, $this->pathes, $placeholder_path, -1, $count);
//A valid placeholder can have only one
@ -247,4 +254,118 @@ class AttachmentPathResolver
return $ret;
}
private const OLD_FOOTPINT_PATH_REPLACEMENT = [
'Aktiv' => 'Active',
'Bedrahtet' => 'THT',
'Dioden' => 'Diodes',
'Gleichrichter' => 'Rectifier',
'GLEICHRICHTER' => 'RECTIFIER',
'Oszillatoren' => 'Oscillator',
'Keramikresonatoren_SMD' => 'CeramicResonator_SMD',
'Quarze_bedrahtet' => 'Crystals_THT',
'QUARZ' => 'CRYSTAL',
'Quarze_SMD' => 'Crystals_SMD',
'Quarzoszillatoren_bedrahtet' => 'CrystalOscillator_THT',
'QUARZOSZILLATOR' => 'CRYSTAL_OSCILLATOR',
'Quarzoszillator_SMD' => 'CrystalOscillator_SMD',
'Schaltregler' => 'SwitchingRegulator',
'SCHALTREGLER' => 'SWITCHING_REGULATOR',
'Akustik' => 'Acoustics',
'Elektromechanik' => 'Electromechanics',
'Drahtbruecken' => 'WireJumpers',
'DRAHTBRUECKE' => 'WIREJUMPER',
'IC-Sockel' => 'IC-Socket',
'SOCKEL' => 'SOCKET',
'Kuehlkoerper' => 'Heatsinks',
'KUEHLKOERPER' => 'HEATSINK',
'Relais' => 'Relays',
'RELAIS' => 'RELAY',
'Schalter_Taster' => 'Switches_Buttons',
'Drehschalter' => 'RotarySwitches',
'DREHSCHALTER' => 'ROTARY_SWITCH',
'Drucktaster' => 'Button',
'TASTER' => 'BUTTON',
'Kippschalter' => 'ToggleSwitch',
'KIPPSCHALTER' => 'TOGGLE_SWITCH',
'Gewinde' => 'Threaded',
'abgewinkelt' => 'angled',
'hochkant' => 'vertical',
'liegend' => 'horizontal',
'Schiebeschalter' => 'SlideSwitch',
'SCHIEBESCHALTER' => 'SLIDE_SWITCH',
'Sicherungshalter' => 'Fuseholder',
'SICHERUNGSHALTER_Laengs' => 'FUSEHOLDER_Lenghtway',
'SICHERUNGSHALTER_Quer' => 'FUSEHOLDER_Across',
'Speicherkartenslots' => 'MemoryCardSlots',
'KARTENSLOT' => 'CARD_SLOT',
'SD-Karte' => 'SD_Card',
'Rot' => 'Red',
'Schwarz' => 'Black',
'Verbinder' => 'Connectors',
'BUCHSE' => 'SOCKET',
'Buchsenleisten' => 'SocketStrips',
'Reihig' => 'Row',
'gerade' => 'straight',
'flach' => 'flat',
'praezisions' => 'precision',
'BUCHSENLEISTE' => 'SOCKET_STRIP',
'GERADE' => 'STRAIGHT',
'FLACH' => 'FLAT',
'PRAEZISION' => 'PRECISION',
'ABGEWINKELT' => 'ANGLED',
'Federkraftklemme' => 'SpringClamps',
'SCHRAUBKLEMME' => 'SCREW_CLAMP',
'KLEMME' => 'CLAMP',
'VERBINDER' => 'CONNECTOR',
'Loetoesen' => 'SolderingPads',
'LOETOESE' => 'SOLDERING_PAD',
'Rundsteckverbinder' => 'DINConnectors',
'Schraubklemmen' => 'ScrewClamps',
'Sonstiges' => 'Miscellaneous',
'Stiftleisten' => 'PinHeaders',
'STIFTLEISTE' => 'PIN_HEADER',
'mit_Rahmen' => 'with_frame',
'RAHMEN' => 'FRAME',
'Maennlich' => 'Male',
'Platinenmontage' => 'PCBMount',
'PLATINENMONTAGE' => 'PCB_MOUNT',
'Weiblich' => 'Female',
'Optik' => 'Optics',
'BLAU' => 'BLUE',
'GELD' => 'YELLOW',
'GRUEN' => 'GREEN',
'ROT' => 'RED',
'eckig' => 'square',
'Passiv' => 'Passive',
'EMV' => 'EMC',
'Induktivitaeten' => 'Inductors',
'SPULE' => 'COIL',
'Kondensatoren' => 'Capacitors',
'ELKO' => 'Electrolyte',
'Elektrolyt' => 'Electrolyte',
'Folie' => 'Film',
'FOLIENKONDENSATOR' => 'FILM_CAPACITOR',
'Keramik' => 'Ceramic',
'KERKO' => 'Ceramic',
'Tantal' => 'Tantalum',
'TANTAL' => 'TANTALUM',
'Trimmkondensatoren' => 'TrimmerCapacitors',
'TRIMMKONDENSATOR' => 'TRIMMER_CAPACITOR',
'KONDENSATOR' => 'CAPACITOR',
'Transformatoren' => 'Transformers',
'TRAFO' => 'TRANSFORMER',
'Widerstaende' => 'Resistors',
'WIDERSTAND' => 'RESISTOR',
'Dickschicht' => 'ThickFilm',
'DICKSCHICHT' => 'THICK_FILM',
'KERAMIK' => 'CERAMIC',
'Kohleschicht' => 'Carbon',
'KOHLE' => 'CARBON',
];
private function convertOldFootprintPath(string $old_path): string
{
return strtr($old_path, self::OLD_FOOTPINT_PATH_REPLACEMENT);
}
}

View file

@ -139,4 +139,29 @@ class AttachmentPathResolverTest extends WebTestCase
{
$this->assertSame($expected, $this->service->realPathToPlaceholder($param, $old_method));
}
public function germanFootprintPathdDataProvider()
{
self::bootKernel();
$this->projectDir_orig = realpath(self::$kernel->getProjectDir());
$this->projectDir = str_replace('\\', '/', $this->projectDir_orig);
$this->footprint_path = $this->projectDir.'/public/img/footprints';
yield [$this->footprint_path. '/Active/Diodes/THT/DIODE_P600.png', '%FOOTPRINTS%/Aktiv/Dioden/Bedrahtet/DIODE_P600.png'];
yield [$this->footprint_path . '/Passive/Resistors/THT/Carbon/RESISTOR-CARBON_0207.png', '%FOOTPRINTS%/Passiv/Widerstaende/Bedrahtet/Kohleschicht/WIDERSTAND-KOHLE_0207.png'];
yield [$this->footprint_path . '/Optics/LEDs/THT/LED-GREEN_3MM.png', '%FOOTPRINTS%/Optik/LEDs/Bedrahtet/LED-GRUEN_3MM.png'];
yield [$this->footprint_path . '/Passive/Capacitors/TrimmerCapacitors/TRIMMER_CAPACITOR-RED_TZ03F.png', '%FOOTPRINTS%/Passiv/Kondensatoren/Trimmkondensatoren/TRIMMKONDENSATOR-ROT_TZ03F.png'];
yield [$this->footprint_path . '/Active/ICs/TO/IC_TO126.png', '%FOOTPRINTS%/Aktiv/ICs/TO/IC_TO126.png'];
yield [$this->footprint_path . '/Electromechanics/Switches_Buttons/RotarySwitches/ROTARY_SWITCH_DIP10.png', '%FOOTPRINTS%/Elektromechanik/Schalter_Taster/Drehschalter/DREHSCHALTER_DIP10.png'];
yield [$this->footprint_path . '/Electromechanics/Connectors/DINConnectors/SOCKET_DIN_MAB_4.png', '%FOOTPRINTS%/Elektromechanik/Verbinder/Rundsteckverbinder/BUCHSE_DIN_MAB_4.png'];
}
/**
* @dataProvider germanFootprintPathdDataProvider
* @return void
*/
public function testConversionOfGermanFootprintPaths(string $expected, string $input): void
{
$this->assertSame($expected, $this->service->placeholderToRealPath($input));
}
}