jenncad 1.0.0.pre.alpha3 → 1.0.0.pre.alpha4

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
  SHA256:
3
- metadata.gz: b3b2667c6121606bece58cc0edbb2d7c0e0f2454dc175b62c3749209c1eef266
4
- data.tar.gz: d8dbc84a707b0767374830df107ebcb098b89591664f0f7062468404b0c512e2
3
+ metadata.gz: ea1fa04592f59d248c5801c3b645f16429bd7ae9f0b754aa467c8a401c89ec4b
4
+ data.tar.gz: 4df185f63b22b5945784cf820b4af937e4fbc660875f36093bbd5ebe9baa2aa9
5
5
  SHA512:
6
- metadata.gz: e512b91a4c6355cfd1b516bc52e434b1670e5aae02b39d75581e423a6242a90b11257a4c4902e30db74de0d4c1693aa7608829393df45806ecf56fc3e409bce9
7
- data.tar.gz: 26fad5ebe17ad65610283315c2c33d9d7842717b78ad8560029038238b18c88aa351667a395f24ef134cf3f9fce298fcb1528ca459c7aeebfe618d71a5186233
6
+ metadata.gz: '0809987ec1b33518b17402acb27b659da2dc7b97ee304d1549abd857ae4448e0342d6ee4523e8d2277d7ce765e1278f996af9882b5da91b71c93acec8bd9ffd9'
7
+ data.tar.gz: e412b05272163c37096d36a44d83ac3d3c5ae07089d7d8d7236c1c53a263c24742566b691efbb5a03c9148960cb7734eb2859bc279e450e34c131fda2ae85af5
data/README.md ADDED
@@ -0,0 +1,83 @@
1
+
2
+ # jenncad
3
+ Create physical objects in Ruby, OpenScad export
4
+
5
+ This is a successor to my older project CrystalScad.
6
+
7
+ # Installation
8
+
9
+ A packaged release is not yet available, please build your own package in the meantime:
10
+
11
+ $ git clone git@github.com:jglauche/jenncad.git
12
+ $ cd jenncad
13
+ $ rake install
14
+
15
+ This will create a gem and a binary jenncad.
16
+
17
+ # Using Jenncad
18
+
19
+ **To create a new project directory, run:**
20
+
21
+ $ jenncad create meow
22
+
23
+
24
+
25
+
26
+ This will generate a directory meow/ and an executable ruby file meow.rb in its directory
27
+
28
+ $ cd meow
29
+ $ ./meow
30
+
31
+ This will generate a dummy project which generates a dummy cube as OpenSCAD output:
32
+
33
+ $ cat output/meow.scad
34
+ > $fn=64;
35
+ > translate([-5, -5, 0])cube([10, 10, 10.0]);
36
+
37
+ **Automatically refresh OpenSCAD output while developing**
38
+
39
+ Jenncad bundles the observr gem which will check if files were changed while developing. In the project directory run:
40
+
41
+ $ jenncad
42
+ This should display something like:
43
+ > refreshing...
44
+ > ok
45
+ > JennCad running, refreshing on file changes. Press ctrl+c to exit
46
+
47
+ **Note:** This does not check for new files in the project. You will have to restart it when you create a new part in a new file
48
+
49
+ **Create new part**
50
+
51
+ In your project directory, run:
52
+
53
+ $ jenncad new cat
54
+ part parts/cat.rb created. In your meow.rb add to class Meow:
55
+ def cat
56
+ Cat.new(config)
57
+ end
58
+
59
+
60
+ You will have to link the part to the project manually into the meow.rb file in your project directory. When you add it, your meow.rb should look like this:
61
+
62
+ #!/usr/bin/env ruby
63
+ require "jenncad"
64
+ include JennCad
65
+
66
+ class Meow < Project
67
+ def config
68
+ {}
69
+ end
70
+
71
+ def meow
72
+ cube(10,10,10)
73
+ end
74
+
75
+ def cat
76
+ Cat.new(config)
77
+ end
78
+
79
+ end
80
+ Meow.new.run
81
+
82
+
83
+
@@ -94,7 +94,12 @@ module JennCad::Exporters
94
94
  if !v.kind_of?(Array) && !v.kind_of?(TrueClass) && !v.kind_of?(FalseClass) && v == v.to_i
