/***************************************************************************
 *                          Zanoza Modeler v2.x                            *
 *      This is unpublished propietary source code of Zanoza Software.     *
 *      The copyright notice does not evidence any actual or intended      *
 *                    publication of such source code.                     *
 *                                                                         *
 *                   Copyright (c) 2002 Zanoza Software.                   *
 *                                                                         *
 *                        All rights reserved.                             *
 ***************************************************************************
 *--------------------------------------------------------------------------
 * @author:   Oleg M.
 *--------------------------------------------------------------------------
 * @purpose:  ZModeler's native polygons
 *--------------------------------------------------------------------------
 * @histroy: 26.04.2003. reCreated
 */
#ifndef zpolygon_h_included
#define zpolygon_h_included

//------------------------------------------------------
//
//  ZPoly - ZModeler's native polygon.
//  
//------------------------------------------------------
class DLL_LINKAGE ZPoly : public ZEntityBase
{
public:
  //
  // constructors/destructors
  //
  ZPoly();
  virtual ~ZPoly();

public:
  //
  // typedefs
  //
  enum ePolyType
  {
    NONE  = 0,  //ZPolyBuf only
    MIXED = 1,  //ZPolyBuf only
    POLY  = 2,  //ZPolyBuf and ZPoly
    TRI   = 3,  //ZPolyBuf and ZPoly
    QUAD  = 4   //ZPolyBuf and ZPoly
  };


public:
  //
  // type and size:
  //
  virtual ePolyType type() const;
  virtual bool type(const ePolyType t) const;
  virtual DWORD size() const {return sizeof(ZPoly);} //in bytes

public:
  //
  // assignment operators
  //
  virtual ZPoly& operator = ( const ZPoly& poly);

public:
  //
  // compare operators
  //
  virtual bool operator == ( const ZPoly& poly) const;
  virtual bool operator != ( const ZPoly& poly) const;

public:
  //
  // accessors
  //
  virtual WORD& operator [] (const long _indx);
  virtual const WORD operator [] (const long _indx) const;

  //
  // operations
  //
  virtual short     verts();
  virtual short     tris();
  virtual ZRESULT   verts(const short v, const WORD* data=NULL);
  virtual ZVector&  normal();
  virtual bool      isUsed(const WORD iVert) const;
  virtual bool      isUsed(const tUShortSeq& verts) const;
  //-------------------------------------------------------
  // @name :      invalidate
  // notifies polygon that vertices have changed.
  //-------------------------------------------------------
  virtual void      invalidate();

  //-------------------------------------------------------
  // @name :      flip
  // flips visible side of the polygon
  //-------------------------------------------------------
  virtual void      flip();
  //-------------------------------------------------------
  // @name :   getTriangles
  // Provides triangulated polygon data. Triplet of longs
  // makes a single triangle [0,1,2] then [3,4,5] and so on.
  // @param const ZVertexBuf& vBuf         : [new] vertex buffer
  // @param tUShortSeq& triples              : ret-val arg
  //-------------------------------------------------------
  virtual ZRESULT   getTriangles(const ZVertexBuf& vBuf, tUShortSeq& triples);
  // provides exterior indices
  virtual ZRESULT   getExterior(tUShortSeq& verts);
  // Sets the exterior polygon sequence
  virtual ZRESULT   setExterior(tUShortSeq& verts);
  virtual ZRESULT   setExteriorLength(const long nLen);
  // provides an amount of 'holes' in polygon. holes are not
  // filled with tringlies unlike the rest of polygon.
  virtual long numHoles() const;
  // Provides i-th hole vertices sequence
  virtual ZRESULT getHole(const int i, tUShortSeq& verts) const;
  // sets i-th hole vertices sequence
  virtual ZRESULT setHole(const int i, tUShortSeq& verts);
  // Removes i-th hole
  virtual ZRESULT removeHole(const int i);
  // polygon material accessor:
  inline long& material() { return m_nMaterialIndex; }
  // provides polygon's centerpoint
  virtual ZPoint3D& getCenter() const;

private:
  //
  // data members
  //
  long      m_nMaterialIndex;//zero-based index of material to use.

  //
  // (the rest is hidden)
  //
};

// helper function. obtians default compatibility's polygon type
DLL_LINKAGE ZPoly::ePolyType getDefaultPolygonType();

#endif //zpolygon_h_included

