jenncad 1.0.0.pre.alpha14 → 1.0.0.pre.alpha17

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,6 +3,11 @@ module JennCad
3
3
  Circle.new(args).set_parent(self)
4
4
  end
5
5
 
6
+ def square(args)
7
+ Square.new(args).set_parent(self)
8
+ end
9
+ alias :sq :square
10
+
6
11
  def cylinder(*args)
7
12
  Cylinder.new(args).set_parent(self)
8
13
  end
@@ -18,6 +23,10 @@ module JennCad
18
23
  Polygon.new(args).set_parent(self)
19
24
  end
20
25
 
26
+ def polyhedron(args)
27
+ Polyhedron.new(args).set_parent(self)
28
+ end
29
+
21
30
  def slot(*args)
22
31
  Slot.new(args).set_parent(self)
23
32
  end
@@ -32,6 +41,7 @@ module JennCad
32
41
  end
33
42
  alias :rcube :rounded_cube
34
43
  alias :rc :rounded_cube
44
+ alias :rsq :rounded_cube
35
45
 
36
46
  # import/use OpenScad library
37
47
  def import(import,name,args)
@@ -93,8 +103,8 @@ module JennCad
93
103
  private
94
104
  def boolean_operation(part, klass)
95
105
  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))
106
+ # Clone the part in place
107
+ part = part.fix
98
108
  end
99
109
 
100
110
  case self
@@ -103,7 +113,12 @@ module JennCad
103
113
  when klass
104
114
  add_or_new(part)
105
115
  else
106
- klass.new(self,part)
116
+ own_part = if self.respond_to? :transformations
117
+ self.fix # clone self
118
+ else
119
+ self
120
+ end
121
+ klass.new(own_part,part)
107
122
  end
108
123
  end
109
124
  end
data/lib/jenncad/thing.rb CHANGED
@@ -11,6 +11,10 @@ module JennCad
11
11
  attr_accessor :parent
12
12
 
13
13
  def initialize(args={})
14
+ init(args)
15
+ end
16
+
17
+ def init(args={})
14
18
  @transformations = []
15
19
  # calculated origin; only works for move atm
16
20
  @calc_x = 0
@@ -18,7 +22,7 @@ module JennCad
18
22
  @calc_z = 0
19
23
  @calc_h = args[:z] || 0
20
24
  @anchors = {}
21
- @parent = args[:parent]
25
+ @parent = args[:parent] || nil
22
26
  @opts ||= args
23
27
  @cache = nil
24
28
  end
@@ -33,25 +37,102 @@ module JennCad
33
37
  @opts[key] = val
34
38
  end
35
39
 
40
+ def set_flag(key)
41
+ set_option(key, true)
42
+ self
43
+ end
44
+
45
+ def unset_flag(key)
46
+ set_option(key, false)
47
+ self
48
+ end
49
+
50
+
51
+ def cut_to(face, part=nil, args={})
52
+ an = anchor(face, part)
53
+ unless an
54
+ $log.error "Cannot find anchor to cut_to"
55
+ return self
56
+ end
57
+ if an[:z].to_d == 0.0
58
+ $log.error "cut_to only supports cuts to an anchor with Z set. This anchor: #{an}"
59
+ return self
60
+ end
61
+ modify_values(self, z: an[:z].to_d)
62
+ self.name="#{self.class}_cut_to_#{an[:z].to_f}"
63
+ self
64
+ end
65
+
66
+ def modify_values(parts, value, opts = {})
67
+ case parts
68
+ when Array
69
+ parts.each do |pa|
70
+ modify_values(pa, value, opts)
71
+ end
72
+ else
73
+ if parts.kind_of?(BooleanObject)
74
+ modify_values(parts.only_additives_of(parts), value, opts)
75
+ elsif parts.kind_of?(Part)
76
+ modify_values(parts.part, value, opts)
77
+ modify_values(parts.get_contents, value, opts)
78
+ parts.modify_values!(value, opts)
79
+ elsif parts.kind_of?(Primitive)
80
+ parts.modify_values!(value, opts)
81
+ end
82
+ end
83
+ end
84
+
85
+ def modify_values!(values, opts)
86
+ $log.info "Modify value! #{self.class} #{values}" if self.debug?
87
+ values.each do |key, val|
88
+ if @opts
89
+ case opts[:mode]
90
+ when :add
91
+ @opts[key] = @opts[key].to_d + val.to_d
92
+ when :sub
93
+ @opts[key] = @opts[key].to_d - val.to_d
94
+ else
95
+ @opts[key] = val
96
+ end
97
+ end
98
+ if self.respond_to? key
99
+ self.send("#{key}=", @opts[key])
100
+ end
101
+ end
102
+ $log.info "Modified value now: #{self.inspect}" if self.debug?
103
+ end
104
+
105
+
106
+ def debug?
107
+ option(:debug) || false
108
+ end
109
+
110
+ def fixate
111
+ Marshal.load(Marshal.dump(self))
112
+ end
113
+ alias :fix :fixate
114
+
36
115
  def set_parent(parent)
37
116
  @parent = parent
38
117
  self
39
118
  end
40
119
 
41
- def anchor(name, thing=nil)
120
+ def anchor(name, thing=nil, args={})
42
121
  if thing
43
- res = thing.anchor(name)
122
+ res = thing.anchor(name, nil, args)
44
123
  return res unless res.nil?
45
124
  end
46
125
  @anchors ||= {}
47
126
  if anch = @anchors[name]
48
127
  return anch
128
+ elsif args[:fail_quick] && args[:fail_quick] == true
129
+ return
49
130
  elsif @parent
50
131
  return @parent.anchor(name)
51
132
  elsif self.respond_to? :get_contents
52
133
  con = get_contents
53
134
  if con.respond_to? :anchor
54
- con.anchor(name)
135
+ con.anchor(name, nil, fail_quick: true)
55
136
  end
56
137
  end
57
138
  end
@@ -64,6 +145,32 @@ module JennCad
64
145
  end
65
146
  alias :sa :set_anchor
66
147
 
148
+ def set_anchor_from(name, new_name, args={})
149
+ unless name.kind_of? Symbol or name.kind_of? String
150
+ $log.error "set_anchor_from: name must be a string or symbol. Supplied: #{name}"
151
+ return
152
+ end
153
+ unless new_name.kind_of? Symbol or new_name.kind_of? String
154
+ $log.error "set_anchor_from: new_name must be a string or symbol. Supplied: #{new_name}"
155
+ return
156
+ end
157
+
158
+
159
+ a = anchor(name, args[:from]).dup
160
+ if !a
161
+ $log.error "set_anchor_from couldn't find anchor #{name}"
162
+ return
163
+ end
164
+
165
+ [:x, :y, :z, :xy, :xz, :xyz, :yz].each do |key|
166
+ a[key] ||= 0.to_d
167
+ args[key] ||= 0.to_d
168
+ a[key] += args[key]
169
+ end
170
+ set_anchor new_name, a
171
+ end
172
+ alias :saf :set_anchor_from
173
+
67
174
  def auto_extrude
68
175
  ret = self.extrude
69
176
  ret.set_option(:auto_extrude, true)
@@ -180,6 +287,27 @@ module JennCad
180
287
  return args
181
288
  end
182
289
 
290
+ # reset last move
291
+ def reset_last_move
292
+ lt = @transformations.last
293
+ unless lt.class == Move
294
+ $log.error "Tried to call rst_move but last object is a #{lt.class}"
295
+ return self
296
+ end
297
+ @transformations.delete_at(-1)
298
+
299
+ self
300
+ end
301
+ alias :rstlm :reset_last_move
302
+
303
+ # resets all transformations
304
+ def reset
305
+ @transformations = []
306
+ self
307
+ end
308
+ alias :rst :reset
309
+
310
+
183
311
  def move(args={})
184
312
  return self if args.nil? or args.empty?
185
313
 
@@ -206,10 +334,12 @@ module JennCad
206
334
  end
207
335
 
208
336
  if lt && lt.class == Move && chain == false
337
+ $log.debug "#{self} at move: Adding to previous move #{lt.inspect} , args: #{args}" if self.debug?
209
338
  lt.x += args[:x].to_d
210
339
  lt.y += args[:y].to_d
211
340
  lt.z += args[:z].to_d
212
341
  else
342
+ $log.debug "#{self} at move: Adding move of #{args} to transformations" if self.debug?
213
343
  @transformations << Move.new(args)
214
344
  end
215
345
  end
@@ -240,7 +370,7 @@ module JennCad
240
370
  thing = nil
241
371
  end
242
372
 
243
- an = anchor(key, thing)
373
+ an = anchor(key, thing, args)
244
374
 
245
375
  unless an
246
376
  $log.error "Error: Anchor #{key} not found"
@@ -258,6 +388,7 @@ module JennCad
258
388
  end
259
389
  end
260
390
  end
391
+ alias :ma :movea
261
392
 
262
393
  # move to anchor - inverted
