oozby 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5011b1b0b04f3a797f17d23572edc2bcefab387c
4
- data.tar.gz: 20e1ce49a8c42a847bb40930d4c76b041674e85b
3
+ metadata.gz: 65d655bb878ca1d6f884b0ed18f710669e64d6f7
4
+ data.tar.gz: 4d9e1326e16f2436caa73b9a1a73a43dca9e7a18
5
5
  SHA512:
6
- metadata.gz: ad55acc6736bbcd0c1fdc4c41b22daacbcae995dd9c915c7c95aac4a24038fbe66db4cfa622c0eacb3b8a133957a005a3642c2e5a8b56c3a5c6496c99f9b07fe
7
- data.tar.gz: 1f47fca1a937a05c199686a62007b8f7246dde56112278fa9bfc34ee201eb165ade3da96e092795d62a4dd5fdf7caa68d3b465d1ddd20df68f9e12bc094b20ef
6
+ metadata.gz: 87f4f684352daf605291502a0c470c38a181e2263dac1588f177c818486db5a5092e6abd3e6190ac10bbb67e451ac3bb39769e98a88961ea986d868f6c6de151
7
+ data.tar.gz: 244a08c28e31d3cfd781fd895d34df5c843b2f1f15aa68e1f89ab7173809653b2adf15b1bf407bd4d86255dd622d3b7a97cfb008c93cb7259353a05edca67bfa
data/bin/oozby CHANGED
@@ -2,23 +2,25 @@
2
2
  require 'thor'
3
3
  require 'listen'
4
4
  require 'pp'
5
+ require 'rbconfig'
5
6
  require File.join(__dir__, '..', 'lib', 'oozby')
6
7
 
7
8
  # motivational exit messages!
8
9
  $quit_message = {
9
- '0.2.2' => "Have a nice day!",
10
- '0.2.3' => "You're a superstar!",
11
- '0.2.4' => "Keep up the great work!",
12
- '0.2.5' => "Nice job!",
13
- '0.2.6' => "It was a pleasure working with you!"
10
+ '0.3.0' => "Have a nice day!",
11
+ '0.3.1' => "You're a superstar!",
12
+ '0.3.2' => "Keep up the great work!",
13
+ '0.3.3' => "Nice job!",
14
+ '0.3.4' => "It was a pleasure working with you!"
14
15
  }
15
16
 
16
17
  class OozbyUtility < Thor
17
18
  desc "compile some#{File::SEPARATOR}folder", "The Oozby Utility searches a directory and compiles all the .oozby files it finds, creating identically named files with .scad stuck on the end, translated in to OpenSCAD nonsense. Open those files in OpenSCAD app and enable Automatic Reload and Compile in the Design menu, then get to work."
18
19
 
19
20
  option :verbose, type: :boolean, desc: "Output lots of gunk, to figure out bizarre bugs in Oozby"
21
+ option :abstract_tree, type: :boolean, desc: "Output Abstract Tree (debugging)"
20
22
  option :all, type: :boolean, desc: "Don't skip any files - recompile them all!"
21
- option :watch, type: :boolean, default: true, desc: "Watch directory for changes and automatically recompile"
23
+ option :no_watch, type: :boolean, desc: "Don't watch directory for changes - exit immediately"
22
24
  def compile path
23
25
  if File.file? path
24
26
  ooz = Oozby.new
@@ -28,7 +30,7 @@ class OozbyUtility < Thor
28
30
  begin
29
31
  ooz.parse_file path
30
32
 
31
- if options[:verbose]
33
+ if options[:abstract_tree]
32
34
  puts "Oozby Abstract Syntax Tree:"
33
35
  pp ooz.abstract_tree
34
36
  end
@@ -50,12 +52,12 @@ class OozbyUtility < Thor
50
52
  globber = File.join(directory, '**', '*.oozby')
51
53
  files = Dir.glob(globber)
52
54
  files.each do |filename|
53
- compile filename if !File.exists?("#{filename}.scad") || File.mtime(filename) >= File.mtime("#{filename}.scad") || options[:all]
55
+ subprocess_compile filename if !File.exists?("#{filename}.scad") || File.mtime(filename) >= File.mtime("#{filename}.scad") || options[:all]
54
56
  end
55
57
 
56
- if options[:watch]
58
+ unless options[:no_watch]
57
59
  recompile_handler = lambda do |*args|
58
- compile File.join(*args)
60
+ subprocess_compile File.join(*args)
59
61
  end
60
62
 
61
63
  puts "Watching folder for changes... (CTRL+C to exit)"
@@ -76,6 +78,18 @@ class OozbyUtility < Thor
76
78
  puts ""
