Skip to content
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

Cja/update resistor capacitor symbols #165

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions examples/symbols/resistor.stanza
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,26 @@ pcb-component test-SMT:
val lp = create-landpattern(pkg)
assign-landpattern(lp)

pcb-component test-SMT-2:
reference-prefix = "R"
pin-properties :
[pin:Ref | pads:Ref ... | side:Dir | bank:Int]
[p[1] | p[1] | Up | 0]
[p[2] | p[2] | Down | 0]

val override = ResistorSymbolParams( style = OpenRectangle)
val symb = ResistorSymbol(params = One $ override)
assign-symbol(create-symbol(symb))
val chip-def = chips["1206"]
val pkg = SMT-Chip(
chip-def,
density-level = DensityLevelC
)

val lp = create-landpattern(pkg)
assign-landpattern(lp)


pcb-component test-Var-SMT:

pin-properties :
Expand Down Expand Up @@ -96,6 +116,7 @@ pcb-module test-design:
inst R2 : test-Var-SMT
inst R3 : test-Photo-SMT
inst R4 : test-Potentiometer
inst R5 : test-SMT-2

; Set the top level module (the module to be compile into a schematic and PCB)
set-current-design("Resistor-Symb-TEST")
Expand Down
156 changes: 80 additions & 76 deletions src/symbols/capacitors.stanza
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ defpackage jsl/symbols/capacitors:
import math
import jitx

import maybe-utils

import jsl/ensure
import jsl/design/Classable
import jsl/symbols/framework
Expand All @@ -13,44 +15,36 @@ val DEF_PORCH_WIDTH = (80 %)
val DEF_WIDTH = 1.5
val DEF_LINE_WIDTH = 0.05

doc: \<DOC>
Construct Parameter Set for a Non-Polarized Capacitor Symbol

Each keyword argument for this function has a default value
that can be overriden. These parameters are all of the
configurable aspects of the symbol.
<DOC>
public defstruct CapacitorSymbolParams <: Equalable :
doc: \<DOC>
The porch width is the length of line from the pin to the capacitor plate lines
This value can be either an absolute value in symbol grid units or it
can be a percentage of the `pitch / 2.0`.
<DOC>
porch-width:Double|Percentage with: (
ensure => ensure-positive!,
porch-width:Double|Percentage with:
ensure => ensure-positive!
updater => sub-porch-width
)
width:Double with: (
ensure => ensure-positive!,
updater => sub-width,
)
line-width:Double with: (
ensure => ensure-positive!,
default => DEF_PORCH_WIDTH
width:Double with:
ensure => ensure-positive!
updater => sub-width
default => DEF_WIDTH
line-width:Double with:
ensure => ensure-positive!
updater => sub-line-width
)
default => DEF_LINE_WIDTH
with:
constructor => #CapacitorSymbolParams
keyword-constructor => true
equalable => true
printer => true

doc: \<DOC>
Construct Parameter Set for a Non-Polarized Capacitor Symbol

Each keyword argument for this function has a default value
that can be overriden. These parameters are all of the
configurable aspects of the symbol.
<DOC>
public defn CapacitorSymbolParams (
--
porch-width:Double|Percentage = DEF_PORCH_WIDTH
width:Double = DEF_WIDTH
line-width:Double = DEF_LINE_WIDTH
) -> CapacitorSymbolParams :
#CapacitorSymbolParams(porch-width, width, line-width)

public defn to-tuple (p:CapacitorSymbolParams) -> [Double|Percentage, Double, Double] :
[porch-width(p), width(p), line-width(p)]

Expand All @@ -70,54 +64,49 @@ val DEF_POL_STYLE = Polarized-Straight-Style
val DEF_POL_RADIUS = 5.0
val DEF_PLUS_SIZE = (20 %)

doc: \<DOC>
Construct Parameter Set for PolCap Symbol Shape

The parameters of this function are the configurable
features of a Polarized Capacitor's default symbol shape.
Each argument has a default value that can be overriden.
<DOC>
public defstruct PolarizedCapacitorSymbolParams <: CapacitorSymbolParams :
style:PolarizedStyle
style:PolarizedStyle with:
default => DEF_POL_STYLE
doc: \<DOC>
The porch width is the length of line from the pin to the capacitor plate lines
This value can be either an absolute value in symbol grid units or it
can be a percentage of the `pitch / 2.0`.
<DOC>
porch-width:Double|Percentage with:
ensure => ensure-positive!,
updater => sub-porch-width,
ensure => ensure-positive!
updater => sub-porch-width
as-method => true
default => DEF_PORCH_WIDTH
width:Double with:
ensure => ensure-positive!,
updater => sub-width,
ensure => ensure-positive!
updater => sub-width
as-method => true
default => DEF_WIDTH
line-width:Double with:
ensure => ensure-positive!,
ensure => ensure-positive!
updater => sub-line-width
as-method => true
default => DEF_LINE_WIDTH
pol-radius:Double with:
ensure => ensure-positive!,
updater => sub-pol-radius,
ensure => ensure-positive!
updater => sub-pol-radius
default => DEF_POL_RADIUS
plus-size:Double|Percentage with:
ensure => ensure-positive!,
ensure => ensure-positive!
updater => sub-plus-size
default => DEF_PLUS_SIZE
with:
constructor => #PolarizedCapacitorSymbolParams
keyword-constructor => true
equalable => true
printer => true

doc: \<DOC>
Construct Parameter Set for PolCap Symbol Shape

