GeopsyGui/SignalLayer.h
Go to the documentation of this file.
00001 /***************************************************************************
00002 **
00003 **  This file is part of GeopsyGui.
00004 **
00005 **  This library is free software; you can redistribute it and/or
00006 **  modify it under the terms of the GNU Lesser General Public
00007 **  License as published by the Free Software Foundation; either
00008 **  version 2.1 of the License, or (at your option) any later version.
00009 **
00010 **  This file is distributed in the hope that it will be useful, but WITHOUT
00011 **  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00012 **  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
00013 **  License for more details.
00014 **
00015 **  You should have received a copy of the GNU Lesser General Public
00016 **  License along with this library; if not, write to the Free Software
00017 **  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00018 **
00019 **  See http://www.geopsy.org for more information.
00020 **
00021 **  Created : 2002-08-30
00022 **  Authors :
00023 **    Marc Wathelet
00024 **    Marc Wathelet (ULg, Liège, Belgium)
00025 **    Marc Wathelet (LGIT, Grenoble, France)
00026 **
00027 ***************************************************************************/
00028 
00029 #ifndef SIGNALLAYER_H
00030 #define SIGNALLAYER_H
00031 
00032 #include <GeopsyCore.h>
00033 #include <SciFigs.h>
00034 
00035 #include "GeopsyGuiDLLExport.h"
00036 
00037 namespace GeopsyGui {
00038 
00039 class SignalInt;
00040 class SubPoolWindow;
00041 
00042 class GEOPSYGUI_EXPORT SignalLayer: public GridPlot
00043 {
00044   Q_OBJECT
00045   // Compatibility
00046   Q_PROPERTY(bool smoothGrid READ dummyPropertyInt WRITE setSmooth STORED false)
00047   Q_PROPERTY(QString norm READ dummyPropertyString WRITE setNormalize STORED false)
00048   Q_PROPERTY(double normValue READ dummyPropertyDouble WRITE setNormalizeValue STORED false)
00049   Q_PROPERTY(bool useReceiverCoord READ dummyPropertyInt WRITE setReceiverYAxis STORED false)
00050 
00051   Q_PROPERTY(bool variableArea READ variableArea WRITE setVariableArea)
00052   Q_PROPERTY(bool wiggleTrace READ wiggleTrace WRITE setWiggleTrace)
00053   Q_PROPERTY(bool grid READ grid WRITE setGrid)
00054   Q_PROPERTY(double normalizeValue READ normalizeValue WRITE setNormalizeValue)
00055   Q_PROPERTY(double clipValue READ clipValue WRITE setClipValue)
00056   Q_PROPERTY(double clipPerc READ clipPerc WRITE setClipPerc)
00057   Q_PROPERTY(double overlap READ overlap WRITE setOverlap)
00058   Q_PROPERTY(QString clip READ clipString WRITE setClip)
00059   Q_PROPERTY(QString normalize READ normalizeString WRITE setNormalize)
00060   Q_PROPERTY(QString offset READ offsetString WRITE setOffset)
00061   Q_PROPERTY(QString yAxis READ yAxisString WRITE setYAxis)
00062   Q_PROPERTY(QString timeRange READ timeRangeString WRITE setTimeRange)
00063   Q_PROPERTY(QString aroundPickName READ aroundPickName WRITE setAroundPickName)
00064   Q_PROPERTY(double beforePickDelay READ beforePickDelay WRITE setBeforePickDelay)
00065   Q_PROPERTY(double afterPickDelay READ afterPickDelay WRITE setAfterPickDelay)
00066 public:
00067   SignalLayer(AxisWindow * parent=0);
00068   ~SignalLayer ();
00069 
00070   virtual const QString& xml_tagName() const {return xmlSignalLayerTag;}
00071   static const QString xmlSignalLayerTag;
00072 
00073   void subPoolUpdate(SubSignalPool * subPool=0);
00074   void signalsUpdate();
00075 
00076   void minMaxY (double& min, double& max) const;
00077   int signalAt (int yPos, double& baseDistance) const;
00078   void sigYBoundaries (int index, double overlap, QRect& bound) const;
00079 
00080   virtual Rect boundingRect() const;
00081 
00082   const SubSignalPool * subPool() const {return _subPool;}
00083 
00084   enum Normalize {NormalizeAll, NormalizeOne,
00085                    NormalizeVisibleAll, NormalizeVisibleOne,
00086                    NormalizeValue};
00087   enum Offset {NoOffset, GlobalOffset, VisibleOffset};
00088   enum Clip {NoClip, ClipOverlap, ClipValue, ClipPercentage};
00089   enum YAxis{ViewerIndex, Receiver, SignalName, Overlayed};
00090   enum TimeRange {AvailableRange, AroundPickRange, CustomRange};
00091 
00092   bool variableArea() const {return _variableArea;}
00093   void setVariableArea (bool b) {_variableArea=b;}
00094 
00095   bool wiggleTrace() const {return _wiggleTrace;}
00096   void setWiggleTrace (bool b) {_wiggleTrace=b;}
00097 
00098   bool grid() const {return _gridPlot;}
00099   void setGrid (bool b);
00100 
00101   double normalizeValue() const {return _normalizeValue;}
00102   void setNormalizeValue (double v) {_normalizeValue=v;}
00103 
00104   double clipValue() const {return _clipValue;}
00105   void setClipValue (double v) {_clipValue=v;}
00106 
00107   double clipPerc() const {return _clipPerc;}
00108   void setClipPerc (double v) {_clipPerc=v;}
00109 
00110   double overlap() const {return _overlap;}
00111   void setOverlap (double v) {_overlap=v; _signalOverlaps.clear();}
00112 
00113   Normalize normalize() const {return _normalize;}
00114   void setNormalize (Normalize n) {_normalize=n;}
00115   QString normalizeString() const;
00116   void setNormalize (QString n);
00117 
00118   Offset offset() const {return _offset;}
00119   void setOffset (Offset o) {_offset=o;}
00120   QString offsetString() const;
00121   void setOffset (QString n);
00122 
00123   Clip clip() const {return _clip;}
00124   void setClip (Clip c) {_clip=c;}
00125   QString clipString() const;
00126   void setClip (QString c);
00127 
00128   YAxis yAxis() const {return _yAxis;}
00129   QString yAxisString() const;
00130   void setYAxis(YAxis a) {_yAxis=a;}
00131   void setYAxis(QString a);
00132   // Compatibility
00133   void setReceiverYAxis(bool rc) {_yAxis=rc ? Receiver : ViewerIndex;}
00134 
00135   TimeRange timeRange() const {return _timeRange;}
00136   QString timeRangeString() const;
00137   void setTimeRange(TimeRange tr) {_timeRange=tr;}
00138   void setTimeRange(QString tr);
00139 
00140   const QString& aroundPickName() const {return _aroundPickName;}
00141   void setAroundPickName(const QString& pn) {_aroundPickName=pn;}
00142 
00143   double beforePickDelay() const {return _beforePickDelay;}
00144   void setBeforePickDelay(double d) {_beforePickDelay=d;}
00145 
00146   double afterPickDelay() const {return _afterPickDelay;}
00147   void setAfterPickDelay(double d) {_afterPickDelay=d;}
00148 
00149   const TimeRangeParameters& customTimeRange() const {return _customTimeRange;}
00150   void setCustomTimeRange(const TimeRangeParameters& ctr) {_customTimeRange=ctr;}
00151 
00152   void highlightSignal(const GraphContentOptions& gc, QPainter& p, int w, int iSig, int isigmin, int isigmax) const;
00153 
00154   const QColor& signalColor(const Signal * sig) const;
00155   void setSignalColor(const Signal * sig, const QColor& c);
00156   void clearSignalColors();
00157 
00158   virtual bool hasProperties() {return true;}
00159   virtual void addProperties(PropertyProxy * pp);
00160   virtual void removeProperties(PropertyProxy * pp);
00161   virtual void properties(PropertyWidget * w) const;
00162   virtual void setProperty(uint wid, int pid, QVariant val);
00163 signals:
00164   void propertiesChanged();
00165 protected:
00166   virtual void paintData(const LayerPainterRequest& lp, QPainter& p, double dotpercm) const;
00167   virtual bool wheelEvent (QWheelEvent * e);
00168   virtual bool keyPressEvent (QKeyEvent* e);
00169 
00170   virtual void xml_writeProperties(XML_WRITEPROPERTIES_ARGS) const;
00171   virtual void xml_writeChildren(XML_WRITECHILDREN_ARGS) const;
00172   virtual XMLMember xml_member(XML_MEMBER_ARGS);
00173   virtual bool xml_setProperty(XML_SETPROPERTY_ARGS);
00174   virtual void xml_polishChild(XML_POLISHCHILD_ARGS);
00175   virtual void xml_polish(XML_POLISH_ARGS);
00176 protected:
00177   friend class PickLayer;
00178   friend class TimeWindowLayer;
00179   // Pointer to graphic window's official subPool
00180   SubSignalPool * _subPool;
00181   bool _subPoolOwner;
00182 
00183   // Appearance options
00184   // ------------------
00185   // If true, positive variable area is filled in black
00186   bool _variableArea;
00187   // If true, a wiggle trace is displayed
00188   bool _wiggleTrace;
00189   // Pointeur to grid structure, if NULL trace plotting is used
00190   Grid2D<double> * _gridPlot;
00191   // Type of Y axis
00192   YAxis _yAxis;
00193   // Vector where to store the projections of the receiver coordinates (axis Y)
00194   // or the index of signals (if ViewerIndex)
00195   QVector<double> _signalY;
00196 
00197   // Trace plotting options
00198   // ----------------------
00199   Offset _offset;
00200   Normalize _normalize;
00201   // User value to normalize
00202   double _normalizeValue;
00203   // Flag to select the type of clipping
00204   Clip _clip;
00205   // Value used to clip is _clip is Value
00206   double _clipValue;
00207   // Percentage used to clip is _clip is Percentage
00208   double _clipPerc;
00209   // Value of overlap between adjacent signals
00210   double _overlap;
00211   // Individual values of overlap
00212   QMap<const Signal *, double> _signalOverlaps;
00213   // Individual colors for signals
00214   QMap<const Signal *, QColor> _signalColors;
00215 
00216   // Time range options
00217   // ----------------------
00218   TimeRange _timeRange;
00219   TimeRangeParameters _customTimeRange;
00220   QString _aroundPickName;
00221   double _beforePickDelay;
00222   double _afterPickDelay;
00223 
00224   static uint _tab;
00225 
00226   // Calculate the valClip and affmax for signal sig between samples itmin and itmax
00227   void drawingAmplitude(const Signal * sig, int itmin, int itmax, double& valClip, double& affMax) const;
00228   double maxAmplitude(const GraphContentOptions& gc) const;
00229   bool visibleSamples(const GraphContentOptions& gc, const Signal * sig,
00230                        int& itmin, int& itmax, double& x0, double& dx) const;
00231   // Overloaded function to simplify computation of itmin and itmax only
00232   void visibleSamples(const GraphContentOptions& gc, const Signal * sig, int& itmin, int& itmax) const;
00233   // Updates the internal grid whenever the signals change
00234   void updateGrid();
00235   void drawSignal(const GraphContentOptions& gc, QPainter& p, const Signal * sig,
00236                    int iSig, int itmin, int itmax, double x0, double dx,
00237                    bool allSamplesVisible, double affMax, int pixelWidth,
00238                    bool variableArea, bool wiggleTrace) const;
00239   void drawGaps(const GraphContentOptions& gc, QPainter& p, const Signal * sig, int iSig) const;
00240   void setIsigMinMax(const GraphContentOptions& gc, int& isigmin, int& isigmax) const;
00241 private:
00242   void spinOverlap(int nSteps, bool individual, int y);
00243 
00244   static const QString signalColorTag;
00245   static const QString signalOverlapTag;
00246   static const QString indexTag;
00247 };
00248 
00252 inline void SignalLayer::setIsigMinMax(const GraphContentOptions& gc, int& isigmin, int& isigmax) const
00253 {
00254   TRACE;
00255   int n=_subPool->count();
00256   switch(_yAxis) {
00257   case ViewerIndex:
00258     if(n > 1) {
00259       if(gc.yVisMin() > 1)
00260         isigmin=(int) floor(gc.yVisMin()) - 1;
00261       else isigmin=0;
00262       isigmax=(int) ceil(gc.yVisMax()) - 1;
00263       if(isigmax > n) isigmax=n;
00264     } else {
00265       isigmin=0;
00266       isigmax=n;
00267     }
00268     break;
00269   case Receiver: // TODO something better
00270     isigmin=0;
00271     isigmax=n;
00272     break;
00273   case SignalName:         // TODO something better
00274     isigmin=0;
00275     isigmax=n;
00276     break;
00277   case Overlayed:
00278     isigmin=0;
00279     isigmax=n;
00280     break;
00281   }
00282 }
00283 
00284 inline void SignalLayer::visibleSamples(const GraphContentOptions& gc, const Signal * sig,
00285                                             int& itmin, int& itmax) const
00286 {
00287   TRACE;
00288   double x0, dx;
00289   visibleSamples(gc, sig, itmin, itmax, x0, dx);
00290 }
00291 
00292 } // namespace GeopsyGui
00293 
00294 #endif // SIGNALLAYER_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines