aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKing Kévin <kingkevin@cuvoodoo.info>2019-05-13 22:34:26 +0200
committerKing Kévin <kingkevin@cuvoodoo.info>2019-05-13 22:34:26 +0200
commit75a8b18d68edc64265f0c54b69b4913d9fa2eb0b (patch)
tree6ecdcca42dd02563cd026c35e49ebc682b8d43c5
parentb89f6dbf3d8b6107ff4fc9688ed47bb371b59e83 (diff)
add generator for coralEDA pcb-rnd sub-circuits
-rw-r--r--cvlp_lib.js269
1 files changed, 268 insertions, 1 deletions
diff --git a/cvlp_lib.js b/cvlp_lib.js
index 3964125..e349220 100644
--- a/cvlp_lib.js
+++ b/cvlp_lib.js
@@ -469,4 +469,271 @@ function json2eagle(json) {
}
}
return xml
-}
+}
+
+// convert CuVoodoo Land Pattern JSON to coralEDA subscircuit
+function json2subc(json)
+{
+ console.log(json)
+ // create file and add info
+ var subc = ''
+ subc += '# footprint generated from CuVoodoo Land Pattern\n'
+ subc += '# author: '+json.author+'\n'
+ subc += '# version: '+json.version+'\n'
+ subc += '# date: '+json.date+'\n'
+
+ id = 1 // global subc id
+ subc += 'li:pcb-rnd-subcircuit-v6 {\n'
+ subc += ' ha:subc.' + (id++) + ' {\n'
+ subc += ' uid = any_24_ASCII_characters_\n'
+ subc += ' ha:attributes {\n'
+ subc += ' footprint = ' + json.name + '\n'
+ subc += ' }\n'
+ subc += ' ha:data {\n'
+
+ // try to group the pads/pins
+ function element_generic(element) {
+ generic = JSON.parse(JSON.stringify(element))
+ delete generic.x
+ delete generic.y
+ delete generic.number
+ return generic
+ }
+
+ // get pins/pads
+ padstacks = []
+ for (var element_i in json.elements) {
+ var element = json.elements[element_i]
+ if (element.type == 'pin' || element.type == 'pad') {
+ padstacks.push(element_generic(element))
+ }
+ }
+ padstacks = padstacks.map((value) => JSON.stringify(value))
+ padstacks = padstacks.filter((value, index, self) => self.indexOf(value) == index)
+ padstacks = padstacks.map((value) => JSON.parse(value))
+
+ // add padstacks prototypes
+ id = 2
+ subc += ' li:padstack_prototypes {\n'
+ for (var padstack_i in padstacks) {
+ var padstack = padstacks[padstack_i]
+ switch (padstack.type) {
+ case 'pad':
+ subc += ' ha:ps_proto_v6.' + (id++) + ' {\n'
+ subc += ' htop = 0\n'
+ subc += ' hbottom = 0\n'
+ subc += ' hdia = 0\n'
+ subc += ' hplated = 0\n'
+ subc += ' li:shape {\n'
+ var line = ''
+ line += ' ha:ps_line {\n'
+ var x1, y1, x2, y2, thickness
+ if (padstack.width > padstack.height) {
+ x1 = - padstack.width / 2 + padstack.height / 2
+ y1 = 0
+ x2 = padstack.width / 2 - padstack.height / 2
+ y2 = 0
+ thickness = padstack.height
+ } else {
+ x1 = 0
+ y1 = - padstack.height / 2 + padstack.width / 2
+ x2 = 0
+ y2 = padstack.height / 2 - padstack.width / 2
+ thickness = padstack.width
+ }
+ line += ' x1 = ' + convert_unit(x1, json.unit, 'mm') + 'mm\n'
+ line += ' y1 = ' + convert_unit(y1, json.unit, 'mm') + 'mm\n'
+ line += ' x2 = ' + convert_unit(x2, json.unit, 'mm') + 'mm\n'
+ line += ' y2 = ' + convert_unit(y2, json.unit, 'mm') + 'mm\n'
+ line += ' thickness =' + convert_unit(thickness, json.unit, 'mm') + 'mm\n'
+ line += ' square = ' + (padstack.round ? '0' : '1') + '\n'
+ line += ' }\n'
+ subc += ' ha:ps_shape_v4 {\n'
+ subc += ' clearance = 0\n'
+ subc += line
+ subc += ' ha:layer_mask {\n'
+ subc += ' top = 1\n'
+ subc += ' copper = 1\n'
+ subc += ' }\n'
+ subc += ' }\n'
+ subc += ' ha:ps_shape_v4 {\n'
+ subc += ' clearance = 0\n'
+ subc += line
+ subc += ' ha:layer_mask {\n'
+ subc += ' top = 1\n'
+ subc += ' mask = 1\n'
+ subc += ' }\n'
+ subc += ' ha:combining {\n'
+ subc += ' sub = 1\n'
+ subc += ' auto = 1\n'
+ subc += ' }\n'
+ subc += ' }\n'
+ subc += ' ha:ps_shape_v4 {\n'
+ subc += ' clearance = 0\n'
+ subc += line
+ subc += ' ha:layer_mask {\n'
+ subc += ' top = 1\n'
+ subc += ' paste = 1\n'
+ subc += ' }\n'
+ subc += ' ha:combining {\n'
+ subc += ' auto = 1\n'
+ subc += ' }\n'
+ subc += ' }\n'
+ subc += ' }\n'
+ subc += ' }\n'
+ break
+ case 'pin':
+ subc += ' ha:ps_proto_v6.' + (id++) + ' {\n'
+ subc += ' htop = 0\n'
+ subc += ' hbottom = 0\n'
+ subc += ' hdia = ' + convert_unit(element.hole, json.unit, 'mm') + 'mm\n'
+ subc += ' hplated = ' + (element.thickness > element.hole ? '1' : '0') + '\n'
+ subc += ' li:shape {\n'
+ var circle = ''
+ circle += ' ha:ps_circ {\n'
+ circle += ' x = 0\n'
+ circle += ' y = 0\n'
+ circle += ' dia = ' + convert_unit(element.thickness, json.unit, 'mm') + 'mm\n'
+ circle += ' }\n'
+ subc += ' ha:ps_shape_v4 {\n'
+ subc += ' clearance = 0\n'
+ subc += circle
+ subc += ' ha:layer_mask {\n'
+ subc += ' top = 1\n'
+ subc += ' copper = 1\n'
+ subc += ' }\n'
+ subc += ' }\n'
+ subc += ' ha:ps_shape_v4 {\n'
+ subc += ' clearance = 0\n'
+ subc += circle
+ subc += ' ha:layer_mask {\n'
+ subc += ' top = 1\n'
+ subc += ' mask = 1\n'
+ subc += ' }\n'
+ subc += ' ha:combining {\n'
+ subc += ' sub = 1\n'
+ subc += ' auto = 1\n'
+ subc += ' }\n'
+ subc += ' }\n'
+ subc += ' ha:ps_shape_v4 {\n'
+ subc += ' clearance = 0\n'
+ subc += circle
+ subc += ' ha:layer_mask {\n'
+ subc += ' intern = 1\n'
+ subc += ' copper = 1\n'
+ subc += ' }\n'
+ subc += ' }\n'
+ subc += ' ha:ps_shape_v4 {\n'
+ subc += ' clearance = 0\n'
+ subc += circle
+ subc += ' ha:layer_mask {\n'
+ subc += ' bottom = 1\n'
+ subc += ' copper = 1\n'
+ subc += ' }\n'
+ subc += ' }\n'
+ subc += ' ha:ps_shape_v4 {\n'
+ subc += ' clearance = 0\n'
+ subc += circle
+ subc += ' ha:layer_mask {\n'
+ subc += ' bottom = 1\n'
+ subc += ' mask = 1\n'
+ subc += ' }\n'
+ subc += ' ha:combining {\n'
+ subc += ' sub = 1\n'
+ subc += ' auto = 1\n'
+ subc += ' }\n'
+ subc += ' }\n'
+ subc += ' }\n'
+ subc += ' }\n'
+ break
+ }
+ }
+ subc += ' }\n' // end padstack_prototypes
+
+ // add pads/pins
+ subc += ' li:objects {\n'
+ for (var element_i in json.elements) {
+ var element = json.elements[element_i]
+ if (element.type != 'pin' && element.type != 'pad') {
+ continue
+ }
+ padstack = padstacks.map((value) => JSON.stringify(value)).indexOf(JSON.stringify(element_generic(element)))
+ if (padstack < 0) {
+ continue
+ }
+ subc += ' ha:padstack_ref.' + (id++) + '{\n'
+ subc += ' proto = ' + (2 + padstack) + '\n'
+ subc += ' rot = 0\n'
+ subc += ' x = ' + convert_unit(element.x, json.unit, 'mm') + 'mm\n'
+ subc += ' y = ' + convert_unit(element.y, json.unit, 'mm') + 'mm\n'
+ subc += ' ha:attributes {\n'
+ subc += ' term = ' + element.number + '\n'
+ subc += ' name = ' + element.number + '\n'
+ subc += ' }\n'
+ subc += ' }\n'
+ }
+ subc += ' }\n' // end objects
+
+ // add silkscreen
+ subc += ' li:layers {\n'
+ subc += ' ha:top-silkscreen {\n'
+ subc += ' lid = 1\n'
+ subc += ' ha:type {\n'
+ subc += ' top = 1\n'
+ subc += ' silk = 1\n'
+ subc += ' }\n'
+ subc += ' li:objects {\n'
+ for (var element_i in json.elements) {
+ var element = json.elements[element_i]
+ switch (element.type) {
+ case 'line':
+ subc += ' ha:line.' + (id++) + '{\n'
+ subc += ' clearance = 0\n'
+ subc += ' x1 = ' + convert_unit(element.x1, json.unit, 'mm') + 'mm\n'
+ subc += ' y1 = ' + convert_unit(element.y1, json.unit, 'mm') + 'mm\n'
+ subc += ' x2 = ' + convert_unit(element.x2, json.unit, 'mm') + 'mm\n'
+ subc += ' y2 = ' + convert_unit(element.y2, json.unit, 'mm') + 'mm\n'
+ subc += ' thickness = ' + convert_unit(element.thickness, json.unit, 'mm') + 'mm\n'
+ subc += ' }\n'
+ break
+ case 'arc':
+ subc += ' ha:arc.' + (id++) + '{\n'
+ subc += ' clearance = 0\n'
+ subc += ' x = ' + convert_unit(element.x, json.unit, 'mm') + 'mm\n'
+ subc += ' y = ' + convert_unit(element.y, json.unit, 'mm') + 'mm\n'
+ subc += ' width = ' + convert_unit(element.radius, json.unit, 'mm') + 'mm\n'
+ subc += ' height = ' + convert_unit(element.radius, json.unit, 'mm') + 'mm\n'
+ subc += ' thickness = ' + convert_unit(element.thickness, json.unit, 'mm') + 'mm\n'
+ subc += ' astart = ' + ((element.start * -1 + 180) % 360) + '\n'
+ subc += ' adelta = ' + (element.angle * -1) + '\n'
+ subc += ' }\n'
+ break
+ }
+ if (element.type != 'pin' && element.type != 'pad') {
+ continue
+ }
+ padstack = padstacks.map((value) => JSON.stringify(value)).indexOf(JSON.stringify(element_generic(element)))
+ if (padstack < 0) {
+ continue
+ }
+ subc += ' ha:padstack_ref.' + (id++) + '{\n'
+ subc += ' proto = ' + (2 + padstack) + '\n'
+ subc += ' rot = 0\n'
+ subc += ' x = ' + convert_unit(element.x, json.unit, 'mm') + 'mm\n'
+ subc += ' y = ' + convert_unit(element.y, json.unit, 'mm') + 'mm\n'
+ subc += ' ha:attributes {\n'
+ subc += ' term = ' + element.number + '\n'
+ subc += ' name = ' + element.number + '\n'
+ subc += ' }\n'
+ subc += ' }\n'
+ }
+ subc += ' }\n' // end objects
+ subc += ' }\n' // end silkscreen
+ subc += ' }\n' // end layers
+
+ subc += ' }\n' // end data
+ subc += ' }\n' // end subc
+ subc += '}\n' // end pcb-rnd-subcircuit-v6
+
+ return subc
+}