Back to index

salome-gui  6.5.0
SALOME_Actor.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 //  SALOME OBJECT : implementation of interactive object visualization for OCC and VTK viewers
00024 //  File   : SALOME_Actor.cxx
00025 //  Author : Nicolas REJNERI
00026 
00033 #include "SALOME_Actor.h"
00034 #include "SALOME_InteractiveObject.hxx"
00035 
00036 #include "VTKViewer_Algorithm.h"
00037 #include "VTKViewer_Transform.h"
00038 #include "VTKViewer_TransformFilter.h"
00039 #include "VTKViewer_GeometryFilter.h"
00040 #include "VTKViewer_FramedTextActor.h"
00041 #include "SVTK_RectPicker.h"
00042 
00043 #include "SVTK_Actor.h"
00044 
00045 #include <SUIT_ResourceMgr.h>
00046 #include <SUIT_Session.h>
00047 
00048 // VTK Includes
00049 #include <vtkCell.h>
00050 #include <vtkLine.h>
00051 #include <vtkPicker.h>
00052 #include <vtkPointPicker.h>
00053 #include <vtkCellPicker.h>
00054 #include <vtkRenderer.h>
00055 #include <vtkPolyData.h>
00056 #include <vtkObjectFactory.h>
00057 #include <vtkDataSetMapper.h>
00058 #include <vtkPolyDataMapper.h>
00059 #include <vtkProperty.h>
00060 #include <vtkOutlineSource.h>
00061 
00062 #include <vtkInteractorStyle.h>
00063 #include <vtkRenderWindowInteractor.h>
00064 #include <vtkPassThroughFilter.h>
00065 
00066 #include <TColStd_MapOfInteger.hxx>
00067 #include <TColStd_IndexedMapOfInteger.hxx>
00068 
00069 #if defined __GNUC__
00070   #if __GNUC__ == 2
00071     #define __GNUC_2__
00072   #endif
00073 #endif
00074 
00075 int SALOME_POINT_SIZE = 5;
00076 int SALOME_LINE_WIDTH = 3;
00077 
00078 namespace
00079 {
00080   int
00081   GetEdgeId(SALOME_Actor* theActor,
00082             vtkPicker* thePicker, 
00083             int theObjId)
00084   {
00085     int anEdgeId = 0;
00086     if (vtkCell* aPickedCell = theActor->GetElemCell(theObjId)) {
00087       vtkFloatingPointType aPickPosition[3];
00088       thePicker->GetPickPosition(aPickPosition);
00089       vtkFloatingPointType aMinDist = 1000000.0, aDist = 0;
00090       for (int i = 0, iEnd = aPickedCell->GetNumberOfEdges(); i < iEnd; i++){
00091         if(vtkLine* aLine = vtkLine::SafeDownCast(aPickedCell->GetEdge(i))){
00092           int subId;  
00093           vtkFloatingPointType pcoords[3], closestPoint[3], weights[3];
00094           aLine->EvaluatePosition(aPickPosition,closestPoint,subId,pcoords,aDist,weights);
00095           if (aDist < aMinDist) {
00096             aMinDist = aDist;
00097             anEdgeId = -1 - i;
00098           }
00099         }
00100       }
00101     }
00102     return anEdgeId;
00103   }
00104 
00105   inline
00106   bool
00107   CheckDimensionId(Selection_Mode theMode, 
00108                    SALOME_Actor *theActor, 
00109                    vtkIdType theObjId)
00110   {
00111     switch(theMode){
00112     case CellSelection:
00113       return true;
00114     case EdgeSelection:
00115       return ( theActor->GetObjDimension( theObjId ) == 1 );
00116     case FaceSelection:
00117       return ( theActor->GetObjDimension( theObjId ) == 2 );
00118     case VolumeSelection:
00119       return ( theActor->GetObjDimension( theObjId ) == 3 );
00120     };
00121     return false;
00122   }
00123 }
00124 
00125 namespace SVTK
00126 {
00130   TPickLimiter::TPickLimiter(vtkAbstractPicker* picker, SALOME_Actor* actor):myPicker(picker)
00131   {
00132     myPicker->InitializePickList();
00133     myPicker->AddPickList( actor );
00134     myPicker->SetPickFromList( true );
00135   }
00139   TPickLimiter::~TPickLimiter()
00140   {
00141     myPicker->SetPickFromList( false );
00142     myPicker->InitializePickList();
00143   }
00144 }
00145 
00146 
00147 vtkStandardNewMacro(SALOME_Actor);
00148 
00152 SALOME_Actor
00153 ::SALOME_Actor():
00154   myRenderer(NULL),
00155   myInteractor(NULL),
00156   mySelectionMode(ActorSelection),
00157   myPreHighlightActor(SVTK_Actor::New()),
00158   myHighlightActor(SVTK_Actor::New()),
00159   myOutline(vtkOutlineSource::New()),
00160   myOutlineActor(VTKViewer_Actor::New()),
00161   myIsDisplayNameActor(false),
00162   myNameActor(VTKViewer_FramedTextActor::New())
00163 {
00164   myPreHighlightActor->Delete();
00165   myPreHighlightActor->Initialize();
00166   myPreHighlightActor->PickableOff();
00167   myPreHighlightActor->SetVisibility( false );
00168   myPreHighlightActor->SetCoincident3DAllowed(true);
00169 
00170   myHighlightActor->Delete();
00171   myHighlightActor->Initialize();
00172   myHighlightActor->PickableOff();
00173   myHighlightActor->SetVisibility( false );
00174   myHighlightActor->SetCoincident3DAllowed(true);
00175 
00176   myOutline->Delete();
00177 
00178   vtkPolyDataMapper* anOutlineMapper = vtkPolyDataMapper::New();
00179   anOutlineMapper->SetInput(myOutline->GetOutput());
00180 
00181   myOutlineActor->Delete();
00182   myOutlineActor->SetMapper( anOutlineMapper );
00183   anOutlineMapper->Delete();
00184 
00185   myOutlineActor->PickableOff();
00186   myOutlineActor->DragableOff();
00187   myOutlineActor->GetProperty()->SetColor(1.0,0.0,0.0);
00188   myOutlineActor->GetProperty()->SetAmbient(1.0);
00189   myOutlineActor->GetProperty()->SetDiffuse(0.0);
00190   myOutlineActor->SetVisibility( false );
00191 
00192   // Name actor
00193   myNameActor->Delete();
00194   myNameActor->SetVisibility(false);
00195   myNameActor->SetPickable(false);
00196   myNameActor->SetModePosition(VTKViewer_FramedTextActor::TopRight);
00197   myNameActor->SetLayoutType(VTKViewer_FramedTextActor::Vertical);
00198 
00199   SUIT_ResourceMgr* aResourceMgr = SUIT_Session::session()->resourceMgr();
00200 
00201   QColor aForegroundColor = aResourceMgr->colorValue( "VTKViewer", "group_names_text_color", Qt::white );
00202   myNameActor->SetForegroundColor(aForegroundColor.redF(),
00203                                   aForegroundColor.greenF(),
00204                                   aForegroundColor.blueF());
00205 
00206   vtkFloatingPointType aGroupNamesTransparency = 0.5;
00207   aGroupNamesTransparency = aResourceMgr->doubleValue( "VTKViewer", "group_names_transparency", aGroupNamesTransparency );
00208   myNameActor->SetTransparency(aGroupNamesTransparency);
00209 }
00210 
00214 SALOME_Actor
00215 ::~SALOME_Actor()
00216 {}
00217 
00218 
00222 Standard_Boolean 
00223 SALOME_Actor
00224 ::hasIO() 
00225 { 
00226   return !myIO.IsNull(); 
00227 }
00228 
00232 const Handle(SALOME_InteractiveObject)& 
00233 SALOME_Actor
00234 ::getIO()
00235 { 
00236   return myIO; 
00237 }
00238 
00243 void
00244 SALOME_Actor
00245 ::setIO(const Handle(SALOME_InteractiveObject)& theIO) 
00246 { 
00247   myIO = theIO; 
00248 }
00249 
00254 void
00255 SALOME_Actor
00256 ::setName(const char* theName)
00257 {
00258   if(hasIO())   
00259     myIO->setName(theName);
00260   myNameActor->SetText(theName);
00261   Superclass::setName(theName);
00262 }
00263 
00264 
00268 void
00269 SALOME_Actor
00270 ::AddToRender(vtkRenderer* theRenderer)
00271 {
00272   Superclass::AddToRender(theRenderer);
00273 
00274   myRenderer = theRenderer;
00275 
00276   theRenderer->AddActor( myPreHighlightActor.GetPointer() );
00277   theRenderer->AddActor( myHighlightActor.GetPointer() );
00278   theRenderer->AddActor( myOutlineActor.GetPointer() );
00279   theRenderer->AddActor( myNameActor.GetPointer() );
00280 }
00281 
00285 void 
00286 SALOME_Actor
00287 ::RemoveFromRender(vtkRenderer* theRenderer)
00288 {
00289   Superclass::RemoveFromRender(theRenderer);
00290 
00291   theRenderer->RemoveActor( myPreHighlightActor.GetPointer() );
00292   theRenderer->RemoveActor( myHighlightActor.GetPointer() );
00293   theRenderer->RemoveActor( myOutlineActor.GetPointer() );
00294   theRenderer->RemoveActor( myNameActor.GetPointer() );
00295 }
00296 
00300 vtkRenderer*
00301 SALOME_Actor
00302 ::GetRenderer()
00303 {
00304   return myRenderer;
00305 }
00306 
00311 void
00312 SALOME_Actor
00313 ::SetInteractor(vtkRenderWindowInteractor* theInteractor)
00314 {
00315   myInteractor = theInteractor;
00316 }
00317 
00321 void
00322 SALOME_Actor
00323 ::Update()
00324 {
00325   myInteractor->CreateTimer(VTKI_TIMER_UPDATE);    
00326 }
00327 
00332 void
00333 SALOME_Actor
00334 ::SetTransform(VTKViewer_Transform* theTransform)
00335 {
00336   Superclass::SetTransform(theTransform);
00337 
00338   myPreHighlightActor->SetTransform(theTransform);
00339   myHighlightActor->SetTransform(theTransform);
00340   myOutlineActor->SetTransform(theTransform);
00341 }
00342 
00346 void
00347 SALOME_Actor
00348 ::SetPosition(vtkFloatingPointType _arg1, 
00349               vtkFloatingPointType _arg2, 
00350               vtkFloatingPointType _arg3)
00351 {
00352   Superclass::SetPosition(_arg1,_arg2,_arg3);
00353 
00354   myPreHighlightActor->SetPosition(_arg1,_arg2,_arg3);
00355   myHighlightActor->SetPosition(_arg1,_arg2,_arg3);
00356   myOutlineActor->SetPosition(_arg1,_arg2,_arg3);
00357 }
00358 
00362 void
00363 SALOME_Actor
00364 ::SetPosition(vtkFloatingPointType _arg[3])
00365 {
00366   SetPosition(_arg[0],_arg[1],_arg[2]);
00367 }
00368 
00373 void
00374 SALOME_Actor
00375 ::SetVisibility( int theVisibility )
00376 {
00377   Superclass::SetVisibility( theVisibility );
00378 
00379   myOutlineActor->SetVisibility( theVisibility && isHighlighted() && !hasHighlight() );
00380 
00381   myPreHighlightActor->SetVisibility( theVisibility && myIsPreselected );
00382 
00383   if(mySelector.GetPointer() && hasIO()){
00384     if(mySelector->SelectionMode() != ActorSelection){
00385       int aHasIndex = mySelector->HasIndex( getIO() );
00386       myHighlightActor->SetVisibility( theVisibility && isHighlighted() && aHasIndex);
00387     }
00388   }
00389 
00390   UpdateNameActors();
00391 }
00392 
00396 bool 
00397 SALOME_Actor
00398 ::ShouldBeDisplayed()
00399 {
00400   return true;
00401 }
00402 
00407 void
00408 SALOME_Actor
00409 ::SetSelector(SVTK_Selector* theSelector)
00410 {
00411   mySelector = theSelector;
00412 }
00413 
00417 void
00418 SALOME_Actor
00419 ::Highlight(bool theIsHighlight)
00420 {
00421   mySelectionMode = mySelector->SelectionMode();
00422   myHighlightActor->SetVisibility( false );
00423   myOutlineActor->SetVisibility( false );
00424 
00425   if(mySelector.GetPointer()){
00426     if(mySelectionMode != ActorSelection){
00427       TColStd_IndexedMapOfInteger aMapIndex;
00428       mySelector->GetIndex( getIO(), aMapIndex );
00429       switch( mySelectionMode ){
00430       case NodeSelection:
00431         myHighlightActor->GetProperty()->SetRepresentationToPoints();
00432         myHighlightActor->MapPoints( this, aMapIndex );
00433         break;
00434       case EdgeOfCellSelection:
00435         myHighlightActor->GetProperty()->SetRepresentationToWireframe();
00436         myHighlightActor->MapEdge( this, aMapIndex );
00437         break;
00438       case CellSelection:
00439       case EdgeSelection:
00440       case FaceSelection:
00441       case VolumeSelection:
00442         myHighlightActor->GetProperty()->SetRepresentationToSurface();
00443         myHighlightActor->MapCells( this, aMapIndex );
00444         break;
00445       }
00446       myHighlightActor->SetVisibility( GetVisibility() && theIsHighlight );
00447     }
00448   }
00449 
00450   highlight(theIsHighlight);
00451 }
00452 
00456 void
00457 SALOME_Actor
00458 ::highlight(bool theIsHighlight)
00459 {
00460   vtkFloatingPointType aBounds[6];
00461   vtkDataSet * aDataSet = GetHighlightedDataSet();
00462   aDataSet->GetBounds(aBounds);
00463   myOutline->SetBounds(aBounds);
00464   myOutlineActor->SetVisibility( GetVisibility() && theIsHighlight );
00465 
00466   Superclass::highlight(theIsHighlight);
00467 }
00468 
00469 
00473 bool
00474 SALOME_Actor
00475 ::PreHighlight(vtkInteractorStyle *theInteractorStyle, 
00476                SVTK_SelectionEvent* theSelectionEvent,
00477                bool theIsHighlight)
00478 {
00479   if ( !GetPickable() )
00480     return false;
00481       
00482   vtkRenderer *aRenderer = theInteractorStyle->GetCurrentRenderer();
00483   //
00484   myPreHighlightActor->SetVisibility( false );
00485   bool anIsPreselected = myIsPreselected;
00486   SetPreSelected( false );
00487 
00488   Selection_Mode aSelectionMode = theSelectionEvent->mySelectionMode;
00489   bool anIsChanged = (mySelectionMode != aSelectionMode);
00490 
00491   myPreHighlightActor->SetMarkerEnabled( aSelectionMode == NodeSelection );
00492 
00493   vtkFloatingPointType x = theSelectionEvent->myX;
00494   vtkFloatingPointType y = theSelectionEvent->myY;
00495   vtkFloatingPointType z = 0.0;
00496 
00497   if( !theIsHighlight ) {
00498     if ( hasIO() ) {
00499       VTK::ActorCollectionCopy aCopy(aRenderer->GetActors());
00500       vtkActorCollection* theActors = aCopy.GetActors();
00501       theActors->InitTraversal();
00502       while( vtkActor *ac = theActors->GetNextActor() )
00503        if( SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( ac ) )
00504          if( anActor->hasIO() && myIO->isSame( anActor->getIO() ) )
00505            anActor->SetPreSelected( false );
00506     }
00507   }else{
00508     switch(aSelectionMode) {
00509     case NodeSelection: 
00510     {
00511       SVTK::TPickLimiter aPickLimiter( myPointPicker, this );
00512       myPointPicker->Pick( x, y, z, aRenderer );
00513       
00514       int aVtkId = myPointPicker->GetPointId();
00515       if( aVtkId >= 0 && mySelector->IsValid( this, aVtkId, true ) ) {
00516         int anObjId = GetNodeObjId( aVtkId );
00517         myIsPreselected = (anObjId >= 0);
00518         if(myIsPreselected){
00519           const TColStd_IndexedMapOfInteger& aMapIndex = myPreHighlightActor->GetMapIndex();
00520           int anExtent = aMapIndex.Extent();
00521           anIsChanged |= (anExtent == 0 || (anExtent > 0 && anObjId != aMapIndex(1)));
00522           if(anIsChanged){
00523             TColStd_IndexedMapOfInteger aMapIndex;
00524             aMapIndex.Add( anObjId );
00525             
00526             myPreHighlightActor->GetProperty()->SetRepresentationToPoints();
00527             myPreHighlightActor->MapPoints( this, aMapIndex );
00528           }
00529           myPreHighlightActor->SetVisibility( true );
00530         }
00531       }
00532       break;
00533     }
00534     case CellSelection: 
00535     case EdgeSelection:
00536     case FaceSelection:
00537     case VolumeSelection: 
00538     {
00539       SVTK::TPickLimiter aPickLimiter( myCellPicker, this );
00540       myCellPicker->Pick( x, y, z, aRenderer );
00541       
00542       int aVtkId = myCellPicker->GetCellId();
00543       if ( aVtkId >= 0 && mySelector->IsValid( this, aVtkId ) && hasIO() ) {
00544         int anObjId = GetElemObjId (aVtkId );
00545         if ( anObjId >= 0 ) {
00546           myIsPreselected = CheckDimensionId(aSelectionMode,this,anObjId);
00547           if(myIsPreselected){
00548             const TColStd_IndexedMapOfInteger& aMapIndex = myPreHighlightActor->GetMapIndex();
00549             int anExtent = aMapIndex.Extent();
00550             anIsChanged |= (anExtent == 0 || (anExtent > 0 && anObjId != aMapIndex(1)));
00551             if(anIsChanged){
00552               TColStd_IndexedMapOfInteger aMapIndex;
00553               aMapIndex.Add( anObjId );
00554               
00555               myPreHighlightActor->GetProperty()->SetRepresentationToSurface();
00556               myPreHighlightActor->MapCells( this, aMapIndex );
00557             }
00558             myPreHighlightActor->SetVisibility( true );
00559           }
00560         }
00561       }
00562       break;
00563     }
00564     case EdgeOfCellSelection:
00565     {
00566       SVTK::TPickLimiter aPickLimiter( myCellPicker, this );
00567       myCellPicker->Pick( x, y, z, aRenderer );
00568       
00569       int aVtkId = myCellPicker->GetCellId();
00570       if ( aVtkId >= 0 && mySelector->IsValid( this, aVtkId )) {
00571         int anObjId = GetElemObjId( aVtkId );
00572         if ( anObjId >= 0 ) {
00573           int anEdgeId = GetEdgeId(this,myCellPicker.GetPointer(),anObjId);
00574           myIsPreselected = anEdgeId < 0;
00575           if(myIsPreselected){
00576             const TColStd_IndexedMapOfInteger& aMapIndex = myPreHighlightActor->GetMapIndex();
00577             int anExtent = aMapIndex.Extent();
00578             anIsChanged |= (anExtent == 0 || anExtent == 1);
00579             anIsChanged |= (anExtent == 2 && (anObjId != aMapIndex(1) || anEdgeId != aMapIndex(2)));
00580             if(anIsChanged){
00581               TColStd_IndexedMapOfInteger aMapIndex;
00582               aMapIndex.Add( anObjId );
00583               aMapIndex.Add( anEdgeId );
00584 
00585               myPreHighlightActor->GetProperty()->SetRepresentationToWireframe();
00586               myPreHighlightActor->MapEdge( this, aMapIndex );
00587             }
00588             myPreHighlightActor->SetVisibility( true );
00589           }
00590         }
00591       }
00592       break;
00593     }
00594     case ActorSelection : 
00595     {
00596       if( !mySelector->IsSelected( myIO ) ) {
00597         SetPreSelected( true );
00598 
00599        if ( hasIO() ) {
00600          VTK::ActorCollectionCopy aCopy(aRenderer->GetActors());
00601          vtkActorCollection* theActors = aCopy.GetActors();
00602          theActors->InitTraversal();
00603          while( vtkActor *anAct = theActors->GetNextActor() ) {
00604            if( anAct != this )
00605              if( SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( anAct ) )
00606               if( anActor->hasIO() && myIO->isSame( anActor->getIO() ) )
00607                 anActor->SetPreSelected( true );
00608          }
00609        }
00610       }
00611     }
00612     default:
00613       break;
00614     }
00615   }
00616 
00617   mySelectionMode = aSelectionMode;
00618   anIsChanged |= (anIsPreselected != myIsPreselected);
00619 
00620   return anIsChanged;
00621 }
00622 
00626 bool
00627 SALOME_Actor
00628 ::Highlight(vtkInteractorStyle *theInteractorStyle, 
00629             SVTK_SelectionEvent* theSelectionEvent,
00630             bool theIsHighlight)
00631 {
00632   if ( !GetPickable() || !mySelector )
00633     return false;
00634 
00635   myOutlineActor->SetVisibility( false );
00636   myHighlightActor->SetVisibility( false );
00637 
00638   vtkRenderer *aRenderer = theInteractorStyle->GetCurrentRenderer();
00639   //
00640   Selection_Mode aSelectionMode = theSelectionEvent->mySelectionMode;
00641   bool anIsShift = theSelectionEvent->myIsShift;
00642   if( !anIsShift || !theIsHighlight ) {
00643     mySelector->RemoveIObject( this );
00644   }
00645 
00646   if ( !theIsHighlight )
00647     return true;
00648 
00649   myHighlightActor->SetMarkerEnabled( aSelectionMode == NodeSelection );
00650 
00651   vtkFloatingPointType x = theSelectionEvent->myX;
00652   vtkFloatingPointType y = theSelectionEvent->myY;
00653   vtkFloatingPointType z = 0.0;
00654 
00655   if( !theSelectionEvent->myIsRectangle ) {
00656     switch(aSelectionMode){
00657     case NodeSelection: {
00658       SVTK::TPickLimiter aPickLimiter( myPointPicker, this );
00659       myPointPicker->Pick( x, y, z, aRenderer );
00660 
00661       int aVtkId = myPointPicker->GetPointId();
00662       if( aVtkId >= 0 && mySelector->IsValid( this, aVtkId, true ) ) {
00663         int anObjId = GetNodeObjId( aVtkId );
00664         if( hasIO() && anObjId >= 0 ) {
00665           mySelector->AddOrRemoveIndex( myIO, anObjId, anIsShift );
00666           mySelector->AddIObject( this );
00667         }
00668       }
00669       break;
00670     }
00671     case CellSelection: 
00672     case EdgeSelection:
00673     case FaceSelection:
00674     case VolumeSelection: 
00675     {
00676       SVTK::TPickLimiter aPickLimiter( myCellPicker, this );
00677       myCellPicker->Pick( x, y, z, aRenderer );
00678     
00679       int aVtkId = myCellPicker->GetCellId();
00680       if( aVtkId >= 0 && mySelector->IsValid( this, aVtkId ) ) {
00681         int anObjId = GetElemObjId( aVtkId );
00682         if( anObjId >= 0 ) {
00683           if ( hasIO() && CheckDimensionId(aSelectionMode,this,anObjId) ) {
00684             mySelector->AddOrRemoveIndex( myIO, anObjId, anIsShift );
00685             mySelector->AddIObject( this );
00686           }
00687         }
00688       }
00689       break;
00690     }
00691     case EdgeOfCellSelection: 
00692     {
00693       SVTK::TPickLimiter aPickLimiter( myCellPicker, this );
00694       myCellPicker->Pick( x, y, z, aRenderer );
00695     
00696       int aVtkId = myCellPicker->GetCellId();
00697       if( aVtkId >= 0 && mySelector->IsValid( this, aVtkId ) ) {
00698         int anObjId = GetElemObjId( aVtkId );
00699         if( anObjId >= 0 ) {
00700           int anEdgeId = GetEdgeId(this,myCellPicker.GetPointer(),anObjId);
00701           if( hasIO() && anEdgeId < 0 ) {
00702             mySelector->AddOrRemoveIndex( myIO, anObjId, false );
00703             mySelector->AddOrRemoveIndex( myIO, anEdgeId, true );
00704             mySelector->AddIObject( this );
00705           } 
00706         }
00707       }
00708       break;
00709     }
00710     case ActorSelection : 
00711     {
00712       if ( hasIO() ) {
00713        if( mySelector->IsSelected( myIO ) && anIsShift )
00714          mySelector->RemoveIObject( this );
00715        else {
00716          mySelector->AddIObject( this );
00717        }
00718       }
00719       break;
00720     }
00721     default:
00722       break;
00723     }
00724   }else{
00725     vtkFloatingPointType xLast = theSelectionEvent->myLastX;
00726     vtkFloatingPointType yLast = theSelectionEvent->myLastY;
00727     vtkFloatingPointType zLast = 0.0;
00728 
00729     vtkFloatingPointType x1 = x < xLast ? x : xLast;
00730     vtkFloatingPointType y1 = y < yLast ? y : yLast;
00731     vtkFloatingPointType z1 = z < zLast ? z : zLast;
00732     vtkFloatingPointType x2 = x > xLast ? x : xLast;
00733     vtkFloatingPointType y2 = y > yLast ? y : yLast;
00734     vtkFloatingPointType z2 = z > zLast ? z : zLast;
00735 
00736     switch(aSelectionMode){
00737     case NodeSelection: {
00738 
00739       SVTK::TPickLimiter aPickLimiter( myPointRectPicker, this );
00740       myPointRectPicker->Pick( x1, y1, z1, x2, y2, z2, aRenderer );
00741 
00742       const SVTK_RectPicker::TVectorIdsMap& aVectorIdsMap = myPointRectPicker->GetPointIdsMap();
00743       SVTK_RectPicker::TVectorIdsMap::const_iterator aMapIter = aVectorIdsMap.find(this);
00744       TColStd_MapOfInteger anIndexes;
00745       if(aMapIter != aVectorIdsMap.end()){
00746         const SVTK_RectPicker::TVectorIds& aVectorIds = aMapIter->second;
00747         vtkIdType anEnd = aVectorIds.size();
00748         for(vtkIdType anId = 0; anId < anEnd; anId++ ) {
00749           int aPointId = aVectorIds[anId];
00750           if( aPointId >= 0 && mySelector->IsValid( this, aPointId, true ) ) {
00751             int anObjId = GetNodeObjId( aPointId );
00752             anIndexes.Add( anObjId );
00753           }
00754         }
00755       }
00756       
00757       if ( hasIO() ) {
00758        if( !anIndexes.IsEmpty() ) {
00759          mySelector->AddOrRemoveIndex( myIO, anIndexes, anIsShift );
00760          mySelector->AddIObject( this );
00761          anIndexes.Clear();
00762        }
00763        else if ( !anIsShift )
00764          mySelector->RemoveIObject( this );
00765       }
00766       break;
00767     }
00768     case ActorSelection :
00769     {
00770       vtkFloatingPointType aPnt[3];
00771       vtkFloatingPointType* aBounds = GetBounds();
00772 
00773       bool anIsPicked = true;
00774       for( int i = 0; i <= 1; i++ ) {
00775         for( int j = 2; j <= 3; j++ ) {
00776           for( int k = 4; k <= 5; k++ ) {
00777             aRenderer->SetWorldPoint( aBounds[ i ], aBounds[ j ], aBounds[ k ], 1.0 );
00778             aRenderer->WorldToDisplay();
00779             aRenderer->GetDisplayPoint( aPnt );
00780 
00781             if( aPnt[0] < x1 || aPnt[0] > x2 || aPnt[1] < y1 || aPnt[1] > y2 ) {
00782               anIsPicked = false;
00783               break;
00784             }
00785           }
00786         }
00787       }
00788 
00789       if( anIsPicked )
00790         mySelector->AddIObject(this);
00791 
00792       break;
00793     }
00794     case CellSelection: 
00795     case EdgeSelection:
00796     case FaceSelection:
00797     case VolumeSelection: 
00798     {
00799       SVTK::TPickLimiter aPickLimiter( myCellRectPicker, this );
00800       myCellRectPicker->Pick( x1, y1, z1, x2, y2, z2, aRenderer );
00801 
00802       const SVTK_RectPicker::TVectorIdsMap& aVectorIdsMap = myCellRectPicker->GetCellIdsMap();
00803       SVTK_RectPicker::TVectorIdsMap::const_iterator aMapIter = aVectorIdsMap.find(this);
00804       TColStd_MapOfInteger anIndexes;
00805       if(aMapIter != aVectorIdsMap.end()){
00806         const SVTK_RectPicker::TVectorIds& aVectorIds = aMapIter->second;
00807         vtkIdType anEnd = aVectorIds.size();
00808         for(vtkIdType anId = 0; anId < anEnd; anId++ ) {
00809           int aCellId = aVectorIds[anId];
00810           if ( !mySelector->IsValid( this, aCellId ) )
00811             continue;
00812 
00813           int anObjId = GetElemObjId( aCellId );
00814           if( anObjId != -1 )
00815             if ( CheckDimensionId(aSelectionMode,this,anObjId) ) {
00816               anIndexes.Add(anObjId);
00817             }
00818         }
00819       }
00820       
00821       if ( hasIO() ) {
00822        if( !anIndexes.IsEmpty() ) {
00823          mySelector->AddOrRemoveIndex( myIO, anIndexes, anIsShift );
00824          mySelector->AddIObject( this );
00825          anIndexes.Clear();
00826        }
00827        else if ( !anIsShift )
00828          mySelector->RemoveIObject( this );
00829       }
00830     }
00831     default:
00832       break;
00833     }
00834   }
00835 
00836   mySelectionMode = aSelectionMode;
00837 
00838   return true;
00839 }
00840 
00845 bool
00846 SALOME_Actor
00847 ::IsDisplayNameActor() const
00848 {
00849   return myIsDisplayNameActor;
00850 }
00851 
00856 void
00857 SALOME_Actor
00858 ::SetIsDisplayNameActor(bool theIsDisplayNameActor)
00859 {
00860   SUIT_ResourceMgr* aResourceMgr = SUIT_Session::session()->resourceMgr();
00861   bool isShowGroupNames = aResourceMgr->booleanValue("VTKViewer", "show_group_names", false);
00862   myIsDisplayNameActor = theIsDisplayNameActor && isShowGroupNames;
00863   UpdateNameActors();
00864 }
00865 
00870 void
00871 SALOME_Actor
00872 ::SetNameActorText(const char* theText)
00873 {
00874   myNameActor->SetText(theText);
00875 }
00876 
00881 void
00882 SALOME_Actor
00883 ::SetNameActorOffset(int theOffset[2])
00884 {
00885   myNameActor->SetOffset(theOffset);
00886 }
00887 
00893 void
00894 SALOME_Actor
00895 ::GetNameActorSize(vtkRenderer* theRenderer, int theSize[2]) const
00896 {
00897   myNameActor->GetSize(theRenderer, theSize);
00898 }
00899 
00903 void
00904 SALOME_Actor
00905 ::UpdateNameActors()
00906 {
00907   if( vtkRenderer* aRenderer = GetRenderer() )
00908   {
00909     int anOffset[2] = { 0, 0 };
00910     VTK::ActorCollectionCopy aCopy(aRenderer->GetActors());
00911     vtkActorCollection* aCollection = aCopy.GetActors();
00912     for( int anIndex = 0, aNbItems = aCollection->GetNumberOfItems(); anIndex < aNbItems; anIndex++ )
00913     {
00914       if( SALOME_Actor* anActor = dynamic_cast<SALOME_Actor*>( aCollection->GetItemAsObject( anIndex ) ) )
00915       {
00916         if( anActor->IsDisplayNameActor() )
00917         {
00918           anActor->SetNameActorOffset( anOffset );
00919           if( anActor->GetVisibility() )
00920           {
00921             int aSize[2];
00922             anActor->GetNameActorSize( aRenderer, aSize );
00923             anOffset[0] = anOffset[0] + aSize[0];
00924             anOffset[1] = anOffset[1] + aSize[1];
00925           }
00926         }
00927       }
00928     }
00929   }
00930   myNameActor->SetVisibility( GetVisibility() && IsDisplayNameActor() );
00931 }
00932 
00937 void
00938 SALOME_Actor
00939 ::SetPointPicker(vtkPointPicker* thePointPicker) 
00940 {
00941   myPointPicker = thePointPicker;
00942 }
00943 
00948 void
00949 SALOME_Actor
00950 ::SetCellPicker(vtkCellPicker* theCellPicker) 
00951 {
00952   myCellPicker = theCellPicker;
00953 }
00954 
00959 void
00960 SALOME_Actor
00961 ::SetPointRectPicker(SVTK_RectPicker* theRectPicker) 
00962 {
00963   myPointRectPicker = theRectPicker;
00964 }
00965 
00970 void
00971 SALOME_Actor
00972 ::SetCellRectPicker(SVTK_RectPicker* theRectPicker) 
00973 {
00974   myCellRectPicker = theRectPicker;
00975 }
00976 
00980 void
00981 SALOME_Actor
00982 ::SetPreHighlightProperty(vtkProperty* theProperty) 
00983 {
00984   myPreHighlightActor->SetProperty(theProperty);
00985 }
00986 
00990 void
00991 SALOME_Actor
00992 ::SetHighlightProperty(vtkProperty* theProperty) 
00993 {
00994   myHighlightActor->SetProperty(theProperty);
00995 }
00996 
01002 void
01003 SALOME_Actor
01004 ::SetMarkerStd( VTK::MarkerType theMarkerType, VTK::MarkerScale theMarkerScale )
01005 {
01006   myPreHighlightActor->SetMarkerStd( theMarkerType, theMarkerScale );
01007   myHighlightActor->SetMarkerStd( theMarkerType, theMarkerScale );
01008 }
01009 
01015 void
01016 SALOME_Actor
01017 ::SetMarkerTexture( int theMarkerId, VTK::MarkerTexture theMarkerTexture )
01018 {
01019   myPreHighlightActor->SetMarkerTexture( theMarkerId, theMarkerTexture );
01020   myHighlightActor->SetMarkerTexture( theMarkerId, theMarkerTexture );
01021 }
01022 
01027 VTK::MarkerType
01028 SALOME_Actor
01029 ::GetMarkerType()
01030 {
01031   return myPreHighlightActor->GetMarkerType();
01032 }
01033 
01038 VTK::MarkerScale
01039 SALOME_Actor
01040 ::GetMarkerScale()
01041 {
01042   return myPreHighlightActor->GetMarkerScale();
01043 }
01044 
01049 int
01050 SALOME_Actor
01051 ::GetMarkerTexture()
01052 {
01053   return myPreHighlightActor->GetMarkerTexture();
01054 }