crystalscad 0.5.7 → 0.5.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,24 @@
1
+ #!/usr/bin/ruby1.9.3
2
+ require "rubygems"
3
+ require "crystalscad"
4
+ include CrystalScad
5
+
6
+
7
+
8
+
9
+ res = cube([160,20,20]).center_y.translate(x:-5)
10
+ [2.5,3,4,5,6,8,10,12].each do |size|
11
+ b = Bolt.new(size,40)
12
+ n = Nut.new(size)
13
+ res -= b.output
14
+ res -= n.output
15
+ res += n.add_support(0.2)
16
+
17
+ res.translate(x:-20)
18
+ end
19
+
20
+
21
+
22
+
23
+ res.save("nut_support.scad","$fn=64;")
24
+
@@ -11,7 +11,7 @@
11
11
  # GNU General Public License for more details.
12
12
  #
13
13
  # You should have received a copy of the GNU General Public License
14
- # along with CrystalScad. If not, see <http://www.gnu.org/licenses/>.
14
+ # along with CrystalScad. If not, see <http://www.gnu.org/licenses/>fre.
15
15
 
16
16
  require "rubygems"
17
17
  require "rubyscad"
@@ -265,6 +265,8 @@ module CrystalScad
265
265
  rescue NoMethodError
266
266
  end
267
267
  end
268
+ #puts @children.map{|l| l.walk_tree_classes}.inspect
269
+
268
270
  ret +="}"
269
271
  end
270
272
  end
@@ -297,8 +299,26 @@ module CrystalScad
297
299
  end
298
300
  end
299
301
 
302
+ def optimize_union(top, child)
303
+ if top.kind_of? Union and not child.kind_of? Union
304
+ top.children << child
305
+ return top
306
+ else
307
+ return Union.new(top,child)
308
+ end
309
+ end
310
+
311
+ def optimize_difference(top, child)
312
+ if top.kind_of? Difference and not child.kind_of? Difference
313
+ top.children << child
314
+ return top
315
+ else
316
+ return Difference.new(top,child)
317
+ end
318
+ end
319
+
300
320
  def +(args)
301
- return args if self == nil
321
+ return Union.new(nil,args) if self == nil
302
322
  if args.kind_of? Array
303
323
  r = self
304
324
  args.each do |a|
@@ -310,7 +330,7 @@ module CrystalScad
310
330
  end
311
331
  r
312
332
  else
313
- Union.new(self,args)
333
+ optimize_union(self,args)
314
334
  end
315
335
  end
316
336
 
@@ -327,7 +347,7 @@ module CrystalScad
327
347
  end
328
348
  r
329
349
  else
330
- Difference.new(self,args)
350
+ optimize_difference(self,args)
331
351
  end
332
352
  end
333
353
 
@@ -344,7 +364,8 @@ module CrystalScad
344
364
  class Import < Primitive
345
365
  def initialize(args)
346
366
  @transformations = []
347
-
367
+ @children = []
368
+
348
369
  if args.kind_of? String
349
370
  filename = args
350
371
  else # assume hash otherwise
@@ -363,7 +384,12 @@ module CrystalScad
363
384
  if @layer
364
385
  layer = ",layer=\"#{@layer}\""
365
386
  end
366
- return RubyScadBridge.new.import("file=\""+@filename.to_s+"\"#{layer}") # apparently the quotes get lost otherwise
387
+ res = self.children.map{|l| l.walk_tree}
388
+ if res == []
389
+ res = ""
390
+ end
391
+ res += RubyScadBridge.new.import("file=\""+@filename.to_s+"\"#{layer}") # apparently the quotes get lost otherwise
392
+ res
367
393
  end
368
394
  end
369
395
 
@@ -371,6 +397,31 @@ module CrystalScad
371
397
  Import.new(filename)
372
398
  end
373
399
 
400
+ class Render < Primitive
401
+ def initialize(object, attributes)
402
+ @operation = "render"
403
+ @children = [object]
404
+ super(object, attributes)
405
+ end
406
+
407
+ def to_rubyscad
408
+ layer = ""
409
+ if @layer
410
+ layer = ",layer=\"#{@layer}\""
411
+ end
412
+ res = ""
413
+ self.children.map{|l| res += l.walk_tree}
414
+ res += RubyScadBridge.new.render
415
+ res
416
+ end
417
+
418
+ end
419
+
420
+ def render(args={})
421
+ return Render.new(self,args)
422
+ end
423
+
424
+
374
425
  class CSGModifier < Primitive
375
426
  def initialize(object, attributes)
376
427
  @transformations = []
@@ -412,7 +463,7 @@ module CrystalScad
412
463
  super(object, attributes)
413
464
  end
414
465
  end
415
-
466
+
416
467
  class LinearExtrude < CSGModifier
417
468
  def initialize(object, attributes)
418
469
  @operation = "linear_extrude"
@@ -438,6 +489,7 @@ module CrystalScad
438
489
  return Color.new(self,args)
439
490
  end
440
491
 
