Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Merge pull request #26 from tscircuit/schematic-path
Schematic Path Support
- Loading branch information
Showing
9 changed files
with
80 additions
and
1 deletion.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
src/lib/builder/schematic-symbol-builder/schematic-path-builder.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,34 @@ | ||
import { Dimension, SchematicPath } from "lib/types" | ||
import { ProjectBuilder } from "../project-builder" | ||
import { createSimpleDataBuilderClass } from "../simple-data-builder" | ||
|
||
export type SchematicPathBuilderFields = Partial< | ||
Omit<SchematicPath, "position"> & { | ||
position: { x: Dimension; y: Dimension } | ||
} | ||
> | ||
|
||
export interface SchematicPathBuilder { | ||
builder_type: "schematic_path_builder" | ||
props: SchematicPathBuilderFields | ||
setProps(props: Partial<SchematicPathBuilderFields>): SchematicPathBuilder | ||
build(): Omit<SchematicPathBuilderFields, "x" | "y"> & { | ||
x: Dimension | ||
y: Dimension | ||
} | ||
} | ||
|
||
export const SchematicPathBuilder = createSimpleDataBuilderClass( | ||
"schematic_path_builder", | ||
{ | ||
type: "schematic_path", | ||
points: [], | ||
} as SchematicPathBuilder["props"], | ||
["position"] | ||
) | ||
|
||
export const createSchematicPathBuilder = ( | ||
project_builder: ProjectBuilder | ||
): SchematicPathBuilder => { | ||
return new SchematicPathBuilder(project_builder) as any | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
export * from "./units" | ||
export * from "./common" | ||
export * from "./source" | ||
export * from "./schematic" |
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,2 @@ | ||
export * from "./schematic_box" | ||
export * from "./schematic_path" |
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,12 @@ | ||
import { z } from "zod" | ||
import { point } from "../common/point" | ||
|
||
export const schematic_path = z.object({ | ||
type: z.literal("schematic_path"), | ||
schematic_component_id: z.string(), | ||
fill_color: z.string().optional(), | ||
is_filled: z.boolean().optional(), | ||
points: z.array(point), | ||
}) | ||
|
||
export type SchematicPath = z.infer<typeof schematic_path> |
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,2 @@ | ||
export * from "./source_simple_capacitor" | ||
export * from "./source_simple_resistor" |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import test from "ava" | ||
import { createProjectBuilder } from "lib/builder" | ||
import { logLayout } from "../utils/log-layout" | ||
|
||
test("render a simple schematic path", async (t) => { | ||
const soup = await createProjectBuilder() | ||
.add("component", (cb) => | ||
cb.modifySchematic((sb) => | ||
sb.add("schematic_path", (sp) => | ||
sp.setProps({ | ||
points: [ | ||
{ x: 0, y: 0 }, | ||
{ x: 100, y: 100 }, | ||
], | ||
}) | ||
) | ||
) | ||
) | ||
.build() | ||
|
||
await logLayout("custom schematic symbol with path", soup) | ||
t.pass() | ||
}) |