00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef NEUROSCOPEDOC_H
00019 #define NEUROSCOPEDOC_H
00020
00021 #ifdef HAVE_CONFIG_H
00022 #include <config.h>
00023 #endif
00024
00025
00026 #include <qobject.h>
00027 #include <qstring.h>
00028 #include <qptrlist.h>
00029 #include <qpair.h>
00030
00031
00032 #include <kurl.h>
00033
00034
00035 #include "channelpalette.h"
00036 #include "dataprovider.h"
00037 #include "eventsprovider.h"
00038
00039
00040
00041 class NeuroscopeView;
00042 class NeuroscopeApp;
00043 class ChannelColors;
00044 class TracesProvider;
00045 class NeuroscopeXmlReader;
00046 class ItemColors;
00047 class ItemPalette;
00048
00059 class NeuroscopeDoc : public QObject
00060 {
00061 Q_OBJECT
00062
00063 private:
00065 KURL docUrl;
00066
00068 KURL sessionUrl;
00069
00071 KURL parameterUrl;
00072
00074 ChannelPalette& displayChannelPalette;
00075
00077 ChannelPalette& spikeChannelPalette;
00078
00080 int channelNb;
00081
00083 double samplingRate;
00084
00086 int initialOffset;
00087
00089 int gain;
00090
00092 int acquisitionGain;
00093
00095 float screenGain;
00096
00098 int voltageRange;
00099
00101 int amplification;
00102
00104 int resolution;
00105
00107 int resolutionDefault;
00108
00110 int channelNbDefault;
00111
00113 double datSamplingRateDefault;
00114
00116 double eegSamplingRateDefault;
00117
00119 double videoSamplingRateDefault;
00120
00122 int initialOffsetDefault;
00123
00125 int gainDefault;
00126
00128 int acquisitionGainDefault;
00129
00131 float screenGainDefault;
00132
00134 int voltageRangeDefault;
00135
00137 int amplificationDefault;
00138
00140 QMap<int,int> displayChannelsGroups;
00141
00143 QMap<int, QValueList<int> > displayGroupsChannels;
00144
00146 QMap<int,int> channelsSpikeGroups;
00147
00149 QMap<int, QValueList<int> > spikeGroupsChannels;
00150
00152 bool isCommandLineProperties;
00153
00155 ChannelColors* channelColorList;
00156
00157
00158 QMap<int,int> channelDefaultOffsets;
00159
00161 TracesProvider* tracesProvider;
00162
00164 QWidget* parent;
00165
00167 QString baseName;
00168
00170 double datSamplingRate;
00171
00173 double eegSamplingRate;
00174
00176 double videoSamplingRate;
00177
00179 int nbSamples;
00180
00182 int peakSampleIndex;
00183
00185 int nbSamplesDefault;
00186
00188 int peakSampleIndexDefault;
00189
00191 float waveformLength;
00192
00194 float indexLength;
00195
00197 float waveformLengthDefault;
00198
00200 float indexLengthDefault;
00201
00203 QDict<DataProvider> providers;
00204
00206 QMap<QString,KURL> providerUrls;
00207
00209 QString lastLoadedProvider;
00210
00212 QDict<ItemColors> providerItemColors;
00213
00219 QMap<QString,double> extensionSamplingRates;
00220
00226 QMap<int, QValueList<int> > displayGroupsClusterFile;
00227
00229 QString extension;
00230
00231
00232 int lastEventProviderGridX;
00233
00235 int eventPosition;
00236
00238 int clusterPosition;
00239
00241 QString undoRedoProviderName;
00242
00244 int undoRedoEventId;
00245
00247 double modifiedEventTime;
00248
00250 double undoRedoEventTime;
00251
00253 bool newEventDescriptionCreated;
00254
00256 QPair<QString,QString> removedDescription;
00257
00259 int videoWidthDefault;
00261 int videoHeightDefault;
00263 QString backgroundImageDefault;
00264
00266 QString traceBackgroundImageDefault;
00267
00269 int rotationDefault;
00272 int flipDefault;
00273
00275 int videoWidth;
00277 int videoHeight;
00279 QString backgroundImage;
00280
00282 QString traceBackgroundImage;
00283
00285 int rotation;
00289 int flip;
00290
00292 QImage transformedBackground;
00293
00295 bool drawPositionsOnBackground;
00296
00298 bool drawPositionsOnBackgroundDefault;
00299
00301 bool positionFileOpenOnce;
00302
00304 QString positionFileExtension;
00305
00307 QMap<int,bool> skipStatus;
00308
00310 double upsamplingRate;
00311
00312
00313
00317 void loadSession(NeuroscopeXmlReader reader);
00318
00322 void loadDocumentInformation(NeuroscopeXmlReader reader);
00323
00325 void computeClusterFilesMapping();
00326
00332 QImage transformBackgroundImage(bool useWhiteBackground = false);
00333
00334 public:
00335
00337 enum OpenSaveCreateReturnMessage {OK=0,OPEN_ERROR=1,DOWNLOAD_ERROR=3,INCORRECT_FILE=4,SAVE_ERROR=5,
00338 UPLOAD_ERROR=6,INCORRECT_CONTENT=7,CREATION_ERROR=8,PARSE_ERROR=9,MISSING_FILE=10,
00339 ALREADY_OPENED=11,NOT_WRITABLE=12};
00340
00366 NeuroscopeDoc(QWidget* parent,ChannelPalette& displayChannelPalette,ChannelPalette& spikeChannelPalette,int channelNbDefault,double datSamplingRateDefault,
00367 double eegSamplingRateDefault, int initialOffset,int voltageRangeDefault,int amplificationDefault,float screenGainDefault,int resolutionDefault,
00368 int eventPosition,int clusterPosition,int nbSamples, int peakSampleIndex,double videoSamplingRate, int width, int height, QString backgroundImage, QString traceBackgroundImage,
00369 int rotation,int flip,bool positionsBackground);
00371 ~NeuroscopeDoc();
00372
00374 void addView(NeuroscopeView* view);
00375
00377 void removeView(NeuroscopeView* view);
00378
00380 void closeDocument();
00381
00386 int openDocument(const KURL& url);
00387
00392 OpenSaveCreateReturnMessage saveSession();
00393
00397 int saveEventFiles();
00398
00403 inline OpenSaveCreateReturnMessage saveSession(KURL newSessionUrl){
00404 sessionUrl = newSessionUrl;
00405 return saveSession();
00406 };
00407
00413 OpenSaveCreateReturnMessage createEventFile(KURL eventUrl,NeuroscopeView*activeView);
00414
00416 const KURL& url() const;
00417
00419 void setURL(const KURL& url);
00420
00425 void singleChannelColorUpdate(int channelId,NeuroscopeView* activeView);
00426
00432 void clusterColorUpdate(QString providerName,int clusterId,NeuroscopeView* activeView);
00433
00439 void eventColorUpdate(QString providerName,int eventId,NeuroscopeView* activeView);
00440
00445 void channelGroupColorUpdate(int groupId,NeuroscopeView* activeView);
00446
00451
00452
00457 void groupsModified(NeuroscopeView* activeView);
00458
00462 void setBackgroundColor(QColor backgroundColor);
00463
00467 void setTraceBackgroundImage(QString traceBackgroundImagePath);
00468
00470 void setInitialOffset(int offset);
00471
00477 void setGains(int voltageRange,int amplification,float screenGain);
00478
00482 void setResolution(int resolution);
00483
00487 void setSamplingRate(double rate);
00488
00493 void setAcquisitionSystemSamplingRate(double rate);
00494
00498 void setChannelNb(int nb);
00499
00503 inline int getInitialOffset()const{return initialOffset;};
00504
00508 inline int getAcquisitionGain()const{return acquisitionGain;};
00509
00513 inline int getGain()const{return gain;};
00514
00518 inline int getVoltageRange()const{return voltageRange;};
00519
00523 inline int getAmplification()const{return amplification;};
00524
00528 inline float getScreenGain()const{return screenGain;};
00529
00533 inline int getResolution()const{return resolution;};
00534
00538 inline double getSamplingRate()const{return samplingRate;};
00539
00540
00544 inline double getAcquisitionSystemSamplingRate()const{return datSamplingRate;};
00545
00550 inline bool getPositionsBackground()const{return drawPositionsOnBackground;};
00551
00552
00558 inline void setDefaultGains(int voltageRangeDefault,int amplificationDefault,float screenGainDefault){
00559 acquisitionGainDefault = static_cast<int>(0.5 +
00560 static_cast<float>(pow(static_cast<double>(2),static_cast<double>(resolutionDefault))
00561 / static_cast<float>(voltageRangeDefault * 1000))
00562 * amplificationDefault);
00563
00564 gainDefault = static_cast<int>(0.5 + screenGainDefault * acquisitionGainDefault);
00565 this->voltageRangeDefault = voltageRangeDefault;
00566 this->amplificationDefault = amplificationDefault;
00567 this->screenGainDefault = screenGainDefault;
00568 };
00569
00573 inline void setVoltageRange(int range){
00574 voltageRange = range;
00575 acquisitionGain = static_cast<int>(0.5 +
00576 static_cast<float>(pow(static_cast<double>(2),static_cast<double>(resolution))
00577 / static_cast<float>(voltageRange * 1000))
00578 * amplification);
00579
00580 gain = static_cast<int>(0.5 + screenGain * acquisitionGain);
00581 };
00582
00586 inline void setAmplification(int amplification){
00587 this->amplification = amplification;
00588 acquisitionGain = static_cast<int>(0.5 +
00589 static_cast<float>(pow(static_cast<double>(2),static_cast<double>(resolution))
00590 / static_cast<float>(voltageRange * 1000))
00591 * amplification);
00592
00593 gain = static_cast<int>(0.5 + screenGain * acquisitionGain);
00594 };
00595
00599 inline void setScreenGain(float gain){
00600 screenGain = gain;
00601 acquisitionGain = static_cast<int>(0.5 +
00602 static_cast<float>(pow(static_cast<double>(2),static_cast<double>(resolution))
00603 / static_cast<float>(voltageRange * 1000))
00604 * amplification);
00605
00606 gain = static_cast<int>(0.5 + screenGain * acquisitionGain);
00607 };
00608
00612 inline void setDefaultInitialOffset(int offset){initialOffsetDefault = offset;};
00613
00617 inline void setDefaultResolution(int resolution){resolutionDefault = resolution;};
00618
00622 inline void setDefaultEegSamplingRate(double rate){eegSamplingRateDefault = rate;};
00623
00627 inline void setDefaultDatSamplingRate(double rate){datSamplingRateDefault = rate;};
00628
00632 inline void setDefaultChannelNb(int nb){channelNbDefault = nb;};
00633
00637 inline void setDefaultTraceBackgroundImage(QString traceBackgroundImagePath){
00638 traceBackgroundImageDefault = traceBackgroundImagePath;
00639 }
00640
00642 inline void propertiesFromCommandLine(){isCommandLineProperties = true;};
00643
00647 inline ChannelColors* channelColors() const {return channelColorList;} ;
00648
00652 inline TracesProvider& tracesDataProvider() const {return *tracesProvider;};
00653
00656 inline QMap<int,int>* getDisplayChannelsGroups() {return &displayChannelsGroups;};
00657
00660 inline QMap<int, QValueList<int> >* getDisplayGroupsChannels() {return &displayGroupsChannels;};
00661
00664 inline QMap<int,int>* getChannelsSpikeGroups() {return &channelsSpikeGroups;};
00665
00668 inline QMap<int, QValueList<int> >* getSpikeGroupsChannels() {return &spikeGroupsChannels;};
00669
00674 void selectAllChannels(NeuroscopeView& activeView,bool editMode);
00675
00680 void deselectAllChannels(NeuroscopeView& activeView,bool editMode);
00681
00684 void synchronize();
00685
00708 inline void updateFileProperties(int channelNb,double SR,int resolution,int offset,int voltageRange,int amplification,
00709 float screenGain,int newNbSamples,int newPeakSampleIndex,double videoSamplingRate,
00710 int width, int height, QString backgroundImage, QString traceBackgroundImage,int rotation,int flip,double acquisitionSystemSamplingRate,
00711 bool positionsBackground){
00712 this->channelNb = channelNb;
00713 if(extension != "dat") samplingRate = SR;
00714 else samplingRate = acquisitionSystemSamplingRate;
00715 datSamplingRate = acquisitionSystemSamplingRate;
00716 this->voltageRange = voltageRange;
00717 this->amplification = amplification;
00718 this->screenGain = screenGain;
00719 this->resolution = resolution;
00720 initialOffset = offset;
00721 nbSamples = newNbSamples;
00722 peakSampleIndex = newPeakSampleIndex;
00723 this->videoSamplingRate = videoSamplingRate;
00724 videoWidth = width;
00725 videoHeight = height;
00726 this->backgroundImage = backgroundImage;
00727 this->traceBackgroundImage = traceBackgroundImage;
00728 this->rotation = rotation;
00729 this->flip = flip;
00730 drawPositionsOnBackground = positionsBackground;
00731
00732 acquisitionGain = static_cast<int>(0.5 +
00733 static_cast<float>(pow(static_cast<double>(2),static_cast<double>(resolution))
00734 / static_cast<float>(voltageRange * 1000))
00735 * amplification);
00736
00737 gain = static_cast<int>(0.5 + screenGain * acquisitionGain);
00738 };
00739
00741 inline bool isCurrentFileAdatFile(){
00742 if(extension == "dat") return true;
00743 else return false;
00744 };
00745
00747 inline QString documentBaseName(){return baseName;};
00748
00750 QString sessionPath() const;
00751
00753 long long recordingLength();
00754
00758 bool isADocumentToClose();
00759
00763 void setNoneEditMode(NeuroscopeView* activeView);
00764
00771 bool canCloseDocument(NeuroscopeApp* mainWindow,QString callingMethod);
00772
00778 void showCalibration(bool show,NeuroscopeView* activeView);
00779
00782 inline QString lastLoadedProviderName(){return lastLoadedProvider;};
00783
00787 inline ItemColors* providerColorList(QString fileName){return providerItemColors[fileName];};
00788
00794 OpenSaveCreateReturnMessage loadClusterFile(KURL clusterUrl,NeuroscopeView* activeView);
00795
00803 OpenSaveCreateReturnMessage loadClusterFile(KURL clusterUrl,QMap<EventDescription,QColor>& itemColors,QDateTime lastModified,bool firstFile);
00804
00805
00811 OpenSaveCreateReturnMessage loadPositionFile(KURL url,NeuroscopeView*activeView);
00812
00817 OpenSaveCreateReturnMessage loadPositionFile(QString filePath);
00818
00824 void removeClusterFile(QString providerName,NeuroscopeView* activeView);
00825
00831 OpenSaveCreateReturnMessage loadEventFile(KURL eventUrl,NeuroscopeView* activeView);
00832
00840 OpenSaveCreateReturnMessage loadEventFile(KURL eventUrl,QMap<EventDescription,QColor>& itemColors,QDateTime lastModified,bool firstFile);
00841
00848 void removeEventFile(QString providerName,NeuroscopeView* activeView,bool lastFile);
00849
00853 void setProviders(NeuroscopeView* activeView);
00854
00861 void showAllClustersExcept(ItemPalette* clusterPalette,NeuroscopeView* activeView,QValueList<int> clustersToHide);
00862
00867 void deselectAllClusters(ItemPalette* clusterPalette,NeuroscopeView* activeView);
00868
00869
00874 void showAllEvents(ItemPalette* eventPalette,NeuroscopeView* activeView);
00875
00880 void deselectAllEvents(ItemPalette* eventPalette,NeuroscopeView* activeView);
00881
00883 inline int getLastEventProviderGridX() const {return lastEventProviderGridX;};
00884
00886 void setEventPosition(int position);
00887
00889 void setClusterPosition(int position);
00890
00898 void eventModified(QString providerName,int selectedEventId,double time,double newTime,NeuroscopeView* activeView);
00899
00906 void eventRemoved(QString providerName,int selectedEventId,double time,NeuroscopeView* activeView);
00907
00911 void undo(NeuroscopeView* activeView);
00912
00916 void redo(NeuroscopeView* activeView);
00917
00924 void eventAdded(QString providerName,QString addedEventDescription,double time,NeuroscopeView* activeView);
00925
00926
00931 QValueList<EventDescription> eventIds(QString providerName);
00932
00933
00939 void setWaveformInformation(int nb,int index,NeuroscopeView* activeView);
00940
00941
00946 inline void setDefaultWaveformInformation(int nb,int index){
00947 nbSamplesDefault = nb;
00948 peakSampleIndexDefault = index;
00949 };
00950
00952 inline int getNbSamples()const{return nbSamples;};
00953
00955 inline int getPeakIndex()const{return peakSampleIndex;};
00956
00957
00968 void setPositionInformation(double videoSamplingRate, int width, int height, QString backgroundImage,
00969 int rotation,int flip,bool positionsBackground,NeuroscopeView* activeView);
00970
00980 void setDefaultPositionInformation(double videoSamplingRate, int width, int height, QString backgroundImage,int rotation,int flip,bool positionsBackground);
00981
00985 inline double getVideoSamplingRate()const{return videoSamplingRate;};
00986
00990 inline int getChannelNb()const{return channelNb;};
00991
00995 inline int getWidth()const{return videoWidth;};
00996
01000 inline int getHeight()const{return videoHeight;};
01001
01005 inline QString getBackgroundImage()const{return backgroundImage;};
01006
01010 inline QString getTraceBackgroundImage()const{return traceBackgroundImage;};
01011
01015 inline int getRotation()const{return rotation;};
01016
01021 inline int getFlip()const{return flip;};
01022
01027 void removePositionFile(NeuroscopeView* activeView);
01028
01033 void addPositionView(NeuroscopeView* activeView,QColor backgroundColor);
01034
01035 class CloseDocumentEvent;
01036 friend class CloseDocumentEvent;
01037
01038 inline CloseDocumentEvent* getCloseDocumentEvent(QString origin){
01039 return new CloseDocumentEvent(origin);
01040 };
01041
01046 class CloseDocumentEvent : public QCustomEvent{
01047
01048
01049 friend CloseDocumentEvent* NeuroscopeDoc::getCloseDocumentEvent(QString origin);
01050
01051 public:
01052 inline QString methodOfOrigin(){return origin;};
01053 inline ~CloseDocumentEvent(){};
01054
01055 private:
01056 CloseDocumentEvent(QString origin):QCustomEvent(QEvent::User + 200),origin(origin){};
01057
01058 QString origin;
01059 };
01060
01061
01067 inline QImage getWhiteTrajectoryBackground(){
01068 if(!drawPositionsOnBackground) return QImage();
01069 return transformBackgroundImage(true);
01070 };
01071
01072
01077 void updateSkippedChannelColors(bool whiteBackground,QColor backgroundColor);
01078
01080 void updateSkipStatus();
01081
01082
01083
01084
01085 void setDefaultOffsets(NeuroscopeView* activeView);
01086
01088 void resetDefaultOffsets();
01089
01091 inline const QMap<int,int>& getChannelDefaultOffsets()const{return channelDefaultOffsets;};
01092
01093 public slots:
01094
01101 void slotNewEventDescriptionCreated(QString providerName,QMap<int,int> oldNewEventIds,QMap<int,int> newOldEventIds,QString eventDescriptionAdded);
01102
01110 void slotEventDescriptionRemoved(QString providerName,QMap<int,int> oldNewEventIds,QMap<int,int> newOldEventIds,int eventIdToRemove,QString eventDescriptionToRemove);
01111
01112 signals:
01117 void noSession(QMap<int,int>& channelDefaultOffsets,QMap<int,bool>& skipStatus);
01118
01139 void loadFirstDisplay(QValueList<int>* channelsToDisplay,bool verticalLines,bool raster,bool waveforms,bool showLabels,
01140 bool multipleColumns,bool greyMode,QValueList<int> offsets,QValueList<int> channelGains,
01141 QValueList<int> selectedChannels,QMap<int,bool>& skipStatus,long startTime,long duration,QString tabLabel,bool positionView,int rasterHeight,
01142 bool showEventsInPositionView);
01143
01144 public:
01146 QPtrList<NeuroscopeView>* viewList;
01147
01148
01149 };
01150
01151 #endif // NEUROSCOPEDOC_H