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