crystalscad 0.3.4 → 0.3.5
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.
- data/lib/crystalscad/Assembly.rb +15 -0
- data/lib/crystalscad/BoltHoles.rb +92 -0
- data/lib/crystalscad/CrystalScad.rb +27 -2
- data/lib/crystalscad/Gears.rb +11 -5
- data/lib/crystalscad/Hardware.rb +15 -5
- data/lib/crystalscad/version.rb +1 -1
- data/lib/crystalscad.rb +1 -0
- metadata +4 -3
data/lib/crystalscad/Assembly.rb
CHANGED
@@ -1,3 +1,18 @@
|
|
1
|
+
# This file is part of CrystalScad.
|
2
|
+
#
|
3
|
+
# CrystalScad is free software: you can redistribute it and/or modify
|
4
|
+
# it under the terms of the GNU General Public License as published by
|
5
|
+
# the Free Software Foundation, either version 3 of the License, or
|
6
|
+
# (at your option) any later version.
|
7
|
+
#
|
8
|
+
# CrystalScad is distributed in the hope that it will be useful,
|
9
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
10
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
11
|
+
# GNU General Public License for more details.
|
12
|
+
#
|
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/>.
|
15
|
+
|
1
16
|
module CrystalScad
|
2
17
|
class Assembly
|
3
18
|
attr_accessor :height
|
@@ -0,0 +1,92 @@
|
|
1
|
+
# This file is part of CrystalScad.
|
2
|
+
#
|
3
|
+
# CrystalScad is free software: you can redistribute it and/or modify
|
4
|
+
# it under the terms of the GNU General Public License as published by
|
5
|
+
# the Free Software Foundation, either version 3 of the License, or
|
6
|
+
# (at your option) any later version.
|
7
|
+
#
|
8
|
+
# CrystalScad is distributed in the hope that it will be useful,
|
9
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
10
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
11
|
+
# GNU General Public License for more details.
|
12
|
+
#
|
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/>.
|
15
|
+
|
16
|
+
module CrystalScad::BoltHoles
|
17
|
+
class BoltHole
|
18
|
+
# I would name this Thread but that's already taken by something else
|
19
|
+
|
20
|
+
attr_accessor :x,:y,:z,:size, :depth
|
21
|
+
|
22
|
+
def initialize(args={})
|
23
|
+
@x = args[:x] || 0
|
24
|
+
@y = args[:y] || 0
|
25
|
+
@z = args[:z] || 0
|
26
|
+
@depth = args[:depth]
|
27
|
+
@size = args[:size]
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
def create_bolts(face,obj1,obj2,args={})
|
33
|
+
# make a obj1-=obj2 with bolts corresponding to the heigh tof obj1
|
34
|
+
|
35
|
+
if face == nil or obj1 == nil or obj2 == nil
|
36
|
+
raise "usage: create_bolts(face,obj1,obj2,args={}) - args can include (obj1.)height and bolt_height"
|
37
|
+
return
|
38
|
+
end
|
39
|
+
|
40
|
+
# we need to know obj1 height (if not supplied by user)
|
41
|
+
height ||= args[:height]
|
42
|
+
height ||= obj1.z rescue nil
|
43
|
+
height ||= obj1.height rescue nil
|
44
|
+
if height == nil
|
45
|
+
raise "the object we're substracting from doesn't have a height defined; please define manually"
|
46
|
+
return
|
47
|
+
end
|
48
|
+
|
49
|
+
# lets check if the obj2 responds to the bolt_holes_[face] method
|
50
|
+
|
51
|
+
meth = "bolt_holes_#{face}"
|
52
|
+
|
53
|
+
unless obj2.respond_to?(meth)
|
54
|
+
raise "The object you're trying to get bolts holes from doesn't supply any on the face '#{face}'. Please add a method #{meth} to this object"
|
55
|
+
return
|
56
|
+
end
|
57
|
+
holes = obj2.send(meth)
|
58
|
+
|
59
|
+
|
60
|
+
# let the user either define bolt_heights as integer, array or none (will be guessed)
|
61
|
+
if args[:bolt_height].kind_of? Array
|
62
|
+
bolt_heights = args[:bolt_height]
|
63
|
+
if bolt_heights.size != holes.size
|
64
|
+
raise "object has #{holes.size} threads for bolts but you supplied #{bolt_heights.size}"
|
65
|
+
return
|
66
|
+
end
|
67
|
+
else
|
68
|
+
bolt_heights = []
|
69
|
+
holes.each do |hole|
|
70
|
+
if args[:bolt_height]
|
71
|
+
bolt_heights << args[:bolt_height]
|
72
|
+
else
|
73
|
+
bolt_heights << (height+hole.depth).floor
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
ret = []
|
79
|
+
holes.each_with_index do |hole,i|
|
80
|
+
bolt = Bolt.new(hole.size,bolt_heights[i])
|
81
|
+
|
82
|
+
# FIXME: this all currently only works for "top"
|
83
|
+
bolt.transformations << Rotate.new(x:180)
|
84
|
+
bolt.transformations << Translate.new({x:hole.x,y:hole.y,z:hole.z+height})
|
85
|
+
|
86
|
+
ret << bolt
|
87
|
+
end
|
88
|
+
|
89
|
+
ret
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|
@@ -21,6 +21,7 @@ module CrystalScad
|
|
21
21
|
include CrystalScad::Hardware
|
22
22
|
include CrystalScad::LinearBearing
|
23
23
|
include CrystalScad::Gears
|
24
|
+
include CrystalScad::BoltHoles
|
24
25
|
|
25
26
|
|
26
27
|
class CrystalScadObject
|
@@ -267,12 +268,36 @@ module CrystalScad
|
|
267
268
|
|
268
269
|
def +(args)
|
269
270
|
return args if self == nil
|
270
|
-
|
271
|
+
if args.kind_of? Array
|
272
|
+
r = self
|
273
|
+
args.each do |a|
|
274
|
+
if a.respond_to? :show
|
275
|
+
r = Union.new(r,a.show)
|
276
|
+
else
|
277
|
+
r = Union.new(r,a)
|
278
|
+
end
|
279
|
+
end
|
280
|
+
r
|
281
|
+
else
|
282
|
+
Union.new(self,args)
|
283
|
+
end
|
271
284
|
end
|
272
285
|
|
273
286
|
def -(args)
|
274
287
|
return args if self == nil
|
275
|
-
|
288
|
+
if args.kind_of? Array
|
289
|
+
r = self
|
290
|
+
args.each do |a|
|
291
|
+
if a.respond_to? :output
|
292
|
+
r = Difference.new(r,a.output)
|
293
|
+
else
|
294
|
+
r = Difference.new(r,a)
|
295
|
+
end
|
296
|
+
end
|
297
|
+
r
|
298
|
+
else
|
299
|
+
Difference.new(self,args)
|
300
|
+
end
|
276
301
|
end
|
277
302
|
|
278
303
|
def *(args)
|
data/lib/crystalscad/Gears.rb
CHANGED
@@ -29,14 +29,11 @@ module CrystalScad::Gears
|
|
29
29
|
@height = args[:height] || 3.0
|
30
30
|
@hub_dia = args[:hub_dia] || 0.0
|
31
31
|
@hub_height = args[:hub_height] || 0.0
|
32
|
+
@output_margin_dia = args[:output_margin_dia] || 2
|
33
|
+
@output_margin_height = args[:output_margin_height] || 1
|
32
34
|
end
|
33
35
|
|
34
36
|
def show
|
35
|
-
output
|
36
|
-
end
|
37
|
-
|
38
|
-
# very simple output
|
39
|
-
def output
|
40
37
|
res = cylinder(d:@module*@teeth,h:@height)
|
41
38
|
|
42
39
|
if @hub_height.to_f > 0 && @hub_dia.to_f > 0
|
@@ -48,6 +45,15 @@ module CrystalScad::Gears
|
|
48
45
|
end
|
49
46
|
res.color("darkgray")
|
50
47
|
end
|
48
|
+
|
49
|
+
def output
|
50
|
+
res = cylinder(d:@module*@teeth+@output_margin_dia,h:@height+@output_margin_height)
|
51
|
+
if @hub_height.to_f > 0 && @hub_dia.to_f > 0
|
52
|
+
res += cylinder(d:@hub_dia+@output_margin_dia,h:@hub_height+@output_margin_height).translate(z:@height+@output_margin_height)
|
53
|
+
end
|
54
|
+
|
55
|
+
res
|
56
|
+
end
|
51
57
|
|
52
58
|
def distance_to(other_gear)
|
53
59
|
if @module != other_gear.module
|
data/lib/crystalscad/Hardware.rb
CHANGED
@@ -16,6 +16,8 @@
|
|
16
16
|
module CrystalScad::Hardware
|
17
17
|
|
18
18
|
class Bolt < CrystalScad::Assembly
|
19
|
+
attr_accessor :transformations
|
20
|
+
|
19
21
|
def initialize(size,length,args={})
|
20
22
|
@args = args
|
21
23
|
@args[:type] ||= "912"
|
@@ -27,7 +29,7 @@ module CrystalScad::Hardware
|
|
27
29
|
|
28
30
|
@size = size
|
29
31
|
@length = length
|
30
|
-
|
32
|
+
@transformations ||= []
|
31
33
|
|
32
34
|
@@bom.add(description)
|
33
35
|
end
|
@@ -44,14 +46,22 @@ module CrystalScad::Hardware
|
|
44
46
|
end
|
45
47
|
|
46
48
|
def output
|
47
|
-
return bolt_912(@args[:additional_length],@args[:additional_diameter]) if @args[:type] == "912"
|
48
|
-
return bolt_7380(@args[:additional_length],@args[:additional_diameter]) if @args[:type] == "7380"
|
49
|
+
return transform(bolt_912(@args[:additional_length],@args[:additional_diameter])) if @args[:type] == "912"
|
50
|
+
return transform(bolt_7380(@args[:additional_length],@args[:additional_diameter])) if @args[:type] == "7380"
|
49
51
|
end
|
50
52
|
|
51
53
|
def show
|
52
|
-
return bolt_912(0,0) if @args[:type] == "912"
|
53
|
-
return bolt_7380(0,0) if @args[:type] == "7380"
|
54
|
+
return transform(bolt_912(0,0)) if @args[:type] == "912"
|
55
|
+
return transform(bolt_7380(0,0)) if @args[:type] == "7380"
|
54
56
|
end
|
57
|
+
|
58
|
+
def transform(obj)
|
59
|
+
@transformations.each do |t|
|
60
|
+
obj.transformations << t
|
61
|
+
end
|
62
|
+
|
63
|
+
return obj
|
64
|
+
end
|
55
65
|
|
56
66
|
# ISO 7380
|
57
67
|
def bolt_7380(additional_length=0, addtional_diameter=0)
|
data/lib/crystalscad/version.rb
CHANGED
data/lib/crystalscad.rb
CHANGED
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:
|
4
|
+
hash: 25
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 3
|
9
|
-
-
|
10
|
-
version: 0.3.
|
9
|
+
- 5
|
10
|
+
version: 0.3.5
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Joachim Glauche
|
@@ -67,6 +67,7 @@ files:
|
|
67
67
|
- lib/crystalscad.rb
|
68
68
|
- lib/crystalscad/Assembly.rb
|
69
69
|
- lib/crystalscad/BillOfMaterial.rb
|
70
|
+
- lib/crystalscad/BoltHoles.rb
|
70
71
|
- lib/crystalscad/CrystalScad.rb
|
71
72
|
- lib/crystalscad/Gears.rb
|
72
73
|
- lib/crystalscad/Hardware.rb
|