From 12f08b38bc570991271eab9aff17816e6ff69fb8 Mon Sep 17 00:00:00 2001 From: Jens Ahrensfeld Date: Mon, 11 Nov 2019 17:42:29 +0000 Subject: [PATCH] - add enable button for up down pass abort git-svn-id: http://moon:8086/svn/software/trunk/projects/Rbm@655 b431acfa-c32f-4a4a-93f1-934dc6c82436 --- source/RbmComponent.cpp | 41 +++++++++++++++++++++++++++++++++-------- source/RbmComponent.hpp | 19 ++++++++++++++++--- 2 files changed, 49 insertions(+), 11 deletions(-) diff --git a/source/RbmComponent.cpp b/source/RbmComponent.cpp index 5af22ef..c1732c7 100644 --- a/source/RbmComponent.cpp +++ b/source/RbmComponent.cpp @@ -34,14 +34,18 @@ RbmComponent::RbmComponent (const std::string &name, size_t id, size_t numVisibl addAndMakeVisible (DrawTraining = new DrawComponent (numVisibleX, numVisibleY)); DrawTraining->setListener(this); - addAndMakeVisible (DrawReconstruction = new DrawComponent (numVisibleX, numVisibleY)); - - - addAndMakeVisible (DrawWeights = new DrawComponent (numVisibleX, numVisibleY, 0.5, 0.5)); addAndMakeVisible (DrawHidden = new DrawComponent (numHidden, 1)); DrawHidden->setListener(this); + + addAndMakeVisible (DrawReconstruction = new DrawComponent (numVisibleX, numVisibleY)); + addAndMakeVisible (DrawWeights = new DrawComponent (numVisibleX, numVisibleY, 0.5, 0.5)); + + addAndMakeVisible (m_toggleEnable = new ToggleButton ("Enable layer")); + m_toggleEnable->setTooltip (TRANS("Enable layer for up pass")); + m_toggleEnable->setButtonText (TRANS("Enable")); + m_toggleEnable->addListener (this); + redrawWeights(); -// redrawReconstruction(); setSize (430, 130); resized(); @@ -139,6 +143,7 @@ void RbmComponent::resized() DrawReconstruction->setBoundsRelative(110./430, 0, 100./430, 100./130); DrawWeights->setBoundsRelative (220./430, 0, 100./430, 100./130); DrawHidden->setBoundsRelative (0, 110./130, 430./430, 20./130); + m_toggleEnable->setBoundsRelative (330./430, 0, 80./430, 24./130); } void RbmComponent::mouseMove (const MouseEvent& e) @@ -203,6 +208,19 @@ void RbmComponent::onDraw(DrawComponent &obj) } } +void RbmComponent::buttonClicked(Button* buttonThatWasClicked) +{ + if (buttonThatWasClicked == m_toggleEnable) + { + bool state = isEnabled(); + if (next) + { + RbmComponent *pComp = static_cast (next); + pComp->enable(state); + } + } +} + void RbmComponent::redrawReconstruction(const arma::mat& v) { uint32_t i; @@ -228,9 +246,9 @@ void RbmComponent::upPass(const arma::mat& v) if (next) { RbmComponent *pComp = static_cast (next); - pComp->upPass(DrawHidden->getData()); + pComp->upPass(DrawHidden->getData()); + } } -} void RbmComponent::downPass(const arma::mat& h) { @@ -257,7 +275,14 @@ void RbmComponent::upDownPass(const arma::mat& v) if (next) { RbmComponent *pComp = static_cast (next); - pComp->upDownPass(DrawHidden->getData()); + if (pComp->isEnabled()) + { + pComp->upDownPass(DrawHidden->getData()); + } + else + { + return; + } } else if (prev) { diff --git a/source/RbmComponent.hpp b/source/RbmComponent.hpp index ead4826..87380e7 100644 --- a/source/RbmComponent.hpp +++ b/source/RbmComponent.hpp @@ -34,9 +34,10 @@ Describe your class and how it works here! //[/Comments] */ -class RbmComponent : public Component - , public Layer - , public DrawListener +class RbmComponent : public Component + , public Layer + , public DrawListener + , public ButtonListener { public: //============================================================================== @@ -76,8 +77,20 @@ private: //[UserVariables] -- You can add your own custom variables in this section. ScopedPointer DrawReconstruction; ScopedPointer DrawWeights; + ScopedPointer m_toggleEnable; + bool isEnabled() + { + return m_toggleEnable->getToggleState(); + } + + void enable(bool state) + { + m_toggleEnable->setToggleState(state, NotificationType::sendNotification); + } + size_t m_currWeightIndexToDraw; void onDraw(DrawComponent &obj) override; + void buttonClicked(Button* buttonThatWasClicked) override; //[/UserVariables] //==============================================================================