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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
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_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 bool res = 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_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( this, "PickingDlg" );
305 myPickingDlg->SetAction( myPickingAction );
307 // Plane/Sphere Segmentation
308 aPixmap = theResourceMgr->loadPixmap("VISU",tr("ICON_VVTK_PLANE_SEGMENTATION_SWITCH"));
309 myPlaneSegmentationAction = new QtxAction(tr("MNU_VVTK_PLANE_SEGMENTATION_SWITCH"),
311 tr( "MNU_VVTK_PLANE_SEGMENTATION_SWITCH" ),
314 "VVTK/SVTK PlaneSegmentationSwitch",
316 myPlaneSegmentationAction->setToggleAction(true);
317 myPlaneSegmentationAction->setStatusTip(tr("DSC_VVTK_PLANE_SEGMENTATION_SWITCH"));
318 //myPlaneSegmentationAction->addTo( myPtsToolBar );
319 connect( myPlaneSegmentationAction, SIGNAL( activated() ), this, SLOT( OnSegmentationSwitch() ) );
321 aPixmap = theResourceMgr->loadPixmap("VISU",tr("ICON_VVTK_SPHERE_SEGMENTATION_SWITCH"));
322 mySphereSegmentationAction = new QtxAction(tr("MNU_VVTK_SPHERE_SEGMENTATION_SWITCH"),
324 tr( "MNU_VVTK_SPHERE_SEGMENTATION_SWITCH" ),
327 "VVTK/SVTK SphereSegmentationSwitch",
329 mySphereSegmentationAction->setToggleAction(true);
330 mySphereSegmentationAction->setStatusTip(tr("DSC_VVTK_SPHERE_SEGMENTATION_SWITCH"));
331 //mySphereSegmentationAction->addTo( myPtsToolBar );
332 connect( mySphereSegmentationAction, SIGNAL( activated() ), this, SLOT( OnSegmentationSwitch() ) );
334 mySegmentationCursorDlg = new VVTK_SegmentationCursorDlg( this, "SegmentationCursorDlg" );
335 mySegmentationCursorDlg->SetPlaneAction( myPlaneSegmentationAction );
336 mySegmentationCursorDlg->SetSphereAction( mySphereSegmentationAction );
337 connect( mySegmentationCursorDlg, SIGNAL( scgClose() ), this, SLOT( OnSegmentationSwitch() ) );
339 SUIT_ToolButton* aSegmentationButton = new SUIT_ToolButton( myPtsToolBar );
340 aSegmentationButton->AddAction( myPlaneSegmentationAction );
341 aSegmentationButton->AddAction( mySphereSegmentationAction );
346 ::Initialize(SVTK_RenderWindowInteractor* theInteractor,
347 VVTK_Renderer1* theRenderer)
349 myRenderer = theRenderer;
350 VVTK_MainWindow::Initialize(theInteractor);
352 if( myStyleSwitchAction->isOn() )
353 PushInteractorStyle(myInteractorStyle.GetPointer());
354 connect(myStyleSwitchAction, SIGNAL(toggled(bool)), this, SLOT(OnInteractorStyleSwitch(bool)));
356 mySegmentationCursorDlg->SetWidgetCtrl( theRenderer->GetWidgetCtrl() );
357 mySegmentationCursorDlg->SetInteractor( theInteractor );
359 connect( theInteractor, SIGNAL( selectionChanged() ), SLOT( OnSelectionChanged() ) );
360 myPickingDlg->SetInteractor( theInteractor );
364 ::~VVTK_MainWindow1()
367 //----------------------------------------------------------------------------
370 ::CreateMainWindow2(QWidget* theParent,
372 SUIT_ResourceMgr* theResourceMgr,
373 SUIT_ViewWindow* theViewWindow)
375 myMainWindow2 = new VVTK_MainWindow2(theParent,
379 myStyleSwitchAction);
380 return myMainWindow2;
384 //----------------------------------------------------------------------------
387 ::OnSelectionModeSwitch(bool theIsSelectionOn)
389 Selection_Mode aSelectionMode = SelectionMode();
390 if(theIsSelectionOn && aSelectionMode != GaussPointSelection)
391 SetSelectionMode(GaussPointSelection);
392 else if(!theIsSelectionOn && aSelectionMode == GaussPointSelection)
393 SetSelectionMode(ActorSelection);
395 if( theIsSelectionOn )
397 myPickingDlg->Update();
398 myPickingDlg->show();
401 myPickingDlg->hide();
406 ::OnSelectionChanged()
408 Selection_Mode aSelectionMode = SelectionMode();
409 if(myPickingAction->isOn() && aSelectionMode != GaussPointSelection)
410 myPickingAction->setOn(false);
411 else if(!myPickingAction->isOn() && aSelectionMode == GaussPointSelection)
412 myPickingAction->setOn(true);
416 //----------------------------------------------------------------------------
421 return myRenderer->GetWidgetCtrl();
424 VISU_InsideCursorSettings*
426 ::GetInsideCursorSettings()
428 return mySegmentationCursorDlg->GetInsideCursorSettings();
431 VISU_OutsideCursorSettings*
433 ::GetOutsideCursorSettings()
435 return mySegmentationCursorDlg->GetOutsideCursorSettings();
438 VISU_PickingSettings*
440 ::GetPickingSettings()
442 return myPickingDlg->GetPickingSettings();
445 //----------------------------------------------------------------------------
448 ::SetPlanesSegementation(bool theIsOn)
450 myPlaneSegmentationAction->setOn( theIsOn );
451 OnSegmentationSwitch(myPlaneSegmentationAction);
456 ::SetSphereSegementation(bool theIsOn)
458 mySphereSegmentationAction->setOn( theIsOn );
459 OnSegmentationSwitch(mySphereSegmentationAction);
464 ::OnSegmentationSwitch(QtxAction* theAction)
466 bool anIsSegmentationOn = myPlaneSegmentationAction->isOn() ||
467 mySphereSegmentationAction->isOn();
472 VISU_WidgetCtrl *aWidgetCtrl = myRenderer->GetWidgetCtrl();
474 if (anIsSegmentationOn) {
475 int anIndex = (theAction == myPlaneSegmentationAction) ? 0 : 1;
476 aWidgetCtrl->SetActiveIndex(anIndex);
478 aWidgetCtrl->SetEnabled(anIsSegmentationOn);
480 if( theAction == myPlaneSegmentationAction && anIsSegmentationOn )
481 mySphereSegmentationAction->setOn( false );
482 else if( theAction == mySphereSegmentationAction && anIsSegmentationOn )
483 myPlaneSegmentationAction->setOn( false );
485 if( anIsSegmentationOn )
487 myMainWindow2->show();
488 mySegmentationCursorDlg->SetIsPlaneSegmentation( theAction == myPlaneSegmentationAction );
489 mySegmentationCursorDlg->UpdateSegmentation();
490 mySegmentationCursorDlg->UpdateInsideGaussPoints();
491 mySegmentationCursorDlg->UpdateOutsideGaussPoints();
492 mySegmentationCursorDlg->show();
496 myMainWindow2->hide();
497 mySegmentationCursorDlg->hide();
503 ::OnSegmentationSwitch()
505 QtxAction* anAction = ( QtxAction* )sender();
506 OnSegmentationSwitch(anAction);
510 //----------------------------------------------------------------------------
512 ::VVTK_MainWindow2(QWidget* theParent,
514 SUIT_ResourceMgr* theResourceMgr,
515 SUIT_ViewWindow* theViewWindow,
516 QtxAction* theStyleSwitchAction):
517 VVTK_MainWindow(theParent,theName,theResourceMgr,theViewWindow),
518 myStyleSwitchAction(theStyleSwitchAction)
522 ::~VVTK_MainWindow2()
526 //----------------------------------------------------------------------------
529 ::Initialize(SVTK_RenderWindowInteractor* theInteractor)
531 VVTK_MainWindow::Initialize(theInteractor);
533 if( myStyleSwitchAction->isOn() )
534 PushInteractorStyle(myInteractorStyle.GetPointer());
535 connect(myStyleSwitchAction, SIGNAL(toggled(bool)), this, SLOT(OnInteractorStyleSwitch(bool)));