Class: SolidRuby::Assemblies::TSlot

Inherits:
Assembly show all
Defined in:
lib/solidruby/assemblies/tslot.rb

Direct Known Subclasses

TSlotMachining

Instance Attribute Summary collapse

Attributes inherited from Assembly

#hardware, #skip, #transformations, #x, #y, #z

Attributes inherited from SolidRubyObject

#attributes, #children, #siblings, #transformations

Instance Method Summary collapse

Methods inherited from Assembly

#*, #+, #-, #add_to_bom, #color, #colorize, get_skip, get_views, #part, #scad_output, #show_hardware, skip, #transform, view, #walk_tree

Methods inherited from SolidRubyObject

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

Constructor Details

#initialize(args = {}) ⇒ TSlot

Returns a new instance of TSlot.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/solidruby/assemblies/tslot.rb', line 22

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

  @args[:size] ||= 20
  @args[:length] ||= 100
  @args[:configuration] ||= 1
  @args[:gap] ||= 8.13
  @args[:thickness] ||= 2.55
  @args[:simple] ||= false
  @machining = SolidRubyObject.new
  @machining_string = ''

  super(args)
end

Instance Attribute Details

#argsObject

the code in this class is based on code by edef1c Ported to SolidRuby by Jennifer Glauche License: GPLv3



21
22
23
# File 'lib/solidruby/assemblies/tslot.rb', line 21

def args
  @args
end

Instance Method Details

#descriptionObject



44
45
46
# File 'lib/solidruby/assemblies/tslot.rb', line 44

def description
  "T-Slot #{@args[:size]}x#{@args[:size] * @args[:configuration]}, length #{@args[:length]}mm #{@machining_string}"
end

#hole(args = {}) ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/solidruby/assemblies/tslot.rb', line 70

def hole(args = {})
  diameter = args[:diameter] || 8
  position = args[:position] || 'front'
  side = args[:side] || 'x'

  if position.is_a? String
    case position
    when 'front'
      z = @args[:size] / 2
      @machining_string += "with #{diameter}mm hole on front "
    when 'back'
      z = @args[:length] - @args[:size] / 2
      @machining_string += "with #{diameter}mm hole on back "
    end
  else
    z = position
    @machining_string += "with #{diameter}mm hole on #{z}mm "
  end

  @args[:configuration].times do |c|
    cyl = cylinder(d: diameter, h: @args[:size])
    if side == 'x'
      @machining += cyl.rotate(x: -90).translate(x: @args[:size] / 2 + c * @args[:size], z: z)
    else
      @machining += cyl.rotate(y: 90).translate(y: @args[:size] / 2 + c * @args[:size], z: z)
    end
  end

  self
end

#holes(args = {}) ⇒ Object



63
64
65
66
67
68
# File 'lib/solidruby/assemblies/tslot.rb', line 63

def holes(args = {})
  args[:position] = 'front'
  res = hole(args)
  args[:position] = 'back'
  res.hole(args)
end

#length(length) ⇒ Object



48
49
50
51
# File 'lib/solidruby/assemblies/tslot.rb', line 48

def length(length)
  @args[:length] = length
  self
end

#multi_profileObject



132
133
134
135
136
137
138
139
# File 'lib/solidruby/assemblies/tslot.rb', line 132

def multi_profile
  res = single_profile
  (@args[:configuration] - 1).times do |c|
    c += 1
    res += single_profile.translate(y: c * @args[:size])
  end
    res
end

#outputObject Also known as: show



37
38
39
40
# File 'lib/solidruby/assemblies/tslot.rb', line 37

def output
  res = profile
  res - @machining
end

#profileObject



101
102
103
104
105
# File 'lib/solidruby/assemblies/tslot.rb', line 101

def profile
  BillOfMaterial.bom.add(description) unless args[:no_bom] == true
  return single_profile.color('Silver') if @args[:configuration] == 1
  multi_profile.color('Silver')
end

#single_profileObject



107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/solidruby/assemblies/tslot.rb', line 107

def single_profile
  if @args[:simple] == true
    cube([@args[:size], @args[:size], @args[:length]])
  else
    start = @args[:thickness].to_f / Math.sqrt(2)

    gap = @args[:gap].to_f
    thickness = @args[:thickness].to_f
    size = @args[:size]
    square_size = gap + thickness
    if square_size > 0
      profile = square(size: square_size, center: true)
    else
     profile = nil
    end

    (0..3).each do |d|
      profile += polygon(points: [[0, 0], [0, start], [size / 2 - thickness - start, size / 2 - thickness], [gap / 2, size / 2 - thickness], [gap / 2, size / 2], [size / 2, size / 2], [size / 2, gap / 2], [size / 2 - thickness, gap / 2], [size / 2 - thickness, size / 2 - thickness - start], [start, 0]]).rotate(z: d * 90)
    end
    profile -= circle(r: gap / 2, center: true)
    profile = profile.translate(x: size / 2, y: size / 2)
    profile.linear_extrude(height: @args[:length], convexity: 2)
  end
end

#thread(args = {}) ⇒ Object



53
54
55
56
57
# File 'lib/solidruby/assemblies/tslot.rb', line 53

def thread(args = {})
  position = args[:position] || 'front'
  @machining_string += "with thread on #{position} "
  self
end

#threadsObject



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

def threads
  thread.thread(position: 'back')
end