Salome HOME
PR: mergefrom_PAL_OCC_21Oct04
[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   /* Reimplemented from SALOME_View */
82   void          Display( const SALOME_Prs2d* );
83   void          Erase( const SALOME_Prs2d*, const bool = false );
84   SALOME_Prs*   CreatePrs( const char* entry = 0 );
85   virtual void  BeforeDisplay( SALOME_Displayer* d );
86   virtual void  AfterDisplay ( SALOME_Displayer* d );
87
88   /* event filter */
89   bool    eventFilter( QObject* o, QEvent* e );
90
91   /* operations */
92   void    setTitle( const QString& title );
93   QString getTitle() const { return myTitle; }
94   void    displayCurve( Plot2d_Curve* curve, bool update = false );
95   void    displayCurves( Plot2d_CurveContainer& curves, bool update = false );
96   void    eraseCurve( Plot2d_Curve* curve, bool update = false );
97   void    eraseCurves( Plot2d_CurveContainer& curves, bool update = false );
98   int     getCurves( QList<Plot2d_Curve>& clist );
99   int     hasCurve( Plot2d_Curve* curve );
100   Plot2d_Curve* getCurveByIO( const Handle(SALOME_InteractiveObject)& theIObject );
101   void    updateCurve( Plot2d_Curve* curve, bool update = false );
102   void    fitAll();
103   void    fitArea( const QRect& area );
104
105   /* view parameters */
106   void    setCurveType( int curveType, bool update = true );
107   int     getCurveType() const { return myCurveType; }
108   void    showLegend( bool show, bool update = true );
109   void    setLegendPos( int pos );
110   int     getLegendPos() const { return myLegendPos; }
111   void    setMarkerSize( const int size, bool update = true  );
112   int     getMarkerSize() const { return myMarkerSize; }
113   void    setBackgroundColor( const QColor& color );
114   QColor  backgroundColor() const;
115   void    setXGrid( bool xMajorEnabled, const int xMajorMax, bool xMinorEnabled, const int xMinorMax, bool update = true );
116   void    setYGrid( bool yMajorEnabled, const int yMajorMax, bool yMinorEnabled, const int yMinorMax, bool update = true );
117   void    setMainTitle( bool enabled, const QString& title,  bool update = true);
118   void    setXTitle( bool enabled, const QString& title, bool update = true );
119   QString getXTitle() const { return myXTitle; }
120   void    setYTitle( bool enabled, const QString& title, bool update = true );
121   QString getYTitle() const { return myYTitle; }
122   void    setHorScaleMode( const int mode, bool update = true );
123   int     getHorScaleMode() const { return myXMode; }
124   void    setVerScaleMode( const int mode, bool update = true );
125   int     getVerScaleMode() const { return myYMode; }
126
127 protected:
128   void    createActions();
129   int     testOperation( const QMouseEvent& );
130   void    readPreferences();
131   void    writePreferences();
132   QString getInfo( const QPoint& pnt );
133   void    updateTitles();
134
135 public slots:
136   void    onViewPan(); 
137   void    onViewZoom();
138   void    onViewFitAll();
139   void    onViewFitArea();
140   void    onViewGlobalPan(); 
141   void    onViewRotate();
142   void    onViewReset();     
143   void    onViewFront(); 
144   void    onViewBack(); 
145   void    onViewRight(); 
146   void    onViewLeft();     
147   void    onViewBottom();
148   void    onViewTop();
149   void    onViewTrihedron(); 
150   void    onHorMode();
151   void    onVerMode();
152   void    onLegend();
153   void    onCurves();
154   void    onSettings();
155   void    onFitData();
156   void    onChangeBackground();
157
158 protected slots:
159   void    onLegendClicked( long key );
160   void    plotMousePressed( const QMouseEvent& );
161   void    plotMouseMoved( const QMouseEvent& );
162   void    plotMouseReleased( const QMouseEvent& );
163
164 private:
165   Plot2d_Plot2d*               myPlot;
166   ActionMap                    myActions;
167   int                          myOperation;
168   QPoint                       myPnt;
169   CurveDict                    myCurves;
170
171   int                          myCurveType;
172   bool                         myShowLegend;
173   int                          myLegendPos;
174   int                          myMarkerSize;
175   QColor                       myBackground;
176   QString                      myTitle, myXTitle, myYTitle;
177   bool                         myTitleEnabled, myXTitleEnabled, myYTitleEnabled;
178   bool                         myXGridMajorEnabled, myYGridMajorEnabled;
179   bool                         myXGridMinorEnabled, myYGridMinorEnabled;
180   int                          myXGridMaxMajor, myYGridMaxMajor;
181   int                          myXGridMaxMinor, myYGridMaxMinor;
182   int                          myXMode, myYMode;
183 };
184
185 //=================================================================================
186 // class    : Plot2d_Plot2d
187 // purpose  : Plot2d View
188 //=================================================================================
189 class Plot2d_Plot2d : public QwtPlot 
190 {
191 public:
192   Plot2d_Plot2d( QWidget* parent );
193
194   void       replot();
195   void       getNextMarker( QwtSymbol::Style& typeMarker, QColor& color, Qt::PenStyle& typeLine );
196   QwtLegend* getLegend() { return d_legend; }
197
198 protected:
199   bool       existMarker( const QwtSymbol::Style typeMarker, const QColor& color, const Qt::PenStyle typeLine );
200
201 protected:
202   QValueList<QColor> myColors;
203 };
204
205 #endif // Plot2d_ViewFrame_H
206
207
208
209