crystalscad 0.6.2 → 0.6.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,48 @@
1
+ #!/usr/bin/ruby1.9.3
2
+ require "rubygems"
3
+ require "crystalscad"
4
+ include CrystalScad
5
+
6
+ class NutPart < CrystalScad::Assembly
7
+ def initialize
8
+ @hardware = []
9
+ @height = 10
10
+ end
11
+
12
+ def part(show)
13
+ res = cube([50,50,@height]).center_xy
14
+
15
+ @hardware << Nut.new(4,direction:"-z")
16
+ @hardware << Nut.new(4,direction:"z").translate(x:10,z:@height-3)
17
+ @hardware << Nut.new(4,slot:15,slot_direction:"-x",direction:"x").rotate(y:90).translate(x:-20,y:5,z:@height-5)
18
+ @hardware << Nut.new(4,slot:15,slot_direction:"x",direction:"x").rotate(y:-90).translate(x:20,y:-8,z:@height-5)
19
+
20
+ @hardware << Nut.new(4,slot:15,slot_direction:"-y",direction:"y").rotate(x:-90).translate(x:2,y:-20,z:@height-5)
21
+ @hardware << Nut.new(4,slot:15,slot_direction:"y",direction:"y").rotate(x:90).translate(x:-10,y:20,z:@height-5)
22
+
23
+ res -= @hardware
24
+ end
25
+ end
26
+
27
+
28
+ class ScrewOnPart < CrystalScad::Assembly
29
+ def initialize
30
+ @nutpart = NutPart.new
31
+ end
32
+
33
+ def part(show)
34
+ res = @nutpart.show
35
+
36
+ @nutpart.hardware.each do |hw|
37
+ res += hw.bolt(20)
38
+ end
39
+ res
40
+ end
41
+
42
+ end
43
+
44
+
45
+
46
+ res = ScrewOnPart.new.show
47
+
48
+ res.save("threads3.scad")
@@ -217,18 +217,53 @@ module CrystalScad::Hardware
217
217
  @surface = args[:surface] ||= "zinc plated"
218
218
  @support = args[:support] ||= false
219
219
  @support_layer_height = args[:support_layer_height] ||= 0.2
220
+ @margin = args[:margin] ||= 0.3 # default output margin
220
221
 
222
+ @slot = args[:slot] || nil
223
+ @slot_margin = args[:slot_margin] || 0.5
224
+ @slot_direction = args[:slot_direction] || "z"
225
+ @cylinder_length = args[:cylinder_length] || 0 # for slot only
221
226
 
222
227
  @transformations ||= []
223
228
  @args = args
224
229
  prepare_data
225
230
  @height = args[:height] || @height
231
+
232
+ @direction = args[:direction] || @slot_direction
233
+
234
+ @bolt = nil
235
+
226
236
  end
227
237
 
228
238
  def description
229
239
  "M#{@size} Nut, DIN #{@type}, #{@material} #{@surface}"
230
240
  end
231
241
 
242
+ def bolt(length=nil, args={})
243
+ return @bolt if @bolt
244
+ @bolt = Bolt.new(@size,length,args)
245
+ case @direction
246
+ when "z"
247
+ bolt.transformations << Rotate.new(x:180)
248
+ bolt.transformations << Translate.new({z:length })
249
+ when "-z"
250
+ bolt.transformations << Translate.new({z:-length+@height})
251
+ when "-x"
252
+ bolt.transformations << Rotate.new(x:180)
253
+ bolt.transformations << Translate.new({z:length})
254
+ when "x"
255
+ bolt.transformations << Translate.new({z:-length+@height})
256
+ when "-y"
257
+ bolt.transformations << Rotate.new(x:180)
258
+ bolt.transformations << Translate.new({z:length})
259
+ when "y"
260
+ bolt.transformations << Translate.new({z:-length+@height})
261
+ end
262
+ @bolt.transformations += self.transformations.dup
263
+
264
+ return @bolt
265
+ end
266
+
232
267
  def prepare_data
