/*
    C++ Mesh Generation Library
    Copyright (c) 2000echet <eric at bechet dot ca>

    This file is part of the C++ Mesh Generation Library.

    See the NOTICE & LICENSE files for conditions.
*/
#ifndef FM_gmshELEMENT_H
#define FM_gmshELEMENT_H


#include "MElement.h"
#include "MVertex.h"

#include "GModel.h"
#include <vector>
#include <algorithm>
#include <map>

using namespace std;

namespace FM
{
  class gmshNode;

  class gmshElement
  {
  public:
    gmshElement() :pgmsh ( ( MElement* ) 0 ) {}
    gmshElement ( MElement *e ) :pgmsh ( e ) {}
    virtual void GetNodes ( vector<gmshNode> &tab ) const ;
    virtual void GetNeighbors ( vector<gmshElement> &tab ) const;
    virtual void CommonNodes ( const gmshElement &other,vector<gmshNode> &tabcommon,vector<gmshNode> &tabother ) const ;
    virtual void CommonNodes ( const gmshElement &other,vector<gmshNode> &tabcommon,vector<gmshNode> &tabother,vector<gmshNode> &tabother2 ) const ;

    virtual void Print ( void )
    {
//      pgmsh->print();
    }

    virtual int GetDim() const
    {
      return pgmsh->getDim();
    }
    virtual bool operator < ( const gmshElement &other ) const
    {
      return ( ( void* ) ( pgmsh ) < ( void* ) ( other.pgmsh ) );
    }
    virtual bool operator == ( const gmshElement &other ) const
    {
      return ( ( void* ) ( pgmsh ) == ( void* ) ( other.pgmsh ) );
    }
    MElement * GetBase()
    {
      return pgmsh;
    }
  private:
    MElement *pgmsh;
  };

  class FMModel : public GModel
  {
  public:
    FMModel() {if (Ptr==NULL) Ptr=this;}
    ~FMModel() {if (Ptr==this) Ptr=NULL;}
    void buildAdj(int code);
    static FMModel* Ptr; // singleton
    std::vector<MElement*> Els;
    std::map<MVertex *,std::vector<MElement*> > v_to_ele;
    std::map<MElement *,std::vector<MElement*> > ele_to_ele;
  };
}
#endif //FM_ELEMENT_H
 
