]> SALOME platform Git repositories - modules/kernel.git/blob - src/VTKViewer/VTKViewer_RenderWindowInteractor.cxx
Salome HOME
DCQ : Merge with Ecole_ete_a6.
[modules/kernel.git] / src / VTKViewer / VTKViewer_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 "VTKViewer_RenderWindowInteractor.h"
30 #include "VTKViewer_RenderWindow.h"
31 #include "VTKViewer_InteractorStyleSALOME.h"
32
33 #include "QAD_Application.h"
34 #include "QAD_Desktop.h"
35
36 //#include "SALOME_Selection.h"
37 #include "SALOME_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 <vtkAssemblyNode.h>
46 #include <vtkActor.h>
47 #include <vtkInteractorStyle.h>
48 #include <vtkObjectFactory.h>
49 #include <vtkPicker.h>
50 #include <vtkCellPicker.h>
51 #include <vtkPointPicker.h>
52 #include <vtkUnstructuredGrid.h>
53 #include <vtkPolyDataMapper.h>
54 #include <vtkSphereSource.h>
55 #include <vtkDataSet.h>
56 #include <vtkMaskPoints.h>
57 #include <vtkVertex.h>
58 #include <vtkRendererCollection.h>
59 #include <vtkPolyDataWriter.h>
60
61 // QT Includes
62 #include <qkeycode.h>
63
64 using namespace std;
65
66 VTKViewer_RenderWindowInteractor* VTKViewer_RenderWindowInteractor::New() {
67   vtkObject *ret = vtkObjectFactory::CreateInstance("VTKViewer_RenderWindowInteractor") ;
68   if( ret ) {
69     return dynamic_cast<VTKViewer_RenderWindowInteractor *>(ret) ;
70   }
71   return new VTKViewer_RenderWindowInteractor;
72 }
73
74 VTKViewer_RenderWindowInteractor::VTKViewer_RenderWindowInteractor() {
75   this->Enabled = 0 ;
76   this->mTimer = new QTimer( this ) ;
77   this->displaymode = 0;
78   myGUIWindow = 0;
79   vtkPicker* thepicker = vtkPicker::New();
80   thepicker->SetTolerance(0);
81   this->SetPicker(thepicker);
82
83   connect(mTimer, SIGNAL(timeout()), this, SLOT(TimerFunc())) ;
84 }
85
86
87 VTKViewer_RenderWindowInteractor::~VTKViewer_RenderWindowInteractor() {
88   delete mTimer ;
89 }
90
91 void VTKViewer_RenderWindowInteractor::PrintSelf(ostream& os, vtkIndent indent) {
92   vtkRenderWindowInteractor::PrintSelf(os, indent) ;
93   //
94   // :NOTE: Fri Apr 21 21:51:05 2000 Pagey
95   // QGL specific stuff goes here. One should add output 
96   // lines here if any protected members are added to
97   // the class. 
98   //
99 }
100
101 //
102 // We never allow the VTKViewer_RenderWindowInteractor to control 
103 // the event loop. The application always has the control. 
104 //
105 void VTKViewer_RenderWindowInteractor::Initialize() {
106   //
107   // We cannot do much unless there is a render window 
108   // associated with this interactor. 
109   //
110   if( ! RenderWindow ) {
111     vtkErrorMacro(<< "VTKViewer_RenderWindowInteractor::Initialize(): No render window attached!") ;
112     return ;
113   }
114
115   //
116   // We cannot hand a render window which is not a VTKViewer_RenderWindow. 
117   // One way to force this is to use dynamic_cast and hope that 
118   // it works. If the dynamic_cast does not work, we flag an error
119   // and get the hell out.
120   //
121   vtkRenderWindow *my_render_win = dynamic_cast<vtkRenderWindow *>(RenderWindow) ;
122   if( !my_render_win ) {
123     vtkErrorMacro(<< "VTKViewer_RenderWindowInteractor::Initialize() can only handle VTKViewer_RenderWindow.") ;
124     return ;
125   }
126
127   //
128   // If the render window has zero size, then set it to a default 
129   // value of 300x300.
130   // 
131   int* aSize = my_render_win->GetSize();
132   this->Size[0] = ((aSize[0] > 0) ? aSize[0] : 300);
133   this->Size[1] = ((aSize[1] > 0) ? aSize[1] : 300);
134
135   //
136   // Enable the interactor. 
137   //
138   this->Enable() ;
139
140   //
141   // Start the rendering of the window. 
142   //
143   my_render_win->Start() ;
144
145   //
146   // The interactor has been initialized.
147   //
148   this->Initialized = 1 ;
149
150   myTolNodes = 0.025;
151   myTolItems = 0.001;
152
153   Cell_Actor = vtkActor::New(); 
154   Cell_Actor->PickableOff();
155   Cell_Actor->GetProperty()->SetColor(1,1,0);
156   Cell_Actor->GetProperty()->SetLineWidth(5);
157   Cell_Actor->GetProperty()->SetRepresentationToSurface();
158
159   Edge_Actor = vtkActor::New(); 
160   Edge_Actor->PickableOff();
161   Edge_Actor->GetProperty()->SetColor(1,0,0);
162   Edge_Actor->GetProperty()->SetLineWidth(5);
163   Edge_Actor->GetProperty()->SetRepresentationToWireframe();
164
165   Point_Actor = vtkActor::New(); 
166   Point_Actor->PickableOff();
167   Point_Actor->GetProperty()->SetColor(1,1,0);
168   Point_Actor->GetProperty()->SetPointSize(5);
169   Point_Actor->GetProperty()->SetRepresentationToPoints();
170
171   return ;
172 }
173
174
175 void VTKViewer_RenderWindowInteractor::SetInteractorStyle(vtkInteractorObserver *theInteractor){
176   myInteractorStyle = dynamic_cast<VTKViewer_InteractorStyleSALOME*>(theInteractor);
177   vtkRenderWindowInteractor::SetInteractorStyle(theInteractor);
178 }
179
180
181 void VTKViewer_RenderWindowInteractor::SetSelectionMode(Selection_Mode mode)
182 {
183   Cell_Actor->VisibilityOff();
184   Edge_Actor->VisibilityOff();
185   Point_Actor->VisibilityOff();
186
187   selectionmode = mode;
188   if ( mode == NodeSelection ) {
189     vtkPointPicker* thepicker = vtkPointPicker::New();
190     thepicker->SetTolerance(myTolNodes);
191     this->SetPicker(thepicker);
192   } else if ( mode == EdgeOfCellSelection ) {
193     vtkCellPicker* thepicker = vtkCellPicker::New();
194     thepicker->SetTolerance(myTolItems);
195     this->SetPicker(thepicker);
196   } else if ( mode == CellSelection || mode == EdgeSelection || 
197               mode == FaceSelection || mode == VolumeSelection ) {
198     vtkCellPicker* thepicker = vtkCellPicker::New();
199     thepicker->SetTolerance(myTolItems); 
200     this->SetPicker(thepicker);
201   } else if ( mode == ActorSelection ) {
202     vtkPicker* thepicker = vtkPicker::New();
203     thepicker->SetTolerance(myTolItems);
204     this->SetPicker(thepicker);
205   }
206
207   VTKViewer_InteractorStyleSALOME* Style = 0;
208   if (this->InteractorStyle->IsA("VTKViewer_InteractorStyleSALOME"))
209     Style = VTKViewer_InteractorStyleSALOME::SafeDownCast(this->InteractorStyle);
210   else 
211     return;
212   Style->OnSelectionModeChanged();
213 }
214
215 void VTKViewer_RenderWindowInteractor::SetSelectionProp(const double& theRed, const double& theGreen, 
216                                                         const double& theBlue, const int& theWidth) 
217 {
218   Cell_Actor->GetProperty()->SetColor(theRed, theGreen, theBlue);
219   Cell_Actor->GetProperty()->SetLineWidth(theWidth);
220
221   Point_Actor->GetProperty()->SetColor(theRed, theGreen, theBlue);
222   Point_Actor->GetProperty()->SetPointSize(theWidth);
223 }
224
225 void VTKViewer_RenderWindowInteractor::SetSelectionTolerance(const double& theTolNodes, const double& theTolItems)
226 {
227   myTolNodes = theTolNodes;
228   myTolItems = theTolItems;
229   if (this->GetPicker()->IsA("vtkPointPicker")) {
230     vtkPointPicker* picker = vtkPointPicker::SafeDownCast(this->GetPicker());
231     picker->SetTolerance(theTolNodes);
232   }
233   else if (this->GetPicker()->IsA("vtkPicker")) {
234     vtkPicker* picker = vtkPicker::SafeDownCast(this->GetPicker());
235     picker->SetTolerance(theTolItems);
236   }
237 }
238
239 void VTKViewer_RenderWindowInteractor::Enable() {
240   //
241   // Do not need to do anything if already enabled.
242   //
243   if( this->Enabled ) {
244     return ;
245   }
246   
247   //
248   // Attach slots to every useful signal of the render window. 
249   //
250   this->ConnectSlots() ;
251   
252   this->Enabled = 1 ;
253   this->Modified() ;
254 }
255
256 void VTKViewer_RenderWindowInteractor::Disable() {
257   if( ! this->Enabled ) {
258     return ;
259   }
260
261   this->DisconnectSlots() ;
262   this->Enabled = 0 ;
263   this->Modified() ;
264 }
265
266 // ================================== 
267 void VTKViewer_RenderWindowInteractor::Start() {
268   //
269   // We do not allow this interactor to control the 
270   // event loop. Only the QtApplication objects are
271   // allowed to do that. 
272   //
273   vtkErrorMacro(<<"VTKViewer_RenderWindowInteractor::Start() not allowed to start event loop.") ;
274   return ;
275 }
276
277 void VTKViewer_RenderWindowInteractor::UpdateSize(int w, int h) {
278   // if the size changed send this on to the RenderWindow
279   if ((w != this->Size[0])||(h != this->Size[1])) {
280     this->Size[0] = w;
281     this->Size[1] = h;
282     this->RenderWindow->SetSize(w,h);
283   }
284 }
285
286 int VTKViewer_RenderWindowInteractor::CreateTimer(int vtkNotUsed(timertype)) {
287   //
288   // Start a one-shot timer for 10ms. 
289   //
290   mTimer->start(10, TRUE) ;
291   return 1 ;
292 }
293
294 int VTKViewer_RenderWindowInteractor::DestroyTimer(void) {
295   //
296   // :TRICKY: Tue May  2 00:17:32 2000 Pagey
297   //
298   // QTimer will automatically expire after 10ms. So 
299   // we do not need to do anything here. In fact, we 
300   // should not even Stop() the QTimer here because doing 
301   // this will skip some of the processing that the TimerFunc()
302   // does and will result in undesirable effects. For 
303   // example, this will result in vtkLODActor to leave
304   // the models in low-res mode after the mouse stops
305   // moving. 
306   //
307   return 1 ;
308 }
309
310 void VTKViewer_RenderWindowInteractor::TimerFunc() {
311   if( ! this->Enabled ) {
312     return ;
313   }
314
315   ((vtkInteractorStyle*)this->InteractorStyle)->OnTimer() ;
316   emit RenderWindowModified() ;
317 }
318
319 void VTKViewer_RenderWindowInteractor::ConnectSlots() {
320   ProcessSlotConnections(true) ;
321 }
322
323 void VTKViewer_RenderWindowInteractor::DisconnectSlots() {
324   ProcessSlotConnections(false) ;
325 }
326
327 void VTKViewer_RenderWindowInteractor::ProcessSlotConnections(bool conn) {
328   //
329   // We cannot do much unless there is a render window 
330   // associated with this interactor. 
331   //
332   if( ! myGUIWindow ) {
333     vtkErrorMacro(<< "VTKViewer_RenderWindowInteractor::Initialize(): No render window attached!") ;
334     return ;
335   }
336
337   
338   bool (*slot_func) ( const QObject * sender, 
339                       const char * signal, 
340                       const QObject * receiver, 
341                       const char * member ) ;
342   if( conn ) {
343     slot_func = &QObject::connect ;
344   } else {
345     slot_func = &QObject::disconnect ;
346   }
347   //
348   // We cannot hand a render window which is not a VTKViewer_RenderWindow. 
349   // One way to force this is to use dynamic_cast and hope that 
350   // it works. If the dynamic_cast does not work, we flag an error
351   // and get the hell out.
352   //
353   if( ! myGUIWindow ) {
354     vtkErrorMacro(<< "VTKViewer_RenderWindowInteractor::Initialize() can only handle VTKViewer_RenderWindow.") ;
355     return ;
356   }
357
358   slot_func ( myGUIWindow, SIGNAL(ButtonPressed(const QMouseEvent *)), 
359               this,          SLOT(ButtonPressed(const QMouseEvent *)) ) ;
360   slot_func( myGUIWindow, SIGNAL(ButtonReleased(const QMouseEvent *)), 
361              this,          SLOT(ButtonReleased(const QMouseEvent *)) ) ;
362   
363   
364   slot_func( myGUIWindow, SIGNAL(LeftButtonPressed(const QMouseEvent *)), 
365              this,          SLOT(LeftButtonPressed(const QMouseEvent *)) ) ;
366   slot_func( myGUIWindow, SIGNAL(LeftButtonReleased(const QMouseEvent *)), 
367              this,          SLOT(LeftButtonReleased(const QMouseEvent *)) ) ;
368   
369   slot_func( myGUIWindow, SIGNAL(MiddleButtonPressed(const QMouseEvent *)), 
370              this,          SLOT(MiddleButtonPressed(const QMouseEvent *)) ) ;
371   slot_func( myGUIWindow, SIGNAL(MiddleButtonReleased(const QMouseEvent *)), 
372              this,          SLOT(MiddleButtonReleased(const QMouseEvent *)) ) ;
373   
374   slot_func( myGUIWindow, SIGNAL(RightButtonPressed(const QMouseEvent *)), 
375              this,          SLOT(RightButtonPressed(const QMouseEvent *)) ) ;
376   slot_func( myGUIWindow, SIGNAL(RightButtonReleased(const QMouseEvent *)), 
377              this,          SLOT(RightButtonReleased(const QMouseEvent *)) ) ;
378   
379   slot_func( myGUIWindow, SIGNAL(MouseMove(const QMouseEvent *)), 
380              this,          SLOT(MouseMove(const QMouseEvent *)) ) ;
381   
382   slot_func( myGUIWindow, SIGNAL(KeyPressed(QKeyEvent *)),
383              this,          SLOT(KeyPressed(QKeyEvent *)) ) ;
384   
385   slot_func( this,          SIGNAL(RenderWindowModified()), 
386              myGUIWindow, SLOT(update()) ) ;
387
388 }
389
390 void VTKViewer_RenderWindowInteractor::MouseMove(const QMouseEvent *event) {
391   if( ! this->Enabled ) {
392     return ;
393   }
394   VTKViewer_InteractorStyleSALOME* Style = 0;
395   if (this->InteractorStyle->IsA("VTKViewer_InteractorStyleSALOME"))
396     Style = VTKViewer_InteractorStyleSALOME::SafeDownCast(this->InteractorStyle);
397   else {
398     emit RenderWindowModified() ; 
399     return;
400   }
401   Style->OnMouseMove(0, 0, event->x(), event->y()/*this->Size[1] - event->y() - 1*/) ;
402   if (Style->needsRedrawing() )
403     emit RenderWindowModified() ; 
404 }
405
406 void VTKViewer_RenderWindowInteractor::LeftButtonPressed(const QMouseEvent *event) {
407   if( ! this->Enabled ) {
408     return ;
409   }
410   VTKViewer_InteractorStyleSALOME* Style = 0;
411   if (this->InteractorStyle->IsA("VTKViewer_InteractorStyleSALOME"))
412     Style = VTKViewer_InteractorStyleSALOME::SafeDownCast(this->InteractorStyle);
413   else 
414     return;
415   Style->OnLeftButtonDown((event->state() & ControlButton), 
416                           (event->state() & ShiftButton), 
417                           event->x(), event->y());
418 }
419
420 void VTKViewer_RenderWindowInteractor::LeftButtonReleased(const QMouseEvent *event) {
421   if( ! this->Enabled ) {
422     return ;
423   }
424   VTKViewer_InteractorStyleSALOME* Style = 0;
425   if (this->InteractorStyle->IsA("VTKViewer_InteractorStyleSALOME"))
426     Style = VTKViewer_InteractorStyleSALOME::SafeDownCast(this->InteractorStyle);
427   else 
428     return;
429   Style->OnLeftButtonUp( (event->state() & ControlButton), 
430                          (event->state() & ShiftButton), 
431                          event->x(), event->y() ) ;
432 }
433
434 void VTKViewer_RenderWindowInteractor::MiddleButtonPressed(const QMouseEvent *event) {
435   if( ! this->Enabled ) {
436     return ;
437   }
438   VTKViewer_InteractorStyleSALOME* Style = 0;
439   if (this->InteractorStyle->IsA("VTKViewer_InteractorStyleSALOME"))
440     Style = VTKViewer_InteractorStyleSALOME::SafeDownCast(this->InteractorStyle);
441   else 
442     return;
443   Style->OnMiddleButtonDown((event->state() & ControlButton), 
444                             (event->state() & ShiftButton), 
445                             event->x(), event->y() ) ;
446 }
447
448 void VTKViewer_RenderWindowInteractor::MiddleButtonReleased(const QMouseEvent *event) {
449   if( ! this->Enabled ) {
450     return ;
451   }
452   VTKViewer_InteractorStyleSALOME* Style = 0;
453   if (this->InteractorStyle->IsA("VTKViewer_InteractorStyleSALOME"))
454     Style = VTKViewer_InteractorStyleSALOME::SafeDownCast(this->InteractorStyle);
455   else 
456     return;
457   Style->OnMiddleButtonUp( (event->state() & ControlButton), 
458                            (event->state() & ShiftButton), 
459                            event->x(), event->y() ) ;
460 }
461
462 void VTKViewer_RenderWindowInteractor::RightButtonPressed(const QMouseEvent *event) {
463   if( ! this->Enabled ) {
464     return ;
465   }
466   VTKViewer_InteractorStyleSALOME* Style = 0;
467   if (this->InteractorStyle->IsA("VTKViewer_InteractorStyleSALOME"))
468     Style = VTKViewer_InteractorStyleSALOME::SafeDownCast(this->InteractorStyle);
469   else 
470     return;
471   Style->OnRightButtonDown( (event->state() & ControlButton), 
472                             (event->state() & ShiftButton), 
473                             event->x(), event->y() ) ;
474 }
475
476 void VTKViewer_RenderWindowInteractor::RightButtonReleased(const QMouseEvent *event) {
477   if( ! this->Enabled ) {
478     return ;
479   }
480   VTKViewer_InteractorStyleSALOME* Style = 0;
481   if (this->InteractorStyle->IsA("VTKViewer_InteractorStyleSALOME"))
482     Style = VTKViewer_InteractorStyleSALOME::SafeDownCast(this->InteractorStyle);
483   else 
484     return;
485   Style->OnRightButtonUp( (event->state() & ControlButton), 
486                           (event->state() & ShiftButton), 
487                           event->x(), event->y() ) ;
488 }
489
490 void VTKViewer_RenderWindowInteractor::ButtonPressed(const QMouseEvent *event) {
491   return ;
492 }
493
494 void VTKViewer_RenderWindowInteractor::ButtonReleased(const QMouseEvent *event) {
495   return ;
496 }
497
498 void VTKViewer_RenderWindowInteractor::ChangeRepresentationToWireframe(vtkActorCollection* ac)
499 {
500   vtkActor* anActor;
501
502   for (ac->InitTraversal(); (anActor = ac->GetNextActor()); ) {
503     if ( anActor->IsA("GEOM_Actor") ) {
504       SALOME_Actor* SALOMEactor = SALOME_Actor::SafeDownCast(anActor);
505       // Specific for GEOM actor
506       if ( SALOMEactor->getDisplayMode() == 1 )
507         SALOMEactor->setDisplayMode(0);
508     } else {
509       anActor->GetProperty()->SetRepresentationToWireframe();
510     }
511   }
512   this->RenderWindow->Render();
513   emit RenderWindowModified() ;
514 }
515
516 int VTKViewer_RenderWindowInteractor::GetDisplayMode() {
517   return displaymode;
518 }
519
520 void VTKViewer_RenderWindowInteractor::SetDisplayMode(int mode) {
521   if(mode==0) ChangeRepresentationToWireframe();
522   else ChangeRepresentationToSurface();
523   displaymode = mode;
524 }
525
526 void VTKViewer_RenderWindowInteractor::SwitchRepresentation(const Handle(SALOME_InteractiveObject)& IObject,
527                                                             bool update) {  
528   vtkRenderer* aren;
529   for (this->RenderWindow->GetRenderers()->InitTraversal(); 
530        (aren = this->RenderWindow->GetRenderers()->GetNextItem()); ) {
531     vtkActorCollection* theActors = aren->GetActors();
532     theActors->InitTraversal();
533     vtkActor *ac = theActors->GetNextActor();
534     while(!(ac==NULL)) {
535       if ( ac->IsA("SALOME_Actor") ) {
536         SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( ac );
537         if ( anActor->hasIO() ) {
538           if ( IObject->isSame( anActor->getIO() ) ) {
539             if ( anActor->IsA("GEOM_Actor") ) {
540               // GEOM actor
541               if ( anActor->getDisplayMode() == 0 ) anActor->setDisplayMode(1);
542               else anActor->setDisplayMode(0);
543             }
544             else {
545               if(anActor->GetProperty()->GetRepresentation() <= 1)
546                 anActor->GetProperty()->SetRepresentationToSurface();
547               else
548                 anActor->GetProperty()->SetRepresentationToWireframe(); 
549             }
550           }
551         }
552       }
553       ac = theActors->GetNextActor();
554     }
555   } 
556   if (update) {
557     this->RenderWindow->Render();
558     emit RenderWindowModified() ;
559   }
560 }
561
562
563
564 void VTKViewer_RenderWindowInteractor::ChangeRepresentationToWireframe()
565   // change all actors to wireframe
566 {
567   vtkActorCollection *ac;
568   vtkActor *anActor, *aPart;
569   
570   ac = GetRenderer()->GetActors();
571   ChangeRepresentationToWireframe(ac);
572 }
573
574
575
576 void VTKViewer_RenderWindowInteractor::ChangeRepresentationToSurface(vtkActorCollection* ac)
577 {
578   vtkActor *anActor, *aPart;
579   
580   for (ac->InitTraversal(); (anActor = ac->GetNextActor()); ) {
581     if ( anActor->IsA("GEOM_Actor") ) {
582       SALOME_Actor* SALOMEactor = SALOME_Actor::SafeDownCast(anActor);
583       // Specific for GEOM actor
584       if ( SALOMEactor->getDisplayMode() == 0 )
585         SALOMEactor->setDisplayMode(1);
586     } else {
587       anActor->GetProperty()->SetRepresentationToSurface();
588     }
589   }
590   this->RenderWindow->Render();
591   emit RenderWindowModified() ;
592 }
593
594 void VTKViewer_RenderWindowInteractor::ChangeRepresentationToSurface()
595   // change all actors to "surface" or solid
596 {
597   vtkActorCollection *ac;
598   vtkActor *anActor, *aPart;
599   
600   ac = GetRenderer()->GetActors();
601   ChangeRepresentationToSurface(ac);
602 }
603
604 vtkRenderer* VTKViewer_RenderWindowInteractor::GetRenderer()
605 {
606   vtkRendererCollection * theRenderers =  this->RenderWindow->GetRenderers();
607   theRenderers->InitTraversal();
608   return theRenderers->GetNextItem();
609 }
610
611 void VTKViewer_RenderWindowInteractor::EraseAll()
612 {   
613   vtkActorCollection *ac;
614   vtkActor *anActor, *aPart;
615   
616   ac = GetRenderer()->GetActors();
617   for (ac->InitTraversal(); (anActor = ac->GetNextActor()); ) {
618     if ( anActor->IsA("SALOME_Actor") ) {
619       SALOME_Actor* SActor = SALOME_Actor::SafeDownCast( anActor );
620       SActor->SetVisibility(false);
621     }
622   }
623   emit RenderWindowModified() ;
624 }
625
626 void VTKViewer_RenderWindowInteractor::DisplayAll()
627 {   
628   vtkActorCollection *ac;
629   vtkActor *anActor, *aPart;
630   
631   ac = GetRenderer()->GetActors();
632   for (ac->InitTraversal(); (anActor = ac->GetNextActor()); ) {
633     if ( anActor->IsA("SALOME_Actor") ) {
634       SALOME_Actor* SActor = SALOME_Actor::SafeDownCast( anActor );
635       SActor->SetVisibility( true );
636     }
637   }
638   emit RenderWindowModified() ;
639 }
640
641 void VTKViewer_RenderWindowInteractor::Erase( SALOME_Actor* SActor, bool update)
642 {
643   SActor->SetVisibility( false );
644
645   // Erase dependent actors
646   vtkActorCollection* theChildActors = vtkActorCollection::New(); 
647   SActor->GetChildActors(theChildActors);
648
649   theChildActors->InitTraversal();
650   vtkActor *ac = theChildActors->GetNextActor();
651   while(!(ac==NULL)) {
652     ac->SetVisibility( false );
653     ac = theChildActors->GetNextActor();
654   }
655
656   if (update) 
657     emit RenderWindowModified();
658 }
659
660 void VTKViewer_RenderWindowInteractor::Erase(const Handle(SALOME_InteractiveObject)& IObject, bool update)
661 {
662   vtkRenderer* aren;
663   for (this->RenderWindow->GetRenderers()->InitTraversal(); 
664        (aren = this->RenderWindow->GetRenderers()->GetNextItem()); ) {
665     vtkActorCollection* theActors = aren->GetActors();
666     theActors->InitTraversal();
667     vtkActor *ac = theActors->GetNextActor();
668     while(!(ac==NULL)) {
669       if ( ac->IsA("SALOME_Actor") ) {
670         SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( ac );
671         if ( anActor->hasIO() ) {
672           if ( IObject->isSame( anActor->getIO() ) ) {
673             Erase(anActor, false);
674           }
675         }
676       }
677       ac = theActors->GetNextActor();
678     }
679   } 
680   if (update)
681     emit RenderWindowModified() ;
682 }
683
684 void VTKViewer_RenderWindowInteractor::Remove(const Handle(SALOME_InteractiveObject)& IObject, bool update)
685 {
686   vtkRenderer* aren;
687   for (this->RenderWindow->GetRenderers()->InitTraversal(); 
688        (aren = this->RenderWindow->GetRenderers()->GetNextItem()); ) {
689     vtkActorCollection* theActors = aren->GetActors();
690     theActors->InitTraversal();
691     vtkActor *ac = theActors->GetNextActor();
692     while(!(ac==NULL)) {
693       if ( ac->IsA("SALOME_Actor") ) {
694         SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( ac );
695         if ( anActor->hasIO() ) {
696           if ( IObject->isSame( anActor->getIO() ) ) {
697             aren->RemoveActor(anActor);
698           }
699         }
700       }
701       ac = theActors->GetNextActor();
702     }
703   } 
704   if (update)
705     emit RenderWindowModified() ;
706 }
707
708 float VTKViewer_RenderWindowInteractor::GetTransparency(const Handle(SALOME_InteractiveObject)& IObject) {
709   vtkRenderer* aren;
710   for (this->RenderWindow->GetRenderers()->InitTraversal(); 
711        (aren = this->RenderWindow->GetRenderers()->GetNextItem()); ) {
712     vtkActorCollection* theActors = aren->GetActors();
713     theActors->InitTraversal();
714     vtkActor *ac = theActors->GetNextActor();
715     while(!(ac==NULL)) {
716       if ( ac->IsA("SALOME_Actor") ) {
717         SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( ac );
718         if ( anActor->hasIO() ) {
719           if ( IObject->isSame( anActor->getIO() ) ) {
720             if ( anActor->IsA("GEOM_Actor") ) {
721               // GEOM actor
722               return (1-(anActor->GetOpacity()));
723             }
724             else return (1-anActor->GetProperty()->GetOpacity());
725           }
726         }
727       }
728       ac = theActors->GetNextActor();
729     }
730   } 
731   return -1;
732 }
733
734 void VTKViewer_RenderWindowInteractor::SetTransparency(const Handle(SALOME_InteractiveObject)& IObject, float trans) {
735   vtkRenderer* aren;
736   for (this->RenderWindow->GetRenderers()->InitTraversal(); 
737        (aren = this->RenderWindow->GetRenderers()->GetNextItem()); ) {
738     vtkActorCollection* theActors = aren->GetActors();
739     theActors->InitTraversal();
740     vtkActor *ac = theActors->GetNextActor();
741     while(!(ac==NULL)) {
742       if ( ac->IsA("SALOME_Actor") ) {
743         SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( ac );
744         if ( anActor->hasIO() ) {
745           if ( IObject->isSame( anActor->getIO() ) ) {
746             if ( anActor->IsA("GEOM_Actor") ) {
747               // GEOM actor
748               anActor->SetOpacity(1-trans);
749             }
750             else anActor->GetProperty()->SetOpacity(1-trans);
751           }
752         }
753       }
754       ac = theActors->GetNextActor();
755     }
756   } 
757 }
758
759 void VTKViewer_RenderWindowInteractor::Display( SALOME_Actor* SActor, bool update)
760 {
761   vtkRenderer* aren;
762   for (this->RenderWindow->GetRenderers()->InitTraversal(); 
763        (aren = this->RenderWindow->GetRenderers()->GetNextItem()); ) {
764     aren->AddActor( SActor );
765     SActor->SetVisibility( true );
766   }
767
768   if (update) {
769     Render();
770     emit RenderWindowModified();
771   }
772 }
773
774 void VTKViewer_RenderWindowInteractor::Display(const Handle(SALOME_InteractiveObject)& IObject, bool update)
775 {
776   Standard_Boolean isalreadydisplayed = false;
777
778   vtkRenderer* aren;
779   for (this->RenderWindow->GetRenderers()->InitTraversal(); 
780        (aren = this->RenderWindow->GetRenderers()->GetNextItem()); ) {
781     vtkActorCollection* theActors = aren->GetActors();
782     theActors->InitTraversal();
783     vtkActor *ac = theActors->GetNextActor();
784     while(!(ac==NULL)) {
785       if ( ac->IsA("SALOME_Actor") ) {
786         SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( ac );
787         if ( anActor->hasIO() ) {
788           if ( IObject->isSame( anActor->getIO() ) ) {
789             anActor->SetVisibility( true );
790           }
791         }
792       }
793       ac = theActors->GetNextActor();
794     }
795   }
796   if (update)
797     emit RenderWindowModified() ;
798 }
799
800 void VTKViewer_RenderWindowInteractor::KeyPressed(QKeyEvent *event) {
801 //    MESSAGE ( " vtkQGLRenderWindowInteractor::KeyPressed " )
802
803 //    if (!QAD_Application::getDesktop()->getActiveComponent().isEmpty()) {
804 //      QAD_Application::getDesktop()->onKeyPress( event );
805 //    }
806 }
807
808 bool VTKViewer_RenderWindowInteractor::highlight( const Handle(SALOME_InteractiveObject)& IObject, 
809                                                   bool hilight, 
810                                                   bool update)
811 {
812   VTKViewer_InteractorStyleSALOME* aStyle = 
813     VTKViewer_InteractorStyleSALOME::SafeDownCast(this->InteractorStyle);
814   if(!aStyle) return false;
815   vtkRendererCollection* aRenColl = this->RenderWindow->GetRenderers();
816   aRenColl->InitTraversal();
817   while(vtkRenderer* aRen = this->RenderWindow->GetRenderers()->GetNextItem()){
818       vtkActorCollection* theActors = aRen->GetActors();
819       theActors->InitTraversal();
820       while(vtkActor *anAct = theActors->GetNextActor()) {
821         if(SALOME_Actor* anActor = SALOME_Actor::SafeDownCast(anAct)){
822           if(anActor->hasIO()){
823             if(IObject->isSame(anActor->getIO())){
824               if(anActor->GetMapper() == NULL)
825                 return false;
826               //highlight or unhilight actors
827               if(anActor->hasHighlight())
828                 anActor->highlight(hilight);
829               else{
830                 if(anActor->GetVisibility() == 1 && hilight)
831                   aStyle->HighlightProp(anActor);
832                 else if(!hilight)
833                   aStyle->HighlightProp(NULL);
834               }
835             }
836           }
837         }
838       }
839     }
840   if(update){
841     Render();
842     emit RenderWindowModified();
843   }
844   return false;
845 }
846
847 void VTKViewer_RenderWindowInteractor::Update() {
848   vtkRenderer* aren;
849   for (this->RenderWindow->GetRenderers()->InitTraversal(); 
850        (aren = this->RenderWindow->GetRenderers()->GetNextItem()); ) {
851     vtkActorCollection* theActors = aren->GetActors();
852     theActors->InitTraversal();
853     vtkActor *ac = theActors->GetNextActor();
854
855     while(!(ac==NULL)) {
856       ac->ApplyProperties();
857       //VSV: No in VTK: ac->Update();
858       ac = theActors->GetNextActor();
859     }
860     aren->ResetCamera();
861     emit RenderWindowModified() ;  
862   }
863 }
864
865
866 bool VTKViewer_RenderWindowInteractor::unHighlightAll(){
867   VTKViewer_InteractorStyleSALOME* aStyle = 
868     VTKViewer_InteractorStyleSALOME::SafeDownCast(this->InteractorStyle);
869   if(aStyle) aStyle->HighlightProp(NULL);
870   vtkRendererCollection* aRenColl = this->RenderWindow->GetRenderers();
871   aRenColl->InitTraversal();
872   while(vtkRenderer* aRen = this->RenderWindow->GetRenderers()->GetNextItem()){
873     vtkActorCollection* theActors = aRen->GetActors();
874     if(theActors->IsItemPresent(Point_Actor)) 
875       aRen->RemoveActor(Point_Actor);
876     if(theActors->IsItemPresent(Edge_Actor)) 
877       aRen->RemoveActor(Edge_Actor); 
878     if(theActors->IsItemPresent(Cell_Actor)) 
879       aRen->RemoveActor(Cell_Actor);
880
881     theActors->InitTraversal();
882     while(vtkActor *anAct = theActors->GetNextActor()) {
883       if(SALOME_Actor* anActor = SALOME_Actor::SafeDownCast(anAct)){
884         if(anActor->hasIO()){
885           //highlight or unhilight actors
886           if(anActor->hasHighlight())
887             anActor->highlight(false);
888         }
889       }
890     }
891   }
892   emit RenderWindowModified() ;
893   return false;
894 }
895
896 //-----------------
897 // Color methods
898 //-----------------
899
900 void VTKViewer_RenderWindowInteractor::SetColor(const Handle(SALOME_InteractiveObject)& IObject,QColor thecolor) {
901   vtkRenderer* aren;
902   for (this->RenderWindow->GetRenderers()->InitTraversal(); 
903        (aren = this->RenderWindow->GetRenderers()->GetNextItem()); ) {
904     vtkActorCollection* theActors = aren->GetActors();
905     theActors->InitTraversal();
906     vtkActor *ac = theActors->GetNextActor();
907     while(!(ac==NULL)) {
908       if ( ac->IsA("SALOME_Actor") ) {
909         SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( ac );
910         if ( anActor->hasIO() ) {
911           if ( IObject->isSame( anActor->getIO() ) ) {
912             if ( anActor->IsA("GEOM_Actor") ) {
913               // GEOM actor
914               anActor->SetColor(float(thecolor.red())/255,float(thecolor.green())/255,float(thecolor.blue())/255);
915             }
916             else {
917               anActor->GetProperty()->SetColor(float(thecolor.red())/255,float(thecolor.green())/255,float(thecolor.blue())/255);
918             }
919           }
920         }
921       }
922       ac = theActors->GetNextActor();
923     }
924   } 
925 }
926
927 QColor VTKViewer_RenderWindowInteractor::GetColor(const Handle(SALOME_InteractiveObject)& IObject) {
928   vtkRenderer* aren;
929   QColor emptycolor(0,0,0);
930   for (this->RenderWindow->GetRenderers()->InitTraversal(); 
931        (aren = this->RenderWindow->GetRenderers()->GetNextItem()); ) {
932     vtkActorCollection* theActors = aren->GetActors();
933     theActors->InitTraversal();
934     vtkActor *ac = theActors->GetNextActor();
935     while(!(ac==NULL)) {
936       if ( ac->IsA("SALOME_Actor") ) {
937         SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( ac );
938         if ( anActor->hasIO() ) {
939           if ( IObject->isSame( anActor->getIO() ) ) {
940             if ( anActor->IsA("GEOM_Actor") ) {
941               // GEOM actor
942               float r,g,b;
943               anActor->GetColor(r,g,b);
944               return QColor(int(r*255),int(g*255),int(b*255));
945             }
946             else {
947               float color[3];
948               anActor->GetProperty()->GetColor(color);   
949               return QColor(int(color[0]*255),int(color[1]*255),int(color[2]*255));
950             }
951           }
952         }
953       }
954       ac = theActors->GetNextActor();
955     }
956   } 
957   return emptycolor;
958 }
959
960
961
962
963 bool VTKViewer_RenderWindowInteractor::isInViewer(const Handle(SALOME_InteractiveObject)& IObject)
964 {
965   vtkRenderer* aren;
966   for (this->RenderWindow->GetRenderers()->InitTraversal(); 
967        (aren = this->RenderWindow->GetRenderers()->GetNextItem()); ) {
968     vtkActorCollection* theActors = aren->GetActors();
969     theActors->InitTraversal();
970     vtkActor *ac = theActors->GetNextActor();
971     while(!(ac==NULL)) {
972       if ( ac->IsA("SALOME_Actor") ) {
973         SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( ac );
974         if ( anActor->hasIO() ) {
975           if ( IObject->isSame( anActor->getIO() ) ) {
976             //MESSAGE ( " VTKViewer_RenderWindowInteractor::isInViewer = TRUE" )
977             return true;
978           }
979         }
980       }
981       ac = theActors->GetNextActor();
982     }
983   }
984   //MESSAGE ( " VTKViewer_RenderWindowInteractor::isInViewer = FALSE" )
985   return false;
986 }
987
988 bool VTKViewer_RenderWindowInteractor::isVisible(const Handle(SALOME_InteractiveObject)& IObject)
989 {
990   vtkRenderer* aren;
991   for (this->RenderWindow->GetRenderers()->InitTraversal(); 
992        (aren = this->RenderWindow->GetRenderers()->GetNextItem()); ) {
993     vtkActorCollection* theActors = aren->GetActors();
994     theActors->InitTraversal();
995     vtkActor *ac = theActors->GetNextActor();
996     while(!(ac==NULL)) {
997       if ( ac->IsA("SALOME_Actor") ) {
998         SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( ac );
999         if ( anActor->hasIO() ) {
1000           if ( IObject->isSame( anActor->getIO() ) ) {
1001             return anActor->GetVisibility();
1002           }
1003         }
1004       }
1005       ac = theActors->GetNextActor();
1006     }
1007   }
1008   return false;
1009 }
1010
1011 void VTKViewer_RenderWindowInteractor::rename(const Handle(SALOME_InteractiveObject)& IObject, QString newName)
1012 {
1013   vtkRenderer* aren;
1014   for (this->RenderWindow->GetRenderers()->InitTraversal(); 
1015        (aren = this->RenderWindow->GetRenderers()->GetNextItem()); ) {
1016     vtkActorCollection* theActors = aren->GetActors();
1017     theActors->InitTraversal();
1018     vtkActor *ac = theActors->GetNextActor();
1019     while(!(ac==NULL)) {
1020       if ( ac->IsA("SALOME_Actor") ) {
1021         SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( ac );
1022         if ( anActor->hasIO() ) {
1023           if ( IObject->isSame( anActor->getIO() ) ) {
1024             anActor->setName(strdup(newName));
1025           }
1026         }
1027       }
1028       ac = theActors->GetNextActor();
1029     }
1030   }  
1031
1032   emit RenderWindowModified() ;
1033 }
1034
1035 bool VTKViewer_RenderWindowInteractor::highlight(const Handle(SALOME_InteractiveObject)& IObject, 
1036                                                  const TColStd_MapOfInteger& MapIndex, 
1037                                                  VTKViewer_RenderWindowInteractor::TCreateMapperFun theFun,
1038                                                  vtkActor *theActor, bool hilight, bool update )
1039 {
1040   if(MapIndex.Extent() == 0) return false;
1041   vtkRenderer* aRen = GetRenderer();
1042   vtkActorCollection* anActorColl = aRen->GetActors();
1043   if ( anActorColl->IsItemPresent(theActor) != 0 ) 
1044     aRen->RemoveActor(theActor);
1045   
1046   if (hilight) {
1047     setActorData(IObject, MapIndex, theFun, theActor);
1048     aRen->AddActor(theActor);         
1049     theActor->VisibilityOn();
1050   }
1051   else {
1052     theActor->VisibilityOff();
1053   }
1054
1055   if(update){
1056     this->RenderWindow->Render();  
1057     emit RenderWindowModified() ;
1058   }
1059
1060   return false;
1061 }
1062   
1063 void VTKViewer_RenderWindowInteractor::setActorData(const Handle(SALOME_InteractiveObject)& IObject,
1064                                                     const TColStd_MapOfInteger& MapIndex, 
1065                                                     VTKViewer_RenderWindowInteractor::TCreateMapperFun theFun,
1066                                                     vtkActor* theActor)
1067 {
1068   vtkActorCollection* anActorColl = GetRenderer()->GetActors();
1069   anActorColl->InitTraversal();
1070   vtkActor *ac = NULL;
1071   while ((ac = anActorColl->GetNextActor()) != NULL) {
1072     if (ac->IsA("SALOME_Actor")){
1073       SALOME_Actor* anActor = SALOME_Actor::SafeDownCast(ac);
1074       if (anActor->hasIO()) {
1075         if (IObject->isSame(anActor->getIO())) {
1076           if (vtkPolyData* aSourcePolyData = anActor->GetPolyDataInput()) {
1077             vtkPolyDataMapper* aMapper = vtkPolyDataMapper::New();
1078             (*theFun)(aSourcePolyData,aMapper,MapIndex);
1079             theActor->SetMapper(aMapper);   
1080             aMapper->Delete();
1081             break;
1082           }
1083         }
1084       }
1085     }
1086   }
1087 }
1088
1089
1090 static void CellCreateMapper(vtkPolyData *theSourcePolyData, vtkPolyDataMapper* theMapper, 
1091                       const TColStd_MapOfInteger& theMapIndex)
1092 {
1093   vtkPolyData* aPolyData = vtkPolyData::New();
1094   aPolyData->Allocate();
1095
1096   vtkIdList *ptIds = vtkIdList::New(); 
1097   ptIds->Allocate(theSourcePolyData->GetMaxCellSize());
1098   //  vtkPolyDataMapper* aMapper = vtkPolyDataMapper::New();
1099   aPolyData->SetPoints(theSourcePolyData->GetPoints());
1100   TColStd_MapIteratorOfMapOfInteger ite(theMapIndex);
1101   int aNbOfParts = theSourcePolyData->GetNumberOfCells();
1102   for(; ite.More(); ite.Next()){
1103     int aPartId = ite.Key();
1104     if(0 > aPartId || aPartId >= aNbOfParts) break;
1105     theSourcePolyData->GetCellPoints(aPartId,ptIds);
1106     vtkCell* aCell = theSourcePolyData->GetCell(aPartId);
1107     aPolyData->InsertNextCell(aCell->GetCellType(),ptIds);
1108     for (int i = 0, iEnd = aCell->GetNumberOfEdges(); i < iEnd; i++){
1109       vtkCell* anEdgeCell = aCell->GetEdge(i);
1110       aPolyData->InsertNextCell(VTK_LINE,anEdgeCell->GetPointIds());
1111     }
1112   }
1113   ptIds->Delete();
1114   theMapper->SetInput(aPolyData);  
1115   aPolyData->Delete();
1116 }
1117   
1118 bool VTKViewer_RenderWindowInteractor::highlightCell(const Handle(SALOME_InteractiveObject)& IObject, 
1119                                                      bool hilight, 
1120                                                      const TColStd_MapOfInteger& MapIndex, 
1121                                                      bool update )
1122 {
1123   return highlight(IObject,MapIndex,&CellCreateMapper,Cell_Actor,hilight,update);
1124 }
1125   
1126 void VTKViewer_RenderWindowInteractor::setCellData(const Handle(SALOME_InteractiveObject)& IObject, 
1127                                                    const int& theIndex, vtkActor* theActor )
1128 {
1129   TColStd_MapOfInteger MapIndex; MapIndex.Add(theIndex);
1130   return setActorData(IObject,MapIndex,&CellCreateMapper,theActor);
1131 }
1132   
1133 void VTKViewer_RenderWindowInteractor::setCellData(const Handle(SALOME_InteractiveObject)& IObject, 
1134                                                    const std::vector<int>& theIndexes, vtkActor* theActor )
1135 {
1136   TColStd_MapOfInteger MapIndex; 
1137   std::vector<int>::const_iterator it;
1138   for (it = theIndexes.begin(); it != theIndexes.end(); ++it)
1139     MapIndex.Add(*it);
1140   return setActorData(IObject,MapIndex,&CellCreateMapper,theActor);
1141 }
1142
1143
1144 static void PointCreateMapper(vtkPolyData *theSourcePolyData, vtkPolyDataMapper* theMapper, 
1145                        const TColStd_MapOfInteger& theMapIndex)
1146 {
1147   vtkPolyData* aPolyData = vtkPolyData::New();
1148   aPolyData->Allocate();
1149
1150   vtkPoints *aPoints = vtkPoints::New();
1151   vtkMaskPoints* aMaskPoints = vtkMaskPoints::New();
1152   TColStd_MapIteratorOfMapOfInteger ite(theMapIndex);
1153   aPoints->SetNumberOfPoints(theMapIndex.Extent());
1154   int aNbOfParts = theSourcePolyData->GetNumberOfPoints();
1155   for(int i = 0; ite.More(); ite.Next(),i++){
1156     int aPartId = ite.Key();
1157     if(0 > aPartId || aPartId >= aNbOfParts) break;
1158     aPoints->SetPoint(i,theSourcePolyData->GetPoint(aPartId));
1159   }
1160   aPolyData->SetPoints(aPoints);
1161   aPoints->Delete();
1162   aMaskPoints->SetInput(aPolyData);
1163   aMaskPoints->SetGenerateVertices(1);
1164   aMaskPoints->SetOnRatio(1);
1165   theMapper->SetInput(aMaskPoints->GetOutput());  
1166   aMaskPoints->Delete();
1167 }
1168   
1169 bool VTKViewer_RenderWindowInteractor::highlightPoint(const Handle(SALOME_InteractiveObject)& IObject, 
1170                                                       bool hilight, const TColStd_MapOfInteger& MapIndex, 
1171                                                       bool update)
1172 {
1173   return highlight(IObject,MapIndex,&PointCreateMapper,Point_Actor,hilight,update);
1174 }
1175   
1176   
1177 void VTKViewer_RenderWindowInteractor::setPointData(const Handle(SALOME_InteractiveObject)& IObject, 
1178                                                     const int& theIndex, vtkActor* theActor )
1179 {
1180   TColStd_MapOfInteger MapIndex; MapIndex.Add(theIndex);
1181   return setActorData(IObject,MapIndex,&PointCreateMapper,theActor);
1182 }
1183
1184   
1185 static void EdgeCreateMapper(vtkPolyData *theSourcePolyData, vtkPolyDataMapper* theMapper, 
1186                       const TColStd_MapOfInteger& theMapIndex)
1187 {
1188   vtkPolyData* aPolyData = vtkPolyData::New();
1189   aPolyData->Allocate();
1190
1191   vtkIdList *ptIds = vtkIdList::New(); 
1192   ptIds->Allocate(theSourcePolyData->GetMaxCellSize());
1193   vtkPolyDataMapper* aMapper = vtkPolyDataMapper::New();
1194   aPolyData->SetPoints(theSourcePolyData->GetPoints());
1195   int aCellId = -1, aCellCounter = 0;
1196   for(TColStd_MapIteratorOfMapOfInteger ite(theMapIndex); ite.More(); ite.Next()){
1197     if(ite.Key() > 0){
1198       aCellId = ite.Key();
1199       aCellCounter++;
1200     }
1201   }
1202   if(aCellCounter == 1){
1203     vtkCell* aCell = theSourcePolyData->GetCell(aCellId);
1204     if(aCell->GetCellType() <= VTK_LINE){
1205       aPolyData->InsertNextCell(aCell->GetCellType(),aCell->GetPointIds());
1206     }else{
1207       TColStd_MapIteratorOfMapOfInteger ite(theMapIndex);
1208       int aNbOfParts = aCell->GetNumberOfEdges();
1209       for(; ite.More(); ite.Next()){
1210         if(ite.Key() < 0){
1211           int aPartId = -ite.Key()-1;
1212           if(0 > aPartId || aPartId >= aNbOfParts) break;
1213           vtkCell* anEdgeCell = aCell->GetEdge(aPartId);
1214           aPolyData->InsertNextCell(VTK_LINE,anEdgeCell->GetPointIds());
1215         }
1216       }
1217     }
1218   }else{
1219     int aNbOfParts = theSourcePolyData->GetNumberOfCells();
1220     for(TColStd_MapIteratorOfMapOfInteger ite(theMapIndex); ite.More(); ite.Next()){
1221       if(ite.Key() > 0){
1222         int aPartId = ite.Key();
1223         if(0 > aPartId || aPartId >= aNbOfParts) break;
1224         vtkCell* aCell = theSourcePolyData->GetCell(aPartId);
1225         aPolyData->InsertNextCell(aCell->GetCellType(),aCell->GetPointIds());
1226       }
1227     }
1228   }
1229   ptIds->Delete();
1230   theMapper->SetInput(aPolyData);  
1231   aPolyData->Delete();
1232 }
1233   
1234
1235 bool VTKViewer_RenderWindowInteractor::highlightEdge( const Handle(SALOME_InteractiveObject)& IObject, 
1236                                                       bool hilight, 
1237                                                       const TColStd_MapOfInteger& MapIndex, 
1238                                                       bool update )
1239 {
1240   return highlight(IObject,MapIndex,&EdgeCreateMapper,Edge_Actor,hilight,update);
1241 }
1242   
1243 void VTKViewer_RenderWindowInteractor::setEdgeData(const Handle(SALOME_InteractiveObject)& IObject, 
1244                                                    const int& theCellIndex, const int& theEdgeIndex, 
1245                                                    vtkActor* theActor )
1246 {
1247   TColStd_MapOfInteger MapIndex; MapIndex.Add(theCellIndex); MapIndex.Add(theEdgeIndex);
1248   return setActorData(IObject,MapIndex,&EdgeCreateMapper,theActor);
1249 }