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 //////////////////////////////////////////////////////////////////////
22 #include "Plot2d_ViewWindow.h"
23 #include "Plot2d_ViewFrame.h"
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"
31 #include "QtxAction.h"
33 #include <qstatusbar.h>
35 #include <qapplication.h>
36 #include <qpopupmenu.h>
39 //////////////////////////////////////////////////////////////////////
40 // Construction/Destruction
41 //////////////////////////////////////////////////////////////////////
43 Plot2d_ViewWindow::Plot2d_ViewWindow(SUIT_Desktop* theDesktop, Plot2d_Viewer* theModel)
44 : SUIT_ViewWindow(theDesktop)
48 myViewFrame = new Plot2d_ViewFrame(this, "plotView");
49 setCentralWidget(myViewFrame);
51 myToolBar = new QToolBar(this);
52 myToolBar->setCloseMode(QDockWindow::Undocked);
53 myToolBar->setLabel(tr("LBL_TOOLBAR_LABEL"));
57 connect(myViewFrame, SIGNAL(vpModeHorChanged()), this, SLOT(onChangeHorMode()));
58 connect(myViewFrame, SIGNAL(vpModeVerChanged()), this, SLOT(onChangeVerMode()));
59 connect(myViewFrame, SIGNAL(vpCurveChanged()), this, SLOT(onChangeCurveMode()));
60 connect(myViewFrame, SIGNAL(contextMenuRequested( QContextMenuEvent * )),
61 this, SIGNAL(contextMenuRequested( QContextMenuEvent * )) );
65 Plot2d_ViewWindow::~Plot2d_ViewWindow()
69 //****************************************************************
70 void Plot2d_ViewWindow::putInfo(QString theMsg)
72 QStatusBar* aStatusBar = myDesktop->statusBar();
73 aStatusBar->message(theMsg/*, 3000*/);
76 //****************************************************************
77 void Plot2d_ViewWindow::contextMenuPopup( QPopupMenu* thePopup )
80 QPopupMenu* scalingPopup = new QPopupMenu( thePopup );
81 myActionsMap[ PModeXLinearId ]->addTo( scalingPopup );
82 myActionsMap[ PModeXLogarithmicId ]->addTo( scalingPopup );
84 scalingPopup->insertSeparator();
85 myActionsMap[ PModeYLinearId ]->addTo( scalingPopup );
86 myActionsMap[ PModeYLogarithmicId ]->addTo( scalingPopup );
87 thePopup->insertItem( tr( "SCALING_POPUP" ), scalingPopup );
90 thePopup->insertItem(tr("TOT_PLOT2D_FITDATA"), myViewFrame, SLOT(onFitData()));
92 QPopupMenu* curTypePopup = new QPopupMenu( thePopup );
93 myActionsMap[ CurvPointsId ]->addTo( curTypePopup );
94 myActionsMap[ CurvLinesId ]->addTo( curTypePopup );
95 myActionsMap[ CurvSplinesId ]->addTo( curTypePopup );
96 thePopup->insertItem( tr( "CURVE_TYPE_POPUP" ), curTypePopup );
99 myActionsMap[ LegendId ]->addTo(thePopup);
101 myActionsMap[ CurvSettingsId ]->addTo(thePopup);
104 //****************************************************************
105 bool Plot2d_ViewWindow::eventFilter(QObject* watched, QEvent* e)
107 if (watched == myViewFrame) {
108 int aType = e->type();
110 case QEvent::MouseButtonPress:
111 emit mousePressed(this, (QMouseEvent*) e);
114 case QEvent::MouseButtonRelease:
115 emit mouseReleased(this, (QMouseEvent*) e);
118 case QEvent::MouseMove:
119 emit mouseMoving(this, (QMouseEvent*) e);
126 return SUIT_ViewWindow::eventFilter(watched, e);
129 //****************************************************************
130 void Plot2d_ViewWindow::createActions()
132 if ( !myActionsMap.isEmpty() )
136 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
139 aAction = new QtxAction(tr("MNU_DUMP_VIEW"), aResMgr->loadPixmap( "Plot2d", tr( "ICON_PLOT2D_DUMP" ) ),
140 tr( "MNU_DUMP_VIEW" ), 0, this);
141 aAction->setStatusTip(tr("DSC_DUMP_VIEW"));
142 connect(aAction, SIGNAL(activated()), this, SLOT(onDumpView()));
143 myActionsMap[ DumpId ] = aAction;
146 aAction = new QtxAction(tr("MNU_FITALL"), aResMgr->loadPixmap( "Plot2d", tr( "ICON_PLOT2D_FIT_ALL" ) ),
147 tr( "MNU_FITALL" ), 0, this);
148 aAction->setStatusTip(tr("DSC_FITALL"));
149 connect(aAction, SIGNAL(activated()), this, SLOT(onFitAll()));
150 myActionsMap[ FitAllId ] = aAction;
153 aAction = new QtxAction(tr("MNU_FITRECT"), aResMgr->loadPixmap( "Plot2d", tr( "ICON_PLOT2D_FIT_AREA" ) ),
154 tr( "MNU_FITRECT" ), 0, this);
155 aAction->setStatusTip(tr("DSC_FITRECT"));
156 connect(aAction, SIGNAL(activated()), this, SLOT(onFitRect()));
157 myActionsMap[ FitRectId ] = aAction;
160 aAction = new QtxAction(tr("MNU_ZOOM_VIEW"), aResMgr->loadPixmap( "Plot2d", tr( "ICON_PLOT2D_ZOOM" ) ),
161 tr( "MNU_ZOOM_VIEW" ), 0, this);
162 aAction->setStatusTip(tr("DSC_ZOOM_VIEW"));
163 connect(aAction, SIGNAL(activated()), this, SLOT(onZoom()));
164 myActionsMap[ ZoomId ] = aAction;
167 aAction = new QtxAction(tr("MNU_PAN_VIEW"), aResMgr->loadPixmap( "Plot2d", tr( "ICON_PLOT2D_PAN" ) ),
168 tr( "MNU_PAN_VIEW" ), 0, this);
169 aAction->setStatusTip(tr("DSC_PAN_VIEW"));
170 connect(aAction, SIGNAL(activated()), this, SLOT(onPanning()));
171 myActionsMap[ PanId ] = aAction;
174 aAction = new QtxAction(tr("MNU_GLOBALPAN_VIEW"), aResMgr->loadPixmap( "Plot2d", tr( "ICON_PLOT2D_GLOBALPAN" ) ),
175 tr( "MNU_GLOBALPAN_VIEW" ), 0, this);
176 aAction->setStatusTip(tr("DSC_GLOBALPAN_VIEW"));
177 connect(aAction, SIGNAL(activated()), this, SLOT(onGlobalPanning()));
178 myActionsMap[ GlobalPanId ] = aAction;
180 // Curve type - points
181 aAction = new QtxAction(tr("TOT_PLOT2D_CURVES_POINTS"),
182 aResMgr->loadPixmap("Plot2d", tr("ICON_PLOT2D_CURVES_POINTS")),
183 tr("MEN_PLOT2D_CURVES_POINTS"), 0, this);
184 aAction->setStatusTip(tr("PRP_PLOT2D_CURVES_POINTS"));
185 connect(aAction, SIGNAL(activated()), this, SLOT(onCurves()));
186 aAction->setToggleAction(true);
187 myActionsMap[ CurvPointsId ] = aAction;
189 // Curve type - lines
190 aAction = new QtxAction(tr("TOT_PLOT2D_CURVES_LINES"),
191 aResMgr->loadPixmap("Plot2d", tr("ICON_PLOT2D_CURVES_LINES")),
192 tr("MEN_PLOT2D_CURVES_LINES"), 0, this);
193 aAction->setStatusTip(tr("PRP_PLOT2D_CURVES_LINES"));
194 connect(aAction, SIGNAL(activated()), this, SLOT(onCurves()));
195 aAction->setToggleAction(true);
196 myActionsMap[ CurvLinesId ] = aAction;
198 // Curve type - splines
199 aAction = new QtxAction(tr("TOT_PLOT2D_CURVES_SPLINES"),
200 aResMgr->loadPixmap("Plot2d", tr("ICON_PLOT2D_CURVES_SPLINES")),
201 tr("MEN_PLOT2D_CURVES_SPLINES"), 0, this);
202 aAction->setStatusTip(tr("PRP_PLOT2D_CURVES_SPLINES"));
203 connect(aAction, SIGNAL(activated()), this, SLOT(onCurves()));
204 aAction->setToggleAction(true);
205 myActionsMap[ CurvSplinesId ] = aAction;
207 // Mode for X (linear or logarithmic)
208 aAction = new QtxAction(tr("TOT_PLOT2D_MODE_LINEAR_HOR"),
209 aResMgr->loadPixmap("Plot2d", tr("ICON_PLOT2D_MODE_LINEAR_HOR")),
210 tr("MEN_PLOT2D_MODE_LINEAR_HOR"), 0, this);
211 aAction->setStatusTip (tr("PRP_PLOT2D_MODE_LINEAR_HOR"));
212 connect(aAction, SIGNAL(activated()), this, SLOT(onViewHorMode()));
213 myActionsMap[ HorId ] = aAction;
215 // Mode for Y (linear or logarithmic)
216 aAction = new QtxAction(tr("TOT_PLOT2D_MODE_LINEAR_VER"),
217 aResMgr->loadPixmap("Plot2d", tr("ICON_PLOT2D_MODE_LINEAR_VER")),
218 tr("MEN_PLOT2D_MODE_LINEAR_VER" ), 0, this);
219 aAction->setStatusTip(tr("PRP_PLOT2D_MODE_LINEAR_VER"));
220 connect(aAction, SIGNAL(activated()), this, SLOT(onViewVerMode()));
221 myActionsMap[ VerId ] = aAction;
224 aAction = new QtxAction(tr("TOT_PLOT2D_SHOW_LEGEND"),
225 aResMgr->loadPixmap("Plot2d", tr("ICON_PLOT2D_SHOW_LEGEND")),
226 tr("MEN_PLOT2D_SHOW_LEGEND"), 0, this);
227 aAction->setStatusTip(tr("PRP_PLOT2D_SHOW_LEGEND"));
228 connect(aAction, SIGNAL(activated()), this, SLOT(onLegend()));
229 aAction->setToggleAction(true);
230 myActionsMap[ LegendId ] = aAction;
233 aAction = new QtxAction(tr( "TOT_PLOT2D_SETTINGS"),
234 aResMgr->loadPixmap("Plot2d", tr("ICON_PLOT2D_SETTINGS")),
235 tr("MEN_PLOT2D_SETTINGS"), 0, this);
236 aAction->setStatusTip(tr( "PRP_PLOT2D_SETTINGS"));
237 connect(aAction, SIGNAL(activated()), myViewFrame, SLOT(onSettings()));
238 myActionsMap[ CurvSettingsId ] = aAction;
241 aAction = new QtxAction(tr("MNU_CLONE_VIEW"), aResMgr->loadPixmap( "Plot2d", tr( "ICON_PLOT2D_CLONE_VIEW" ) ),
242 tr( "MNU_CLONE_VIEW" ), 0, this);
243 aAction->setStatusTip(tr("DSC_CLONE_VIEW"));
244 connect(aAction, SIGNAL(activated()), this, SIGNAL(cloneView()));
245 myActionsMap[ CloneId ] = aAction;
248 /* Linear/logarithmic mode */
250 aAction = new QtxAction(tr("TOT_PLOT2D_MODE_LINEAR_HOR"),
251 aResMgr->loadPixmap("Plot2d", tr("ICON_PLOT2D_MODE_LINEAR_HOR")),
252 tr("MEN_PLOT2D_MODE_LINEAR_HOR"), 0, this);
253 aAction->setStatusTip (tr("PRP_PLOT2D_MODE_LINEAR_HOR"));
254 aAction->setToggleAction(true);
255 myActionsMap[PModeXLinearId] = aAction;
256 connect(aAction, SIGNAL(activated()), this, SLOT(onViewHorMode()));
258 aAction = new QtxAction(tr("TOT_PLOT2D_MODE_LOGARITHMIC_HOR"),
259 aResMgr->loadPixmap("Plot2d", tr("ICON_PLOT2D_MODE_LOGARITHMIC_HOR")),
260 tr("MEN_PLOT2D_MODE_LOGARITHMIC_HOR"), 0, this);
261 aAction->setStatusTip(tr("PRP_PLOT2D_MODE_LOGARITHMIC_HOR"));
262 aAction->setToggleAction(true);
263 myActionsMap[PModeXLogarithmicId] = aAction;
264 connect(aAction, SIGNAL(activated()), this, SLOT(onViewHorMode()));
267 aAction = new QtxAction(tr("TOT_PLOT2D_MODE_LINEAR_VER"),
268 aResMgr->loadPixmap("Plot2d", tr("ICON_PLOT2D_MODE_LINEAR_VER")),
269 tr("MEN_PLOT2D_MODE_LINEAR_VER" ), 0, this);
270 aAction->setStatusTip(tr("PRP_PLOT2D_MODE_LINEAR_VER"));
271 aAction->setToggleAction(true);
272 myActionsMap[PModeYLinearId] = aAction;
273 connect(aAction, SIGNAL(activated()), this, SLOT(onViewVerMode()));
275 aAction = new QtxAction(tr("TOT_PLOT2D_MODE_LOGARITHMIC_VER"),
276 aResMgr->loadPixmap("Plot2d", tr("ICON_PLOT2D_MODE_LOGARITHMIC_VER")),
277 tr("MEN_PLOT2D_MODE_LOGARITHMIC_VER" ), 0, this);
278 aAction->setStatusTip(tr("PRP_PLOT2D_MODE_LOGARITHMIC_VER"));
279 aAction->setToggleAction(true);
280 myActionsMap[PModeYLogarithmicId] = aAction;
281 connect(aAction, SIGNAL(activated()), this, SLOT(onViewVerMode()));
285 //****************************************************************
286 void Plot2d_ViewWindow::createToolBar()
288 myActionsMap[DumpId]->addTo(myToolBar);
290 SUIT_ToolButton* aScaleBtn = new SUIT_ToolButton(myToolBar);
291 aScaleBtn->AddAction(myActionsMap[FitAllId]);
292 aScaleBtn->AddAction(myActionsMap[FitRectId]);
293 aScaleBtn->AddAction(myActionsMap[ZoomId]);
295 SUIT_ToolButton* aPanBtn = new SUIT_ToolButton(myToolBar);
296 aPanBtn->AddAction(myActionsMap[PanId]);
297 aPanBtn->AddAction(myActionsMap[GlobalPanId]);
299 myCurveBtn = new SUIT_ToolButton(myToolBar);
300 myCurveBtn->AddAction(myActionsMap[CurvPointsId]);
301 myCurveBtn->AddAction(myActionsMap[CurvLinesId]);
302 myCurveBtn->AddAction(myActionsMap[CurvSplinesId]);
303 myActionsMap[CurvLinesId]->setOn(true);
306 myActionsMap[HorId]->addTo(myToolBar);
308 myActionsMap[VerId]->addTo(myToolBar);
311 myActionsMap[LegendId]->addTo(myToolBar);
312 myActionsMap[CurvSettingsId]->addTo(myToolBar);
313 myActionsMap[CloneId]->addTo(myToolBar);
314 onChangeLegendMode();
317 //****************************************************************
318 void Plot2d_ViewWindow::onChangeHorMode()
320 bool aLinear = myViewFrame->isModeHorLinear();
321 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
323 myActionsMap[PModeXLinearId]->setOn( aLinear );
324 myActionsMap[PModeXLogarithmicId]->setOn( !aLinear );
326 QPixmap pix = aResMgr->loadPixmap( "Plot2d", tr( aLinear ? "ICON_PLOT2D_MODE_LOGARITHMIC_HOR" :
327 "ICON_PLOT2D_MODE_LINEAR_HOR" ) );
328 myActionsMap[HorId]->setIconSet( pix );
329 myActionsMap[HorId]->setToolTip( tr( aLinear ? "TOT_PLOT2D_MODE_LOGARITHMIC_HOR" :
330 "TOT_PLOT2D_MODE_LINEAR_HOR" ) );
331 myActionsMap[HorId]->setStatusTip( tr( aLinear ? "PRP_PLOT2D_MODE_LOGARITHMIC_HOR" :
332 "PRP_PLOT2D_MODE_LINEAR_HOR" ) );
334 myActionsMap[GlobalPanId]->setEnabled( myViewFrame->isModeVerLinear() && myViewFrame->isModeHorLinear() );
337 //****************************************************************
338 void Plot2d_ViewWindow::onChangeVerMode()
340 bool aLinear = myViewFrame->isModeVerLinear();
341 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
343 myActionsMap[PModeYLinearId]->setOn( aLinear );
344 myActionsMap[PModeYLogarithmicId]->setOn( !aLinear );
346 QPixmap pix = aResMgr->loadPixmap( "Plot2d", tr( aLinear ? "ICON_PLOT2D_MODE_LOGARITHMIC_VER" :
347 "ICON_PLOT2D_MODE_LINEAR_VER" ) );
348 myActionsMap[VerId]->setIconSet( pix );
349 myActionsMap[VerId]->setToolTip( tr( aLinear ? "TOT_PLOT2D_MODE_LOGARITHMIC_VER" :
350 "TOT_PLOT2D_MODE_LINEAR_VER" ) );
351 myActionsMap[VerId]->setStatusTip( tr( aLinear ? "PRP_PLOT2D_MODE_LOGARITHMIC_VER" :
352 "PRP_PLOT2D_MODE_LINEAR_VER" ) );
354 myActionsMap[GlobalPanId]->setEnabled( myViewFrame->isModeVerLinear() && myViewFrame->isModeHorLinear() );
357 //****************************************************************
358 void Plot2d_ViewWindow::onChangeCurveMode()
360 int aCurveType = myViewFrame->getCurveType();
361 myCurveBtn->SetItem(aCurveType);
363 myActionsMap[CurvPointsId]->setOn(aCurveType == 0);
364 myActionsMap[CurvLinesId]->setOn(aCurveType == 1);
365 myActionsMap[CurvSplinesId]->setOn(aCurveType == 2);
368 //****************************************************************
369 void Plot2d_ViewWindow::onChangeLegendMode()
371 myActionsMap[ LegendId ]->setOn(myViewFrame->isLegendShow());
374 //****************************************************************
375 void Plot2d_ViewWindow::onFitAll()
377 myViewFrame->onViewFitAll();
380 //****************************************************************
381 void Plot2d_ViewWindow::onFitRect()
383 myViewFrame->onViewFitArea();
386 //****************************************************************
387 void Plot2d_ViewWindow::onZoom()
389 myViewFrame->onViewZoom();
392 //****************************************************************
393 void Plot2d_ViewWindow::onPanning()
395 myViewFrame->onViewPan();
398 //****************************************************************
399 void Plot2d_ViewWindow::onGlobalPanning()
401 myViewFrame->onViewGlobalPan();
404 //****************************************************************
405 void Plot2d_ViewWindow::onViewHorMode()
407 if (myViewFrame->isModeHorLinear())
408 myViewFrame->setHorScaleMode(1);
410 myViewFrame->setHorScaleMode(0);
413 //****************************************************************
414 void Plot2d_ViewWindow::onViewVerMode()
416 if (myViewFrame->isModeVerLinear())
417 myViewFrame->setVerScaleMode(1);
419 myViewFrame->setVerScaleMode(0);
422 //****************************************************************
423 void Plot2d_ViewWindow::onLegend()
425 myViewFrame->showLegend(!myViewFrame->isLegendShow());
426 onChangeLegendMode();
429 //****************************************************************
430 void Plot2d_ViewWindow::onCurves()
432 QtxAction* aSender = (QtxAction*) sender();
433 if(aSender == myActionsMap[CurvPointsId])
434 myViewFrame->setCurveType(0);
435 else if(aSender == myActionsMap[CurvLinesId])
436 myViewFrame->setCurveType(1);
437 else if(aSender == myActionsMap[CurvSplinesId])
438 myViewFrame->setCurveType(2);
441 //****************************************************************
442 void Plot2d_ViewWindow::onDumpView()
444 qApp->postEvent( myViewFrame, new QPaintEvent( QRect( 0, 0, myViewFrame->width(), myViewFrame->height() ), TRUE ) );
445 SUIT_ViewWindow::onDumpView();
448 //****************************************************************
449 QImage Plot2d_ViewWindow::dumpView()
451 QPixmap px = QPixmap::grabWindow( myViewFrame->winId() );
452 return px.convertToImage();
455 bool Plot2d_ViewWindow::dumpViewToFormat( const QString& fileName, const QString& format )
457 bool res = myViewFrame ? myViewFrame->print( fileName, format ) : false;
459 res = SUIT_ViewWindow::dumpViewToFormat( fileName, format );
464 QString Plot2d_ViewWindow::filter() const
466 return SUIT_ViewWindow::filter() + ";;" + tr( "POSTSCRIPT_FILES" );