492
+
441
493
  def linear_extrude(args)
442
494
  if args[:h] # rename to height
443
495
  args[:height] = args[:h]
@@ -534,9 +586,7 @@ module CrystalScad
534
586
  output = nil
535
587
 
536
588
  res.send :initialize # ensure default values are loaded at each interation
537
- unless i == :show or i == :output # call the view method
538
- output = res.send i
539
- end
589
+ output = res.send i
540
590
 
541
591
  # if previous call resulted in a CrystalScadObject, don't call the show method again,
542
592
  # otherwise call it.
@@ -554,6 +604,23 @@ module CrystalScad
554
604
 
555
605
  end
556
606
 
607
+ def get_classes_from_file(filename)
608
+ classes = []
609
+ File.readlines(filename).find_all{|l| l.include?("class")}.each do |line|
610
+ # strip all spaces, tabs
611
+ line.strip!
612
+ # ignore comments (Warning: will not worth with ruby multi line comments)
613
+ next if line[0..0] == "#"
614
+ # strip class definition
615
+ line = line[6..-1]
616
+ # strip until space appears - or if not, to the end
617
+ classes << Object.const_get(line[0..line.index(" ").to_i-1])
618
+ end
619
+
620
+ return classes
621
+ end
622
+
623
+
557
624
  end
558
625
 
559
626
 
@@ -65,7 +65,6 @@ module CrystalScad::Extras
65
65
  res = cube(([x,y,height]))
66
66
  res -= cylinder(d:0.9,h:height*1.42,fn:16).rotate(y:45).translate(x:0)
67
67
  res -= cylinder(d:0.9,h:height*1.42,fn:16).rotate(y:-45).translate(x:1.5)
68
-
69
68
  res
70
69
  end
71
70
 
@@ -230,14 +230,14 @@ module CrystalScad::Hardware
230
230
  end
231
231
 
232
232
  def prepare_data
233
- chart_934 = {2.5=> {side_to_side:5,height:2},
234
- 3 => {side_to_side:5.5,height:2.4},
235
- 4 => {side_to_side:7,height:3.2},
236
- 5 => {side_to_side:8,height:4},
237
- 6 => {side_to_side:10,height:5},
238
- 8 => {side_to_side:13,height:6.5},
239
- 10 => {side_to_side:17,height:8},
240
- 12 => {side_to_side:19,height:10},
233
+ chart_934 = {2.5=> {side_to_side:5,height:2, support_diameter:2.8},
234
+ 3 => {side_to_side:5.5,height:2.4, support_diameter:3.5},
235
+ 4 => {side_to_side:7,height:3.2, support_diameter:4.4},
236
+ 5 => {side_to_side:8,height:4, support_diameter:5.3},
237
+ 6 => {side_to_side:10,height:5, support_diameter:6.3},
238
+ 8 => {side_to_side:13,height:6.5, support_diameter:8.3},
239
+ 10 => {side_to_side:17,height:8, support_diameter:10.3},
240
+ 12 => {side_to_side:19,height:10, support_diameter:12.3},
241
241
 
242
242
  }
243
243
  # for securing nuts
@@ -250,6 +250,7 @@ module CrystalScad::Hardware
250
250
 
251
251
  @s = chart_934[@size][:side_to_side]
252
252
  @height = chart_934[@size][:height]
253
+ @support_diameter = chart_934[@size][:support_diameter]
253
254
 
254
255
  if @type == "985"
255
256
  @height = chart_985[@size][:height]
@@ -257,6 +258,15 @@ module CrystalScad::Hardware
257
258
 
258
259
  end
259
260
 
261
+ def add_support(layer_height=0.2)
262
+ res = cylinder(d:@support_diameter,h:@height-layer_height)
263
+ # on very small nuts, add a support base of one layer height, so the support won't fall over
264
+ if @size < 6
265
+ res += cylinder(d:@s-1,h:layer_height)
266
+ end
267
+ res
268
+ end
269
+
260
270
  def output(margin=0.3)
261
271
  add_to_bom
262
272
  return nut_934(false,margin)
@@ -1,4 +1,4 @@
1
1
  module CrystalScad
2
- VERSION = "0.5.7"
2
+ VERSION = "0.5.8"
3
3
  end
4
4
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: crystalscad
3
3
  version: !ruby/object:Gem::Version
4
- hash: 5
4
+ hash: 27
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 5
9
- - 7
10
- version: 0.5.7
9
+ - 8
10
+ version: 0.5.8
11
11
  platform: ruby
12
12
  authors:
13
13
  - Joachim Glauche
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2015-04-20 00:00:00 Z
18
+ date: 2015-04-28 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: rubyscad
@@ -97,6 +97,7 @@ files:
97
97
  - crystalscad.gemspec
98
98
  - examples/gear.rb
99
99
  - examples/knurls.rb
100
+ - examples/nut_support.rb
100
101
  - examples/openscad_examples/example001.rb
101
102
  - examples/openscad_examples/example002.rb
102
103
  - examples/openscad_examples/example003.rb