class Disp3D::Node

Attributes

instance_id[R]
name[R]
parents[R]

Public Class Methods

new(name = nil) click to toggle source
# File lib/node/node.rb, line 27
def initialize(name = nil)
  Util3D.check_arg_type(Symbol, name, true)
  @parents = []
  @instance_id = gen_instance_id()
  @name = name
  NodeDB.add(self)
end

Public Instance Methods

ancestors() click to toggle source
# File lib/node/node.rb, line 46
def ancestors
  rtn_ancestors_ary = []
  return ancestors_inner(rtn_ancestors_ary)
end
post_draw() click to toggle source
# File lib/node/node.rb, line 42
def post_draw
  GL.PopMatrix()
end
pre_draw() click to toggle source
# File lib/node/node.rb, line 35
def pre_draw
  GL.PushMatrix()
  GL.Translate(pre_translate.x, pre_translate.y, pre_translate.z) if(@pre_translate)
  GL.MultMatrix(@rotate.to_array) if(@rotate)
  GL.Translate(post_translate.x, post_translate.y, post_translate.z) if(@post_translate)
end

Protected Instance Methods

ancestors_inner(rtn_ancestors_ary) click to toggle source
# File lib/node/node.rb, line 120
def ancestors_inner(rtn_ancestors_ary)
  parents.each do |parent|
    if(!rtn_ancestors_ary.include?(parent.instance_id))
      rtn_ancestors_ary.push(parent.instance_id)
      parent.ancestors_inner(rtn_ancestors_ary)
    end
  end
  return rtn_ancestors_ary
end
box_transform(box) click to toggle source
# File lib/node/node.rb, line 113
def box_transform(box)
  box = box.translate(@pre_translate) if(@pre_translate)
  box = box.rotate(@rotate) if(@rotate)
  box = box.translate(@post_translate) if(@post_translate)
  return box
end
create(hash) click to toggle source
# File lib/node/node.rb, line 52
def create(hash)
  Util3D.check_key_arg(hash, :type)
  geom_arg = hash[:geom]
  name_arg = hash[:name]
  clazz = eval "Node" + hash[:type].to_s
  # node leaf constractor need 2 args
  if( clazz < Disp3D::NodeLeaf )
    new_node = clazz.new(geom_arg, name_arg)
  elsif( clazz <= Disp3D::NodeCollection )
    new_node = clazz.new(name_arg)
  else
    raise
  end
  hash.delete(:geom)
  hash.delete(:type)
  hash.delete(:name)
  new_node.update(hash)
  return new_node
end
delete(node_name) click to toggle source
# File lib/node/node.rb, line 92
def delete(node_name)
  Util3D::check_arg_type(Symbol, node_name)
  node = NodeDB.find_by_name(node_name)

  if(node.kind_of?(Array))
    node.each do | node_ele |
     remove_from_parents(node_ele)
    end
  elsif(!node.nil?)
     remove_from_parents(node)
  end
  NodeDB.delete_by_name(node_name)
end
remove_from_parents(node) click to toggle source
# File lib/node/node.rb, line 106
def remove_from_parents(node)
  Util3D::check_arg_type(Node, node)
  node.parents.each do |parent|
    parent.remove_child_by_node(node)
  end
end
update(hash) click to toggle source

cannnot contains key :type and :name. they cannot be set

# File lib/node/node.rb, line 73
def update(hash)
  if(hash.include?(:name))
    node = NodeDB.find_by_name(hash[:name])
    hash.delete(:name)
    if(node.kind_of?(Array))
      node.each do |item|
        item.update(hash)
      end
    elsif(!node.nil?)
      node.update(hash)
    end
  elsif
    hash.each do | key, value |
      next if( key == :type or key ==:name) # cannot change name and type
      self.send( key.to_s+"=", value)
    end
  end
end

Private Instance Methods

gen_instance_id() click to toggle source
# File lib/node/node.rb, line 131
def gen_instance_id
  return GL.GenLists(1)
end