remove: lines and arcs can only be round
This commit is contained in:
parent
003e7b0733
commit
984b2a2b94
|
@ -23,7 +23,6 @@
|
|||
"x2": 100, // end horizontal position of line
|
||||
"y2": 100, // end vertical position of the line
|
||||
"thickness": 10, // thickness of line (positive)
|
||||
"round": true, // round or square edges to start/stop of line (adds thickness/2 to end of line)
|
||||
},
|
||||
{
|
||||
"type": "arc", // a circle arc (on silk screen layer)
|
||||
|
@ -33,7 +32,6 @@
|
|||
"start": 0, // start point of arc in degrees (0=east, 90=south, 180=west, 270=north)
|
||||
"angle": 0, // angle of clockwise arc in degrees (can be negative)
|
||||
"thickness": 10, // thickness of trace (positive)
|
||||
"round": true, // round or square edges to start/stop of line (adds thickness/2 to end of arc)
|
||||
},
|
||||
{
|
||||
"type": "pad" // a pad (on copper layer). angled pads are not supported
|
||||
|
|
71
cvlp_lib.js
71
cvlp_lib.js
|
@ -1,7 +1,7 @@
|
|||
// library for creating CuVoodoo Land Pattern (cvlp) JSON files and render them
|
||||
|
||||
// create a set of elements with an line element
|
||||
function cvlp_line(x1, y1, x2, y2, thickness, round=true) {
|
||||
function cvlp_line(x1, y1, x2, y2, thickness) {
|
||||
var line = {}
|
||||
line.type = "line"
|
||||
line.x1 = x1
|
||||
|
@ -9,13 +9,12 @@ function cvlp_line(x1, y1, x2, y2, thickness, round=true) {
|
|||
line.x2 = x2
|
||||
line.y2 = y2
|
||||
line.thickness = thickness
|
||||
line.round = round
|
||||
return [line]
|
||||
}
|
||||
|
||||
// create a set of elements with an arc element
|
||||
// arc goes angle degrees clockwise from start
|
||||
function cvlp_arc(x, y, radius, start, angle, thickness, round=true) {
|
||||
function cvlp_arc(x, y, radius, start, angle, thickness) {
|
||||
var arc = {}
|
||||
arc.type = "arc"
|
||||
arc.x = x
|
||||
|
@ -24,7 +23,6 @@ function cvlp_arc(x, y, radius, start, angle, thickness, round=true) {
|
|||
arc.start = start
|
||||
arc.angle = angle
|
||||
arc.thickness = thickness
|
||||
arc.round = round
|
||||
return [arc]
|
||||
}
|
||||
|
||||
|
@ -75,17 +73,17 @@ function cvlp_polyline(points, thickness, closed=false) {
|
|||
|
||||
// create a set of elements representing a rectangle
|
||||
// provide top corner, size, an radius of corner
|
||||
function cvlp_rectangle(x, y, width, height, thickness, radius=0, round=true) {
|
||||
function cvlp_rectangle(x, y, width, height, thickness, radius=0) {
|
||||
var rectangle = []
|
||||
rectangle = rectangle.concat(cvlp_line(x+radius, y, x+width-radius, y, thickness, round))
|
||||
rectangle = rectangle.concat(cvlp_line(x+width, y+radius, x+width, y+height-radius, thickness, round))
|
||||
rectangle = rectangle.concat(cvlp_line(x+width-radius, y+height, x+radius, y+height, thickness, round))
|
||||
rectangle = rectangle.concat(cvlp_line(x, y+height-radius, x, y+radius, thickness, round))
|
||||
rectangle = rectangle.concat(cvlp_line(x+radius, y, x+width-radius, y, thickness))
|
||||
rectangle = rectangle.concat(cvlp_line(x+width, y+radius, x+width, y+height-radius, thickness))
|
||||
rectangle = rectangle.concat(cvlp_line(x+width-radius, y+height, x+radius, y+height, thickness))
|
||||
rectangle = rectangle.concat(cvlp_line(x, y+height-radius, x, y+radius, thickness))
|
||||
if (radius!=0) {
|
||||
rectangle = rectangle.concat(cvlp_arc(x+radius, y+radius, radius, 180, 90, thickness, round))
|
||||
rectangle = rectangle.concat(cvlp_arc(x+width-radius, y+radius, radius, 270, 90, thickness, round))
|
||||
rectangle = rectangle.concat(cvlp_arc(x+width-radius, y+width-radius, radius, 0, 90, thickness, round))
|
||||
rectangle = rectangle.concat(cvlp_arc(x+radius, y+width-radius, radius, 90, 90, thickness, round))
|
||||
rectangle = rectangle.concat(cvlp_arc(x+radius, y+radius, radius, 180, 90, thickness))
|
||||
rectangle = rectangle.concat(cvlp_arc(x+width-radius, y+radius, radius, 270, 90, thickness))
|
||||
rectangle = rectangle.concat(cvlp_arc(x+width-radius, y+width-radius, radius, 0, 90, thickness))
|
||||
rectangle = rectangle.concat(cvlp_arc(x+radius, y+width-radius, radius, 90, 90, thickness))
|
||||
}
|
||||
return rectangle
|
||||
}
|
||||
|
@ -175,16 +173,12 @@ function json2svg(json) {
|
|||
switch (element.type) {
|
||||
case 'line':
|
||||
var line = document.createElementNS(svgNS,'line')
|
||||
line.style.setProperty('stroke-width',element.thickness)
|
||||
if (element.round) {
|
||||
line.style.setProperty('stroke-linecap','round')
|
||||
} else {
|
||||
line.style.setProperty('stroke-linecap','square')
|
||||
}
|
||||
line.setAttribute('x1',element.x1)
|
||||
line.setAttribute('y1',element.y1)
|
||||
line.setAttribute('x2',element.x2)
|
||||
line.setAttribute('y2',element.y2)
|
||||
line.style.setProperty('stroke-width',element.thickness)
|
||||
line.style.setProperty('stroke-linecap','round')
|
||||
layers['silkscreen'].appendChild(line)
|
||||
break
|
||||
case 'arc':
|
||||
|
@ -205,11 +199,7 @@ function json2svg(json) {
|
|||
arc.setAttribute('d','M '+x1+' '+y1+' A '+element.radius+' '+element.radius+' 0 '+((element.angle)%360>180 ? '1' : '0')+' 1 '+x2+' '+y2+' ')
|
||||
}
|
||||
arc.style.setProperty('stroke-width',element.thickness)
|
||||
if (element.round) {
|
||||
arc.style.setProperty('stroke-linecap','round')
|
||||
} else {
|
||||
arc.style.setProperty('stroke-linecap','square')
|
||||
}
|
||||
arc.style.setProperty('stroke-linecap','round')
|
||||
layers['silkscreen'].appendChild(arc)
|
||||
break
|
||||
case 'pad':
|
||||
|
@ -440,7 +430,6 @@ function json2eagle(json) {
|
|||
xml.documentElement.appendChild(comment)
|
||||
var drawing = xml.createElement('drawing')
|
||||
xml.documentElement.appendChild(drawing)
|
||||
// settings and grid are skipped
|
||||
// add layers
|
||||
var layers = xml.createElement('layers')
|
||||
drawing.appendChild(layers)
|
||||
|
@ -480,24 +469,14 @@ function json2eagle(json) {
|
|||
var element = json.elements[element_i]
|
||||
switch (element.type) {
|
||||
case 'line':
|
||||
if (element.round) {
|
||||
var line = xml.createElement('wire')
|
||||
line.setAttribute('x1',convert_unit(element.x1,json.unit,'mm'))
|
||||
line.setAttribute('y1',convert_unit(-1*element.y1,json.unit,'mm'))
|
||||
line.setAttribute('x2',convert_unit(element.x2,json.unit,'mm'))
|
||||
line.setAttribute('y2',convert_unit(-1*element.y2,json.unit,'mm'))
|
||||
line.setAttribute('width',convert_unit(element.thickness,json.unit,'mm'))
|
||||
line.setAttribute('layer','21')
|
||||
packag.appendChild(line)
|
||||
} else { // note: in eagle only arcs support flat caps. use rectangles for wires
|
||||
var line = xml.createElement('rectangle')
|
||||
line.setAttribute('x1',convert_unit(element.x1-element.thickness/2,json.unit,'mm'))
|
||||
line.setAttribute('y1',convert_unit(-1*(element.y1-element.thickness/2),json.unit,'mm'))
|
||||
line.setAttribute('x2',convert_unit(element.x2+element.thickness/2,json.unit,'mm'))
|
||||
line.setAttribute('y2',convert_unit(-1*(element.y2+element.thickness/2),json.unit,'mm'))
|
||||
line.setAttribute('layer','21')
|
||||
packag.appendChild(line)
|
||||
}
|
||||
var line = xml.createElement('wire')
|
||||
line.setAttribute('x1',convert_unit(element.x1,json.unit,'mm'))
|
||||
line.setAttribute('y1',convert_unit(-1*element.y1,json.unit,'mm'))
|
||||
line.setAttribute('x2',convert_unit(element.x2,json.unit,'mm'))
|
||||
line.setAttribute('y2',convert_unit(-1*element.y2,json.unit,'mm'))
|
||||
line.setAttribute('width',convert_unit(element.thickness,json.unit,'mm'))
|
||||
line.setAttribute('layer','21')
|
||||
packag.appendChild(line)
|
||||
break
|
||||
case 'arc':
|
||||
var wire = xml.createElement('wire')
|
||||
|
@ -508,11 +487,7 @@ function json2eagle(json) {
|
|||
wire.setAttribute('curve',-1*element.angle)
|
||||
wire.setAttribute('width',convert_unit(element.thickness,json.unit,'mm'))
|
||||
wire.setAttribute('layer','21')
|
||||
if (element.round) {
|
||||
wire.setAttribute('cap','round')
|
||||
} else {
|
||||
wire.setAttribute('cap','flat')
|
||||
}
|
||||
wire.setAttribute('cap','round')
|
||||
packag.appendChild(wire)
|
||||
break
|
||||
case 'pad':
|
||||
|
|
Loading…
Reference in New Issue