X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FPlot2d%2FPlot2d_ViewFrame.h;h=a085e887b726f0d3b87738bf6328baf412bcde3a;hb=e07448c48ea5b2127e34fc7b8c3427d01c7ce17b;hp=5d1faccb51a8c968787fb352c7fbeab6d09c676e;hpb=101fd10f1e736daa5d7f0f0ee5499b951460832a;p=modules%2Fgui.git diff --git a/src/Plot2d/Plot2d_ViewFrame.h b/src/Plot2d/Plot2d_ViewFrame.h index 5d1faccb5..a085e887b 100755 --- a/src/Plot2d/Plot2d_ViewFrame.h +++ b/src/Plot2d/Plot2d_ViewFrame.h @@ -1,199 +1,500 @@ -// Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D -// +// Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either +// License as published by the Free Software Foundation; either // version 2.1 of the License. -// -// This library is distributed in the hope that it will be useful -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. // -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // -// See http://www.salome-platform.org/ +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // + #ifndef PLOT2D_VIEWFRAME_H #define PLOT2D_VIEWFRAME_H +#include "Plot2d.h" #include "Plot2d_Curve.h" -#include -#include +#include "Plot2d_AnalyticalCurve.h" +#include "Plot2d_NormalizeAlgorithm.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include class Plot2d_Plot2d; class Plot2d_Prs; +class Plot2d_Curve; +class Plot2d_Object; +class QCustomEvent; +class QwtPlotItem; +class QwtPlotCurve; +class QwtPlotGrid; +class QwtPlotZoomer; +class Plot2d_AxisScaleDraw; +class Plot2d_QwtPlotPicker; -typedef QIntDict CurveDict; +typedef QMultiHash CurveDict; +typedef QMultiHash ObjectDict; -class PLOT2D_EXPORT Plot2d_ViewFrame : public QWidget +class PLOT2D_EXPORT Plot2d_ViewFrame : public QWidget, public Plot2d_CurveContainer { Q_OBJECT - + enum { NoOpId, FitAreaId, ZoomId, PanId, GlPanId, DumpId, - ModeXLinearId, ModeXLogarithmicId, ModeYLinearId, ModeYLogarithmicId, - LegendId, CurvePointsId, CurveLinesId, CurveSplinesId }; + ModeXLinearId, ModeXLogarithmicId, ModeYLinearId, ModeYLogarithmicId, + LegendId, CurvePointsId, CurveLinesId, CurveSplinesId }; public: /* Construction/destruction */ - Plot2d_ViewFrame( QWidget* parent, const QString& title = "" ); + Plot2d_ViewFrame( QWidget*, const QString& = "" ); virtual ~Plot2d_ViewFrame(); enum ObjectType { MainTitle, XTitle, YTitle, Y2Title, XAxis, YAxis, Y2Axis }; -public: - QWidget* getViewWidget(); + QWidget* getViewWidget(); /* display */ - void DisplayAll(); - void EraseAll(); - void Repaint(); + virtual void DisplayAll(); + virtual void EraseAll(); + void Repaint(); + + void Display( const Plot2d_Prs* ); + void Erase( const Plot2d_Prs*, const bool = false ); + Plot2d_Prs* CreatePrs( const char* = 0 ); - void Display( const Plot2d_Prs* ); - void Erase( const Plot2d_Prs*, const bool = false ); - Plot2d_Prs* CreatePrs( const char* entry = 0 ); + virtual bool eventFilter( QObject*, QEvent* ); /* operations */ - void updateTitles(); - void setTitle( const QString& title ); - QString getTitle() const { return myTitle; } - void displayCurve( Plot2d_Curve* curve, bool update = false ); - void displayCurves( const curveList& curves, bool update = false ); - void eraseCurve( Plot2d_Curve* curve, bool update = false ); - void eraseCurves( const curveList& curves, bool update = false ); - int getCurves( curveList& clist ); - const CurveDict& getCurves() { return myCurves; } - int hasCurve( Plot2d_Curve* curve ); - bool isVisible( Plot2d_Curve* curve ); - void updateCurve( Plot2d_Curve* curve, bool update = false ); - void updateLegend( const Plot2d_Prs* prs ); - void fitAll(); - void fitArea( const QRect& area ); - void fitData(const int mode, - const double xMin, const double xMax, - const double yMin, const double yMax, - const double y2Min = 0, const double y2Max = 0); - - void getFitRanges(double& xMin, double& xMax, - double& yMin, double& yMax, - double& y2Min, double& y2Max); + void updateTitles(); + void setTitle( const QString& ); + QString getTitle() const; + + /* addition MultiX */ + void createCurveTooltips( Plot2d_Curve *curve, + Plot2d_QwtPlotPicker *picker); + + void displayPlot2dCurveList( QList< QList > sysCoCurveList, + Plot2d_QwtPlotPicker* picker, + bool displayLegend); + + void displayPlot2dCurveList( QList curveList, + int groupsize, + Plot2d_QwtPlotPicker* picker, + bool displayLegend); + + Plot2d_Curve* createPlot2dCurve( QString & title, + QString & unit, + QList & xList, + QList & yList, + QList & tooltipList, + Plot2d::LineType lineKind, + int lineWidth, + QColor & lineColor, + QwtSymbol::Style markerKind, + Plot2d_QwtPlotPicker* picker, + bool toDraw, + bool displayLegend=true); + + QColor getPlot2dCurveColor( Plot2d_Curve* plot2dCurve); + + void createSegment( double *X, double *Y, int nbPoint, + Qt::PenStyle lineKind, + int lineWidth, + QColor & lineColor, + QwtSymbol::Style markerKind); + + /* curves operations [ obsolete ] */ + void displayCurve( Plot2d_Curve*, bool = false ); + void displayCurves( const curveList&, bool = false ); + void eraseCurve( Plot2d_Curve*, bool = false ); + void eraseCurves( const curveList&, bool = false ); + int getCurves( curveList& ) const; + CurveDict getCurves() const; + void updateCurve( Plot2d_Curve*, bool = false ); + void processFiltering(bool = false); + + /* objects operations */ + QwtPlotItem* displayObject( Plot2d_Object*, bool = false ); + void displayObjects( const objectList&, bool = false ); + void eraseObject( Plot2d_Object*, bool = false ); + void eraseObjects( const objectList&, bool = false ); + int getObjects( objectList& ) const; + bool isVisible( Plot2d_Object* ) const; + void updateObject( Plot2d_Object*, bool = false ); + + void updateLegend( const Plot2d_Prs* ); + void updateLegend(); + void fitAll(); + void fitArea( const QRect& ); + void fitData( const int, const double, const double, + const double, const double, + const double = 0, const double = 0 ); + + void getFitRanges( double&, double&, double&, double&, + double&, double&); + + void getFitRangeByCurves( double&, double&, double&, double&, + double&, double& ); + + void addAnalyticalCurve( Plot2d_AnalyticalCurve* ); + void removeAnalyticalCurve( Plot2d_AnalyticalCurve* ); + void updateAnalyticalCurve( Plot2d_AnalyticalCurve*, bool = false ); + void updateAnalyticalCurves(); + void deselectAnalyticalCurves(); + void deselectObjects(); + + AnalyticalCurveList getAnalyticalCurves() const; + Plot2d_AnalyticalCurve* getAnalyticalCurve(QwtPlotItem *); /* view parameters */ - void copyPreferences( Plot2d_ViewFrame* ); - void setCurveType( int curveType, bool update = true ); - int getCurveType() const { return myCurveType; } - void setCurveTitle( int curveKey, const QString& title ); - void showLegend( bool show, bool update = true ); - void setLegendPos( int pos ); - int getLegendPos() const { return myLegendPos; } - void setMarkerSize( const int size, bool update = true ); - int getMarkerSize() const { return myMarkerSize; } - void setBackgroundColor( const QColor& color ); - QColor backgroundColor() const; - void setXGrid( bool xMajorEnabled, const int xMajorMax, - bool xMinorEnabled, const int xMinorMax, bool update = true ); - void setYGrid( bool yMajorEnabled, const int yMajorMax, - bool yMinorEnabled, const int yMinorMax, - bool y2MajorEnabled, const int y2MajorMax, - bool y2MinorEnabled, const int y2MinorMax, bool update = true ); - void setTitle( bool enabled, const QString& title, ObjectType type, bool update = true ); - QString getTitle( ObjectType type ) const; - - void setFont( const QFont& font, ObjectType type, bool update = true ); - void setHorScaleMode( const int mode, bool update = true ); - int getHorScaleMode() const { return myXMode; } - void setVerScaleMode( const int mode, bool update = true ); - int getVerScaleMode() const { return myYMode; } - - bool isModeHorLinear(); - bool isModeVerLinear(); - bool isLegendShow() { return myShowLegend; }; + void copyPreferences( Plot2d_ViewFrame* ); + void setCurveType( int, bool = true ); + int getCurveType() const; + void setCurveTitle( Plot2d_Curve*, const QString& ); + void setObjectTitle( Plot2d_Object*, const QString& ); + void showLegend( bool, bool = true ); + void setLegendPos( int ); + int getLegendPos() const; + void setLegendFont( const QFont& ); + QFont getLegendFont() const; + void setLegendFontColor( const QColor& ); + QColor getLegendFontColor() const; + void setMarkerSize( const int, bool = true ); + int getMarkerSize() const; + void setBackgroundColor( const QColor& ); + QColor backgroundColor() const; + void setXGrid( bool, const int, bool, const int, bool = true ); + void setYGrid( bool, const int, bool, const int, + bool, const int, bool, const int, bool = true ); + void setTitle( bool, const QString&, ObjectType, bool = true ); + QString getTitle( ObjectType ) const; + + void setFont( const QFont&, ObjectType, bool = true ); + void setHorScaleMode( const int, bool = true ); + int getHorScaleMode() const; + void setVerScaleMode( const int, bool = true ); + int getVerScaleMode() const; + void setNormLMaxMode( bool, bool = true); + bool getNormLMaxMode()const; + void setNormLMinMode( bool, bool = true); + bool getNormLMinMode()const; + void setNormRMaxMode( bool, bool = true); + bool getNormRMaxMode()const; + void setNormRMinMode( bool, bool = true); + bool getNormRMinMode()const; + + + bool isModeHorLinear(); + bool isModeVerLinear(); + bool isNormLMaxMode(); + bool isNormLMinMode(); + bool isNormRMaxMode(); + bool isNormRMinMode(); + + bool isLegendShow() const; // Protection against QwtCurve::drawLines() bug in Qwt 0.4.x: // it crashes if switched to X/Y logarithmic mode, when one or more points have // non-positive X/Y coordinate - bool isXLogEnabled() const; - bool isYLogEnabled() const; + bool isXLogEnabled() const; + bool isYLogEnabled() const; + void setEnableAxis( QwtPlot::Axis, bool ); + + virtual bool print( const QString&, const QString& ) const; + void printPlot( QPainter*, const QRect&, + const QwtPlotPrintFilter& = QwtPlotPrintFilter() ) const; + + QString getVisualParameters(); + void setVisualParameters( const QString& ); - virtual bool print( const QString& file, const QString& format ) const; + void incrementalPan ( const int, const int ); + void incrementalZoom( const int, const int ); - QString getVisualParameters(); - void setVisualParameters( const QString& parameters ); + QwtPlotCanvas* getPlotCanvas() const; + Plot2d_Curve* getClosestCurve( QPoint, double&, int& ) const; + + Plot2d_Object* getPlotObject( QwtPlotItem* ) const; + QwtPlotItem* getPlotObject( Plot2d_Object* ) const; + QwtPlotCurve* getPlotCurve( Plot2d_Curve* ) const; + Plot2d_Plot2d* getPlot() const { return myPlot; } + void updatePlotItem(Plot2d_Object*, QwtPlotItem*); protected: - int testOperation( const QMouseEvent& ); - void readPreferences(); - void writePreferences(); - QString getInfo( const QPoint& pnt ); - virtual void wheelEvent( QWheelEvent* ); + int testOperation( const QMouseEvent& ); + void readPreferences(); + void writePreferences(); + QString getInfo( const QPoint& ); + virtual void wheelEvent( QWheelEvent* ); + bool hasPlotCurve( Plot2d_Curve* ) const; + void setCurveType( QwtPlotCurve*, int ); + bool hasPlotObject( Plot2d_Object* ) const; + QString getXmlVisualParameters(); + bool setXmlVisualParameters(const QString&); + + + + public slots: - void onViewPan(); - void onViewZoom(); - void onViewFitAll(); - void onViewFitArea(); - void onViewGlobalPan(); - void onSettings(); - void onFitData(); - void onChangeBackground(); + void onViewPan(); + void onViewZoom(); + void onViewFitAll(); + void onViewFitArea(); + void onViewGlobalPan(); + void onSettings(); + void onAnalyticalCurve(); + void onFitData(); + void onChangeBackground(); + void onPanLeft(); + void onPanRight(); + void onPanUp(); + void onPanDown(); + void onZoomIn(); + void onZoomOut(); -protected slots: - void plotMousePressed( const QMouseEvent& ); - void plotMouseMoved( const QMouseEvent& ); - void plotMouseReleased( const QMouseEvent& ); +protected: + virtual void customEvent( QEvent* ); + void plotMousePressed( const QMouseEvent& ); + bool plotMouseMoved( const QMouseEvent& ); + void plotMouseReleased( const QMouseEvent& ); signals: - void vpModeHorChanged(); - void vpModeVerChanged(); - void vpCurveChanged(); - void contextMenuRequested( QContextMenuEvent *e ); + void vpModeHorChanged(); + void vpModeVerChanged(); + void vpNormLModeChanged(); + void vpNormRModeChanged(); + void vpCurveChanged(); + void contextMenuRequested( QContextMenuEvent* ); + void legendClicked( QwtPlotItem* ); protected: - Plot2d_Plot2d* myPlot; - int myOperation; - QPoint myPnt; - CurveDict myCurves; - - int myCurveType; - bool myShowLegend; - int myLegendPos; - int myMarkerSize; - QColor myBackground; - QString myTitle, myXTitle, myYTitle, myY2Title; - bool myTitleEnabled, myXTitleEnabled, myYTitleEnabled, myY2TitleEnabled; - bool myXGridMajorEnabled, myYGridMajorEnabled, myY2GridMajorEnabled; - bool myXGridMinorEnabled, myYGridMinorEnabled, myY2GridMinorEnabled; - int myXGridMaxMajor, myYGridMaxMajor, myY2GridMaxMajor; - int myXGridMaxMinor, myYGridMaxMinor, myY2GridMaxMinor; - int myXMode, myYMode; - double myXDistance, myYDistance, myYDistance2; - bool mySecondY; + Plot2d_Plot2d* myPlot; + int myOperation; + QPoint myPnt; + + int myCurveType; + bool myShowLegend; + int myLegendPos; + QFont myLegendFont; + QColor myLegendColor; + int myMarkerSize; + QColor myBackground; + QString myTitle, myXTitle, myYTitle, myY2Title; + bool myTitleEnabled, myXTitleEnabled, myYTitleEnabled, myY2TitleEnabled; + bool myXGridMajorEnabled, myYGridMajorEnabled, myY2GridMajorEnabled; + bool myXGridMinorEnabled, myYGridMinorEnabled, myY2GridMinorEnabled; + int myXGridMaxMajor, myYGridMaxMajor, myY2GridMaxMajor; + int myXGridMaxMinor, myYGridMaxMinor, myY2GridMaxMinor; + int myXMode, myYMode; + bool myNormLMin, myNormLMax, myNormRMin, myNormRMax; + double myXDistance, myYDistance, myYDistance2; + bool mySecondY; + ObjectDict myObjects; + AnalyticalCurveList myAnalyticalCurves; + Plot2d_NormalizeAlgorithm* myLNormAlgo; + Plot2d_NormalizeAlgorithm* myRNormAlgo; + bool myIsDefTitle; + private: + // List of QwtPlotCurve curves to draw (created by Plot2d_Curve::createPlotItem() ) + QList myQwtPlotCurveList; + + // List of intermittent segments to connect curves + QList myIntermittentSegmentList; + + // List of markers associated with curves points + QList myMarkerList; + + // List of curves Plot2d_Curve + QList myPlot2dCurveList; }; class Plot2d_Plot2d : public QwtPlot { + Q_OBJECT public: - Plot2d_Plot2d( QWidget* parent ); - - void replot(); - void getNextMarker( QwtSymbol::Style& typeMarker, QColor& color, Qt::PenStyle& typeLine ); - QwtLegend* getLegend() { -#if QWT_VERSION < 0x040200 - return d_legend; -#else - return legend(); /* mpv: porting to the Qwt 4.2.0 */ -#endif - } - virtual QSize sizeHint() const; - virtual QSizePolicy sizePolicy() const; - virtual QSize minimumSizeHint() const; + Plot2d_Plot2d( QWidget* ); + virtual ~Plot2d_Plot2d(); + + void setLogScale( int, bool ); + + void replot(); + QwtLegend* getLegend(); + QSize sizeHint() const; + QSize minimumSizeHint() const; + void defaultPicker(); + void setPickerMousePattern( int, int = Qt::NoButton ); + void setPicker( Plot2d_QwtPlotPicker *picker); + Plot2d_QwtPlotPicker* getPicker() { return myPicker; } + Plot2d_AxisScaleDraw* getScaleDraw() { return myScaleDraw; } + QList getSeparationLineList() { return mySeparationLineList; } + void clearSeparationLineList(); + QwtPlotMarker *createMarkerAndTooltip( QwtSymbol symbol, + double X, + double Y, + QString & tooltip, + Plot2d_QwtPlotPicker *picker); + + bool polished() const; + QwtPlotGrid* grid() const; + QwtPlotZoomer* zoomer() const; + + virtual void updateYAxisIdentifiers(); + + // Methods to deal with axes ticks + + void createAxisScaleDraw(); + void applyTicks(); + void unactivAxisScaleDraw( int numcall); + + void displayXTicksAndLabels( + double XLeftmargin, double XRightMargin, + const QList< QPair< QString, QMap > > & devicesPosLabelTicks); + + void createSeparationLine( double Xpos); + + +public slots: + virtual void polish(); + +protected slots: + void onScaleDivChanged(); protected: - bool existMarker( const QwtSymbol::Style typeMarker, const QColor& color, const Qt::PenStyle typeLine ); + QwtPlotGrid* myGrid; + QList myColors; + bool myIsPolished; + QwtPlotZoomer* myPlotZoomer; + Plot2d_AxisScaleDraw* myScaleDraw; + // The point picker associated with the graphic view + Plot2d_QwtPlotPicker *myPicker; +private: + // List of verticals segments between two curves + QList mySeparationLineList; +}; + +class Plot2d_ScaleDraw: public QwtScaleDraw +{ +public: + Plot2d_ScaleDraw( char f = 'g', int prec = 6 ); + Plot2d_ScaleDraw( const QwtScaleDraw& scaleDraw, char f = 'g', int prec = 6 ); + + virtual QwtText label( double value ) const; + + int precision() const { return myPrecision; } + +private: + char myFormat; + int myPrecision; +}; + +class Plot2d_YScaleDraw: public QwtScaleDraw +{ +public: + Plot2d_YScaleDraw(); + + virtual QwtText label( double value ) const; +}; + +/* Definition of X axis graduations + */ +class Plot2d_AxisScaleDraw: public QwtScaleDraw +{ +public: + static const QString DEVICE_FONT; + static const int DEVICE_FONT_SIZE; + static const int DEVICE_BY; + + Plot2d_AxisScaleDraw(Plot2d_Plot2d* plot); + + virtual ~Plot2d_AxisScaleDraw(); + + void unactivTicksDrawing( int numcall); + + virtual void draw( QPainter * painter, const QPalette & palette) const; + + virtual QwtText label(double value) const; + + void setLabelTick(double value, QString label, bool isDevice = false); + + void setTicks(const QList aTicks); + + void setInterval(double lowerBound, double upperBound); + + void applyTicks(); + +protected: + + void drawLabel( QPainter* painter, double value) const; + + void drawTick( QPainter* painter, double value, int len) const; + +private: + bool myActivTicksDrawing; // true => activate drawing ticks (with draw() ) + int myNumTicksDrawingCall; // call number to ticks drawing + + // Ticks list to display on X axis + QMap myLabelX; // position, label + // + QList myTicks; // positions + + // Systems names to display under X axis + QMap myLabelDevice; + + Plot2d_Plot2d* myPlot; // Drawing zone QwtPlot + + double myLowerBound; + double myUpperBound; +}; + + + + +/* Management of tooltips associated with markers for curves points or others points + */ +class Plot2d_QwtPlotPicker : public QwtPlotPicker +{ +public: + static const double BOUND_HV_SIZE; + + Plot2d_QwtPlotPicker( int xAxis, + int yAxis, + int selectionFlags, + RubberBand rubberBand, + DisplayMode trackerMode, + QwtPlotCanvas *canvas); + + Plot2d_QwtPlotPicker( int xAxis, + int yAxis, + QwtPlotCanvas *canvas); + + virtual ~Plot2d_QwtPlotPicker(); + + QList pMarkers; // points markers + QMap pMarkersToolTip; // associations (marker,tooltip) protected: - QValueList myColors; + + virtual QwtText trackerText( const QwtDoublePoint & pos ) const; + }; #endif