1 // SALOME VTKViewer : build VTK viewer into Salome desktop
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : VTKViewer_RenderWindowInteractor.cxx
25 // Author : Nicolas REJNERI
29 #include "VTKViewer_RenderWindowInteractor.h"
31 #include "VTKViewer_InteractorStyleSALOME.h"
32 #include "VTKViewer_RenderWindow.h"
33 #include "VTKViewer_ViewFrame.h"
35 #include "VTKViewer_Algorithm.h"
36 #include "VTKViewer_Functor.h"
38 #include "QAD_Application.h"
39 #include "QAD_Desktop.h"
41 #include "VTKViewer_Actor.h"
49 #include <vtkObjectFactory.h>
50 #include <vtkPicker.h>
51 #include <vtkCellPicker.h>
52 #include <vtkPointPicker.h>
53 #include <vtkRendererCollection.h>
58 #include <TColStd_IndexedMapOfInteger.hxx>
60 #include "utilities.h"
65 static int MYDEBUG = 0;
67 static int MYDEBUG = 0;
71 VTKViewer_RenderWindowInteractor* VTKViewer_RenderWindowInteractor::New() {
72 vtkObject *ret = vtkObjectFactory::CreateInstance("VTKViewer_RenderWindowInteractor") ;
74 return dynamic_cast<VTKViewer_RenderWindowInteractor *>(ret) ;
76 return new VTKViewer_RenderWindowInteractor;
79 VTKViewer_RenderWindowInteractor::VTKViewer_RenderWindowInteractor() {
81 this->mTimer = new QTimer( this ) ;
85 myBasicPicker = vtkPicker::New();
86 myCellPicker = vtkCellPicker::New();
87 myPointPicker = vtkPointPicker::New();
89 myCellActor = VTKViewer_Actor::New();
90 myCellActor->PickableOff();
91 myCellActor->GetProperty()->SetColor(1,1,0);
92 myCellActor->GetProperty()->SetLineWidth(5);
93 myCellActor->GetProperty()->SetRepresentationToSurface();
95 myEdgeActor = VTKViewer_Actor::New();
96 myEdgeActor->PickableOff();
97 myEdgeActor->GetProperty()->SetColor(1,0,0);
98 myEdgeActor->GetProperty()->SetLineWidth(5);
99 myEdgeActor->GetProperty()->SetRepresentationToWireframe();
101 myPointActor = VTKViewer_Actor::New();
102 myPointActor->PickableOff();
103 myPointActor->GetProperty()->SetColor(1,1,0);
104 myPointActor->GetProperty()->SetPointSize(5);
105 myPointActor->GetProperty()->SetRepresentationToPoints();
107 connect(mTimer, SIGNAL(timeout()), this, SLOT(TimerFunc())) ;
111 VTKViewer_RenderWindowInteractor::~VTKViewer_RenderWindowInteractor() {
112 if(MYDEBUG) INFOS("VTKViewer_RenderWindowInteractor::~VTKViewer_RenderWindowInteractor()");
116 myViewFrame->RemoveActor(myCellActor);
117 myViewFrame->RemoveActor(myEdgeActor);
118 myViewFrame->RemoveActor(myPointActor);
120 myCellActor->Delete();
121 myEdgeActor->Delete();
122 myPointActor->Delete();
124 myBasicPicker->Delete();
125 myCellPicker->Delete();
126 myPointPicker->Delete();
129 void VTKViewer_RenderWindowInteractor::PrintSelf(ostream& os, vtkIndent indent) {
130 vtkRenderWindowInteractor::PrintSelf(os, indent) ;
132 // :NOTE: Fri Apr 21 21:51:05 2000 Pagey
133 // QGL specific stuff goes here. One should add output
134 // lines here if any protected members are added to
140 // We never allow the VTKViewer_RenderWindowInteractor to control
141 // the event loop. The application always has the control.
143 void VTKViewer_RenderWindowInteractor::Initialize() {
145 // We cannot do much unless there is a render window
146 // associated with this interactor.
148 if( ! RenderWindow ) {
149 vtkErrorMacro(<< "VTKViewer_RenderWindowInteractor::Initialize(): No render window attached!") ;
154 // We cannot hand a render window which is not a VTKViewer_RenderWindow.
155 // One way to force this is to use dynamic_cast and hope that
156 // it works. If the dynamic_cast does not work, we flag an error
157 // and get the hell out.
159 vtkRenderWindow *my_render_win = dynamic_cast<vtkRenderWindow *>(RenderWindow) ;
160 if( !my_render_win ) {
161 vtkErrorMacro(<< "VTKViewer_RenderWindowInteractor::Initialize() can only handle VTKViewer_RenderWindow.") ;
166 // If the render window has zero size, then set it to a default
169 int* aSize = my_render_win->GetSize();
170 this->Size[0] = ((aSize[0] > 0) ? aSize[0] : 300);
171 this->Size[1] = ((aSize[1] > 0) ? aSize[1] : 300);
173 this->SetPicker(myBasicPicker);
175 SetSelectionTolerance();
178 // Enable the interactor.
183 // Start the rendering of the window.
185 my_render_win->Start() ;
188 // The interactor has been initialized.
190 this->Initialized = 1 ;
196 //----------------------------------------------------------------------------
197 void VTKViewer_RenderWindowInteractor::setGUIWindow(QWidget* theWindow){
198 myGUIWindow = theWindow;
201 //----------------------------------------------------------------------------
202 void VTKViewer_RenderWindowInteractor::setViewFrame(VTKViewer_ViewFrame* theViewFrame){
203 myViewFrame = theViewFrame;
205 myViewFrame->InsertActor(myCellActor);
206 myViewFrame->InsertActor(myEdgeActor);
207 myViewFrame->InsertActor(myPointActor);
210 //----------------------------------------------------------------------------
211 void VTKViewer_RenderWindowInteractor::MoveInternalActors()
213 myViewFrame->MoveActor(myCellActor);
214 myViewFrame->MoveActor(myEdgeActor);
215 myViewFrame->MoveActor(myPointActor);
218 //----------------------------------------------------------------------------
219 void VTKViewer_RenderWindowInteractor::SetInteractorStyle(vtkInteractorObserver *theInteractor){
220 myInteractorStyle = dynamic_cast<VTKViewer_InteractorStyleSALOME*>(theInteractor);
221 vtkRenderWindowInteractor::SetInteractorStyle(theInteractor);
225 void VTKViewer_RenderWindowInteractor::SetSelectionMode(Selection_Mode theMode)
227 myCellActor->SetVisibility(false);
228 myEdgeActor->SetVisibility(false);
229 myPointActor->SetVisibility(false);
233 this->SetPicker(myBasicPicker);
236 this->SetPicker(myPointPicker);
241 case VolumeSelection:
242 case EdgeOfCellSelection:
243 this->SetPicker(myCellPicker);
247 myInteractorStyle->OnSelectionModeChanged();
250 void VTKViewer_RenderWindowInteractor::SetSelectionProp(const double& theRed, const double& theGreen,
251 const double& theBlue, const int& theWidth)
253 myCellActor->GetProperty()->SetColor(theRed, theGreen, theBlue);
254 myCellActor->GetProperty()->SetLineWidth(theWidth);
256 myPointActor->GetProperty()->SetColor(theRed, theGreen, theBlue);
257 myPointActor->GetProperty()->SetPointSize(theWidth);
260 void VTKViewer_RenderWindowInteractor::SetSelectionTolerance(const double& theTolNodes, const double& theTolItems)
262 myTolNodes = theTolNodes;
263 myTolItems = theTolItems;
265 myBasicPicker->SetTolerance(myTolItems);
266 myCellPicker->SetTolerance(myTolItems);
267 myPointPicker->SetTolerance(myTolNodes);
271 void VTKViewer_RenderWindowInteractor::Enable() {
273 // Do not need to do anything if already enabled.
275 if( this->Enabled ) {
280 // Attach slots to every useful signal of the render window.
282 this->ConnectSlots() ;
288 void VTKViewer_RenderWindowInteractor::Disable() {
289 if( ! this->Enabled ) {
293 this->DisconnectSlots() ;
298 // ==================================
299 void VTKViewer_RenderWindowInteractor::Start() {
301 // We do not allow this interactor to control the
302 // event loop. Only the QtApplication objects are
303 // allowed to do that.
305 vtkErrorMacro(<<"VTKViewer_RenderWindowInteractor::Start() not allowed to start event loop.") ;
309 void VTKViewer_RenderWindowInteractor::UpdateSize(int w, int h) {
310 // if the size changed send this on to the RenderWindow
311 if ((w != this->Size[0])||(h != this->Size[1])) {
314 this->RenderWindow->SetSize(w,h);
318 int VTKViewer_RenderWindowInteractor::CreateTimer(int vtkNotUsed(timertype)) {
320 // Start a one-shot timer for 10ms.
322 mTimer->start(10, TRUE) ;
326 int VTKViewer_RenderWindowInteractor::DestroyTimer(void) {
328 // :TRICKY: Tue May 2 00:17:32 2000 Pagey
330 // QTimer will automatically expire after 10ms. So
331 // we do not need to do anything here. In fact, we
332 // should not even Stop() the QTimer here because doing
333 // this will skip some of the processing that the TimerFunc()
334 // does and will result in undesirable effects. For
335 // example, this will result in vtkLODActor to leave
336 // the models in low-res mode after the mouse stops
342 void VTKViewer_RenderWindowInteractor::TimerFunc() {
343 if( ! this->Enabled ) {
347 ((vtkInteractorStyle*)this->InteractorStyle)->OnTimer() ;
348 emit RenderWindowModified() ;
351 void VTKViewer_RenderWindowInteractor::ConnectSlots() {
352 ProcessSlotConnections(true) ;
355 void VTKViewer_RenderWindowInteractor::DisconnectSlots() {
356 ProcessSlotConnections(false) ;
359 void VTKViewer_RenderWindowInteractor::ProcessSlotConnections(bool conn) {
361 // We cannot do much unless there is a render window
362 // associated with this interactor.
364 if( ! myGUIWindow ) {
365 vtkErrorMacro(<< "VTKViewer_RenderWindowInteractor::Initialize(): No render window attached!") ;
370 bool (*slot_func) ( const QObject * sender,
372 const QObject * receiver,
373 const char * member ) ;
375 slot_func = &QObject::connect ;
377 slot_func = &QObject::disconnect ;
380 // We cannot hand a render window which is not a VTKViewer_RenderWindow.
381 // One way to force this is to use dynamic_cast and hope that
382 // it works. If the dynamic_cast does not work, we flag an error
383 // and get the hell out.
385 if( ! myGUIWindow ) {
386 vtkErrorMacro(<< "VTKViewer_RenderWindowInteractor::Initialize() can only handle VTKViewer_RenderWindow.") ;
390 slot_func ( myGUIWindow, SIGNAL(ButtonPressed(const QMouseEvent *)),
391 this, SLOT(ButtonPressed(const QMouseEvent *)) ) ;
392 slot_func( myGUIWindow, SIGNAL(ButtonReleased(const QMouseEvent *)),
393 this, SLOT(ButtonReleased(const QMouseEvent *)) ) ;
396 slot_func( myGUIWindow, SIGNAL(LeftButtonPressed(const QMouseEvent *)),
397 this, SLOT(LeftButtonPressed(const QMouseEvent *)) ) ;
398 slot_func( myGUIWindow, SIGNAL(LeftButtonReleased(const QMouseEvent *)),
399 this, SLOT(LeftButtonReleased(const QMouseEvent *)) ) ;
401 slot_func( myGUIWindow, SIGNAL(MiddleButtonPressed(const QMouseEvent *)),
402 this, SLOT(MiddleButtonPressed(const QMouseEvent *)) ) ;
403 slot_func( myGUIWindow, SIGNAL(MiddleButtonReleased(const QMouseEvent *)),
404 this, SLOT(MiddleButtonReleased(const QMouseEvent *)) ) ;
406 slot_func( myGUIWindow, SIGNAL(RightButtonPressed(const QMouseEvent *)),
407 this, SLOT(RightButtonPressed(const QMouseEvent *)) ) ;
408 slot_func( myGUIWindow, SIGNAL(RightButtonReleased(const QMouseEvent *)),
409 this, SLOT(RightButtonReleased(const QMouseEvent *)) ) ;
411 slot_func( myGUIWindow, SIGNAL(MouseMove(const QMouseEvent *)),
412 this, SLOT(MouseMove(const QMouseEvent *)) ) ;
414 slot_func( myGUIWindow, SIGNAL(KeyPressed(QKeyEvent *)),
415 this, SLOT(KeyPressed(QKeyEvent *)) ) ;
417 slot_func( this, SIGNAL(RenderWindowModified()),
418 myGUIWindow, SLOT(update()) ) ;
422 void VTKViewer_RenderWindowInteractor::MouseMove(const QMouseEvent *event) {
423 if( ! this->Enabled ) {
426 myInteractorStyle->OnMouseMove(0, 0, event->x(), event->y()/*this->Size[1] - event->y() - 1*/) ;
427 if (myInteractorStyle->needsRedrawing() )
428 emit RenderWindowModified() ;
431 void VTKViewer_RenderWindowInteractor::LeftButtonPressed(const QMouseEvent *event) {
432 if( ! this->Enabled ) {
435 myInteractorStyle->OnLeftButtonDown((event->state() & ControlButton),
436 (event->state() & ShiftButton),
437 event->x(), event->y());
440 void VTKViewer_RenderWindowInteractor::LeftButtonReleased(const QMouseEvent *event) {
441 if( ! this->Enabled ) {
444 myInteractorStyle->OnLeftButtonUp( (event->state() & ControlButton),
445 (event->state() & ShiftButton),
446 event->x(), event->y() ) ;
449 void VTKViewer_RenderWindowInteractor::MiddleButtonPressed(const QMouseEvent *event) {
450 if( ! this->Enabled ) {
453 myInteractorStyle->OnMiddleButtonDown((event->state() & ControlButton),
454 (event->state() & ShiftButton),
455 event->x(), event->y() ) ;
458 void VTKViewer_RenderWindowInteractor::MiddleButtonReleased(const QMouseEvent *event) {
459 if( ! this->Enabled ) {
462 myInteractorStyle->OnMiddleButtonUp( (event->state() & ControlButton),
463 (event->state() & ShiftButton),
464 event->x(), event->y() ) ;
467 void VTKViewer_RenderWindowInteractor::RightButtonPressed(const QMouseEvent *event) {
468 if( ! this->Enabled ) {
471 myInteractorStyle->OnRightButtonDown( (event->state() & ControlButton),
472 (event->state() & ShiftButton),
473 event->x(), event->y() ) ;
476 void VTKViewer_RenderWindowInteractor::RightButtonReleased(const QMouseEvent *event) {
477 if( ! this->Enabled ) {
480 myInteractorStyle->OnRightButtonUp( (event->state() & ControlButton),
481 (event->state() & ShiftButton),
482 event->x(), event->y() ) ;
485 void VTKViewer_RenderWindowInteractor::ButtonPressed(const QMouseEvent *event) {
489 void VTKViewer_RenderWindowInteractor::ButtonReleased(const QMouseEvent *event) {
494 int VTKViewer_RenderWindowInteractor::GetDisplayMode() {
495 return myDisplayMode;
498 void VTKViewer_RenderWindowInteractor::SetDisplayMode(int theMode) {
500 ChangeRepresentationToWireframe();
502 ChangeRepresentationToSurface();
503 myDisplayMode = theMode;
507 void VTKViewer_RenderWindowInteractor::SetDisplayMode(const Handle(SALOME_InteractiveObject)& theIObject, int theMode){
508 using namespace SALOME::VTK;
509 ForEachIf<SALOME_Actor>(GetRenderer()->GetActors(),
510 TIsSameIObject<SALOME_Actor>(theIObject),
511 TSetFunction<SALOME_Actor,int>
512 (&SALOME_Actor::setDisplayMode,theMode));
516 void VTKViewer_RenderWindowInteractor::ChangeRepresentationToWireframe()
518 ChangeRepresentationToWireframe(GetRenderer()->GetActors());
521 void VTKViewer_RenderWindowInteractor::ChangeRepresentationToSurface()
523 ChangeRepresentationToSurface(GetRenderer()->GetActors());
527 void VTKViewer_RenderWindowInteractor::ChangeRepresentationToWireframe(vtkActorCollection* theCollection)
529 using namespace SALOME::VTK;
530 ForEach<SALOME_Actor>(theCollection,
531 TSetFunction<SALOME_Actor,int>
532 (&SALOME_Actor::setDisplayMode,0));
533 emit RenderWindowModified();
536 void VTKViewer_RenderWindowInteractor::ChangeRepresentationToSurface(vtkActorCollection* theCollection)
538 using namespace SALOME::VTK;
539 ForEach<SALOME_Actor>(theCollection,
540 TSetFunction<SALOME_Actor,int>
541 (&SALOME_Actor::setDisplayMode,1));
542 emit RenderWindowModified();
546 vtkRenderer* VTKViewer_RenderWindowInteractor::GetRenderer()
548 vtkRendererCollection * theRenderers = this->RenderWindow->GetRenderers();
549 theRenderers->InitTraversal();
550 return theRenderers->GetNextItem();
555 SALOME::VTK::TSetFunction<vtkActor,int> mySetFunction;
557 mySetFunction(&vtkActor::SetVisibility,false)
559 void operator()(SALOME_Actor* theActor){
560 theActor->SetVisibility(false);
561 // Erase dependent actors
562 vtkActorCollection* aCollection = vtkActorCollection::New();
563 theActor->GetChildActors(aCollection);
564 SALOME::VTK::ForEach<vtkActor>(aCollection,mySetFunction);
565 aCollection->Delete();
569 void VTKViewer_RenderWindowInteractor::EraseAll()
571 using namespace SALOME::VTK;
572 ForEach<SALOME_Actor>(GetRenderer()->GetActors(),
575 emit RenderWindowModified() ;
578 void VTKViewer_RenderWindowInteractor::DisplayAll()
580 vtkActorCollection* aCollection = GetRenderer()->GetActors();
581 using namespace SALOME::VTK;
582 ForEach<SALOME_Actor>(aCollection,TSetVisibility<SALOME_Actor>(true));
584 emit RenderWindowModified() ;
588 void VTKViewer_RenderWindowInteractor::Erase(SALOME_Actor* theActor, bool update)
593 emit RenderWindowModified();
597 void VTKViewer_RenderWindowInteractor::Erase(const Handle(SALOME_InteractiveObject)& theIObject, bool update)
599 using namespace SALOME::VTK;
600 ForEachIf<SALOME_Actor>(GetRenderer()->GetActors(),
601 TIsSameIObject<SALOME_Actor>(theIObject),
605 emit RenderWindowModified();
609 struct TRemoveAction{
611 TRemoveAction(vtkRenderer* theRen): myRen(theRen){}
612 void operator()(SALOME_Actor* theActor){
613 myRen->RemoveActor(theActor);
617 void VTKViewer_RenderWindowInteractor::Remove(const Handle(SALOME_InteractiveObject)& theIObject, bool update)
619 vtkRenderer* aRen = GetRenderer();
621 using namespace SALOME::VTK;
622 ForEachIf<SALOME_Actor>(aRen->GetActors(),
623 TIsSameIObject<SALOME_Actor>(theIObject),
624 TRemoveAction(aRen));
629 void VTKViewer_RenderWindowInteractor::Remove( SALOME_Actor* SActor, bool updateViewer )
633 GetRenderer()->RemoveProp( SActor );
635 emit RenderWindowModified();
639 void VTKViewer_RenderWindowInteractor::RemoveAll( const bool updateViewer )
641 vtkRenderer* aRenderer = GetRenderer();
642 vtkActorCollection* anActors = aRenderer->GetActors();
645 anActors->InitTraversal();
646 while ( vtkActor *anAct = anActors->GetNextActor() )
648 if ( anAct->IsA( "SALOME_Actor" ) )
650 SALOME_Actor* aSAct = (SALOME_Actor*)anAct;
651 if ( aSAct->hasIO() && aSAct->getIO()->hasEntry() )
652 aRenderer->RemoveActor( anAct );
657 emit RenderWindowModified();
662 float VTKViewer_RenderWindowInteractor::GetTransparency(const Handle(SALOME_InteractiveObject)& theIObject)
664 using namespace SALOME::VTK;
665 SALOME_Actor* anActor =
666 Find<SALOME_Actor>(GetRenderer()->GetActors(),
667 TIsSameIObject<SALOME_Actor>(theIObject));
669 return 1.0 - anActor->GetOpacity();
674 void VTKViewer_RenderWindowInteractor::SetTransparency(const Handle(SALOME_InteractiveObject)& theIObject, float theTrans)
676 float anOpacity = 1.0 - theTrans;
677 using namespace SALOME::VTK;
678 ForEachIf<SALOME_Actor>(GetRenderer()->GetActors(),
679 TIsSameIObject<SALOME_Actor>(theIObject),
680 TSetFunction<SALOME_Actor,float>
681 (&SALOME_Actor::SetOpacity,anOpacity));
685 void VTKViewer_RenderWindowInteractor::Display(SALOME_Actor* theActor, bool update)
687 GetRenderer()->AddActor(theActor);
688 theActor->SetVisibility(true);
691 emit RenderWindowModified();
695 void VTKViewer_RenderWindowInteractor::Display(const Handle(SALOME_InteractiveObject)& theIObject, bool update)
697 using namespace SALOME::VTK;
698 ForEachIf<SALOME_Actor>(GetRenderer()->GetActors(),
699 TIsSameIObject<SALOME_Actor>(theIObject),
700 TSetVisibility<SALOME_Actor>(true));
703 emit RenderWindowModified() ;
707 void VTKViewer_RenderWindowInteractor::KeyPressed(QKeyEvent *event){}
710 struct THighlightAction{
712 VTKViewer_InteractorStyleSALOME* myInteractorStyle;
713 THighlightAction(VTKViewer_InteractorStyleSALOME* theInteractorStyle,
714 bool theIsHighlight):
715 myInteractorStyle(theInteractorStyle),
716 myIsHighlight(theIsHighlight)
718 void operator()(SALOME_Actor* theActor){
719 if(theActor->GetMapper()){
720 if(theActor->hasHighlight())
721 theActor->highlight(myIsHighlight);
723 if(theActor->GetVisibility() && myIsHighlight)
724 myInteractorStyle->HighlightProp(theActor);
725 else if(!myIsHighlight)
726 myInteractorStyle->HighlightProp(NULL);
732 bool VTKViewer_RenderWindowInteractor::highlight( const Handle(SALOME_InteractiveObject)& theIObject,
736 using namespace SALOME::VTK;
737 ForEachIf<SALOME_Actor>(GetRenderer()->GetActors(),
738 TIsSameIObject<SALOME_Actor>(theIObject),
739 THighlightAction(myInteractorStyle,hilight));
742 emit RenderWindowModified();
748 struct TUpdateAction{
749 void operator()(vtkActor* theActor){
750 theActor->ApplyProperties();
754 void VTKViewer_RenderWindowInteractor::Update() {
755 vtkRenderer* aRen = GetRenderer();
757 using namespace SALOME::VTK;
758 ForEach<vtkActor>(aRen->GetActors(),TUpdateAction());
762 emit RenderWindowModified();
766 void VTKViewer_RenderWindowInteractor::unHighlightSubSelection(){
767 myPointActor->SetVisibility(false);
768 myEdgeActor->SetVisibility(false);
769 myCellActor->SetVisibility(false);
773 struct TUnHighlightAllAction{
774 void operator()(SALOME_Actor* theActor){
775 if(theActor->hasIO()){
776 if(theActor->hasHighlight())
777 theActor->highlight(false);
782 bool VTKViewer_RenderWindowInteractor::unHighlightAll(){
783 unHighlightSubSelection();
785 using namespace SALOME::VTK;
786 ForEach<SALOME_Actor>(GetRenderer()->GetActors(),
787 TUnHighlightAllAction());
789 emit RenderWindowModified() ;
797 void VTKViewer_RenderWindowInteractor::SetColor(const Handle(SALOME_InteractiveObject)& theIObject,QColor theColor)
799 float aColor[3] = {theColor.red()/255., theColor.green()/255., theColor.blue()/255.};
800 using namespace SALOME::VTK;
801 ForEachIf<SALOME_Actor>(GetRenderer()->GetActors(),
802 TIsSameIObject<SALOME_Actor>(theIObject),
803 TSetFunction<SALOME_Actor,const float*>
804 (&SALOME_Actor::SetColor,aColor));
808 QColor VTKViewer_RenderWindowInteractor::GetColor(const Handle(SALOME_InteractiveObject)& theIObject)
810 using namespace SALOME::VTK;
811 SALOME_Actor* anActor =
812 Find<SALOME_Actor>(GetRenderer()->GetActors(),
813 TIsSameIObject<SALOME_Actor>(theIObject));
816 anActor->GetColor(r,g,b);
817 return QColor(int(r*255),int(g*255),int(b*255));
819 return QColor(0,0,0);
823 bool VTKViewer_RenderWindowInteractor::isInViewer(const Handle(SALOME_InteractiveObject)& theIObject)
825 using namespace SALOME::VTK;
826 SALOME_Actor* anActor =
827 Find<SALOME_Actor>(GetRenderer()->GetActors(),
828 TIsSameIObject<SALOME_Actor>(theIObject));
829 return anActor != NULL;
833 bool VTKViewer_RenderWindowInteractor::isVisible(const Handle(SALOME_InteractiveObject)& theIObject)
835 using namespace SALOME::VTK;
836 SALOME_Actor* anActor =
837 Find<SALOME_Actor>(GetRenderer()->GetActors(),
838 TIsSameIObject<SALOME_Actor>(theIObject));
839 return anActor != NULL && anActor->GetVisibility();
843 void VTKViewer_RenderWindowInteractor::rename(const Handle(SALOME_InteractiveObject)& theIObject, QString theName)
845 using namespace SALOME::VTK;
846 ForEachIf<SALOME_Actor>(GetRenderer()->GetActors(),
847 TIsSameIObject<SALOME_Actor>(theIObject),
848 TSetFunction<SALOME_Actor,const char*,QString>
849 (&SALOME_Actor::setName,theName.latin1()));
853 //----------------------------------------------------------------------------
854 bool VTKViewer_RenderWindowInteractor::highlight(const TColStd_IndexedMapOfInteger& theMapIndex,
855 SALOME_Actor* theMapActor, VTKViewer_Actor* theActor,
856 TUpdateActor theFun, bool hilight, bool update)
858 if(theMapIndex.Extent() == 0) return false;
861 setActorData(theMapIndex,theMapActor,theActor,theFun);
862 theActor->SetVisibility(true);
865 theActor->SetVisibility(false);
869 this->RenderWindow->Render();
870 emit RenderWindowModified() ;
876 void VTKViewer_RenderWindowInteractor::setActorData(const TColStd_IndexedMapOfInteger& theMapIndex,
877 SALOME_Actor* theMapActor,
878 VTKViewer_Actor *theActor,
881 (*theFun)(theMapIndex,theMapActor,theActor);
883 theMapActor->GetPosition(aPos);
884 theActor->SetPosition(aPos);
888 //----------------------------------------------------------------------------
889 static void CellsUpdateActor(const TColStd_IndexedMapOfInteger& theMapIndex,
890 SALOME_Actor* theMapActor,
891 VTKViewer_Actor* theActor)
893 theActor->MapCells(theMapActor,theMapIndex);
896 bool VTKViewer_RenderWindowInteractor::highlightCell(const TColStd_IndexedMapOfInteger& theMapIndex,
897 SALOME_Actor* theMapActor,
901 return highlight(theMapIndex,theMapActor,myCellActor,&CellsUpdateActor,hilight,update);
904 void VTKViewer_RenderWindowInteractor::setCellData(const int& theIndex,
905 SALOME_Actor* theMapActor,
906 VTKViewer_Actor* theActor)
908 TColStd_IndexedMapOfInteger MapIndex;
909 MapIndex.Add(theIndex);
910 theActor->MapCells(theMapActor,MapIndex);
914 //----------------------------------------------------------------------------
915 static void PointsUpdateActor(const TColStd_IndexedMapOfInteger& theMapIndex,
916 SALOME_Actor* theMapActor,
917 VTKViewer_Actor* theActor)
919 theActor->MapPoints(theMapActor,theMapIndex);
922 bool VTKViewer_RenderWindowInteractor::highlightPoint(const TColStd_IndexedMapOfInteger& theMapIndex,
923 SALOME_Actor* theMapActor,
927 return highlight(theMapIndex,theMapActor,myPointActor,&PointsUpdateActor,hilight,update);
930 void VTKViewer_RenderWindowInteractor::setPointData(const int& theIndex,
931 SALOME_Actor* theMapActor,
932 VTKViewer_Actor* theActor)
934 TColStd_IndexedMapOfInteger MapIndex;
935 MapIndex.Add(theIndex);
936 theActor->MapPoints(theMapActor,MapIndex);
940 //----------------------------------------------------------------------------
941 static void EdgesUpdateActor(const TColStd_IndexedMapOfInteger& theMapIndex,
942 SALOME_Actor* theMapActor,
943 VTKViewer_Actor* theActor)
945 theActor->MapEdge(theMapActor,theMapIndex);
948 bool VTKViewer_RenderWindowInteractor::highlightEdge(const TColStd_IndexedMapOfInteger& theMapIndex,
949 SALOME_Actor* theMapActor,
953 return highlight(theMapIndex,theMapActor,myEdgeActor,&EdgesUpdateActor,hilight,update);
956 void VTKViewer_RenderWindowInteractor::setEdgeData(const int& theCellIndex,
957 SALOME_Actor* theMapActor,
958 const int& theEdgeIndex,
959 VTKViewer_Actor* theActor )
961 TColStd_IndexedMapOfInteger MapIndex;
962 MapIndex.Add(theCellIndex);
963 MapIndex.Add(theEdgeIndex);
964 theActor->MapEdge(theMapActor,MapIndex);