jenncad 1.0.0.pre.alpha4 → 1.0.0.pre.alpha6

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: ea1fa04592f59d248c5801c3b645f16429bd7ae9f0b754aa467c8a401c89ec4b
4
- data.tar.gz: 4df185f63b22b5945784cf820b4af937e4fbc660875f36093bbd5ebe9baa2aa9
3
+ metadata.gz: 8dc72aa8cfaaa41cf4b96038f454073f708502cea9d9ce84a13fc28203ff4dc2
4
+ data.tar.gz: c5f0cbe4442bf7b59c39ee2f69e2096d0166fa4ae336c48029f8856606da3d9a
5
5
  SHA512:
6
- metadata.gz: '0809987ec1b33518b17402acb27b659da2dc7b97ee304d1549abd857ae4448e0342d6ee4523e8d2277d7ce765e1278f996af9882b5da91b71c93acec8bd9ffd9'
7
- data.tar.gz: e412b05272163c37096d36a44d83ac3d3c5ae07089d7d8d7236c1c53a263c24742566b691efbb5a03c9148960cb7734eb2859bc279e450e34c131fda2ae85af5
6
+ metadata.gz: 425dda2b4dda1793baa9ef4d6f30155325acc949df98c2ca214b7abb931a1a9aa7757f6b906a89cf12d7a17c4447ef3b92b3b999120d455cfb8693a2b5cfe0af
7
+ data.tar.gz: 706f8e591aab9c10702577c09fc95a4e5e7cd1444cb3fbda88e715872e4aab67fb8b35449a97a27a1b874325e3804cf20377884ebb67896484e9bc9cee5a6625
data/jenncad.gemspec CHANGED
@@ -22,7 +22,7 @@ Gem::Specification.new do |gem|
22
22
  gem.required_ruby_version = ">= 2.6.0"
23
23
  gem.add_runtime_dependency "geo3d"
24
24
  gem.add_runtime_dependency "deep_merge"
25
- gem.add_runtime_dependency "hanami-cli"
25
+ gem.add_runtime_dependency "hanami-cli", "0.3.1"
26
26
  gem.add_runtime_dependency "activesupport"
27
27
  gem.add_runtime_dependency "observr"
28
28
  end
@@ -1,6 +1,7 @@
1
1
  module JennCad
2
2
  module Commands
3
3
  extend Hanami::CLI::Registry
4
+ MAGIC = "jenncad-append-project-magic"
4
5
 
5
6
  class Run < Hanami::CLI::Command
6
7
  argument :name, required: false
@@ -122,10 +123,34 @@ module JennCad
122
123
  f.puts " end"
123
124
  f.puts "end"
124
125
  end
125
- puts "part #{filename} created. In your #{executable} add to class #{executable_class}:"
126
- puts " def #{name}"
127
- puts " #{classname}.new(config)"
128
- puts " end"
126
+
127
+ lines = File.readlines(executable)
128
+ magic_line = nil;
129
+ lines.each_with_index do |l, i|
130
+ if l.rindex(MAGIC)
131
+ magic_line = i
132
+ end
133
+ end
134
+ puts "part #{filename} created."
135
+ if !magic_line
136
+ puts "In your #{executable} add to class #{executable_class}:"
137
+ puts " def #{name}"
138
+ puts " #{classname}.new(config)"
139
+ puts " end"
140
+ puts ""
141
+ puts "For jenncad to insert this line automatically, add this line to your project file before the \"end\"-statement of your class:"
142
+ puts "##{MAGIC}"
143
+ else
144
+ data = "\n"
145
+ data += " def #{name}\n"
146
+ data += " #{classname}.new(config)\n"
147
+ data += " end\n"
148
+ lines.insert(magic_line, data)
149
+ f = File.open(executable, "w")
150
+ f.write(lines.join)
151
+ f.close
152
+ end
153
+
129
154
 
130
155
  end
131
156
 
@@ -152,9 +177,7 @@ module JennCad
152
177
  f.puts " {}"
153
178
  f.puts " end"
154
179
  f.puts ""
155
- f.puts " def #{name}"
156
- f.puts " cube(10,10,10)"
157
- f.puts " end"
180
+ f.puts " # #{MAGIC}"
158
181
  f.puts "end"
159
182
  f.puts ""
160
183
  f.puts "#{classname}.new.run"
data/lib/jenncad/part.rb CHANGED
@@ -2,9 +2,8 @@ module JennCad
2
2
  # Part should be inherited from the user when making parts
3
3
  class Part < Thing
4
4
 
5
- def to_openscad #make_openscad_compatible
6
- # auto_color
7
- a = Aggregation.new(self.class.to_s, self.part) #make_openscad_compatible!(self.part))
5
+ def to_openscad
6
+ a = Aggregation.new(self.class.to_s, self.part)
8
7
  a.transformations = @transformations
9
8
  a.color(:auto)
10
9
  a
@@ -2,10 +2,9 @@ module JennCad::Primitives
2
2
  class Cube < Primitive
3
3
  extend JennCad::Features::Cuttable
4
4
 
5
- def initialize(args)
6
- if args.kind_of?(Array) && args[0].kind_of?(Hash)
7
- args = args.first
8
- end
5
+
6
+ def feed_opts(args)
7
+ # FIXME: this doesn't seem to work
9
8
  if args.kind_of? Array
10
9
  m = {}
11
10
  if args.last.kind_of? Hash
@@ -13,7 +12,13 @@ module JennCad::Primitives
13
12
  end
14
13
  args = [:x, :y, :z].zip(args.flatten).to_h
15
14
  args.deep_merge!(m)
15
+ @opts.deep_merge!(args)
16
+ else
17
+ @opts.deep_merge!(args)
16
18
  end
19
+ end
20
+
21
+ def initialize(args)
17
22
  @opts = {
18
23
  x: 0,
19
24
  y: 0,
@@ -27,10 +32,18 @@ module JennCad::Primitives
27
32
  center_y: false,
28
33
  center_x: false,
29
34
  center_z: false,
30
- }.deep_merge!(args)
31
- handle_margins
35
+ }
36
+ if args.kind_of? Array
37
+ args.each do |a|
38
+ feed_opts(parse_xyz_shortcuts(a))
39
+ end
40
+ else
41
+ feed_opts(parse_xyz_shortcuts(args))
42
+ end
43
+
32
44
 
33
- super(args)
45
+ handle_margins
46
+ super(z: @opts[:z])
34
47
  @h = @z.dup
35
48
  @calc_h = @z.dup
36
49
  end
@@ -42,30 +55,34 @@ module JennCad::Primitives
42
55
 
43
56
  def not_centered
44
57
  @opts[:center] = false
58
+ self
45
59
  end
46
60
  alias :nc :not_centered
47
61
 
48
62
  def cx
49
63
  nc
50
64
  @opts[:center_x] = true
65
+ self
51
66
  end
52
67
 
53
68
  def cy
54
69
  nc
55
70
  @opts[:center_y] = true
71
+ self
56
72
  end
57
73
 
58
74
  def cz
59
75
  nc
60
76
  @opts[:center_z] = true
77
+ self
61
78
  end
62
79
 
63
80
  def centered_axis
64
81
  return [:x, :y] if @opts[:center]
65
82
  a = []
66
83
  a << :x if @opts[:center_x]
67
- a << :y if @opts[:center_x]
68
- a << :z if @opts[:center_x]
84
+ a << :y if @opts[:center_y]
85
+ a << :z if @opts[:center_z]
69
86
  a
70
87
  end
71
88
 
@@ -1,10 +1,10 @@
1
1
  module JennCad::Primitives
2
- attr_accessor :center_bool, :convexity, :twist, :slices, :height
2
+ attr_accessor :center_bool, :convexity, :twist, :slices
3
3
  class LinearExtrude < JennCad::Thing
4
- def initialize(part, args)
4
+ def initialize(part, args={})
5
5
  @transformations = []
6
6
  @parts = [part]
7
- @height = args[:h] || args[:height]
7
+ @z = args[:h] || args[:height]
8
8
  @center_bool = args[:center]
9
9
  @convexity = args[:convexity]
10
10
  @twist = args[:twist]
@@ -12,6 +12,10 @@ module JennCad::Primitives
12
12
  @fn = args[:fn]
13
13
  end
14
14
 
15
+ def height
16
+ @z
17
+ end
18
+
15
19
  def openscad_params
16
20
  res = {}
17
21
  [:height, :convexity, :twist, :slices, :fn].each do |n|
@@ -1,5 +1,5 @@
1
1
  module JennCad::Primitives
2
- class RoundedCube < Primitive
2
+ class RoundedCube < Cube
3
3
  attr_accessor :d, :r
4
4
  include JennCad::Features::Cuttable
5
5
 
@@ -23,6 +23,10 @@ module JennCad::Primitives
23
23
  z: nil,
24
24
  r: nil,
25
25
  flat_edges: nil,
