Class: EagleCAD::Board

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

Defined Under Namespace

Classes: ContactReference, Element, Signal, Via

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBoard

Returns a new instance of Board.



135
136
137
138
139
140
141
142
143
# File 'lib/eaglecad/board.rb', line 135

def initialize
    @attributes = []
    @classes = []
    @contact_references = []
    @elements = []
    @libraries = {}
    @passes = Hash.new {|hash, key| hash[key] = Hash.new }
    @plain = []
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



11
12
13
# File 'lib/eaglecad/board.rb', line 11

def attributes
  @attributes
end

#classesObject (readonly)

Returns the value of attribute classes.



11
12
13
# File 'lib/eaglecad/board.rb', line 11

def classes
  @classes
end

#descriptionObject

Returns the value of attribute description.



10
11
12
# File 'lib/eaglecad/board.rb', line 10

def description
  @description
end

#design_rulesObject

Returns the value of attribute design_rules.



10
11
12
# File 'lib/eaglecad/board.rb', line 10

def design_rules
  @design_rules
end

#elementsObject (readonly)

Returns the value of attribute elements.



11
12
13
# File 'lib/eaglecad/board.rb', line 11

def elements
  @elements
end

#librariesObject (readonly)

Returns the value of attribute libraries.



11
12
13
# File 'lib/eaglecad/board.rb', line 11

def libraries
  @libraries
end

#passesObject (readonly)

Returns the value of attribute passes.



11
12
13
# File 'lib/eaglecad/board.rb', line 11

def passes
  @passes
end

#plainObject (readonly)

Returns the value of attribute plain.



11
12
13
# File 'lib/eaglecad/board.rb', line 11

def plain
  @plain
end

Class Method Details

.from_xml(element) ⇒ Object



103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/eaglecad/board.rb', line 103

def self.from_xml(element)
    Board.new.tap do |board|
	element.elements.each do |element|
	    case element.name
		when 'attributes'
		    element.elements.each {|attribute| board.attributes.push Attribute.from_xml(attribute) }
		when 'autorouter'
		    element.elements.each do |pass_element|
			pass = board.passes[pass_element.attributes['name']]
			pass_element.elements.each {|parameter| pass[parameter.attributes['name']] = parameter.attributes['value'] }
		    end
		when 'classes'
		    element.elements.each {|clearance| board.classes.push Clearance.from_xml(clearance) }
		when 'description'
		    board.description = element.text
		when 'designrules'
		    board.design_rules = DesignRules.from_xml(element)
		when 'elements'
		    element.elements.each {|object| board.elements.push Element.from_xml(object) }
		when 'libraries'
		    element.elements.each {|library| board.libraries[library.attributes['name']] = Library.from_xml(library) }
		when 'plain'
		    element.elements.each {|object| board.plain.push Geometry.from_xml(object) }
		when 'signals'
		when 'variantdefs'
		else
		    raise StandardError, "Unrecognized Board element '#{element.name}'"
	    end
	end
    end
end

Instance Method Details

#to_xmlREXML::Element

Returns:

  • (REXML::Element)


146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
# File 'lib/eaglecad/board.rb', line 146

def to_xml
    REXML::Element.new('board').tap do |element|
	element.add_element('attributes').tap do |attribute_element|
	    attributes.each {|attribute| attribute_element.add_element attribute.to_xml }
	end

	element.add_element('description').text = description

	element.add_element('autorouter').tap do |autorouter_element|
	    passes.each do |name, pass|
		autorouter_element.add_element('pass', {'name' => name}).tap do |pass_element|
		    pass.each {|name, value| pass_element.add_element('param', {'name' => name, 'value' => value})}
		end
	    end
	end

	element.add_element('classes').tap do |classes_element|
	    classes.each do |clearance|
		classes_element.add_element clearance.to_xml
	    end
	end

	element.add_element(design_rules.to_xml) if design_rules

	element.add_element('elements').tap do |element_element|
	    elements.each {|object| element_element.add_element object.to_xml }
	end

	element.add_element('libraries').tap do |libraries_element|
	    libraries.each {|name, library| libraries_element.add_element library.to_xml }
	end

	element.add_element('plain').tap do |plain_element|
	    plain.each {|object| plain_element.add_element object.to_xml }
	end
    end
end