jenncad 1.0.0.pre.alpha21 → 1.0.0.pre.alpha22

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: bf38a53bfb5d20ab5af97d24c948792ae3e5d577d63806f4a9d7008b5429f507
4
- data.tar.gz: aae023c68738b1aee605fff567b3d0792f98753252858e1ee2569a18dd470daf
3
+ metadata.gz: 655d1eab8f78d92f18915154cdc36a57fecfcb222e40dc69e663c974d5d85052
4
+ data.tar.gz: 79bd0ecee0ea0b3b691c4953ec33e68e1783248899d1e9417fe9cfac80e6fc46
5
5
  SHA512:
6
- metadata.gz: fe8765bc981516be5fe1e94212e946a32d14baf295e0995be9820589dbe31b1be430a1792c1c8bd57ceaeab132ae495668ba8852fa7dbd16676b3345d3c4c8e8
7
- data.tar.gz: 5667ae97532fa9094125d65603f8542a2cef77621c082ff2c097eebc3865ae5ca683ac16cc5cc9b2a3a09042ca6bd678cadd351f0fa468698e94fc56cf3bedfc
6
+ metadata.gz: 77c14e0645ff92f85f8746830469707d91495b7cf57d8d64210a0c2da7d7a6b0f9c27c3b4eb6fdcfdcd983a6d647b54309d4e10d2d407d70f7e55d02cd72ec9f
7
+ data.tar.gz: dd7538fb2068d4cb15326af37f7324d19c31828e3584b700f78ea585004790ee9033576e235e17774f007722f3b5a729d4a6a4c75f9c9fd2a0e2b0ee33e59bb4
@@ -95,6 +95,9 @@ module JennCad::Exporters
95
95
  if v == nil
96
96
  next
97
97
  end
98
+ if v.kind_of?(Symbol)
99
+ v = v.to_s
100
+ end
98
101
  if v.kind_of?(Array)
99
102
  v = handle_args(v)
100
103
  elsif !v.kind_of?(TrueClass) && !v.kind_of?(FalseClass) && v == v.to_i
@@ -172,6 +175,8 @@ module JennCad::Exporters
172
175
  prim('circle', part)
173
176
  when JennCad::Primitives::Square
174
177
  prim('square', part)
178
+ when JennCad::Primitives::Text
179
+ prim('text', part)
175
180
  when JennCad::Primitives::LinearExtrude
176
181
  new_obj(part, :linear_extrude, part.openscad_params, parse(part.parts))
177
182
  when JennCad::Primitives::RotateExtrude