95
95
  v = v.to_i
96
96
  end
97
- res << "#{k}=#{v}"
97
+ if v.kind_of? String
98
+ q = "\""
99
+ else
100
+ q = ""
101
+ end
102
+ res << "#{k}=#{q}#{v}#{q}"
98
103
  end
99
104
  res.join(",").gsub("size=","")
100
105
  else
@@ -165,6 +170,8 @@ module JennCad::Exporters
165
170
  new_obj(part, :projection, collect_params(part), parse(part.parts))
166
171
  when JennCad::Primitives::Polygon
167
172
  new_obj(part, :polygon, collect_params(part))
173
+ when JennCad::StlImport
174
+ new_obj(part, :import, collect_params(part))
168
175
  when JennCad::Part
169
176
  parse(part.part)
170
177
  when nil
@@ -192,8 +199,11 @@ module JennCad::Exporters
192
199
  end
193
200
 
194
201
  def collect_params(part)
202
+ if part.respond_to? :openscad_params
203
+ return part.openscad_params
204
+ end
195
205
  res = {}
196
- [:d, :h, :d1, :d2, :size, :fn, :points].each do |var|
206
+ [:d, :h, :d1, :d2, :size, :fn, :points, :file].each do |var|
197
207
  if part.respond_to? var
198
208
  res[var] = part.send var
199
209
  end
@@ -239,7 +249,7 @@ module JennCad::Exporters
239
249
 
240
250
  # accept aggregation
241
251
  def register_module(part)
242
- @modules[part.name] = OpenScadObject.new(:module,part.name, parse(part.part))
252
+ @modules[part.name] = OpenScadObject.new(:module, part.name, parse(part.part))
243
253
  end
244
254
 
245
255
  def handle_import(part)
@@ -1,11 +1,15 @@
1
1
  module JennCad::Features
2
2
  class Aggregation < Feature
3
- attr_accessor :part
3
+ attr_accessor :parts
4
4
 
5
5
  def initialize(name=nil, part=nil)
6
6
  super({})
7
7
  @name = name
8
- @part = part
8
+ @parts = [part] # NOTE: single length arrayto make checking children easier
9
+ end
10
+
11
+ def part
12
+ @parts.first
9
13
  end
10
14
 
11
15
  end
@@ -0,0 +1,10 @@
1
+ module JennCad::Features
2
+ class StlImport < Feature
3
+ attr_accessor :file, :args
4
+
5
+ def initialize(file, args={})
6
+ @file = file
7
+ @args = args
8
+ end
9
+ end
10
+ end
@@ -3,6 +3,8 @@ require "jenncad/features/aggregation"
3
3
  require "jenncad/features/cuttable"
4
4
  require "jenncad/features/openscad_include"
5
5
  require "jenncad/features/climb"
6
+ require "jenncad/features/stl_import"
7
+
6
8
 
7
9
  module JennCad
8
10
  include Features
data/lib/jenncad/part.rb CHANGED
@@ -3,10 +3,10 @@ module JennCad
3
3
  class Part < Thing
4
4
 
5
5
  def to_openscad #make_openscad_compatible
6
- auto_color
6
+ # auto_color
7
7
  a = Aggregation.new(self.class.to_s, self.part) #make_openscad_compatible!(self.part))
8
8
  a.transformations = @transformations
9
- a.color(color)
9
+ a.color(:auto)
10
10
  a
11
11
  end
12
12
 
@@ -1,6 +1,6 @@
1
1
  module JennCad::Primitives
