(layoutBase: IEditSnapshot, ls: ILSState, compLibrary: CompLibrary)
| 300 | } |
| 301 | |
| 302 | export function wiresFromLsState(layoutBase: IEditSnapshot, ls: ILSState, compLibrary: CompLibrary): IEditSnapshot { |
| 303 | |
| 304 | let wireIdx = 0; |
| 305 | let newWires: IWireGraph[] = ls.wires.map(w => ({ |
| 306 | id: '' + wireIdx++, |
| 307 | nodes: w.nodes.map(n => ({ |
| 308 | id: n.id, |
| 309 | pos: new Vec3(n.x, n.y), |
| 310 | edges: n.edges, |
| 311 | ref: n.ref, |
| 312 | })), |
| 313 | })); |
| 314 | |
| 315 | let maxWireId = 0; |
| 316 | for (let w of newWires) { |
| 317 | maxWireId = Math.max(maxWireId, parseInt(w.id)); |
| 318 | } |
| 319 | |
| 320 | checkWires(newWires, 'wiresFromLsState'); |
| 321 | |
| 322 | let lsCompLookup = new Map<string, ILSComp>(); |
| 323 | for (let c of ls.comps) { |
| 324 | lsCompLookup.set(c.id, c); |
| 325 | } |
| 326 | |
| 327 | let comps: IComp[] = ls.comps.map(c => { |
| 328 | let comp = compLibrary.create(c.defId, c.args); |
| 329 | |
| 330 | comp.id = c.id; |
| 331 | comp.pos = new Vec3(c.x, c.y); |
| 332 | comp.subSchematicId = c.subSchematicId; |
| 333 | |
| 334 | return comp; |
| 335 | }); |
| 336 | |
| 337 | let maxCompId = 0; |
| 338 | for (let c of comps) { |
| 339 | maxCompId = Math.max(maxCompId, parseInt(c.id)); |
| 340 | } |
| 341 | |
| 342 | return assignImm(layoutBase, { |
| 343 | mainSchematic: assignImm(layoutBase.mainSchematic, { |
| 344 | nextWireId: maxWireId + 1, |
| 345 | nextCompId: maxCompId + 1, |
| 346 | parentCompDefId: ls.parentCompDefId, |
| 347 | wires: newWires, |
| 348 | comps: comps, |
| 349 | }), |
| 350 | }); |
| 351 | } |
| 352 | |
| 353 | export function schematicToLsState(layout: ISchematic): ILSState { |
| 354 | return { |
no test coverage detected