Class: EagleCAD::Drawing
- Inherits:
-
Object
- Object
- EagleCAD::Drawing
- Defined in:
- lib/eaglecad/drawing.rb
Instance Attribute Summary collapse
-
#altdistance ⇒ Object
Grid attributes.
-
#altunit ⇒ Object
Grid attributes.
-
#altunitdist ⇒ Object
Grid attributes.
-
#always_vector_font ⇒ Object
Settings attributes.
-
#board ⇒ Object
Returns the value of attribute board.
-
#display ⇒ Object
Grid attributes.
-
#distance ⇒ Object
Grid attributes.
-
#layers ⇒ Object
readonly
Returns the value of attribute layers.
-
#multiple ⇒ Object
Grid attributes.
-
#schematic ⇒ Object
Returns the value of attribute schematic.
-
#style ⇒ Object
Grid attributes.
-
#unit ⇒ Object
Grid attributes.
-
#unitdistance ⇒ Object
Grid attributes.
-
#vertical_text ⇒ Object
Settings attributes.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize ⇒ Drawing
constructor
A new instance of Drawing.
-
#to_xml ⇒ REXML::element
Generate XML for the Drawing element.
- #write(output) ⇒ Object
Constructor Details
#initialize ⇒ Drawing
Returns a new instance of Drawing.
66 67 68 69 70 71 72 73 |
# File 'lib/eaglecad/drawing.rb', line 66 def initialize() @layers = [] self.vertical_text = :up self.display = false self.multiple = 1 self.style = :lines end |
Instance Attribute Details
#altdistance ⇒ Object
Grid attributes
13 14 15 |
# File 'lib/eaglecad/drawing.rb', line 13 def altdistance @altdistance end |
#altunit ⇒ Object
Grid attributes
13 14 15 |
# File 'lib/eaglecad/drawing.rb', line 13 def altunit @altunit end |
#altunitdist ⇒ Object
Grid attributes
13 14 15 |
# File 'lib/eaglecad/drawing.rb', line 13 def altunitdist @altunitdist end |
#always_vector_font ⇒ Object
Settings attributes
16 17 18 |
# File 'lib/eaglecad/drawing.rb', line 16 def always_vector_font @always_vector_font end |
#board ⇒ Object
Returns the value of attribute board.
9 10 11 |
# File 'lib/eaglecad/drawing.rb', line 9 def board @board end |
#display ⇒ Object
Grid attributes
13 14 15 |
# File 'lib/eaglecad/drawing.rb', line 13 def display @display end |
#distance ⇒ Object
Grid attributes
13 14 15 |
# File 'lib/eaglecad/drawing.rb', line 13 def distance @distance end |
#layers ⇒ Object (readonly)
Returns the value of attribute layers.
10 11 12 |
# File 'lib/eaglecad/drawing.rb', line 10 def layers @layers end |
#multiple ⇒ Object
Grid attributes
13 14 15 |
# File 'lib/eaglecad/drawing.rb', line 13 def multiple @multiple end |
#schematic ⇒ Object
Returns the value of attribute schematic.
9 10 11 |
# File 'lib/eaglecad/drawing.rb', line 9 def schematic @schematic end |
#style ⇒ Object
Grid attributes
13 14 15 |
# File 'lib/eaglecad/drawing.rb', line 13 def style @style end |
#unit ⇒ Object
Grid attributes
13 14 15 |
# File 'lib/eaglecad/drawing.rb', line 13 def unit @unit end |
#unitdistance ⇒ Object
Grid attributes
13 14 15 |
# File 'lib/eaglecad/drawing.rb', line 13 def unitdistance @unitdistance end |
#vertical_text ⇒ Object
Settings attributes
16 17 18 |
# File 'lib/eaglecad/drawing.rb', line 16 def vertical_text @vertical_text end |
Class Method Details
.from_xml(element) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/eaglecad/drawing.rb', line 19 def self.from_xml(element) self.new.tap do |drawing| element.elements.each do |element| case element.name when 'board' raise StandardError, "Drawing files must contain only one Board element" if drawing.board drawing.board = Board.from_xml(element) when 'grid' element.attributes.each do |name, value| case name when 'altdistance' then drawing.altdistance = value.to_f when 'altunit' then drawing.altunit = value.to_sym when 'altunitdist' then drawing.altunitdist = value.to_sym when 'display' then drawing.display = ('no' != value) when 'distance' then drawing.distance = value.to_f when 'unit' then drawing.unit = value.to_sym when 'unitdist' then drawing.unitdistance = value.to_sym when 'multiple' then drawing.multiple = value.to_i when 'style' then drawing.style = value.to_sym end end when 'layers' element.elements.each {|element| drawing.layers.push Layer.from_xml(element) } when 'schematic' raise StandardError, "Drawing files must contain only one Schematic element" if drawing.schematic drawing.schematic = Schematic.from_xml(element) when 'settings' element.elements.each do |element| element.attributes.each do |name, value| case name when 'alwaysvectorfont' then drawing.always_vector_font = ('no' != value) when 'verticaltext' then drawing.vertical_text = value.to_sym end end end else raise StandardError, "Unrecognized Drawing element '#{element.name}'" end end end end |
Instance Method Details
#to_xml ⇒ REXML::element
Generate XML for the EagleCAD::Drawing element
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/eaglecad/drawing.rb', line 77 def to_xml drawing_element = REXML::Element.new 'drawing' settings = REXML::Element.new 'settings', drawing_element settings.add_element 'setting', {'alwaysvectorfont' => (always_vector_font ? 'yes' : 'no')} settings.add_element 'setting', {'verticaltext' => vertical_text} grid_element = REXML::Element.new 'grid', drawing_element grid_element.add_attributes({ 'altdistance' => altdistance, 'altunit' => altunit, 'altunitdist' => altunitdist, 'display' => (display ? 'yes' : 'no'), 'distance' => distance, 'multiple' => multiple, 'unit' => unit, 'unitdist' => unitdistance, 'style' => style, }) layers_element = REXML::Element.new 'layers', drawing_element layers.each {|layer| layers_element.add_element layer.to_xml } drawing_element.add_element(board.to_xml) if board drawing_element.add_element(schematic.to_xml) if schematic drawing_element end |
#write(output) ⇒ Object
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/eaglecad/drawing.rb', line 106 def write(output) document = REXML::Document.new('<?xml version="1.0" encoding="utf-8"?><!DOCTYPE eagle SYSTEM "eagle.dtd">') eagle = REXML::Element.new('eagle') eagle.add_attribute('version', '6.0') eagle.add_element to_xml document.add eagle output = File.open(output, 'w') if output.is_a? String # This is a hack to force REXML to output PCDATA text inline with the enclosing element. Eagle has problems with the extra newlines that REXML tends to add. formatter = REXML::Formatters::Pretty.new(0) formatter.compact = true formatter.write(document, output) output.close end |