#ifndef GLOBAL_H
#define GLOBAL_H

#include <QObject>
#include <QList>
#include <QMutex>

namespace GlobalStatement
{
enum CellIndex
{
    Point = 0,

    //线性单元类型-----------------------------------------------
    Vertex,             //顶点(Vertex)
    PolyVertex,         //多点(PolyVertex)
    Line,               //线段(Line)
    PolyLine,           //多段线(PolyLine)
    Triangle,           //三角形(Triangle)
    TriangleStrip,      //三角带(TriangleStrip)
    Polygon,            //多边形(Polygon)
    Pixel,              //四边形1(Pixel)
    Quad,               //四边形2(Quad)
    Tetra,              //四面体(Tetra，它是一个三维的立体图形,具有四个面,且这四个面都是等边三角形)
    Voxel,              //正方体(Voxel)
    Hexahedron,         //六面体(Hexahedron)
    Wedge,              //楔形(Wedge)
    Pyramid,            //金字塔(Pyramid)
    PentagonalPrism,    //五角棱柱(PentagonalPrism)
    HexagonalPrism,     //六角棱柱(HexagonalPrism)

    //非线性单元类型-------------------------------------------
    QuadraticEdge,      //二次曲线段(Quadratic Edge)
    QuadraticTriangle,  //二次三角形(Quadratic Triangle)
    QuadraticQuad,      // 二次四边形(Quadratic Quad)
    QuadraticTetra,     // 二次四面体(Quadratic Tetra)
    QuadraticHexahedron,// 二次六面体(Quadratic Hexahedron)
    QuadraticWedge,     // 二次楔形(Quadratic Wedge)
    QuadraticPyramid    // 二次金字塔(Quadratic Pyramid)
};


QString cellIndexToStr(CellIndex idx);

CellIndex strToCellIndex(const QString& str);

QString cellIndexToExplain(CellIndex idx);
}




/**
* @brief 配置参数
**/
struct ConfigParam
{
    QString outputFile;
    QString cellIndexs;
    int cellNum;
    int shape;
    int xLength;
    int yLength;
    int zLength;
    bool groupCell;
    int weiDu = 1;
};

/**
* @brief 单例类
*  用来管理配置文件
**/
class Global
{
public:
    static Global *Instance();

    void setRootDirPath(const QString &path);
    QString rootDirPath();

    QString resourceDirPath();

    void setConfigParam(ConfigParam p);
    ConfigParam configParam();

protected:
    Global();

private:
    /**
     *@brief 检查资源目录或者文件是否存在
     **/
    void checkResource();

    QString configFilePath();

private:
    static Global *mInstance;
    static QMutex mMutex;

    QString mRootPath;

    ConfigParam mConfigParam;

    // GC类
    // 程序退出后，该类的析构函数释放单例内存
    class GC
    {
    public:
        ~GC()
        {
            if (mInstance != nullptr)
            {
                delete mInstance;
                mInstance = nullptr;
            }
        }
    };

    static GC gc;
};

#endif // GLOBAL_H
