1 // SALOME OBJECT : implementation of interactive object visualization for OCC and VTK viewers
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 "VVTK_MainWindow.h"
30 #include "VVTK_InteractorStyle.h"
31 #include "VVTK_Recorder.h"
32 #include "VVTK_RecorderDlg.h"
33 #include "VISU_WidgetCtrl.hxx"
34 #include "VISU_GaussPtsAct.h"
35 #include "VISU_Event.h"
37 #include "SVTK_ViewWindow.h"
38 #include "SVTK_RenderWindowInteractor.h"
39 #include "VVTK_Renderer.h"
40 #include "VVTK_PickingDlg.h"
41 #include "VVTK_SegmentationCursorDlg.h"
43 #include "SUIT_Application.h"
44 #include "SUIT_Session.h"
45 #include "SUIT_Tools.h"
46 #include "SUIT_ViewWindow.h"
47 #include "SUIT_ResourceMgr.h"
48 #include "SUIT_ToolButton.h"
49 #include "SUIT_Accel.h"
50 #include "SUIT_MessageBox.h"
51 #include "QtxAction.h"
55 #include <qsplitter.h>
56 #include <qfiledialog.h>
57 #include <qapplication.h>
59 //----------------------------------------------------------------------------
61 ::VVTK_MainWindow(QWidget* theParent,
63 SUIT_ResourceMgr* theResourceMgr,
64 SUIT_ViewWindow* theViewWindow):
65 SVTK_MainWindow(theParent,theName,theResourceMgr,theViewWindow),
66 myInteractorStyle(VVTK_InteractorStyle::New()),
67 myControllerIncrement(VVTK_ControllerIncrement::New()),
68 myControllerOnKeyDown(VVTK_ControllerOnKeyDown::New())
70 myInteractorStyle->SetControllerIncrement(myControllerIncrement.GetPointer());
71 myControllerIncrement->Delete();
73 myInteractorStyle->SetControllerOnKeyDown(myControllerOnKeyDown.GetPointer());
74 myControllerOnKeyDown->Delete();
76 myInteractorStyle->Delete();
78 moveDockWindow(myToolBar,Qt::DockLeft);
79 myActionsMap[NonIsometric]->removeFrom(myToolBar);
82 myRecordingToolBar = new QToolBar(this);
83 myRecordingToolBar->setCloseMode(QDockWindow::Undocked);
84 myRecordingToolBar->setLabel(tr("LBL_TOOLBAR_RECORD_LABEL"));
85 moveDockWindow(myRecordingToolBar,Qt::DockLeft);
87 myStartAction = new QtxAction(tr("MNU_VVTK_RECORDING_START"),
88 theResourceMgr->loadPixmap( "VISU", tr( "ICON_VVTK_RECORDING_START" ) ),
89 tr( "MNU_VVTK_RECORDING_START" ), 0, this);
90 myStartAction->setStatusTip(tr("DSC_VVTK_RECORDING_START"));
91 myStartAction->addTo( myRecordingToolBar );
92 connect( myStartAction, SIGNAL( activated() ), this, SLOT( OnStartRecording() ) );
94 myPlayAction = new QtxAction(tr("MNU_VVTK_RECORDING_PLAY"),
95 theResourceMgr->loadPixmap( "VISU", tr( "ICON_VVTK_RECORDING_PLAY" ) ),
96 tr( "MNU_VVTK_RECORDING_PLAY" ), 0, this);
97 myPlayAction->setStatusTip(tr("DSC_VVTK_RECORDING_PLAY"));
98 myPlayAction->setEnabled( false );
99 myPlayAction->addTo( myRecordingToolBar );
100 connect( myPlayAction, SIGNAL( activated() ), this, SLOT( OnPlayRecording() ) );
102 myPauseAction = new QtxAction(tr("MNU_VVTK_RECORDING_PAUSE"),
103 theResourceMgr->loadPixmap( "VISU", tr( "ICON_VVTK_RECORDING_PAUSE" ) ),
104 tr( "MNU_VVTK_RECORDING_PAUSE" ), 0, this);
105 myPauseAction->setStatusTip(tr("DSC_VVTK_RECORDING_PAUSE"));
106 myPauseAction->setEnabled( false );
107 myPauseAction->addTo( myRecordingToolBar );
108 connect( myPauseAction, SIGNAL( activated() ), this, SLOT( OnPauseRecording() ) );
110 myStopAction = new QtxAction(tr("MNU_VVTK_RECORDING_STOP"),
111 theResourceMgr->loadPixmap( "VISU", tr( "ICON_VVTK_RECORDING_STOP" ) ),
112 tr( "MNU_VVTK_RECORDING_STOP" ), 0, this);
113 myStopAction->setStatusTip(tr("DSC_VVTK_RECORDING_STOP"));
114 myStopAction->setEnabled( false );
115 myStopAction->addTo( myRecordingToolBar );
116 connect( myStopAction, SIGNAL( activated() ), this, SLOT( OnStopRecording() ) );
118 myRecorder = VVTK_Recorder::New();
119 //myRecorder->CheckExistAVIMaker();
120 //if(myRecorder->ErrorStatus())
121 // myRecordingToolBar->setEnabled(false);
124 //----------------------------------------------------------------------------
127 ::Initialize(SVTK_RenderWindowInteractor* theInteractor)
129 vtkInteractorStyle* aStyle = theInteractor->GetInteractorStyle();
130 if(SVTK_InteractorStyle *anInteractorStyle = dynamic_cast<SVTK_InteractorStyle*>(aStyle)){
131 anInteractorStyle->SetControllerIncrement(myControllerIncrement.GetPointer());
132 anInteractorStyle->SetControllerOnKeyDown(myControllerOnKeyDown.GetPointer());
135 myRecorder->SetNbFPS(17.3);
136 myRecorder->SetQuality(100);
137 myRecorder->SetProgressiveMode(true);
138 myRecorder->SetUseSkippedFrames(true);
139 myRecorder->SetRenderWindow(theInteractor->getRenderWindow());
141 disconnect( myActionsMap[ DumpId ], SIGNAL( activated() ),
142 myViewWindow, SLOT( onDumpView() ) );
144 connect( myActionsMap[ DumpId ], SIGNAL( activated() ),
145 this, SLOT( onDumpView() ) );
147 SVTK_MainWindow::Initialize(theInteractor);
150 VVTK_MainWindow::~VVTK_MainWindow()
153 myRecorder->Delete();
156 //----------------------------------------------------------------------------
157 void VVTK_MainWindow::onDumpView()
159 QImage img = dumpView();
163 SUIT_Application* app = SUIT_Session::session()->activeApplication();
164 QString fileName = app->getFileName( false, QString::null,
165 tr( "TLT_IMAGE_FILES" ),
166 tr( "TLT_DUMP_VIEW" ), 0 );
167 if( fileName.isEmpty() )
170 QString fmt = SUIT_Tools::extension( fileName ).upper();
172 fmt = QString( "BMP" ); // default format
173 else if( fmt == "JPG" )
176 QApplication::setOverrideCursor( Qt::waitCursor );
177 img.save( fileName, fmt.latin1() );
178 QApplication::restoreOverrideCursor();
181 //----------------------------------------------------------------------------
184 ::OnInteractorStyleSwitch(bool theIsGaussStyleOn)
186 if ( theIsGaussStyleOn )
187 this->PushInteractorStyle(myInteractorStyle.GetPointer());
189 this->PopInteractorStyle();
192 //----------------------------------------------------------------------------
193 void VVTK_MainWindow::OnStartRecording()
195 myRecorder->CheckExistAVIMaker();
196 if (myRecorder->ErrorStatus()) {
197 SUIT_MessageBox::warn1(this, tr("ERROR"), tr("MSG_NO_AVI_MAKER"), tr("&OK"));
200 VVTK_RecorderDlg* aRecorderDlg = new VVTK_RecorderDlg( this, myRecorder );
202 if( !aRecorderDlg->exec() )
205 myStartAction->setEnabled( false );
206 myPlayAction->setEnabled( false );
207 myPauseAction->setEnabled( true );
208 myStopAction->setEnabled( true );
210 myRecorder->Record();
214 //----------------------------------------------------------------------------
215 void VVTK_MainWindow::OnPlayRecording()
217 myStartAction->setEnabled( false );
218 myPlayAction->setEnabled( false );
219 myPauseAction->setEnabled( true );
220 myStopAction->setEnabled( true );
225 //----------------------------------------------------------------------------
226 void VVTK_MainWindow::OnPauseRecording()
228 myStartAction->setEnabled( false );
229 myPlayAction->setEnabled( true );
230 myPauseAction->setEnabled( false );
231 myStopAction->setEnabled( true );
236 //----------------------------------------------------------------------------
237 void VVTK_MainWindow::OnStopRecording()
239 myStartAction->setEnabled( true );
240 myPlayAction->setEnabled( false );
241 myPauseAction->setEnabled( false );
242 myStopAction->setEnabled( false );
247 //----------------------------------------------------------------------------
250 ::action( const int accelAction )
252 if ( accelAction == SUIT_Accel::ZoomFit )
255 int anEvent = SVTK::convertAction( accelAction );
256 InvokeEvent( anEvent, 0 );
260 //----------------------------------------------------------------------------
262 ::VVTK_MainWindow1(QSplitter* theParent,
264 SUIT_ResourceMgr* theResourceMgr,
265 SUIT_ViewWindow* theViewWindow):
266 VVTK_MainWindow(theParent,theName,theResourceMgr,theViewWindow),
267 myStyleSwitchAction(NULL),
268 mySplitter(theParent),
271 myPtsToolBar = new QToolBar(this);
272 myPtsToolBar->setCloseMode(QDockWindow::Undocked);
273 myPtsToolBar->setLabel(tr("LBL_TOOLBAR_GAUSS_LABEL"));
274 moveDockWindow(myPtsToolBar,Qt::DockLeft);
279 aPixmap = theResourceMgr->loadPixmap( "VISU", tr( "ICON_VVTK_INTERACTOR_STYLE_SWITCH" ) );
280 anAction = new QtxAction(tr("MNU_VVTK_INTERACTOR_STYLE_SWITCH"),
282 tr( "MNU_VVTK_INTERACTOR_STYLE_SWITCH" ),
285 "VVTK/SVTK StyleSwitch",
287 anAction->setToggleAction(true);
288 anAction->setStatusTip(tr("DSC_VVTK_INTERACTOR_STYLE_SWITCH"));
290 anAction->addTo( myPtsToolBar );
291 myStyleSwitchAction = anAction;
293 if( theResourceMgr->integerValue( "VISU", "mouse_behaviour", true ) == 1 )
294 myStyleSwitchAction->toggle();
296 aPixmap = theResourceMgr->loadPixmap("VISU",tr("ICON_VVTK_SELECTION_MODE_SWITCH"));
297 myPickingAction = new QtxAction(tr("MNU_VVTK_SELECTION_MODE_SWITCH"),
299 tr( "MNU_VVTK_SELECTION_MODE_SWITCH" ),
302 "VVTK/SVTK SelectionSwitch",
304 myPickingAction->setToggleAction(true);
305 myPickingAction->setStatusTip(tr("DSC_VVTK_SELECTION_MODE_SWITCH"));
306 myPickingAction->addTo( myPtsToolBar );
307 connect(myPickingAction, SIGNAL(toggled(bool)), this, SLOT(OnSelectionModeSwitch(bool)));
309 myPickingDlg = new VVTK_PickingDlg( myPickingAction, this, "PickingDlg" );
311 // Plane/Sphere Segmentation
312 aPixmap = theResourceMgr->loadPixmap("VISU",tr("ICON_VVTK_PLANE_SEGMENTATION_SWITCH"));
313 myPlaneSegmentationAction = new QtxAction(tr("MNU_VVTK_PLANE_SEGMENTATION_SWITCH"),
315 tr( "MNU_VVTK_PLANE_SEGMENTATION_SWITCH" ),
318 "VVTK/SVTK PlaneSegmentationSwitch",
320 myPlaneSegmentationAction->setToggleAction(true);
321 myPlaneSegmentationAction->setStatusTip(tr("DSC_VVTK_PLANE_SEGMENTATION_SWITCH"));
322 //myPlaneSegmentationAction->addTo( myPtsToolBar );
323 connect( myPlaneSegmentationAction, SIGNAL( activated() ), this, SLOT( OnSegmentationSwitch() ) );
325 aPixmap = theResourceMgr->loadPixmap("VISU",tr("ICON_VVTK_SPHERE_SEGMENTATION_SWITCH"));
326 mySphereSegmentationAction = new QtxAction(tr("MNU_VVTK_SPHERE_SEGMENTATION_SWITCH"),
328 tr( "MNU_VVTK_SPHERE_SEGMENTATION_SWITCH" ),
331 "VVTK/SVTK SphereSegmentationSwitch",
333 mySphereSegmentationAction->setToggleAction(true);
334 mySphereSegmentationAction->setStatusTip(tr("DSC_VVTK_SPHERE_SEGMENTATION_SWITCH"));
335 //mySphereSegmentationAction->addTo( myPtsToolBar );
336 connect( mySphereSegmentationAction, SIGNAL( activated() ), this, SLOT( OnSegmentationSwitch() ) );
338 mySegmentationCursorDlg = new VVTK_SegmentationCursorDlg( this, "SegmentationCursorDlg" );
339 mySegmentationCursorDlg->SetPlaneAction( myPlaneSegmentationAction );
340 mySegmentationCursorDlg->SetSphereAction( mySphereSegmentationAction );
341 connect( mySegmentationCursorDlg, SIGNAL( scgClose() ), this, SLOT( OnSegmentationSwitch() ) );
343 SUIT_ToolButton* aSegmentationButton = new SUIT_ToolButton( myPtsToolBar );
344 aSegmentationButton->AddAction( myPlaneSegmentationAction );
345 aSegmentationButton->AddAction( mySphereSegmentationAction );
350 ::Initialize(SVTK_RenderWindowInteractor* theInteractor,
351 VVTK_Renderer1* theRenderer)
353 myRenderer = theRenderer;
354 VVTK_MainWindow::Initialize(theInteractor);
356 if( myStyleSwitchAction->isOn() )
357 PushInteractorStyle(myInteractorStyle.GetPointer());
358 connect(myStyleSwitchAction, SIGNAL(toggled(bool)), this, SLOT(OnInteractorStyleSwitch(bool)));
360 mySegmentationCursorDlg->SetWidgetCtrl( theRenderer->GetWidgetCtrl() );
361 mySegmentationCursorDlg->SetInteractor( theInteractor );
363 connect( theInteractor, SIGNAL( selectionChanged() ), SLOT( OnSelectionChanged() ) );
364 myPickingDlg->SetInteractor( theInteractor );
368 ::~VVTK_MainWindow1()
371 //----------------------------------------------------------------------------
374 ::CreateMainWindow2(QWidget* theParent,
376 SUIT_ResourceMgr* theResourceMgr,
377 SUIT_ViewWindow* theViewWindow)
379 myMainWindow2 = new VVTK_MainWindow2(theParent,
383 myStyleSwitchAction);
384 return myMainWindow2;
388 //----------------------------------------------------------------------------
391 ::OnSelectionModeSwitch(bool theIsSelectionOn)
393 if ( theIsSelectionOn && !isVisible() )
396 Selection_Mode aSelectionMode = SelectionMode();
397 if(theIsSelectionOn && aSelectionMode != GaussPointSelection)
398 SetSelectionMode(GaussPointSelection);
399 else if(!theIsSelectionOn && aSelectionMode == GaussPointSelection)
400 SetSelectionMode(ActorSelection);
402 if( theIsSelectionOn )
404 myPickingDlg->Update();
405 myPickingDlg->show();
408 myPickingDlg->hide();
413 ::OnSelectionChanged()
415 Selection_Mode aSelectionMode = SelectionMode();
416 if(myPickingAction->isOn() && aSelectionMode != GaussPointSelection)
417 myPickingAction->setOn(false);
418 else if(!myPickingAction->isOn() && aSelectionMode == GaussPointSelection)
419 myPickingAction->setOn(true);
423 //----------------------------------------------------------------------------
428 return myRenderer->GetWidgetCtrl();
431 VISU_InsideCursorSettings*
433 ::GetInsideCursorSettings()
435 return mySegmentationCursorDlg->GetInsideCursorSettings();
438 VISU_OutsideCursorSettings*
440 ::GetOutsideCursorSettings()
442 return mySegmentationCursorDlg->GetOutsideCursorSettings();
445 VISU_PickingSettings*
447 ::GetPickingSettings()
449 return myPickingDlg->GetPickingSettings();
452 //----------------------------------------------------------------------------
455 ::SetPlanesSegementation(bool theIsOn)
457 myPlaneSegmentationAction->setOn( theIsOn );
458 OnSegmentationSwitch(myPlaneSegmentationAction);
463 ::SetSphereSegementation(bool theIsOn)
465 mySphereSegmentationAction->setOn( theIsOn );
466 OnSegmentationSwitch(mySphereSegmentationAction);
471 ::OnSegmentationSwitch(QtxAction* theAction)
473 bool anIsSegmentationOn = myPlaneSegmentationAction->isOn() ||
474 mySphereSegmentationAction->isOn();
479 VISU_WidgetCtrl *aWidgetCtrl = myRenderer->GetWidgetCtrl();
481 if (anIsSegmentationOn) {
482 int anIndex = (theAction == myPlaneSegmentationAction) ? 0 : 1;
483 aWidgetCtrl->SetActiveIndex(anIndex);
485 aWidgetCtrl->SetEnabled(anIsSegmentationOn);
487 if( theAction == myPlaneSegmentationAction && anIsSegmentationOn )
488 mySphereSegmentationAction->setOn( false );
489 else if( theAction == mySphereSegmentationAction && anIsSegmentationOn )
490 myPlaneSegmentationAction->setOn( false );
492 if( anIsSegmentationOn )
494 myMainWindow2->show();
495 mySegmentationCursorDlg->SetIsPlaneSegmentation( theAction == myPlaneSegmentationAction );
496 mySegmentationCursorDlg->UpdateSegmentation();
497 mySegmentationCursorDlg->UpdateInsideGaussPoints();
498 mySegmentationCursorDlg->UpdateOutsideGaussPoints();
499 mySegmentationCursorDlg->show();
503 myMainWindow2->hide();
504 mySegmentationCursorDlg->hide();
510 ::OnSegmentationSwitch()
512 QtxAction* anAction = ( QtxAction* )sender();
513 OnSegmentationSwitch(anAction);
517 //----------------------------------------------------------------------------
519 ::VVTK_MainWindow2(QWidget* theParent,
521 SUIT_ResourceMgr* theResourceMgr,
522 SUIT_ViewWindow* theViewWindow,
523 QtxAction* theStyleSwitchAction):
524 VVTK_MainWindow(theParent,theName,theResourceMgr,theViewWindow),
525 myStyleSwitchAction(theStyleSwitchAction)
529 ::~VVTK_MainWindow2()
533 //----------------------------------------------------------------------------
536 ::Initialize(SVTK_RenderWindowInteractor* theInteractor)
538 VVTK_MainWindow::Initialize(theInteractor);
540 if( myStyleSwitchAction->isOn() )
541 PushInteractorStyle(myInteractorStyle.GetPointer());
542 connect(myStyleSwitchAction, SIGNAL(toggled(bool)), this, SLOT(OnInteractorStyleSwitch(bool)));