Class: VORuby::STC::V1_10::Coords::Position3D

Inherits:
Vector3Coordinate show all
Includes:
Position
Defined in:
lib/voruby/stc/1.10/coords.rb

Instance Attribute Summary collapse

Attributes inherited from Vector3Coordinate

#error, #pix_size, #resolution, #size, #value

Attributes inherited from CoordinateType

#name

Class Method Summary collapse

Instance Method Summary collapse

Methods included from SerializableToXml

#element

Constructor Details

#initialize(options = {}) ⇒ Position3D

Returns a new instance of Position3D.



1492
1493
1494
1495
# File 'lib/voruby/stc/1.10/coords.rb', line 1492

def initialize(options={})
  raise_argument_required_error('unit') if !options.has_key?(:unit)
  super(options)
end

Instance Attribute Details

#unitObject

Returns the value of attribute unit.



1490
1491
1492
# File 'lib/voruby/stc/1.10/coords.rb', line 1490

def unit
  @unit
end

Class Method Details

.from_xml(xml) ⇒ Object



1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
# File 'lib/voruby/stc/1.10/coords.rb', line 1522

def self.from_xml(xml)
  root = element_from(xml)

  options = {
   :name => REXML::XPath.first(root, 'x:Name', {'x' => obj_ns.uri}).text
  }
  unit = root.attributes.get_attribute_ns(obj_ns.uri, 'unit')
  options[:unit] = PosUnit.new(unit.value) if unit
  options[:value] = xml_to_obj(root, CValue3, true)
  options[:error] = xml_to_obj(root, CError3)
  options[:resolution] = xml_to_obj(root, CResolution3)
  options[:size] = xml_to_obj(root, CSize3)
  options[:pix_size] = xml_to_obj(root, CPixSize3)

  Position3D.new(options)
end

Instance Method Details

#==(p) ⇒ Object



1539
1540
1541
1542
# File 'lib/voruby/stc/1.10/coords.rb', line 1539

def ==(p)
  super(p) and
  self.unit == p.unit
end

#to_xmlObject



1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
# File 'lib/voruby/stc/1.10/coords.rb', line 1503

def to_xml
  el = element()
  el.attributes["#{obj_ns.prefix}:unit"] = self.unit.to_s if self.unit
  
  name = REXML::Element.new("#{obj_ns.prefix}:Name")
  name.text = self.name

  el.add_element(name)
  el.add_element(self.value.to_xml) if self.value
  self.error.each { |e| el.add_element(e.to_xml) } if self.error
  self.resolution.each { |r| el.add_element(r.to_xml) } if self.resolution
  self.size.each { |s| el.add_element(s.to_xml) } if self.size
  self.pix_size.each { |p| el.add_element(p.to_xml) } if self.pix_size
  
  collapse_namespaces(el)
  
  el
end