233
268
  chart_934 = {2.5=> {side_to_side:5,height:2, support_diameter:2.8},
234
269
  3 => {side_to_side:5.5,height:2.4, support_diameter:3.5},
@@ -266,9 +301,40 @@ module CrystalScad::Hardware
266
301
  res
267
302
  end
268
303
 
269
- def output(margin=0.3)
304
+ def slot
305
+ case @slot_direction
306
+ when "x"
307
+ pos = {x:@slot}
308
+ when "y"
309
+ pos = {y:@slot}
310
+ when "z"
311
+ pos = {z:@slot}
312
+ when "-x"
313
+ pos = {x:-@slot}
314
+ when "-y"
315
+ pos = {y:-@slot}
316
+ when "-z"
317
+ pos = {z:-@slot}
318
+ else
319
+ raise "Invalid slot direction #{@slot_direction}"
320
+ end
321
+ res = hull(
322
+ nut_934(false,@margin,@slot_margin),
323
+ nut_934(false,@margin,@slot_margin).translate(pos)
324
+ )
325
+ if @cylinder_length > 0
326
+ res += cylinder(d:@size+@margin,h:@cylinder_length)
327
+ end
328
+ res
329
+ end
330
+
331
+ def output
270
332
  add_to_bom
271
- return transform(nut_934(false,margin))
333
+ if @slot == nil
334
+ return transform(nut_934(false,@margin))
335
+ else
336
+ return transform(slot)
337
+ end
272
338
  end
273
339
 
274
340
  def show
@@ -276,9 +342,10 @@ module CrystalScad::Hardware
276
342
  return transform(nut_934)
277
343
  end
278
344
 
279
- def nut_934(show=true,margin=0)
345
+ def nut_934(show=true,margin=0,height_margin=0)
280
346
  @s += margin
281
- res = cylinder(d:(@s/Math.sqrt(3))*2,h:@height,fn:6)
347
+
348
+ res = cylinder(d:(@s/Math.sqrt(3))*2,h:@height+height_margin,fn:6)
282
349
  res -= cylinder(d:@size,h:@height) if show == true
283
350
  if @support
284
351
  res -= add_support
@@ -16,7 +16,7 @@
16
16
 
17
17
 
18
18
  module CrystalScad
19
- class Pipe
19
+ class Pipe < Assembly
20
20
  attr_accessor :x,:y, :sum_x, :sum_y, :pipe, :bent_segments
21
21
  # Warning: sum_x and sum_y are both a quick hack at the moment
22
22
  # They will ONLY work on bends if you do same thing in the other direction
@@ -23,7 +23,7 @@ module CrystalScad
23
23
  @transformations << Translate.new(args)
24
24
  self
25
25
  end
26
-
26
+
27
27
  def union(args)
28
28
  @transformations ||= []
29
29
  @transformations << Union.new(args)
@@ -45,6 +45,13 @@ module CrystalScad
45
45
  self
46
46
  end
47
47
 
48
+ # copies the transformation of obj to self
49
+ def transform(obj)
50
+ @transformations ||= []
51
+ @transformations += obj.transformations
52
+ self
53
+ end
54
+
48
55
 
49
56
  end
50
57
  end
@@ -86,7 +86,7 @@ module CrystalScad::ScrewThreads
86
86
  end
87
87
 
88
88
  def create_bolts(face,obj1,obj2,args={})
89
- # make a obj1-=obj2 with bolts corresponding to the heigh tof obj1
89
+ # make a obj1-=obj2 with bolts corresponding to the height of obj1
90
90
 
91
91
  if face == nil or obj1 == nil or obj2 == nil
92
92
  raise "usage: create_bolts(face,obj1,obj2,args={}) - args can include (obj1.)height and bolt_height"
@@ -1,4 +1,4 @@
1
1
  module CrystalScad
2
- VERSION = "0.6.2"
2
+ VERSION = "0.6.3"
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: 3
4
+ hash: 1
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 6
9
- - 2
10
- version: 0.6.2
9
+ - 3
10
+ version: 0.6.3
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-05-08 00:00:00 Z
18
+ date: 2015-05-15 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: rubyscad
@@ -111,6 +111,7 @@ files:
111
111
  - examples/stack.rb
112
112
  - examples/threads.rb
113
113
  - examples/threads2.rb
114
+ - examples/threads3.rb
114
115
  - lib/crystalscad.rb
115
116
  - lib/crystalscad/Assembly.rb
116
117
  - lib/crystalscad/BillOfMaterial.rb