diff --git a/lib/components/primitive-components/Group/applySchematicMatchPackLayoutToTree.ts b/lib/components/primitive-components/Group/applySchematicMatchPackLayoutToTree.ts index 1b57cd9bbc..7367097115 100644 --- a/lib/components/primitive-components/Group/applySchematicMatchPackLayoutToTree.ts +++ b/lib/components/primitive-components/Group/applySchematicMatchPackLayoutToTree.ts @@ -42,6 +42,94 @@ type NestedGroupMatchpackProxy = { size: Point } +type NestedGroupSchematicElements = { + rootSchematicGroup: SchematicGroup + descendantSchematicGroups: SchematicGroup[] + schematicComponents: SchematicComponent[] +} + +/** + * Collect the schematic_group and schematic_component elements owned by a + * nested group node within the active sheet-scoped layout tree (schematic + * world coordinates, mm, +X right, +Y up). + * + * Walking `groupTreeNode` includes components inside deeper descendant groups + * (e.g. schematic groups nested under PCB wrapper groups) while staying scoped + * to the active sheet and stopping at collapsed `showAsSchematicBox` groups. + */ +function collectNestedGroupSchematicElements({ + db, + groupTreeNode, + schematicSheetId, +}: { + db: CircuitJsonUtilObjects + groupTreeNode: CircuitJsonTreeNode + schematicSheetId?: SchematicSheetId +}): NestedGroupSchematicElements | null { + const rootSourceGroupId = groupTreeNode.sourceGroup?.source_group_id + if (!rootSourceGroupId) return null + + const rootSchematicGroup = db.schematic_group?.getWhere?.({ + source_group_id: rootSourceGroupId, + }) + if (!rootSchematicGroup) return null + + const descendantSchematicGroups: SchematicGroup[] = [] + const schematicComponents: SchematicComponent[] = [] + const seenSchematicGroupIds = new Set() + const seenSchematicComponentIds = new Set< + SchematicComponent["schematic_component_id"] + >() + + const appendGroupComponents = (schematicGroup: SchematicGroup) => { + const components = db.schematic_component.list({ + schematic_group_id: schematicGroup.schematic_group_id, + ...(schematicSheetId ? { schematic_sheet_id: schematicSheetId } : {}), + }) + for (const component of components) { + if (seenSchematicComponentIds.has(component.schematic_component_id)) { + continue + } + seenSchematicComponentIds.add(component.schematic_component_id) + schematicComponents.push(component) + } + } + + const visitGroupNode = ( + node: CircuitJsonTreeNode, + schematicGroup: SchematicGroup, + isRootGroup: boolean, + ) => { + if (seenSchematicGroupIds.has(schematicGroup.schematic_group_id)) return + seenSchematicGroupIds.add(schematicGroup.schematic_group_id) + + if (!isRootGroup) { + descendantSchematicGroups.push(schematicGroup) + } + + appendGroupComponents(schematicGroup) + + if (schematicGroup.show_as_schematic_box) return + + for (const childNode of node.childNodes) { + if (childNode.nodeType !== "group" || !childNode.sourceGroup) continue + const childSchematicGroup = db.schematic_group?.getWhere?.({ + source_group_id: childNode.sourceGroup.source_group_id, + }) + if (!childSchematicGroup) continue + visitGroupNode(childNode, childSchematicGroup, false) + } + } + + visitGroupNode(groupTreeNode, rootSchematicGroup, true) + + return { + rootSchematicGroup, + descendantSchematicGroups, + schematicComponents, + } +} + const ROTATION_TO_PLACE_SIDE_ON_TOP: Record = { "y+": 0, @@ -480,22 +568,24 @@ function convertTreeToMatchPackInputProblem( const groupId = getTreeChildChipId(child, index)! debug(`[${group.name}] Processing nested group: ${groupId}`) - const schematicGroup = db.schematic_group?.getWhere?.({ - source_group_id: child.sourceGroup.source_group_id, + const nestedGroupElements = collectNestedGroupSchematicElements({ + db, + groupTreeNode: child, + schematicSheetId: opts.schematicSheetId, }) debug( `[${group.name}] Found schematic_group for ${groupId}:`, - schematicGroup, + nestedGroupElements?.rootSchematicGroup, ) - if (schematicGroup) { + if (nestedGroupElements) { + const { + rootSchematicGroup: schematicGroup, + schematicComponents: groupComponents, + } = nestedGroupElements debug(`[${group.name}] Treating group ${groupId} as composite chip`) - const groupComponents = db.schematic_component.list({ - schematic_group_id: schematicGroup.schematic_group_id, - }) - debug( `[${group.name}] Group ${groupId} has ${groupComponents.length} components:`, groupComponents.map((c: any) => c.source_component_id), @@ -577,16 +667,14 @@ function convertTreeToMatchPackInputProblem( }) if (treeNode?.nodeType === "group" && treeNode.sourceGroup) { - const schematicGroup = db.schematic_group?.getWhere?.({ - source_group_id: treeNode.sourceGroup.source_group_id, + const nestedGroupElements = collectNestedGroupSchematicElements({ + db, + groupTreeNode: treeNode, + schematicSheetId: opts.schematicSheetId, }) - if (schematicGroup) { - const groupComponents = db.schematic_component.list({ - schematic_group_id: schematicGroup.schematic_group_id, - }) - - for (const comp of groupComponents) { + if (nestedGroupElements) { + for (const comp of nestedGroupElements.schematicComponents) { const sourcePorts = db.source_port.list({ source_component_id: comp.source_component_id, }) @@ -1025,19 +1113,23 @@ export function applySchematicMatchPackLayoutToTree< } } } else if (treeNode.nodeType === "group" && treeNode.sourceGroup) { - const schematicGroup = db.schematic_group?.getWhere?.({ - source_group_id: treeNode.sourceGroup.source_group_id, + const nestedGroupElements = collectNestedGroupSchematicElements({ + db, + groupTreeNode: treeNode, + schematicSheetId: opts.schematicSheetId, }) - if (schematicGroup) { + if (nestedGroupElements) { + const { + rootSchematicGroup: schematicGroup, + descendantSchematicGroups, + schematicComponents: groupComponents, + } = nestedGroupElements + debug( `Moving group ${chipId} to (${newCenter.x}, ${newCenter.y}) from (${schematicGroup.center?.x}, ${schematicGroup.center?.y})`, ) - const groupComponents = db.schematic_component.list({ - schematic_group_id: schematicGroup.schematic_group_id, - }) - debug( `Group ${chipId} has ${groupComponents.length} components to move`, ) @@ -1094,6 +1186,15 @@ export function applySchematicMatchPackLayoutToTree< } } + for (const descendantGroup of descendantSchematicGroups) { + if (descendantGroup.center) { + descendantGroup.center = { + x: descendantGroup.center.x + positionDelta.x, + y: descendantGroup.center.y + positionDelta.y, + } + } + } + schematicGroup.center = newCenter if (matchpackProxy) { schematicGroup.width = matchpackProxy.size.x diff --git a/tests/groups/__snapshots__/group-schematic-matchpack-nested-pcb-groups1-schematic.snap.svg b/tests/groups/__snapshots__/group-schematic-matchpack-nested-pcb-groups1-schematic.snap.svg new file mode 100644 index 0000000000..2ef788e634 --- /dev/null +++ b/tests/groups/__snapshots__/group-schematic-matchpack-nested-pcb-groups1-schematic.snap.svg @@ -0,0 +1,12 @@ +-17,-13-17,-12-17,-11-17,-10-17,-9-17,-8-17,-7-17,-6-17,-5-17,-4-17,-3-17,-2-17,-1-17,0-17,1-17,2-17,3-17,4-17,5-17,6-17,7-17,8-17,9-17,10-17,11-16,-13-16,-12-16,-11-16,-10-16,-9-16,-8-16,-7-16,-6-16,-5-16,-4-16,-3-16,-2-16,-1-16,0-16,1-16,2-16,3-16,4-16,5-16,6-16,7-16,8-16,9-16,10-16,11-15,-13-15,-12-15,-11-15,-10-15,-9-15,-8-15,-7-15,-6-15,-5-15,-4-15,-3-15,-2-15,-1-15,0-15,1-15,2-15,3-15,4-15,5-15,6-15,7-15,8-15,9-15,10-15,11-14,-13-14,-12-14,-11-14,-10-14,-9-14,-8-14,-7-14,-6-14,-5-14,-4-14,-3-14,-2-14,-1-14,0-14,1-14,2-14,3-14,4-14,5-14,6-14,7-14,8-14,9-14,10-14,11-13,-13-13,-12-13,-11-13,-10-13,-9-13,-8-13,-7-13,-6-13,-5-13,-4-13,-3-13,-2-13,-1-13,0-13,1-13,2-13,3-13,4-13,5-13,6-13,7-13,8-13,9-13,10-13,11-12,-13-12,-12-12,-11-12,-10-12,-9-12,-8-12,-7-12,-6-12,-5-12,-4-12,-3-12,-2-12,-1-12,0-12,1-12,2-12,3-12,4-12,5-12,6-12,7-12,8-12,9-12,10-12,11-11,-13-11,-12-11,-11-11,-10-11,-9-11,-8-11,-7-11,-6-11,-5-11,-4-11,-3-11,-2-11,-1-11,0-11,1-11,2-11,3-11,4-11,5-11,6-11,7-11,8-11,9-11,10-11,11-10,-13-10,-12-10,-11-10,-10-10,-9-10,-8-10,-7-10,-6-10,-5-10,-4-10,-3-10,-2-10,-1-10,0-10,1-10,2-10,3-10,4-10,5-10,6-10,7-10,8-10,9-10,10-10,11-9,-13-9,-12-9,-11-9,-10-9,-9-9,-8-9,-7-9,-6-9,-5-9,-4-9,-3-9,-2-9,-1-9,0-9,1-9,2-9,3-9,4-9,5-9,6-9,7-9,8-9,9-9,10-9,11-8,-13-8,-12-8,-11-8,-10-8,-9-8,-8-8,-7-8,-6-8,-5-8,-4-8,-3-8,-2-8,-1-8,0-8,1-8,2-8,3-8,4-8,5-8,6-8,7-8,8-8,9-8,10-8,11-7,-13-7,-12-7,-11-7,-10-7,-9-7,-8-7,-7-7,-6-7,-5-7,-4-7,-3-7,-2-7,-1-7,0-7,1-7,2-7,3-7,4-7,5-7,6-7,7-7,8-7,9-7,10-7,11-6,-13-6,-12-6,-11-6,-10-6,-9-6,-8-6,-7-6,-6-6,-5-6,-4-6,-3-6,-2-6,-1-6,0-6,1-6,2-6,3-6,4-6,5-6,6-6,7-6,8-6,9-6,10-6,11-5,-13-5,-12-5,-11-5,-10-5,-9-5,-8-5,-7-5,-6-5,-5-5,-4-5,-3-5,-2-5,-1-5,0-5,1-5,2-5,3-5,4-5,5-5,6-5,7-5,8-5,9-5,10-5,11-4,-13-4,-12-4,-11-4,-10-4,-9-4,-8-4,-7-4,-6-4,-5-4,-4-4,-3-4,-2-4,-1-4,0-4,1-4,2-4,3-4,4-4,5-4,6-4,7-4,8-4,9-4,10-4,11-3,-13-3,-12-3,-11-3,-10-3,-9-3,-8-3,-7-3,-6-3,-5-3,-4-3,-3-3,-2-3,-1-3,0-3,1-3,2-3,3-3,4-3,5-3,6-3,7-3,8-3,9-3,10-3,11-2,-13-2,-12-2,-11-2,-10-2,-9-2,-8-2,-7-2,-6-2,-5-2,-4-2,-3-2,-2-2,-1-2,0-2,1-2,2-2,3-2,4-2,5-2,6-2,7-2,8-2,9-2,10-2,11-1,-13-1,-12-1,-11-1,-10-1,-9-1,-8-1,-7-1,-6-1,-5-1,-4-1,-3-1,-2-1,-1-1,0-1,1-1,2-1,3-1,4-1,5-1,6-1,7-1,8-1,9-1,10-1,110,-130,-120,-110,-100,-90,-80,-70,-60,-50,-40,-30,-20,-10,00,10,20,30,40,50,60,70,80,90,100,111,-131,-121,-111,-101,-91,-81,-71,-61,-51,-41,-31,-21,-11,01,11,21,31,41,51,61,71,81,91,101,112,-132,-122,-112,-102,-92,-82,-72,-62,-52,-42,-32,-22,-12,02,12,22,32,42,52,62,72,82,92,102,113,-133,-123,-113,-103,-93,-83,-73,-63,-53,-43,-33,-23,-13,03,13,23,33,43,53,63,73,83,93,103,114,-134,-124,-114,-104,-94,-84,-74,-64,-54,-44,-34,-24,-14,04,14,24,34,44,54,64,74,84,94,104,115,-135,-125,-115,-105,-95,-85,-75,-65,-55,-45,-35,-25,-15,05,15,25,35,45,55,65,75,85,95,105,116,-136,-126,-116,-106,-96,-86,-76,-66,-56,-46,-36,-26,-16,06,16,26,36,46,56,66,76,86,96,106,117,-137,-127,-117,-107,-97,-87,-77,-67,-57,-47,-37,-27,-17,07,17,27,37,47,57,67,77,87,97,107,118,-138,-128,-118,-108,-98,-88,-78,-68,-58,-48,-38,-28,-18,08,18,28,38,48,58,68,78,88,98,108,119,-139,-129,-119,-109,-99,-89,-79,-69,-59,-49,-39,-29,-19,09,19,29,39,49,59,69,79,89,99,109,1110,-1310,-1210,-1110,-1010,-910,-810,-710,-610,-510,-410,-310,-210,-110,010,110,210,310,410,510,610,710,810,910,1010,1111,-1311,-1211,-1111,-1011,-911,-811,-711,-611,-511,-411,-311,-211,-111,011,111,211,311,411,511,611,711,811,911,1011,1112,-1312,-1212,-1112,-1012,-912,-812,-712,-612,-512,-412,-312,-212,-112,012,112,212,312,412,512,612,712,812,912,1012,1113,-1313,-1213,-1113,-1013,-913,-813,-713,-613,-513,-413,-313,-213,-113,013,113,213,313,413,513,613,713,813,913,1013,1114,-1314,-1214,-1114,-1014,-914,-814,-714,-614,-514,-414,-314,-214,-114,014,114,214,314,414,514,614,714,814,914,1014,1115,-1315,-1215,-1115,-1015,-915,-815,-715,-615,-515,-415,-315,-215,-115,015,115,215,315,415,515,615,715,815,915,1015,1116,-1316,-1216,-1116,-1016,-916,-816,-716,-616,-516,-416,-316,-216,-116,016,116,216,316,416,516,616,716,816,916,1016,1117,-1317,-1217,-1117,-1017,-917,-817,-717,-617,-517,-417,-317,-217,-117,017,117,217,317,417,517,617,717,817,917,1017,11112233445566AABBCCDDR11kΩR21kΩ \ No newline at end of file diff --git a/tests/groups/__snapshots__/group-schematic-matchpack-nested-pcb-groups2-schematic_stacked.snap.svg b/tests/groups/__snapshots__/group-schematic-matchpack-nested-pcb-groups2-schematic_stacked.snap.svg new file mode 100644 index 0000000000..7cc8d0709f --- /dev/null +++ b/tests/groups/__snapshots__/group-schematic-matchpack-nested-pcb-groups2-schematic_stacked.snap.svg @@ -0,0 +1,23 @@ +power-16,-13-16,-12-16,-11-16,-10-16,-9-16,-8-16,-7-16,-6-16,-5-16,-4-16,-3-16,-2-16,-1-16,0-16,1-16,2-16,3-16,4-16,5-16,6-16,7-16,8-16,9-16,10-16,11-15,-13-15,-12-15,-11-15,-10-15,-9-15,-8-15,-7-15,-6-15,-5-15,-4-15,-3-15,-2-15,-1-15,0-15,1-15,2-15,3-15,4-15,5-15,6-15,7-15,8-15,9-15,10-15,11-14,-13-14,-12-14,-11-14,-10-14,-9-14,-8-14,-7-14,-6-14,-5-14,-4-14,-3-14,-2-14,-1-14,0-14,1-14,2-14,3-14,4-14,5-14,6-14,7-14,8-14,9-14,10-14,11-13,-13-13,-12-13,-11-13,-10-13,-9-13,-8-13,-7-13,-6-13,-5-13,-4-13,-3-13,-2-13,-1-13,0-13,1-13,2-13,3-13,4-13,5-13,6-13,7-13,8-13,9-13,10-13,11-12,-13-12,-12-12,-11-12,-10-12,-9-12,-8-12,-7-12,-6-12,-5-12,-4-12,-3-12,-2-12,-1-12,0-12,1-12,2-12,3-12,4-12,5-12,6-12,7-12,8-12,9-12,10-12,11-11,-13-11,-12-11,-11-11,-10-11,-9-11,-8-11,-7-11,-6-11,-5-11,-4-11,-3-11,-2-11,-1-11,0-11,1-11,2-11,3-11,4-11,5-11,6-11,7-11,8-11,9-11,10-11,11-10,-13-10,-12-10,-11-10,-10-10,-9-10,-8-10,-7-10,-6-10,-5-10,-4-10,-3-10,-2-10,-1-10,0-10,1-10,2-10,3-10,4-10,5-10,6-10,7-10,8-10,9-10,10-10,11-9,-13-9,-12-9,-11-9,-10-9,-9-9,-8-9,-7-9,-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30,40,50,60,70,80,90,100,111,-131,-121,-111,-101,-91,-81,-71,-61,-51,-41,-31,-21,-11,01,11,21,31,41,51,61,71,81,91,101,112,-132,-122,-112,-102,-92,-82,-72,-62,-52,-42,-32,-22,-12,02,12,22,32,42,52,62,72,82,92,102,113,-133,-123,-113,-103,-93,-83,-73,-63,-53,-43,-33,-23,-13,03,13,23,33,43,53,63,73,83,93,103,114,-134,-124,-114,-104,-94,-84,-74,-64,-54,-44,-34,-24,-14,04,14,24,34,44,54,64,74,84,94,104,115,-135,-125,-115,-105,-95,-85,-75,-65,-55,-45,-35,-25,-15,05,15,25,35,45,55,65,75,85,95,105,116,-136,-126,-116,-106,-96,-86,-76,-66,-56,-46,-36,-26,-16,06,16,26,36,46,56,66,76,86,96,106,117,-137,-127,-117,-107,-97,-87,-77,-67,-57,-47,-37,-27,-17,07,17,27,37,47,57,67,77,87,97,107,118,-138,-128,-118,-108,-98,-88,-78,-68,-58,-48,-38,-28,-18,08,18,28,38,48,58,68,78,88,98,108,119,-139,-129,-119,-109,-99,-89,-79,-69,-59,-49,-39,-29,-19,09,19,29,39,49,59,69,79,89,99,109,1110,-1310,-1210,-1110,-1010,-910,-810,-710,-610,-510,-410,-310,-210,-110,010,110,210,310,410,510,610,710,810,910,1010,1111,-1311,-1211,-1111,-1011,-911,-811,-711,-611,-511,-411,-311,-211,-111,011,111,211,311,411,511,611,711,811,911,1011,1112,-1312,-1212,-1112,-1012,-912,-812,-712,-612,-512,-412,-312,-212,-112,012,112,212,312,412,512,612,712,812,912,1012,1113,-1313,-1213,-1113,-1013,-913,-813,-713,-613,-513,-413,-313,-213,-113,013,113,213,313,413,513,613,713,813,913,1013,1114,-1314,-1214,-1114,-1014,-914,-814,-714,-614,-514,-414,-314,-214,-114,014,114,214,314,414,514,614,714,814,914,1014,1115,-1315,-1215,-1115,-1015,-915,-815,-715,-615,-515,-415,-315,-215,-115,015,115,215,315,415,515,615,715,815,915,1015,1116,-1316,-1216,-1116,-1016,-916,-816,-716,-616,-516,-416,-316,-216,-116,016,116,216,316,416,516,616,716,816,916,1016,1117,-1317,-1217,-1117,-1017,-917,-817,-717,-617,-517,-417,-317,-217,-117,017,117,217,317,417,517,617,717,817,917,1017,1118,-1318,-1218,-1118,-1018,-918,-818,-718,-618,-518,-418,-318,-218,-118,018,118,218,318,418,518,618,718,818,918,1018,11112233445566AABBCCDDR11kΩC1100nFR22.2kΩio-17,-12-17,-11-17,-10-17,-9-17,-8-17,-7-17,-6-17,-5-17,-4-17,-3-17,-2-17,-1-17,0-17,1-17,2-17,3-17,4-17,5-17,6-17,7-17,8-17,9-17,10-17,11-17,12-16,-12-16,-11-16,-10-16,-9-16,-8-16,-7-16,-6-16,-5-16,-4-16,-3-16,-2-16,-1-16,0-16,1-16,2-16,3-16,4-16,5-16,6-16,7-16,8-16,9-16,10-16,11-16,12-15,-12-15,-11-15,-10-15,-9-15,-8-15,-7-15,-6-15,-5-15,-4-15,-3-15,-2-15,-1-15,0-15,1-15,2-15,3-15,4-15,5-15,6-15,7-15,8-15,9-15,10-15,11-15,12-14,-12-14,-11-14,-10-14,-9-14,-8-14,-7-14,-6-14,-5-14,-4-14,-3-14,-2-14,-1-14,0-14,1-14,2-14,3-14,4-14,5-14,6-14,7-14,8-14,9-14,10-14,11-14,12-13,-12-13,-11-13,-10-13,-9-13,-8-13,-7-13,-6-13,-5-13,-4-13,-3-13,-2-13,-1-13,0-13,1-13,2-13,3-13,4-13,5-13,6-13,7-13,8-13,9-13,10-13,11-13,12-12,-12-12,-11-12,-10-12,-9-12,-8-12,-7-12,-6-12,-5-12,-4-12,-3-12,-2-12,-1-12,0-12,1-12,2-12,3-12,4-12,5-12,6-12,7-12,8-12,9-12,10-12,11-12,12-11,-12-11,-11-11,-10-11,-9-11,-8-11,-7-11,-6-11,-5-11,-4-11,-3-11,-2-11,-1-11,0-11,1-11,2-11,3-11,4-11,5-11,6-11,7-11,8-11,9-11,10-11,11-11,12-10,-12-10,-11-10,-10-10,-9-10,-8-10,-7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1,-3-1,-2-1,-1-1,0-1,1-1,2-1,3-1,4-1,5-1,6-1,7-1,8-1,9-1,10-1,11-1,120,-120,-110,-100,-90,-80,-70,-60,-50,-40,-30,-20,-10,00,10,20,30,40,50,60,70,80,90,100,110,121,-121,-111,-101,-91,-81,-71,-61,-51,-41,-31,-21,-11,01,11,21,31,41,51,61,71,81,91,101,111,122,-122,-112,-102,-92,-82,-72,-62,-52,-42,-32,-22,-12,02,12,22,32,42,52,62,72,82,92,102,112,123,-123,-113,-103,-93,-83,-73,-63,-53,-43,-33,-23,-13,03,13,23,33,43,53,63,73,83,93,103,113,124,-124,-114,-104,-94,-84,-74,-64,-54,-44,-34,-24,-14,04,14,24,34,44,54,64,74,84,94,104,114,125,-125,-115,-105,-95,-85,-75,-65,-55,-45,-35,-25,-15,05,15,25,35,45,55,65,75,85,95,105,115,126,-126,-116,-106,-96,-86,-76,-66,-56,-46,-36,-26,-16,06,16,26,36,46,56,66,76,86,96,106,116,127,-127,-117,-107,-97,-87,-77,-67,-57,-47,-37,-27,-17,07,17,27,37,47,57,67,77,87,97,107,117,128,-128,-118,-108,-98,-88,-78,-68,-58,-48,-38,-28,-18,08,18,28,38,48,58,68,78,88,98,108,118,129,-129,-119,-109,-99,-89,-79,-69,-59,-49,-39,-29,-19,09,19,29,39,49,59,69,79,89,99,109,119,1210,-1210,-1110,-1010,-910,-810,-710,-610,-510,-410,-310,-210,-110,010,110,210,310,410,510,610,710,810,910,1010,1110,1211,-1211,-1111,-1011,-911,-811,-711,-611,-511,-411,-311,-211,-111,011,111,211,311,411,511,611,711,811,911,1011,1111,1212,-1212,-1112,-1012,-912,-812,-712,-612,-512,-412,-312,-212,-112,012,112,212,312,412,512,612,712,812,912,1012,1112,1213,-1213,-1113,-1013,-913,-813,-713,-613,-513,-413,-313,-213,-113,013,113,213,313,413,513,613,713,813,913,1013,1113,1214,-1214,-1114,-1014,-914,-814,-714,-614,-514,-414,-314,-214,-114,014,114,214,314,414,514,614,714,814,914,1014,1114,1215,-1215,-1115,-1015,-915,-815,-715,-615,-515,-415,-315,-215,-115,015,115,215,315,415,515,615,715,815,915,1015,1115,1216,-1216,-1116,-1016,-916,-816,-716,-616,-516,-416,-316,-216,-116,016,116,216,316,416,516,616,716,816,916,1016,1116,1217,-1217,-1117,-1017,-917,-817,-717,-617,-517,-417,-317,-217,-117,017,117,217,317,417,517,617,717,817,917,1017,1117,12112233445566AABBCCDDR310kΩ \ No newline at end of file diff --git a/tests/groups/group-schematic-matchpack-nested-pcb-groups1.test.tsx b/tests/groups/group-schematic-matchpack-nested-pcb-groups1.test.tsx new file mode 100644 index 0000000000..9bd25476f1 --- /dev/null +++ b/tests/groups/group-schematic-matchpack-nested-pcb-groups1.test.tsx @@ -0,0 +1,70 @@ +import { expect, test } from "bun:test" +import { getTestFixture } from "tests/fixtures/get-test-fixture" + +test("schematic auto-layout separates groups nested under separate PCB groups", async () => { + const { circuit } = getTestFixture() + + circuit.add( + + + + + + + + + + + + + , + ) + + await circuit.renderUntilSettled() + + const r1Source = circuit.db.source_component.getWhere({ name: "R1" })! + const r2Source = circuit.db.source_component.getWhere({ name: "R2" })! + const r1Sch = circuit.db.schematic_component.getWhere({ + source_component_id: r1Source.source_component_id, + })! + const r2Sch = circuit.db.schematic_component.getWhere({ + source_component_id: r2Source.source_component_id, + })! + const r1Pcb = circuit.db.pcb_component.getWhere({ + source_component_id: r1Source.source_component_id, + })! + const r2Pcb = circuit.db.pcb_component.getWhere({ + source_component_id: r2Source.source_component_id, + })! + const groupA = circuit.db.source_group.getWhere({ name: "A" })! + const groupB = circuit.db.source_group.getWhere({ name: "B" })! + const schGroupA = circuit.db.schematic_group.getWhere({ + source_group_id: groupA.source_group_id, + })! + const schGroupB = circuit.db.schematic_group.getWhere({ + source_group_id: groupB.source_group_id, + })! + + expect( + Math.hypot( + r1Sch.center.x - r2Sch.center.x, + r1Sch.center.y - r2Sch.center.y, + ), + ).toBeGreaterThan(1) + expect(schGroupA.center).toEqual(r1Sch.center) + expect(schGroupB.center).toEqual(r2Sch.center) + expect(r1Pcb.center.x).toBeCloseTo(-6, 3) + expect(r2Pcb.center.x).toBeCloseTo(6, 3) + + await expect(circuit).toMatchSchematicSnapshot(import.meta.path) +}) diff --git a/tests/groups/group-schematic-matchpack-nested-pcb-groups2.test.tsx b/tests/groups/group-schematic-matchpack-nested-pcb-groups2.test.tsx new file mode 100644 index 0000000000..79c43aba68 --- /dev/null +++ b/tests/groups/group-schematic-matchpack-nested-pcb-groups2.test.tsx @@ -0,0 +1,84 @@ +import { expect, test } from "bun:test" +import { getTestFixture } from "tests/fixtures/get-test-fixture" + +test("multi-sheet schematic auto-layout scopes nested PCB groups to each sheet", async () => { + const { circuit } = getTestFixture() + + circuit.add( + + + + + + + + + + + + + + + + + + + , + ) + + await circuit.renderUntilSettled() + + const getSchComp = (name: string) => { + const source = circuit.db.source_component.getWhere({ name })! + return circuit.db.schematic_component.getWhere({ + source_component_id: source.source_component_id, + })! + } + + const r1 = getSchComp("R1") + const c1 = getSchComp("C1") + const r2 = getSchComp("R2") + const r3 = getSchComp("R3") + const powerSheet = circuit.db.schematic_sheet.getWhere({ name: "power" })! + const ioSheet = circuit.db.schematic_sheet.getWhere({ name: "io" })! + + expect(r1.schematic_sheet_id).toBe(powerSheet.schematic_sheet_id) + expect(c1.schematic_sheet_id).toBe(powerSheet.schematic_sheet_id) + expect(r2.schematic_sheet_id).toBe(powerSheet.schematic_sheet_id) + expect(r3.schematic_sheet_id).toBe(ioSheet.schematic_sheet_id) + + // R1 and C1 remain separated inside A, and B (R2) does not overlap either of them. + expect( + Math.hypot(r1.center.x - c1.center.x, r1.center.y - c1.center.y), + ).toBeGreaterThan(1) + expect( + Math.hypot(r2.center.x - r1.center.x, r2.center.y - r1.center.y), + ).toBeGreaterThan(1) + expect( + Math.hypot(r2.center.x - c1.center.x, r2.center.y - c1.center.y), + ).toBeGreaterThan(1) + // R3 is the sole component on the "io" sheet and stays unaffected by "power" sheet layout. + expect(r3.center).toEqual({ x: 0, y: 0 }) + + await expect(circuit).toMatchStackedSchematicSnapshot(import.meta.path) +})