1 // Copyright (C) 2007-2008 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
22 #ifndef PLOT2D_VIEWFRAME_H
23 #define PLOT2D_VIEWFRAME_H
25 #include "Plot2d_Curve.h"
29 #include <qwt_symbol.h>
30 #include <qwt_scale_draw.h>
39 typedef QMultiHash<QwtPlotCurve*, Plot2d_Curve*> CurveDict;
41 class PLOT2D_EXPORT Plot2d_ViewFrame : public QWidget
45 enum { NoOpId, FitAreaId, ZoomId, PanId, GlPanId, DumpId,
46 ModeXLinearId, ModeXLogarithmicId, ModeYLinearId, ModeYLogarithmicId,
47 LegendId, CurvePointsId, CurveLinesId, CurveSplinesId };
49 /* Construction/destruction */
50 Plot2d_ViewFrame( QWidget* parent, const QString& title = "" );
51 virtual ~Plot2d_ViewFrame();
53 enum ObjectType { MainTitle, XTitle, YTitle, Y2Title, XAxis, YAxis, Y2Axis };
56 QWidget* getViewWidget();
63 void Display( const Plot2d_Prs* );
64 void Erase( const Plot2d_Prs*, const bool = false );
65 Plot2d_Prs* CreatePrs( const char* entry = 0 );
67 virtual bool eventFilter(QObject* watched, QEvent* e);
71 void setTitle( const QString& title );
72 QString getTitle() const { return myTitle; }
73 void displayCurve( Plot2d_Curve* curve, bool update = false );
74 void displayCurves( const curveList& curves, bool update = false );
75 void eraseCurve( Plot2d_Curve* curve, bool update = false );
76 void eraseCurves( const curveList& curves, bool update = false );
77 int getCurves( curveList& clist );
78 const CurveDict& getCurves();
79 bool isVisible( Plot2d_Curve* curve );
80 void updateCurve( Plot2d_Curve* curve, bool update = false );
81 void updateLegend( const Plot2d_Prs* prs );
83 void fitArea( const QRect& area );
84 void fitData(const int mode,
85 const double xMin, const double xMax,
86 const double yMin, const double yMax,
87 const double y2Min = 0, const double y2Max = 0);
89 void getFitRanges(double& xMin, double& xMax,
90 double& yMin, double& yMax,
91 double& y2Min, double& y2Max);
94 void copyPreferences( Plot2d_ViewFrame* );
95 void setCurveType( int curveType, bool update = true );
96 int getCurveType() const { return myCurveType; }
97 void setCurveTitle( Plot2d_Curve* curve, const QString& title );
98 void showLegend( bool show, bool update = true );
99 void setLegendPos( int pos );
100 int getLegendPos() const { return myLegendPos; }
101 void setMarkerSize( const int size, bool update = true );
102 int getMarkerSize() const { return myMarkerSize; }
103 void setBackgroundColor( const QColor& color );
104 QColor backgroundColor() const;
105 void setXGrid( bool xMajorEnabled, const int xMajorMax,
106 bool xMinorEnabled, const int xMinorMax, bool update = true );
107 void setYGrid( bool yMajorEnabled, const int yMajorMax,
108 bool yMinorEnabled, const int yMinorMax,
109 bool y2MajorEnabled, const int y2MajorMax,
110 bool y2MinorEnabled, const int y2MinorMax, bool update = true );
111 void setTitle( bool enabled, const QString& title, ObjectType type, bool update = true );
112 QString getTitle( ObjectType type ) const;
114 void setFont( const QFont& font, ObjectType type, bool update = true );
115 void setHorScaleMode( const int mode, bool update = true );
116 int getHorScaleMode() const { return myXMode; }
117 void setVerScaleMode( const int mode, bool update = true );
118 int getVerScaleMode() const { return myYMode; }
120 bool isModeHorLinear();
121 bool isModeVerLinear();
122 bool isLegendShow() { return myShowLegend; };
124 // Protection against QwtCurve::drawLines() bug in Qwt 0.4.x:
125 // it crashes if switched to X/Y logarithmic mode, when one or more points have
126 // non-positive X/Y coordinate
127 bool isXLogEnabled() const;
128 bool isYLogEnabled() const;
130 virtual bool print( const QString& file, const QString& format ) const;
132 QString getVisualParameters();
133 void setVisualParameters( const QString& parameters );
135 void incrementalPan ( const int incrX, const int incrY );
136 void incrementalZoom( const int incrX, const int incrY );
139 int testOperation( const QMouseEvent& );
140 void readPreferences();
141 void writePreferences();
142 QString getInfo( const QPoint& pnt );
143 virtual void wheelEvent( QWheelEvent* );
144 QwtPlotCurve* getPlotCurve( Plot2d_Curve* curve );
145 bool hasPlotCurve( Plot2d_Curve* curve );
146 void setCurveType( QwtPlotCurve* curve, int curveType );
152 void onViewFitArea();
153 void onViewGlobalPan();
156 void onChangeBackground();
165 virtual void customEvent( QEvent* );
166 void plotMousePressed( const QMouseEvent& );
167 bool plotMouseMoved( const QMouseEvent& );
168 void plotMouseReleased( const QMouseEvent& );
171 void vpModeHorChanged();
172 void vpModeVerChanged();
173 void vpCurveChanged();
174 void contextMenuRequested( QContextMenuEvent *e );
175 void legendClicked( QwtPlotItem* );
178 Plot2d_Plot2d* myPlot;
187 QString myTitle, myXTitle, myYTitle, myY2Title;
188 bool myTitleEnabled, myXTitleEnabled, myYTitleEnabled, myY2TitleEnabled;
189 bool myXGridMajorEnabled, myYGridMajorEnabled, myY2GridMajorEnabled;
190 bool myXGridMinorEnabled, myYGridMinorEnabled, myY2GridMinorEnabled;
191 int myXGridMaxMajor, myYGridMaxMajor, myY2GridMaxMajor;
192 int myXGridMaxMinor, myYGridMaxMinor, myY2GridMaxMinor;
193 int myXMode, myYMode;
194 double myXDistance, myYDistance, myYDistance2;
198 class Plot2d_Plot2d : public QwtPlot
202 Plot2d_Plot2d( QWidget* parent );
204 void setLogScale( int axisId, bool log10 );
207 void getNextMarker( QwtSymbol::Style& typeMarker, QColor& color, Qt::PenStyle& typeLine );
208 QwtLegend* getLegend() {
209 #if QWT_VERSION < 0x040200
212 return legend(); /* mpv: porting to the Qwt 4.2.0 */
215 virtual QSize sizeHint() const;
216 virtual QSizePolicy sizePolicy() const;
217 virtual QSize minimumSizeHint() const;
218 void defaultPicker();
219 void setPickerMousePattern( int button, int state = Qt::NoButton );
221 bool polished() const { return myIsPolished; }
222 QwtPlotGrid* grid() { return myGrid; };
223 CurveDict& getCurves() { return myCurves; }
224 Plot2d_Curve* getClosestCurve( QPoint p, double& distance, int& index );
227 virtual void polish();
230 bool existMarker( const QwtSymbol::Style typeMarker, const QColor& color, const Qt::PenStyle typeLine );
233 void onScaleDivChanged();
238 QList<QColor> myColors;
240 QwtPlotZoomer* myPlotZoomer;
243 class Plot2d_ScaleDraw: public QwtScaleDraw
246 Plot2d_ScaleDraw( char f = 'g', int prec = 6 );
247 Plot2d_ScaleDraw( const QwtScaleDraw& scaleDraw, char f = 'g', int prec = 6 );
249 virtual QwtText label( double value ) const;
251 int precision() const { return myPrecision; }