/*
  ==============================================================================

  This is an automatically generated GUI class created by the Introjucer!

  Be careful when adding custom code to these files, as only the code within
  the "//[xyz]" and "//[/xyz]" sections will be retained when the file is loaded
  and re-saved.

  Created with Introjucer version: 3.1.0

  ------------------------------------------------------------------------------

  The Introjucer is part of the JUCE library - "Jules' Utility Class Extensions"
  Copyright 2004-13 by Raw Material Software Ltd.

  ==============================================================================
*/

#ifndef __JUCE_HEADER_9002020A4DD09B20__
#define __JUCE_HEADER_9002020A4DD09B20__

//[Headers]     -- You can add your own extra header files here --
#include <armadillo>
#include "JuceHeader.h"
#include "Stack.hpp"
#include "RbmComponent.hpp"
		
//[/Headers]



//==============================================================================
/**
                                                                    //[Comments]
    An auto-generated component, created by the Introjucer.

    Describe your class and how it works here!
                                                                    //[/Comments]
*/
class MainComponent
: public Component
, public Thread
, public LayerConstructor
, public Rbm::IListener
, public ButtonListener
, public SliderListener
, public LabelListener
, public ComboBoxListener
{
public:
    //==============================================================================
    MainComponent (const String prjname);
    ~MainComponent();

    //==============================================================================
    //[UserMethods]     -- You can add your own custom methods in this section.
    //[/UserMethods]

    void paint (Graphics& g);
    void resized();
    void buttonClicked (Button* buttonThatWasClicked);
    void sliderValueChanged (Slider* sliderThatWasMoved);
    void labelTextChanged (Label* labelThatHasChanged);
    void comboBoxChanged (ComboBox* comboBoxThatHasChanged);
    void mouseMove (const MouseEvent& e);
    void mouseEnter (const MouseEvent& e);
    void mouseExit (const MouseEvent& e);
    void mouseDown (const MouseEvent& e);
    void mouseDrag (const MouseEvent& e);
    void mouseUp (const MouseEvent& e);
    void mouseDoubleClick (const MouseEvent& e);
    void mouseWheelMove (const MouseEvent& e, const MouseWheelDetails& wheel);

	Layer* onConstruct(const std::string &name, size_t id, size_t numVisibleX, size_t numVisibleY, size_t numHidden)
	{
		RbmComponent *pComp = new RbmComponent(name, id, numVisibleX, numVisibleY, numHidden);
		addAndMakeVisible(pComp);
		return static_cast<Layer*>(pComp);
	}

	
private:
    //[UserVariables]   -- You can add your own custom variables in this section.
	static const size_t DBN_SIZE = 4;
	ScopedPointer<Stack> m_stack;
	RbmComponent *m_pLayer;
	int m_weightIndex;
	int m_trainingIndex;
	void save();
	const juce::String& getBaseDir();
	void run();
	String m_baseDir;
	TooltipWindow m_toolTipWindow;
	bool m_doStop;
	void clearTraining()
	{
		patterSlider->setRange(0, m_stack->numTraining()-1, 1);
	}

	void loadTraining()
	{
		m_stack->loadTraining();
		patterSlider->setRange(0, m_stack->numTraining()-1, 1);
	}

	void saveTraining()
	{
		m_stack->save();
	}

	void addTraining(const arma::mat &training)
	{
		m_stack->addTraining(training);
		patterSlider->setRange(0, m_stack->numTraining()-1, 1);
	}
	
	void removeTrainingAt(size_t index)
	{
		m_stack->delTraining(index);
		patterSlider->setRange(0, m_stack->numTraining()-1, 1);
	}

	void updateControls();
	bool onProgress(Rbm *pRbm, const Rbm::Status &status) override;
	
    //[/UserVariables]

    //==============================================================================
    ScopedPointer<TextButton> trainButton;
    ScopedPointer<TextButton> addButton;
    ScopedPointer<Slider> patterSlider;
    ScopedPointer<TextButton> ShakeButton;
    ScopedPointer<Slider> WeightsSlider;
    ScopedPointer<Label> numEpochslabel;
    ScopedPointer<Label> learningRateLabel;
    ScopedPointer<Label> numVisibleLabel;
    ScopedPointer<Label> numHiddenLabel;
    ScopedPointer<TextButton> createButton;
    ScopedPointer<Label> projectNameLabel;
    ScopedPointer<TextButton> loadButton;
    ScopedPointer<TextButton> saveButton;
    ScopedPointer<Label> numVisibleYLabel;
    ScopedPointer<TextButton> loadTrainingButton;
    ScopedPointer<TextButton> saveTrainingButton;
    ScopedPointer<TextButton> clearTrainingButton;
    ScopedPointer<TextButton> removeTrainingButton;
    ScopedPointer<Slider> numGibbsSlider;
    ScopedPointer<ToggleButton> rbmDoRaoBlackwellToggleButton;
    ScopedPointer<ToggleButton> rbmDoSampleVisibleToggleButton;
    ScopedPointer<Label> lambdaLabel;
    ScopedPointer<Label> sigmaLabel;
    ScopedPointer<ToggleButton> rbmUseVisibleGaussianToggleButton;
    ScopedPointer<ToggleButton> rbmDoSparseToggleButton;
    ScopedPointer<Label> sparsityLabel;
    ScopedPointer<Label> sigmaDecayLabel;
    ScopedPointer<Label> weightDecayLabel;
    ScopedPointer<Slider> m_progressBarSlider;
    ScopedPointer<Label> momentumLabel;
    ScopedPointer<Label> sparsityLearningRateLabel;
    ScopedPointer<Label> weightInitLabel;
    ScopedPointer<ToggleButton> rbmLearnVarianceButton;
    ScopedPointer<ToggleButton> rbmNormalizeDataToggleButton;
    ScopedPointer<ComboBox> m_rbmSelect;
    ScopedPointer<ToggleButton> rbmDoSampleBatch;
    ScopedPointer<Label> sizeMiniBatch;
    ScopedPointer<ToggleButton> rbmUseHiddenGaussianToggleButton;


    //==============================================================================
    JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MainComponent)
};

//[EndFile] You can add extra defines here...
//[/EndFile]

#endif   // __JUCE_HEADER_9002020A4DD09B20__
