From 13f8705a1c637bd8932f3d799939a640be458999 Mon Sep 17 00:00:00 2001
From: jsiegle <jsiegle@mit.edu>
Date: Sun, 4 Aug 2013 16:54:17 -0400
Subject: [PATCH] SpikeDetector now saves and loads all settings

---
 .../Editors/SpikeDetectorEditor.cpp           |  7 +++
 .../Processors/Editors/SpikeDetectorEditor.h  |  2 +
 Source/Processors/SpikeDetector.cpp           | 50 +++++++++++--------
 .../Visualization/LfpDisplayCanvas.cpp        | 23 ++++++---
 .../Visualization/LfpDisplayCanvas.h          |  1 +
 5 files changed, 55 insertions(+), 28 deletions(-)

diff --git a/Source/Processors/Editors/SpikeDetectorEditor.cpp b/Source/Processors/Editors/SpikeDetectorEditor.cpp
index ff18041b1..a75a65fdf 100755
--- a/Source/Processors/Editors/SpikeDetectorEditor.cpp
+++ b/Source/Processors/Editors/SpikeDetectorEditor.cpp
@@ -479,6 +479,11 @@ void SpikeDetectorEditor::comboBoxChanged(ComboBox* comboBox)
     thresholdSlider->setActive(false);
 }
 
+void SpikeDetectorEditor::checkSettings()
+{
+    electrodeList->setSelectedItemIndex(0);
+}
+
 void SpikeDetectorEditor::drawElectrodeButtons(int ID)
 {
 
@@ -511,6 +516,8 @@ void SpikeDetectorEditor::drawElectrodeButtons(int ID)
         else
         {
             activeChannels.add(processor->getChannel(ID,i));
+
+            button->setToggleState(processor->isChannelActive(ID,i), false);
         }
 
         if (numChannels < 3)
diff --git a/Source/Processors/Editors/SpikeDetectorEditor.h b/Source/Processors/Editors/SpikeDetectorEditor.h
index 2bbf5d90f..706a25821 100755
--- a/Source/Processors/Editors/SpikeDetectorEditor.h
+++ b/Source/Processors/Editors/SpikeDetectorEditor.h
@@ -154,6 +154,8 @@ public:
 
     bool addElectrode(int nChans);
 
+    void checkSettings();
+
 private:
 
     void drawElectrodeButtons(int);
diff --git a/Source/Processors/SpikeDetector.cpp b/Source/Processors/SpikeDetector.cpp
index f333dd405..191d23e15 100755
--- a/Source/Processors/SpikeDetector.cpp
+++ b/Source/Processors/SpikeDetector.cpp
@@ -634,31 +634,37 @@ void SpikeDetector::loadCustomParametersFromXml()
             if (xmlNode->hasTagName("ELECTRODE"))
             {
 
-//                electrodeIndex++;
-//
-//                int channelsPerElectrode = xmlNode->getIntAttribute("numChannels");
-//
-//                SpikeDetectorEditor* sde = (SpikeDetectorEditor*) getEditor();
-//                sde->addElectrode(channelsPerElectrode);
-//
-//                setElectrodeName(electrodeIndex+1, xmlNode->getStringAttribute("name"));
-//
-//                int channelIndex = -1;
-//
-//                forEachXmlChildElement(*parametersAsXml, channelNode)
-//                {
-//                    if (channelNode->hasTagName("SUBCHANNEL"))
-//                    {
-//                        channelIndex++;
-//
-//                        setChannel(electrodeIndex, channelIndex, channelNode->getIntAttribute("ch"));
-//                        setChannelThreshold(electrodeIndex, channelIndex, channelNode->getDoubleAttribute("thresh"));
-//                        setChannelActive(electrodeIndex, channelIndex, channelNode->getBoolAttribute("isActive"));
-//                    }
-//                }
+                electrodeIndex++;
+
+                int channelsPerElectrode = xmlNode->getIntAttribute("numChannels");
+
+                SpikeDetectorEditor* sde = (SpikeDetectorEditor*) getEditor();
+                sde->addElectrode(channelsPerElectrode);
+
+                setElectrodeName(electrodeIndex+1, xmlNode->getStringAttribute("name"));
+
+                int channelIndex = -1;
+
+                forEachXmlChildElement(*xmlNode, channelNode)
+                {
+                    if (channelNode->hasTagName("SUBCHANNEL"))
+                    {
+                        channelIndex++;
+
+                        std::cout << "Subchannel " << channelIndex << std::endl;
+
+                        setChannel(electrodeIndex, channelIndex, channelNode->getIntAttribute("ch"));
+                        setChannelThreshold(electrodeIndex, channelIndex, channelNode->getDoubleAttribute("thresh"));
+                        setChannelActive(electrodeIndex, channelIndex, channelNode->getBoolAttribute("isActive"));
+                    }
+               }
+
 
             }
         }
     }
 
+    SpikeDetectorEditor* ed = (SpikeDetectorEditor*) getEditor();
+    ed->checkSettings();
+
 }
diff --git a/Source/Processors/Visualization/LfpDisplayCanvas.cpp b/Source/Processors/Visualization/LfpDisplayCanvas.cpp
index 42dc6e02a..db469dfbc 100755
--- a/Source/Processors/Visualization/LfpDisplayCanvas.cpp
+++ b/Source/Processors/Visualization/LfpDisplayCanvas.cpp
@@ -511,9 +511,9 @@ void LfpDisplayCanvas::loadVisualizerParameters(XmlElement* xml)
 
             	if (channelDisplayState.substring(i,i+1).equalsIgnoreCase("1"))
             	{
-            		lfpDisplay->setEnabledState(true, i);
+            		lfpDisplay->enableChannel(true, i);
             	} else {
-            		lfpDisplay->setEnabledState(false, i);
+            		lfpDisplay->enableChannel(false, i);
             	}
 
             	
@@ -891,6 +891,15 @@ bool LfpDisplay::getEventDisplayState(int ch)
     return eventDisplayEnabled[ch];
 }
 
+void LfpDisplay::enableChannel(bool state, int chan)
+{
+
+	if (chan < numChans)
+	{
+		channelInfo[chan]->setEnabledState(state);
+	}
+}
+
 void LfpDisplay::setEnabledState(bool state, int chan)
 {
 
@@ -898,7 +907,6 @@ void LfpDisplay::setEnabledState(bool state, int chan)
 	{
 
 		channels[chan]->setEnabledState(state);
-		channelInfo[chan]->setEnabledState(state);
 	}
 }
 
@@ -941,10 +949,13 @@ LfpChannelDisplay::~LfpChannelDisplay()
 void LfpChannelDisplay::setEnabledState(bool state)
 {
 
-
-	std::cout << "Setting channel " << name << " to " << state << std::endl;
+	if (state)
+		std::cout << "Setting channel " << name << " to true." << std::endl;
+	else
+		std::cout << "Setting channel " << name << " to false." << std::endl;
 
 	isEnabled = state;
+
 }
 
 void LfpChannelDisplay::paint(Graphics& g)
@@ -1191,7 +1202,7 @@ void LfpChannelDisplayInfo::buttonClicked(Button* button)
 
 void LfpChannelDisplayInfo::setEnabledState(bool state)
 {
-	enableButton->setToggleState(state, false);
+	enableButton->setToggleState(state, true);
 }
 
 void LfpChannelDisplayInfo::paint(Graphics& g)
diff --git a/Source/Processors/Visualization/LfpDisplayCanvas.h b/Source/Processors/Visualization/LfpDisplayCanvas.h
index 4c6426480..baee4957d 100755
--- a/Source/Processors/Visualization/LfpDisplayCanvas.h
+++ b/Source/Processors/Visualization/LfpDisplayCanvas.h
@@ -188,6 +188,7 @@ public:
 
     void setEnabledState(bool, int);
     bool getEnabledState(int);
+    void enableChannel(bool, int);
 
     Array<Colour> channelColours;
 
-- 
GitLab