namespace X3DTK {
namespace MESH {

template<class MData, class VData, class EData, class FData, bool RW>
TemplateVerticesDrawerStateVariables<MData, VData, EData, FData, RW>::TemplateVerticesDrawerStateVariables()
: StateVariables(), _selectionMode(false)
{
}

template<class MData, class VData, class EData, class FData, bool RW>
void TemplateVerticesDrawerStateVariables<MData, VData, EData, FData, RW>::init()
{
  _matrixStack.push_front(SFMatrix34f::identity);
  _matrixVector.clear();
  _meshVector.clear();
}

template<class MData, class VData, class EData, class FData, bool RW>
void TemplateVerticesDrawerStateVariables<MData, VData, EData, FData, RW>::finish()
{
  _matrixStack.pop_front();
  if (_matrixStack.size() != 0)
  {
    cx3d << "TemplateVerticesDrawerStateVariables::finish: Non empty matrix stack at the end of TemplateVerticesDrawer traversal" << std::endl;
    _matrixStack.clear();
  }
}

template<class MData, class VData, class EData, class FData, bool RW>
void TemplateVerticesDrawerStateVariables<MData, VData, EData, FData, RW>::pushMatrix(const SFMatrix34f &transformation)
{
  _matrixStack.push_front(_matrixStack.front()*transformation);
}

template<class MData, class VData, class EData, class FData, bool RW>
void TemplateVerticesDrawerStateVariables<MData, VData, EData, FData, RW>::popMatrix()
{
  _matrixStack.pop_front();
}

template<class MData, class VData, class EData, class FData, bool RW>
int TemplateVerticesDrawerStateVariables<MData, VData, EData, FData, RW>::getCurrentMeshId()
{
  return _matrixVector.size() - 1;
}

template<class MData, class VData, class EData, class FData, bool RW>
void TemplateVerticesDrawerStateVariables<MData, VData, EData, FData, RW>::storeMesh(TemplateMesh<MData, VData, EData, FData, RW> *mesh)
{
  _matrixVector.push_back(_matrixStack.front());
  _meshVector.push_back(mesh);
}

template<class MData, class VData, class EData, class FData, bool RW>
TemplateMesh<MData, VData, EData, FData, RW> *TemplateVerticesDrawerStateVariables<MData, VData, EData, FData, RW>::getMesh(int i) const 
{
  return _meshVector[i];
}

template<class MData, class VData, class EData, class FData, bool RW>
const SFMatrix34f &TemplateVerticesDrawerStateVariables<MData, VData, EData, FData, RW>::getMatrix(int i) const 
{
  return _matrixVector[i];
}

template<class MData, class VData, class EData, class FData, bool RW>
void TemplateVerticesDrawerStateVariables<MData, VData, EData, FData, RW>::setSelectionMode(bool selectionMode) 
{
  _selectionMode = selectionMode;
}

template<class MData, class VData, class EData, class FData, bool RW>
bool TemplateVerticesDrawerStateVariables<MData, VData, EData, FData, RW>::getSelectionMode() const 
{
  return _selectionMode;
}
  
}
}
