jenncad 1.0.0.pre.alpha11 → 1.0.0.pre.alpha14
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/jenncad/default_profile.rb +12 -0
- data/lib/jenncad/exporters/openscad.rb +23 -13
- data/lib/jenncad/extras/din912.rb +1 -1
- data/lib/jenncad/extras/din933.rb +1 -1
- data/lib/jenncad/extras/iso7380.rb +1 -1
- data/lib/jenncad/features/aggregation.rb +1 -1
- data/lib/jenncad/features/climb.rb +3 -3
- data/lib/jenncad/features/cuttable.rb +2 -2
- data/lib/jenncad/part.rb +6 -2
- data/lib/jenncad/patches/array.rb +1 -1
- data/lib/jenncad/primitives/boolean_object.rb +8 -5
- data/lib/jenncad/primitives/cylinder.rb +8 -8
- data/lib/jenncad/primitives/primitive.rb +5 -5
- data/lib/jenncad/primitives/slot.rb +21 -6
- data/lib/jenncad/primitives/subtract_object.rb +3 -3
- data/lib/jenncad/shortcuts.rb +6 -1
- data/lib/jenncad/thing.rb +118 -52
- data/lib/jenncad/transformation/color.rb +1 -1
- data/lib/jenncad/version.rb +1 -2
- data/lib/jenncad.rb +1 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: beb1887d6ae1d3fc87da9c816de1cd2cb54ea5fb3ce7f1277ca6af8bcfc4e687
|
4
|
+
data.tar.gz: 5cc6fd0fc52de9b8b9087dfadd0387122014b157c9573b091aa7c4570a5f2c6a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8f86a697557b258219756ba02c0bb0e478d1c240c05fd53ecb1221749caedd4e7bf7c3395c439f9c0d426e33366d104e71c20a89bca894ee8e0c843733a0446d
|
7
|
+
data.tar.gz: 4ee555b106f36751024a876ece4880b3cea9138e606c541457a809828645f399f3a417cc0f40256e7363bf20f2b212a20f27166429337062a297caddb21931e1
|
@@ -16,6 +16,18 @@ module JennCad
|
|
16
16
|
)
|
17
17
|
end
|
18
18
|
|
19
|
+
# By default, jenncad will add coordinates of subsequent moves in the output
|
20
|
+
# i.e.
|
21
|
+
# .move(x: 10, y: 20).move(x: 10) would result depending on the value of this option:
|
22
|
+
#
|
23
|
+
# true = translate([10,20, 0])translate([10, 0, 0])
|
24
|
+
# false = translate([20, 20, 0])
|
25
|
+
#
|
26
|
+
# defaults to false
|
27
|
+
def chain_moves
|
28
|
+
false
|
29
|
+
end
|
30
|
+
|
19
31
|
def colors
|
20
32
|
case @colors
|
21
33
|
when nil, []
|
@@ -1,8 +1,10 @@
|
|
1
1
|
module JennCad::Exporters
|
2
2
|
class OpenScadObject
|
3
|
-
def initialize(cmd, args, children=[])
|
3
|
+
def initialize(cmd, args, children=[], modifier=nil)
|
4
4
|
@command = cmd
|
5
5
|
@args = args
|
6
|
+
@modifier = modifier || ""
|
7
|
+
|
6
8
|
case children
|
7
9
|
when Array
|
8
10
|
@children = children
|
@@ -43,11 +45,11 @@ module JennCad::Exporters
|
|
43
45
|
def handle_command(i=1)
|
44
46
|
case @children.size
|
45
47
|
when 0
|
46
|
-
"#{@command}(#{handle_args});"
|
48
|
+
"#{@modifier}#{@command}(#{handle_args(@args)});"
|
47
49
|
when 1
|
48
|
-
"#{@command}(#{handle_args})#{@children.first.handle_command(i+1)}"
|
50
|
+
"#{@modifier}#{@command}(#{handle_args(@args)})#{@children.first.handle_command(i+1)}"
|
49
51
|
when (1..)
|
50
|
-
res = "#{@command}(#{handle_args}){"
|
52
|
+
res = "#{@modifier}#{@command}(#{handle_args(@args)}){"
|
51
53
|
res += nl
|
52
54
|
inner = @children.map do |c|
|
53
55
|
next if c == nil
|
@@ -66,17 +68,19 @@ module JennCad::Exporters
|
|
66
68
|
}.join(nl)
|
67
69
|
end
|
68
70
|
|
69
|
-
def handle_args
|
70
|
-
case
|
71
|
+
def handle_args(args)
|
72
|
+
case args
|
71
73
|
when String, Symbol
|
72
|
-
return "\"#{
|
74
|
+
return "\"#{args}\""
|
73
75
|
when Array
|
74
|
-
return
|
76
|
+
return args.map do |l|
|
75
77
|
if l == nil
|
76
78
|
0
|
77
79
|
elsif l.kind_of? Array
|
78
80
|
l # skipping check of 2-dmin Arrays for now (used in multmatrix)
|
79
|
-
elsif l
|
81
|
+
elsif l == 0
|
82
|
+
0
|
83
|
+
elsif l == l.to_i
|
80
84
|
l.to_i
|
81
85
|
else
|
82
86
|
l.to_f
|
@@ -84,15 +88,19 @@ module JennCad::Exporters
|
|
84
88
|
end
|
85
89
|
when Hash
|
86
90
|
res = []
|
87
|
-
|
91
|
+
args.each do |k,v|
|
88
92
|
if k.to_s == "fn"
|
89
93
|
k = "$fn"
|
90
94
|
end
|
91
95
|
if v == nil
|
92
96
|
next
|
93
97
|
end
|
94
|
-
if
|
98
|
+
if v.kind_of?(Array)
|
99
|
+
v = handle_args(v)
|
100
|
+
elsif !v.kind_of?(TrueClass) && !v.kind_of?(FalseClass) && v == v.to_i
|
95
101
|
v = v.to_i
|
102
|
+
elsif v.kind_of? BigDecimal
|
103
|
+
v = v.to_f
|
96
104
|
end
|
97
105
|
if v.kind_of? String
|
98
106
|
q = "\""
|
@@ -185,7 +193,8 @@ module JennCad::Exporters
|
|
185
193
|
def new_obj(part, cmd, args=nil, children=[])
|
186
194
|
transform(part) do
|
187
195
|
apply_color(part) do
|
188
|
-
|
196
|
+
modifier = part.openscad_modifier || nil
|
197
|
+
OpenScadObject.new(cmd, args, children, modifier)
|
189
198
|
end
|
190
199
|
end
|
191
200
|
end
|
@@ -242,7 +251,8 @@ module JennCad::Exporters
|
|
242
251
|
|
243
252
|
def handle_aggregation(part, tabindex=0)
|
244
253
|
register_module(part) unless @modules[part.name]
|
245
|
-
|
254
|
+
$log.debug "aggregation #{part.name} transformations: #{part.transformations.inspect}" if part && part.option(:debug)
|
255
|
+
transform(part.clone) do
|
246
256
|
new_obj(part, part.name, nil)
|
247
257
|
end
|
248
258
|
end
|
@@ -64,7 +64,7 @@ module JennCad::Extras
|
|
64
64
|
if show
|
65
65
|
res.color("Gainsboro")
|
66
66
|
thread_length=Data[@size][:thread_length]
|
67
|
-
if total_length.
|
67
|
+
if total_length.to_d <= thread_length
|
68
68
|
res+= cylinder(d:@size+addtional_diameter, h:total_length).color("DarkGray")
|
69
69
|
else
|
70
70
|
res+= cylinder(d:@size+addtional_diameter, h:total_length-thread_length)
|
@@ -48,7 +48,7 @@ module JennCad::Extras
|
|
48
48
|
14=> {head_side_to_side:22,head_length:9},
|
49
49
|
16=> {head_side_to_side:24,head_length:10},
|
50
50
|
}
|
51
|
-
head_dia = chart[@size][:head_side_to_side].
|
51
|
+
head_dia = chart[@size][:head_side_to_side].to_d + head_margin.to_d
|
52
52
|
res = cylinder(d:(head_dia/Math.sqrt(3))*2,fn:6,h:chart[@size][:head_length]).move(z:-chart[@size][:head_length])
|
53
53
|
total_length = @length + additional_length
|
54
54
|
res+= cylinder(d:@size+addtional_diameter, h:total_length)
|
@@ -36,7 +36,7 @@ module JennCad::Extras
|
|
36
36
|
|
37
37
|
# ISO 7380
|
38
38
|
def bolt_7380(additional_length=0, addtional_diameter=0, head_margin=0)
|
39
|
-
if head_margin.
|
39
|
+
if head_margin.to_d != 0
|
40
40
|
puts "[warning] :head_margin is not implemented for 7380 bolts"
|
41
41
|
end
|
42
42
|
chart_iso7380 = {
|
@@ -31,7 +31,7 @@ module JennCad::Features
|
|
31
31
|
steps = @opts[:steps]
|
32
32
|
(z / steps).floor
|
33
33
|
else
|
34
|
-
step.
|
34
|
+
step.to_d
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
@@ -62,8 +62,8 @@ module JennCad::Features
|
|
62
62
|
|
63
63
|
offset = get_offset(ref_z)
|
64
64
|
|
65
|
-
lo = (ref_z-offset*2).
|
66
|
-
unless lo.
|
65
|
+
lo = (ref_z-offset*2).to_d % step.to_d
|
66
|
+
unless lo.to_d == 0.0
|
67
67
|
puts "[Warning]: climb has leftover offset #{lo}"
|
68
68
|
end
|
69
69
|
|
@@ -16,12 +16,12 @@ module JennCad::Features
|
|
16
16
|
|
17
17
|
def prepare_cut(l, r, &block)
|
18
18
|
part = block.call
|
19
|
-
if part.z.
|
19
|
+
if part.z.to_d > 0.0
|
20
20
|
part.opts[:margins][:z] = 0.2
|
21
21
|
if l == 0.0
|
22
22
|
part.mz(r+0.1)
|
23
23
|
else
|
24
|
-
part.mz(l+part.z.
|
24
|
+
part.mz(l+part.z.to_d-0.2)
|
25
25
|
end
|
26
26
|
else
|
27
27
|
part.opts[:margins][:z] = 0.2
|
data/lib/jenncad/part.rb
CHANGED
@@ -3,9 +3,13 @@ module JennCad
|
|
3
3
|
class Part < Thing
|
4
4
|
|
5
5
|
def to_openscad
|
6
|
-
a = Aggregation.new(self.class.to_s, self.
|
6
|
+
a = Aggregation.new(self.class.to_s, self.get_contents)
|
7
7
|
a.transformations = @transformations
|
8
|
-
|
8
|
+
if self.has_explicit_color?
|
9
|
+
a.color(self.color)
|
10
|
+
else
|
11
|
+
a.color(:auto)
|
12
|
+
end
|
9
13
|
a
|
10
14
|
end
|
11
15
|
|
@@ -7,7 +7,9 @@ module JennCad::Primitives
|
|
7
7
|
else
|
8
8
|
@parts = parts
|
9
9
|
end
|
10
|
+
|
10
11
|
@parent = @parts.first.parent
|
12
|
+
|
11
13
|
after_add
|
12
14
|
end
|
13
15
|
|
@@ -22,6 +24,7 @@ module JennCad::Primitives
|
|
22
24
|
end
|
23
25
|
|
24
26
|
def add(part)
|
27
|
+
return if part.nil?
|
25
28
|
@parts << part
|
26
29
|
after_add
|
27
30
|
end
|
@@ -41,25 +44,25 @@ module JennCad::Primitives
|
|
41
44
|
end
|
42
45
|
|
43
46
|
def inherit_z
|
44
|
-
heights = @parts.map{|l| l.calc_z.
|
47
|
+
heights = @parts.map{|l| l.calc_z.to_d}.uniq
|
45
48
|
if heights.size > 1
|
46
49
|
total_heights = []
|
47
50
|
@parts.each do |p|
|
48
|
-
total_heights << p.z.
|
51
|
+
total_heights << p.z.to_d + p.calc_z.to_d
|
49
52
|
end
|
50
53
|
@z = total_heights.max
|
51
54
|
@calc_z = heights.min
|
52
55
|
else
|
53
|
-
@calc_z = heights.first.
|
56
|
+
@calc_z = heights.first.to_d
|
54
57
|
@z = @parts.map(&:z).compact.max
|
55
58
|
end
|
56
59
|
end
|
57
60
|
|
58
61
|
def inherit_zref
|
59
62
|
return if @parts.first == nil
|
60
|
-
#return if @parts.first.z.
|
63
|
+
#return if @parts.first.z.to_d == 0.0
|
61
64
|
get_primitives(@parts[1..-1]).flatten.each do |part|
|
62
|
-
if part.z.
|
65
|
+
if part.z.to_d == 0.0
|
63
66
|
part.set_option :zref, @parts.first
|
64
67
|
end
|
65
68
|
end
|
@@ -67,13 +67,13 @@ module JennCad::Primitives
|
|
67
67
|
def handle_fn
|
68
68
|
case @opts[:fn]
|
69
69
|
when nil, 0
|
70
|
-
$fn =
|
70
|
+
$fn = auto_dn!
|
71
71
|
else
|
72
72
|
@fn = @opts[:fn]
|
73
73
|
end
|
74
74
|
end
|
75
75
|
|
76
|
-
def
|
76
|
+
def auto_dn!
|
77
77
|
case @d
|
78
78
|
when (16..)
|
79
79
|
@fn = (@d*4).ceil
|
@@ -85,25 +85,25 @@ module JennCad::Primitives
|
|
85
85
|
def handle_radius_diameter
|
86
86
|
case @opts[:d]
|
87
87
|
when 0, nil
|
88
|
-
@r = @opts[:r].
|
88
|
+
@r = @opts[:r].to_d + @opts[:margins][:r].to_d
|
89
89
|
@d = @r * 2.0
|
90
90
|
else
|
91
|
-
@d = @opts[:d].
|
91
|
+
@d = @opts[:d].to_d + @opts[:margins][:d].to_d
|
92
92
|
@r = @d / 2.0
|
93
93
|
end
|
94
94
|
|
95
95
|
case @opts[:d1]
|
96
96
|
when 0, nil
|
97
97
|
else
|
98
|
-
@d1 = @opts[:d1].
|
99
|
-
@d2 = @opts[:d2].
|
98
|
+
@d1 = @opts[:d1].to_d + @opts[:margins][:d].to_d
|
99
|
+
@d2 = @opts[:d2].to_d + @opts[:margins][:d].to_d
|
100
100
|
end
|
101
101
|
|
102
102
|
case @opts[:r1]
|
103
103
|
when 0, nil
|
104
104
|
else
|
105
|
-
@d1 = 2 * @opts[:r1].
|
106
|
-
@d2 = 2 * @opts[:r2].
|
105
|
+
@d1 = 2 * @opts[:r1].to_d + @opts[:margins][:d].to_d
|
106
|
+
@d2 = 2 * @opts[:r2].to_d + @opts[:margins][:d].to_d
|
107
107
|
end
|
108
108
|
end
|
109
109
|
|
@@ -5,14 +5,14 @@ module JennCad::Primitives
|
|
5
5
|
end
|
6
6
|
|
7
7
|
def handle_margins
|
8
|
-
@x = @opts[:x] + @opts[:margins][:x]
|
9
|
-
@y = @opts[:y] + @opts[:margins][:y]
|
10
|
-
@z = @opts[:z] + @opts[:margins][:z]
|
8
|
+
@x = @opts[:x].to_d + @opts[:margins][:x].to_d
|
9
|
+
@y = @opts[:y].to_d + @opts[:margins][:y].to_d
|
10
|
+
@z = @opts[:z].to_d + @opts[:margins][:z].to_d
|
11
11
|
end
|
12
12
|
|
13
13
|
def handle_diameter
|
14
|
-
@d = opts[:d]
|
15
|
-
@r = opts[:r]
|
14
|
+
@d = opts[:d].to_d
|
15
|
+
@r = opts[:r].to_d
|
16
16
|
if @d
|
17
17
|
@r = @d/2.0
|
18
18
|
elsif @r
|
@@ -36,10 +36,25 @@ module JennCad::Primitives
|
|
36
36
|
@d = @opts[:d]
|
37
37
|
@a = @opts[:a]
|
38
38
|
@h = @opts[:h]
|
39
|
-
@r = @opts[:r]
|
39
|
+
@r = @opts[:r] || nil
|
40
|
+
if @r
|
41
|
+
@d = @r * 2
|
42
|
+
end
|
40
43
|
@fn = @opts[:fn]
|
41
44
|
@len_x = @opts[:x]
|
42
45
|
@len_y = @opts[:y]
|
46
|
+
tx = @opts[:tx] || @opts[:total_x] || nil
|
47
|
+
ty = @opts[:ty] || @opts[:total_y] || nil
|
48
|
+
if tx
|
49
|
+
@len_x = tx - @d
|
50
|
+
end
|
51
|
+
if ty
|
52
|
+
@len_y = ty - @d
|
53
|
+
end
|
54
|
+
|
55
|
+
# TODO: this needs anchors like cube
|
56
|
+
# TODO: color on this needs to apply to hull, not on the cylinders.
|
57
|
+
|
43
58
|
end
|
44
59
|
|
45
60
|
def to_openscad
|
@@ -64,16 +79,16 @@ module JennCad::Primitives
|
|
64
79
|
end
|
65
80
|
|
66
81
|
def end_vector
|
67
|
-
if @a.
|
82
|
+
if @a.to_d == 0.0
|
68
83
|
return [@len_x, 0] if @len_x
|
69
84
|
return [0, @len_y] if @len_y
|
70
85
|
end
|
71
86
|
if @len_x
|
72
|
-
x = cos(PI*@a/180.0)*@len_x.
|
73
|
-
y = sin(PI*@a/180.0)*@len_x.
|
87
|
+
x = cos(PI*@a/180.0)*@len_x.to_d
|
88
|
+
y = sin(PI*@a/180.0)*@len_x.to_d
|
74
89
|
else
|
75
|
-
x = -1* sin(PI*@a/180.0)*@len_y.
|
76
|
-
y = cos(PI*@a/180.0)*@len_y.
|
90
|
+
x = -1* sin(PI*@a/180.0)*@len_y.to_d
|
91
|
+
y = cos(PI*@a/180.0)*@len_y.to_d
|
77
92
|
end
|
78
93
|
[x,y]
|
79
94
|
end
|
@@ -2,13 +2,13 @@ module JennCad::Primitives
|
|
2
2
|
class SubtractObject < BooleanObject
|
3
3
|
def inherit_z
|
4
4
|
@z = 0
|
5
|
-
@calc_z = parts.first.calc_z.
|
5
|
+
@calc_z = parts.first.calc_z.to_d
|
6
6
|
|
7
7
|
only_additives_of(@parts).each do |p|
|
8
8
|
if option(:debug)
|
9
9
|
$log.debug "inherit_z checks for: #{p}"
|
10
10
|
end
|
11
|
-
z = p.z.
|
11
|
+
z = p.z.to_d
|
12
12
|
@z = z if z > @z
|
13
13
|
end
|
14
14
|
$log.debug "inherit_z called, biggest z found: #{@z}" if option(:debug)
|
@@ -80,7 +80,7 @@ module JennCad::Primitives
|
|
80
80
|
part.opts[:margins][:z] += 0.004
|
81
81
|
# part.z+=0.004
|
82
82
|
part.mz(-0.002)
|
83
|
-
elsif part.calc_z.
|
83
|
+
elsif part.calc_z.to_d+part.calc_h.to_d == compare_h
|
84
84
|
# puts "z fighting at top: #{compare_h}"
|
85
85
|
#part.z+=0.004
|
86
86
|
part.opts[:margins][:z] += 0.004
|
data/lib/jenncad/shortcuts.rb
CHANGED
@@ -39,7 +39,7 @@ module JennCad
|
|
39
39
|
end
|
40
40
|
|
41
41
|
def stl(file, args={})
|
42
|
-
StlImport.new(file, args)
|
42
|
+
StlImport.new(file, args).set_parent(self)
|
43
43
|
end
|
44
44
|
|
45
45
|
def extrude(args={})
|
@@ -92,6 +92,11 @@ module JennCad
|
|
92
92
|
|
93
93
|
private
|
94
94
|
def boolean_operation(part, klass)
|
95
|
+
if part.respond_to? :transformations
|
96
|
+
# Since ruby doesn't provide a way to make a deep clone, this seems to be the simplest solution that will effectively do that:
|
97
|
+
part = Marshal.load(Marshal.dump(part))
|
98
|
+
end
|
99
|
+
|
95
100
|
case self
|
96
101
|
when nil
|
97
102
|
part
|
data/lib/jenncad/thing.rb
CHANGED
@@ -20,6 +20,7 @@ module JennCad
|
|
20
20
|
@anchors = {}
|
21
21
|
@parent = args[:parent]
|
22
22
|
@opts ||= args
|
23
|
+
@cache = nil
|
23
24
|
end
|
24
25
|
|
25
26
|
def option(key)
|
@@ -39,13 +40,19 @@ module JennCad
|
|
39
40
|
|
40
41
|
def anchor(name, thing=nil)
|
41
42
|
if thing
|
42
|
-
|
43
|
+
res = thing.anchor(name)
|
44
|
+
return res unless res.nil?
|
43
45
|
end
|
44
46
|
@anchors ||= {}
|
45
47
|
if anch = @anchors[name]
|
46
48
|
return anch
|
47
49
|
elsif @parent
|
48
50
|
return @parent.anchor(name)
|
51
|
+
elsif self.respond_to? :get_contents
|
52
|
+
con = get_contents
|
53
|
+
if con.respond_to? :anchor
|
54
|
+
con.anchor(name)
|
55
|
+
end
|
49
56
|
end
|
50
57
|
end
|
51
58
|
alias :a :anchor
|
@@ -86,7 +93,7 @@ module JennCad
|
|
86
93
|
case self
|
87
94
|
when UnionObject
|
88
95
|
ref = self.parts.first
|
89
|
-
rz = self.z.
|
96
|
+
rz = self.z.to_d + self.calc_h.to_d
|
90
97
|
when BooleanObject
|
91
98
|
ref = self.parts.first
|
92
99
|
rz = ref.calc_z + ref.calc_h
|
@@ -114,7 +121,7 @@ module JennCad
|
|
114
121
|
alias :fy :flip_y
|
115
122
|
|
116
123
|
def radians(a)
|
117
|
-
a.
|
124
|
+
a.to_d/180.0*PI
|
118
125
|
end
|
119
126
|
|
120
127
|
# experiment
|
@@ -174,21 +181,41 @@ module JennCad
|
|
174
181
|
end
|
175
182
|
|
176
183
|
def move(args={})
|
184
|
+
return self if args.nil? or args.empty?
|
185
|
+
|
177
186
|
if args.kind_of? Array
|
178
187
|
x,y,z = args
|
179
188
|
return move(x:x, y:y, z:z)
|
180
189
|
end
|
181
190
|
args = parse_xyz_shortcuts(args)
|
182
191
|
|
192
|
+
if args[:x].to_d == 0.0 && args[:y].to_d == 0.0 && args[:z].to_d == 0.0
|
193
|
+
return self
|
194
|
+
end
|
195
|
+
|
183
196
|
@transformations ||= []
|
184
197
|
if args[:prepend]
|
185
198
|
@transformations.prepend(Move.new(args))
|
186
199
|
else
|
187
|
-
@transformations
|
200
|
+
lt = @transformations.last
|
201
|
+
|
202
|
+
chain = if args[:chain]
|
203
|
+
args[:chain]
|
204
|
+
else
|
205
|
+
$jenncad_profile.chain_moves
|
206
|
+
end
|
207
|
+
|
208
|
+
if lt && lt.class == Move && chain == false
|
209
|
+
lt.x += args[:x].to_d
|
210
|
+
lt.y += args[:y].to_d
|
211
|
+
lt.z += args[:z].to_d
|
212
|
+
else
|
213
|
+
@transformations << Move.new(args)
|
214
|
+
end
|
188
215
|
end
|
189
|
-
@calc_x += args[:x].
|
190
|
-
@calc_y += args[:y].
|
191
|
-
@calc_z += args[:z].
|
216
|
+
@calc_x += args[:x].to_d
|
217
|
+
@calc_y += args[:y].to_d
|
218
|
+
@calc_z += args[:z].to_d
|
192
219
|
self
|
193
220
|
end
|
194
221
|
alias :translate :move
|
@@ -207,27 +234,39 @@ module JennCad
|
|
207
234
|
end
|
208
235
|
|
209
236
|
# move to anchor
|
210
|
-
def movea(key, thing=nil)
|
237
|
+
def movea(key, thing=nil, args={})
|
238
|
+
if thing.kind_of? Hash # if you leave out thing, args may be interpreted as thing
|
239
|
+
args = thing
|
240
|
+
thing = nil
|
241
|
+
end
|
242
|
+
|
211
243
|
an = anchor(key, thing)
|
244
|
+
|
212
245
|
unless an
|
213
246
|
$log.error "Error: Anchor #{key} not found"
|
214
247
|
$log.error "Available anchors: #{@anchors}"
|
215
248
|
return self
|
216
249
|
else
|
217
|
-
|
250
|
+
m = an.dup
|
251
|
+
if args[:chain]
|
252
|
+
m[:chain] = args[:chain]
|
253
|
+
end
|
254
|
+
if args[:inverted]
|
255
|
+
self.movei(m)
|
256
|
+
else
|
257
|
+
self.move(m)
|
258
|
+
end
|
218
259
|
end
|
219
260
|
end
|
220
261
|
|
221
262
|
# move to anchor - inverted
|
222
|
-
def moveai(key, thing=nil)
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
$log.error "Available anchors: #{@anchors}"
|
227
|
-
return self
|
228
|
-
else
|
229
|
-
self.movei(an.dup)
|
263
|
+
def moveai(key, thing=nil, args={})
|
264
|
+
if thing.kind_of? Hash # if you leave out thing, args may be interpreted as thing
|
265
|
+
args = thing
|
266
|
+
thing = nil
|
230
267
|
end
|
268
|
+
args[:inverted] = true
|
269
|
+
movea(key, thing, args)
|
231
270
|
end
|
232
271
|
|
233
272
|
|
@@ -264,6 +303,7 @@ module JennCad
|
|
264
303
|
to[key] = args[key]*-1
|
265
304
|
end
|
266
305
|
end
|
306
|
+
to[:chain] = args[:chain]
|
267
307
|
move(to)
|
268
308
|
end
|
269
309
|
|
@@ -327,7 +367,7 @@ module JennCad
|
|
327
367
|
end
|
328
368
|
|
329
369
|
def top_of(other_object)
|
330
|
-
self.move(z:other_object.z+other_object.calc_z.
|
370
|
+
self.move(z:other_object.z+other_object.calc_z.to_d)
|
331
371
|
end
|
332
372
|
|
333
373
|
def on_top_of(other_object)
|
@@ -341,36 +381,14 @@ module JennCad
|
|
341
381
|
def get_children(item, stop_at)
|
342
382
|
res = [item]
|
343
383
|
if item.respond_to?(:parts) && item.parts != nil
|
344
|
-
item.parts.each do |
|
345
|
-
unless stop_at != nil &&
|
346
|
-
res << get_children(
|
384
|
+
item.parts.each do |pa|
|
385
|
+
unless stop_at != nil && pa.kind_of?(stop_at)
|
386
|
+
res << get_children(pa, stop_at)
|
347
387
|
end
|
348
388
|
end
|
349
389
|
end
|
350
390
|
res
|
351
391
|
end
|
352
|
-
=begin def make_openscad_compatible
|
353
|
-
make_openscad_compatible!(self)
|
354
|
-
end
|
355
|
-
|
356
|
-
def make_openscad_compatible!(item)
|
357
|
-
if item.respond_to?(:parts) && item.parts != nil
|
358
|
-
item.parts.each_with_index do |part, i|
|
359
|
-
if part.respond_to? :to_openscad
|
360
|
-
item.parts[i] = part.to_openscad
|
361
|
-
else
|
362
|
-
item.parts[i] = part.make_openscad_compatible
|
363
|
-
end
|
364
|
-
end
|
365
|
-
elsif item.respond_to? :part
|
366
|
-
item = item.part.make_openscad_compatible
|
367
|
-
end
|
368
|
-
if item.respond_to? :to_openscad
|
369
|
-
item = item.to_openscad
|
370
|
-
end
|
371
|
-
item
|
372
|
-
end
|
373
|
-
=end
|
374
392
|
|
375
393
|
def inherit_color(other)
|
376
394
|
self.set_option(:color, other.option(:color))
|
@@ -386,11 +404,14 @@ module JennCad
|
|
386
404
|
|
387
405
|
def only_color?(parts, lvl=0)
|
388
406
|
return true if parts == nil
|
407
|
+
unless parts.kind_of? Array
|
408
|
+
parts = [parts]
|
409
|
+
end
|
389
410
|
|
390
411
|
parts.each do |part|
|
391
|
-
#
|
412
|
+
#puts " " * lvl + "[only_color?] #{part}"
|
392
413
|
if part.has_explicit_color?
|
393
|
-
#
|
414
|
+
#puts " " * lvl + "found explicit color here: #{part.color}"
|
394
415
|
return false
|
395
416
|
end
|
396
417
|
if !only_color?(part.parts, lvl+1)
|
@@ -406,14 +427,14 @@ module JennCad
|
|
406
427
|
parts.each do |part|
|
407
428
|
unless part.has_explicit_color?
|
408
429
|
if only_color?(part.parts, lvl+1)
|
409
|
-
#
|
430
|
+
#puts " " * lvl + "children have no explicit color, setting it here"
|
410
431
|
part.set_auto_color(col)
|
411
432
|
else
|
412
|
-
#
|
433
|
+
#puts " " * lvl + "[set_auto_color_for_children] #{part}"
|
413
434
|
set_auto_color_for_children(col, part.parts, lvl+1)
|
414
435
|
end
|
415
436
|
else
|
416
|
-
#
|
437
|
+
#puts " " * lvl + "[set_auto_color_for_children] this part has a color #{part.color}, ignoring their children"
|
417
438
|
end
|
418
439
|
|
419
440
|
end
|
@@ -489,8 +510,15 @@ module JennCad
|
|
489
510
|
|
490
511
|
def get_contents
|
491
512
|
return @parts unless @parts.nil?
|
513
|
+
|
514
|
+
if @cache
|
515
|
+
return @cache
|
516
|
+
end
|
517
|
+
|
492
518
|
if self.respond_to? :part
|
493
|
-
|
519
|
+
# cache things to prevent calling the code in #part multiple times
|
520
|
+
@cache = part
|
521
|
+
return @cache
|
494
522
|
end
|
495
523
|
end
|
496
524
|
|
@@ -503,6 +531,9 @@ module JennCad
|
|
503
531
|
|
504
532
|
def find_calculated_h(parts)
|
505
533
|
return if parts == nil
|
534
|
+
unless parts.kind_of? Array
|
535
|
+
parts = [parts]
|
536
|
+
end
|
506
537
|
parts.each do |part|
|
507
538
|
if z = calculated_h
|
508
539
|
return z
|
@@ -513,6 +544,10 @@ module JennCad
|
|
513
544
|
|
514
545
|
def set_heights_for_auto_extrude(parts, parent=nil)
|
515
546
|
return if parts.nil?
|
547
|
+
unless parts.kind_of? Array
|
548
|
+
parts = [parts]
|
549
|
+
end
|
550
|
+
|
516
551
|
parts.each do |part|
|
517
552
|
if part.option(:auto_extrude)
|
518
553
|
part.z = parent.calculated_h
|
@@ -529,8 +564,39 @@ module JennCad
|
|
529
564
|
JennCad::Exporters::OpenScad.new(self).save(file)
|
530
565
|
end
|
531
566
|
|
567
|
+
def ghost
|
568
|
+
set_option :ghost, true
|
569
|
+
set_option :no_auto_color, true
|
570
|
+
set_option :color, nil
|
571
|
+
set_option :auto_color, false
|
572
|
+
self
|
573
|
+
end
|
574
|
+
|
575
|
+
def hide
|
576
|
+
set_option :hide, true
|
577
|
+
self
|
578
|
+
end
|
579
|
+
|
580
|
+
def only
|
581
|
+
set_option :only, true
|
582
|
+
self
|
583
|
+
end
|
584
|
+
|
585
|
+
def hl
|
586
|
+
set_option :highlight, true
|
587
|
+
self
|
588
|
+
end
|
589
|
+
|
590
|
+
def openscad_modifier
|
591
|
+
return "%" if option(:ghost)
|
592
|
+
return "#" if option(:highlight)
|
593
|
+
return "!" if option(:only)
|
594
|
+
return "*" if option(:hide)
|
595
|
+
nil
|
596
|
+
end
|
597
|
+
|
532
598
|
def referenced_z
|
533
|
-
return false if @z.
|
599
|
+
return false if @z.to_d != 0.0
|
534
600
|
return option(:zref) if option(:zref)
|
535
601
|
return false
|
536
602
|
end
|
@@ -545,7 +611,7 @@ module JennCad
|
|
545
611
|
when nil, false
|
546
612
|
@z + z_margin
|
547
613
|
else
|
548
|
-
ref.z.
|
614
|
+
ref.z.to_d + ref.z_margin.to_d
|
549
615
|
end
|
550
616
|
end
|
551
617
|
|
@@ -554,7 +620,7 @@ module JennCad
|
|
554
620
|
when nil, {}
|
555
621
|
0.0
|
556
622
|
else
|
557
|
-
m[:z].
|
623
|
+
m[:z].to_d
|
558
624
|
end
|
559
625
|
end
|
560
626
|
|
data/lib/jenncad/version.rb
CHANGED
data/lib/jenncad.rb
CHANGED
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.
|
4
|
+
version: 1.0.0.pre.alpha14
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jennifer Glauche
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-05-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: geo3d
|