@@ -0,0 +1,138 @@
1
+ module JennCad
2
+ class Size
3
+ attr_accessor :size
4
+ def initialize(args={})
5
+ @size = {
6
+ x: args[:x].to_d,
7
+ y: args[:y].to_d,
8
+ z: (args[:z] || args[:h]).to_d,
9
+ d: args[:d].to_d,
10
+ }
11
+ end
12
+
13
+ def add(other)
14
+ return self if other.nil?
15
+ @size[:x] += other.x
16
+ @size[:y] += other.y
17
+ @size[:z] += other.z
18
+ @size[:d] += other.d
19
+ self
20
+ end
21
+
22
+ def union(other)
23
+ @size[:x] = [@size[:x], other.x].max
24
+ @size[:y] = [@size[:y], other.y].max
25
+ @size[:z] = [@size[:z], other.z].max
26
+ @size[:d] = [@size[:d], other.d].max
27
+ self
28
+ end
29
+
30
+ def to_point
31
+ Point.new(x: @size[:x], y: @size[:y], z: @size[:z])
32
+ end
33
+
34
+ def set(a, to)
35
+ @size[a] = to
36
+ end
37
+
38
+ def x
39
+ @size[:x]
40
+ end
41
+
42
+ def y
43
+ @size[:y]
44
+ end
45
+
46
+ def z
47
+ @size[:z]
48
+ end
49
+
50
+ def d
51
+ @size[:d]
52
+ end
53
+
54
+ end
55
+
56
+ class Point
57
+ attr_accessor :pos
58
+ def initialize(args={})
59
+ @pos = {x: 0.to_d, y: 0.to_d, z: 0.to_d}
60
+ add(args)
61
+ end
62
+
63
+ def x
64
+ @pos[:x]
65
+ end
66
+
67
+ def y
68
+ @pos[:y]
69
+ end
70
+
71
+ def z
72
+ @pos[:z]
73
+ end
74
+
75
+ def zero?
76
+ return true if x == 0.0 && y == 0.0 && z == 0.0
77
+ false
78
+ end
79
+
80
+ def to_a
81
+ if @z != 0.0
82
+ [@pos[:x], @pos[:y], @pos[:z]]
83
+ else
84
+ [@pos[:x], @pos[:y]]
85
+ end
86
+ end
87
+
88
+ def to_h
89
+ @pos.clone.delete_if{|k,v| v.to_d == 0.0}
90
+ end
91
+
92
+ def add(args)
93
+ if args.kind_of? Point
94
+ @pos[:x] += args.x
95
+ @pos[:y] += args.y
96
+ @pos[:z] += args.z
97
+ return self
98
+ end
99
+
100
+ args.each do |k, val|
101
+ if [:chain, :debug].include? k
102
+ next
103
+ end
104
+ unless val.kind_of? Numeric
105
+ next
106
+ end
107
+ if val.to_d == 0.0
108
+ next
109
+ end
110
+
111
+ keys = k.to_s.chars
112
+ axis = []
113
+ axis << keys.delete("x")
114
+ axis << keys.delete("y")
115
+ axis << keys.delete("z")
116
+ multi = 1
117
+
118
+ if keys.size > 0
119
+ if keys.include?("h")
120
+ multi = 0.5
121
+ elsif keys.include?("q")
122
+ multi = 0.25
123
+ elsif keys.include?("d")
124
+ multi = 2.0
125
+ end
126
+ if keys.include?("n") || keys.include?("i")
127
+ multi *= -1
128
+ end
129
+ end
130
+ axis.compact.each do |a|
131
+ @pos[a.to_sym] += val.to_d * multi.to_d
132
+ end
133
+ end
134
+ self
135
+ end
136
+ end
137
+
138
+ end
@@ -13,10 +13,13 @@ module JennCad::Primitives
13
13
  end
14
14
 
15
15
  if parts.first && parts.first.respond_to?(:debug?) && parts.first.debug?
16
- $log.debug("Creating new #{self.class} for part #{parts}")
16
+ $log.debug("Creating new #{self.class} for part #{parts.pretty_inspect}")
17
17
  end
18
18
 
19
- @parent = @parts.first.parent
19
+
20
+ @parent = @parts.first.parent if @parts.first
21
+ @csize = @parts.first.csize if @parts.first
22
+ @csize ||= Size.new
20
23
 
21
24
  after_add
22
25
  end
@@ -38,6 +38,7 @@ module JennCad::Primitives
38
38
  handle_radius_diameter
39
39
  handle_fn
40
40
  set_anchors_2d
41
+ @csize = Size.new(d: @opts[:d])
41
42
  end
42
43
 
43
44
  def openscad_params
@@ -1,6 +1,7 @@
1
1
  module JennCad::Primitives
2
2
  class Cube < Square
3
3
  extend JennCad::Features::Cuttable
4
+ include ZIsh
4
5
 
5
6
  def initialize(args)
