Salome HOME
Remove dependency from KERNEL
[modules/gui.git] / src / SVTK / SVTK_RenderWindowInteractor.cxx
1 //  SALOME VTKViewer : build VTK viewer into Salome desktop
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
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. 
10 // 
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. 
15 // 
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 
19 // 
20 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : VTKViewer_RenderWindowInteractor.cxx
25 //  Author : Nicolas REJNERI
26 //  Module : SALOME
27 //  $Header$
28
29 #include "SVTK_RenderWindowInteractor.h"
30
31 #include "SVTK_InteractorStyle.h"
32 #include "SVTK_RenderWindow.h"
33 #include "SVTK_ViewWindow.h"
34
35 #include "VTKViewer_Algorithm.h"
36 #include "SVTK_Functor.h"
37 #include "SVTK_Actor.h"
38
39 #include <stdio.h>
40 #include <stdlib.h>
41 #include <string.h>
42 #include <math.h>
43
44 // VTK Includes
45 #include <vtkObjectFactory.h>
46 #include <vtkPicker.h>
47 #include <vtkCellPicker.h>
48 #include <vtkPointPicker.h>
49 #include <vtkRendererCollection.h>
50 #include <vtkRenderWindow.h>
51
52 // QT Includes
53 #include <qkeycode.h>
54
55 #include <TColStd_IndexedMapOfInteger.hxx>
56
57 using namespace std;
58
59 SVTK_RenderWindowInteractor* 
60 SVTK_RenderWindowInteractor
61 ::New() 
62 {
63   vtkObject *ret = vtkObjectFactory::CreateInstance("SVTK_RenderWindowInteractor") ;
64   if( ret ) {
65     return dynamic_cast<SVTK_RenderWindowInteractor *>(ret) ;
66   }
67   return new SVTK_RenderWindowInteractor;
68 }
69
70 SVTK_RenderWindowInteractor
71 ::SVTK_RenderWindowInteractor() 
72 {
73   this->Enabled = 0 ;
74   this->mTimer = new QTimer( this ) ;
75   myDisplayMode = 0;
76   myGUIWindow = 0;
77
78   myBasicPicker = vtkPicker::New();
79   myCellPicker = vtkCellPicker::New();
80   myPointPicker = vtkPointPicker::New();
81
82   myCellActor = SVTK_Actor::New(); 
83   myCellActor->PickableOff();
84   myCellActor->GetProperty()->SetColor(1,1,0);
85   myCellActor->GetProperty()->SetLineWidth(5);
86   myCellActor->GetProperty()->SetRepresentationToSurface();
87
88   myEdgeActor = SVTK_Actor::New(); 
89   myEdgeActor->PickableOff();
90   myEdgeActor->GetProperty()->SetColor(1,0,0);
91   myEdgeActor->GetProperty()->SetLineWidth(5);
92   myEdgeActor->GetProperty()->SetRepresentationToWireframe();
93
94   myPointActor = SVTK_Actor::New(); 
95   myPointActor->PickableOff();
96   myPointActor->GetProperty()->SetColor(1,1,0);
97   myPointActor->GetProperty()->SetPointSize(5);
98   myPointActor->GetProperty()->SetRepresentationToPoints();
99
100   connect(mTimer, SIGNAL(timeout()), this, SLOT(TimerFunc())) ;
101 }
102
103
104 SVTK_RenderWindowInteractor
105 ::~SVTK_RenderWindowInteractor() 
106 {
107   delete mTimer ;
108
109   myViewWindow->RemoveActor(myCellActor);
110   myViewWindow->RemoveActor(myEdgeActor);
111   myViewWindow->RemoveActor(myPointActor);
112
113   myCellActor->Delete();
114   myEdgeActor->Delete();
115   myPointActor->Delete();
116
117   myBasicPicker->Delete();
118   myCellPicker->Delete();
119   myPointPicker->Delete();
120 }
121
122 //
123 // We never allow the SVTK_RenderWindowInteractor to control 
124 // the event loop. The application always has the control. 
125 //
126 void
127 SVTK_RenderWindowInteractor
128 ::Initialize() 
129 {
130   //
131   // We cannot do much unless there is a render window 
132   // associated with this interactor. 
133   //
134   if( ! RenderWindow ) {
135     vtkErrorMacro(<< "SVTK_RenderWindowInteractor::Initialize(): No render window attached!") ;
136     return ;
137   }
138
139   //
140   // We cannot hand a render window which is not a VTKViewer_RenderWindow. 
141   // One way to force this is to use dynamic_cast and hope that 
142   // it works. If the dynamic_cast does not work, we flag an error
143   // and get the hell out.
144   //
145   vtkRenderWindow *aRenderWindow = dynamic_cast<vtkRenderWindow *>(RenderWindow) ;
146   if( !aRenderWindow ) {
147     vtkErrorMacro(<< "SVTK_RenderWindowInteractor::Initialize() can only handle VTKViewer_RenderWindow.") ;
148     return ;
149   }
150
151   //
152   // If the render window has zero size, then set it to a default 
153   // value of 300x300.
154   // 
155   int* aSize = aRenderWindow->GetSize();
156   this->Size[0] = ((aSize[0] > 0) ? aSize[0] : 300);
157   this->Size[1] = ((aSize[1] > 0) ? aSize[1] : 300);
158
159   this->SetPicker(myBasicPicker);
160
161   SetSelectionTolerance();
162
163   //
164   // Enable the interactor. 
165   //
166   this->Enable() ;
167
168   //
169   // Start the rendering of the window. 
170   //
171   aRenderWindow->Start() ;
172
173   //
174   // The interactor has been initialized.
175   //
176   this->Initialized = 1 ;
177
178   return ;
179 }
180
181
182 //----------------------------------------------------------------------------
183 void
184 SVTK_RenderWindowInteractor
185 ::setGUIWindow(QWidget* theWindow)
186 {
187   myGUIWindow = theWindow;
188 }
189
190 //----------------------------------------------------------------------------
191 void
192 SVTK_RenderWindowInteractor
193 ::setViewWindow(SVTK_ViewWindow* theViewWindow)
194 {
195   myViewWindow = theViewWindow;
196
197   myViewWindow->InsertActor(myCellActor);
198   myViewWindow->InsertActor(myEdgeActor);
199   myViewWindow->InsertActor(myPointActor);
200 }
201
202 //----------------------------------------------------------------------------
203 void
204 SVTK_RenderWindowInteractor
205 ::MoveInternalActors()
206 {
207   myViewWindow->MoveActor(myCellActor);
208   myViewWindow->MoveActor(myEdgeActor);
209   myViewWindow->MoveActor(myPointActor);
210 }
211
212 //----------------------------------------------------------------------------
213 void
214 SVTK_RenderWindowInteractor
215 ::SetInteractorStyle(vtkInteractorObserver *theInteractor)
216 {
217   myInteractorStyle = dynamic_cast<SVTK_InteractorStyle*>(theInteractor);
218   vtkRenderWindowInteractor::SetInteractorStyle(theInteractor);
219 }
220
221
222 void
223 SVTK_RenderWindowInteractor
224 ::SetSelectionMode(Selection_Mode theMode)
225 {
226   myCellActor->SetVisibility(false);
227   myEdgeActor->SetVisibility(false);
228   myPointActor->SetVisibility(false);
229
230   switch(theMode){
231   case ActorSelection:
232     this->SetPicker(myBasicPicker);
233     break;
234   case NodeSelection:
235     this->SetPicker(myPointPicker);
236     break;
237   case CellSelection:
238   case EdgeSelection:
239   case FaceSelection:
240   case VolumeSelection:
241   case EdgeOfCellSelection:
242     this->SetPicker(myCellPicker);
243     break;
244   }
245
246   myInteractorStyle->OnSelectionModeChanged();
247 }
248
249 void
250 SVTK_RenderWindowInteractor
251 ::SetSelectionProp(const double& theRed, 
252                    const double& theGreen, 
253                    const double& theBlue, 
254                    const int& theWidth) 
255 {
256   myCellActor->GetProperty()->SetColor(theRed, theGreen, theBlue);
257   myCellActor->GetProperty()->SetLineWidth(theWidth);
258
259   myPointActor->GetProperty()->SetColor(theRed, theGreen, theBlue);
260   myPointActor->GetProperty()->SetPointSize(theWidth);
261 }
262
263 void
264 SVTK_RenderWindowInteractor
265 ::SetSelectionTolerance(const double& theTolNodes, 
266                         const double& theTolItems)
267 {
268   myTolNodes = theTolNodes;
269   myTolItems = theTolItems;
270
271   myBasicPicker->SetTolerance(myTolItems);
272   myCellPicker->SetTolerance(myTolItems);
273   myPointPicker->SetTolerance(myTolNodes);
274
275 }
276
277 // ================================== 
278 void
279 SVTK_RenderWindowInteractor
280 ::Start() 
281 {
282   //
283   // We do not allow this interactor to control the 
284   // event loop. Only the QtApplication objects are
285   // allowed to do that. 
286   //
287   vtkErrorMacro(<<"SVTK_RenderWindowInteractor::Start() not allowed to start event loop.") ;
288   return ;
289 }
290
291 void
292 SVTK_RenderWindowInteractor
293 ::UpdateSize(int w, int h) 
294 {
295   // if the size changed send this on to the RenderWindow
296   if ((w != this->Size[0])||(h != this->Size[1])) {
297     this->Size[0] = w;
298     this->Size[1] = h;
299     this->RenderWindow->SetSize(w,h);
300   }
301 }
302
303 int
304 SVTK_RenderWindowInteractor
305 ::CreateTimer(int vtkNotUsed(timertype)) 
306 {
307   //
308   // Start a one-shot timer for 10ms. 
309   //
310   mTimer->start(10, TRUE) ;
311   return 1 ;
312 }
313
314 int
315 SVTK_RenderWindowInteractor
316 ::DestroyTimer(void) 
317 {
318   //
319   // :TRICKY: Tue May  2 00:17:32 2000 Pagey
320   //
321   // QTimer will automatically expire after 10ms. So 
322   // we do not need to do anything here. In fact, we 
323   // should not even Stop() the QTimer here because doing 
324   // this will skip some of the processing that the TimerFunc()
325   // does and will result in undesirable effects. For 
326   // example, this will result in vtkLODActor to leave
327   // the models in low-res mode after the mouse stops
328   // moving. 
329   //
330   return 1 ;
331 }
332
333 void
334 SVTK_RenderWindowInteractor
335 ::TimerFunc() 
336 {
337   if( ! this->Enabled ) {
338     return ;
339   }
340
341   myInteractorStyle->OnTimer();
342
343   emit RenderWindowModified();
344 }
345
346 void
347 SVTK_RenderWindowInteractor
348 ::MouseMove(const QMouseEvent *event) 
349 {
350   if( ! this->Enabled ) {
351     return ;
352   }
353   myInteractorStyle->OnMouseMove(0, 0, event->x(), event->y()/*this->Size[1] - event->y() - 1*/) ;
354   if (myInteractorStyle->needsRedrawing() )
355     emit RenderWindowModified() ; 
356 }
357
358 void
359 SVTK_RenderWindowInteractor
360 ::LeftButtonPressed(const QMouseEvent *event) 
361 {
362   if( ! this->Enabled ) {
363     return ;
364   }
365   myInteractorStyle->OnLeftButtonDown((event->state() & ControlButton), 
366                                       (event->state() & ShiftButton), 
367                                       event->x(), event->y());
368 }
369
370 void
371 SVTK_RenderWindowInteractor
372 ::LeftButtonReleased(const QMouseEvent *event) {
373   if( ! this->Enabled ) {
374     return ;
375   }
376   myInteractorStyle->OnLeftButtonUp( (event->state() & ControlButton), 
377                                      (event->state() & ShiftButton), 
378                                      event->x(), event->y() ) ;
379 }
380
381 void 
382 SVTK_RenderWindowInteractor
383 ::MiddleButtonPressed(const QMouseEvent *event) 
384 {
385   if( ! this->Enabled ) {
386     return ;
387   }
388   myInteractorStyle->OnMiddleButtonDown((event->state() & ControlButton), 
389                                         (event->state() & ShiftButton), 
390                                         event->x(), event->y() ) ;
391 }
392
393 void
394 SVTK_RenderWindowInteractor
395 ::MiddleButtonReleased(const QMouseEvent *event) 
396 {
397   if( ! this->Enabled ) {
398     return ;
399   }
400   myInteractorStyle->OnMiddleButtonUp( (event->state() & ControlButton), 
401                                        (event->state() & ShiftButton), 
402                                        event->x(), event->y() ) ;
403 }
404
405 void
406 SVTK_RenderWindowInteractor
407 ::RightButtonPressed(const QMouseEvent *event) 
408 {
409   if( ! this->Enabled ) {
410     return ;
411   }
412   myInteractorStyle->OnRightButtonDown( (event->state() & ControlButton), 
413                                         (event->state() & ShiftButton), 
414                                         event->x(), event->y() ) ;
415 }
416
417 void
418 SVTK_RenderWindowInteractor
419 ::RightButtonReleased(const QMouseEvent *event) 
420 {
421   if( ! this->Enabled ) {
422     return ;
423   }
424   myInteractorStyle->OnRightButtonUp( (event->state() & ControlButton), 
425                                       (event->state() & ShiftButton), 
426                                       event->x(), event->y() ) ;
427
428   if(myInteractorStyle->GetState() == VTK_INTERACTOR_STYLE_CAMERA_NONE && !( event->state() & KeyButtonMask )){
429     QContextMenuEvent aEvent( QContextMenuEvent::Mouse,
430                               event->pos(), event->globalPos(),
431                               event->state() );
432     emit contextMenuRequested( &aEvent );
433   }
434 }
435
436 void
437 SVTK_RenderWindowInteractor
438 ::ButtonPressed(const QMouseEvent *event) 
439 {
440   return ;
441 }
442
443 void
444 SVTK_RenderWindowInteractor
445 ::ButtonReleased(const QMouseEvent *event) 
446 {
447   return ;
448 }
449
450
451 int
452 SVTK_RenderWindowInteractor
453 ::GetDisplayMode() 
454 {
455   return myDisplayMode;
456 }
457
458 void
459 SVTK_RenderWindowInteractor
460 ::SetDisplayMode(int theMode)
461 {
462   if(theMode == 0) 
463     ChangeRepresentationToWireframe();
464   else 
465     ChangeRepresentationToSurface();
466   myDisplayMode = theMode;
467 }
468
469
470 void
471 SVTK_RenderWindowInteractor
472 ::SetDisplayMode(const Handle(SALOME_InteractiveObject)& theIObject, 
473                  int theMode)
474 {
475   using namespace VTK;
476   ForEachIf<SALOME_Actor>(GetRenderer()->GetActors(),
477                           TIsSameIObject<SALOME_Actor>(theIObject),
478                           TSetFunction<SALOME_Actor,int>
479                           (&SALOME_Actor::setDisplayMode,theMode));
480 }
481
482
483 void
484 SVTK_RenderWindowInteractor
485 ::ChangeRepresentationToWireframe()
486 {
487   ChangeRepresentationToWireframe(GetRenderer()->GetActors());
488 }
489
490 void
491 SVTK_RenderWindowInteractor
492 ::ChangeRepresentationToSurface()
493 {
494   ChangeRepresentationToSurface(GetRenderer()->GetActors());
495 }
496
497
498 void
499 SVTK_RenderWindowInteractor
500 ::ChangeRepresentationToWireframe(vtkActorCollection* theCollection)
501 {
502   using namespace VTK;
503   ForEach<SALOME_Actor>(theCollection,
504                         TSetFunction<SALOME_Actor,int>
505                         (&SALOME_Actor::setDisplayMode,0));
506   emit RenderWindowModified();
507 }
508
509 void
510 SVTK_RenderWindowInteractor
511 ::ChangeRepresentationToSurface(vtkActorCollection* theCollection)
512 {
513   using namespace VTK;
514   ForEach<SALOME_Actor>(theCollection,
515                         TSetFunction<SALOME_Actor,int>
516                         (&SALOME_Actor::setDisplayMode,1));
517   emit RenderWindowModified();
518 }
519
520
521 vtkRenderer* 
522 SVTK_RenderWindowInteractor
523 ::GetRenderer()
524 {
525   vtkRendererCollection * theRenderers =  this->RenderWindow->GetRenderers();
526   theRenderers->InitTraversal();
527   return theRenderers->GetNextItem();
528 }
529
530
531 struct TErase{
532   VTK::TSetFunction<vtkActor,int> mySetFunction;
533   TErase():
534     mySetFunction(&vtkActor::SetVisibility,false)
535   {}
536   void operator()(SALOME_Actor* theActor){
537     theActor->SetVisibility(false);
538     // Erase dependent actors
539     vtkActorCollection* aCollection = vtkActorCollection::New(); 
540     theActor->GetChildActors(aCollection);
541     VTK::ForEach<vtkActor>(aCollection,mySetFunction);
542     aCollection->Delete();
543   }
544 };
545
546 void
547 SVTK_RenderWindowInteractor
548 ::EraseAll()
549 {   
550   using namespace VTK;
551   ForEach<SALOME_Actor>(GetRenderer()->GetActors(),
552                         TErase());
553
554   emit RenderWindowModified() ;
555 }
556
557 void
558 SVTK_RenderWindowInteractor
559 ::DisplayAll()
560
561   vtkActorCollection* aCollection = GetRenderer()->GetActors();
562   using namespace VTK;
563   ForEach<SALOME_Actor>(aCollection,TSetVisibility<SALOME_Actor>(true));
564
565   emit RenderWindowModified() ;
566 }
567
568
569 void
570 SVTK_RenderWindowInteractor
571 ::Erase(SALOME_Actor* theActor, bool update)
572 {
573   TErase()(theActor);
574
575   if(update)
576     emit RenderWindowModified();
577 }
578
579
580 void
581 SVTK_RenderWindowInteractor
582 ::Erase(const Handle(SALOME_InteractiveObject)& theIObject, 
583         bool update)
584 {
585   using namespace VTK;
586   ForEachIf<SALOME_Actor>(GetRenderer()->GetActors(),
587                           TIsSameIObject<SALOME_Actor>(theIObject),
588                           TErase());
589
590   if(update)
591     emit RenderWindowModified();
592 }
593
594
595 struct TRemoveAction{
596   vtkRenderer* myRen;
597   TRemoveAction(vtkRenderer* theRen): myRen(theRen){}
598   void operator()(SALOME_Actor* theActor){
599     myRen->RemoveActor(theActor);
600   }
601 };
602
603 void
604 SVTK_RenderWindowInteractor
605 ::Remove(const Handle(SALOME_InteractiveObject)& theIObject, 
606          bool update)
607 {
608   vtkRenderer* aRen = GetRenderer();
609
610   using namespace VTK;
611   ForEachIf<SALOME_Actor>(aRen->GetActors(),
612                           TIsSameIObject<SALOME_Actor>(theIObject),
613                           TRemoveAction(aRen));
614 }
615
616 void
617 SVTK_RenderWindowInteractor
618 ::Remove( SALOME_Actor* SActor, bool updateViewer )
619 {
620   if ( SActor != 0 )
621   {
622     GetRenderer()->RemoveProp( SActor );
623     if ( updateViewer )
624       emit RenderWindowModified();
625   }
626 }
627
628 void
629 SVTK_RenderWindowInteractor
630 ::RemoveAll( const bool updateViewer )
631 {
632   vtkRenderer* aRenderer = GetRenderer();
633   vtkActorCollection* anActors = aRenderer->GetActors();
634   if ( anActors )
635   {
636     anActors->InitTraversal();
637     while ( vtkActor *anAct = anActors->GetNextActor() )
638     {
639       if ( anAct->IsA( "SALOME_Actor" ) )
640       {
641         SALOME_Actor* aSAct = (SALOME_Actor*)anAct;
642         if ( aSAct->hasIO() && aSAct->getIO()->hasEntry() )
643           aRenderer->RemoveActor( anAct );
644       }
645     }
646
647     if ( updateViewer )
648       emit RenderWindowModified();
649   }
650 }
651
652
653 float
654 SVTK_RenderWindowInteractor
655 ::GetTransparency(const Handle(SALOME_InteractiveObject)& theIObject) 
656 {
657   using namespace VTK;
658   SALOME_Actor* anActor = 
659     Find<SALOME_Actor>(GetRenderer()->GetActors(),
660                        TIsSameIObject<SALOME_Actor>(theIObject));
661   if(anActor)
662     return 1.0 - anActor->GetOpacity();
663   return -1.0;
664 }
665
666
667 void
668 SVTK_RenderWindowInteractor
669 ::SetTransparency(const Handle(SALOME_InteractiveObject)& theIObject, 
670                   float theTrans)
671 {
672   float anOpacity = 1.0 - theTrans;
673   using namespace VTK;
674   ForEachIf<SALOME_Actor>(GetRenderer()->GetActors(),
675                           TIsSameIObject<SALOME_Actor>(theIObject),
676                           TSetFunction<SALOME_Actor,float>
677                           (&SALOME_Actor::SetOpacity,anOpacity));
678 }
679
680
681 void
682 SVTK_RenderWindowInteractor
683 ::Display(SALOME_Actor* theActor, bool update)
684 {
685   GetRenderer()->AddActor(theActor);
686   theActor->SetVisibility(true);
687
688   if(update)
689     emit RenderWindowModified();
690 }
691
692
693 void
694 SVTK_RenderWindowInteractor
695 ::Display(const Handle(SALOME_InteractiveObject)& theIObject, bool update)
696 {
697   using namespace VTK;
698   ForEachIf<SALOME_Actor>(GetRenderer()->GetActors(),
699                           TIsSameIObject<SALOME_Actor>(theIObject),
700                           TSetVisibility<SALOME_Actor>(true));
701
702   if(update)
703     emit RenderWindowModified() ;
704 }
705
706
707 void
708 SVTK_RenderWindowInteractor
709 ::KeyPressed(QKeyEvent *event)
710 {}
711
712
713 struct THighlightAction{
714   bool myIsHighlight;
715   SVTK_InteractorStyle* myInteractorStyle;
716   THighlightAction(SVTK_InteractorStyle* theInteractorStyle,
717                    bool theIsHighlight): 
718     myInteractorStyle(theInteractorStyle),
719     myIsHighlight(theIsHighlight)
720   {}
721   void operator()(SALOME_Actor* theActor){
722     if(theActor->GetMapper()){
723       if(theActor->hasHighlight())
724         theActor->highlight(myIsHighlight);
725       else{
726         if(theActor->GetVisibility() && myIsHighlight)
727           myInteractorStyle->HighlightProp(theActor);
728         else if(!myIsHighlight)
729           myInteractorStyle->HighlightProp(NULL);
730       }
731     }
732   }
733 };
734
735 bool
736 SVTK_RenderWindowInteractor
737 ::highlight( const Handle(SALOME_InteractiveObject)& theIObject, 
738              bool hilight, 
739              bool update)
740 {
741   using namespace VTK;
742   ForEachIf<SALOME_Actor>(GetRenderer()->GetActors(),
743                           TIsSameIObject<SALOME_Actor>(theIObject),
744                           THighlightAction(myInteractorStyle,hilight));
745
746   if(update)
747     emit RenderWindowModified();
748
749   return false;
750 }
751
752
753 struct TUpdateAction{
754   void operator()(vtkActor* theActor){
755     theActor->ApplyProperties();
756   }
757 };
758
759 void
760 SVTK_RenderWindowInteractor
761 ::Update() 
762 {
763   vtkRenderer* aRen = GetRenderer();
764
765   using namespace VTK;
766   ForEach<vtkActor>(aRen->GetActors(),TUpdateAction());
767
768   aRen->ResetCamera();
769
770   emit RenderWindowModified();  
771 }
772
773
774 void
775 SVTK_RenderWindowInteractor
776 ::unHighlightSubSelection()
777 {
778   myPointActor->SetVisibility(false);
779   myEdgeActor->SetVisibility(false);
780   myCellActor->SetVisibility(false);
781 }
782
783
784 bool
785 SVTK_RenderWindowInteractor
786 ::unHighlightAll()
787 {
788   unHighlightSubSelection();
789
790   using namespace VTK;
791   ForEach<SALOME_Actor>(GetRenderer()->GetActors(),
792                         THighlightAction(myInteractorStyle,false));
793
794   emit RenderWindowModified() ;
795
796   return false;
797 }
798
799 //-----------------
800 // Color methods
801 //-----------------
802
803 void
804 SVTK_RenderWindowInteractor
805 ::SetColor(const Handle(SALOME_InteractiveObject)& theIObject,QColor theColor) 
806 {
807   float aColor[3] = {theColor.red()/255., theColor.green()/255., theColor.blue()/255.};
808   using namespace VTK;
809   ForEachIf<SALOME_Actor>(GetRenderer()->GetActors(),
810                           TIsSameIObject<SALOME_Actor>(theIObject),
811                           TSetFunction<SALOME_Actor,const float*>
812                           (&SALOME_Actor::SetColor,aColor));
813 }
814
815
816 QColor
817 SVTK_RenderWindowInteractor
818 ::GetColor(const Handle(SALOME_InteractiveObject)& theIObject) 
819 {
820   using namespace VTK;
821   SALOME_Actor* anActor = 
822     Find<SALOME_Actor>(GetRenderer()->GetActors(),
823                        TIsSameIObject<SALOME_Actor>(theIObject));
824   if(anActor){
825     float r,g,b;
826     anActor->GetColor(r,g,b);
827     return QColor(int(r*255),int(g*255),int(b*255));
828   }
829   return QColor(0,0,0);
830 }
831
832
833 bool
834 SVTK_RenderWindowInteractor
835 ::isInViewer(const Handle(SALOME_InteractiveObject)& theIObject)
836 {
837   using namespace VTK;
838   SALOME_Actor* anActor = 
839     Find<SALOME_Actor>(GetRenderer()->GetActors(),
840                        TIsSameIObject<SALOME_Actor>(theIObject));
841   return anActor != NULL;
842 }
843
844
845 bool
846 SVTK_RenderWindowInteractor
847 ::isVisible(const Handle(SALOME_InteractiveObject)& theIObject)
848 {
849   using namespace VTK;
850   SALOME_Actor* anActor = 
851     Find<SALOME_Actor>(GetRenderer()->GetActors(),
852                        TIsSameIObject<SALOME_Actor>(theIObject));
853   return anActor != NULL && anActor->GetVisibility();
854 }
855
856
857 void
858 SVTK_RenderWindowInteractor
859 ::rename(const Handle(SALOME_InteractiveObject)& theIObject, QString theName)
860 {
861   using namespace VTK;
862   ForEachIf<SALOME_Actor>(GetRenderer()->GetActors(),
863                           TIsSameIObject<SALOME_Actor>(theIObject),
864                           TSetFunction<SALOME_Actor,const char*,QString>
865                           (&SALOME_Actor::setName,theName.latin1()));
866 }
867
868
869 //----------------------------------------------------------------------------
870 bool
871 SVTK_RenderWindowInteractor
872 ::highlight(const TColStd_IndexedMapOfInteger& theMapIndex,
873             SALOME_Actor* theMapActor, 
874             SVTK_Actor* theActor,
875             TUpdateActor theFun, 
876             bool hilight, 
877             bool update)
878 {
879   if(theMapIndex.Extent() == 0) return false;
880   
881   if (hilight) {
882     setActorData(theMapIndex,theMapActor,theActor,theFun);
883     theActor->SetVisibility(true);
884   }
885   else {
886     theActor->SetVisibility(false);
887   }
888
889   if(update){
890     this->RenderWindow->Render();  
891     emit RenderWindowModified() ;
892   }
893
894   return false;
895 }
896   
897 void
898 SVTK_RenderWindowInteractor
899 ::setActorData(const TColStd_IndexedMapOfInteger& theMapIndex,
900                SALOME_Actor* theMapActor,
901                SVTK_Actor *theActor,
902                TUpdateActor theFun)
903 {
904   (*theFun)(theMapIndex,theMapActor,theActor);
905   float aPos[3];
906   theMapActor->GetPosition(aPos);
907   theActor->SetPosition(aPos);
908 }
909
910
911 //----------------------------------------------------------------------------
912 static void CellsUpdateActor(const TColStd_IndexedMapOfInteger& theMapIndex,
913                              SALOME_Actor* theMapActor, 
914                              SVTK_Actor* theActor)
915 {
916   theActor->MapCells(theMapActor,theMapIndex);
917 }
918   
919 bool
920 SVTK_RenderWindowInteractor
921 ::highlightCell(const TColStd_IndexedMapOfInteger& theMapIndex,
922                 SALOME_Actor* theMapActor, 
923                 bool hilight, 
924                 bool update)
925 {
926   return highlight(theMapIndex,theMapActor,myCellActor,&CellsUpdateActor,hilight,update);
927 }
928   
929 void 
930 SVTK_RenderWindowInteractor
931 ::setCellData(const int& theIndex, 
932               SALOME_Actor* theMapActor,
933               SVTK_Actor* theActor)
934 {
935   TColStd_IndexedMapOfInteger MapIndex; 
936   MapIndex.Add(theIndex);
937   theActor->MapCells(theMapActor,MapIndex);
938 }
939
940
941 //----------------------------------------------------------------------------
942 static void PointsUpdateActor(const TColStd_IndexedMapOfInteger& theMapIndex,
943                               SALOME_Actor* theMapActor, 
944                               SVTK_Actor* theActor)
945 {
946   theActor->MapPoints(theMapActor,theMapIndex);
947 }
948   
949 bool
950 SVTK_RenderWindowInteractor
951 ::highlightPoint(const TColStd_IndexedMapOfInteger& theMapIndex,
952                  SALOME_Actor* theMapActor, 
953                  bool hilight, 
954                  bool update)
955 {
956   return highlight(theMapIndex,theMapActor,myPointActor,&PointsUpdateActor,hilight,update);
957 }
958   
959 void
960 SVTK_RenderWindowInteractor
961 ::setPointData(const int& theIndex, 
962                SALOME_Actor* theMapActor,
963                SVTK_Actor* theActor)
964 {
965   TColStd_IndexedMapOfInteger MapIndex; 
966   MapIndex.Add(theIndex);
967   theActor->MapPoints(theMapActor,MapIndex);
968 }
969
970   
971 //----------------------------------------------------------------------------
972 static void EdgesUpdateActor(const TColStd_IndexedMapOfInteger& theMapIndex,
973                              SALOME_Actor* theMapActor, 
974                              SVTK_Actor* theActor)
975 {
976   theActor->MapEdge(theMapActor,theMapIndex);
977 }
978   
979 bool
980 SVTK_RenderWindowInteractor
981 ::highlightEdge(const TColStd_IndexedMapOfInteger& theMapIndex,
982                 SALOME_Actor* theMapActor, 
983                 bool hilight, 
984                 bool update)
985 {
986   return highlight(theMapIndex,theMapActor,myEdgeActor,&EdgesUpdateActor,hilight,update);
987 }
988   
989 void 
990 SVTK_RenderWindowInteractor
991 ::setEdgeData(const int& theCellIndex, 
992               SALOME_Actor* theMapActor,
993               const int& theEdgeIndex, 
994               SVTK_Actor* theActor )
995 {
996   TColStd_IndexedMapOfInteger MapIndex; 
997   MapIndex.Add(theCellIndex); 
998   MapIndex.Add(theEdgeIndex);
999   theActor->MapEdge(theMapActor,MapIndex);
1000 }