Salome HOME
Debug of CMake build procedure
[modules/gui.git] / src / Plot2d / Plot2d_ViewWindow.cxx
1 // Copyright (C) 2007-2014  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, or (at your option) any later version.
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   aAction = new QtxAction( tr( "TOT_PLOT2D_ANALYTICAL_CURVES" ),
437                            aResMgr->loadPixmap( "Plot2d", tr( "ICON_PLOT2D_ANALYTICAL_CURVES" ) ),
438                            tr( "MEN_PLOT2D_ANALYTICAL_CURVES" ),
439                            0, this );
440
441   aAction->setStatusTip( tr( "PRP_PLOT2D_ANALYTICAL_CURVES" ) );
442   connect( aAction, SIGNAL( triggered( bool ) ), myViewFrame, SLOT( onAnalyticalCurve() ) );
443   mgr->registerAction( aAction, AnalyticalCurveId );
444
445   // 10. Clone
446   aAction = new QtxAction( tr( "MNU_CLONE_VIEW" ),
447                            aResMgr->loadPixmap( "Plot2d", tr( "ICON_PLOT2D_CLONE_VIEW" ) ),
448                            tr( "MNU_CLONE_VIEW" ),
449                            0, this);
450   aAction->setStatusTip( tr( "DSC_CLONE_VIEW" ) );
451   connect( aAction, SIGNAL( triggered( bool ) ), this, SIGNAL( cloneView() ) );
452   mgr->registerAction( aAction, CloneId );
453
454   // 11. Print 
455   aAction = new QtxAction( tr( "MNU_PRINT_VIEW" ),
456                            aResMgr->loadPixmap( "STD", tr( "ICON_PLOT2D_PRINT" ) ),
457                            tr( "MNU_PRINT_VIEW" ),
458                            0, this);
459   aAction->setStatusTip( tr( "DSC_PRINT_VIEW" ) );
460   connect( aAction, SIGNAL( triggered( bool ) ), this, SLOT( onPrintView() ) );
461   mgr->registerAction( aAction, PrintId );
462
463   // Set initial values
464   onChangeCurveMode();
465   onChangeHorMode();
466   onChangeVerMode();
467   onChangeNormLMode();
468   onChangeNormRMode();
469   onChangeLegendMode();
470 }
471
472 /*!
473   \brief Create toolbar for the view window.
474 */
475 void Plot2d_ViewWindow::createToolBar()
476 {
477   QtxActionToolMgr* mgr = toolMgr();
478   myToolBar = mgr->createToolBar( tr( "LBL_TOOLBAR_LABEL" ), false );
479   mgr->append( DumpId, myToolBar );
480   mgr->append( ScaleOpId, myToolBar );
481   mgr->append( MoveOpId, myToolBar );
482   mgr->append( toolMgr()->separator(), myToolBar );
483   mgr->append( CurvPointsId, myToolBar );
484   mgr->append( CurvLinesId, myToolBar );
485   mgr->append( CurvSplinesId, myToolBar );
486   mgr->append( toolMgr()->separator(), myToolBar );
487   mgr->append( PModeNormLMaxId, myToolBar );
488   mgr->append( PModeNormLMinId, myToolBar );
489   mgr->append( toolMgr()->separator(), myToolBar );
490   mgr->append( PModeNormRMaxId, myToolBar );
491   mgr->append( PModeNormRMinId, myToolBar );
492   mgr->append( toolMgr()->separator(), myToolBar );
493   mgr->append( PModeXLinearId, myToolBar );
494   mgr->append( PModeXLogarithmicId, myToolBar );
495   mgr->append( toolMgr()->separator(), myToolBar );
496   mgr->append( PModeYLinearId, myToolBar );
497   mgr->append( PModeYLogarithmicId, myToolBar );
498   mgr->append( toolMgr()->separator(), myToolBar );
499   mgr->append( LegendId, myToolBar );
500   mgr->append( CurvSettingsId, myToolBar );
501   mgr->append( AnalyticalCurveId, myToolBar );
502   mgr->append( CloneId, myToolBar );
503   mgr->append( PrintId, myToolBar );
504 }
505
506 /*!
507   \brief Get the visual parameters of the view window.
508   \return visual parameters of this view window formatted to the string
509 */
510 QString Plot2d_ViewWindow::getVisualParameters()
511 {
512   return myViewFrame->getVisualParameters();
513 }
514
515 /*!
516   \brief Restore visual parameters of the view window from the formated string
517   \param parameters view window visual parameters
518 */
519 void Plot2d_ViewWindow::setVisualParameters( const QString& parameters )
520 {
521   myViewFrame->setVisualParameters( parameters );
522 }
523
524 /*!
525   \brief Grab the view window to the internal image.
526 */
527 void Plot2d_ViewWindow::RefreshDumpImage()
528 {
529   QPixmap px = QPixmap::grabWindow( myViewFrame->winId() );
530   myDumpImage = px.toImage();
531 }
532
533 /*!
534   \brief Called when the scale mode for the horizontal axis is changed.
535 */
536 void Plot2d_ViewWindow::onChangeHorMode()
537 {
538   bool aHorLinear = myViewFrame->isModeHorLinear();
539   bool aVerLinear = myViewFrame->isModeVerLinear();
540
541   if ( aHorLinear )
542     toolMgr()->action( PModeXLinearId )->setChecked( true );
543   else
544     toolMgr()->action( PModeXLogarithmicId )->setChecked( true );
545
546   toolMgr()->action( GlobalPanId )->setEnabled( aHorLinear && aVerLinear );
547 }
548
549 /*!
550   \brief Called when the scale mode for the vertical axis is changed.
551 */
552 void Plot2d_ViewWindow::onChangeVerMode()
553 {
554   bool aHorLinear = myViewFrame->isModeHorLinear();
555   bool aVerLinear = myViewFrame->isModeVerLinear();
556
557   if ( aVerLinear )
558     toolMgr()->action( PModeYLinearId )->setChecked( true );
559   else
560     toolMgr()->action( PModeYLogarithmicId )->setChecked( true );
561
562   toolMgr()->action( GlobalPanId )->setEnabled( aHorLinear && aVerLinear );
563 }
564
565 /*!
566   \brief Called when the normalization mode (by left Y axis) for curves is changed.
567 */
568 void Plot2d_ViewWindow::onChangeNormLMode()
569 {
570   bool aNormMax = myViewFrame->isNormLMaxMode();
571   bool aNormMin = myViewFrame->isNormLMinMode();
572
573   if ( aNormMax )
574     toolMgr()->action( PModeNormLMaxId )->setChecked( true );
575   else
576     toolMgr()->action( PModeNormLMaxId )->setChecked( false );
577   if ( aNormMin )
578     toolMgr()->action( PModeNormLMinId )->setChecked( true );
579   else
580     toolMgr()->action( PModeNormLMinId )->setChecked( false );
581 }
582
583 /*!
584   \brief Called when the normalization mode (by left Y axis) for curves is changed.
585 */
586 void Plot2d_ViewWindow::onChangeNormRMode()
587 {
588   bool aNormMax = myViewFrame->isNormRMaxMode();
589   bool aNormMin = myViewFrame->isNormRMinMode();
590
591   if ( aNormMax )
592     toolMgr()->action( PModeNormRMaxId )->setChecked( true );
593   else
594     toolMgr()->action( PModeNormRMaxId )->setChecked( false );
595   if ( aNormMin )
596     toolMgr()->action( PModeNormRMinId )->setChecked( true );
597   else
598     toolMgr()->action( PModeNormRMinId )->setChecked( false );
599 }
600
601 /*!
602   \brief Called when the curve type is changed.
603 */
604 void Plot2d_ViewWindow::onChangeCurveMode()
605 {
606   switch ( myViewFrame->getCurveType() ) {
607   case 0:
608     toolMgr()->action( CurvPointsId )->setChecked( true );
609     break;
610   case 1:
611     toolMgr()->action( CurvLinesId )->setChecked( true );
612     break;
613   case 2:
614     toolMgr()->action( CurvSplinesId )->setChecked( true );
615     break;
616   default:
617     break;
618   }
619 }
620
621 /*!
622   \brief Called when the legend mode is changed.
623 */
624 void Plot2d_ViewWindow::onChangeLegendMode()
625 {
626   toolMgr()->action( LegendId )->setChecked( myViewFrame->isLegendShow() );
627 }
628
629 /*!
630   \brief Called when the "Fit all" action is activated.
631 */
632 void Plot2d_ViewWindow::onFitAll()
633 {
634   myViewFrame->onViewFitAll();
635 }
636
637 /*!
638   \brief Called when the "Fit rect" action is activated.
639 */
640 void Plot2d_ViewWindow::onFitRect()
641 {
642   myViewFrame->onViewFitArea();
643 }
644
645 /*!
646   \brief Called when the "Zoom" action is activated.
647 */
648 void Plot2d_ViewWindow::onZoom()
649 {
650   myViewFrame->onViewZoom();
651 }
652
653 /*!
654   \brief Called when the "Panning" action is activated.
655 */
656 void Plot2d_ViewWindow::onPanning()
657 {
658   myViewFrame->onViewPan();
659 }
660
661 /*!
662   \brief Called when the "Global panning" action is activated.
663 */
664 void Plot2d_ViewWindow::onGlobalPanning()
665 {
666   myViewFrame->onViewGlobalPan();
667 }
668
669 /*!
670   \brief Called when horizontal axis scale mode action is activated.
671 */
672 void Plot2d_ViewWindow::onViewHorMode()
673 {
674   myViewFrame->setHorScaleMode( toolMgr()->action( PModeXLinearId )->isChecked() ? 0 : 1 );
675 }
676
677 /*!
678   \brief Called when vertical axis scale mode action is activated.
679 */
680 void Plot2d_ViewWindow::onViewVerMode()
681 {
682   myViewFrame->setVerScaleMode( toolMgr()->action( PModeYLinearId )->isChecked() ? 0 : 1 );
683 }
684
685 /*!
686   \brief Called when normalization mode action (by left Y axis) is activated.
687 */
688
689 void Plot2d_ViewWindow::onViewNormLMode()
690 {
691   myViewFrame->setNormLMaxMode( toolMgr()->action( PModeNormLMaxId )->isChecked() ? true : false );
692   myViewFrame->setNormLMinMode( toolMgr()->action( PModeNormLMinId )->isChecked() ? true : false );
693 }
694
695 /*!
696   \brief Called when normalization mode action (by right Y axis) is activated.
697 */
698
699 void Plot2d_ViewWindow::onViewNormRMode()
700 {
701   myViewFrame->setNormRMaxMode( toolMgr()->action( PModeNormRMaxId )->isChecked() ? true : false );
702   myViewFrame->setNormRMinMode( toolMgr()->action( PModeNormRMinId )->isChecked() ? true : false );
703 }
704
705 /*!
706   \brief Called when the "Show legend" action is activated.
707 */
708 void Plot2d_ViewWindow::onLegend()
709 {
710   myViewFrame->showLegend( !myViewFrame->isLegendShow() );
711   onChangeLegendMode();
712 }
713
714 /*!
715   \brief Called when the "Change curve type" action is activated.
716 */
717 void Plot2d_ViewWindow::onCurves()
718 {
719   if( toolMgr()->action( CurvPointsId )->isChecked() )
720     myViewFrame->setCurveType( 0 );
721   else if ( toolMgr()->action( CurvLinesId )->isChecked() )
722     myViewFrame->setCurveType( 1 );
723   else if ( toolMgr()->action( CurvSplinesId )->isChecked() )
724     myViewFrame->setCurveType( 2 );
725 }
726  
727 /*!
728   \brief Called when the "Dump view" action is activated.
729 */
730 void Plot2d_ViewWindow::onDumpView()
731 {
732   qApp->postEvent( myViewFrame, new QPaintEvent( QRect( 0, 0, myViewFrame->width(), myViewFrame->height() ) ) );
733   SUIT_ViewWindow::onDumpView();
734 }
735
736 /*!
737   \brief Dump the contents of the view window to the image.
738   \return image, containing all scene rendered in the window
739 */
740 QImage Plot2d_ViewWindow::dumpView()
741 {
742   if ( getToolBar()->underMouse() || myDumpImage.isNull() ) {
743     QPixmap px = QPixmap::grabWindow( myViewFrame->winId() );
744     return px.toImage();
745   }
746   
747   return myDumpImage;
748 }
749
750 /*!
751   \brief Dump scene rendered in the view window to the file.
752   \param img image
753   \param fileName name of file
754   \param format image format ("BMP" [default], "JPEG", "JPG", "PNG")
755 */
756 bool Plot2d_ViewWindow::dumpViewToFormat( const QImage&  img,
757                                           const QString& fileName, 
758                                           const QString& format )
759 {
760   bool res = myViewFrame ? myViewFrame->print( fileName, format ) : false;
761   if( !res )
762     res = SUIT_ViewWindow::dumpViewToFormat( img, fileName, format );
763
764   return res;
765 }
766
767 /*!
768   \brief Get supported image files wildcards.
769   \return image files wildcards (list of wildcards, separated by ";;")
770 */
771 QString Plot2d_ViewWindow::filter() const
772 {
773   QStringList filters = SUIT_ViewWindow::filter().split( ";;", QString::SkipEmptyParts );
774   filters << tr( "PDF_FILES" );
775   filters << tr( "POSTSCRIPT_FILES" );
776   filters << tr( "ENCAPSULATED_POSTSCRIPT_FILES" );
777   return filters.join( ";;" );
778 }
779
780 /*!
781   \brief Called when the "Print view" action is activated.
782 */
783 void Plot2d_ViewWindow::onPrintView()
784 {
785   if ( !myViewFrame )
786     return;
787
788 #if !defined(WIN32) && !defined(QT_NO_CUPS)
789 #if QT_VERSION < 0x040303
790   if ( !Qtx::hasAnyPrinters() ) {
791     SUIT_MessageBox::warning( this, tr( "WRN_WARNING" ),
792                               tr( "WRN_NO_PRINTERS" ) );
793     return;
794   }
795 #endif
796 #endif
797
798   // stored settings for further starts
799   static QString aPrinterName;
800   static int aColorMode = -1;
801   static int anOrientation = -1;
802
803   QPrinter aPrinter;
804
805   // restore settinds from previous launching
806
807   // printer name
808   if ( !aPrinterName.isEmpty() )
809     aPrinter.setPrinterName( aPrinterName );
810   else 
811   {
812     // Nothing to do for the first printing. aPrinter contains default printer name by default
813   }
814
815   // color mode
816   if ( aColorMode >= 0 )
817     aPrinter.setColorMode( (QPrinter::ColorMode)aColorMode );
818   else 
819   {
820     // Black-and-wight printers are often used
821     aPrinter.setColorMode( QPrinter::GrayScale );
822   }
823
824   if ( anOrientation >= 0 )
825     aPrinter.setOrientation( (QPrinter::Orientation)anOrientation );
826   else
827     aPrinter.setOrientation( QPrinter::Landscape );
828
829   QPrintDialog printDlg( &aPrinter, this );
830   printDlg.setPrintRange( QAbstractPrintDialog::AllPages );
831   if ( printDlg.exec() != QDialog::Accepted ) 
832     return;
833
834   // store printer settings for further starts
835   aPrinterName = aPrinter.printerName();
836   aColorMode = aPrinter.colorMode();
837   anOrientation = aPrinter.orientation();
838   
839   int W, H;
840   QPainter aPainter;
841
842   bool needColorCorrection = aPrinter.colorMode() == QPrinter::GrayScale;
843
844   // work arround for printing on real printer
845   if ( aPrinter.outputFileName().isEmpty() && aPrinter.orientation() == QPrinter::Landscape )
846   {
847     aPrinter.setFullPage( false );
848     // set paper orientation and rotate painter
849     aPrinter.setOrientation( QPrinter::Portrait );
850
851     W = aPrinter.height();
852     H = aPrinter.width();
853
854     aPainter.begin( &aPrinter );
855     aPainter.translate( QPoint( H, 0 ) );
856     aPainter.rotate( 90 );
857   }
858   else 
859   {
860     aPrinter.setFullPage( false );
861     aPainter.begin( &aPrinter );
862     W = aPrinter.width();
863     H = aPrinter.height();
864   }
865
866   QMap< QwtPlotCurve*, QPen > aCurvToPen;
867   QMap< QwtPlotCurve*, QwtSymbol > aCurvToSymbol;
868
869   if ( needColorCorrection )
870   {
871     // Iterate through, store temporary their parameters and assign 
872     // parameters proper for printing
873
874     CurveDict aCurveDict = myViewFrame->getCurves();
875     CurveDict::iterator it;
876     for ( it = aCurveDict.begin(); it != aCurveDict.end(); it++ ) 
877     {
878       QwtPlotCurve* aCurve = it.key();
879       if ( !aCurve )
880         continue;
881
882       // pen
883       QPen aPen = aCurve->pen();
884       aCurvToPen[ aCurve ] = aPen;
885
886       aPen.setColor( QColor( 0, 0, 0 ) );
887       aPen.setWidthF( 1.5 );
888
889       aCurve->setPen( aPen );
890
891       // symbol
892       QwtSymbol aSymbol = aCurve->symbol();
893       aCurvToSymbol[ aCurve ] = aSymbol;
894       aPen = aSymbol.pen();
895       aPen.setColor( QColor( 0, 0, 0 ) );
896       aPen.setWidthF( 1.5 );
897       aSymbol.setPen( aPen );
898
899       aCurve->setSymbol( aSymbol );
900     }
901   }
902
903   myViewFrame->printPlot( &aPainter, QRect( 0, 0, W, H ) );
904   aPainter.end();
905
906   // restore old pens and symbols
907   if ( needColorCorrection && !aCurvToPen.isEmpty() )
908   {
909     CurveDict aCurveDict = myViewFrame->getCurves();
910     CurveDict::iterator it;
911     for ( it = aCurveDict.begin(); it != aCurveDict.end(); it++ ) 
912     {
913       QwtPlotCurve* aCurve = it.key();
914       if ( !aCurve || 
915            !aCurvToPen.contains( aCurve ) ||
916            !aCurvToSymbol.contains( aCurve ) )
917         continue;
918
919       aCurve->setPen( aCurvToPen[ aCurve ] );
920       aCurve->setSymbol( aCurvToSymbol[ aCurve ] );
921     }
922   }
923 }
924
925 /*!
926   \fn void Plot2d_ViewWindow::cloneView();
927   \brief Emitted when the "Clone View" action is activated.
928 */