Skip to content
Snippets Groups Projects
Commit 01510deb authored by Felix de las Pozas's avatar Felix de las Pozas
Browse files

Merge branch 'load-groups-stackviz' into 'master'

Load groups stackviz

See merge request nsviz/visimpl!83
parents 564bdca1 d6978ed7
No related branches found
Tags 1.7.4
No related merge requests found
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
cmake_minimum_required( VERSION 3.1 FATAL_ERROR ) cmake_minimum_required( VERSION 3.1 FATAL_ERROR )
# visimpl project and version # visimpl project and version
project( visimpl VERSION 1.7.3 ) project( visimpl VERSION 1.7.4 )
set( visimpl_VERSION_ABI 6 ) set( visimpl_VERSION_ABI 6 )
SET( VISIMPL_LICENSE "GPL") SET( VISIMPL_LICENSE "GPL")
......
...@@ -50,6 +50,9 @@ ...@@ -50,6 +50,9 @@
#include <QShortcut> #include <QShortcut>
#include <QDateTime> #include <QDateTime>
#include <QtGlobal> #include <QtGlobal>
#include <QJsonArray>
#include <QJsonDocument>
#include <QJsonObject>
#include <boost/bind.hpp> #include <boost/bind.hpp>
...@@ -162,11 +165,15 @@ void MainWindow::init( const std::string &session ) ...@@ -162,11 +165,15 @@ void MainWindow::init( const std::string &session )
connect( _ui->actionOpenSubsetEventsFile, SIGNAL( triggered( void )), connect( _ui->actionOpenSubsetEventsFile, SIGNAL( triggered( void )),
this, SLOT( openSubsetEventsFileThroughDialog( void ))); this, SLOT( openSubsetEventsFileThroughDialog( void )));
connect( _ui->actionOpenGroupsFile, SIGNAL( triggered( void )),
this, SLOT( openGroupsThroughDialog( void )));
connect( _ui->actionCloseData, SIGNAL(triggered(bool)), connect( _ui->actionCloseData, SIGNAL(triggered(bool)),
this, SLOT(closeData())); this, SLOT(closeData()));
_ui->actionOpenSubsetEventsFile->setEnabled(false); _ui->actionOpenSubsetEventsFile->setEnabled(false);
_ui->actionOpenGroupsFile->setEnabled(false);
initPlaybackDock( ); initPlaybackDock( );
...@@ -1049,6 +1056,7 @@ void MainWindow::updateUIonOpen(const std::string &eventsFile) ...@@ -1049,6 +1056,7 @@ void MainWindow::updateUIonOpen(const std::string &eventsFile)
_ui->actionShowDataManager->setEnabled(true); _ui->actionShowDataManager->setEnabled(true);
_ui->actionOpenSubsetEventsFile->setEnabled(true); _ui->actionOpenSubsetEventsFile->setEnabled(true);
_ui->actionOpenGroupsFile->setEnabled(true);
_ui->actionCloseData->setEnabled(true); _ui->actionCloseData->setEnabled(true);
_dockSimulation->setEnabled(true); _dockSimulation->setEnabled(true);
...@@ -1459,3 +1467,112 @@ void stackviz::MainWindow::loadRESTData(const simil::LoaderRestData::Configurati ...@@ -1459,3 +1467,112 @@ void stackviz::MainWindow::loadRESTData(const simil::LoaderRestData::Configurati
m_loader->start( ); m_loader->start( );
} }
#endif #endif
void MainWindow::openGroupsThroughDialog()
{
const auto title = tr("Load Groups");
const QString groupsFilename = QFileDialog::getOpenFileName(this, title,
_lastOpenedGroupsFileName,
tr("Json files (*.json)"),
nullptr, QFileDialog::ReadOnly | QFileDialog::DontUseNativeDialog);
if (groupsFilename.isEmpty())
return;
QFile file{groupsFilename};
if (!file.open(QIODevice::ReadOnly))
{
const auto message = tr("Couldn't open file %1").arg(groupsFilename);
QMessageBox msgbox(this);
msgbox.setWindowTitle(title);
msgbox.setIcon(QMessageBox::Icon::Critical);
msgbox.setText(message);
msgbox.setWindowIcon(QIcon(":/visimpl.png"));
msgbox.setStandardButtons(QMessageBox::Ok);
msgbox.exec();
return;
}
const auto contents = file.readAll();
QJsonParseError jsonError;
const auto jsonDoc = QJsonDocument::fromJson(contents, &jsonError);
if (jsonDoc.isNull() || !jsonDoc.isObject())
{
const auto message = tr("Couldn't read the contents of %1 or parsing error.").arg(groupsFilename);
QMessageBox msgbox{this};
msgbox.setWindowTitle(title);
msgbox.setIcon(QMessageBox::Icon::Critical);
msgbox.setText(message);
msgbox.setWindowIcon(QIcon(":/visimpl.png"));
msgbox.setStandardButtons(QMessageBox::Ok);
msgbox.setDetailedText(jsonError.errorString());
msgbox.exec();
return;
}
const auto jsonObj = jsonDoc.object();
if (jsonObj.isEmpty())
{
const auto message = tr("Error parsing the contents of %1.").arg(groupsFilename);
QMessageBox msgbox{this};
msgbox.setWindowTitle(title);
msgbox.setIcon(QMessageBox::Icon::Critical);
msgbox.setText(message);
msgbox.setWindowIcon(QIcon(":/visimpl.png"));
msgbox.setStandardButtons(QMessageBox::Ok);
msgbox.exec();
return;
}
QApplication::setOverrideCursor(Qt::WaitCursor);
const auto jsonGroups = jsonObj.value("groups").toArray();
for (const auto group : jsonGroups)
{
const auto o = group.toObject();
const auto name = o.value("name").toString();
const auto gidsStrings = o.value("gids").toString().split(",");
visimpl::GIDUSet gids;
auto addGids = [&gids](const QString s)
{
if (s.contains(":"))
{
auto limits = s.split(":");
for (unsigned int id = limits.first().toUInt();
id <= limits.last().toUInt(); ++id)
gids.insert(id);
}
else
{
gids.insert(s.toUInt());
}
};
std::for_each(gidsStrings.cbegin(), gidsStrings.cend(), addGids);
visimpl::Selection selection;
selection.gids = gids;
selection.name = name.toStdString();
#ifdef VISIMPL_USE_ZEROEQ
_summary->AddNewHistogram(selection, false);
#else
_summary->AddNewHistogram(selection);
#endif
}
_summary->UpdateHistograms();
if (_displayManager)
{
_displayManager->dirtyHistograms();
_displayManager->refresh();
}
QApplication::restoreOverrideCursor();
}
\ No newline at end of file
...@@ -94,6 +94,7 @@ namespace stackviz ...@@ -94,6 +94,7 @@ namespace stackviz
void openH5FilesThroughDialog( void ); void openH5FilesThroughDialog( void );
void openSubsetEventsFileThroughDialog( void ); void openSubsetEventsFileThroughDialog( void );
void openRESTThroughDialog(); void openRESTThroughDialog();
void openGroupsThroughDialog();
void aboutDialog( void ); void aboutDialog( void );
void togglePlaybackDock( void ); void togglePlaybackDock( void );
...@@ -167,6 +168,7 @@ namespace stackviz ...@@ -167,6 +168,7 @@ namespace stackviz
QString _lastOpenedFileNamePath; QString _lastOpenedFileNamePath;
QString _lastOpenedSubsetsFileName; QString _lastOpenedSubsetsFileName;
QString _lastOpenedGroupsFileName;
simil::TSimulationType _simulationType; simil::TSimulationType _simulationType;
......
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>1280</width> <width>1280</width>
<height>22</height> <height>24</height>
</rect> </rect>
</property> </property>
<widget class="QMenu" name="menuFile"> <widget class="QMenu" name="menuFile">
...@@ -38,6 +38,8 @@ ...@@ -38,6 +38,8 @@
<addaction name="separator"/> <addaction name="separator"/>
<addaction name="actionOpenSubsetEventsFile"/> <addaction name="actionOpenSubsetEventsFile"/>
<addaction name="separator"/> <addaction name="separator"/>
<addaction name="actionOpenGroupsFile"/>
<addaction name="separator"/>
<addaction name="actionCloseData"/> <addaction name="actionCloseData"/>
<addaction name="separator"/> <addaction name="separator"/>
<addaction name="actionQuit"/> <addaction name="actionQuit"/>
...@@ -340,6 +342,21 @@ ...@@ -340,6 +342,21 @@
<string>Ctrl+Q</string> <string>Ctrl+Q</string>
</property> </property>
</action> </action>
<action name="actionOpenGroupsFile">
<property name="icon">
<iconset resource="resources.qrc">
<normaloff>:/icons/folder-doc.svg</normaloff>:/icons/folder-doc.svg</iconset>
</property>
<property name="text">
<string>Open Groups file...</string>
</property>
<property name="toolTip">
<string>Open groups as histograms</string>
</property>
<property name="shortcut">
<string>Ctrl+G</string>
</property>
</action>
</widget> </widget>
<resources> <resources>
<include location="resources.qrc"/> <include location="resources.qrc"/>
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment