SpikeStream Application Library
0.2
|
00001 //SpikeStream includes 00002 #include "AbstractConnectionWidget.h" 00003 #include "Globals.h" 00004 #include "SpikeStreamException.h" 00005 #include "SynapseType.h" 00006 #include "Util.h" 00007 using namespace spikestream; 00008 00009 //Qt includes 00010 #include <QMessageBox> 00011 00012 00014 AbstractConnectionWidget::AbstractConnectionWidget(QWidget *parent) : QWidget(parent){ 00015 00016 } 00017 00018 00020 AbstractConnectionWidget::~AbstractConnectionWidget(){ 00021 delete connectionBuilder; 00022 } 00023 00024 00025 /*----------------------------------------------------------*/ 00026 /*----- PROTECTED METHODS -----*/ 00027 /*----------------------------------------------------------*/ 00028 00030 void AbstractConnectionWidget::addNeuronGroups(QComboBox* combo){ 00031 QList<NeuronGroupInfo> neurGrpInfoList = Globals::getNetwork()->getNeuronGroupsInfo(); 00032 foreach(NeuronGroupInfo neurGrpInfo, neurGrpInfoList){ 00033 combo->addItem(neurGrpInfo.getName() + " (" + QString::number(neurGrpInfo.getID()) + ")"); 00034 } 00035 } 00036 00037 00039 void AbstractConnectionWidget::addSynapseTypes(QComboBox* combo){ 00040 QList<SynapseType> synapseTypesList = Globals::getNetworkDao()->getSynapseTypes(); 00041 foreach(SynapseType synType, synapseTypesList){ 00042 combo->addItem(synType.getDescription() + " (" + QString::number(synType.getID()) + ")"); 00043 } 00044 } 00045 00046 00048 void AbstractConnectionWidget::checkInput(QComboBox* combo, const QString& errorMessage){ 00049 if(combo->count() == 0){ 00050 throw SpikeStreamException(errorMessage); 00051 } 00052 } 00053 00054 00056 void AbstractConnectionWidget::checkInput(QLineEdit* inputEdit, const QString& errMsg){ 00057 if(inputEdit->text().isEmpty()){ 00058 throw SpikeStreamException(errMsg); 00059 } 00060 } 00061 00062 00064 unsigned int AbstractConnectionWidget::getNeuronGroupID(const QString& comboText){ 00065 if(comboText.isEmpty()) 00066 throw SpikeStreamException("Cannot extract a neuron group ID from empty text."); 00067 00068 QRegExp regExp("[()]"); 00069 return Util::getUInt(comboText.section(regExp, 1, 1)); 00070 } 00071 00072 00074 unsigned int AbstractConnectionWidget::getSynapseTypeID(const QString& comboText){ 00075 if(comboText.isEmpty()) 00076 throw SpikeStreamException("Cannot extract a synapse type ID from empty text."); 00077 00078 QRegExp regExp("[()]"); 00079 return Util::getUInt(comboText.section(regExp, 1, 1)); 00080 } 00081 00082 00083 00084 /*----------------------------------------------------------*/ 00085 /*----- PRIVATE SLOTS -----*/ 00086 /*----------------------------------------------------------*/ 00087 00090 void AbstractConnectionWidget::addButtonClicked(){ 00091 //Double check network is loaded 00092 if(!Globals::networkLoaded()){ 00093 QMessageBox::critical(this, "Random1 Connection Group Builder Error", "No network loaded.", QMessageBox::Ok); 00094 return; 00095 } 00096 00097 //Check inputs have sensible values 00098 if(!checkInputs()) 00099 return; 00100 00101 try{ 00102 //Get connection group info 00103 ConnectionGroupInfo info = getConnectionGroupInfo(); 00104 00105 //Start thread to add connections 00106 connectionBuilder->startBuildConnectionGroup(info); 00107 progressDialog = new QProgressDialog("Adding connection group", "Cancel", 0, 100, this, Qt::CustomizeWindowHint); 00108 progressDialog->setWindowModality(Qt::WindowModal); 00109 progressDialog->setMinimumDuration(2000); 00110 progressDialog->show(); 00111 updatingProgress = false; 00112 } 00113 catch(SpikeStreamException& ex){ 00114 qCritical()<<ex.getMessage(); 00115 } 00116 00117 } 00118 00119 00121 void AbstractConnectionWidget::builderThreadFinished(){ 00122 if(connectionBuilder->isError()) 00123 qCritical()<<connectionBuilder->getErrorMessage(); 00124 00125 //Close progress dialog 00126 progressDialog->close(); 00127 00128 //Inform other classes that network has changed 00129 Globals::getEventRouter()->networkChangedSlot(); 00130 } 00131 00132 00134 void AbstractConnectionWidget::updateProgress(int stepsCompleted, int totalSteps, QString message){ 00135 //Set flag to avoid multiple calls to progress dialog while it is redrawing 00136 if(updatingProgress) 00137 return; 00138 updatingProgress = true; 00139 00140 //Check for cancellation 00141 if(progressDialog->wasCanceled()){ 00142 connectionBuilder->stop(); 00143 progressDialog->setLabelText("Cleaning up."); 00144 progressDialog->setCancelButton(0);//Should not be able to cancel the clean up 00145 progressDialog->show(); 00146 } 00147 //Update progress 00148 else if(stepsCompleted < totalSteps){ 00149 progressDialog->setValue(stepsCompleted); 00150 progressDialog->setMaximum(totalSteps); 00151 progressDialog->setLabelText(message); 00152 } 00153 //Progress has finished 00154 else{ 00155 progressDialog->close(); 00156 } 00157 00158 //Clear flag to indicate that update of progress is complete 00159 updatingProgress = false; 00160 } 00161