1 // Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
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.
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.
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
17 // See http://www.salome-platform.org/
19 // Plot2d_ViewWindow.cxx: implementation of the Plot2d_ViewWindow class.
21 #include "Plot2d_ViewWindow.h"
22 #include "Plot2d_ViewFrame.h"
24 #include "SUIT_ViewManager.h"
25 #include "SUIT_ResourceMgr.h"
26 #include "SUIT_Session.h"
27 #include "SUIT_ToolButton.h"
28 #include "SUIT_Desktop.h"
30 #include "QtxAction.h"
32 #include <qstatusbar.h>
34 #include <qapplication.h>
35 #include <qpopupmenu.h>
41 Plot2d_ViewWindow::Plot2d_ViewWindow(SUIT_Desktop* theDesktop, Plot2d_Viewer* theModel)
42 : SUIT_ViewWindow(theDesktop)
46 myViewFrame = new Plot2d_ViewFrame(this, "plotView");
47 setCentralWidget(myViewFrame);
49 myToolBar = new QToolBar(this);
50 myToolBar->setCloseMode(QDockWindow::Undocked);
51 myToolBar->setLabel(tr("LBL_TOOLBAR_LABEL"));
55 connect(myViewFrame, SIGNAL(vpModeHorChanged()), this, SLOT(onChangeHorMode()));
56 connect(myViewFrame, SIGNAL(vpModeVerChanged()), this, SLOT(onChangeVerMode()));
57 connect(myViewFrame, SIGNAL(vpCurveChanged()), this, SLOT(onChangeCurveMode()));
58 connect(myViewFrame, SIGNAL(contextMenuRequested( QContextMenuEvent * )),
59 this, SIGNAL(contextMenuRequested( QContextMenuEvent * )) );
66 Plot2d_ViewWindow::~Plot2d_ViewWindow()
71 Puts message to status bar
72 \param theMsg - message text
74 void Plot2d_ViewWindow::putInfo(QString theMsg)
76 QStatusBar* aStatusBar = myDesktop->statusBar();
77 aStatusBar->message(theMsg/*, 3000*/);
81 Fills popup menu with custom actions
82 \param popup - popup menu to be filled with
84 void Plot2d_ViewWindow::contextMenuPopup( QPopupMenu* thePopup )
87 QPopupMenu* scalingPopup = new QPopupMenu( thePopup );
88 myActionsMap[ PModeXLinearId ]->addTo( scalingPopup );
89 myActionsMap[ PModeXLogarithmicId ]->addTo( scalingPopup );
91 scalingPopup->insertSeparator();
92 myActionsMap[ PModeYLinearId ]->addTo( scalingPopup );
93 myActionsMap[ PModeYLogarithmicId ]->addTo( scalingPopup );
94 thePopup->insertItem( tr( "SCALING_POPUP" ), scalingPopup );
97 thePopup->insertItem(tr("TOT_PLOT2D_FITDATA"), myViewFrame, SLOT(onFitData()));
99 QPopupMenu* curTypePopup = new QPopupMenu( thePopup );
100 myActionsMap[ CurvPointsId ]->addTo( curTypePopup );
101 myActionsMap[ CurvLinesId ]->addTo( curTypePopup );
102 myActionsMap[ CurvSplinesId ]->addTo( curTypePopup );
103 thePopup->insertItem( tr( "CURVE_TYPE_POPUP" ), curTypePopup );
106 myActionsMap[ LegendId ]->addTo(thePopup);
108 myActionsMap[ CurvSettingsId ]->addTo(thePopup);
114 bool Plot2d_ViewWindow::eventFilter(QObject* watched, QEvent* e)
116 if (watched == myViewFrame) {
117 int aType = e->type();
119 case QEvent::MouseButtonPress:
120 emit mousePressed(this, (QMouseEvent*) e);
123 case QEvent::MouseButtonRelease:
124 emit mouseReleased(this, (QMouseEvent*) e);
127 case QEvent::MouseMove:
128 emit mouseMoving(this, (QMouseEvent*) e);
135 return SUIT_ViewWindow::eventFilter(watched, e);
139 Create actions for Plot2d view window
141 void Plot2d_ViewWindow::createActions()
143 if ( !myActionsMap.isEmpty() )
147 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
150 aAction = new QtxAction(tr("MNU_DUMP_VIEW"), aResMgr->loadPixmap( "Plot2d", tr( "ICON_PLOT2D_DUMP" ) ),
151 tr( "MNU_DUMP_VIEW" ), 0, this);
152 aAction->setStatusTip(tr("DSC_DUMP_VIEW"));
153 connect(aAction, SIGNAL(activated()), this, SLOT(onDumpView()));
154 myActionsMap[ DumpId ] = aAction;
157 aAction = new QtxAction(tr("MNU_FITALL"), aResMgr->loadPixmap( "Plot2d", tr( "ICON_PLOT2D_FIT_ALL" ) ),
158 tr( "MNU_FITALL" ), 0, this);
159 aAction->setStatusTip(tr("DSC_FITALL"));
160 connect(aAction, SIGNAL(activated()), this, SLOT(onFitAll()));
161 myActionsMap[ FitAllId ] = aAction;
164 aAction = new QtxAction(tr("MNU_FITRECT"), aResMgr->loadPixmap( "Plot2d", tr( "ICON_PLOT2D_FIT_AREA" ) ),
165 tr( "MNU_FITRECT" ), 0, this);
166 aAction->setStatusTip(tr("DSC_FITRECT"));
167 connect(aAction, SIGNAL(activated()), this, SLOT(onFitRect()));
168 myActionsMap[ FitRectId ] = aAction;
171 aAction = new QtxAction(tr("MNU_ZOOM_VIEW"), aResMgr->loadPixmap( "Plot2d", tr( "ICON_PLOT2D_ZOOM" ) ),
172 tr( "MNU_ZOOM_VIEW" ), 0, this);
173 aAction->setStatusTip(tr("DSC_ZOOM_VIEW"));
174 connect(aAction, SIGNAL(activated()), this, SLOT(onZoom()));
175 myActionsMap[ ZoomId ] = aAction;
178 aAction = new QtxAction(tr("MNU_PAN_VIEW"), aResMgr->loadPixmap( "Plot2d", tr( "ICON_PLOT2D_PAN" ) ),
179 tr( "MNU_PAN_VIEW" ), 0, this);
180 aAction->setStatusTip(tr("DSC_PAN_VIEW"));
181 connect(aAction, SIGNAL(activated()), this, SLOT(onPanning()));
182 myActionsMap[ PanId ] = aAction;
185 aAction = new QtxAction(tr("MNU_GLOBALPAN_VIEW"), aResMgr->loadPixmap( "Plot2d", tr( "ICON_PLOT2D_GLOBALPAN" ) ),
186 tr( "MNU_GLOBALPAN_VIEW" ), 0, this);
187 aAction->setStatusTip(tr("DSC_GLOBALPAN_VIEW"));
188 connect(aAction, SIGNAL(activated()), this, SLOT(onGlobalPanning()));
189 myActionsMap[ GlobalPanId ] = aAction;
191 // Curve type - points
192 aAction = new QtxAction(tr("TOT_PLOT2D_CURVES_POINTS"),
193 aResMgr->loadPixmap("Plot2d", tr("ICON_PLOT2D_CURVES_POINTS")),
194 tr("MEN_PLOT2D_CURVES_POINTS"), 0, this);
195 aAction->setStatusTip(tr("PRP_PLOT2D_CURVES_POINTS"));
196 connect(aAction, SIGNAL(activated()), this, SLOT(onCurves()));
197 aAction->setToggleAction(true);
198 myActionsMap[ CurvPointsId ] = aAction;
200 // Curve type - lines
201 aAction = new QtxAction(tr("TOT_PLOT2D_CURVES_LINES"),
202 aResMgr->loadPixmap("Plot2d", tr("ICON_PLOT2D_CURVES_LINES")),
203 tr("MEN_PLOT2D_CURVES_LINES"), 0, this);
204 aAction->setStatusTip(tr("PRP_PLOT2D_CURVES_LINES"));
205 connect(aAction, SIGNAL(activated()), this, SLOT(onCurves()));
206 aAction->setToggleAction(true);
207 myActionsMap[ CurvLinesId ] = aAction;
209 // Curve type - splines
210 aAction = new QtxAction(tr("TOT_PLOT2D_CURVES_SPLINES"),
211 aResMgr->loadPixmap("Plot2d", tr("ICON_PLOT2D_CURVES_SPLINES")),
212 tr("MEN_PLOT2D_CURVES_SPLINES"), 0, this);
213 aAction->setStatusTip(tr("PRP_PLOT2D_CURVES_SPLINES"));
214 connect(aAction, SIGNAL(activated()), this, SLOT(onCurves()));
215 aAction->setToggleAction(true);
216 myActionsMap[ CurvSplinesId ] = aAction;
218 // Mode for X (linear or logarithmic)
219 aAction = new QtxAction(tr("TOT_PLOT2D_MODE_LINEAR_HOR"),
220 aResMgr->loadPixmap("Plot2d", tr("ICON_PLOT2D_MODE_LINEAR_HOR")),
221 tr("MEN_PLOT2D_MODE_LINEAR_HOR"), 0, this);
222 aAction->setStatusTip (tr("PRP_PLOT2D_MODE_LINEAR_HOR"));
223 connect(aAction, SIGNAL(activated()), this, SLOT(onViewHorMode()));
224 myActionsMap[ HorId ] = aAction;
226 // Mode for Y (linear or logarithmic)
227 aAction = new QtxAction(tr("TOT_PLOT2D_MODE_LINEAR_VER"),
228 aResMgr->loadPixmap("Plot2d", tr("ICON_PLOT2D_MODE_LINEAR_VER")),
229 tr("MEN_PLOT2D_MODE_LINEAR_VER" ), 0, this);
230 aAction->setStatusTip(tr("PRP_PLOT2D_MODE_LINEAR_VER"));
231 connect(aAction, SIGNAL(activated()), this, SLOT(onViewVerMode()));
232 myActionsMap[ VerId ] = aAction;
235 aAction = new QtxAction(tr("TOT_PLOT2D_SHOW_LEGEND"),
236 aResMgr->loadPixmap("Plot2d", tr("ICON_PLOT2D_SHOW_LEGEND")),
237 tr("MEN_PLOT2D_SHOW_LEGEND"), 0, this);
238 aAction->setStatusTip(tr("PRP_PLOT2D_SHOW_LEGEND"));
239 connect(aAction, SIGNAL(activated()), this, SLOT(onLegend()));
240 aAction->setToggleAction(true);
241 myActionsMap[ LegendId ] = aAction;
244 aAction = new QtxAction(tr( "TOT_PLOT2D_SETTINGS"),
245 aResMgr->loadPixmap("Plot2d", tr("ICON_PLOT2D_SETTINGS")),
246 tr("MEN_PLOT2D_SETTINGS"), 0, this);
247 aAction->setStatusTip(tr( "PRP_PLOT2D_SETTINGS"));
248 connect(aAction, SIGNAL(activated()), myViewFrame, SLOT(onSettings()));
249 myActionsMap[ CurvSettingsId ] = aAction;
252 aAction = new QtxAction(tr("MNU_CLONE_VIEW"), aResMgr->loadPixmap( "Plot2d", tr( "ICON_PLOT2D_CLONE_VIEW" ) ),
253 tr( "MNU_CLONE_VIEW" ), 0, this);
254 aAction->setStatusTip(tr("DSC_CLONE_VIEW"));
255 connect(aAction, SIGNAL(activated()), this, SIGNAL(cloneView()));
256 myActionsMap[ CloneId ] = aAction;
259 /* Linear/logarithmic mode */
261 aAction = new QtxAction(tr("TOT_PLOT2D_MODE_LINEAR_HOR"),
262 aResMgr->loadPixmap("Plot2d", tr("ICON_PLOT2D_MODE_LINEAR_HOR")),
263 tr("MEN_PLOT2D_MODE_LINEAR_HOR"), 0, this);
264 aAction->setStatusTip (tr("PRP_PLOT2D_MODE_LINEAR_HOR"));
265 aAction->setToggleAction(true);
266 myActionsMap[PModeXLinearId] = aAction;
267 connect(aAction, SIGNAL(activated()), this, SLOT(onViewHorMode()));
269 aAction = new QtxAction(tr("TOT_PLOT2D_MODE_LOGARITHMIC_HOR"),
270 aResMgr->loadPixmap("Plot2d", tr("ICON_PLOT2D_MODE_LOGARITHMIC_HOR")),
271 tr("MEN_PLOT2D_MODE_LOGARITHMIC_HOR"), 0, this);
272 aAction->setStatusTip(tr("PRP_PLOT2D_MODE_LOGARITHMIC_HOR"));
273 aAction->setToggleAction(true);
274 myActionsMap[PModeXLogarithmicId] = aAction;
275 connect(aAction, SIGNAL(activated()), this, SLOT(onViewHorMode()));
278 aAction = new QtxAction(tr("TOT_PLOT2D_MODE_LINEAR_VER"),
279 aResMgr->loadPixmap("Plot2d", tr("ICON_PLOT2D_MODE_LINEAR_VER")),
280 tr("MEN_PLOT2D_MODE_LINEAR_VER" ), 0, this);
281 aAction->setStatusTip(tr("PRP_PLOT2D_MODE_LINEAR_VER"));
282 aAction->setToggleAction(true);
283 myActionsMap[PModeYLinearId] = aAction;
284 connect(aAction, SIGNAL(activated()), this, SLOT(onViewVerMode()));
286 aAction = new QtxAction(tr("TOT_PLOT2D_MODE_LOGARITHMIC_VER"),
287 aResMgr->loadPixmap("Plot2d", tr("ICON_PLOT2D_MODE_LOGARITHMIC_VER")),
288 tr("MEN_PLOT2D_MODE_LOGARITHMIC_VER" ), 0, this);
289 aAction->setStatusTip(tr("PRP_PLOT2D_MODE_LOGARITHMIC_VER"));
290 aAction->setToggleAction(true);
291 myActionsMap[PModeYLogarithmicId] = aAction;
292 connect(aAction, SIGNAL(activated()), this, SLOT(onViewVerMode()));
297 Create toolbar for Plot2d view window
299 void Plot2d_ViewWindow::createToolBar()
301 myActionsMap[DumpId]->addTo(myToolBar);
303 SUIT_ToolButton* aScaleBtn = new SUIT_ToolButton(myToolBar);
304 aScaleBtn->AddAction(myActionsMap[FitAllId]);
305 aScaleBtn->AddAction(myActionsMap[FitRectId]);
306 aScaleBtn->AddAction(myActionsMap[ZoomId]);
308 SUIT_ToolButton* aPanBtn = new SUIT_ToolButton(myToolBar);
309 aPanBtn->AddAction(myActionsMap[PanId]);
310 aPanBtn->AddAction(myActionsMap[GlobalPanId]);
312 myCurveBtn = new SUIT_ToolButton(myToolBar);
313 myCurveBtn->AddAction(myActionsMap[CurvPointsId]);
314 myCurveBtn->AddAction(myActionsMap[CurvLinesId]);
315 myCurveBtn->AddAction(myActionsMap[CurvSplinesId]);
316 myActionsMap[CurvLinesId]->setOn(true);
319 myActionsMap[HorId]->addTo(myToolBar);
321 myActionsMap[VerId]->addTo(myToolBar);
324 myActionsMap[LegendId]->addTo(myToolBar);
325 myActionsMap[CurvSettingsId]->addTo(myToolBar);
326 myActionsMap[CloneId]->addTo(myToolBar);
327 onChangeLegendMode();
331 SLOT: called if scale mode for horizontal axis is changed
333 void Plot2d_ViewWindow::onChangeHorMode()
335 bool aLinear = myViewFrame->isModeHorLinear();
336 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
338 myActionsMap[PModeXLinearId]->setOn( aLinear );
339 myActionsMap[PModeXLogarithmicId]->setOn( !aLinear );
341 QPixmap pix = aResMgr->loadPixmap( "Plot2d", tr( aLinear ? "ICON_PLOT2D_MODE_LOGARITHMIC_HOR" :
342 "ICON_PLOT2D_MODE_LINEAR_HOR" ) );
343 myActionsMap[HorId]->setIconSet( pix );
344 myActionsMap[HorId]->setToolTip( tr( aLinear ? "TOT_PLOT2D_MODE_LOGARITHMIC_HOR" :
345 "TOT_PLOT2D_MODE_LINEAR_HOR" ) );
346 myActionsMap[HorId]->setStatusTip( tr( aLinear ? "PRP_PLOT2D_MODE_LOGARITHMIC_HOR" :
347 "PRP_PLOT2D_MODE_LINEAR_HOR" ) );
349 myActionsMap[GlobalPanId]->setEnabled( myViewFrame->isModeVerLinear() && myViewFrame->isModeHorLinear() );
353 SLOT: called if scale mode for vertical axis is changed
355 void Plot2d_ViewWindow::onChangeVerMode()
357 bool aLinear = myViewFrame->isModeVerLinear();
358 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
360 myActionsMap[PModeYLinearId]->setOn( aLinear );
361 myActionsMap[PModeYLogarithmicId]->setOn( !aLinear );
363 QPixmap pix = aResMgr->loadPixmap( "Plot2d", tr( aLinear ? "ICON_PLOT2D_MODE_LOGARITHMIC_VER" :
364 "ICON_PLOT2D_MODE_LINEAR_VER" ) );
365 myActionsMap[VerId]->setIconSet( pix );
366 myActionsMap[VerId]->setToolTip( tr( aLinear ? "TOT_PLOT2D_MODE_LOGARITHMIC_VER" :
367 "TOT_PLOT2D_MODE_LINEAR_VER" ) );
368 myActionsMap[VerId]->setStatusTip( tr( aLinear ? "PRP_PLOT2D_MODE_LOGARITHMIC_VER" :
369 "PRP_PLOT2D_MODE_LINEAR_VER" ) );
371 myActionsMap[GlobalPanId]->setEnabled( myViewFrame->isModeVerLinear() && myViewFrame->isModeHorLinear() );
375 SLOT: called if curve type is changed
377 void Plot2d_ViewWindow::onChangeCurveMode()
379 int aCurveType = myViewFrame->getCurveType();
380 myCurveBtn->SetItem(aCurveType);
382 myActionsMap[CurvPointsId]->setOn(aCurveType == 0);
383 myActionsMap[CurvLinesId]->setOn(aCurveType == 1);
384 myActionsMap[CurvSplinesId]->setOn(aCurveType == 2);
388 SLOT: called if legend mode is changed
390 void Plot2d_ViewWindow::onChangeLegendMode()
392 myActionsMap[ LegendId ]->setOn(myViewFrame->isLegendShow());
396 SLOT: called if action "Fit all" is activated
398 void Plot2d_ViewWindow::onFitAll()
400 myViewFrame->onViewFitAll();
404 SLOT: called if action "Fit rect" is activated
406 void Plot2d_ViewWindow::onFitRect()
408 myViewFrame->onViewFitArea();
412 SLOT: called if action "Zoom" is activated
414 void Plot2d_ViewWindow::onZoom()
416 myViewFrame->onViewZoom();
420 SLOT: called if action "Panning" is activated
422 void Plot2d_ViewWindow::onPanning()
424 myViewFrame->onViewPan();
428 SLOT: called if action "Global panning" is activated
430 void Plot2d_ViewWindow::onGlobalPanning()
432 myViewFrame->onViewGlobalPan();
436 SLOT: called if action of scale mode for horizontal axis changing is activated
438 void Plot2d_ViewWindow::onViewHorMode()
440 if (myViewFrame->isModeHorLinear())
441 myViewFrame->setHorScaleMode(1);
443 myViewFrame->setHorScaleMode(0);
447 SLOT: called if action of scale mode for vertical axis changing is activated
449 void Plot2d_ViewWindow::onViewVerMode()
451 if (myViewFrame->isModeVerLinear())
452 myViewFrame->setVerScaleMode(1);
454 myViewFrame->setVerScaleMode(0);
458 SLOT: called if action "Show legend" is activated
460 void Plot2d_ViewWindow::onLegend()
462 myViewFrame->showLegend(!myViewFrame->isLegendShow());
463 onChangeLegendMode();
467 SLOT: called if action "Change curve type" is activated
469 void Plot2d_ViewWindow::onCurves()
471 QtxAction* aSender = (QtxAction*) sender();
472 if(aSender == myActionsMap[CurvPointsId])
473 myViewFrame->setCurveType(0);
474 else if(aSender == myActionsMap[CurvLinesId])
475 myViewFrame->setCurveType(1);
476 else if(aSender == myActionsMap[CurvSplinesId])
477 myViewFrame->setCurveType(2);
481 SLOT: called if action "Dump view" is activated
483 void Plot2d_ViewWindow::onDumpView()
485 qApp->postEvent( myViewFrame, new QPaintEvent( QRect( 0, 0, myViewFrame->width(), myViewFrame->height() ), TRUE ) );
486 SUIT_ViewWindow::onDumpView();
490 \return QImage, containing all scene rendering in window
492 QImage Plot2d_ViewWindow::dumpView()
494 QPixmap px = QPixmap::grabWindow( myViewFrame->winId() );
495 return px.convertToImage();
499 Saves scene rendering in window to file
500 \param fileName - name of file
501 \param format - string contains name of format (for example, "BMP"(default) or "JPEG", "JPG")
503 bool Plot2d_ViewWindow::dumpViewToFormat( const QString& fileName, const QString& format )
505 bool res = myViewFrame ? myViewFrame->print( fileName, format ) : false;
507 res = SUIT_ViewWindow::dumpViewToFormat( fileName, format );
513 \return filter of image files
515 QString Plot2d_ViewWindow::filter() const
517 return SUIT_ViewWindow::filter() + ";;" + tr( "POSTSCRIPT_FILES" );
521 \return the visual parameters of this view as a formated string
523 QString Plot2d_ViewWindow::getVisualParameters()
525 return myViewFrame->getVisualParameters();
529 The method restors visual parameters of this view from a formated string
531 void Plot2d_ViewWindow::setVisualParameters( const QString& parameters )
533 myViewFrame->setVisualParameters( parameters );