Class: SolidRuby::CSGModifiers::CSGModifier

Inherits:
SolidRubyObject show all
Defined in:
lib/solidruby/csg_modifiers/csg_modifier.rb

Direct Known Subclasses

Color, LinearExtrude, Projection, RotateExtrude

Instance Attribute Summary

Attributes inherited from SolidRubyObject

#attributes, #children, #siblings, #transformations

Instance Method Summary collapse

Methods inherited from SolidRubyObject

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

Constructor Details

#initialize(object, attributes) ⇒ CSGModifier

Returns a new instance of CSGModifier.



18
19
20
21
22
23
# File 'lib/solidruby/csg_modifiers/csg_modifier.rb', line 18

def initialize(object, attributes)
  super(attributes)
  @transformations = []
  @children = [object]
  @attributes = attributes
end

Instance Method Details

#to_rubyscadObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/solidruby/csg_modifiers/csg_modifier.rb', line 25

def to_rubyscad
  att = @attributes
  if att.is_a? Hash
    att = @attributes.select {|k, v| !v.nil? }.collect do |k, v|
      sv = RubyScadBridge.new.format_value(v)
      "#{k} = #{sv}"
    end.sort_by{ |x| x[0] == 'f' ? ('z' + x) : x }
  end

  att = att.join(', ') if att.is_a? Array

  #	Apparently this doesn't work for CSGModifiers, like it does for other things in RubyScad?
  # also this is a dirty, dirty hack.
  att = att.gsub('fn', '$fn').gsub('$$', '$')
  ret = "#{@operation}(#{att}){"
  @children ||= []
  @children.each do |child|
    begin
      ret += child.walk_tree
    rescue NoMethodError
    end
  end
  ret += '}'
end