jenncad 1.0.0.pre.alpha18 → 1.0.0.pre.alpha21

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: 5d05a39eda135dbbda74bcdc75c66a4c9d7620e426d5656e377442dcc17ef665
4
- data.tar.gz: 1514fd3b8ecc502f95c0a9a7e93e13622e706d518abe31f7af4e60d56d85f357
3
+ metadata.gz: bf38a53bfb5d20ab5af97d24c948792ae3e5d577d63806f4a9d7008b5429f507
4
+ data.tar.gz: aae023c68738b1aee605fff567b3d0792f98753252858e1ee2569a18dd470daf
5
5
  SHA512:
6
- metadata.gz: 9ea62b48418d86b7daa3f2ddcb895d03494942dea723fd60de9f81cbd25aab1d6aefd801136258192ab18b0dc9803cfe368cfb3f5b8bb1a33288eade384b7b96
7
- data.tar.gz: e25c9f138b698f5c041dc7d0455a06807fe26ba12663039a9c522f0433d7435f3ecebdb72031069e81dea24414a8b0cfec76809a20bdedc50ab76442e7380b65
6
+ metadata.gz: fe8765bc981516be5fe1e94212e946a32d14baf295e0995be9820589dbe31b1be430a1792c1c8bd57ceaeab132ae495668ba8852fa7dbd16676b3345d3c4c8e8
7
+ data.tar.gz: 5667ae97532fa9094125d65603f8542a2cef77621c082ff2c097eebc3865ae5ca683ac16cc5cc9b2a3a09042ca6bd678cadd351f0fa468698e94fc56cf3bedfc
@@ -46,6 +46,7 @@ module JennCad
46
46
 
47
47
  class Build < Run
48
48
  option :binary, type: :boolean, default: false, desc: "run through admesh to create a binary stl"
49
+ option :only_print, type: :boolean, default: true, desc: "If a part has a print orientation set, only build that orientation as STL"
49
50
 
50
51
  def build(options)
51
52
  if options[:binary]
@@ -55,7 +56,13 @@ module JennCad
55
56
  end
56
57
  end
57
58
 
58
- Dir.glob("output/**/*.scad").each do |file|
59
+ files = Dir.glob("output/**/*.scad")
60
+ if options[:only_print]
61
+ # Remove non _print.scad files from the list of files to build if we have a print orientation (and the only_print flag set)
62
+ files -= Dir.glob("output/**/*_print.scad").map{|x| x.gsub("_print.scad",".scad")}
63
+ end
64
+
65
+ files.each do |file|
59
66
  stl = file.gsub(".scad",".stl")
60
67
  build_stl(file, stl)
61
68
  convert_to_binary(stl) if options[:binary] && admesh_installed
@@ -7,9 +7,6 @@ require "jenncad/features/stl_import"
7
7
  require "jenncad/features/path"
8
8
  require "jenncad/features/multiples_of"
9
9
 
10
-
11
-
12
-
13
10
  module JennCad
14
11
  include Features
15
12
  end
data/lib/jenncad/part.rb CHANGED
@@ -10,6 +10,8 @@ end
10
10
  module JennCad
11
11
  # Part should be inherited from the user when making parts
12
12
  class Part < Thing
13
+ attr_accessor :d
14
+
13
15
  def self.inherited(subclass)
14
16
  subclass.prepend(AutoName) if subclass.superclass == Part
15
17
  end
@@ -7,6 +7,11 @@ module JennCad::Primitives
7
7
  else
8
8
  @parts = parts
9
9
  end
10
+
11
+ if @parts.first.respond_to? :anchors
12
+ @anchors = @parts.first.anchors
13
+ end
14
+
10
15
  if parts.first && parts.first.respond_to?(:debug?) && parts.first.debug?
11
16
  $log.debug("Creating new #{self.class} for part #{parts}")
12
17
  end
@@ -1,5 +1,7 @@
1
1
  module JennCad::Primitives
2
2
  class Circle < Primitive
3
+ include CircleIsh
4
+
3
5
  attr_accessor :d, :r, :fn
4
6
  def initialize(args)
5
7
  if args.kind_of?(Array) && args[0].kind_of?(Hash)
@@ -38,21 +40,6 @@ module JennCad::Primitives
38
40
  set_anchors_2d
39
41
  end
40
42
 
41
- def set_anchors_2d
42
- @anchors = {} # reset anchors
43
- if @opts[:d]
44
- rad = @opts[:d] / 2.0
45
- else
46
- rad = @opts[:r]
47
- end
48
-
49
- # Similar to cube
50
- set_anchor :left, x: -rad
51
- set_anchor :right, x: rad
52
- set_anchor :top, y: rad
53
- set_anchor :bottom, y: -rad
54
- end
55
-
56
43
  def openscad_params
