#!/usr/bin/env python
# -*- coding: iso-8859-1 -*-
"""DOCS HERE.
"""

# Copyright (C) 2010
# $Id: scene_object.py 1916 2006-11-21 17:21:05Z  $
__version__ = "$Revision: 1916 $"[11:-2]

# numpy lib
import numpy as np

# FrustumTracer CORE Classes
from scene_element import *

# --------------------------------------------------------------------------------------------------

class SceneObject( SceneGeometryHandler ):
    """ ABSTRACT CLASS
    Base class for generic SceneObject (TrangleMesh, Source, BoundingBox etc).
    A SceneObject is a collection of SceneElements. """
    
    object_type = "Object_Type_Not_Defined"
    object_name = "no_name"

    object_normal = None
    object_center = None
    object_parent = None
    
    # MAIN list of elements
    element_list = None
    num_element  = None
    
    def __init__(self,  object_name):
        self.object_name  = object_name
        self.element_list = []
        self.num_element  = 0

    def __str__(self):
        return_string = '"%s", %s' % ( self.object_name, self.object_type )
        for i in range(self.num_element):
            return_string += "\n |-Element %d: %s" % ( i, self.element_list[i] )
        # return str
        return return_string

    def __repr__(self):
        repr_string  = '"%s", %s' % ( self.object_name, object.__repr__(self) )
        repr_string += "\n(type: %s, number of elements: %s)" % ( self.object_type, len(self.element_list) )
        # return repr
        return repr_string

    def __iter__(self):
        for element in self.element_list: yield element

    def iterelements(self):
        for element_index, element in enumerate(self.element_list):
            yield element_index, element.element_name, element
    
    def addElement(self, element):
        element.parent = self
        self.element_list.append(element)
        self.num_element = len(self.element_list)
        # return added element
        return self.element_list[-1]

    def getObjectNormal(self):
        if self.object_normal == None:
            # DO DEFAULT CALCULATION AND STORE IT IN SELF
            pass
        return self.object_normal

    def getObjectCenter(self):
        if self.object_center == None:
            # DO DEFAULT CALCULATION AND STORE IT IN SELF
            pass
        return self.object_center
        
    def renderToNodePaths(self):
        rendered_node_paths = []

        # Render all elements (invisible elements will return None)
        for element in self.element_list:
            node_path = element.renderToNodePath()
            if node_path: rendered_node_paths.append( node_path )
            
        return rendered_node_paths

# --------------------------------------------------------------------------------------------------
