From 9c3a462b3104521e049112e55289508a553b9fc0 Mon Sep 17 00:00:00 2001 From: Anas sarkiz Date: Mon, 2 Dec 2024 15:29:33 +0200 Subject: [PATCH] Moved Schematic Text Logic to SchematicComponentRenderWithSchematicBoxDimensions --- .../base-components/NormalComponent.ts | 36 +++++++++++++++++- lib/components/normal-components/Chip.ts | 38 ------------------- lib/components/normal-components/PinHeader.ts | 16 -------- ...lex-schematic-crossings-schematic.snap.svg | 2 +- .../__snapshots__/header-schematic.snap.svg | 2 +- .../pin-header-schematic.snap.svg | 2 +- ...ple9-schematicDisabled-schematic.snap.svg} | 0 ...sx => example9-schematicDisabled.test.tsx} | 0 8 files changed, 38 insertions(+), 58 deletions(-) rename tests/examples/__snapshots__/{example9-shcematicDisabled-schematic.snap.svg => example9-schematicDisabled-schematic.snap.svg} (100%) rename tests/examples/{example9-shcematicDisabled.test.tsx => example9-schematicDisabled.test.tsx} (100%) diff --git a/lib/components/base-components/NormalComponent.ts b/lib/components/base-components/NormalComponent.ts index 14810482..8a65740b 100644 --- a/lib/components/base-components/NormalComponent.ts +++ b/lib/components/base-components/NormalComponent.ts @@ -432,7 +432,41 @@ export class NormalComponent< source_component_id: this.source_component_id!, }) - + const hasTopOrBottomPins = + props.schPortArrangement?.topSide !== undefined || + props.schPortArrangement?.bottomSide !== undefined + const schematic_box_width = dimensions?.getSize().width + const schematic_box_height = dimensions?.getSize().height + const manufacturer_part_number_schematic_text = db.schematic_text.insert({ + text: props.manufacturerPartNumber ?? "", + schematic_component_id: schematic_component.schematic_component_id, + anchor: "left", + rotation: 0, + position: { + x: hasTopOrBottomPins + ? (props.schX ?? 0) + (schematic_box_width ?? 0) / 2 + 0.1 + : (props.schX ?? 0) - (schematic_box_width ?? 0) / 2, + y: hasTopOrBottomPins + ? (props.schY ?? 0) + (schematic_box_height ?? 0) / 2 + 0.35 + : (props.schY ?? 0) - (schematic_box_height ?? 0) / 2 - 0.13, + }, + color: "#006464", + }) + const component_name_text = db.schematic_text.insert({ + text: props.name ?? "", + schematic_component_id: schematic_component.source_component_id, + anchor: "left", + rotation: 0, + position: { + x: hasTopOrBottomPins + ? (props.schX ?? 0) + (schematic_box_width ?? 0) / 2 + 0.1 + : (props.schX ?? 0) - (schematic_box_width ?? 0) / 2, + y: hasTopOrBottomPins + ? (props.schY ?? 0) + (schematic_box_height ?? 0) / 2 + 0.55 + : (props.schY ?? 0) + (schematic_box_height ?? 0) / 2 + 0.13, + }, + color: "#006464", + }) this.schematic_component_id = schematic_component.schematic_component_id } diff --git a/lib/components/normal-components/Chip.ts b/lib/components/normal-components/Chip.ts index 491f3d8f..53657d4b 100644 --- a/lib/components/normal-components/Chip.ts +++ b/lib/components/normal-components/Chip.ts @@ -31,44 +31,6 @@ export class Chip extends NormalComponent< manufacturer_part_number: props.manufacturerPartNumber, supplier_part_numbers: props.supplierPartNumbers, }) - if (!this.parent?.root?.schematicDisabled) { - const dimensions = this._getSchematicBoxDimensions() - const hasTopOrBottomPins = - props.schPortArrangement?.topSide !== undefined || - props.schPortArrangement?.bottomSide !== undefined - const schematic_box_width = dimensions?.getSize().width - const schematic_box_height = dimensions?.getSize().height - const manufacturer_part_number_text = db.schematic_text.insert({ - text: props.manufacturerPartNumber ?? "", - schematic_component_id: source_component.source_component_id, - anchor: "left", - rotation: 0, - position: { - x: hasTopOrBottomPins - ? (props.schX ?? 0) + (schematic_box_width ?? 0) / 2 + 0.1 - : (props.schX ?? 0) - (schematic_box_width ?? 0) / 2, - y: hasTopOrBottomPins - ? (props.schY ?? 0) + (schematic_box_height ?? 0) / 2 + 0.35 - : (props.schY ?? 0) - (schematic_box_height ?? 0) / 2 - 0.13, - }, - color: "#006464", - }) - const component_name_text = db.schematic_text.insert({ - text: props.name ?? "", - schematic_component_id: source_component.source_component_id, - anchor: "left", - rotation: 0, - position: { - x: hasTopOrBottomPins - ? (props.schX ?? 0) + (schematic_box_width ?? 0) / 2 + 0.1 - : (props.schX ?? 0) - (schematic_box_width ?? 0) / 2, - y: hasTopOrBottomPins - ? (props.schY ?? 0) + (schematic_box_height ?? 0) / 2 + 0.55 - : (props.schY ?? 0) + (schematic_box_height ?? 0) / 2 + 0.13, - }, - color: "#006464", - }) - } this.source_component_id = source_component.source_component_id! } doInitialPcbComponentRender() { diff --git a/lib/components/normal-components/PinHeader.ts b/lib/components/normal-components/PinHeader.ts index 54398bc6..a4106fa9 100644 --- a/lib/components/normal-components/PinHeader.ts +++ b/lib/components/normal-components/PinHeader.ts @@ -62,22 +62,6 @@ export class PinHeader extends NormalComponent { pin_count: props.pinCount, gender: props.gender, } as SourceSimplePinHeader) - if (!this.parent?.root?.schematicDisabled) { - const dimensions = this._getSchematicBoxDimensions() - const schematic_box_width = dimensions?.getSize().width - const schematic_box_height = dimensions?.getSize().height - const component_name_text = db.schematic_text.insert({ - text: props.name ?? "", - schematic_component_id: source_component.source_component_id, - anchor: "left", - rotation: 0, - position: { - x: (props.schX ?? 0) - (schematic_box_width ?? 0) / 2, - y: (props.schY ?? 0) + (schematic_box_height ?? 0) / 2 + 0.13, - }, - color: "#006464", - }) - } this.source_component_id = source_component.source_component_id } } diff --git a/tests/components/normal-components/__snapshots__/chip-complex-schematic-crossings-schematic.snap.svg b/tests/components/normal-components/__snapshots__/chip-complex-schematic-crossings-schematic.snap.svg index a6b34274..66cc2e2c 100644 --- a/tests/components/normal-components/__snapshots__/chip-complex-schematic-crossings-schematic.snap.svg +++ b/tests/components/normal-components/__snapshots__/chip-complex-schematic-crossings-schematic.snap.svg @@ -14,4 +14,4 @@ .pin-number { fill: rgb(169, 0, 0); } .port-label { fill: rgb(0, 100, 100); } .component-name { fill: rgb(0, 100, 100); } - -6,-5-6,-4-6,-3-6,-2-6,-1-6,0-6,1-6,2-6,3-5,-5-5,-4-5,-3-5,-2-5,-1-5,0-5,1-5,2-5,3-4,-5-4,-4-4,-3-4,-2-4,-1-4,0-4,1-4,2-4,3-3,-5-3,-4-3,-3-3,-2-3,-1-3,0-3,1-3,2-3,3-2,-5-2,-4-2,-3-2,-2-2,-1-2,0-2,1-2,2-2,3-1,-5-1,-4-1,-3-1,-2-1,-1-1,0-1,1-1,2-1,30,-50,-40,-30,-20,-10,00,10,20,31,-51,-41,-31,-21,-11,01,11,21,32,-52,-42,-32,-22,-12,02,12,22,33,-53,-43,-33,-23,-13,03,13,23,34,-54,-44,-34,-24,-14,04,14,24,35,-55,-45,-35,-25,-15,05,15,25,36,-56,-46,-36,-26,-16,06,16,26,37,-57,-47,-37,-27,-17,07,17,27,31IN12IN23IN34IN45IN56IN67IN78IN89OUT110OUT211OUT312OUT413OUT514OUT615OUT716OUT8R110kΩR210kΩR310kΩR410kΩR510kΩR610kΩR710kΩR810kΩR910kΩR1010kΩR1110kΩR1210kΩU1 \ No newline at end of file + -6,-5-6,-4-6,-3-6,-2-6,-1-6,0-6,1-6,2-6,3-5,-5-5,-4-5,-3-5,-2-5,-1-5,0-5,1-5,2-5,3-4,-5-4,-4-4,-3-4,-2-4,-1-4,0-4,1-4,2-4,3-3,-5-3,-4-3,-3-3,-2-3,-1-3,0-3,1-3,2-3,3-2,-5-2,-4-2,-3-2,-2-2,-1-2,0-2,1-2,2-2,3-1,-5-1,-4-1,-3-1,-2-1,-1-1,0-1,1-1,2-1,30,-50,-40,-30,-20,-10,00,10,20,31,-51,-41,-31,-21,-11,01,11,21,32,-52,-42,-32,-22,-12,02,12,22,33,-53,-43,-33,-23,-13,03,13,23,34,-54,-44,-34,-24,-14,04,14,24,35,-55,-45,-35,-25,-15,05,15,25,36,-56,-46,-36,-26,-16,06,16,26,37,-57,-47,-37,-27,-17,07,17,27,31IN12IN23IN34IN45IN56IN67IN78IN89OUT110OUT211OUT312OUT413OUT514OUT615OUT716OUT8R110kΩR210kΩR310kΩR410kΩR510kΩR610kΩR710kΩR810kΩR910kΩR1010kΩR1110kΩR1210kΩU1 \ No newline at end of file diff --git a/tests/components/normal-components/__snapshots__/header-schematic.snap.svg b/tests/components/normal-components/__snapshots__/header-schematic.snap.svg index d0e02724..05d8d832 100644 --- a/tests/components/normal-components/__snapshots__/header-schematic.snap.svg +++ b/tests/components/normal-components/__snapshots__/header-schematic.snap.svg @@ -14,4 +14,4 @@ .pin-number { fill: rgb(169, 0, 0); } .port-label { fill: rgb(0, 100, 100); } .component-name { fill: rgb(0, 100, 100); } - -2,-1-2,0-2,1-2,2-1,-1-1,0-1,1-1,20,-10,00,10,21,-11,01,11,22,-12,02,12,21label12label23label34label4J1 \ No newline at end of file + -2,-2-2,-1-2,0-2,1-2,2-1,-2-1,-1-1,0-1,1-1,20,-20,-10,00,10,21,-21,-11,01,11,22,-22,-12,02,12,21label12label23label34label4J1J1 \ No newline at end of file diff --git a/tests/components/normal-components/__snapshots__/pin-header-schematic.snap.svg b/tests/components/normal-components/__snapshots__/pin-header-schematic.snap.svg index a925c6da..12b2f629 100644 --- a/tests/components/normal-components/__snapshots__/pin-header-schematic.snap.svg +++ b/tests/components/normal-components/__snapshots__/pin-header-schematic.snap.svg @@ -14,4 +14,4 @@ .pin-number { fill: rgb(169, 0, 0); } .port-label { fill: rgb(0, 100, 100); } .component-name { fill: rgb(0, 100, 100); } - -2,-1-2,0-2,1-2,2-1,-1-1,0-1,1-1,20,-10,00,10,21,-11,01,11,22,-12,02,12,21234P1 \ No newline at end of file + -2,-2-2,-1-2,0-2,1-2,2-1,-2-1,-1-1,0-1,1-1,20,-20,-10,00,10,21,-21,-11,01,11,22,-22,-12,02,12,21234P1P1 \ No newline at end of file diff --git a/tests/examples/__snapshots__/example9-shcematicDisabled-schematic.snap.svg b/tests/examples/__snapshots__/example9-schematicDisabled-schematic.snap.svg similarity index 100% rename from tests/examples/__snapshots__/example9-shcematicDisabled-schematic.snap.svg rename to tests/examples/__snapshots__/example9-schematicDisabled-schematic.snap.svg diff --git a/tests/examples/example9-shcematicDisabled.test.tsx b/tests/examples/example9-schematicDisabled.test.tsx similarity index 100% rename from tests/examples/example9-shcematicDisabled.test.tsx rename to tests/examples/example9-schematicDisabled.test.tsx