263
394
  def moveai(key, thing=nil, args={})
@@ -268,7 +399,7 @@ module JennCad
268
399
  args[:inverted] = true
269
400
  movea(key, thing, args)
270
401
  end
271
-
402
+ alias :mai :moveai
272
403
 
273
404
  # move half
274
405
  def moveh(args={})
@@ -488,6 +619,8 @@ module JennCad
488
619
  return "##{args}"
489
620
  when String
490
621
  return args
622
+ when Symbol
623
+ return args.to_s
491
624
  end
492
625
  nil
493
626
  end
@@ -512,7 +645,7 @@ module JennCad
512
645
  return @parts unless @parts.nil?
513
646
 
514
647
  if @cache
515
- return @cache
648
+ return @cache unless option(:no_cache) == true
516
649
  end
517
650
 
518
651
  if self.respond_to? :part
@@ -624,5 +757,25 @@ module JennCad
624
757
  end
625
758
  end
626
759
 
760
+ def to_mod(name)
761
+ a = Aggregation.new(name, self)
762
+ a.transformations = @transformations
763
+ a
764
+ end
765
+
766
+ def is_2d?
767
+ !is_3d?
768
+ end
769
+
770
+ def is_3d?
771
+ if self.respond_to?(:dimensions) && self.dimensions
772
+ return true if self.dimensions && self.dimensions.include?(:z)
773
+ else
774
+ # assume true if not set
775
+ return true
776
+ end
777
+ false
778
+ end
779
+
627
780
  end
628
781
  end
@@ -1,3 +1,3 @@
1
1
  module JennCad
2
- VERSION = "1.0.0-alpha14"
2
+ VERSION = "1.0.0-alpha17"
3
3
  end
data/lib/jenncad.rb CHANGED
@@ -6,7 +6,6 @@ require "geo3d"
6
6
  require "deep_merge"
7
7
  require "fileutils"
8
8
  require "observr"
9
- require "hanami/cli"
10
9
  require "active_support"
11
10
 
12
11
  include Math
data/todo.txt CHANGED
@@ -11,16 +11,6 @@
11
11
  Features wanted
12
12
  ===================
13
13
  28.4.22:
14
- - Parts often come with 4 holes around a center, and I often do something like:
15
-
16
- [-1, 1].each do |i|
17
- [-1, 1].each do |j|
18
- res += @bolt.cut.move(x: @hole_center*i, y: @hole_center*j)
19
- end
20
- end
21
-
22
- there should be a shorter way to do this.
23
-
24
14
 
25
15
  - instead of moving Bolts output, make it the default to make their positions an anchor
26
16
 
@@ -34,6 +24,12 @@ there should be a shorter way to do this.
34
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..
35
25
  - Bolts should be able to also make thread inserts
36
26
 
27
+ 8.5.22:
28
+ - need an easy way to switch between faces on an object to work efficiently in a 2.5D way
29
+ 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
30
+
31
+
32
+
37
33
 
38
34
 
39
35
 
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.alpha14
4
+ version: 1.0.0.pre.alpha17
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-02 00:00:00.000000000 Z
11
+ date: 2022-05-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: geo3d
@@ -122,6 +122,7 @@ files:
122
122
  - lib/jenncad/features/climb.rb
123
123
  - lib/jenncad/features/cuttable.rb
124
124
  - lib/jenncad/features/feature.rb
125
+ - lib/jenncad/features/multiples_of.rb
125
126
  - lib/jenncad/features/openscad_include.rb
126
127
  - lib/jenncad/features/path.rb
127
128
  - lib/jenncad/features/stl_import.rb
@@ -136,12 +137,14 @@ files:
136
137
  - lib/jenncad/primitives/intersection_object.rb
137
138
  - lib/jenncad/primitives/linear_extrude.rb
138
139
  - lib/jenncad/primitives/polygon.rb
140
+ - lib/jenncad/primitives/polyhedron.rb
139
141
  - lib/jenncad/primitives/primitive.rb
140
142
  - lib/jenncad/primitives/projection.rb
141
143
  - lib/jenncad/primitives/rotate_extrude.rb
142
144
  - lib/jenncad/primitives/rounded_cube.rb
143
145
  - lib/jenncad/primitives/slot.rb
144
146
  - lib/jenncad/primitives/sphere.rb
147
+ - lib/jenncad/primitives/square.rb
145
148
  - lib/jenncad/primitives/subtract_object.rb
146
149
  - lib/jenncad/primitives/union_object.rb
147
150
  - lib/jenncad/profile_loader.rb