//#####################################################################
// Copyright 2020, Craig Schroeder.
// This file is part of PhysBAM whose distribution is governed by the license contained in the accompanying file PHYSBAM_COPYRIGHT.txt.
//#####################################################################
#ifndef __QT_GRID_COMPONENT__
#define __QT_GRID_COMPONENT__

#include "QT_COMPONENT.h"
#include <memory>

namespace PhysBAM{
template<class TV> class GRID;
template<int d> class QT_GRID;
struct GRID_COMPONENT_OPTIONS;

template<int d>
class QT_GRID_COMPONENT:public QT_COMPONENT
{
    typedef VECTOR<int,d> IV;
    typedef VECTOR<float,d> TV;
protected:
    std::shared_ptr<QT_GRID<TV::m>> ptr;
public:
    const GRID<TV>& grid;
    typename QT_GRID<TV::m>::T_ITER iter;

    QT_GRID_COMPONENT(QT_WORLD& world,const std::string& name,const std::string& grid_file);
    ~QT_GRID_COMPONENT();

    virtual void Print_Selection_Info(std::ostream& o,const IV& index,
        bool cell) const = 0;

    void Set_Selection(ARRAY_VIEW<int> selection) override;
    void Clear_Selection() override;
    FV Selection_Point() override;
    std::string Grid_Name() const;
    const auto& Get_Grid() const {return ptr;}

protected:
    RANGE<FV> Bounding_Box_Helper(const RANGE<IV>& indices) const;
};
}
#endif
