SpikeStream Application Library  0.2
Globals.cpp
Go to the documentation of this file.
00001 //SpikeStream includes
00002 #include "Globals.h"
00003 #include "SpikeStreamException.h"
00004 #include "SpikeStreamAnalysisException.h"
00005 using namespace spikestream;
00006 
00007 //Other includes
00008 #include <iostream>
00009 using namespace std;
00010 
00011 //Define controlling output of memory information
00012 #define MEMORY_DEBUG
00013 
00014 //Declare static variables
00015 QHash<QString, unsigned int> Globals::analysisMap;
00016 QHash<QString, bool> Globals::analysisRunningMap;
00017 AnalysisDao* Globals::analysisDao = NULL;
00018 Archive* Globals::archive = NULL;
00019 ArchiveDao* Globals::archiveDao = NULL;
00020 bool Globals::archivePlaying = false;
00021 EventRouter* Globals::eventRouter = new EventRouter();
00022 Network* Globals::network = NULL;
00023 NetworkDao* Globals::networkDao = NULL;
00024 NetworkDisplay* Globals::networkDisplay = new NetworkDisplay();
00025 bool Globals::rendering = false;
00026 QString Globals::spikeStreamRoot = "";
00027 QString Globals::workingDirectory = "";
00028 AbstractSimulation* Globals::simulation = NULL;
00029 bool Globals::simulationRunning = false;
00030 
00031 
00032 /*---------------------------------------------------------------------------------*/
00033 /*----------                  PUBLIC METHODS                          -------------*/
00034 /*---------------------------------------------------------------------------------*/
00035 
00037 void Globals::clearAnalysisRunning(const QString &analysisName){
00038         analysisRunningMap.remove(analysisName);
00039 }
00040 
00041 
00043 bool Globals::isAnalysisLoaded(const QString& analysisName){
00044         //Map has an entry for this analysis - return false if ID is zero
00045         if(analysisMap.contains(analysisName)){
00046                 if(analysisMap[analysisName] == 0)
00047                         return false;
00048                 return true;
00049         }
00050 
00051         //No entry in map so no analysis loaded
00052         return false;
00053 }
00054 
00055 
00057 bool Globals::isAnalysisRunning(){
00058         //Analysis running map is empty, so no analyses are running
00059         if(analysisRunningMap.isEmpty())
00060                 return false;
00061         return true;
00062 }
00063 
00064 
00066 unsigned int Globals::getAnalysisID(const QString& analysisName){
00067         if(analysisMap.contains(analysisName))
00068                 return analysisMap[analysisName];
00069 
00070         //No analysis ID has been set for this name, so return zero
00071         return 0;
00072 }
00073 
00074 
00078 bool Globals::archiveLoaded(){
00079         if(archive == NULL)
00080                 return false;
00081         return true;
00082 }
00083 
00084 
00087 void Globals::cleanUp(){
00088         #ifdef MEMORY_DEBUG
00089                 cout<<"Cleaning up Globals"<<endl;
00090         #endif//MEMORY_DEBUG
00091 
00092         if(archive != NULL){
00093                 delete archive;
00094                 archive = NULL;
00095         }
00096         if(network != NULL){
00097                 //Delete network if it has been marked as temporary and has not been saved.
00098                 if(network->isTransient() && !network->isSaved()){
00099                         NetworkDaoThread networkDaoThread(networkDao->getDBInfo());
00100                         networkDaoThread.startDeleteNetwork(network->getID());
00101                         networkDaoThread.wait();
00102                 }
00103                 delete network;
00104                 network = NULL;
00105         }
00106         if(networkDao != NULL){
00107                 delete networkDao;
00108                 networkDao = NULL;
00109         }
00110         if(eventRouter != NULL){
00111                 delete eventRouter;
00112                 eventRouter = NULL;
00113         }
00114 }
00115 
00116 
00118 AnalysisDao* Globals::getAnalysisDao(){
00119         return analysisDao;
00120 }
00121 
00122 
00124 Archive* Globals::getArchive(){
00125         if(archive == NULL)
00126                 throw SpikeStreamException("No archive loaded. You should check that archive is loaded using archiveLoaded() before calling this method.");
00127         return archive;
00128 }
00129 
00130 
00133 ArchiveDao* Globals::getArchiveDao(){
00134         return archiveDao;
00135 }
00136 
00137 
00139 Network* Globals::getNetwork(){
00140         if(network == NULL)
00141                 throw SpikeStreamException("No network loaded. You should check that network is loaded using networkLoaded() before calling this method.");
00142         return network;
00143 }
00144 
00145 
00148 NetworkDao* Globals::getNetworkDao(){
00149         return networkDao;
00150 }
00151 
00152 
00154 NetworkDisplay* Globals::getNetworkDisplay(){
00155         return networkDisplay;
00156 }
00157 
00158 
00160 AbstractSimulation* Globals::getSimulation(){
00161         return Globals::simulation;
00162 }
00163 
00164 
00166 QString Globals::getSpikeStreamRoot(){
00167         return spikeStreamRoot;
00168 }
00169 
00170 
00172 QString Globals::getWorkingDirectory(){
00173         return workingDirectory;
00174 }
00175 
00176 
00178 bool Globals::networkLoaded(){
00179         if(network == NULL)
00180                 return false;
00181         return true;
00182 }
00183 
00184 
00186 bool Globals::isRendering() {
00187         return rendering;
00188 }
00189 
00190 
00192 bool Globals::isArchivePlaying() {
00193         return archivePlaying;
00194 }
00195 
00196 
00198 bool  Globals::isSimulationLoaded(){
00199         if(simulation == NULL)
00200                 return false;
00201         return true;
00202 }
00203 
00204 
00206 bool  Globals::isSimulationRunning(){
00207         return Globals::simulationRunning;
00208 }
00209 
00214 bool Globals::networkChangeOk(){
00215         //If no network is loaded, then simulation or analysis will not be running
00216         if(!Globals::networkLoaded())
00217                 return true;
00218 
00219         //Cannot change network when simulation is running
00220         if(Globals::isSimulationRunning()){
00221                 qWarning()<<"Network cannot be changed or deleted whilst a simulation is running.\nStop the simulation and try again.";
00222                 return false;
00223         }
00224 
00225         //Cannot change network when analysis is running
00226         if(Globals::isAnalysisRunning()){
00227                 qWarning()<<"Network cannot be changed or deleted whilst an analysis is running.\nStop all analyses and try again.";
00228                 return false;
00229         }
00230 
00231         //Cannot change network when archive is playing
00232         if(Globals::isArchivePlaying()){
00233                 qWarning()<<"Network cannot be changed or deleted whilst an archive is playing.\nStop archive playback and try again.";
00234                 return false;
00235         }
00236 
00237         //Check that user wants to unload simulation
00238         if(Globals::isSimulationLoaded()){
00239                 qWarning()<<"A simulation is currently loaded.\nUnload the simulation before changing or deleting the current network.";
00240                 return false;
00241         }
00242 
00243         //Network change is ok if we have reached this point
00244         return true;
00245 }
00246 
00247 
00249 void Globals::setAnalysisID(const QString& analysisName, unsigned int id){
00250         analysisMap[analysisName] = id;
00251 }
00252 
00253 
00255 void Globals::setAnalysisRunning(const QString &analysisName){
00256         analysisRunningMap[analysisName] = true;
00257 }
00258 
00259 
00261 void Globals::setSimulationRunning(bool simulationRunning){
00262         Globals::simulationRunning = simulationRunning;
00263 }
00264 
00265 
00266 /*-------------------------------------------------------------*/
00267 /*------                 PRIVATE METHODS                 ------*/
00268 /*-------------------------------------------------------------*/
00269 
00271 void Globals::setAnalysisDao(AnalysisDao* newAnalysisDao){
00272         //Clean up the old analysis DAO if it exists
00273         if(Globals::analysisDao != NULL)
00274                 delete analysisDao;
00275 
00276         Globals::analysisDao = newAnalysisDao;
00277 }
00278 
00279 
00281 void Globals::setArchive(Archive* arch){
00282         //Clean up the old network if it exists
00283         if(Globals::archive != NULL)
00284                 delete Globals::archive;
00285 
00286         //Store reference to the new network.
00287         Globals::archive = arch;
00288 }
00289 
00290 
00292 void Globals::setArchiveDao(ArchiveDao* archiveDao){
00293         //Clean up the old network DAO if it exists
00294         if(Globals::archiveDao != NULL)
00295                 delete archiveDao;
00296 
00297         Globals::archiveDao = archiveDao;
00298 }
00299 
00300 
00302 void Globals::setArchivePlaying(bool archivePlaying){
00303         Globals::archivePlaying = archivePlaying;
00304 }
00305 
00306 
00308 void Globals::setEventRouter(EventRouter* eventRouter){
00309         //Clean up the old network if it exists
00310         if(Globals::eventRouter != NULL)
00311                 delete eventRouter;
00312 
00313         Globals::eventRouter = eventRouter;
00314 }
00315 
00316 
00318 void Globals::setNetwork(Network* net){
00319         //Clean up the old network if it exists
00320         if(Globals::network != NULL)
00321                 delete Globals::network;
00322 
00323         //Store reference to the new network.
00324         Globals::network = net;
00325 }
00326 
00327 
00329 void Globals::setNetworkDisplay(NetworkDisplay* networkDisplay){
00330         //Clean up the old network display if it exists
00331         if(Globals::networkDisplay != NULL)
00332                 delete networkDisplay;
00333 
00334         //Store reference to the new network display
00335         Globals::networkDisplay = networkDisplay;
00336 }
00337 
00338 
00340 void Globals::setNetworkDao(NetworkDao* networkDao){
00341         //Clean up the old network DAO if it exists
00342         if(Globals::networkDao != NULL)
00343                 delete networkDao;
00344 
00345         Globals::networkDao = networkDao;
00346 }
00347 
00348 
00350 void Globals::setRendering(bool rendering){
00351         Globals::rendering = rendering;
00352 }
00353 
00354 
00357 void Globals::setSimulation(AbstractSimulation* simulation){
00358         Globals::simulation = simulation;
00359 }
00360 
00361 
00363 void Globals::setSpikeStreamRoot(QString rootDir){
00364         spikeStreamRoot = rootDir;
00365 }
00366 
00367 
00369 void Globals::setWorkingDirectory(QString workDir){
00370         workingDirectory = workDir;
00371 }
00372 
00373 
00374 
 All Classes Files Functions Variables Typedefs Friends Defines