1 // Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/
19 #include <qpopupmenu.h>
\r
20 #include <qcolordialog.h>
\r
22 #include <vtkCamera.h>
\r
23 #include <vtkRenderer.h>
\r
24 #include <vtkActorCollection.h>
\r
26 #include "SUIT_Session.h"
\r
28 #include "SVTK_Selection.h"
\r
29 #include "SVTK_ViewModel.h"
\r
30 #include "SVTK_ViewWindow.h"
\r
31 #include "SVTK_Prs.h"
\r
33 #include "VTKViewer_ViewModel.h"
\r
35 #include "SVTK_RenderWindowInteractor.h"
\r
36 #include "SVTK_RenderWindow.h"
\r
38 //#include <ToolsGUI.h>
\r
40 #include <SALOME_Actor.h>
\r
41 #include <SALOME_InteractiveObject.hxx>
\r
43 // Temporarily commented to avoid awful dependecy on SALOMEDS
\r
44 // TODO: better mechanism of storing display/erse status in a study
\r
45 // should be provided...
\r
46 //#include "Utils_ORB_INIT.hxx"
\r
47 //#include "Utils_SINGLETON.hxx"
\r
48 //#include "SALOME_ModuleCatalog_impl.hxx"
\r
49 //#include "SALOME_NamingService.hxx"
\r
51 //#include "SALOMEDSClient.hxx"
\r
52 //#include "SALOMEDS_StudyManager.hxx"
\r
54 // in order NOT TO link with SalomeApp, here the code returns SALOMEDS_Study.
\r
55 // SalomeApp_Study::studyDS() does it as well, but -- here it is retrieved from
\r
56 // SALOMEDS::StudyManager - no linkage with SalomeApp.
\r
58 // Temporarily commented to avoid awful dependecy on SALOMEDS
\r
59 // TODO: better mechanism of storing display/erse status in a study
\r
60 // should be provided...
\r
61 //static _PTR(Study) getStudyDS()
\r
63 // SALOMEDSClient_Study* aStudy = NULL;
\r
64 // _PTR(StudyManager) aMgr( new SALOMEDS_StudyManager() );
\r
65 // get id of SUIT_Study, if it's a SalomeApp_Study, it will return
\r
66 // id of its underlying SALOMEDS::Study
\r
67 // SUIT_Application* app = SUIT_Session::session()->activeApplication();
\r
68 // if ( !app ) return _PTR(Study)(aStudy);
\r
69 // SUIT_Study* stud = app->activeStudy();
\r
70 // if ( !stud ) return _PTR(Study)(aStudy);
\r
71 // const int id = stud->id(); // virtual method, must return SALOMEDS_Study id
\r
72 // get SALOMEDS_Study with this id from StudyMgr
\r
73 // return aMgr->GetStudyByID( id );
\r
76 //==========================================================
\r
77 SVTK_Viewer::SVTK_Viewer()
\r
79 myTrihedronSize = 100;
\r
82 //==========================================================
\r
83 SVTK_Viewer::~SVTK_Viewer()
\r
87 QColor SVTK_Viewer::backgroundColor() const
\r
92 void SVTK_Viewer::setBackgroundColor( const QColor& c )
\r
98 //==========================================================
\r
99 SUIT_ViewWindow* SVTK_Viewer::createView( SUIT_Desktop* theDesktop )
\r
101 SVTK_ViewWindow* vw = new SVTK_ViewWindow( theDesktop, this );
\r
102 vw->setBackgroundColor( backgroundColor() );
\r
103 vw->SetTrihedronSize( trihedronSize() );
\r
107 int SVTK_Viewer::trihedronSize() const
\r
109 return myTrihedronSize;
\r
112 void SVTK_Viewer::setTrihedronSize( const int sz )
\r
114 myTrihedronSize = sz;
\r
116 SUIT_ViewManager* vm = getViewManager();
\r
120 QPtrVector<SUIT_ViewWindow> vec = vm->getViews();
\r
121 for ( int i = 0; i < vec.count(); i++ )
\r
123 SUIT_ViewWindow* win = vec.at( i );
\r
124 if ( !win || !win->inherits( "SVTK_ViewWindow" ) )
\r
127 SVTK_ViewWindow* vw = (SVTK_ViewWindow*)win;
\r
128 vw->SetTrihedronSize( sz );
\r
132 //==========================================================
\r
133 void SVTK_Viewer::setViewManager(SUIT_ViewManager* theViewManager)
\r
135 SUIT_ViewModel::setViewManager(theViewManager);
\r
137 if ( !theViewManager )
\r
140 connect(theViewManager, SIGNAL(mousePress(SUIT_ViewWindow*, QMouseEvent*)),
\r
141 this, SLOT(onMousePress(SUIT_ViewWindow*, QMouseEvent*)));
\r
143 connect(theViewManager, SIGNAL(mouseMove(SUIT_ViewWindow*, QMouseEvent*)),
\r
144 this, SLOT(onMouseMove(SUIT_ViewWindow*, QMouseEvent*)));
\r
146 connect(theViewManager, SIGNAL(mouseRelease(SUIT_ViewWindow*, QMouseEvent*)),
\r
147 this, SLOT(onMouseRelease(SUIT_ViewWindow*, QMouseEvent*)));
\r
150 //==========================================================
\r
151 void SVTK_Viewer::contextMenuPopup( QPopupMenu* thePopup )
\r
153 thePopup->insertItem( VTKViewer_Viewer::tr( "MEN_DUMP_VIEW" ), this, SLOT( onDumpView() ) );
\r
154 thePopup->insertItem( VTKViewer_Viewer::tr( "MEN_CHANGE_BACKGROUD" ), this, SLOT( onChangeBgColor() ) );
\r
156 thePopup->insertSeparator();
\r
158 SVTK_ViewWindow* aView = (SVTK_ViewWindow*)(myViewManager->getActiveView());
\r
159 if ( aView && !aView->getToolBar()->isVisible() )
\r
160 thePopup->insertItem( VTKViewer_Viewer::tr( "MEN_SHOW_TOOLBAR" ), this, SLOT( onShowToolbar() ) );
\r
163 //==========================================================
\r
164 void SVTK_Viewer::onMousePress(SUIT_ViewWindow* vw, QMouseEvent* event)
\r
166 if(SVTK_ViewWindow* aVW = dynamic_cast<SVTK_ViewWindow*>(vw)){
\r
167 if(SVTK_RenderWindowInteractor* aRWI = aVW->getRWInteractor()){
\r
168 switch(event->button()) {
\r
170 aRWI->LeftButtonPressed(event) ;
\r
173 aRWI->MiddleButtonPressed(event) ;
\r
176 aRWI->RightButtonPressed(event) ;
\r
185 //==========================================================
\r
188 ::onMouseMove(SUIT_ViewWindow* vw, QMouseEvent* event)
\r
190 if(SVTK_ViewWindow* aVW = dynamic_cast<SVTK_ViewWindow*>(vw)){
\r
191 if(SVTK_RenderWindowInteractor* aRWI = aVW->getRWInteractor()){
\r
192 aRWI->MouseMove( event );
\r
197 //==========================================================
\r
200 ::onMouseRelease(SUIT_ViewWindow* vw, QMouseEvent* event)
\r
202 if(SVTK_ViewWindow* aVW = dynamic_cast<SVTK_ViewWindow*>(vw)){
\r
203 if(SVTK_RenderWindowInteractor* aRWI = aVW->getRWInteractor()){
\r
204 switch(event->button()) {
\r
206 aRWI->LeftButtonReleased(event) ;
\r
209 aRWI->MiddleButtonReleased(event) ;
\r
212 aRWI->RightButtonReleased(event) ;
\r
221 //==========================================================
\r
224 ::enableSelection(bool isEnabled)
\r
226 mySelectionEnabled = isEnabled;
\r
227 //!! To be done for view windows
\r
230 //==========================================================
\r
233 ::enableMultiselection(bool isEnable)
\r
235 myMultiSelectionEnabled = isEnable;
\r
236 //!! To be done for view windows
\r
239 void SVTK_Viewer::onDumpView()
\r
241 SVTK_ViewWindow* aView = (SVTK_ViewWindow*)(myViewManager->getActiveView());
\r
243 aView->onDumpView();
\r
246 //==========================================================
\r
247 void SVTK_Viewer::onChangeBgColor()
\r
249 QPtrVector<SUIT_ViewWindow> aViews = myViewManager->getViews();
\r
250 for(int i = 0, iEnd = aViews.size(); i < iEnd; i++)
\r
251 if(SUIT_ViewWindow* aViewWindow = aViews.at(i))
\r
252 if(SVTK_ViewWindow* aView = dynamic_cast<SVTK_ViewWindow*>(aViewWindow)){
\r
253 QColor aColor = QColorDialog::getColor( aView->backgroundColor(), aView);
\r
254 if ( aColor.isValid() )
\r
255 aView->setBackgroundColor(aColor);
\r
259 //==========================================================
\r
264 QPtrVector<SUIT_ViewWindow> aViews = myViewManager->getViews();
\r
265 for(int i = 0, iEnd = aViews.size(); i < iEnd; i++)
\r
266 if(SUIT_ViewWindow* aViewWindow = aViews.at(i))
\r
267 if(SVTK_ViewWindow* aView = dynamic_cast<SVTK_ViewWindow*>(aViewWindow))
\r
268 aView->getToolBar()->show();
\r
271 //==========================================================
\r
274 ::Display( const SALOME_VTKPrs* prs )
\r
276 // try do downcast object
\r
277 if(const SVTK_Prs* aPrs = dynamic_cast<const SVTK_Prs*>( prs )){
\r
280 if(vtkActorCollection* anActorCollection = aPrs->GetObjects()){
\r
281 // get SALOMEDS Study
\r
282 // Temporarily commented to avoid awful dependecy on SALOMEDS
\r
283 // TODO: better mechanism of storing display/erse status in a study
\r
284 // should be provided...
\r
285 // _PTR(Study) aStudy(getStudyDS());
\r
286 anActorCollection->InitTraversal();
\r
287 while(vtkActor* anActor = anActorCollection->GetNextActor()){
\r
288 if(SALOME_Actor* anAct = SALOME_Actor::SafeDownCast(anActor)){
\r
289 // Set visibility flag
\r
290 // Temporarily commented to avoid awful dependecy on SALOMEDS
\r
291 // TODO: better mechanism of storing display/erse status in a study
\r
292 // should be provided...
\r
293 //Handle(SALOME_InteractiveObject) anObj = anAct->getIO();
\r
294 //if(!anObj.IsNull() && anObj->hasEntry() && aStudy){
\r
295 // ToolsGUI::SetVisibility(aStudy,anObj->getEntry(),true,this);
\r
297 // just display the object
\r
298 QPtrVector<SUIT_ViewWindow> aViews = myViewManager->getViews();
\r
299 for(int i = 0, iEnd = aViews.size(); i < iEnd; i++){
\r
300 if(SUIT_ViewWindow* aViewWindow = aViews.at(i)){
\r
301 if(SVTK_ViewWindow* aView = dynamic_cast<SVTK_ViewWindow*>(aViewWindow)){
\r
302 if(SVTK_RenderWindowInteractor* aRWI = aView->getRWInteractor()){
\r
303 aRWI->Display(anAct,false);
\r
304 if(anAct->IsSetCamera()){
\r
305 vtkRenderer* aRenderer = aView->getRenderer();
\r
306 anAct->SetCamera( aRenderer->GetActiveCamera() );
\r
318 //==========================================================
\r
321 ::Erase( const SALOME_VTKPrs* prs, const bool forced )
\r
323 // try do downcast object
\r
324 if(const SVTK_Prs* aPrs = dynamic_cast<const SVTK_Prs*>( prs )){
\r
327 if(vtkActorCollection* anActorCollection = aPrs->GetObjects()){
\r
328 // get SALOMEDS Study
\r
329 // Temporarily commented to avoid awful dependecy on SALOMEDS
\r
330 // TODO: better mechanism of storing display/erse status in a study
\r
331 // should be provided...
\r
332 //_PTR(Study) aStudy(getStudyDS());
\r
333 anActorCollection->InitTraversal();
\r
334 while(vtkActor* anActor = anActorCollection->GetNextActor())
\r
335 if(SALOME_Actor* anAct = SALOME_Actor::SafeDownCast(anActor)){
\r
336 // Set visibility flag
\r
337 // Temporarily commented to avoid awful dependecy on SALOMEDS
\r
338 // TODO: better mechanism of storing display/erse status in a study
\r
339 // should be provided...
\r
340 //Handle(SALOME_InteractiveObject) anObj = anAct->getIO();
\r
341 //if(!anObj.IsNull() && anObj->hasEntry() && aStudy){
\r
342 // ToolsGUI::SetVisibility(aStudy,anObj->getEntry(),false,this);
\r
344 // just display the object
\r
345 QPtrVector<SUIT_ViewWindow> aViews = myViewManager->getViews();
\r
346 for(int i = 0, iEnd = aViews.size(); i < iEnd; i++){
\r
347 if(SUIT_ViewWindow* aViewWindow = aViews.at(i))
\r
348 if(SVTK_ViewWindow* aView = dynamic_cast<SVTK_ViewWindow*>(aViewWindow))
\r
349 if(SVTK_RenderWindowInteractor* aRWI = aView->getRWInteractor())
\r
351 aRWI->Remove(anAct,false);
\r
353 aRWI->Erase(anAct,forced);
\r
360 //==========================================================
\r
363 ::EraseAll( const bool forced )
\r
365 // Temporarily commented to avoid awful dependecy on SALOMEDS
\r
366 // TODO: better mechanism of storing display/erse status in a study
\r
367 // should be provided...
\r
368 //_PTR(Study) aStudy(getStudyDS());
\r
369 QPtrVector<SUIT_ViewWindow> aViews = myViewManager->getViews();
\r
370 for(int i = 0, iEnd = aViews.size(); i < iEnd; i++){
\r
371 if(SUIT_ViewWindow* aViewWindow = aViews.at(i)){
\r
372 if(SVTK_ViewWindow* aView = dynamic_cast<SVTK_ViewWindow*>(aViewWindow)){
\r
373 vtkRenderer* aRenderer = aView->getRenderer();
\r
374 vtkActorCollection* anActorCollection = aRenderer->GetActors();
\r
375 anActorCollection->InitTraversal();
\r
376 while(vtkActor* anActor = anActorCollection->GetNextActor()){
\r
377 if(SALOME_Actor* anAct = SALOME_Actor::SafeDownCast(anActor)){
\r
378 // Set visibility flag
\r
379 // Temporarily commented to avoid awful dependecy on SALOMEDS
\r
380 // TODO: better mechanism of storing display/erse status in a study
\r
381 // should be provided...
\r
382 //Handle(SALOME_InteractiveObject) anObj = anAct->getIO();
\r
383 //if(!anObj.IsNull() && anObj->hasEntry() && aStudy)
\r
384 // ToolsGUI::SetVisibility(aStudy,anObj->getEntry(),false,this);
\r
386 aRenderer->RemoveActor(anAct);
\r
388 // just erase actor
\r
389 anAct->SetVisibility( false );
\r
390 // erase dependent actors
\r
391 vtkActorCollection* aCollection = vtkActorCollection::New();
\r
392 anAct->GetChildActors( aCollection );
\r
393 aCollection->InitTraversal();
\r
394 while(vtkActor* aSubAct = aCollection->GetNextActor())
\r
395 aSubAct->SetVisibility( false );
\r
396 aCollection->Delete();
\r
406 //==========================================================
\r
409 ::CreatePrs( const char* entry )
\r
411 SVTK_Prs* prs = new SVTK_Prs();
\r
413 vtkRenderer* rnr = ( (SVTK_ViewWindow*) getViewManager()->getActiveView() )->getRenderer();
\r
414 vtkActorCollection* theActors = rnr->GetActors();
\r
415 theActors->InitTraversal();
\r
417 while( ( ac = theActors->GetNextActor() ) ) {
\r
418 SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( ac );
\r
419 if ( anActor && anActor->hasIO() && !strcmp( anActor->getIO()->getEntry(), entry ) ) {
\r
420 prs->AddObject( ac );
\r
427 //==========================================================
\r
430 ::BeforeDisplay( SALOME_Displayer* d )
\r
432 d->BeforeDisplay( this, SALOME_VTKViewType() );
\r
435 //==========================================================
\r
437 SVTK_Viewer::AfterDisplay( SALOME_Displayer* d )
\r
439 d->AfterDisplay( this, SALOME_VTKViewType() );
\r
442 //==========================================================
\r
445 ::isVisible( const Handle(SALOME_InteractiveObject)& io )
\r
447 QPtrVector<SUIT_ViewWindow> aViews = myViewManager->getViews();
\r
448 for(int i = 0, iEnd = aViews.size(); i < iEnd; i++)
\r
449 if(SUIT_ViewWindow* aViewWindow = aViews.at(i))
\r
450 if(SVTK_ViewWindow* aView = dynamic_cast<SVTK_ViewWindow*>(aViewWindow))
\r
451 if(SVTK_RenderWindowInteractor* aRWI = aView->getRWInteractor())
\r
452 if(!aRWI->isVisible( io ))
\r
457 //==========================================================
\r
462 // if (theUpdateTrihedron) onAdjustTrihedron();
\r
463 QPtrVector<SUIT_ViewWindow> aViews = myViewManager->getViews();
\r
464 for(int i = 0, iEnd = aViews.size(); i < iEnd; i++)
\r
465 if(SUIT_ViewWindow* aViewWindow = aViews.at(i))
\r
466 if(SVTK_ViewWindow* aView = dynamic_cast<SVTK_ViewWindow*>(aViewWindow))
\r
467 if(SVTK_RenderWindow* aRW = aView->getRenderWindow())
\r
473 ::onSelectionChanged()
\r
475 emit selectionChanged();
\r