Skip to content

Commit

Permalink
Use p.eaxy() and change from p.rot to p.r
Browse files Browse the repository at this point in the history
  • Loading branch information
ceoloide committed Apr 12, 2024
1 parent bec5e45 commit 711b129
Show file tree
Hide file tree
Showing 13 changed files with 284 additions and 418 deletions.
72 changes: 19 additions & 53 deletions battery_connector_jst_ph_2.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,40 +54,6 @@ module.exports = {
BAT_N: { type: 'net', value: 'GND' },
},
body: p => {

const get_at_coordinates = () => {
const pattern = /\(at (-?[\d\.]*) (-?[\d\.]*) (-?[\d\.]*)\)/;
const matches = p.at.match(pattern);
if (matches && matches.length == 4) {
return [parseFloat(matches[1]), parseFloat(matches[2]), parseFloat(matches[3])];
} else {
return null;
}
}

const adjust_point = (x, y) => {
const at_l = get_at_coordinates();
if (at_l == null) {
throw new Error(
`Could not get x and y coordinates from p.at: ${p.at}`
);
}
const at_x = at_l[0];
const at_y = at_l[1];
const at_angle = at_l[2];
const adj_x = at_x + x;
const adj_y = at_y + y;

const radians = (Math.PI / 180) * at_angle,
cos = Math.cos(radians),
sin = Math.sin(radians),
nx = (cos * (adj_x - at_x)) + (sin * (adj_y - at_y)) + at_x,
ny = (cos * (adj_y - at_y)) - (sin * (adj_x - at_x)) + at_y;

const point_str = `${nx.toFixed(3)} ${ny.toFixed(3)}`;
return point_str;
}

let local_nets = [
p.local_net("1"),
p.local_net("2"),
Expand All @@ -98,7 +64,7 @@ module.exports = {
${p.at /* parametric position */}
(descr "JST PH series connector, S2B-PH-K (http://www.jst-mfg.com/product/pdf/eng/ePH.pdf)")
(fp_text reference "${p.ref}" (at 0 4.8 ${p.rot}) (layer "${p.side}.SilkS") ${p.ref_hide}
(fp_text reference "${p.ref}" (at 0 4.8 ${p.r}) (layer "${p.side}.SilkS") ${p.ref_hide}
(effects (font (size 1 1) (thickness 0.15)))
)
`
Expand Down Expand Up @@ -161,17 +127,17 @@ module.exports = {
(fp_line (start 3.06 6.36) (end 3.06 5.36) (width 0.12) (layer "B.SilkS"))
`
const front_pads = `
(pad 1 thru_hole roundrect (at -1 0 ${p.rot}) (size 1.2 1.75) (drill 0.75) (layers "*.Cu" "*.Mask") (roundrect_rratio 0.20) ${p.BAT_N.str})
(pad 2 thru_hole oval (at 1 0 ${p.rot}) (size 1.2 1.75) (drill 0.75) (layers "*.Cu" "*.Mask") ${p.BAT_P.str})
(pad 1 thru_hole roundrect (at -1 0 ${p.r}) (size 1.2 1.75) (drill 0.75) (layers "*.Cu" "*.Mask") (roundrect_rratio 0.20) ${p.BAT_N.str})
(pad 2 thru_hole oval (at 1 0 ${p.r}) (size 1.2 1.75) (drill 0.75) (layers "*.Cu" "*.Mask") ${p.BAT_P.str})
`
const back_pads = `
(pad 1 thru_hole roundrect (at 1 0 ${p.rot}) (size 1.2 1.75) (drill 0.75) (layers "*.Cu" "*.Mask") (roundrect_rratio 0.20) ${p.BAT_N.str})
(pad 2 thru_hole oval (at -1 0 ${p.rot}) (size 1.2 1.75) (drill 0.75) (layers "*.Cu" "*.Mask") ${p.BAT_P.str})
(pad 1 thru_hole roundrect (at 1 0 ${p.r}) (size 1.2 1.75) (drill 0.75) (layers "*.Cu" "*.Mask") (roundrect_rratio 0.20) ${p.BAT_N.str})
(pad 2 thru_hole oval (at -1 0 ${p.r}) (size 1.2 1.75) (drill 0.75) (layers "*.Cu" "*.Mask") ${p.BAT_P.str})
`
const reversible_pads = `
(pad 11 thru_hole oval (at -1 0 ${p.rot}) (size 1.2 1.75) (drill 0.75) (layers "*.Cu" "*.Mask") ${local_nets[0].str})
(pad 12 thru_hole oval (at 1 0 ${p.rot}) (size 1.2 1.75) (drill 0.75) (layers "*.Cu" "*.Mask") ${local_nets[1].str})
(pad 21 smd custom (at -1 1.8 ${180 + p.rot}) (size 0.1 0.1) (layers "F.Cu" "F.Mask")
(pad 11 thru_hole oval (at -1 0 ${p.r}) (size 1.2 1.75) (drill 0.75) (layers "*.Cu" "*.Mask") ${local_nets[0].str})
(pad 12 thru_hole oval (at 1 0 ${p.r}) (size 1.2 1.75) (drill 0.75) (layers "*.Cu" "*.Mask") ${local_nets[1].str})
(pad 21 smd custom (at -1 1.8 ${180 + p.r}) (size 0.1 0.1) (layers "F.Cu" "F.Mask")
(clearance 0.1) (zone_connect 0)
(options (clearance outline) (anchor rect))
(primitives
Expand All @@ -186,7 +152,7 @@ module.exports = {
(width 0))
)
${local_nets[0]})
(pad 31 smd custom (at -1 1.8 ${180 + p.rot}) (size 0.1 0.1) (layers "B.Cu" "B.Mask")
(pad 31 smd custom (at -1 1.8 ${180 + p.r}) (size 0.1 0.1) (layers "B.Cu" "B.Mask")
(clearance 0.1) (zone_connect 0)
(options (clearance outline) (anchor rect))
(primitives
Expand All @@ -201,7 +167,7 @@ module.exports = {
(width 0))
)
${local_nets[0]})
(pad 22 smd custom (at 1 1.8 ${180 + p.rot}) (size 0.1 0.1) (layers "F.Cu" "F.Mask")
(pad 22 smd custom (at 1 1.8 ${180 + p.r}) (size 0.1 0.1) (layers "F.Cu" "F.Mask")
(clearance 0.1) (zone_connect 0)
(options (clearance outline) (anchor rect))
(primitives
Expand All @@ -216,7 +182,7 @@ module.exports = {
(width 0))
)
${local_nets[1]})
(pad 32 smd custom (at 1 1.8 ${180 + p.rot}) (size 0.1 0.1) (layers "B.Cu" "B.Mask")
(pad 32 smd custom (at 1 1.8 ${180 + p.r}) (size 0.1 0.1) (layers "B.Cu" "B.Mask")
(clearance 0.1) (zone_connect 0)
(options (clearance outline) (anchor rect))
(primitives
Expand All @@ -231,7 +197,7 @@ module.exports = {
(width 0))
)
${local_nets[1]})
(pad 1 smd custom (at -1 2.816 ${180 + p.rot}) (size 1.2 0.5) (layers "F.Cu" "F.Mask") ${p.BAT_P.str}
(pad 1 smd custom (at -1 2.816 ${180 + p.r}) (size 1.2 0.5) (layers "F.Cu" "F.Mask") ${p.BAT_P.str}
(clearance 0.1) (zone_connect 0)
(options (clearance outline) (anchor rect))
(primitives
Expand All @@ -245,7 +211,7 @@ module.exports = {
)
(width 0))
) )
(pad 1 smd custom (at 1 2.816 ${180 + p.rot}) (size 1.2 0.5) (layers "B.Cu" "B.Mask") ${p.BAT_P.str}
(pad 1 smd custom (at 1 2.816 ${180 + p.r}) (size 1.2 0.5) (layers "B.Cu" "B.Mask") ${p.BAT_P.str}
(clearance 0.1) (zone_connect 0)
(options (clearance outline) (anchor rect))
(primitives
Expand All @@ -259,7 +225,7 @@ module.exports = {
)
(width 0))
) )
(pad 2 smd custom (at -1 2.816 ${180 + p.rot}) (size 1.2 0.5) (layers "B.Cu" "B.Mask") ${p.BAT_N.str}
(pad 2 smd custom (at -1 2.816 ${180 + p.r}) (size 1.2 0.5) (layers "B.Cu" "B.Mask") ${p.BAT_N.str}
(clearance 0.1) (zone_connect 0)
(options (clearance outline) (anchor rect))
(primitives
Expand All @@ -273,7 +239,7 @@ module.exports = {
)
(width 0))
) )
(pad 2 smd custom (at 1 2.816 ${180 + p.rot}) (size 1.2 0.5) (layers "F.Cu" "F.Mask") ${p.BAT_N.str}
(pad 2 smd custom (at 1 2.816 ${180 + p.r}) (size 1.2 0.5) (layers "F.Cu" "F.Mask") ${p.BAT_N.str}
(clearance 0.1) (zone_connect 0)
(options (clearance outline) (anchor rect))
(primitives
Expand All @@ -293,10 +259,10 @@ module.exports = {
`

const reversible_traces = `
(segment (start ${adjust_point(-1, 1.8)}) (end ${adjust_point(-1, 0)}) (width ${p.trace_width}) (layer "F.Cu") (net ${local_nets[0].index}))
(segment (start ${adjust_point(-1, 1.8)}) (end ${adjust_point(-1, 0)}) (width ${p.trace_width}) (layer "B.Cu") (net ${local_nets[0].index}))
(segment (start ${adjust_point(1, 1.8)}) (end ${adjust_point(1, 0)}) (width ${p.trace_width}) (layer "F.Cu") (net ${local_nets[1].index}))
(segment (start ${adjust_point(1, 1.8)}) (end ${adjust_point(1, 0)}) (width ${p.trace_width}) (layer "B.Cu") (net ${local_nets[1].index}))
(segment (start ${p.eaxy(-1, 1.8)}) (end ${p.eaxy(-1, 0)}) (width ${p.trace_width}) (layer "F.Cu") (net ${local_nets[0].index}))
(segment (start ${p.eaxy(-1, 1.8)}) (end ${p.eaxy(-1, 0)}) (width ${p.trace_width}) (layer "B.Cu") (net ${local_nets[0].index}))
(segment (start ${p.eaxy(1, 1.8)}) (end ${p.eaxy(1, 0)}) (width ${p.trace_width}) (layer "F.Cu") (net ${local_nets[1].index}))
(segment (start ${p.eaxy(1, 1.8)}) (end ${p.eaxy(1, 0)}) (width ${p.trace_width}) (layer "B.Cu") (net ${local_nets[1].index}))
`

let final = standard_opening;
Expand Down
15 changes: 7 additions & 8 deletions diode_tht_sod123.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,10 @@ module.exports = {
to: undefined
},
body: p => {

const standard_opening = `
(module "ceoloide:diode_tht_sod123" (layer ${p.side}.Cu) (tedit 5B24D78E)
${p.at /* parametric position */}
(fp_text reference "${p.ref}" (at 0 0 ${p.rot}) (layer ${p.side}.SilkS) ${p.ref_hide} (effects (font (size 1.27 1.27) (thickness 0.15))))
(fp_text reference "${p.ref}" (at 0 0 ${p.r}) (layer ${p.side}.SilkS) ${p.ref_hide} (effects (font (size 1.27 1.27) (thickness 0.15))))
`
const front = `
(fp_line (start 0.25 0) (end 0.75 0) (layer F.SilkS) (width 0.1))
Expand All @@ -73,8 +72,8 @@ module.exports = {
(fp_line (start -0.35 0) (end -0.35 0.55) (layer F.SilkS) (width 0.1))
(fp_line (start -0.35 0) (end -0.35 -0.55) (layer F.SilkS) (width 0.1))
(fp_line (start -0.75 0) (end -0.35 0) (layer F.SilkS) (width 0.1))
(pad 1 smd rect (at -1.65 0 ${p.rot}) (size 0.9 1.2) (layers F.Cu F.Paste F.Mask) ${p.to.str})
(pad 2 smd rect (at 1.65 0 ${p.rot}) (size 0.9 1.2) (layers F.Cu F.Paste F.Mask) ${p.from.str})
(pad 1 smd rect (at -1.65 0 ${p.r}) (size 0.9 1.2) (layers F.Cu F.Paste F.Mask) ${p.to.str})
(pad 2 smd rect (at 1.65 0 ${p.r}) (size 0.9 1.2) (layers F.Cu F.Paste F.Mask) ${p.from.str})
`
const back = `
(fp_line (start 0.25 0) (end 0.75 0) (layer B.SilkS) (width 0.1))
Expand All @@ -84,13 +83,13 @@ module.exports = {
(fp_line (start -0.35 0) (end -0.35 0.55) (layer B.SilkS) (width 0.1))
(fp_line (start -0.35 0) (end -0.35 -0.55) (layer B.SilkS) (width 0.1))
(fp_line (start -0.75 0) (end -0.35 0) (layer B.SilkS) (width 0.1))
(pad 2 smd rect (at 1.65 0 ${p.rot}) (size 0.9 1.2) (layers B.Cu B.Paste B.Mask) ${p.from.str})
(pad 1 smd rect (at -1.65 0 ${p.rot}) (size 0.9 1.2) (layers B.Cu B.Paste B.Mask) ${p.to.str})
(pad 2 smd rect (at 1.65 0 ${p.r}) (size 0.9 1.2) (layers B.Cu B.Paste B.Mask) ${p.from.str})
(pad 1 smd rect (at -1.65 0 ${p.r}) (size 0.9 1.2) (layers B.Cu B.Paste B.Mask) ${p.to.str})
`

const tht = `
(pad 1 thru_hole rect (at -3.81 0 ${p.rot}) (size 1.778 1.778) (drill 0.9906) (layers *.Cu *.Mask) ${p.to.str})
(pad 2 thru_hole circle (at 3.81 0 ${p.rot}) (size 1.905 1.905) (drill 0.9906) (layers *.Cu *.Mask) ${p.from.str})
(pad 1 thru_hole rect (at -3.81 0 ${p.r}) (size 1.778 1.778) (drill 0.9906) (layers *.Cu *.Mask) ${p.to.str})
(pad 2 thru_hole circle (at 3.81 0 ${p.r}) (size 1.905 1.905) (drill 0.9906) (layers *.Cu *.Mask) ${p.from.str})
`

const diode_3dmodel = `
Expand Down
Loading

0 comments on commit 711b129

Please sign in to comment.