Skip to content
Snippets Groups Projects
Commit 1d4ff66e authored by Priyanjit Dey's avatar Priyanjit Dey
Browse files

New Class for converting string to range

parent 2228fbfa
No related branches found
No related tags found
No related merge requests found
......@@ -261,6 +261,7 @@
<ClCompile Include="..\..\Source\AccessClass.cpp" />
<ClCompile Include="..\..\Source\Network\PracticalSocket.cpp" />
<ClCompile Include="..\..\Source\Audio\AudioComponent.cpp" />
<ClCompile Include="..\..\Source\Processors\Editors\ListSliceParser.cpp" />
<ClCompile Include="..\..\Source\Processors\PlaceholderProcessor\PlaceholderProcessorEditor.cpp" />
<ClCompile Include="..\..\Source\Processors\PlaceholderProcessor\PlaceholderProcessor.cpp" />
<ClCompile Include="..\..\Source\Processors\Dsp\Bessel.cpp" />
......@@ -1464,6 +1465,7 @@
<ClInclude Include="..\..\Source\AccessClass.h" />
<ClInclude Include="..\..\Source\Network\PracticalSocket.h" />
<ClInclude Include="..\..\Source\Audio\AudioComponent.h" />
<ClInclude Include="..\..\Source\Processors\Editors\ListSliceParser.h" />
<ClInclude Include="..\..\Source\Processors\PlaceholderProcessor\PlaceholderProcessorEditor.h" />
<ClInclude Include="..\..\Source\Processors\PlaceholderProcessor\PlaceholderProcessor.h" />
<ClInclude Include="..\..\Source\Processors\Dsp\Bessel.h" />
......
......@@ -1785,6 +1785,9 @@
<ClCompile Include="..\..\JuceLibraryCode\modules\juce_video\juce_video.cpp">
<Filter>Juce Library Code</Filter>
</ClCompile>
<ClCompile Include="..\..\Source\Processors\Editors\ListSliceParser.cpp">
<Filter>open-ephys\Source\Processors\Editors</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\Source\CoreServices.h">
......@@ -3398,6 +3401,9 @@
<ClInclude Include="..\..\JuceLibraryCode\JuceHeader.h">
<Filter>Juce Library Code</Filter>
</ClInclude>
<ClInclude Include="..\..\Source\Processors\Editors\ListSliceParser.h">
<Filter>open-ephys\Source\Processors\Editors</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="..\..\Resources\Fonts\cpmono-black-serialized">
......
......@@ -22,6 +22,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "ChannelSelector.h"
#include "ListSliceParser.h"
#include <math.h>
#include "../../AccessClass.h"
......@@ -75,27 +76,21 @@ ChannelSelector::ChannelSelector(bool createButtons, Font& titleFont_) :
selectButtonParam = new EditorButton("+", titleFont);
selectButtonParam->addListener(this);
addAndMakeVisible(selectButtonParam);
deselectButtonParam = new EditorButton("-", titleFont);
deselectButtonParam->addListener(this);
addAndMakeVisible(deselectButtonParam);
selectButtonRecord = new EditorButton("+", titleFont);
selectButtonRecord->addListener(this);
addAndMakeVisible(selectButtonRecord);
deselectButtonRecord = new EditorButton("-", titleFont);
deselectButtonRecord->addListener(this);
addAndMakeVisible(deselectButtonRecord);
selectButtonAudio = new EditorButton("+", titleFont);
selectButtonAudio->addListener(this);
addAndMakeVisible(selectButtonAudio);
deselectButtonAudio = new EditorButton("-", titleFont);
deselectButtonAudio->addListener(this);
addAndMakeVisible(deselectButtonAudio);
channelSelectorRegion = new ChannelSelectorRegion(this);
//channelSelectorRegion->setBounds(0,20,0,getHeight()-35);
......@@ -103,12 +98,21 @@ ChannelSelector::ChannelSelector(bool createButtons, Font& titleFont_) :
channelSelectorRegion->toBack();
paramBox = new ChannelSelectorBox();
channelSelectorRegion->addAndMakeVisible(paramBox);
recordBox = new ChannelSelectorBox();
channelSelectorRegion->addAndMakeVisible(recordBox);
audioBox = new ChannelSelectorBox();
channelSelectorRegion->addAndMakeVisible(audioBox);
channelSelectorRegion->addAndMakeVisible(selectButtonParam);
channelSelectorRegion->addAndMakeVisible(deselectButtonParam);
channelSelectorRegion->addAndMakeVisible(selectButtonRecord);
channelSelectorRegion->addAndMakeVisible(deselectButtonRecord);
channelSelectorRegion->addAndMakeVisible(selectButtonAudio);
channelSelectorRegion->addAndMakeVisible(deselectButtonAudio);
numColumnsLessThan100 = 8;
numColumnsGreaterThan100 = 6;
}
ChannelSelector::~ChannelSelector()
......@@ -255,12 +259,9 @@ void ChannelSelector::refreshButtonBoundaries()
/*
definition of textbox
*/
paramBox->setBounds(px, py+20, 90, 20);
addAndMakeVisible(paramBox);
recordBox->setBounds(rx, ry+20, 90, 20);
addAndMakeVisible(recordBox);
audioBox->setBounds(ax, ay+20, 90, 20);
addAndMakeVisible(audioBox);
paramBox->setBounds(px, py, 90, 20);
recordBox->setBounds(rx, ry, 90, 20);
audioBox->setBounds(ax, ay, 90, 20);
/*
audio,record and param tabs
......@@ -272,14 +273,14 @@ void ChannelSelector::refreshButtonBoundaries()
/*
select and deselect button under each tab
*/
selectButtonParam->setBounds(px + 95, py + 20, 20, 20);
deselectButtonParam->setBounds(px + 117, py + 20, 20, 20);
selectButtonParam->setBounds(px + 95, py, 20, 20);
deselectButtonParam->setBounds(px + 117, py, 20, 20);
selectButtonRecord->setBounds(rx + 95, ry + 20, 20, 20);
deselectButtonRecord->setBounds(rx + 117, ry + 20, 20, 20);
selectButtonRecord->setBounds(rx + 95, ry, 20, 20);
deselectButtonRecord->setBounds(rx + 117, ry, 20, 20);
selectButtonAudio->setBounds(ax + 95, ay + 20, 20, 20);
deselectButtonAudio->setBounds(ax + 117, ay + 20, 20, 20);
selectButtonAudio->setBounds(ax + 95, ay, 20, 20);
deselectButtonAudio->setBounds(ax + 117, ay, 20, 20);
/*
All and None buttons
*/
......@@ -580,6 +581,7 @@ int ChannelSelector::getDesiredWidth()
void ChannelSelector::buttonClicked(Button* button)
{
//checkChannelSelectors();
ListSliceParser* sp = new ListSliceParser("");
if (button == paramsButton)
{
// make sure param buttons are visible
......@@ -683,9 +685,8 @@ void ChannelSelector::buttonClicked(Button* button)
{ // select channels in parameter tab
selectButtonParam->removeListener(this);
deselectButtonParam->removeListener(this);
std::vector<int> getBoxList;
int fa, lim, comd, i, j;
getBoxList = paramBox->getBoxInfo(parameterButtons.size());
std::vector<int> getBoxList = sp->parseStringIntoRange(paramBox->getText().toStdString(),parameterButtons.size());
if (getBoxList.size() < 3)
{
selectButtonParam->addListener(this);
......@@ -711,9 +712,8 @@ void ChannelSelector::buttonClicked(Button* button)
{ // select channels in record tab
selectButtonRecord->removeListener(this);
deselectButtonRecord->removeListener(this);
std::vector<int> getBoxList;
std::vector<int> getBoxList = sp->parseStringIntoRange(recordBox->getText().toStdString(), recordButtons.size());
int fa, lim, comd, i, j;
getBoxList = recordBox->getBoxInfo(recordButtons.size());
if (getBoxList.size() < 3)
{
selectButtonRecord->addListener(this);
......@@ -739,9 +739,8 @@ void ChannelSelector::buttonClicked(Button* button)
{ // select channels in audio tab
selectButtonAudio->removeListener(this);
deselectButtonAudio->removeListener(this);
std::vector<int> getBoxList;
std::vector<int> getBoxList = sp->parseStringIntoRange(audioBox->getText().toStdString(), audioButtons.size());
int fa, lim, comd, i, j;
getBoxList = audioBox->getBoxInfo(audioButtons.size());
if (getBoxList.size() < 3)
{
selectButtonAudio->addListener(this);
......@@ -767,9 +766,8 @@ void ChannelSelector::buttonClicked(Button* button)
{ // deselect channels in param tab
selectButtonParam->removeListener(this);
deselectButtonParam->removeListener(this);
std::vector<int> getBoxList;
std::vector<int> getBoxList = sp->parseStringIntoRange(paramBox->getText().toStdString(), parameterButtons.size());
int fa, lim, comd, i, j;
getBoxList = paramBox->getBoxInfo(parameterButtons.size());
if (getBoxList.size() < 3)
{
selectButtonParam->addListener(this);
......@@ -795,9 +793,8 @@ void ChannelSelector::buttonClicked(Button* button)
{ // deselect channels in record tab
selectButtonRecord->removeListener(this);
deselectButtonRecord->removeListener(this);
std::vector<int> getBoxList;
std::vector<int> getBoxList = sp->parseStringIntoRange(recordBox->getText().toStdString(), recordButtons.size());
int fa, lim, comd, i, j;
getBoxList = recordBox->getBoxInfo(recordButtons.size());
if (getBoxList.size() < 3)
{
selectButtonRecord->addListener(this);
......@@ -823,9 +820,8 @@ void ChannelSelector::buttonClicked(Button* button)
{ // deselect channels in audio tab
selectButtonAudio->removeListener(this);
deselectButtonAudio->removeListener(this);
std::vector<int> getBoxList;
std::vector<int> getBoxList = sp->parseStringIntoRange(audioBox->getText().toStdString(), audioButtons.size());
int fa, lim, comd, i, j;
getBoxList = audioBox->getBoxInfo(audioButtons.size());
if (getBoxList.size() < 3)
{
selectButtonAudio->addListener(this);
......@@ -1229,164 +1225,4 @@ ChannelSelectorBox::ChannelSelectorBox()
ChannelSelectorBox::~ChannelSelectorBox()
{
}
/*
convert a string to integer.
*/
int ChannelSelectorBox::convertToInteger(std::string s)
{
char ar[20];
int i, j, k = 0;
for (i = 0; i < s.size(); i++)
{
if (s[i] >= 48 && s[i] <= 57)
{
ar[k] = s[i];
k++;
}
}
if (k>7)
{
return 1000000;
}
ar[k] = '\0';
k = atoi(ar);
return k;
}
/*
TextBox to take input. Valid formats:
1. [ : ] -> select/deselect all channels
2. [ a : b] -> select/deselect all channels from a to b.
3. [ a : c : b] -> select/deselect all channels from a to b such that the difference between in each consecutive selected channel is c.
*/
std::vector<int> ChannelSelectorBox::getBoxInfo(int len)
{
std::string s = ",";
s += getText().toStdString();
std::vector<int> finalList,separator,rangeseparator;
int i, j, a, b, k, openb, closeb, otherchar,x,y;
s += ",";
for (i = 0; i < s.size(); i++) //split string by ' , ' or ' ; '
{
if (s[i] == ';' || s[i] == ',')
{
separator.push_back(i);
}
}
for (i = 0; i < separator.size()-1; i++) // split ranges by ' : ' or ' - '
{
j = k = separator[i] + 1;
openb = closeb = otherchar = 0;
rangeseparator.clear();
for (; j < separator[i + 1]; j++)
{
if (s[j] == '-' || s[j] == ':')
{
rangeseparator.push_back(j);
}
else if (((int)s[j] == 32))
{
continue;
}
else if (s[j] == '[' || s[j] == '{' || s[j] == '(')
{
openb++;
}
else if (s[j] == ']' || s[j] == '}' || s[j] == ')')
{
closeb++;
}
else if ( (int)s[j] > 57 || (int)s[j] < 48)
{
otherchar++;
}
}
if (openb != closeb || openb > 1 || closeb > 1 || otherchar > 0) //Invalid input
{
continue;
}
for (x = separator[i] + 1; x < separator[i + 1]; x++) //trim whitespace and brackets from front
{
if (((int)s[x] >= 48 && (int)s[x] <= 57) || s[x] == ':' || s[x] == '-')
{
break;
}
}
for (y = separator[i + 1] - 1; y > separator[i]; y--) //trim whitespace and brackets from end
{
if (((int)s[y] >= 48 && (int)s[y] <= 57) || s[y] == ':' || s[y] == '-')
{
break;
}
}
if (x > y)
{
continue;
}
if (rangeseparator.size() == 0) //syntax of form - x or [x]
{
a = convertToInteger(s.substr(x, y - x + 1));
if (a == 0||a>len)
{
continue;
}
finalList.push_back(a - 1);
finalList.push_back(a - 1);
finalList.push_back(1);
}
else if (rangeseparator.size() == 1) // syntax of type - x-y or [x-y]
{
a = convertToInteger(s.substr(x, rangeseparator[0] - x + 1));
b = convertToInteger(s.substr(rangeseparator[0], y - rangeseparator[0] + 1));
if (a == 0)
{
a = 1;
}
if (b == 0)
{
b = len;
}
if (a > b || a > len || b > len)
{
continue;
}
finalList.push_back(a - 1);
finalList.push_back(b - 1);
finalList.push_back(1);
}
else if (rangeseparator.size() == 2) // syntax of type [x:y:z] or x-y-z
{
a = convertToInteger(s.substr(x, rangeseparator[0] - x + 1));
k = convertToInteger(s.substr(rangeseparator[0], rangeseparator[1] - rangeseparator[0] + 1));
b = convertToInteger(s.substr(rangeseparator[1], y - rangeseparator[1] + 1));
if (a == 0)
{
a = 1;
}
if (b == 0)
{
b = len;
}
if (k == 0)
{
k = 1;
}
if (a > b || a > len || b > len)
{
continue;
}
finalList.push_back(a - 1);
finalList.push_back(b - 1);
finalList.push_back(k);
}
}
return finalList;
}
\ No newline at end of file
......@@ -310,8 +310,5 @@ class ChannelSelectorBox :public TextEditor
public:
ChannelSelectorBox();
~ChannelSelectorBox();
std::vector<int> getBoxInfo(int len); // Extract Information from the box.
int convertToInteger(std::string s); // Conversion of string to integer.
};
#endif // __CHANNELSELECTOR_H_68124E35__
/*
------------------------------------------------------------------
This file is part of the Open Ephys GUI
Copyright (C) 2013 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 "ListSliceParser.h"
#include <vector>
ListSliceParser::ListSliceParser(std::string s)
{
defaultString = s;
}
ListSliceParser::~ListSliceParser()
{
}
int ListSliceParser::convertToInteger(std::string s)
{
char ar[20];
int i, j, k = 0;
for (i = 0; i < s.size(); i++)
{
if (s[i] >= 48 && s[i] <= 57)
{
ar[k] = s[i];
k++;
}
}
if (k>7)
{
return 1000000;
}
ar[k] = '\0';
k = atoi(ar);
return k;
}
std::vector<int> ListSliceParser::parseStringIntoRange(std::string textBoxInfo,int rangeValue)
{
std::string s = ",";
s += textBoxInfo;
std::vector<int> finalList, separator, rangeseparator;
int i, j, a, b, k, openb, closeb, otherchar, x, y;
s += ",";
for (i = 0; i < s.size(); i++) //split string by ' , ' or ' ; '
{
if (s[i] == ';' || s[i] == ',')
{
separator.push_back(i);
}
}
for (i = 0; i < separator.size() - 1; i++) // split ranges by ' : ' or ' - '
{
j = k = separator[i] + 1;
openb = closeb = otherchar = 0;
rangeseparator.clear();
for (; j < separator[i + 1]; j++)
{
if (s[j] == '-' || s[j] == ':')
{
rangeseparator.push_back(j);
}
else if (((int)s[j] == 32))
{
continue;
}
else if (s[j] == '[' || s[j] == '{' || s[j] == '(')
{
openb++;
}
else if (s[j] == ']' || s[j] == '}' || s[j] == ')')
{
closeb++;
}
else if ((int)s[j] > 57 || (int)s[j] < 48)
{
otherchar++;
}
}
if (openb != closeb || openb > 1 || closeb > 1 || otherchar > 0) //Invalid input
{
continue;
}
for (x = separator[i] + 1; x < separator[i + 1]; x++) //trim whitespace and brackets from front
{
if (((int)s[x] >= 48 && (int)s[x] <= 57) || s[x] == ':' || s[x] == '-')
{
break;
}
}
for (y = separator[i + 1] - 1; y > separator[i]; y--) //trim whitespace and brackets from end
{
if (((int)s[y] >= 48 && (int)s[y] <= 57) || s[y] == ':' || s[y] == '-')
{
break;
}
}
if (x > y)
{
continue;
}
if (rangeseparator.size() == 0) //syntax of form - x or [x]
{
a = convertToInteger(s.substr(x, y - x + 1));
if (a == 0 || a>rangeValue)
{
continue;
}
finalList.push_back(a - 1);
finalList.push_back(a - 1);
finalList.push_back(1);
}
else if (rangeseparator.size() == 1) // syntax of type - x-y or [x-y]
{
a = convertToInteger(s.substr(x, rangeseparator[0] - x + 1));
b = convertToInteger(s.substr(rangeseparator[0], y - rangeseparator[0] + 1));
if (a == 0)
{
a = 1;
}
if (b == 0)
{
b = rangeValue;
}
if (a > b || a > rangeValue || b > rangeValue)
{
continue;
}
finalList.push_back(a - 1);
finalList.push_back(b - 1);
finalList.push_back(1);
}
else if (rangeseparator.size() == 2) // syntax of type [x:y:z] or x-y-z
{
a = convertToInteger(s.substr(x, rangeseparator[0] - x + 1));
k = convertToInteger(s.substr(rangeseparator[0], rangeseparator[1] - rangeseparator[0] + 1));
b = convertToInteger(s.substr(rangeseparator[1], y - rangeseparator[1] + 1));
if (a == 0)
{
a = 1;
}
if (b == 0)
{
b = rangeValue;
}
if (k == 0)
{
k = 1;
}
if (a > b || a > rangeValue || b > rangeValue)
{
continue;
}
finalList.push_back(a - 1);
finalList.push_back(b - 1);
finalList.push_back(k);
}
}
return finalList;
}
\ No newline at end of file
/*
------------------------------------------------------------------
This file is part of the Open Ephys GUI
Copyright (C) 2013 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/>.
*/
#ifndef __LISTSPICEPARSER_H_
#define __LISTSPICEPARSER_H_
#include "../../../JuceLibraryCode/JuceHeader.h"
class ListSliceParser;
/*
ListSliceParser Class: Find out ranges from a string separated by ';' or ','.
The range can be of one of the following type:
1. [ : ] -> no start and end value. In this case start value is 1 and end value is index of last element
2. [ x : y ] -> range given. Start from index x and end at index y.
3. [ x : p : y] -> stride parameter p. start from x, select channels at intervals p upto y.
*/
class ListSliceParser
{
public:
ListSliceParser(std::string s);
~ListSliceParser();
std::vector<int> parseStringIntoRange(std::string textBoxInfo,int rangeValue);
private:
std::string defaultString;
int convertToInteger(std::string s); //Changes string to int. Make this public if you want to use it outside this class.
};
#endif //__LISTSPICEPARSER_H_
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment