]> SALOME platform Git repositories - modules/gui.git/blob - src/Plot2d/Plot2d_ViewWindow.cxx
Salome HOME
95b49ab033cfc65acfc3eb32861604b58b8bcdba
[modules/gui.git] / src / Plot2d / Plot2d_ViewWindow.cxx
1 // Copyright (C) 2005  OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
2 // 
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either 
6 // version 2.1 of the License.
7 // 
8 // This library is distributed in the hope that it will be useful 
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of 
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public  
14 // License along with this library; if not, write to the Free Software 
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/
18 //
19 // Plot2d_ViewWindow.cxx: implementation of the Plot2d_ViewWindow class.
20 //
21 //////////////////////////////////////////////////////////////////////
22 #include "Plot2d_ViewWindow.h"
23 #include "Plot2d_ViewFrame.h"
24
25 #include "SUIT_ViewManager.h"
26 #include "SUIT_ResourceMgr.h"
27 #include "SUIT_Session.h"
28 #include "SUIT_ToolButton.h"
29 #include "SUIT_Desktop.h"
30
31 #include "QtxAction.h"
32
33 #include <qstatusbar.h>
34 #include <qlayout.h>
35 #include <qapplication.h>
36 #include <qpopupmenu.h>
37
38 //////////////////////////////////////////////////////////////////////
39 // Construction/Destruction
40 //////////////////////////////////////////////////////////////////////
41
42 Plot2d_ViewWindow::Plot2d_ViewWindow(SUIT_Desktop* theDesktop, Plot2d_Viewer* theModel)
43 : SUIT_ViewWindow(theDesktop)
44 {
45   myModel = theModel;
46
47   myViewFrame = new Plot2d_ViewFrame(this, "plotView");
48   setCentralWidget(myViewFrame);
49
50   myToolBar = new QToolBar(this);
51   myToolBar->setCloseMode(QDockWindow::Undocked);
52   myToolBar->setLabel(tr("LBL_TOOLBAR_LABEL"));
53   createActions();
54   createToolBar();
55
56   connect(myViewFrame, SIGNAL(vpModeHorChanged()), this, SLOT(onChangeHorMode()));
57   connect(myViewFrame, SIGNAL(vpModeVerChanged()), this, SLOT(onChangeVerMode()));
58   connect(myViewFrame, SIGNAL(vpCurveChanged()),   this, SLOT(onChangeCurveMode()));
59   connect(myViewFrame, SIGNAL(contextMenuRequested( QContextMenuEvent * )),
60           this,        SIGNAL(contextMenuRequested( QContextMenuEvent * )) );
61
62 }
63
64 Plot2d_ViewWindow::~Plot2d_ViewWindow()
65 {
66 }
67
68 //****************************************************************
69 void Plot2d_ViewWindow::putInfo(QString theMsg)
70 {
71   QStatusBar*   aStatusBar = myDesktop->statusBar();
72   aStatusBar->message(theMsg/*, 3000*/);
73 }
74
75 //****************************************************************
76 void Plot2d_ViewWindow::contextMenuPopup( QPopupMenu* thePopup )
77 {
78   // scaling
79   QPopupMenu* scalingPopup = new QPopupMenu( thePopup );
80   myActionsMap[ PModeXLinearId ]->addTo( scalingPopup );
81   myActionsMap[ PModeXLogarithmicId ]->addTo( scalingPopup );
82   onChangeHorMode();
83   scalingPopup->insertSeparator();
84   myActionsMap[ PModeYLinearId ]->addTo( scalingPopup );
85   myActionsMap[ PModeYLogarithmicId ]->addTo( scalingPopup );
86   thePopup->insertItem( tr( "SCALING_POPUP" ), scalingPopup );
87   onChangeVerMode();
88
89   thePopup->insertItem(tr("TOT_PLOT2D_FITDATA"), myViewFrame, SLOT(onFitData()));
90   // curve type
91   QPopupMenu* curTypePopup = new QPopupMenu( thePopup );
92   myActionsMap[ CurvPointsId ]->addTo( curTypePopup );
93   myActionsMap[ CurvLinesId ]->addTo( curTypePopup );
94   myActionsMap[ CurvSplinesId ]->addTo( curTypePopup );
95   thePopup->insertItem( tr( "CURVE_TYPE_POPUP" ), curTypePopup );
96
97   // legend
98   myActionsMap[ LegendId ]->addTo(thePopup);
99   // settings
100   myActionsMap[ CurvSettingsId ]->addTo(thePopup);
101 }
102
103 //****************************************************************
104 bool Plot2d_ViewWindow::eventFilter(QObject* watched, QEvent* e)
105 {
106   if (watched == myViewFrame) {
107     int aType = e->type();
108     switch(aType) {
109     case QEvent::MouseButtonPress:
110       emit mousePressed(this, (QMouseEvent*) e);
111       return true;
112
113     case QEvent::MouseButtonRelease:
114       emit mouseReleased(this, (QMouseEvent*) e);
115       return true;
116
117     case QEvent::MouseMove:
118       emit mouseMoving(this, (QMouseEvent*) e);
119       return true;
120
121     default:
122       break;
123     }
124   }
125   return SUIT_ViewWindow::eventFilter(watched, e);
126 }
127
128 //****************************************************************
129 void Plot2d_ViewWindow::createActions()
130 {
131   if ( !myActionsMap.isEmpty() )
132     return;
133
134   QtxAction* aAction;
135   SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
136
137   // Dump view
138   aAction = new QtxAction(tr("MNU_DUMP_VIEW"), aResMgr->loadPixmap( "Plot2d", tr( "ICON_PLOT2D_DUMP" ) ),
139                            tr( "MNU_DUMP_VIEW" ), 0, this);
140   aAction->setStatusTip(tr("DSC_DUMP_VIEW"));
141   connect(aAction, SIGNAL(activated()), this, SLOT(onDumpView()));
142   myActionsMap[ DumpId ] = aAction;
143
144   // FitAll
145   aAction = new QtxAction(tr("MNU_FITALL"), aResMgr->loadPixmap( "Plot2d", tr( "ICON_PLOT2D_FIT_ALL" ) ),
146                            tr( "MNU_FITALL" ), 0, this);
147   aAction->setStatusTip(tr("DSC_FITALL"));
148   connect(aAction, SIGNAL(activated()), this, SLOT(onFitAll()));
149   myActionsMap[ FitAllId ] = aAction;
150
151   // FitRect
152   aAction = new QtxAction(tr("MNU_FITRECT"), aResMgr->loadPixmap( "Plot2d", tr( "ICON_PLOT2D_FIT_AREA" ) ),
153                            tr( "MNU_FITRECT" ), 0, this);
154   aAction->setStatusTip(tr("DSC_FITRECT"));
155   connect(aAction, SIGNAL(activated()), this, SLOT(onFitRect()));
156   myActionsMap[ FitRectId ] = aAction;
157
158   // Zoom
159   aAction = new QtxAction(tr("MNU_ZOOM_VIEW"), aResMgr->loadPixmap( "Plot2d", tr( "ICON_PLOT2D_ZOOM" ) ),
160                            tr( "MNU_ZOOM_VIEW" ), 0, this);
161   aAction->setStatusTip(tr("DSC_ZOOM_VIEW"));
162   connect(aAction, SIGNAL(activated()), this, SLOT(onZoom()));
163   myActionsMap[ ZoomId ] = aAction;
164
165   // Panning
166   aAction = new QtxAction(tr("MNU_PAN_VIEW"), aResMgr->loadPixmap( "Plot2d", tr( "ICON_PLOT2D_PAN" ) ),
167                            tr( "MNU_PAN_VIEW" ), 0, this);
168   aAction->setStatusTip(tr("DSC_PAN_VIEW"));
169   connect(aAction, SIGNAL(activated()), this, SLOT(onPanning()));
170   myActionsMap[ PanId ] = aAction;
171
172   // Global Panning
173   aAction = new QtxAction(tr("MNU_GLOBALPAN_VIEW"), aResMgr->loadPixmap( "Plot2d", tr( "ICON_PLOT2D_GLOBALPAN" ) ),
174                            tr( "MNU_GLOBALPAN_VIEW" ), 0, this);
175   aAction->setStatusTip(tr("DSC_GLOBALPAN_VIEW"));
176   connect(aAction, SIGNAL(activated()), this, SLOT(onGlobalPanning()));
177   myActionsMap[ GlobalPanId ] = aAction;
178
179   // Curve type - points
180   aAction = new QtxAction(tr("TOT_PLOT2D_CURVES_POINTS"),
181                 aResMgr->loadPixmap("Plot2d", tr("ICON_PLOT2D_CURVES_POINTS")),
182                 tr("MEN_PLOT2D_CURVES_POINTS"), 0, this);
183   aAction->setStatusTip(tr("PRP_PLOT2D_CURVES_POINTS"));
184   connect(aAction, SIGNAL(activated()), this, SLOT(onCurves()));
185   aAction->setToggleAction(true);
186   myActionsMap[ CurvPointsId ] = aAction;
187
188   // Curve type - lines
189   aAction = new QtxAction(tr("TOT_PLOT2D_CURVES_LINES"),
190                aResMgr->loadPixmap("Plot2d", tr("ICON_PLOT2D_CURVES_LINES")),
191                tr("MEN_PLOT2D_CURVES_LINES"), 0, this);
192   aAction->setStatusTip(tr("PRP_PLOT2D_CURVES_LINES"));
193   connect(aAction, SIGNAL(activated()), this, SLOT(onCurves()));
194   aAction->setToggleAction(true);
195   myActionsMap[ CurvLinesId ] = aAction;
196
197   // Curve type - splines
198   aAction = new QtxAction(tr("TOT_PLOT2D_CURVES_SPLINES"),
199                  aResMgr->loadPixmap("Plot2d", tr("ICON_PLOT2D_CURVES_SPLINES")),
200                  tr("MEN_PLOT2D_CURVES_SPLINES"), 0, this);
201   aAction->setStatusTip(tr("PRP_PLOT2D_CURVES_SPLINES"));
202   connect(aAction, SIGNAL(activated()), this, SLOT(onCurves()));
203   aAction->setToggleAction(true);
204   myActionsMap[ CurvSplinesId ] = aAction;
205
206   // Mode for X (linear or logarithmic)
207   aAction = new QtxAction(tr("TOT_PLOT2D_MODE_LINEAR_HOR"),
208                  aResMgr->loadPixmap("Plot2d", tr("ICON_PLOT2D_MODE_LINEAR_HOR")),
209                  tr("MEN_PLOT2D_MODE_LINEAR_HOR"), 0, this);
210   aAction->setStatusTip (tr("PRP_PLOT2D_MODE_LINEAR_HOR"));
211   connect(aAction, SIGNAL(activated()), this, SLOT(onViewHorMode()));
212   myActionsMap[ HorId ] = aAction;
213
214   // Mode for Y (linear or logarithmic)
215   aAction = new QtxAction(tr("TOT_PLOT2D_MODE_LINEAR_VER"),
216                  aResMgr->loadPixmap("Plot2d", tr("ICON_PLOT2D_MODE_LINEAR_VER")),
217                  tr("MEN_PLOT2D_MODE_LINEAR_VER" ), 0, this);
218   aAction->setStatusTip(tr("PRP_PLOT2D_MODE_LINEAR_VER"));
219   connect(aAction, SIGNAL(activated()), this, SLOT(onViewVerMode()));
220   myActionsMap[ VerId ] = aAction;
221
222   // Legend
223   aAction = new QtxAction(tr("TOT_PLOT2D_SHOW_LEGEND"),
224                 aResMgr->loadPixmap("Plot2d", tr("ICON_PLOT2D_SHOW_LEGEND")),
225                 tr("MEN_PLOT2D_SHOW_LEGEND"), 0, this);
226   aAction->setStatusTip(tr("PRP_PLOT2D_SHOW_LEGEND"));
227   connect(aAction, SIGNAL(activated()), this, SLOT(onLegend()));
228   aAction->setToggleAction(true);
229   myActionsMap[ LegendId ] = aAction;
230
231   // Settings
232   aAction = new QtxAction(tr( "TOT_PLOT2D_SETTINGS"),
233                 aResMgr->loadPixmap("Plot2d", tr("ICON_PLOT2D_SETTINGS")),
234                 tr("MEN_PLOT2D_SETTINGS"), 0, this);
235   aAction->setStatusTip(tr( "PRP_PLOT2D_SETTINGS"));
236   connect(aAction, SIGNAL(activated()), myViewFrame, SLOT(onSettings()));
237   myActionsMap[ CurvSettingsId ] = aAction;
238
239   // Clone
240   aAction = new QtxAction(tr("MNU_CLONE_VIEW"), aResMgr->loadPixmap( "Plot2d", tr( "ICON_PLOT2D_CLONE_VIEW" ) ),
241                            tr( "MNU_CLONE_VIEW" ), 0, this);
242   aAction->setStatusTip(tr("DSC_CLONE_VIEW"));
243   connect(aAction, SIGNAL(activated()), this, SIGNAL(cloneView()));
244   myActionsMap[ CloneId ] = aAction;
245
246   /* Popup Actions */
247   /* Linear/logarithmic mode */
248   // Horizontal axis
249   aAction = new QtxAction(tr("TOT_PLOT2D_MODE_LINEAR_HOR"),
250                  aResMgr->loadPixmap("Plot2d", tr("ICON_PLOT2D_MODE_LINEAR_HOR")),
251                  tr("MEN_PLOT2D_MODE_LINEAR_HOR"), 0, this);
252   aAction->setStatusTip (tr("PRP_PLOT2D_MODE_LINEAR_HOR"));
253   aAction->setToggleAction(true);
254   myActionsMap[PModeXLinearId] = aAction;
255   connect(aAction, SIGNAL(activated()), this, SLOT(onViewHorMode()));
256
257   aAction = new QtxAction(tr("TOT_PLOT2D_MODE_LOGARITHMIC_HOR"),
258               aResMgr->loadPixmap("Plot2d", tr("ICON_PLOT2D_MODE_LOGARITHMIC_HOR")),
259               tr("MEN_PLOT2D_MODE_LOGARITHMIC_HOR"), 0, this);
260   aAction->setStatusTip(tr("PRP_PLOT2D_MODE_LOGARITHMIC_HOR"));
261   aAction->setToggleAction(true);
262   myActionsMap[PModeXLogarithmicId] = aAction;
263   connect(aAction, SIGNAL(activated()), this, SLOT(onViewHorMode()));
264
265   // Vertical axis
266   aAction = new QtxAction(tr("TOT_PLOT2D_MODE_LINEAR_VER"),
267                  aResMgr->loadPixmap("Plot2d", tr("ICON_PLOT2D_MODE_LINEAR_VER")),
268                  tr("MEN_PLOT2D_MODE_LINEAR_VER" ), 0, this);
269   aAction->setStatusTip(tr("PRP_PLOT2D_MODE_LINEAR_VER"));
270   aAction->setToggleAction(true);
271   myActionsMap[PModeYLinearId] = aAction;
272   connect(aAction, SIGNAL(activated()), this, SLOT(onViewVerMode()));
273
274   aAction = new QtxAction(tr("TOT_PLOT2D_MODE_LOGARITHMIC_VER"),
275                  aResMgr->loadPixmap("Plot2d", tr("ICON_PLOT2D_MODE_LOGARITHMIC_VER")),
276                  tr("MEN_PLOT2D_MODE_LOGARITHMIC_VER" ), 0, this);
277   aAction->setStatusTip(tr("PRP_PLOT2D_MODE_LOGARITHMIC_VER"));
278   aAction->setToggleAction(true);
279   myActionsMap[PModeYLogarithmicId] = aAction;
280   connect(aAction, SIGNAL(activated()), this, SLOT(onViewVerMode()));
281
282 }
283
284 //****************************************************************
285 void Plot2d_ViewWindow::createToolBar()
286 {
287   myActionsMap[DumpId]->addTo(myToolBar);
288
289   SUIT_ToolButton* aScaleBtn = new SUIT_ToolButton(myToolBar);
290   aScaleBtn->AddAction(myActionsMap[FitAllId]);
291   aScaleBtn->AddAction(myActionsMap[FitRectId]);
292   aScaleBtn->AddAction(myActionsMap[ZoomId]);
293
294   SUIT_ToolButton* aPanBtn = new SUIT_ToolButton(myToolBar);
295   aPanBtn->AddAction(myActionsMap[PanId]);
296   aPanBtn->AddAction(myActionsMap[GlobalPanId]);
297
298   myCurveBtn = new SUIT_ToolButton(myToolBar);
299   myCurveBtn->AddAction(myActionsMap[CurvPointsId]);
300   myCurveBtn->AddAction(myActionsMap[CurvLinesId]);
301   myCurveBtn->AddAction(myActionsMap[CurvSplinesId]);
302   myActionsMap[CurvLinesId]->setOn(true);
303   onChangeCurveMode();
304
305   myActionsMap[HorId]->addTo(myToolBar);
306   onChangeHorMode();
307   myActionsMap[VerId]->addTo(myToolBar);
308   onChangeVerMode();
309
310   myActionsMap[LegendId]->addTo(myToolBar);
311   myActionsMap[CurvSettingsId]->addTo(myToolBar);
312   myActionsMap[CloneId]->addTo(myToolBar);
313   onChangeLegendMode();
314 }
315
316 //****************************************************************
317 void Plot2d_ViewWindow::onChangeHorMode()
318 {
319   bool aLinear = myViewFrame->isModeHorLinear();
320   SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
321
322   myActionsMap[PModeXLinearId]->setOn( aLinear );
323   myActionsMap[PModeXLogarithmicId]->setOn( !aLinear );
324
325   QPixmap pix = aResMgr->loadPixmap( "Plot2d", tr( aLinear ? "ICON_PLOT2D_MODE_LOGARITHMIC_HOR" :
326                                                              "ICON_PLOT2D_MODE_LINEAR_HOR" ) );
327   myActionsMap[HorId]->setIconSet( pix );
328   myActionsMap[HorId]->setToolTip( tr( aLinear ? "TOT_PLOT2D_MODE_LOGARITHMIC_HOR" :
329                                                  "TOT_PLOT2D_MODE_LINEAR_HOR" ) );
330   myActionsMap[HorId]->setStatusTip( tr( aLinear ? "PRP_PLOT2D_MODE_LOGARITHMIC_HOR" :
331                                                    "PRP_PLOT2D_MODE_LINEAR_HOR" ) );
332
333   myActionsMap[GlobalPanId]->setEnabled( myViewFrame->isModeVerLinear() && myViewFrame->isModeHorLinear() );
334 }
335
336 //****************************************************************
337 void Plot2d_ViewWindow::onChangeVerMode()
338 {
339   bool aLinear = myViewFrame->isModeVerLinear();
340   SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
341
342   myActionsMap[PModeYLinearId]->setOn( aLinear );
343   myActionsMap[PModeYLogarithmicId]->setOn( !aLinear );
344
345   QPixmap pix = aResMgr->loadPixmap( "Plot2d", tr( aLinear ? "ICON_PLOT2D_MODE_LOGARITHMIC_VER" :
346                                                              "ICON_PLOT2D_MODE_LINEAR_VER" ) );
347   myActionsMap[VerId]->setIconSet( pix );
348   myActionsMap[VerId]->setToolTip( tr( aLinear ? "TOT_PLOT2D_MODE_LOGARITHMIC_VER" :
349                                                  "TOT_PLOT2D_MODE_LINEAR_VER" ) );
350   myActionsMap[VerId]->setStatusTip( tr( aLinear ? "PRP_PLOT2D_MODE_LOGARITHMIC_VER" :
351                                                    "PRP_PLOT2D_MODE_LINEAR_VER" ) );
352
353   myActionsMap[GlobalPanId]->setEnabled( myViewFrame->isModeVerLinear() && myViewFrame->isModeHorLinear() );
354 }
355
356 //****************************************************************
357 void Plot2d_ViewWindow::onChangeCurveMode()
358 {
359   myCurveBtn->SetItem(myViewFrame->getCurveType());
360 }
361
362 //****************************************************************
363 void Plot2d_ViewWindow::onChangeLegendMode()
364 {
365   myActionsMap[ LegendId ]->setOn(myViewFrame->isLegendShow());
366 }
367
368 //****************************************************************
369 void Plot2d_ViewWindow::onFitAll()
370 {
371   myViewFrame->onViewFitAll();
372 }
373
374 //****************************************************************
375 void Plot2d_ViewWindow::onFitRect()
376 {
377   myViewFrame->onViewFitArea();
378 }
379
380 //****************************************************************
381 void Plot2d_ViewWindow::onZoom()
382 {
383   myViewFrame->onViewZoom();
384 }
385
386 //****************************************************************
387 void Plot2d_ViewWindow::onPanning()
388 {
389   myViewFrame->onViewPan();
390 }
391
392 //****************************************************************
393 void Plot2d_ViewWindow::onGlobalPanning()
394 {
395   myViewFrame->onViewGlobalPan();
396 }
397
398 //****************************************************************
399 void Plot2d_ViewWindow::onViewHorMode()
400 {
401   if (myViewFrame->isModeHorLinear())
402     myViewFrame->setHorScaleMode(1);
403   else
404     myViewFrame->setHorScaleMode(0);
405 }
406
407 //****************************************************************
408 void Plot2d_ViewWindow::onViewVerMode()
409 {
410   if (myViewFrame->isModeVerLinear())
411     myViewFrame->setVerScaleMode(1);
412   else
413     myViewFrame->setVerScaleMode(0);
414 }
415
416 //****************************************************************
417 void Plot2d_ViewWindow::onLegend()
418 {
419   myViewFrame->showLegend(!myViewFrame->isLegendShow());
420   onChangeLegendMode();
421 }
422
423 //****************************************************************
424 void Plot2d_ViewWindow::onCurves()
425 {
426   QtxAction* aSender = (QtxAction*) sender();
427   if(aSender == myActionsMap[CurvPointsId]) {
428     myActionsMap[CurvPointsId]->setOn(true);
429     myActionsMap[CurvLinesId]->setOn(false);
430     myActionsMap[CurvSplinesId]->setOn(false);
431     myViewFrame->setCurveType(0);
432   }
433   else if(aSender == myActionsMap[CurvLinesId]) {
434     myActionsMap[CurvLinesId]->setOn(true);
435     myActionsMap[CurvPointsId]->setOn(false);
436     myActionsMap[CurvSplinesId]->setOn(false);
437     myViewFrame->setCurveType(1);
438   }
439   else if(aSender == myActionsMap[CurvSplinesId]) {
440     myActionsMap[CurvSplinesId]->setOn( true );
441     myActionsMap[CurvPointsId]->setOn( false );
442     myActionsMap[CurvLinesId]->setOn( false );
443     myViewFrame->setCurveType(2);
444   }
445 }
446
447 //****************************************************************
448 void Plot2d_ViewWindow::onDumpView()
449 {
450   qApp->postEvent( myViewFrame, new QPaintEvent( QRect( 0, 0, myViewFrame->width(), myViewFrame->height() ), TRUE ) );
451   SUIT_ViewWindow::onDumpView();
452 }
453
454 //****************************************************************
455 QImage Plot2d_ViewWindow::dumpView()
456 {
457   QPixmap px = QPixmap::grabWindow( myViewFrame->winId() );
458   return px.convertToImage();
459 }