Class: EagleCAD::Sheet::Instance

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

#initialize(part, gate, origin) ⇒ Instance

Returns a new instance of Instance.



64
65
66
67
68
69
70
71
# File 'lib/eaglecad/sheet.rb', line 64

def initialize(part, gate, origin)
		@attributes = []
		@part = part
		@gate = gate
		@origin = origin
		@smashed = false
		@rotation = 'R0'
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



46
47
48
# File 'lib/eaglecad/sheet.rb', line 46

def attributes
  @attributes
end

#gateObject

Returns the value of attribute gate.



45
46
47
# File 'lib/eaglecad/sheet.rb', line 45

def gate
  @gate
end

#originObject

Returns the value of attribute origin.



45
46
47
# File 'lib/eaglecad/sheet.rb', line 45

def origin
  @origin
end

#partObject

Returns the value of attribute part.



45
46
47
# File 'lib/eaglecad/sheet.rb', line 45

def part
  @part
end

#rotationObject

Returns the value of attribute rotation.



45
46
47
# File 'lib/eaglecad/sheet.rb', line 45

def rotation
  @rotation
end

#smashedObject

Returns the value of attribute smashed.



45
46
47
# File 'lib/eaglecad/sheet.rb', line 45

def smashed
  @smashed
end

Class Method Details

.from_xml(element) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/eaglecad/sheet.rb', line 48

def self.from_xml(element)
		Instance.new(element.attributes['part'], element.attributes['gate'], Geometry.point_from(element)).tap do |instance|
 element.attributes.each do |name, value|
			case name
  when 'smashed'  then instance.smashed = ('no' != element.attributes['smashed'])
  when 'rot'	    then instance.rotation = element.attributes['rot']
  when 'part', 'gate', 'x', 'y'	# Ignore; already handled
  else
				raise StandardError, "Unrecognized Instance attribute '#{name}'"
			end
 end

 element.elements.each {|attribute| instance.attributes.push Attribute.from_xml(attribute) }
		end
end

Instance Method Details

#to_xmlObject



73
74
75
76
77
78
79
80
81
# File 'lib/eaglecad/sheet.rb', line 73

def to_xml
		REXML::Element.new('instance').tap do |element|
 element.add_attributes({'part' => part, 'gate' => gate, 'x' => origin.x, 'y' => origin.y})
 element.add_attribute('smashed', 'yes') if smashed
 element.add_attribute('rot', rotation)

 attributes.each {|attribute| element.add_element attribute.to_xml }
		end
end