]> SALOME platform Git repositories - modules/gui.git/blob - src/SVTK/SALOME_Actor.cxx
Salome HOME
Merge from V6_main 11/02/2013
[modules/gui.git] / src / SVTK / SALOME_Actor.cxx
1 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  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.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 //  SALOME OBJECT : implementation of interactive object visualization for OCC and VTK viewers
24 //  File   : SALOME_Actor.cxx
25 //  Author : Nicolas REJNERI
26
27 /*!
28   \class SALOME_Actor SALOME_Actor.h
29   \brief Abstract class of SALOME Objects in VTK.
30 */
31
32
33 #include "SALOME_Actor.h"
34 #include "SALOME_InteractiveObject.hxx"
35
36 #include "VTKViewer_Algorithm.h"
37 #include "VTKViewer_Transform.h"
38 #include "VTKViewer_TransformFilter.h"
39 #include "VTKViewer_GeometryFilter.h"
40 #include "VTKViewer_FramedTextActor.h"
41 #include "SVTK_RectPicker.h"
42
43 #include "SVTK_Actor.h"
44
45 #include <SUIT_ResourceMgr.h>
46 #include <SUIT_Session.h>
47
48 // VTK Includes
49 #include <vtkCell.h>
50 #include <vtkLine.h>
51 #include <vtkPicker.h>
52 #include <vtkPointPicker.h>
53 #include <vtkCellPicker.h>
54 #include <vtkRenderer.h>
55 #include <vtkPolyData.h>
56 #include <vtkObjectFactory.h>
57 #include <vtkDataSetMapper.h>
58 #include <vtkPolyDataMapper.h>
59 #include <vtkProperty.h>
60 #include <vtkOutlineSource.h>
61
62 #include <vtkInteractorStyle.h>
63 #include <vtkRenderWindowInteractor.h>
64 #include <vtkPassThroughFilter.h>
65
66 #include <TColStd_MapOfInteger.hxx>
67 #include <TColStd_IndexedMapOfInteger.hxx>
68
69 #if defined __GNUC__
70   #if __GNUC__ == 2
71     #define __GNUC_2__
72   #endif
73 #endif
74
75 int SALOME_POINT_SIZE = 5;
76 int SALOME_LINE_WIDTH = 3;
77
78 namespace
79 {
80   int
81   GetEdgeId(SALOME_Actor* theActor,
82             vtkPicker* thePicker, 
83             int theObjId)
84   {
85     int anEdgeId = 0;
86     if (vtkCell* aPickedCell = theActor->GetElemCell(theObjId)) {
87       vtkFloatingPointType aPickPosition[3];
88       thePicker->GetPickPosition(aPickPosition);
89       vtkFloatingPointType aMinDist = 1000000.0, aDist = 0;
90       for (int i = 0, iEnd = aPickedCell->GetNumberOfEdges(); i < iEnd; i++){
91         if(vtkLine* aLine = vtkLine::SafeDownCast(aPickedCell->GetEdge(i))){
92           int subId;  
93           vtkFloatingPointType pcoords[3], closestPoint[3], weights[3];
94           aLine->EvaluatePosition(aPickPosition,closestPoint,subId,pcoords,aDist,weights);
95           if (aDist < aMinDist) {
96             aMinDist = aDist;
97             anEdgeId = -1 - i;
98           }
99         }
100       }
101     }
102     return anEdgeId;
103   }
104
105   inline
106   bool
107   CheckDimensionId(Selection_Mode theMode, 
108                    SALOME_Actor *theActor, 
109                    vtkIdType theObjId)
110   {
111     switch(theMode) {
112     case CellSelection:
113       return true;
114     case EdgeSelection:
115       return ( theActor->GetObjDimension( theObjId ) == 1 );
116     case FaceSelection:
117       return ( theActor->GetObjDimension( theObjId ) == 2 );
118     case VolumeSelection:
119       return ( theActor->GetObjDimension( theObjId ) == 3 );
120     case Elem0DSelection:        
121       return ((theActor->GetObjDimension( theObjId ) == 0) &&
122                theActor->GetElemCell(theObjId) && 
123               (theActor->GetElemCell(theObjId)->GetCellType() == VTK_VERTEX));
124     case BallSelection:
125       return ((theActor->GetObjDimension( theObjId ) == 0) &&
126                theActor->GetElemCell(theObjId) && 
127               (theActor->GetElemCell(theObjId)->GetCellType() == VTK_POLY_VERTEX));
128
129     };
130     return false;
131   }
132 }
133
134 namespace SVTK
135 {
136   /*!
137     Make picker work with this actor only
138   */
139   TPickLimiter::TPickLimiter(vtkAbstractPicker* picker, SALOME_Actor* actor):myPicker(picker)
140   {
141     myPicker->InitializePickList();
142     myPicker->AddPickList( actor );
143     myPicker->SetPickFromList( true );
144   }
145   /*!
146     Unlimit picking
147   */
148   TPickLimiter::~TPickLimiter()
149   {
150     myPicker->SetPickFromList( false );
151     myPicker->InitializePickList();
152   }
153 }
154
155
156 vtkStandardNewMacro(SALOME_Actor);
157
158 /*!
159   Constructor
160 */
161 SALOME_Actor
162 ::SALOME_Actor():
163   myRenderer(NULL),
164   myInteractor(NULL),
165   mySelectionMode(ActorSelection),
166   myPreHighlightActor(SVTK_Actor::New()),
167   myHighlightActor(SVTK_Actor::New()),
168   myOutline(vtkOutlineSource::New()),
169   myOutlineActor(VTKViewer_Actor::New()),
170   myIsDisplayNameActor(false),
171   myNameActor(VTKViewer_FramedTextActor::New())
172 {
173   myPreHighlightActor->Delete();
174   myPreHighlightActor->Initialize();
175   myPreHighlightActor->PickableOff();
176   myPreHighlightActor->SetVisibility( false );
177   myPreHighlightActor->SetCoincident3DAllowed(true);
178
179   myHighlightActor->Delete();
180   myHighlightActor->Initialize();
181   myHighlightActor->PickableOff();
182   myHighlightActor->SetVisibility( false );
183   myHighlightActor->SetCoincident3DAllowed(true);
184
185   myOutline->Delete();
186
187   vtkPolyDataMapper* anOutlineMapper = vtkPolyDataMapper::New();
188   anOutlineMapper->SetInput(myOutline->GetOutput());
189
190   myOutlineActor->Delete();
191   myOutlineActor->SetMapper( anOutlineMapper );
192   anOutlineMapper->Delete();
193
194   myOutlineActor->PickableOff();
195   myOutlineActor->DragableOff();
196   myOutlineActor->GetProperty()->SetColor(1.0,0.0,0.0);
197   myOutlineActor->GetProperty()->SetAmbient(1.0);
198   myOutlineActor->GetProperty()->SetDiffuse(0.0);
199   myOutlineActor->SetVisibility( false );
200
201   // Name actor
202   myNameActor->Delete();
203   myNameActor->SetVisibility(false);
204   myNameActor->SetPickable(false);
205   myNameActor->SetModePosition(VTKViewer_FramedTextActor::TopRight);
206   myNameActor->SetLayoutType(VTKViewer_FramedTextActor::Vertical);
207
208   SUIT_ResourceMgr* aResourceMgr = SUIT_Session::session()->resourceMgr();
209
210   QColor aForegroundColor = aResourceMgr->colorValue( "VTKViewer", "group_names_text_color", Qt::white );
211   myNameActor->SetForegroundColor(aForegroundColor.redF(),
212                                   aForegroundColor.greenF(),
213                                   aForegroundColor.blueF());
214
215   vtkFloatingPointType aGroupNamesTransparency = 0.5;
216   aGroupNamesTransparency = aResourceMgr->doubleValue( "VTKViewer", "group_names_transparency", aGroupNamesTransparency );
217   myNameActor->SetTransparency(aGroupNamesTransparency);
218 }
219
220 /*!
221   Destructor
222 */
223 SALOME_Actor
224 ::~SALOME_Actor()
225 {}
226
227
228 /*!
229   \return true if the SALOME_Actor has a reference to SALOME_InteractiveObject
230 */
231 Standard_Boolean 
232 SALOME_Actor
233 ::hasIO() 
234
235   return !myIO.IsNull(); 
236 }
237
238 /*!
239   \return correspoinding reference to SALOME_InteractiveObject
240 */
241 const Handle(SALOME_InteractiveObject)& 
242 SALOME_Actor
243 ::getIO()
244
245   return myIO; 
246 }
247
248 /*!
249   Sets reference to SALOME_InteractiveObject
250   \param theIO - new SALOME_InteractiveObject
251 */
252 void
253 SALOME_Actor
254 ::setIO(const Handle(SALOME_InteractiveObject)& theIO) 
255
256   myIO = theIO; 
257 }
258
259 /*!
260   Sets name the SALOME_Actor
261   \param theName - new name
262 */
263 void
264 SALOME_Actor
265 ::setName(const char* theName)
266 {
267   if(hasIO())   
268     myIO->setName(theName);
269   myNameActor->SetText(theName);
270   Superclass::setName(theName);
271 }
272
273
274 /*!
275   Publishes the actor in all its internal devices
276 */
277 void
278 SALOME_Actor
279 ::AddToRender(vtkRenderer* theRenderer)
280 {
281   Superclass::AddToRender(theRenderer);
282
283   myRenderer = theRenderer;
284
285   myHighlightActor->AddToRender(theRenderer);
286   myPreHighlightActor->AddToRender(theRenderer);
287   theRenderer->AddActor( myOutlineActor.GetPointer() );
288   theRenderer->AddActor( myNameActor.GetPointer() );
289 }
290
291 /*!
292   Removes the actor from all its internal devices
293 */
294 void 
295 SALOME_Actor
296 ::RemoveFromRender(vtkRenderer* theRenderer)
297 {
298   Superclass::RemoveFromRender(theRenderer);
299
300   myHighlightActor->RemoveFromRender(theRenderer);
301   myPreHighlightActor->RemoveFromRender(theRenderer);
302
303   theRenderer->RemoveActor( myPreHighlightActor.GetPointer() );
304   theRenderer->RemoveActor( myHighlightActor.GetPointer() );
305   theRenderer->RemoveActor( myOutlineActor.GetPointer() );
306   theRenderer->RemoveActor( myNameActor.GetPointer() );
307 }
308
309 /*!
310   \return reference on renderer where it is published
311 */
312 vtkRenderer*
313 SALOME_Actor
314 ::GetRenderer()
315 {
316   return myRenderer;
317 }
318
319 /*!
320   Sets interactor in order to use vtkInteractorObserver devices
321   \param theInteractor - new interactor
322 */
323 void
324 SALOME_Actor
325 ::SetInteractor(vtkRenderWindowInteractor* theInteractor)
326 {
327   myInteractor = theInteractor;
328 }
329
330 /*!
331   Put a request to redraw the view 
332 */
333 void
334 SALOME_Actor
335 ::Update()
336 {
337   myInteractor->CreateTimer(VTKI_TIMER_UPDATE);    
338 }
339
340 /*!
341   Apply view transformation
342   \param theTransform - transformation
343 */
344 void
345 SALOME_Actor
346 ::SetTransform(VTKViewer_Transform* theTransform)
347 {
348   Superclass::SetTransform(theTransform);
349
350   myPreHighlightActor->SetTransform(theTransform);
351   myHighlightActor->SetTransform(theTransform);
352   myOutlineActor->SetTransform(theTransform);
353 }
354
355 /*!
356   Apply additional position
357 */
358 void
359 SALOME_Actor
360 ::SetPosition(vtkFloatingPointType _arg1, 
361               vtkFloatingPointType _arg2, 
362               vtkFloatingPointType _arg3)
363 {
364   Superclass::SetPosition(_arg1,_arg2,_arg3);
365
366   myPreHighlightActor->SetPosition(_arg1,_arg2,_arg3);
367   myHighlightActor->SetPosition(_arg1,_arg2,_arg3);
368   myOutlineActor->SetPosition(_arg1,_arg2,_arg3);
369 }
370
371 /*!
372   Apply additional position
373 */
374 void
375 SALOME_Actor
376 ::SetPosition(vtkFloatingPointType _arg[3])
377 {
378   SetPosition(_arg[0],_arg[1],_arg[2]);
379 }
380
381 /*!
382   Shows/hides actor
383   \param theVisibility - new visibility state
384 */
385 void
386 SALOME_Actor
387 ::SetVisibility( int theVisibility )
388 {
389   Superclass::SetVisibility( theVisibility );
390
391   myOutlineActor->SetVisibility( theVisibility && isHighlighted() && !hasHighlight() );
392
393   myPreHighlightActor->SetVisibility( theVisibility && myIsPreselected );
394
395   if(mySelector.GetPointer() && hasIO()){
396     if(mySelector->SelectionMode() != ActorSelection){
397       int aHasIndex = mySelector->HasIndex( getIO() );
398       myHighlightActor->SetVisibility( theVisibility && isHighlighted() && aHasIndex);
399     }
400   }
401
402   UpdateNameActors();
403 }
404
405 /*!
406   Gets know whether the actor should be displayed or not
407 */
408 bool 
409 SALOME_Actor
410 ::ShouldBeDisplayed()
411 {
412   return true;
413 }
414
415 /*!
416   Set selector in order to the actor at any time can restore current selection
417   \param theSelector - new selector
418 */
419 void
420 SALOME_Actor
421 ::SetSelector(SVTK_Selector* theSelector)
422 {
423   mySelector = theSelector;
424 }
425
426 /*!
427   To map current selection to VTK representation
428 */
429 void
430 SALOME_Actor
431 ::Highlight(bool theIsHighlight)
432 {
433   mySelectionMode = mySelector->SelectionMode();
434   myHighlightActor->SetVisibility( false );
435   myOutlineActor->SetVisibility( false );
436
437   if(mySelector.GetPointer()){
438     if(mySelectionMode != ActorSelection){
439       TColStd_IndexedMapOfInteger aMapIndex;
440       mySelector->GetIndex( getIO(), aMapIndex );
441       switch( mySelectionMode ){
442       case NodeSelection:
443         myHighlightActor->GetProperty()->SetRepresentationToPoints();
444         myHighlightActor->MapPoints( this, aMapIndex );
445         break;
446       case EdgeOfCellSelection:
447         myHighlightActor->GetProperty()->SetRepresentationToWireframe();
448         myHighlightActor->MapEdge( this, aMapIndex );
449         break;
450       case CellSelection:
451       case EdgeSelection:
452       case FaceSelection:
453       case VolumeSelection:
454       case Elem0DSelection: 
455       case BallSelection: 
456         myHighlightActor->GetProperty()->SetRepresentationToSurface();
457         myHighlightActor->MapCells( this, aMapIndex );
458         break;
459       }
460       myHighlightActor->SetVisibility( GetVisibility() && theIsHighlight );
461     }
462   }
463
464   highlight(theIsHighlight);
465 }
466
467 /*!
468   Updates visibility of the highlight devices  
469 */
470 void
471 SALOME_Actor
472 ::highlight(bool theIsHighlight)
473 {
474   vtkFloatingPointType aBounds[6];
475   vtkDataSet * aDataSet = GetHighlightedDataSet();
476   aDataSet->GetBounds(aBounds);
477   myOutline->SetBounds(aBounds);
478   myOutlineActor->SetVisibility( GetVisibility() && theIsHighlight );
479
480   Superclass::highlight(theIsHighlight);
481 }
482
483
484 /*!
485   To process prehighlight (called from SVTK_InteractorStyle)
486 */
487 bool
488 SALOME_Actor
489 ::PreHighlight(vtkInteractorStyle *theInteractorStyle, 
490                SVTK_SelectionEvent* theSelectionEvent,
491                bool theIsHighlight)
492 {
493   if ( !GetPickable() )
494     return false;
495       
496   vtkRenderer *aRenderer = theInteractorStyle->GetCurrentRenderer();
497   //
498   myPreHighlightActor->SetVisibility( false );
499   bool anIsPreselected = myIsPreselected;
500   SetPreSelected( false );
501
502   Selection_Mode aSelectionMode = theSelectionEvent->mySelectionMode;
503   bool anIsChanged = (mySelectionMode != aSelectionMode);
504
505   myPreHighlightActor->SetMarkerEnabled( aSelectionMode == NodeSelection );
506
507   vtkFloatingPointType x = theSelectionEvent->myX;
508   vtkFloatingPointType y = theSelectionEvent->myY;
509   vtkFloatingPointType z = 0.0;
510
511   if( !theIsHighlight ) {
512     if ( hasIO() ) {
513       VTK::ActorCollectionCopy aCopy(aRenderer->GetActors());
514       vtkActorCollection* theActors = aCopy.GetActors();
515       theActors->InitTraversal();
516       while( vtkActor *ac = theActors->GetNextActor() )
517         if( SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( ac ) )
518           if( anActor->hasIO() && myIO->isSame( anActor->getIO() ) )
519             anActor->SetPreSelected( false );
520     }
521   }else{
522     switch(aSelectionMode) {
523     case NodeSelection: 
524     {
525       SVTK::TPickLimiter aPickLimiter( myPointPicker, this );
526       myPointPicker->Pick( x, y, z, aRenderer );
527       
528       int aVtkId = myPointPicker->GetPointId();
529       if( aVtkId >= 0 && mySelector->IsValid( this, aVtkId, true ) ) {
530         int anObjId = GetNodeObjId( aVtkId );
531         myIsPreselected = (anObjId >= 0);
532         if(myIsPreselected){
533           const TColStd_IndexedMapOfInteger& aMapIndex = myPreHighlightActor->GetMapIndex();
534           int anExtent = aMapIndex.Extent();
535           anIsChanged |= (anExtent == 0 || (anExtent > 0 && anObjId != aMapIndex(1)));
536           if(anIsChanged){
537             TColStd_IndexedMapOfInteger aMapIndex;
538             aMapIndex.Add( anObjId );
539             
540             myPreHighlightActor->GetProperty()->SetRepresentationToPoints();
541             myPreHighlightActor->MapPoints( this, aMapIndex );
542           }
543           myPreHighlightActor->SetVisibility( true );
544         }
545       }
546       break;
547     }
548     case CellSelection: 
549     case EdgeSelection:
550     case FaceSelection:
551     case VolumeSelection: 
552     case Elem0DSelection:        
553     case BallSelection: 
554     {
555       SVTK::TPickLimiter aPickLimiter( myCellPicker, this );
556       myCellPicker->Pick( x, y, z, aRenderer );
557       
558       int aVtkId = myCellPicker->GetCellId();
559       if ( aVtkId >= 0 && mySelector->IsValid( this, aVtkId ) && hasIO() ) {
560         int anObjId = GetElemObjId (aVtkId );
561         if ( anObjId >= 0 ) {
562           myIsPreselected = CheckDimensionId(aSelectionMode,this,anObjId);
563           if(myIsPreselected){
564             const TColStd_IndexedMapOfInteger& aMapIndex = myPreHighlightActor->GetMapIndex();
565             int anExtent = aMapIndex.Extent();
566             anIsChanged |= (anExtent == 0 || (anExtent > 0 && anObjId != aMapIndex(1)));
567             if(anIsChanged){
568               TColStd_IndexedMapOfInteger aMapIndex;
569               aMapIndex.Add( anObjId );
570               
571               myPreHighlightActor->GetProperty()->SetRepresentationToSurface();
572               myPreHighlightActor->MapCells( this, aMapIndex );
573             }
574             myPreHighlightActor->SetVisibility( true );
575           }
576         }
577       }
578       break;
579     }
580     case EdgeOfCellSelection:
581     {
582       SVTK::TPickLimiter aPickLimiter( myCellPicker, this );
583       myCellPicker->Pick( x, y, z, aRenderer );
584       
585       int aVtkId = myCellPicker->GetCellId();
586       if ( aVtkId >= 0 && mySelector->IsValid( this, aVtkId )) {
587         int anObjId = GetElemObjId( aVtkId );
588         if ( anObjId >= 0 ) {
589           int anEdgeId = GetEdgeId(this,myCellPicker.GetPointer(),anObjId);
590           myIsPreselected = anEdgeId < 0;
591           if(myIsPreselected){
592             const TColStd_IndexedMapOfInteger& aMapIndex = myPreHighlightActor->GetMapIndex();
593             int anExtent = aMapIndex.Extent();
594             anIsChanged |= (anExtent == 0 || anExtent == 1);
595             anIsChanged |= (anExtent == 2 && (anObjId != aMapIndex(1) || anEdgeId != aMapIndex(2)));
596             if(anIsChanged){
597               TColStd_IndexedMapOfInteger aMapIndex;
598               aMapIndex.Add( anObjId );
599               aMapIndex.Add( anEdgeId );
600
601               myPreHighlightActor->GetProperty()->SetRepresentationToWireframe();
602               myPreHighlightActor->MapEdge( this, aMapIndex );
603             }
604             myPreHighlightActor->SetVisibility( true );
605           }
606         }
607       }
608       break;
609     }
610     case ActorSelection : 
611     {
612       if( !mySelector->IsSelected( myIO ) ) {
613         SetPreSelected( true );
614
615         if ( hasIO() ) {
616           VTK::ActorCollectionCopy aCopy(aRenderer->GetActors());
617           vtkActorCollection* theActors = aCopy.GetActors();
618           theActors->InitTraversal();
619           while( vtkActor *anAct = theActors->GetNextActor() ) {
620             if( anAct != this )
621               if( SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( anAct ) )
622                 if( anActor->hasIO() && myIO->isSame( anActor->getIO() ) )
623                   anActor->SetPreSelected( true );
624           }
625         }
626       }
627     }
628     default:
629       break;
630     }
631   }
632
633   mySelectionMode = aSelectionMode;
634   anIsChanged |= (anIsPreselected != myIsPreselected);
635
636   return anIsChanged;
637 }
638
639 /*!
640   To process highlight (called from SVTK_InteractorStyle)
641 */
642 bool
643 SALOME_Actor
644 ::Highlight(vtkInteractorStyle *theInteractorStyle, 
645             SVTK_SelectionEvent* theSelectionEvent,
646             bool theIsHighlight)
647 {
648   if ( !GetPickable() || !mySelector )
649     return false;
650
651   myOutlineActor->SetVisibility( false );
652   myHighlightActor->SetVisibility( false );
653
654   vtkRenderer *aRenderer = theInteractorStyle->GetCurrentRenderer();
655   //
656   Selection_Mode aSelectionMode = theSelectionEvent->mySelectionMode;
657   bool anIsShift = theSelectionEvent->myIsShift;
658   if( !anIsShift || !theIsHighlight ) {
659     mySelector->RemoveIObject( this );
660   }
661
662   if ( !theIsHighlight )
663     return true;
664
665   myHighlightActor->SetMarkerEnabled( aSelectionMode == NodeSelection );
666
667   vtkFloatingPointType x = theSelectionEvent->myX;
668   vtkFloatingPointType y = theSelectionEvent->myY;
669   vtkFloatingPointType z = 0.0;
670
671   if( !theSelectionEvent->myIsRectangle ) {
672     switch(aSelectionMode){
673     case NodeSelection: {
674       SVTK::TPickLimiter aPickLimiter( myPointPicker, this );
675       myPointPicker->Pick( x, y, z, aRenderer );
676
677       int aVtkId = myPointPicker->GetPointId();
678       if( aVtkId >= 0 && mySelector->IsValid( this, aVtkId, true ) ) {
679         int anObjId = GetNodeObjId( aVtkId );
680         if( hasIO() && anObjId >= 0 ) {
681           mySelector->AddOrRemoveIndex( myIO, anObjId, anIsShift );
682           mySelector->AddIObject( this );
683         }
684       }
685       break;
686     }
687     case CellSelection: 
688     case EdgeSelection:
689     case FaceSelection:
690     case VolumeSelection: 
691     case Elem0DSelection:        
692     case BallSelection: 
693     {
694       SVTK::TPickLimiter aPickLimiter( myCellPicker, this );
695       myCellPicker->Pick( x, y, z, aRenderer );
696     
697       int aVtkId = myCellPicker->GetCellId();
698       if( aVtkId >= 0 && mySelector->IsValid( this, aVtkId ) ) {
699         int anObjId = GetElemObjId( aVtkId );
700         if( anObjId >= 0 ) {
701           if ( hasIO() && CheckDimensionId(aSelectionMode,this,anObjId) ) {
702             mySelector->AddOrRemoveIndex( myIO, anObjId, anIsShift );
703             mySelector->AddIObject( this );
704           }
705         }
706       }
707       break;
708     }
709     case EdgeOfCellSelection: 
710     {
711       SVTK::TPickLimiter aPickLimiter( myCellPicker, this );
712       myCellPicker->Pick( x, y, z, aRenderer );
713     
714       int aVtkId = myCellPicker->GetCellId();
715       if( aVtkId >= 0 && mySelector->IsValid( this, aVtkId ) ) {
716         int anObjId = GetElemObjId( aVtkId );
717         if( anObjId >= 0 ) {
718           int anEdgeId = GetEdgeId(this,myCellPicker.GetPointer(),anObjId);
719           if( hasIO() && anEdgeId < 0 ) {
720             mySelector->AddOrRemoveIndex( myIO, anObjId, false );
721             mySelector->AddOrRemoveIndex( myIO, anEdgeId, true );
722             mySelector->AddIObject( this );
723           } 
724         }
725       }
726       break;
727     }
728     case ActorSelection : 
729     {
730       if ( hasIO() ) {
731         if( mySelector->IsSelected( myIO ) && anIsShift )
732           mySelector->RemoveIObject( this );
733         else {
734           mySelector->AddIObject( this );
735         }
736       }
737       break;
738     }
739     default:
740       break;
741     }
742   }else{
743     vtkFloatingPointType xLast = theSelectionEvent->myLastX;
744     vtkFloatingPointType yLast = theSelectionEvent->myLastY;
745     vtkFloatingPointType zLast = 0.0;
746
747     vtkFloatingPointType x1 = x < xLast ? x : xLast;
748     vtkFloatingPointType y1 = y < yLast ? y : yLast;
749     vtkFloatingPointType z1 = z < zLast ? z : zLast;
750     vtkFloatingPointType x2 = x > xLast ? x : xLast;
751     vtkFloatingPointType y2 = y > yLast ? y : yLast;
752     vtkFloatingPointType z2 = z > zLast ? z : zLast;
753
754     switch(aSelectionMode){
755     case NodeSelection: {
756
757       SVTK::TPickLimiter aPickLimiter( myPointRectPicker, this );
758       myPointRectPicker->Pick( x1, y1, z1, x2, y2, z2, aRenderer );
759
760       const SVTK_RectPicker::TVectorIdsMap& aVectorIdsMap = myPointRectPicker->GetPointIdsMap();
761       SVTK_RectPicker::TVectorIdsMap::const_iterator aMapIter = aVectorIdsMap.find(this);
762       TColStd_MapOfInteger anIndexes;
763       if(aMapIter != aVectorIdsMap.end()){
764         const SVTK_RectPicker::TVectorIds& aVectorIds = aMapIter->second;
765         vtkIdType anEnd = aVectorIds.size();
766         for(vtkIdType anId = 0; anId < anEnd; anId++ ) {
767           int aPointId = aVectorIds[anId];
768           if( aPointId >= 0 && mySelector->IsValid( this, aPointId, true ) ) {
769             int anObjId = GetNodeObjId( aPointId );
770             anIndexes.Add( anObjId );
771           }
772         }
773       }
774       
775       if ( hasIO() ) {
776         if( !anIndexes.IsEmpty() ) {
777           mySelector->AddOrRemoveIndex( myIO, anIndexes, anIsShift );
778           mySelector->AddIObject( this );
779           anIndexes.Clear();
780         }
781         else if ( !anIsShift )
782           mySelector->RemoveIObject( this );
783       }
784       break;
785     }
786     case ActorSelection :
787     {
788       vtkFloatingPointType aPnt[3];
789       vtkFloatingPointType* aBounds = GetBounds();
790
791       bool anIsPicked = true;
792       for( int i = 0; i <= 1; i++ ) {
793         for( int j = 2; j <= 3; j++ ) {
794           for( int k = 4; k <= 5; k++ ) {
795             aRenderer->SetWorldPoint( aBounds[ i ], aBounds[ j ], aBounds[ k ], 1.0 );
796             aRenderer->WorldToDisplay();
797             aRenderer->GetDisplayPoint( aPnt );
798
799             if( aPnt[0] < x1 || aPnt[0] > x2 || aPnt[1] < y1 || aPnt[1] > y2 ) {
800               anIsPicked = false;
801               break;
802             }
803           }
804         }
805       }
806
807       if( anIsPicked )
808         mySelector->AddIObject(this);
809
810       break;
811     }
812     case CellSelection: 
813     case EdgeSelection:
814     case FaceSelection:
815     case VolumeSelection: 
816     case Elem0DSelection:        
817     case BallSelection: 
818     {
819       SVTK::TPickLimiter aPickLimiter( myCellRectPicker, this );
820       myCellRectPicker->Pick( x1, y1, z1, x2, y2, z2, aRenderer );
821
822       const SVTK_RectPicker::TVectorIdsMap& aVectorIdsMap = myCellRectPicker->GetCellIdsMap();
823       SVTK_RectPicker::TVectorIdsMap::const_iterator aMapIter = aVectorIdsMap.find(this);
824       TColStd_MapOfInteger anIndexes;
825       if(aMapIter != aVectorIdsMap.end()){
826         const SVTK_RectPicker::TVectorIds& aVectorIds = aMapIter->second;
827         vtkIdType anEnd = aVectorIds.size();
828         for(vtkIdType anId = 0; anId < anEnd; anId++ ) {
829           int aCellId = aVectorIds[anId];
830           if ( !mySelector->IsValid( this, aCellId ) )
831             continue;
832
833           int anObjId = GetElemObjId( aCellId );
834           if( anObjId != -1 )
835             if ( CheckDimensionId(aSelectionMode,this,anObjId) ) {
836               anIndexes.Add(anObjId);
837             }
838         }
839       }
840       
841       if ( hasIO() ) {
842         if( !anIndexes.IsEmpty() ) {
843           mySelector->AddOrRemoveIndex( myIO, anIndexes, anIsShift );
844           mySelector->AddIObject( this );
845           anIndexes.Clear();
846         }
847         else if ( !anIsShift )
848           mySelector->RemoveIObject( this );
849       }
850     }
851     default:
852       break;
853     }
854   }
855
856   mySelectionMode = aSelectionMode;
857
858   return true;
859 }
860
861 /*!
862   To get flag of displaying of name actor
863   \return flag to display or not to display name actor
864 */
865 bool
866 SALOME_Actor
867 ::IsDisplayNameActor() const
868 {
869   return myIsDisplayNameActor;
870 }
871
872 /*!
873   To set flag of displaying of name actor
874   \param theIsDisplayNameActor flag to display or not to display name actor
875 */
876 void
877 SALOME_Actor
878 ::SetIsDisplayNameActor(bool theIsDisplayNameActor)
879 {
880   SUIT_ResourceMgr* aResourceMgr = SUIT_Session::session()->resourceMgr();
881   bool isShowGroupNames = aResourceMgr->booleanValue("VTKViewer", "show_group_names", false);
882   myIsDisplayNameActor = theIsDisplayNameActor && isShowGroupNames;
883   UpdateNameActors();
884 }
885
886 /*!
887   To set text of name actor
888   \param theText - text of name actor
889 */
890 void
891 SALOME_Actor
892 ::SetNameActorText(const char* theText)
893 {
894   myNameActor->SetText(theText);
895 }
896
897 /*!
898   To set offset of name actor
899   \param theOffset - offset of name actor
900 */
901 void
902 SALOME_Actor
903 ::SetNameActorOffset(int theOffset[2])
904 {
905   myNameActor->SetOffset(theOffset);
906 }
907
908 /*!
909   To get size of name actor
910   \param theRenderer - renderer
911   \param theSize - size of name actor
912 */
913 void
914 SALOME_Actor
915 ::GetNameActorSize(vtkRenderer* theRenderer, int theSize[2]) const
916 {
917   myNameActor->GetSize(theRenderer, theSize);
918 }
919
920 /*!
921   Update visibility of name actors
922 */
923 void
924 SALOME_Actor
925 ::UpdateNameActors()
926 {
927   if( vtkRenderer* aRenderer = GetRenderer() )
928   {
929     int anOffset[2] = { 0, 0 };
930     VTK::ActorCollectionCopy aCopy(aRenderer->GetActors());
931     vtkActorCollection* aCollection = aCopy.GetActors();
932     for( int anIndex = 0, aNbItems = aCollection->GetNumberOfItems(); anIndex < aNbItems; anIndex++ )
933     {
934       if( SALOME_Actor* anActor = dynamic_cast<SALOME_Actor*>( aCollection->GetItemAsObject( anIndex ) ) )
935       {
936         if( anActor->IsDisplayNameActor() )
937         {
938           anActor->SetNameActorOffset( anOffset );
939           if( anActor->GetVisibility() )
940           {
941             int aSize[2];
942             anActor->GetNameActorSize( aRenderer, aSize );
943             anOffset[0] = anOffset[0] + aSize[0];
944             anOffset[1] = anOffset[1] + aSize[1];
945           }
946         }
947       }
948     }
949   }
950   myNameActor->SetVisibility( GetVisibility() && IsDisplayNameActor() );
951 }
952
953 /*!
954   To set up a picker for nodal selection (initialized by SVTK_Renderer::AddActor)
955   \param thePointPicker - new picker
956 */
957 void
958 SALOME_Actor
959 ::SetPointPicker(vtkPointPicker* thePointPicker) 
960 {
961   myPointPicker = thePointPicker;
962 }
963
964 /*!
965   To set up a picker for cell selection (initialized by SVTK_Renderer::AddActor)
966   \param theCellPicker - new picker
967 */
968 void
969 SALOME_Actor
970 ::SetCellPicker(vtkCellPicker* theCellPicker) 
971 {
972   myCellPicker = theCellPicker;
973 }
974
975 /*!
976   To set up a picker for point rectangle selection (initialized by SVTK_Renderer::AddActor)
977   \param theRectPicker - new picker
978 */
979 void
980 SALOME_Actor
981 ::SetPointRectPicker(SVTK_RectPicker* theRectPicker) 
982 {
983   myPointRectPicker = theRectPicker;
984 }
985
986 /*!
987   To set up a picker for cell rectangle selection (initialized by SVTK_Renderer::AddActor)
988   \param theRectPicker - new picker
989 */
990 void
991 SALOME_Actor
992 ::SetCellRectPicker(SVTK_RectPicker* theRectPicker) 
993 {
994   myCellRectPicker = theRectPicker;
995 }
996
997 /*!
998   To set up a prehighlight property (initialized by SVTK_Renderer::AddActor)
999 */
1000 void
1001 SALOME_Actor
1002 ::SetPreHighlightProperty(vtkProperty* theProperty) 
1003 {
1004   myPreHighlightActor->SetProperty(theProperty);
1005 }
1006
1007 /*!
1008   To set up a highlight property (initialized by SVTK_Renderer::AddActor)
1009 */
1010 void
1011 SALOME_Actor
1012 ::SetHighlightProperty(vtkProperty* theProperty) 
1013 {
1014   myHighlightActor->SetProperty(theProperty);
1015 }
1016
1017 /*!
1018   Set standard point marker
1019   \param theMarkerType type of the marker
1020   \param theMarkerScale scale of the marker
1021 */
1022 void
1023 SALOME_Actor
1024 ::SetMarkerStd( VTK::MarkerType theMarkerType, VTK::MarkerScale theMarkerScale )
1025 {
1026   myPreHighlightActor->SetMarkerStd( theMarkerType, theMarkerScale );
1027   myHighlightActor->SetMarkerStd( theMarkerType, theMarkerScale );
1028 }
1029
1030 /*!
1031   Set custom point marker
1032   \param theMarkerId id of the marker texture
1033   \param theMarkerTexture marker texture
1034 */
1035 void
1036 SALOME_Actor
1037 ::SetMarkerTexture( int theMarkerId, VTK::MarkerTexture theMarkerTexture )
1038 {
1039   myPreHighlightActor->SetMarkerTexture( theMarkerId, theMarkerTexture );
1040   myHighlightActor->SetMarkerTexture( theMarkerId, theMarkerTexture );
1041 }
1042
1043 /*!
1044   Get type of the point marker
1045   \return type of the point marker
1046 */
1047 VTK::MarkerType
1048 SALOME_Actor
1049 ::GetMarkerType()
1050 {
1051   return myPreHighlightActor->GetMarkerType();
1052 }
1053
1054 /*!
1055   Get scale of the point marker
1056   \return scale of the point marker
1057 */
1058 VTK::MarkerScale
1059 SALOME_Actor
1060 ::GetMarkerScale()
1061 {
1062   return myPreHighlightActor->GetMarkerScale();
1063 }
1064
1065 /*!
1066   Get texture identifier of the point marker
1067   \return texture identifier of the point marker
1068  */
1069 int
1070 SALOME_Actor
1071 ::GetMarkerTexture()
1072 {
1073   return myPreHighlightActor->GetMarkerTexture();
1074 }