Class: VORuby::STC::V1_10::Region::CircleType

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

Overview

Circle shape: center and radius

Direct Known Subclasses

Circle, EllipseType

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 = {}) ⇒ CircleType

Returns a new instance of CircleType.



117
118
119
120
121
# File 'lib/voruby/stc/1.10/region.rb', line 117

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

Instance Attribute Details

#centerObject

Returns the value of attribute center.



113
114
115
# File 'lib/voruby/stc/1.10/region.rb', line 113

def center
  @center
end

#radiusObject

Returns the value of attribute radius.



113
114
115
# File 'lib/voruby/stc/1.10/region.rb', line 113

def radius
  @radius
end

Class Method Details

.from_xml(xml) ⇒ Object



157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
# File 'lib/voruby/stc/1.10/region.rb', line 157

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')
  unit = root.attributes.get_attribute_ns(obj_ns.uri, 'unit')
  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),
    :unit => unit ? PosUnit.new(unit.value) : nil,
    :center => Double2.from_xml(REXML::XPath.first(root, 'x:Center', {'x' => obj_ns.uri})),
    :radius => Float(REXML::XPath.first(root, 'x:Radius', {'x' => obj_ns.uri}).text)
  }
  
  self.new(options)
end

.xml_typeObject



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

def self.xml_type; 'circleType' end

Instance Method Details

#==(s) ⇒ Object



135
136
137
138
139
# File 'lib/voruby/stc/1.10/region.rb', line 135

def ==(s)
  super(s) and
  self.center == s.center and
  self.radius == s.radius
end

#to_sObject



153
154
155
# File 'lib/voruby/stc/1.10/region.rb', line 153

def to_s
  "CIRCLE #{self.coord_system_id} #{self.center} #{self.radius}"
end

#to_xml(name = nil) ⇒ Object



141
142
143
144
145
146
147
148
149
150
151
# File 'lib/voruby/stc/1.10/region.rb', line 141

def to_xml(name=nil)
  el = super(name)
  
  el.add_element(self.center.to_xml("Center", obj_ns))
  radius = REXML::Element.new("#{obj_ns.prefix}:Radius")
  radius.text = self.radius.to_s
  el.add_element(radius)
  
  collapse_namespaces(el)
  el
end