/// This file is part of the X3DToolKit library
/// Copyright (C) 2002-2004  Yannick Le Goc (legoc@imag.fr)

/// http://artis.imag.fr/Members/Yannick.Legoc/X3D/

/// This library is free software; you can redistribute it and/or
/// modify it under the terms of the GNU Lesser General Public
/// License as published by the Free Software Foundation; either
/// version 2.1 of the License, or (at your option) any later version.

/// This library is distributed in the hope that it will be useful,
/// but WITHOUT ANY WARRANTY; without even the implied warranty of
/// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
/// Lesser General Public License for more details.

/// You should have received a copy of the GNU Lesser General Public
/// License along with this library; if not, write to the Free Software
/// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#ifndef X3DTK_MESH_SFFACE_H
#define X3DTK_MESH_SFFACE_H

#include "MESH_SceneGraphTypes.h"
#include "MESH_BaseSFFace.h"

#include <vector>
#include <iostream>

namespace X3DTK {
namespace MESH {

template<class MData, class VData, class EData, class FData, bool RW> class TemplateMesh;
template<class MData, class VData, class EData, class FData, bool RW> class SFTemplateEdge;
template<class MData, class VData, class EData, class FData, bool RW> class EntityMFTemplateEdge;

/*! \brief Template class declared in <b><X3DTK/MESH/scenegraph.h></b> 
 *  providing a face structure for the Mesh class.
 *
 * \ingroup MeshSceneGraph
 */

template<class MData, class VData, class EData, class FData, bool RW>
class SFTemplateFace : public BaseSFFace
{
  friend class TemplateMesh<MData, VData, EData, FData, RW>;
public:
  typedef EntityMFTemplateEdge<MData, VData, EData, FData, RW> MFEdge;
  typedef EntityMFTemplateVertex<MData, VData, EData, FData, RW> MFVertex;
  
  /// Gets the edges of the face. The order is given b the order of definition of the face.
  inline const MFEdge &getEdges() const;
  /// Gets the vertices of the face. This method is not efficient, because SFTemplateFace
  /// has not a vertices attribute, meaning that the method cannot return a reference. So
  /// a copy constructor is called. Prefer getting the edges and getting the from vertex
  /// of each edge.
  MFVertex getVertices() const;
  /// Gets the data.
  inline FData &data();
  /// Gets the data.
  inline const FData &data() const;
  /// Reverses the face.
  void reverse();
  /// Returns the mesh of which belongs the face.
  inline TemplateMesh<MData, VData, EData, FData, RW> *getMesh() const {return _mesh;};
   
#ifdef TEMPLATE_SPECIALIZATION_SUPPORTED
  /// Gets the data F from FData which must be of type clist<tlist<T...> >.
  template<class F>  
  F &getData();
  /// Gets optionally the data F from FData which must be of type clist<tlist<T...> >.
  template<class F>  
  F &ogetData();
#endif
  
private:
  MFEdge _edges;
  FData _data;
  TemplateMesh<MData, VData, EData, FData, RW> *_mesh;
  
  /// Constructor.
  SFTemplateFace(unsigned int i);
  /// Destructor.
  ~SFTemplateFace();
  
  /// Adds an edge.
  void addEdge(SFTemplateEdge<MData, VData, EData, FData, RW> *edge);
};

/// operator<< overloaded for SFFace class.
template<class MData, class VData, class EData, class FData, bool RW>
std::ostream& operator<<(std::ostream& o, const SFTemplateFace<MData, VData, EData, FData, RW> &f);

}
}

#include "MESH_SFFace.inl"

#endif
