-using namespace std;
-// File : VTKViewer_RenderWindowInteractor.cxx
-// Created : Wed Mar 20 11:32:45 2002
-// Author : Nicolas REJNERI
-// Project : SALOME
-// Module : VTKViewer
-// Copyright : Open CASCADE 2002
+// SALOME VTKViewer : build VTK viewer into Salome desktop
+//
+// 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 : VTKViewer_RenderWindowInteractor.cxx
+// Author : Nicolas REJNERI
+// Module : SALOME
// $Header$
#include "VTKViewer_RenderWindowInteractor.h"
-#include "VTKViewer_RenderWindow.h"
+
#include "VTKViewer_InteractorStyleSALOME.h"
+#include "VTKViewer_RenderWindow.h"
+#include "VTKViewer_ViewFrame.h"
+
+#include "VTKViewer_Algorithm.h"
+#include "VTKViewer_Functor.h"
#include "QAD_Application.h"
#include "QAD_Desktop.h"
-#include "SALOME_Selection.h"
-#include "SALOME_Actor.h"
+#include "VTKViewer_Actor.h"
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
// VTK Includes
-#include <vtkAssemblyNode.h>
-#include <vtkActor.h>
-#include <vtkInteractorStyle.h>
#include <vtkObjectFactory.h>
#include <vtkPicker.h>
#include <vtkCellPicker.h>
#include <vtkPointPicker.h>
-#include <vtkDataSetMapper.h>
-#include <vtkUnstructuredGrid.h>
-#include <vtkUnstructuredGridReader.h>
-#include <vtkSphereSource.h>
-#include <vtkDataSet.h>
-#include <vtkMaskPoints.h>
-#include <vtkVertex.h>
+#include <vtkRendererCollection.h>
// QT Includes
#include <qkeycode.h>
+#include <TColStd_IndexedMapOfInteger.hxx>
+
+#include "utilities.h"
+
+using namespace std;
+
+#ifdef _DEBUG_
+static int MYDEBUG = 0;
+#else
+static int MYDEBUG = 0;
+#endif
+
+
VTKViewer_RenderWindowInteractor* VTKViewer_RenderWindowInteractor::New() {
vtkObject *ret = vtkObjectFactory::CreateInstance("VTKViewer_RenderWindowInteractor") ;
if( ret ) {
VTKViewer_RenderWindowInteractor::VTKViewer_RenderWindowInteractor() {
this->Enabled = 0 ;
this->mTimer = new QTimer( this ) ;
- this->displaymode = 0;
-
- vtkPicker* thepicker = vtkPicker::New();
- thepicker->SetTolerance(0);
- this->SetPicker(thepicker);
+ myDisplayMode = 0;
+ myGUIWindow = 0;
+
+ myBasicPicker = vtkPicker::New();
+ myCellPicker = vtkCellPicker::New();
+ myPointPicker = vtkPointPicker::New();
+
+ myCellActor = VTKViewer_Actor::New();
+ myCellActor->PickableOff();
+ myCellActor->GetProperty()->SetColor(1,1,0);
+ myCellActor->GetProperty()->SetLineWidth(5);
+ myCellActor->GetProperty()->SetRepresentationToSurface();
+
+ myEdgeActor = VTKViewer_Actor::New();
+ myEdgeActor->PickableOff();
+ myEdgeActor->GetProperty()->SetColor(1,0,0);
+ myEdgeActor->GetProperty()->SetLineWidth(5);
+ myEdgeActor->GetProperty()->SetRepresentationToWireframe();
+
+ myPointActor = VTKViewer_Actor::New();
+ myPointActor->PickableOff();
+ myPointActor->GetProperty()->SetColor(1,1,0);
+ myPointActor->GetProperty()->SetPointSize(5);
+ myPointActor->GetProperty()->SetRepresentationToPoints();
connect(mTimer, SIGNAL(timeout()), this, SLOT(TimerFunc())) ;
}
VTKViewer_RenderWindowInteractor::~VTKViewer_RenderWindowInteractor() {
+ if(MYDEBUG) INFOS("VTKViewer_RenderWindowInteractor::~VTKViewer_RenderWindowInteractor()");
+
delete mTimer ;
+
+ myViewFrame->RemoveActor(myCellActor);
+ myViewFrame->RemoveActor(myEdgeActor);
+ myViewFrame->RemoveActor(myPointActor);
+
+ myCellActor->Delete();
+ myEdgeActor->Delete();
+ myPointActor->Delete();
+
+ myBasicPicker->Delete();
+ myCellPicker->Delete();
+ myPointPicker->Delete();
}
void VTKViewer_RenderWindowInteractor::PrintSelf(ostream& os, vtkIndent indent) {
// it works. If the dynamic_cast does not work, we flag an error
// and get the hell out.
//
- VTKViewer_RenderWindow *my_render_win = dynamic_cast<VTKViewer_RenderWindow *>(RenderWindow) ;
- if( ! my_render_win ) {
+ vtkRenderWindow *my_render_win = dynamic_cast<vtkRenderWindow *>(RenderWindow) ;
+ if( !my_render_win ) {
vtkErrorMacro(<< "VTKViewer_RenderWindowInteractor::Initialize() can only handle VTKViewer_RenderWindow.") ;
return ;
}
// If the render window has zero size, then set it to a default
// value of 300x300.
//
- int *size = my_render_win->GetSize() ;
- size[0] = ((size[0] > 0) ? size[0] : 300);
- size[1] = ((size[1] > 0) ? size[1] : 300);
+ int* aSize = my_render_win->GetSize();
+ this->Size[0] = ((aSize[0] > 0) ? aSize[0] : 300);
+ this->Size[1] = ((aSize[1] > 0) ? aSize[1] : 300);
+
+ this->SetPicker(myBasicPicker);
+
+ SetSelectionTolerance();
//
// Enable the interactor.
//
my_render_win->Start() ;
- //
- // Set our size to that of the render window.
- //
- this->Size[0] = size[0] ;
- this->Size[1] = size[1] ;
-
//
// The interactor has been initialized.
//
this->Initialized = 1 ;
- VTKViewer_InteractorStyleSALOME* style = VTKViewer_InteractorStyleSALOME::New();
- this->SetInteractorStyle(style);
+ return ;
+}
- Cell_Actor = vtkActor::New();
- Cell_Actor->PickableOff();
- Cell_Actor->GetProperty()->SetColor(1,1,0);
- Cell_Actor->GetProperty()->SetRepresentationToSurface();
- Edge_Actor = vtkActor::New();
- Edge_Actor->PickableOff();
- Edge_Actor->GetProperty()->SetColor(1,0,0);
- Edge_Actor->GetProperty()->SetRepresentationToSurface();
- Edge_Actor->GetProperty()->SetLineWidth(20);
+//----------------------------------------------------------------------------
+void VTKViewer_RenderWindowInteractor::setGUIWindow(QWidget* theWindow){
+ myGUIWindow = theWindow;
+}
- Point_Actor = vtkActor::New();
- Point_Actor->PickableOff();
- Point_Actor->GetProperty()->SetColor(1,1,0);
- Point_Actor->GetProperty()->SetRepresentationToSurface();
- Point_Actor->GetProperty()->SetPointSize(3);
+//----------------------------------------------------------------------------
+void VTKViewer_RenderWindowInteractor::setViewFrame(VTKViewer_ViewFrame* theViewFrame){
+ myViewFrame = theViewFrame;
- return ;
+ myViewFrame->InsertActor(myCellActor);
+ myViewFrame->InsertActor(myEdgeActor);
+ myViewFrame->InsertActor(myPointActor);
}
-void VTKViewer_RenderWindowInteractor::SetSelectionMode(int mode)
+//----------------------------------------------------------------------------
+void VTKViewer_RenderWindowInteractor::MoveInternalActors()
{
- Cell_Actor->VisibilityOff();
- Edge_Actor->VisibilityOff();
- Point_Actor->VisibilityOff();
-
- selectionmode = mode;
- if ( mode == 1 ) {
- vtkPointPicker* thepicker = vtkPointPicker::New();
- // thepicker->SetTolerance(0.001);
- this->SetPicker(thepicker);
- } else if ( mode == 2 ) {
- vtkCellPicker* thepicker = vtkCellPicker::New();
- thepicker->SetTolerance(0.001);
- this->SetPicker(thepicker);
- } else if ( mode == 3 ) {
- vtkCellPicker* thepicker = vtkCellPicker::New();
- thepicker->SetTolerance(0.001);
- this->SetPicker(thepicker);
- } else if ( mode == 4 ) {
- vtkPicker* thepicker = vtkPicker::New();
- thepicker->SetTolerance(0.001);
- this->SetPicker(thepicker);
- }
+ myViewFrame->MoveActor(myCellActor);
+ myViewFrame->MoveActor(myEdgeActor);
+ myViewFrame->MoveActor(myPointActor);
+}
+
+//----------------------------------------------------------------------------
+void VTKViewer_RenderWindowInteractor::SetInteractorStyle(vtkInteractorObserver *theInteractor){
+ myInteractorStyle = dynamic_cast<VTKViewer_InteractorStyleSALOME*>(theInteractor);
+ vtkRenderWindowInteractor::SetInteractorStyle(theInteractor);
+}
+
+
+void VTKViewer_RenderWindowInteractor::SetSelectionMode(Selection_Mode theMode)
+{
+ myCellActor->SetVisibility(false);
+ myEdgeActor->SetVisibility(false);
+ myPointActor->SetVisibility(false);
+
+ switch(theMode){
+ case ActorSelection:
+ this->SetPicker(myBasicPicker);
+ break;
+ case NodeSelection:
+ this->SetPicker(myPointPicker);
+ break;
+ case CellSelection:
+ case EdgeSelection:
+ case FaceSelection:
+ case VolumeSelection:
+ case EdgeOfCellSelection:
+ this->SetPicker(myCellPicker);
+ break;
+ }
+
+ myInteractorStyle->OnSelectionModeChanged();
+}
+
+void VTKViewer_RenderWindowInteractor::SetSelectionProp(const double& theRed, const double& theGreen,
+ const double& theBlue, const int& theWidth)
+{
+ myCellActor->GetProperty()->SetColor(theRed, theGreen, theBlue);
+ myCellActor->GetProperty()->SetLineWidth(theWidth);
+
+ myPointActor->GetProperty()->SetColor(theRed, theGreen, theBlue);
+ myPointActor->GetProperty()->SetPointSize(theWidth);
}
+void VTKViewer_RenderWindowInteractor::SetSelectionTolerance(const double& theTolNodes, const double& theTolItems)
+{
+ myTolNodes = theTolNodes;
+ myTolItems = theTolItems;
+
+ myBasicPicker->SetTolerance(myTolItems);
+ myCellPicker->SetTolerance(myTolItems);
+ myPointPicker->SetTolerance(myTolNodes);
+
+}
void VTKViewer_RenderWindowInteractor::Enable() {
//
return ;
}
- this->InteractorStyle->OnTimer() ;
+ ((vtkInteractorStyle*)this->InteractorStyle)->OnTimer() ;
emit RenderWindowModified() ;
}
// We cannot do much unless there is a render window
// associated with this interactor.
//
- if( ! RenderWindow ) {
+ if( ! myGUIWindow ) {
vtkErrorMacro(<< "VTKViewer_RenderWindowInteractor::Initialize(): No render window attached!") ;
return ;
}
// it works. If the dynamic_cast does not work, we flag an error
// and get the hell out.
//
- VTKViewer_RenderWindow *my_render_win = dynamic_cast<VTKViewer_RenderWindow *>(RenderWindow) ;
- if( ! my_render_win ) {
+ if( ! myGUIWindow ) {
vtkErrorMacro(<< "VTKViewer_RenderWindowInteractor::Initialize() can only handle VTKViewer_RenderWindow.") ;
return ;
}
- slot_func ( my_render_win, SIGNAL(ButtonPressed(const QMouseEvent *)),
+ slot_func ( myGUIWindow, SIGNAL(ButtonPressed(const QMouseEvent *)),
this, SLOT(ButtonPressed(const QMouseEvent *)) ) ;
- slot_func( my_render_win, SIGNAL(ButtonReleased(const QMouseEvent *)),
+ slot_func( myGUIWindow, SIGNAL(ButtonReleased(const QMouseEvent *)),
this, SLOT(ButtonReleased(const QMouseEvent *)) ) ;
- slot_func( my_render_win, SIGNAL(LeftButtonPressed(const QMouseEvent *)),
+ slot_func( myGUIWindow, SIGNAL(LeftButtonPressed(const QMouseEvent *)),
this, SLOT(LeftButtonPressed(const QMouseEvent *)) ) ;
- slot_func( my_render_win, SIGNAL(LeftButtonReleased(const QMouseEvent *)),
+ slot_func( myGUIWindow, SIGNAL(LeftButtonReleased(const QMouseEvent *)),
this, SLOT(LeftButtonReleased(const QMouseEvent *)) ) ;
- slot_func( my_render_win, SIGNAL(MiddleButtonPressed(const QMouseEvent *)),
+ slot_func( myGUIWindow, SIGNAL(MiddleButtonPressed(const QMouseEvent *)),
this, SLOT(MiddleButtonPressed(const QMouseEvent *)) ) ;
- slot_func( my_render_win, SIGNAL(MiddleButtonReleased(const QMouseEvent *)),
+ slot_func( myGUIWindow, SIGNAL(MiddleButtonReleased(const QMouseEvent *)),
this, SLOT(MiddleButtonReleased(const QMouseEvent *)) ) ;
- slot_func( my_render_win, SIGNAL(RightButtonPressed(const QMouseEvent *)),
+ slot_func( myGUIWindow, SIGNAL(RightButtonPressed(const QMouseEvent *)),
this, SLOT(RightButtonPressed(const QMouseEvent *)) ) ;
- slot_func( my_render_win, SIGNAL(RightButtonReleased(const QMouseEvent *)),
+ slot_func( myGUIWindow, SIGNAL(RightButtonReleased(const QMouseEvent *)),
this, SLOT(RightButtonReleased(const QMouseEvent *)) ) ;
- slot_func( my_render_win, SIGNAL(MouseMove(const QMouseEvent *)),
+ slot_func( myGUIWindow, SIGNAL(MouseMove(const QMouseEvent *)),
this, SLOT(MouseMove(const QMouseEvent *)) ) ;
- slot_func( my_render_win, SIGNAL(KeyPressed(QKeyEvent *)),
+ slot_func( myGUIWindow, SIGNAL(KeyPressed(QKeyEvent *)),
this, SLOT(KeyPressed(QKeyEvent *)) ) ;
slot_func( this, SIGNAL(RenderWindowModified()),
- my_render_win, SLOT(updateGL()) ) ;
+ myGUIWindow, SLOT(update()) ) ;
}
if( ! this->Enabled ) {
return ;
}
- this->InteractorStyle->OnMouseMove(0, 0,
- event->x(),
- event->y()/*this->Size[1] - event->y() - 1*/) ;
- VTKViewer_InteractorStyleSALOME* Style = 0;
- if (this->InteractorStyle->IsA("VTKViewer_InteractorStyleSALOME"))
- Style = VTKViewer_InteractorStyleSALOME::SafeDownCast(this->InteractorStyle);
- if (!Style || Style->needsRedrawing() )
+ myInteractorStyle->OnMouseMove(0, 0, event->x(), event->y()/*this->Size[1] - event->y() - 1*/) ;
+ if (myInteractorStyle->needsRedrawing() )
emit RenderWindowModified() ;
}
if( ! this->Enabled ) {
return ;
}
- this->InteractorStyle->OnLeftButtonDown( (event->state() & ControlButton),
- (event->state() & ShiftButton),
- event->x(),
- event->y()) ;
+ myInteractorStyle->OnLeftButtonDown((event->state() & ControlButton),
+ (event->state() & ShiftButton),
+ event->x(), event->y());
}
void VTKViewer_RenderWindowInteractor::LeftButtonReleased(const QMouseEvent *event) {
if( ! this->Enabled ) {
return ;
}
- this->InteractorStyle->OnLeftButtonUp( (event->state() & ControlButton),
- (event->state() & ShiftButton),
- event->x(),
- event->y() ) ;
+ myInteractorStyle->OnLeftButtonUp( (event->state() & ControlButton),
+ (event->state() & ShiftButton),
+ event->x(), event->y() ) ;
}
void VTKViewer_RenderWindowInteractor::MiddleButtonPressed(const QMouseEvent *event) {
if( ! this->Enabled ) {
return ;
}
- this->InteractorStyle->OnMiddleButtonDown( (event->state() & ControlButton),
- (event->state() & ShiftButton),
- event->x(),
- event->y() ) ;
+ myInteractorStyle->OnMiddleButtonDown((event->state() & ControlButton),
+ (event->state() & ShiftButton),
+ event->x(), event->y() ) ;
}
void VTKViewer_RenderWindowInteractor::MiddleButtonReleased(const QMouseEvent *event) {
if( ! this->Enabled ) {
return ;
}
- this->InteractorStyle->OnMiddleButtonUp( (event->state() & ControlButton),
- (event->state() & ShiftButton),
- event->x(),
- event->y() ) ;
+ myInteractorStyle->OnMiddleButtonUp( (event->state() & ControlButton),
+ (event->state() & ShiftButton),
+ event->x(), event->y() ) ;
}
void VTKViewer_RenderWindowInteractor::RightButtonPressed(const QMouseEvent *event) {
if( ! this->Enabled ) {
return ;
}
- this->InteractorStyle->OnRightButtonDown( (event->state() & ControlButton),
- (event->state() & ShiftButton),
- event->x(),
- event->y() ) ;
+ myInteractorStyle->OnRightButtonDown( (event->state() & ControlButton),
+ (event->state() & ShiftButton),
+ event->x(), event->y() ) ;
}
void VTKViewer_RenderWindowInteractor::RightButtonReleased(const QMouseEvent *event) {
if( ! this->Enabled ) {
return ;
}
- this->InteractorStyle->OnRightButtonUp( (event->state() & ControlButton),
- (event->state() & ShiftButton),
- event->x(),
- event->y() ) ;
+ myInteractorStyle->OnRightButtonUp( (event->state() & ControlButton),
+ (event->state() & ShiftButton),
+ event->x(), event->y() ) ;
}
void VTKViewer_RenderWindowInteractor::ButtonPressed(const QMouseEvent *event) {
return ;
}
-void VTKViewer_RenderWindowInteractor::ChangeRepresentationToWireframe(vtkActorCollection* ac)
-{
- vtkActor* anActor;
-
- for (ac->InitTraversal(); (anActor = ac->GetNextActor()); ) {
- if ( anActor->IsA("GEOM_Actor") ) {
- SALOME_Actor* SALOMEactor = SALOME_Actor::SafeDownCast(anActor);
- // Specific for GEOM actor
- if ( SALOMEactor->getDisplayMode() == 1 )
- SALOMEactor->setDisplayMode(0);
- } else {
- anActor->GetProperty()->SetRepresentationToWireframe();
- }
- }
- this->RenderWindow->Render();
- emit RenderWindowModified() ;
-}
int VTKViewer_RenderWindowInteractor::GetDisplayMode() {
- return displaymode;
-}
-
-void VTKViewer_RenderWindowInteractor::SetDisplayMode(int mode) {
- if(mode==0) ChangeRepresentationToWireframe();
- else ChangeRepresentationToSurface();
- displaymode = mode;
-}
-
-void VTKViewer_RenderWindowInteractor::SwitchRepresentation(const Handle(SALOME_InteractiveObject)& IObject,
- bool update) {
- vtkRenderer* aren;
- for (this->RenderWindow->GetRenderers()->InitTraversal();
- (aren = this->RenderWindow->GetRenderers()->GetNextItem()); ) {
- vtkActorCollection* theActors = aren->GetActors();
- theActors->InitTraversal();
- vtkActor *ac = theActors->GetNextActor();
- while(!(ac==NULL)) {
- if ( ac->IsA("SALOME_Actor") ) {
- SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( ac );
- if ( anActor->hasIO() ) {
- if ( IObject->isSame( anActor->getIO() ) ) {
- if ( anActor->IsA("GEOM_Actor") ) {
- // GEOM actor
- if ( anActor->getDisplayMode() == 0 ) anActor->setDisplayMode(1);
- else anActor->setDisplayMode(0);
- }
- else {
- if(anActor->GetProperty()->GetRepresentation() <= 1)
- anActor->GetProperty()->SetRepresentationToSurface();
- else
- anActor->GetProperty()->SetRepresentationToWireframe();
- }
- }
- }
- }
- ac = theActors->GetNextActor();
- }
- }
- if (update) {
- this->RenderWindow->Render();
- emit RenderWindowModified() ;
- }
+ return myDisplayMode;
}
+void VTKViewer_RenderWindowInteractor::SetDisplayMode(int theMode) {
+ if(theMode == 0)
+ ChangeRepresentationToWireframe();
+ else
+ ChangeRepresentationToSurface();
+ myDisplayMode = theMode;
+}
+
+
+void VTKViewer_RenderWindowInteractor::SetDisplayMode(const Handle(SALOME_InteractiveObject)& theIObject, int theMode){
+ using namespace SALOME::VTK;
+ ForEachIf<SALOME_Actor>(GetRenderer()->GetActors(),
+ TIsSameIObject<SALOME_Actor>(theIObject),
+ TSetFunction<SALOME_Actor,int>
+ (&SALOME_Actor::setDisplayMode,theMode));
+}
void VTKViewer_RenderWindowInteractor::ChangeRepresentationToWireframe()
- // change all actors to wireframe
{
- vtkActorCollection *ac;
- vtkActor *anActor, *aPart;
-
- ac = GetRenderer()->GetActors();
- ChangeRepresentationToWireframe(ac);
+ ChangeRepresentationToWireframe(GetRenderer()->GetActors());
}
+void VTKViewer_RenderWindowInteractor::ChangeRepresentationToSurface()
+{
+ ChangeRepresentationToSurface(GetRenderer()->GetActors());
+}
-void VTKViewer_RenderWindowInteractor::ChangeRepresentationToSurface(vtkActorCollection* ac)
+void VTKViewer_RenderWindowInteractor::ChangeRepresentationToWireframe(vtkActorCollection* theCollection)
{
- vtkActor *anActor, *aPart;
-
- for (ac->InitTraversal(); (anActor = ac->GetNextActor()); ) {
- if ( anActor->IsA("GEOM_Actor") ) {
- SALOME_Actor* SALOMEactor = SALOME_Actor::SafeDownCast(anActor);
- // Specific for GEOM actor
- if ( SALOMEactor->getDisplayMode() == 0 )
- SALOMEactor->setDisplayMode(1);
- } else {
- anActor->GetProperty()->SetRepresentationToSurface();
- }
- }
- this->RenderWindow->Render();
- emit RenderWindowModified() ;
+ using namespace SALOME::VTK;
+ ForEach<SALOME_Actor>(theCollection,
+ TSetFunction<SALOME_Actor,int>
+ (&SALOME_Actor::setDisplayMode,0));
+ emit RenderWindowModified();
}
-void VTKViewer_RenderWindowInteractor::ChangeRepresentationToSurface()
- // change all actors to "surface" or solid
+void VTKViewer_RenderWindowInteractor::ChangeRepresentationToSurface(vtkActorCollection* theCollection)
{
- vtkActorCollection *ac;
- vtkActor *anActor, *aPart;
-
- ac = GetRenderer()->GetActors();
- ChangeRepresentationToSurface(ac);
+ using namespace SALOME::VTK;
+ ForEach<SALOME_Actor>(theCollection,
+ TSetFunction<SALOME_Actor,int>
+ (&SALOME_Actor::setDisplayMode,1));
+ emit RenderWindowModified();
}
+
vtkRenderer* VTKViewer_RenderWindowInteractor::GetRenderer()
{
vtkRendererCollection * theRenderers = this->RenderWindow->GetRenderers();
return theRenderers->GetNextItem();
}
+
+struct TErase{
+ SALOME::VTK::TSetFunction<vtkActor,int> mySetFunction;
+ TErase():
+ mySetFunction(&vtkActor::SetVisibility,false)
+ {}
+ void operator()(SALOME_Actor* theActor){
+ theActor->SetVisibility(false);
+ // Erase dependent actors
+ vtkActorCollection* aCollection = vtkActorCollection::New();
+ theActor->GetChildActors(aCollection);
+ SALOME::VTK::ForEach<vtkActor>(aCollection,mySetFunction);
+ aCollection->Delete();
+ }
+};
+
void VTKViewer_RenderWindowInteractor::EraseAll()
{
- vtkActorCollection *ac;
- vtkActor *anActor, *aPart;
-
- ac = GetRenderer()->GetActors();
- for (ac->InitTraversal(); (anActor = ac->GetNextActor()); ) {
- if ( anActor->IsA("SALOME_Actor") ) {
- SALOME_Actor* SActor = SALOME_Actor::SafeDownCast( anActor );
- SActor->SetVisibility(false);
- }
- }
+ using namespace SALOME::VTK;
+ ForEach<SALOME_Actor>(GetRenderer()->GetActors(),
+ TErase());
+
emit RenderWindowModified() ;
}
void VTKViewer_RenderWindowInteractor::DisplayAll()
-{
- vtkActorCollection *ac;
- vtkActor *anActor, *aPart;
-
- ac = GetRenderer()->GetActors();
- for (ac->InitTraversal(); (anActor = ac->GetNextActor()); ) {
- if ( anActor->IsA("SALOME_Actor") ) {
- SALOME_Actor* SActor = SALOME_Actor::SafeDownCast( anActor );
- SActor->SetVisibility( true );
- }
- }
+{
+ vtkActorCollection* aCollection = GetRenderer()->GetActors();
+ using namespace SALOME::VTK;
+ ForEach<SALOME_Actor>(aCollection,TSetVisibility<SALOME_Actor>(true));
+
emit RenderWindowModified() ;
}
-void VTKViewer_RenderWindowInteractor::Erase(const Handle(SALOME_InteractiveObject)& IObject, bool update)
+
+void VTKViewer_RenderWindowInteractor::Erase(SALOME_Actor* theActor, bool update)
{
- vtkRenderer* aren;
- for (this->RenderWindow->GetRenderers()->InitTraversal();
- (aren = this->RenderWindow->GetRenderers()->GetNextItem()); ) {
- vtkActorCollection* theActors = aren->GetActors();
- vtkActorCollection* theChildActors = vtkActorCollection::New();
- theActors->InitTraversal();
- vtkActor *ac = theActors->GetNextActor();
- while(!(ac==NULL)) {
- if ( ac->IsA("SALOME_Actor") ) {
- SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( ac );
- if ( anActor->hasIO() ) {
- if ( IObject->isSame( anActor->getIO() ) ) {
- anActor->SetVisibility( false );
- anActor->GetChildActors(theChildActors);
- }
- }
- }
- ac = theActors->GetNextActor();
- }
+ TErase()(theActor);
- // Erase dependent actors
- theChildActors->InitTraversal();
- ac = theChildActors->GetNextActor();
- while(!(ac==NULL)) {
- ac->SetVisibility( false );
- ac = theChildActors->GetNextActor();
- }
- }
- if (update)
- emit RenderWindowModified() ;
+ if(update)
+ emit RenderWindowModified();
}
-void VTKViewer_RenderWindowInteractor::Remove(const Handle(SALOME_InteractiveObject)& IObject, bool update)
+
+void VTKViewer_RenderWindowInteractor::Erase(const Handle(SALOME_InteractiveObject)& theIObject, bool update)
{
- vtkRenderer* aren;
- for (this->RenderWindow->GetRenderers()->InitTraversal();
- (aren = this->RenderWindow->GetRenderers()->GetNextItem()); ) {
- vtkActorCollection* theActors = aren->GetActors();
- theActors->InitTraversal();
- vtkActor *ac = theActors->GetNextActor();
- while(!(ac==NULL)) {
- if ( ac->IsA("SALOME_Actor") ) {
- SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( ac );
- if ( anActor->hasIO() ) {
- if ( IObject->isSame( anActor->getIO() ) ) {
- aren->RemoveActor(anActor);
- }
- }
- }
- ac = theActors->GetNextActor();
- }
- }
- if (update)
- emit RenderWindowModified() ;
-}
+ using namespace SALOME::VTK;
+ ForEachIf<SALOME_Actor>(GetRenderer()->GetActors(),
+ TIsSameIObject<SALOME_Actor>(theIObject),
+ TErase());
-float VTKViewer_RenderWindowInteractor::GetTransparency(const Handle(SALOME_InteractiveObject)& IObject) {
- vtkRenderer* aren;
- for (this->RenderWindow->GetRenderers()->InitTraversal();
- (aren = this->RenderWindow->GetRenderers()->GetNextItem()); ) {
- vtkActorCollection* theActors = aren->GetActors();
- theActors->InitTraversal();
- vtkActor *ac = theActors->GetNextActor();
- while(!(ac==NULL)) {
- if ( ac->IsA("SALOME_Actor") ) {
- SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( ac );
- if ( anActor->hasIO() ) {
- if ( IObject->isSame( anActor->getIO() ) ) {
- if ( anActor->IsA("GEOM_Actor") ) {
- // GEOM actor
- return (1-(anActor->GetOpacity()));
- }
- else return (1-anActor->GetProperty()->GetOpacity());
- }
- }
- }
- ac = theActors->GetNextActor();
- }
- }
- return -1;
-}
-
-void VTKViewer_RenderWindowInteractor::SetTransparency(const Handle(SALOME_InteractiveObject)& IObject, float trans) {
- vtkRenderer* aren;
- for (this->RenderWindow->GetRenderers()->InitTraversal();
- (aren = this->RenderWindow->GetRenderers()->GetNextItem()); ) {
- vtkActorCollection* theActors = aren->GetActors();
- theActors->InitTraversal();
- vtkActor *ac = theActors->GetNextActor();
- while(!(ac==NULL)) {
- if ( ac->IsA("SALOME_Actor") ) {
- SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( ac );
- if ( anActor->hasIO() ) {
- if ( IObject->isSame( anActor->getIO() ) ) {
- if ( anActor->IsA("GEOM_Actor") ) {
- // GEOM actor
- anActor->SetOpacity(1-trans);
- }
- else anActor->GetProperty()->SetOpacity(1-trans);
- }
- }
- }
- ac = theActors->GetNextActor();
- }
- }
+ if(update)
+ emit RenderWindowModified();
}
-void VTKViewer_RenderWindowInteractor::Display( SALOME_Actor* SActor, bool update)
-{
- vtkRenderer* aren;
- for (this->RenderWindow->GetRenderers()->InitTraversal();
- (aren = this->RenderWindow->GetRenderers()->GetNextItem()); ) {
- aren->AddActor( SActor );
- SActor->SetVisibility( true );
+
+struct TRemoveAction{
+ vtkRenderer* myRen;
+ TRemoveAction(vtkRenderer* theRen): myRen(theRen){}
+ void operator()(SALOME_Actor* theActor){
+ myRen->RemoveActor(theActor);
}
+};
- if (update) {
- Render();
- emit RenderWindowModified();
+void VTKViewer_RenderWindowInteractor::Remove(const Handle(SALOME_InteractiveObject)& theIObject, bool update)
+{
+ vtkRenderer* aRen = GetRenderer();
+
+ using namespace SALOME::VTK;
+ ForEachIf<SALOME_Actor>(aRen->GetActors(),
+ TIsSameIObject<SALOME_Actor>(theIObject),
+ TRemoveAction(aRen));
+
+
+}
+
+void VTKViewer_RenderWindowInteractor::Remove( SALOME_Actor* SActor, bool updateViewer )
+{
+ if ( SActor != 0 )
+ {
+ GetRenderer()->RemoveProp( SActor );
+ if ( updateViewer )
+ emit RenderWindowModified();
}
}
-void VTKViewer_RenderWindowInteractor::Display(const Handle(SALOME_InteractiveObject)& IObject, bool update)
+void VTKViewer_RenderWindowInteractor::RemoveAll( const bool updateViewer )
{
- Standard_Boolean isalreadydisplayed = false;
-
- vtkRenderer* aren;
- for (this->RenderWindow->GetRenderers()->InitTraversal();
- (aren = this->RenderWindow->GetRenderers()->GetNextItem()); ) {
- vtkActorCollection* theActors = aren->GetActors();
- theActors->InitTraversal();
- vtkActor *ac = theActors->GetNextActor();
- while(!(ac==NULL)) {
- if ( ac->IsA("SALOME_Actor") ) {
- SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( ac );
- if ( anActor->hasIO() ) {
- if ( IObject->isSame( anActor->getIO() ) ) {
- anActor->SetVisibility( true );
- }
- }
+ vtkRenderer* aRenderer = GetRenderer();
+ vtkActorCollection* anActors = aRenderer->GetActors();
+ if ( anActors )
+ {
+ anActors->InitTraversal();
+ while ( vtkActor *anAct = anActors->GetNextActor() )
+ {
+ if ( anAct->IsA( "SALOME_Actor" ) )
+ {
+ SALOME_Actor* aSAct = (SALOME_Actor*)anAct;
+ if ( aSAct->hasIO() && aSAct->getIO()->hasEntry() )
+ aRenderer->RemoveActor( anAct );
}
- ac = theActors->GetNextActor();
}
+
+ if ( updateViewer )
+ emit RenderWindowModified();
}
- if (update)
- emit RenderWindowModified() ;
}
-void VTKViewer_RenderWindowInteractor::KeyPressed(QKeyEvent *event) {
-// MESSAGE ( " vtkQGLRenderWindowInteractor::KeyPressed " )
-// if (!QAD_Application::getDesktop()->getActiveComponent().isEmpty()) {
-// QAD_Application::getDesktop()->onKeyPress( event );
-// }
+float VTKViewer_RenderWindowInteractor::GetTransparency(const Handle(SALOME_InteractiveObject)& theIObject)
+{
+ using namespace SALOME::VTK;
+ SALOME_Actor* anActor =
+ Find<SALOME_Actor>(GetRenderer()->GetActors(),
+ TIsSameIObject<SALOME_Actor>(theIObject));
+ if(anActor)
+ return 1.0 - anActor->GetOpacity();
+ return -1.0;
+}
+
+
+void VTKViewer_RenderWindowInteractor::SetTransparency(const Handle(SALOME_InteractiveObject)& theIObject, float theTrans)
+{
+ float anOpacity = 1.0 - theTrans;
+ using namespace SALOME::VTK;
+ ForEachIf<SALOME_Actor>(GetRenderer()->GetActors(),
+ TIsSameIObject<SALOME_Actor>(theIObject),
+ TSetFunction<SALOME_Actor,float>
+ (&SALOME_Actor::SetOpacity,anOpacity));
}
-bool VTKViewer_RenderWindowInteractor::highlight( const Handle(SALOME_InteractiveObject)& IObject,
- bool hilight,
- bool update)
+
+void VTKViewer_RenderWindowInteractor::Display(SALOME_Actor* theActor, bool update)
{
- vtkRenderer* aren;
- for (this->RenderWindow->GetRenderers()->InitTraversal();
- (aren = this->RenderWindow->GetRenderers()->GetNextItem()); ) {
- vtkActorCollection* theActors = aren->GetActors();
- theActors->InitTraversal();
- vtkActor *ac = theActors->GetNextActor();
- while(!(ac==NULL)) {
- if ( ac->IsA("SALOME_Actor") ) {
- SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( ac );
- if ( anActor->hasIO() ) {
- if ( IObject->isSame( anActor->getIO() ) ) {
- if ( anActor->GetMapper() == NULL ) {
- return false;
- }
- //highlight or unhilight actors
- if ( anActor->hasHighlight() ) {
- anActor->highlight(hilight);
- } else {
- if ( anActor->GetVisibility() == 1 ) {
- if (hilight) {
- vtkActor2D *actor2D;
- vtkProp3D *prop3D;
- if ( (prop3D=vtkProp3D::SafeDownCast(anActor)) != NULL ) {
- this->InteractorStyle->HighlightProp3D(prop3D);
- } else if ( (actor2D=vtkActor2D::SafeDownCast(anActor)) != NULL ) {
- this->InteractorStyle->HighlightActor2D(actor2D);
- }
- //this->InteractorStyle->HighlightProp(anActor);
- } else {
- this->InteractorStyle->HighlightProp3D(NULL);
- this->InteractorStyle->HighlightActor2D(NULL);
- //this->InteractorStyle->HighlightProp(NULL);
- }
- }
- }
- }
- }
+ GetRenderer()->AddActor(theActor);
+ theActor->SetVisibility(true);
+
+ if(update)
+ emit RenderWindowModified();
+}
+
+
+void VTKViewer_RenderWindowInteractor::Display(const Handle(SALOME_InteractiveObject)& theIObject, bool update)
+{
+ using namespace SALOME::VTK;
+ ForEachIf<SALOME_Actor>(GetRenderer()->GetActors(),
+ TIsSameIObject<SALOME_Actor>(theIObject),
+ TSetVisibility<SALOME_Actor>(true));
+
+ if(update)
+ emit RenderWindowModified() ;
+}
+
+
+void VTKViewer_RenderWindowInteractor::KeyPressed(QKeyEvent *event){}
+
+
+struct THighlightAction{
+ bool myIsHighlight;
+ VTKViewer_InteractorStyleSALOME* myInteractorStyle;
+ THighlightAction(VTKViewer_InteractorStyleSALOME* 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);
}
- ac = theActors->GetNextActor();
}
}
- if (update) {
- Render();
+};
+
+bool VTKViewer_RenderWindowInteractor::highlight( const Handle(SALOME_InteractiveObject)& theIObject,
+ bool hilight,
+ bool update)
+{
+ using namespace SALOME::VTK;
+ ForEachIf<SALOME_Actor>(GetRenderer()->GetActors(),
+ TIsSameIObject<SALOME_Actor>(theIObject),
+ THighlightAction(myInteractorStyle,hilight));
+
+ if(update)
emit RenderWindowModified();
- }
return false;
}
-void VTKViewer_RenderWindowInteractor::Update() {
- vtkRenderer* aren;
- for (this->RenderWindow->GetRenderers()->InitTraversal();
- (aren = this->RenderWindow->GetRenderers()->GetNextItem()); ) {
- vtkActorCollection* theActors = aren->GetActors();
- theActors->InitTraversal();
- vtkActor *ac = theActors->GetNextActor();
-
- while(!(ac==NULL)) {
- ac->ApplyProperties();
- ac->Update();
- ac = theActors->GetNextActor();
- }
- aren->ResetCamera();
- emit RenderWindowModified() ;
+
+struct TUpdateAction{
+ void operator()(vtkActor* theActor){
+ theActor->ApplyProperties();
}
+};
+
+void VTKViewer_RenderWindowInteractor::Update() {
+ vtkRenderer* aRen = GetRenderer();
+
+ using namespace SALOME::VTK;
+ ForEach<vtkActor>(aRen->GetActors(),TUpdateAction());
+
+ aRen->ResetCamera();
+
+ emit RenderWindowModified();
}
-bool VTKViewer_RenderWindowInteractor::unHighlightAll()
-{
- vtkRenderer* aren;
- for (this->RenderWindow->GetRenderers()->InitTraversal();
- (aren = this->RenderWindow->GetRenderers()->GetNextItem()); ) {
- vtkActorCollection* theActors = aren->GetActors();
- theActors->InitTraversal();
-
- if ( theActors->IsItemPresent(Point_Actor) != 0 )
- aren->RemoveActor( Point_Actor );
- if ( theActors->IsItemPresent( Edge_Actor ) != 0 )
- aren->RemoveActor( Edge_Actor );
- if ( theActors->IsItemPresent( Cell_Actor ) != 0 )
- aren->RemoveActor( Cell_Actor );
-
- vtkActor *ac = theActors->GetNextActor();
-
- while(!(ac==NULL)) {
- if ( ac->IsA("SALOME_Actor") ) {
- SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( ac );
- if ( anActor->hasIO() ) {
- //highlight or unhilight actors
- if ( anActor->hasHighlight() )
- anActor->highlight(false);
- }
- }
- ac = theActors->GetNextActor();
+void VTKViewer_RenderWindowInteractor::unHighlightSubSelection(){
+ myPointActor->SetVisibility(false);
+ myEdgeActor->SetVisibility(false);
+ myCellActor->SetVisibility(false);
+}
+
+
+struct TUnHighlightAllAction{
+ void operator()(SALOME_Actor* theActor){
+ if(theActor->hasIO()){
+ if(theActor->hasHighlight())
+ theActor->highlight(false);
}
}
+};
+
+bool VTKViewer_RenderWindowInteractor::unHighlightAll(){
+ unHighlightSubSelection();
+
+ using namespace SALOME::VTK;
+ ForEach<SALOME_Actor>(GetRenderer()->GetActors(),
+ TUnHighlightAllAction());
emit RenderWindowModified() ;
return false;
// Color methods
//-----------------
-void VTKViewer_RenderWindowInteractor::SetColor(const Handle(SALOME_InteractiveObject)& IObject,QColor thecolor) {
- vtkRenderer* aren;
- for (this->RenderWindow->GetRenderers()->InitTraversal();
- (aren = this->RenderWindow->GetRenderers()->GetNextItem()); ) {
- vtkActorCollection* theActors = aren->GetActors();
- theActors->InitTraversal();
- vtkActor *ac = theActors->GetNextActor();
- while(!(ac==NULL)) {
- if ( ac->IsA("SALOME_Actor") ) {
- SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( ac );
- if ( anActor->hasIO() ) {
- if ( IObject->isSame( anActor->getIO() ) ) {
- if ( anActor->IsA("GEOM_Actor") ) {
- // GEOM actor
- anActor->SetColor(float(thecolor.red())/255,float(thecolor.green())/255,float(thecolor.blue())/255);
- }
- else {
- anActor->GetProperty()->SetColor(float(thecolor.red())/255,float(thecolor.green())/255,float(thecolor.blue())/255);
- }
- }
- }
- }
- ac = theActors->GetNextActor();
- }
- }
-}
-
-QColor VTKViewer_RenderWindowInteractor::GetColor(const Handle(SALOME_InteractiveObject)& IObject) {
- vtkRenderer* aren;
- QColor emptycolor(0,0,0);
- for (this->RenderWindow->GetRenderers()->InitTraversal();
- (aren = this->RenderWindow->GetRenderers()->GetNextItem()); ) {
- vtkActorCollection* theActors = aren->GetActors();
- theActors->InitTraversal();
- vtkActor *ac = theActors->GetNextActor();
- while(!(ac==NULL)) {
- if ( ac->IsA("SALOME_Actor") ) {
- SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( ac );
- if ( anActor->hasIO() ) {
- if ( IObject->isSame( anActor->getIO() ) ) {
- if ( anActor->IsA("GEOM_Actor") ) {
- // GEOM actor
- float r,g,b;
- anActor->GetColor(r,g,b);
- return QColor(r*255,g*255,b*255);
- }
- else {
- float color[3];
- anActor->GetProperty()->GetColor(color);
- return QColor(color[0]*255,color[1]*255,color[2]*255);
- }
- }
- }
- }
- ac = theActors->GetNextActor();
- }
- }
- return emptycolor;
+void VTKViewer_RenderWindowInteractor::SetColor(const Handle(SALOME_InteractiveObject)& theIObject,QColor theColor)
+{
+ float aColor[3] = {theColor.red()/255., theColor.green()/255., theColor.blue()/255.};
+ using namespace SALOME::VTK;
+ ForEachIf<SALOME_Actor>(GetRenderer()->GetActors(),
+ TIsSameIObject<SALOME_Actor>(theIObject),
+ TSetFunction<SALOME_Actor,const float*>
+ (&SALOME_Actor::SetColor,aColor));
}
-
-
-bool VTKViewer_RenderWindowInteractor::isInViewer(const Handle(SALOME_InteractiveObject)& IObject)
+QColor VTKViewer_RenderWindowInteractor::GetColor(const Handle(SALOME_InteractiveObject)& theIObject)
{
- vtkRenderer* aren;
- for (this->RenderWindow->GetRenderers()->InitTraversal();
- (aren = this->RenderWindow->GetRenderers()->GetNextItem()); ) {
- vtkActorCollection* theActors = aren->GetActors();
- theActors->InitTraversal();
- vtkActor *ac = theActors->GetNextActor();
- while(!(ac==NULL)) {
- if ( ac->IsA("SALOME_Actor") ) {
- SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( ac );
- if ( anActor->hasIO() ) {
- if ( IObject->isSame( anActor->getIO() ) ) {
- //MESSAGE ( " VTKViewer_RenderWindowInteractor::isInViewer = TRUE" )
- return true;
- }
- }
- }
- ac = theActors->GetNextActor();
- }
+ using namespace SALOME::VTK;
+ SALOME_Actor* anActor =
+ Find<SALOME_Actor>(GetRenderer()->GetActors(),
+ TIsSameIObject<SALOME_Actor>(theIObject));
+ if(anActor){
+ float r,g,b;
+ anActor->GetColor(r,g,b);
+ return QColor(int(r*255),int(g*255),int(b*255));
}
- //MESSAGE ( " VTKViewer_RenderWindowInteractor::isInViewer = FALSE" )
- return false;
+ return QColor(0,0,0);
}
-bool VTKViewer_RenderWindowInteractor::isVisible(const Handle(SALOME_InteractiveObject)& IObject)
+
+bool VTKViewer_RenderWindowInteractor::isInViewer(const Handle(SALOME_InteractiveObject)& theIObject)
{
- vtkRenderer* aren;
- for (this->RenderWindow->GetRenderers()->InitTraversal();
- (aren = this->RenderWindow->GetRenderers()->GetNextItem()); ) {
- vtkActorCollection* theActors = aren->GetActors();
- theActors->InitTraversal();
- vtkActor *ac = theActors->GetNextActor();
- while(!(ac==NULL)) {
- if ( ac->IsA("SALOME_Actor") ) {
- SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( ac );
- if ( anActor->hasIO() ) {
- if ( IObject->isSame( anActor->getIO() ) ) {
- return anActor->GetVisibility();
- }
- }
- }
- ac = theActors->GetNextActor();
- }
- }
- return false;
+ using namespace SALOME::VTK;
+ SALOME_Actor* anActor =
+ Find<SALOME_Actor>(GetRenderer()->GetActors(),
+ TIsSameIObject<SALOME_Actor>(theIObject));
+ return anActor != NULL;
}
-void VTKViewer_RenderWindowInteractor::rename(const Handle(SALOME_InteractiveObject)& IObject, QString newName)
+
+bool VTKViewer_RenderWindowInteractor::isVisible(const Handle(SALOME_InteractiveObject)& theIObject)
{
- vtkRenderer* aren;
- for (this->RenderWindow->GetRenderers()->InitTraversal();
- (aren = this->RenderWindow->GetRenderers()->GetNextItem()); ) {
- vtkActorCollection* theActors = aren->GetActors();
- theActors->InitTraversal();
- vtkActor *ac = theActors->GetNextActor();
- while(!(ac==NULL)) {
- if ( ac->IsA("SALOME_Actor") ) {
- SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( ac );
- if ( anActor->hasIO() ) {
- if ( IObject->isSame( anActor->getIO() ) ) {
- anActor->setName(strdup(newName));
- }
- }
- }
- ac = theActors->GetNextActor();
- }
- }
+ using namespace SALOME::VTK;
+ SALOME_Actor* anActor =
+ Find<SALOME_Actor>(GetRenderer()->GetActors(),
+ TIsSameIObject<SALOME_Actor>(theIObject));
+ return anActor != NULL && anActor->GetVisibility();
+}
- emit RenderWindowModified() ;
+
+void VTKViewer_RenderWindowInteractor::rename(const Handle(SALOME_InteractiveObject)& theIObject, QString theName)
+{
+ using namespace SALOME::VTK;
+ ForEachIf<SALOME_Actor>(GetRenderer()->GetActors(),
+ TIsSameIObject<SALOME_Actor>(theIObject),
+ TSetFunction<SALOME_Actor,const char*,QString>
+ (&SALOME_Actor::setName,theName.latin1()));
}
-bool VTKViewer_RenderWindowInteractor::highlightCell( const Handle(SALOME_InteractiveObject)& IObject,
- bool hilight,
- const TColStd_MapOfInteger& MapIndex,
- bool update )
+
+//----------------------------------------------------------------------------
+bool VTKViewer_RenderWindowInteractor::highlight(const TColStd_IndexedMapOfInteger& theMapIndex,
+ SALOME_Actor* theMapActor, VTKViewer_Actor* theActor,
+ TUpdateActor theFun, bool hilight, bool update)
{
- vtkRenderer* aren;
- for (this->RenderWindow->GetRenderers()->InitTraversal();
- (aren = this->RenderWindow->GetRenderers()->GetNextItem()); ) {
- vtkActorCollection* theActors = aren->GetActors();
-
- if ( theActors->IsItemPresent(Cell_Actor) != 0 )
- aren->RemoveActor( Cell_Actor );
-
- theActors->InitTraversal();
- vtkActor *ac = theActors->GetNextActor();
- for ( ; ac; ac = theActors->GetNextActor() ) {
- if ( ac->IsA("SALOME_Actor") ) {
- SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( ac );
- if ( anActor->hasIO() ) {
- if ( IObject->isSame( anActor->getIO() ) ) {
- vtkUnstructuredGrid* Cell_UGrid = vtkUnstructuredGrid::New();
- vtkUnstructuredGrid* UGrid = vtkUnstructuredGrid::SafeDownCast( ac->GetMapper()->GetInput() );
- if (UGrid == 0) break;
- vtkIdList *ptIds = vtkIdList::New(); ptIds->Allocate(12);
- vtkDataSetMapper* Cell_Mapper = vtkDataSetMapper::New();
- Cell_UGrid->SetPoints( UGrid->GetPoints() );
- TColStd_MapIteratorOfMapOfInteger ite( MapIndex );
- for ( ; ite.More(); ite.Next() ) {
- UGrid->GetCellPoints( ite.Key(), ptIds );
- Cell_UGrid->InsertNextCell(ac->GetMapper()->GetInput()->GetCellType( ite.Key() ), ptIds);
- }
-
-
- Cell_Mapper->SetInput(Cell_UGrid);
- Cell_Actor->SetMapper(Cell_Mapper);
-
- if ( theActors->IsItemPresent(Cell_Actor) == 0 )
- aren->AddActor( Cell_Actor );
-
- if ( hilight )
- Cell_Actor->VisibilityOn();
- else
- Cell_Actor->VisibilityOff();
- break;
- }
- }
- }
- }
+ if(theMapIndex.Extent() == 0) return false;
+
+ if (hilight) {
+ setActorData(theMapIndex,theMapActor,theActor,theFun);
+ theActor->SetVisibility(true);
+ }
+ else {
+ theActor->SetVisibility(false);
}
- if (update) {
+
+ if(update){
this->RenderWindow->Render();
emit RenderWindowModified() ;
}
- return 0;
-}
-bool VTKViewer_RenderWindowInteractor::highlightEdge( const Handle(SALOME_InteractiveObject)& IObject,
- bool hilight,
- const TColStd_MapOfInteger& MapIndex,
- bool update )
+ return false;
+}
+
+void VTKViewer_RenderWindowInteractor::setActorData(const TColStd_IndexedMapOfInteger& theMapIndex,
+ SALOME_Actor* theMapActor,
+ VTKViewer_Actor *theActor,
+ TUpdateActor theFun)
{
- vtkRenderer* aren;
- for (this->RenderWindow->GetRenderers()->InitTraversal();
- (aren = this->RenderWindow->GetRenderers()->GetNextItem()); ) {
- vtkActorCollection* theActors = aren->GetActors();
- theActors->InitTraversal();
- vtkActor *ac = theActors->GetNextActor();
- for( ; ac; ac = theActors->GetNextActor() ) {
- if ( ac->IsA("SALOME_Actor") ) {
- SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( ac );
- if ( anActor->hasIO() ) {
- if ( IObject->isSame( anActor->getIO() ) ) {
-
- vtkUnstructuredGrid* Edge_UGrid = vtkUnstructuredGrid::New();
- vtkUnstructuredGrid* UGrid = vtkUnstructuredGrid::SafeDownCast( ac->GetMapper()->GetInput() );
- if (UGrid == 0) break;
-
- vtkDataSetMapper* Edge_Mapper = vtkDataSetMapper::New();
- vtkCell* pickedCell;
- vtkCell* pickedEdge;
- int cellId, edgeId;
- Edge_UGrid->SetPoints( UGrid->GetPoints() );
- TColStd_MapIteratorOfMapOfInteger ite( MapIndex );
- int numberOfIndexes = MapIndex.Extent();
- int i, j, npts, *pts, aLen;
-
- if ( theActors->IsItemPresent(Cell_Actor) != 0 ) {
- Cell_Actor->VisibilityOff();
- if ( theActors->IsItemPresent(Edge_Actor) != 0 ) {
- vtkUnstructuredGrid* EdgeGrid = vtkUnstructuredGrid::SafeDownCast( Edge_Actor->GetMapper()->GetInput() );
- if (EdgeGrid) {
- aLen = EdgeGrid->GetNumberOfCells();
- //SRN: modified traversal of edge cells.
- vtkCellArray* cells = EdgeGrid->GetCells();
- for (i=0, cells->InitTraversal(); cells->GetNextCell(npts,pts); i++) {
- if(MapIndex.Contains(i))
- Edge_UGrid->InsertNextCell(VTK_LINE, npts, pts);
- }
- }
- }
- vtkUnstructuredGrid* CellGrid = vtkUnstructuredGrid::SafeDownCast( Cell_Actor->GetMapper()->GetInput() );
-
- bool isOneEdge = (MapIndex.Extent() <= 2);
- int edgeId;
-
- //SRN: modified finding the selected edges
- if (CellGrid) {
- aLen = CellGrid->GetNumberOfCells();
- for (i=0; i<aLen; i++) {
- pickedCell = CellGrid->GetCell(i);
- int aLen2 = pickedCell->GetNumberOfEdges();
- for(j=0; j<aLen2; j++) {
- edgeId = (isOneEdge)?(-j):j;
- if(MapIndex.Contains(edgeId)) {
- pickedEdge = pickedCell->GetEdge(j);
- Edge_UGrid->InsertNextCell(pickedEdge->GetCellType(), pickedEdge->GetPointIds());
- }
- }
- }
- }
-
- Edge_Mapper->SetInput(Edge_UGrid);
- Edge_Actor->SetMapper(Edge_Mapper);
-
- if ( theActors->IsItemPresent(Edge_Actor) == 0 )
- aren->AddActor( Edge_Actor );
-
- if ( hilight )
- Edge_Actor->VisibilityOn();
- else
- Edge_Actor->VisibilityOff();
- }
-
- break;
- }
- }
- }
- }
- }
+ (*theFun)(theMapIndex,theMapActor,theActor);
+ float aPos[3];
+ theMapActor->GetPosition(aPos);
+ theActor->SetPosition(aPos);
+}
- if (update) {
- this->RenderWindow->Render();
- emit RenderWindowModified();
- }
- return 0;
+//----------------------------------------------------------------------------
+static void CellsUpdateActor(const TColStd_IndexedMapOfInteger& theMapIndex,
+ SALOME_Actor* theMapActor,
+ VTKViewer_Actor* theActor)
+{
+ theActor->MapCells(theMapActor,theMapIndex);
}
+
+bool VTKViewer_RenderWindowInteractor::highlightCell(const TColStd_IndexedMapOfInteger& theMapIndex,
+ SALOME_Actor* theMapActor,
+ bool hilight,
+ bool update)
+{
+ return highlight(theMapIndex,theMapActor,myCellActor,&CellsUpdateActor,hilight,update);
+}
+
+void VTKViewer_RenderWindowInteractor::setCellData(const int& theIndex,
+ SALOME_Actor* theMapActor,
+ VTKViewer_Actor* theActor)
+{
+ TColStd_IndexedMapOfInteger MapIndex;
+ MapIndex.Add(theIndex);
+ theActor->MapCells(theMapActor,MapIndex);
+}
+
-bool VTKViewer_RenderWindowInteractor::highlightPoint(const Handle(SALOME_InteractiveObject)& IObject,
- bool hilight, const TColStd_MapOfInteger& MapIndex,
+//----------------------------------------------------------------------------
+static void PointsUpdateActor(const TColStd_IndexedMapOfInteger& theMapIndex,
+ SALOME_Actor* theMapActor,
+ VTKViewer_Actor* theActor)
+{
+ theActor->MapPoints(theMapActor,theMapIndex);
+}
+
+bool VTKViewer_RenderWindowInteractor::highlightPoint(const TColStd_IndexedMapOfInteger& theMapIndex,
+ SALOME_Actor* theMapActor,
+ bool hilight,
bool update)
{
- vtkRenderer* aren;
- for (this->RenderWindow->GetRenderers()->InitTraversal();
- (aren = this->RenderWindow->GetRenderers()->GetNextItem()); ) {
- vtkActorCollection* theActors = aren->GetActors();
-
- if ( theActors->IsItemPresent(Point_Actor) != 0 )
- aren->RemoveActor( Point_Actor );
-
- theActors->InitTraversal();
- vtkActor *ac = theActors->GetNextActor();
- for ( ; ac; ac = theActors->GetNextActor() ) {
- if ( ac->IsA("SALOME_Actor") ) {
- SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( ac );
- if ( anActor->hasIO() ) {
- if ( IObject->isSame( anActor->getIO() ) ) {
- vtkUnstructuredGrid* UGrid = vtkUnstructuredGrid::SafeDownCast( ac->GetMapper()->GetInput() );
- if (UGrid == 0) break;
- vtkUnstructuredGrid* Point_UGrid = vtkUnstructuredGrid::New();
- float pts[3];
-
- vtkPoints *Points = vtkPoints::New();
- vtkMaskPoints* verts = vtkMaskPoints::New();
- vtkPolyDataMapper* vertMapper = vtkPolyDataMapper::New();
-
- TColStd_MapIteratorOfMapOfInteger ite( MapIndex );
- int i = 0;
- // Points->SetNumberOfPoints( MapIndex.Extent() );
- if ( MapIndex.Extent() == 1 )
- Points->SetNumberOfPoints( MapIndex.Extent() + 1 );
- else
- Points->SetNumberOfPoints( MapIndex.Extent() );
-
- for ( ; ite.More(); ite.Next() ) {
- UGrid->GetPoint( ite.Key(), pts) ;
- Points->SetPoint(i, pts );
- i++;
- // DEBUG : it's not possible to see only one point !!!!
- if ( MapIndex.Extent() == 1 )
- Points->SetPoint(i, 0., 0., 0. );
- }
-
- Point_UGrid->SetPoints(Points);
- verts->SetInput(Point_UGrid);
- verts->SetGenerateVertices(1);
- verts->SetOnRatio(1);
- vertMapper->SetInput(verts->GetOutput());
- Point_Actor->SetMapper(vertMapper);
-
- if ( theActors->IsItemPresent(Point_Actor) == 0 ) {
- aren->AddActor( Point_Actor );
- }
-
- if ( hilight )
- Point_Actor->VisibilityOn();
- else
- Point_Actor->VisibilityOff();
-
- break;
- }
- }
- }
- }
- }
+ return highlight(theMapIndex,theMapActor,myPointActor,&PointsUpdateActor,hilight,update);
+}
- if (update) {
- this->RenderWindow->Render();
- emit RenderWindowModified();
- }
- return 0;
+void VTKViewer_RenderWindowInteractor::setPointData(const int& theIndex,
+ SALOME_Actor* theMapActor,
+ VTKViewer_Actor* theActor)
+{
+ TColStd_IndexedMapOfInteger MapIndex;
+ MapIndex.Add(theIndex);
+ theActor->MapPoints(theMapActor,MapIndex);
+}
+
+
+//----------------------------------------------------------------------------
+static void EdgesUpdateActor(const TColStd_IndexedMapOfInteger& theMapIndex,
+ SALOME_Actor* theMapActor,
+ VTKViewer_Actor* theActor)
+{
+ theActor->MapEdge(theMapActor,theMapIndex);
+}
+
+bool VTKViewer_RenderWindowInteractor::highlightEdge(const TColStd_IndexedMapOfInteger& theMapIndex,
+ SALOME_Actor* theMapActor,
+ bool hilight,
+ bool update)
+{
+ return highlight(theMapIndex,theMapActor,myEdgeActor,&EdgesUpdateActor,hilight,update);
+}
+
+void VTKViewer_RenderWindowInteractor::setEdgeData(const int& theCellIndex,
+ SALOME_Actor* theMapActor,
+ const int& theEdgeIndex,
+ VTKViewer_Actor* theActor )
+{
+ TColStd_IndexedMapOfInteger MapIndex;
+ MapIndex.Add(theCellIndex);
+ MapIndex.Add(theEdgeIndex);
+ theActor->MapEdge(theMapActor,MapIndex);
}