diff --git a/lib/dsn-pcb/circuit-json-to-dsn-json/process-components-and-pads.ts b/lib/dsn-pcb/circuit-json-to-dsn-json/process-components-and-pads.ts index e8d39a4..4afd51d 100644 --- a/lib/dsn-pcb/circuit-json-to-dsn-json/process-components-and-pads.ts +++ b/lib/dsn-pcb/circuit-json-to-dsn-json/process-components-and-pads.ts @@ -150,7 +150,7 @@ export function processComponentsAndPads( const componentEntry = { name: footprintName, places: components.map((component) => ({ - refdes: component.componentName, + refdes: `${component.componentName}_${component.sourceComponent?.source_component_id}`, x: component.coordinates.x, y: component.coordinates.y, side: "front" as const, diff --git a/lib/dsn-pcb/circuit-json-to-dsn-json/process-nets.ts b/lib/dsn-pcb/circuit-json-to-dsn-json/process-nets.ts index 05ec698..21cf540 100644 --- a/lib/dsn-pcb/circuit-json-to-dsn-json/process-nets.ts +++ b/lib/dsn-pcb/circuit-json-to-dsn-json/process-nets.ts @@ -35,7 +35,7 @@ export function processNets(circuitElements: AnyCircuitElement[], pcb: DsnPcb) { ) padsBySourcePortId.set(sourcePort.source_port_id, { - componentName, + componentName: `${componentName}_${sourcePort.source_component_id}`, pinNumber, sourcePortId: sourcePort.source_port_id, }) @@ -119,7 +119,7 @@ export function processNets(circuitElements: AnyCircuitElement[], pcb: DsnPcb) { // Add source nets (GND, VCC, etc.) for (const element of circuitElements) { if (element.type === "source_net") { - const netName = element.name + const netName = `${element.name}_${element.source_net_id}` if (!netMap.has(netName)) { netMap.set(netName, new Set()) } diff --git a/lib/dsn-pcb/dsn-json-to-circuit-json/convert-dsn-session-to-circuit-json.ts b/lib/dsn-pcb/dsn-json-to-circuit-json/convert-dsn-session-to-circuit-json.ts index 1f4ddef..bef307b 100644 --- a/lib/dsn-pcb/dsn-json-to-circuit-json/convert-dsn-session-to-circuit-json.ts +++ b/lib/dsn-pcb/dsn-json-to-circuit-json/convert-dsn-session-to-circuit-json.ts @@ -74,12 +74,27 @@ export function convertDsnSessionToCircuitJson( // Find corresponding source trace for this net const sourceTrace = existingSourceTraces.find((st) => { const sourceNetIds = (st as any).connected_source_net_ids || [] - const sourceNet = inputPcbElms.find( - (elm) => - elm.type === "source_net" && - elm.name === net.name && - sourceNetIds.includes(elm.source_net_id), - ) + const sourceNet = inputPcbElms.find((elm) => { + if (elm.type === "source_net") { + if (elm.name.startsWith("Net")) { + // For connected nets (Net-1, Net-2, etc.) + const modifiedName = elm.name.replace(/_source_component_.+?-/, "-") + return ( + elm.type === "source_net" && + modifiedName === net.name && + sourceNetIds.includes(elm.source_net_id) + ) + } else { + // For GND,VCC etc + const modifiedName = elm.name.split("_")[0] + return ( + elm.type === "source_net" && + modifiedName === net.name && + sourceNetIds.includes(elm.source_net_id) + ) + } + } + }) return sourceNet !== undefined }) diff --git a/tests/assets/repro/subcircuits-same-components.json b/tests/assets/repro/subcircuits-same-components.json new file mode 100644 index 0000000..d5cb056 --- /dev/null +++ b/tests/assets/repro/subcircuits-same-components.json @@ -0,0 +1,810 @@ +[ + { + "type": "source_port", + "source_port_id": "source_port_0", + "name": "pin1", + "pin_number": 1, + "port_hints": ["anode", "pos", "left", "pin1", "1"], + "source_component_id": "source_component_0" + }, + { + "type": "source_port", + "source_port_id": "source_port_1", + "name": "pin2", + "pin_number": 2, + "port_hints": ["cathode", "neg", "right", "pin2", "2"], + "source_component_id": "source_component_0" + }, + { + "type": "source_component", + "source_component_id": "source_component_0", + "ftype": "simple_resistor", + "name": "R1", + "resistance": 1000, + "display_resistance": "1kΩ" + }, + { + "type": "source_port", + "source_port_id": "source_port_2", + "name": "pin1", + "pin_number": 1, + "port_hints": ["anode", "pos", "left", "pin1", "1"], + "source_component_id": "source_component_1" + }, + { + "type": "source_port", + "source_port_id": "source_port_3", + "name": "pin2", + "pin_number": 2, + "port_hints": ["cathode", "neg", "right", "pin2", "2"], + "source_component_id": "source_component_1" + }, + { + "type": "source_component", + "source_component_id": "source_component_1", + "ftype": "simple_capacitor", + "name": "C1", + "capacitance": 1e-9, + "display_capacitance": "1nF" + }, + { + "type": "source_net", + "source_net_id": "source_net_0", + "name": "NET1", + "member_source_group_ids": [] + }, + { + "type": "source_port", + "source_port_id": "source_port_4", + "name": "pin1", + "pin_number": 1, + "port_hints": ["anode", "pos", "left", "pin1", "1"], + "source_component_id": "source_component_2" + }, + { + "type": "source_port", + "source_port_id": "source_port_5", + "name": "pin2", + "pin_number": 2, + "port_hints": ["cathode", "neg", "right", "pin2", "2"], + "source_component_id": "source_component_2" + }, + { + "type": "source_component", + "source_component_id": "source_component_2", + "ftype": "simple_resistor", + "name": "R1", + "resistance": 1000, + "display_resistance": "1kΩ" + }, + { + "type": "source_port", + "source_port_id": "source_port_6", + "name": "pin1", + "pin_number": 1, + "port_hints": ["anode", "pos", "left", "pin1", "1"], + "source_component_id": "source_component_3" + }, + { + "type": "source_port", + "source_port_id": "source_port_7", + "name": "pin2", + "pin_number": 2, + "port_hints": ["cathode", "neg", "right", "pin2", "2"], + "source_component_id": "source_component_3" + }, + { + "type": "source_component", + "source_component_id": "source_component_3", + "ftype": "simple_capacitor", + "name": "C1", + "capacitance": 1e-9, + "display_capacitance": "1nF" + }, + { + "type": "source_net", + "source_net_id": "source_net_1", + "name": "NET1", + "member_source_group_ids": [] + }, + { + "type": "source_trace", + "source_trace_id": "source_trace_0", + "connected_source_port_ids": ["source_port_0"], + "connected_source_net_ids": ["source_net_0"], + "display_name": ".R1 > .pin1 to net.NET1", + "subcircuit_connectivity_map_key": "unnamedsubcircuit327_connectivity_net0" + }, + { + "type": "source_trace", + "source_trace_id": "source_trace_1", + "connected_source_port_ids": ["source_port_2"], + "connected_source_net_ids": ["source_net_0"], + "max_length": null, + "display_name": ".C1 > .pin1 to net.NET1", + "subcircuit_connectivity_map_key": "unnamedsubcircuit327_connectivity_net0" + }, + { + "type": "source_trace", + "source_trace_id": "source_trace_2", + "connected_source_port_ids": ["source_port_4"], + "connected_source_net_ids": ["source_net_1"], + "display_name": ".R1 > .pin1 to net.NET1", + "subcircuit_connectivity_map_key": "unnamedsubcircuit340_connectivity_net0" + }, + { + "type": "source_trace", + "source_trace_id": "source_trace_3", + "connected_source_port_ids": ["source_port_6"], + "connected_source_net_ids": ["source_net_1"], + "max_length": null, + "display_name": ".C1 > .pin1 to net.NET1", + "subcircuit_connectivity_map_key": "unnamedsubcircuit340_connectivity_net0" + }, + { + "type": "schematic_component", + "schematic_component_id": "schematic_component_0", + "center": { + "x": 3, + "y": 0 + }, + "rotation": 0, + "size": { + "width": 1.0583332999999997, + "height": 0.388910699999999 + }, + "source_component_id": "source_component_0", + "symbol_name": "boxresistor_right", + "symbol_display_value": "1kΩ" + }, + { + "type": "schematic_component", + "schematic_component_id": "schematic_component_1", + "center": { + "x": -3, + "y": 0 + }, + "rotation": 0, + "size": { + "width": 1.0583333000000001, + "height": 0.8400173000000031 + }, + "source_component_id": "source_component_1", + "symbol_name": "capacitor_right", + "symbol_display_value": "1nF" + }, + { + "type": "schematic_component", + "schematic_component_id": "schematic_component_2", + "center": { + "x": 3, + "y": 0 + }, + "rotation": 0, + "size": { + "width": 1.0583332999999997, + "height": 0.388910699999999 + }, + "source_component_id": "source_component_2", + "symbol_name": "boxresistor_right", + "symbol_display_value": "1kΩ" + }, + { + "type": "schematic_component", + "schematic_component_id": "schematic_component_3", + "center": { + "x": -3, + "y": 0 + }, + "rotation": 0, + "size": { + "width": 1.0583333000000001, + "height": 0.8400173000000031 + }, + "source_component_id": "source_component_3", + "symbol_name": "capacitor_right", + "symbol_display_value": "1nF" + }, + { + "type": "schematic_port", + "schematic_port_id": "schematic_port_0", + "schematic_component_id": "schematic_component_0", + "center": { + "x": 2.4662093, + "y": 0.045805199999999324 + }, + "source_port_id": "source_port_0", + "facing_direction": "left", + "distance_from_component_edge": 0.4, + "pin_number": 1, + "display_pin_label": "left" + }, + { + "type": "schematic_port", + "schematic_port_id": "schematic_port_1", + "schematic_component_id": "schematic_component_0", + "center": { + "x": 3.5337907000000004, + "y": 0.04525870000000065 + }, + "source_port_id": "source_port_1", + "facing_direction": "right", + "distance_from_component_edge": 0.4, + "pin_number": 2, + "display_pin_label": "right" + }, + { + "type": "schematic_port", + "schematic_port_id": "schematic_port_2", + "schematic_component_id": "schematic_component_1", + "center": { + "x": -3.5512093000000005, + "y": 0.016380250000000984 + }, + "source_port_id": "source_port_2", + "facing_direction": "left", + "distance_from_component_edge": 0.4, + "pin_number": 1, + "display_pin_label": "left" + }, + { + "type": "schematic_port", + "schematic_port_id": "schematic_port_3", + "schematic_component_id": "schematic_component_1", + "center": { + "x": -2.4487907, + "y": 0.016926950000000218 + }, + "source_port_id": "source_port_3", + "facing_direction": "right", + "distance_from_component_edge": 0.4, + "pin_number": 2, + "display_pin_label": "right" + }, + { + "type": "schematic_port", + "schematic_port_id": "schematic_port_4", + "schematic_component_id": "schematic_component_2", + "center": { + "x": 2.4662093, + "y": 0.045805199999999324 + }, + "source_port_id": "source_port_4", + "facing_direction": "left", + "distance_from_component_edge": 0.4, + "pin_number": 1, + "display_pin_label": "left" + }, + { + "type": "schematic_port", + "schematic_port_id": "schematic_port_5", + "schematic_component_id": "schematic_component_2", + "center": { + "x": 3.5337907000000004, + "y": 0.04525870000000065 + }, + "source_port_id": "source_port_5", + "facing_direction": "right", + "distance_from_component_edge": 0.4, + "pin_number": 2, + "display_pin_label": "right" + }, + { + "type": "schematic_port", + "schematic_port_id": "schematic_port_6", + "schematic_component_id": "schematic_component_3", + "center": { + "x": -3.5512093000000005, + "y": 0.016380250000000984 + }, + "source_port_id": "source_port_6", + "facing_direction": "left", + "distance_from_component_edge": 0.4, + "pin_number": 1, + "display_pin_label": "left" + }, + { + "type": "schematic_port", + "schematic_port_id": "schematic_port_7", + "schematic_component_id": "schematic_component_3", + "center": { + "x": -2.4487907, + "y": 0.016926950000000218 + }, + "source_port_id": "source_port_7", + "facing_direction": "right", + "distance_from_component_edge": 0.4, + "pin_number": 2, + "display_pin_label": "right" + }, + { + "type": "schematic_net_label", + "schematic_net_label_id": "schematic_net_label_0", + "text": "NET1", + "source_net_id": "source_net_0", + "anchor_position": { + "x": 2.4662093, + "y": 0.045805199999999324 + }, + "center": { + "x": 2.4662093, + "y": 0.045805199999999324 + }, + "anchor_side": "right" + }, + { + "type": "schematic_net_label", + "schematic_net_label_id": "schematic_net_label_1", + "text": "NET1", + "source_net_id": "source_net_0", + "anchor_position": { + "x": -3.5512093000000005, + "y": 0.016380250000000984 + }, + "center": { + "x": -3.5512093000000005, + "y": 0.016380250000000984 + }, + "anchor_side": "right" + }, + { + "type": "schematic_net_label", + "schematic_net_label_id": "schematic_net_label_2", + "text": "NET1", + "source_net_id": "source_net_1", + "anchor_position": { + "x": 2.4662093, + "y": 0.045805199999999324 + }, + "center": { + "x": 2.4662093, + "y": 0.045805199999999324 + }, + "anchor_side": "right" + }, + { + "type": "schematic_net_label", + "schematic_net_label_id": "schematic_net_label_3", + "text": "NET1", + "source_net_id": "source_net_1", + "anchor_position": { + "x": -3.5512093000000005, + "y": 0.016380250000000984 + }, + "center": { + "x": -3.5512093000000005, + "y": 0.016380250000000984 + }, + "anchor_side": "right" + }, + { + "type": "pcb_component", + "pcb_component_id": "pcb_component_0", + "center": { + "x": 3, + "y": 3 + }, + "width": 1.5999999999999996, + "height": 0.5999999999999996, + "layer": "top", + "rotation": 0, + "source_component_id": "source_component_0" + }, + { + "type": "pcb_component", + "pcb_component_id": "pcb_component_1", + "center": { + "x": -3, + "y": 3 + }, + "width": 1.5999999999999996, + "height": 0.5999999999999996, + "layer": "top", + "rotation": 0, + "source_component_id": "source_component_1" + }, + { + "type": "pcb_component", + "pcb_component_id": "pcb_component_2", + "center": { + "x": 0, + "y": 0 + }, + "width": 0, + "height": 0, + "layer": "top", + "rotation": 0, + "source_component_id": null + }, + { + "type": "pcb_component", + "pcb_component_id": "pcb_component_3", + "center": { + "x": 3, + "y": -3 + }, + "width": 1.5999999999999996, + "height": 0.5999999999999996, + "layer": "top", + "rotation": 0, + "source_component_id": "source_component_2" + }, + { + "type": "pcb_component", + "pcb_component_id": "pcb_component_4", + "center": { + "x": -3, + "y": -3 + }, + "width": 1.5999999999999996, + "height": 0.5999999999999996, + "layer": "top", + "rotation": 0, + "source_component_id": "source_component_3" + }, + { + "type": "pcb_component", + "pcb_component_id": "pcb_component_5", + "center": { + "x": 0, + "y": 0 + }, + "width": 0, + "height": 0, + "layer": "top", + "rotation": 0, + "source_component_id": null + }, + { + "type": "pcb_board", + "pcb_board_id": "pcb_board_0", + "center": { + "x": 0, + "y": 0 + }, + "thickness": 1.4, + "num_layers": 4, + "width": 10, + "height": 10 + }, + { + "type": "pcb_smtpad", + "pcb_smtpad_id": "pcb_smtpad_0", + "pcb_component_id": "pcb_component_0", + "pcb_port_id": "pcb_port_0", + "layer": "top", + "shape": "rect", + "width": 0.6000000000000001, + "height": 0.6000000000000001, + "port_hints": ["1", "left"], + "x": 2.5, + "y": 3 + }, + { + "type": "pcb_solder_paste", + "pcb_solder_paste_id": "pcb_solder_paste_0", + "layer": "top", + "shape": "rect", + "width": 0.42000000000000004, + "height": 0.42000000000000004, + "x": 2.5, + "y": 3, + "pcb_component_id": "pcb_component_0", + "pcb_smtpad_id": "pcb_smtpad_0" + }, + { + "type": "pcb_smtpad", + "pcb_smtpad_id": "pcb_smtpad_1", + "pcb_component_id": "pcb_component_0", + "pcb_port_id": "pcb_port_1", + "layer": "top", + "shape": "rect", + "width": 0.6000000000000001, + "height": 0.6000000000000001, + "port_hints": ["2", "right"], + "x": 3.5, + "y": 3 + }, + { + "type": "pcb_solder_paste", + "pcb_solder_paste_id": "pcb_solder_paste_1", + "layer": "top", + "shape": "rect", + "width": 0.42000000000000004, + "height": 0.42000000000000004, + "x": 3.5, + "y": 3, + "pcb_component_id": "pcb_component_0", + "pcb_smtpad_id": "pcb_smtpad_1" + }, + { + "type": "pcb_smtpad", + "pcb_smtpad_id": "pcb_smtpad_2", + "pcb_component_id": "pcb_component_1", + "pcb_port_id": "pcb_port_2", + "layer": "top", + "shape": "rect", + "width": 0.6000000000000001, + "height": 0.6000000000000001, + "port_hints": ["1", "left"], + "x": -3.5, + "y": 3 + }, + { + "type": "pcb_solder_paste", + "pcb_solder_paste_id": "pcb_solder_paste_2", + "layer": "top", + "shape": "rect", + "width": 0.42000000000000004, + "height": 0.42000000000000004, + "x": -3.5, + "y": 3, + "pcb_component_id": "pcb_component_1", + "pcb_smtpad_id": "pcb_smtpad_2" + }, + { + "type": "pcb_smtpad", + "pcb_smtpad_id": "pcb_smtpad_3", + "pcb_component_id": "pcb_component_1", + "pcb_port_id": "pcb_port_3", + "layer": "top", + "shape": "rect", + "width": 0.6000000000000001, + "height": 0.6000000000000001, + "port_hints": ["2", "right"], + "x": -2.5, + "y": 3 + }, + { + "type": "pcb_solder_paste", + "pcb_solder_paste_id": "pcb_solder_paste_3", + "layer": "top", + "shape": "rect", + "width": 0.42000000000000004, + "height": 0.42000000000000004, + "x": -2.5, + "y": 3, + "pcb_component_id": "pcb_component_1", + "pcb_smtpad_id": "pcb_smtpad_3" + }, + { + "type": "pcb_smtpad", + "pcb_smtpad_id": "pcb_smtpad_4", + "pcb_component_id": "pcb_component_3", + "pcb_port_id": "pcb_port_4", + "layer": "top", + "shape": "rect", + "width": 0.6000000000000001, + "height": 0.6000000000000001, + "port_hints": ["1", "left"], + "x": 2.5, + "y": -3 + }, + { + "type": "pcb_solder_paste", + "pcb_solder_paste_id": "pcb_solder_paste_4", + "layer": "top", + "shape": "rect", + "width": 0.42000000000000004, + "height": 0.42000000000000004, + "x": 2.5, + "y": -3, + "pcb_component_id": "pcb_component_3", + "pcb_smtpad_id": "pcb_smtpad_4" + }, + { + "type": "pcb_smtpad", + "pcb_smtpad_id": "pcb_smtpad_5", + "pcb_component_id": "pcb_component_3", + "pcb_port_id": "pcb_port_5", + "layer": "top", + "shape": "rect", + "width": 0.6000000000000001, + "height": 0.6000000000000001, + "port_hints": ["2", "right"], + "x": 3.5, + "y": -3 + }, + { + "type": "pcb_solder_paste", + "pcb_solder_paste_id": "pcb_solder_paste_5", + "layer": "top", + "shape": "rect", + "width": 0.42000000000000004, + "height": 0.42000000000000004, + "x": 3.5, + "y": -3, + "pcb_component_id": "pcb_component_3", + "pcb_smtpad_id": "pcb_smtpad_5" + }, + { + "type": "pcb_smtpad", + "pcb_smtpad_id": "pcb_smtpad_6", + "pcb_component_id": "pcb_component_4", + "pcb_port_id": "pcb_port_6", + "layer": "top", + "shape": "rect", + "width": 0.6000000000000001, + "height": 0.6000000000000001, + "port_hints": ["1", "left"], + "x": -3.5, + "y": -3 + }, + { + "type": "pcb_solder_paste", + "pcb_solder_paste_id": "pcb_solder_paste_6", + "layer": "top", + "shape": "rect", + "width": 0.42000000000000004, + "height": 0.42000000000000004, + "x": -3.5, + "y": -3, + "pcb_component_id": "pcb_component_4", + "pcb_smtpad_id": "pcb_smtpad_6" + }, + { + "type": "pcb_smtpad", + "pcb_smtpad_id": "pcb_smtpad_7", + "pcb_component_id": "pcb_component_4", + "pcb_port_id": "pcb_port_7", + "layer": "top", + "shape": "rect", + "width": 0.6000000000000001, + "height": 0.6000000000000001, + "port_hints": ["2", "right"], + "x": -2.5, + "y": -3 + }, + { + "type": "pcb_solder_paste", + "pcb_solder_paste_id": "pcb_solder_paste_7", + "layer": "top", + "shape": "rect", + "width": 0.42000000000000004, + "height": 0.42000000000000004, + "x": -2.5, + "y": -3, + "pcb_component_id": "pcb_component_4", + "pcb_smtpad_id": "pcb_smtpad_7" + }, + { + "type": "pcb_port", + "pcb_port_id": "pcb_port_0", + "pcb_component_id": "pcb_component_0", + "layers": ["top"], + "x": 2.5, + "y": 3, + "source_port_id": "source_port_0" + }, + { + "type": "pcb_port", + "pcb_port_id": "pcb_port_1", + "pcb_component_id": "pcb_component_0", + "layers": ["top"], + "x": 3.5, + "y": 3, + "source_port_id": "source_port_1" + }, + { + "type": "pcb_port", + "pcb_port_id": "pcb_port_2", + "pcb_component_id": "pcb_component_1", + "layers": ["top"], + "x": -3.5, + "y": 3, + "source_port_id": "source_port_2" + }, + { + "type": "pcb_port", + "pcb_port_id": "pcb_port_3", + "pcb_component_id": "pcb_component_1", + "layers": ["top"], + "x": -2.5, + "y": 3, + "source_port_id": "source_port_3" + }, + { + "type": "pcb_port", + "pcb_port_id": "pcb_port_4", + "pcb_component_id": "pcb_component_3", + "layers": ["top"], + "x": 2.5, + "y": -3, + "source_port_id": "source_port_4" + }, + { + "type": "pcb_port", + "pcb_port_id": "pcb_port_5", + "pcb_component_id": "pcb_component_3", + "layers": ["top"], + "x": 3.5, + "y": -3, + "source_port_id": "source_port_5" + }, + { + "type": "pcb_port", + "pcb_port_id": "pcb_port_6", + "pcb_component_id": "pcb_component_4", + "layers": ["top"], + "x": -3.5, + "y": -3, + "source_port_id": "source_port_6" + }, + { + "type": "pcb_port", + "pcb_port_id": "pcb_port_7", + "pcb_component_id": "pcb_component_4", + "layers": ["top"], + "x": -2.5, + "y": -3, + "source_port_id": "source_port_7" + }, + { + "type": "cad_component", + "cad_component_id": "cad_component_0", + "position": { + "x": 3, + "y": 3, + "z": 0.7 + }, + "rotation": { + "x": 0, + "y": 0, + "z": 0 + }, + "pcb_component_id": "pcb_component_0", + "source_component_id": "source_component_0", + "footprinter_string": "0402" + }, + { + "type": "cad_component", + "cad_component_id": "cad_component_1", + "position": { + "x": -3, + "y": 3, + "z": 0.7 + }, + "rotation": { + "x": 0, + "y": 0, + "z": 0 + }, + "pcb_component_id": "pcb_component_1", + "source_component_id": "source_component_1", + "footprinter_string": "0402" + }, + { + "type": "cad_component", + "cad_component_id": "cad_component_2", + "position": { + "x": 3, + "y": -3, + "z": 0.7 + }, + "rotation": { + "x": 0, + "y": 0, + "z": 0 + }, + "pcb_component_id": "pcb_component_3", + "source_component_id": "source_component_2", + "footprinter_string": "0402" + }, + { + "type": "cad_component", + "cad_component_id": "cad_component_3", + "position": { + "x": -3, + "y": -3, + "z": 0.7 + }, + "rotation": { + "x": 0, + "y": 0, + "z": 0 + }, + "pcb_component_id": "pcb_component_4", + "source_component_id": "source_component_3", + "footprinter_string": "0402" + } +] diff --git a/tests/dsn-pcb/subcircuits-having-same-component.test.ts b/tests/dsn-pcb/subcircuits-having-same-component.test.ts new file mode 100644 index 0000000..fefde7b --- /dev/null +++ b/tests/dsn-pcb/subcircuits-having-same-component.test.ts @@ -0,0 +1,16 @@ +import { expect, test } from "bun:test" +import { convertCircuitJsonToDsnString, convertCircuitJsonToDsnJson } from "lib" +import inputCircuitFile from "../assets/repro/subcircuits-same-components.json" +import type { AnyCircuitElement } from "circuit-json" + +test("convert circuit json to dsn pcb", async () => { + const circuitJson = inputCircuitFile as AnyCircuitElement[] + const dsnJson = convertCircuitJsonToDsnJson(circuitJson) + + expect(dsnJson.network.nets.length).toBe(6) + + const net1Count = dsnJson.network.nets.filter((net) => + net.name.startsWith("NET1"), + ).length + expect(net1Count).toBe(2) +}) diff --git a/tests/repros/repro-4-arduino-nano.test.ts b/tests/repros/repro-4-arduino-nano.test.ts index 6caa5b3..08a7fa8 100644 --- a/tests/repros/repro-4-arduino-nano.test.ts +++ b/tests/repros/repro-4-arduino-nano.test.ts @@ -40,5 +40,5 @@ test("circuit json (arduino nano) -> dsn file", async () => { // padstack length expect(dsnJson.library.padstacks.length).toBe(10) // net length - expect(dsnJson.network.nets.length).toBe(72) + expect(dsnJson.network.nets.length).toBe(75) }) diff --git a/tests/repros/repro-7-fixing-hover.test.ts b/tests/repros/repro-7-fixing-hover.test.ts index 73e2718..1ef8b0a 100644 --- a/tests/repros/repro-7-fixing-hover.test.ts +++ b/tests/repros/repro-7-fixing-hover.test.ts @@ -37,12 +37,12 @@ test("motor driver circuit with hover", async () => { ) expect(pcbTraces.length).toBe(67) - expect(sourceTraceIds.every((id) => id >= 0 && id <= 22)).toBe(true) + expect(sourceTraceIds.every((id) => id >= 0 && id <= 31)).toBe(true) // Checking the proper linkage of source traces to source ports expect(sourceTraceIds.filter((id) => id === 17).length).toBe(2) - expect(sourceTraceIds.filter((id) => id === 5).length).toBe(21) - expect(sourceTraceIds.filter((id) => id === 4).length).toBe(5) + expect(sourceTraceIds.filter((id) => id === 23).length).toBe(21) + expect(sourceTraceIds.filter((id) => id === 31).length).toBe(5) expect(sourceTraceIds.filter((id) => id === 10).length).toBe(6) expect(sourceTraceIds.filter((id) => id === 0).length).toBe(11) }) diff --git a/tests/repros/repro2-motor-driver.test.ts b/tests/repros/repro2-motor-driver.test.ts index af21c01..290ba2f 100644 --- a/tests/repros/repro2-motor-driver.test.ts +++ b/tests/repros/repro2-motor-driver.test.ts @@ -42,12 +42,24 @@ test("circuit json (motor driver breakout) -> dsn file", async () => { expect(dsnJson.network.nets.length).toBe(16) //expect the first net to have length name "GND" and pins length 11 - expect(dsnJson.network.nets[0].name).toBe("GND") - expect(dsnJson.network.nets[0].pins.length).toBe(11) + let foundGndNet = false + dsnJson.network.nets.forEach((net) => { + if (net.name === "GND_source_net_1") { + expect(net.pins.length).toBe(11) + foundGndNet = true + } + }) + expect(foundGndNet).toBe(true) //expect the second net to have length name "VCC" and pins length 3 - expect(dsnJson.network.nets[1].name).toBe("VCC") - expect(dsnJson.network.nets[1].pins.length).toBe(3) + let foundVccNet = false + dsnJson.network.nets.forEach((net) => { + if (net.name === "VCC_source_net_0") { + expect(net.pins.length).toBe(3) + foundVccNet = true + } + }) + expect(foundVccNet).toBe(true) }) test("session file (motor driver breakout) -> circuit json", async () => {