2
2
  class Cylinder < Primitive
3
- attr_accessor :d, :r, :fn
3
+ attr_accessor :d, :d1, :d2, :r, :fn
4
4
  def initialize(args)
5
5
  if args.kind_of?(Array) && args[0].kind_of?(Hash)
6
6
  args = args.first
@@ -43,6 +43,20 @@ module JennCad::Primitives
43
43
  super(args)
44
44
  end
45
45
 
46
+ def openscad_params
47
+ res = {}
48
+ if @opts[:d1]
49
+ [:d1, :d2, :h, :fn].each do |n|
50
+ res[n] = self.send n
51
+ end
52
+ else
53
+ [:d, :h, :fn].each do |n|
54
+ res[n] = self.send n
55
+ end
56
+ end
57
+ res
58
+ end
59
+
46
60
  def handle_fn
47
61
  case @opts[:fn]
48
62
  when nil, 0
@@ -70,6 +84,20 @@ module JennCad::Primitives
70
84
  @d = @opts[:d].to_f + @opts[:margins][:d].to_f
71
85
  @r = @d / 2.0
72
86
  end
87
+
88
+ case @opts[:d1]
89
+ when 0, nil
90
+ else
91
+ @d1 = @opts[:d1].to_f + @opts[:margins][:d].to_f
92
+ @d2 = @opts[:d2].to_f + @opts[:margins][:d].to_f
93
+ end
94
+
95
+ case @opts[:r1]
96
+ when 0, nil
97
+ else
98
+ @d1 = 2 * @opts[:r1].to_f + @opts[:margins][:d].to_f
99
+ @d2 = 2 * @opts[:r2].to_f + @opts[:margins][:d].to_f
100
+ end
73
101
  end
74
102
 
75
103
  def h
@@ -1,5 +1,5 @@
1
1
  module JennCad::Primitives
2
- attr_accessor :convexity
2
+ attr_accessor :cut, :convexity
3
3
  class RotateExtrude < JennCad::Thing
4
4
  def initialize(part, args)
5
5
  @transformations = []
@@ -38,6 +38,10 @@ module JennCad
38
38
  OpenScadImport.new(import, name, args)
39
39
  end
40
40
 
41
+ def stl(file, args={})
42
+ StlImport.new(file, args)
43
+ end
44
+
41
45
  def extrude(args)
42
46
  LinearExtrude.new(self, args)
43
47
  end
data/lib/jenncad/thing.rb CHANGED
@@ -251,38 +251,109 @@ module JennCad
251
251
  item
252
252
  end
253
253
 
254
+ def has_explicit_color?
255
+ if option(:auto_color) == false
256
+ return true
257
+ end
258
+ return false
259
+ end
260
+
261
+ def only_color?(parts, lvl=0)
262
+ return true if parts == nil
263
+
264
+ parts.each do |part|
265
+ # puts " " * lvl + "[only_color?] #{part}"
266
+ if part.has_explicit_color?
267
+ # puts " " * lvl + "found explicit color here"
268
+ return false
269
+ end
270
+ if !only_color?(part.parts, lvl+1)
271
+ return false
272
+ end
273
+ end
274
+ true
275
+ end
276
+
277
+ def set_auto_color_for_children(col, parts, lvl=0)
278
+ return if parts == nil
279
+
280
+ parts.each do |part|
281
+ unless part.has_explicit_color?
282
+ if only_color?(part.parts, lvl+1)
283
+ # puts " " * lvl + "children have no explicit color, setting it here"
284
+ part.set_auto_color(col)
285
+ else
286
+ # puts " " * lvl + "[set_auto_color_for_children] #{part}"
287
+ set_auto_color_for_children(col, part.parts, lvl+1)
288
+ end
289
+ else
290
+ # puts " " * lvl + "[set_auto_color_for_children] this part has a color, ignoring their children"
291
+ end
292
+
293
+ end
294
+ end
295
+
296
+ def set_auto_color(col)
297
+ set_option :color, col
298
+ set_option :auto_color, true
299
+ end
300
+
254
301
  def color(args=nil)
