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.salome-platform.org/ or email : webmaster.salome@opencascade.com
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"
45 #include "SVTK_SetRotationPointDlg.h"
47 #include "SVTK_MainWindow.h"
48 #include "SVTK_Event.h"
49 #include "SVTK_Renderer.h"
50 #include "SVTK_RenderWindowInteractor.h"
51 #include "SVTK_InteractorStyle.h"
53 #include "SVTK_Selector.h"
61 ::SVTK_MainWindow(QWidget* theParent,
63 SUIT_ResourceMgr* theResourceMgr,
64 SUIT_ViewWindow* theViewWindow) :
65 QMainWindow(theParent,theName,0),
66 myViewWindow(theViewWindow)
68 myToolBar = new QToolBar(this);
69 myToolBar->setCloseMode(QDockWindow::Undocked);
70 myToolBar->setLabel(tr("LBL_TOOLBAR_LABEL"));
72 createActions(theResourceMgr);
77 To initialize the class
81 ::Initialize(SVTK_RenderWindowInteractor* theInteractor)
83 myInteractor = theInteractor;
84 SetEventDispatcher(myInteractor->GetDevice());
86 setCentralWidget(myInteractor);
87 myInteractor->setBackgroundMode(Qt::NoBackground);
89 myInteractor->setFocusPolicy(StrongFocus);
90 myInteractor->setFocus();
91 setFocusProxy(myInteractor);
93 myUpdateRateDlg = new SVTK_UpdateRateDlg(myActionsMap[UpdateRate],this,"SVTK_UpdateRateDlg");
94 myNonIsometricDlg = new SVTK_NonIsometricDlg(myActionsMap[NonIsometric],this,"SVTK_NonIsometricDlg");
95 myCubeAxesDlg = new SVTK_CubeAxesDlg(myActionsMap[GraduatedAxes],this,"SVTK_CubeAxesDlg");
96 mySetRotationPointDlg = new SVTK_SetRotationPointDlg(myActionsMap[ChangeRotationPointId],this,"SVTK_SetRotationPointDlg");
108 \return used SVTK_RenderWindowInteractor
110 SVTK_RenderWindowInteractor*
118 \return used #vtkRenderWindowInteractor (obsolete)
120 vtkRenderWindowInteractor*
124 return GetInteractor()->GetDevice();
128 \return used vtkRenderWindow (obsolete)
134 return GetInteractor()->getRenderWindow();
139 \param theUpdateTrihedron - adjust trihedron
143 ::Repaint(bool theUpdateTrihedron)
145 if(theUpdateTrihedron)
146 GetRenderer()->OnAdjustTrihedron();
148 GetInteractor()->update();
150 if ( (SVTK_InteractorStyle*)GetInteractorStyle() )
151 ((SVTK_InteractorStyle*)GetInteractorStyle())->OnTimer();
155 To invoke a VTK event on SVTK_RenderWindowInteractor instance
159 ::InvokeEvent(unsigned long theEvent, void* theCallData)
161 GetInteractor()->InvokeEvent(theEvent,theCallData);
165 Redirect the request to SVTK_RenderWindowInteractor::GetInteractorStyle
169 ::GetInteractorStyle()
171 return GetInteractor()->GetInteractorStyle();
175 Redirect the request to SVTK_RenderWindowInteractor::PushInteractorStyle
179 ::PushInteractorStyle(vtkInteractorStyle* theStyle)
181 GetInteractor()->PushInteractorStyle(theStyle);
185 Redirect the request to SVTK_RenderWindowInteractor::PopInteractorStyle
189 ::PopInteractorStyle()
191 GetInteractor()->PopInteractorStyle();
195 Redirect the request to SVTK_RenderWindowInteractor::GetSelector
201 return GetInteractor()->GetSelector();
205 Redirect the request to SVTK_RenderWindowInteractor::SelectionMode
211 return GetSelector()->SelectionMode();
215 Redirect the request to SVTK_RenderWindowInteractor::SetSelectionMode
219 ::SetSelectionMode(Selection_Mode theMode)
221 GetSelector()->SetSelectionMode(theMode);
225 Redirect the request to SVTK_RenderWindowInteractor::GetRenderer
231 return GetInteractor()->GetRenderer();
235 Redirect the request to SVTK_RenderWindowInteractor::getRenderer
241 return GetInteractor()->getRenderer();
245 Sets background color of the view
246 \param theColor - new background color
250 ::SetBackgroundColor(const QColor& theColor)
252 getRenderer()->SetBackground(theColor.red()/255.0,
253 theColor.green()/255.0,
254 theColor.blue()/255.0);
258 \return background color of the view
264 vtkFloatingPointType aBackgroundColor[3];
265 getRenderer()->GetBackground(aBackgroundColor);
266 return QColor(int(aBackgroundColor[0]*255),
267 int(aBackgroundColor[1]*255),
268 int(aBackgroundColor[2]*255));
272 Redirect the request to SVTK_Renderer::GetScale
276 ::GetScale( double theScale[3] )
278 GetRenderer()->GetScale( theScale );
282 Redirect the request to SVTK_Renderer::SetScale
286 ::SetScale( double theScale[3] )
288 GetRenderer()->SetScale( theScale );
293 Redirect the request to SVTK_Renderer::AddActor
297 ::AddActor(VTKViewer_Actor* theActor,
300 GetRenderer()->AddActor(theActor);
306 Redirect the request to SVTK_Renderer::RemoveActor
310 ::RemoveActor(VTKViewer_Actor* theActor,
313 GetRenderer()->RemoveActor(theActor);
319 Redirect the request to SVTK_Renderer::GetTrihedronSize
325 return GetRenderer()->GetTrihedronSize();
329 Redirect the request to SVTK_Renderer::SetTrihedronSize
333 ::SetTrihedronSize( const vtkFloatingPointType theSize, const bool theRelative )
335 GetRenderer()->SetTrihedronSize(theSize, theRelative);
340 /*! If parameter theIsForcedUpdate is true, recalculate parameters for
341 * trihedron and cube axes, even if trihedron and cube axes is invisible.
347 GetRenderer()->AdjustActors();
352 Redirect the request to SVTK_Renderer::IsTrihedronDisplayed
356 ::IsTrihedronDisplayed()
358 return GetRenderer()->IsTrihedronDisplayed();
362 Redirect the request to SVTK_Renderer::IsCubeAxesDisplayed
366 ::IsCubeAxesDisplayed()
368 return GetRenderer()->IsCubeAxesDisplayed();
372 Redirect the request to SVTK_Renderer::GetTrihedron
378 return GetRenderer()->GetTrihedron();
382 Redirect the request to SVTK_Renderer::GetCubeAxes
384 SVTK_CubeAxesActor2D*
388 return GetRenderer()->GetCubeAxes();
392 \return toolbar of svtk main window
403 ::SetEventDispatcher(vtkObject* theDispatcher)
405 myEventDispatcher = theDispatcher;
408 #if defined(WIN32) && !defined(_DEBUG)
409 #pragma optimize( "", off )
413 Creates all actions of svtk main window
417 ::createActions(SUIT_ResourceMgr* theResourceMgr)
419 if(!myActionsMap.isEmpty())
425 anAction = new QtxAction(tr("MNU_DUMP_VIEW"),
426 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_DUMP" ) ),
427 tr( "MNU_DUMP_VIEW" ), 0, this);
428 anAction->setStatusTip(tr("DSC_DUMP_VIEW"));
429 connect(anAction, SIGNAL(activated()), myViewWindow, SLOT(onDumpView()));
430 myActionsMap[ DumpId ] = anAction;
433 anAction = new QtxAction(tr("MNU_FITALL"),
434 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_FITALL" ) ),
435 tr( "MNU_FITALL" ), 0, this);
436 anAction->setStatusTip(tr("DSC_FITALL"));
437 connect(anAction, SIGNAL(activated()), this, SLOT(onFitAll()));
438 myActionsMap[ FitAllId ] = anAction;
441 anAction = new QtxAction(tr("MNU_FITRECT"),
442 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_FITAREA" ) ),
443 tr( "MNU_FITRECT" ), 0, this);
444 anAction->setStatusTip(tr("DSC_FITRECT"));
445 connect(anAction, SIGNAL(activated()), this, SLOT(activateWindowFit()));
446 myActionsMap[ FitRectId ] = anAction;
449 anAction = new QtxAction(tr("MNU_ZOOM_VIEW"),
450 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_ZOOM" ) ),
451 tr( "MNU_ZOOM_VIEW" ), 0, this);
452 anAction->setStatusTip(tr("DSC_ZOOM_VIEW"));
453 connect(anAction, SIGNAL(activated()), this, SLOT(activateZoom()));
454 myActionsMap[ ZoomId ] = anAction;
457 anAction = new QtxAction(tr("MNU_PAN_VIEW"),
458 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_PAN" ) ),
459 tr( "MNU_PAN_VIEW" ), 0, this);
460 anAction->setStatusTip(tr("DSC_PAN_VIEW"));
461 connect(anAction, SIGNAL(activated()), this, SLOT(activatePanning()));
462 myActionsMap[ PanId ] = anAction;
465 anAction = new QtxAction(tr("MNU_GLOBALPAN_VIEW"),
466 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_GLOBALPAN" ) ),
467 tr( "MNU_GLOBALPAN_VIEW" ), 0, this);
468 anAction->setStatusTip(tr("DSC_GLOBALPAN_VIEW"));
469 connect(anAction, SIGNAL(activated()), this, SLOT(activateGlobalPanning()));
470 myActionsMap[ GlobalPanId ] = anAction;
472 // Change rotation point
473 anAction = new QtxAction(tr("MNU_CHANGINGROTATIONPOINT_VIEW"),
474 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_ROTATION_POINT" ) ),
475 tr( "MNU_CHANGINGROTATIONPOINT_VIEW" ), 0, this);
476 anAction->setStatusTip(tr("DSC_CHANGINGROTATIONPOINT_VIEW"));
477 anAction->setToggleAction(true);
478 connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onChangeRotationPoint(bool)));
479 myActionsMap[ ChangeRotationPointId ] = anAction;
482 anAction = new QtxAction(tr("MNU_ROTATE_VIEW"),
483 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_ROTATE" ) ),
484 tr( "MNU_ROTATE_VIEW" ), 0, this);
485 anAction->setStatusTip(tr("DSC_ROTATE_VIEW"));
486 connect(anAction, SIGNAL(activated()), this, SLOT(activateRotation()));
487 myActionsMap[ RotationId ] = anAction;
490 anAction = new QtxAction(tr("MNU_FRONT_VIEW"),
491 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_FRONT" ) ),
492 tr( "MNU_FRONT_VIEW" ), 0, this);
493 anAction->setStatusTip(tr("DSC_FRONT_VIEW"));
494 connect(anAction, SIGNAL(activated()), this, SLOT(onFrontView()));
495 myActionsMap[ FrontId ] = anAction;
497 anAction = new QtxAction(tr("MNU_BACK_VIEW"),
498 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_BACK" ) ),
499 tr( "MNU_BACK_VIEW" ), 0, this);
500 anAction->setStatusTip(tr("DSC_BACK_VIEW"));
501 connect(anAction, SIGNAL(activated()), this, SLOT(onBackView()));
502 myActionsMap[ BackId ] = anAction;
504 anAction = new QtxAction(tr("MNU_TOP_VIEW"),
505 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_TOP" ) ),
506 tr( "MNU_TOP_VIEW" ), 0, this);
507 anAction->setStatusTip(tr("DSC_TOP_VIEW"));
508 connect(anAction, SIGNAL(activated()), this, SLOT(onTopView()));
509 myActionsMap[ TopId ] = anAction;
511 anAction = new QtxAction(tr("MNU_BOTTOM_VIEW"),
512 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_BOTTOM" ) ),
513 tr( "MNU_BOTTOM_VIEW" ), 0, this);
514 anAction->setStatusTip(tr("DSC_BOTTOM_VIEW"));
515 connect(anAction, SIGNAL(activated()), this, SLOT(onBottomView()));
516 myActionsMap[ BottomId ] = anAction;
518 anAction = new QtxAction(tr("MNU_LEFT_VIEW"),
519 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_LEFT" ) ),
520 tr( "MNU_LEFT_VIEW" ), 0, this);
521 anAction->setStatusTip(tr("DSC_LEFT_VIEW"));
522 connect(anAction, SIGNAL(activated()), this, SLOT(onLeftView()));
523 myActionsMap[ LeftId ] = anAction;
525 anAction = new QtxAction(tr("MNU_RIGHT_VIEW"),
526 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_RIGHT" ) ),
527 tr( "MNU_RIGHT_VIEW" ), 0, this);
528 anAction->setStatusTip(tr("DSC_RIGHT_VIEW"));
529 connect(anAction, SIGNAL(activated()), this, SLOT(onRightView()));
530 myActionsMap[ RightId ] = anAction;
533 anAction = new QtxAction(tr("MNU_RESET_VIEW"),
534 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_RESET" ) ),
535 tr( "MNU_RESET_VIEW" ), 0, this);
536 anAction->setStatusTip(tr("DSC_RESET_VIEW"));
537 connect(anAction, SIGNAL(activated()), this, SLOT(onResetView()));
538 myActionsMap[ ResetId ] = anAction;
540 // onViewTrihedron: Shows - Hides Trihedron
541 anAction = new QtxAction(tr("MNU_SHOW_TRIHEDRON"),
542 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_TRIHEDRON" ) ),
543 tr( "MNU_SHOW_TRIHEDRON" ), 0, this);
544 anAction->setStatusTip(tr("DSC_SHOW_TRIHEDRON"));
545 connect(anAction, SIGNAL(activated()), this, SLOT(onViewTrihedron()));
546 myActionsMap[ ViewTrihedronId ] = anAction;
548 // onNonIsometric: Manage non-isometric params
549 anAction = new QtxAction(tr("MNU_SVTK_SCALING"),
550 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_SCALING" ) ),
551 tr( "MNU_SVTK_SCALING" ), 0, this);
552 anAction->setStatusTip(tr("DSC_SVTK_SCALING"));
553 anAction->setToggleAction(true);
554 connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onNonIsometric(bool)));
555 myActionsMap[ NonIsometric ] = anAction;
557 // onGraduatedAxes: Manage graduated axes params
558 anAction = new QtxAction(tr("MNU_SVTK_GRADUATED_AXES"),
559 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_GRADUATED_AXES" ) ),
560 tr( "MNU_SVTK_GRADUATED_AXES" ), 0, this);
561 anAction->setStatusTip(tr("DSC_SVTK_GRADUATED_AXES"));
562 anAction->setToggleAction(true);
563 connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onGraduatedAxes(bool)));
564 myActionsMap[ GraduatedAxes ] = anAction;
566 // onGraduatedAxes: Manage graduated axes params
567 anAction = new QtxAction(tr("MNU_SVTK_UPDATE_RATE"),
568 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_UPDATE_RATE" ) ),
569 tr( "MNU_SVTK_UPDATE_RATE" ), 0, this);
570 anAction->setStatusTip(tr("DSC_SVTK_UPDATE_RATE"));
571 anAction->setToggleAction(true);
572 connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onUpdateRate(bool)));
573 myActionsMap[ UpdateRate ] = anAction;
576 #if defined(WIN32) && !defined(_DEBUG)
577 #pragma optimize( "", on )
581 Creates toolbar of svtk main window
587 myActionsMap[DumpId]->addTo(myToolBar);
588 myActionsMap[ViewTrihedronId]->addTo(myToolBar);
590 SUIT_ToolButton* aScaleBtn = new SUIT_ToolButton(myToolBar);
591 aScaleBtn->AddAction(myActionsMap[FitAllId]);
592 aScaleBtn->AddAction(myActionsMap[FitRectId]);
593 aScaleBtn->AddAction(myActionsMap[ZoomId]);
595 SUIT_ToolButton* aPanningBtn = new SUIT_ToolButton(myToolBar);
596 aPanningBtn->AddAction(myActionsMap[PanId]);
597 aPanningBtn->AddAction(myActionsMap[GlobalPanId]);
599 myActionsMap[ChangeRotationPointId]->addTo(myToolBar);
601 myActionsMap[RotationId]->addTo(myToolBar);
603 SUIT_ToolButton* aViewsBtn = new SUIT_ToolButton(myToolBar);
604 aViewsBtn->AddAction(myActionsMap[FrontId]);
605 aViewsBtn->AddAction(myActionsMap[BackId]);
606 aViewsBtn->AddAction(myActionsMap[TopId]);
607 aViewsBtn->AddAction(myActionsMap[BottomId]);
608 aViewsBtn->AddAction(myActionsMap[LeftId]);
609 aViewsBtn->AddAction(myActionsMap[RightId]);
611 myActionsMap[ResetId]->addTo(myToolBar);
613 myActionsMap[UpdateRate]->addTo(myToolBar);
614 myActionsMap[NonIsometric]->addTo(myToolBar);
615 myActionsMap[GraduatedAxes]->addTo(myToolBar);
619 Custom show event handler
623 ::showEvent( QShowEvent * theEvent )
625 emit Show( theEvent );
629 Custom hide event handler
633 ::hideEvent( QHideEvent * theEvent )
635 emit Hide( theEvent );
639 Starts zoom transformation
645 myEventDispatcher->InvokeEvent(SVTK::StartZoom,0);
649 Starts panning transformation
655 myEventDispatcher->InvokeEvent(SVTK::StartPan,0);
659 Starts rotation transformation
665 myEventDispatcher->InvokeEvent(SVTK::StartRotate,0);
669 Change rotation point
673 ::onChangeRotationPoint(bool theIsActivate)
676 mySetRotationPointDlg->addObserver();
677 if ( mySetRotationPointDlg->IsFirstShown() )
678 activateSetRotationGravity();
679 mySetRotationPointDlg->show();
681 mySetRotationPointDlg->hide();
685 Set the gravity center as a rotation point
689 ::activateSetRotationGravity()
691 myEventDispatcher->InvokeEvent(SVTK::SetRotateGravity,0);
695 Set the selected point as a rotation point
699 ::activateSetRotationSelected(void* theData)
701 myEventDispatcher->InvokeEvent(SVTK::ChangeRotationPoint,theData);
705 Set the point selected by user as a rotation point
709 ::activateStartPointSelection()
711 myEventDispatcher->InvokeEvent(SVTK::StartPointSelection,0);
715 Starts global panning transformation
719 ::activateGlobalPanning()
721 myEventDispatcher->InvokeEvent(SVTK::StartGlobalPan,0);
725 Starts window fit transformation
729 ::activateWindowFit()
731 myEventDispatcher->InvokeEvent(SVTK::StartFitArea,0);
735 Processes transformation "front view"
741 GetRenderer()->OnFrontView();
746 Processes transformation "back view"
752 GetRenderer()->OnBackView();
757 Processes transformation "top view"
763 GetRenderer()->OnTopView();
768 Processes transformation "bottom view"
774 GetRenderer()->OnBottomView();
779 Processes transformation "left view"
785 GetRenderer()->OnLeftView();
790 Processes transformation "right view"
796 GetRenderer()->OnRightView();
801 Processes transformation "reset view": sets default orientation of viewport camera
807 GetRenderer()->OnResetView();
812 Processes transformation "fit all"
818 GetRenderer()->OnFitAll();
829 GetRenderer()->OnViewTrihedron();
840 GetRenderer()->OnViewCubeAxes();
846 ::onUpdateRate(bool theIsActivate)
849 myUpdateRateDlg->Update();
850 myUpdateRateDlg->show();
852 myUpdateRateDlg->hide();
857 ::onNonIsometric(bool theIsActivate)
860 myNonIsometricDlg->Update();
861 myNonIsometricDlg->show();
863 myNonIsometricDlg->hide();
868 ::onGraduatedAxes(bool theIsActivate)
871 myCubeAxesDlg->Update();
872 myCubeAxesDlg->show();
874 myCubeAxesDlg->hide();
879 ::onAdjustTrihedron()
881 GetRenderer()->OnAdjustTrihedron();
888 GetRenderer()->OnAdjustCubeAxes();
892 \return QImage, containing all scene rendering in window
898 QPixmap px = QPixmap::grabWindow( GetInteractor()->winId() );
899 return px.convertToImage();