Salome HOME
Merge from branch mpa/qwt6_porting
[modules/gui.git] / src / Plot2d / Plot2d_ViewWindow.cxx
1 // Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 // File   : Plot2d_ViewWindow.cxx
24 // Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
25 //
26 #include "Plot2d_ViewWindow.h"
27 #include "Plot2d_ViewFrame.h"
28
29 #include <SUIT_ViewManager.h>
30 #include <SUIT_ResourceMgr.h>
31 #include <SUIT_Session.h>
32 #include <SUIT_Desktop.h>
33 #include <SUIT_MessageBox.h>
34
35 #include <Qtx.h>
36 #include <QtxAction.h>
37 #include <QtxMultiAction.h>
38 #include <QtxActionToolMgr.h>
39
40 #include <QStatusBar>
41 #include <QLayout>
42 #include <QApplication>
43 #include <QMenu>
44 #include <QImage>
45 #include <QToolBar>
46 #include <QPaintEvent>
47 #include <QActionGroup>
48 #include <QPainter>
49 #include <QPrinter>
50 #include <QPrintDialog>
51
52 #include <qwt_plot_curve.h>
53
54 /*!
55   \class Plot2d_ViewWindow
56   \brief Plot2d view window.
57 */
58
59 /*!
60   \brief Constructor.
61   \param theDesktop parent desktop window
62   \param theModel plt2d view model
63 */
64 Plot2d_ViewWindow::Plot2d_ViewWindow( SUIT_Desktop* theDesktop, Plot2d_Viewer* theModel )
65 : SUIT_ViewWindow( theDesktop )
66 {
67   myModel = theModel;
68 }
69
70 /*!
71   \brief Destructor.
72 */
73 Plot2d_ViewWindow::~Plot2d_ViewWindow()
74 {
75 }
76
77 /*!
78   \brief Internal initialization.
79 */
80 void Plot2d_ViewWindow::initLayout()
81 {
82   myDumpImage = QImage();
83   myViewFrame = new Plot2d_ViewFrame( this, "plotView" );
84   setCentralWidget( myViewFrame );
85
86   createActions();
87   createToolBar();
88
89   connect( myViewFrame, SIGNAL( vpModeHorChanged() ), this, SLOT( onChangeHorMode() ) );
90   connect( myViewFrame, SIGNAL( vpModeVerChanged() ), this, SLOT( onChangeVerMode() ) );
91   connect( myViewFrame, SIGNAL( vpNormLModeChanged() ), this, SLOT( onChangeNormLMode() ) );
92   connect( myViewFrame, SIGNAL( vpNormRModeChanged() ), this, SLOT( onChangeNormRMode() ) );
93   connect( myViewFrame, SIGNAL( vpCurveChanged() ),   this, SLOT( onChangeCurveMode() ) );
94   connect( myViewFrame, SIGNAL( contextMenuRequested( QContextMenuEvent* ) ),
95            this,        SIGNAL( contextMenuRequested( QContextMenuEvent* ) ) );
96
97   myViewFrame->installEventFilter( this );
98 }
99
100 /*!
101   \brief Get view model.
102   \return Plot2d view model
103 */
104 Plot2d_Viewer* Plot2d_ViewWindow::getModel()
105 {
106   return myModel;
107 }
108
109 /*!
110   \brief Put message to the status bar.
111   \param theMsg message text
112 */
113 void Plot2d_ViewWindow::putInfo( const QString& theMsg )
114 {
115   QStatusBar* aStatusBar = myDesktop->statusBar();
116   aStatusBar->showMessage( theMsg/*, 3000*/ );
117 }
118
119 /*!
120   \brief Get view frame window.
121   \return view frame window
122 */
123 Plot2d_ViewFrame* Plot2d_ViewWindow::getViewFrame()
124
125   return myViewFrame;
126 }
127
128 /*!
129   \brief Get view window's toolbar.
130   \return toolbar
131 */
132 QToolBar* Plot2d_ViewWindow::getToolBar()
133 {
134   return toolMgr()->toolBar( myToolBar );
135 }
136
137 /*!
138   \brief Fill popup menu with the actions,
139   \param thePopup popup menu
140 */
141 void Plot2d_ViewWindow::contextMenuPopup( QMenu* thePopup )
142 {
143   QtxActionToolMgr* mgr = toolMgr();
144   // scaling
145   QMenu* scalingPopup = thePopup->addMenu( tr( "SCALING_POPUP" ) );
146   scalingPopup->addAction( mgr->action( PModeXLinearId ) );
147   scalingPopup->addAction( mgr->action( PModeXLogarithmicId ) );
148   scalingPopup->addSeparator();
149   scalingPopup->addAction( mgr->action( PModeYLinearId ) );
150   scalingPopup->addAction( mgr->action( PModeYLogarithmicId ) );
151
152   // fit data
153   thePopup->addAction( tr( "TOT_PLOT2D_FITDATA" ), myViewFrame, SLOT( onFitData() ) );
154
155   // curve type
156   QMenu* curTypePopup = thePopup->addMenu( tr( "CURVE_TYPE_POPUP" ) );
157   curTypePopup->addAction( mgr->action( CurvPointsId ) );
158   curTypePopup->addAction( mgr->action( CurvLinesId ) );
159   curTypePopup->addAction( mgr->action( CurvSplinesId ) );
160
161   //Normalization type
162   QMenu* normTypePopup = thePopup->addMenu( tr( "NORMALIZATION_TYPE_POPUP" ) );
163   normTypePopup->addAction( mgr->action( PModeNormLMinId ) );
164   normTypePopup->addAction( mgr->action( PModeNormLMaxId ) );
165   normTypePopup->addSeparator();
166   normTypePopup->addAction( mgr->action( PModeNormRMinId ) );
167   normTypePopup->addAction( mgr->action( PModeNormRMaxId ) );
168
169
170   // legend
171   thePopup->addAction( mgr->action( LegendId ) );
172
173   // settings
174   thePopup->addAction( mgr->action( CurvSettingsId ) );
175 }
176
177 /*!
178   \brief Custom event filter.
179   \param watched event receiver object
180   \param e event
181   \return \c true if further event processing should be stopped
182 */
183 bool Plot2d_ViewWindow::eventFilter( QObject* watched, QEvent* e )
184 {
185   if ( watched == myViewFrame ) {
186     switch( e->type() ) {
187     case QEvent::MouseButtonPress:
188       emit mousePressed( this, (QMouseEvent*)e );
189       return true;
190     case QEvent::MouseButtonRelease:
191       emit mouseReleased( this, (QMouseEvent*)e );
192       return true;
193     case QEvent::MouseMove:
194       emit mouseMoving( this, (QMouseEvent*)e );
195       return true;
196     default:
197       break;
198     }
199   }
200   return SUIT_ViewWindow::eventFilter( watched, e );
201 }
202
203 /*!
204   \brief Create actions for the view window.
205 */
206 void Plot2d_ViewWindow::createActions()
207 {
208   QtxActionToolMgr* mgr = toolMgr();
209   QtxAction* aAction;
210   SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
211
212   // 1. Dump View
213   aAction = new QtxAction( tr( "MNU_DUMP_VIEW" ),
214                            aResMgr->loadPixmap( "Plot2d", tr( "ICON_PLOT2D_DUMP" ) ),
215                            tr( "MNU_DUMP_VIEW" ),
216                            0, this);
217   aAction->setStatusTip( tr( "DSC_DUMP_VIEW" ) );
218   connect( aAction, SIGNAL( triggered( bool ) ), this, SLOT( onDumpView() ) );
219   mgr->registerAction( aAction, DumpId );
220
221   // 2. Scaling operations
222
223   // 2.1. Fit All
224   aAction = new QtxAction( tr( "MNU_FITALL" ),
225                            aResMgr->loadPixmap( "Plot2d", tr( "ICON_PLOT2D_FIT_ALL" ) ),
226                            tr( "MNU_FITALL" ),
227                            0, this);
228   aAction->setStatusTip( tr( "DSC_FITALL" ) );
229   connect( aAction, SIGNAL( triggered( bool ) ), this, SLOT( onFitAll() ) );
230   mgr->registerAction( aAction, FitAllId );
231
232   // 2.2. Fit Rect
233   aAction = new QtxAction( tr( "MNU_FITRECT" ),
234                            aResMgr->loadPixmap( "Plot2d", tr( "ICON_PLOT2D_FIT_AREA" ) ),
235                            tr( "MNU_FITRECT" ),
236                            0, this);
237   aAction->setStatusTip( tr( "DSC_FITRECT" ) );
238   connect( aAction, SIGNAL( triggered( bool ) ), this, SLOT( onFitRect() ) );
239   mgr->registerAction( aAction, FitRectId );
240
241   // 2.3. Zoom
242   aAction = new QtxAction( tr( "MNU_ZOOM_VIEW" ),
243                            aResMgr->loadPixmap( "Plot2d", tr( "ICON_PLOT2D_ZOOM" ) ),
244                            tr( "MNU_ZOOM_VIEW" ),
245                            0, this);
246   aAction->setStatusTip( tr( "DSC_ZOOM_VIEW" ) );
247   connect( aAction, SIGNAL( triggered( bool ) ), this, SLOT( onZoom() ) );
248   mgr->registerAction( aAction, ZoomId );
249
250   // 2.4. Create multi-action for scaling operations
251   QtxMultiAction* aScaleAction = new QtxMultiAction( this );
252   aScaleAction->insertAction( mgr->action( FitAllId  ) );
253   aScaleAction->insertAction( mgr->action( FitRectId ) );
254   aScaleAction->insertAction( mgr->action( ZoomId    ) );
255   mgr->registerAction( aScaleAction, ScaleOpId );
256
257   // 3. Moving operations
258
259   // 3.1. Panning
260   aAction = new QtxAction( tr( "MNU_PAN_VIEW" ),
261                            aResMgr->loadPixmap( "Plot2d", tr( "ICON_PLOT2D_PAN" ) ),
262                            tr( "MNU_PAN_VIEW" ), 
263                            0, this);
264   aAction->setStatusTip( tr( "DSC_PAN_VIEW" ) );
265   connect( aAction, SIGNAL( triggered( bool ) ), this, SLOT( onPanning() ) );
266   mgr->registerAction( aAction, PanId );
267
268   // 3.2. Global Panning
269   aAction = new QtxAction( tr( "MNU_GLOBALPAN_VIEW" ),
270                            aResMgr->loadPixmap( "Plot2d", tr( "ICON_PLOT2D_GLOBALPAN" ) ),
271                            tr( "MNU_GLOBALPAN_VIEW" ),
272                            0, this);
273   aAction->setStatusTip( tr( "DSC_GLOBALPAN_VIEW" ) );
274   connect( aAction, SIGNAL( triggered( bool ) ), this, SLOT( onGlobalPanning() ) );
275   mgr->registerAction( aAction, GlobalPanId );
276
277   // 3.3. Create multi-action for moving operations
278   QtxMultiAction* aPanAction = new QtxMultiAction( this );
279   aPanAction->insertAction( mgr->action( PanId ) );
280   aPanAction->insertAction( mgr->action( GlobalPanId ) );
281   mgr->registerAction( aPanAction, MoveOpId );
282
283   // 4. Curve type operations
284   
285   // 4.1. Points
286   aAction = new QtxAction( tr( "TOT_PLOT2D_CURVES_POINTS" ),
287                            aResMgr->loadPixmap( "Plot2d", tr( "ICON_PLOT2D_CURVES_POINTS" ) ),
288                            tr( "MEN_PLOT2D_CURVES_POINTS" ),
289                            0, this );
290   aAction->setStatusTip( tr( "PRP_PLOT2D_CURVES_POINTS" ) );
291   aAction->setCheckable( true );
292   mgr->registerAction( aAction, CurvPointsId );
293
294   // 4.2. Lines
295   aAction = new QtxAction( tr( "TOT_PLOT2D_CURVES_LINES" ),
296                            aResMgr->loadPixmap( "Plot2d", tr( "ICON_PLOT2D_CURVES_LINES" ) ),
297                            tr( "MEN_PLOT2D_CURVES_LINES" ),
298                            0, this );
299   aAction->setStatusTip( tr( "PRP_PLOT2D_CURVES_LINES" ) );
300   aAction->setCheckable( true );
301   mgr->registerAction( aAction, CurvLinesId );
302
303   // 4.3. Splines
304   aAction = new QtxAction( tr( "TOT_PLOT2D_CURVES_SPLINES" ),
305                            aResMgr->loadPixmap( "Plot2d", tr( "ICON_PLOT2D_CURVES_SPLINES" ) ),
306                            tr( "MEN_PLOT2D_CURVES_SPLINES" ),
307                            0, this );
308   aAction->setStatusTip( tr( "PRP_PLOT2D_CURVES_SPLINES" ) );
309   aAction->setCheckable( true );
310   mgr->registerAction( aAction, CurvSplinesId );
311
312   // 4.4. Create action group for curve type operations
313   QActionGroup* aCurveGroup = new QActionGroup( this );
314   aCurveGroup->addAction( mgr->action( CurvPointsId ) );
315   aCurveGroup->addAction( mgr->action( CurvLinesId ) );
316   aCurveGroup->addAction( mgr->action( CurvSplinesId ) );
317   connect( aCurveGroup, SIGNAL( triggered( QAction* ) ), this, SLOT( onCurves() ) );
318
319   // 5. Horizontal scaling mode operations
320
321   // 5.1. Linear
322   aAction = new QtxAction( tr( "TOT_PLOT2D_MODE_LINEAR_HOR" ),
323                            aResMgr->loadPixmap( "Plot2d", tr( "ICON_PLOT2D_MODE_LINEAR_HOR" ) ),
324                            tr( "MEN_PLOT2D_MODE_LINEAR_HOR" ),
325                            0, this );
326   aAction->setStatusTip( tr( "PRP_PLOT2D_MODE_LINEAR_HOR" ) );
327   connect( aAction, SIGNAL( triggered( bool ) ), this, SLOT( onViewHorMode() ) );
328   aAction->setCheckable( true );
329   mgr->registerAction( aAction, PModeXLinearId );
330   
331   // 5.2. Logarithmic
332   aAction = new QtxAction( tr( "TOT_PLOT2D_MODE_LOGARITHMIC_HOR" ),
333                            aResMgr->loadPixmap( "Plot2d", tr( "ICON_PLOT2D_MODE_LOGARITHMIC_HOR" ) ),
334                            tr( "MEN_PLOT2D_MODE_LOGARITHMIC_HOR" ),
335                            0, this );
336   aAction->setStatusTip( tr( "PRP_PLOT2D_MODE_LOGARITHMIC_HOR" ) );
337   connect( aAction, SIGNAL( triggered( bool ) ), this, SLOT( onViewHorMode() ) );
338   aAction->setCheckable( true );
339   mgr->registerAction( aAction, PModeXLogarithmicId );
340
341   // 5.3. Create action group for horizontal scaling mode operations
342   QActionGroup* aHorGroup = new QActionGroup( this );
343   aHorGroup->addAction( mgr->action( PModeXLinearId ) );
344   aHorGroup->addAction( mgr->action( PModeXLogarithmicId ) );
345
346   // 6. Vertical scaling mode operations
347
348   // 6.1. Linear
349   aAction = new QtxAction( tr( "TOT_PLOT2D_MODE_LINEAR_VER" ),
350                            aResMgr->loadPixmap( "Plot2d", tr( "ICON_PLOT2D_MODE_LINEAR_VER" ) ),
351                            tr( "MEN_PLOT2D_MODE_LINEAR_VER" ),
352                            0, this );
353   aAction->setStatusTip( tr( "PRP_PLOT2D_MODE_LINEAR_VER" ) );
354   connect( aAction, SIGNAL( triggered( bool ) ), this, SLOT( onViewVerMode() ) );
355   aAction->setCheckable( true );
356   mgr->registerAction( aAction, PModeYLinearId );
357
358   // 6.2. Logarithmic
359   aAction = new QtxAction( tr( "TOT_PLOT2D_MODE_LOGARITHMIC_VER" ),
360                            aResMgr->loadPixmap( "Plot2d", tr( "ICON_PLOT2D_MODE_LOGARITHMIC_VER" ) ),
361                            tr( "MEN_PLOT2D_MODE_LOGARITHMIC_VER" ),
362                            0, this );
363   aAction->setStatusTip( tr( "PRP_PLOT2D_MODE_LOGARITHMIC_VER" ) );
364   connect( aAction, SIGNAL( triggered( bool ) ), this, SLOT( onViewVerMode() ) );
365   aAction->setCheckable( true );
366   mgr->registerAction( aAction, PModeYLogarithmicId );
367
368   // 6.3. Create action group for vertical scaling mode operations
369   QActionGroup* aVerGroup = new QActionGroup( this );
370   aVerGroup->addAction( mgr->action( PModeYLinearId ) );
371   aVerGroup->addAction( mgr->action( PModeYLogarithmicId ) );
372
373   // 7. Normalization mode operations
374
375   // 7.1. Normalize to the global minimum by left Y axis
376   aAction = new QtxAction( tr( "TOT_PLOT2D_NORMALIZE_MODE_LMIN" ),
377                            aResMgr->loadPixmap( "Plot2d", tr( "ICON_PLOT2D_NORMALIZE_MODE_LMIN" ) ),
378                            tr( "MEN_PLOT2D_NORMALIZE_MODE_LMIN" ),
379                            0, this );
380   aAction->setStatusTip( tr( "PRP_PLOT2D_NORMALIZE_MODE_LMIN" ) );
381   connect( aAction, SIGNAL( triggered( bool ) ), this, SLOT( onViewNormLMode() ) );
382   aAction->setCheckable( true );
383   mgr->registerAction( aAction, PModeNormLMinId );
384
385   // 7.2. Normalize to the global maximum by right Y axis
386   aAction = new QtxAction( tr( "TOT_PLOT2D_NORMALIZE_MODE_LMAX" ),
387                            aResMgr->loadPixmap( "Plot2d", tr( "ICON_PLOT2D_NORMALIZE_MODE_LMAX" ) ),
388                            tr( "MEN_PLOT2D_NORMALIZE_MODE_LMAX" ),
389                            0, this );
390   aAction->setStatusTip( tr( "PRP_PLOT2D_NORMALIZE_MODE_LMAX" ) );
391   connect( aAction, SIGNAL( triggered( bool ) ), this, SLOT( onViewNormLMode() ) );
392   aAction->setCheckable( true );
393   mgr->registerAction( aAction, PModeNormLMaxId );
394
395     // 7.3. Normalize to the global minimum by right Y axis
396   aAction = new QtxAction( tr( "TOT_PLOT2D_NORMALIZE_MODE_RMIN" ),
397                            aResMgr->loadPixmap( "Plot2d", tr( "ICON_PLOT2D_NORMALIZE_MODE_RMIN" ) ),
398                            tr( "MEN_PLOT2D_NORMALIZE_MODE_RMIN" ),
399                            0, this );
400   aAction->setStatusTip( tr( "PRP_PLOT2D_NORMALIZE_MODE_RMIN" ) );
401   connect( aAction, SIGNAL( triggered( bool ) ), this, SLOT( onViewNormRMode() ) );
402   aAction->setCheckable( true );
403   mgr->registerAction( aAction, PModeNormRMinId );
404
405   // 7.4. Normalize to the global maximum by left Y axis
406   aAction = new QtxAction( tr( "TOT_PLOT2D_NORMALIZE_MODE_RMAX" ),
407                            aResMgr->loadPixmap( "Plot2d", tr( "ICON_PLOT2D_NORMALIZE_MODE_RMAX" ) ),
408                            tr( "MEN_PLOT2D_NORMALIZE_MODE_RMAX" ),
409                            0, this );
410   aAction->setStatusTip( tr( "PRP_PLOT2D_NORMALIZE_MODE_RMAX" ) );
411   connect( aAction, SIGNAL( triggered( bool ) ), this, SLOT( onViewNormRMode() ) );
412   aAction->setCheckable( true );
413   mgr->registerAction( aAction, PModeNormRMaxId );
414
415   // 8. Legend
416   aAction = new QtxAction( tr( "TOT_PLOT2D_SHOW_LEGEND" ),
417                            aResMgr->loadPixmap( "Plot2d", tr( "ICON_PLOT2D_SHOW_LEGEND" ) ),
418                            tr( "MEN_PLOT2D_SHOW_LEGEND" ),
419                            0, this );
420   aAction->setStatusTip( tr( "PRP_PLOT2D_SHOW_LEGEND" ) );
421   connect( aAction, SIGNAL( triggered( bool ) ), this, SLOT( onLegend() ) );
422   aAction->setCheckable( true );
423   mgr->registerAction( aAction, LegendId );
424
425   // 9. Settings
426   aAction = new QtxAction( tr( "TOT_PLOT2D_SETTINGS" ),
427                            aResMgr->loadPixmap( "Plot2d", tr( "ICON_PLOT2D_SETTINGS" ) ),
428                            tr( "MEN_PLOT2D_SETTINGS" ),
429                            0, this );
430
431   aAction->setStatusTip( tr( "PRP_PLOT2D_SETTINGS" ) );
432   connect( aAction, SIGNAL( triggered( bool ) ), myViewFrame, SLOT( onSettings() ) );
433   mgr->registerAction( aAction, CurvSettingsId );
434
435   // 9. Analytical curves
436 #ifndef DISABLE_PYCONSOLE
437   aAction = new QtxAction( tr( "TOT_PLOT2D_ANALYTICAL_CURVES" ),
438                            aResMgr->loadPixmap( "Plot2d", tr( "ICON_PLOT2D_ANALYTICAL_CURVES" ) ),
439                            tr( "MEN_PLOT2D_ANALYTICAL_CURVES" ),
440                            0, this );
441
442   aAction->setStatusTip( tr( "PRP_PLOT2D_ANALYTICAL_CURVES" ) );
443   connect( aAction, SIGNAL( triggered( bool ) ), myViewFrame, SLOT( onAnalyticalCurve() ) );
444   mgr->registerAction( aAction, AnalyticalCurveId );
445 #endif
446
447   // 10. Clone
448   aAction = new QtxAction( tr( "MNU_CLONE_VIEW" ),
449                            aResMgr->loadPixmap( "Plot2d", tr( "ICON_PLOT2D_CLONE_VIEW" ) ),
450                            tr( "MNU_CLONE_VIEW" ),
451                            0, this);
452   aAction->setStatusTip( tr( "DSC_CLONE_VIEW" ) );
453   connect( aAction, SIGNAL( triggered( bool ) ), this, SIGNAL( cloneView() ) );
454   mgr->registerAction( aAction, CloneId );
455
456   // 11. Print 
457   aAction = new QtxAction( tr( "MNU_PRINT_VIEW" ),
458                            aResMgr->loadPixmap( "STD", tr( "ICON_PLOT2D_PRINT" ) ),
459                            tr( "MNU_PRINT_VIEW" ),
460                            0, this);
461   aAction->setStatusTip( tr( "DSC_PRINT_VIEW" ) );
462   connect( aAction, SIGNAL( triggered( bool ) ), this, SLOT( onPrintView() ) );
463   mgr->registerAction( aAction, PrintId );
464
465   // Set initial values
466   onChangeCurveMode();
467   onChangeHorMode();
468   onChangeVerMode();
469   onChangeNormLMode();
470   onChangeNormRMode();
471   onChangeLegendMode();
472 }
473
474 /*!
475   \brief Create toolbar for the view window.
476 */
477 void Plot2d_ViewWindow::createToolBar()
478 {
479   QtxActionToolMgr* mgr = toolMgr();
480   myToolBar = mgr->createToolBar( tr( "LBL_TOOLBAR_LABEL" ), false );
481   mgr->append( DumpId, myToolBar );
482   mgr->append( ScaleOpId, myToolBar );
483   mgr->append( MoveOpId, myToolBar );
484   mgr->append( toolMgr()->separator(), myToolBar );
485   mgr->append( CurvPointsId, myToolBar );
486   mgr->append( CurvLinesId, myToolBar );
487   mgr->append( CurvSplinesId, myToolBar );
488   mgr->append( toolMgr()->separator(), myToolBar );
489   mgr->append( PModeNormLMaxId, myToolBar );
490   mgr->append( PModeNormLMinId, myToolBar );
491   mgr->append( toolMgr()->separator(), myToolBar );
492   mgr->append( PModeNormRMaxId, myToolBar );
493   mgr->append( PModeNormRMinId, myToolBar );
494   mgr->append( toolMgr()->separator(), myToolBar );
495   mgr->append( PModeXLinearId, myToolBar );
496   mgr->append( PModeXLogarithmicId, myToolBar );
497   mgr->append( toolMgr()->separator(), myToolBar );
498   mgr->append( PModeYLinearId, myToolBar );
499   mgr->append( PModeYLogarithmicId, myToolBar );
500   mgr->append( toolMgr()->separator(), myToolBar );
501   mgr->append( LegendId, myToolBar );
502   mgr->append( CurvSettingsId, myToolBar );
503   mgr->append( AnalyticalCurveId, myToolBar );
504   mgr->append( CloneId, myToolBar );
505   mgr->append( PrintId, myToolBar );
506 }
507
508 /*!
509   \brief Get the visual parameters of the view window.
510   \return visual parameters of this view window formatted to the string
511 */
512 QString Plot2d_ViewWindow::getVisualParameters()
513 {
514   return myViewFrame->getVisualParameters();
515 }
516
517 /*!
518   \brief Restore visual parameters of the view window from the formated string
519   \param parameters view window visual parameters
520 */
521 void Plot2d_ViewWindow::setVisualParameters( const QString& parameters )
522 {
523   myViewFrame->setVisualParameters( parameters );
524 }
525
526 /*!
527   \brief Grab the view window to the internal image.
528 */
529 void Plot2d_ViewWindow::RefreshDumpImage()
530 {
531   QPixmap px = QPixmap::grabWindow( myViewFrame->winId() );
532   myDumpImage = px.toImage();
533 }
534
535 /*!
536   \brief Called when the scale mode for the horizontal axis is changed.
537 */
538 void Plot2d_ViewWindow::onChangeHorMode()
539 {
540   bool aHorLinear = myViewFrame->isModeHorLinear();
541   bool aVerLinear = myViewFrame->isModeVerLinear();
542
543   if ( aHorLinear )
544     toolMgr()->action( PModeXLinearId )->setChecked( true );
545   else
546     toolMgr()->action( PModeXLogarithmicId )->setChecked( true );
547
548   toolMgr()->action( GlobalPanId )->setEnabled( aHorLinear && aVerLinear );
549 }
550
551 /*!
552   \brief Called when the scale mode for the vertical axis is changed.
553 */
554 void Plot2d_ViewWindow::onChangeVerMode()
555 {
556   bool aHorLinear = myViewFrame->isModeHorLinear();
557   bool aVerLinear = myViewFrame->isModeVerLinear();
558
559   if ( aVerLinear )
560     toolMgr()->action( PModeYLinearId )->setChecked( true );
561   else
562     toolMgr()->action( PModeYLogarithmicId )->setChecked( true );
563
564   toolMgr()->action( GlobalPanId )->setEnabled( aHorLinear && aVerLinear );
565 }
566
567 /*!
568   \brief Called when the normalization mode (by left Y axis) for curves is changed.
569 */
570 void Plot2d_ViewWindow::onChangeNormLMode()
571 {
572   bool aNormMax = myViewFrame->isNormLMaxMode();
573   bool aNormMin = myViewFrame->isNormLMinMode();
574
575   if ( aNormMax )
576     toolMgr()->action( PModeNormLMaxId )->setChecked( true );
577   else
578     toolMgr()->action( PModeNormLMaxId )->setChecked( false );
579   if ( aNormMin )
580     toolMgr()->action( PModeNormLMinId )->setChecked( true );
581   else
582     toolMgr()->action( PModeNormLMinId )->setChecked( false );
583 }
584
585 /*!
586   \brief Called when the normalization mode (by left Y axis) for curves is changed.
587 */
588 void Plot2d_ViewWindow::onChangeNormRMode()
589 {
590   bool aNormMax = myViewFrame->isNormRMaxMode();
591   bool aNormMin = myViewFrame->isNormRMinMode();
592
593   if ( aNormMax )
594     toolMgr()->action( PModeNormRMaxId )->setChecked( true );
595   else
596     toolMgr()->action( PModeNormRMaxId )->setChecked( false );
597   if ( aNormMin )
598     toolMgr()->action( PModeNormRMinId )->setChecked( true );
599   else
600     toolMgr()->action( PModeNormRMinId )->setChecked( false );
601 }
602
603 /*!
604   \brief Called when the curve type is changed.
605 */
606 void Plot2d_ViewWindow::onChangeCurveMode()
607 {
608   switch ( myViewFrame->getCurveType() ) {
609   case 0:
610     toolMgr()->action( CurvPointsId )->setChecked( true );
611     break;
612   case 1:
613     toolMgr()->action( CurvLinesId )->setChecked( true );
614     break;
615   case 2:
616     toolMgr()->action( CurvSplinesId )->setChecked( true );
617     break;
618   default:
619     break;
620   }
621 }
622
623 /*!
624   \brief Called when the legend mode is changed.
625 */
626 void Plot2d_ViewWindow::onChangeLegendMode()
627 {
628   toolMgr()->action( LegendId )->setChecked( myViewFrame->isLegendShow() );
629 }
630
631 /*!
632   \brief Called when the "Fit all" action is activated.
633 */
634 void Plot2d_ViewWindow::onFitAll()
635 {
636   myViewFrame->onViewFitAll();
637 }
638
639 /*!
640   \brief Called when the "Fit rect" action is activated.
641 */
642 void Plot2d_ViewWindow::onFitRect()
643 {
644   myViewFrame->onViewFitArea();
645 }
646
647 /*!
648   \brief Called when the "Zoom" action is activated.
649 */
650 void Plot2d_ViewWindow::onZoom()
651 {
652   myViewFrame->onViewZoom();
653 }
654
655 /*!
656   \brief Called when the "Panning" action is activated.
657 */
658 void Plot2d_ViewWindow::onPanning()
659 {
660   myViewFrame->onViewPan();
661 }
662
663 /*!
664   \brief Called when the "Global panning" action is activated.
665 */
666 void Plot2d_ViewWindow::onGlobalPanning()
667 {
668   myViewFrame->onViewGlobalPan();
669 }
670
671 /*!
672   \brief Called when horizontal axis scale mode action is activated.
673 */
674 void Plot2d_ViewWindow::onViewHorMode()
675 {
676   myViewFrame->setHorScaleMode( toolMgr()->action( PModeXLinearId )->isChecked() ? 0 : 1 );
677 }
678
679 /*!
680   \brief Called when vertical axis scale mode action is activated.
681 */
682 void Plot2d_ViewWindow::onViewVerMode()
683 {
684   myViewFrame->setVerScaleMode( toolMgr()->action( PModeYLinearId )->isChecked() ? 0 : 1 );
685 }
686
687 /*!
688   \brief Called when normalization mode action (by left Y axis) is activated.
689 */
690
691 void Plot2d_ViewWindow::onViewNormLMode()
692 {
693   myViewFrame->setNormLMaxMode( toolMgr()->action( PModeNormLMaxId )->isChecked() ? true : false );
694   myViewFrame->setNormLMinMode( toolMgr()->action( PModeNormLMinId )->isChecked() ? true : false );
695 }
696
697 /*!
698   \brief Called when normalization mode action (by right Y axis) is activated.
699 */
700
701 void Plot2d_ViewWindow::onViewNormRMode()
702 {
703   myViewFrame->setNormRMaxMode( toolMgr()->action( PModeNormRMaxId )->isChecked() ? true : false );
704   myViewFrame->setNormRMinMode( toolMgr()->action( PModeNormRMinId )->isChecked() ? true : false );
705 }
706
707 /*!
708   \brief Called when the "Show legend" action is activated.
709 */
710 void Plot2d_ViewWindow::onLegend()
711 {
712   myViewFrame->showLegend( !myViewFrame->isLegendShow() );
713   onChangeLegendMode();
714 }
715
716 /*!
717   \brief Called when the "Change curve type" action is activated.
718 */
719 void Plot2d_ViewWindow::onCurves()
720 {
721   if( toolMgr()->action( CurvPointsId )->isChecked() )
722     myViewFrame->setCurveType( 0 );
723   else if ( toolMgr()->action( CurvLinesId )->isChecked() )
724     myViewFrame->setCurveType( 1 );
725   else if ( toolMgr()->action( CurvSplinesId )->isChecked() )
726     myViewFrame->setCurveType( 2 );
727 }
728  
729 /*!
730   \brief Called when the "Dump view" action is activated.
731 */
732 void Plot2d_ViewWindow::onDumpView()
733 {
734   qApp->postEvent( myViewFrame, new QPaintEvent( QRect( 0, 0, myViewFrame->width(), myViewFrame->height() ) ) );
735   SUIT_ViewWindow::onDumpView();
736 }
737
738 /*!
739   \brief Dump the contents of the view window to the image.
740   \return image, containing all scene rendered in the window
741 */
742 QImage Plot2d_ViewWindow::dumpView()
743 {
744   if ( getToolBar()->underMouse() || myDumpImage.isNull() ) {
745     QPixmap px = QPixmap::grabWindow( myViewFrame->winId() );
746     return px.toImage();
747   }
748   
749   return myDumpImage;
750 }
751
752 /*!
753   \brief Dump scene rendered in the view window to the file.
754   \param img image
755   \param fileName name of file
756   \param format image format ("BMP" [default], "JPEG", "JPG", "PNG")
757 */
758 bool Plot2d_ViewWindow::dumpViewToFormat( const QImage&  img,
759                                           const QString& fileName, 
760                                           const QString& format )
761 {
762   bool res = myViewFrame ? myViewFrame->print( fileName, format ) : false;
763   if( !res )
764     res = SUIT_ViewWindow::dumpViewToFormat( img, fileName, format );
765
766   return res;
767 }
768
769 /*!
770   \brief Get supported image files wildcards.
771   \return image files wildcards (list of wildcards, separated by ";;")
772 */
773 QString Plot2d_ViewWindow::filter() const
774 {
775   QStringList filters = SUIT_ViewWindow::filter().split( ";;", QString::SkipEmptyParts );
776   filters << tr( "PDF_FILES" );
777   filters << tr( "POSTSCRIPT_FILES" );
778   filters << tr( "ENCAPSULATED_POSTSCRIPT_FILES" );
779   return filters.join( ";;" );
780 }
781
782 /*!
783   \brief Called when the "Print view" action is activated.
784 */
785 void Plot2d_ViewWindow::onPrintView()
786 {
787   if ( !myViewFrame )
788     return;
789
790 #if !defined(WIN32) && !defined(QT_NO_CUPS)
791 #if QT_VERSION < 0x040303
792   if ( !Qtx::hasAnyPrinters() ) {
793     SUIT_MessageBox::warning( this, tr( "WRN_WARNING" ),
794                               tr( "WRN_NO_PRINTERS" ) );
795     return;
796   }
797 #endif
798 #endif
799
800   // stored settings for further starts
801   static QString aPrinterName;
802   static int aColorMode = -1;
803   static int anOrientation = -1;
804
805   QPrinter aPrinter;
806
807   // restore settinds from previous launching
808
809   // printer name
810   if ( !aPrinterName.isEmpty() )
811     aPrinter.setPrinterName( aPrinterName );
812   else 
813   {
814     // Nothing to do for the first printing. aPrinter contains default printer name by default
815   }
816
817   // color mode
818   if ( aColorMode >= 0 )
819     aPrinter.setColorMode( (QPrinter::ColorMode)aColorMode );
820   else 
821   {
822     // Black-and-wight printers are often used
823     aPrinter.setColorMode( QPrinter::GrayScale );
824   }
825
826   if ( anOrientation >= 0 )
827     aPrinter.setOrientation( (QPrinter::Orientation)anOrientation );
828   else
829     aPrinter.setOrientation( QPrinter::Landscape );
830
831   QPrintDialog printDlg( &aPrinter, this );
832   printDlg.setPrintRange( QAbstractPrintDialog::AllPages );
833   if ( printDlg.exec() != QDialog::Accepted ) 
834     return;
835
836   // store printer settings for further starts
837   aPrinterName = aPrinter.printerName();
838   aColorMode = aPrinter.colorMode();
839   anOrientation = aPrinter.orientation();
840   
841   int W, H;
842   QPainter aPainter;
843
844   bool needColorCorrection = aPrinter.colorMode() == QPrinter::GrayScale;
845
846   // work arround for printing on real printer
847   if ( aPrinter.outputFileName().isEmpty() && aPrinter.orientation() == QPrinter::Landscape )
848   {
849     aPrinter.setFullPage( false );
850     // set paper orientation and rotate painter
851     aPrinter.setOrientation( QPrinter::Portrait );
852
853     W = aPrinter.height();
854     H = aPrinter.width();
855
856     aPainter.begin( &aPrinter );
857     aPainter.translate( QPoint( H, 0 ) );
858     aPainter.rotate( 90 );
859   }
860   else 
861   {
862     aPrinter.setFullPage( false );
863     aPainter.begin( &aPrinter );
864     W = aPrinter.width();
865     H = aPrinter.height();
866   }
867
868   QMap< QwtPlotCurve*, QPen > aCurvToPen;
869   QMap< QwtPlotCurve*, QwtSymbol* > aCurvToSymbol;
870
871   if ( needColorCorrection )
872   {
873     // Iterate through, store temporary their parameters and assign 
874     // parameters proper for printing
875
876     CurveDict aCurveDict = myViewFrame->getCurves();
877     CurveDict::iterator it;
878     for ( it = aCurveDict.begin(); it != aCurveDict.end(); it++ ) 
879     {
880       QwtPlotCurve* aCurve = it.key();
881       if ( !aCurve )
882         continue;
883
884       // pen
885       QPen aPen = aCurve->pen();
886       aCurvToPen[ aCurve ] = aPen;
887
888       aPen.setColor( QColor( 0, 0, 0 ) );
889       aPen.setWidthF( 1.5 );
890
891       aCurve->setPen( aPen );
892
893       // symbol
894       QwtSymbol* aSymbol = const_cast<QwtSymbol*>( aCurve->symbol() );
895       aCurvToSymbol[ aCurve ] = aSymbol;
896       aPen = aSymbol->pen();
897       aPen.setColor( QColor( 0, 0, 0 ) );
898       aPen.setWidthF( 1.5 );
899       aSymbol->setPen( aPen );
900
901       aCurve->setSymbol( aSymbol );
902     }
903   }
904
905   myViewFrame->printPlot( &aPainter, QRect( 0, 0, W, H ) );
906   aPainter.end();
907
908   // restore old pens and symbols
909   if ( needColorCorrection && !aCurvToPen.isEmpty() )
910   {
911     CurveDict aCurveDict = myViewFrame->getCurves();
912     CurveDict::iterator it;
913     for ( it = aCurveDict.begin(); it != aCurveDict.end(); it++ ) 
914     {
915       QwtPlotCurve* aCurve = it.key();
916       if ( !aCurve || 
917            !aCurvToPen.contains( aCurve ) ||
918            !aCurvToSymbol.contains( aCurve ) )
919         continue;
920
921       aCurve->setPen( aCurvToPen[ aCurve ] );
922       aCurve->setSymbol( aCurvToSymbol[ aCurve ] );
923     }
924   }
925 }
926
927 /*!
928   \fn void Plot2d_ViewWindow::cloneView();
929   \brief Emitted when the "Clone View" action is activated.
930 */