52 #include <QTextStream>
61 using namespace UTILSLIB;
76 if(!path.contains(
".sel"))
83 if(!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
84 qDebug()<<
"Error opening selection file";
89 QTextStream in(&file);
92 QString line = in.readLine();
94 if(line.contains(
"%") ==
false && line.contains(
":") ==
true)
96 QStringList firstSplit = line.split(
":");
99 QString key = firstSplit.at(0);
101 QStringList secondSplit = firstSplit.at(1).split(
"|");
104 if(secondSplit.at(secondSplit.size()-1) ==
"")
105 secondSplit.removeLast();
108 selectionMap.insert(key, secondSplit);
122 if(path.find(
".sel") != std::string::npos)
126 selectionMap.clear();
128 std::ifstream inFile(path);
129 if(!inFile.is_open()){
130 qDebug()<<
"Error opening selection file";
136 while(std::getline(inFile, line)){
137 if(line.find(
'%') == std::string::npos && line.find(
':') != std::string::npos){
138 std::stringstream stream{line};
139 std::vector<std::string> firstSplit;
140 for (std::string element; std::getline(stream, line,
':');){
141 firstSplit.push_back(element);
143 std::string key = firstSplit.at(0);
145 std::vector<std::string> secondSplit;
146 for (std::string element; std::getline(stream, line,
'|');){
147 secondSplit.push_back(element);
149 if(secondSplit.back() ==
""){
150 secondSplit.pop_back();
152 selectionMap.insert({key, secondSplit});
164 if(!path.contains(
".mon"))
168 selectionMap.clear();
171 if(!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
172 qDebug()<<
"Error opening montage file";
177 QTextStream in(&file);
178 QString groupName = in.readLine();
179 QStringList channels;
182 QString line = in.readLine();
184 if(line.contains(
":") ==
true) {
185 QStringList secondSplit = line.split(
":");
186 QString key = secondSplit.at(0);
187 channels.append(key);
192 selectionMap.insert(groupName, channels);
204 if(path.find(
".mon") != std::string::npos)
208 selectionMap.clear();
210 std::ifstream inFile(path);
211 if(!inFile.is_open()){
212 qDebug()<<
"Error opening montage file";
215 std::vector<std::string> channels;
217 std::string groupName;
218 std::getline(inFile, groupName);
221 while(std::getline(inFile, line)){
222 if(line.find(
':') != std::string::npos){
223 std::stringstream stream{line};
224 std::vector<std::string> split;
225 for (std::string element; std::getline(stream, line,
':');){
226 split.push_back(std::move(element));
228 channels.push_back(split.at(0));
232 selectionMap.insert({groupName, channels});
242 if(!path.contains(
".sel"))
246 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)){
247 qDebug()<<
"Error opening sel file for writing";
252 QTextStream out(&file);
254 QMultiMap<QString, QStringList>::const_iterator i = selectionMap.constBegin();
255 while (i != selectionMap.constEnd()) {
256 out << i.key() <<
":";
258 for(
int u=0; u<i.value().size() ; u++)
259 out << i.value().at(u) <<
"|";
276 if(path.find(
".sel") == std::string::npos)
279 std::ofstream outFile(path);
280 if (outFile.is_open()){
281 qDebug()<<
"Error opening sel file for writing";
285 for(
auto& mapElement : selectionMap){
286 outFile << mapElement.first <<
":";
287 for(
auto& vectorElement : mapElement.second){
288 outFile << vectorElement <<
"|";
290 outFile <<
"\n" <<
"\n";
301 if(!path.contains(
".mon"))
304 for(
auto i = selectionMap.constBegin(); i != selectionMap.constEnd(); i++) {
305 QFileInfo fileInfo(path);
307 QString newPath = QString(
"%1/%2.mon").arg(fileInfo.absolutePath()).arg(i.key());
312 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)){
313 qDebug()<<
"Error opening mon file for writing";
318 QTextStream out(&file);
322 for(
int u=0; u<i.value().size() ; u++)
323 out << i.value().at(u) <<
" : " << i.value().at(u) <<
"\n";
336 if(path.find(
".mon") == std::string::npos)
339 for(
auto& mapElement : selectionMap){
341 std::string newPath{path.substr(0, path.find_last_of(
"/") + 1) + mapElement.first +
".mon"};
342 std::ofstream outFile(newPath);
343 if(!outFile.is_open()){
344 qDebug()<<
"Error opening mon file for writing";
348 outFile << mapElement.first <<
"\n";
349 for(
auto& vectorElement : mapElement.second){
350 outFile << vectorElement <<
" : " << vectorElement <<
"\n";