Class: JennCad::Commands::Build

Inherits:
Run
  • Object
show all
Defined in:
lib/jenncad/commands.rb

Instance Method Summary collapse

Methods inherited from Run

#check_executable, #execute, #guess_executable, #observe

Instance Method Details

#build(options) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/jenncad/commands.rb', line 51

def build(options)
  if options[:binary]
    admesh_installed = system("admesh --version > /dev/null")
    unless admesh_installed
      puts "Warning: cannot find admesh, stl export will be in ASCII"
    end
  end

  files = Dir.glob("output/**/*.scad")
  if options[:only_print]
    # Remove non _print.scad files from the list of files to build if we have a print orientation (and the only_print flag set)
    files -= Dir.glob("output/**/*_print.scad").map{|x| x.gsub("_print.scad",".scad")}
  end

  files.each do |file|
    stl = file.gsub(".scad",".stl")
    build_stl(file, stl)
    convert_to_binary(stl) if options[:binary] && admesh_installed
  end
end

#build_stl(scad, stl) ⇒ Object



72
73
74
75
# File 'lib/jenncad/commands.rb', line 72

def build_stl(scad, stl)
  puts "building #{stl}"
  system("openscad #{scad} -o #{stl}")
end

#call(options) ⇒ Object



82
83
84
85
86
87
88
89
90
91
# File 'lib/jenncad/commands.rb', line 82

def call(options)
  name = options[:name]
  unless name
    name = guess_executable
  end
  if check_executable(name)
    execute(name)
    build(options)
  end
end

#convert_to_binary(stl) ⇒ Object



77
78
79
# File 'lib/jenncad/commands.rb', line 77

def convert_to_binary(stl)
  system("admesh #{stl} -b #{stl}")
end