77
79
  puts $quit_message[Oozby.version] || $quit_message.values.last
78
80
  end
81
+
82
+ private
83
+ # open up a subprocess to execute this file, so we don't polute the scope when watching
84
+ # or processing several files
85
+ def subprocess_compile filename
86
+ this_file = File.expand_path(__FILE__)
87
+ ruby_bin = File.join(RbConfig::CONFIG['bindir'], RbConfig::CONFIG['ruby_install_name'])
88
+ args = [ruby_bin, this_file, 'compile']
89
+ args.push '--verbose' if options[:verbose]
90
+ args.push filename
91
+ system(*args)
92
+ end
79
93
  end
80
94
 
81
95
  OozbyUtility.start(ARGV)
@@ -0,0 +1,35 @@
1
+ # Liion represents standard round lithium ion cells, like the common 18650
2
+ # offering width and height properties, and a #part method which instansiates
3
+ # a 3D model of the battery, including specified tollerance
4
+ class LiionBattery
5
+ include Oozby::Geometry # allow module to call oozby methods
6
+ ProtectedRoundLiionOffset = 1020
7
+
8
+ def initialize code, protected: false, tollerance: 0.5
9
+ @tollerance = tollerance
10
+ @protected = protected
11
+
12
+ # decode battery code in to diameters
13
+ code = code.to_i + ProtectedRoundLiionOffset if protected
14
+ @width, @height = code.to_s.match(/(\d\d)(\d\d\d)/).captures.map(&:to_f)
15
+ @height = @height / 10.0
16
+ @height += @tollerance
17
+ @width += @tollerance
18
+ end
19
+
20
+ # create 3D model of battery at current oozby location
21
+ def part
22
+ positive_tab_diameter = (@width / 2.5) .. (@width / 3.0)
23
+
24
+ union do
25
+ # main battery section
26
+ cylinder height: @height, diameter: @width
27
+
28
+ # positive tab
29
+ translate(z: @height - 0.05) > cylinder(diameter: positive_tab_diameter, height: 1.0)
30
+ end
31
+ end
32
+
33
+ attr_accessor :width, :height, :protected, :tollerance
34
+ end
35
+
@@ -20,12 +20,21 @@ class Oozby
20
20
 
21
21
  # rescue block to filter out junk oozby library stuff from backtraces
22
22
  begin
23
- compiled = eval("lambda {; #{code};\n }", nil, filename)
24
- env.instance_exec(&compiled)
23
+ compiled = eval("lambda {; #{code}\n }", nil, filename)
24
+ env._execute_oozby(&compiled)
25
25
  rescue StandardError, NoMethodError => err
26
26
  backtrace = $!.backtrace
27
27
  #backtrace = backtrace.select { |item| !item.include? __dir__ } unless backtrace.first.include? __dir__
28
- backtrace.delete_if { |item| item.to_s =~ /(\.rb|\/oozby):/ } if @filter_errors
28
+
29
+ if @filter_errors # and backtrace.index { |i| i.include? ".oozby:" } < 3
30
+ execute_oozby_idx = backtrace.index { |i| i.include? "in `_execute_oozby'" }
31
+ backtrace = backtrace[0...execute_oozby_idx] if execute_oozby_idx
32
+ backtrace.delete_if do |item|
33
+ filename = item.split(':').first
34
+ filename = File.realpath(filename)
35
+ filename.start_with? __dir__
36
+ end
37
+ end
29
38
 
30
39
  raise $!, $!.message, backtrace
31
40
  end
@@ -8,6 +8,10 @@ class Oozby::Environment
8
8
  fragments: 0
9
9
  }
10
10
 
11
+ class << self
12
+ attr_accessor :active
13
+ end
14
+
11
15
  def initialize(ooz: nil)
12
16
  @parent = ooz
13
17
  @ast = []
@@ -21,7 +25,7 @@ class Oozby::Environment
21
25
  end
22
26
 
23
27
  # create a new scope that inherits from this one, and capture syntax tree created
24
- def _subscope &proc
28
+ def _subscope *args, &proc
25
29
  # capture instance variables
26
30
  capture = {}
27
31
  instance_variables.each { |key| capture[key] = self.instance_variable_get(key) }
@@ -31,7 +35,7 @@ class Oozby::Environment
31
35
  @one_time_modifier = nil
32
36
  @defaults = @defaults.dup
33
37
  @resolution = @resolution.dup
34
- self.instance_eval &proc
38
+ proc[*args]
35
39
  syntax_tree = @ast
36
40
 
37
41
  # restore instance variables
@@ -45,9 +49,14 @@ class Oozby::Environment
45
49
  @ast.push(*code)
