From f4cb231f3b17f9a1536f7a62b5eac0dab873a87c Mon Sep 17 00:00:00 2001 From: medengineer Date: Fri, 17 Nov 2023 11:37:30 -0800 Subject: [PATCH] Update SpikeDetector undoable actions --- .../SpikeDetector/PopupConfigurationWindow.cpp | 6 +++++- .../SpikeDetector/SpikeDetector.cpp | 18 ++++++++++++++---- .../SpikeDetector/SpikeDetector.h | 3 ++- .../SpikeDetector/SpikeDetectorActions.cpp | 8 ++++++-- .../SpikeDetector/SpikeDetectorActions.h | 4 +++- .../SpikeDetector/SpikeDetectorEditor.cpp | 4 ++-- .../SpikeDetector/SpikeDetectorEditor.h | 2 +- 7 files changed, 33 insertions(+), 12 deletions(-) diff --git a/Plugins/BasicSpikeDisplay/SpikeDetector/PopupConfigurationWindow.cpp b/Plugins/BasicSpikeDisplay/SpikeDetector/PopupConfigurationWindow.cpp index 48b1a36fd0..139e82602d 100644 --- a/Plugins/BasicSpikeDisplay/SpikeDetector/PopupConfigurationWindow.cpp +++ b/Plugins/BasicSpikeDisplay/SpikeDetector/PopupConfigurationWindow.cpp @@ -502,6 +502,7 @@ void SpikeDetectorTableModel::cellClicked(int rowNumber, int columnId, const Mou void SpikeDetectorTableModel::deleteSelectedRows(int rowThatWasClicked) { SparseSet selectedRows = table->getSelectedRows(); + Array indeces; if (!acquisitionIsActive) { @@ -510,10 +511,13 @@ void SpikeDetectorTableModel::deleteSelectedRows(int rowThatWasClicked) for (int i = 0; i < spikeChannels.size(); i++) { if (selectedRows.contains(i) || i == rowThatWasClicked) + { channelsToDelete.add(spikeChannels[i]); + indeces.add(i); + } } - editor->removeSpikeChannels(owner, channelsToDelete); + editor->removeSpikeChannels(owner, channelsToDelete, indeces); table->deselectAllRows(); diff --git a/Plugins/BasicSpikeDisplay/SpikeDetector/SpikeDetector.cpp b/Plugins/BasicSpikeDisplay/SpikeDetector/SpikeDetector.cpp index 23e6d8030c..1af4070455 100644 --- a/Plugins/BasicSpikeDisplay/SpikeDetector/SpikeDetector.cpp +++ b/Plugins/BasicSpikeDisplay/SpikeDetector/SpikeDetector.cpp @@ -393,7 +393,8 @@ String SpikeDetector::ensureUniqueName(String name, uint16 currentStream) SpikeChannel* SpikeDetector::addSpikeChannel (SpikeChannel::Type type, uint16 currentStream, int startChannel, - String name) + String name, + int index) { Array selectedChannels; @@ -487,10 +488,19 @@ SpikeChannel* SpikeDetector::addSpikeChannel (SpikeChannel::Type type, localChannels }; + + SpikeChannel* spikeChannel; - spikeChannels.add(new SpikeChannel(spikeChannelSettings)); - - SpikeChannel* spikeChannel = spikeChannels.getLast(); + if (index < 0) + { + spikeChannels.add(new SpikeChannel(spikeChannelSettings)); + spikeChannel = spikeChannels.getLast(); + } + else + { + spikeChannels.insert(index, new SpikeChannel(spikeChannelSettings)); + spikeChannel = spikeChannels[index]; + } spikeChannel->addProcessor(this); diff --git a/Plugins/BasicSpikeDisplay/SpikeDetector/SpikeDetector.h b/Plugins/BasicSpikeDisplay/SpikeDetector/SpikeDetector.h index c4c2cf4e58..87dae96200 100644 --- a/Plugins/BasicSpikeDisplay/SpikeDetector/SpikeDetector.h +++ b/Plugins/BasicSpikeDisplay/SpikeDetector/SpikeDetector.h @@ -229,7 +229,8 @@ class SpikeDetector : public GenericProcessor SpikeChannel* addSpikeChannel(SpikeChannel::Type type, uint16 currentStream, int startChannel = -1, - String name = ""); + String name = "", + int index = -1); /** Removes a spike channel, based on a SpikeChannel pointer. */ void removeSpikeChannel (SpikeChannel*); diff --git a/Plugins/BasicSpikeDisplay/SpikeDetector/SpikeDetectorActions.cpp b/Plugins/BasicSpikeDisplay/SpikeDetector/SpikeDetectorActions.cpp index 62d06d172a..15d3563bb6 100644 --- a/Plugins/BasicSpikeDisplay/SpikeDetector/SpikeDetectorActions.cpp +++ b/Plugins/BasicSpikeDisplay/SpikeDetector/SpikeDetectorActions.cpp @@ -68,9 +68,11 @@ bool AddSpikeChannels::undo() RemoveSpikeChannels::RemoveSpikeChannels(SpikeDetector* processor_, DataStream* stream_, - Array spikeChannelsToRemove_) : + Array spikeChannelsToRemove_, + Array indeces_) : processor(processor_), spikeChannelsToRemove(spikeChannelsToRemove_), + indeces(indeces_), streamId(stream_->getStreamId()) { settings = std::make_unique("SPIKE_CHANNELS"); @@ -121,6 +123,7 @@ bool RemoveSpikeChannels::perform() bool RemoveSpikeChannels::undo() { + int idx = 0; for (auto* spikeParamsXml : settings->getChildIterator()) { String name = spikeParamsXml->getStringAttribute("name", ""); @@ -137,7 +140,7 @@ bool RemoveSpikeChannels::undo() { uint16 streamId = processor->findSimilarStream(stream_source, stream_name, sample_rate, true); - SpikeChannel* spikeChannel = processor->addSpikeChannel(type, streamId, -1, name); + SpikeChannel* spikeChannel = processor->addSpikeChannel(type, streamId, -1, name, indeces[idx]); spikeChannel->getParameter("local_channels")->fromXml(spikeParamsXml); @@ -155,6 +158,7 @@ bool RemoveSpikeChannels::undo() spikeChannel->getParameter("waveform_type")->fromXml(spikeParamsXml); } + idx++; } CoreServices::updateSignalChain(processor->getEditor()); return true; diff --git a/Plugins/BasicSpikeDisplay/SpikeDetector/SpikeDetectorActions.h b/Plugins/BasicSpikeDisplay/SpikeDetector/SpikeDetectorActions.h index 829df4da46..c9cb344e97 100644 --- a/Plugins/BasicSpikeDisplay/SpikeDetector/SpikeDetectorActions.h +++ b/Plugins/BasicSpikeDisplay/SpikeDetector/SpikeDetectorActions.h @@ -77,7 +77,8 @@ class RemoveSpikeChannels : public UndoableAction /** Constructor*/ RemoveSpikeChannels(SpikeDetector* processor, DataStream* stream, - Array spikeChannelsToRemove); + Array spikeChannelsToRemove, + Array indeces); /** Destructor */ ~RemoveSpikeChannels(); @@ -96,6 +97,7 @@ class RemoveSpikeChannels : public UndoableAction uint16 streamId; Array spikeChannelsToRemove; Array removedSpikeChannels; + Array indeces; }; diff --git a/Plugins/BasicSpikeDisplay/SpikeDetector/SpikeDetectorEditor.cpp b/Plugins/BasicSpikeDisplay/SpikeDetector/SpikeDetectorEditor.cpp index 71fb37958d..e914cf9697 100644 --- a/Plugins/BasicSpikeDisplay/SpikeDetector/SpikeDetectorEditor.cpp +++ b/Plugins/BasicSpikeDisplay/SpikeDetector/SpikeDetectorEditor.cpp @@ -99,14 +99,14 @@ void SpikeDetectorEditor::addSpikeChannels(PopupConfigurationWindow* window, Spi } -void SpikeDetectorEditor::removeSpikeChannels(PopupConfigurationWindow* window, Array spikeChannelsToRemove) +void SpikeDetectorEditor::removeSpikeChannels(PopupConfigurationWindow* window, Array spikeChannelsToRemove, Array indeces) { SpikeDetector* processor = (SpikeDetector*)getProcessor(); DataStream* stream = processor->getDataStream(getCurrentStream()); - RemoveSpikeChannels* action = new RemoveSpikeChannels(processor, stream, spikeChannelsToRemove); + RemoveSpikeChannels* action = new RemoveSpikeChannels(processor, stream, spikeChannelsToRemove, indeces); CoreServices::getUndoManager()->beginNewTransaction(); CoreServices::getUndoManager()->perform(action); diff --git a/Plugins/BasicSpikeDisplay/SpikeDetector/SpikeDetectorEditor.h b/Plugins/BasicSpikeDisplay/SpikeDetector/SpikeDetectorEditor.h index fd6df26b66..19d69d1f96 100644 --- a/Plugins/BasicSpikeDisplay/SpikeDetector/SpikeDetectorEditor.h +++ b/Plugins/BasicSpikeDisplay/SpikeDetector/SpikeDetectorEditor.h @@ -60,7 +60,7 @@ class SpikeDetectorEditor : public GenericEditor, void addSpikeChannels(PopupConfigurationWindow* window, SpikeChannel::Type type, int count, Array startChannels = Array()); /** Removes spike channels based on an array of pointers to SpikeChannel objects*/ - void removeSpikeChannels(PopupConfigurationWindow* window, Array spikeChannelsToRemove); + void removeSpikeChannels(PopupConfigurationWindow* window, Array spikeChannelsToRemove, Array indeces); /** Called when stream is updated */ void selectedStreamHasChanged() override;