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