Salome HOME
DCQ : Merge with Ecole_ete_a6.
[modules/kernel.git] / src / Plot2d / Plot2d_ViewFrame.h
1 //  Copyright (C) 2003  CEA/DEN, EDF R&D
2 //
3 //
4 //
5 //  File   : Plot2d_ViewFrame.h
6 //  Author : Vadim SANDLER
7 //  Module : SALOME
8 //  $Header$
9
10 #ifndef Plot2d_ViewFrame_H
11 #define Plot2d_ViewFrame_H
12
13 #include "QAD_ViewFrame.h"
14 #include "QAD_Popup.h"
15 #include "QAD_Action.h"
16 #include "Plot2d_Curve.h"
17 #include "Plot2d_CurveContainer.h"
18 #include "SALOME_Selection.h"
19 #include <qmainwindow.h>
20 #include <qmap.h>
21 #include <qintdict.h>
22 #include <qwt_plot.h>
23 #include <qwt_legend.h>
24
25 //=================================================================================
26 // class    : Plot2d_ViewFrame
27 // purpose  : Plot2d view frame
28 //=================================================================================
29 class Plot2d_Plot2d;
30 typedef QIntDict<Plot2d_Curve> CurveDict;
31
32 class QAD_EXPORT Plot2d_ViewFrame : public QAD_ViewFrame, public QAD_PopupClientServer 
33
34   Q_OBJECT
35
36   enum { NoOpId, FitAllId, FitAreaId, ZoomId, PanId, DumpId, 
37          ModeXLinearId, ModeXLogarithmicId, ModeYLinearId, ModeYLogarithmicId,
38          LegendId, CurvePointsId, CurveLinesId, CurveSplinesId, SettingsId, FitDataId, ChangeBackgroundId };
39 public:
40   /* Construction/destruction */
41   Plot2d_ViewFrame( QWidget* parent, const QString& title = "" );
42   virtual ~Plot2d_ViewFrame();
43
44 public:
45   /* inherited */
46   ViewType          getTypeView() const { return VIEW_PLOT2D; }
47   QWidget*          getViewWidget();
48   void              SetSelectionMode( Selection_Mode mode ) {}
49   void              onAdjustTrihedron( ) {}
50
51   /* popup management */
52   void              setPopupServer( QAD_Application* );
53   void              onCreatePopup();
54
55   /*  interactive object management */
56   void              highlight( const Handle(SALOME_InteractiveObject)& IObject, 
57                                bool highlight, bool update = true ) {}
58   void              unHighlightAll() {}
59   void              rename( const Handle(SALOME_InteractiveObject)& IObject,
60                             QString newName );
61   bool              isInViewer( const Handle(SALOME_InteractiveObject)& IObject );
62   bool              isVisible( const Handle(SALOME_InteractiveObject)& IObject );
63
64   /*  undo/redo management */
65   void              undo( SALOMEDS::Study_var aStudy,
66                           const char* StudyFrameEntry ) {}
67   void              redo( SALOMEDS::Study_var aStudy,
68                           const char* StudyFrameEntry ) {}
69
70   /* interactive objects handling */
71   Handle(SALOME_InteractiveObject) FindIObject( const char* Entry );
72
73   /* display */         
74   void           Display( const Handle(SALOME_InteractiveObject)& IObject, bool update = true );
75   void           DisplayOnly( const Handle(SALOME_InteractiveObject)& IObject );
76   void           Erase( const Handle(SALOME_InteractiveObject)& IObject, bool update = true );
77   void           DisplayAll();
78   void           EraseAll();
79   void           Repaint();
80
81   /* event filter */
82   bool    eventFilter( QObject* o, QEvent* e );
83
84   /* operations */
85   void    setTitle( const QString& title );
86   QString getTitle() const { return myTitle; }
87   void    displayCurve( Plot2d_Curve* curve, bool update = false );
88   void    displayCurves( Plot2d_CurveContainer& curves, bool update = false );
89   void    eraseCurve( Plot2d_Curve* curve, bool update = false );
90   void    eraseCurves( Plot2d_CurveContainer& curves, bool update = false );
91   int     getCurves( QList<Plot2d_Curve>& clist );
92   int     hasCurve( Plot2d_Curve* curve );
93   Plot2d_Curve* getCurveByIO( const Handle(SALOME_InteractiveObject)& theIObject );
94   void    updateCurve( Plot2d_Curve* curve, bool update = false );
95   void    fitAll();
96   void    fitArea( const QRect& area );
97
98   /* view parameters */
99   void    setCurveType( int curveType, bool update = true );
100   int     getCurveType() const { return myCurveType; }
101   void    showLegend( bool show, bool update = true );
102   void    setLegendPos( int pos );
103   int     getLegendPos() const { return myLegendPos; }
104   void    setMarkerSize( const int size, bool update = true  );
105   int     getMarkerSize() const { return myMarkerSize; }
106   void    setBackgroundColor( const QColor& color );
107   QColor  backgroundColor() const;
108   void    setXGrid( bool xMajorEnabled, const int xMajorMax, bool xMinorEnabled, const int xMinorMax, bool update = true );
109   void    setYGrid( bool yMajorEnabled, const int yMajorMax, bool yMinorEnabled, const int yMinorMax, bool update = true );
110   void    setMainTitle( bool enabled, const QString& title,  bool update = true);
111   void    setXTitle( bool enabled, const QString& title, bool update = true );
112   QString getXTitle() const { return myXTitle; }
113   void    setYTitle( bool enabled, const QString& title, bool update = true );
114   QString getYTitle() const { return myYTitle; }
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; }
119
120 protected:
121   void    createActions();
122   int     testOperation( const QMouseEvent& );
123   void    readPreferences();
124   void    writePreferences();
125   QString getInfo( const QPoint& pnt );
126   void    updateTitles();
127
128 public slots:
129   void    onViewPan(); 
130   void    onViewZoom();
131   void    onViewFitAll();
132   void    onViewFitArea();
133   void    onViewGlobalPan(); 
134   void    onViewRotate();
135   void    onViewReset();     
136   void    onViewFront(); 
137   void    onViewBack(); 
138   void    onViewRight(); 
139   void    onViewLeft();     
140   void    onViewBottom();
141   void    onViewTop();
142   void    onViewTrihedron(); 
143   void    onHorMode();
144   void    onVerMode();
145   void    onLegend();
146   void    onCurves();
147   void    onSettings();
148   void    onFitData();
149   void    onChangeBackground();
150
151 protected slots:
152   void    onLegendClicked( long key );
153   void    plotMousePressed( const QMouseEvent& );
154   void    plotMouseMoved( const QMouseEvent& );
155   void    plotMouseReleased( const QMouseEvent& );
156
157 private:
158   Plot2d_Plot2d*               myPlot;
159   ActionMap                    myActions;
160   int                          myOperation;
161   QPoint                       myPnt;
162   CurveDict                    myCurves;
163
164   int                          myCurveType;
165   bool                         myShowLegend;
166   int                          myLegendPos;
167   int                          myMarkerSize;
168   QColor                       myBackground;
169   QString                      myTitle, myXTitle, myYTitle;
170   bool                         myTitleEnabled, myXTitleEnabled, myYTitleEnabled;
171   bool                         myXGridMajorEnabled, myYGridMajorEnabled;
172   bool                         myXGridMinorEnabled, myYGridMinorEnabled;
173   int                          myXGridMaxMajor, myYGridMaxMajor;
174   int                          myXGridMaxMinor, myYGridMaxMinor;
175   int                          myXMode, myYMode;
176 };
177
178 //=================================================================================
179 // class    : Plot2d_Plot2d
180 // purpose  : Plot2d View
181 //=================================================================================
182 class Plot2d_Plot2d : public QwtPlot 
183 {
184 public:
185   Plot2d_Plot2d( QWidget* parent );
186
187   void       replot();
188   void       getNextMarker( QwtSymbol::Style& typeMarker, QColor& color, Qt::PenStyle& typeLine );
189   QwtLegend* getLegend() { return d_legend; }
190
191 protected:
192   bool       existMarker( const QwtSymbol::Style typeMarker, const QColor& color, const Qt::PenStyle typeLine );
193
194 protected:
195   QValueList<QColor> myColors;
196 };
197
198 #endif // Plot2d_ViewFrame_H
199
200
201
202