1 // SALOME VTKViewer : build VTK viewer into Salome desktop
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
29 #include "SALOME_Actor.h"
31 #include <vtkGenericRenderWindowInteractor.h>
32 #include <vtkRenderer.h>
34 #include "QtxAction.h"
36 #include "SUIT_ToolButton.h"
37 #include "SUIT_MessageBox.h"
38 #include "SUIT_ViewWindow.h"
40 #include "SUIT_Tools.h"
41 #include "SUIT_ResourceMgr.h"
42 #include "SVTK_NonIsometricDlg.h"
43 #include "SVTK_UpdateRateDlg.h"
44 #include "SVTK_CubeAxesDlg.h"
46 #include "SVTK_MainWindow.h"
47 #include "SVTK_Event.h"
48 #include "SVTK_Renderer.h"
49 #include "SVTK_RenderWindowInteractor.h"
51 #include "SVTK_Selector.h"
59 ::SVTK_MainWindow(QWidget* theParent,
61 SUIT_ResourceMgr* theResourceMgr,
62 SUIT_ViewWindow* theViewWindow) :
63 QMainWindow(theParent,theName,0),
64 myViewWindow(theViewWindow)
66 myToolBar = new QToolBar(this);
67 myToolBar->setCloseMode(QDockWindow::Undocked);
68 myToolBar->setLabel(tr("LBL_TOOLBAR_LABEL"));
70 createActions(theResourceMgr);
75 To initialize the class
79 ::Initialize(SVTK_RenderWindowInteractor* theInteractor)
81 myInteractor = theInteractor;
82 SetEventDispatcher(myInteractor->GetDevice());
84 setCentralWidget(myInteractor);
85 myInteractor->setBackgroundMode(Qt::NoBackground);
87 myInteractor->setFocusPolicy(StrongFocus);
88 myInteractor->setFocus();
89 setFocusProxy(myInteractor);
91 myUpdateRateDlg = new SVTK_UpdateRateDlg(myActionsMap[UpdateRate],this,"SVTK_UpdateRateDlg");
92 myNonIsometricDlg = new SVTK_NonIsometricDlg(myActionsMap[NonIsometric],this,"SVTK_NonIsometricDlg");
93 myCubeAxesDlg = new SVTK_CubeAxesDlg(myActionsMap[GraduatedAxes],this,"SVTK_CubeAxesDlg");
105 \return used SVTK_RenderWindowInteractor
107 SVTK_RenderWindowInteractor*
115 \return used #vtkRenderWindowInteractor (obsolete)
117 vtkRenderWindowInteractor*
121 return GetInteractor()->GetDevice();
125 \return used vtkRenderWindow (obsolete)
131 return GetInteractor()->getRenderWindow();
136 \param theUpdateTrihedron - adjust trihedron
140 ::Repaint(bool theUpdateTrihedron)
142 if(theUpdateTrihedron)
143 GetRenderer()->OnAdjustTrihedron();
145 GetInteractor()->update();
149 To invoke a VTK event on SVTK_RenderWindowInteractor instance
153 ::InvokeEvent(unsigned long theEvent, void* theCallData)
155 GetInteractor()->InvokeEvent(theEvent,theCallData);
159 Redirect the request to SVTK_RenderWindowInteractor::GetInteractorStyle
163 ::GetInteractorStyle()
165 return GetInteractor()->GetInteractorStyle();
169 Redirect the request to SVTK_RenderWindowInteractor::PushInteractorStyle
173 ::PushInteractorStyle(vtkInteractorStyle* theStyle)
175 GetInteractor()->PushInteractorStyle(theStyle);
179 Redirect the request to SVTK_RenderWindowInteractor::PopInteractorStyle
183 ::PopInteractorStyle()
185 GetInteractor()->PopInteractorStyle();
189 Redirect the request to SVTK_RenderWindowInteractor::GetSelector
195 return GetInteractor()->GetSelector();
199 Redirect the request to SVTK_RenderWindowInteractor::SelectionMode
205 return GetSelector()->SelectionMode();
209 Redirect the request to SVTK_RenderWindowInteractor::SetSelectionMode
213 ::SetSelectionMode(Selection_Mode theMode)
215 GetSelector()->SetSelectionMode(theMode);
219 Redirect the request to SVTK_RenderWindowInteractor::GetRenderer
225 return GetInteractor()->GetRenderer();
229 Redirect the request to SVTK_RenderWindowInteractor::getRenderer
235 return GetInteractor()->getRenderer();
239 Sets background color of the view
240 \param theColor - new background color
244 ::SetBackgroundColor(const QColor& theColor)
246 getRenderer()->SetBackground(theColor.red()/255.0,
247 theColor.green()/255.0,
248 theColor.blue()/255.0);
252 \return background color of the view
258 vtkFloatingPointType aBackgroundColor[3];
259 getRenderer()->GetBackground(aBackgroundColor);
260 return QColor(int(aBackgroundColor[0]*255),
261 int(aBackgroundColor[1]*255),
262 int(aBackgroundColor[2]*255));
266 Redirect the request to SVTK_Renderer::GetScale
270 ::GetScale( double theScale[3] )
272 GetRenderer()->GetScale( theScale );
276 Redirect the request to SVTK_Renderer::SetScale
280 ::SetScale( double theScale[3] )
282 GetRenderer()->SetScale( theScale );
287 Redirect the request to SVTK_Renderer::AddActor
291 ::AddActor(VTKViewer_Actor* theActor,
294 GetRenderer()->AddActor(theActor);
300 Redirect the request to SVTK_Renderer::RemoveActor
304 ::RemoveActor(VTKViewer_Actor* theActor,
307 GetRenderer()->RemoveActor(theActor);
313 Redirect the request to SVTK_Renderer::GetTrihedronSize
319 return GetRenderer()->GetTrihedronSize();
323 Redirect the request to SVTK_Renderer::SetTrihedronSize
327 ::SetTrihedronSize( const int theSize, const bool theRelative )
329 GetRenderer()->SetTrihedronSize(theSize, theRelative);
334 /*! If parameter theIsForcedUpdate is true, recalculate parameters for
335 * trihedron and cube axes, even if trihedron and cube axes is invisible.
341 GetRenderer()->AdjustActors();
346 Redirect the request to SVTK_Renderer::IsTrihedronDisplayed
350 ::IsTrihedronDisplayed()
352 return GetRenderer()->IsTrihedronDisplayed();
356 Redirect the request to SVTK_Renderer::IsCubeAxesDisplayed
360 ::IsCubeAxesDisplayed()
362 return GetRenderer()->IsCubeAxesDisplayed();
366 Redirect the request to SVTK_Renderer::GetTrihedron
372 return GetRenderer()->GetTrihedron();
376 Redirect the request to SVTK_Renderer::GetCubeAxes
378 SVTK_CubeAxesActor2D*
382 return GetRenderer()->GetCubeAxes();
386 \return toolbar of svtk main window
397 ::SetEventDispatcher(vtkObject* theDispatcher)
399 myEventDispatcher = theDispatcher;
402 #if defined(WIN32) && !defined(_DEBUG)
403 #pragma optimize( "", off )
407 Creates all actions of svtk main window
411 ::createActions(SUIT_ResourceMgr* theResourceMgr)
413 if(!myActionsMap.isEmpty())
419 anAction = new QtxAction(tr("MNU_DUMP_VIEW"),
420 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_DUMP" ) ),
421 tr( "MNU_DUMP_VIEW" ), 0, this);
422 anAction->setStatusTip(tr("DSC_DUMP_VIEW"));
423 connect(anAction, SIGNAL(activated()), myViewWindow, SLOT(onDumpView()));
424 myActionsMap[ DumpId ] = anAction;
427 anAction = new QtxAction(tr("MNU_FITALL"),
428 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_FITALL" ) ),
429 tr( "MNU_FITALL" ), 0, this);
430 anAction->setStatusTip(tr("DSC_FITALL"));
431 connect(anAction, SIGNAL(activated()), this, SLOT(onFitAll()));
432 myActionsMap[ FitAllId ] = anAction;
435 anAction = new QtxAction(tr("MNU_FITRECT"),
436 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_FITAREA" ) ),
437 tr( "MNU_FITRECT" ), 0, this);
438 anAction->setStatusTip(tr("DSC_FITRECT"));
439 connect(anAction, SIGNAL(activated()), this, SLOT(activateWindowFit()));
440 myActionsMap[ FitRectId ] = anAction;
443 anAction = new QtxAction(tr("MNU_ZOOM_VIEW"),
444 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_ZOOM" ) ),
445 tr( "MNU_ZOOM_VIEW" ), 0, this);
446 anAction->setStatusTip(tr("DSC_ZOOM_VIEW"));
447 connect(anAction, SIGNAL(activated()), this, SLOT(activateZoom()));
448 myActionsMap[ ZoomId ] = anAction;
451 anAction = new QtxAction(tr("MNU_PAN_VIEW"),
452 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_PAN" ) ),
453 tr( "MNU_PAN_VIEW" ), 0, this);
454 anAction->setStatusTip(tr("DSC_PAN_VIEW"));
455 connect(anAction, SIGNAL(activated()), this, SLOT(activatePanning()));
456 myActionsMap[ PanId ] = anAction;
459 anAction = new QtxAction(tr("MNU_GLOBALPAN_VIEW"),
460 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_GLOBALPAN" ) ),
461 tr( "MNU_GLOBALPAN_VIEW" ), 0, this);
462 anAction->setStatusTip(tr("DSC_GLOBALPAN_VIEW"));
463 connect(anAction, SIGNAL(activated()), this, SLOT(activateGlobalPanning()));
464 myActionsMap[ GlobalPanId ] = anAction;
467 anAction = new QtxAction(tr("MNU_ROTATE_VIEW"),
468 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_ROTATE" ) ),
469 tr( "MNU_ROTATE_VIEW" ), 0, this);
470 anAction->setStatusTip(tr("DSC_ROTATE_VIEW"));
471 connect(anAction, SIGNAL(activated()), this, SLOT(activateRotation()));
472 myActionsMap[ RotationId ] = anAction;
475 anAction = new QtxAction(tr("MNU_FRONT_VIEW"),
476 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_FRONT" ) ),
477 tr( "MNU_FRONT_VIEW" ), 0, this);
478 anAction->setStatusTip(tr("DSC_FRONT_VIEW"));
479 connect(anAction, SIGNAL(activated()), this, SLOT(onFrontView()));
480 myActionsMap[ FrontId ] = anAction;
482 anAction = new QtxAction(tr("MNU_BACK_VIEW"),
483 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_BACK" ) ),
484 tr( "MNU_BACK_VIEW" ), 0, this);
485 anAction->setStatusTip(tr("DSC_BACK_VIEW"));
486 connect(anAction, SIGNAL(activated()), this, SLOT(onBackView()));
487 myActionsMap[ BackId ] = anAction;
489 anAction = new QtxAction(tr("MNU_TOP_VIEW"),
490 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_TOP" ) ),
491 tr( "MNU_TOP_VIEW" ), 0, this);
492 anAction->setStatusTip(tr("DSC_TOP_VIEW"));
493 connect(anAction, SIGNAL(activated()), this, SLOT(onTopView()));
494 myActionsMap[ TopId ] = anAction;
496 anAction = new QtxAction(tr("MNU_BOTTOM_VIEW"),
497 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_BOTTOM" ) ),
498 tr( "MNU_BOTTOM_VIEW" ), 0, this);
499 anAction->setStatusTip(tr("DSC_BOTTOM_VIEW"));
500 connect(anAction, SIGNAL(activated()), this, SLOT(onBottomView()));
501 myActionsMap[ BottomId ] = anAction;
503 anAction = new QtxAction(tr("MNU_LEFT_VIEW"),
504 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_LEFT" ) ),
505 tr( "MNU_LEFT_VIEW" ), 0, this);
506 anAction->setStatusTip(tr("DSC_LEFT_VIEW"));
507 connect(anAction, SIGNAL(activated()), this, SLOT(onLeftView()));
508 myActionsMap[ LeftId ] = anAction;
510 anAction = new QtxAction(tr("MNU_RIGHT_VIEW"),
511 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_RIGHT" ) ),
512 tr( "MNU_RIGHT_VIEW" ), 0, this);
513 anAction->setStatusTip(tr("DSC_RIGHT_VIEW"));
514 connect(anAction, SIGNAL(activated()), this, SLOT(onRightView()));
515 myActionsMap[ RightId ] = anAction;
518 anAction = new QtxAction(tr("MNU_RESET_VIEW"),
519 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_RESET" ) ),
520 tr( "MNU_RESET_VIEW" ), 0, this);
521 anAction->setStatusTip(tr("DSC_RESET_VIEW"));
522 connect(anAction, SIGNAL(activated()), this, SLOT(onResetView()));
523 myActionsMap[ ResetId ] = anAction;
525 // onViewTrihedron: Shows - Hides Trihedron
526 anAction = new QtxAction(tr("MNU_SHOW_TRIHEDRON"),
527 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_TRIHEDRON" ) ),
528 tr( "MNU_SHOW_TRIHEDRON" ), 0, this);
529 anAction->setStatusTip(tr("DSC_SHOW_TRIHEDRON"));
530 connect(anAction, SIGNAL(activated()), this, SLOT(onViewTrihedron()));
531 myActionsMap[ ViewTrihedronId ] = anAction;
533 // onNonIsometric: Manage non-isometric params
534 anAction = new QtxAction(tr("MNU_SVTK_SCALING"),
535 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_SCALING" ) ),
536 tr( "MNU_SVTK_SCALING" ), 0, this);
537 anAction->setStatusTip(tr("DSC_SVTK_SCALING"));
538 anAction->setToggleAction(true);
539 connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onNonIsometric(bool)));
540 myActionsMap[ NonIsometric ] = anAction;
542 // onGraduatedAxes: Manage graduated axes params
543 anAction = new QtxAction(tr("MNU_SVTK_GRADUATED_AXES"),
544 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_GRADUATED_AXES" ) ),
545 tr( "MNU_SVTK_GRADUATED_AXES" ), 0, this);
546 anAction->setStatusTip(tr("DSC_SVTK_GRADUATED_AXES"));
547 anAction->setToggleAction(true);
548 connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onGraduatedAxes(bool)));
549 myActionsMap[ GraduatedAxes ] = anAction;
551 // onGraduatedAxes: Manage graduated axes params
552 anAction = new QtxAction(tr("MNU_SVTK_UPDATE_RATE"),
553 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_UPDATE_RATE" ) ),
554 tr( "MNU_SVTK_UPDATE_RATE" ), 0, this);
555 anAction->setStatusTip(tr("DSC_SVTK_UPDATE_RATE"));
556 anAction->setToggleAction(true);
557 connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onUpdateRate(bool)));
558 myActionsMap[ UpdateRate ] = anAction;
561 #if defined(WIN32) && !defined(_DEBUG)
562 #pragma optimize( "", on )
566 Creates toolbar of svtk main window
572 myActionsMap[DumpId]->addTo(myToolBar);
573 myActionsMap[ViewTrihedronId]->addTo(myToolBar);
575 SUIT_ToolButton* aScaleBtn = new SUIT_ToolButton(myToolBar);
576 aScaleBtn->AddAction(myActionsMap[FitAllId]);
577 aScaleBtn->AddAction(myActionsMap[FitRectId]);
578 aScaleBtn->AddAction(myActionsMap[ZoomId]);
580 SUIT_ToolButton* aPanningBtn = new SUIT_ToolButton(myToolBar);
581 aPanningBtn->AddAction(myActionsMap[PanId]);
582 aPanningBtn->AddAction(myActionsMap[GlobalPanId]);
584 myActionsMap[RotationId]->addTo(myToolBar);
586 SUIT_ToolButton* aViewsBtn = new SUIT_ToolButton(myToolBar);
587 aViewsBtn->AddAction(myActionsMap[FrontId]);
588 aViewsBtn->AddAction(myActionsMap[BackId]);
589 aViewsBtn->AddAction(myActionsMap[TopId]);
590 aViewsBtn->AddAction(myActionsMap[BottomId]);
591 aViewsBtn->AddAction(myActionsMap[LeftId]);
592 aViewsBtn->AddAction(myActionsMap[RightId]);
594 myActionsMap[ResetId]->addTo(myToolBar);
596 myActionsMap[UpdateRate]->addTo(myToolBar);
597 myActionsMap[NonIsometric]->addTo(myToolBar);
598 myActionsMap[GraduatedAxes]->addTo(myToolBar);
602 Custom show event handler
606 ::showEvent( QShowEvent * theEvent )
608 emit Show( theEvent );
612 Custom hide event handler
616 ::hideEvent( QHideEvent * theEvent )
618 emit Hide( theEvent );
622 Starts zoom transformation
628 myEventDispatcher->InvokeEvent(SVTK::StartZoom,0);
632 Starts panning transformation
638 myEventDispatcher->InvokeEvent(SVTK::StartPan,0);
642 Starts rotation transformation
648 myEventDispatcher->InvokeEvent(SVTK::StartRotate,0);
652 Starts global panning transformation
656 ::activateGlobalPanning()
658 myEventDispatcher->InvokeEvent(SVTK::StartGlobalPan,0);
662 Starts window fit transformation
666 ::activateWindowFit()
668 myEventDispatcher->InvokeEvent(SVTK::StartFitArea,0);
672 Processes transformation "front view"
678 GetRenderer()->OnFrontView();
683 Processes transformation "back view"
689 GetRenderer()->OnBackView();
694 Processes transformation "top view"
700 GetRenderer()->OnTopView();
705 Processes transformation "bottom view"
711 GetRenderer()->OnBottomView();
716 Processes transformation "left view"
722 GetRenderer()->OnLeftView();
727 Processes transformation "right view"
733 GetRenderer()->OnRightView();
738 Processes transformation "reset view": sets default orientation of viewport camera
744 GetRenderer()->OnResetView();
749 Processes transformation "fit all"
755 GetRenderer()->OnFitAll();
766 GetRenderer()->OnViewTrihedron();
777 GetRenderer()->OnViewCubeAxes();
783 ::onUpdateRate(bool theIsActivate)
786 myUpdateRateDlg->Update();
787 myUpdateRateDlg->show();
789 myUpdateRateDlg->hide();
794 ::onNonIsometric(bool theIsActivate)
797 myNonIsometricDlg->Update();
798 myNonIsometricDlg->show();
800 myNonIsometricDlg->hide();
805 ::onGraduatedAxes(bool theIsActivate)
808 myCubeAxesDlg->Update();
809 myCubeAxesDlg->show();
811 myCubeAxesDlg->hide();
816 ::onAdjustTrihedron()
818 GetRenderer()->OnAdjustTrihedron();
825 GetRenderer()->OnAdjustCubeAxes();
829 \return QImage, containing all scene rendering in window
835 QPixmap px = QPixmap::grabWindow( GetInteractor()->winId() );
836 return px.convertToImage();