Class: SolidRuby::Assemblies::Assembly

Inherits:
SolidRubyObject show all
Defined in:
lib/solidruby/assemblies/assembly.rb

Direct Known Subclasses

Bolt, Gear, LasercutSheet, Lm_uu, Nut, Pipe, Printed, Ruler, TSlot, Washer

Instance Attribute Summary collapse

Attributes inherited from SolidRubyObject

#attributes, #children, #siblings

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from SolidRubyObject

#&, alias_attr, #debug, #debug?, #mirror, #place, #rotate, #rotate_around, #save, #scale, #to_rubyscad, #translate, #union, #walk_tree_classes

Constructor Details

#initialize(args = {}) ⇒ Assembly

Returns a new instance of Assembly.



31
32
33
34
35
36
37
38
39
40
# File 'lib/solidruby/assemblies/assembly.rb', line 31

def initialize(args = {})
  super(args)
  @args ||= args

  @x = args[:x]
  @y = args[:y]
  @z = args[:z]

  add_to_bom
end

Instance Attribute Details

#hardwareObject

Returns the value of attribute hardware.



18
19
20
# File 'lib/solidruby/assemblies/assembly.rb', line 18

def hardware
  @hardware
end

#skipObject

Returns the value of attribute skip.



18
19
20
# File 'lib/solidruby/assemblies/assembly.rb', line 18

def skip
  @skip
end

#transformationsObject

Returns the value of attribute transformations.



18
19
20
# File 'lib/solidruby/assemblies/assembly.rb', line 18

def transformations
  @transformations
end

#xObject

Returns the value of attribute x.



18
19
20
# File 'lib/solidruby/assemblies/assembly.rb', line 18

def x
  @x
end

#yObject

Returns the value of attribute y.



18
19
20
# File 'lib/solidruby/assemblies/assembly.rb', line 18

def y
  @y
end

#zObject

Returns the value of attribute z.



18
19
20
# File 'lib/solidruby/assemblies/assembly.rb', line 18

def z
  @z
end

Class Method Details

.get_skipObject



120
121
122
# File 'lib/solidruby/assemblies/assembly.rb', line 120

def self.get_skip
  @skip
end

.get_viewsObject



137
138
139
# File 'lib/solidruby/assemblies/assembly.rb', line 137

def self.get_views
  @added_views || []
end

.skip(args) ⇒ Object

Makes the save_all method in SolidRuby skip the specified method(s)



107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/solidruby/assemblies/assembly.rb', line 107

def self.skip(args)
  @skip = [] if @skip.nil?
  if args.is_a? Array
    args.each do |arg|
      skip(arg)
    end
    return
  end

  @skip << args.to_s
  nil
end

.view(args) ⇒ Object



124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/solidruby/assemblies/assembly.rb', line 124

def self.view(args)
  @added_views = [] if @added_views.nil?
  if args.is_a? Array
    args.each do |arg|
      view(arg)
    end
    return
  end

  @added_views << args.to_s
  nil
end

Instance Method Details

#*(args) ⇒ Object



80
81
82
# File 'lib/solidruby/assemblies/assembly.rb', line 80

def *(args)
  output * args
end

#+(args) ⇒ Object



72
73
74
# File 'lib/solidruby/assemblies/assembly.rb', line 72

def +(args)
  output + args
end

#-(args) ⇒ Object



76
77
78
# File 'lib/solidruby/assemblies/assembly.rb', line 76

def -(args)
  output - args
end

#add_to_bomObject



42
43
44
45
46
47
48
49
# File 'lib/solidruby/assemblies/assembly.rb', line 42

def add_to_bom
  @bom_added ||= false

  unless @bom_added
    BillOfMaterial.bom.add(description) unless @args[:no_bom] == true
    @bom_added = true
  end
end

#color(args = {}) ⇒ Object



141
142
143
144
# File 'lib/solidruby/assemblies/assembly.rb', line 141

def color(args = {})
  @color = args
  self
end

#colorize(res) ⇒ Object



146
147
148
149
# File 'lib/solidruby/assemblies/assembly.rb', line 146

def colorize(res)
  return res if @color.nil?
  res.color(@color)
end

#descriptionObject



51
52
53
# File 'lib/solidruby/assemblies/assembly.rb', line 51

def description
  "No description set for Class #{self.class}"
end

#outputObject



59
60
61
# File 'lib/solidruby/assemblies/assembly.rb', line 59

def output
  transform(part(false))
end

#part(_show = false) ⇒ Object



63
64
65
# File 'lib/solidruby/assemblies/assembly.rb', line 63

def part(_show = false)
  #SolidRubyObject.new
end

#scad_outputObject



84
85
86
87
# File 'lib/solidruby/assemblies/assembly.rb', line 84

def scad_output
  res = debug? ? '#' : ''
  res + output.scad_output
end

#showObject



55
56
57
# File 'lib/solidruby/assemblies/assembly.rb', line 55

def show
  transform(part(true))
end

#show_hardwareObject



151
152
153
154
155
156
157
158
# File 'lib/solidruby/assemblies/assembly.rb', line 151

def show_hardware
  return nil if @hardware.nil? || (@hardware == [])
  res = nil
  @hardware.each do |part|
    res += part.show
  end
  transform(res)
end

#threadsObject



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/solidruby/assemblies/assembly.rb', line 89

def threads
  a = []
  [:threads_top, :threads_bottom, :threads_left, :threads_right, :threads_front, :threads_back].each do |m|
    next unless respond_to? m
    ret = send m
    unless ret.nil?
      if ret.is_a? Array
        a += ret
      else
        a << ret
      end
    end
  end

  a
end

#transform(obj) ⇒ Object



20
21
22
23
24
25
26
27
28
29
# File 'lib/solidruby/assemblies/assembly.rb', line 20

def transform(obj)
  obj = obj.debug if debug?
  @transformations ||= nil
  return obj if @transformations.nil?
  @transformations.each do |t|
    obj.transformations << t
  end

  obj
end

#walk_treeObject



67
68
69
70
# File 'lib/solidruby/assemblies/assembly.rb', line 67

def walk_tree
  res = debug? ? '#' : ''
  res + output.walk_tree
end