Class: VORuby::STC::V1_10::Region::SectorType

Inherits:
Shape show all
Defined in:
lib/voruby/stc/1.10/region.rb

Overview

A sector is the counter-clockwise area between two half-lines

Direct Known Subclasses

Sector

Instance Attribute Summary collapse

Attributes inherited from Shape

#coord_system_id, #unit

Attributes inherited from RegionType

#note

Class Method Summary collapse

Instance Method Summary collapse

Methods included from SerializableToXml

#element

Methods inherited from RegionType

#fill_factor, #fill_factor=

Constructor Details

#initialize(options) ⇒ SectorType

Returns a new instance of SectorType.



457
458
459
460
461
462
# File 'lib/voruby/stc/1.10/region.rb', line 457

def initialize(options)
  raise_argument_required_error('position') if !options.has_key?(:position)
  raise_argument_required_error('position angle 1') if !options.has_key?(:pos_angle1)
  raise_argument_required_error('position angle 2') if !options.has_key?(:pos_angle2)
  super(options)
end

Instance Attribute Details

#pos_angle1Object

Returns the value of attribute pos_angle1.



453
454
455
# File 'lib/voruby/stc/1.10/region.rb', line 453

def pos_angle1
  @pos_angle1
end

#pos_angle2Object

Returns the value of attribute pos_angle2.



453
454
455
# File 'lib/voruby/stc/1.10/region.rb', line 453

def pos_angle2
  @pos_angle2
end

#positionObject

Returns the value of attribute position.



453
454
455
# File 'lib/voruby/stc/1.10/region.rb', line 453

def position
  @position
end

Class Method Details

.from_xml(xml) ⇒ Object



525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
# File 'lib/voruby/stc/1.10/region.rb', line 525

def self.from_xml(xml)
  root = element_from(xml)
  
  fill_factor = root.attributes.get_attribute_ns(obj_ns.uri, 'fill_factor')
  note = root.attributes.get_attribute_ns(obj_ns.uri, 'note')
  options = {
    :fill_factor => fill_factor ? Float(fill_factor.value) : nil,
    :note => note ? note.value : nil,
    :coord_system_id => IdRef.new(root.attributes.get_attribute_ns(obj_ns.uri, 'coord_system_id').value),
    :position => Double2.from_xml(REXML::XPath.first(root, 'x:Position', {'x' => obj_ns.uri})),
    :pos_angle1 => Float(REXML::XPath.first(root, 'x:PosAngle1', {'x' => obj_ns.uri}).text),
    :pos_angle2 => Float(REXML::XPath.first(root, 'x:PosAngle2', {'x' => obj_ns.uri}).text)
  }
  
  unit = root.attributes.get_attribute_ns(obj_ns.uri, 'unit')
  options[:unit] = PosUnit.new(unit.value) if unit
  
  pos_angle_unit = root.attributes.get_attribute_ns(obj_ns.uri, 'pos_angle_unit')
  options[:pos_angle_unit] = PosUnit.new(pos_angle_unit.value) if pos_angle_unit
  
  self.new(options)
end

.xml_typeObject



455
# File 'lib/voruby/stc/1.10/region.rb', line 455

def self.xml_type; 'sectorType' end

Instance Method Details

#==(s) ⇒ Object



493
494
495
496
497
498
499
# File 'lib/voruby/stc/1.10/region.rb', line 493

def ==(s)
  super(s) and
  self.position == s.position and
  self.pos_angle1 == s.pos_angle1 and
  self.pos_angle2 == s.pos_angle2 and
  self.pos_angle_unit == s.pos_angle_unit
end

#pos_angle_unitObject



489
490
491
# File 'lib/voruby/stc/1.10/region.rb', line 489

def pos_angle_unit
  @pos_angle_unit || PosUnit.new('deg')
end

#pos_angle_unit=(u) ⇒ Object



484
485
486
487
# File 'lib/voruby/stc/1.10/region.rb', line 484

def pos_angle_unit=(u)
  raise_argument_required_error('position angle unit') if !u
  @pos_angle_unit = u.is_a?(PosUnit) ? u : PosUnit.new(u.to_s)
end

#to_sObject



521
522
523
# File 'lib/voruby/stc/1.10/region.rb', line 521

def to_s
  "SECTOR #{self.coord_system_id} #{self.position} #{self.pos_angle1} #{self.pos_angle2}"
end

#to_xml(name = nil) ⇒ Object



501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
# File 'lib/voruby/stc/1.10/region.rb', line 501

def to_xml(name=nil)
  el = super(name)
  
  el.attributes["#{obj_ns.prefix}:pos_angle_unit"] = self.pos_angle_unit.to_s
  
  el.add_element(self.position.to_xml('Position', obj_ns))
  
  pos_angle1 = REXML::Element.new("#{obj_ns.prefix}:PosAngle1")
  pos_angle1.text = self.pos_angle1.to_s
  el.add_element(pos_angle1)
  
  pos_angle2 = REXML::Element.new("#{obj_ns.prefix}:PosAngle2")
  pos_angle2.text = self.pos_angle2.to_s
  el.add_element(pos_angle2)
  
  collapse_namespaces(el)
  
  el
end