1 // Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #ifndef PLOT2D_VIEWFRAME_H
24 #define PLOT2D_VIEWFRAME_H
27 #include "Plot2d_Curve.h"
28 #include "Plot2d_AnalyticalCurve.h"
29 #include "Plot2d_NormalizeAlgorithm.h"
36 #include <qwt_symbol.h>
37 #include <qwt_scale_draw.h>
38 #include <qwt_plot_marker.h>
39 #include <qwt_plot_picker.h>
53 class Plot2d_AxisScaleDraw;
54 class Plot2d_QwtPlotPicker;
56 typedef QMultiHash<QwtPlotCurve*, Plot2d_Curve*> CurveDict;
57 typedef QMultiHash<QwtPlotItem*, Plot2d_Object*> ObjectDict;
59 class PLOT2D_EXPORT Plot2d_ViewFrame : public QWidget, public Plot2d_CurveContainer
63 enum { NoOpId, FitAreaId, ZoomId, PanId, GlPanId, DumpId,
64 ModeXLinearId, ModeXLogarithmicId, ModeYLinearId, ModeYLogarithmicId,
65 LegendId, CurvePointsId, CurveLinesId, CurveSplinesId };
67 /* Construction/destruction */
68 Plot2d_ViewFrame( QWidget*, const QString& = "" );
69 virtual ~Plot2d_ViewFrame();
71 enum ObjectType { MainTitle, XTitle, YTitle, Y2Title, XAxis, YAxis, Y2Axis };
73 QWidget* getViewWidget();
76 virtual void DisplayAll();
77 virtual void EraseAll();
80 void Display( const Plot2d_Prs* );
81 void Erase( const Plot2d_Prs*, const bool = false );
82 Plot2d_Prs* CreatePrs( const char* = 0 );
84 virtual bool eventFilter( QObject*, QEvent* );
88 void setTitle( const QString& );
89 QString getTitle() const;
91 QVector< QVector<QwtPlotCurve *> > displayPlot2dCurveList( const QList< QList<Plot2d_Curve*> >& sysCoCurveList,
93 const QList< QList<bool> >& sides);
95 QVector< QVector<QwtPlotCurve *> > displayPlot2dCurveList( const QList<Plot2d_Curve*>& curveList,
98 const QList< bool >& sides);
100 Plot2d_Curve* createPlot2dCurve( QString & title,
102 QList<double> & xList,
103 QList<double> & yList,
104 QList<QString> & tooltipList,
105 Plot2d::LineType lineKind,
108 QwtSymbol::Style markerKind,
109 Plot2d_QwtPlotPicker* picker,
111 bool displayLegend=true);
113 QColor getPlot2dCurveColor( Plot2d_Curve* plot2dCurve);
115 QwtPlotCurve *createSegment( double *X, double *Y, int nbPoint,
116 Qt::PenStyle lineKind,
119 QwtSymbol::Style markerKind,
122 /* curves operations [ obsolete ] */
123 void displayCurve( Plot2d_Curve*, bool = false );
124 void displayCurves( const curveList&, bool = false );
125 void eraseCurve( Plot2d_Curve*, bool = false );
126 void eraseCurves( const curveList&, bool = false );
127 int getCurves( curveList& ) const;
128 CurveDict getCurves() const;
129 void updateCurve( Plot2d_Curve*, bool = false );
130 void processFiltering(bool = false);
132 /* objects operations */
133 QwtPlotItem* displayObject( Plot2d_Object*, bool = false );
134 void displayObjects( const objectList&, bool = false );
135 void eraseObject( Plot2d_Object*, bool = false );
136 void eraseObjects( const objectList&, bool = false );
137 void eraseBasicObject( QwtPlotItem*, bool = false );
138 void eraseBasicObjects( const QList<QwtPlotItem*> &, bool = false );
139 int getObjects( objectList& ) const;
140 bool isVisible( Plot2d_Object* ) const;
141 void updateObject( Plot2d_Object*, bool = false );
143 void updateLegend( const Plot2d_Prs* );
146 void fitArea( const QRect& );
147 void fitData( const int, const double, const double,
148 const double, const double,
149 const double = 0, const double = 0 );
151 void getFitRanges( double&, double&, double&, double&,
154 void getFitRangeByCurves( double&, double&, double&, double&,
157 void addAnalyticalCurve( Plot2d_AnalyticalCurve* );
158 void removeAnalyticalCurve( Plot2d_AnalyticalCurve* );
159 void updateAnalyticalCurve( Plot2d_AnalyticalCurve*, bool = false );
160 void updateAnalyticalCurves();
161 void deselectAnalyticalCurves();
162 void deselectObjects();
164 AnalyticalCurveList getAnalyticalCurves() const;
165 Plot2d_AnalyticalCurve* getAnalyticalCurve(QwtPlotItem *);
167 /* view parameters */
168 void copyPreferences( Plot2d_ViewFrame* );
169 void setCurveType( int, bool = true );
170 int getCurveType() const;
171 void setCurveTitle( Plot2d_Curve*, const QString& );
172 void setObjectTitle( Plot2d_Object*, const QString& );
173 void showLegend( bool, bool = true );
174 void setLegendPos( int );
175 int getLegendPos() const;
176 void setLegendFont( const QFont& );
177 QFont getLegendFont() const;
178 void setLegendFontColor( const QColor& );
179 QColor getLegendFontColor() const;
180 void setMarkerSize( const int, bool = true );
181 int getMarkerSize() const;
182 void setBackgroundColor( const QColor& );
183 QColor backgroundColor() const;
184 void setXGrid( bool, const int, bool, const int, bool = true );
185 void setYGrid( bool, const int, bool, const int,
186 bool, const int, bool, const int, bool = true );
187 void setTitle( bool, const QString&, ObjectType, bool = true );
188 QString getTitle( ObjectType ) const;
190 void setFont( const QFont&, ObjectType, bool = true );
191 void setHorScaleMode( const int, bool = true );
192 int getHorScaleMode() const;
193 void setVerScaleMode( const int, bool = true );
194 int getVerScaleMode() const;
195 void setNormLMaxMode( bool, bool = true);
196 bool getNormLMaxMode()const;
197 void setNormLMinMode( bool, bool = true);
198 bool getNormLMinMode()const;
199 void setNormRMaxMode( bool, bool = true);
200 bool getNormRMaxMode()const;
201 void setNormRMinMode( bool, bool = true);
202 bool getNormRMinMode()const;
205 bool isModeHorLinear();
206 bool isModeVerLinear();
207 bool isNormLMaxMode();
208 bool isNormLMinMode();
209 bool isNormRMaxMode();
210 bool isNormRMinMode();
212 bool isLegendShow() const;
214 // Protection against QwtCurve::drawLines() bug in Qwt 0.4.x:
215 // it crashes if switched to X/Y logarithmic mode, when one or more points have
216 // non-positive X/Y coordinate
217 bool isXLogEnabled() const;
218 bool isYLogEnabled() const;
219 void setEnableAxis( QwtPlot::Axis, bool );
221 virtual bool print( const QString&, const QString& ) const;
222 void printPlot( QPainter*, const QRect&,
223 const QwtPlotPrintFilter& = QwtPlotPrintFilter() ) const;
225 QString getVisualParameters();
226 void setVisualParameters( const QString& );
228 void incrementalPan ( const int, const int );
229 void incrementalZoom( const int, const int );
231 QwtPlotCanvas* getPlotCanvas() const;
232 Plot2d_Curve* getClosestCurve( QPoint, double&, int& ) const;
234 Plot2d_Object* getPlotObject( QwtPlotItem* ) const;
235 QwtPlotItem* getPlotObject( Plot2d_Object* ) const;
236 QwtPlotCurve* getPlotCurve( Plot2d_Curve* ) const;
237 Plot2d_Plot2d* getPlot() const { return myPlot; }
239 void updatePlotItem(Plot2d_Object*, QwtPlotItem*);
241 int testOperation( const QMouseEvent& );
242 void readPreferences();
243 void writePreferences();
244 QString getInfo( const QPoint& );
245 virtual void wheelEvent( QWheelEvent* );
246 bool hasPlotCurve( Plot2d_Curve* ) const;
247 void setCurveType( QwtPlotCurve*, int );
248 bool hasPlotObject( Plot2d_Object* ) const;
249 QString getXmlVisualParameters();
250 bool setXmlVisualParameters(const QString&);
260 void onViewFitArea();
261 void onViewGlobalPan();
263 void onAnalyticalCurve();
265 void onChangeBackground();
274 virtual void customEvent( QEvent* );
275 void plotMousePressed( const QMouseEvent& );
276 bool plotMouseMoved( const QMouseEvent& );
277 void plotMouseReleased( const QMouseEvent& );
280 void vpModeHorChanged();
281 void vpModeVerChanged();
282 void vpNormLModeChanged();
283 void vpNormRModeChanged();
284 void vpCurveChanged();
285 void contextMenuRequested( QContextMenuEvent* );
286 void legendClicked( QwtPlotItem* );
289 Plot2d_Plot2d* myPlot;
297 QColor myLegendColor;
300 QString myTitle, myXTitle, myYTitle, myY2Title;
301 bool myTitleEnabled, myXTitleEnabled, myYTitleEnabled, myY2TitleEnabled;
302 bool myXGridMajorEnabled, myYGridMajorEnabled, myY2GridMajorEnabled;
303 bool myXGridMinorEnabled, myYGridMinorEnabled, myY2GridMinorEnabled;
304 int myXGridMaxMajor, myYGridMaxMajor, myY2GridMaxMajor;
305 int myXGridMaxMinor, myYGridMaxMinor, myY2GridMaxMinor;
306 int myXMode, myYMode;
307 bool myNormLMin, myNormLMax, myNormRMin, myNormRMax;
308 double myXDistance, myYDistance, myYDistance2;
310 ObjectDict myObjects;
311 AnalyticalCurveList myAnalyticalCurves;
312 Plot2d_NormalizeAlgorithm* myLNormAlgo;
313 Plot2d_NormalizeAlgorithm* myRNormAlgo;
316 // List of QwtPlotCurve curves to draw (created by Plot2d_Curve::createPlotItem() )
317 QList<QwtPlotItem*> myQwtPlotCurveList;
319 // List of intermittent segments to connect curves
320 QList<QwtPlotCurve*> myIntermittentSegmentList;
322 // List of markers associated with curves points
323 QList<QwtPlotMarker*> myMarkerList;
325 // List of curves Plot2d_Curve
326 QList<Plot2d_Curve*> myPlot2dCurveList;
329 class Plot2d_Plot2d : public QwtPlot
333 Plot2d_Plot2d( QWidget* );
334 virtual ~Plot2d_Plot2d();
336 void setLogScale( int, bool );
339 QwtLegend* getLegend();
340 QSize sizeHint() const;
341 QSize minimumSizeHint() const;
342 void defaultPicker();
343 void setPickerMousePattern( int, int = Qt::NoButton );
344 void setPicker( Plot2d_QwtPlotPicker *picker);
345 Plot2d_QwtPlotPicker* getPicker() { return myPicker; }
346 Plot2d_AxisScaleDraw* getScaleDraw() { return myScaleDraw; }
347 QList<QwtPlotMarker*> getSeparationLineList() { return mySeparationLineList; }
348 void clearSeparationLineList();
349 QwtPlotMarker *createMarkerAndTooltip( QwtSymbol symbol,
353 Plot2d_QwtPlotPicker *picker);
355 bool polished() const;
356 QwtPlotGrid* grid() const;
357 QwtPlotZoomer* zoomer() const;
359 virtual void updateYAxisIdentifiers();
361 // Methods to deal with axes ticks
363 void createAxisScaleDraw();
365 void unactivAxisScaleDraw( int numcall);
367 void displayXTicksAndLabels(
368 double XLeftmargin, double XRightMargin,
369 const QList< QPair< QString, QMap<double,QString> > > & devicesPosLabelTicks);
371 void createSeparationLine( double Xpos);
375 virtual void polish();
378 void onScaleDivChanged();
382 QList<QColor> myColors;
384 QwtPlotZoomer* myPlotZoomer;
385 Plot2d_AxisScaleDraw* myScaleDraw;
386 // The point picker associated with the graphic view
387 Plot2d_QwtPlotPicker *myPicker;
389 // List of verticals segments between two curves
390 QList<QwtPlotMarker*> mySeparationLineList;
393 class Plot2d_ScaleDraw: public QwtScaleDraw
396 Plot2d_ScaleDraw( char f = 'g', int prec = 6 );
397 Plot2d_ScaleDraw( const QwtScaleDraw& scaleDraw, char f = 'g', int prec = 6 );
399 virtual QwtText label( double value ) const;
401 int precision() const { return myPrecision; }
408 class Plot2d_YScaleDraw: public QwtScaleDraw
413 virtual QwtText label( double value ) const;
416 /* Definition of X axis graduations
418 class Plot2d_AxisScaleDraw: public QwtScaleDraw
421 static const QString DEVICE_FONT;
422 static const int DEVICE_FONT_SIZE;
423 static const int DEVICE_BY;
425 Plot2d_AxisScaleDraw(Plot2d_Plot2d* plot);
427 virtual ~Plot2d_AxisScaleDraw();
429 void unactivTicksDrawing( int numcall);
431 virtual void draw( QPainter * painter, const QPalette & palette) const;
433 virtual QwtText label(double value) const;
435 void setLabelTick(double value, QString label, bool isDevice = false);
437 void setTicks(const QList<double> aTicks);
439 void setInterval(double lowerBound, double upperBound);
445 void drawLabel( QPainter* painter, double value) const;
447 void drawTick( QPainter* painter, double value, int len) const;
450 bool myActivTicksDrawing; // true => activate drawing ticks (with draw() )
451 int myNumTicksDrawingCall; // call number to ticks drawing
453 // Ticks list to display on X axis
454 QMap<double, QString> myLabelX; // position, label
456 QList<double> myTicks; // positions
458 // Systems names to display under X axis
459 QMap<double, QString> myLabelDevice;
461 Plot2d_Plot2d* myPlot; // Drawing zone QwtPlot
470 /* Management of tooltips associated with markers for curves points or others points
472 class Plot2d_QwtPlotPicker : public QwtPlotPicker
475 static const double BOUND_HV_SIZE;
477 Plot2d_QwtPlotPicker( int xAxis,
480 RubberBand rubberBand,
481 DisplayMode trackerMode,
482 QwtPlotCanvas *canvas);
484 Plot2d_QwtPlotPicker( int xAxis,
486 QwtPlotCanvas *canvas);
488 virtual ~Plot2d_QwtPlotPicker();
490 QList<QwtPlotMarker*> pMarkers; // points markers
491 QMap<QwtPlotMarker*, QwtText> pMarkersToolTip; // associations (marker,tooltip)
495 virtual QwtText trackerText( const QwtDoublePoint & pos ) const;