/// 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_SFEDGECONTENT_H
#define X3DTK_MESH_SFEDGECONTENT_H

#include <vector>
#include <algorithm>

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 TemplateVertex;
template<class MData, class VData, class EData, class FData, bool RW> class SFTemplateVertex;
template<class MData, class VData, class EData, class FData, bool RW> class SFTemplateFace;
template<class MData, class VData, class EData, class FData, bool RW> class EntityMFTemplateFace;
template<class MData, class VData, class EData, class FData, bool RW> class SFTemplateDirectEdge;
template<class MData, class VData, class EData, class FData, bool RW> class SFTemplateIndirectEdge;

/*! \brief Template class declared in <b><X3DTK/MESH/scenegraph.h></b> 
 *  providing the shared content of an SFEdge structure.
 *
 * \ingroup MeshSceneGraph
 */

template<class MData, class VData, class EData, class FData, bool RW = true>
class SFTemplateEdgeContent
{
  friend class TemplateVertex<MData, VData, EData, FData, RW>;
  friend class SFTemplateEdge<MData, VData, EData, FData, RW>;
  friend class SFTemplateDirectEdge<MData, VData, EData, FData, RW>;
  friend class SFTemplateIndirectEdge<MData, VData, EData, FData, RW>;
public:
  typedef EntityMFTemplateFace<MData, VData, EData, FData, RW> MFFace;
 
  /// Gets the Vertex from.
  inline SFTemplateVertex<MData, VData, EData, FData, RW> *getFromVertex() const;
  /// Gets the Vertex to.
  inline SFTemplateVertex<MData, VData, EData, FData, RW> *getToVertex() const;
  /// Gets the 1-faces.
  inline const MFFace &get1Faces() const;
  /// Gets the 2-faces.
  inline const MFFace &get2Faces() const;
  /// Returns true if is a boundary.
  inline bool isBoundary() const;
  /// Returns true if is non-manifold.
  inline bool isNonManifold() const;
  /// Gets the data.
  inline EData &data();
  /// Gets the data.
  inline const EData &data() const;

private:
  SFTemplateVertex<MData, VData, EData, FData, RW> *const _from;
  SFTemplateVertex<MData, VData, EData, FData, RW> *const _to;
  MFFace _r1Faces;
  MFFace _r2Faces;
  EData _data;
  
  /// Constructor.
  SFTemplateEdgeContent(SFTemplateVertex<MData, VData, EData, FData, RW> * from, SFTemplateVertex<MData, VData, EData, FData, RW> *const to);
  /// Destructor.
  ~SFTemplateEdgeContent();
    
  /// Adds a 1-face.
  void add1Face(SFTemplateFace<MData, VData, EData, FData, RW> *face);
  /// Adds a 2-face.
  void add2Face(SFTemplateFace<MData, VData, EData, FData, RW> *face);
  
  /// Removes a 1-face.
  void remove1Face(SFTemplateFace<MData, VData, EData, FData, RW> *face);
  /// Removes a 2-face.
  void remove2Face(SFTemplateFace<MData, VData, EData, FData, RW> *face);
  
  /// Reverses the face, ie if face is a 1-face, it becomes a 2-face.
  void reverse(SFTemplateFace<MData, VData, EData, FData, RW> *face);
};

}
}

#include "MESH_SFEdgeContent.inl"

#endif