The parameters of this function are the configurable
features of a Polarized Capacitor's default symbol shape.
Each argument has a default value that can be overriden.
<DOC>
public defn PolarizedCapacitorSymbolParams (
--
style:PolarizedStyle = DEF_POL_STYLE
porch-width:Double|Percentage = DEF_PORCH_WIDTH
width:Double = DEF_WIDTH
line-width:Double = DEF_LINE_WIDTH
pol-radius:Double = DEF_POL_RADIUS
plus-size:Double|Percentage = DEF_PLUS_SIZE
) -> PolarizedCapacitorSymbolParams :
#PolarizedCapacitorSymbolParams(style, porch-width, width, line-width, pol-radius, plus-size)

public defn sub-base-params (p:PolarizedCapacitorSymbolParams, b:CapacitorSymbolParams) -> PolarizedCapacitorSymbolParams :
p $> sub-porch-width{_, porch-width(b)}
$> sub-width{_, width(b)}
Expand Down Expand Up @@ -231,14 +220,16 @@ public defn build-pol-cap-glyphs (
val pol-r = pol-radius(params)
val half-angle = to-degrees $ atan( w2 / pol-r )

val porch-line = Line(line-width, [Point(0.0, (- h)), Point(0.0, (- cross-y))])
val pol-r-center = Point(0.0, (- (cross-y + pol-r)))
val pline = Polyline(line-width,[
[
Point(0.0, (- h)), Point(0.0, (- cross-y)), ; Shaft
Arc(Point(0.0, (- pol-r)), pol-r, 90.0 + half-angle, (- 2.0 * half-angle))
Arc(Point(0.0, (- pol-r)), pol-r, 90.0 - half-angle, (2.0 * half-angle))
Arc(pol-r-center, pol-r, 90.0 + half-angle, (- 2.0 * half-angle))
Arc(pol-r-center, pol-r, 90.0 - half-angle, (2.0 * half-angle))
]
] )
pline
; pline
Union([porch-line, pline])
add-glyph(node, bot-plate, name? = One("bot-plate"))

val plus-len = match(plus-size(params)):
Expand All @@ -264,40 +255,40 @@ public defstruct CapacitorSymbol <: TwoPinSymbol :
pitch:Double with:
as-method => true
default => TWO_PIN_DEF_PITCH
doc: \<DOC>
Indicates whether the symbol will use c/a style pins

This is typically not used for non-polarized capacitors
but it is part of the TwoPinSymbol definition. The default
is `false`.
<DOC>
polarized?:True|False with:
as-method => true
default => false
doc: \<DOC>
Optional Capacitor Symbol Parameters Override
If this value is not None, then we will use these
parameters to construct the capacitor symbol instead
of `get-default-cap-symbol-params()`
If this value is None, then this function will
consult {@link get-default-cap-symbol-params}
when constructing the capacitor symbol. Otherwise,
this value will override the existing defaults.
<DOC>
params:Maybe<CapacitorSymbolParams> with: (
params:Maybe<CapacitorSymbolParams> with:
; NOTE: I'm not using `get-default-cap-symbol-params()` here
; because it would prevent the user from overriding the defaults
; because `CURR-CAPACITOR-SYMBOL` gets instantiate on run.
default => None()
)
with:
constructor => #CapacitorSymbol
keyword-constructor => true
printer => true

public defn CapacitorSymbol (
--
pitch:Double = TWO_PIN_DEF_PITCH
params:CapacitorSymbolParams = ?
) -> CapacitorSymbol:
#CapacitorSymbol(pitch, false, params)

public defmethod name (x:CapacitorSymbol) -> String :
"Capacitor"

public defmethod build-artwork (
x:CapacitorSymbol, sn:SymbolNode
):
val p = match(params(x)):
(_:None): get-default-cap-symbol-params()
(y:One<CapacitorSymbolParams>): value(y)
val p = value-or-else(params(x), get-default-cap-symbol-params)
build-capacitor-glyphs(sn, pitch(x), p)

var CURR-CAPACITOR-SYMBOL:TwoPinSymbol = CapacitorSymbol()
Expand All @@ -310,9 +301,24 @@ public defstruct PolarizedCapacitorSymbol <: TwoPinSymbol :
pitch:Double with:
as-method => true
default => TWO_PIN_DEF_PITCH
doc: \<DOC>
Indicates whether the symbol will use c/a style pins

This is value defaults to `true` for the Polarized
capacitor symbol.
<DOC>
polarized?:True|False with:
as-method => true
default => true
doc: \<DOC>
Optional Override Parameters for Polarized Capacitor Glyph

This value can be used to override the capacitor glyph
parameters and replace them with custom parameters.
This value is by default `None()` which will cause
{@link get-default-polarized-cap-symbol-params} to be
consulted for parameters when the symbol is built.
<DOC>
params:Maybe<PolarizedCapacitorSymbolParams> with:
default => None()
with:
Expand All @@ -332,9 +338,7 @@ public defmethod name (x:PolarizedCapacitorSymbol) -> String :
public defmethod build-artwork (
x:PolarizedCapacitorSymbol, sn:SymbolNode
):
val p = match(params(x)):
(_:None): get-default-polarized-cap-symbol-params()
(y:One<PolarizedCapacitorSymbolParams>): value(y)
val p = value-or-else(params(x), get-default-polarized-cap-symbol-params)
build-pol-cap-glyphs(sn, pitch(x), p)

var CURR-POL-CAP-SYMBOL:TwoPinSymbol = PolarizedCapacitorSymbol()
Expand Down
Loading
Loading