//#####################################################################
// Copyright 2004, Eran Guendelman.
// This file is part of PhysBAM whose distribution is governed by the license contained in the accompanying file PHYSBAM_COPYRIGHT.txt.
//#####################################################################
// Class QT_TRIANGULATED_OBJECT
//##################################################################### 
#ifndef __QT_TRIANGULATED_OBJECT__
#define __QT_TRIANGULATED_OBJECT__

#include <Core/Geometry_Particles/GEOMETRY_PARTICLES.h>
#include <Core/Meshes/MESHES_FORWARD.h>
#include "QT_COMPONENT.h"
#include "QT_SPLIT_OBJECT.h"
#include <memory>

namespace PhysBAM
{
template<class OBJ> class QT_OBJECT;

template<class TV>
class QT_TRIANGULATED_OBJECT:public QT_SPLIT_OBJECT<TV,MESH_OBJECT<TV,2>>
{
public:
    typedef typename TV::SCALAR T;
    typedef MESH_OBJECT<TV,2> TYPE;
    typedef typename TYPE::MESH MESH;

    typedef MESH_OPTIONS<2> OPT;
    typedef QT_SPLIT_OBJECT<TV,MESH_OBJECT<TV,2>> BASE;
private:
    OPT opt,raw_opt[4];
    using typename BASE::FV;using BASE::Obj;using BASE::valid;
    using BASE::name;using BASE::action;

    int selected_vertex=-1;
    int selected_segment=-1;
    int selected_triangle=-1;
    static const QT_COMPONENT_OPTION options[];
    static const int num_options;
    typedef QT_TRIANGULATED_OBJECT SELF;

public:

    QT_TRIANGULATED_OBJECT(QT_WORLD& world,const std::string& name,const std::string& file);
    QT_TRIANGULATED_OBJECT(QT_WORLD& world,const std::string& name,const std::string& mesh_file,const std::string& part_file);
    QT_TRIANGULATED_OBJECT(QT_WORLD& world,const std::string& name,const std::shared_ptr<QT_OBJECT<TYPE>>& obj);

    virtual ~QT_TRIANGULATED_OBJECT();

    RANGE<FV> Bounding_Box() override;
    void Render(QT_RENDER_UTILS& ru) override;
    void Read() override;
    void Set_Selection(ARRAY_VIEW<int> selection) override;
    void Clear_Selection() override;
    FV Selection_Point() override;
    void Make_Dialog(QT_WINDOW& window) override;
    void Read_Option(std::istream& in,int level) override;
    void Set_Draw(bool draw) override;
    bool Draw() const override;
    void Save_Settings(std::ostream& out) override;
    void Clear_Settings() override;
};
}

#endif