255
- case args
256
- when nil
302
+ if args == nil
257
303
  return option(:color)
258
- when :auto
259
- return auto_color!
304
+ end
305
+
306
+ if args == :auto
307
+ ac = auto_color
308
+ unless ac.nil?
309
+ #puts "auto color to #{ac}"
310
+ if only_color?(self.parts)
311
+ set_option :color, ac
312
+ set_option :auto_color, true
313
+ else
314
+ set_auto_color_for_children(ac, self.parts)
315
+ end
316
+
317
+ end
318
+ return self
319
+ end
320
+
321
+ c = color_parse(args)
322
+ unless c.nil?
323
+ set_option :color, c
324
+ set_option :auto_color, false
325
+ end
326
+
327
+ self
328
+ end
329
+
330
+ def color_parse(args=nil)
331
+ case args
260
332
  when :none
261
333
  set_option :no_auto_color, true
262
334
  when :random
263
- set_option :color, Color.random
335
+ return Color.random
264
336
  when Array
265
- set_option :color, Color.parse(args)
337
+ return Color.parse(args)
266
338
  when /(?<=#)(?<!^)(\h{6}|\h{3})/
267
- set_option :color, args
339
+ return args
268
340
  when /(?<!^)(\h{6}|\h{3})/
269
- set_option :color, "##{args}"
341
+ return "##{args}"
270
342
  when String
271
- set_option :color, args
272
- else
273
- puts "meow"
343
+ return args
274
344
  end
275
- self
345
+ nil
276
346
  end
277
347
 
278
348
  def auto_color
279
349
  if option(:color) == nil && !option(:no_auto_color)
280
- auto_color!
350
+ return auto_color!
281
351
  end
352
+ nil
282
353
  end
283
354
 
284
355
  def auto_color!
285
- color($jenncad_profile.colors.pop)
356
+ color_parse($jenncad_profile.colors.pop)
286
357
  end
287
358
 
288
359
  def color_or_fallback
@@ -1,4 +1,4 @@
1
1
  module JennCad
2
- VERSION = "1.0.0-alpha3"
2
+ VERSION = "1.0.0-alpha4"
3
3
  end
4
4
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jenncad
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.pre.alpha3
4
+ version: 1.0.0.pre.alpha4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jennifer Glauche
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-06-30 00:00:00.000000000 Z
11
+ date: 2022-04-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: geo3d
@@ -88,6 +88,7 @@ executables:
88
88
  extensions: []
89
89
  extra_rdoc_files: []
90
90
  files:
91
+ - README.md
91
92
  - Rakefile
92
93
  - bin/jenncad
93
94
  - examples/old/cube.rb
@@ -114,6 +115,7 @@ files:
114
115
  - lib/jenncad/features/cuttable.rb
115
116
  - lib/jenncad/features/feature.rb
116
117
  - lib/jenncad/features/openscad_include.rb
118
+ - lib/jenncad/features/stl_import.rb
117
119
  - lib/jenncad/part.rb
118
120
  - lib/jenncad/patches/array.rb
119
121
  - lib/jenncad/primitives.rb
@@ -151,7 +153,7 @@ homepage: ''
151
153
  licenses:
152
154
  - LGPL-3
153
155
  metadata: {}
154
- post_install_message:
156
+ post_install_message:
155
157
  rdoc_options: []
156
158
  require_paths:
157
159
  - lib
@@ -166,8 +168,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
166
168
  - !ruby/object:Gem::Version
167
169
  version: 1.3.1
168
170
  requirements: []
169
- rubygems_version: 3.0.3
170
- signing_key:
171
+ rubygems_version: 3.0.9
172
+ signing_key:
171
173
  specification_version: 4
172
174
  summary: TBD
173
175
  test_files: []