Class: VORuby::STC::V1_10::Coords::Velocity2D

Inherits:
Vector2Coordinate show all
Includes:
Velocity
Defined in:
lib/voruby/stc/1.10/coords.rb

Overview

2-D Velocity coordinate

Instance Attribute Summary

Attributes included from Velocity

#unit, #vel_time_unit

Attributes inherited from Vector2Coordinate

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

Attributes inherited from CoordinateType

#name

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Velocity

#==

Methods included from SerializableToXml

#element

Methods inherited from Vector2Coordinate

#==

Methods inherited from CoordinateType

#==

Constructor Details

#initialize(options = {}) ⇒ Velocity2D

Returns a new instance of Velocity2D.



1622
1623
1624
1625
1626
# File 'lib/voruby/stc/1.10/coords.rb', line 1622

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

Class Method Details

.from_xml(xml) ⇒ Object



1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
# File 'lib/voruby/stc/1.10/coords.rb', line 1648

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)
  vel_time_unit = root.attributes.get_attribute_ns(obj_ns.uri, 'vel_time_unit')
  options[:vel_time_unit] = VelTimeUnit.new(vel_time_unit.value)
  options[:value] = xml_to_obj(root, CValue2, true)
  options[:error] = xml_to_obj(root, CError2)
  options[:resolution] = xml_to_obj(root, CResolution2)
  options[:size] = xml_to_obj(root, CSize2)
  options[:pix_size] = xml_to_obj(root, CPixSize2)

  Velocity2D.new(options)
end

Instance Method Details

#to_xmlObject



1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
# File 'lib/voruby/stc/1.10/coords.rb', line 1628

def to_xml
  el = element()
  el.attributes["#{obj_ns.prefix}:unit"] = self.unit.to_s
  el.attributes["#{obj_ns.prefix}:vel_time_unit"] = self.vel_time_unit.to_s
  
  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