X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSVTK%2FSVTK_View.cxx;h=2820669426c9cf1786a0f4e83a590c773109e061;hb=f0d76ff6227bfa6cdacdeac79fc557cfd0130f7f;hp=8174f0c4f5e23ab963563e3247ec7b4331e835f9;hpb=1c889394b028b786898a995d38c07c8f3d564837;p=modules%2Fgui.git diff --git a/src/SVTK/SVTK_View.cxx b/src/SVTK/SVTK_View.cxx index 8174f0c4f..282066942 100644 --- a/src/SVTK/SVTK_View.cxx +++ b/src/SVTK/SVTK_View.cxx @@ -1,43 +1,43 @@ -// Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE +// Copyright (C) 2007-2015 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-2007 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 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, or (at your option) any later version. // -// 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. +// 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 +// 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 +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // + // SALOME VTKViewer : build VTK viewer into Salome desktop // File : // Author : -// Module : SALOME -// $Header$ -// + #include "SALOME_Actor.h" #include "SVTK_View.h" #include "SVTK_Renderer.h" #include "SVTK_ViewWindow.h" #include "SVTK_RenderWindowInteractor.h" -#include "SALOME_ListIteratorOfListIO.hxx" +#include "SALOME_ListIO.hxx" #include "VTKViewer_Algorithm.h" #include "SVTK_Functor.h" #include #include +#include /*! Constructor @@ -50,21 +50,21 @@ SVTK_SignalHandler SVTK_RenderWindowInteractor* anInteractor = theMainWindow->GetInteractor(); connect(anInteractor,SIGNAL(KeyPressed(QKeyEvent*)), - this,SIGNAL(KeyPressed(QKeyEvent*)) ); + this,SIGNAL(KeyPressed(QKeyEvent*)) ); connect(anInteractor,SIGNAL(KeyReleased(QKeyEvent*)), - this,SIGNAL(KeyReleased(QKeyEvent*))); + this,SIGNAL(KeyReleased(QKeyEvent*))); connect(anInteractor,SIGNAL(MouseButtonPressed(QMouseEvent*)), - this,SIGNAL(MouseButtonPressed(QMouseEvent*))); + this,SIGNAL(MouseButtonPressed(QMouseEvent*))); connect(anInteractor,SIGNAL(MouseButtonReleased(QMouseEvent*)), - this,SIGNAL(MouseButtonReleased(QMouseEvent*))); + this,SIGNAL(MouseButtonReleased(QMouseEvent*))); connect(anInteractor,SIGNAL(MouseDoubleClicked(QMouseEvent*)), - this,SIGNAL(MouseDoubleClicked(QMouseEvent*))); + this,SIGNAL(MouseDoubleClicked(QMouseEvent*))); connect(anInteractor,SIGNAL(MouseMove(QMouseEvent*)), - this,SIGNAL(MouseMove(QMouseEvent*))); + this,SIGNAL(MouseMove(QMouseEvent*))); connect(anInteractor,SIGNAL(contextMenuRequested(QContextMenuEvent*)), - this,SIGNAL(contextMenuRequested(QContextMenuEvent*))); + this,SIGNAL(contextMenuRequested(QContextMenuEvent*))); connect(anInteractor,SIGNAL(selectionChanged()), - this,SIGNAL(selectionChanged())); + this,SIGNAL(selectionChanged())); } /*! @@ -129,7 +129,7 @@ namespace SVTK operator()( SALOME_Actor* theActor) { if(theActor->GetMapper() && theActor->hasIO()){ - theActor->Highlight( myIsHighlight ); + theActor->Highlight( myIsHighlight ); } } }; @@ -142,18 +142,19 @@ void SVTK_SignalHandler ::onSelectionChanged() { - vtkActorCollection* anActors = myMainWindow->getRenderer()->GetActors(); + VTK::ActorCollectionCopy aCopy(myMainWindow->getRenderer()->GetActors()); + vtkActorCollection* anActors = aCopy.GetActors(); using namespace SVTK; ForEach(anActors, - THighlightAction( false )); + THighlightAction( false )); SVTK_Selector* aSelector = myMainWindow->GetSelector(); const SALOME_ListIO& aListIO = aSelector->StoredIObjects(); SALOME_ListIteratorOfListIO anIter(aListIO); for(; anIter.More(); anIter.Next()){ ForEachIf(anActors, - TIsSameIObject(anIter.Value()), - THighlightAction(true)); + TIsSameIObject(anIter.Value()), + THighlightAction(true)); } myMainWindow->Repaint(false); @@ -184,8 +185,9 @@ SVTK_View ::unHighlightAll() { using namespace SVTK; - ForEach(getRenderer()->GetActors(), - THighlightAction( false )); + VTK::ActorCollectionCopy aCopy(getRenderer()->GetActors()); + ForEach(aCopy.GetActors(), + THighlightAction( false )); Repaint(); } @@ -198,13 +200,14 @@ SVTK_View void SVTK_View ::highlight( const Handle(SALOME_InteractiveObject)& theIO, - bool theIsHighlight, - bool theIsUpdate ) + bool theIsHighlight, + bool theIsUpdate ) { using namespace SVTK; - ForEachIf(getRenderer()->GetActors(), - TIsSameIObject( theIO ), - THighlightAction(theIsHighlight)); + VTK::ActorCollectionCopy aCopy(getRenderer()->GetActors()); + ForEachIf(aCopy.GetActors(), + TIsSameIObject( theIO ), + THighlightAction(theIsHighlight)); Repaint(); } @@ -217,9 +220,10 @@ SVTK_View ::FindIObject(const char* theEntry) { using namespace SVTK; + VTK::ActorCollectionCopy aCopy(getRenderer()->GetActors()); SALOME_Actor* anActor = - Find(getRenderer()->GetActors(), - TIsSameEntry(theEntry)); + Find(aCopy.GetActors(), + TIsSameEntry(theEntry)); if(anActor != NULL) return anActor->getIO(); @@ -232,9 +236,9 @@ SVTK_View void SVTK_View ::SetSelectionProp(const double& theRed, - const double& theGreen, - const double& theBlue, - const int& theWidth) + const double& theGreen, + const double& theBlue, + const int& theWidth) { GetRenderer()->SetSelectionProp(theRed,theGreen,theBlue,theWidth); } @@ -245,9 +249,9 @@ SVTK_View void SVTK_View ::SetPreselectionProp(const double& theRed, - const double& theGreen, - const double& theBlue, - const int& theWidth) + const double& theGreen, + const double& theBlue, + const int& theWidth) { GetRenderer()->SetPreselectionProp(theRed,theGreen,theBlue,theWidth); } @@ -258,8 +262,8 @@ SVTK_View void SVTK_View ::SetSelectionTolerance(const double& theTolNodes, - const double& theTolCell, - const double& theTolObjects) + const double& theTolCell, + const double& theTolObjects) { GetRenderer()->SetSelectionTolerance(theTolNodes, theTolCell, theTolObjects); } @@ -273,12 +277,32 @@ SVTK_View ::isInViewer(const Handle(SALOME_InteractiveObject)& theIObject) { using namespace SVTK; + VTK::ActorCollectionCopy aCopy(getRenderer()->GetActors()); SALOME_Actor* anActor = - Find(getRenderer()->GetActors(), - TIsSameIObject(theIObject)); + Find(aCopy.GetActors(), + TIsSameIObject(theIObject)); return anActor != NULL; } +namespace SVTK +{ + struct TIsActorVisibleAction + { + bool& myResult; + TIsActorVisibleAction(bool& theResult): + myResult(theResult) + { + myResult = false; + } + void + operator()(SALOME_Actor* theActor) + { + if( !myResult ) + myResult = theActor->GetVisibility(); + } + }; +} + /*! \return true if object is displayed in viewer \param theIO - object to be checked @@ -288,10 +312,12 @@ SVTK_View ::isVisible(const Handle(SALOME_InteractiveObject)& theIObject) { using namespace SVTK; - SALOME_Actor* anActor = - Find(getRenderer()->GetActors(), - TIsSameIObject(theIObject)); - return anActor != NULL && anActor->GetVisibility(); + bool aResult; + VTK::ActorCollectionCopy aCopy(getRenderer()->GetActors()); + ForEachIf(aCopy.GetActors(), + TIsSameIObject(theIObject), + TIsActorVisibleAction(aResult)); + return aResult; } /*! @@ -302,13 +328,14 @@ SVTK_View void SVTK_View ::rename(const Handle(SALOME_InteractiveObject)& theIObject, - const QString& theName) + const QString& theName) { using namespace SVTK; - ForEachIf(getRenderer()->GetActors(), - TIsSameIObject(theIObject), - TSetFunction - (&SALOME_Actor::setName,theName.toLatin1().data())); + VTK::ActorCollectionCopy aCopy(getRenderer()->GetActors()); + ForEachIf(aCopy.GetActors(), + TIsSameIObject(theIObject), + TSetFunction + (&SALOME_Actor::setName,theName.toLatin1().data())); } /*! @@ -331,8 +358,12 @@ SVTK_View { if(theMode == 0) ChangeRepresentationToWireframe(); - else + else if (theMode == 1) ChangeRepresentationToSurface(); + else if (theMode == 2) { + ChangeRepresentationToSurfaceWithEdges(); + theMode++; + } myDisplayMode = theMode; } @@ -344,13 +375,14 @@ SVTK_View void SVTK_View ::SetDisplayMode(const Handle(SALOME_InteractiveObject)& theIObject, - int theMode) + int theMode) { using namespace SVTK; - ForEachIf(getRenderer()->GetActors(), - TIsSameIObject(theIObject), - TSetFunction - (&SALOME_Actor::setDisplayMode,theMode)); + VTK::ActorCollectionCopy aCopy(getRenderer()->GetActors()); + ForEachIf(aCopy.GetActors(), + TIsSameIObject(theIObject), + TSetFunction + (&SALOME_Actor::setDisplayMode,theMode)); } /*! @@ -360,7 +392,8 @@ void SVTK_View ::ChangeRepresentationToWireframe() { - ChangeRepresentationToWireframe(getRenderer()->GetActors()); + VTK::ActorCollectionCopy aCopy(getRenderer()->GetActors()); + ChangeRepresentationToWireframe(aCopy.GetActors()); } /*! @@ -370,7 +403,19 @@ void SVTK_View ::ChangeRepresentationToSurface() { - ChangeRepresentationToSurface(getRenderer()->GetActors()); + VTK::ActorCollectionCopy aCopy(getRenderer()->GetActors()); + ChangeRepresentationToSurface(aCopy.GetActors()); +} + +/*! + Change all actors to shading with edges +*/ +void +SVTK_View +::ChangeRepresentationToSurfaceWithEdges() +{ + VTK::ActorCollectionCopy aCopy(getRenderer()->GetActors()); + ChangeRepresentationToSurfaceWithEdges(aCopy.GetActors()); } /*! @@ -383,8 +428,8 @@ SVTK_View { using namespace SVTK; ForEach(theCollection, - TSetFunction - (&SALOME_Actor::setDisplayMode,0)); + TSetFunction + (&SALOME_Actor::setDisplayMode,0)); Repaint(); } @@ -398,8 +443,23 @@ SVTK_View { using namespace SVTK; ForEach(theCollection, - TSetFunction - (&SALOME_Actor::setDisplayMode,1)); + TSetFunction + (&SALOME_Actor::setDisplayMode,1)); + Repaint(); +} + +/*! + Change to shading with edges a list of vtkactor + theCollection - list of vtkactor +*/ +void +SVTK_View +::ChangeRepresentationToSurfaceWithEdges(vtkActorCollection* theCollection) +{ + using namespace SVTK; + ForEach(theCollection, + TSetFunction + (&SALOME_Actor::setDisplayMode,3)); Repaint(); } @@ -432,8 +492,9 @@ SVTK_View ::EraseAll() { using namespace SVTK; - ForEach(getRenderer()->GetActors(), - TErase()); + VTK::ActorCollectionCopy aCopy(getRenderer()->GetActors()); + ForEach(aCopy.GetActors(), + TErase()); Repaint(); } @@ -445,8 +506,9 @@ SVTK_View ::DisplayAll() { using namespace SVTK; - ForEach(getRenderer()->GetActors(), - TSetVisibility(true)); + VTK::ActorCollectionCopy aCopy(getRenderer()->GetActors()); + ForEach(aCopy.GetActors(), + TSetVisibility(true)); Repaint(); } @@ -458,7 +520,7 @@ SVTK_View void SVTK_View ::Erase(SALOME_Actor* theActor, - bool theIsUpdate) + bool theIsUpdate) { SVTK::TErase()(theActor); @@ -475,12 +537,13 @@ SVTK_View void SVTK_View ::Erase(const Handle(SALOME_InteractiveObject)& theIObject, - bool theIsUpdate) + bool theIsUpdate) { using namespace SVTK; - ForEachIf(getRenderer()->GetActors(), - TIsSameIObject(theIObject), - TErase()); + VTK::ActorCollectionCopy aCopy(getRenderer()->GetActors()); + ForEachIf(aCopy.GetActors(), + TIsSameIObject(theIObject), + TErase()); if(theIsUpdate) Repaint(); } @@ -491,7 +554,7 @@ SVTK_View void SVTK_View ::Display(SALOME_Actor* theActor, - bool theIsUpdate) + bool theIsUpdate) { GetRenderer()->AddActor(theActor); theActor->SetVisibility(true); @@ -506,12 +569,13 @@ SVTK_View void SVTK_View ::Display(const Handle(SALOME_InteractiveObject)& theIObject, - bool theIsUpdate) + bool theIsUpdate) { using namespace SVTK; - ForEachIf(getRenderer()->GetActors(), - TIsSameIObject(theIObject), - TSetVisibility(true)); + VTK::ActorCollectionCopy aCopy(getRenderer()->GetActors()); + ForEachIf(aCopy.GetActors(), + TIsSameIObject(theIObject), + TSetVisibility(true)); if(theIsUpdate) Repaint(); @@ -551,12 +615,13 @@ namespace SVTK void SVTK_View ::Remove(const Handle(SALOME_InteractiveObject)& theIObject, - bool theIsUpdate) + bool theIsUpdate) { using namespace SVTK; - ForEachIf(getRenderer()->GetActors(), - TIsSameIObject(theIObject), - TRemoveAction(GetRenderer())); + VTK::ActorCollectionCopy aCopy(getRenderer()->GetActors()); + ForEachIf(aCopy.GetActors(), + TIsSameIObject(theIObject), + TRemoveAction(GetRenderer())); if(theIsUpdate) Repaint(); } @@ -567,7 +632,7 @@ SVTK_View void SVTK_View ::Remove(SALOME_Actor* theActor, - bool theIsUpdate) + bool theIsUpdate) { GetRenderer()->RemoveActor(theActor); if(theIsUpdate) @@ -582,7 +647,8 @@ SVTK_View ::RemoveAll(bool theIsUpdate) { vtkRenderer* aRenderer = getRenderer(); - if(vtkActorCollection* anActors = aRenderer->GetActors()){ + VTK::ActorCollectionCopy aCopy(getRenderer()->GetActors()); + if(vtkActorCollection* anActors = aCopy.GetActors()){ anActors->InitTraversal(); while(vtkActor *anAct = anActors->GetNextActor()){ if(SALOME_Actor* aSAct = SALOME_Actor::SafeDownCast(anAct)){ @@ -605,9 +671,10 @@ SVTK_View ::GetTransparency(const Handle(SALOME_InteractiveObject)& theIObject) { using namespace SVTK; + VTK::ActorCollectionCopy aCopy(getRenderer()->GetActors()); SALOME_Actor* anActor = - Find(getRenderer()->GetActors(), - TIsSameIObject(theIObject)); + Find(aCopy.GetActors(), + TIsSameIObject(theIObject)); if(anActor) return 1.0 - anActor->GetOpacity(); return -1.0; @@ -622,14 +689,15 @@ SVTK_View void SVTK_View ::SetTransparency(const Handle(SALOME_InteractiveObject)& theIObject, - float theTrans) + float theTrans) { - vtkFloatingPointType anOpacity = 1.0 - theTrans; + double anOpacity = 1.0 - theTrans; using namespace SVTK; - ForEachIf(getRenderer()->GetActors(), - TIsSameIObject(theIObject), - TSetFunction - (&SALOME_Actor::SetOpacity,anOpacity)); + VTK::ActorCollectionCopy aCopy(getRenderer()->GetActors()); + ForEachIf(aCopy.GetActors(), + TIsSameIObject(theIObject), + TSetFunction + (&SALOME_Actor::SetOpacity,anOpacity)); } /*! @@ -640,15 +708,16 @@ SVTK_View void SVTK_View ::SetColor(const Handle(SALOME_InteractiveObject)& theIObject, - const QColor& theColor) + const QColor& theColor) { - vtkFloatingPointType aColor[3] = {theColor.red()/255., theColor.green()/255., theColor.blue()/255.}; + double aColor[3] = {theColor.red()/255., theColor.green()/255., theColor.blue()/255.}; using namespace SVTK; - ForEachIf(getRenderer()->GetActors(), - TIsSameIObject(theIObject), - TSetFunction - (&SALOME_Actor::SetColor,aColor)); + VTK::ActorCollectionCopy aCopy(getRenderer()->GetActors()); + ForEachIf(aCopy.GetActors(), + TIsSameIObject(theIObject), + TSetFunction + (&SALOME_Actor::SetColor,aColor)); } @@ -661,11 +730,12 @@ SVTK_View ::GetColor(const Handle(SALOME_InteractiveObject)& theIObject) { using namespace SVTK; + VTK::ActorCollectionCopy aCopy(getRenderer()->GetActors()); SALOME_Actor* anActor = - Find(getRenderer()->GetActors(), - TIsSameIObject(theIObject)); + Find(aCopy.GetActors(), + TIsSameIObject(theIObject)); if(anActor){ - vtkFloatingPointType r,g,b; + double r,g,b; anActor->GetColor(r,g,b); return QColor(int(r*255),int(g*255),int(b*255)); } @@ -673,3 +743,74 @@ SVTK_View return QColor(0,0,0); } +/*! + Change material + \param theIObject - object + \param thePropF - property contained new properties of front material + \param thePropB - property contained new properties of back material +*/ +void +SVTK_View +::SetMaterial(const Handle(SALOME_InteractiveObject)& theIObject, + vtkProperty* thePropF, vtkProperty* thePropB) +{ + using namespace SVTK; + VTK::ActorCollectionCopy aCopy(getRenderer()->GetActors()); + std::vector aProps; + aProps.push_back( thePropF ); + aProps.push_back( thePropB ); + ForEachIf(aCopy.GetActors(), + TIsSameIObject(theIObject), + TSetFunction > + (&SALOME_Actor::SetMaterial,aProps)); +} + +/*! + Get current front material + \param theIObject - object + \return property contained front material properties of the given object +*/ +vtkProperty* +SVTK_View +::GetFrontMaterial(const Handle(SALOME_InteractiveObject)& theIObject) +{ + using namespace SVTK; + VTK::ActorCollectionCopy aCopy(getRenderer()->GetActors()); + SALOME_Actor* anActor = + Find(aCopy.GetActors(), + TIsSameIObject(theIObject)); + if(anActor) + return anActor->GetFrontMaterial(); + return NULL; +} + +/*! + Get current back material + \param theIObject - object + \return property contained back material properties of the given object +*/ +vtkProperty* +SVTK_View +::GetBackMaterial(const Handle(SALOME_InteractiveObject)& theIObject) +{ + using namespace SVTK; + VTK::ActorCollectionCopy aCopy(getRenderer()->GetActors()); + SALOME_Actor* anActor = + Find(aCopy.GetActors(), + TIsSameIObject(theIObject)); + if(anActor) + return anActor->GetBackMaterial(); + return NULL; +} + +/*! + \Collect objects visible in viewer + \param theList - visible objects collection +*/ +void SVTK_View::GetVisible( SALOME_ListIO& theList ) +{ + using namespace SVTK; + VTK::ActorCollectionCopy aCopy(getRenderer()->GetActors()); + ForEach(aCopy.GetActors(), + TCollectIfVisible(theList)); +}