Skip to content

Commit

Permalink
Update SpikeDetector undoable actions
Browse files Browse the repository at this point in the history
  • Loading branch information
medengineer committed Nov 17, 2023
1 parent 1e6fa1f commit f4cb231
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,7 @@ void SpikeDetectorTableModel::cellClicked(int rowNumber, int columnId, const Mou
void SpikeDetectorTableModel::deleteSelectedRows(int rowThatWasClicked)
{
SparseSet<int> selectedRows = table->getSelectedRows();
Array<int> indeces;

if (!acquisitionIsActive)
{
Expand All @@ -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();

Expand Down
18 changes: 14 additions & 4 deletions Plugins/BasicSpikeDisplay/SpikeDetector/SpikeDetector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<var> selectedChannels;
Expand Down Expand Up @@ -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);

Expand Down
3 changes: 2 additions & 1 deletion Plugins/BasicSpikeDisplay/SpikeDetector/SpikeDetector.h
Original file line number Diff line number Diff line change
Expand Up @@ -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*);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,11 @@ bool AddSpikeChannels::undo()

RemoveSpikeChannels::RemoveSpikeChannels(SpikeDetector* processor_,
DataStream* stream_,
Array<SpikeChannel*> spikeChannelsToRemove_) :
Array<SpikeChannel*> spikeChannelsToRemove_,
Array<int> indeces_) :
processor(processor_),
spikeChannelsToRemove(spikeChannelsToRemove_),
indeces(indeces_),
streamId(stream_->getStreamId())
{
settings = std::make_unique<XmlElement>("SPIKE_CHANNELS");
Expand Down Expand Up @@ -121,6 +123,7 @@ bool RemoveSpikeChannels::perform()

bool RemoveSpikeChannels::undo()
{
int idx = 0;
for (auto* spikeParamsXml : settings->getChildIterator())
{
String name = spikeParamsXml->getStringAttribute("name", "");
Expand All @@ -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);

Expand All @@ -155,6 +158,7 @@ bool RemoveSpikeChannels::undo()

spikeChannel->getParameter("waveform_type")->fromXml(spikeParamsXml);
}
idx++;
}
CoreServices::updateSignalChain(processor->getEditor());
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ class RemoveSpikeChannels : public UndoableAction
/** Constructor*/
RemoveSpikeChannels(SpikeDetector* processor,
DataStream* stream,
Array<SpikeChannel*> spikeChannelsToRemove);
Array<SpikeChannel*> spikeChannelsToRemove,
Array<int> indeces);

/** Destructor */
~RemoveSpikeChannels();
Expand All @@ -96,6 +97,7 @@ class RemoveSpikeChannels : public UndoableAction
uint16 streamId;
Array<SpikeChannel*> spikeChannelsToRemove;
Array<SpikeChannel*> removedSpikeChannels;
Array<int> indeces;

};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,14 @@ void SpikeDetectorEditor::addSpikeChannels(PopupConfigurationWindow* window, Spi
}


void SpikeDetectorEditor::removeSpikeChannels(PopupConfigurationWindow* window, Array<SpikeChannel*> spikeChannelsToRemove)
void SpikeDetectorEditor::removeSpikeChannels(PopupConfigurationWindow* window, Array<SpikeChannel*> spikeChannelsToRemove, Array<int> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class SpikeDetectorEditor : public GenericEditor,
void addSpikeChannels(PopupConfigurationWindow* window, SpikeChannel::Type type, int count, Array<int> startChannels = Array<int>());

/** Removes spike channels based on an array of pointers to SpikeChannel objects*/
void removeSpikeChannels(PopupConfigurationWindow* window, Array<SpikeChannel*> spikeChannelsToRemove);
void removeSpikeChannels(PopupConfigurationWindow* window, Array<SpikeChannel*> spikeChannelsToRemove, Array<int> indeces);

/** Called when stream is updated */
void selectedStreamHasChanged() override;
Expand Down

0 comments on commit f4cb231

Please sign in to comment.