Class: SolidRuby::Assemblies::Pipe

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

Instance Attribute Summary collapse

Attributes inherited from Assembly

#hardware, #skip, #transformations, #z

Attributes inherited from SolidRubyObject

#attributes, #children, #siblings, #transformations

Instance Method Summary collapse

Methods inherited from Assembly

#*, #+, #-, #add_to_bom, #color, #colorize, #description, get_skip, get_views, #output, #part, #scad_output, #show, #show_hardware, skip, #threads, #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 = {}) ⇒ Pipe

Warning: sum_x and sum_y are both a quick hack at the moment They will ONLY work on bends if you do same thing in the other direction for example pipe.cw(20,30) pipe.ccw(20,30) This might be fixed in the future.



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/solidruby/assemblies/pipe.rb', line 26

def initialize(args = {})
  # parameters
  @diameter = args[:diameter] || 1
  @fn = args[:fn] || 64
  @bent_segments = args[:bent_segments] || 128
  @line_rotation = args[:line_rotation] || 0 # z rotation in case needed with fn values

  # variable initialization
  @pipe = nil
  @sum_x = 0
  @sum_y = 0
end

Instance Attribute Details

#bent_segmentsObject

Returns the value of attribute bent_segments.



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

def bent_segments
  @bent_segments
end

#pipeObject

Returns the value of attribute pipe.



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

def pipe
  @pipe
end

#sum_xObject

Returns the value of attribute sum_x.



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

def sum_x
  @sum_x
end

#sum_yObject

Returns the value of attribute sum_y.



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

def sum_y
  @sum_y
end

#xObject

Returns the value of attribute x.



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

def x
  @x
end

#yObject

Returns the value of attribute y.



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

def y
  @y
end

Instance Method Details

#apply_rotation(obj) ⇒ Object

This will be called on bent, so this library can work with rectangle pipes, if you overwrite this and let it rotate z by 90



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

def apply_rotation(obj)
  obj
end

#ccw(radius, angle, color = nil) ⇒ Object

go counter clockwise



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/solidruby/assemblies/pipe.rb', line 70

def ccw(radius, angle, color = nil)
  return false if angle > 360
  # since bent can only do up to 90°, splitting it up in chunks in order to grow it
  return ccw(radius, 90, color) + ccw(radius, angle - 90, color) if angle > 90

  if @pipe.nil?
    @pipe = bent_ccw(radius, angle)
    @pipe = @pipe.color(color) unless color.nil?
  else
    rotated_pipe = @pipe.rotate(z: angle)
    pipe_piece = bent_ccw(radius, angle)
    pipe_piece = pipe_piece.color(color) unless color.nil?
    @pipe = pipe_piece + rotated_pipe.translate(x: x, y: y + radius)
  end
end

#cw(radius, angle, color = nil) ⇒ Object

go clockwise



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/solidruby/assemblies/pipe.rb', line 53

def cw(radius, angle, color = nil)
  return false if angle > 360
  # since bent can only do up to 90°, splitting it up in chunks in order to grow it
  return cw(radius, 90, color) + cw(radius, angle - 90, color) if angle > 90

  if @pipe.nil?
    @pipe = bent_cw(radius, angle)
    @pipe = @pipe.color(color) unless color.nil?
  else
    rotated_pipe = @pipe.rotate(z: -angle)
    pipe_piece = bent_cw(radius, angle)
    pipe_piece = pipe_piece.color(color) unless color.nil?
    @pipe = pipe_piece + rotated_pipe.translate(x: x, y: y - radius)
  end
end

#inner_shapeObject



43
44
45
# File 'lib/solidruby/assemblies/pipe.rb', line 43

def inner_shape
  nil
end

#line(length, color = nil) ⇒ Object



86
87
88
89
90
91
92
93
# File 'lib/solidruby/assemblies/pipe.rb', line 86

def line(length, color = nil)
  @pipe = if @pipe.nil?
            create_line(length, color)
          else
            @pipe.translate(x: length) + create_line(length, color)
          end
  @sum_x += length
end

#shapeObject



39
40
41
# File 'lib/solidruby/assemblies/pipe.rb', line 39

def shape
  circle(d: @diameter, fn: @fn)
end