-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #69 from tscircuit/merge-dsn-session-parity
fix merge dsn session to have SVG parity
- Loading branch information
Showing
8 changed files
with
116 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
lib/dsn-pcb/circuit-json-to-dsn-json/process-pcb-traces/DsnTraceOperationsWrapper.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import type { DsnPcb, DsnSession, Wire } from "lib/dsn-pcb/types" | ||
|
||
export interface DsnTraceOperationsWrapper { | ||
getNextNetId(): string | ||
addWire(wire: Wire): void | ||
getLibrary(): DsnPcb["library"] | ||
getStructure(): DsnPcb["structure"] | null | ||
} | ||
|
||
/** | ||
* This operations wrapper allows you to operate on either DSN PCB or DSN | ||
* Session objects, increasing code reusability when working with traces. | ||
* | ||
* Please add more methods to this as you need them! | ||
*/ | ||
export const getDsnTraceOperationsWrapper = ( | ||
dsnObj: DsnPcb | DsnSession, | ||
): DsnTraceOperationsWrapper => { | ||
if (dsnObj.is_dsn_pcb) { | ||
return { | ||
getNextNetId: () => `Net-${dsnObj.network.nets.length + 1}`, | ||
addWire: (wire: Wire) => { | ||
dsnObj.wiring.wires.push(wire as any) | ||
}, | ||
getStructure: () => dsnObj.structure, | ||
getLibrary: () => dsnObj.library, | ||
} | ||
} | ||
|
||
if (dsnObj.is_dsn_session) { | ||
return { | ||
getNextNetId: () => `Net-${dsnObj.routes.network_out.nets.length + 1}`, | ||
getLibrary: () => dsnObj.routes.library_out!, | ||
getStructure: () => null, | ||
addWire: (wire: Wire) => { | ||
let net = dsnObj.routes.network_out.nets.find( | ||
(net) => net.name === wire.net, | ||
) | ||
if (!net) { | ||
net = { | ||
name: wire.net!, | ||
wires: [], | ||
} | ||
dsnObj.routes.network_out.nets.push(net) | ||
} | ||
net.wires.push(wire) | ||
}, | ||
} | ||
} | ||
|
||
throw new Error("Invalid DSN object") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters