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