1 // Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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, or (at your option) any later version.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // SALOME OBJECT : implementation of interactive object visualization for OCC and VTK viewers
24 // File : SALOME_Actor.cxx
25 // Author : Nicolas REJNERI
28 \class SALOME_Actor SALOME_Actor.h
29 \brief Abstract class of SALOME Objects in VTK.
33 #include "SALOME_Actor.h"
34 #include "SALOME_InteractiveObject.hxx"
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_AreaPicker.h"
43 #include "SVTK_Actor.h"
45 #include <SUIT_ResourceMgr.h>
46 #include <SUIT_Session.h>
51 #include <vtkQuadraticEdge.h>
52 #include <vtkPicker.h>
53 #include <vtkPointPicker.h>
54 #include <vtkCellPicker.h>
55 #include <vtkRenderer.h>
56 #include <vtkPolyData.h>
57 #include <vtkObjectFactory.h>
58 #include <vtkDataSetMapper.h>
59 #include <vtkPolyDataMapper.h>
60 #include <vtkProperty.h>
61 #include <vtkOutlineSource.h>
62 #include <vtkPolygon.h>
64 #include <vtkInteractorStyle.h>
65 #include <vtkRenderWindowInteractor.h>
66 #include <vtkPassThroughFilter.h>
68 #include <TColStd_MapOfInteger.hxx>
69 #include <TColStd_IndexedMapOfInteger.hxx>
81 int SALOME_POINT_SIZE = 5;
82 int SALOME_LINE_WIDTH = 3;
87 GetEdgeAndNodesId(SALOME_Actor* theActor,
94 if (vtkCell* aPickedCell = theActor->GetElemCell(theObjId)) {
95 double aPickPosition[3];
96 thePicker->GetPickPosition(aPickPosition);
97 double aMinDist = 1000000.0, aDist = 0;
99 for (int i = 0, iEnd = aPickedCell->GetNumberOfEdges(); i < iEnd; i++){
100 aSelEdge = aPickedCell->GetEdge(i);
101 if(vtkLine::SafeDownCast(aPickedCell->GetEdge(i)) ||
102 vtkQuadraticEdge::SafeDownCast(aPickedCell->GetEdge(i))){
104 double pcoords[3], closestPoint[3], weights[3];
105 aSelEdge->EvaluatePosition(aPickPosition,closestPoint,subId,pcoords,aDist,weights);
106 if (aDist < aMinDist) {
109 theFirstNodeId = aSelEdge->GetPointId(0);
110 theSecondNodeId = aSelEdge->GetPointId(1);
120 CheckDimensionId(Selection_Mode theMode,
121 SALOME_Actor *theActor,
128 return ( theActor->GetObjDimension( theObjId ) == 1 );
130 return ( theActor->GetObjDimension( theObjId ) == 2 );
131 case VolumeSelection:
132 return ( theActor->GetObjDimension( theObjId ) == 3 );
133 case Elem0DSelection:
134 return ((theActor->GetObjDimension( theObjId ) == 0) &&
135 theActor->GetElemCell(theObjId) &&
136 (theActor->GetElemCell(theObjId)->GetCellType() == VTK_VERTEX));
138 return ((theActor->GetObjDimension( theObjId ) == 0) &&
139 theActor->GetElemCell(theObjId) &&
140 (theActor->GetElemCell(theObjId)->GetCellType() == VTK_POLY_VERTEX));
150 Make picker work with this actor only
152 TPickLimiter::TPickLimiter(vtkAbstractPicker* picker, SALOME_Actor* actor):myPicker(picker)
154 myPicker->InitializePickList();
155 myPicker->AddPickList( actor );
156 myPicker->SetPickFromList( true );
161 TPickLimiter::~TPickLimiter()
163 myPicker->SetPickFromList( false );
164 myPicker->InitializePickList();
169 vtkStandardNewMacro(SALOME_Actor);
178 mySelectionMode(ActorSelection),
179 myPreHighlightActor(SVTK_Actor::New()),
180 myHighlightActor(SVTK_Actor::New()),
181 myOutline(vtkOutlineSource::New()),
182 myOutlineActor(VTKViewer_Actor::New()),
183 myIsDisplayNameActor(false),
184 myNameActor(VTKViewer_FramedTextActor::New())
186 myPreHighlightActor->Delete();
187 myPreHighlightActor->Initialize();
188 myPreHighlightActor->PickableOff();
189 myPreHighlightActor->SetVisibility( false );
190 myPreHighlightActor->SetCoincident3DAllowed(true);
192 myHighlightActor->Delete();
193 myHighlightActor->Initialize();
194 myHighlightActor->PickableOff();
195 myHighlightActor->SetVisibility( false );
196 myHighlightActor->SetCoincident3DAllowed(true);
200 vtkPolyDataMapper* anOutlineMapper = vtkPolyDataMapper::New();
201 anOutlineMapper->SetInputConnection(myOutline->GetOutputPort());
203 myOutlineActor->Delete();
204 myOutlineActor->SetMapper( anOutlineMapper );
205 anOutlineMapper->Delete();
207 myOutlineActor->PickableOff();
208 myOutlineActor->DragableOff();
209 myOutlineActor->GetProperty()->SetColor(1.0,0.0,0.0);
210 myOutlineActor->GetProperty()->SetAmbient(1.0);
211 myOutlineActor->GetProperty()->SetDiffuse(0.0);
212 myOutlineActor->SetVisibility( false );
215 myNameActor->Delete();
216 myNameActor->SetVisibility(false);
217 myNameActor->SetPickable(false);
218 myNameActor->SetModePosition(VTKViewer_FramedTextActor::TopRight);
219 myNameActor->SetLayoutType(VTKViewer_FramedTextActor::Vertical);
221 SUIT_ResourceMgr* aResourceMgr = SUIT_Session::session()->resourceMgr();
223 QColor aForegroundColor = aResourceMgr->colorValue( "VTKViewer", "group_names_text_color", Qt::white );
224 myNameActor->SetForegroundColor(aForegroundColor.redF(),
225 aForegroundColor.greenF(),
226 aForegroundColor.blueF());
228 double aGroupNamesTransparency = 0.5;
229 aGroupNamesTransparency = aResourceMgr->doubleValue( "VTKViewer", "group_names_transparency", aGroupNamesTransparency );
230 myNameActor->SetTransparency(aGroupNamesTransparency);
242 \return true if the SALOME_Actor has a reference to SALOME_InteractiveObject
248 return !myIO.IsNull();
252 \return correspoinding reference to SALOME_InteractiveObject
254 const Handle(SALOME_InteractiveObject)&
262 Sets reference to SALOME_InteractiveObject
263 \param theIO - new SALOME_InteractiveObject
267 ::setIO(const Handle(SALOME_InteractiveObject)& theIO)
273 Sets name the SALOME_Actor
274 \param theName - new name
278 ::setName(const char* theName)
281 myIO->setName(theName);
282 myNameActor->SetText(theName);
283 Superclass::setName(theName);
288 Publishes the actor in all its internal devices
292 ::AddToRender(vtkRenderer* theRenderer)
294 Superclass::AddToRender(theRenderer);
296 myRenderer = theRenderer;
298 myHighlightActor->AddToRender(theRenderer);
299 myPreHighlightActor->AddToRender(theRenderer);
300 theRenderer->AddActor( myOutlineActor.GetPointer() );
301 theRenderer->AddActor( myNameActor.GetPointer() );
305 Removes the actor from all its internal devices
309 ::RemoveFromRender(vtkRenderer* theRenderer)
311 Superclass::RemoveFromRender(theRenderer);
313 myHighlightActor->RemoveFromRender(theRenderer);
314 myPreHighlightActor->RemoveFromRender(theRenderer);
316 theRenderer->RemoveActor( myPreHighlightActor.GetPointer() );
317 theRenderer->RemoveActor( myHighlightActor.GetPointer() );
318 theRenderer->RemoveActor( myOutlineActor.GetPointer() );
319 theRenderer->RemoveActor( myNameActor.GetPointer() );
323 \return reference on renderer where it is published
333 Sets interactor in order to use vtkInteractorObserver devices
334 \param theInteractor - new interactor
338 ::SetInteractor(vtkRenderWindowInteractor* theInteractor)
340 myInteractor = theInteractor;
344 Put a request to redraw the view
350 myInteractor->CreateTimer(VTKI_TIMER_UPDATE);
354 Apply view transformation
355 \param theTransform - transformation
359 ::SetTransform(VTKViewer_Transform* theTransform)
361 Superclass::SetTransform(theTransform);
363 myPreHighlightActor->SetTransform(theTransform);
364 myHighlightActor->SetTransform(theTransform);
365 myOutlineActor->SetTransform(theTransform);
369 Apply additional position
373 ::SetPosition(double _arg1,
377 Superclass::SetPosition(_arg1,_arg2,_arg3);
379 myPreHighlightActor->SetPosition(_arg1,_arg2,_arg3);
380 myHighlightActor->SetPosition(_arg1,_arg2,_arg3);
381 myOutlineActor->SetPosition(_arg1,_arg2,_arg3);
385 Apply additional position
389 ::SetPosition(double _arg[3])
391 SetPosition(_arg[0],_arg[1],_arg[2]);
396 \param theVisibility - new visibility state
400 ::SetVisibility( int theVisibility )
402 Superclass::SetVisibility( theVisibility );
404 myOutlineActor->SetVisibility( theVisibility && isHighlighted() && !hasHighlight() );
406 myPreHighlightActor->SetVisibility( theVisibility && myIsPreselected );
408 if(mySelector.GetPointer() && hasIO()){
409 if(mySelector->SelectionMode() != ActorSelection){
410 int aHasIndex = mySelector->HasIndex( getIO() );
411 myHighlightActor->SetVisibility( theVisibility && isHighlighted() && aHasIndex);
419 Gets know whether the actor should be displayed or not
423 ::ShouldBeDisplayed()
429 Set selector in order to the actor at any time can restore current selection
430 \param theSelector - new selector
434 ::SetSelector(SVTK_Selector* theSelector)
436 mySelector = theSelector;
440 To map current selection to VTK representation
444 ::Highlight(bool theIsHighlight)
446 mySelectionMode = mySelector->SelectionMode();
447 myHighlightActor->SetVisibility( false );
448 myOutlineActor->SetVisibility( false );
450 if(mySelector.GetPointer()){
451 if(mySelectionMode != ActorSelection){
452 TColStd_IndexedMapOfInteger aMapIndex;
453 mySelector->GetIndex( getIO(), aMapIndex );
454 switch( mySelectionMode ) {
456 myHighlightActor->GetProperty()->SetRepresentationToPoints();
457 myHighlightActor->MapPoints( this, aMapIndex );
462 case VolumeSelection:
463 case Elem0DSelection:
465 myHighlightActor->GetProperty()->SetRepresentationToSurface();
466 myHighlightActor->MapCells( this, aMapIndex );
468 case EdgeOfCellSelection:
469 SVTK_IndexedMapOfIds aMapCompositeIndex;
470 mySelector->GetCompositeIndex( getIO(), aMapCompositeIndex );
471 myHighlightActor->GetProperty()->SetRepresentationToWireframe();
472 myHighlightActor->MapEdge( this, aMapCompositeIndex );
475 myHighlightActor->SetVisibility( GetVisibility() && theIsHighlight );
477 myHighlightActor->SetMarkerEnabled( mySelectionMode == NodeSelection );
480 highlight(theIsHighlight);
484 Updates visibility of the highlight devices
488 ::highlight(bool theIsHighlight)
491 vtkDataSet * aDataSet = GetHighlightedDataSet();
492 aDataSet->GetBounds(aBounds);
493 myOutline->SetBounds(aBounds);
495 myOutlineActor->SetVisibility( GetVisibility() && theIsHighlight );
497 Superclass::highlight(theIsHighlight);
502 To process prehighlight (called from SVTK_InteractorStyle)
506 ::PreHighlight(vtkInteractorStyle *theInteractorStyle,
507 SVTK_SelectionEvent* theSelectionEvent,
510 if ( !GetPickable() || !mySelector || !mySelector->IsPreSelectionEnabled() )
513 vtkRenderer *aRenderer = theInteractorStyle->GetCurrentRenderer();
515 myPreHighlightActor->SetVisibility( false );
516 bool anIsPreselected = myIsPreselected;
517 SetPreSelected( false );
519 Selection_Mode aSelectionMode = theSelectionEvent->mySelectionMode;
520 bool anIsChanged = (mySelectionMode != aSelectionMode);
522 myPreHighlightActor->SetMarkerEnabled( aSelectionMode == NodeSelection );
524 double x = theSelectionEvent->myX;
525 double y = theSelectionEvent->myY;
528 if( !theIsHighlight ) {
530 VTK::ActorCollectionCopy aCopy(aRenderer->GetActors());
531 vtkActorCollection* theActors = aCopy.GetActors();
532 theActors->InitTraversal();
533 while( vtkActor *ac = theActors->GetNextActor() )
534 if( SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( ac ) )
535 if( anActor->hasIO() && myIO->isSame( anActor->getIO() ) )
536 anActor->SetPreSelected( false );
539 switch(aSelectionMode) {
542 SVTK::TPickLimiter aPickLimiter( myPointPicker, this );
543 myPointPicker->Pick( x, y, z, aRenderer );
545 int aVtkId = myPointPicker->GetPointId();
546 if( aVtkId >= 0 && mySelector->IsValid( this, aVtkId, true ) ) {
547 int anObjId = GetNodeObjId( aVtkId );
548 myIsPreselected = (anObjId >= 0);
550 const TColStd_IndexedMapOfInteger& aMapIndex = myPreHighlightActor->GetMapIndex();
551 int anExtent = aMapIndex.Extent();
552 anIsChanged |= (anExtent == 0 || (anExtent > 0 && anObjId != aMapIndex(1)));
554 TColStd_IndexedMapOfInteger aMapIndex;
555 aMapIndex.Add( anObjId );
557 myPreHighlightActor->GetProperty()->SetRepresentationToPoints();
558 myPreHighlightActor->MapPoints( this, aMapIndex );
560 myPreHighlightActor->SetVisibility( true );
568 case VolumeSelection:
569 case Elem0DSelection:
572 SVTK::TPickLimiter aPickLimiter( myCellPicker, this );
573 myCellPicker->Pick( x, y, z, aRenderer );
575 int aVtkId = myCellPicker->GetCellId();
576 if ( aVtkId >= 0 && mySelector->IsValid( this, aVtkId ) && hasIO() ) {
577 int anObjId = GetElemObjId (aVtkId );
578 if ( anObjId >= 0 ) {
579 myIsPreselected = CheckDimensionId(aSelectionMode,this,anObjId);
581 const TColStd_IndexedMapOfInteger& aMapIndex = myPreHighlightActor->GetMapIndex();
582 int anExtent = aMapIndex.Extent();
583 anIsChanged |= (anExtent == 0 || (anExtent > 0 && anObjId != aMapIndex(1)));
585 TColStd_IndexedMapOfInteger aMapIndex;
586 aMapIndex.Add( anObjId );
588 myPreHighlightActor->GetProperty()->SetRepresentationToSurface();
589 myPreHighlightActor->MapCells( this, aMapIndex );
591 myPreHighlightActor->SetVisibility( true );
597 case EdgeOfCellSelection:
599 SVTK::TPickLimiter aPickLimiter( myCellPicker, this );
600 myCellPicker->Pick( x, y, z, aRenderer );
602 int aVtkId = myCellPicker->GetCellId();
603 if ( aVtkId >= 0 && mySelector->IsValid( this, aVtkId )) {
604 int anObjId = GetElemObjId( aVtkId );
605 if ( anObjId >= 0 ) {
607 int anEdgeId = GetEdgeAndNodesId(this,myCellPicker.GetPointer(),anObjId,aFNId,aSNId);
608 myIsPreselected = anEdgeId < 0;
610 int aFNObjId = GetNodeObjId( aFNId );
611 int aSNObjId = GetNodeObjId( aSNId );
612 const SVTK_IndexedMapOfIds& aMapIds = myPreHighlightActor->GetMapCompositeIndex();
613 int anExtent = aMapIds.Extent();
614 anIsChanged |= (anExtent == 0 || (anExtent > 0 && aMapIds(1).size() == 2 &&
615 (aFNObjId != aMapIds(1)[0] || aSNObjId != aMapIds(1)[1] ) ) );
617 SVTK_IndexedMapOfIds aMapIds;
618 SVTK_ListOfInteger aCompositeID;
619 aCompositeID.push_back( aFNObjId );
620 aCompositeID.push_back( aSNObjId );
621 aMapIds.Add( aCompositeID );
622 myPreHighlightActor->GetProperty()->SetRepresentationToWireframe();
623 myPreHighlightActor->MapEdge( this, aMapIds );
625 myPreHighlightActor->SetVisibility( true );
631 case ActorSelection :
633 if( !mySelector->IsSelected( myIO ) ) {
634 SetPreSelected( true );
637 VTK::ActorCollectionCopy aCopy(aRenderer->GetActors());
638 vtkActorCollection* theActors = aCopy.GetActors();
639 theActors->InitTraversal();
640 while( vtkActor *anAct = theActors->GetNextActor() ) {
642 if( SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( anAct ) )
643 if( anActor->hasIO() && myIO->isSame( anActor->getIO() ) )
644 anActor->SetPreSelected( true );
654 mySelectionMode = aSelectionMode;
655 anIsChanged |= (anIsPreselected != myIsPreselected);
661 To process highlight (called from SVTK_InteractorStyle)
665 ::Highlight(vtkInteractorStyle *theInteractorStyle,
666 SVTK_SelectionEvent* theSelectionEvent,
669 if ( !GetPickable() || !mySelector || !mySelector->IsSelectionEnabled() )
672 myOutlineActor->SetVisibility( false );
673 myHighlightActor->SetVisibility( false );
675 vtkRenderer *aRenderer = theInteractorStyle->GetCurrentRenderer();
677 Selection_Mode aSelectionMode = theSelectionEvent->mySelectionMode;
678 bool anIsShift = theSelectionEvent->myIsShift;
679 if( !anIsShift || !theIsHighlight ) {
680 mySelector->RemoveIObject( this );
683 if ( !theIsHighlight )
686 double x = theSelectionEvent->myX;
687 double y = theSelectionEvent->myY;
689 if( theSelectionEvent->myIsRectangle || theSelectionEvent->myIsPolygon ) {
690 double xLast = theSelectionEvent->myLastX;
691 double yLast = theSelectionEvent->myLastY;
693 double x1 = x < xLast ? x : xLast;
694 double y1 = y < yLast ? y : yLast;
695 double x2 = x > xLast ? x : xLast;
696 double y2 = y > yLast ? y : yLast;
698 switch(aSelectionMode){
699 case NodeSelection: {
701 SVTK::TPickLimiter aPickLimiter( myPointAreaPicker, this );
702 if ( theSelectionEvent->myIsRectangle )
703 myPointAreaPicker->Pick( x1, y1, x2, y2, aRenderer, SVTK_AreaPicker::RectangleMode );
704 else if( theSelectionEvent->myIsPolygon )
705 myPointAreaPicker->Pick( theSelectionEvent->myPolygonPoints, aRenderer, SVTK_AreaPicker::PolygonMode );
707 const SVTK_AreaPicker::TVectorIdsMap& aVectorIdsMap = myPointAreaPicker->GetPointIdsMap();
708 SVTK_AreaPicker::TVectorIdsMap::const_iterator aMapIter = aVectorIdsMap.find(this);
709 TColStd_MapOfInteger anIndexes;
710 if(aMapIter != aVectorIdsMap.end()){
711 const SVTK_AreaPicker::TVectorIds& aVectorIds = aMapIter->second;
712 vtkIdType anEnd = aVectorIds.size();
713 for(vtkIdType anId = 0; anId < anEnd; anId++ ) {
714 int aPointId = aVectorIds[anId];
715 if( aPointId >= 0 && mySelector->IsValid( this, aPointId, true ) ) {
716 int anObjId = GetNodeObjId( aPointId );
717 anIndexes.Add( anObjId );
723 if( !anIndexes.IsEmpty() ) {
724 mySelector->AddOrRemoveIndex( myIO, anIndexes, anIsShift );
725 mySelector->AddIObject( this );
728 else if ( !anIsShift )
729 mySelector->RemoveIObject( this );
733 case ActorSelection :
736 double* aBounds = GetBounds();
738 bool anIsPicked = true;
739 for( int i = 0; i <= 1; i++ ) {
740 for( int j = 2; j <= 3; j++ ) {
741 for( int k = 4; k <= 5; k++ ) {
742 aRenderer->SetWorldPoint( aBounds[ i ], aBounds[ j ], aBounds[ k ], 1.0 );
743 aRenderer->WorldToDisplay();
744 aRenderer->GetDisplayPoint( aPnt );
745 bool anIsPointInSelection;
746 if( theSelectionEvent->myIsRectangle )
747 anIsPointInSelection = aPnt[0] > x1 && aPnt[0] < x2 && aPnt[1] > y1 && aPnt[1] < y2;
748 else if( theSelectionEvent->myIsPolygon )
749 anIsPointInSelection = myPointAreaPicker->isPointInPolygon( QPoint( aPnt[0], aPnt[1] ),
750 theSelectionEvent->myPolygonPoints );
752 if( !anIsPointInSelection ) {
761 if( anIsPicked && mySelector->IsSelected( myIO ) && anIsShift )
762 mySelector->RemoveIObject( this );
763 else if ( anIsPicked ){
764 mySelector->AddIObject( this );
773 case VolumeSelection:
774 case Elem0DSelection:
777 SVTK::TPickLimiter aPickLimiter( myCellAreaPicker, this );
778 if( theSelectionEvent->myIsRectangle )
779 myCellAreaPicker->Pick( x1, y1, x2, y2, aRenderer, SVTK_AreaPicker::RectangleMode );
780 else if( theSelectionEvent->myIsPolygon )
781 myCellAreaPicker->Pick( theSelectionEvent->myPolygonPoints, aRenderer, SVTK_AreaPicker::PolygonMode );
783 const SVTK_AreaPicker::TVectorIdsMap& aVectorIdsMap = myCellAreaPicker->GetCellIdsMap();
784 SVTK_AreaPicker::TVectorIdsMap::const_iterator aMapIter = aVectorIdsMap.find(this);
785 TColStd_MapOfInteger anIndexes;
786 if(aMapIter != aVectorIdsMap.end()){
787 const SVTK_AreaPicker::TVectorIds& aVectorIds = aMapIter->second;
788 vtkIdType anEnd = aVectorIds.size();
789 for(vtkIdType anId = 0; anId < anEnd; anId++ ) {
790 int aCellId = aVectorIds[anId];
791 if ( !mySelector->IsValid( this, aCellId ) )
794 int anObjId = GetElemObjId( aCellId );
796 if ( CheckDimensionId(aSelectionMode,this,anObjId) ) {
797 anIndexes.Add(anObjId);
803 if( !anIndexes.IsEmpty() ) {
804 mySelector->AddOrRemoveIndex( myIO, anIndexes, anIsShift );
805 mySelector->AddIObject( this );
808 else if ( !anIsShift )
809 mySelector->RemoveIObject( this );
813 case EdgeOfCellSelection:
815 SVTK::TPickLimiter aPickLimiter( myCellAreaPicker, this );
816 if( theSelectionEvent->myIsRectangle )
817 myCellAreaPicker->Pick( x1, y1, x2, y2, aRenderer, SVTK_AreaPicker::RectangleMode );
818 else if( theSelectionEvent->myIsPolygon )
819 myCellAreaPicker->Pick( theSelectionEvent->myPolygonPoints, aRenderer, SVTK_AreaPicker::PolygonMode );
821 const SVTK_AreaPicker::TVectorIdsMap& aVectorIdsMap = myCellAreaPicker->GetCellIdsMap();
822 SVTK_AreaPicker::TVectorIdsMap::const_iterator aMapIter = aVectorIdsMap.find(this);
823 SVTK_IndexedMapOfIds anIndexes;
824 if(aMapIter != aVectorIdsMap.end()){
825 const SVTK_AreaPicker::TVectorIds& aVectorIds = aMapIter->second;
826 vtkIdType anEnd = aVectorIds.size();
827 for(vtkIdType anId = 0; anId < anEnd; anId++ ) {
828 int aCellId = aVectorIds[anId];
829 if ( !mySelector->IsValid( this, aCellId ) )
832 int anObjId = GetElemObjId( aCellId );
833 if( anObjId != -1 ) {
835 int anEdgeId = GetEdgeAndNodesId(this,myCellPicker.GetPointer(),anObjId,aFNId,aSNId);
837 SVTK_ListOfInteger aCompositeID;
838 aCompositeID.push_back( GetNodeObjId( aFNId ) );
839 aCompositeID.push_back( GetNodeObjId( aSNId ) );
840 anIndexes.Add( aCompositeID );
847 if( !anIndexes.IsEmpty() ) {
848 mySelector->AddOrRemoveCompositeIndex( myIO, anIndexes, anIsShift );
849 mySelector->AddIObject( this );
852 else if ( !anIsShift )
853 mySelector->RemoveIObject( this );
861 switch(aSelectionMode){
862 case NodeSelection: {
863 SVTK::TPickLimiter aPickLimiter( myPointPicker, this );
864 myPointPicker->Pick( x, y, 0.0, aRenderer );
866 int aVtkId = myPointPicker->GetPointId();
867 if( aVtkId >= 0 && mySelector->IsValid( this, aVtkId, true ) ) {
868 int anObjId = GetNodeObjId( aVtkId );
869 if( hasIO() && anObjId >= 0 ) {
870 mySelector->AddOrRemoveIndex( myIO, anObjId, anIsShift );
871 mySelector->AddIObject( this );
879 case VolumeSelection:
880 case Elem0DSelection:
883 SVTK::TPickLimiter aPickLimiter( myCellPicker, this );
884 myCellPicker->Pick( x, y, 0.0, aRenderer );
886 int aVtkId = myCellPicker->GetCellId();
887 if( aVtkId >= 0 && mySelector->IsValid( this, aVtkId ) ) {
888 int anObjId = GetElemObjId( aVtkId );
890 if ( hasIO() && CheckDimensionId(aSelectionMode,this,anObjId) ) {
891 mySelector->AddOrRemoveIndex( myIO, anObjId, anIsShift );
892 mySelector->AddIObject( this );
898 case EdgeOfCellSelection:
900 SVTK::TPickLimiter aPickLimiter( myCellPicker, this );
901 myCellPicker->Pick( x, y, 0.0, aRenderer );
903 int aVtkId = myCellPicker->GetCellId();
904 if( aVtkId >= 0 && mySelector->IsValid( this, aVtkId ) ) {
905 int anObjId = GetElemObjId( aVtkId );
908 int anEdgeId = GetEdgeAndNodesId(this,myCellPicker.GetPointer(),anObjId,aFNId,aSNId);
909 if( hasIO() && anEdgeId < 0 ) {
910 SVTK_ListOfInteger aCompositeID;
911 aCompositeID.push_back( GetNodeObjId( aFNId ) );
912 aCompositeID.push_back( GetNodeObjId( aSNId ) );
913 mySelector->AddOrRemoveCompositeIndex( myIO, aCompositeID, anIsShift );
914 mySelector->AddIObject( this );
920 case ActorSelection :
923 if( mySelector->IsSelected( myIO ) && anIsShift )
924 mySelector->RemoveIObject( this );
926 mySelector->AddIObject( this );
936 mySelectionMode = aSelectionMode;
942 To get flag of displaying of name actor
943 \return flag to display or not to display name actor
947 ::IsDisplayNameActor() const
949 return myIsDisplayNameActor;
953 To set flag of displaying of name actor
954 \param theIsDisplayNameActor flag to display or not to display name actor
958 ::SetIsDisplayNameActor(bool theIsDisplayNameActor)
960 SUIT_ResourceMgr* aResourceMgr = SUIT_Session::session()->resourceMgr();
961 bool isShowGroupNames = aResourceMgr->booleanValue("VTKViewer", "show_group_names", false);
962 myIsDisplayNameActor = theIsDisplayNameActor && isShowGroupNames;
967 To set text of name actor
968 \param theText - text of name actor
972 ::SetNameActorText(const char* theText)
974 myNameActor->SetText(theText);
978 To set offset of name actor
979 \param theOffset - offset of name actor
983 ::SetNameActorOffset(double theOffset[2])
985 myNameActor->SetOffset(theOffset);
989 To get size of name actor
990 \param theRenderer - renderer
991 \param theSize - size of name actor
995 ::GetNameActorSize(vtkRenderer* theRenderer, double theSize[2]) const
997 myNameActor->GetSize(theRenderer, theSize);
1001 Update visibility of name actors
1005 ::UpdateNameActors()
1007 if( vtkRenderer* aRenderer = GetRenderer() )
1009 double anOffset[2] = { 0, 0 };
1010 VTK::ActorCollectionCopy aCopy(aRenderer->GetActors());
1011 vtkActorCollection* aCollection = aCopy.GetActors();
1012 for( int anIndex = 0, aNbItems = aCollection->GetNumberOfItems(); anIndex < aNbItems; anIndex++ )
1014 if( SALOME_Actor* anActor = dynamic_cast<SALOME_Actor*>( aCollection->GetItemAsObject( anIndex ) ) )
1016 if( anActor->IsDisplayNameActor() )
1018 anActor->SetNameActorOffset( anOffset );
1019 if( anActor->GetVisibility() )
1022 anActor->GetNameActorSize( aRenderer, aSize );
1023 anOffset[0] = anOffset[0] + aSize[0];
1024 anOffset[1] = anOffset[1] + aSize[1];
1030 myNameActor->SetVisibility( GetVisibility() && IsDisplayNameActor() );
1034 To set up a picker for nodal selection (initialized by SVTK_Renderer::AddActor)
1035 \param thePointPicker - new picker
1039 ::SetPointPicker(vtkPointPicker* thePointPicker)
1041 myPointPicker = thePointPicker;
1045 To set up a picker for cell selection (initialized by SVTK_Renderer::AddActor)
1046 \param theCellPicker - new picker
1050 ::SetCellPicker(vtkCellPicker* theCellPicker)
1052 myCellPicker = theCellPicker;
1056 To set up a picker for point rectangle or polygonal selection (initialized by SVTK_Renderer::AddActor)
1057 \param theAreaPicker - new picker
1061 ::SetPointAreaPicker(SVTK_AreaPicker* theAreaPicker)
1063 myPointAreaPicker = theAreaPicker;
1067 To set up a picker for cell rectangle of polygonal selection (initialized by SVTK_Renderer::AddActor)
1068 \param theAreaPicker - new picker
1072 ::SetCellAreaPicker(SVTK_AreaPicker* theAreaPicker)
1074 myCellAreaPicker = theAreaPicker;
1078 To find a gravity center of object
1079 \param theObjId - identification of object
1083 ::GetGravityCenter( int theObjId )
1085 double* result = new double[3];
1086 for( int i = 0; i < 3; i++ )
1089 vtkPoints* points = GetElemCell( theObjId )->GetPoints();
1090 int nbPoints = points->GetNumberOfPoints();
1095 for( int i = 0; i < nbPoints; i++ )
1097 double* aPoint = points->GetPoint(i);
1098 result[0] += aPoint[0];
1099 result[1] += aPoint[1];
1100 result[2] += aPoint[2];
1102 result[0] = result[0] / nbPoints;
1103 result[1] = result[1] / nbPoints;
1104 result[2] = result[2] / nbPoints;
1110 To set up a prehighlight property (initialized by SVTK_Renderer::AddActor)
1114 ::SetPreHighlightProperty(vtkProperty* theProperty)
1116 myPreHighlightActor->SetProperty(theProperty);
1120 To set up a highlight property (initialized by SVTK_Renderer::AddActor)
1124 ::SetHighlightProperty(vtkProperty* theProperty)
1126 myHighlightActor->SetProperty(theProperty);
1130 Set standard point marker
1131 \param theMarkerType type of the marker
1132 \param theMarkerScale scale of the marker
1136 ::SetMarkerStd( VTK::MarkerType theMarkerType, VTK::MarkerScale theMarkerScale )
1138 myPreHighlightActor->SetMarkerStd( theMarkerType, theMarkerScale );
1139 myHighlightActor->SetMarkerStd( theMarkerType, theMarkerScale );
1143 Set custom point marker
1144 \param theMarkerId id of the marker texture
1145 \param theMarkerTexture marker texture
1149 ::SetMarkerTexture( int theMarkerId, VTK::MarkerTexture theMarkerTexture )
1151 myPreHighlightActor->SetMarkerTexture( theMarkerId, theMarkerTexture );
1152 myHighlightActor->SetMarkerTexture( theMarkerId, theMarkerTexture );
1156 Get type of the point marker
1157 \return type of the point marker
1163 return myPreHighlightActor->GetMarkerType();
1167 Get scale of the point marker
1168 \return scale of the point marker
1174 return myPreHighlightActor->GetMarkerScale();
1178 Get texture identifier of the point marker
1179 \return texture identifier of the point marker
1183 ::GetMarkerTexture()
1185 return myPreHighlightActor->GetMarkerTexture();