Class: EagleCAD::Sheet::Segment

Inherits:
Object
  • Object
show all
Defined in:
lib/eaglecad/sheet.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSegment

Returns a new instance of Segment.



169
170
171
172
173
# File 'lib/eaglecad/sheet.rb', line 169

def initialize
    @elements = []
    @layers = {}
    @layers.default_proc = proc {|hash, key| hash[key] = []}
end

Instance Attribute Details

#elementsObject (readonly)

Returns the value of attribute elements.



148
149
150
# File 'lib/eaglecad/sheet.rb', line 148

def elements
  @elements
end

#layersObject (readonly)

Returns the value of attribute layers.



148
149
150
# File 'lib/eaglecad/sheet.rb', line 148

def layers
  @layers
end

Class Method Details

.from_xml(element) ⇒ Object



150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# 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

Instance Method Details

#push(layer_number, element) ⇒ Object

Push a new element to the given layer number

Parameters:

  • layer_number (Numeric)

    The layer to add the element to

  • element (Object)

    The thing to push



178
179
180
181
# File 'lib/eaglecad/sheet.rb', line 178

def push(layer_number, element)
    layer = @layers[layer_number]
    layer.push element
end

#to_xmlObject



183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
# 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