1 // Copyright (C) 2007-2013 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 #ifndef NO_ANALYTICAL_CURVES
29 #include "Plot2d_AnalyticalCurve.h"
31 #include "Plot2d_NormalizeAlgorithm.h"
38 #include <qwt_symbol.h>
39 #include <qwt_scale_draw.h>
40 #include <qwt_plot_marker.h>
41 #include <qwt_plot_picker.h>
55 class Plot2d_AxisScaleDraw;
56 class Plot2d_QwtPlotPicker;
58 typedef QMultiHash<QwtPlotCurve*, Plot2d_Curve*> CurveDict;
59 typedef QMultiHash<QwtPlotItem*, Plot2d_Object*> ObjectDict;
61 class PLOT2D_EXPORT Plot2d_ViewFrame : public QWidget
62 #ifndef NO_ANALYTICAL_CURVES
63 , public Plot2d_CurveContainer
68 enum { NoOpId, FitAreaId, ZoomId, PanId, GlPanId, DumpId,
69 ModeXLinearId, ModeXLogarithmicId, ModeYLinearId, ModeYLogarithmicId,
70 LegendId, CurvePointsId, CurveLinesId, CurveSplinesId };
72 /* Construction/destruction */
73 Plot2d_ViewFrame( QWidget*, const QString& = "" );
74 virtual ~Plot2d_ViewFrame();
78 enum ObjectType { MainTitle, XTitle, YTitle, Y2Title, XAxis, YAxis, Y2Axis };
80 QWidget* getViewWidget();
83 virtual void DisplayAll();
84 virtual void EraseAll();
87 void Display( const Plot2d_Prs* );
88 void Erase( const Plot2d_Prs*, const bool = false );
89 Plot2d_Prs* CreatePrs( const char* = 0 );
91 virtual bool eventFilter( QObject*, QEvent* );
94 void updateTitles( const bool = true );
95 void setTitle( const QString& );
96 QString getTitle() const;
98 QVector< QVector<QwtPlotCurve *> > displayPlot2dCurveList( const QList< QList<Plot2d_Curve*> >& sysCoCurveList,
100 const QList< QList<bool> >& sides);
102 QVector< QVector<QwtPlotCurve *> > displayPlot2dCurveList( const QList<Plot2d_Curve*>& curveList,
105 const QList< bool >& sides);
107 Plot2d_Curve* createPlot2dCurve( QString & title,
109 QList<double> & xList,
110 QList<double> & yList,
111 QList<QString> & tooltipList,
112 Plot2d::LineType lineKind,
115 QwtSymbol::Style markerKind,
116 Plot2d_QwtPlotPicker* picker,
118 bool displayLegend=true);
120 QColor getPlot2dCurveColor( Plot2d_Curve* plot2dCurve);
122 QwtPlotCurve *createSegment( double *X, double *Y, int nbPoint,
123 Qt::PenStyle lineKind,
126 QwtSymbol::Style markerKind,
129 /* curves operations [ obsolete ] */
130 void displayCurve( Plot2d_Curve*, bool = false );
131 void displayCurves( const curveList&, bool = false );
132 void eraseCurve( Plot2d_Curve*, bool = false );
133 void eraseCurves( const curveList&, bool = false );
134 int getCurves( curveList& ) const;
135 CurveDict getCurves() const;
136 void updateCurve( Plot2d_Curve*, bool = false );
137 void processFiltering(bool = false);
139 /* objects operations */
140 QwtPlotItem* displayObject( Plot2d_Object*, bool = false );
141 void displayObjects( const objectList&, bool = false );
142 void eraseObject( Plot2d_Object*, bool = false );
143 void eraseObjects( const objectList&, bool = false );
144 void eraseBasicObject( QwtPlotItem*, bool = false );
145 void eraseBasicObjects( const QList<QwtPlotItem*> &, bool = false );
146 int getObjects( objectList& ) const;
147 bool isVisible( Plot2d_Object* ) const;
148 void updateObject( Plot2d_Object*, bool = false );
150 void updateLegend( const Plot2d_Prs* );
153 void fitArea( const QRect& );
154 void fitData( const int, const double, const double,
155 const double, const double,
156 const double = 0, const double = 0 );
158 void getFitRanges( double&, double&, double&, double&,
161 void getFitRangeByCurves( double&, double&, double&, double&,
164 void getFitRangeByMarkers(double&, double&, double&, double&,
167 #ifndef NO_ANALYTICAL_CURVES
168 void addAnalyticalCurve( Plot2d_AnalyticalCurve* );
169 void removeAnalyticalCurve( Plot2d_AnalyticalCurve* );
170 void updateAnalyticalCurve( Plot2d_AnalyticalCurve*, bool = false );
171 void updateAnalyticalCurves();
172 void deselectAnalyticalCurves();
174 AnalyticalCurveList getAnalyticalCurves() const;
175 Plot2d_AnalyticalCurve* getAnalyticalCurve(QwtPlotItem *);
178 void deselectObjects();
180 /* view parameters */
181 void copyPreferences( Plot2d_ViewFrame* );
182 void setCurveType( int, bool = true );
183 int getCurveType() const;
184 void setCurveTitle( Plot2d_Curve*, const QString& );
185 void setObjectTitle( Plot2d_Object*, const QString& );
186 void showLegend( bool, bool = true );
187 void setLegendPos( int );
188 int getLegendPos() const;
189 void setLegendFont( const QFont& );
190 QFont getLegendFont() const;
191 void setLegendFontColor( const QColor& );
192 QColor getLegendFontColor() const;
193 void setMarkerSize( const int, bool = true );
194 int getMarkerSize() const;
195 virtual void setBackgroundColor( const QColor& );
196 QColor backgroundColor() const;
197 void setXGrid( bool, const int, bool, const int, bool = true );
198 void setYGrid( bool, const int, bool, const int,
199 bool, const int, bool, const int, bool = true );
200 void setTitle( bool, const QString&, ObjectType, bool = true );
201 QString getTitle( ObjectType ) const;
203 void setFont( const QFont&, ObjectType, bool = true );
204 void setHorScaleMode( const int, bool = true );
205 int getHorScaleMode() const;
206 void setVerScaleMode( const int, bool = true );
207 int getVerScaleMode() const;
208 void setNormLMaxMode( bool, bool = true);
209 bool getNormLMaxMode()const;
210 void setNormLMinMode( bool, bool = true);
211 bool getNormLMinMode()const;
212 void setNormRMaxMode( bool, bool = true);
213 bool getNormRMaxMode()const;
214 void setNormRMinMode( bool, bool = true);
215 bool getNormRMinMode()const;
218 bool isModeHorLinear();
219 bool isModeVerLinear();
220 bool isNormLMaxMode();
221 bool isNormLMinMode();
222 bool isNormRMaxMode();
223 bool isNormRMinMode();
225 bool isLegendShow() const;
227 // Protection against QwtCurve::drawLines() bug in Qwt 0.4.x:
228 // it crashes if switched to X/Y logarithmic mode, when one or more points have
229 // non-positive X/Y coordinate
230 bool isXLogEnabled() const;
231 bool isYLogEnabled() const;
232 void setEnableAxis( QwtPlot::Axis, bool );
234 virtual bool print( const QString&, const QString& ) const;
235 void printPlot( QPainter*, const QRect&,
236 const QwtPlotPrintFilter& = QwtPlotPrintFilter() ) const;
238 QString getVisualParameters();
239 void setVisualParameters( const QString& );
241 void incrementalPan ( const int, const int );
242 void incrementalZoom( const int, const int );
244 QwtPlotCanvas* getPlotCanvas() const;
245 Plot2d_Curve* getClosestCurve( QPoint, double&, int& ) const;
247 Plot2d_Object* getPlotObject( QwtPlotItem* ) const;
248 QwtPlotItem* getPlotObject( Plot2d_Object* ) const;
249 QwtPlotCurve* getPlotCurve( Plot2d_Curve* ) const;
250 Plot2d_Plot2d* getPlot() const { return myPlot; }
252 void updatePlotItem(Plot2d_Object*, QwtPlotItem*);
254 int testOperation( const QMouseEvent& );
255 virtual void readPreferences();
256 virtual void writePreferences();
257 QString getInfo( const QPoint& );
258 virtual void wheelEvent( QWheelEvent* );
259 bool hasPlotCurve( Plot2d_Curve* ) const;
260 void setCurveType( QwtPlotCurve*, int );
261 bool hasPlotObject( Plot2d_Object* ) const;
262 QString getXmlVisualParameters();
263 bool setXmlVisualParameters(const QString&);
269 void onViewFitArea();
270 void onViewGlobalPan();
272 #ifndef NO_ANALYTICAL_CURVES
273 void onAnalyticalCurve();
276 void onChangeBackground();
285 virtual void customEvent( QEvent* );
286 void plotMousePressed( const QMouseEvent& );
287 bool plotMouseMoved( const QMouseEvent& );
288 void plotMouseReleased( const QMouseEvent& );
291 void vpModeHorChanged();
292 void vpModeVerChanged();
293 void vpNormLModeChanged();
294 void vpNormRModeChanged();
295 void vpCurveChanged();
296 void contextMenuRequested( QContextMenuEvent* );
297 void legendClicked( QwtPlotItem* );
300 Plot2d_Plot2d* myPlot;
308 QColor myLegendColor;
311 QString myTitle, myXTitle, myYTitle, myY2Title;
312 bool myTitleEnabled, myXTitleEnabled, myYTitleEnabled, myY2TitleEnabled;
313 bool myXGridMajorEnabled, myYGridMajorEnabled, myY2GridMajorEnabled;
314 bool myXGridMinorEnabled, myYGridMinorEnabled, myY2GridMinorEnabled;
315 int myXGridMaxMajor, myYGridMaxMajor, myY2GridMaxMajor;
316 int myXGridMaxMinor, myYGridMaxMinor, myY2GridMaxMinor;
317 int myXMode, myYMode;
318 bool myNormLMin, myNormLMax, myNormRMin, myNormRMax;
319 double myXDistance, myYDistance, myYDistance2;
321 ObjectDict myObjects;
322 #ifndef NO_ANALYTICAL_CURVES
323 AnalyticalCurveList myAnalyticalCurves;
325 Plot2d_NormalizeAlgorithm* myLNormAlgo;
326 Plot2d_NormalizeAlgorithm* myRNormAlgo;
329 // List of QwtPlotCurve curves to draw (created by Plot2d_Curve::createPlotItem() )
330 QList<QwtPlotItem*> myQwtPlotCurveList;
332 // List of intermittent segments to connect curves
333 QList<QwtPlotCurve*> myIntermittentSegmentList;
335 // List of curves Plot2d_Curve
336 QList<Plot2d_Curve*> myPlot2dCurveList;
339 class Plot2d_Plot2d : public QwtPlot
343 Plot2d_Plot2d( QWidget* );
344 virtual ~Plot2d_Plot2d();
346 void setLogScale( int, bool );
349 QwtLegend* getLegend();
350 QSize sizeHint() const;
351 QSize minimumSizeHint() const;
352 void defaultPicker();
353 void setPickerMousePattern( int, int = Qt::NoButton );
354 void setPicker( Plot2d_QwtPlotPicker *picker);
355 Plot2d_QwtPlotPicker* getPicker() { return myPicker; }
356 Plot2d_AxisScaleDraw* getScaleDraw() { return myScaleDraw; }
357 QList<QwtPlotMarker*> getSeparationLineList() { return mySeparationLineList; }
358 void clearSeparationLineList();
359 QwtPlotMarker *createMarkerAndTooltip( QwtSymbol symbol,
363 Plot2d_QwtPlotPicker *picker);
365 bool polished() const;
366 QwtPlotGrid* grid() const;
367 QwtPlotZoomer* zoomer() const;
369 virtual void updateYAxisIdentifiers();
371 // Methods to deal with axes ticks
373 void createAxisScaleDraw();
375 void unactivAxisScaleDraw( int numcall);
377 void displayXTicksAndLabels(
378 double XLeftmargin, double XRightMargin,
379 const QList< QPair< QString, QMap<double,QString> > > & devicesPosLabelTicks);
381 void createSeparationLine( double Xpos);
385 virtual void polish();
388 void onScaleDivChanged();
392 QList<QColor> myColors;
394 QwtPlotZoomer* myPlotZoomer;
395 Plot2d_AxisScaleDraw* myScaleDraw;
396 // The point picker associated with the graphic view
397 Plot2d_QwtPlotPicker *myPicker;
399 // List of verticals segments between two curves
400 QList<QwtPlotMarker*> mySeparationLineList;
403 class Plot2d_ScaleDraw: public QwtScaleDraw
406 Plot2d_ScaleDraw( char f = 'g', int prec = 6 );
407 Plot2d_ScaleDraw( const QwtScaleDraw& scaleDraw, char f = 'g', int prec = 6 );
409 virtual QwtText label( double value ) const;
411 int precision() const { return myPrecision; }
418 class Plot2d_YScaleDraw: public QwtScaleDraw
423 virtual QwtText label( double value ) const;
426 /* Definition of X axis graduations
428 class Plot2d_AxisScaleDraw: public QwtScaleDraw
431 static const QString DEVICE_FONT;
432 static const int DEVICE_FONT_SIZE;
433 static const int DEVICE_BY;
435 Plot2d_AxisScaleDraw(Plot2d_Plot2d* plot);
437 virtual ~Plot2d_AxisScaleDraw();
439 void unactivTicksDrawing( int numcall);
441 virtual void draw( QPainter * painter, const QPalette & palette) const;
443 virtual QwtText label(double value) const;
445 void setLabelTick(double value, QString label, bool isDevice = false);
447 void setTicks(const QList<double> aTicks);
449 void setInterval(double lowerBound, double upperBound);
455 void drawLabel( QPainter* painter, double value) const;
457 void drawTick( QPainter* painter, double value, int len) const;
460 bool myActivTicksDrawing; // true => activate drawing ticks (with draw() )
461 int myNumTicksDrawingCall; // call number to ticks drawing
463 // Ticks list to display on X axis
464 QMap<double, QString> myLabelX; // position, label
466 QList<double> myTicks; // positions
468 // Systems names to display under X axis
469 QMap<double, QString> myLabelDevice;
471 Plot2d_Plot2d* myPlot; // Drawing zone QwtPlot
480 /* Management of tooltips associated with markers for curves points or others points
482 class Plot2d_QwtPlotPicker : public QwtPlotPicker
485 static const double BOUND_HV_SIZE;
487 Plot2d_QwtPlotPicker( int xAxis,
490 RubberBand rubberBand,
491 DisplayMode trackerMode,
492 QwtPlotCanvas *canvas);
494 Plot2d_QwtPlotPicker( int xAxis,
496 QwtPlotCanvas *canvas);
498 virtual ~Plot2d_QwtPlotPicker();
500 QList<QwtPlotMarker*> pMarkers; // points markers
501 QMap<QwtPlotMarker*, QwtText> pMarkersToolTip; // associations (marker,tooltip)
505 virtual QwtText trackerText( const QwtDoublePoint & pos ) const;