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() ;
579 void VTKViewer_RenderWindowInteractor::DisplayAll()
581 vtkActorCollection* aCollection = GetRenderer()->GetActors();
582 using namespace SALOME::VTK;
583 ForEach<SALOME_Actor>(aCollection,TSetVisibility<SALOME_Actor>(true));
585 emit RenderWindowModified() ;
589 void VTKViewer_RenderWindowInteractor::Erase(SALOME_Actor* theActor, bool update)
594 emit RenderWindowModified();
598 void VTKViewer_RenderWindowInteractor::Erase(const Handle(SALOME_InteractiveObject)& theIObject, bool update)
600 using namespace SALOME::VTK;
601 ForEachIf<SALOME_Actor>(GetRenderer()->GetActors(),
602 TIsSameIObject<SALOME_Actor>(theIObject),
606 emit RenderWindowModified();
610 struct TRemoveAction{
612 TRemoveAction(vtkRenderer* theRen): myRen(theRen){}
613 void operator()(SALOME_Actor* theActor){
614 myRen->RemoveActor(theActor);
618 void VTKViewer_RenderWindowInteractor::Remove(const Handle(SALOME_InteractiveObject)& theIObject, bool update)
620 vtkRenderer* aRen = GetRenderer();
622 using namespace SALOME::VTK;
623 ForEachIf<SALOME_Actor>(aRen->GetActors(),
624 TIsSameIObject<SALOME_Actor>(theIObject),
625 TRemoveAction(aRen));
628 emit RenderWindowModified();
632 float VTKViewer_RenderWindowInteractor::GetTransparency(const Handle(SALOME_InteractiveObject)& theIObject)
634 using namespace SALOME::VTK;
635 SALOME_Actor* anActor =
636 Find<SALOME_Actor>(GetRenderer()->GetActors(),
637 TIsSameIObject<SALOME_Actor>(theIObject));
639 return 1.0 - anActor->GetOpacity();
644 void VTKViewer_RenderWindowInteractor::SetTransparency(const Handle(SALOME_InteractiveObject)& theIObject, float theTrans)
646 float anOpacity = 1.0 - theTrans;
647 using namespace SALOME::VTK;
648 ForEachIf<SALOME_Actor>(GetRenderer()->GetActors(),
649 TIsSameIObject<SALOME_Actor>(theIObject),
650 TSetFunction<SALOME_Actor,float>
651 (&SALOME_Actor::SetOpacity,anOpacity));
655 void VTKViewer_RenderWindowInteractor::Display(SALOME_Actor* theActor, bool update)
657 GetRenderer()->AddActor(theActor);
658 theActor->SetVisibility(true);
661 emit RenderWindowModified();
665 void VTKViewer_RenderWindowInteractor::Display(const Handle(SALOME_InteractiveObject)& theIObject, bool update)
667 using namespace SALOME::VTK;
668 ForEachIf<SALOME_Actor>(GetRenderer()->GetActors(),
669 TIsSameIObject<SALOME_Actor>(theIObject),
670 TSetVisibility<SALOME_Actor>(true));
673 emit RenderWindowModified() ;
677 void VTKViewer_RenderWindowInteractor::KeyPressed(QKeyEvent *event){}
680 struct THighlightAction{
682 VTKViewer_InteractorStyleSALOME* myInteractorStyle;
683 THighlightAction(VTKViewer_InteractorStyleSALOME* theInteractorStyle,
684 bool theIsHighlight):
685 myInteractorStyle(theInteractorStyle),
686 myIsHighlight(theIsHighlight)
688 void operator()(SALOME_Actor* theActor){
689 if(theActor->GetMapper()){
690 if(theActor->hasHighlight())
691 theActor->highlight(myIsHighlight);
693 if(theActor->GetVisibility() && myIsHighlight)
694 myInteractorStyle->HighlightProp(theActor);
695 else if(!myIsHighlight)
696 myInteractorStyle->HighlightProp(NULL);
702 bool VTKViewer_RenderWindowInteractor::highlight( const Handle(SALOME_InteractiveObject)& theIObject,
706 using namespace SALOME::VTK;
707 ForEachIf<SALOME_Actor>(GetRenderer()->GetActors(),
708 TIsSameIObject<SALOME_Actor>(theIObject),
709 THighlightAction(myInteractorStyle,hilight));
712 emit RenderWindowModified();
718 struct TUpdateAction{
719 void operator()(vtkActor* theActor){
720 theActor->ApplyProperties();
724 void VTKViewer_RenderWindowInteractor::Update() {
725 vtkRenderer* aRen = GetRenderer();
727 using namespace SALOME::VTK;
728 ForEach<vtkActor>(aRen->GetActors(),TUpdateAction());
732 emit RenderWindowModified();
736 void VTKViewer_RenderWindowInteractor::unHighlightSubSelection(){
737 myPointActor->SetVisibility(false);
738 myEdgeActor->SetVisibility(false);
739 myCellActor->SetVisibility(false);
743 struct TUnHighlightAllAction{
744 void operator()(SALOME_Actor* theActor){
745 if(theActor->hasIO()){
746 if(theActor->hasHighlight())
747 theActor->highlight(false);
752 bool VTKViewer_RenderWindowInteractor::unHighlightAll(){
753 unHighlightSubSelection();
755 using namespace SALOME::VTK;
756 ForEach<SALOME_Actor>(GetRenderer()->GetActors(),
757 TUnHighlightAllAction());
759 emit RenderWindowModified() ;
767 void VTKViewer_RenderWindowInteractor::SetColor(const Handle(SALOME_InteractiveObject)& theIObject,QColor theColor)
769 float aColor[3] = {theColor.red()/255., theColor.green()/255., theColor.blue()/255.};
770 using namespace SALOME::VTK;
771 ForEachIf<SALOME_Actor>(GetRenderer()->GetActors(),
772 TIsSameIObject<SALOME_Actor>(theIObject),
773 TSetFunction<SALOME_Actor,const float*>
774 (&SALOME_Actor::SetColor,aColor));
778 QColor VTKViewer_RenderWindowInteractor::GetColor(const Handle(SALOME_InteractiveObject)& theIObject)
780 using namespace SALOME::VTK;
781 SALOME_Actor* anActor =
782 Find<SALOME_Actor>(GetRenderer()->GetActors(),
783 TIsSameIObject<SALOME_Actor>(theIObject));
786 anActor->GetColor(r,g,b);
787 return QColor(int(r*255),int(g*255),int(b*255));
789 return QColor(0,0,0);
793 bool VTKViewer_RenderWindowInteractor::isInViewer(const Handle(SALOME_InteractiveObject)& theIObject)
795 using namespace SALOME::VTK;
796 SALOME_Actor* anActor =
797 Find<SALOME_Actor>(GetRenderer()->GetActors(),
798 TIsSameIObject<SALOME_Actor>(theIObject));
799 return anActor != NULL;
803 bool VTKViewer_RenderWindowInteractor::isVisible(const Handle(SALOME_InteractiveObject)& theIObject)
805 using namespace SALOME::VTK;
806 SALOME_Actor* anActor =
807 Find<SALOME_Actor>(GetRenderer()->GetActors(),
808 TIsSameIObject<SALOME_Actor>(theIObject));
809 return anActor != NULL && anActor->GetVisibility();
813 void VTKViewer_RenderWindowInteractor::rename(const Handle(SALOME_InteractiveObject)& theIObject, QString theName)
815 using namespace SALOME::VTK;
816 ForEachIf<SALOME_Actor>(GetRenderer()->GetActors(),
817 TIsSameIObject<SALOME_Actor>(theIObject),
818 TSetFunction<SALOME_Actor,const char*,QString>
819 (&SALOME_Actor::setName,theName.latin1()));
823 //----------------------------------------------------------------------------
824 bool VTKViewer_RenderWindowInteractor::highlight(const TColStd_IndexedMapOfInteger& theMapIndex,
825 SALOME_Actor* theMapActor, VTKViewer_Actor* theActor,
826 TUpdateActor theFun, bool hilight, bool update)
828 if(theMapIndex.Extent() == 0) return false;
831 setActorData(theMapIndex,theMapActor,theActor,theFun);
832 theActor->SetVisibility(true);
835 theActor->SetVisibility(false);
839 this->RenderWindow->Render();
840 emit RenderWindowModified() ;
846 void VTKViewer_RenderWindowInteractor::setActorData(const TColStd_IndexedMapOfInteger& theMapIndex,
847 SALOME_Actor* theMapActor,
848 VTKViewer_Actor *theActor,
851 (*theFun)(theMapIndex,theMapActor,theActor);
855 //----------------------------------------------------------------------------
856 static void CellsUpdateActor(const TColStd_IndexedMapOfInteger& theMapIndex,
857 SALOME_Actor* theMapActor,
858 VTKViewer_Actor* theActor)
860 theActor->MapCells(theMapActor,theMapIndex);
863 bool VTKViewer_RenderWindowInteractor::highlightCell(const TColStd_IndexedMapOfInteger& theMapIndex,
864 SALOME_Actor* theMapActor,
868 return highlight(theMapIndex,theMapActor,myCellActor,&CellsUpdateActor,hilight,update);
871 void VTKViewer_RenderWindowInteractor::setCellData(const int& theIndex,
872 SALOME_Actor* theMapActor,
873 VTKViewer_Actor* theActor)
875 TColStd_IndexedMapOfInteger MapIndex;
876 MapIndex.Add(theIndex);
877 theActor->MapCells(theMapActor,MapIndex);
881 //----------------------------------------------------------------------------
882 static void PointsUpdateActor(const TColStd_IndexedMapOfInteger& theMapIndex,
883 SALOME_Actor* theMapActor,
884 VTKViewer_Actor* theActor)
886 theActor->MapPoints(theMapActor,theMapIndex);
889 bool VTKViewer_RenderWindowInteractor::highlightPoint(const TColStd_IndexedMapOfInteger& theMapIndex,
890 SALOME_Actor* theMapActor,
894 return highlight(theMapIndex,theMapActor,myPointActor,&PointsUpdateActor,hilight,update);
897 void VTKViewer_RenderWindowInteractor::setPointData(const int& theIndex,
898 SALOME_Actor* theMapActor,
899 VTKViewer_Actor* theActor)
901 TColStd_IndexedMapOfInteger MapIndex;
902 MapIndex.Add(theIndex);
903 theActor->MapPoints(theMapActor,MapIndex);
907 //----------------------------------------------------------------------------
908 static void EdgesUpdateActor(const TColStd_IndexedMapOfInteger& theMapIndex,
909 SALOME_Actor* theMapActor,
910 VTKViewer_Actor* theActor)
912 theActor->MapEdge(theMapActor,theMapIndex);
915 bool VTKViewer_RenderWindowInteractor::highlightEdge(const TColStd_IndexedMapOfInteger& theMapIndex,
916 SALOME_Actor* theMapActor,
920 return highlight(theMapIndex,theMapActor,myEdgeActor,&EdgesUpdateActor,hilight,update);
923 void VTKViewer_RenderWindowInteractor::setEdgeData(const int& theCellIndex,
924 SALOME_Actor* theMapActor,
925 const int& theEdgeIndex,
926 VTKViewer_Actor* theActor )
928 TColStd_IndexedMapOfInteger MapIndex;
929 MapIndex.Add(theCellIndex);
930 MapIndex.Add(theEdgeIndex);
931 theActor->MapEdge(theMapActor,MapIndex);