00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef TRACEVIEW_H
00019 #define TRACEVIEW_H
00020
00021
00022 #include <qwidget.h>
00023 #include <qpixmap.h>
00024 #include <qdict.h>
00025 #include <qpair.h>
00026 #include <qimage.h>
00027
00028
00029 #include "baseframe.h"
00030 #include "tracesprovider.h"
00031 #include "eventdata.h"
00032
00033
00034 #include <kstatusbar.h>
00035
00036
00037 #include <math.h>
00038
00039
00040 class ChannelColors;
00041 class ItemColors;
00042 class ClustersProvider;
00043 class EventsProvider;
00044
00050 class TraceView : public BaseFrame {
00051 Q_OBJECT
00052 public:
00086 TraceView(TracesProvider& tracesProvider,bool greyScale,bool multiColumns,bool verticalLines,
00087 bool raster,bool waveforms,bool labelsDisplay,QValueList<int>& channelsToDisplay,int unitGain,int acquisitionGain,long start,long timeFrameWidth,
00088 ChannelColors* channelColors,QMap<int, QValueList<int> >* groupsChannels,QMap<int,int>* channelsGroups,
00089 QValueList<int>& channelOffsets,QValueList<int>& gains,const QValueList<int>& skippedChannels, int rasterHeight,QImage backgroundImage,QWidget* parent=0, const char* name=0,QColor backgroundColor = Qt::black,KStatusBar* statusBar = 0L,
00090 int minSize = 500, int maxSize = 4000, int windowTopLeft = -500,int windowBottomRight = 1001, int border = 0);
00091
00092
00093
00094 ~TraceView();
00095
00101 enum {SELECT = ZOOM+1,MEASURE = ZOOM+2,SELECT_TIME = ZOOM+3,SELECT_EVENT = ZOOM+4,ADD_EVENT = ZOOM+5,DRAW_LINE = ZOOM+6};
00102
00103
00108 void setMultiColumns(bool multiple);
00109
00113 void setClusterVerticalLines(bool lines);
00114
00118 void setClusterRaster(bool raster);
00119
00123 void setClusterWaveforms(bool waveforms);
00124
00125
00129 void setGreyScale(bool grey);
00130
00135 void displayTimeFrame(long start,long timeFrameWidth);
00136
00141 void showChannels(const QValueList<int>& channelsToShow);
00142
00145 void increaseAllAmplitude();
00146
00149 void decreaseAllAmplitude();
00150
00154 void increaseSelectedChannelsAmplitude(const QValueList<int>& channelIds);
00155
00159 void decreaseSelectedChannelsAmplitude(const QValueList<int>& channelIds);
00160
00165 void setGains(int gain,int acquisitionGain);
00166
00171 void channelColorUpdate(int channelId,bool active);
00172
00177 inline void groupColorUpdate(int groupId,bool active){
00178
00179 drawContentsMode = REDRAW ;
00180 if(active) update();
00181 };
00182
00184 inline void updateDrawing(){
00185 if(retrieveClusterData) updateClusterData(true);
00186 else{
00187
00188 drawContentsMode = REDRAW ;
00189 update();
00190 }
00191 };
00192
00197 void groupsModified(bool active);
00198
00203 inline void setMode(BaseFrame::Mode selectedMode,bool active){
00204 Mode previousMode = mode;
00205 mode = selectedMode;
00206 if(selectedMode == SELECT){
00207 setCursor(selectCursor);
00208 drawRubberBand(false);
00209 }
00210 if(selectedMode == SELECT_EVENT){
00211 setCursor(selectEventCursor);
00212 drawRubberBand(false);
00213 }
00214 if(selectedMode == ADD_EVENT){
00215 setCursor(addEventCursor);
00216 drawRubberBand(false);
00217 }
00218 if(selectedMode == ZOOM){
00219 setCursor(zoomCursor);
00220 drawRubberBand(false);
00221 }
00222 if(selectedMode == MEASURE){
00223 drawRubberBand(true);
00224 setCursor(measureCursor);
00225 }
00226 if(selectedMode == SELECT_TIME){
00227 drawRubberBand(true,true);
00228 setCursor(selectTimeCursor);
00229 }
00230 if(selectedMode == DRAW_LINE){
00231 setCursor(drawLineCursor);
00232 drawRubberBand(false);
00233 }
00234 if(previousMode == SELECT){
00235 selectedChannels.clear();
00236 drawContentsMode = REDRAW;
00237 if(active) update();
00238 }
00239 if(previousMode == SELECT_EVENT){
00240 selectedEvent.first = "";
00241 selectedEvent.second = 0;
00242 drawContentsMode = REDRAW;
00243 if(active) update();
00244 }
00245 if(previousMode == ADD_EVENT){
00246 newEventPosition = -1;
00247 }
00248 if(previousMode == DRAW_LINE){
00249 linePositions.clear();
00250 }
00251 };
00252
00256 void selectChannels(const QValueList<int>& selectedIds);
00257
00261 void resetOffsets(const QMap<int,int>& selectedChannelDefaultOffsets);
00262
00266 void resetGains(const QValueList<int>& selectedChannels);
00267
00269 void reset();
00270
00274 void showHideLabels(bool show);
00275
00280 inline void showCalibration(bool show,bool active){
00281 drawContentsMode = REDRAW;
00282 showCalibrationScale = show;
00283 if(active) update();
00284 };
00285
00298 void addClusterProvider(ClustersProvider* clustersProvider,QString name,ItemColors* clusterColors,
00299 bool active,QValueList<int>& clustersToShow,QMap<int, QValueList<int> >* displayGroupsClusterFile,
00300 QMap<int,int>* channelsSpikeGroups,int nbSamplesBefore,int nbSamplesAfter,const QValueList<int>& clustersToSkip);
00301
00306 void removeClusterProvider(QString name,bool active);
00307
00314 void showClusters(QString name,QValueList<int>& clustersToShow);
00315
00321 void clusterColorUpdate(QString name,int clusterId,bool active);
00322
00323
00332 void addEventProvider(EventsProvider* eventsProvider,QString name,ItemColors* eventColors,
00333 bool active,QValueList<int>& eventsToShow,const QValueList<int>& eventsToSkip);
00334
00339 void removeEventProvider(QString name,bool active);
00340
00347 void showEvents(QString name,QValueList<int>& eventsToShow);
00348
00354 void eventColorUpdate(QString name,int eventId,bool active);
00355
00362 void print(QPainter& printPainter,QPaintDeviceMetrics& metrics,bool whiteBackground);
00363
00365 void showNextEvent();
00366
00368 void showPreviousEvent();
00369
00374 inline void updateEvents(QString providerName,bool active){
00375 if(!eventProvidersToUpdate.contains(providerName)) eventProvidersToUpdate.append(providerName);
00376 if(active) update();
00377 };
00378
00384 void updateEvents(QString providerName,QValueList<int>& eventsToShow,bool active);
00385
00388 void removeEvent();
00389
00391 void showNextCluster();
00392
00394 void showPreviousCluster();
00395
00400 void updateNoneBrowsingEventList(QString providerName,const QValueList<int>& eventsToNotBrowse);
00401
00406 void updateNoneBrowsingClusterList(QString providerName,const QValueList<int>& clustersToNotBrowse);
00407
00413 void updateWaveformInformation(int nbSamplesBefore,int nbSamplesAfter,bool active);
00414
00419 inline void samplingRateModified(long long length){
00420 recordingLength = length;
00421 int samplingRate = tracesProvider.getSamplingRate();
00422 timeStepUnit = timeStep = static_cast<float>(static_cast<float>(1000) / static_cast<float>(samplingRate));
00423 };
00424
00428 void updateClusterData(bool active);
00429
00437 void updateClusters(QString name,QValueList<int>& clustersToShow,ItemColors* clusterColors,bool active);
00438
00440 void increaseRatio();
00441
00443 void decreaseRatio();
00444
00450 void getCurrentEventInformation(long startTime,long endTime,QObject* initiator);
00451
00456 void traceBackgroundImageUpdate(QImage traceBackgroundImage,bool active);
00457
00458 public slots:
00463 void dataAvailable(Array<dataType>& data,QObject* initiator);
00464
00471 void dataAvailable(Array<dataType>& data,QObject* initiator,QString providerName);
00472
00479 void dataAvailable(Array<dataType>& times,Array<int>& ids,QObject* initiator,QString providerName);
00480
00489 void nextClusterDataAvailable(Array<dataType>& data,QObject* initiator,QString providerName,long startingTime,long startingTimeInRecordingUnits);
00490
00499 void previousClusterDataAvailable(Array<dataType>& data,QObject* initiator,QString providerName,long startingTime,long startingTimeInRecordingUnits);
00500
00508 void nextEventDataAvailable(Array<dataType>& times,Array<int>& ids,QObject* initiator,QString providerName,long startingTime);
00509
00517 void previousEventDataAvailable(Array<dataType>& times,Array<int>& ids,QObject* initiator,QString providerName,long startingTime);
00518
00523 inline void eventToAddProperties(QString providerName,QString eventDescription){
00524
00525
00526 if(!eventBeingModified){
00527 eventDescriptionToCreate = eventDescription;
00528 eventProvider = providerName;
00529 }
00530 };
00531
00535 void skipStatusChanged(const QValueList<int>& skippedChannels);
00536
00540 inline int getRasterHeight(){return rasterHeight;};
00541
00542
00543 signals:
00544 void channelsSelected(const QValueList<int>& selectedIds);
00545 void setStartAndDuration(long time,long duration);
00546 void eventModified(QString providerName,int selectedEventId,double time,double newTime);
00547 void eventRemoved(QString providerName,int selectedEventId,double time);
00548 void eventAdded(QString providerName,QString addedEventDescription,double time);
00549 void eventsAvailable(QDict<EventData>& eventsData,QMap<QString, QValueList<int> >& selectedEvents,QDict<ItemColors>& providerItemColors,QObject* initiator,double samplingRate);
00550
00551 protected:
00556 void drawContents(QPainter* painter);
00557
00562 void mouseMoveEvent(QMouseEvent* event);
00563
00568 inline void resizeEvent(QResizeEvent* event){
00569 drawContentsMode = REDRAW;
00570 resized = true;
00571 };
00572
00576 void mousePressEvent(QMouseEvent* event);
00577
00581 void mouseReleaseEvent(QMouseEvent* event);
00582
00586 void mouseDoubleClickEvent(QMouseEvent* event);
00587
00588 private:
00589
00591 bool greyScaleMode;
00592
00594 KStatusBar* statusBar;
00595
00597 TracesProvider& tracesProvider;
00598
00600 bool multiColumns;
00601
00603 bool verticalLines;
00604
00606 bool raster;
00607
00609 bool waveforms;
00610
00612 QValueList<int> shownChannels;
00613
00615 bool dataReady;
00616
00618 Array<dataType> data;
00619
00621 QValueList<int>& channelOffsets;
00622
00626 QValueList<float> channelFactors;
00627
00631 QValueList<int>& gains;
00632
00634 int traceVspace;
00635
00637 int nbChannels;
00638
00640 int peakPositionInWaveform;
00641
00643 int nbSamplesInWaveform;
00644
00646 long startTime;
00647
00649 long endTime;
00650
00652 ChannelColors* channelColors;
00653
00657 QMap<int, QValueList<int> >* groupsChannels;
00658
00661 QMap<int,int>* channelsGroups;
00662
00665 QMap<int, QValueList<int> > shownGroupsChannels;
00666
00668 long abscissaMin;
00669
00671 long abscissaMax;
00672
00674 long ordinateMin;
00675
00677 long ordinateMax;
00678
00680 int borderX;
00681
00683 int borderY;
00684
00686 int Yshift;
00687
00689 int Xshift;
00690
00692 int Xstep;
00693
00695 int XGroupSpace;
00696
00698 int Yspace;
00699
00701 int YGroupSpace;
00702
00704 int YTracesRasterSeparator;
00705
00707 int YRasterSpace;
00708
00711 long X0;
00712
00715 long Y0;
00716
00718 long Y0Raster;
00719
00724 QPixmap doublebuffer;
00725
00727 QImage background;
00728
00730 QPixmap scaledBackground;
00731
00732
00734 float timeStep;
00735
00737 float timeStepUnit;
00738
00740 int acquisitionGain;
00741
00743 int unitGain;
00744
00749 float alpha;
00750
00753 QValueList<float> channelDisplayGains;
00754
00755 int nbClusters;
00756
00758 int rasterHeight;
00759
00761 long timeFrameWidth;
00762
00764 QMap<int,int> channelsStartingOrdinate;
00765
00767 QMap<int,int> channelsStartingAbscissa;
00768
00771 static const int XMARGIN;
00772
00775 static const int YMARGIN;
00776
00779 int xMargin;
00780
00783 int yMargin;
00784
00786 bool columnDisplayChanged;
00787
00789 bool resized;
00790
00792 QValueList<int> selectedChannels;
00793
00795 bool groupsChanged;
00796
00798 int previousDragOrdinate;
00799
00801 int lastClickOrdinate;
00802
00803
00804 bool nbSamplesModified;
00805
00806
00807 bool alreadySelected;
00808
00810 bool isInit;
00811
00813 int screenResolution;
00814
00816 int channelforVoltageComputation;
00817
00819 int startingIndex;
00820
00822 QCursor selectCursor;
00823
00825 QCursor measureCursor;
00826
00828 QCursor selectTimeCursor;
00829
00831 QCursor selectEventCursor;
00832
00834 QCursor addEventCursor;
00835
00837 QCursor drawLineCursor;
00838
00842 bool showLabels;
00843
00847 bool showCalibrationScale;
00848
00849
00853 float downSampling;
00854
00856 bool zoomed;
00857
00858
00859 bool firstZoom;
00860
00861
00862
00863 bool doubleClick;
00864
00866 float initialDownSampling;
00867
00869 float zoomFactor;
00870
00871
00872 bool maxZoomReached;
00873
00874
00875 bool zoomOut;
00876
00878 QRect initialWindow;
00879
00881 QRect previousWindow;
00882
00884 int traceWidth;
00885
00887 int initialXGroupSpace;
00888
00890 int initialXshift;
00891
00893 int initialTraceWidth;
00894
00896 QMap<int, QValueList<int> > selectedClusters;
00897
00899 struct ClusterData{
00900 Array<dataType> data;
00901 bool ready;
00902
00903 ClusterData(Array<dataType> d,bool status){
00904 data = d;
00905 ready = status;
00906 };
00907 ClusterData(){
00908 ready = false;
00909 };
00910 void setStatus(bool status){ready = status;};
00911 void setData(Array<dataType>& d){data = d;};
00912 bool status(){return ready;};
00913 Array<dataType>& getData(){return data;};
00914
00915 ~ClusterData(){};
00916 };
00917
00919 QDict<ClusterData> clustersData;
00920
00922 QDict<ClustersProvider> clusterProviders;
00923
00925 QDict<ItemColors> providerItemColors;
00926
00930 QValueList<QString> clustersOrder;
00931
00933 QValueList<int> rasterOrdinates;
00934
00936 QValueList<int> rasterAbscisses;
00937
00943 QMap<int, QValueList<int> >* groupClusterFiles;
00944
00945
00946 QMap<int,int>* channelClusterFiles;
00947
00948
00949 int nbSamplesBefore;
00950
00951
00952 int nbSamplesAfter;
00953
00954
00955 bool printState;
00956
00958 QMap<QString, QValueList<int> > selectedEvents;
00959
00962 QPair<QString,long> nextClusterProvider;
00963
00966 QPair<QString,long> previousClusterProvider;
00967
00969 QString clusterProviderToSkip;
00970
00974 long startTimeInRecordingUnits;
00975
00979 long previousStartTimeInRecordingUnits;
00980
00982 bool spikeBrowsing;
00983
00985 QDict<EventData> eventsData;
00986
00988 QDict<EventsProvider> eventProviders;
00989
00992 QPair<QString,long> nextEventProvider;
00993
00996 QPair<QString,long> previousEventProvider;
00997
00999 QString eventProviderToSkip;
01000
01002 long long recordingLength;
01003
01005 QPair<QString,int> selectedEvent;
01006
01008 int previousDragAbscissa;
01009
01011 int lastClickAbscissa;
01012
01014 QValueList<int> selectedEventPosition;
01015
01017 bool startEventDragging;
01018
01021 QValueList<QString> eventProvidersToUpdate;
01022
01024 int newEventPosition;
01025
01027 QString eventDescriptionToCreate;
01028
01030 QString eventProvider;
01031
01033 bool eventBeingModified;
01034
01036 QMap<QString, QValueList<int> > clustersNotUsedForBrowsing;
01037
01039 QMap<QString, QValueList<int> > eventsNotUsedForBrowsing;
01040
01041 bool retrieveClusterData;
01042
01043
01044 QValueList<int> skippedChannels;
01045
01046
01047 QValueList<int> linePositions;
01048
01049
01050
01052 void updateWindow();
01053
01058 void updateShownGroupsChannels(const QValueList<int>& channelsToShow);
01059
01064 void drawTraces(QPainter& painter);
01065
01071 void drawTraces(QValueList<int> channels,bool highlight);
01072
01085 void drawTrace(QPainter& painter,int limit,int basePosition,int X,int channelId,int nbSamplesToDraw,bool mouseMoveEvent = false);
01086
01090 void drawChannelIdsAndGain(QPainter& painter);
01091
01093 void computeChannelDisplayGain();
01094
01098 void computeChannelDisplayGain(const QValueList<int>& selectedChannels);
01099
01103 void drawCalibrationScale(QPainter& painter);
01104
01108 void correctZoom(QRect& r);
01109
01110
01117 void drawEvent(QString providerName,int selectedEventId,dataType selectedEventIndex,bool highlight);
01118
01124 void drawTimeLine(int x,bool initialLine,bool eraseLine = false);
01125
01127 void scaleBackgroundImage();
01128
01129 };
01130
01131 #endif