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_RenderWindowInteractor.h"
38 #include "VVTK_Renderer.h"
39 #include "VVTK_PickingDlg.h"
40 #include "VVTK_SegmentationCursorDlg.h"
42 #include "SUIT_Application.h"
43 #include "SUIT_Session.h"
44 #include "SUIT_Tools.h"
45 #include "SUIT_ViewWindow.h"
46 #include "SUIT_ResourceMgr.h"
47 #include "SUIT_ToolButton.h"
48 #include "SUIT_Accel.h"
49 #include "QtxAction.h"
53 #include <qsplitter.h>
54 #include <qfiledialog.h>
55 #include <qapplication.h>
57 //----------------------------------------------------------------------------
59 ::VVTK_MainWindow(QWidget* theParent,
61 SUIT_ResourceMgr* theResourceMgr,
62 SUIT_ViewWindow* theViewWindow):
63 SVTK_MainWindow(theParent,theName,theResourceMgr,theViewWindow),
64 myInteractorStyle(VVTK_InteractorStyle::New()),
65 myControllerIncrement(VVTK_ControllerIncrement::New()),
66 myControllerOnKeyDown(VVTK_ControllerOnKeyDown::New())
68 myInteractorStyle->SetControllerIncrement(myControllerIncrement.GetPointer());
69 myControllerIncrement->Delete();
71 myInteractorStyle->SetControllerOnKeyDown(myControllerOnKeyDown.GetPointer());
72 myControllerOnKeyDown->Delete();
74 myInteractorStyle->Delete();
76 moveDockWindow(myToolBar,Qt::DockLeft);
77 myActionsMap[NonIsometric]->removeFrom(myToolBar);
80 myRecordingToolBar = new QToolBar(this);
81 myRecordingToolBar->setCloseMode(QDockWindow::Undocked);
82 myRecordingToolBar->setLabel(tr("LBL_TOOLBAR_RECORD_LABEL"));
83 moveDockWindow(myRecordingToolBar,Qt::DockLeft);
85 myStartAction = new QtxAction(tr("MNU_VVTK_RECORDING_START"),
86 theResourceMgr->loadPixmap( "VISU", tr( "ICON_VVTK_RECORDING_START" ) ),
87 tr( "MNU_VVTK_RECORDING_START" ), 0, this);
88 myStartAction->setStatusTip(tr("DSC_VVTK_RECORDING_START"));
89 myStartAction->addTo( myRecordingToolBar );
90 connect( myStartAction, SIGNAL( activated() ), this, SLOT( OnStartRecording() ) );
92 myPlayAction = new QtxAction(tr("MNU_VVTK_RECORDING_PLAY"),
93 theResourceMgr->loadPixmap( "VISU", tr( "ICON_VVTK_RECORDING_PLAY" ) ),
94 tr( "MNU_VVTK_RECORDING_PLAY" ), 0, this);
95 myPlayAction->setStatusTip(tr("DSC_VVTK_RECORDING_PLAY"));
96 myPlayAction->setEnabled( false );
97 myPlayAction->addTo( myRecordingToolBar );
98 connect( myPlayAction, SIGNAL( activated() ), this, SLOT( OnPlayRecording() ) );
100 myPauseAction = new QtxAction(tr("MNU_VVTK_RECORDING_PAUSE"),
101 theResourceMgr->loadPixmap( "VISU", tr( "ICON_VVTK_RECORDING_PAUSE" ) ),
102 tr( "MNU_VVTK_RECORDING_PAUSE" ), 0, this);
103 myPauseAction->setStatusTip(tr("DSC_VVTK_RECORDING_PAUSE"));
104 myPauseAction->setEnabled( false );
105 myPauseAction->addTo( myRecordingToolBar );
106 connect( myPauseAction, SIGNAL( activated() ), this, SLOT( OnPauseRecording() ) );
108 myStopAction = new QtxAction(tr("MNU_VVTK_RECORDING_STOP"),
109 theResourceMgr->loadPixmap( "VISU", tr( "ICON_VVTK_RECORDING_STOP" ) ),
110 tr( "MNU_VVTK_RECORDING_STOP" ), 0, this);
111 myStopAction->setStatusTip(tr("DSC_VVTK_RECORDING_STOP"));
112 myStopAction->setEnabled( false );
113 myStopAction->addTo( myRecordingToolBar );
114 connect( myStopAction, SIGNAL( activated() ), this, SLOT( OnStopRecording() ) );
116 myRecorder = VVTK_Recorder::New();
117 myRecorder->CheckExistAVIMaker();
118 if(myRecorder->ErrorStatus())
119 myRecordingToolBar->setEnabled(false);
122 //----------------------------------------------------------------------------
125 ::Initialize(SVTK_RenderWindowInteractor* theInteractor)
127 vtkInteractorStyle* aStyle = theInteractor->GetInteractorStyle();
128 if(SVTK_InteractorStyle *anInteractorStyle = dynamic_cast<SVTK_InteractorStyle*>(aStyle)){
129 anInteractorStyle->SetControllerIncrement(myControllerIncrement.GetPointer());
130 anInteractorStyle->SetControllerOnKeyDown(myControllerOnKeyDown.GetPointer());
133 myRecorder->SetNbFPS(17.3);
134 myRecorder->SetQuality(100);
135 myRecorder->SetProgressiveMode(true);
136 myRecorder->SetUseSkippedFrames(true);
137 myRecorder->SetRenderWindow(theInteractor->getRenderWindow());
139 disconnect( myActionsMap[ DumpId ], SIGNAL( activated() ),
140 myViewWindow, SLOT( onDumpView() ) );
142 connect( myActionsMap[ DumpId ], SIGNAL( activated() ),
143 this, SLOT( onDumpView() ) );
145 SVTK_MainWindow::Initialize(theInteractor);
148 VVTK_MainWindow::~VVTK_MainWindow()
151 myRecorder->Delete();
154 //----------------------------------------------------------------------------
155 void VVTK_MainWindow::onDumpView()
157 SUIT_Application* app = SUIT_Session::session()->activeApplication();
158 QString fileName = app->getFileName( false, QString::null,
159 tr( "TLT_IMAGE_FILES" ),
160 tr( "TLT_DUMP_VIEW" ), 0 );
161 if( fileName.isEmpty() )
164 QImage img = dumpView();
168 QString fmt = SUIT_Tools::extension( fileName ).upper();
170 fmt = QString( "BMP" ); // default format
171 else if( fmt == "JPG" )
174 QApplication::setOverrideCursor( Qt::waitCursor );
175 img.save( fileName, fmt.latin1() );
176 QApplication::restoreOverrideCursor();
179 //----------------------------------------------------------------------------
182 ::OnInteractorStyleSwitch(bool theIsGaussStyleOn)
184 if ( theIsGaussStyleOn )
185 this->PushInteractorStyle(myInteractorStyle.GetPointer());
187 this->PopInteractorStyle();
190 //----------------------------------------------------------------------------
191 void VVTK_MainWindow::OnStartRecording()
193 VVTK_RecorderDlg* aRecorderDlg = new VVTK_RecorderDlg( this, myRecorder );
195 if( !aRecorderDlg->exec() )
198 myStartAction->setEnabled( false );
199 myPlayAction->setEnabled( false );
200 myPauseAction->setEnabled( true );
201 myStopAction->setEnabled( true );
203 myRecorder->Record();
206 //----------------------------------------------------------------------------
207 void VVTK_MainWindow::OnPlayRecording()
209 myStartAction->setEnabled( false );
210 myPlayAction->setEnabled( false );
211 myPauseAction->setEnabled( true );
212 myStopAction->setEnabled( true );
217 //----------------------------------------------------------------------------
218 void VVTK_MainWindow::OnPauseRecording()
220 myStartAction->setEnabled( false );
221 myPlayAction->setEnabled( true );
222 myPauseAction->setEnabled( false );
223 myStopAction->setEnabled( true );
228 //----------------------------------------------------------------------------
229 void VVTK_MainWindow::OnStopRecording()
231 myStartAction->setEnabled( true );
232 myPlayAction->setEnabled( false );
233 myPauseAction->setEnabled( false );
234 myStopAction->setEnabled( false );
239 //----------------------------------------------------------------------------
241 convertAction( const int accelAction );
245 ::action( const int accelAction )
247 if ( accelAction == SUIT_Accel::ZoomFit )
250 int anEvent = convertAction( accelAction );
251 InvokeEvent( anEvent, 0 );
255 //----------------------------------------------------------------------------
257 ::VVTK_MainWindow1(QSplitter* theParent,
259 SUIT_ResourceMgr* theResourceMgr,
260 SUIT_ViewWindow* theViewWindow):
261 VVTK_MainWindow(theParent,theName,theResourceMgr,theViewWindow),
262 myStyleSwitchAction(NULL),
263 mySplitter(theParent),
266 myPtsToolBar = new QToolBar(this);
267 myPtsToolBar->setCloseMode(QDockWindow::Undocked);
268 myPtsToolBar->setLabel(tr("LBL_TOOLBAR_GAUSS_LABEL"));
269 moveDockWindow(myPtsToolBar,Qt::DockLeft);
274 aPixmap = theResourceMgr->loadPixmap( "VISU", tr( "ICON_VVTK_INTERACTOR_STYLE_SWITCH" ) );
275 anAction = new QtxAction(tr("MNU_VVTK_INTERACTOR_STYLE_SWITCH"),
277 tr( "MNU_VVTK_INTERACTOR_STYLE_SWITCH" ),
280 "VVTK/SVTK StyleSwitch",
282 anAction->setToggleAction(true);
283 anAction->setStatusTip(tr("DSC_VVTK_INTERACTOR_STYLE_SWITCH"));
285 anAction->addTo( myPtsToolBar );
286 myStyleSwitchAction = anAction;
288 if( theResourceMgr->integerValue( "VISU", "mouse_behaviour", true ) == 1 )
289 myStyleSwitchAction->toggle();
291 aPixmap = theResourceMgr->loadPixmap("VISU",tr("ICON_VVTK_SELECTION_MODE_SWITCH"));
292 myPickingAction = new QtxAction(tr("MNU_VVTK_SELECTION_MODE_SWITCH"),
294 tr( "MNU_VVTK_SELECTION_MODE_SWITCH" ),
297 "VVTK/SVTK SelectionSwitch",
299 myPickingAction->setToggleAction(true);
300 myPickingAction->setStatusTip(tr("DSC_VVTK_SELECTION_MODE_SWITCH"));
301 myPickingAction->addTo( myPtsToolBar );
302 connect(myPickingAction, SIGNAL(toggled(bool)), this, SLOT(OnSelectionModeSwitch(bool)));
304 myPickingDlg = new VVTK_PickingDlg( myPickingAction, this, "PickingDlg" );
306 // Plane/Sphere Segmentation
307 aPixmap = theResourceMgr->loadPixmap("VISU",tr("ICON_VVTK_PLANE_SEGMENTATION_SWITCH"));
308 myPlaneSegmentationAction = new QtxAction(tr("MNU_VVTK_PLANE_SEGMENTATION_SWITCH"),
310 tr( "MNU_VVTK_PLANE_SEGMENTATION_SWITCH" ),
313 "VVTK/SVTK PlaneSegmentationSwitch",
315 myPlaneSegmentationAction->setToggleAction(true);
316 myPlaneSegmentationAction->setStatusTip(tr("DSC_VVTK_PLANE_SEGMENTATION_SWITCH"));
317 //myPlaneSegmentationAction->addTo( myPtsToolBar );
318 connect( myPlaneSegmentationAction, SIGNAL( activated() ), this, SLOT( OnSegmentationSwitch() ) );
320 aPixmap = theResourceMgr->loadPixmap("VISU",tr("ICON_VVTK_SPHERE_SEGMENTATION_SWITCH"));
321 mySphereSegmentationAction = new QtxAction(tr("MNU_VVTK_SPHERE_SEGMENTATION_SWITCH"),
323 tr( "MNU_VVTK_SPHERE_SEGMENTATION_SWITCH" ),
326 "VVTK/SVTK SphereSegmentationSwitch",
328 mySphereSegmentationAction->setToggleAction(true);
329 mySphereSegmentationAction->setStatusTip(tr("DSC_VVTK_SPHERE_SEGMENTATION_SWITCH"));
330 //mySphereSegmentationAction->addTo( myPtsToolBar );
331 connect( mySphereSegmentationAction, SIGNAL( activated() ), this, SLOT( OnSegmentationSwitch() ) );
333 mySegmentationCursorDlg = new VVTK_SegmentationCursorDlg( this, "SegmentationCursorDlg" );
334 mySegmentationCursorDlg->SetPlaneAction( myPlaneSegmentationAction );
335 mySegmentationCursorDlg->SetSphereAction( mySphereSegmentationAction );
336 connect( mySegmentationCursorDlg, SIGNAL( scgClose() ), this, SLOT( OnSegmentationSwitch() ) );
338 SUIT_ToolButton* aSegmentationButton = new SUIT_ToolButton( myPtsToolBar );
339 aSegmentationButton->AddAction( myPlaneSegmentationAction );
340 aSegmentationButton->AddAction( mySphereSegmentationAction );
345 ::Initialize(SVTK_RenderWindowInteractor* theInteractor,
346 VVTK_Renderer1* theRenderer)
348 myRenderer = theRenderer;
349 VVTK_MainWindow::Initialize(theInteractor);
351 if( myStyleSwitchAction->isOn() )
352 PushInteractorStyle(myInteractorStyle.GetPointer());
353 connect(myStyleSwitchAction, SIGNAL(toggled(bool)), this, SLOT(OnInteractorStyleSwitch(bool)));
355 mySegmentationCursorDlg->SetWidgetCtrl( theRenderer->GetWidgetCtrl() );
356 mySegmentationCursorDlg->SetInteractor( theInteractor );
358 connect( theInteractor, SIGNAL( selectionChanged() ), SLOT( OnSelectionChanged() ) );
359 myPickingDlg->SetInteractor( theInteractor );
363 ::~VVTK_MainWindow1()
366 //----------------------------------------------------------------------------
369 ::CreateMainWindow2(QWidget* theParent,
371 SUIT_ResourceMgr* theResourceMgr,
372 SUIT_ViewWindow* theViewWindow)
374 myMainWindow2 = new VVTK_MainWindow2(theParent,
378 myStyleSwitchAction);
379 return myMainWindow2;
383 //----------------------------------------------------------------------------
386 ::OnSelectionModeSwitch(bool theIsSelectionOn)
388 if ( theIsSelectionOn && !isVisible() )
391 Selection_Mode aSelectionMode = SelectionMode();
392 if(theIsSelectionOn && aSelectionMode != GaussPointSelection)
393 SetSelectionMode(GaussPointSelection);
394 else if(!theIsSelectionOn && aSelectionMode == GaussPointSelection)
395 SetSelectionMode(ActorSelection);
397 if( theIsSelectionOn )
399 myPickingDlg->Update();
400 myPickingDlg->show();
403 myPickingDlg->hide();
408 ::OnSelectionChanged()
410 Selection_Mode aSelectionMode = SelectionMode();
411 if(myPickingAction->isOn() && aSelectionMode != GaussPointSelection)
412 myPickingAction->setOn(false);
413 else if(!myPickingAction->isOn() && aSelectionMode == GaussPointSelection)
414 myPickingAction->setOn(true);
418 //----------------------------------------------------------------------------
423 return myRenderer->GetWidgetCtrl();
426 VISU_InsideCursorSettings*
428 ::GetInsideCursorSettings()
430 return mySegmentationCursorDlg->GetInsideCursorSettings();
433 VISU_OutsideCursorSettings*
435 ::GetOutsideCursorSettings()
437 return mySegmentationCursorDlg->GetOutsideCursorSettings();
440 VISU_PickingSettings*
442 ::GetPickingSettings()
444 return myPickingDlg->GetPickingSettings();
447 //----------------------------------------------------------------------------
450 ::SetPlanesSegementation(bool theIsOn)
452 myPlaneSegmentationAction->setOn( theIsOn );
453 OnSegmentationSwitch(myPlaneSegmentationAction);
458 ::SetSphereSegementation(bool theIsOn)
460 mySphereSegmentationAction->setOn( theIsOn );
461 OnSegmentationSwitch(mySphereSegmentationAction);
466 ::OnSegmentationSwitch(QtxAction* theAction)
468 bool anIsSegmentationOn = myPlaneSegmentationAction->isOn() ||
469 mySphereSegmentationAction->isOn();
474 VISU_WidgetCtrl *aWidgetCtrl = myRenderer->GetWidgetCtrl();
476 if (anIsSegmentationOn) {
477 int anIndex = (theAction == myPlaneSegmentationAction) ? 0 : 1;
478 aWidgetCtrl->SetActiveIndex(anIndex);
480 aWidgetCtrl->SetEnabled(anIsSegmentationOn);
482 if( theAction == myPlaneSegmentationAction && anIsSegmentationOn )
483 mySphereSegmentationAction->setOn( false );
484 else if( theAction == mySphereSegmentationAction && anIsSegmentationOn )
485 myPlaneSegmentationAction->setOn( false );
487 if( anIsSegmentationOn )
489 myMainWindow2->show();
490 mySegmentationCursorDlg->SetIsPlaneSegmentation( theAction == myPlaneSegmentationAction );
491 mySegmentationCursorDlg->UpdateSegmentation();
492 mySegmentationCursorDlg->UpdateInsideGaussPoints();
493 mySegmentationCursorDlg->UpdateOutsideGaussPoints();
494 mySegmentationCursorDlg->show();
498 myMainWindow2->hide();
499 mySegmentationCursorDlg->hide();
505 ::OnSegmentationSwitch()
507 QtxAction* anAction = ( QtxAction* )sender();
508 OnSegmentationSwitch(anAction);
512 //----------------------------------------------------------------------------
514 ::VVTK_MainWindow2(QWidget* theParent,
516 SUIT_ResourceMgr* theResourceMgr,
517 SUIT_ViewWindow* theViewWindow,
518 QtxAction* theStyleSwitchAction):
519 VVTK_MainWindow(theParent,theName,theResourceMgr,theViewWindow),
520 myStyleSwitchAction(theStyleSwitchAction)
524 ::~VVTK_MainWindow2()
528 //----------------------------------------------------------------------------
531 ::Initialize(SVTK_RenderWindowInteractor* theInteractor)
533 VVTK_MainWindow::Initialize(theInteractor);
535 if( myStyleSwitchAction->isOn() )
536 PushInteractorStyle(myInteractorStyle.GetPointer());
537 connect(myStyleSwitchAction, SIGNAL(toggled(bool)), this, SLOT(OnInteractorStyleSwitch(bool)));