adapted wire stubs with auto side detection
This commit is contained in:
parent
5616544707
commit
26231b2f48
Binary file not shown.
@ -14,24 +14,10 @@
|
|||||||
debug: (ports: true)
|
debug: (ports: true)
|
||||||
)
|
)
|
||||||
|
|
||||||
element.block(
|
|
||||||
size: (1, 2),
|
|
||||||
ports: (
|
|
||||||
west: (("a", "A"), "e"),
|
|
||||||
north: "b",
|
|
||||||
east: "c",
|
|
||||||
south: "d"
|
|
||||||
),
|
|
||||||
pos: (
|
|
||||||
(offset: -1, from: "PCBuf.south"),
|
|
||||||
2,//(align: "e", with: "PCBuf.EN"),
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
/*
|
|
||||||
wire.stub("PCBuf.CLK", name: "CLK")
|
wire.stub("PCBuf.CLK", name: "CLK")
|
||||||
wire.stub("PCBuf.EN", name: "PCWrite")
|
wire.stub("PCBuf.EN", name: "PCWrite")
|
||||||
|
|
||||||
|
/*
|
||||||
element.multiplexer(
|
element.multiplexer(
|
||||||
pos: (
|
pos: (
|
||||||
3, (align: "in0", with: "PCBuf.PC")
|
3, (align: "in0", with: "PCBuf.PC")
|
||||||
|
11
src/util.typ
11
src/util.typ
@ -74,3 +74,14 @@
|
|||||||
"center", "north", "east", "west", "south",
|
"center", "north", "east", "west", "south",
|
||||||
"north-east", "north-west", "south-east", "south-west"
|
"north-east", "north-west", "south-east", "south-west"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
#let get-port-side(element, port) = {
|
||||||
|
for (side, ports) in element.ports {
|
||||||
|
for p in ports {
|
||||||
|
if p.id == port {
|
||||||
|
return side
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
panic("Unknown port " + port + " on element " + element.id)
|
||||||
|
}
|
103
src/wire.typ
103
src/wire.typ
@ -1,5 +1,6 @@
|
|||||||
#import "@preview/cetz:0.3.2": draw, coordinate
|
#import "@preview/cetz:0.3.2": draw, coordinate
|
||||||
#import "util.typ": opposite-anchor
|
#import "util.typ": opposite-anchor, get-port-side
|
||||||
|
#import "elements/element.typ"
|
||||||
|
|
||||||
/// List of valid wire styles
|
/// List of valid wire styles
|
||||||
/// #examples.wires
|
/// #examples.wires
|
||||||
@ -267,40 +268,70 @@
|
|||||||
/// - vertical (bool): Whether the name should be displayed vertically
|
/// - vertical (bool): Whether the name should be displayed vertically
|
||||||
/// - length (number): The length of the stub
|
/// - length (number): The length of the stub
|
||||||
/// - name-offset (number): The name offset, perpendicular to the stub
|
/// - name-offset (number): The name offset, perpendicular to the stub
|
||||||
#let stub(port-id, side, name: none, vertical: false, length: 1em, name-offset: 0) = {
|
#let stub(anchor, name: none, vertical: false, length: 1em, name-offset: 0) = {
|
||||||
let end-offset = (
|
if "." not in anchor {
|
||||||
north: (0, length),
|
panic("`anchor` must be a valid anchor of an element")
|
||||||
east: (length, 0),
|
|
||||||
south: (0, -length),
|
|
||||||
west: (-length, 0)
|
|
||||||
).at(side)
|
|
||||||
|
|
||||||
let name-offset = (
|
|
||||||
north: (name-offset, length),
|
|
||||||
east: (length, name-offset),
|
|
||||||
south: (name-offset, -length),
|
|
||||||
west: (-length, name-offset)
|
|
||||||
).at(side)
|
|
||||||
|
|
||||||
draw.line(
|
|
||||||
port-id,
|
|
||||||
(rel: end-offset, to: port-id)
|
|
||||||
)
|
|
||||||
if name != none {
|
|
||||||
let text-anchor = if vertical {
|
|
||||||
(
|
|
||||||
"north": "west",
|
|
||||||
"south": "east",
|
|
||||||
"west": "south",
|
|
||||||
"east": "north"
|
|
||||||
).at(side)
|
|
||||||
} else { opposite-anchor(side) }
|
|
||||||
draw.content(
|
|
||||||
anchor: text-anchor,
|
|
||||||
padding: 0.2em,
|
|
||||||
angle: if vertical {90deg} else {0deg},
|
|
||||||
(rel: name-offset, to: port-id),
|
|
||||||
name
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
let parts = anchor.split(".")
|
||||||
|
let port-id = parts.last()
|
||||||
|
let port-elmt-id = parts.slice(0, -1).join(".")
|
||||||
|
|
||||||
|
let pre-process = (elements, elmt) => {
|
||||||
|
let eid = elmt.id
|
||||||
|
|
||||||
|
if port-elmt-id not in elements {
|
||||||
|
panic("Unknown element " + port-elmt-id)
|
||||||
|
}
|
||||||
|
let port-elmt = elements.at(port-elmt-id)
|
||||||
|
let side = get-port-side(port-elmt, port-id)
|
||||||
|
elements.at(eid).insert("side", side)
|
||||||
|
return elements
|
||||||
|
}
|
||||||
|
|
||||||
|
let draw-func(elmt, bounds) = {
|
||||||
|
let side = elmt.side
|
||||||
|
let end-offset = (
|
||||||
|
north: (0, length),
|
||||||
|
east: (length, 0),
|
||||||
|
south: (0, -length),
|
||||||
|
west: (-length, 0)
|
||||||
|
).at(side)
|
||||||
|
|
||||||
|
let name-offset = (
|
||||||
|
north: (name-offset, length),
|
||||||
|
east: (length, name-offset),
|
||||||
|
south: (name-offset, -length),
|
||||||
|
west: (-length, name-offset)
|
||||||
|
).at(side)
|
||||||
|
|
||||||
|
let shapes = ()
|
||||||
|
shapes += draw.line(
|
||||||
|
anchor,
|
||||||
|
(rel: end-offset, to: anchor)
|
||||||
|
)
|
||||||
|
if name != none {
|
||||||
|
let text-anchor = if vertical {
|
||||||
|
(
|
||||||
|
"north": "west",
|
||||||
|
"south": "east",
|
||||||
|
"west": "south",
|
||||||
|
"east": "north"
|
||||||
|
).at(side)
|
||||||
|
} else { opposite-anchor(side) }
|
||||||
|
shapes += draw.content(
|
||||||
|
anchor: text-anchor,
|
||||||
|
padding: 0.2em,
|
||||||
|
angle: if vertical {90deg} else {0deg},
|
||||||
|
(rel: name-offset, to: anchor),
|
||||||
|
name
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
return (shapes, bounds)
|
||||||
|
}
|
||||||
|
|
||||||
|
return element.elmt(
|
||||||
|
draw-shape: draw-func,
|
||||||
|
pre-process: pre-process
|
||||||
|
)
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user