SpikeStream Application Library
0.2
|
00001 //SpikeStream includes 00002 #include "Globals.h" 00003 #include "NeuronGroupWidget.h" 00004 #include "NeuronGroupTableView.h" 00005 #include "PluginsDialog.h" 00006 #include "SpikeStreamException.h" 00007 using namespace spikestream; 00008 00009 //Qt includes 00010 #include <QMessageBox> 00011 #include <QLayout> 00012 #include <QTableView> 00013 00014 00016 NeuronGroupWidget::NeuronGroupWidget(QWidget* parent) : QWidget(parent) { 00017 //Vertical box to organize layout 00018 QVBoxLayout* verticalBox = new QVBoxLayout(this); 00019 00020 //Add button to launch add neurons dialog and button to delete neuron groups 00021 QHBoxLayout* buttonLayout = new QHBoxLayout(); 00022 addNeuronsButton = new QPushButton(" Add Neurons "); 00023 addNeuronsButton->setEnabled(false); 00024 connect (addNeuronsButton, SIGNAL(clicked()), this, SLOT(addNeurons())); 00025 buttonLayout->addWidget(addNeuronsButton); 00026 deleteButton = new QPushButton(QIcon(Globals::getSpikeStreamRoot() + "/images/trash_can.png"), ""); 00027 deleteButton->setMaximumSize(150, 30); 00028 deleteButton->setEnabled(false); 00029 connect (deleteButton, SIGNAL(clicked()), this, SLOT(deleteSelectedNeurons())); 00030 buttonLayout->addWidget(deleteButton); 00031 buttonLayout->addStretch(10); 00032 verticalBox->addLayout(buttonLayout); 00033 00034 //Construct table view and model 00035 neuronGroupModel = new NeuronGroupModel(); 00036 QTableView* neuronGroupView = new NeuronGroupTableView(this, neuronGroupModel); 00037 verticalBox->addWidget(neuronGroupView); 00038 00039 //Enable or disable buttons depending on whether a network is loaded or not 00040 connect(Globals::getEventRouter(), SIGNAL(networkChangedSignal()), this, SLOT(networkChanged())); 00041 } 00042 00043 00045 NeuronGroupWidget::~NeuronGroupWidget(){ 00046 } 00047 00048 00049 /*--------------------------------------------------------*/ 00050 /*------- PRIVATE SLOTS -------*/ 00051 /*--------------------------------------------------------*/ 00052 00054 void NeuronGroupWidget::addNeurons(){ 00055 //Run some checks - cannot change network if simulation or analysis is going on. 00056 if(!Globals::networkChangeOk()) 00057 return; 00058 PluginsDialog* pluginsDialog = new PluginsDialog(this, "/plugins/neurons", "Add Neurons"); 00059 pluginsDialog->exec(); 00060 delete pluginsDialog; 00061 } 00062 00063 00065 void NeuronGroupWidget::deleteSelectedNeurons(){ 00066 //Run some checks - cannot change network if simulation or analysis is going on. 00067 if(!Globals::networkLoaded()){ 00068 qCritical()<<"Attempting to delete neurons when network is not loaded"; 00069 return; 00070 } 00071 //Check if network is editable or not 00072 if(Globals::getNetwork()->hasArchives()){ 00073 qWarning()<<"You cannot alter a network that has archives.\nDelete the archives and try again."; 00074 return; 00075 } 00076 if(!Globals::networkChangeOk()) 00077 return; 00078 00079 //Do nothing if no neuron groups are selected 00080 QList<unsigned int> deleteNeurIDList = neuronGroupModel->getSelectedNeuronGroupIDs(); 00081 if(deleteNeurIDList.isEmpty()) 00082 return; 00083 00084 //Show warning 00085 QMessageBox msgBox(QMessageBox::Warning, "Deleting Neuron Groups", "Are you sure that you want to delete these neuron groups?\nThis step cannot be undone.", QMessageBox::Ok | QMessageBox::Cancel, this); 00086 if(msgBox.exec() != QMessageBox::Ok) 00087 return; 00088 00089 //Delete neuron groups 00090 try{ 00091 connect(Globals::getNetwork(), SIGNAL(taskFinished()), this, SLOT(networkTaskFinished()), Qt::UniqueConnection); 00092 progressDialog = new QProgressDialog("Deleting neuron group(s)", "Cancel", 0, 0, this); 00093 progressDialog->setWindowModality(Qt::WindowModal); 00094 progressDialog->show(); 00095 Globals::getNetwork()->deleteNeuronGroups(deleteNeurIDList); 00096 } 00097 catch(SpikeStreamException& ex){ 00098 qCritical()<<ex.getMessage(); 00099 00100 //Call networkTaskFinished to handle error 00101 networkTaskFinished(); 00102 } 00103 } 00104 00105 00107 void NeuronGroupWidget::networkChanged(){ 00108 if(Globals::networkLoaded()){ 00109 addNeuronsButton->setEnabled(true); 00110 deleteButton->setEnabled(true); 00111 } 00112 else{ 00113 addNeuronsButton->setEnabled(false); 00114 deleteButton->setEnabled(false); 00115 } 00116 } 00117 00118 00121 void NeuronGroupWidget::networkTaskFinished(){ 00122 //Check for errors 00123 if(Globals::getNetwork()->isError()) 00124 qCritical()<<Globals::getNetwork()->getErrorMessage(); 00125 Globals::getNetwork()->clearError(); 00126 00127 progressDialog->setValue(100); 00128 progressDialog->close(); 00129 //delete progressDialog; 00130 00131 //Clear selection on neuron group model 00132 neuronGroupModel->clearSelection(); 00133 00134 //Prevent this method being called when network finishes other tasks 00135 disconnect(Globals::getNetwork(), SIGNAL(taskFinished()), this, SLOT(networkTaskFinished())); 00136 00137 //Inform other classes that network has changed 00138 Globals::getEventRouter()->networkChangedSlot(); 00139 } 00140