#######################################################################
#
# $Id: Group.py,v 1.2 2008-02-07 05:45:25 lorenz Exp $
# 
# Copyright (C) 2004-2008 Petr Lorenz
# All rights reserved.
# 
# ##### BEGIN LICENSE BLOCK #####
#
# Version: MPL 1.1 / GPL 2.0 / LGPL 2.1
#
# The contents of this file are subject to the Mozilla Public License
# Version 1.1 (the "License"); you may not use this file except in
# compliance with the License. You may obtain a copy of the License at
# http://www.mozilla.org/MPL/
# 
# Software distributed under the License is distributed on an "AS IS"
# basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
# License for the specific language governing rights and limitations
# under the License.
# 
# The Original Code is Petr Lorenz emGine Graphical User Interface (GUI).
# 
# The Initial Developer of the Original Code is Petr Lorenz.
# Portions created by the Initial Developer are Copyright (C) 2004-2008.
# All Rights Reserved.
# 
# Alternatively, the contents of this file may be used under the terms of
# either the GNU General Public License Version 2 or later (the  "GPL"), or the
# GNU Lesser General Public License Version 2.1 or later (the "LGPL"), in which
# case the provisions of the GPL or the LGPL are applicable instead of those
# above.  If you wish to allow use of your version of this file only under the
# terms of either the GPL or the LGPL and not to allow others to use your
# version of this file under the MPL, indicate your decision by deleting the
# provisions above and replace them with the notice and other provisions
# required by the GPL or LGPL.  If you do not delete the provisions above, a
# recipient may use your version of this file under the terms of any one of the
# MPL License, the GPL or the LGPL.
#
# ##### END LICENSE BLOCK #####
#
#######################################################################
#
# $Log: Group.py,v $
# Revision 1.2  2008-02-07 05:45:25  lorenz
# * Fixed 'Simulation Boundary View' check problem
#   when closing a project.
#
# * Fixed Bounding Box problems when moving/editing a geometry.
#
# Revision 1.1.1.1  2008-01-28 06:15:35  lorenz
# Import emGine GUI v. 0.7.1
#
# Revision 1.3  2007-07-02 06:37:17  lorenz
# Clean up of old code.
#
# Revision 1.2  2007-06-14 06:31:51  lorenz
# Added emGine settings handling.
# Better handling of GUI state through GUIState class.
#
# Revision 1.1.1.1  2007-05-08 06:22:35  lorenz
# Initial Import
#
#######################################################################

# July 2006 - January 2008

# abstract class

from tlmObject import tlmObject

class Group(tlmObject):
  def __init__(self, type_ = "Group"):
    tlmObject.__init__(self, type_)
    self.group_list = list()

  def add(self, new_object):
    self.group_list.append(new_object)

  def get_list(self):
    return self.group_list

  def get_object_by_name(self, objname):
    for obj in self.group_list:
      if obj.name == objname:
        return obj
    return None

  def get_list_of_names(self):
    names = list()
    for obj in self.group_list:
      names.append(obj.name)
    return names

  def get_index_by_name(self, objname):
    obj = self.get_object_by_name(objname)
    if not obj:
      return None
    return self.group_list.index(obj)

  def replace_object(self, old_object, new_object):
    ind = self.group_list.index(old_object)
    self.group_list[ind] = new_object

  def get_info(self):
    info = "Group info:\n"
    info += " Number of objects: " + str(len(self.group_list)) + "\n"
    info += " group_list:\n" + str(self.group_list) + "\n"
    return info

