]> SALOME platform Git repositories - modules/visu.git/blob - src/VVTK/VVTK_ViewModel.cxx
Salome HOME
Join modifications from BR_Dev_For_4_0 tag V4_1_1.
[modules/visu.git] / src / VVTK / VVTK_ViewModel.cxx
1 // Copyright (C) 2005  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
3 //
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License.
8 //
9 // This library is distributed in the hope that it will be useful
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 // Lesser General Public License for more details.
13 //
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 //
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 //
20 #include "VVTK_ViewModel.h"
21
22 #include "VVTK_ViewWindow.h"
23
24 #include "VTKViewer_Algorithm.h"
25 #include "SVTK_Functor.h"
26 #include "VISU_Actor.h"
27 #include "SVTK_View.h"
28 #include "SVTK_Prs.h"
29
30 #include <vtkActorCollection.h>
31 #include <vtkRenderer.h>
32
33 //---------------------------------------------------------------
34 VVTK_Viewer
35 ::VVTK_Viewer()
36 {
37 }
38
39 //---------------------------------------------------------------
40 VVTK_Viewer
41 ::~VVTK_Viewer() 
42 {
43 }
44
45 //---------------------------------------------------------------
46 SUIT_ViewWindow*
47 VVTK_Viewer
48 ::createView( SUIT_Desktop* theDesktop )
49 {
50   TViewWindow* aViewWindow = new TViewWindow (theDesktop);
51   aViewWindow->Initialize(this);
52
53   aViewWindow->setBackgroundColor( backgroundColor() );
54   aViewWindow->SetTrihedronSize( trihedronSize() );
55
56   return aViewWindow;
57 }
58
59 //---------------------------------------------------------------
60 void
61 VVTK_Viewer
62 ::Display(const SALOME_VTKPrs* thePrs)
63 {
64   // try do downcast object
65   if(const SVTK_Prs* aPrs = dynamic_cast<const SVTK_Prs*>(thePrs)){
66     if(aPrs->IsNull())
67       return;
68     if(vtkActorCollection* aCollection = aPrs->GetObjects()){
69       aCollection->InitTraversal();
70       while(VISU_Actor* anActor = dynamic_cast<VISU_Actor*>(aCollection->GetNextActor())){
71         if(!anActor->GetFactory()->GetActiveState())
72           continue;
73         QPtrVector<SUIT_ViewWindow> aViews = myViewManager->getViews();
74         for(int i = 0, iEnd = aViews.size(); i < iEnd; i++){
75           if(SVTK_ViewWindow* aViewWindow = dynamic_cast<SVTK_ViewWindow*>(aViews.at(i))){
76             if(SVTK_View* aView = aViewWindow->getView()){
77               aView->Display(anActor, false);
78             }
79           }
80         }
81       }
82     }
83   }
84 }
85
86 //---------------------------------------------------------------
87 namespace VVTK
88 {
89   struct TIsOneActorVisibleAction
90   {
91     bool& myResult;
92     TIsOneActorVisibleAction(bool& theResult): 
93       myResult(theResult)
94     {
95       myResult = false;
96     }
97     void
98     operator()(SALOME_Actor* theActor)
99     {
100       if(!myResult)
101         myResult = theActor->GetVisibility();
102     }
103   };
104 }
105
106 //---------------------------------------------------------------
107 bool
108 VVTK_Viewer
109 ::isVisible( const Handle(SALOME_InteractiveObject)& theIO )
110 {
111   QPtrVector<SUIT_ViewWindow> aViews = myViewManager->getViews();
112   for(int i = 0, iEnd = aViews.size(); i < iEnd; i++)
113     if(SVTK_ViewWindow* aViewWindow = dynamic_cast<SVTK_ViewWindow*>(aViews.at(i))){
114       bool aResult;
115       VVTK::TIsOneActorVisibleAction anAction(aResult);
116       SVTK::ForEachIf<SALOME_Actor>(aViewWindow->getRenderer()->GetActors(),
117                                     SVTK::TIsSameIObject<SALOME_Actor>(theIO),
118                                     anAction);
119       return anAction.myResult;
120     }
121   
122   return false;
123 }