-
Notifications
You must be signed in to change notification settings - Fork 41
New component SchematicBox #823
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
+195
−52
Closed
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
be5dab7
New component SchematicBox
Abse2001 16f1457
spelling mistake
Abse2001 b2ed1f1
another one
Abse2001 c2e2455
update
Abse2001 a57c241
Merge branch 'main' into main
Abse2001 e122d32
?
Abse2001 aea88d8
//////////:
Abse2001 f5674b7
what is life
Abse2001 fd57f78
Im not sure
Abse2001 6b613dc
wip
Abse2001 df49df9
Update SchematicBox.ts
Abse2001 9c17e25
Update SchematicBox.ts
Abse2001 ac459e6
wip
Abse2001 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,89 @@ | ||
import { PrimitiveComponent } from "../base-components/PrimitiveComponent" | ||
import { schematicBoxProps } from "@tscircuit/props" | ||
import type { Port } from "./Port" | ||
|
||
export class SchematicBox extends PrimitiveComponent<typeof schematicBoxProps> { | ||
isSchematicPrimitive = true | ||
|
||
get config() { | ||
return { | ||
componentName: "SchematicSection", | ||
zodProps: schematicBoxProps, | ||
shouldRenderAsSchematicBox: true, | ||
} | ||
} | ||
|
||
doInitialSchematicPrimitiveRender(): void { | ||
if (this.root?.schematicDisabled) return | ||
const { db } = this.root! | ||
const { _parsedProps: props } = this | ||
let portsWithSelectors: Array<{ selector: string; port: Port }> = [] | ||
if (props.overlay) { | ||
portsWithSelectors = props.overlay.map((selector) => ({ | ||
selector, | ||
port: | ||
(this.getSubcircuit().selectOne(selector, { | ||
type: "port", | ||
}) as Port) ?? null, | ||
})) | ||
} | ||
const portsWithPosition = portsWithSelectors.map(({ port }) => ({ | ||
port, | ||
position: port._getGlobalSchematicPositionAfterLayout(), | ||
schematic_port_id: port.schematic_port_id!, | ||
facingDirection: port.facingDirection, | ||
})) | ||
if (portsWithPosition.length > 0) { | ||
const basePadding = 0.6 | ||
const xs = portsWithPosition.map((p) => p.position.x) | ||
const ys = portsWithPosition.map((p) => p.position.y) | ||
|
||
const minX = Math.min(...xs) | ||
const maxX = Math.max(...xs) | ||
const minY = Math.min(...ys) | ||
const maxY = Math.max(...ys) | ||
|
||
const rawWidth = maxX - minX | ||
const rawHeight = maxY - minY | ||
|
||
let widthPadding: number | ||
let heightPadding: number | ||
|
||
if (rawWidth > rawHeight) { | ||
// Horizontal row → more vertical padding | ||
widthPadding = basePadding / 2 | ||
heightPadding = basePadding | ||
} else { | ||
// Vertical column → more horizontal padding | ||
widthPadding = basePadding | ||
heightPadding = basePadding / 2 | ||
} | ||
|
||
const width = rawWidth + widthPadding | ||
const height = rawHeight + heightPadding | ||
|
||
const x = minX - widthPadding / 2 | ||
const y = minY - heightPadding / 2 | ||
|
||
db.schematic_box.insert({ | ||
height, | ||
width, | ||
x, | ||
y, | ||
is_dashed: props.strokeStyle === "dashed", | ||
schematic_component_id: "", | ||
}) | ||
|
||
console.log({ rawWidth, rawHeight, width, height }) | ||
|
||
db.schematic_box.insert({ | ||
height, | ||
width, | ||
x, | ||
y, | ||
is_dashed: props.strokeStyle === "dashed", | ||
schematic_component_id: "", | ||
}) | ||
} | ||
} | ||
} |
This file contains hidden or 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 hidden or 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 hidden or 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,27 @@ | ||
import { expect, it } from "bun:test" | ||
import { InvalidProps } from "lib/errors/InvalidProps" | ||
import "lib/register-catalogue" | ||
import { getTestFixture } from "tests/fixtures/get-test-fixture" | ||
|
||
it("Chip with pinrow footprint", async () => { | ||
const { circuit } = getTestFixture() | ||
|
||
circuit.add( | ||
<board width="10mm" height="10mm"> | ||
<chip name="U1" footprint={"soic8"} /> | ||
<chip name="U2" footprint={"soic8"} schX={2} /> | ||
<schematicbox | ||
height={0} | ||
width={2} | ||
overlay={[".U1 > .pin1", ".U1 > .pin2", ".U1 > .pin3", ".U1 > .pin4"]} | ||
schX={0} | ||
schY={0} | ||
/> | ||
</board>, | ||
) | ||
|
||
circuit.render() | ||
console.log( | ||
circuit.getCircuitJson().find((el) => el.type === "schematic_box"), | ||
) | ||
}) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.