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_CubeAxesDlg.h"
45 #include "SVTK_MainWindow.h"
46 #include "SVTK_Event.h"
47 #include "SVTK_Renderer.h"
48 #include "SVTK_RenderWindowInteractor.h"
50 #include "SVTK_Selector.h"
55 //----------------------------------------------------------------------------
57 ::SVTK_MainWindow(QWidget* theParent,
59 SUIT_ResourceMgr* theResourceMgr,
60 SUIT_ViewWindow* theViewWindow) :
61 QMainWindow(theParent,theName,0),
62 myViewWindow(theViewWindow)
64 myToolBar = new QToolBar(this);
65 myToolBar->setCloseMode(QDockWindow::Undocked);
66 myToolBar->setLabel(tr("LBL_TOOLBAR_LABEL"));
68 createActions(theResourceMgr);
74 ::Initialize(SVTK_RenderWindowInteractor* theInteractor)
76 myInteractor = theInteractor;
77 SetEventDispatcher(myInteractor->GetDevice());
79 setCentralWidget(myInteractor);
80 myInteractor->setBackgroundMode(Qt::NoBackground);
82 myInteractor->setFocusPolicy(StrongFocus);
83 myInteractor->setFocus();
84 setFocusProxy(myInteractor);
88 //----------------------------------------------------------------------------
95 //----------------------------------------------------------------------------
96 SVTK_RenderWindowInteractor*
103 vtkRenderWindowInteractor*
107 return GetInteractor()->GetDevice();
114 return GetInteractor()->getRenderWindow();
117 //----------------------------------------------------------------------------
120 ::Repaint(bool theUpdateTrihedron)
122 if(theUpdateTrihedron)
123 GetRenderer()->OnAdjustTrihedron();
125 GetInteractor()->update();
128 //----------------------------------------------------------------------------
131 ::InvokeEvent(unsigned long theEvent, void* theCallData)
133 GetInteractor()->InvokeEvent(theEvent,theCallData);
136 //----------------------------------------------------------------------------
139 ::GetInteractorStyle()
141 return GetInteractor()->GetInteractorStyle();
146 ::PushInteractorStyle(vtkInteractorStyle* theStyle)
148 GetInteractor()->PushInteractorStyle(theStyle);
153 ::PopInteractorStyle()
155 GetInteractor()->PopInteractorStyle();
158 //----------------------------------------------------------------------------
163 return GetInteractor()->GetSelector();
170 return GetSelector()->SelectionMode();
175 ::SetSelectionMode(Selection_Mode theMode)
177 GetSelector()->SetSelectionMode(theMode);
181 //----------------------------------------------------------------------------
186 return GetInteractor()->GetRenderer();
193 return GetInteractor()->getRenderer();
196 //----------------------------------------------------------------------------
199 ::SetBackgroundColor(const QColor& theColor)
201 getRenderer()->SetBackground(theColor.red()/255.0,
202 theColor.green()/255.0,
203 theColor.blue()/255.0);
210 float aBackgroundColor[3];
211 getRenderer()->GetBackground(aBackgroundColor);
212 return QColor(int(aBackgroundColor[0]*255),
213 int(aBackgroundColor[1]*255),
214 int(aBackgroundColor[2]*255));
217 //----------------------------------------------------------------------------
220 ::GetScale( double theScale[3] )
222 GetRenderer()->GetScale( theScale );
227 ::SetScale( double theScale[3] )
229 GetRenderer()->SetScale( theScale );
234 //----------------------------------------------------------------------------
237 ::AddActor(VTKViewer_Actor* theActor,
240 GetRenderer()->AddActor(theActor);
245 //----------------------------------------------------------------------------
248 ::RemoveActor(VTKViewer_Actor* theActor,
251 GetRenderer()->RemoveActor(theActor);
257 //----------------------------------------------------------------------------
262 return GetRenderer()->GetTrihedronSize();
265 //----------------------------------------------------------------------------
268 ::SetTrihedronSize( const int theSize, const bool theRelative )
270 GetRenderer()->SetTrihedronSize(theSize, theRelative);
275 //----------------------------------------------------------------------------
276 /*! If parameter theIsForcedUpdate is true, recalculate parameters for
277 * trihedron and cube axes, even if trihedron and cube axes is invisible.
283 GetRenderer()->AdjustActors();
287 //----------------------------------------------------------------------------
290 ::IsTrihedronDisplayed()
292 return GetRenderer()->IsTrihedronDisplayed();
295 //----------------------------------------------------------------------------
298 ::IsCubeAxesDisplayed()
300 return GetRenderer()->IsCubeAxesDisplayed();
303 //----------------------------------------------------------------------------
308 return GetRenderer()->GetTrihedron();
311 //----------------------------------------------------------------------------
312 SVTK_CubeAxesActor2D*
316 return GetRenderer()->GetCubeAxes();
320 //----------------------------------------------------------------------------
328 //----------------------------------------------------------------------------
331 ::SetEventDispatcher(vtkObject* theDispatcher)
333 myEventDispatcher = theDispatcher;
336 //----------------------------------------------------------------------------
337 #if defined(WIN32) && !defined(_DEBUG)
338 #pragma optimize( "", off )
343 ::createActions(SUIT_ResourceMgr* theResourceMgr)
345 if(!myActionsMap.isEmpty())
351 anAction = new QtxAction(tr("MNU_DUMP_VIEW"),
352 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_DUMP" ) ),
353 tr( "MNU_DUMP_VIEW" ), 0, this);
354 anAction->setStatusTip(tr("DSC_DUMP_VIEW"));
355 connect(anAction, SIGNAL(activated()), myViewWindow, SLOT(onDumpView()));
356 myActionsMap[ DumpId ] = anAction;
359 anAction = new QtxAction(tr("MNU_FITALL"),
360 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_FITALL" ) ),
361 tr( "MNU_FITALL" ), 0, this);
362 anAction->setStatusTip(tr("DSC_FITALL"));
363 connect(anAction, SIGNAL(activated()), this, SLOT(onFitAll()));
364 myActionsMap[ FitAllId ] = anAction;
367 anAction = new QtxAction(tr("MNU_FITRECT"),
368 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_FITAREA" ) ),
369 tr( "MNU_FITRECT" ), 0, this);
370 anAction->setStatusTip(tr("DSC_FITRECT"));
371 connect(anAction, SIGNAL(activated()), this, SLOT(activateWindowFit()));
372 myActionsMap[ FitRectId ] = anAction;
375 anAction = new QtxAction(tr("MNU_ZOOM_VIEW"),
376 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_ZOOM" ) ),
377 tr( "MNU_ZOOM_VIEW" ), 0, this);
378 anAction->setStatusTip(tr("DSC_ZOOM_VIEW"));
379 connect(anAction, SIGNAL(activated()), this, SLOT(activateZoom()));
380 myActionsMap[ ZoomId ] = anAction;
383 anAction = new QtxAction(tr("MNU_PAN_VIEW"),
384 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_PAN" ) ),
385 tr( "MNU_PAN_VIEW" ), 0, this);
386 anAction->setStatusTip(tr("DSC_PAN_VIEW"));
387 connect(anAction, SIGNAL(activated()), this, SLOT(activatePanning()));
388 myActionsMap[ PanId ] = anAction;
391 anAction = new QtxAction(tr("MNU_GLOBALPAN_VIEW"),
392 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_GLOBALPAN" ) ),
393 tr( "MNU_GLOBALPAN_VIEW" ), 0, this);
394 anAction->setStatusTip(tr("DSC_GLOBALPAN_VIEW"));
395 connect(anAction, SIGNAL(activated()), this, SLOT(activateGlobalPanning()));
396 myActionsMap[ GlobalPanId ] = anAction;
399 anAction = new QtxAction(tr("MNU_ROTATE_VIEW"),
400 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_ROTATE" ) ),
401 tr( "MNU_ROTATE_VIEW" ), 0, this);
402 anAction->setStatusTip(tr("DSC_ROTATE_VIEW"));
403 connect(anAction, SIGNAL(activated()), this, SLOT(activateRotation()));
404 myActionsMap[ RotationId ] = anAction;
407 anAction = new QtxAction(tr("MNU_FRONT_VIEW"),
408 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_FRONT" ) ),
409 tr( "MNU_FRONT_VIEW" ), 0, this);
410 anAction->setStatusTip(tr("DSC_FRONT_VIEW"));
411 connect(anAction, SIGNAL(activated()), this, SLOT(onFrontView()));
412 myActionsMap[ FrontId ] = anAction;
414 anAction = new QtxAction(tr("MNU_BACK_VIEW"),
415 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_BACK" ) ),
416 tr( "MNU_BACK_VIEW" ), 0, this);
417 anAction->setStatusTip(tr("DSC_BACK_VIEW"));
418 connect(anAction, SIGNAL(activated()), this, SLOT(onBackView()));
419 myActionsMap[ BackId ] = anAction;
421 anAction = new QtxAction(tr("MNU_TOP_VIEW"),
422 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_TOP" ) ),
423 tr( "MNU_TOP_VIEW" ), 0, this);
424 anAction->setStatusTip(tr("DSC_TOP_VIEW"));
425 connect(anAction, SIGNAL(activated()), this, SLOT(onTopView()));
426 myActionsMap[ TopId ] = anAction;
428 anAction = new QtxAction(tr("MNU_BOTTOM_VIEW"),
429 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_BOTTOM" ) ),
430 tr( "MNU_BOTTOM_VIEW" ), 0, this);
431 anAction->setStatusTip(tr("DSC_BOTTOM_VIEW"));
432 connect(anAction, SIGNAL(activated()), this, SLOT(onBottomView()));
433 myActionsMap[ BottomId ] = anAction;
435 anAction = new QtxAction(tr("MNU_LEFT_VIEW"),
436 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_LEFT" ) ),
437 tr( "MNU_LEFT_VIEW" ), 0, this);
438 anAction->setStatusTip(tr("DSC_LEFT_VIEW"));
439 connect(anAction, SIGNAL(activated()), this, SLOT(onLeftView()));
440 myActionsMap[ LeftId ] = anAction;
442 anAction = new QtxAction(tr("MNU_RIGHT_VIEW"),
443 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_RIGHT" ) ),
444 tr( "MNU_RIGHT_VIEW" ), 0, this);
445 anAction->setStatusTip(tr("DSC_RIGHT_VIEW"));
446 connect(anAction, SIGNAL(activated()), this, SLOT(onRightView()));
447 myActionsMap[ RightId ] = anAction;
450 anAction = new QtxAction(tr("MNU_RESET_VIEW"),
451 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_RESET" ) ),
452 tr( "MNU_RESET_VIEW" ), 0, this);
453 anAction->setStatusTip(tr("DSC_RESET_VIEW"));
454 connect(anAction, SIGNAL(activated()), this, SLOT(onResetView()));
455 myActionsMap[ ResetId ] = anAction;
457 // onViewTrihedron: Shows - Hides Trihedron
458 anAction = new QtxAction(tr("MNU_SHOW_TRIHEDRON"),
459 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_TRIHEDRON" ) ),
460 tr( "MNU_SHOW_TRIHEDRON" ), 0, this);
461 anAction->setStatusTip(tr("DSC_SHOW_TRIHEDRON"));
462 connect(anAction, SIGNAL(activated()), this, SLOT(onViewTrihedron()));
463 myActionsMap[ ViewTrihedronId ] = anAction;
465 // onNonIsometric: Manage non-isometric params
466 anAction = new QtxAction(tr("MNU_SVTK_SCALING"),
467 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_SCALING" ) ),
468 tr( "MNU_SVTK_SCALING" ), 0, this);
469 anAction->setStatusTip(tr("DSC_SVTK_SCALING"));
470 anAction->setToggleAction(true);
471 connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onNonIsometric(bool)));
472 myActionsMap[ NonIsometric ] = anAction;
474 myNonIsometricDlg = new SVTK_NonIsometricDlg(this,"SVTK_NonIsometricDlg",anAction);
476 // onGraduatedAxes: Manage graduated axes params
477 anAction = new QtxAction(tr("MNU_SVTK_GRADUATED_AXES"),
478 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_GRADUATED_AXES" ) ),
479 tr( "MNU_SVTK_GRADUATED_AXES" ), 0, this);
480 anAction->setStatusTip(tr("DSC_SVTK_GRADUATED_AXES"));
481 anAction->setToggleAction(true);
482 connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onGraduatedAxes(bool)));
483 myActionsMap[ GraduatedAxes ] = anAction;
485 myCubeAxesDlg = new SVTK_CubeAxesDlg(this,"SVTK_CubeAxesDlg",anAction);
488 #if defined(WIN32) && !defined(_DEBUG)
489 #pragma optimize( "", on )
492 //----------------------------------------------------------------------------
497 myActionsMap[DumpId]->addTo(myToolBar);
498 myActionsMap[ViewTrihedronId]->addTo(myToolBar);
500 SUIT_ToolButton* aScaleBtn = new SUIT_ToolButton(myToolBar);
501 aScaleBtn->AddAction(myActionsMap[FitAllId]);
502 aScaleBtn->AddAction(myActionsMap[FitRectId]);
503 aScaleBtn->AddAction(myActionsMap[ZoomId]);
505 SUIT_ToolButton* aPanningBtn = new SUIT_ToolButton(myToolBar);
506 aPanningBtn->AddAction(myActionsMap[PanId]);
507 aPanningBtn->AddAction(myActionsMap[GlobalPanId]);
509 myActionsMap[RotationId]->addTo(myToolBar);
511 SUIT_ToolButton* aViewsBtn = new SUIT_ToolButton(myToolBar);
512 aViewsBtn->AddAction(myActionsMap[FrontId]);
513 aViewsBtn->AddAction(myActionsMap[BackId]);
514 aViewsBtn->AddAction(myActionsMap[TopId]);
515 aViewsBtn->AddAction(myActionsMap[BottomId]);
516 aViewsBtn->AddAction(myActionsMap[LeftId]);
517 aViewsBtn->AddAction(myActionsMap[RightId]);
519 myActionsMap[ResetId]->addTo(myToolBar);
521 myActionsMap[NonIsometric]->addTo(myToolBar);
522 myActionsMap[GraduatedAxes]->addTo(myToolBar);
525 //----------------------------------------------------------------------------
530 myEventDispatcher->InvokeEvent(SVTK::StartZoom,0);
533 //----------------------------------------------------------------------------
538 myEventDispatcher->InvokeEvent(SVTK::StartPan,0);
541 //----------------------------------------------------------------------------
546 myEventDispatcher->InvokeEvent(SVTK::StartRotate,0);
549 //----------------------------------------------------------------------------
552 ::activateGlobalPanning()
554 myEventDispatcher->InvokeEvent(SVTK::StartGlobalPan,0);
557 //----------------------------------------------------------------------------
560 ::activateWindowFit()
562 myEventDispatcher->InvokeEvent(SVTK::StartFitArea,0);
565 //----------------------------------------------------------------------------
570 GetRenderer()->OnFrontView();
574 //----------------------------------------------------------------------------
579 GetRenderer()->OnBackView();
583 //----------------------------------------------------------------------------
588 GetRenderer()->OnTopView();
592 //----------------------------------------------------------------------------
597 GetRenderer()->OnBottomView();
601 //----------------------------------------------------------------------------
606 GetRenderer()->OnLeftView();
610 //----------------------------------------------------------------------------
615 GetRenderer()->OnRightView();
619 //----------------------------------------------------------------------------
624 GetRenderer()->OnResetView();
628 //----------------------------------------------------------------------------
633 GetRenderer()->OnFitAll();
637 //----------------------------------------------------------------------------
642 GetRenderer()->OnViewTrihedron();
646 //----------------------------------------------------------------------------
651 GetRenderer()->OnViewCubeAxes();
655 //----------------------------------------------------------------------------
658 ::onNonIsometric(bool theIsActivate)
661 myNonIsometricDlg->Update();
662 myNonIsometricDlg->show();
664 myNonIsometricDlg->hide();
669 ::onGraduatedAxes(bool theIsActivate)
672 myCubeAxesDlg->Update();
673 myCubeAxesDlg->show();
675 myCubeAxesDlg->hide();
678 //----------------------------------------------------------------------------
681 ::onAdjustTrihedron()
683 GetRenderer()->OnAdjustTrihedron();
686 //----------------------------------------------------------------------------
691 GetRenderer()->OnAdjustCubeAxes();
694 //----------------------------------------------------------------------------
699 QPixmap px = QPixmap::grabWindow( GetInteractor()->winId() );
700 return px.convertToImage();