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>
38 //////////////////////////////////////////////////////////////////////
39 // Construction/Destruction
40 //////////////////////////////////////////////////////////////////////
42 Plot2d_ViewWindow::Plot2d_ViewWindow(SUIT_Desktop* theDesktop, Plot2d_Viewer* theModel)
43 : SUIT_ViewWindow(theDesktop)
47 myViewFrame = new Plot2d_ViewFrame(this, "plotView");
48 setCentralWidget(myViewFrame);
50 myToolBar = new QToolBar(this);
51 myToolBar->setCloseMode(QDockWindow::Undocked);
52 myToolBar->setLabel(tr("LBL_TOOLBAR_LABEL"));
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 * )) );
64 Plot2d_ViewWindow::~Plot2d_ViewWindow()
68 //****************************************************************
69 void Plot2d_ViewWindow::putInfo(QString theMsg)
71 QStatusBar* aStatusBar = myDesktop->statusBar();
72 aStatusBar->message(theMsg/*, 3000*/);
75 //****************************************************************
76 void Plot2d_ViewWindow::contextMenuPopup( QPopupMenu* thePopup )
79 QPopupMenu* scalingPopup = new QPopupMenu( thePopup );
80 myActionsMap[ PModeXLinearId ]->addTo( scalingPopup );
81 myActionsMap[ PModeXLogarithmicId ]->addTo( scalingPopup );
83 scalingPopup->insertSeparator();
84 myActionsMap[ PModeYLinearId ]->addTo( scalingPopup );
85 myActionsMap[ PModeYLogarithmicId ]->addTo( scalingPopup );
86 thePopup->insertItem( tr( "SCALING_POPUP" ), scalingPopup );
89 thePopup->insertItem(tr("TOT_PLOT2D_FITDATA"), myViewFrame, SLOT(onFitData()));
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 );
98 myActionsMap[ LegendId ]->addTo(thePopup);
100 myActionsMap[ CurvSettingsId ]->addTo(thePopup);
103 //****************************************************************
104 bool Plot2d_ViewWindow::eventFilter(QObject* watched, QEvent* e)
106 if (watched == myViewFrame) {
107 int aType = e->type();
109 case QEvent::MouseButtonPress:
110 emit mousePressed(this, (QMouseEvent*) e);
113 case QEvent::MouseButtonRelease:
114 emit mouseReleased(this, (QMouseEvent*) e);
117 case QEvent::MouseMove:
118 emit mouseMoving(this, (QMouseEvent*) e);
125 return SUIT_ViewWindow::eventFilter(watched, e);
128 //****************************************************************
129 void Plot2d_ViewWindow::createActions()
131 if ( !myActionsMap.isEmpty() )
135 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
247 /* Linear/logarithmic mode */
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()));
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()));
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()));
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()));
284 //****************************************************************
285 void Plot2d_ViewWindow::createToolBar()
287 myActionsMap[DumpId]->addTo(myToolBar);
289 SUIT_ToolButton* aScaleBtn = new SUIT_ToolButton(myToolBar);
290 aScaleBtn->AddAction(myActionsMap[FitAllId]);
291 aScaleBtn->AddAction(myActionsMap[FitRectId]);
292 aScaleBtn->AddAction(myActionsMap[ZoomId]);
294 SUIT_ToolButton* aPanBtn = new SUIT_ToolButton(myToolBar);
295 aPanBtn->AddAction(myActionsMap[PanId]);
296 aPanBtn->AddAction(myActionsMap[GlobalPanId]);
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);
305 myActionsMap[HorId]->addTo(myToolBar);
307 myActionsMap[VerId]->addTo(myToolBar);
310 myActionsMap[LegendId]->addTo(myToolBar);
311 myActionsMap[CurvSettingsId]->addTo(myToolBar);
312 myActionsMap[CloneId]->addTo(myToolBar);
313 onChangeLegendMode();
316 //****************************************************************
317 void Plot2d_ViewWindow::onChangeHorMode()
319 bool aLinear = myViewFrame->isModeHorLinear();
320 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
322 myActionsMap[PModeXLinearId]->setOn( aLinear );
323 myActionsMap[PModeXLogarithmicId]->setOn( !aLinear );
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" ) );
333 myActionsMap[GlobalPanId]->setEnabled( myViewFrame->isModeVerLinear() && myViewFrame->isModeHorLinear() );
336 //****************************************************************
337 void Plot2d_ViewWindow::onChangeVerMode()
339 bool aLinear = myViewFrame->isModeVerLinear();
340 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
342 myActionsMap[PModeYLinearId]->setOn( aLinear );
343 myActionsMap[PModeYLogarithmicId]->setOn( !aLinear );
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" ) );
353 myActionsMap[GlobalPanId]->setEnabled( myViewFrame->isModeVerLinear() && myViewFrame->isModeHorLinear() );
356 //****************************************************************
357 void Plot2d_ViewWindow::onChangeCurveMode()
359 myCurveBtn->SetItem(myViewFrame->getCurveType());
362 //****************************************************************
363 void Plot2d_ViewWindow::onChangeLegendMode()
365 myActionsMap[ LegendId ]->setOn(myViewFrame->isLegendShow());
368 //****************************************************************
369 void Plot2d_ViewWindow::onFitAll()
371 myViewFrame->onViewFitAll();
374 //****************************************************************
375 void Plot2d_ViewWindow::onFitRect()
377 myViewFrame->onViewFitArea();
380 //****************************************************************
381 void Plot2d_ViewWindow::onZoom()
383 myViewFrame->onViewZoom();
386 //****************************************************************
387 void Plot2d_ViewWindow::onPanning()
389 myViewFrame->onViewPan();
392 //****************************************************************
393 void Plot2d_ViewWindow::onGlobalPanning()
395 myViewFrame->onViewGlobalPan();
398 //****************************************************************
399 void Plot2d_ViewWindow::onViewHorMode()
401 if (myViewFrame->isModeHorLinear())
402 myViewFrame->setHorScaleMode(1);
404 myViewFrame->setHorScaleMode(0);
407 //****************************************************************
408 void Plot2d_ViewWindow::onViewVerMode()
410 if (myViewFrame->isModeVerLinear())
411 myViewFrame->setVerScaleMode(1);
413 myViewFrame->setVerScaleMode(0);
416 //****************************************************************
417 void Plot2d_ViewWindow::onLegend()
419 myViewFrame->showLegend(!myViewFrame->isLegendShow());
420 onChangeLegendMode();
423 //****************************************************************
424 void Plot2d_ViewWindow::onCurves()
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);
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);
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);
447 //****************************************************************
448 void Plot2d_ViewWindow::onDumpView()
450 qApp->postEvent( myViewFrame, new QPaintEvent( QRect( 0, 0, myViewFrame->width(), myViewFrame->height() ), TRUE ) );
451 SUIT_ViewWindow::onDumpView();
454 //****************************************************************
455 QImage Plot2d_ViewWindow::dumpView()
457 QPixmap px = QPixmap::grabWindow( myViewFrame->winId() );
458 return px.convertToImage();