Skip to content

Commit

Permalink
fix: Merge pull request #26 from tscircuit/schematic-path
Browse files Browse the repository at this point in the history
Schematic Path Support
  • Loading branch information
seveibar committed Mar 27, 2024
2 parents f942356 + 314d99c commit f3c38e0
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 1 deletion.
34 changes: 34 additions & 0 deletions src/lib/builder/schematic-symbol-builder/schematic-path-builder.ts
@@ -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
}
Expand Up @@ -13,11 +13,13 @@ import {
SchematicTextBuilder,
createSchematicTextBuilder,
} from "./schematic-text-builder"
import { createSchematicPathBuilder } from "./schematic-path-builder"

const schematic_symbol_addables = {
schematic_box: createSchematicBoxBuilder,
schematic_line: createSchematicLineBuilder,
schematic_text: createSchematicTextBuilder,
schematic_path: createSchematicPathBuilder,
}

type SchematicSymbolAddables = typeof schematic_symbol_addables
Expand Down
2 changes: 2 additions & 0 deletions src/lib/soup/index.ts
@@ -1,2 +1,4 @@
export * from "./units"
export * from "./common"
export * from "./source"
export * from "./schematic"
2 changes: 2 additions & 0 deletions src/lib/soup/schematic/index.ts
@@ -0,0 +1,2 @@
export * from "./schematic_box"
export * from "./schematic_path"
12 changes: 12 additions & 0 deletions src/lib/soup/schematic/schematic_path.ts
@@ -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>
2 changes: 2 additions & 0 deletions src/lib/soup/source/index.ts
@@ -0,0 +1,2 @@
export * from "./source_simple_capacitor"
export * from "./source_simple_resistor"
2 changes: 1 addition & 1 deletion src/lib/soup/source/source_simple_capacitor.ts
Expand Up @@ -2,7 +2,7 @@ import { z } from "zod"
import { source_component_base } from "lib/soup/source/base/source_component_base"
import { capacitance } from "lib/soup/units"

export const source_simple_resistor = source_component_base.extend({
export const source_simple_capacitor = source_component_base.extend({
ftype: z.literal("simple_capacitor"),
capacitance,
})
2 changes: 2 additions & 0 deletions src/lib/types/core.ts
Expand Up @@ -127,6 +127,8 @@ export interface SchematicText {
anchor: "center" | "left" | "right" | "top" | "bottom"
}

export type SchematicPath = Soup.SchematicPath

export interface SchematicPort {
type: "schematic_port"
schematic_port_id: string
Expand Down
23 changes: 23 additions & 0 deletions tests/primitives/schematic-path.test.ts
@@ -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()
})

0 comments on commit f3c38e0

Please sign in to comment.