26
+ center: true,
27
+ center_y: false,
28
+ center_x: false,
29
+ center_z: false,
26
30
  margins: {
27
31
  r: 0,
28
32
  d: 0,
@@ -41,16 +45,16 @@ module JennCad::Primitives
41
45
  # make diameter not bigger than any side
42
46
  @d = [@d, @x, @y].min
43
47
  res = HullObject.new(
44
- cylinder(d:@d, h:z+z_margin).moveh(x: -@x + @d, y: @y - @d),
45
- cylinder(d:@d).moveh(x: @x - @d, y: @y - @d),
46
- cylinder(d:@d).moveh(x: -@x + @d, y: -@y + @d),
47
- cylinder(d:@d).moveh(x: @x - @d, y: -@y + @d),
48
- )
48
+ cylinder(d:@d, h:z+z_margin),
49
+ cylinder(d:@d).move(x: @x - @d, y: 0),
50
+ cylinder(d:@d).move(x: 0, y: @y - @d),
51
+ cylinder(d:@d).move(x: @x - @d, y: @y - @d),
52
+ ).moveh(xy: @d)
49
53
 
50
54
  res += flat_edge(@opts[:flat_edges])
51
55
 
52
56
  res.transformations = @transformations
53
- res
57
+ res.moveh(centered_axis.to_h{|a| [a, -@opts[a]] })
54
58
  end
55
59
 
56
60
  def flat_edge(edge)
@@ -55,6 +55,7 @@ module JennCad::Primitives
55
55
  part.opts[:margins] ||= {}
56
56
  if part.referenced_z && part.z != 0.0
57
57
  case part
58
+ when JennCad::Circle
58
59
  when JennCad::BooleanObject
59
60
  when JennCad::Aggregation
60
61
  else
@@ -42,7 +42,7 @@ module JennCad
42
42
  StlImport.new(file, args)
43
43
  end
44
44
 
45
- def extrude(args)
45
+ def extrude(args={})
46
46
  LinearExtrude.new(self, args)
47
47
  end
48
48
 
data/lib/jenncad/thing.rb CHANGED
@@ -7,6 +7,7 @@ module JennCad
7
7
  attr_accessor :calc_x, :calc_y, :calc_z, :calc_h
8
8
  attr_accessor :shape
9
9
  attr_accessor :angle, :fn
10
+ attr_accessor :anchor
10
11
 
11
12
  def initialize(args={})
12
13
  @transformations = []
@@ -28,6 +29,41 @@ module JennCad
28
29
  @opts[key] = val
29
30
  end
30
31
 
32
+ def set_anchor(args)
33
+ self.anchor ||= {}
34
+ args.each do |key, val|
35
+ self.anchor[key] = val
36
+ end
37
+ end
38
+
39
+ def movea(key)
40
+ a = self.anchor[key]
41
+ unless a
42
+ puts "Error: Anchor #{key} not found"
43
+ puts "Available anchor: #{self.anchor}"
44
+ return self
45
+ else
46
+ self.movei(a)
47
+ end
48
+ end
49
+
50
+ def movei(args)
51
+ to = {}
52
+ [:x, :y, :z].each do |key|
53
+ if args[key]
54
+ to[key] = args[key]*-1
55
+ end
56
+ end
57
+ move(to)
58
+ end
59
+
60
+
61
+ def auto_extrude
62
+ ret = self.extrude
63
+ ret.set_option(:auto_extrude, true)
64
+ ret
65
+ end
66
+
31
67
  def rotate(args)
32
68
  @transformations ||= []
33
69
  @transformations << Rotate.new(args)
@@ -96,17 +132,43 @@ module JennCad
96
132
  [v.x,v.y,v.z]
97
133
  end
98
134
 
99
- # todo: check if that works
100
135
  def rotate_around(point,args)
101
- x,y,z= point.x, point.y, point.z
136
+ x,y,z= point[:x], point[:y], point[:z]
102
137
  self.move(x:-x,y:-y,z:-z).rotate(args).move(x:x,y:y,z:z)
103
138
  end
104
139
 
140
+ def parse_xyz_shortcuts(args)
141
+ [:x, :y, :z].each do |key|
142
+ args[key] ||= 0.0
143
+ end
144
+
145
+ if args[:xy]
146
+ args[:x] += args[:xy]
147
+ args[:y] += args[:xy]
148
+ end
149
+ if args[:xyz]
150
+ args[:x] += args[:xyz]
151
+ args[:y] += args[:xyz]
152
+ args[:z] += args[:xyz]
153
+ end
154
+ if args[:xz]
155
+ args[:x] += args[:xz]
156
+ args[:z] += args[:xz]
157
+ end
158
+ if args[:yz]
159
+ args[:y] += args[:yz]
160
+ args[:z] += args[:yz]
161
+ end
162
+ return args
163
+ end
164
+
105
165
  def move(args)