6
7
  @opts = {
@@ -26,27 +27,19 @@ module JennCad::Primitives
26
27
  end
27
28
  init
28
29
 
29
-
30
30
  handle_margins
31
31
  @h = @z.dup
32
32
  @calc_h = @z.dup
33
33
 
34
34
  @dimensions = [:x, :y, :z]
35
+ @csize = Size.new(x: @opts[:x], y: @opts[:y], z: @opts[:z])
35
36
 
36
37
  set_anchors
37
38
  end
38
39
 
39
40
  def set_anchors
40
41
  set_anchors_2d
41
- if @opts[:center_z]
42
- set_anchor :bottom_face, z: -@z/2.0
43
- set_anchor :top_face, z: @z/2.0
44
- else
45
- set_anchor :bottom_face, z: 0
46
- set_anchor :top_face, z: @z
47
- end
48
-
49
-
42
+ set_anchors_z
50
43
  end
51
44
 
52
45
  # used for openscad export
@@ -54,13 +47,6 @@ module JennCad::Primitives
54
47
  [@x, @y, z+z_margin]
55
48
  end
56
49
 
57
- def cz
58
- nc
59
- @opts[:center_z] = true
60
- set_anchors
61
- self
62
- end
63
- alias :center_z :cz
64
50
 
65
51
  end
66
52
  end
@@ -1,5 +1,6 @@
1
1
  module JennCad::Primitives
2
2
  class Cylinder < Circle
3
+ include ZIsh
3
4
  attr_accessor :d, :d1, :d2, :r, :fn, :anchors
4
5
  def initialize(args)
5
6
  if args.kind_of?(Array) && args[0].kind_of?(Hash)
@@ -15,7 +16,7 @@ module JennCad::Primitives
15
16
  end
16
17
 
17
18
  args[:z] ||= args[:h]
18
-
19
+ args[:center_z] ||= args[:cz]
19
20
  @opts = {
20
21
  d: 0,
21
22
  d1: nil,
@@ -24,7 +25,7 @@ module JennCad::Primitives
24
25
  r2: nil,
25
26
  z: nil,
26
27
  r: 0,
27
- cz: false,
28
+ center_z: false,
28
29
  margins: {
29
30
  r: 0,
30
31
  d: 0,
@@ -43,22 +44,16 @@ module JennCad::Primitives
43
44
  handle_fn
44
45
  @dimensions = [:x, :y, :z]
45
46
  set_anchors
47
+ @csize = Size.new(x: @opts[:d], y: @opts[:d], d: @opts[:d], z: @z)
46
48
  end
47
49
 
48
50
  def set_anchors
49
51
  set_anchors_2d
52
+ set_anchors_z
50
53
  # TODO: figure out if we also want to have "corners"
51
54
  # - possibly move it like a cube
52
55
  # - points at 45 ° angles might not be that useful unless you can get the point on the circle at a given angle
53
56
  # - inner/outer points could be useful for small $fn values
54
-
55
- if @opts[:cz]
56
- set_anchor :bottom_face, z: -@z/2.0
57
- set_anchor :top_face, z: @z/2.0
58
- else
59
- set_anchor :bottom_face, z: 0
60
- set_anchor :top_face, z: @z
61
- end
62
57
  end
63
58
 
64
59
  def openscad_params
@@ -78,7 +73,7 @@ module JennCad::Primitives
78
73
  # Centers the cylinder around it's center point by height
79
74
  # This will transform the cylinder around the center point.
80
75
  def cz
81
- @opts[:cz] = true
76
+ @opts[:center_z] = true
82
77
  @transformations ||= []
83
78
  @transformations << Move.new(z: -@z / 2.0)
84
79
  set_anchors
@@ -1,5 +1,7 @@
1
1
  module JennCad::Primitives
2
+ include ZIsh
2
3
  attr_accessor :center_bool, :convexity, :twist, :slices
4
+
3
5
  class LinearExtrude < JennCad::Thing
4
6
  def initialize(part, args={})
5
7
  @transformations = []
@@ -7,22 +9,28 @@ module JennCad::Primitives
7
9
  if args.kind_of? Numeric
8
10
  args = {h: args}
9
11
  end
10
-
11
12
  @z = args[:h] || args[:height] || args[:z]
13
+ @csize = Size.new(z: @z).add(part.csize)
14
+
12
15
  @center_bool = args[:center]
13
16
  @convexity = args[:convexity]
14
17
  @twist = args[:twist]
15
18
  @slices = args[:slices]
16
19
  @fn = args[:fn]
17
20
  @opts = {
21
+ center_z: false,
18
22
  margins: {
19
23
  z: 0,
20
24
  }
21
25
  }.deep_merge(args)
26
+ set_anchors_z
27
+
28
+ @x = part.x
29
+ @y = part.y
22
30
  end
23
31
 
24
32
  def height
25
- @z.to_d + @opts[:margins][:z].to_d
33
+ @z.to_d + z_margin
26
34
  end
27
35
 
28
36
  def openscad_params
@@ -44,6 +44,8 @@ module JennCad::Primitives
44
44
  feed_opts(parse_xyz_shortcuts(args))
45
45
  end
46
46
  init(args)
47
+ @d = opts[:d]
48
+ @csize = Size.new(x: @opts[:x], y: @opts[:y], z: @opts[:z])
47
49
 
48
50
  handle_margins
49
51
  handle_diameter
@@ -52,6 +54,7 @@ module JennCad::Primitives
52
54
  else
53
55
  @dimensions = [:x, :y]
54
56
  end
57
+
55
58
  set_anchors
56
59
  end
57
60
 
@@ -59,28 +62,28 @@ module JennCad::Primitives
59
62
  # FIXME: this check needs to be done on object creation
60
63
  # otherwise it fails to position it
61
64
  if @d == 0
62
- if @z.to_d > 0
65
+ if @csize.z.to_d > 0
63
66
  return cube(@opts)
64
67
  else
65
68
  return square(@opts)
66
69
  end
67
70
  end
68
71
  # make diameter not bigger than any side
69
- d = [@d, @x, @y].min
72
+ d = [@d, @csize.x, @csize.y].min
70
73
  res = HullObject.new(
71
74
  circle(d: d),
72
- circle(d: d).move(x: @x - d, y: 0),
73
- circle(d: d).move(x: 0, y: @y - d),
74
- circle(d: d).move(x: @x - d, y: @y - d),
75
+ circle(d: d).move(x: @csize.x - d, y: 0),
76
+ circle(d: d).move(x: 0, y: @csize.y - d),
77
+ circle(d: d).move(x: @csize.x - d, y: @csize.y - d),
75
78
  )
76
- res = res.move(xy: d/2.0)
79
+ res = res.move(xyh: d)
77
80
 
78
81
  @opts[:flat_edges].each do |edge|
79
82
  res += apply_flat_edge(edge)
80
83
  end
81
84
 
82
- if @z.to_d > 0
83
- res = res.extrude(z: @z + z_margin)
85
+ if @csize.z.to_d > 0
86
+ res = res.extrude(z: @csize.z + z_margin)
84
87
  end
85
88
 
86
89
  res = union(res) # put everything we have in a parent union that we can apply the transformations of this object of
@@ -103,13 +106,13 @@ module JennCad::Primitives
103
106
  def apply_flat_edge(edge)
104
107
  case edge
105
108
  when :up, :top
106
- square(x: @x, y: @y/2.0).nc.moveh(y:@y)
109
+ square(x: @csize.x, y: @csize.y/2.0).nc.moveh(y:@csize.y)
107
110
  when :down, :bottom
108
- square(x: @x, y: @y/2.0).nc
111
+ square(x: @csize.x, y: @csize.y/2.0).nc
109
112
  when :right
110
- square(x: @x/2.0, y: @y).nc.moveh(x:@x)
113
+ square(x: @csize.x/2.0, y: @csize.y).nc.moveh(x:@csize.x)
111
114
  when :left
112
- square(x: @x/2.0, y: @y).nc
115
+ square(x: @csize.x/2.0, y: @csize.y).nc
113
116
  else
114
117
  nil
115
118
  end
@@ -65,6 +65,11 @@ module JennCad::Primitives
65
65
  if ty
66
66
  @len_y = ty - @d
67
67
  end
68
+ if @opts[:z] && opts[:z].to_d > 0
69
+ @dimensions = [:x, :y, :z]
70
+ else
71
+ @dimensions = [:x, :y]
72
+ end
68
73
 
69
74
  set_anchors
70
75
  end
@@ -28,6 +28,8 @@ module JennCad::Primitives
28
28
  @x = args[:x]
29
29
  @y = args[:y]
30
30
  @dimensions = [:x, :y]
31
+ @sits_on = :bottom
32
+ @csize = Size.new(x: @opts[:x], y: @opts[:y])
31
33
  end
32
34
 
33
35
 
@@ -137,8 +139,6 @@ module JennCad::Primitives
137
139
  self
138
140
  end
139
141
 
140
-
141
-
142
142
  def not_centered
143
143
  @opts[:center] = false
144
144
  set_anchors
@@ -162,8 +162,6 @@ module JennCad::Primitives
162
162
  end
163
163
  alias :center_y :cy
164
164
 
165
-
166
-
167
165
  def centered_axis
168
166
  return [:x, :y] if @opts[:center]
169
167
  a = []
@@ -174,10 +172,8 @@ module JennCad::Primitives
174
172
  end
175
173
 
176
174
  def to_openscad
177
- self.mh(centered_axis.to_h{|a| [a, -@opts[a]] }) # center cube
175
+ self.mh(centered_axis.to_h{|a| [a, -@opts[a]] }.merge(prepend: true)) # center cube
178
176
  end
179
177
 
180
-
181
-
182
178
  end
183
179
  end
@@ -0,0 +1,50 @@
1
+ module JennCad::Primitives
2
+ class Text < Primitive
3
+ attr_accessor :text, :font, :valign, :halign, :size, :spacing, :script, :fn, :direction, :language
4
+
5
+ def initialize(args)
6
+ @text = args[:text]
7
+ @size = args[:size]
8
+ @font = args[:font]
9
+ @valign = args[:valign]
10
+ @halign = args[:halign]
11
+ @spacing = args[:spacing]
12
+ @script = args[:script]
13
+ @direction = parse_dir(args[:dir] || args[:direction])
14
+ case @direction
15
+ when "btt", "ttb"
16
+ @valign ||= :top
17
+ @halign ||= :left
18
+ end
19
+
20
+ @language = args[:language]
21
+ @fn = args[:fn]
22
+
23
+ init(args)
24
+ end
25
+
26
+ def parse_dir(dir)
27
+ case dir.to_s
28
+ when "x", "ltr"
29
+ "ltr"
30
+ when "-x", "xn", "nx", "xi", "rtl"
31
+ "rtl"
32
+ when "y", "btt"
33
+ "btt"
34
+ when "-y", "yn", "ny", "yi", "ttb"
35
+ "ttb"
36
+ else
37
+ nil
38
+ end
39
+ end
40
+
41
+ def openscad_params
42
+ res = {}
43
+ [:text, :font, :valign, :halign, :size, :spacing, :script, :direction, :language, :fn].each do |n|
44
+ res[n] = self.send n
45
+ end
46
+ res
47
+ end
48
+
49
+ end
50
+ end
@@ -1,5 +1,21 @@
1
1
  module JennCad::Primitives
2
2
  class UnionObject < BooleanObject
3
+ def initialize(*parts)
4
+ super(*parts)
5
+
6
+ blacklist = [SubtractObject, IntersectionObject]
7
+
8
+ @parts[1..-1].each do |part|
9
+ blacklist.each do |b|
10
+ if part.kind_of? b
11
+ next
12
+ end
13
+ end
14
+ @csize = part.csize
15
+ # @csize.union(part.csize.clone) if part.csize
16
+ end
17
+
18
+ end
3
19
 
4
20
  end
5
21
  end
@@ -16,6 +16,7 @@ require "jenncad/primitives/intersection_object"
16
16
  require "jenncad/primitives/projection"
17
17
  require "jenncad/primitives/linear_extrude"
18
18
  require "jenncad/primitives/rotate_extrude"
19
+ require "jenncad/primitives/text"
19
20
 
20
21
  module JennCad
21
22
  include Primitives
@@ -1,3 +1,5 @@
1
1
  module CubeIsh
2
2
  # TBD
3
+
4
+
3
5
  end
@@ -0,0 +1,55 @@
1
+ module ZIsh
2
+
3
+ def set_anchors_z
4
+ if @opts[:center_z]
5
+ set_anchor :bottom_face, z: -z/2.0
6
+ set_anchor :top_face, z: z/2.0
7
+ set_anchor :center, x: 0
8
+ else
9
+ set_anchor :bottom_face, z: 0
10
+ set_anchor :top_face, z: z
11
+ set_anchor :center, zh: z
12
+ end
13
+ end
14
+
15
+ def cz
16
+ if self.respond_to? :nc
17
+ nc
18
+ end
19
+ @opts[:center_z] = true
20
+ set_anchors_z
21
+ self
22
+ end
23
+ alias :center_z :cz
24
+
25
+ def flip_axis(dir)
26
+ case dir
27
+ when :bottom
28
+ nil
29
+ when :top
30
+ :z
31
+ when :left, :right
32
+ :x
33
+ when :front, :back
34
+ :y
35
+ end
36
+ end
37
+
38
+ def flip_rotation(dir)
39
+ case dir
40
+ when :bottom
41
+ {}
42
+ when :left
43
+ {y: 270}
44
+ when :top
45
+ {x: 180}
46
+ when :right
47
+ {y: 90}
48
+ when :front
49
+ {x: 90}
50
+ when :back
51
+ {x: 270}
52
+ end
53
+ end
54
+
55
+ end
@@ -1,3 +1,4 @@
1
1
  require "jenncad/shared/circle_ish"
2
2
  require "jenncad/shared/cube_ish"
3
+ require "jenncad/shared/z_ish"
3
4
 
@@ -73,6 +73,10 @@ module JennCad
73
73
  end
74
74
  alias :as_2d :to_2d
75
75
 
76
+ def text(txt, args={})
77
+ Text.new(args.merge({text: txt}))
78
+ end
79
+
76
80
  def union(*args)
77
81
  UnionObject.new(*args)
78
82
  end
data/lib/jenncad/thing.rb CHANGED
@@ -9,17 +9,21 @@ module JennCad
9
9
  attr_accessor :angle, :fn
10
10
  attr_accessor :anchors
11
11
  attr_accessor :parent
12
+ attr_accessor :pos, :csize
13
+ attr_accessor :sits_on
12
14
 
13
15
  def initialize(args={})
14
16
  init(args)
15
17
  end
16
18
 
17
19
  def init(args={})
20
+ @csize = Size.new()
18
21
  @transformations = []
19
22
  # calculated origin; only works for move atm
20
23
  @calc_x = 0
21
24
  @calc_y = 0
22
25
  @calc_z = 0
26
+ @pos = Point.new
23
27
  @calc_h = args[:z] || 0
24
28
  @anchors = {}
25
29
  @parent = args[:parent] || nil
@@ -47,6 +51,11 @@ module JennCad
47
51
  self
48
52
  end
49
53
 
54
+ def dbg
55
+ set_flag(:debug)
56
+ self
57
+ end
58
+
50
59
  def cut_to(face, part=nil, args={})
51
60
  an = anchor(face, part)
52
61
  unless an
@@ -209,36 +218,50 @@ module JennCad
209
218
  rt(z:v)
210
219
  end
211
220
 
212
- def flip(direction)
213
- case self
214
- when UnionObject
215
- ref = self.parts.first
216
- rz = self.z.to_d + self.calc_h.to_d
217
- when BooleanObject
218
- ref = self.parts.first
219
- rz = ref.calc_z + ref.calc_h
220
- else
221
- ref = self
222
- rz = self.z + self.calc_h
223
- end
221
+ def flipc(dir, args={})
222
+ flip(dir, args.merge(rel: true, center: true))
223
+ end
224
+
225
+ def flip(dir, args={})
226
+ @sits_on ||= :bottom
224
227
 
225
- case direction
226
- when :x
227
- self.ry(90).mh(x: -rz, z: ref.x)
228
- when :y
229
- self.rx(90).mh(y: rz, z: ref.y)
228
+ ro = flip_rotation(dir)
229
+ flip_rotation(@sits_on).each do |key, val|
230
+ ro[key] ||= 0
231
+ ro[key] -= val
232
+ end
233
+ unless ro == {}
234
+ self.moveai(:center).rotate(ro)
230
235
  end
231
- end
232
236
 
233
- def flip_x
234
- flip(:x)
235
- end
236
- alias :fx :flip_x
237
+ @opts ||= {}
238
+
239
+ if args[:center]
240
+ if ro == {} # if we didn't move earlier, let's move it now
241
+ self.moveai(:center)
242
+ end
243
+ @opts[:center_z] = true
244
+ set_anchors_z if self.respond_to? :set_anchors_z
245
+ else
246
+ # TODO: fix anchors
247
+ if debug?
248
+ $log.info "flip_axis(#{dir}): #{flip_axis(dir)} csize: #{@csize.size}"
249
+ end
250
+
251
+ case flip_axis(dir)
252
+ when :x
253
+ self.move(zh: @csize.x)
254
+ when :y
255
+ self.move(zh: @csize.y)
256
+ when :z
257
+ self.move(zh: @csize.z)
258
+ end
259
+ @opts[:center_z] = false
260
+ end
261
+ @sits_on = dir
237
262
 
238
- def flip_y
239
- flip(:y)
263
+ self
240
264
  end
241
- alias :fy :flip_y
242
265
 
243
266
  def radians(a)
244
267
  a.to_d/180.0*PI
@@ -263,6 +286,7 @@ module JennCad
263
286
  self.move(x:-x,y:-y,z:-z).rotate(args).move(x:x,y:y,z:z)
264
287
  end
265
288
 
289
+ # Deprecated, moved to Point
266
290
  def parse_xyz_shortcuts(args)
267
291
  unless args.kind_of? Hash
268
292
  $log.warn "parse_xyz_shortcuts called for type #{args.class} #{args.inspect}"
@@ -328,34 +352,44 @@ module JennCad
328
352
  x,y,z = args
329
353
  return move(x:x, y:y, z:z)
330
354
  end
331
- args = parse_xyz_shortcuts(args)
332
355
 
333
- if args[:x].to_d == 0.0 && args[:y].to_d == 0.0 && args[:z].to_d == 0.0
356
+ chain = if args[:chain]
357
+ args[:chain]
358
+ else
359
+ $jenncad_profile.chain_moves
360
+ end
361
+
362
+ point = Point.new(args)
363
+
364
+ if point.zero?
334
365
  return self
335
366
  end
367
+ pre = args[:prepend]
368
+ args = point.to_h
336
369
 
337
370
  @transformations ||= []
338
- if args[:prepend]
339
- @transformations.prepend(Move.new(args))
340
- else
341
- lt = @transformations.last
342
-
343
- chain = if args[:chain]
344
- args[:chain]
371
+ if pre
372
+ lt = @transformations.first
373
+ if lt && lt.class == Move && chain == false
374
+ $log.debug "#{self} at move(prepend): Adding to first move #{lt.inspect} , args: #{args}" if self.debug?
375
+ lt.pos.add(point)
345
376
  else
346
- $jenncad_profile.chain_moves
377
+ @transformations.prepend(Move.new(pos: point))
347
378
  end
379
+ else
380
+ lt = @transformations.last
348
381
 
349
382
  if lt && lt.class == Move && chain == false
350
383
  $log.debug "#{self} at move: Adding to previous move #{lt.inspect} , args: #{args}" if self.debug?
351
- lt.x += args[:x].to_d
352
- lt.y += args[:y].to_d
353
- lt.z += args[:z].to_d
384
+ lt.pos.add(point) # TODO: figure out why this doesn't work on export
354
385
  else
355
386
  $log.debug "#{self} at move: Adding move of #{args} to transformations" if self.debug?
356
- @transformations << Move.new(args)
387
+ @transformations << Move.new(pos: point)
357
388
  end
358
389
  end
390
+ @pos ||= Point.new
391
+ @pos.add(point)
392
+ # NOTE: this needs more migration so everythign runs over point
359
393
  @calc_x += args[:x].to_d
360
394
  @calc_y += args[:y].to_d
361
395
  @calc_z += args[:z].to_d
@@ -387,6 +421,7 @@ module JennCad
387
421
  if key.kind_of? Hash
388
422
  an = key
389
423
  else
424
+ thing ||= self
390
425
  an = anchor(key, thing, args)
391
426
  end
392
427
  unless an
@@ -394,7 +429,10 @@ module JennCad
394
429
  an = {} # this will move by 0,0 and still display the block
395
430
  end
396
431
  part.movei(an)
397
- part = block.yield.move(an)
432
+ bl = block.yield
433
+ unless bl == nil
434
+ part = bl.move(an)
435
+ end
398
436
  end
399
437
  part
400
438
  end
@@ -443,11 +481,14 @@ module JennCad
443
481
  x,y,z = args
444
482
  args = {x: x, y: y, z: z}
445
483
  end
446
- [:x, :y, :z, :xy, :xyz, :xz, :yz].each do |key|
447
- args[key] = args[key] / 2.0 unless args[key] == nil
484
+ to = {}
485
+ args.each do |key, val|
486
+ to[key] = val.to_d / 2.0 if val.kind_of? Numeric
448
487
  end
488
+ to[:chain] = args[:chain]
489
+ to[:prepend] = args[:prepend]
449
490
 
450
- move(args)
491
+ move(to)
451
492
  end
452
493
  alias :mh :moveh
453
494
 
@@ -465,11 +506,9 @@ module JennCad
465
506
 
466
507
  def movei(args={})
467
508
  to = {}
468
- [:x, :y, :z, :xy, :xz, :yz, :xyz].each do |key|
469
- if args[key]
470
- to[key] = args[key]*-1
471
- end
472
- end
509
+ args.each do |key, val|
510
+ to[key] = val.to_d * -1 if val.kind_of? Numeric
511
+ end
473
512
  to[:chain] = args[:chain]
474
513
  move(to)
475
514
  end
@@ -1,7 +1,13 @@
1
1
  module JennCad
2
+ attr_accessor :pos
2
3
  class Move < Transformation
3
4
  def initialize(args)
4
- super(args)
5
+ pos = args[:pos]
6
+ super(args.merge(pos: pos))
7
+ end
8
+
9
+ def coordinates
10
+ @pos.to_a
5
11
  end
6
12
  end
7
13
  end
@@ -3,5 +3,9 @@ module JennCad
3
3
  def initialize(args)
4
4
  super(args)
5
5
  end
6
+
7
+ def coordinates
8
+ [@x, @y, @z]
9
+ end
6
10
  end
7
11
  end
@@ -2,13 +2,14 @@ module JennCad
2
2
  class Transformation
3
3
  attr_accessor :x,:y,:z, :coordinates
4
4
  def initialize(args)
5
+ @pos = args[:pos]
5
6
  @x = args[:x]
6
7
  @y = args[:y]
7
8
  @z = args[:z]
8
9
  end
9
10
 
10
11
  def coordinates
11
- [@x,@y,@z]
12
+ @pos.to_a
12
13
  end
13
14
  end
14
15
  end
@@ -1,3 +1,3 @@
1
1
  module JennCad
2
- VERSION = "1.0.0-alpha21"
2
+ VERSION = "1.0.0-alpha22"
3
3
  end
data/lib/jenncad.rb CHANGED
@@ -1,3 +1,4 @@
1
+ require "pp"
1
2
  require "logger"
2
3
  $log = Logger.new(STDOUT)
3
4
 
@@ -18,6 +19,7 @@ JennCad::ProfileLoader.new
18
19
 
19
20
 
20
21
  require "jenncad/patches/array"
22
+ require "jenncad/position"
21
23
  require "jenncad/thing"
22
24
  require "jenncad/part"
23
25
  require "jenncad/project"
data/todo.txt CHANGED
@@ -24,14 +24,38 @@ Features wanted
24
24
  - but also, when you have a part that can be mounted in any top/bottom direction, you always end up having the bolts facing the wrong direction..
25
25
  - Bolts should be able to also make thread inserts
26
26
 
27
+ - Bolts / Nuts by default should be able to use as mixin, i.e.
28
+ cylinder(Nut::M3)
29
+ slot(Nut::M5, x: 10)
30
+
31
+ possbibly M* like
32
+ cylinder(M4)
33
+ or
34
+ cylinder(M4, h: 25)
35
+
36
+ Possibly via symbols
37
+ cylinder(:m4, h: 30)
38
+ cylinder(:m4, :nut)
39
+
40
+ slot(:m5, :nut, x: 10)
41
+
42
+
27
43
  8.5.22:
28
44
  - need an easy way to switch between faces on an object to work efficiently in a 2.5D way
29
45
  i.e. I worked on a part stacking a few things, added a cube along and now wanted to use inner_anchors for the y face for screws. it was easier to make anchors manually for the prototype
46
+ [#at functionality is half-way there; would be great to have this for rotation as well]
30
47
 
31
48
 
49
+ 23.5.22:
50
+ - get slice of circle (input angle, output angle)
51
+ - skip stl build for part
52
+ - at doesn't work well if you need to mirror a part
53
+ -> anchors need to be able to do flipping, possibly rotation
32
54
 
33
55
 
34
56
 
57
+ 24.5.22
58
+ - multithreading output building
35
59
 
36
60
  other awful things
37
61
  ===================
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.alpha21
4
+ version: 1.0.0.pre.alpha22
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-05-22 00:00:00.000000000 Z
11
+ date: 2022-05-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: geo3d
@@ -128,6 +128,7 @@ files:
128
128
  - lib/jenncad/features/stl_import.rb
129
129
  - lib/jenncad/part.rb
130
130
  - lib/jenncad/patches/array.rb
131
+ - lib/jenncad/position.rb
131
132
  - lib/jenncad/primitives.rb
132
133
  - lib/jenncad/primitives/boolean_object.rb
133
134
  - lib/jenncad/primitives/circle.rb
@@ -146,6 +147,7 @@ files:
146
147
  - lib/jenncad/primitives/sphere.rb
147
148
  - lib/jenncad/primitives/square.rb
148
149
  - lib/jenncad/primitives/subtract_object.rb
150
+ - lib/jenncad/primitives/text.rb
149
151
  - lib/jenncad/primitives/union_object.rb
150
152
  - lib/jenncad/profile_loader.rb
151
153
  - lib/jenncad/project.rb
@@ -153,6 +155,7 @@ files:
153
155
  - lib/jenncad/shared.rb
154
156
  - lib/jenncad/shared/circle_ish.rb
155
157
  - lib/jenncad/shared/cube_ish.rb
158
+ - lib/jenncad/shared/z_ish.rb
156
159
  - lib/jenncad/shortcuts.rb
157
160
  - lib/jenncad/thing.rb
158
161
  - lib/jenncad/transformation/color.rb