mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2026-03-01 12:59:36 +00:00
Add KiCad HTTP Library API v2 with volatile field support
Implements preliminary support for the KiCad HTTP Library API v2 spec (currently in draft). Key differences from v1: - Volatile fields: Stock and Storage Location are marked volatile (shown in KiCad UI but not saved to schematic files) - Root endpoint returns links to categories endpoint - Uses int $apiVersion parameter for clean version switching v2 spec draft: https://gitlab.com/RosyDev/kicad-dev-docs/-/blob/http-lib-v2/content/apis-and-binding/http-libraries/http-lib-v2-00.adoc
This commit is contained in:
parent
5126f7ff9c
commit
4427ba8ca6
3 changed files with 307 additions and 5 deletions
|
|
@ -197,8 +197,15 @@ class KiCadHelper
|
|||
});
|
||||
}
|
||||
|
||||
public function getKiCADPart(Part $part): array
|
||||
/**
|
||||
* @param int $apiVersion The API version to use (1 or 2). Version 2 adds volatile field support.
|
||||
*/
|
||||
public function getKiCADPart(Part $part, int $apiVersion = 1): array
|
||||
{
|
||||
if ($apiVersion < 1 || $apiVersion > 2) {
|
||||
throw new \InvalidArgumentException(sprintf('Unsupported API version %d. Supported versions: 1, 2.', $apiVersion));
|
||||
}
|
||||
|
||||
$result = [
|
||||
'id' => (string)$part->getId(),
|
||||
'name' => $part->getName(),
|
||||
|
|
@ -332,9 +339,10 @@ class KiCadHelper
|
|||
}
|
||||
}
|
||||
}
|
||||
$result['fields']['Stock'] = $this->createField($totalStock);
|
||||
// In API v2, stock and location are volatile (shown but not saved to schematic)
|
||||
$result['fields']['Stock'] = $this->createField($totalStock, false, $apiVersion >= 2);
|
||||
if ($locations !== []) {
|
||||
$result['fields']['Storage Location'] = $this->createField(implode(', ', array_unique($locations)));
|
||||
$result['fields']['Storage Location'] = $this->createField(implode(', ', array_unique($locations)), false, $apiVersion >= 2);
|
||||
}
|
||||
|
||||
//Add parameters marked for EDA export (explicit true, or system default when null)
|
||||
|
|
@ -446,14 +454,21 @@ class KiCadHelper
|
|||
* Creates a field array for KiCAD
|
||||
* @param string|int|float $value
|
||||
* @param bool $visible
|
||||
* @param bool $volatile If true (API v2), field is shown in KiCad but NOT saved to schematic
|
||||
* @return array
|
||||
*/
|
||||
private function createField(string|int|float $value, bool $visible = false): array
|
||||
private function createField(string|int|float $value, bool $visible = false, bool $volatile = false): array
|
||||
{
|
||||
return [
|
||||
$field = [
|
||||
'value' => (string)$value,
|
||||
'visible' => $this->boolToKicadBool($visible),
|
||||
];
|
||||
|
||||
if ($volatile) {
|
||||
$field['volatile'] = $this->boolToKicadBool(true);
|
||||
}
|
||||
|
||||
return $field;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue