2 // File : VTKViewer_RenderWindowInteractor.cxx
3 // Created : Wed Mar 20 11:32:45 2002
4 // Author : Nicolas REJNERI
7 // Copyright : Open CASCADE 2002
10 #include "VTKViewer_RenderWindowInteractor.h"
11 #include "VTKViewer_RenderWindow.h"
12 #include "VTKViewer_InteractorStyleSALOME.h"
14 #include "QAD_Application.h"
15 #include "QAD_Desktop.h"
17 #include "SALOME_Selection.h"
18 #include "SALOME_Actor.h"
26 #include <vtkAssemblyNode.h>
28 #include <vtkInteractorStyle.h>
29 #include <vtkObjectFactory.h>
30 #include <vtkPicker.h>
31 #include <vtkCellPicker.h>
32 #include <vtkPointPicker.h>
33 #include <vtkDataSetMapper.h>
34 #include <vtkUnstructuredGrid.h>
35 #include <vtkUnstructuredGridReader.h>
36 #include <vtkSphereSource.h>
37 #include <vtkDataSet.h>
38 #include <vtkMaskPoints.h>
39 #include <vtkVertex.h>
44 VTKViewer_RenderWindowInteractor* VTKViewer_RenderWindowInteractor::New() {
45 vtkObject *ret = vtkObjectFactory::CreateInstance("VTKViewer_RenderWindowInteractor") ;
47 return dynamic_cast<VTKViewer_RenderWindowInteractor *>(ret) ;
49 return new VTKViewer_RenderWindowInteractor;
52 VTKViewer_RenderWindowInteractor::VTKViewer_RenderWindowInteractor() {
54 this->mTimer = new QTimer( this ) ;
55 this->displaymode = 0;
57 vtkPicker* thepicker = vtkPicker::New();
58 thepicker->SetTolerance(0);
59 this->SetPicker(thepicker);
61 connect(mTimer, SIGNAL(timeout()), this, SLOT(TimerFunc())) ;
65 VTKViewer_RenderWindowInteractor::~VTKViewer_RenderWindowInteractor() {
69 void VTKViewer_RenderWindowInteractor::PrintSelf(ostream& os, vtkIndent indent) {
70 vtkRenderWindowInteractor::PrintSelf(os, indent) ;
72 // :NOTE: Fri Apr 21 21:51:05 2000 Pagey
73 // QGL specific stuff goes here. One should add output
74 // lines here if any protected members are added to
80 // We never allow the VTKViewer_RenderWindowInteractor to control
81 // the event loop. The application always has the control.
83 void VTKViewer_RenderWindowInteractor::Initialize() {
85 // We cannot do much unless there is a render window
86 // associated with this interactor.
88 if( ! RenderWindow ) {
89 vtkErrorMacro(<< "VTKViewer_RenderWindowInteractor::Initialize(): No render window attached!") ;
94 // We cannot hand a render window which is not a VTKViewer_RenderWindow.
95 // One way to force this is to use dynamic_cast and hope that
96 // it works. If the dynamic_cast does not work, we flag an error
97 // and get the hell out.
99 VTKViewer_RenderWindow *my_render_win = dynamic_cast<VTKViewer_RenderWindow *>(RenderWindow) ;
100 if( ! my_render_win ) {
101 vtkErrorMacro(<< "VTKViewer_RenderWindowInteractor::Initialize() can only handle VTKViewer_RenderWindow.") ;
106 // If the render window has zero size, then set it to a default
109 int *size = my_render_win->GetSize() ;
110 size[0] = ((size[0] > 0) ? size[0] : 300);
111 size[1] = ((size[1] > 0) ? size[1] : 300);
114 // Enable the interactor.
119 // Start the rendering of the window.
121 my_render_win->Start() ;
124 // Set our size to that of the render window.
126 this->Size[0] = size[0] ;
127 this->Size[1] = size[1] ;
130 // The interactor has been initialized.
132 this->Initialized = 1 ;
134 VTKViewer_InteractorStyleSALOME* style = VTKViewer_InteractorStyleSALOME::New();
135 this->SetInteractorStyle(style);
137 Cell_Actor = vtkActor::New();
138 Cell_Actor->PickableOff();
139 Cell_Actor->GetProperty()->SetColor(1,1,0);
140 Cell_Actor->GetProperty()->SetRepresentationToSurface();
142 Edge_Actor = vtkActor::New();
143 Edge_Actor->PickableOff();
144 Edge_Actor->GetProperty()->SetColor(1,0,0);
145 Edge_Actor->GetProperty()->SetRepresentationToSurface();
146 Edge_Actor->GetProperty()->SetLineWidth(20);
148 Point_Actor = vtkActor::New();
149 Point_Actor->PickableOff();
150 Point_Actor->GetProperty()->SetColor(1,1,0);
151 Point_Actor->GetProperty()->SetRepresentationToSurface();
152 Point_Actor->GetProperty()->SetPointSize(3);
157 void VTKViewer_RenderWindowInteractor::SetSelectionMode(int mode)
159 Cell_Actor->VisibilityOff();
160 Edge_Actor->VisibilityOff();
161 Point_Actor->VisibilityOff();
163 selectionmode = mode;
165 vtkPointPicker* thepicker = vtkPointPicker::New();
166 // thepicker->SetTolerance(0.001);
167 this->SetPicker(thepicker);
168 } else if ( mode == 2 ) {
169 vtkCellPicker* thepicker = vtkCellPicker::New();
170 thepicker->SetTolerance(0.001);
171 this->SetPicker(thepicker);
172 } else if ( mode == 3 ) {
173 vtkCellPicker* thepicker = vtkCellPicker::New();
174 thepicker->SetTolerance(0.001);
175 this->SetPicker(thepicker);
176 } else if ( mode == 4 ) {
177 vtkPicker* thepicker = vtkPicker::New();
178 thepicker->SetTolerance(0.001);
179 this->SetPicker(thepicker);
184 void VTKViewer_RenderWindowInteractor::Enable() {
186 // Do not need to do anything if already enabled.
188 if( this->Enabled ) {
193 // Attach slots to every useful signal of the render window.
195 this->ConnectSlots() ;
201 void VTKViewer_RenderWindowInteractor::Disable() {
202 if( ! this->Enabled ) {
206 this->DisconnectSlots() ;
211 // ==================================
212 void VTKViewer_RenderWindowInteractor::Start() {
214 // We do not allow this interactor to control the
215 // event loop. Only the QtApplication objects are
216 // allowed to do that.
218 vtkErrorMacro(<<"VTKViewer_RenderWindowInteractor::Start() not allowed to start event loop.") ;
222 void VTKViewer_RenderWindowInteractor::UpdateSize(int w, int h) {
223 // if the size changed send this on to the RenderWindow
224 if ((w != this->Size[0])||(h != this->Size[1])) {
227 this->RenderWindow->SetSize(w,h);
231 int VTKViewer_RenderWindowInteractor::CreateTimer(int vtkNotUsed(timertype)) {
233 // Start a one-shot timer for 10ms.
235 mTimer->start(10, TRUE) ;
239 int VTKViewer_RenderWindowInteractor::DestroyTimer(void) {
241 // :TRICKY: Tue May 2 00:17:32 2000 Pagey
243 // QTimer will automatically expire after 10ms. So
244 // we do not need to do anything here. In fact, we
245 // should not even Stop() the QTimer here because doing
246 // this will skip some of the processing that the TimerFunc()
247 // does and will result in undesirable effects. For
248 // example, this will result in vtkLODActor to leave
249 // the models in low-res mode after the mouse stops
255 void VTKViewer_RenderWindowInteractor::TimerFunc() {
256 if( ! this->Enabled ) {
260 this->InteractorStyle->OnTimer() ;
261 emit RenderWindowModified() ;
264 void VTKViewer_RenderWindowInteractor::ConnectSlots() {
265 ProcessSlotConnections(true) ;
268 void VTKViewer_RenderWindowInteractor::DisconnectSlots() {
269 ProcessSlotConnections(false) ;
272 void VTKViewer_RenderWindowInteractor::ProcessSlotConnections(bool conn) {
274 // We cannot do much unless there is a render window
275 // associated with this interactor.
277 if( ! RenderWindow ) {
278 vtkErrorMacro(<< "VTKViewer_RenderWindowInteractor::Initialize(): No render window attached!") ;
283 bool (*slot_func) ( const QObject * sender,
285 const QObject * receiver,
286 const char * member ) ;
288 slot_func = &QObject::connect ;
290 slot_func = &QObject::disconnect ;
293 // We cannot hand a render window which is not a VTKViewer_RenderWindow.
294 // One way to force this is to use dynamic_cast and hope that
295 // it works. If the dynamic_cast does not work, we flag an error
296 // and get the hell out.
298 VTKViewer_RenderWindow *my_render_win = dynamic_cast<VTKViewer_RenderWindow *>(RenderWindow) ;
299 if( ! my_render_win ) {
300 vtkErrorMacro(<< "VTKViewer_RenderWindowInteractor::Initialize() can only handle VTKViewer_RenderWindow.") ;
304 slot_func ( my_render_win, SIGNAL(ButtonPressed(const QMouseEvent *)),
305 this, SLOT(ButtonPressed(const QMouseEvent *)) ) ;
306 slot_func( my_render_win, SIGNAL(ButtonReleased(const QMouseEvent *)),
307 this, SLOT(ButtonReleased(const QMouseEvent *)) ) ;
310 slot_func( my_render_win, SIGNAL(LeftButtonPressed(const QMouseEvent *)),
311 this, SLOT(LeftButtonPressed(const QMouseEvent *)) ) ;
312 slot_func( my_render_win, SIGNAL(LeftButtonReleased(const QMouseEvent *)),
313 this, SLOT(LeftButtonReleased(const QMouseEvent *)) ) ;
315 slot_func( my_render_win, SIGNAL(MiddleButtonPressed(const QMouseEvent *)),
316 this, SLOT(MiddleButtonPressed(const QMouseEvent *)) ) ;
317 slot_func( my_render_win, SIGNAL(MiddleButtonReleased(const QMouseEvent *)),
318 this, SLOT(MiddleButtonReleased(const QMouseEvent *)) ) ;
320 slot_func( my_render_win, SIGNAL(RightButtonPressed(const QMouseEvent *)),
321 this, SLOT(RightButtonPressed(const QMouseEvent *)) ) ;
322 slot_func( my_render_win, SIGNAL(RightButtonReleased(const QMouseEvent *)),
323 this, SLOT(RightButtonReleased(const QMouseEvent *)) ) ;
325 slot_func( my_render_win, SIGNAL(MouseMove(const QMouseEvent *)),
326 this, SLOT(MouseMove(const QMouseEvent *)) ) ;
328 slot_func( my_render_win, SIGNAL(KeyPressed(QKeyEvent *)),
329 this, SLOT(KeyPressed(QKeyEvent *)) ) ;
331 slot_func( this, SIGNAL(RenderWindowModified()),
332 my_render_win, SLOT(updateGL()) ) ;
336 void VTKViewer_RenderWindowInteractor::MouseMove(const QMouseEvent *event) {
337 if( ! this->Enabled ) {
340 this->InteractorStyle->OnMouseMove(0, 0,
342 event->y()/*this->Size[1] - event->y() - 1*/) ;
343 VTKViewer_InteractorStyleSALOME* Style = 0;
344 if (this->InteractorStyle->IsA("VTKViewer_InteractorStyleSALOME"))
345 Style = VTKViewer_InteractorStyleSALOME::SafeDownCast(this->InteractorStyle);
346 if (!Style || Style->needsRedrawing() )
347 emit RenderWindowModified() ;
350 void VTKViewer_RenderWindowInteractor::LeftButtonPressed(const QMouseEvent *event) {
351 if( ! this->Enabled ) {
354 this->InteractorStyle->OnLeftButtonDown( (event->state() & ControlButton),
355 (event->state() & ShiftButton),
360 void VTKViewer_RenderWindowInteractor::LeftButtonReleased(const QMouseEvent *event) {
361 if( ! this->Enabled ) {
364 this->InteractorStyle->OnLeftButtonUp( (event->state() & ControlButton),
365 (event->state() & ShiftButton),
370 void VTKViewer_RenderWindowInteractor::MiddleButtonPressed(const QMouseEvent *event) {
371 if( ! this->Enabled ) {
374 this->InteractorStyle->OnMiddleButtonDown( (event->state() & ControlButton),
375 (event->state() & ShiftButton),
380 void VTKViewer_RenderWindowInteractor::MiddleButtonReleased(const QMouseEvent *event) {
381 if( ! this->Enabled ) {
384 this->InteractorStyle->OnMiddleButtonUp( (event->state() & ControlButton),
385 (event->state() & ShiftButton),
390 void VTKViewer_RenderWindowInteractor::RightButtonPressed(const QMouseEvent *event) {
391 if( ! this->Enabled ) {
394 this->InteractorStyle->OnRightButtonDown( (event->state() & ControlButton),
395 (event->state() & ShiftButton),
400 void VTKViewer_RenderWindowInteractor::RightButtonReleased(const QMouseEvent *event) {
401 if( ! this->Enabled ) {
404 this->InteractorStyle->OnRightButtonUp( (event->state() & ControlButton),
405 (event->state() & ShiftButton),
410 void VTKViewer_RenderWindowInteractor::ButtonPressed(const QMouseEvent *event) {
414 void VTKViewer_RenderWindowInteractor::ButtonReleased(const QMouseEvent *event) {
418 void VTKViewer_RenderWindowInteractor::ChangeRepresentationToWireframe(vtkActorCollection* ac)
422 for (ac->InitTraversal(); (anActor = ac->GetNextActor()); ) {
423 if ( anActor->IsA("GEOM_Actor") ) {
424 SALOME_Actor* SALOMEactor = SALOME_Actor::SafeDownCast(anActor);
425 // Specific for GEOM actor
426 if ( SALOMEactor->getDisplayMode() == 1 )
427 SALOMEactor->setDisplayMode(0);
429 anActor->GetProperty()->SetRepresentationToWireframe();
432 this->RenderWindow->Render();
433 emit RenderWindowModified() ;
436 int VTKViewer_RenderWindowInteractor::GetDisplayMode() {
440 void VTKViewer_RenderWindowInteractor::SetDisplayMode(int mode) {
441 if(mode==0) ChangeRepresentationToWireframe();
442 else ChangeRepresentationToSurface();
446 void VTKViewer_RenderWindowInteractor::SwitchRepresentation(const Handle(SALOME_InteractiveObject)& IObject,
449 for (this->RenderWindow->GetRenderers()->InitTraversal();
450 (aren = this->RenderWindow->GetRenderers()->GetNextItem()); ) {
451 vtkActorCollection* theActors = aren->GetActors();
452 theActors->InitTraversal();
453 vtkActor *ac = theActors->GetNextActor();
455 if ( ac->IsA("SALOME_Actor") ) {
456 SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( ac );
457 if ( anActor->hasIO() ) {
458 if ( IObject->isSame( anActor->getIO() ) ) {
459 if ( anActor->IsA("GEOM_Actor") ) {
461 if ( anActor->getDisplayMode() == 0 ) anActor->setDisplayMode(1);
462 else anActor->setDisplayMode(0);
465 if(anActor->GetProperty()->GetRepresentation() <= 1)
466 anActor->GetProperty()->SetRepresentationToSurface();
468 anActor->GetProperty()->SetRepresentationToWireframe();
473 ac = theActors->GetNextActor();
477 this->RenderWindow->Render();
478 emit RenderWindowModified() ;
484 void VTKViewer_RenderWindowInteractor::ChangeRepresentationToWireframe()
485 // change all actors to wireframe
487 vtkActorCollection *ac;
488 vtkActor *anActor, *aPart;
490 ac = GetRenderer()->GetActors();
491 ChangeRepresentationToWireframe(ac);
496 void VTKViewer_RenderWindowInteractor::ChangeRepresentationToSurface(vtkActorCollection* ac)
498 vtkActor *anActor, *aPart;
500 for (ac->InitTraversal(); (anActor = ac->GetNextActor()); ) {
501 if ( anActor->IsA("GEOM_Actor") ) {
502 SALOME_Actor* SALOMEactor = SALOME_Actor::SafeDownCast(anActor);
503 // Specific for GEOM actor
504 if ( SALOMEactor->getDisplayMode() == 0 )
505 SALOMEactor->setDisplayMode(1);
507 anActor->GetProperty()->SetRepresentationToSurface();
510 this->RenderWindow->Render();
511 emit RenderWindowModified() ;
514 void VTKViewer_RenderWindowInteractor::ChangeRepresentationToSurface()
515 // change all actors to "surface" or solid
517 vtkActorCollection *ac;
518 vtkActor *anActor, *aPart;
520 ac = GetRenderer()->GetActors();
521 ChangeRepresentationToSurface(ac);
524 vtkRenderer* VTKViewer_RenderWindowInteractor::GetRenderer()
526 vtkRendererCollection * theRenderers = this->RenderWindow->GetRenderers();
527 theRenderers->InitTraversal();
528 return theRenderers->GetNextItem();
531 void VTKViewer_RenderWindowInteractor::EraseAll()
533 vtkActorCollection *ac;
534 vtkActor *anActor, *aPart;
536 ac = GetRenderer()->GetActors();
537 for (ac->InitTraversal(); (anActor = ac->GetNextActor()); ) {
538 if ( anActor->IsA("SALOME_Actor") ) {
539 SALOME_Actor* SActor = SALOME_Actor::SafeDownCast( anActor );
540 SActor->SetVisibility(false);
543 emit RenderWindowModified() ;
546 void VTKViewer_RenderWindowInteractor::DisplayAll()
548 vtkActorCollection *ac;
549 vtkActor *anActor, *aPart;
551 ac = GetRenderer()->GetActors();
552 for (ac->InitTraversal(); (anActor = ac->GetNextActor()); ) {
553 if ( anActor->IsA("SALOME_Actor") ) {
554 SALOME_Actor* SActor = SALOME_Actor::SafeDownCast( anActor );
555 SActor->SetVisibility( true );
558 emit RenderWindowModified() ;
561 void VTKViewer_RenderWindowInteractor::Erase(const Handle(SALOME_InteractiveObject)& IObject, bool update)
564 for (this->RenderWindow->GetRenderers()->InitTraversal();
565 (aren = this->RenderWindow->GetRenderers()->GetNextItem()); ) {
566 vtkActorCollection* theActors = aren->GetActors();
567 vtkActorCollection* theChildActors = vtkActorCollection::New();
568 theActors->InitTraversal();
569 vtkActor *ac = theActors->GetNextActor();
571 if ( ac->IsA("SALOME_Actor") ) {
572 SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( ac );
573 if ( anActor->hasIO() ) {
574 if ( IObject->isSame( anActor->getIO() ) ) {
575 anActor->SetVisibility( false );
576 anActor->GetChildActors(theChildActors);
580 ac = theActors->GetNextActor();
583 // Erase dependent actors
584 theChildActors->InitTraversal();
585 ac = theChildActors->GetNextActor();
587 ac->SetVisibility( false );
588 ac = theChildActors->GetNextActor();
592 emit RenderWindowModified() ;
595 void VTKViewer_RenderWindowInteractor::Remove(const Handle(SALOME_InteractiveObject)& IObject, bool update)
598 for (this->RenderWindow->GetRenderers()->InitTraversal();
599 (aren = this->RenderWindow->GetRenderers()->GetNextItem()); ) {
600 vtkActorCollection* theActors = aren->GetActors();
601 theActors->InitTraversal();
602 vtkActor *ac = theActors->GetNextActor();
604 if ( ac->IsA("SALOME_Actor") ) {
605 SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( ac );
606 if ( anActor->hasIO() ) {
607 if ( IObject->isSame( anActor->getIO() ) ) {
608 aren->RemoveActor(anActor);
612 ac = theActors->GetNextActor();
616 emit RenderWindowModified() ;
619 float VTKViewer_RenderWindowInteractor::GetTransparency(const Handle(SALOME_InteractiveObject)& IObject) {
621 for (this->RenderWindow->GetRenderers()->InitTraversal();
622 (aren = this->RenderWindow->GetRenderers()->GetNextItem()); ) {
623 vtkActorCollection* theActors = aren->GetActors();
624 theActors->InitTraversal();
625 vtkActor *ac = theActors->GetNextActor();
627 if ( ac->IsA("SALOME_Actor") ) {
628 SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( ac );
629 if ( anActor->hasIO() ) {
630 if ( IObject->isSame( anActor->getIO() ) ) {
631 if ( anActor->IsA("GEOM_Actor") ) {
633 return (1-(anActor->GetOpacity()));
635 else return (1-anActor->GetProperty()->GetOpacity());
639 ac = theActors->GetNextActor();
645 void VTKViewer_RenderWindowInteractor::SetTransparency(const Handle(SALOME_InteractiveObject)& IObject, float trans) {
647 for (this->RenderWindow->GetRenderers()->InitTraversal();
648 (aren = this->RenderWindow->GetRenderers()->GetNextItem()); ) {
649 vtkActorCollection* theActors = aren->GetActors();
650 theActors->InitTraversal();
651 vtkActor *ac = theActors->GetNextActor();
653 if ( ac->IsA("SALOME_Actor") ) {
654 SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( ac );
655 if ( anActor->hasIO() ) {
656 if ( IObject->isSame( anActor->getIO() ) ) {
657 if ( anActor->IsA("GEOM_Actor") ) {
659 anActor->SetOpacity(1-trans);
661 else anActor->GetProperty()->SetOpacity(1-trans);
665 ac = theActors->GetNextActor();
670 void VTKViewer_RenderWindowInteractor::Display( SALOME_Actor* SActor, bool update)
673 for (this->RenderWindow->GetRenderers()->InitTraversal();
674 (aren = this->RenderWindow->GetRenderers()->GetNextItem()); ) {
675 aren->AddActor( SActor );
676 SActor->SetVisibility( true );
681 emit RenderWindowModified();
685 void VTKViewer_RenderWindowInteractor::Display(const Handle(SALOME_InteractiveObject)& IObject, bool update)
687 Standard_Boolean isalreadydisplayed = false;
690 for (this->RenderWindow->GetRenderers()->InitTraversal();
691 (aren = this->RenderWindow->GetRenderers()->GetNextItem()); ) {
692 vtkActorCollection* theActors = aren->GetActors();
693 theActors->InitTraversal();
694 vtkActor *ac = theActors->GetNextActor();
696 if ( ac->IsA("SALOME_Actor") ) {
697 SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( ac );
698 if ( anActor->hasIO() ) {
699 if ( IObject->isSame( anActor->getIO() ) ) {
700 anActor->SetVisibility( true );
704 ac = theActors->GetNextActor();
708 emit RenderWindowModified() ;
711 void VTKViewer_RenderWindowInteractor::KeyPressed(QKeyEvent *event) {
712 // MESSAGE ( " vtkQGLRenderWindowInteractor::KeyPressed " )
714 // if (!QAD_Application::getDesktop()->getActiveComponent().isEmpty()) {
715 // QAD_Application::getDesktop()->onKeyPress( event );
719 bool VTKViewer_RenderWindowInteractor::highlight( const Handle(SALOME_InteractiveObject)& IObject,
724 for (this->RenderWindow->GetRenderers()->InitTraversal();
725 (aren = this->RenderWindow->GetRenderers()->GetNextItem()); ) {
726 vtkActorCollection* theActors = aren->GetActors();
727 theActors->InitTraversal();
728 vtkActor *ac = theActors->GetNextActor();
730 if ( ac->IsA("SALOME_Actor") ) {
731 SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( ac );
732 if ( anActor->hasIO() ) {
733 if ( IObject->isSame( anActor->getIO() ) ) {
734 if ( anActor->GetMapper() == NULL ) {
737 //highlight or unhilight actors
738 if ( anActor->hasHighlight() ) {
739 anActor->highlight(hilight);
741 if ( anActor->GetVisibility() == 1 ) {
745 if ( (prop3D=vtkProp3D::SafeDownCast(anActor)) != NULL ) {
746 this->InteractorStyle->HighlightProp3D(prop3D);
747 } else if ( (actor2D=vtkActor2D::SafeDownCast(anActor)) != NULL ) {
748 this->InteractorStyle->HighlightActor2D(actor2D);
750 //this->InteractorStyle->HighlightProp(anActor);
752 this->InteractorStyle->HighlightProp3D(NULL);
753 this->InteractorStyle->HighlightActor2D(NULL);
754 //this->InteractorStyle->HighlightProp(NULL);
761 ac = theActors->GetNextActor();
766 emit RenderWindowModified();
772 void VTKViewer_RenderWindowInteractor::Update() {
774 for (this->RenderWindow->GetRenderers()->InitTraversal();
775 (aren = this->RenderWindow->GetRenderers()->GetNextItem()); ) {
776 vtkActorCollection* theActors = aren->GetActors();
777 theActors->InitTraversal();
778 vtkActor *ac = theActors->GetNextActor();
781 ac->ApplyProperties();
783 ac = theActors->GetNextActor();
786 emit RenderWindowModified() ;
791 bool VTKViewer_RenderWindowInteractor::unHighlightAll()
794 for (this->RenderWindow->GetRenderers()->InitTraversal();
795 (aren = this->RenderWindow->GetRenderers()->GetNextItem()); ) {
796 vtkActorCollection* theActors = aren->GetActors();
797 theActors->InitTraversal();
799 if ( theActors->IsItemPresent(Point_Actor) != 0 )
800 aren->RemoveActor( Point_Actor );
801 if ( theActors->IsItemPresent( Edge_Actor ) != 0 )
802 aren->RemoveActor( Edge_Actor );
803 if ( theActors->IsItemPresent( Cell_Actor ) != 0 )
804 aren->RemoveActor( Cell_Actor );
806 vtkActor *ac = theActors->GetNextActor();
809 if ( ac->IsA("SALOME_Actor") ) {
810 SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( ac );
811 if ( anActor->hasIO() ) {
812 //highlight or unhilight actors
813 if ( anActor->hasHighlight() )
814 anActor->highlight(false);
817 ac = theActors->GetNextActor();
821 emit RenderWindowModified() ;
829 void VTKViewer_RenderWindowInteractor::SetColor(const Handle(SALOME_InteractiveObject)& IObject,QColor thecolor) {
831 for (this->RenderWindow->GetRenderers()->InitTraversal();
832 (aren = this->RenderWindow->GetRenderers()->GetNextItem()); ) {
833 vtkActorCollection* theActors = aren->GetActors();
834 theActors->InitTraversal();
835 vtkActor *ac = theActors->GetNextActor();
837 if ( ac->IsA("SALOME_Actor") ) {
838 SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( ac );
839 if ( anActor->hasIO() ) {
840 if ( IObject->isSame( anActor->getIO() ) ) {
841 if ( anActor->IsA("GEOM_Actor") ) {
843 anActor->SetColor(float(thecolor.red())/255,float(thecolor.green())/255,float(thecolor.blue())/255);
846 anActor->GetProperty()->SetColor(float(thecolor.red())/255,float(thecolor.green())/255,float(thecolor.blue())/255);
851 ac = theActors->GetNextActor();
856 QColor VTKViewer_RenderWindowInteractor::GetColor(const Handle(SALOME_InteractiveObject)& IObject) {
858 QColor emptycolor(0,0,0);
859 for (this->RenderWindow->GetRenderers()->InitTraversal();
860 (aren = this->RenderWindow->GetRenderers()->GetNextItem()); ) {
861 vtkActorCollection* theActors = aren->GetActors();
862 theActors->InitTraversal();
863 vtkActor *ac = theActors->GetNextActor();
865 if ( ac->IsA("SALOME_Actor") ) {
866 SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( ac );
867 if ( anActor->hasIO() ) {
868 if ( IObject->isSame( anActor->getIO() ) ) {
869 if ( anActor->IsA("GEOM_Actor") ) {
872 anActor->GetColor(r,g,b);
873 return QColor(r*255,g*255,b*255);
877 anActor->GetProperty()->GetColor(color);
878 return QColor(color[0]*255,color[1]*255,color[2]*255);
883 ac = theActors->GetNextActor();
892 bool VTKViewer_RenderWindowInteractor::isInViewer(const Handle(SALOME_InteractiveObject)& IObject)
895 for (this->RenderWindow->GetRenderers()->InitTraversal();
896 (aren = this->RenderWindow->GetRenderers()->GetNextItem()); ) {
897 vtkActorCollection* theActors = aren->GetActors();
898 theActors->InitTraversal();
899 vtkActor *ac = theActors->GetNextActor();
901 if ( ac->IsA("SALOME_Actor") ) {
902 SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( ac );
903 if ( anActor->hasIO() ) {
904 if ( IObject->isSame( anActor->getIO() ) ) {
905 //MESSAGE ( " VTKViewer_RenderWindowInteractor::isInViewer = TRUE" )
910 ac = theActors->GetNextActor();
913 //MESSAGE ( " VTKViewer_RenderWindowInteractor::isInViewer = FALSE" )
917 bool VTKViewer_RenderWindowInteractor::isVisible(const Handle(SALOME_InteractiveObject)& IObject)
920 for (this->RenderWindow->GetRenderers()->InitTraversal();
921 (aren = this->RenderWindow->GetRenderers()->GetNextItem()); ) {
922 vtkActorCollection* theActors = aren->GetActors();
923 theActors->InitTraversal();
924 vtkActor *ac = theActors->GetNextActor();
926 if ( ac->IsA("SALOME_Actor") ) {
927 SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( ac );
928 if ( anActor->hasIO() ) {
929 if ( IObject->isSame( anActor->getIO() ) ) {
930 return anActor->GetVisibility();
934 ac = theActors->GetNextActor();
940 void VTKViewer_RenderWindowInteractor::rename(const Handle(SALOME_InteractiveObject)& IObject, QString newName)
943 for (this->RenderWindow->GetRenderers()->InitTraversal();
944 (aren = this->RenderWindow->GetRenderers()->GetNextItem()); ) {
945 vtkActorCollection* theActors = aren->GetActors();
946 theActors->InitTraversal();
947 vtkActor *ac = theActors->GetNextActor();
949 if ( ac->IsA("SALOME_Actor") ) {
950 SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( ac );
951 if ( anActor->hasIO() ) {
952 if ( IObject->isSame( anActor->getIO() ) ) {
953 anActor->setName(strdup(newName));
957 ac = theActors->GetNextActor();
961 emit RenderWindowModified() ;
964 bool VTKViewer_RenderWindowInteractor::highlightCell( const Handle(SALOME_InteractiveObject)& IObject,
966 const TColStd_MapOfInteger& MapIndex,
970 for (this->RenderWindow->GetRenderers()->InitTraversal();
971 (aren = this->RenderWindow->GetRenderers()->GetNextItem()); ) {
972 vtkActorCollection* theActors = aren->GetActors();
974 if ( theActors->IsItemPresent(Cell_Actor) != 0 )
975 aren->RemoveActor( Cell_Actor );
977 theActors->InitTraversal();
978 vtkActor *ac = theActors->GetNextActor();
979 for ( ; ac; ac = theActors->GetNextActor() ) {
980 if ( ac->IsA("SALOME_Actor") ) {
981 SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( ac );
982 if ( anActor->hasIO() ) {
983 if ( IObject->isSame( anActor->getIO() ) ) {
984 vtkUnstructuredGrid* Cell_UGrid = vtkUnstructuredGrid::New();
985 vtkUnstructuredGrid* UGrid = vtkUnstructuredGrid::SafeDownCast( ac->GetMapper()->GetInput() );
986 if (UGrid == 0) break;
987 vtkIdList *ptIds = vtkIdList::New(); ptIds->Allocate(12);
988 vtkDataSetMapper* Cell_Mapper = vtkDataSetMapper::New();
989 Cell_UGrid->SetPoints( UGrid->GetPoints() );
990 TColStd_MapIteratorOfMapOfInteger ite( MapIndex );
991 for ( ; ite.More(); ite.Next() ) {
992 UGrid->GetCellPoints( ite.Key(), ptIds );
993 Cell_UGrid->InsertNextCell(ac->GetMapper()->GetInput()->GetCellType( ite.Key() ), ptIds);
997 Cell_Mapper->SetInput(Cell_UGrid);
998 Cell_Actor->SetMapper(Cell_Mapper);
1000 if ( theActors->IsItemPresent(Cell_Actor) == 0 )
1001 aren->AddActor( Cell_Actor );
1004 Cell_Actor->VisibilityOn();
1006 Cell_Actor->VisibilityOff();
1014 this->RenderWindow->Render();
1015 emit RenderWindowModified() ;
1020 bool VTKViewer_RenderWindowInteractor::highlightEdge( const Handle(SALOME_InteractiveObject)& IObject,
1022 const TColStd_MapOfInteger& MapIndex,
1026 for (this->RenderWindow->GetRenderers()->InitTraversal();
1027 (aren = this->RenderWindow->GetRenderers()->GetNextItem()); ) {
1028 vtkActorCollection* theActors = aren->GetActors();
1029 theActors->InitTraversal();
1030 vtkActor *ac = theActors->GetNextActor();
1031 for( ; ac; ac = theActors->GetNextActor() ) {
1032 if ( ac->IsA("SALOME_Actor") ) {
1033 SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( ac );
1034 if ( anActor->hasIO() ) {
1035 if ( IObject->isSame( anActor->getIO() ) ) {
1037 vtkUnstructuredGrid* Edge_UGrid = vtkUnstructuredGrid::New();
1038 vtkUnstructuredGrid* UGrid = vtkUnstructuredGrid::SafeDownCast( ac->GetMapper()->GetInput() );
1039 if (UGrid == 0) break;
1041 vtkDataSetMapper* Edge_Mapper = vtkDataSetMapper::New();
1042 vtkCell* pickedCell;
1043 vtkCell* pickedEdge;
1045 Edge_UGrid->SetPoints( UGrid->GetPoints() );
1046 TColStd_MapIteratorOfMapOfInteger ite( MapIndex );
1047 int numberOfIndexes = MapIndex.Extent();
1048 int i, j, npts, *pts, aLen;
1050 if ( theActors->IsItemPresent(Cell_Actor) != 0 ) {
1051 Cell_Actor->VisibilityOff();
1052 if ( theActors->IsItemPresent(Edge_Actor) != 0 ) {
1053 vtkUnstructuredGrid* EdgeGrid = vtkUnstructuredGrid::SafeDownCast( Edge_Actor->GetMapper()->GetInput() );
1055 aLen = EdgeGrid->GetNumberOfCells();
1056 //SRN: modified traversal of edge cells.
1057 vtkCellArray* cells = EdgeGrid->GetCells();
1058 for (i=0, cells->InitTraversal(); cells->GetNextCell(npts,pts); i++) {
1059 if(MapIndex.Contains(i))
1060 Edge_UGrid->InsertNextCell(VTK_LINE, npts, pts);
1064 vtkUnstructuredGrid* CellGrid = vtkUnstructuredGrid::SafeDownCast( Cell_Actor->GetMapper()->GetInput() );
1066 bool isOneEdge = (MapIndex.Extent() <= 2);
1069 //SRN: modified finding the selected edges
1071 aLen = CellGrid->GetNumberOfCells();
1072 for (i=0; i<aLen; i++) {
1073 pickedCell = CellGrid->GetCell(i);
1074 int aLen2 = pickedCell->GetNumberOfEdges();
1075 for(j=0; j<aLen2; j++) {
1076 edgeId = (isOneEdge)?(-j):j;
1077 if(MapIndex.Contains(edgeId)) {
1078 pickedEdge = pickedCell->GetEdge(j);
1079 Edge_UGrid->InsertNextCell(pickedEdge->GetCellType(), pickedEdge->GetPointIds());
1085 Edge_Mapper->SetInput(Edge_UGrid);
1086 Edge_Actor->SetMapper(Edge_Mapper);
1088 if ( theActors->IsItemPresent(Edge_Actor) == 0 )
1089 aren->AddActor( Edge_Actor );
1092 Edge_Actor->VisibilityOn();
1094 Edge_Actor->VisibilityOff();
1105 this->RenderWindow->Render();
1106 emit RenderWindowModified();
1112 bool VTKViewer_RenderWindowInteractor::highlightPoint(const Handle(SALOME_InteractiveObject)& IObject,
1113 bool hilight, const TColStd_MapOfInteger& MapIndex,
1117 for (this->RenderWindow->GetRenderers()->InitTraversal();
1118 (aren = this->RenderWindow->GetRenderers()->GetNextItem()); ) {
1119 vtkActorCollection* theActors = aren->GetActors();
1121 if ( theActors->IsItemPresent(Point_Actor) != 0 )
1122 aren->RemoveActor( Point_Actor );
1124 theActors->InitTraversal();
1125 vtkActor *ac = theActors->GetNextActor();
1126 for ( ; ac; ac = theActors->GetNextActor() ) {
1127 if ( ac->IsA("SALOME_Actor") ) {
1128 SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( ac );
1129 if ( anActor->hasIO() ) {
1130 if ( IObject->isSame( anActor->getIO() ) ) {
1131 vtkUnstructuredGrid* UGrid = vtkUnstructuredGrid::SafeDownCast( ac->GetMapper()->GetInput() );
1132 if (UGrid == 0) break;
1133 vtkUnstructuredGrid* Point_UGrid = vtkUnstructuredGrid::New();
1136 vtkPoints *Points = vtkPoints::New();
1137 vtkMaskPoints* verts = vtkMaskPoints::New();
1138 vtkPolyDataMapper* vertMapper = vtkPolyDataMapper::New();
1140 TColStd_MapIteratorOfMapOfInteger ite( MapIndex );
1142 // Points->SetNumberOfPoints( MapIndex.Extent() );
1143 if ( MapIndex.Extent() == 1 )
1144 Points->SetNumberOfPoints( MapIndex.Extent() + 1 );
1146 Points->SetNumberOfPoints( MapIndex.Extent() );
1148 for ( ; ite.More(); ite.Next() ) {
1149 UGrid->GetPoint( ite.Key(), pts) ;
1150 Points->SetPoint(i, pts );
1152 // DEBUG : it's not possible to see only one point !!!!
1153 if ( MapIndex.Extent() == 1 )
1154 Points->SetPoint(i, 0., 0., 0. );
1157 Point_UGrid->SetPoints(Points);
1158 verts->SetInput(Point_UGrid);
1159 verts->SetGenerateVertices(1);
1160 verts->SetOnRatio(1);
1161 vertMapper->SetInput(verts->GetOutput());
1162 Point_Actor->SetMapper(vertMapper);
1164 if ( theActors->IsItemPresent(Point_Actor) == 0 ) {
1165 aren->AddActor( Point_Actor );
1169 Point_Actor->VisibilityOn();
1171 Point_Actor->VisibilityOff();
1181 this->RenderWindow->Render();
1182 emit RenderWindowModified();