-// 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 <vtkActorCollection.h>
#include <vtkRenderer.h>
+#include <vtkProperty.h>
/*!
Constructor
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()));
}
/*!
operator()( SALOME_Actor* theActor)
{
if(theActor->GetMapper() && theActor->hasIO()){
- theActor->Highlight( myIsHighlight );
+ theActor->Highlight( myIsHighlight );
}
}
};
SVTK_SignalHandler
::onSelectionChanged()
{
- vtkActorCollection* anActors = myMainWindow->getRenderer()->GetActors();
+ VTK::ActorCollectionCopy aCopy(myMainWindow->getRenderer()->GetActors());
+ vtkActorCollection* anActors = aCopy.GetActors();
using namespace SVTK;
ForEach<SALOME_Actor>(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<SALOME_Actor>(anActors,
- TIsSameIObject<SALOME_Actor>(anIter.Value()),
- THighlightAction(true));
+ TIsSameIObject<SALOME_Actor>(anIter.Value()),
+ THighlightAction(true));
}
myMainWindow->Repaint(false);
::unHighlightAll()
{
using namespace SVTK;
- ForEach<SALOME_Actor>(getRenderer()->GetActors(),
- THighlightAction( false ));
+ VTK::ActorCollectionCopy aCopy(getRenderer()->GetActors());
+ ForEach<SALOME_Actor>(aCopy.GetActors(),
+ THighlightAction( false ));
Repaint();
}
void
SVTK_View
::highlight( const Handle(SALOME_InteractiveObject)& theIO,
- bool theIsHighlight,
- bool theIsUpdate )
+ bool theIsHighlight,
+ bool theIsUpdate )
{
using namespace SVTK;
- ForEachIf<SALOME_Actor>(getRenderer()->GetActors(),
- TIsSameIObject<SALOME_Actor>( theIO ),
- THighlightAction(theIsHighlight));
+ VTK::ActorCollectionCopy aCopy(getRenderer()->GetActors());
+ ForEachIf<SALOME_Actor>(aCopy.GetActors(),
+ TIsSameIObject<SALOME_Actor>( theIO ),
+ THighlightAction(theIsHighlight));
Repaint();
}
::FindIObject(const char* theEntry)
{
using namespace SVTK;
+ VTK::ActorCollectionCopy aCopy(getRenderer()->GetActors());
SALOME_Actor* anActor =
- Find<SALOME_Actor>(getRenderer()->GetActors(),
- TIsSameEntry<SALOME_Actor>(theEntry));
+ Find<SALOME_Actor>(aCopy.GetActors(),
+ TIsSameEntry<SALOME_Actor>(theEntry));
if(anActor != NULL)
return anActor->getIO();
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);
}
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);
}
void
SVTK_View
::SetSelectionTolerance(const double& theTolNodes,
- const double& theTolCell,
- const double& theTolObjects)
+ const double& theTolCell,
+ const double& theTolObjects)
{
GetRenderer()->SetSelectionTolerance(theTolNodes, theTolCell, theTolObjects);
}
::isInViewer(const Handle(SALOME_InteractiveObject)& theIObject)
{
using namespace SVTK;
+ VTK::ActorCollectionCopy aCopy(getRenderer()->GetActors());
SALOME_Actor* anActor =
- Find<SALOME_Actor>(getRenderer()->GetActors(),
- TIsSameIObject<SALOME_Actor>(theIObject));
+ Find<SALOME_Actor>(aCopy.GetActors(),
+ TIsSameIObject<SALOME_Actor>(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
::isVisible(const Handle(SALOME_InteractiveObject)& theIObject)
{
using namespace SVTK;
- SALOME_Actor* anActor =
- Find<SALOME_Actor>(getRenderer()->GetActors(),
- TIsSameIObject<SALOME_Actor>(theIObject));
- return anActor != NULL && anActor->GetVisibility();
+ bool aResult;
+ VTK::ActorCollectionCopy aCopy(getRenderer()->GetActors());
+ ForEachIf<SALOME_Actor>(aCopy.GetActors(),
+ TIsSameIObject<SALOME_Actor>(theIObject),
+ TIsActorVisibleAction(aResult));
+ return aResult;
}
/*!
void
SVTK_View
::rename(const Handle(SALOME_InteractiveObject)& theIObject,
- const QString& theName)
+ const QString& theName)
{
using namespace SVTK;
- ForEachIf<SALOME_Actor>(getRenderer()->GetActors(),
- TIsSameIObject<SALOME_Actor>(theIObject),
- TSetFunction<SALOME_Actor,const char*,const char*>
- (&SALOME_Actor::setName,theName.toLatin1().data()));
+ VTK::ActorCollectionCopy aCopy(getRenderer()->GetActors());
+ ForEachIf<SALOME_Actor>(aCopy.GetActors(),
+ TIsSameIObject<SALOME_Actor>(theIObject),
+ TSetFunction<SALOME_Actor,const char*,const char*>
+ (&SALOME_Actor::setName,theName.toLatin1().data()));
}
/*!
{
if(theMode == 0)
ChangeRepresentationToWireframe();
- else
+ else if (theMode == 1)
ChangeRepresentationToSurface();
+ else if (theMode == 2) {
+ ChangeRepresentationToSurfaceWithEdges();
+ theMode++;
+ }
myDisplayMode = theMode;
}
void
SVTK_View
::SetDisplayMode(const Handle(SALOME_InteractiveObject)& theIObject,
- int theMode)
+ int theMode)
{
using namespace SVTK;
- ForEachIf<SALOME_Actor>(getRenderer()->GetActors(),
- TIsSameIObject<SALOME_Actor>(theIObject),
- TSetFunction<SALOME_Actor,int>
- (&SALOME_Actor::setDisplayMode,theMode));
+ VTK::ActorCollectionCopy aCopy(getRenderer()->GetActors());
+ ForEachIf<SALOME_Actor>(aCopy.GetActors(),
+ TIsSameIObject<SALOME_Actor>(theIObject),
+ TSetFunction<SALOME_Actor,int>
+ (&SALOME_Actor::setDisplayMode,theMode));
}
/*!
SVTK_View
::ChangeRepresentationToWireframe()
{
- ChangeRepresentationToWireframe(getRenderer()->GetActors());
+ VTK::ActorCollectionCopy aCopy(getRenderer()->GetActors());
+ ChangeRepresentationToWireframe(aCopy.GetActors());
}
/*!
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());
}
/*!
{
using namespace SVTK;
ForEach<SALOME_Actor>(theCollection,
- TSetFunction<SALOME_Actor,int>
- (&SALOME_Actor::setDisplayMode,0));
+ TSetFunction<SALOME_Actor,int>
+ (&SALOME_Actor::setDisplayMode,0));
Repaint();
}
{
using namespace SVTK;
ForEach<SALOME_Actor>(theCollection,
- TSetFunction<SALOME_Actor,int>
- (&SALOME_Actor::setDisplayMode,1));
+ TSetFunction<SALOME_Actor,int>
+ (&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<SALOME_Actor>(theCollection,
+ TSetFunction<SALOME_Actor,int>
+ (&SALOME_Actor::setDisplayMode,3));
Repaint();
}
::EraseAll()
{
using namespace SVTK;
- ForEach<SALOME_Actor>(getRenderer()->GetActors(),
- TErase());
+ VTK::ActorCollectionCopy aCopy(getRenderer()->GetActors());
+ ForEach<SALOME_Actor>(aCopy.GetActors(),
+ TErase());
Repaint();
}
::DisplayAll()
{
using namespace SVTK;
- ForEach<SALOME_Actor>(getRenderer()->GetActors(),
- TSetVisibility<SALOME_Actor>(true));
+ VTK::ActorCollectionCopy aCopy(getRenderer()->GetActors());
+ ForEach<SALOME_Actor>(aCopy.GetActors(),
+ TSetVisibility<SALOME_Actor>(true));
Repaint();
}
void
SVTK_View
::Erase(SALOME_Actor* theActor,
- bool theIsUpdate)
+ bool theIsUpdate)
{
SVTK::TErase()(theActor);
void
SVTK_View
::Erase(const Handle(SALOME_InteractiveObject)& theIObject,
- bool theIsUpdate)
+ bool theIsUpdate)
{
using namespace SVTK;
- ForEachIf<SALOME_Actor>(getRenderer()->GetActors(),
- TIsSameIObject<SALOME_Actor>(theIObject),
- TErase());
+ VTK::ActorCollectionCopy aCopy(getRenderer()->GetActors());
+ ForEachIf<SALOME_Actor>(aCopy.GetActors(),
+ TIsSameIObject<SALOME_Actor>(theIObject),
+ TErase());
if(theIsUpdate)
Repaint();
}
void
SVTK_View
::Display(SALOME_Actor* theActor,
- bool theIsUpdate)
+ bool theIsUpdate)
{
GetRenderer()->AddActor(theActor);
theActor->SetVisibility(true);
void
SVTK_View
::Display(const Handle(SALOME_InteractiveObject)& theIObject,
- bool theIsUpdate)
+ bool theIsUpdate)
{
using namespace SVTK;
- ForEachIf<SALOME_Actor>(getRenderer()->GetActors(),
- TIsSameIObject<SALOME_Actor>(theIObject),
- TSetVisibility<SALOME_Actor>(true));
+ VTK::ActorCollectionCopy aCopy(getRenderer()->GetActors());
+ ForEachIf<SALOME_Actor>(aCopy.GetActors(),
+ TIsSameIObject<SALOME_Actor>(theIObject),
+ TSetVisibility<SALOME_Actor>(true));
if(theIsUpdate)
Repaint();
void
SVTK_View
::Remove(const Handle(SALOME_InteractiveObject)& theIObject,
- bool theIsUpdate)
+ bool theIsUpdate)
{
using namespace SVTK;
- ForEachIf<SALOME_Actor>(getRenderer()->GetActors(),
- TIsSameIObject<SALOME_Actor>(theIObject),
- TRemoveAction(GetRenderer()));
+ VTK::ActorCollectionCopy aCopy(getRenderer()->GetActors());
+ ForEachIf<SALOME_Actor>(aCopy.GetActors(),
+ TIsSameIObject<SALOME_Actor>(theIObject),
+ TRemoveAction(GetRenderer()));
if(theIsUpdate)
Repaint();
}
void
SVTK_View
::Remove(SALOME_Actor* theActor,
- bool theIsUpdate)
+ bool theIsUpdate)
{
GetRenderer()->RemoveActor(theActor);
if(theIsUpdate)
::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)){
::GetTransparency(const Handle(SALOME_InteractiveObject)& theIObject)
{
using namespace SVTK;
+ VTK::ActorCollectionCopy aCopy(getRenderer()->GetActors());
SALOME_Actor* anActor =
- Find<SALOME_Actor>(getRenderer()->GetActors(),
- TIsSameIObject<SALOME_Actor>(theIObject));
+ Find<SALOME_Actor>(aCopy.GetActors(),
+ TIsSameIObject<SALOME_Actor>(theIObject));
if(anActor)
return 1.0 - anActor->GetOpacity();
return -1.0;
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<SALOME_Actor>(getRenderer()->GetActors(),
- TIsSameIObject<SALOME_Actor>(theIObject),
- TSetFunction<SALOME_Actor,vtkFloatingPointType>
- (&SALOME_Actor::SetOpacity,anOpacity));
+ VTK::ActorCollectionCopy aCopy(getRenderer()->GetActors());
+ ForEachIf<SALOME_Actor>(aCopy.GetActors(),
+ TIsSameIObject<SALOME_Actor>(theIObject),
+ TSetFunction<SALOME_Actor,double>
+ (&SALOME_Actor::SetOpacity,anOpacity));
}
/*!
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<SALOME_Actor>(getRenderer()->GetActors(),
- TIsSameIObject<SALOME_Actor>(theIObject),
- TSetFunction<SALOME_Actor,const vtkFloatingPointType*>
- (&SALOME_Actor::SetColor,aColor));
+ VTK::ActorCollectionCopy aCopy(getRenderer()->GetActors());
+ ForEachIf<SALOME_Actor>(aCopy.GetActors(),
+ TIsSameIObject<SALOME_Actor>(theIObject),
+ TSetFunction<SALOME_Actor,const double*>
+ (&SALOME_Actor::SetColor,aColor));
}
::GetColor(const Handle(SALOME_InteractiveObject)& theIObject)
{
using namespace SVTK;
+ VTK::ActorCollectionCopy aCopy(getRenderer()->GetActors());
SALOME_Actor* anActor =
- Find<SALOME_Actor>(getRenderer()->GetActors(),
- TIsSameIObject<SALOME_Actor>(theIObject));
+ Find<SALOME_Actor>(aCopy.GetActors(),
+ TIsSameIObject<SALOME_Actor>(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));
}
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<vtkProperty*> aProps;
+ aProps.push_back( thePropF );
+ aProps.push_back( thePropB );
+ ForEachIf<SALOME_Actor>(aCopy.GetActors(),
+ TIsSameIObject<SALOME_Actor>(theIObject),
+ TSetFunction<SALOME_Actor,std::vector<vtkProperty*> >
+ (&SALOME_Actor::SetMaterial,aProps));
+}
+
+/*!\r
+ Get current front material\r
+ \param theIObject - object\r
+ \return property contained front material properties of the given object\r
+*/\r
+vtkProperty* \r
+SVTK_View\r
+::GetFrontMaterial(const Handle(SALOME_InteractiveObject)& theIObject)\r
+{\r
+ using namespace SVTK;\r
+ VTK::ActorCollectionCopy aCopy(getRenderer()->GetActors());\r
+ SALOME_Actor* anActor = \r
+ Find<SALOME_Actor>(aCopy.GetActors(),\r
+ TIsSameIObject<SALOME_Actor>(theIObject));\r
+ if(anActor)\r
+ return anActor->GetFrontMaterial();\r
+ return NULL;\r
+}\r
+\r
+/*!\r
+ Get current back material\r
+ \param theIObject - object\r
+ \return property contained back material properties of the given object\r
+*/\r
+vtkProperty* \r
+SVTK_View\r
+::GetBackMaterial(const Handle(SALOME_InteractiveObject)& theIObject)\r
+{\r
+ using namespace SVTK;\r
+ VTK::ActorCollectionCopy aCopy(getRenderer()->GetActors());\r
+ SALOME_Actor* anActor = \r
+ Find<SALOME_Actor>(aCopy.GetActors(),\r
+ TIsSameIObject<SALOME_Actor>(theIObject));\r
+ if(anActor)\r
+ 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<SALOME_Actor>(aCopy.GetActors(),
+ TCollectIfVisible<SALOME_Actor>(theList));
+}