Class: EagleCAD::Geometry::Text

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(origin, layer, size, text, options = {}) ⇒ Text

Returns a new instance of Text.



197
198
199
200
201
202
203
204
205
206
207
208
# File 'lib/eaglecad/geometry.rb', line 197

def initialize(origin, layer, size, text, options={})
		@origin = origin
		@layer = layer
		@size = size
		@text = text

		@align = options['align'] || 'bottom-left'
		@distance = options['distance'] || 50
		@font = options['font'] || 'proportional'
		@ratio = options['ratio'] || 8
		@rotation = options['rot'] || 'R0'
end

Instance Attribute Details

#alignObject

Returns the value of attribute align.



185
186
187
# File 'lib/eaglecad/geometry.rb', line 185

def align
  @align
end

#distanceObject

Returns the value of attribute distance.



185
186
187
# File 'lib/eaglecad/geometry.rb', line 185

def distance
  @distance
end

#fontObject

Returns the value of attribute font.



185
186
187
# File 'lib/eaglecad/geometry.rb', line 185

def font
  @font
end

#layerObject

Returns the value of attribute layer.



185
186
187
# File 'lib/eaglecad/geometry.rb', line 185

def layer
  @layer
end

#originObject

Returns the value of attribute origin.



185
186
187
# File 'lib/eaglecad/geometry.rb', line 185

def origin
  @origin
end

#ratioObject

Returns the value of attribute ratio.



185
186
187
# File 'lib/eaglecad/geometry.rb', line 185

def ratio
  @ratio
end

#rotationObject

Returns the value of attribute rotation.



185
186
187
# File 'lib/eaglecad/geometry.rb', line 185

def rotation
  @rotation
end

#sizeObject

Returns the value of attribute size.



185
186
187
# File 'lib/eaglecad/geometry.rb', line 185

def size
  @size
end

#textObject

Returns the value of attribute text.



185
186
187
# File 'lib/eaglecad/geometry.rb', line 185

def text
  @text
end

Class Method Details

.from_xml(element) ⇒ Object



187
188
189
190
191
192
193
194
195
# File 'lib/eaglecad/geometry.rb', line 187

def self.from_xml(element)
		Geometry::Text.new(Geometry.point_from(element, 'x', 'y'), element.attributes['layer'], element.attributes['size'].to_f, element.text).tap do |object|
 object.align = element.attributes['align'] || object.align
 object.distance = element.attributes['distance'] || object.distance
 object.font = element.attributes['font'] || object.font
 object.ratio = element.attributes['ratio'] || object.ratio
 object.rotation = element.attributes['rot'] || object.rotation
		end
end

Instance Method Details

#to_xmlREXML::Element

Returns:

  • (REXML::Element)


211
212
213
214
215
216
217
218
219
220
221
# File 'lib/eaglecad/geometry.rb', line 211

def to_xml
		REXML::Element.new('text').tap do |element|
 element.add_attributes({'x' => Geometry.format(origin.x), 'y' => Geometry.format(origin.y), 'layer' => layer, 'size' => Geometry.format(size)})
 element.add_attribute('align', align)
 element.add_attribute('distance', distance)
 element.add_attribute('font', font)
 element.add_attribute('ratio', ratio)
 element.add_attribute('rot', rotation)
 element.text = text
		end
end