Skip to content

Commit

Permalink
Add ChannelMappingNodeActions
Browse files Browse the repository at this point in the history
  • Loading branch information
medengineer committed Dec 12, 2023
1 parent 62990d7 commit b96bc82
Show file tree
Hide file tree
Showing 4 changed files with 146 additions and 7 deletions.
2 changes: 2 additions & 0 deletions Plugins/ChannelMappingNode/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ include(../PluginRules.cmake)

#add sources, not including OpenEphysLib.cpp
add_sources(${PLUGIN_NAME}
ChannelMappingNodeActions.cpp
ChannelMappingNodeActions.h
ChannelMappingNode.cpp
ChannelMappingNode.h
ChannelMappingEditor.cpp
Expand Down
14 changes: 7 additions & 7 deletions Plugins/ChannelMappingNode/ChannelMappingEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include <stdio.h>

#include "ChannelMappingEditor.h"
#include "ChannelMappingNode.h"
#include <stdio.h>

#include "ChannelMappingNodeActions.h"

ChannelMappingEditor::ChannelMappingEditor(GenericProcessor* parentNode)
: GenericEditor(parentNode),
Expand Down Expand Up @@ -423,18 +424,17 @@ void ChannelMappingEditor::mouseUp(const MouseEvent& e)

electrodeButtons[lastHoverButton]->setVisible(true);

Array<int> order;
Array<int> newChannelOrder;

for (auto button : electrodeButtons)
{
order.add(button->getChannelNum() - 1);
newChannelOrder.add(button->getChannelNum() - 1);
}

ChannelMappingNode* processor = (ChannelMappingNode*)getProcessor();

processor->setChannelOrder(getCurrentStream(), order);
MapChannelsAction* action = new MapChannelsAction((ChannelMappingNode*)getProcessor(), getProcessor()->getDataStream(getCurrentStream()), newChannelOrder);

CoreServices::updateSignalChain(this);
CoreServices::getUndoManager()->beginNewTransaction();
CoreServices::getUndoManager()->perform((UndoableAction*)action);

/*int from, to;
if (lastHoverButton == initialDraggedButton)
Expand Down
93 changes: 93 additions & 0 deletions Plugins/ChannelMappingNode/ChannelMappingNodeActions.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/*
------------------------------------------------------------------
This file is part of the Open Ephys GUI
Copyright (C) 2023 Open Ephys
------------------------------------------------------------------
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include <stdio.h>

#include "ChannelMappingNodeActions.h"

MapChannelsAction::MapChannelsAction(ChannelMappingNode* processor,
DataStream* stream,
Array<int> newMap) :
OpenEphysAction("MapChannels"),
channelMapper(processor),
streamKey(stream->getKey()),
prevChannelOrder(processor->getChannelOrder(stream->getStreamId())),
nextChannelOrder(newMap)
{
settings = nullptr;
}

MapChannelsAction::~MapChannelsAction()
{
if (settings != nullptr)
delete settings;
}

bool MapChannelsAction::perform()
{
uint16 streamId = 0;
for (auto stream : channelMapper->getDataStreams())
{
if (stream->getKey() == streamKey)
{
streamId = stream->getStreamId();
break;
}
}
if (streamId == 0) return false;

channelMapper->setChannelOrder(streamId, nextChannelOrder);

channelMapper->registerUndoableAction(channelMapper->getNodeId(), this);

CoreServices::updateSignalChain(channelMapper);

return true;
}

bool MapChannelsAction::undo()
{
uint16 streamId = 0;
for (auto stream : channelMapper->getDataStreams())
{
if (stream->getKey() == streamKey)
{
streamId = stream->getStreamId();
break;
}
}
if (streamId == 0) return false;

channelMapper->setChannelOrder(streamId, prevChannelOrder);

channelMapper->registerUndoableAction(channelMapper->getNodeId(), this);

CoreServices::updateSignalChain(channelMapper);

return true;
}

void MapChannelsAction::restoreOwner(GenericProcessor* owner)
{
channelMapper = (ChannelMappingNode*)owner;
}
44 changes: 44 additions & 0 deletions Plugins/ChannelMappingNode/ChannelMappingNodeActions.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Define the actions available for the ChannelMappingNode plugin.

// =====================================================
#ifndef ChannelMappingNodeActions_h
#define ChannelMappingNodeActions_h

#include <ProcessorHeaders.h>

#include "ChannelMappingNode.h"
#include "ChannelMappingEditor.h"

class MapChannelsAction : public OpenEphysAction
{

public:

/** Constructor*/
MapChannelsAction(ChannelMappingNode* processor,
DataStream* stream,
Array<int> nextChannelOrder);

/** Destructor */
~MapChannelsAction();

void restoreOwner(GenericProcessor* processor) override;

/** Perform the action*/
bool perform();

/** Undo the action*/
bool undo();

XmlElement* settings;

private:

ChannelMappingNode* channelMapper;
String streamKey;
Array<int> prevChannelOrder;
Array<int> nextChannelOrder;

};

#endif /* ChannelMappingNodeActions_h */

0 comments on commit b96bc82

Please sign in to comment.