Skip to content
Snippets Groups Projects
Commit 3614d7ae authored by Neil Gershenfeld's avatar Neil Gershenfeld
Browse files

ready to accumulate

parent dfbf2d1a
Branches
No related tags found
No related merge requests found
...@@ -54,10 +54,10 @@ var inputs = { ...@@ -54,10 +54,10 @@ var inputs = {
event:function(evt){ event:function(evt){
if (mod.label.nodeValue == 'calculating') { if (mod.label.nodeValue == 'calculating') {
// //
// calculation in progress, show and accumulate // calculation in progress, draw and accumulate
// //
draw_path(evt.detail) draw_layer(evt.detail)
accumulate_path(evt.detail) accumulate_layer(evt.detail)
mod.offsetCount += 1 mod.offsetCount += 1
if ((mod.offsetCount != parseInt(mod.number.value)) if ((mod.offsetCount != parseInt(mod.number.value))
&& (evt.detail.length > 0)) { && (evt.detail.length > 0)) {
...@@ -65,32 +65,34 @@ var inputs = { ...@@ -65,32 +65,34 @@ var inputs = {
// layer detail present and offset not complete // layer detail present and offset not complete
// //
mod.offset += parseFloat(mod.stepover.value) mod.offset += parseFloat(mod.stepover.value)
outputs.offset.event() outputs.offset.event(
mod.offset*parseFloat(mod.dia_in.value)*mod.dpi)
} }
else if (mod.depth < parseFloat(mod.max_mm.value)) { else if (mod.depthmm < parseFloat(mod.max_mm.value)) {
// //
// layer loop not complete // layer loop not complete
// //
merge_path() merge_layer()
accumulate_toolpath() accumulate_path()
clear_path() clear_layer()
mod.depth += parseFloat(mod.cut_mm.value) mod.depthmm += parseFloat(mod.cut_mm.value)
if (mod.depth > parseFloat(mod.max_mm.value)) { if (mod.depthmm > parseFloat(mod.max_mm.value)) {
mod.depth = parseFloat(mod.max_mm.value) mod.depthmm = parseFloat(mod.max_mm.value)
} }
// //
// clear offset // clear offset
// //
mods.output(mod,'offset','') outputs.offset.event('')
// //
// set new depth // set new depth
// //
outputs.depth.event() outputs.depth.event(mod.depthmm)
// //
// set new offset // set new offset
// //
mod.offsetCount = 0 mod.offsetCount = 0
outputs.offset.event() outputs.offset.event(
mod.offset*parseFloat(mod.dia_in.value)*mod.dpi)
} }
else { else {
// //
...@@ -116,8 +118,8 @@ var inputs = { ...@@ -116,8 +118,8 @@ var inputs = {
// //
var outputs = { var outputs = {
depth:{type:'', depth:{type:'',
event:function(){ event:function(depth){
mods.output(mod,'depth',{depthmm:mod.depth}) mods.output(mod,'depth',{depthmm:depth})
} }
}, },
diameter:{type:'', diameter:{type:'',
...@@ -126,13 +128,13 @@ var outputs = { ...@@ -126,13 +128,13 @@ var outputs = {
} }
}, },
offset:{type:'', offset:{type:'',
event:function(){ event:function(size){
var pixels = mod.offset*parseFloat(mod.dia_in.value)*mod.dpi mods.output(mod,'offset',size)
mods.output(mod,'offset',pixels)
} }
}, },
toolpath:{type:'', toolpath:{type:'',
event:function(){ event:function(){
console.log(mod.path)
cmd = {} cmd = {}
cmd.path = mod.path cmd.path = mod.path
cmd.name = mod.name cmd.name = mod.name
...@@ -317,15 +319,16 @@ var interface = function(div){ ...@@ -317,15 +319,16 @@ var interface = function(div){
mod.labelspan = span mod.labelspan = span
btn.appendChild(span) btn.appendChild(span)
btn.addEventListener('click',function(){ btn.addEventListener('click',function(){
mods.output(mod,'offset','')
mods.output(mod,'depth',{depthmm:mod.depth})
mod.label.nodeValue = 'calculating' mod.label.nodeValue = 'calculating'
mod.labelspan.style.fontWeight = 'bold' mod.labelspan.style.fontWeight = 'bold'
mod.depth = parseFloat(mod.cut_mm.value) outputs.offset.event('') // clear offset
mod.toolpath = [] mod.depthmm = parseFloat(mod.cut_mm.value)
clear_path() outputs.depth.event(mod.depthmm) // set depth
mod.toolpath = [] // start new toolpath
clear_layer() // clear layer
outputs.diameter.event() outputs.diameter.event()
outputs.offset.event() outputs.offset.event( // set offset
mod.offset*parseFloat(mod.dia_in.value)*mod.dpi)
}) })
div.appendChild(btn) div.appendChild(btn)
div.appendChild(document.createTextNode(' ')) div.appendChild(document.createTextNode(' '))
...@@ -404,14 +407,15 @@ function set_values(settings) { ...@@ -404,14 +407,15 @@ function set_values(settings) {
} }
} }
// //
// clear_path // clear_layer
// //
function clear_path() { function clear_layer() {
mod.path = [] mod.path = []
mod.offset = 0.5 mod.offset = 0.5
mod.offsetCount = 0 mod.offsetCount = 0
var svg = document.getElementById(mod.div.id+'svg') var svg = document.getElementById(mod.div.id+'svg')
svg.setAttribute('viewBox',"0 0 "+(mod.img.width-1)+" "+(mod.img.height-1)) svg.setAttribute(
'viewBox',"0 0 "+(mod.img.width-1)+" "+(mod.img.height-1))
var g = document.getElementById(mod.div.id+'g') var g = document.getElementById(mod.div.id+'g')
svg.removeChild(g) svg.removeChild(g)
var g = document.createElementNS('http://www.w3.org/2000/svg','g') var g = document.createElementNS('http://www.w3.org/2000/svg','g')
...@@ -419,11 +423,11 @@ function clear_path() { ...@@ -419,11 +423,11 @@ function clear_path() {
svg.appendChild(g) svg.appendChild(g)
} }
// //
// accumulate_path // accumulate_layer
// todo: replace inefficient insertion sort // todo: replace inefficient insertion sort
// todo: move sort out of main thread // todo: move sort out of main thread
// //
function accumulate_path(path) { function accumulate_layer(path) {
var forward = mod.forward.checked var forward = mod.forward.checked
var conventional = mod.conventional.checked var conventional = mod.conventional.checked
var sort = mod.sort.checked var sort = mod.sort.checked
...@@ -462,9 +466,9 @@ function accumulate_path(path) { ...@@ -462,9 +466,9 @@ function accumulate_path(path) {
} }
} }
// //
// merge_path // merge_layer
// //
function merge_path() { function merge_layer() {
var dmerge = mod.dpi*parseFloat(mod.merge.value)*parseFloat(mod.dia_in.value) var dmerge = mod.dpi*parseFloat(mod.merge.value)*parseFloat(mod.dia_in.value)
var seg = 0 var seg = 0
while (seg < (mod.path.length-1)) { while (seg < (mod.path.length-1)) {
...@@ -482,10 +486,10 @@ function merge_path() { ...@@ -482,10 +486,10 @@ function merge_path() {
} }
} }
// //
// accumulate_toolpath // accumulate_path
// //
function accumulate_toolpath() { function accumulate_path() {
console.log('accum '+mod.depth) console.log('accum '+mod.depthmm)
} }
// //
// add_depth // add_depth
...@@ -534,9 +538,9 @@ function add_depth() { ...@@ -534,9 +538,9 @@ function add_depth() {
mod.depth = Math.round(parseFloat(mod.max_in.value)*mod.dpi) mod.depth = Math.round(parseFloat(mod.max_in.value)*mod.dpi)
} }
// //
// draw_path // draw_layer
// //
function draw_path(path) { function draw_layer(path) {
var g = document.getElementById(mod.div.id+'g') var g = document.getElementById(mod.div.id+'g')
var h = mod.img.height var h = mod.img.height
var w = mod.img.width var w = mod.img.width
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment