SpikeStream Application Library
0.2
|
00001 //SpikeStream includes 00002 #include "AbstractAnalysisWidget.h" 00003 #include "AnalysisParameterDialog.h" 00004 #include "Globals.h" 00005 #include "LoadAnalysisDialog.h" 00006 #include "SpikeStreamAnalysisException.h" 00007 #include "Util.h" 00008 using namespace spikestream; 00009 00010 //Qt includes 00011 #include <QAction> 00012 00013 00015 AbstractAnalysisWidget::AbstractAnalysisWidget(QWidget* parent) : QWidget(parent){ 00016 currentTask = UNDEFINED_TASK; 00017 00018 //Set up class to run analysis 00019 analysisRunner = new AnalysisRunner( 00020 Globals::getNetworkDao()->getDBInfo(), 00021 Globals::getArchiveDao()->getDBInfo(), 00022 Globals::getAnalysisDao()->getDBInfo() 00023 ); 00024 connect(analysisRunner, SIGNAL(finished()), this, SLOT(threadFinished())); 00025 connect(analysisRunner, SIGNAL(finished()), Globals::getEventRouter(), SLOT(analysisStopped())); 00026 connect(analysisRunner, SIGNAL(newResultsFound()), this , SLOT(updateResults()), Qt::QueuedConnection); 00027 00028 00029 //Listen for events that affect whether the tool bar should be enabled or not. 00030 connect(Globals::getEventRouter(), SIGNAL(archiveChangedSignal()), this, SLOT(archiveChanged())); 00031 connect(Globals::getEventRouter(), SIGNAL(archiveChangedSignal()), this, SLOT(loadArchiveTimeStepsIntoCombos())); 00032 connect(Globals::getEventRouter(), SIGNAL(networkChangedSignal()), this, SLOT(networkChanged())); 00033 } 00034 00035 00037 AbstractAnalysisWidget::~AbstractAnalysisWidget(){ 00038 delete analysisRunner; 00039 } 00040 00041 00042 /*----------------------------------------------------------*/ 00043 /*------ PROTECTED SLOTS ------*/ 00044 /*----------------------------------------------------------*/ 00045 00047 void AbstractAnalysisWidget::archiveChanged(){ 00048 if(analysisRunner->isRunning()) 00049 qCritical()<<"Archive should not be changed while analysis is running"; 00050 00051 //The analyses are archive specific, so create a new analysis 00052 newAnalysis(); 00053 } 00054 00055 00057 void AbstractAnalysisWidget::fixTimeStepSelection(int selectedIndex){ 00058 //Check that from time step has not been set to greater than the to 00059 if(sender() == fromTimeStepCombo){//FROM time step combo generated the signal 00060 if(selectedIndex > toTimeStepCombo->currentIndex()){ 00061 toTimeStepCombo->setCurrentIndex(selectedIndex); 00062 } 00063 } 00064 //Check to time step is not less than from 00065 else{//TO time step combo generated the signal 00066 if(selectedIndex < fromTimeStepCombo->currentIndex()){ 00067 fromTimeStepCombo->setCurrentIndex(selectedIndex); 00068 } 00069 } 00070 } 00071 00072 00074 void AbstractAnalysisWidget::loadAnalysis(){ 00075 try{ 00076 //Show dialog to select the analysis the user wants to load 00077 LoadAnalysisDialog loadAnalysisDialog(this, analysisInfo.getAnalyisType()); 00078 if(loadAnalysisDialog.exec() == QDialog::Accepted ) {//Load the archive 00079 analysisInfo = loadAnalysisDialog.getAnalysisInfo(); 00080 updateResults(); 00081 Globals::setAnalysisID(getAnalysisName(), analysisInfo.getID()); 00082 } 00083 } 00084 catch (SpikeStreamException& ex){ 00085 qCritical()<<ex.getMessage(); 00086 Globals::setAnalysisID(getAnalysisName(), 0); 00087 return; 00088 } 00089 } 00090 00091 00093 void AbstractAnalysisWidget::loadArchiveTimeStepsIntoCombos(){ 00094 if(!Globals::archiveLoaded()) 00095 return; 00096 00097 unsigned int minTimeStep = Globals::getArchiveDao()->getMinTimeStep(Globals::getArchive()->getID()); 00098 unsigned int maxTimeStep = Globals::getArchiveDao()->getMaxTimeStep(Globals::getArchive()->getID()); 00099 QStringList timeStepList = getTimeStepList(minTimeStep, maxTimeStep); 00100 fromTimeStepCombo->clear(); 00101 fromTimeStepCombo->addItems(timeStepList); 00102 toTimeStepCombo->clear(); 00103 toTimeStepCombo->addItems(timeStepList); 00104 if(fromTimeStepCombo->count() > 0) 00105 fromTimeStepCombo->setCurrentIndex(0); 00106 } 00107 00108 00110 void AbstractAnalysisWidget::networkChanged(){ 00111 if(analysisRunner->isRunning()) 00112 qCritical()<<"Network should not be changed while analysis is running"; 00113 00114 //The analyses are archive specific, so create a new analysis 00115 newAnalysis(); 00116 } 00117 00118 00122 void AbstractAnalysisWidget::selectParameters(){ 00123 //Record the current description 00124 QString oldDescription = analysisInfo.getDescription(); 00125 00126 AnalysisParameterDialog dialog(this, analysisInfo); 00127 if(dialog.exec() == QDialog::Accepted ) { 00128 //Copy the new information that has been set 00129 analysisInfo = dialog.getInfo(); 00130 00131 //Update the description if it has changed 00132 if(analysisInfo.getDescription() != oldDescription && analysisInfo.getDescription() != "") 00133 Globals::getAnalysisDao()->updateDescription(analysisInfo.getID(), analysisInfo.getDescription()); 00134 } 00135 } 00136 00137 00139 void AbstractAnalysisWidget::stopAnalysis(){ 00140 analysisRunner->stop(); 00141 } 00142 00143 00145 void AbstractAnalysisWidget::threadFinished(){ 00146 //Check for errors 00147 if(analysisRunner->isError()){ 00148 qCritical()<<analysisRunner->getErrorMessage(); 00149 currentTask = UNDEFINED_TASK; 00150 return; 00151 } 00152 00153 switch(currentTask){ 00154 case ANALYSIS_TASK: 00155 Globals::getEventRouter()->analysisStopped(); 00156 break; 00157 default: 00158 qCritical()<<"Current task not recognized: "<<currentTask; 00159 } 00160 currentTask = UNDEFINED_TASK; 00161 } 00162 00163 00164 /*----------------------------------------------------------*/ 00165 /*------ PROTECTED METHODS ------*/ 00166 /*----------------------------------------------------------*/ 00167 00169 void AbstractAnalysisWidget::checkToolBarEnabled(){ 00170 if(Globals::networkLoaded() && Globals::archiveLoaded()) 00171 toolBar->setEnabled(true); 00172 else 00173 toolBar->setEnabled(false); 00174 } 00175 00176 00178 QStringList AbstractAnalysisWidget::getTimeStepList(unsigned int min, unsigned int max){ 00179 QStringList tmpStrList; 00180 for(unsigned int i=min; i<=max; ++i) 00181 tmpStrList.append(QString::number(i)); 00182 return tmpStrList; 00183 } 00184 00185 00187 QToolBar* AbstractAnalysisWidget::getDefaultToolBar(){ 00188 QToolBar* tmpToolBar = new QToolBar(this); 00189 00190 QAction* tmpAction = new QAction(QIcon(Globals::getSpikeStreamRoot() + "/images/open.png"), "Open", this); 00191 connect(tmpAction, SIGNAL(triggered()), this, SLOT(loadAnalysis())); 00192 tmpToolBar->addAction (tmpAction); 00193 00194 tmpAction = new QAction(QIcon(Globals::getSpikeStreamRoot() + "/images/new.png"), "New", this); 00195 connect(tmpAction, SIGNAL(triggered()), this, SLOT(newAnalysis())); 00196 tmpToolBar->addAction (tmpAction); 00197 00198 tmpAction = new QAction(QIcon(Globals::getSpikeStreamRoot() + "/images/save.png"), "Export analysis", this); 00199 connect(tmpAction, SIGNAL(triggered()), this, SLOT(exportAnalysis())); 00200 connect(Globals::getEventRouter(), SIGNAL(analysisNotRunningSignal(bool)), tmpAction, SLOT(setEnabled(bool))); 00201 tmpToolBar->addAction (tmpAction); 00202 00203 tmpAction = new QAction(QIcon(Globals::getSpikeStreamRoot() + "/images/play.png"), "Start analysis", this); 00204 connect(tmpAction, SIGNAL(triggered()), this, SLOT(startAnalysis())); 00205 connect(Globals::getEventRouter(), SIGNAL(analysisNotRunningSignal(bool)), tmpAction, SLOT(setEnabled(bool))); 00206 tmpToolBar->addAction (tmpAction); 00207 00208 tmpAction = new QAction(QIcon(Globals::getSpikeStreamRoot() + "/images/stop.png"), "Stop analysis", this); 00209 connect(tmpAction, SIGNAL(triggered()), this, SLOT(stopAnalysis())); 00210 tmpToolBar->addAction (tmpAction); 00211 00212 fromTimeStepCombo = new QComboBox(this); 00213 tmpToolBar->addWidget(fromTimeStepCombo); 00214 connect(fromTimeStepCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(fixTimeStepSelection(int))); 00215 00216 toTimeStepCombo = new QComboBox(this); 00217 tmpToolBar->addWidget(toTimeStepCombo); 00218 connect(toTimeStepCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(fixTimeStepSelection(int))); 00219 00220 tmpAction = new QAction(QIcon(), "Parameters", this); 00221 connect(tmpAction, SIGNAL(triggered()), this, SLOT(selectParameters())); 00222 tmpToolBar->addAction (tmpAction); 00223 00224 tmpAction = new QAction(QIcon(), "Plot", this); 00225 connect(tmpAction, SIGNAL(triggered()), this, SLOT(plotGraphs())); 00226 tmpToolBar->addAction (tmpAction); 00227 00228 return tmpToolBar; 00229 } 00230 00231 00233 int AbstractAnalysisWidget::getFirstTimeStep(){ 00234 return Util::getInt(fromTimeStepCombo->currentText()); 00235 } 00236 00237 00239 int AbstractAnalysisWidget::getLastTimeStep(){ 00240 return Util::getInt(toTimeStepCombo->currentText()); 00241 } 00242