Skip to content

Commit

Permalink
Update SpikeViewer saving/loading
Browse files Browse the repository at this point in the history
  • Loading branch information
medengineer committed Nov 6, 2023
1 parent 84a7fa6 commit 3dabf22
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 35 deletions.
88 changes: 53 additions & 35 deletions Plugins/BasicSpikeDisplay/SpikeDisplayNode/SpikeDisplayCanvas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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++)
Expand All @@ -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"));
}
}
}
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 3dabf22

Please sign in to comment.