/// 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_VERTEX_H
#define X3DTK_MESH_VERTEX_H

#include "MESH_X3DVertexNode.h"
#include "MESH_SFVertex.h"
#include "MESH_SFDirectEdge.h"
#include "MESH_SFIndirectEdge.h"
#include "MESH_MeshData.h"

namespace X3DTK {
namespace MESH {

template<class MData, class VData, class EData, class FData, bool RW> class MeshMFTemplateVertex;
template<class MData, class VData, class EData, class FData, bool RW> class MeshMFTemplateEdge;
template<class MData, class VData, class EData, class FData, bool RW> class MeshMFTemplateFace;

/*! \brief Template class declared in <b><X3DTK/MESH/scenegraph.h></b> defining a vertex set,
 *  close to the implementation of X3D::Coordinate for the MESH scene graph.
 *
 *  \ingroup MeshSceneGraph
 */

template<class MData, class VData, class EData, class FData, bool RW>
class TemplateVertex : public X3DVertexNode
{
  friend class TemplateMesh<MData, VData, EData, FData, RW>;
public:
  typedef MeshMFTemplateVertex<MData, VData, EData, FData, RW> MFVertex;
  typedef MeshMFTemplateEdge<MData, VData, EData, FData, RW> MFEdge;
  typedef MeshMFTemplateFace<MData, VData, EData, FData, RW> MFFace;

  /// Constructor.
  TemplateVertex();
  /// Virtual destructor.
  virtual ~TemplateVertex();
    
  /// Creates a new vertex.
  SFTemplateVertex<MData, VData, EData, FData, RW> *createVertex();
  /// Creates a new vertex at the position i.
  SFTemplateVertex<MData, VData, EData, FData, RW> *createVertex(unsigned int i);

  /// Removes vertex.
  bool removeVertex(SFTemplateVertex<MData, VData, EData, FData, RW> *vertex);
  
  /// Get the edge from - to.
  static SFTemplateEdge<MData, VData, EData, FData, RW> *getEdge(SFTemplateVertex<MData, VData, EData, FData, RW> *from, SFTemplateVertex<MData, VData, EData, FData, RW> *to);
  /// Gets the vertices.
  inline const MFVertex &getVertices() const;
  /// Gets the edges.
  inline const MFEdge &getEdges() const;

private:
  MFVertex _vertices;
  MFEdge _edges; 
  
  /// Creates a new edge.
  SFTemplateEdge<MData, VData, EData, FData, RW> *createEdge(SFTemplateVertex<MData, VData, EData, FData, RW> *from, SFTemplateVertex<MData, VData, EData, FData, RW> *to);
  /// Removes the edge.
  void removeEdge(SFTemplateEdge<MData, VData, EData, FData, RW> *edge);

};  

/// Vertex for the default X3DNode nodes containing all the geometry and topology 
/// informations of an X3D scene.
typedef TemplateVertex<MeshData, VertexData, EdgeData, FaceData, true> Vertex;

}
}

#include "MESH_Vertex.inl"

#endif
