Use the EDAInfo data to send info to KiCAD

This commit is contained in:
Jan Böhmer 2023-11-30 19:34:50 +01:00
parent b76b2740a7
commit bf5ed030fe
3 changed files with 22 additions and 10 deletions

View file

@ -14,7 +14,7 @@ final class Version20231130180903 extends AbstractMigration
{ {
public function getDescription(): string public function getDescription(): string
{ {
return ''; return 'Added EDA fields';
} }
public function up(Schema $schema): void public function up(Schema $schema): void

View file

@ -34,7 +34,7 @@ trait EDATrait
#[Embedded(class: EDAPartInfo::class)] #[Embedded(class: EDAPartInfo::class)]
protected EDAPartInfo $eda_info; protected EDAPartInfo $eda_info;
public function getEdaInfo(): ?EDAPartInfo public function getEdaInfo(): EDAPartInfo
{ {
return $this->eda_info; return $this->eda_info;
} }

View file

@ -64,6 +64,11 @@ class KiCADHelper
$repo = $this->em->getRepository(Category::class); $repo = $this->em->getRepository(Category::class);
$result = []; $result = [];
foreach ($categories as $category) { foreach ($categories as $category) {
//Skip invisible categories
if ($category->getEdaInfo()->getInvisible() ?? false) {
continue;
}
/** @var $category Category */ /** @var $category Category */
//Ensure that the category contains parts //Ensure that the category contains parts
if ($repo->getPartsCount($category) < 1) { if ($repo->getPartsCount($category) < 1) {
@ -101,6 +106,11 @@ class KiCADHelper
$result = []; $result = [];
foreach ($parts as $part) { foreach ($parts as $part) {
//If the part is invisible, then skip it
if ($part->getEdaInfo()->getInvisible() ?? $part->getCategory()?->getEdaInfo()->getInvisible() ?? false) {
continue;
}
$result[] = [ $result[] = [
'id' => (string)$part->getId(), 'id' => (string)$part->getId(),
'name' => $part->getName(), 'name' => $part->getName(),
@ -117,14 +127,16 @@ class KiCADHelper
$result = [ $result = [
'id' => (string)$part->getId(), 'id' => (string)$part->getId(),
'name' => $part->getName(), 'name' => $part->getName(),
"symbolIdStr" => "Device:R", "symbolIdStr" => $part->getEdaInfo()->getKicadSymbol() ?? $part->getCategory()?->getEdaInfo()->getKicadSymbol() ?? "",
"exclude_from_bom" => $this->boolToKicadBool(false), "exclude_from_bom" => $this->boolToKicadBool($part->getEdaInfo()->getExcludeFromBom() ?? $part->getCategory()?->getEdaInfo()->getExcludeFromBom() ?? false),
"exclude_from_board" => $this->boolToKicadBool(false), "exclude_from_board" => $this->boolToKicadBool($part->getEdaInfo()->getExcludeFromBoard() ?? $part->getCategory()?->getEdaInfo()->getExcludeFromBoard() ?? false),
"exclude_from_sim" => $this->boolToKicadBool(true), "exclude_from_sim" => $this->boolToKicadBool($part->getEdaInfo()->getExcludeFromSim() ?? $part->getCategory()?->getEdaInfo()->getExcludeFromSim() ?? false),
"fields" => [] "fields" => []
]; ];
$result["fields"]["value"] = $this->createField($part->getName(), true); $result["fields"]["footprint"] = $this->createField($part->getEdaInfo()->getKicadFootprint() ?? $part->getFootprint()?->getEdaInfo()->getKicadFootprint() ?? "");
$result["fields"]["reference"] = $this->createField($part->getEdaInfo()->getReferencePrefix() ?? 'U', true);
$result["fields"]["value"] = $this->createField($part->getEdaInfo()->getValue() ?? $part->getName(), true);
$result["fields"]["keywords"] = $this->createField($part->getTags()); $result["fields"]["keywords"] = $this->createField($part->getTags());
//Use the part info page as datasheet link. It must be an absolute URL. //Use the part info page as datasheet link. It must be an absolute URL.
@ -163,7 +175,7 @@ class KiCADHelper
$result["fields"]["Part-DB Unit"] = $this->createField($unit); $result["fields"]["Part-DB Unit"] = $this->createField($unit);
} }
if ($part->getMass()) { if ($part->getMass()) {
$result["fields"]["Mass"] = $this->createField($part->getMass()); $result["fields"]["Mass"] = $this->createField($part->getMass() . ' g');
} }
$result["fields"]["Part-DB ID"] = $this->createField($part->getId()); $result["fields"]["Part-DB ID"] = $this->createField($part->getId());
if (!empty($part->getIpn())) { if (!empty($part->getIpn())) {