#######################################################################
#
# $Id: GeometryObjectPolygon.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: GeometryObjectPolygon.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
#
#######################################################################

# July 2007 - January 2008

from GeometryObject import GeometryObject

class GeometryObjectPolygon(GeometryObject):
  # Description: 2D polygon object
  #
  # points - connectivity list (points) of the polygon (3D points)
  # normal - normal of the polygon
  # orientation as default is with z normal
  #
  def __init__(self, name_, points_ = [], normal_ = [0,0,1], material_ = None):
    GeometryObject.__init__(self, name_, "GeometryObjectPolygon", material_)

    # TODO: check input for correct values
    #print points_
    self.points = points_
    self.normal = normal_

    # create bounding box
    p1 = [points_[0][0], points_[0][1], points_[0][2]]
    p2 = [points_[0][0], points_[0][1], points_[0][2]]
    for point in self.points:
      for ind in range(3):
	if point[ind] < p1[ind]:
	  p1[ind] = point[ind]
	if point[ind] > p2[ind]:
	  p2[ind] = point[ind]

    self.bbox = (p1, p2)

  def get_discretization_points(self):
    return self.points

###############################################
if __name__ == '__main__':
  print "Testing GeometryObjectPolygon Module..."

  polygon1 = GeometryObjectPolygon("Polygon1", [[0.0,0.0,0.0], [1.0,1.0,0.0], [1.0,-1.0,0.0]], [0.0,0.0,1.0])
  print "BBox:"
  print polygon1.bbox
  print "Discretization points:"
  print polygon1.get_discretization_points()