46
50
  end
47
51
 
52
+ # do we know of this method
53
+ def oozby_method_defined? name
54
+ @method_preprocessor.known?(name.to_sym) or !@preprocess or respond_to?(name)
55
+ end
56
+
48
57
  def method_missing method_name, *args, **hash, &proc
49
58
  # unless we know of this method in OpenSCAD or the preprocessor, abort!
50
- unless @method_preprocessor.known?(method_name) or !@preprocess
59
+ unless oozby_method_defined? method_name
51
60
  # grab a list of all known methods, suggest a guess to user
52
61
  known = @method_preprocessor.known
53
62
  known.push(*public_methods(false))
@@ -61,6 +70,10 @@ class Oozby::Environment
61
70
  return super # continue to raise the usual error and all that
62
71
  end
63
72
 
73
+ oozby_send_method method_name, *args, **hash, &proc
74
+ end
75
+
76
+ def oozby_send_method method_name, *args, **hash, &proc
64
77
  if proc
65
78
  children = _subscope(&proc)
66
79
  else
@@ -207,6 +220,15 @@ class Oozby::Environment
207
220
  @ast.push(execute: !!execute, import: filename)
208
221
  end
209
222
 
223
+ # run some oozby code contained inside a proc
224
+ def _execute_oozby &code
225
+ previously = self.class.active
226
+ self.class.active = self
227
+ result = instance_exec(&code)
228
+ self.class.active = previously
229
+ return result
230
+ end
231
+
210
232
  def _scan_methods_from_scad_file filename
211
233
  raise "OpenSCAD file #{filename} not found" unless File.exists? filename
212
234
  data = File.read(filename)
@@ -242,9 +264,19 @@ class Oozby::Environment
242
264
  # returns the abstract tree
243
265
  def _abstract_tree; @ast; end
244
266
 
267
+ # make backtraces clearer
245
268
  def inspect; "OozbyFile"; end
246
269
  end
247
270
 
248
-
249
-
271
+ # module you can include in your classes to be able to make 3d shapes in them
272
+ module Oozby::Geometry
273
+ def method_missing *args, &proc
274
+ environ = Oozby::Environment.active
275
+ if environ.oozby_method_defined?(args.first)
276
+ environ.oozby_send_method *args, &proc
277
+ else
278
+ super
279
+ end
280
+ end
281
+ end
250
282
 
@@ -139,8 +139,10 @@ class Oozby::MethodPreprocessor
139
139
  data = info.named_args.delete(d)
140
140
  if data.is_a? Range
141
141
  data = Range.new(data.first / 2.0, data.last / 2.0, data.exclude_end?)
142
+ elsif data.respond_to? :to_f
143
+ data = data.to_f / 2.0
142
144
  else
143
- data = data / 2.0
145
+ raise "#{data.inspect} must be Numeric or a Range"
144
146
  end
145
147
  info.named_args[r] = data
146
148
  end
@@ -157,8 +159,10 @@ class Oozby::MethodPreprocessor
157
159
  circumradius = Range.new(inradius.first.to_f / @env.cos(180.0 / sides),
158
160
  inradius.first.to_f / @env.cos(180.0 / sides),
159
161
  inradius.exclude_end?)
160
- else
162
+ elsif inradius.respond_to? :to_f
161
163
  circumradius = inradius.to_f / @env.cos(180.0 / sides)
164
+ else
165
+ raise "#{inradius.inspect} must be Numeric or a Range"
162
166
  end
163
167
  info.named_args[r] = circumradius
164
168
  end
@@ -282,9 +286,10 @@ class Oozby::MethodPreprocessor
282
286
  end
283
287
 
284
288
  def capture &proc
285
- (@env._subscope {
286
- preprocessor(false) {
287
- instance_eval(&proc)
289
+ env = @env
290
+ (env._subscope {
291
+ env.preprocessor(false) {
292
+ env._execute_oozby(&proc)
288
293
  }
289
294
  }).first
290
295
  end
@@ -1,5 +1,5 @@
1
1
  class Oozby
2
- Version = '0.3.0'
2
+ Version = '0.3.1'
3
3
 
4
4
  def self.version
5
5
  Oozby::Version
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oozby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bluebie
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-09-23 00:00:00.000000000 Z
11
+ date: 2013-09-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: listen
@@ -73,6 +73,7 @@ files:
73
73
  - lib/oozby.rb
74
74
  - readme.md
75
75
  - license.txt
76
+ - examples/using classes/demo-class.rb
76
77
  - bin/oozby
77
78
  homepage: http://github.com/Bluebie/digiusb.rb
78
79
  licenses: