From: apo Date: Tue, 2 Aug 2005 06:59:45 +0000 (+0000) Subject: 1. Move SALOME_Actor to SVTK package X-Git-Tag: BR-D5-38-2003_D2005-12-09~71 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=0e4fcfbfdc3a8863dc72c1014139d7b1b7c28e1d;p=modules%2Fgui.git 1. Move SALOME_Actor to SVTK package 2. Move Highlight/Prehighlight functionality from InteractorStyle to SALOME_Actor --- diff --git a/src/SVTK/Makefile.in b/src/SVTK/Makefile.in index e41cfb610..a9a26f4f0 100755 --- a/src/SVTK/Makefile.in +++ b/src/SVTK/Makefile.in @@ -15,6 +15,7 @@ VPATH=.:@srcdir@ EXPORT_HEADERS= SVTK.h \ SVTK_Prs.h \ SVTK_Actor.h \ + SALOME_Actor.h \ SVTK_CubeAxesActor2D.h \ SVTK_Functor.h \ SVTK_ViewManager.h \ @@ -31,6 +32,7 @@ LIB = libSVTK.la LIB_SRC= SVTK_Prs.cxx \ SVTK_Actor.cxx \ + SALOME_Actor.cxx \ SVTK_CubeAxesActor2D.cxx \ SVTK_Trihedron.cxx \ SVTK_ViewManager.cxx \ diff --git a/src/SVTK/SALOME_Actor.cxx b/src/SVTK/SALOME_Actor.cxx new file mode 100644 index 000000000..b5caa8e5d --- /dev/null +++ b/src/SVTK/SALOME_Actor.cxx @@ -0,0 +1,586 @@ +// SALOME OBJECT : implementation of interactive object visualization for OCC and VTK viewers +// +// 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 +// +// +// +// File : SALOME_Actor.cxx +// Author : Nicolas REJNERI +// Module : SALOME +// $Header$ + +/*! + \class SALOME_Actor SALOME_Actor.h + \brief Abstract class of SALOME Objects in VTK. +*/ + + +#include "SALOME_Actor.h" + +#include "VTKViewer_Transform.h" +#include "VTKViewer_TransformFilter.h" +#include "VTKViewer_PassThroughFilter.h" +#include "VTKViewer_GeometryFilter.h" + +#include "SVTK_Actor.h" +#include "SVTK_InteractorStyle.h" + +// SALOME Includes +//#include "utilities.h" + +// VTK Includes +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +//using namespace std; + + +#if defined __GNUC__ + #if __GNUC__ == 2 + #define __GNUC_2__ + #endif +#endif + +int SALOME_POINT_SIZE = 3; + + +vtkStandardNewMacro(SALOME_Actor); + + +SALOME_Actor::SALOME_Actor(){ + myIsHighlighted = myIsPreselected = false; + + myRepresentation = 1; + myDisplayMode = myRepresentation - 1; + + myProperty = vtkProperty::New(); + PreviewProperty = NULL; + + myIsInfinite = false; + + myIsResolveCoincidentTopology = true; + + vtkMapper::GetResolveCoincidentTopologyPolygonOffsetParameters(myPolygonOffsetFactor, + myPolygonOffsetUnits); + myStoreMapping = false; + myGeomFilter = VTKViewer_GeometryFilter::New(); + + myTransformFilter = VTKViewer_TransformFilter::New(); + + for(int i = 0; i < 6; i++) + myPassFilter.push_back(VTKViewer_PassThroughFilter::New()); + + // from VISU + myPreHighlightActor = SVTK_Actor::New(); + myPreHighlightActor->GetProperty()->SetColor(0,1,0); + myPreHighlightActor->GetProperty()->SetPointSize(15); + myPreHighlightActor->GetProperty()->SetRepresentationToPoints(); + + myPointProperty = vtkProperty::New(); + myPointProperty->SetColor(1,0,1); + myPointProperty->SetPointSize(15); + myPointProperty->SetRepresentationToPoints(); + + myCellProperty = vtkProperty::New(); + myCellProperty->SetColor(1,1,0); + myCellProperty->SetPointSize(5); + myCellProperty->SetRepresentationToSurface(); + + myEdgeProperty = vtkProperty::New(); + myEdgeProperty->SetColor(1,0,0); + myEdgeProperty->SetPointSize(5); + myEdgeProperty->SetRepresentationToWireframe(); + + myHighlightActor = SVTK_Actor::New(); + myHighlightActor->PickableOff(); + myHighlightActor->SetProperty( myPointProperty ); +} + + +SALOME_Actor::~SALOME_Actor(){ + SetPreviewProperty(NULL); + + myGeomFilter->UnRegisterAllOutputs(); + myGeomFilter->Delete(); + + myTransformFilter->UnRegisterAllOutputs(); + myTransformFilter->Delete(); + + for(int i = 0, iEnd = myPassFilter.size(); i < iEnd; i++){ + if(myPassFilter[i]){ + myPassFilter[i]->UnRegisterAllOutputs(); + myPassFilter[i]->Delete(); + } + } + + myProperty->Delete(); + + // from VISU + myHighlightActor->SetProperty( NULL ); +} + + +void SALOME_Actor::AddToRender(vtkRenderer* theRenderer){ + theRenderer->AddActor(this); + + // from VISU + theRenderer->AddActor( myPreHighlightActor ); + theRenderer->AddActor( myHighlightActor ); +} + +void SALOME_Actor::RemoveFromRender(vtkRenderer* theRenderer){ + theRenderer->RemoveActor(this); + + // from VISU + theRenderer->RemoveActor( myPreHighlightActor ); + theRenderer->RemoveActor( myHighlightActor ); +} + + +void SALOME_Actor::SetTransform(VTKViewer_Transform* theTransform){ + myTransformFilter->SetTransform(theTransform); +} + + +void SALOME_Actor::SetMapper(vtkMapper* theMapper){ + InitPipeLine(theMapper); +} + +void SALOME_Actor::InitPipeLine(vtkMapper* theMapper){ + if(theMapper){ + int anId = 0; + myPassFilter[ anId ]->SetInput( theMapper->GetInput() ); + myPassFilter[ anId + 1]->SetInput( myPassFilter[ anId ]->GetOutput() ); + + anId++; // 1 + myGeomFilter->SetStoreMapping( myStoreMapping ); + myGeomFilter->SetInput( myPassFilter[ anId ]->GetOutput() ); + + anId++; // 2 + myPassFilter[ anId ]->SetInput( myGeomFilter->GetOutput() ); + myPassFilter[ anId + 1 ]->SetInput( myPassFilter[ anId ]->GetOutput() ); + + anId++; // 3 + myTransformFilter->SetInput( myPassFilter[ anId ]->GetPolyDataOutput() ); + + anId++; // 4 + myPassFilter[ anId ]->SetInput( myTransformFilter->GetOutput() ); + myPassFilter[ anId + 1 ]->SetInput( myPassFilter[ anId ]->GetOutput() ); + + anId++; // 5 + if(vtkDataSetMapper* aMapper = dynamic_cast(theMapper)){ + aMapper->SetInput(myPassFilter[anId]->GetOutput()); + }else if(vtkPolyDataMapper* aMapper = dynamic_cast(theMapper)){ + aMapper->SetInput(myPassFilter[anId]->GetPolyDataOutput()); + } + } + vtkLODActor::SetMapper(theMapper); +} + + +void SALOME_Actor::Render(vtkRenderer *ren, vtkMapper* m){ + if(myIsResolveCoincidentTopology){ + int aResolveCoincidentTopology = vtkMapper::GetResolveCoincidentTopology(); + float aFactor, aUnit; + vtkMapper::GetResolveCoincidentTopologyPolygonOffsetParameters(aFactor,aUnit); + + vtkMapper::SetResolveCoincidentTopologyToPolygonOffset(); + vtkMapper::SetResolveCoincidentTopologyPolygonOffsetParameters(myPolygonOffsetFactor, + myPolygonOffsetUnits); + vtkLODActor::Render(ren,m); + + vtkMapper::SetResolveCoincidentTopologyPolygonOffsetParameters(aFactor,aUnit); + vtkMapper::SetResolveCoincidentTopology(aResolveCoincidentTopology); + }else{ + vtkLODActor::Render(ren,m); + } +} + + +void SALOME_Actor::SetResolveCoincidentTopology(bool theIsResolve) { + myIsResolveCoincidentTopology = theIsResolve; +} + +void SALOME_Actor::SetPolygonOffsetParameters(float factor, float units){ + myPolygonOffsetFactor = factor; + myPolygonOffsetUnits = units; +} + +void SALOME_Actor::GetPolygonOffsetParameters(float& factor, float& units){ + factor = myPolygonOffsetFactor; + units = myPolygonOffsetUnits; +} + + +vtkDataSet* SALOME_Actor::GetInput(){ + return myPassFilter.front()->GetOutput(); +} + + +unsigned long int SALOME_Actor::GetMTime(){ + unsigned long mTime = this->Superclass::GetMTime(); + unsigned long time = myTransformFilter->GetMTime(); + mTime = ( time > mTime ? time : mTime ); + if(vtkDataSet *aDataSet = myPassFilter[0]->GetInput()){ + time = aDataSet->GetMTime(); + mTime = ( time > mTime ? time : mTime ); + } + return mTime; +} + + +void SALOME_Actor::SetRepresentation(int theMode) { + switch(myRepresentation){ + case VTK_POINTS : + case VTK_SURFACE : + myProperty->DeepCopy(GetProperty()); + } + switch(theMode){ + case VTK_POINTS : + case VTK_SURFACE : + GetProperty()->DeepCopy(myProperty); + break; + default: + GetProperty()->SetAmbient(1.0); + GetProperty()->SetDiffuse(0.0); + GetProperty()->SetSpecular(0.0); + } + switch(theMode){ + case 3 : + myGeomFilter->SetInside(true); + GetProperty()->SetRepresentation(1); + break; + case VTK_POINTS : + GetProperty()->SetPointSize(SALOME_POINT_SIZE); + default : + GetProperty()->SetRepresentation(theMode); + myGeomFilter->SetInside(false); + } + myRepresentation = theMode; +} + +int SALOME_Actor::GetRepresentation(){ + return myRepresentation; +} + + +vtkCell* SALOME_Actor::GetElemCell(int theObjID){ + return GetInput()->GetCell(theObjID); +} + + +float* SALOME_Actor::GetNodeCoord(int theObjID){ + return GetInput()->GetPoint(theObjID); +} + + +//================================================================================= +// function : GetObjDimension +// purpose : Return object dimension. +// Virtual method shoulb be redifined by derived classes +//================================================================================= +int SALOME_Actor::GetObjDimension( const int theObjId ) +{ + if ( vtkCell* aCell = GetElemCell(theObjId) ) + return aCell->GetCellDimension(); + return 0; +} + + +bool SALOME_Actor::IsInfinitive(){ + return myIsInfinite; +} + + +void SALOME_Actor::SetOpacity(float theOpacity){ + myOpacity = theOpacity; + GetProperty()->SetOpacity(theOpacity); +} + +float SALOME_Actor::GetOpacity(){ + return myOpacity; +} + + +void SALOME_Actor::SetColor(float r,float g,float b){ + GetProperty()->SetColor(r,g,b); +} + +void SALOME_Actor::GetColor(float& r,float& g,float& b){ + float aColor[3]; + GetProperty()->GetColor(aColor); + r = aColor[0]; + g = aColor[1]; + b = aColor[2]; +} + + +int SALOME_Actor::getDisplayMode(){ + return myDisplayMode; +} + +void SALOME_Actor::setDisplayMode(int theMode){ + SetRepresentation(theMode+1); + myDisplayMode = GetRepresentation() - 1; +} + +// from VISU + +//---------------------------------------------------------------- +void SALOME_Actor::highlight( bool theHighlight ) +{ + //cout << "SALOME_Actor::highlight " << ( theHighlight ? "on" : "off" ) << endl; + + myHighlightActor->SetVisibility( theHighlight ); +} + +//---------------------------------------------------------------- +void SALOME_Actor::SetVisibility( int theVisibility ) +{ + vtkProp::SetVisibility( theVisibility ); + + myHighlightActor->SetVisibility( theVisibility && isHighlighted() ); +} + +//---------------------------------------------------------------- +bool SALOME_Actor::PreHighlight( SVTK_InteractorStyle* theInteractorStyle, + const int& theIndex ) +{ + //cout << "SALOME_Actor::PreHighlight : " << theIndex << endl; + + if( theIndex == -1 ) + { + myPreHighlightActor->SetVisibility( false ); + } + else + { + TColStd_IndexedMapOfInteger aMapIndex; + aMapIndex.Add( theIndex ); + + myPreHighlightActor->SetVisibility( true ); + myPreHighlightActor->MapPoints( this, aMapIndex ); + } + + return false; +} + +//---------------------------------------------------------------- +bool SALOME_Actor::Highlight( SVTK_InteractorStyle* theInteractorStyle, + SVTK_Selector* theSelector, + vtkRenderer* theRenderer, + SVTK_SelectionEvent theSelectionEvent, + bool theIsHighlight, + bool theIsUpdate ) +{ + Selection_Mode aSelectionMode = theSelectionEvent.SelectionMode; + float x = theSelectionEvent.X; + float y = theSelectionEvent.Y; + float z = 0.0; + bool isShift = theSelectionEvent.IsShift; + + if( aSelectionMode == NodeSelection ) + { + //vtkSmartPointer picker = VTKViewer_CellRectPicker::New(); + vtkPointPicker* aPicker = vtkPointPicker::New(); + + aPicker->Pick( x, y, z, theRenderer ); + + int aVtkId = aPicker->GetPointId(); + if( aVtkId >= 0 && hasIO() && theInteractorStyle->IsValid( this, aVtkId, true ) ) + { + int anObjId = GetNodeObjId( aVtkId ); + if( anObjId >= 0 ) + { + if( theSelector->IsSelected( myIO ) ) + { + // This IO is already in the selection + theSelector->AddOrRemoveIndex( myIO, anObjId, isShift ); + } + else + { + if( !isShift ) + { + theInteractorStyle->HighlightProp( NULL ); + theSelector->ClearIObjects(); + } + theSelector->AddOrRemoveIndex( myIO, anObjId, isShift ); + theSelector->AddIObject( this ); + } + } + } + aPicker->Delete(); + } + else if( aSelectionMode == CellSelection ) + { + vtkCellPicker* aPicker = vtkCellPicker::New(); + + aPicker->Pick( x, y, z, theRenderer ); + + int aVtkId = aPicker->GetCellId(); + if( aVtkId >= 0 && hasIO() && theInteractorStyle->IsValid( this, aVtkId ) ) + { + int anObjId = GetElemObjId( aVtkId ); + if( anObjId >= 0 ) + { + //if( theInteractorStyle->CheckDimensionId( aSelectionMode, this, anObjId ) ) + { + if( theSelector->IsSelected( myIO ) ) + { + // This IO is already in the selection + theSelector->AddOrRemoveIndex( myIO, anObjId, isShift ); + } + else + { + if( !isShift ) + { + theInteractorStyle->HighlightProp( NULL ); + theSelector->ClearIObjects(); + } + theSelector->AddOrRemoveIndex( myIO, anObjId, isShift ); + theSelector->AddIObject( this ); + } + } + } + } + aPicker->Delete(); + } + else if( aSelectionMode == EdgeOfCellSelection ) + { + vtkCellPicker* aPicker = vtkCellPicker::New(); + + aPicker->Pick( x, y, z, theRenderer ); + + int aVtkId = aPicker->GetCellId(); + if( aVtkId >= 0 && hasIO() && theInteractorStyle->IsValid( this, aVtkId ) ) + { + int anObjId = GetElemObjId( aVtkId ); + if( anObjId >= 0 ) + { + if( !isShift ) + { + theInteractorStyle->HighlightProp( NULL ); + theSelector->ClearIObjects(); + } + int anEdgeId = 0;//theInteractorStyle->GetEdgeId( aPicker, this, anObjId ); + if( anEdgeId >= 0 ) + { + theSelector->AddOrRemoveIndex( myIO, anObjId, false ); + theSelector->AddOrRemoveIndex( myIO, -anEdgeId-1, true ); + theSelector->AddIObject( this ); + } + } + } + aPicker->Delete(); + } + else if( aSelectionMode == ActorSelection ) + { + if ( hasIO() ) + { + //theInteractorStyle->PropPicked++; + if( theSelector->IsSelected( myIO ) ) + { + // This IO is already in the selection + if( isShift ) + theSelector->RemoveIObject( this ); + } + else + { + if( !isShift ) + { + theInteractorStyle->HighlightProp( NULL ); + theSelector->ClearIObjects(); + } + theSelector->AddIObject( this ); + } + } + } + + TColStd_IndexedMapOfInteger aMapIndex; + theSelector->GetIndex( getIO(), aMapIndex ); + /* + cout << "SALOME_Actor::Highlight : "; + for( int i = 1, n = aMapIndex.Extent(); i <= n; i++ ) + cout << aMapIndex(i) << " "; + cout << endl; + cout << "SelectionMode : "; + switch( aSelectionMode ) + { + case NodeSelection: cout << "Nodes" << endl; break; + case CellSelection: cout << "Cells" << endl; break; + case ActorSelection: cout << "Actor" << endl; break; + default: cout << "Other" << endl; break; + } + cout << "IsHighlight : " << ( theIsHighlight ? "true" : "false" ) << endl; + cout << "IsUpdate : " << ( theIsUpdate ? "true" : "false" ) << endl; + */ + + if( GetVisibility() && theIsHighlight ) + theInteractorStyle->HighlightProp( this ); + else if( !theIsHighlight ) + theInteractorStyle->HighlightProp( NULL ); + + //if( aSelectionMode != ActorSelection && !hasHighlight() ) + // return false; + + switch( aSelectionMode ) + { + case NodeSelection: + myHighlightActor->SetProperty( myPointProperty ); + myHighlightActor->MapPoints( this, aMapIndex ); + highlight( theIsHighlight ); + break; + case EdgeOfCellSelection: + myHighlightActor->SetProperty( myEdgeProperty ); + myHighlightActor->MapEdge( this, aMapIndex ); + highlight( theIsHighlight ); + break; + case CellSelection: + case EdgeSelection: + case FaceSelection: + case VolumeSelection: + myHighlightActor->SetProperty( myCellProperty ); + myHighlightActor->MapCells( this, aMapIndex ); + highlight( theIsHighlight ); + break; + case ActorSelection: + highlight( false ); + break; + } + + return false; +} + +//---------------------------------------------------------------- +bool SALOME_Actor::Unhighlight( SVTK_InteractorStyle* theInteractorStyle, + SVTK_Selector* theSelector, + bool theIsUpdate ) +{ + + theInteractorStyle->HighlightProp( NULL ); + theSelector->ClearIObjects(); +} diff --git a/src/SVTK/SALOME_Actor.h b/src/SVTK/SALOME_Actor.h new file mode 100644 index 000000000..a9b6bcced --- /dev/null +++ b/src/SVTK/SALOME_Actor.h @@ -0,0 +1,220 @@ +// SALOME OBJECT : implementation of interactive object visualization for OCC and VTK viewers +// +// 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 +// +// +// +// File : SALOME_Actor.h +// Author : Nicolas REJNERI +// Module : SALOME +// $Header$ + +#ifndef SALOME_ACTOR_H +#define SALOME_ACTOR_H + +#include "SALOME_InteractiveObject.hxx" // INCLUDES "using namespace std" +#ifndef _Handle_SALOME_InteractiveObject_HeaderFile +#include "Handle_SALOME_InteractiveObject.hxx" +#endif + +#include // INCLUDES "stdio.h" +#include + +// to overcome the conflict between std::ostream and io::ostream +// the following variable must be defined: +// VTK_USE_ANSI_STDLIB + +#include + +class vtkCell; +class vtkDataSet; +class vtkPolyData; +class vtkCamera; +class vtkProperty; + +class VTKViewer_Transform; +class VTKViewer_GeometryFilter; +class VTKViewer_TransformFilter; +class VTKViewer_PassThroughFilter; + +extern int SALOME_POINT_SIZE; + +#ifdef WNT +#define SALOME_OBJECT_EXPORT __declspec (dllexport) +#else +#define SALOME_OBJECT_EXPORT +#endif + +#include + +#include "SVTK_Selector.h" +#include "SVTK_SelectionEvent.h" + +#include + +#include + +class vtkRenderer; + +class SVTK_Actor; +class SVTK_InteractorStyle; + +class SALOME_OBJECT_EXPORT SALOME_Actor : public VTKViewer_Actor { + public: + static SALOME_Actor* New(); + + vtkTypeMacro(SALOME_Actor,vtkLODActor); + + virtual Standard_Boolean hasIO() { return !myIO.IsNull(); } + virtual const Handle(SALOME_InteractiveObject)& getIO() { return myIO; } + virtual void setIO(const Handle(SALOME_InteractiveObject)& io) { myIO = io; } + + virtual const char* getName() { return myName.c_str(); } + virtual void setName(const char* theName){ + if(hasIO()) myIO->setName(theName); + myName = theName; + } + + // To generate highlight automaticaly + virtual bool hasHighlight() { return false; } + //virtual void highlight(bool theHighlight) { myIsHighlighted = theHighlight; } + virtual bool isHighlighted() { return myIsHighlighted; } + + virtual void SetOpacity(float theOpacity); + virtual float GetOpacity(); + + virtual void SetColor(float r,float g,float b); + virtual void GetColor(float& r,float& g,float& b); + void SetColor(const float theRGB[3]){ + SetColor(theRGB[0],theRGB[1],theRGB[2]); + } + + vtkSetObjectMacro(PreviewProperty,vtkProperty); + + virtual void SetPreSelected(bool thePreselect = false) { myIsPreselected = thePreselect;} + + // Used to obtain all dependent actors + virtual void GetChildActors(vtkActorCollection*) {}; + + //virtual void AddToRender(vtkRenderer* theRenderer); + //virtual void RemoveFromRender(vtkRenderer* theRenderer); + + + // For selection mapping purpose + virtual int GetNodeObjId(int theVtkID) { return theVtkID;} + virtual float* GetNodeCoord(int theObjID); + + virtual int GetElemObjId(int theVtkID) { return theVtkID;} + virtual vtkCell* GetElemCell(int theObjID); + + virtual int GetObjDimension( const int theObjId ); + + virtual void SetMapper(vtkMapper* theMapper); + virtual vtkDataSet* GetInput(); + + + virtual void SetTransform(VTKViewer_Transform* theTransform); + virtual unsigned long int GetMTime(); + + virtual void SetRepresentation(int theMode); + virtual int GetRepresentation(); + + virtual int getDisplayMode(); + virtual void setDisplayMode(int theMode); + + // Infinitive means actor without size (point for example), + // which is not taken into account in calculation of boundaries of the scene + void SetInfinitive(bool theIsInfinite) { myIsInfinite = theIsInfinite; } + virtual bool IsInfinitive(); + + void SetResolveCoincidentTopology(bool theIsResolve); + void SetPolygonOffsetParameters(float factor, float units); + void GetPolygonOffsetParameters(float& factor, float& units); + + virtual void Render(vtkRenderer *, vtkMapper *); + + virtual float GetShrinkFactor() { return 1.0;} + + virtual bool IsShrunkable() { return false;} + virtual bool IsShrunk() { return false;} + + virtual void SetShrink() {} + virtual void UnShrink() {} + + virtual bool IsSetCamera() const { return false; } + virtual bool IsResizable() const { return false; } + virtual void SetSize( const float ) {} + virtual void SetCamera( vtkCamera* ) {} + + protected: + bool myIsResolveCoincidentTopology; + float myPolygonOffsetFactor; + float myPolygonOffsetUnits; + + Handle(SALOME_InteractiveObject) myIO; + std::string myName; + + vtkProperty *PreviewProperty; + bool myIsPreselected; + + float myOpacity; + bool myIsHighlighted; + int myDisplayMode; + bool myIsInfinite; + + bool myStoreMapping; + VTKViewer_GeometryFilter *myGeomFilter; + VTKViewer_TransformFilter *myTransformFilter; + std::vector myPassFilter; + + int myRepresentation; + vtkProperty *myProperty; + + void InitPipeLine(vtkMapper* theMapper); + + SALOME_Actor(); + ~SALOME_Actor(); + + // From VISU + public: + virtual void highlight( bool ); + + virtual void SetVisibility( int ); + + virtual void AddToRender( vtkRenderer* ); + virtual void RemoveFromRender( vtkRenderer* ); + + virtual bool PreHighlight( SVTK_InteractorStyle*, const int& ); + + virtual bool Highlight( SVTK_InteractorStyle*, SVTK_Selector*, vtkRenderer*, SVTK_SelectionEvent, bool, bool ); + virtual bool Unhighlight( SVTK_InteractorStyle*, SVTK_Selector*, bool ); + + protected: + vtkProperty* myPointProperty; + vtkProperty* myCellProperty; + vtkProperty* myEdgeProperty; + + SVTK_Actor* myPreHighlightActor; + SVTK_Actor* myHighlightActor; +}; + + +#endif // SALOME_ACTOR_H + diff --git a/src/SVTK/SVTK_Actor.h b/src/SVTK/SVTK_Actor.h index 7a9b4a641..517edbd38 100644 --- a/src/SVTK/SVTK_Actor.h +++ b/src/SVTK/SVTK_Actor.h @@ -30,14 +30,14 @@ class vtkUnstructuredGrid; #include "SVTK.h" #include "SALOME_Actor.h" -class SVTK_EXPORT SVTK_Actor : public SALOME_Actor +class SVTK_EXPORT SVTK_Actor : public VTKViewer_Actor { public: virtual ~SVTK_Actor(); static SVTK_Actor* New(); - vtkTypeMacro(SVTK_Actor,SALOME_Actor); + vtkTypeMacro(SVTK_Actor,VTKViewer_Actor); void SetShrinkFactor(float value); virtual void SetShrink(); diff --git a/src/SVTK/SVTK_InteractorStyle.cxx b/src/SVTK/SVTK_InteractorStyle.cxx index c4d585b75..6627d9fb3 100644 --- a/src/SVTK/SVTK_InteractorStyle.cxx +++ b/src/SVTK/SVTK_InteractorStyle.cxx @@ -38,6 +38,7 @@ #include "SVTK_RenderWindowInteractor.h" #include "SVTK_RenderWindow.h" #include "SVTK_ViewWindow.h" +#include "SVTK_Selection.h" #include "SALOME_Actor.h" #include "SVTK_Actor.h" @@ -888,6 +889,7 @@ SVTK_InteractorStyle fitRect(x1, y1, x2, y2); } else { + myViewWindow->unHighlightAll(); if (myPoint == myOtherPoint) { // process point selection int w, h, x, y; @@ -903,94 +905,17 @@ SVTK_InteractorStyle SALOME_Actor* aSActor = SALOME_Actor::SafeDownCast(aPicker->GetActor()); - if (vtkCellPicker* picker = vtkCellPicker::SafeDownCast(aPicker)) { - int aVtkId = picker->GetCellId(); - if ( aVtkId >= 0 && aSActor && aSActor->hasIO() && IsValid( aSActor, aVtkId ) ) { - int anObjId = aSActor->GetElemObjId(aVtkId); - if(anObjId >= 0){ - Handle(SALOME_InteractiveObject) anIO = aSActor->getIO(); - if(aSelectionMode != EdgeOfCellSelection) { - if(CheckDimensionId(aSelectionMode,aSActor,anObjId)){ - if(MYDEBUG) INFOS(" CellId : "<IsSelected(anIO)) { - // This IO is already in the selection - GetSelector()->AddOrRemoveIndex(anIO,anObjId,myShiftState); - } else { - if (!myShiftState) { - this->HighlightProp( NULL ); - GetSelector()->ClearIObjects(); - } - GetSelector()->AddOrRemoveIndex(anIO,anObjId,myShiftState); - GetSelector()->AddIObject(aSActor); - } - } - }else{ - if (!myShiftState) { - this->HighlightProp( NULL ); - GetSelector()->ClearIObjects(); - } - int anEdgeId = GetEdgeId(picker,aSActor,anObjId); - if (anEdgeId >= 0) { - if(MYDEBUG) INFOS(" CellId : "<AddOrRemoveIndex(anIO,anObjId,false); - GetSelector()->AddOrRemoveIndex(anIO,-anEdgeId-1,true); - GetSelector()->AddIObject(aSActor); - } - } - } - } else { - this->HighlightProp( NULL ); - GetSelector()->ClearIObjects(); - } - } else if ( vtkPointPicker* picker = vtkPointPicker::SafeDownCast(aPicker) ) { - int aVtkId = picker->GetPointId(); - if ( aVtkId >= 0 && IsValid( aSActor, aVtkId, true ) ) { - if ( aSActor && aSActor->hasIO() ) { - int anObjId = aSActor->GetNodeObjId(aVtkId); - if(anObjId >= 0){ - Handle(SALOME_InteractiveObject) anIO = aSActor->getIO(); - if(GetSelector()->IsSelected(anIO)) { - // This IO is already in the selection - GetSelector()->AddOrRemoveIndex(anIO,anObjId,myShiftState); - } else { - if(!myShiftState) { - this->HighlightProp( NULL ); - GetSelector()->ClearIObjects(); - } - if(MYDEBUG) INFOS(" PointId : "<AddOrRemoveIndex(anIO,anObjId,myShiftState); - GetSelector()->AddIObject(aSActor); - } - } - } - } else { - this->HighlightProp( NULL ); - GetSelector()->ClearIObjects(); - } - } else { - if ( aSActor && aSActor->hasIO() ) { - this->PropPicked++; - Handle(SALOME_InteractiveObject) anIO = aSActor->getIO(); - if(GetSelector()->IsSelected(anIO)) { - // This IO is already in the selection - if(myShiftState) { - GetSelector()->RemoveIObject(aSActor); - } - } - else { - if(!myShiftState) { - this->HighlightProp( NULL ); - GetSelector()->ClearIObjects(); - } - GetSelector()->AddIObject(aSActor); - } - }else{ - // No selection clear all - this->PropPicked = 0; - this->HighlightProp( NULL ); - GetSelector()->ClearIObjects(); - } + SVTK_SelectionEvent aSelectionEvent = myInteractor->GetSelectionEvent(); + aSelectionEvent.SelectionMode = aSelectionMode; + + if( aSActor ) + aSActor->Highlight( this, GetSelector(), this->CurrentRenderer, aSelectionEvent, true, true ); + else + { + this->HighlightProp( NULL ); + GetSelector()->ClearIObjects(); } + myInteractor->EndPickCallback(); } else { //processing rectangle selection @@ -1132,7 +1057,7 @@ SVTK_InteractorStyle } //end switch myInteractor->EndPickCallback(); } - myViewWindow->onSelectionChanged(); + //myViewWindow->onSelectionChanged(); } } break; @@ -1250,15 +1175,16 @@ SVTK_InteractorStyle myPreSelectionActor->SetVisibility(false); vtkPicker* aPicker = vtkPicker::SafeDownCast(myInteractor->GetPicker()); - aPicker->Pick(x, y, 0.0, this->CurrentRenderer); SALOME_Actor* aSActor = SALOME_Actor::SafeDownCast(aPicker->GetActor()); + if( aSActor ) + aSActor->PreHighlight( this, -1 ); + //cout << "onCursorMove : " << ( aSActor ? "1" : "0" ) << " "; - if (aSActor && myPreSelectionActor){ - float aPos[3]; - aSActor->GetPosition(aPos); - myPreSelectionActor->SetPosition(aPos); - } + aPicker->Pick(x, y, 0.0, this->CurrentRenderer); + + aSActor = SALOME_Actor::SafeDownCast(aPicker->GetActor()); + //cout << ( aSActor ? "1" : "0" ) << endl; if (vtkCellPicker* picker = vtkCellPicker::SafeDownCast(aPicker)) { int aVtkId = picker->GetCellId(); @@ -1274,7 +1200,7 @@ SVTK_InteractorStyle mySelectedActor = aSActor; myElemId = anObjId; if(MYDEBUG) INFOS(" CellId : "<setCellData(anObjId,aSActor,myPreSelectionActor); + //myInteractor->setCellData(anObjId,aSActor,myPreSelectionActor); } } } @@ -1289,7 +1215,7 @@ SVTK_InteractorStyle myEdgeId = anEdgeId; myElemId = anObjId; if(MYDEBUG) INFOS(" CellId : "<setEdgeData(anObjId,aSActor,-anEdgeId-1,myPreSelectionActor); + //myInteractor->setEdgeData(anObjId,aSActor,-anEdgeId-1,myPreSelectionActor); } } } @@ -1302,18 +1228,25 @@ SVTK_InteractorStyle } else if (vtkPointPicker* picker = vtkPointPicker::SafeDownCast(aPicker)) { int aVtkId = picker->GetPointId(); + //cout << "vtkPointPicker" << endl; + //cout << aSActor << endl; + //cout << aVtkId << endl; if ( aVtkId >= 0 && IsValid( aSActor, aVtkId, true ) ) { if ( aSActor && aSActor->hasIO() ) { int anObjId = aSActor->GetNodeObjId(aVtkId); + aSActor->PreHighlight( this, anObjId ); + /* bool anIsSameObjId = (mySelectedActor == aSActor && myNodeId == anObjId); if(!anIsSameObjId) { mySelectedActor = aSActor; myNodeId = anObjId; if(MYDEBUG) INFOS(" PointId : "<setPointData(anObjId,aSActor,myPreSelectionActor); + aSActor->PreHighlight( this, anObjId ); } myPreSelectionActor->GetProperty()->SetRepresentationToSurface(); myPreSelectionActor->SetVisibility(true); + */ } } } diff --git a/src/SVTK/SVTK_RenderWindowInteractor.cxx b/src/SVTK/SVTK_RenderWindowInteractor.cxx index a80733492..9eb6b667c 100644 --- a/src/SVTK/SVTK_RenderWindowInteractor.cxx +++ b/src/SVTK/SVTK_RenderWindowInteractor.cxx @@ -30,11 +30,11 @@ #include "SVTK_InteractorStyle.h" #include "SVTK_RenderWindow.h" -#include "SVTK_ViewWindow.h" +#include "SVTK_Selection.h" #include "VTKViewer_Algorithm.h" #include "SVTK_Functor.h" -#include "SVTK_Actor.h" +#include "SALOME_Actor.h" #include #include @@ -82,30 +82,10 @@ SVTK_RenderWindowInteractor this->Enabled = 0 ; this->mTimer = new QTimer( this ) ; myDisplayMode = 0; - myGUIWindow = 0; myBasicPicker = vtkPicker::New(); myCellPicker = vtkCellPicker::New(); myPointPicker = vtkPointPicker::New(); - - myCellActor = SVTK_Actor::New(); - myCellActor->PickableOff(); - myCellActor->GetProperty()->SetColor(1,1,0); - myCellActor->GetProperty()->SetLineWidth(5); - myCellActor->GetProperty()->SetRepresentationToSurface(); - - myEdgeActor = SVTK_Actor::New(); - myEdgeActor->PickableOff(); - myEdgeActor->GetProperty()->SetColor(1,0,0); - myEdgeActor->GetProperty()->SetLineWidth(5); - myEdgeActor->GetProperty()->SetRepresentationToWireframe(); - - myPointActor = SVTK_Actor::New(); - myPointActor->PickableOff(); - myPointActor->GetProperty()->SetColor(1,1,0); - myPointActor->GetProperty()->SetPointSize(5); - myPointActor->GetProperty()->SetRepresentationToPoints(); - connect(mTimer, SIGNAL(timeout()), this, SLOT(TimerFunc())) ; } @@ -117,14 +97,6 @@ SVTK_RenderWindowInteractor delete mTimer ; - myViewWindow->RemoveActor(myCellActor); - myViewWindow->RemoveActor(myEdgeActor); - myViewWindow->RemoveActor(myPointActor); - - myCellActor->Delete(); - myEdgeActor->Delete(); - myPointActor->Delete(); - myBasicPicker->Delete(); myCellPicker->Delete(); myPointPicker->Delete(); @@ -168,8 +140,9 @@ SVTK_RenderWindowInteractor this->Size[1] = ((aSize[1] > 0) ? aSize[1] : 300); this->SetPicker(myBasicPicker); + //this->SetPicker(vtkPicker::New()); - SetSelectionTolerance(); + //SetSelectionTolerance(); // // Enable the interactor. @@ -189,37 +162,6 @@ SVTK_RenderWindowInteractor return ; } - -//---------------------------------------------------------------------------- -void -SVTK_RenderWindowInteractor -::setGUIWindow(QWidget* theWindow) -{ - myGUIWindow = theWindow; -} - -//---------------------------------------------------------------------------- -void -SVTK_RenderWindowInteractor -::setViewWindow(SVTK_ViewWindow* theViewWindow) -{ - myViewWindow = theViewWindow; - - myViewWindow->InsertActor(myCellActor); - myViewWindow->InsertActor(myEdgeActor); - myViewWindow->InsertActor(myPointActor); -} - -//---------------------------------------------------------------------------- -void -SVTK_RenderWindowInteractor -::MoveInternalActors() -{ - myViewWindow->MoveActor(myCellActor); - myViewWindow->MoveActor(myEdgeActor); - myViewWindow->MoveActor(myPointActor); -} - //---------------------------------------------------------------------------- void SVTK_RenderWindowInteractor @@ -234,10 +176,6 @@ void SVTK_RenderWindowInteractor ::SetSelectionMode(Selection_Mode theMode) { - myCellActor->SetVisibility(false); - myEdgeActor->SetVisibility(false); - myPointActor->SetVisibility(false); - switch(theMode){ case ActorSelection: this->SetPicker(myBasicPicker); @@ -256,7 +194,7 @@ SVTK_RenderWindowInteractor myInteractorStyle->OnSelectionModeChanged(); } - +/* void SVTK_RenderWindowInteractor ::SetSelectionProp(const double& theRed, @@ -284,7 +222,7 @@ SVTK_RenderWindowInteractor myPointPicker->SetTolerance(myTolNodes); } - +*/ // ================================== void SVTK_RenderWindowInteractor @@ -384,6 +322,10 @@ SVTK_RenderWindowInteractor if( ! this->Enabled ) { return ; } + this->SetEventInformationFlipY( event->x(), event->y(), + ( event->state() & ControlButton ), + ( event->state() & ShiftButton ) ); + myInteractorStyle->OnLeftButtonUp( (event->state() & ControlButton), (event->state() & ShiftButton), event->x(), event->y() ) ; @@ -720,47 +662,6 @@ SVTK_RenderWindowInteractor ::KeyPressed(QKeyEvent *event) {} - -struct THighlightAction{ - bool myIsHighlight; - SVTK_InteractorStyle* myInteractorStyle; - THighlightAction(SVTK_InteractorStyle* theInteractorStyle, - bool theIsHighlight): - myInteractorStyle(theInteractorStyle), - myIsHighlight(theIsHighlight) - {} - void operator()(SALOME_Actor* theActor){ - if(theActor->GetMapper()){ - if(theActor->hasHighlight()) - theActor->highlight(myIsHighlight); - else{ - if(theActor->GetVisibility() && myIsHighlight) - myInteractorStyle->HighlightProp(theActor); - else if(!myIsHighlight) - myInteractorStyle->HighlightProp(NULL); - } - } - } -}; - -bool -SVTK_RenderWindowInteractor -::highlight( const Handle(SALOME_InteractiveObject)& theIObject, - bool hilight, - bool update) -{ - using namespace VTK; - ForEachIf(GetRenderer()->GetActors(), - TIsSameIObject(theIObject), - THighlightAction(myInteractorStyle,hilight)); - - if(update) - emit RenderWindowModified(); - - return false; -} - - struct TUpdateAction{ void operator()(vtkActor* theActor){ theActor->ApplyProperties(); @@ -781,32 +682,6 @@ SVTK_RenderWindowInteractor emit RenderWindowModified(); } - -void -SVTK_RenderWindowInteractor -::unHighlightSubSelection() -{ - myPointActor->SetVisibility(false); - myEdgeActor->SetVisibility(false); - myCellActor->SetVisibility(false); -} - - -bool -SVTK_RenderWindowInteractor -::unHighlightAll() -{ - unHighlightSubSelection(); - - using namespace VTK; - ForEach(GetRenderer()->GetActors(), - THighlightAction(myInteractorStyle,false)); - - emit RenderWindowModified() ; - - return false; -} - //----------------- // Color methods //----------------- @@ -876,136 +751,19 @@ SVTK_RenderWindowInteractor (&SALOME_Actor::setName,theName.latin1())); } - -//---------------------------------------------------------------------------- -bool -SVTK_RenderWindowInteractor -::highlight(const TColStd_IndexedMapOfInteger& theMapIndex, - SALOME_Actor* theMapActor, - SVTK_Actor* theActor, - TUpdateActor theFun, - bool hilight, - bool update) -{ - if(theMapIndex.Extent() == 0) return false; - - if (hilight) { - setActorData(theMapIndex,theMapActor,theActor,theFun); - theActor->SetVisibility(true); - } - else { - theActor->SetVisibility(false); - } - - if(update){ - this->RenderWindow->Render(); - emit RenderWindowModified() ; - } - - return false; -} - -void -SVTK_RenderWindowInteractor -::setActorData(const TColStd_IndexedMapOfInteger& theMapIndex, - SALOME_Actor* theMapActor, - SVTK_Actor *theActor, - TUpdateActor theFun) -{ - (*theFun)(theMapIndex,theMapActor,theActor); - float aPos[3]; - theMapActor->GetPosition(aPos); - theActor->SetPosition(aPos); -} - - -//---------------------------------------------------------------------------- -static void CellsUpdateActor(const TColStd_IndexedMapOfInteger& theMapIndex, - SALOME_Actor* theMapActor, - SVTK_Actor* theActor) -{ - theActor->MapCells(theMapActor,theMapIndex); -} - -bool -SVTK_RenderWindowInteractor -::highlightCell(const TColStd_IndexedMapOfInteger& theMapIndex, - SALOME_Actor* theMapActor, - bool hilight, - bool update) -{ - return highlight(theMapIndex,theMapActor,myCellActor,&CellsUpdateActor,hilight,update); -} - -void +SVTK_SelectionEvent SVTK_RenderWindowInteractor -::setCellData(const int& theIndex, - SALOME_Actor* theMapActor, - SVTK_Actor* theActor) +::GetSelectionEvent() { - TColStd_IndexedMapOfInteger MapIndex; - MapIndex.Add(theIndex); - theActor->MapCells(theMapActor,MapIndex); -} + SVTK_SelectionEvent aSelectionEvent; + int x, y; + this->GetEventPosition( x, y ); -//---------------------------------------------------------------------------- -static void PointsUpdateActor(const TColStd_IndexedMapOfInteger& theMapIndex, - SALOME_Actor* theMapActor, - SVTK_Actor* theActor) -{ - theActor->MapPoints(theMapActor,theMapIndex); -} - -bool -SVTK_RenderWindowInteractor -::highlightPoint(const TColStd_IndexedMapOfInteger& theMapIndex, - SALOME_Actor* theMapActor, - bool hilight, - bool update) -{ - return highlight(theMapIndex,theMapActor,myPointActor,&PointsUpdateActor,hilight,update); -} - -void -SVTK_RenderWindowInteractor -::setPointData(const int& theIndex, - SALOME_Actor* theMapActor, - SVTK_Actor* theActor) -{ - TColStd_IndexedMapOfInteger MapIndex; - MapIndex.Add(theIndex); - theActor->MapPoints(theMapActor,MapIndex); -} + aSelectionEvent.X = x; + aSelectionEvent.Y = y; + aSelectionEvent.IsCtrl = this->GetControlKey(); + aSelectionEvent.IsShift = this->GetShiftKey(); - -//---------------------------------------------------------------------------- -static void EdgesUpdateActor(const TColStd_IndexedMapOfInteger& theMapIndex, - SALOME_Actor* theMapActor, - SVTK_Actor* theActor) -{ - theActor->MapEdge(theMapActor,theMapIndex); -} - -bool -SVTK_RenderWindowInteractor -::highlightEdge(const TColStd_IndexedMapOfInteger& theMapIndex, - SALOME_Actor* theMapActor, - bool hilight, - bool update) -{ - return highlight(theMapIndex,theMapActor,myEdgeActor,&EdgesUpdateActor,hilight,update); -} - -void -SVTK_RenderWindowInteractor -::setEdgeData(const int& theCellIndex, - SALOME_Actor* theMapActor, - const int& theEdgeIndex, - SVTK_Actor* theActor ) -{ - TColStd_IndexedMapOfInteger MapIndex; - MapIndex.Add(theCellIndex); - MapIndex.Add(theEdgeIndex); - theActor->MapEdge(theMapActor,MapIndex); + return aSelectionEvent; } diff --git a/src/SVTK/SVTK_RenderWindowInteractor.h b/src/SVTK/SVTK_RenderWindowInteractor.h index 55b07e806..d37b1c6ca 100644 --- a/src/SVTK/SVTK_RenderWindowInteractor.h +++ b/src/SVTK/SVTK_RenderWindowInteractor.h @@ -30,8 +30,8 @@ #define SVTK_RenderWindowInteractor_h #include "SVTK.h" +#include "SVTK_SelectionEvent.h" -#include "SVTK_Selection.h" #include "SALOME_InteractiveObject.hxx" // QT Includes @@ -53,7 +53,6 @@ class vtkPointPicker; class vtkActorCollection; class SALOME_Actor; -class SVTK_Actor; class SVTK_ViewWindow; class SVTK_RenderWindow; @@ -106,36 +105,19 @@ public: virtual int DestroyTimer() ; /* Selection Management */ - bool highlightCell(const TColStd_IndexedMapOfInteger& MapIndex, - SALOME_Actor* theMapActor, - bool hilight, - bool update = true ); - bool highlightEdge(const TColStd_IndexedMapOfInteger& MapIndex, - SALOME_Actor* theMapActor, - bool hilight, - bool update = true ); - bool highlightPoint(const TColStd_IndexedMapOfInteger& MapIndex, - SALOME_Actor* theMapActor, - bool hilight, - bool update = true ); - bool highlight(const Handle(SALOME_InteractiveObject)& IObject, - bool hiligth, - bool immediatly = true ); - void unHighlightSubSelection(); - bool unHighlightAll(); - bool isInViewer( const Handle(SALOME_InteractiveObject)& IObject); bool isVisible( const Handle(SALOME_InteractiveObject)& IObject); void rename(const Handle(SALOME_InteractiveObject)& IObject, QString newName); void SetSelectionMode(Selection_Mode mode); + /* void SetSelectionProp(const double& theRed = 1, const double& theGreen = 1, const double& theBlue = 0, const int& theWidth = 5); void SetSelectionTolerance(const double& theTolNodes = 0.025, const double& theTolCell = 0.001); - + */ // Displaymode management int GetDisplayMode(); void SetDisplayMode(int); @@ -183,54 +165,20 @@ public: vtkRenderer* GetRenderer(); - void setGUIWindow(QWidget* theWindow); + SVTK_SelectionEvent GetSelectionEvent(); - void setViewWindow(SVTK_ViewWindow* theViewWindow); - - void setCellData(const int& theIndex, - SALOME_Actor* theMapActor, - SVTK_Actor* theActor); - void setEdgeData(const int& theCellIndex, - SALOME_Actor* theMapActor, - const int& theEdgeIndex, - SVTK_Actor* theActor ); //NB - void setPointData(const int& theIndex, - SALOME_Actor* theMapActor, - SVTK_Actor* theActor); - - typedef void (*TUpdateActor)(const TColStd_IndexedMapOfInteger& theMapIndex, - SALOME_Actor* theMapActor, - SVTK_Actor* theActor); protected: SVTK_RenderWindowInteractor(); ~SVTK_RenderWindowInteractor(); SVTK_InteractorStyle* myInteractorStyle; - - bool highlight(const TColStd_IndexedMapOfInteger& theMapIndex, - SALOME_Actor* theMapActor, - SVTK_Actor* theActor, - TUpdateActor theFun, - bool hilight, - bool update); - void setActorData(const TColStd_IndexedMapOfInteger& theMapIndex, - SALOME_Actor* theMapActor, - SVTK_Actor *theActor, - TUpdateActor theFun); // Timer used during various mouse events to figure // out mouse movements. QTimer *mTimer ; int myDisplayMode; - - //NRI: Selection mode - SVTK_Actor* myPointActor; - SVTK_Actor* myEdgeActor; - SVTK_Actor* myCellActor; - void MoveInternalActors(); - vtkPicker* myBasicPicker; vtkCellPicker* myCellPicker; vtkPointPicker* myPointPicker; @@ -262,8 +210,6 @@ public: void contextMenuRequested( QContextMenuEvent *e ); private: - SVTK_ViewWindow* myViewWindow; - QWidget* myGUIWindow; double myTolNodes; double myTolItems; }; diff --git a/src/SVTK/SVTK_ViewWindow.cxx b/src/SVTK/SVTK_ViewWindow.cxx index 5260b9732..69eda9c15 100755 --- a/src/SVTK/SVTK_ViewWindow.cxx +++ b/src/SVTK/SVTK_ViewWindow.cxx @@ -78,7 +78,7 @@ SVTK_ViewWindow // Create an interactor. myRWInteractor = SVTK_RenderWindowInteractor::New(); myRWInteractor->SetRenderWindow( myRenderWindow->getRenderWindow() ); - myRWInteractor->setViewWindow( this ); + //myRWInteractor->setViewWindow( this ); SVTK_InteractorStyle* RWS = SVTK_InteractorStyle::New(); RWS->setGUIWindow( myRenderWindow ); @@ -488,6 +488,17 @@ SVTK_ViewWindow Repaint(); } +//---------------------------------------------------------------- +struct THighlightAction{ + bool myIsHighlight; + THighlightAction( bool theIsHighlight ): myIsHighlight(theIsHighlight) {} + void operator()( SALOME_Actor* theActor) { + if(theActor->GetMapper()){ + theActor->highlight( myIsHighlight ); + } + } +}; + //---------------------------------------------------------------- void SVTK_ViewWindow @@ -510,6 +521,7 @@ SVTK_ViewWindow ::SetSelectionMode(Selection_Mode theMode) { mySelector->SetSelectionMode(theMode); + myRWInteractor->SetSelectionMode(theMode); } @@ -526,7 +538,14 @@ void SVTK_ViewWindow ::unHighlightAll() { - myRWInteractor->unHighlightAll(); + //cout << "--------------------------------------------------" << endl; + //cout << "SVTK_ViewWindow::unHighlightAll" << endl; + + using namespace VTK; + ForEach( myRenderer->GetActors(), + THighlightAction( false ) ); + + //myRenderWindow->update(); } //---------------------------------------------------------------- @@ -536,33 +555,12 @@ SVTK_ViewWindow bool theIsHighlight, bool theIsUpdate ) { - myRWInteractor->highlight(theIO, theIsHighlight, theIsUpdate); - - if(mySelector->HasIndex(theIO) && theIO->hasEntry()){ - TColStd_IndexedMapOfInteger aMapIndex; - mySelector->GetIndex(theIO,aMapIndex); - using namespace VTK; - const char* anEntry = theIO->getEntry(); - vtkActorCollection* aCollection = myRenderer->GetActors(); - if(SALOME_Actor* anActor = Find(aCollection,TIsSameEntry(anEntry))){ - switch (mySelector->SelectionMode()) { - case NodeSelection: - myRWInteractor->highlightPoint(aMapIndex,anActor,theIsHighlight,theIsUpdate); - break; - case EdgeOfCellSelection: - myRWInteractor->highlightEdge(aMapIndex,anActor,theIsHighlight,theIsUpdate); - break; - case CellSelection: - case EdgeSelection: - case FaceSelection: - case VolumeSelection: - myRWInteractor->highlightCell(aMapIndex,anActor,theIsHighlight,theIsUpdate); - break; - } - } - }else{ - myRWInteractor->unHighlightSubSelection(); - } + using namespace VTK; + ForEachIf(myRenderer->GetActors(), + TIsSameIObject(theIO), + THighlightAction(theIsHighlight)); + + //myRenderWindow->update(); } //---------------------------------------------------------------- @@ -758,7 +756,7 @@ SVTK_ViewWindow if(aCDisplayed) myCubeAxes->VisibilityOff(); SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr(); - QString aSetting = aResMgr->stringValue("Viewer", "TrihedronSize", "105"); + QString aSetting = aResMgr->stringValue("Viewer:TrihedronSize", "105"); static float aSizeInPercents = aSetting.toFloat(); //bool isComputeTrihedronSize = @@ -985,18 +983,20 @@ SVTK_ViewWindow //---------------------------------------------------------------------------- void SVTK_ViewWindow -::InsertActor( SALOME_Actor* theActor, bool theMoveInternalActors ) +::InsertActor( VTKViewer_Actor* theActor, bool theMoveInternalActors ) { + //cout << "SVTK_ViewWindow::InsertActor" << endl; theActor->AddToRender(myRenderer); + theActor->SetTransform(myTransform); - if(theMoveInternalActors) - myRWInteractor->MoveInternalActors(); + //if(theMoveInternalActors) + // myRWInteractor->MoveInternalActors(); } //---------------------------------------------------------------------------- void SVTK_ViewWindow -::AddActor( SALOME_Actor* theActor, bool theUpdate /*=false*/ ) +::AddActor( VTKViewer_Actor* theActor, bool theUpdate /*=false*/ ) { InsertActor(theActor); if(theUpdate) @@ -1006,8 +1006,11 @@ SVTK_ViewWindow //---------------------------------------------------------------------------- void SVTK_ViewWindow -::RemoveActor( SALOME_Actor* theActor, bool theUpdate /*=false*/ ) +::RemoveActor( VTKViewer_Actor* theActor, bool theUpdate /*=false*/ ) { + //cout << "SVTK_ViewWindow::RemoveActor" << endl; + theActor->RemoveFromRender(myRenderer); + theActor->RemoveFromRender(myRenderer); if(theUpdate) Repaint(); @@ -1016,7 +1019,7 @@ SVTK_ViewWindow //---------------------------------------------------------------------------- void SVTK_ViewWindow -::MoveActor( SALOME_Actor* theActor) +::MoveActor( VTKViewer_Actor* theActor) { RemoveActor(theActor); InsertActor(theActor,true); diff --git a/src/SVTK/SVTK_ViewWindow.h b/src/SVTK/SVTK_ViewWindow.h index 2edda288e..18a9dc768 100755 --- a/src/SVTK/SVTK_ViewWindow.h +++ b/src/SVTK/SVTK_ViewWindow.h @@ -19,7 +19,7 @@ class SUIT_Desktop; class VTKViewer_Trihedron; class VTKViewer_Transform; -class SALOME_Actor; +class VTKViewer_Actor; class SVTK_Viewer; class SVTK_Selector; @@ -76,8 +76,8 @@ public: //apply existing transformation on adding SALOME_Actor void SetScale( double theScale[3] ); void GetScale( double theScale[3] ); - void AddActor( SALOME_Actor*, bool update = false ); - void RemoveActor(SALOME_Actor*, bool update = false); + void AddActor( VTKViewer_Actor*, bool update = false ); + void RemoveActor(VTKViewer_Actor*, bool update = false); void AdjustTrihedrons( const bool forced ); //merge with V2_2_0_VISU_improvements:bool ComputeTrihedronSize( double& theNewSize, @@ -142,9 +142,9 @@ protected slots: private: void InitialSetup(); - void InsertActor( SALOME_Actor* theActor, + void InsertActor( VTKViewer_Actor* theActor, bool theMoveInternalActors = false ); - void MoveActor( SALOME_Actor* theActor ); + void MoveActor( VTKViewer_Actor* theActor ); private: enum { DumpId, FitAllId, FitRectId, ZoomId, PanId, GlobalPanId, RotationId,