1 #include <qpopupmenu.h>
2 #include <qcolordialog.h>
5 #include <vtkRenderer.h>
6 #include <vtkActorCollection.h>
8 #include "SUIT_Session.h"
10 #include "SVTK_Selection.h"
11 #include "SVTK_ViewModel.h"
12 #include "SVTK_ViewWindow.h"
15 #include "SVTK_RenderWindowInteractor.h"
16 #include "SVTK_RenderWindow.h"
20 #include "SALOME_Actor.h"
21 #include "SALOME_InteractiveObject.hxx"
23 // Temporarily commented to avoid awful dependecy on SALOMEDS
24 // TODO: better mechanism of storing display/erse status in a study
25 // should be provided...
26 //#include "Utils_ORB_INIT.hxx"
27 //#include "Utils_SINGLETON.hxx"
28 //#include "SALOME_ModuleCatalog_impl.hxx"
29 //#include "SALOME_NamingService.hxx"
31 //#include "SALOMEDSClient.hxx"
32 //#include "SALOMEDS_StudyManager.hxx"
34 // in order NOT TO link with SalomeApp, here the code returns SALOMEDS_Study.
35 // SalomeApp_Study::studyDS() does it as well, but -- here it is retrieved from
36 // SALOMEDS::StudyManager - no linkage with SalomeApp.
38 // Temporarily commented to avoid awful dependecy on SALOMEDS
39 // TODO: better mechanism of storing display/erse status in a study
40 // should be provided...
41 //static _PTR(Study) getStudyDS()
43 // SALOMEDSClient_Study* aStudy = NULL;
44 // _PTR(StudyManager) aMgr( new SALOMEDS_StudyManager() );
45 // get id of SUIT_Study, if it's a SalomeApp_Study, it will return
46 // id of its underlying SALOMEDS::Study
47 // SUIT_Application* app = SUIT_Session::session()->activeApplication();
48 // if ( !app ) return _PTR(Study)(aStudy);
49 // SUIT_Study* stud = app->activeStudy();
50 // if ( !stud ) return _PTR(Study)(aStudy);
51 // const int id = stud->id(); // virtual method, must return SALOMEDS_Study id
52 // get SALOMEDS_Study with this id from StudyMgr
53 // return aMgr->GetStudyByID( id );
56 //==========================================================
57 SVTK_Viewer::SVTK_Viewer()
59 myTrihedronSize = 100;
62 //==========================================================
63 SVTK_Viewer::~SVTK_Viewer()
67 QColor SVTK_Viewer::backgroundColor() const
72 void SVTK_Viewer::setBackgroundColor( const QColor& c )
78 //==========================================================
79 SUIT_ViewWindow* SVTK_Viewer::createView( SUIT_Desktop* theDesktop )
81 SVTK_ViewWindow* vw = new SVTK_ViewWindow( theDesktop, this );
82 vw->setBackgroundColor( backgroundColor() );
83 vw->SetTrihedronSize( trihedronSize() );
87 int SVTK_Viewer::trihedronSize() const
89 return myTrihedronSize;
92 void SVTK_Viewer::setTrihedronSize( const int sz )
96 SUIT_ViewManager* vm = getViewManager();
100 QPtrVector<SUIT_ViewWindow> vec = vm->getViews();
101 for ( int i = 0; i < vec.count(); i++ )
103 SUIT_ViewWindow* win = vec.at( i );
104 if ( !win || !win->inherits( "SVTK_ViewWindow" ) )
107 SVTK_ViewWindow* vw = (SVTK_ViewWindow*)win;
108 vw->SetTrihedronSize( sz );
112 //==========================================================
113 void SVTK_Viewer::setViewManager(SUIT_ViewManager* theViewManager)
115 SUIT_ViewModel::setViewManager(theViewManager);
117 if ( !theViewManager )
120 connect(theViewManager, SIGNAL(mousePress(SUIT_ViewWindow*, QMouseEvent*)),
121 this, SLOT(onMousePress(SUIT_ViewWindow*, QMouseEvent*)));
123 connect(theViewManager, SIGNAL(mouseMove(SUIT_ViewWindow*, QMouseEvent*)),
124 this, SLOT(onMouseMove(SUIT_ViewWindow*, QMouseEvent*)));
126 connect(theViewManager, SIGNAL(mouseRelease(SUIT_ViewWindow*, QMouseEvent*)),
127 this, SLOT(onMouseRelease(SUIT_ViewWindow*, QMouseEvent*)));
130 //==========================================================
131 void SVTK_Viewer::contextMenuPopup( QPopupMenu* thePopup )
133 thePopup->insertItem( VTKViewer_Viewer::tr( "MEN_DUMP_VIEW" ), this, SLOT( onDumpView() ) );
134 thePopup->insertItem( VTKViewer_Viewer::tr( "MEN_CHANGE_BACKGROUD" ), this, SLOT( onChangeBgColor() ) );
136 thePopup->insertSeparator();
138 SVTK_ViewWindow* aView = (SVTK_ViewWindow*)(myViewManager->getActiveView());
139 if ( aView && !aView->getToolBar()->isVisible() )
140 thePopup->insertItem( VTKViewer_Viewer::tr( "MEN_SHOW_TOOLBAR" ), this, SLOT( onShowToolbar() ) );
143 //==========================================================
144 void SVTK_Viewer::onMousePress(SUIT_ViewWindow* vw, QMouseEvent* event)
146 if(SVTK_ViewWindow* aVW = dynamic_cast<SVTK_ViewWindow*>(vw)){
147 if(SVTK_RenderWindowInteractor* aRWI = aVW->getRWInteractor()){
148 switch(event->button()) {
150 aRWI->LeftButtonPressed(event) ;
153 aRWI->MiddleButtonPressed(event) ;
156 aRWI->RightButtonPressed(event) ;
165 //==========================================================
168 ::onMouseMove(SUIT_ViewWindow* vw, QMouseEvent* event)
170 if(SVTK_ViewWindow* aVW = dynamic_cast<SVTK_ViewWindow*>(vw)){
171 if(SVTK_RenderWindowInteractor* aRWI = aVW->getRWInteractor()){
172 aRWI->MouseMove( event );
177 //==========================================================
180 ::onMouseRelease(SUIT_ViewWindow* vw, QMouseEvent* event)
182 if(SVTK_ViewWindow* aVW = dynamic_cast<SVTK_ViewWindow*>(vw)){
183 if(SVTK_RenderWindowInteractor* aRWI = aVW->getRWInteractor()){
184 switch(event->button()) {
186 aRWI->LeftButtonReleased(event) ;
189 aRWI->MiddleButtonReleased(event) ;
192 aRWI->RightButtonReleased(event) ;
201 //==========================================================
204 ::enableSelection(bool isEnabled)
206 mySelectionEnabled = isEnabled;
207 //!! To be done for view windows
210 //==========================================================
213 ::enableMultiselection(bool isEnable)
215 myMultiSelectionEnabled = isEnable;
216 //!! To be done for view windows
219 void SVTK_Viewer::onDumpView()
221 SVTK_ViewWindow* aView = (SVTK_ViewWindow*)(myViewManager->getActiveView());
226 //==========================================================
227 void SVTK_Viewer::onChangeBgColor()
229 QPtrVector<SUIT_ViewWindow> aViews = myViewManager->getViews();
230 for(int i = 0, iEnd = aViews.size(); i < iEnd; i++)
231 if(SUIT_ViewWindow* aViewWindow = aViews.at(i))
232 if(SVTK_ViewWindow* aView = dynamic_cast<SVTK_ViewWindow*>(aViewWindow)){
233 QColor aColor = QColorDialog::getColor( aView->backgroundColor(), aView);
234 if ( aColor.isValid() )
235 aView->setBackgroundColor(aColor);
239 //==========================================================
244 QPtrVector<SUIT_ViewWindow> aViews = myViewManager->getViews();
245 for(int i = 0, iEnd = aViews.size(); i < iEnd; i++)
246 if(SUIT_ViewWindow* aViewWindow = aViews.at(i))
247 if(SVTK_ViewWindow* aView = dynamic_cast<SVTK_ViewWindow*>(aViewWindow))
248 aView->getToolBar()->show();
251 //==========================================================
254 ::Display( const SALOME_VTKPrs* prs )
256 // try do downcast object
257 if(const SVTK_Prs* aPrs = dynamic_cast<const SVTK_Prs*>( prs )){
260 if(vtkActorCollection* anActorCollection = aPrs->GetObjects()){
261 // get SALOMEDS Study
262 // Temporarily commented to avoid awful dependecy on SALOMEDS
263 // TODO: better mechanism of storing display/erse status in a study
264 // should be provided...
265 // _PTR(Study) aStudy(getStudyDS());
266 anActorCollection->InitTraversal();
267 while(vtkActor* anActor = anActorCollection->GetNextActor()){
268 if(SALOME_Actor* anAct = SALOME_Actor::SafeDownCast(anActor)){
269 // Set visibility flag
270 // Temporarily commented to avoid awful dependecy on SALOMEDS
271 // TODO: better mechanism of storing display/erse status in a study
272 // should be provided...
273 //Handle(SALOME_InteractiveObject) anObj = anAct->getIO();
274 //if(!anObj.IsNull() && anObj->hasEntry() && aStudy){
275 // ToolsGUI::SetVisibility(aStudy,anObj->getEntry(),true,this);
277 // just display the object
278 QPtrVector<SUIT_ViewWindow> aViews = myViewManager->getViews();
279 for(int i = 0, iEnd = aViews.size(); i < iEnd; i++){
280 if(SUIT_ViewWindow* aViewWindow = aViews.at(i)){
281 if(SVTK_ViewWindow* aView = dynamic_cast<SVTK_ViewWindow*>(aViewWindow)){
282 if(SVTK_RenderWindowInteractor* aRWI = aView->getRWInteractor()){
283 aRWI->Display(anAct,false);
284 if(anAct->IsSetCamera()){
285 vtkRenderer* aRenderer = aView->getRenderer();
286 anAct->SetCamera( aRenderer->GetActiveCamera() );
298 //==========================================================
301 ::Erase( const SALOME_VTKPrs* prs, const bool forced )
303 // try do downcast object
304 if(const SVTK_Prs* aPrs = dynamic_cast<const SVTK_Prs*>( prs )){
307 if(vtkActorCollection* anActorCollection = aPrs->GetObjects()){
308 // get SALOMEDS Study
309 // Temporarily commented to avoid awful dependecy on SALOMEDS
310 // TODO: better mechanism of storing display/erse status in a study
311 // should be provided...
312 //_PTR(Study) aStudy(getStudyDS());
313 anActorCollection->InitTraversal();
314 while(vtkActor* anActor = anActorCollection->GetNextActor())
315 if(SALOME_Actor* anAct = SALOME_Actor::SafeDownCast(anActor)){
316 // Set visibility flag
317 // Temporarily commented to avoid awful dependecy on SALOMEDS
318 // TODO: better mechanism of storing display/erse status in a study
319 // should be provided...
320 //Handle(SALOME_InteractiveObject) anObj = anAct->getIO();
321 //if(!anObj.IsNull() && anObj->hasEntry() && aStudy){
322 // ToolsGUI::SetVisibility(aStudy,anObj->getEntry(),false,this);
324 // just display the object
325 QPtrVector<SUIT_ViewWindow> aViews = myViewManager->getViews();
326 for(int i = 0, iEnd = aViews.size(); i < iEnd; i++){
327 if(SUIT_ViewWindow* aViewWindow = aViews.at(i))
328 if(SVTK_ViewWindow* aView = dynamic_cast<SVTK_ViewWindow*>(aViewWindow))
329 if(SVTK_RenderWindowInteractor* aRWI = aView->getRWInteractor())
331 aRWI->Remove(anAct,false);
333 aRWI->Erase(anAct,forced);
340 //==========================================================
343 ::EraseAll( const bool forced )
345 // Temporarily commented to avoid awful dependecy on SALOMEDS
346 // TODO: better mechanism of storing display/erse status in a study
347 // should be provided...
348 //_PTR(Study) aStudy(getStudyDS());
349 QPtrVector<SUIT_ViewWindow> aViews = myViewManager->getViews();
350 for(int i = 0, iEnd = aViews.size(); i < iEnd; i++){
351 if(SUIT_ViewWindow* aViewWindow = aViews.at(i)){
352 if(SVTK_ViewWindow* aView = dynamic_cast<SVTK_ViewWindow*>(aViewWindow)){
353 vtkRenderer* aRenderer = aView->getRenderer();
354 vtkActorCollection* anActorCollection = aRenderer->GetActors();
355 anActorCollection->InitTraversal();
356 while(vtkActor* anActor = anActorCollection->GetNextActor()){
357 if(SALOME_Actor* anAct = SALOME_Actor::SafeDownCast(anActor)){
358 // Set visibility flag
359 // Temporarily commented to avoid awful dependecy on SALOMEDS
360 // TODO: better mechanism of storing display/erse status in a study
361 // should be provided...
362 //Handle(SALOME_InteractiveObject) anObj = anAct->getIO();
363 //if(!anObj.IsNull() && anObj->hasEntry() && aStudy)
364 // ToolsGUI::SetVisibility(aStudy,anObj->getEntry(),false,this);
366 aRenderer->RemoveActor(anAct);
369 anAct->SetVisibility( false );
370 // erase dependent actors
371 vtkActorCollection* aCollection = vtkActorCollection::New();
372 anAct->GetChildActors( aCollection );
373 aCollection->InitTraversal();
374 while(vtkActor* aSubAct = aCollection->GetNextActor())
375 aSubAct->SetVisibility( false );
376 aCollection->Delete();
386 //==========================================================
389 ::CreatePrs( const char* entry )
391 SVTK_Prs* prs = new SVTK_Prs();
393 vtkRenderer* rnr = ( (SVTK_ViewWindow*) getViewManager()->getActiveView() )->getRenderer();
394 vtkActorCollection* theActors = rnr->GetActors();
395 theActors->InitTraversal();
397 while( ( ac = theActors->GetNextActor() ) ) {
398 SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( ac );
399 if ( anActor && anActor->hasIO() && !strcmp( anActor->getIO()->getEntry(), entry ) ) {
400 prs->AddObject( ac );
407 //==========================================================
410 ::BeforeDisplay( SALOME_Displayer* d )
412 d->BeforeDisplay( this, SALOME_VTKViewType() );
415 //==========================================================
417 SVTK_Viewer::AfterDisplay( SALOME_Displayer* d )
419 d->AfterDisplay( this, SALOME_VTKViewType() );
422 //==========================================================
425 ::isVisible( const Handle(SALOME_InteractiveObject)& io )
427 QPtrVector<SUIT_ViewWindow> aViews = myViewManager->getViews();
428 for(int i = 0, iEnd = aViews.size(); i < iEnd; i++)
429 if(SUIT_ViewWindow* aViewWindow = aViews.at(i))
430 if(SVTK_ViewWindow* aView = dynamic_cast<SVTK_ViewWindow*>(aViewWindow))
431 if(SVTK_RenderWindowInteractor* aRWI = aView->getRWInteractor())
432 if(!aRWI->isVisible( io ))
437 //==========================================================
442 // if (theUpdateTrihedron) onAdjustTrihedron();
443 QPtrVector<SUIT_ViewWindow> aViews = myViewManager->getViews();
444 for(int i = 0, iEnd = aViews.size(); i < iEnd; i++)
445 if(SUIT_ViewWindow* aViewWindow = aViews.at(i))
446 if(SVTK_ViewWindow* aView = dynamic_cast<SVTK_ViewWindow*>(aViewWindow))
447 if(SVTK_RenderWindow* aRW = aView->getRenderWindow())
453 ::onSelectionChanged()
455 emit selectionChanged();