Class: CrystalScad::Assembly

Inherits:
Primitive show all
Defined in:
lib/crystalscad/Assembly.rb

Instance Attribute Summary collapse

Attributes inherited from Primitive

#children

Attributes inherited from CrystalScadObject

#args

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Primitive

#mirror, #rotate, #rotate_around, #scale, #translate, #union

Methods inherited from CrystalScadObject

#save, #to_rubyscad, #walk_tree_classes

Constructor Details

#initialize(args = {}) ⇒ Assembly

Returns a new instance of Assembly.



34
35
36
37
38
39
40
41
42
# File 'lib/crystalscad/Assembly.rb', line 34

def initialize(args={})
  @args = args if @args == nil

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

   add_to_bom
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



20
21
22
23
# File 'lib/crystalscad/Assembly.rb', line 20

def method_missing(method, *args, &block)	
	eval( "def #{method}() @#{method}; end" )
	return self.send(method, *args, &block)
end

Instance Attribute Details

#color(args = {}) ⇒ Object

Returns the value of attribute color.



18
19
20
# File 'lib/crystalscad/Assembly.rb', line 18

def color
  @color
end

#hardwareObject

Returns the value of attribute hardware.



18
19
20
# File 'lib/crystalscad/Assembly.rb', line 18

def hardware
  @hardware
end

#skipObject

Returns the value of attribute skip.



18
19
20
# File 'lib/crystalscad/Assembly.rb', line 18

def skip
  @skip
end

#transformationsObject

Returns the value of attribute transformations.



18
19
20
# File 'lib/crystalscad/Assembly.rb', line 18

def transformations
  @transformations
end

#xObject

Returns the value of attribute x.



18
19
20
# File 'lib/crystalscad/Assembly.rb', line 18

def x
  @x
end

#yObject

Returns the value of attribute y.



18
19
20
# File 'lib/crystalscad/Assembly.rb', line 18

def y
  @y
end

#zObject

Returns the value of attribute z.



18
19
20
# File 'lib/crystalscad/Assembly.rb', line 18

def z
  @z
end

Class Method Details

.get_skipObject



119
120
121
# File 'lib/crystalscad/Assembly.rb', line 119

def self.get_skip
	@skip		
end

.get_viewsObject



137
138
139
# File 'lib/crystalscad/Assembly.rb', line 137

def self.get_views
	@added_views || []
end

.skip(args) ⇒ Object

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



106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/crystalscad/Assembly.rb', line 106

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

.view(args) ⇒ Object



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

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

Instance Method Details

#*(args) ⇒ Object



79
80
81
# File 'lib/crystalscad/Assembly.rb', line 79

def *(args)
  return self.output*args
end

#+(args) ⇒ Object



71
72
73
# File 'lib/crystalscad/Assembly.rb', line 71

def +(args)
  return self.output+args
end

#-(args) ⇒ Object



75
76
77
# File 'lib/crystalscad/Assembly.rb', line 75

def -(args)
  return self.output-args
end

#add_to_bomObject



44
45
46
47
48
49
# File 'lib/crystalscad/Assembly.rb', line 44

def add_to_bom
	if !@bom_added				
		@@bom.add(description) unless @args[:no_bom] == true
		@bom_added = true
	end
end

#colorize(res) ⇒ Object



147
148
149
150
# File 'lib/crystalscad/Assembly.rb', line 147

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

#descriptionObject



51
52
53
# File 'lib/crystalscad/Assembly.rb', line 51

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

#outputObject



59
60
61
# File 'lib/crystalscad/Assembly.rb', line 59

def output
  transform(part(false))
end

#part(show = false) ⇒ Object



63
64
65
# File 'lib/crystalscad/Assembly.rb', line 63

def part(show=false)
	CrystalScadObject.new
end

#scad_outputObject



83
84
85
# File 'lib/crystalscad/Assembly.rb', line 83

def scad_output()
  return self.output.scad_output
end

#showObject



55
56
57
# File 'lib/crystalscad/Assembly.rb', line 55

def show
  transform(part(true))
end

#show_hardwareObject



152
153
154
155
156
157
158
159
# File 'lib/crystalscad/Assembly.rb', line 152

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

#threadsObject



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/crystalscad/Assembly.rb', line 87

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

	return a
end

#transform(obj) ⇒ Object



25
26
27
28
29
30
31
32
# File 'lib/crystalscad/Assembly.rb', line 25

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

#walk_treeObject



67
68
69
# File 'lib/crystalscad/Assembly.rb', line 67

def walk_tree
  return output.walk_tree
end