Commit bec52b35 by Alexander Wiebel

[ADD #273] new mechanism to prevent loading multiple fiber datasets if

activated in preferences file
parent 89f6b6f5
## This is a sample configuration file for OpenWalnut.
## Uncomment the options you are interested in.
[general]
allowOnlyOneFiberDataSet = yes # This will prevent you from accidently loading multiple fiber data sets.
[modules]
## use this to specify the default module to add during load.
## It is a comma seperated list. If this is not specified the default empty is assumed.
......
......@@ -66,7 +66,8 @@
WMainWindow::WMainWindow() :
QMainWindow(),
m_iconManager()
m_iconManager(),
m_fibLoaded( false )
{
setupGUI();
}
......@@ -471,7 +472,34 @@ void WMainWindow::openLoadDialog()
{
stdFileNames.push_back( ( *constIterator ).toLocal8Bit().constData() );
}
m_loaderSignal( stdFileNames );
//
// WE KNOW THAT THIS IS KIND OF A HACK. Iis is only provided to prevent naive users from having trouble.
//
bool allowOnlyOneFiberDataSet = false;
bool doubleFibersFound = false; // have we detected the multiple loading of fibers?
if( WPreferences::getPreference( "general.allowOnlyOneFiberDataSet", &allowOnlyOneFiberDataSet ) && allowOnlyOneFiberDataSet )
{
for( std::vector< std::string >::iterator it = stdFileNames.begin(); it != stdFileNames.end(); ++it )
{
using wiotools::getSuffix;
std::string suffix = getSuffix( *it );
bool isFib = ( suffix == ".fib" );
if( m_fibLoaded && isFib )
{
QCoreApplication::postEvent( this, new WModuleCrashEvent(
WModuleFactory::getModuleFactory()->getPrototypeByName( "Data Module" ),
std::string( "Tried to load two fiber data sets. This is not allowed by your preferences." ) ) );
doubleFibersFound = true;
}
m_fibLoaded |= isFib;
}
}
if( !doubleFibersFound )
{
m_loaderSignal( stdFileNames );
}
}
void WMainWindow::openAboutDialog()
......@@ -660,3 +688,8 @@ void WMainWindow::newRoi()
WKernel::getRunningKernel()->getRoiManager()->addRoi( newRoi, m_datasetBrowser->getFirstRoiInSelectedBranch()->getROI() );
}
}
void WMainWindow::setFibersLoaded()
{
m_fibLoaded = true;
}
......@@ -178,6 +178,11 @@ public slots:
*/
void projectSave();
/**
* Sets that a fiber data set has already been loaded. Thi shelps to prevent multiple fiber data sets to be loaded.
*/
void setFibersLoaded();
private:
/**
* Sets up the permanent tool bar.
......@@ -207,6 +212,8 @@ private:
boost::shared_ptr< WQtNavGLWidget > m_navSagittal; //!< the sgittal view widget GL widget of the GUI
QDockWidget* m_dummyWidget; //!< The dummywidget serves as spacer in the dockwidget area;
bool m_fibLoaded; //!< Indicates whether a fiber data set is already loaded.
/**
* All registered WQtCustomDockWidgets.
*/
......
......@@ -36,6 +36,7 @@
#include "WMainWindow.h" // this has to be included before any other includes
#include "../../common/WConditionOneShot.h"
#include "../../common/WIOTools.h"
#include "../../common/WPreferences.h"
#include "../../graphicsEngine/WGraphicsEngine.h"
#include "../../kernel/WKernel.h"
#include "../../kernel/WProjectFile.h"
......@@ -159,7 +160,41 @@ int WQt4Gui::run()
// check if we want to load data due to command line and call the respective function
if( m_optionsMap.count("input") )
{
m_kernel->loadDataSets( m_optionsMap["input"].as< std::vector< std::string > >() );
//
// WE KNOW THAT THIS IS KIND OF A HACK. Iis is only provided to prevent naive users from having trouble.
//
bool allowOnlyOneFiberDataSet = false;
bool doubleFibersFound = false; // have we detected the multiple loading of fibers?
if( WPreferences::getPreference( "general.allowOnlyOneFiberDataSet", &allowOnlyOneFiberDataSet ) && allowOnlyOneFiberDataSet )
{
bool fibFound = false;
std::vector< std::string > tmpFiles = m_optionsMap["input"].as< std::vector< std::string > >();
for( std::vector< std::string >::iterator it = tmpFiles.begin(); it != tmpFiles.end(); ++it )
{
using wiotools::getSuffix;
std::string suffix = getSuffix( *it );
bool isFib = ( suffix == ".fib" );
if( fibFound && isFib )
{
QCoreApplication::postEvent( m_mainWindow, new WModuleCrashEvent(
WModuleFactory::getModuleFactory()->getPrototypeByName( "Data Module" ),
std::string( "Tried to load two fiber data sets. This is not allowed by your preferences." ) ) );
doubleFibersFound = true;
}
fibFound |= isFib;
}
if( fibFound && !doubleFibersFound )
{
// Found exactly one fiber data set. So signal this to main window.
// If more than one are found we do not load them anyways. Thus we can allow to load a new one.
m_mainWindow->setFibersLoaded();
}
}
if( !doubleFibersFound )
{
m_kernel->loadDataSets( m_optionsMap["input"].as< std::vector< std::string > >() );
}
}
// Load project file
......
Markdown is supported
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