// File Import.h by az

#ifndef IMPORTFORMAT_H
#define IMPORTFORMAT_H

#include "RTMSimulator.h"
#include <list>
#include <vector>

class RTMSimulator;

/**
 * @brief Base class for all the import formats. Supplies functions that are used by all the import classes.
 */
class ImportFormat
{
protected:
    RTMSimulator* m_pSimulator;
protected:
    /**
     * @brief Adds a shape part, either a triangle or a quadrangle, depending on the amount of vertices.
     */
    void addShapePart(std::list<int>* connectionList)
    {
        if(connectionList->size() == 3)
        {
            //we have a triangle
            std::list<int>::const_iterator it = connectionList->begin();
            int node1 = *it;
            int node2 = *(++it);
            int node3 = *(++it);
            m_pSimulator->addTriangle(node1,node2,node3);
        }
        else if(connectionList->size() == 4)
        {
            //we have a quadrangle
            std::list<int>::const_iterator it = connectionList->begin();
            int node1 = *it;
            int node2 = *(++it);
            int node3 = *(++it);
            int node4 = *(++it);
            m_pSimulator->addQuadrangle(node1,node2,node3,node4);
        }
    }

    void makeDirectNeighbors(std::list<int>* neighbors)
    {
        for(std::list<int>::const_iterator ita = neighbors->begin(); ita != neighbors->end(); ita++)
        {
            for(std::list<int>::const_iterator itb = neighbors->begin(); itb != neighbors->end(); itb++)
            {
                if(*ita != *itb)
                {
                    m_pSimulator->setDirectNeighbor(*ita,*itb);
                    m_pSimulator->setDirectNeighbor(*itb,*ita);
                }
            }
        }
    }

    void addTetraeder(std::list<int>* points)
    {
        std::vector<int> v(points->begin(),points->end());
        if(v.size() >= 4)
        {
            m_pSimulator->addTriangle(v[0],v[1],v[2]);
            m_pSimulator->addTriangle(v[0],v[1],v[3]);
            m_pSimulator->addTriangle(v[0],v[3],v[2]);
            m_pSimulator->addTriangle(v[3],v[1],v[2]);
        }
    }

public:
    ImportFormat(RTMSimulator* pSimulator) : m_pSimulator(pSimulator) {}
};

#endif //IMPORT_H