57
44
  res = {}
58
45
  [:d, :fn].each do |n|
@@ -61,49 +48,6 @@ module JennCad::Primitives
61
48
  res
62
49
  end
63
50
 
64
- def handle_fn
65
- case @opts[:fn]
66
- when nil, 0
67
- $fn = auto_dn!
68
- else
69
- @fn = @opts[:fn]
70
- end
71
- end
72
-
73
- def auto_dn!
74
- case @d
75
- when (16..)
76
- @fn = (@d*4).ceil
77
- else
78
- @fn = 64
79
- end
80
- end
81
-
82
- def handle_radius_diameter
83
- case @opts[:d]
84
- when 0, nil
85
- @r = @opts[:r].to_d + @opts[:margins][:r].to_d
86
- @d = @r * 2.0
87
- else
88
- @d = @opts[:d].to_d + @opts[:margins][:d].to_d
89
- @r = @d / 2.0
90
- end
91
-
92
- case @opts[:d1]
93
- when 0, nil
94
- else
95
- @d1 = @opts[:d1].to_d + @opts[:margins][:d].to_d
96
- @d2 = @opts[:d2].to_d + @opts[:margins][:d].to_d
97
- end
98
-
99
- case @opts[:r1]
100
- when 0, nil
101
- else
102
- @d1 = 2 * @opts[:r1].to_d + @opts[:margins][:d].to_d
103
- @d2 = 2 * @opts[:r2].to_d + @opts[:margins][:d].to_d
104
- end
105
- end
106
-
107
51
 
108
52
  end
109
53
  end
@@ -4,16 +4,25 @@ module JennCad::Primitives
4
4
  def initialize(part, args={})
5
5
  @transformations = []
6
6
  @parts = [part]
7
+ if args.kind_of? Numeric
8
+ args = {h: args}
9
+ end
10
+
7
11
  @z = args[:h] || args[:height] || args[:z]
8
12
  @center_bool = args[:center]
9
13
  @convexity = args[:convexity]
10
14
  @twist = args[:twist]
11
15
  @slices = args[:slices]
12
16
  @fn = args[:fn]
17
+ @opts = {
18
+ margins: {
19
+ z: 0,
20
+ }
21
+ }.deep_merge(args)
13
22
  end
14
23
 
15
24
  def height
16
- @z
25
+ @z.to_d + @opts[:margins][:z].to_d
17
26
  end
18
27
 
19
28
  def openscad_params
@@ -1,5 +1,6 @@
1
1
  module JennCad::Primitives
2
2
  class Slot < Primitive
3
+ include CircleIsh
3
4
  attr_accessor :d, :r, :h, :fn, :len_x, :len_y
4
5
 
5
6
  def initialize(args)
@@ -28,7 +29,11 @@ module JennCad::Primitives
28
29
  x: 0,
29
30
  y: 0,
30
31
  z: nil,
32
+ d1: nil,
33
+ d2: nil,
34
+ mode: :auto,
31
35
  cz: false,
