class EagleCAD::Sheet::Segment

Attributes

elements[R]
layers[R]

Public Class Methods

from_xml(element) click to toggle source
# File lib/eaglecad/sheet.rb, line 150
def self.from_xml(element)
    Segment.new.tap do |segment|
        element.elements.each do |element|
            case element.name
                when 'junction'
                    segment.elements.push Geometry.point_from(element)
                when 'label'
                    segment.push element.attributes['layer'], Label.from_xml(element)
                when 'pinref'
                    segment.elements.push PinReference.from_xml(element)
                when 'wire'
                    segment.push element.attributes['layer'], Geometry::Line.from_xml(element)
                else
                    raise StandardError, "Unrecognized Segment element '#{element.name}"
            end
        end
    end
end
new() click to toggle source
# File lib/eaglecad/sheet.rb, line 169
def initialize
    @elements = []
    @layers = {}
    @layers.default_proc = proc {|hash, key| hash[key] = []}
end

Public Instance Methods

push(layer_number, element) click to toggle source

Push a new element to the given layer number @param [Numeric] layer_number The layer to add the element to @param [Object] element The thing to push

# File lib/eaglecad/sheet.rb, line 178
def push(layer_number, element)
    layer = @layers[layer_number]
    layer.push element
end
to_xml() click to toggle source
# File lib/eaglecad/sheet.rb, line 183
def to_xml
    REXML::Element.new('segment').tap do |element|
        elements.each do |object|
            if object.is_a? Point
                element.add_element('junction', {'x' => object.x, 'y' => object.y})
            else
                element.add_element object.to_xml
            end
        end

        layers.each do |number, layer|
            layer.each {|obj| element.add_element(obj.to_xml, {'layer' => number}) }
        end
    end
end