106
166
  if args.kind_of? Array
107
167
  x,y,z = args
108
168
  return move(x:x, y:y, z:z)
109
169
  end
170
+ args = parse_xyz_shortcuts(args)
171
+
110
172
  @transformations ||= []
111
173
  if args[:prepend]
112
174
  @transformations.prepend(Move.new(args))
@@ -139,9 +201,9 @@ module JennCad
139
201
  x,y,z = args
140
202
  args = {x: x, y: y, z: z}
141
203
  end
142
- args[:x] = args[:x] / 2.0 unless args[:x] == nil
143
- args[:y] = args[:y] / 2.0 unless args[:y] == nil
144
- args[:z] = args[:z] / 2.0 unless args[:z] == nil
204
+ [:x, :y, :z, :xy, :xyz, :xz, :yz].each do |key|
205
+ args[key] = args[key] / 2.0 unless args[key] == nil
206
+ end
145
207
 
146
208
  move(args)
147
209
  end
@@ -228,8 +290,7 @@ module JennCad
228
290
  end
229
291
  res
230
292
  end
231
-
232
- def make_openscad_compatible
293
+ =begin def make_openscad_compatible
233
294
  make_openscad_compatible!(self)
234
295
  end
235
296
 
@@ -250,6 +311,7 @@ module JennCad
250
311
  end
251
312
  item
252
313
  end
314
+ =end
253
315
 
254
316
  def has_explicit_color?
255
317
  if option(:auto_color) == false
@@ -307,11 +369,11 @@ module JennCad
307
369
  ac = auto_color
308
370
  unless ac.nil?
309
371
  #puts "auto color to #{ac}"
310
- if only_color?(self.parts)
372
+ if only_color?(get_contents)
311
373
  set_option :color, ac
312
374
  set_option :auto_color, true
313
375
  else
314
- set_auto_color_for_children(ac, self.parts)
376
+ set_auto_color_for_children(ac, get_contents)
315
377
  end
316
378
 
317
379
  end
@@ -361,12 +423,44 @@ module JennCad
361
423
  option(:color)
362
424
  end
363
425
 
364
- def openscad(file)
365
- if @parts == nil
366
- if self.respond_to? :part
367
- @parts = [part]
426
+ def get_contents
427
+ return @parts unless @parts.nil?
428
+ if self.respond_to? :part
429
+ return [part]
430
+ end
431
+ end
432
+
433
+ def calculated_h
434
+ return @z unless @z.nil? || @z == 0
435
+ return @h unless @h.nil? || @h == 0
436
+ return @calc_h unless @calc_h.nil? || @calc_h == 0
437
+ return @calc_z unless @calc_z.nil? || @calc_z == 0
438
+ end
439
+
440
+ def find_calculated_h(parts)
441
+ return if parts == nil
442
+ parts.each do |part|
443
+ if z = calculated_h
444
+ return z
445
+ end
446
+ get_calculated_h(part.get_contents)
447
+ end
448
+ end
449
+
450
+ def set_heights_for_auto_extrude(parts, parent=nil)
451
+ return if parts.nil?
452
+ parts.each do |part|
453
+ if part.option(:auto_extrude)
454
+ part.z = parent.calculated_h
368
455
  end
456
+ set_heights_for_auto_extrude(part.get_contents, part)
369
457
  end
458
+ end
459
+
460
+ def openscad(file)
461
+ set_heights_for_auto_extrude(get_contents)
462
+
463
+ @parts = get_contents
370
464
 
371
465
  JennCad::Exporters::OpenScad.new(self).save(file)
372
466
  end
@@ -1,4 +1,4 @@
1
1
  module JennCad
2
- VERSION = "1.0.0-alpha4"
2
+ VERSION = "1.0.0-alpha6"
3
3
  end
4
4
 
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.alpha4
4
+ version: 1.0.0.pre.alpha6
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-04-11 00:00:00.000000000 Z
11
+ date: 2022-04-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: geo3d
@@ -42,16 +42,16 @@ dependencies:
42
42
  name: hanami-cli
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ">="
45
+ - - '='
46
46
  - !ruby/object:Gem::Version
47
- version: '0'
47
+ version: 0.3.1
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ">="
52
+ - - '='
53
53
  - !ruby/object:Gem::Version
54
- version: '0'
54
+ version: 0.3.1
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: activesupport
57
57
  requirement: !ruby/object:Gem::Requirement