36
+ az: false,
32
37
  margins: {
33
38
  r: 0,
34
39
  d: 0,
@@ -61,8 +66,6 @@ module JennCad::Primitives
61
66
  @len_y = ty - @d
62
67
  end
63
68
 
64
- # TODO: this needs anchors like cube
65
- # TODO: color on this needs to apply to hull, not on the cylinders.
66
69
  set_anchors
67
70
  end
68
71
 
@@ -76,11 +79,7 @@ module JennCad::Primitives
76
79
 
77
80
  def set_anchors
78
81
  @anchors = {} # reset anchors
79
- if @opts[:d]
80
- rad = @opts[:d] / 2.0
81
- else
82
- rad = @opts[:r]
83
- end
82
+ rad = radius
84
83
 
85
84
  if @x > 0
86
85
  set_anchor :left, x: - rad
@@ -120,9 +119,39 @@ module JennCad::Primitives
120
119
  end
121
120
  end
122
121
 
122
+ def get_mode
123
+ if @opts[:d1] && @opts[:d2]
124
+ case @opts[:mode]
125
+ when nil, :auto
126
+ :dia1
127
+ when :cyl
128
+ :cyl
129
+ else
130
+ :dia1
131
+ end
132
+ else
133
+ :default
134
+ end
135
+ end
136
+
123
137
  def to_openscad
124
- c1 = cylinder(@opts)
125
- c2 = cylinder(@opts)
138
+ mode = get_mode
139
+
140
+ opts = @opts.clone
141
+ opts.delete(:color)
142
+
143
+ case mode
144
+ when :default
145
+ c1 = ci(opts)
146
+ c2 = ci(opts)
147
+ when :dia1 # new default mode; d1 start dia, d2 end dia
148
+ c1 = ci(opts.merge(d: @opts[:d1]))
149
+ c2 = ci(opts.merge(d: @opts[:d2]))
150
+ when :cyl # old mode; use cylinders
151
+ c1 = cy(opts)
152
+ c2 = cy(opts)
153
+ end
154
+
126
155
  if @len_x
127
156
  c2.move(x:@len_x)
128
157
  end
@@ -130,6 +159,14 @@ module JennCad::Primitives
130
159
  c2.move(y:@len_y)
131
160
  end
132
161
  res = c1 & c2
162
+ if mode != :cyl && @z.to_d > 0
163
+ res = res.e(@z)
164
+ elsif @opts[:az] == true
165
+ # TODO: this needs testing, may not work
166
+ res = res.auto_extrude
167
+ end
168
+ res.inherit_color(self)
169
+
133
170
  if @a != 0.0
134
171
  res = res.rotate(z:@a)
135
172
  end
@@ -42,6 +42,8 @@ module JennCad::Primitives
42
42
 
43
43
  def set_anchors_2d
44
44
  @anchors = {} # this resets anchors
45
+ @corners = [:top_right, :top_left, :bottom_right, :bottom_left]
46
+ @sides = [:left, :right, :top, :bottom]
45
47
 
46
48
  if @opts[:center] || @opts[:center_x]
47
49
  left = -@opts[:x] / 2.0
@@ -17,10 +17,18 @@ module JennCad
17
17
  run_exports
18
18
  end
19
19
 
20
+ def run_export!(part, file)
21
+ part.openscad([output_dir,file].join("/"))
22
+ end
23
+
20
24
  def run_exports
21
25
  outputs.each do |name|
22
26
  part = self.send(name)
23
- part.openscad([output_dir,"#{name}.scad"].join("/"))
27
+ run_export!(part, "#{name}.scad")
28
+ if part.respond_to? :print
29
+ part = self.send(name).print
30
+ run_export!(part, "#{name}_print.scad")
31
+ end
24
32
  end
25
33
  end
26
34
 
@@ -0,0 +1,65 @@
1
+ module CircleIsh
2
+
3
+ def radius
4
+ if @opts[:d]
5
+ @opts[:d].to_d / 2.0
6
+ else
7
+ @opts[:r].to_d
8
+ end
9
+ end
10
+
11
+ def set_anchors_2d
12
+ @anchors = {} # reset anchors
13
+ rad = radius
14
+ # Similar to cube
15
+ set_anchor :left, x: -rad
16
+ set_anchor :right, x: rad
17
+ set_anchor :top, y: rad
18
+ set_anchor :bottom, y: -rad
19
+ end
20
+
21
+ def handle_fn
22
+ case @opts[:fn]
23
+ when nil, 0
24
+ $fn = auto_dn!
25
+ else
26
+ @fn = @opts[:fn]
27
+ end
28
+ end
29
+
30
+ def auto_dn!
31
+ case @d
32
+ when (16..)
33
+ @fn = (@d*4).ceil
34
+ else
35
+ @fn = 64
36
+ end
37
+ end
38
+
39
+ def handle_radius_diameter
40
+ case @opts[:d]
41
+ when 0, nil
42
+ @r = @opts[:r].to_d + @opts[:margins][:r].to_d
43
+ @d = @r * 2.0
44
+ else
45
+ @d = @opts[:d].to_d + @opts[:margins][:d].to_d
46
+ @r = @d / 2.0
47
+ end
48
+
49
+ case @opts[:d1]
50
+ when 0, nil
51
+ else
52
+ @d1 = @opts[:d1].to_d + @opts[:margins][:d].to_d
53
+ @d2 = @opts[:d2].to_d + @opts[:margins][:d].to_d
54
+ end
55
+
56
+ case @opts[:r1]
57
+ when 0, nil
58
+ else
59
+ @d1 = 2 * @opts[:r1].to_d + @opts[:margins][:d].to_d
60
+ @d2 = 2 * @opts[:r2].to_d + @opts[:margins][:d].to_d
61
+ end
62
+ end
63
+
64
+
65
+ end
@@ -0,0 +1,3 @@
1
+ module CubeIsh
2
+ # TBD
3
+ end
@@ -0,0 +1,3 @@
1
+ require "jenncad/shared/circle_ish"
2
+ require "jenncad/shared/cube_ish"
3
+
@@ -2,6 +2,7 @@ module JennCad
2
2
  def circle(args)
3
3
  Circle.new(args).set_parent(self)
4
4
  end
5
+ alias :ci :circle
5
6
 
6
7
  def square(args)
7
8
  Square.new(args).set_parent(self)
@@ -22,14 +23,17 @@ module JennCad
22
23
  def polygon(args)
23
24
  Polygon.new(args).set_parent(self)
24
25
  end
26
+ alias :pg :polygon
25
27
 
26
28
  def polyhedron(args)
27
29
  Polyhedron.new(args).set_parent(self)
28
30
  end
31
+ alias :phd :polyhedron
29
32
 
30
33
  def slot(*args)
31
34
  Slot.new(args).set_parent(self)
32
35
  end
36
+ alias :sl :slot
33
37
 
34
38
  def cube(*args)
35
39
  Cube.new(args).set_parent(self)
@@ -55,14 +59,19 @@ module JennCad
55
59
  def extrude(args={})
56
60
  LinearExtrude.new(self, args)
57
61
  end
62
+ alias :e :extrude
63
+ alias :ex :extrude
58
64
 
59
65
  def rotate_extrude(args={})
60
66
  RotateExtrude.new(self, args)
61
67
  end
68
+ alias :re :rotate_extrude
69
+ alias :rex :rotate_extrude
62
70
 
63
71
  def to_2d(args={})
64
72
  Projection.new(self, args)
65
73
  end
74
+ alias :as_2d :to_2d
66
75
 
67
76
  def union(*args)
68
77
  UnionObject.new(*args)
data/lib/jenncad/thing.rb CHANGED
@@ -47,7 +47,6 @@ module JennCad
47
47
  self
48
48
  end
49
49
 
50
-
51
50
  def cut_to(face, part=nil, args={})
52
51
  an = anchor(face, part)
53
52
  unless an
@@ -145,6 +144,20 @@ module JennCad
145
144
  end
146
145
  alias :sa :set_anchor
147
146
 
147
+ def copy_anchors(thing)
148
+ @anchors = thing.anchors
149
+ end
150
+
151
+ def copy_anchor(name, thing=nil)
152
+ # since it might be confusing to use / use shortcuts for copy_anchor and copy_anchors, let copy_anchor copy all of them when only one parameter is given
153
+ if thing.nil?
154
+ return copy_anchors(name)
155
+ end
156
+ @anchors ||= {}
157
+ @anchors[name] = thing.anchor(name)
158
+ end
159
+ alias :cpa :copy_anchor
160
+
148
161
  def set_anchor_from(name, new_name, args={})
149
162
  unless name.kind_of? Symbol or name.kind_of? String
150
163
  $log.error "set_anchor_from: name must be a string or symbol. Supplied: #{name}"
@@ -363,6 +376,29 @@ module JennCad
363
376
  move(z:v)
364
377
  end
365
378
 
379
+ # Perform something at an anchor location block
380
+ def at(keys, thing=nil, args={}, &block)
381
+ unless keys.kind_of? Array
382
+ keys = [keys]
383
+ end
384
+
385
+ part = self
386
+ keys.each do |key|
387
+ if key.kind_of? Hash
388
+ an = key
389
+ else
390
+ an = anchor(key, thing, args)
391
+ end
392
+ unless an
393
+ $log.error "at on #{thing.class} could not find anchor #{key}"
394
+ an = {} # this will move by 0,0 and still display the block
395
+ end
396
+ part.movei(an)
397
+ part = block.yield.move(an)
398
+ end
399
+ part
400
+ end
401
+
366
402
  # move to anchor
367
403
  def movea(key, thing=nil, args={})
368
404
  if thing.kind_of? Hash # if you leave out thing, args may be interpreted as thing
@@ -445,8 +481,8 @@ module JennCad
445
481
  end
446
482
  alias :mi :mirror
447
483
 
448
- def miz
449
- mirror(z:1)
484
+ def mix
485
+ mirror(x:1)
450
486
  end
451
487
 
452
488
  def miy
@@ -1,3 +1,3 @@
1
1
  module JennCad
2
- VERSION = "1.0.0-alpha18"
2
+ VERSION = "1.0.0-alpha21"
3
3
  end
data/lib/jenncad.rb CHANGED
@@ -23,6 +23,7 @@ require "jenncad/part"
23
23
  require "jenncad/project"
24
24
  require "jenncad/commands"
25
25
 
26
+ require "jenncad/shared"
26
27
  require "jenncad/features"
27
28
  require "jenncad/primitives"
28
29
 
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.alpha18
4
+ version: 1.0.0.pre.alpha21
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-15 00:00:00.000000000 Z
11
+ date: 2022-05-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: geo3d
@@ -150,6 +150,9 @@ files:
150
150
  - lib/jenncad/profile_loader.rb
151
151
  - lib/jenncad/project.rb
152
152
  - lib/jenncad/register.rb
153
+ - lib/jenncad/shared.rb
154
+ - lib/jenncad/shared/circle_ish.rb
155
+ - lib/jenncad/shared/cube_ish.rb
153
156
  - lib/jenncad/shortcuts.rb
154
157
  - lib/jenncad/thing.rb
155
158
  - lib/jenncad/transformation/color.rb