//#####################################################################
// 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_SLICE_MANAGER
//##################################################################### 
#ifndef __QT_SLICE_MANAGER__
#define __QT_SLICE_MANAGER__

#include <Core/Arrays/ARRAY.h>
#include "QT_COMPONENT.h"
#include "QT_SLICE.h"
namespace PhysBAM{

template<class T>
class QT_SLICE_MANAGER
{
public:
    QT_SLICE* slice;
    ARRAY<QT_COMPONENT*> objects;
private:
    QT_CALLBACK slice_has_changed_callback;
   
public:
    QT_SLICE_MANAGER()
        :slice(0)
    {
    }

    ~QT_SLICE_MANAGER()
    {
    }

    void Set_Slice_Has_Changed_Callback(QT_CALLBACK slice_has_changed_callback_input)
    {
        slice_has_changed_callback=slice_has_changed_callback_input;
    }
    
    void Add_Object(QT_COMPONENT* object)
    {
        objects.Append(object);
        object->Set_Slice(slice);
    }

    void Update_Objects()
    {
        for(int i=0;i<objects.m;i++) objects(i)->Slice_Has_Changed();
    }

    // Callbacks for convenience
    void Toggle_Slice_Mode() { slice->Toggle_Slice_Mode(); Update_Objects(); if(slice_has_changed_callback.func) slice_has_changed_callback.func();}
    void Toggle_Slice_Axis() { slice->Toggle_Slice_Axis(); Update_Objects(); if(slice_has_changed_callback.func) slice_has_changed_callback.func();}
    void Increment_Slice() { slice->Increment_Slice(); Update_Objects(); if(slice_has_changed_callback.func) slice_has_changed_callback.func();}
    void Decrement_Slice() { slice->Decrement_Slice(); Update_Objects(); if(slice_has_changed_callback.func) slice_has_changed_callback.func();}
};
}
#endif
