From 3dabf22dd5b8f1cf380e5d321dc1eb91b4adbb34 Mon Sep 17 00:00:00 2001 From: medengineer Date: Mon, 6 Nov 2023 13:20:31 -0800 Subject: [PATCH] Update SpikeViewer saving/loading --- .../SpikeDisplayNode/SpikeDisplayCanvas.cpp | 88 +++++++++++-------- .../SpikeDisplayNode/SpikeDisplayCanvas.h | 3 + 2 files changed, 56 insertions(+), 35 deletions(-) diff --git a/Plugins/BasicSpikeDisplay/SpikeDisplayNode/SpikeDisplayCanvas.cpp b/Plugins/BasicSpikeDisplay/SpikeDisplayNode/SpikeDisplayCanvas.cpp index 70f46dda0..f18c42984 100644 --- a/Plugins/BasicSpikeDisplay/SpikeDisplayNode/SpikeDisplayCanvas.cpp +++ b/Plugins/BasicSpikeDisplay/SpikeDisplayNode/SpikeDisplayCanvas.cpp @@ -231,7 +231,17 @@ void SpikeDisplayCanvas::saveCustomParametersToXml(XmlElement* xml) XmlElement* plotNode = xmlNode->createNewChildElement("PLOT"); - plotNode->setAttribute("name", processor->getSpikeChannel(i)->getIdentifier()); + //plotNode->setAttribute("name", processor->getSpikeChannel(i)->getIdentifier()); + String identifier = processor->getSpikeChannel(i)->getIdentifier(); + + StringArray tokens; + tokens.addTokens(identifier, "|", "\""); + + plotNode->setAttribute("stream_source", tokens[0]); + plotNode->setAttribute("stream_name", tokens[1]); + plotNode->setAttribute("spike_source", tokens[2]); + plotNode->setAttribute("name", tokens[3]); + plotNode->setAttribute("isMonitored", spikeDisplay->getMonitorStateForPlot(i)); for (int j = 0; j < spikeDisplay->getNumChannelsForPlot(i); j++) @@ -248,53 +258,61 @@ void SpikeDisplayCanvas::saveCustomParametersToXml(XmlElement* xml) void SpikeDisplayCanvas::loadCustomParametersFromXml(XmlElement* xml) { - - - for (auto* xmlNode : xml->getChildIterator()) + for (auto* editorNode : xml->getChildIterator()) { - if (xmlNode->hasTagName("SPIKEDISPLAY")) + if (editorNode->hasTagName("CUSTOM_PARAMETERS")) { - int numPlots = xmlNode->getIntAttribute("NumPlots", 0); - int numSpikeChannels = processor->getTotalSpikeChannels(); - - if (!(numPlots && numPlots == numSpikeChannels)) + for (auto* xmlNode : editorNode->getChildIterator()) { - //SpikeDisplayNode has not loaded all spike channels from all incoming branches yet. - //Wait until the processor has loaded all channels before loading the saved settings. - return; + if (xmlNode->hasTagName("SPIKEDISPLAY")) + { + loadSpikeDisplaySettingsFromXml(xmlNode); + } } + } + } +} + +void SpikeDisplayCanvas::loadSpikeDisplaySettingsFromXml(XmlElement* xmlNode) +{ + int numPlots = xmlNode->getIntAttribute("NumPlots", 0); + int numSpikeChannels = processor->getTotalSpikeChannels(); + + if (!(numPlots && numPlots == numSpikeChannels)) + { + //SpikeDisplayNode has not loaded all spike channels from all incoming branches yet. + //Wait until the processor has loaded all channels before loading the saved settings. + return; + } - spikeDisplay->invertSpikes(xmlNode->getBoolAttribute("InvertSpikes")); - invertSpikesButton->setToggleState(xmlNode->getBoolAttribute("InvertSpikes"), dontSendNotification); - lockThresholdsButton->setToggleState(xmlNode->getBoolAttribute("LockThresholds"), sendNotification); + spikeDisplay->invertSpikes(xmlNode->getBoolAttribute("InvertSpikes")); + invertSpikesButton->setToggleState(xmlNode->getBoolAttribute("InvertSpikes"), dontSendNotification); + lockThresholdsButton->setToggleState(xmlNode->getBoolAttribute("LockThresholds"), sendNotification); - int plotIndex = -1; + int plotIndex = -1; - for (auto* plotNode : xmlNode->getChildIterator()) - { - if (plotNode->hasTagName("PLOT")) - { - plotIndex++; + for (auto* plotNode : xmlNode->getChildIterator()) + { + if (plotNode->hasTagName("PLOT")) + { + plotIndex++; - std::string cacheKey = processor->getSpikeChannel(plotIndex)->getIdentifier().toStdString(); + std::string cacheKey = processor->getSpikeChannel(plotIndex)->getIdentifier().toStdString(); - cache->setMonitor(cacheKey, plotNode->getBoolAttribute("isMonitored")); + cache->setMonitor(cacheKey, plotNode->getBoolAttribute("isMonitored")); - int channelIndex = -1; + int channelIndex = -1; - for (auto* channelNode : plotNode->getChildIterator()) - { - if (channelNode->hasTagName("AXIS")) - { - channelIndex++; - cache->setThreshold(cacheKey, channelIndex, channelNode->getDoubleAttribute("thresh")); - cache->setRange(cacheKey, channelIndex, channelNode->getDoubleAttribute("range")); - } - } + for (auto* channelNode : plotNode->getChildIterator()) + { + if (channelNode->hasTagName("AXIS")) + { + channelIndex++; + cache->setThreshold(cacheKey, channelIndex, channelNode->getDoubleAttribute("thresh")); + cache->setRange(cacheKey, channelIndex, channelNode->getDoubleAttribute("range")); } } } } - -} +} \ No newline at end of file diff --git a/Plugins/BasicSpikeDisplay/SpikeDisplayNode/SpikeDisplayCanvas.h b/Plugins/BasicSpikeDisplay/SpikeDisplayNode/SpikeDisplayCanvas.h index 9c35b4a9e..253a3c30d 100644 --- a/Plugins/BasicSpikeDisplay/SpikeDisplayNode/SpikeDisplayCanvas.h +++ b/Plugins/BasicSpikeDisplay/SpikeDisplayNode/SpikeDisplayCanvas.h @@ -178,6 +178,9 @@ class SpikeDisplayCanvas : public Visualizer, /** Loads display parameters */ void loadCustomParametersFromXml(XmlElement* xml); + /** Loads spike plot settings */ + void loadSpikeDisplaySettingsFromXml(XmlElement* xml); + /** Pointer to the underlying SpikeDisplayNode*/ SpikeDisplayNode* processor;