Class: JennCad::Part

Inherits:
Thing
  • Object
show all
Defined in:
lib/jenncad/part.rb

Overview

Part should be inherited from the user when making parts

Instance Attribute Summary collapse

Attributes inherited from Thing

#anchors, #angle, #calc_h, #calc_x, #calc_y, #calc_z, #csize, #diameter, #fn, #name, #opts, #parent, #parts, #pos, #shape, #sits_on, #transformations, #x, #y

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Thing

#anchor, #at, #auto_color, #auto_color!, #auto_extrude, #calculate_center_rotation, #calculated_h, #children_list, #color, #color_or_fallback, #color_parse, #copy_anchor, #copy_anchors, #cut_to, #dbg, #debug?, #find_calculated_h, #fixate, #flip, #flipc, #get_children, #get_contents, #ghost, #has_explicit_color?, #hide, #hl, #inherit_color, #init, #initialize, #is_2d?, #is_3d?, #mhx, #mhy, #mhz, #mirror, #mix, #miy, #miz, #modify_values, #modify_values!, #move, #movea, #moveai, #moveh, #movei, #multmatrix, #mx, #my, #mz, #on_top_of, #only, #only_color?, #openscad, #openscad_modifier, #option, #parse_xyz_shortcuts, #radians, #referenced_z, #reset, #reset_last_move, #rotate, #rotate_around, #rx, #ry, #rz, #scale, #set_anchor, #set_anchor_from, #set_auto_color, #set_auto_color_for_children, #set_flag, #set_heights_for_auto_extrude, #set_option, #set_parent, #skew, #to_mod, #top_of, #transform, #unset_flag, #z, #z=, #z_margin

Constructor Details

This class inherits a constructor from JennCad::Thing

Instance Attribute Details

#dObject

Returns the value of attribute d.



13
14
15
# File 'lib/jenncad/part.rb', line 13

def d
  @d
end

Class Method Details

.inherited(subclass) ⇒ Object



15
16
17
# File 'lib/jenncad/part.rb', line 15

def self.inherited(subclass)
  subclass.prepend(AutoName) if subclass.superclass == Part
end

Instance Method Details

#fix_name_for_openscad(name) ⇒ Object



44
45
46
47
48
49
# File 'lib/jenncad/part.rb', line 44

def fix_name_for_openscad(name)
  [":", ",", ".", "[", "]","-", " "].each do |key|
    name.gsub!(key, "_")
  end
  name
end

#hardware(hw_type = nil, args = {}) ⇒ Object Also known as: hw

this function both gets and defines hardware



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/jenncad/part.rb', line 20

def hardware(hw_type=nil, args={})
  @_hw ||= {}
  if hw_type == nil
    return @_hw
  end

  anchors = args[:anchor] || args[:anchors]
  unless anchors.kind_of? Array
    anchors = [anchors]
  end

  anchors.each do |a|
    @_hw[a] = {
      hw_type: hw_type,
      size: args[:size],
      d: args[:d],
      len: args[:len],
      pos: anchor(a, args[:from]),
    }
  end
  self
end

#partObject



63
64
# File 'lib/jenncad/part.rb', line 63

def part
end

#to_openscadObject



51
52
53
54
55
56
57
58
59
60
61
# File 'lib/jenncad/part.rb', line 51

def to_openscad
  name = @name || @auto_name || self.class.to_s
  a = Aggregation.new(fix_name_for_openscad(name), self.get_contents)
  a.transformations = @transformations
  if self.has_explicit_color?
    a.color(self.color)
  else
    a.color(:auto)
  end
  a
end