Class: VORuby::STC::V1_10::Region::EllipseType

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

Overview

Ellipse shape: adds semi-minor axis and position angle to Circle

Direct Known Subclasses

Ellipse

Instance Attribute Summary collapse

Attributes inherited from CircleType

#center, #radius

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

Returns a new instance of EllipseType.



200
201
202
203
204
# File 'lib/voruby/stc/1.10/region.rb', line 200

def initialize(options={})
  raise_argument_required_error('minor radius') if !options.has_key?(:minor_radius)
  raise_argument_required_error('position angle') if !options.has_key?(:pos_angle)
  super(options)
end

Instance Attribute Details

#minor_radiusObject

Returns the value of attribute minor_radius.



196
197
198
# File 'lib/voruby/stc/1.10/region.rb', line 196

def minor_radius
  @minor_radius
end

#pos_angleObject

Returns the value of attribute pos_angle.



196
197
198
# File 'lib/voruby/stc/1.10/region.rb', line 196

def pos_angle
  @pos_angle
end

Class Method Details

.from_xml(xml) ⇒ Object



256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
# File 'lib/voruby/stc/1.10/region.rb', line 256

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),
    :pos_angle_unit => AngleUnit.new(root.attributes.get_attribute_ns(obj_ns.uri, 'pos_angle_unit').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),
    :minor_radius => Float(REXML::XPath.first(root, 'x:MinorRadius', {'x' => obj_ns.uri}).text),
    :pos_angle => Float(REXML::XPath.first(root, 'x:PosAngle', {'x' => obj_ns.uri}).text)
  }
  
  self.new(options)
end

.xml_typeObject



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

def self.xml_type; 'ellipseType' end

Instance Method Details

#==(s) ⇒ Object



227
228
229
230
231
232
# File 'lib/voruby/stc/1.10/region.rb', line 227

def ==(s)
  super(s) and
  self.minor_radius = s.minor_radius and
  self.pos_angle = s.pos_angle and
  self.pos_angle_unit = s.pos_angle_unit
end

#pos_angle_unitObject



223
224
225
# File 'lib/voruby/stc/1.10/region.rb', line 223

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

#pos_angle_unit=(u) ⇒ Object

Raises:

  • (ArgumentError)


218
219
220
221
# File 'lib/voruby/stc/1.10/region.rb', line 218

def pos_angle_unit=(u)
  raise ArgumentError, 'position angle unit required' if !u
  @pos_angle_unit = u.is_a?(AngleUnit) ? u : AngleUnit.new(u.to_s)
end

#to_sObject



252
253
254
# File 'lib/voruby/stc/1.10/region.rb', line 252

def to_s
  "ELLIPSE #{self.coord_system_id} #{self.center} #{self.radius} #{self.minor_radius} #{self.pos_angle}"
end

#to_xml(name = nil) ⇒ Object



234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
# File 'lib/voruby/stc/1.10/region.rb', line 234

def to_xml(name=nil)
  el = super(name)
  
  el.attributes["#{obj_ns.prefix}:pos_angle_unit"] = self.pos_angle_unit.to_s
  
  minor_radius = REXML::Element.new("#{obj_ns.prefix}:MinorRadius")
  minor_radius.text = self.minor_radius.to_s
  el.add_element(minor_radius)
  
  pos_angle = REXML::Element.new("#{obj_ns.prefix}:PosAngle")
  pos_angle.text = self.pos_angle.to_s
  el.add_element(pos_angle)
  
  collapse_namespaces(el)

  el
end