X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSVTK%2FSALOME_Actor.cxx;h=74c57f9e9ee5f8d95d026c9323a8681c1e3ee134;hb=8c5294030a4c11ca0a18be48fc0165466861adad;hp=9b1b7937d02b90b562884b45d15d114651c3b99c;hpb=9f1a66957ba9a2308f8fdc3f9397140af9df5fd0;p=modules%2Fgui.git diff --git a/src/SVTK/SALOME_Actor.cxx b/src/SVTK/SALOME_Actor.cxx index 9b1b7937d..74c57f9e9 100644 --- a/src/SVTK/SALOME_Actor.cxx +++ b/src/SVTK/SALOME_Actor.cxx @@ -1,30 +1,28 @@ -// SALOME OBJECT : implementation of interactive object visualization for OCC and VTK viewers +// Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS // -// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, -// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. // +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. // +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +// SALOME OBJECT : implementation of interactive object visualization for OCC and VTK viewers // File : SALOME_Actor.cxx // Author : Nicolas REJNERI -// Module : SALOME -// $Header$ /*! \class SALOME_Actor SALOME_Actor.h @@ -33,15 +31,20 @@ #include "SALOME_Actor.h" +#include "SALOME_InteractiveObject.hxx" +#include "VTKViewer_Algorithm.h" #include "VTKViewer_Transform.h" #include "VTKViewer_TransformFilter.h" -#include "VTKViewer_PassThroughFilter.h" #include "VTKViewer_GeometryFilter.h" +#include "VTKViewer_FramedTextActor.h" #include "SVTK_RectPicker.h" #include "SVTK_Actor.h" +#include +#include + // VTK Includes #include #include @@ -58,12 +61,11 @@ #include #include +#include #include #include -using namespace std; - #if defined __GNUC__ #if __GNUC__ == 2 #define __GNUC_2__ @@ -73,28 +75,28 @@ using namespace std; int SALOME_POINT_SIZE = 5; int SALOME_LINE_WIDTH = 3; -//---------------------------------------------------------------------------- namespace { int GetEdgeId(SALOME_Actor* theActor, - vtkPicker* thePicker, - int theObjId) + vtkPicker* thePicker, + int theObjId) { int anEdgeId = 0; if (vtkCell* aPickedCell = theActor->GetElemCell(theObjId)) { - float aPickPosition[3]; + vtkFloatingPointType aPickPosition[3]; thePicker->GetPickPosition(aPickPosition); - float aMinDist = 1000000.0, aDist = 0; + vtkFloatingPointType aMinDist = 1000000.0, aDist = 0; for (int i = 0, iEnd = aPickedCell->GetNumberOfEdges(); i < iEnd; i++){ - if(vtkLine* aLine = vtkLine::SafeDownCast(aPickedCell->GetEdge(i))){ - int subId; float pcoords[3], closestPoint[3], weights[3]; - aLine->EvaluatePosition(aPickPosition,closestPoint,subId,pcoords,aDist,weights); - if (aDist < aMinDist) { - aMinDist = aDist; - anEdgeId = -1 - i; - } - } + if(vtkLine* aLine = vtkLine::SafeDownCast(aPickedCell->GetEdge(i))){ + int subId; + vtkFloatingPointType pcoords[3], closestPoint[3], weights[3]; + aLine->EvaluatePosition(aPickPosition,closestPoint,subId,pcoords,aDist,weights); + if (aDist < aMinDist) { + aMinDist = aDist; + anEdgeId = -1 - i; + } + } } } return anEdgeId; @@ -103,10 +105,10 @@ namespace inline bool CheckDimensionId(Selection_Mode theMode, - SALOME_Actor *theActor, - vtkIdType theObjId) + SALOME_Actor *theActor, + vtkIdType theObjId) { - switch(theMode){ + switch(theMode) { case CellSelection: return true; case EdgeSelection: @@ -115,18 +117,47 @@ namespace return ( theActor->GetObjDimension( theObjId ) == 2 ); case VolumeSelection: return ( theActor->GetObjDimension( theObjId ) == 3 ); + case Elem0DSelection: + return ((theActor->GetObjDimension( theObjId ) == 0) && + theActor->GetElemCell(theObjId) && + (theActor->GetElemCell(theObjId)->GetCellType() == VTK_VERTEX)); + case BallSelection: + return ((theActor->GetObjDimension( theObjId ) == 0) && + theActor->GetElemCell(theObjId) && + (theActor->GetElemCell(theObjId)->GetCellType() == VTK_POLY_VERTEX)); + }; return false; } +} +namespace SVTK +{ + /*! + Make picker work with this actor only + */ + TPickLimiter::TPickLimiter(vtkAbstractPicker* picker, SALOME_Actor* actor):myPicker(picker) + { + myPicker->InitializePickList(); + myPicker->AddPickList( actor ); + myPicker->SetPickFromList( true ); + } + /*! + Unlimit picking + */ + TPickLimiter::~TPickLimiter() + { + myPicker->SetPickFromList( false ); + myPicker->InitializePickList(); + } } -//---------------------------------------------------------------------------- vtkStandardNewMacro(SALOME_Actor); - -//---------------------------------------------------------------------------- +/*! + Constructor +*/ SALOME_Actor ::SALOME_Actor(): myRenderer(NULL), @@ -135,17 +166,21 @@ SALOME_Actor myPreHighlightActor(SVTK_Actor::New()), myHighlightActor(SVTK_Actor::New()), myOutline(vtkOutlineSource::New()), - myOutlineActor(VTKViewer_Actor::New()) + myOutlineActor(VTKViewer_Actor::New()), + myIsDisplayNameActor(false), + myNameActor(VTKViewer_FramedTextActor::New()) { myPreHighlightActor->Delete(); myPreHighlightActor->Initialize(); myPreHighlightActor->PickableOff(); myPreHighlightActor->SetVisibility( false ); + myPreHighlightActor->SetCoincident3DAllowed(true); myHighlightActor->Delete(); myHighlightActor->Initialize(); myHighlightActor->PickableOff(); myHighlightActor->SetVisibility( false ); + myHighlightActor->SetCoincident3DAllowed(true); myOutline->Delete(); @@ -162,16 +197,37 @@ SALOME_Actor myOutlineActor->GetProperty()->SetAmbient(1.0); myOutlineActor->GetProperty()->SetDiffuse(0.0); myOutlineActor->SetVisibility( false ); -} + // Name actor + myNameActor->Delete(); + myNameActor->SetVisibility(false); + myNameActor->SetPickable(false); + myNameActor->SetModePosition(VTKViewer_FramedTextActor::TopRight); + myNameActor->SetLayoutType(VTKViewer_FramedTextActor::Vertical); -//---------------------------------------------------------------------------- + SUIT_ResourceMgr* aResourceMgr = SUIT_Session::session()->resourceMgr(); + + QColor aForegroundColor = aResourceMgr->colorValue( "VTKViewer", "group_names_text_color", Qt::white ); + myNameActor->SetForegroundColor(aForegroundColor.redF(), + aForegroundColor.greenF(), + aForegroundColor.blueF()); + + vtkFloatingPointType aGroupNamesTransparency = 0.5; + aGroupNamesTransparency = aResourceMgr->doubleValue( "VTKViewer", "group_names_transparency", aGroupNamesTransparency ); + myNameActor->SetTransparency(aGroupNamesTransparency); +} + +/*! + Destructor +*/ SALOME_Actor ::~SALOME_Actor() {} -//---------------------------------------------------------------------------- +/*! + \return true if the SALOME_Actor has a reference to SALOME_InteractiveObject +*/ Standard_Boolean SALOME_Actor ::hasIO() @@ -179,6 +235,9 @@ SALOME_Actor return !myIO.IsNull(); } +/*! + \return correspoinding reference to SALOME_InteractiveObject +*/ const Handle(SALOME_InteractiveObject)& SALOME_Actor ::getIO() @@ -186,6 +245,10 @@ SALOME_Actor return myIO; } +/*! + Sets reference to SALOME_InteractiveObject + \param theIO - new SALOME_InteractiveObject +*/ void SALOME_Actor ::setIO(const Handle(SALOME_InteractiveObject)& theIO) @@ -193,17 +256,24 @@ SALOME_Actor myIO = theIO; } +/*! + Sets name the SALOME_Actor + \param theName - new name +*/ void SALOME_Actor ::setName(const char* theName) { - if(hasIO()) + if(hasIO()) myIO->setName(theName); + myNameActor->SetText(theName); Superclass::setName(theName); } -//---------------------------------------------------------------------------- +/*! + Publishes the actor in all its internal devices +*/ void SALOME_Actor ::AddToRender(vtkRenderer* theRenderer) @@ -212,22 +282,33 @@ SALOME_Actor myRenderer = theRenderer; - theRenderer->AddActor( myPreHighlightActor.GetPointer() ); - theRenderer->AddActor( myHighlightActor.GetPointer() ); + myHighlightActor->AddToRender(theRenderer); + myPreHighlightActor->AddToRender(theRenderer); theRenderer->AddActor( myOutlineActor.GetPointer() ); + theRenderer->AddActor( myNameActor.GetPointer() ); } +/*! + Removes the actor from all its internal devices +*/ void SALOME_Actor ::RemoveFromRender(vtkRenderer* theRenderer) { Superclass::RemoveFromRender(theRenderer); + myHighlightActor->RemoveFromRender(theRenderer); + myPreHighlightActor->RemoveFromRender(theRenderer); + theRenderer->RemoveActor( myPreHighlightActor.GetPointer() ); theRenderer->RemoveActor( myHighlightActor.GetPointer() ); theRenderer->RemoveActor( myOutlineActor.GetPointer() ); + theRenderer->RemoveActor( myNameActor.GetPointer() ); } +/*! + \return reference on renderer where it is published +*/ vtkRenderer* SALOME_Actor ::GetRenderer() @@ -235,8 +316,10 @@ SALOME_Actor return myRenderer; } - -//---------------------------------------------------------------------------- +/*! + Sets interactor in order to use vtkInteractorObserver devices + \param theInteractor - new interactor +*/ void SALOME_Actor ::SetInteractor(vtkRenderWindowInteractor* theInteractor) @@ -244,6 +327,9 @@ SALOME_Actor myInteractor = theInteractor; } +/*! + Put a request to redraw the view +*/ void SALOME_Actor ::Update() @@ -251,8 +337,10 @@ SALOME_Actor myInteractor->CreateTimer(VTKI_TIMER_UPDATE); } - -//---------------------------------------------------------------------------- +/*! + Apply view transformation + \param theTransform - transformation +*/ void SALOME_Actor ::SetTransform(VTKViewer_Transform* theTransform) @@ -264,10 +352,14 @@ SALOME_Actor myOutlineActor->SetTransform(theTransform); } - +/*! + Apply additional position +*/ void SALOME_Actor -::SetPosition(float _arg1, float _arg2, float _arg3) +::SetPosition(vtkFloatingPointType _arg1, + vtkFloatingPointType _arg2, + vtkFloatingPointType _arg3) { Superclass::SetPosition(_arg1,_arg2,_arg3); @@ -276,16 +368,20 @@ SALOME_Actor myOutlineActor->SetPosition(_arg1,_arg2,_arg3); } - +/*! + Apply additional position +*/ void SALOME_Actor -::SetPosition(float _arg[3]) +::SetPosition(vtkFloatingPointType _arg[3]) { SetPosition(_arg[0],_arg[1],_arg[2]); } - -//---------------------------------------------------------------- +/*! + Shows/hides actor + \param theVisibility - new visibility state +*/ void SALOME_Actor ::SetVisibility( int theVisibility ) @@ -302,10 +398,24 @@ SALOME_Actor myHighlightActor->SetVisibility( theVisibility && isHighlighted() && aHasIndex); } } + + UpdateNameActors(); } +/*! + Gets know whether the actor should be displayed or not +*/ +bool +SALOME_Actor +::ShouldBeDisplayed() +{ + return true; +} -//---------------------------------------------------------------- +/*! + Set selector in order to the actor at any time can restore current selection + \param theSelector - new selector +*/ void SALOME_Actor ::SetSelector(SVTK_Selector* theSelector) @@ -313,6 +423,9 @@ SALOME_Actor mySelector = theSelector; } +/*! + To map current selection to VTK representation +*/ void SALOME_Actor ::Highlight(bool theIsHighlight) @@ -327,20 +440,22 @@ SALOME_Actor mySelector->GetIndex( getIO(), aMapIndex ); switch( mySelectionMode ){ case NodeSelection: - myHighlightActor->GetProperty()->SetRepresentationToPoints(); - myHighlightActor->MapPoints( this, aMapIndex ); - break; + myHighlightActor->GetProperty()->SetRepresentationToPoints(); + myHighlightActor->MapPoints( this, aMapIndex ); + break; case EdgeOfCellSelection: - myHighlightActor->GetProperty()->SetRepresentationToWireframe(); - myHighlightActor->MapEdge( this, aMapIndex ); - break; + myHighlightActor->GetProperty()->SetRepresentationToWireframe(); + myHighlightActor->MapEdge( this, aMapIndex ); + break; case CellSelection: case EdgeSelection: case FaceSelection: case VolumeSelection: - myHighlightActor->GetProperty()->SetRepresentationToSurface(); - myHighlightActor->MapCells( this, aMapIndex ); - break; + case Elem0DSelection: + case BallSelection: + myHighlightActor->GetProperty()->SetRepresentationToSurface(); + myHighlightActor->MapCells( this, aMapIndex ); + break; } myHighlightActor->SetVisibility( GetVisibility() && theIsHighlight ); } @@ -349,12 +464,16 @@ SALOME_Actor highlight(theIsHighlight); } +/*! + Updates visibility of the highlight devices +*/ void SALOME_Actor ::highlight(bool theIsHighlight) { - float aBounds[6]; - GetInput()->GetBounds(aBounds); + vtkFloatingPointType aBounds[6]; + vtkDataSet * aDataSet = GetHighlightedDataSet(); + aDataSet->GetBounds(aBounds); myOutline->SetBounds(aBounds); myOutlineActor->SetVisibility( GetVisibility() && theIsHighlight ); @@ -362,57 +481,67 @@ SALOME_Actor } -//---------------------------------------------------------------- +/*! + To process prehighlight (called from SVTK_InteractorStyle) +*/ bool SALOME_Actor ::PreHighlight(vtkInteractorStyle *theInteractorStyle, - SVTK_SelectionEvent* theSelectionEvent, - bool theIsHighlight) + SVTK_SelectionEvent* theSelectionEvent, + bool theIsHighlight) { + if ( !GetPickable() ) + return false; + vtkRenderer *aRenderer = theInteractorStyle->GetCurrentRenderer(); // myPreHighlightActor->SetVisibility( false ); bool anIsPreselected = myIsPreselected; - + SetPreSelected( false ); + Selection_Mode aSelectionMode = theSelectionEvent->mySelectionMode; bool anIsChanged = (mySelectionMode != aSelectionMode); - float x = theSelectionEvent->myX; - float y = theSelectionEvent->myY; - float z = 0.0; + myPreHighlightActor->SetMarkerEnabled( aSelectionMode == NodeSelection ); - if( !theIsHighlight ) { - SetPreSelected( false ); - vtkActorCollection* theActors = aRenderer->GetActors(); - theActors->InitTraversal(); - while( vtkActor *ac = theActors->GetNextActor() ) - if( SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( ac ) ) - if( anActor->hasIO() && myIO->isSame( anActor->getIO() ) ) - anActor->SetPreSelected( false ); + vtkFloatingPointType x = theSelectionEvent->myX; + vtkFloatingPointType y = theSelectionEvent->myY; + vtkFloatingPointType z = 0.0; + if( !theIsHighlight ) { + if ( hasIO() ) { + VTK::ActorCollectionCopy aCopy(aRenderer->GetActors()); + vtkActorCollection* theActors = aCopy.GetActors(); + theActors->InitTraversal(); + while( vtkActor *ac = theActors->GetNextActor() ) + if( SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( ac ) ) + if( anActor->hasIO() && myIO->isSame( anActor->getIO() ) ) + anActor->SetPreSelected( false ); + } }else{ - switch(aSelectionMode){ + switch(aSelectionMode) { case NodeSelection: { + SVTK::TPickLimiter aPickLimiter( myPointPicker, this ); myPointPicker->Pick( x, y, z, aRenderer ); int aVtkId = myPointPicker->GetPointId(); if( aVtkId >= 0 && mySelector->IsValid( this, aVtkId, true ) ) { - int anObjId = GetNodeObjId( aVtkId ); - myIsPreselected = (anObjId >= 0); - if(myIsPreselected){ - const TColStd_IndexedMapOfInteger& aMapIndex = myPreHighlightActor->GetMapIndex(); - int anExtent = aMapIndex.Extent(); - anIsChanged |= (anExtent == 0 || anExtent > 0 && anObjId != aMapIndex(1)); - if(anIsChanged){ - TColStd_IndexedMapOfInteger aMapIndex; - aMapIndex.Add( anObjId ); - - myPreHighlightActor->GetProperty()->SetRepresentationToPoints(); - myPreHighlightActor->MapPoints( this, aMapIndex ); - } - myPreHighlightActor->SetVisibility( true ); - } + int anObjId = GetNodeObjId( aVtkId ); + myIsPreselected = (anObjId >= 0); + if(myIsPreselected){ + const TColStd_IndexedMapOfInteger& aMapIndex = myPreHighlightActor->GetMapIndex(); + int anExtent = aMapIndex.Extent(); + anIsChanged |= (anExtent == 0 || (anExtent > 0 && anObjId != aMapIndex(1))); + if(anIsChanged){ + TColStd_IndexedMapOfInteger aMapIndex; + aMapIndex.Add( anObjId ); + + myPreHighlightActor->GetProperty()->SetRepresentationToPoints(); + myPreHighlightActor->MapPoints( this, aMapIndex ); + } + myPreHighlightActor->SetVisibility( true ); + } } break; } @@ -420,72 +549,79 @@ SALOME_Actor case EdgeSelection: case FaceSelection: case VolumeSelection: + case Elem0DSelection: + case BallSelection: { + SVTK::TPickLimiter aPickLimiter( myCellPicker, this ); myCellPicker->Pick( x, y, z, aRenderer ); int aVtkId = myCellPicker->GetCellId(); if ( aVtkId >= 0 && mySelector->IsValid( this, aVtkId ) && hasIO() ) { - int anObjId = GetElemObjId (aVtkId ); - if ( anObjId >= 0 ) { - myIsPreselected = CheckDimensionId(aSelectionMode,this,anObjId); - if(myIsPreselected){ - const TColStd_IndexedMapOfInteger& aMapIndex = myPreHighlightActor->GetMapIndex(); - int anExtent = aMapIndex.Extent(); - anIsChanged |= (anExtent == 0 || anExtent > 0 && anObjId != aMapIndex(1)); - if(anIsChanged){ - TColStd_IndexedMapOfInteger aMapIndex; - aMapIndex.Add( anObjId ); - - myPreHighlightActor->GetProperty()->SetRepresentationToSurface(); - myPreHighlightActor->MapCells( this, aMapIndex ); - } - myPreHighlightActor->SetVisibility( true ); - } - } + int anObjId = GetElemObjId (aVtkId ); + if ( anObjId >= 0 ) { + myIsPreselected = CheckDimensionId(aSelectionMode,this,anObjId); + if(myIsPreselected){ + const TColStd_IndexedMapOfInteger& aMapIndex = myPreHighlightActor->GetMapIndex(); + int anExtent = aMapIndex.Extent(); + anIsChanged |= (anExtent == 0 || (anExtent > 0 && anObjId != aMapIndex(1))); + if(anIsChanged){ + TColStd_IndexedMapOfInteger aMapIndex; + aMapIndex.Add( anObjId ); + + myPreHighlightActor->GetProperty()->SetRepresentationToSurface(); + myPreHighlightActor->MapCells( this, aMapIndex ); + } + myPreHighlightActor->SetVisibility( true ); + } + } } break; } case EdgeOfCellSelection: { + SVTK::TPickLimiter aPickLimiter( myCellPicker, this ); myCellPicker->Pick( x, y, z, aRenderer ); int aVtkId = myCellPicker->GetCellId(); if ( aVtkId >= 0 && mySelector->IsValid( this, aVtkId )) { - int anObjId = GetElemObjId( aVtkId ); - if ( anObjId >= 0 ) { - int anEdgeId = GetEdgeId(this,myCellPicker.GetPointer(),anObjId); - myIsPreselected = anEdgeId < 0; - if(myIsPreselected){ - const TColStd_IndexedMapOfInteger& aMapIndex = myPreHighlightActor->GetMapIndex(); - int anExtent = aMapIndex.Extent(); - anIsChanged |= (anExtent == 0); - anIsChanged |= (anExtent == 2 && (anObjId != aMapIndex(1) || anEdgeId != aMapIndex(2))); - if(anIsChanged){ - TColStd_IndexedMapOfInteger aMapIndex; - aMapIndex.Add( anObjId ); - aMapIndex.Add( anEdgeId ); - - myPreHighlightActor->GetProperty()->SetRepresentationToWireframe(); - myPreHighlightActor->MapEdge( this, aMapIndex ); - } - myPreHighlightActor->SetVisibility( true ); - } - } + int anObjId = GetElemObjId( aVtkId ); + if ( anObjId >= 0 ) { + int anEdgeId = GetEdgeId(this,myCellPicker.GetPointer(),anObjId); + myIsPreselected = anEdgeId < 0; + if(myIsPreselected){ + const TColStd_IndexedMapOfInteger& aMapIndex = myPreHighlightActor->GetMapIndex(); + int anExtent = aMapIndex.Extent(); + anIsChanged |= (anExtent == 0 || anExtent == 1); + anIsChanged |= (anExtent == 2 && (anObjId != aMapIndex(1) || anEdgeId != aMapIndex(2))); + if(anIsChanged){ + TColStd_IndexedMapOfInteger aMapIndex; + aMapIndex.Add( anObjId ); + aMapIndex.Add( anEdgeId ); + + myPreHighlightActor->GetProperty()->SetRepresentationToWireframe(); + myPreHighlightActor->MapEdge( this, aMapIndex ); + } + myPreHighlightActor->SetVisibility( true ); + } + } } break; } case ActorSelection : { if( !mySelector->IsSelected( myIO ) ) { - SetPreSelected( true ); - - vtkActorCollection* theActors = aRenderer->GetActors(); - theActors->InitTraversal(); - while( vtkActor *anAct = theActors->GetNextActor() ) { - if( anAct != this ) - if( SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( anAct ) ) - if( anActor->hasIO() && myIO->isSame( anActor->getIO() ) ) - anActor->SetPreSelected( true ); + SetPreSelected( true ); + + if ( hasIO() ) { + VTK::ActorCollectionCopy aCopy(aRenderer->GetActors()); + vtkActorCollection* theActors = aCopy.GetActors(); + theActors->InitTraversal(); + while( vtkActor *anAct = theActors->GetNextActor() ) { + if( anAct != this ) + if( SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( anAct ) ) + if( anActor->hasIO() && myIO->isSame( anActor->getIO() ) ) + anActor->SetPreSelected( true ); + } } } } @@ -500,14 +636,18 @@ SALOME_Actor return anIsChanged; } - -//---------------------------------------------------------------- +/*! + To process highlight (called from SVTK_InteractorStyle) +*/ bool SALOME_Actor ::Highlight(vtkInteractorStyle *theInteractorStyle, - SVTK_SelectionEvent* theSelectionEvent, - bool theIsHighlight) + SVTK_SelectionEvent* theSelectionEvent, + bool theIsHighlight) { + if ( !GetPickable() || !mySelector ) + return false; + myOutlineActor->SetVisibility( false ); myHighlightActor->SetVisibility( false ); @@ -515,26 +655,32 @@ SALOME_Actor // Selection_Mode aSelectionMode = theSelectionEvent->mySelectionMode; bool anIsShift = theSelectionEvent->myIsShift; - if( !anIsShift ) { + if( !anIsShift || !theIsHighlight ) { mySelector->RemoveIObject( this ); } - float x = theSelectionEvent->myX; - float y = theSelectionEvent->myY; - float z = 0.0; + if ( !theIsHighlight ) + return true; + + myHighlightActor->SetMarkerEnabled( aSelectionMode == NodeSelection ); + + vtkFloatingPointType x = theSelectionEvent->myX; + vtkFloatingPointType y = theSelectionEvent->myY; + vtkFloatingPointType z = 0.0; if( !theSelectionEvent->myIsRectangle ) { switch(aSelectionMode){ case NodeSelection: { + SVTK::TPickLimiter aPickLimiter( myPointPicker, this ); myPointPicker->Pick( x, y, z, aRenderer ); int aVtkId = myPointPicker->GetPointId(); if( aVtkId >= 0 && mySelector->IsValid( this, aVtkId, true ) ) { - int anObjId = GetNodeObjId( aVtkId ); - if( anObjId >= 0 ) { - mySelector->AddOrRemoveIndex( myIO, anObjId, anIsShift ); - mySelector->AddIObject( this ); - } + int anObjId = GetNodeObjId( aVtkId ); + if( hasIO() && anObjId >= 0 ) { + mySelector->AddOrRemoveIndex( myIO, anObjId, anIsShift ); + mySelector->AddIObject( this ); + } } break; } @@ -542,45 +688,51 @@ SALOME_Actor case EdgeSelection: case FaceSelection: case VolumeSelection: + case Elem0DSelection: + case BallSelection: { + SVTK::TPickLimiter aPickLimiter( myCellPicker, this ); myCellPicker->Pick( x, y, z, aRenderer ); int aVtkId = myCellPicker->GetCellId(); if( aVtkId >= 0 && mySelector->IsValid( this, aVtkId ) ) { - int anObjId = GetElemObjId( aVtkId ); - if( anObjId >= 0 ) { - if ( CheckDimensionId(aSelectionMode,this,anObjId) ) { - mySelector->AddOrRemoveIndex( myIO, anObjId, anIsShift ); - mySelector->AddIObject( this ); - } - } + int anObjId = GetElemObjId( aVtkId ); + if( anObjId >= 0 ) { + if ( hasIO() && CheckDimensionId(aSelectionMode,this,anObjId) ) { + mySelector->AddOrRemoveIndex( myIO, anObjId, anIsShift ); + mySelector->AddIObject( this ); + } + } } break; } case EdgeOfCellSelection: { + SVTK::TPickLimiter aPickLimiter( myCellPicker, this ); myCellPicker->Pick( x, y, z, aRenderer ); int aVtkId = myCellPicker->GetCellId(); if( aVtkId >= 0 && mySelector->IsValid( this, aVtkId ) ) { - int anObjId = GetElemObjId( aVtkId ); - if( anObjId >= 0 ) { - int anEdgeId = GetEdgeId(this,myCellPicker.GetPointer(),anObjId); - if( anEdgeId < 0 ) { - mySelector->AddOrRemoveIndex( myIO, anObjId, false ); - mySelector->AddOrRemoveIndex( myIO, anEdgeId, true ); - mySelector->AddIObject( this ); - } - } + int anObjId = GetElemObjId( aVtkId ); + if( anObjId >= 0 ) { + int anEdgeId = GetEdgeId(this,myCellPicker.GetPointer(),anObjId); + if( hasIO() && anEdgeId < 0 ) { + mySelector->AddOrRemoveIndex( myIO, anObjId, false ); + mySelector->AddOrRemoveIndex( myIO, anEdgeId, true ); + mySelector->AddIObject( this ); + } + } } break; } case ActorSelection : { - if( mySelector->IsSelected( myIO ) && anIsShift ) - mySelector->RemoveIObject( this ); - else { - mySelector->AddIObject( this ); + if ( hasIO() ) { + if( mySelector->IsSelected( myIO ) && anIsShift ) + mySelector->RemoveIObject( this ); + else { + mySelector->AddIObject( this ); + } } break; } @@ -588,72 +740,72 @@ SALOME_Actor break; } }else{ - float xLast = theSelectionEvent->myLastX; - float yLast = theSelectionEvent->myLastY; - float zLast = 0.0; + vtkFloatingPointType xLast = theSelectionEvent->myLastX; + vtkFloatingPointType yLast = theSelectionEvent->myLastY; + vtkFloatingPointType zLast = 0.0; - float x1 = x < xLast ? x : xLast; - float y1 = y < yLast ? y : yLast; - float z1 = z < zLast ? z : zLast; - float x2 = x > xLast ? x : xLast; - float y2 = y > yLast ? y : yLast; - float z2 = z > zLast ? z : zLast; + vtkFloatingPointType x1 = x < xLast ? x : xLast; + vtkFloatingPointType y1 = y < yLast ? y : yLast; + vtkFloatingPointType z1 = z < zLast ? z : zLast; + vtkFloatingPointType x2 = x > xLast ? x : xLast; + vtkFloatingPointType y2 = y > yLast ? y : yLast; + vtkFloatingPointType z2 = z > zLast ? z : zLast; switch(aSelectionMode){ case NodeSelection: { - myPointRectPicker->InitializePickList(); - myPointRectPicker->AddPickList(this); + + SVTK::TPickLimiter aPickLimiter( myPointRectPicker, this ); myPointRectPicker->Pick( x1, y1, z1, x2, y2, z2, aRenderer ); const SVTK_RectPicker::TVectorIdsMap& aVectorIdsMap = myPointRectPicker->GetPointIdsMap(); SVTK_RectPicker::TVectorIdsMap::const_iterator aMapIter = aVectorIdsMap.find(this); TColStd_MapOfInteger anIndexes; if(aMapIter != aVectorIdsMap.end()){ - const SVTK_RectPicker::TVectorIds& aVectorIds = aMapIter->second; - vtkIdType anEnd = aVectorIds.size(); - SVTK_RectPicker::TVectorIds::const_iterator anIdIter = aVectorIds.begin(); - for(vtkIdType anId = 0; anId < anEnd; anId++ ) { - int aPointId = aVectorIds[anId]; - if( aPointId >= 0 && mySelector->IsValid( this, aPointId, true ) ) { - int anObjId = GetNodeObjId( aPointId ); - anIndexes.Add( anObjId ); - } - } + const SVTK_RectPicker::TVectorIds& aVectorIds = aMapIter->second; + vtkIdType anEnd = aVectorIds.size(); + for(vtkIdType anId = 0; anId < anEnd; anId++ ) { + int aPointId = aVectorIds[anId]; + if( aPointId >= 0 && mySelector->IsValid( this, aPointId, true ) ) { + int anObjId = GetNodeObjId( aPointId ); + anIndexes.Add( anObjId ); + } + } } - if( !anIndexes.IsEmpty() ) { - mySelector->AddOrRemoveIndex( myIO, anIndexes, anIsShift ); - mySelector->AddIObject( this ); - anIndexes.Clear(); + if ( hasIO() ) { + if( !anIndexes.IsEmpty() ) { + mySelector->AddOrRemoveIndex( myIO, anIndexes, anIsShift ); + mySelector->AddIObject( this ); + anIndexes.Clear(); + } + else if ( !anIsShift ) + mySelector->RemoveIObject( this ); } - else - mySelector->RemoveIObject( this ); - break; } case ActorSelection : { - float aPnt[3]; - float* aBounds = GetBounds(); + vtkFloatingPointType aPnt[3]; + vtkFloatingPointType* aBounds = GetBounds(); bool anIsPicked = true; for( int i = 0; i <= 1; i++ ) { - for( int j = 2; j <= 3; j++ ) { - for( int k = 4; k <= 5; k++ ) { - aRenderer->SetWorldPoint( aBounds[ i ], aBounds[ j ], aBounds[ k ], 1.0 ); - aRenderer->WorldToDisplay(); - aRenderer->GetDisplayPoint( aPnt ); - - if( aPnt[0] < x1 || aPnt[0] > x2 || aPnt[1] < y1 || aPnt[1] > y2 ) { - anIsPicked = false; - break; - } - } - } + for( int j = 2; j <= 3; j++ ) { + for( int k = 4; k <= 5; k++ ) { + aRenderer->SetWorldPoint( aBounds[ i ], aBounds[ j ], aBounds[ k ], 1.0 ); + aRenderer->WorldToDisplay(); + aRenderer->GetDisplayPoint( aPnt ); + + if( aPnt[0] < x1 || aPnt[0] > x2 || aPnt[1] < y1 || aPnt[1] > y2 ) { + anIsPicked = false; + break; + } + } + } } if( anIsPicked ) - mySelector->AddIObject(this); + mySelector->AddIObject(this); break; } @@ -661,32 +813,40 @@ SALOME_Actor case EdgeSelection: case FaceSelection: case VolumeSelection: + case Elem0DSelection: + case BallSelection: { - myCellRectPicker->InitializePickList(); - myCellRectPicker->AddPickList(this); + SVTK::TPickLimiter aPickLimiter( myCellRectPicker, this ); myCellRectPicker->Pick( x1, y1, z1, x2, y2, z2, aRenderer ); const SVTK_RectPicker::TVectorIdsMap& aVectorIdsMap = myCellRectPicker->GetCellIdsMap(); SVTK_RectPicker::TVectorIdsMap::const_iterator aMapIter = aVectorIdsMap.find(this); TColStd_MapOfInteger anIndexes; if(aMapIter != aVectorIdsMap.end()){ - const SVTK_RectPicker::TVectorIds& aVectorIds = aMapIter->second; - vtkIdType anEnd = aVectorIds.size(); - SVTK_RectPicker::TVectorIds::const_iterator anIdIter = aVectorIds.begin(); - for(vtkIdType anId = 0; anId < anEnd; anId++ ) { - int aCellId = aVectorIds[anId]; - if ( !mySelector->IsValid( this, aCellId ) ) - continue; - - int anObjId = GetElemObjId( aCellId ); - if( anObjId != -1 ) - if ( CheckDimensionId(aSelectionMode,this,anObjId) ) { - anIndexes.Add(anObjId); - } + const SVTK_RectPicker::TVectorIds& aVectorIds = aMapIter->second; + vtkIdType anEnd = aVectorIds.size(); + for(vtkIdType anId = 0; anId < anEnd; anId++ ) { + int aCellId = aVectorIds[anId]; + if ( !mySelector->IsValid( this, aCellId ) ) + continue; + + int anObjId = GetElemObjId( aCellId ); + if( anObjId != -1 ) + if ( CheckDimensionId(aSelectionMode,this,anObjId) ) { + anIndexes.Add(anObjId); + } + } + } + + if ( hasIO() ) { + if( !anIndexes.IsEmpty() ) { + mySelector->AddOrRemoveIndex( myIO, anIndexes, anIsShift ); + mySelector->AddIObject( this ); + anIndexes.Clear(); } + else if ( !anIsShift ) + mySelector->RemoveIObject( this ); } - mySelector->AddOrRemoveIndex( myIO, anIndexes, anIsShift ); - mySelector->AddIObject( this ); } default: break; @@ -698,7 +858,102 @@ SALOME_Actor return true; } -//---------------------------------------------------------------------------- +/*! + To get flag of displaying of name actor + \return flag to display or not to display name actor +*/ +bool +SALOME_Actor +::IsDisplayNameActor() const +{ + return myIsDisplayNameActor; +} + +/*! + To set flag of displaying of name actor + \param theIsDisplayNameActor flag to display or not to display name actor +*/ +void +SALOME_Actor +::SetIsDisplayNameActor(bool theIsDisplayNameActor) +{ + SUIT_ResourceMgr* aResourceMgr = SUIT_Session::session()->resourceMgr(); + bool isShowGroupNames = aResourceMgr->booleanValue("VTKViewer", "show_group_names", false); + myIsDisplayNameActor = theIsDisplayNameActor && isShowGroupNames; + UpdateNameActors(); +} + +/*! + To set text of name actor + \param theText - text of name actor +*/ +void +SALOME_Actor +::SetNameActorText(const char* theText) +{ + myNameActor->SetText(theText); +} + +/*! + To set offset of name actor + \param theOffset - offset of name actor +*/ +void +SALOME_Actor +::SetNameActorOffset(int theOffset[2]) +{ + myNameActor->SetOffset(theOffset); +} + +/*! + To get size of name actor + \param theRenderer - renderer + \param theSize - size of name actor +*/ +void +SALOME_Actor +::GetNameActorSize(vtkRenderer* theRenderer, int theSize[2]) const +{ + myNameActor->GetSize(theRenderer, theSize); +} + +/*! + Update visibility of name actors +*/ +void +SALOME_Actor +::UpdateNameActors() +{ + if( vtkRenderer* aRenderer = GetRenderer() ) + { + int anOffset[2] = { 0, 0 }; + VTK::ActorCollectionCopy aCopy(aRenderer->GetActors()); + vtkActorCollection* aCollection = aCopy.GetActors(); + for( int anIndex = 0, aNbItems = aCollection->GetNumberOfItems(); anIndex < aNbItems; anIndex++ ) + { + if( SALOME_Actor* anActor = dynamic_cast( aCollection->GetItemAsObject( anIndex ) ) ) + { + if( anActor->IsDisplayNameActor() ) + { + anActor->SetNameActorOffset( anOffset ); + if( anActor->GetVisibility() ) + { + int aSize[2]; + anActor->GetNameActorSize( aRenderer, aSize ); + anOffset[0] = anOffset[0] + aSize[0]; + anOffset[1] = anOffset[1] + aSize[1]; + } + } + } + } + } + myNameActor->SetVisibility( GetVisibility() && IsDisplayNameActor() ); +} + +/*! + To set up a picker for nodal selection (initialized by SVTK_Renderer::AddActor) + \param thePointPicker - new picker +*/ void SALOME_Actor ::SetPointPicker(vtkPointPicker* thePointPicker) @@ -706,6 +961,10 @@ SALOME_Actor myPointPicker = thePointPicker; } +/*! + To set up a picker for cell selection (initialized by SVTK_Renderer::AddActor) + \param theCellPicker - new picker +*/ void SALOME_Actor ::SetCellPicker(vtkCellPicker* theCellPicker) @@ -713,6 +972,10 @@ SALOME_Actor myCellPicker = theCellPicker; } +/*! + To set up a picker for point rectangle selection (initialized by SVTK_Renderer::AddActor) + \param theRectPicker - new picker +*/ void SALOME_Actor ::SetPointRectPicker(SVTK_RectPicker* theRectPicker) @@ -720,6 +983,10 @@ SALOME_Actor myPointRectPicker = theRectPicker; } +/*! + To set up a picker for cell rectangle selection (initialized by SVTK_Renderer::AddActor) + \param theRectPicker - new picker +*/ void SALOME_Actor ::SetCellRectPicker(SVTK_RectPicker* theRectPicker) @@ -727,7 +994,9 @@ SALOME_Actor myCellRectPicker = theRectPicker; } -//---------------------------------------------------------------------------- +/*! + To set up a prehighlight property (initialized by SVTK_Renderer::AddActor) +*/ void SALOME_Actor ::SetPreHighlightProperty(vtkProperty* theProperty) @@ -735,9 +1004,71 @@ SALOME_Actor myPreHighlightActor->SetProperty(theProperty); } +/*! + To set up a highlight property (initialized by SVTK_Renderer::AddActor) +*/ void SALOME_Actor ::SetHighlightProperty(vtkProperty* theProperty) { myHighlightActor->SetProperty(theProperty); } + +/*! + Set standard point marker + \param theMarkerType type of the marker + \param theMarkerScale scale of the marker +*/ +void +SALOME_Actor +::SetMarkerStd( VTK::MarkerType theMarkerType, VTK::MarkerScale theMarkerScale ) +{ + myPreHighlightActor->SetMarkerStd( theMarkerType, theMarkerScale ); + myHighlightActor->SetMarkerStd( theMarkerType, theMarkerScale ); +} + +/*! + Set custom point marker + \param theMarkerId id of the marker texture + \param theMarkerTexture marker texture +*/ +void +SALOME_Actor +::SetMarkerTexture( int theMarkerId, VTK::MarkerTexture theMarkerTexture ) +{ + myPreHighlightActor->SetMarkerTexture( theMarkerId, theMarkerTexture ); + myHighlightActor->SetMarkerTexture( theMarkerId, theMarkerTexture ); +} + +/*! + Get type of the point marker + \return type of the point marker +*/ +VTK::MarkerType +SALOME_Actor +::GetMarkerType() +{ + return myPreHighlightActor->GetMarkerType(); +} + +/*! + Get scale of the point marker + \return scale of the point marker +*/ +VTK::MarkerScale +SALOME_Actor +::GetMarkerScale() +{ + return myPreHighlightActor->GetMarkerScale(); +} + +/*! + Get texture identifier of the point marker + \return texture identifier of the point marker + */ +int +SALOME_Actor +::GetMarkerTexture() +{ + return myPreHighlightActor->GetMarkerTexture(); +}