Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Class Members | File Members

MonitorWindow.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   SpikeStream Application                                               *
00003  *   Copyright (C) 2007 by David Gamez                                     *
00004  *   david@davidgamez.eu                                                   *
00005  *   Version 0.1                                                           *
00006  *                                                                         *
00007  *   This program is free software; you can redistribute it and/or modify  *
00008  *   it under the terms of the GNU General Public License as published by  *
00009  *   the Free Software Foundation; either version 2 of the License, or     *
00010  *   (at your option) any later version.                                   *
00011  *                                                                         *
00012  *   This program is distributed in the hope that it will be useful,       *
00013  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00014  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00015  *   GNU General Public License for more details.                          *
00016  *                                                                         *
00017  *   You should have received a copy of the GNU General Public License     *
00018  *   along with this program; if not, write to the                         *
00019  *   Free Software Foundation, Inc.,                                       *
00020  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00021  ***************************************************************************/
00022 
00023 //SpikeStream includes
00024 #include "MonitorWindow.h"
00025 #include "Debug.h"
00026 
00027 //Qt includes
00028 #include <qlabel.h>
00029 #include <qlayout.h>
00030 #include <qpushbutton.h>
00031 #include <qwidget.h>
00032 
00033 //Other includes
00034 #include <iostream>
00035 using namespace std;
00036 
00037 
00038 /*! Constructor for monitoring of simulation. */
00039 MonitorWindow::MonitorWindow(SimulationManager *simMan, QWidget *parent) : QDockWindow (parent, "New monitor window") {
00040         //This constructor is used in live monitoring mode
00041         simulationMode = true;
00042 
00043         //Store reference to simulation manager
00044         simulationManager = simMan;
00045 
00046         //Default mode is to monitor neurons
00047         monitorNeurons = true;
00048 
00049         //Set default size of window outside dock
00050         windowWidth = 200;
00051         windowHeight = 200;
00052         xPos = 20;
00053         yPos = 20;
00054         finishedUndockingWindow = false;
00055         oldVisibility = false;
00056 
00057         //Set up properties of monitor window
00058         setResizeEnabled(true); 
00059         setFixedExtentWidth(100);
00060         setFixedExtentHeight(100);
00061         setCloseMode(QDockWindow::Always);
00062         hide();
00063         
00064         //Listen for when its place changed so that window can be resized
00065         connect(this, SIGNAL(placeChanged(QDockWindow::Place)), this, SLOT(windowPlaceChanged(QDockWindow::Place))); 
00066 
00067         //Listen for when window becomes hidden so that monitoring can be switched off
00068         connect(this, SIGNAL(visibilityChanged(bool)), this, SLOT(windowVisibilityChanged(bool)));
00069 }
00070 
00071 
00072 /*! This constructor is used for playing back an archive. */
00073 MonitorWindow::MonitorWindow(QWidget *parent) : QDockWindow (parent, "New monitor window"){
00074         simulationMode = false;
00075 
00076         //Set up properties of monitor window
00077         setResizeEnabled(true); 
00078         setFixedExtentWidth(100);
00079         show();
00080         
00081         //Set default size of window outside dock
00082         windowWidth = 200;
00083         windowHeight = 200;
00084         finishedUndockingWindow = false;
00085 
00086         //Listen for when its place changed so that window can be resized
00087         connect(this, SIGNAL(placeChanged(QDockWindow::Place)), this, SLOT(windowPlaceChanged(QDockWindow::Place))); 
00088 }
00089 
00090 
00091 /*! Destructor. */
00092 MonitorWindow::~MonitorWindow(){
00093         #ifdef MEMORY_DEBUG
00094                 cout<<"DESTROYING MONITOR WINDOW"<<endl;
00095         #endif//MEMORY_DEBUG
00096 }
00097 
00098 
00099 //-------------------------------------------------------------------------
00100 //-------------------------- PUBLIC METHODS -------------------------------
00101 //-------------------------------------------------------------------------
00102 
00103 /*! Accessor method for the ID of the neuron group id being monitored
00104         by this class. */
00105 unsigned int MonitorWindow::getNeuronGrpID(){
00106         return neuronGrpID;
00107 }
00108 
00109 
00110 /*! Sets whether this class is monitoring spikes from a neuron group
00111         or neuron firing patterns. */
00112 void MonitorWindow::setMonitorType(bool monNeurs){
00113         if(monitorNeurons != monNeurs){//Need to take action
00114                 //See if we are actively monitoring at this moment
00115                 if(this->isVisible()){//Window is actively monitoring so need to change type
00116                         simulationManager->stopMonitoringNeuronGroup(neuronGrpID, monitorNeurons);
00117                         simulationManager->monitorNeuronGroup(neuronGrpID, monNeurs);
00118                 }
00119                 /*Otherwise window is not visible so should not be actively
00120                         monitoring anything. In both cases need to store the current type of monitoring */
00121                 monitorNeurons = monNeurs;
00122         }
00123 }
00124 
00125 
00126 /*! Sets the neuron group id for this window. */
00127 void MonitorWindow::setNeuronGrpID(unsigned int neurGrpID){
00128         neuronGrpID = neurGrpID;
00129 }
00130 
00131 
00132 //----------------------------------------------------------------------------
00133 //---------------- PROTECTED METHODS INHERITED FROM QDOCKWINDOW --------------
00134 //----------------------------------------------------------------------------
00135 
00136 /*! Stores the location that it is moved to so that it can be moved to
00137         this location when it is next undocked. */
00138 void MonitorWindow::moveEvent(QMoveEvent *){
00139         if(this->place() == QDockWindow::OutsideDock){
00140                 if(finishedUndockingWindow){
00141                         xPos = this->pos().x();
00142                         yPos = this->pos().y();
00143                 }
00144         }
00145 }
00146 
00147 
00148 /*! Stores the size that it is resized to so that it can be resized
00149         correctly when it is next undocked. */
00150 void MonitorWindow::resizeEvent(QResizeEvent *){
00151         //Store the current width and height if it has been resized outside of the dock
00152         if(this->place() == QDockWindow::OutsideDock){
00153                 if(finishedUndockingWindow){
00154                         windowWidth = this->size().width();
00155                         windowHeight = this->size().height();
00156                 }
00157         }
00158 }
00159 
00160 
00161 //-------------------------------------------------------------------------
00162 //----------------------------- SLOTS -------------------------------------
00163 //-------------------------------------------------------------------------
00164 
00165 /*! Called when the window's place changes and moves and resizes
00166         the window based on stored values. Otherwise default values
00167         are used for the window. */
00168 void MonitorWindow::windowPlaceChanged(QDockWindow::Place place){
00169         if(place == QDockWindow::OutsideDock){
00170                 //Move and resize window
00171                 resize(windowWidth, windowHeight);
00172                 move(xPos, yPos);
00173 
00174                 //Record if undocking is complete
00175                 if(!finishedUndockingWindow)
00176                         finishedUndockingWindow = true;
00177         }
00178         else
00179                 finishedUndockingWindow = false;
00180 }
00181 
00182 
00183 /*! Controls whether the simulation manager requests spike information 
00184         for this neuron group. */
00185 void MonitorWindow::windowVisibilityChanged(bool newVisibility){
00186         /* Only change the monitoring if the visibility has actually changed
00187                 Otherwise get this method called even when windows are hidden. */
00188         if(newVisibility == oldVisibility)
00189                 return;
00190         oldVisibility = newVisibility;
00191 
00192         //Double check that this is not being called in archive mode.
00193         if(!simulationMode){
00194                 cerr<<"MonitorWindow: THIS SHOULD NOT BE CALLED IN ARCHIVE MODE"<<endl;
00195                 return;
00196         }
00197         //Control the monitoring depending on whether this window is visible or not
00198         if(newVisibility){
00199                 simulationManager->monitorNeuronGroup(neuronGrpID, monitorNeurons);
00200         }
00201         else{
00202                 simulationManager->stopMonitoringNeuronGroup(neuronGrpID, monitorNeurons);
00203         }
00204 }
00205 
00206 

Generated on Mon Sep 3 22:29:04 2007 for SpikeStream Application by  doxygen 1.4.4