Mercurial > lasercutter
diff graster/graster/bin/gtile @ 11:f952052e37b7
trying a fix.
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Tue, 24 Aug 2010 19:06:45 -0400 |
parents | |
children |
line wrap: on
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/graster/graster/bin/gtile Tue Aug 24 19:06:45 2010 -0400 1.3 @@ -0,0 +1,74 @@ 1.4 +#!/usr/bin/env ruby -rubygems 1.5 +# Tokyo cache cow command line interface script. 1.6 +# Run <tt>tokyo_cache_cow -h</tt> to get more usage. 1.7 +require File.dirname(__FILE__) + '/../lib/graster' 1.8 + 1.9 +unless ARGV.size == 5 1.10 + puts "usage: ruby tile.rb <input-gcode-file> <tile-width> <tile-height> <horiz-count> <vert-count>" 1.11 + exit(1) 1.12 +end 1.13 + 1.14 +def parse_line line 1.15 + nc = {} 1.16 + line.gsub(/\([^)]*\)/,'').upcase.scan(/([A-Z])\s*([0-9\.]+)?/).each {|code| nc[code[0].intern] = (code[1] && code[1].to_f) } 1.17 + nc 1.18 +end 1.19 + 1.20 +def gcode ncs 1.21 + ncs = [ncs] unless ncs.is_a? Array 1.22 + ncs.reduce('') {|a,nc| a << (nc.map {|k,v| "#{k}#{v}" }.join(' ') + "\n") } 1.23 +end 1.24 + 1.25 +tile_width = ARGV[1].to_f 1.26 +tile_height = ARGV[2].to_f 1.27 +horiz_count = ARGV[3].to_i 1.28 +vert_count = ARGV[4].to_i 1.29 + 1.30 +header = [] 1.31 +body = [] 1.32 +footer = [] 1.33 +state = :header 1.34 + 1.35 + 1.36 +File.open ARGV[0] do |io| 1.37 + io.each_line do |line| 1.38 + if (nc = parse_line(line)) != {} 1.39 + case state 1.40 + when :header 1.41 + if nc[:G] == 0 || nc[:G] == 1 1.42 + state = :body 1.43 + body << nc 1.44 + else 1.45 + header << nc 1.46 + end 1.47 + 1.48 + when :body 1.49 + if nc[:G] == 0 || nc[:G] == 1 1.50 + body << nc 1.51 + else 1.52 + state = :footer 1.53 + footer << nc 1.54 + end 1.55 + 1.56 + when :footer 1.57 + footer << nc 1.58 + end 1.59 + end # case 1.60 + 1.61 + end # io.each_line 1.62 +end # File.open 1.63 + 1.64 +print gcode(header) 1.65 + 1.66 +vert_count.times do |yc| 1.67 + horiz_count.times do |xc| 1.68 + body.each do |nc| 1.69 + nc = nc.dup 1.70 + nc[:X] += xc*tile_width if nc[:X] 1.71 + nc[:Y] += yc*tile_height if nc[:Y] 1.72 + print gcode(nc) 1.73 + end 1.74 + end 1.75 +end 1.76 + 1.77 +print gcode(footer)