mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2026-03-01 04:49:36 +00:00
Add CSV import support for EDA/KiCad fields
Add user-friendly column aliases (kicad_symbol, kicad_footprint, kicad_reference, kicad_value, eda_exclude_bom, etc.) to the CSV import system. Users can now bulk-set KiCad symbols, footprints, and other EDA metadata via CSV/Excel import without knowing the internal dot notation.
This commit is contained in:
parent
43fe3da19f
commit
078f04fe67
2 changed files with 85 additions and 0 deletions
|
|
@ -55,6 +55,15 @@ class PartNormalizer implements NormalizerInterface, DenormalizerInterface, Norm
|
|||
'spn' => 'supplier_part_number',
|
||||
'supplier_product_number' => 'supplier_part_number',
|
||||
'storage_location' => 'storelocation',
|
||||
//EDA/KiCad field aliases
|
||||
'kicad_symbol' => 'eda_kicad_symbol',
|
||||
'kicad_footprint' => 'eda_kicad_footprint',
|
||||
'kicad_reference' => 'eda_reference_prefix',
|
||||
'kicad_value' => 'eda_value',
|
||||
'eda_exclude_bom' => 'eda_exclude_from_bom',
|
||||
'eda_exclude_board' => 'eda_exclude_from_board',
|
||||
'eda_exclude_sim' => 'eda_exclude_from_sim',
|
||||
'eda_invisible' => 'eda_visibility',
|
||||
];
|
||||
|
||||
public function __construct(
|
||||
|
|
@ -190,9 +199,45 @@ class PartNormalizer implements NormalizerInterface, DenormalizerInterface, Norm
|
|||
}
|
||||
}
|
||||
|
||||
//Handle EDA/KiCad fields
|
||||
$this->applyEdaFields($object, $data);
|
||||
|
||||
return $object;
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply EDA/KiCad fields from CSV data to the Part's EDAPartInfo.
|
||||
*/
|
||||
private function applyEdaFields(Part $part, array $data): void
|
||||
{
|
||||
$edaInfo = $part->getEdaInfo();
|
||||
|
||||
if (!empty($data['eda_kicad_symbol'])) {
|
||||
$edaInfo->setKicadSymbol(trim((string) $data['eda_kicad_symbol']));
|
||||
}
|
||||
if (!empty($data['eda_kicad_footprint'])) {
|
||||
$edaInfo->setKicadFootprint(trim((string) $data['eda_kicad_footprint']));
|
||||
}
|
||||
if (!empty($data['eda_reference_prefix'])) {
|
||||
$edaInfo->setReferencePrefix(trim((string) $data['eda_reference_prefix']));
|
||||
}
|
||||
if (!empty($data['eda_value'])) {
|
||||
$edaInfo->setValue(trim((string) $data['eda_value']));
|
||||
}
|
||||
if (isset($data['eda_exclude_from_bom']) && $data['eda_exclude_from_bom'] !== '') {
|
||||
$edaInfo->setExcludeFromBom(filter_var($data['eda_exclude_from_bom'], FILTER_VALIDATE_BOOLEAN));
|
||||
}
|
||||
if (isset($data['eda_exclude_from_board']) && $data['eda_exclude_from_board'] !== '') {
|
||||
$edaInfo->setExcludeFromBoard(filter_var($data['eda_exclude_from_board'], FILTER_VALIDATE_BOOLEAN));
|
||||
}
|
||||
if (isset($data['eda_exclude_from_sim']) && $data['eda_exclude_from_sim'] !== '') {
|
||||
$edaInfo->setExcludeFromSim(filter_var($data['eda_exclude_from_sim'], FILTER_VALIDATE_BOOLEAN));
|
||||
}
|
||||
if (isset($data['eda_visibility']) && $data['eda_visibility'] !== '') {
|
||||
$edaInfo->setVisibility(filter_var($data['eda_visibility'], FILTER_VALIDATE_BOOLEAN));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool[]
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -136,4 +136,44 @@ final class PartNormalizerTest extends WebTestCase
|
|||
$this->assertEqualsWithDelta(1.0, $priceDetail->getPriceRelatedQuantity(), PHP_FLOAT_EPSILON);
|
||||
$this->assertEqualsWithDelta(1.0, $priceDetail->getMinDiscountQuantity(), PHP_FLOAT_EPSILON);
|
||||
}
|
||||
|
||||
public function testDenormalizeEdaFields(): void
|
||||
{
|
||||
$input = [
|
||||
'name' => 'EDA Test Part',
|
||||
'kicad_symbol' => 'Device:R',
|
||||
'kicad_footprint' => 'Resistor_SMD:R_0805_2012Metric',
|
||||
'kicad_reference' => 'R',
|
||||
'kicad_value' => '10k',
|
||||
'eda_exclude_bom' => 'true',
|
||||
'eda_exclude_board' => 'false',
|
||||
];
|
||||
|
||||
$part = $this->service->denormalize($input, Part::class, 'json', ['groups' => ['import'], 'partdb_import' => true]);
|
||||
$this->assertInstanceOf(Part::class, $part);
|
||||
$this->assertSame('EDA Test Part', $part->getName());
|
||||
|
||||
$edaInfo = $part->getEdaInfo();
|
||||
$this->assertSame('Device:R', $edaInfo->getKicadSymbol());
|
||||
$this->assertSame('Resistor_SMD:R_0805_2012Metric', $edaInfo->getKicadFootprint());
|
||||
$this->assertSame('R', $edaInfo->getReferencePrefix());
|
||||
$this->assertSame('10k', $edaInfo->getValue());
|
||||
$this->assertTrue($edaInfo->getExcludeFromBom());
|
||||
$this->assertFalse($edaInfo->getExcludeFromBoard());
|
||||
}
|
||||
|
||||
public function testDenormalizeEdaFieldsEmptyValuesIgnored(): void
|
||||
{
|
||||
$input = [
|
||||
'name' => 'Part Without EDA',
|
||||
'kicad_symbol' => '',
|
||||
'kicad_footprint' => '',
|
||||
];
|
||||
|
||||
$part = $this->service->denormalize($input, Part::class, 'json', ['groups' => ['import'], 'partdb_import' => true]);
|
||||
|
||||
$edaInfo = $part->getEdaInfo();
|
||||
$this->assertNull($edaInfo->getKicadSymbol());
|
||||
$this->assertNull($edaInfo->getKicadFootprint());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue