]> SALOME platform Git repositories - modules/visu.git/blob - src/VVTK/VVTK_ViewModel.cxx
Salome HOME
Merge from BR_V5_DEV 16Feb09
[modules/visu.git] / src / VVTK / VVTK_ViewModel.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 #include "VVTK_ViewModel.h"
23 #include "VISU_ActorFactory.h"
24 #include "VVTK_ViewWindow.h"
25
26 #include "VTKViewer_Algorithm.h"
27 #include "SVTK_Functor.h"
28 #include "VISU_ActorBase.h"
29 #include "SVTK_View.h"
30 #include "SVTK_Prs.h"
31
32 #include <SUIT_ViewManager.h>
33
34 #include <vtkActorCollection.h>
35 #include <vtkRenderer.h>
36
37 //---------------------------------------------------------------
38 VVTK_Viewer::VVTK_Viewer()
39 {
40 }
41
42 //---------------------------------------------------------------
43 VVTK_Viewer::~VVTK_Viewer() 
44 {
45 }
46
47 //---------------------------------------------------------------
48 SUIT_ViewWindow* VVTK_Viewer::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   aViewWindow->SetProjectionMode( projectionMode() );
56   aViewWindow->SetInteractionStyle( interactionStyle() );
57   aViewWindow->SetIncrementalSpeed( incrementalSpeed(), incrementalSpeedMode() );
58   aViewWindow->SetSpacemouseButtons( spacemouseBtn(1), spacemouseBtn(2), spacemouseBtn(3) );
59
60   return aViewWindow;
61 }
62
63 //---------------------------------------------------------------
64 void VVTK_Viewer::Display(const SALOME_VTKPrs* thePrs)
65 {
66   // try do downcast object
67   if(const SVTK_Prs* aPrs = dynamic_cast<const SVTK_Prs*>(thePrs)){
68     if(aPrs->IsNull())
69       return;
70     if(vtkActorCollection* aCollection = aPrs->GetObjects()){
71       aCollection->InitTraversal();
72       while(VISU_ActorBase* anActor = dynamic_cast<VISU_ActorBase*>(aCollection->GetNextActor())){
73         if(!anActor->GetFactory()->GetActiveState())
74           continue;
75         QVector<SUIT_ViewWindow*> aViews = myViewManager->getViews();
76         for(int i = 0, iEnd = aViews.size(); i < iEnd; i++){
77           if(SVTK_ViewWindow* aViewWindow = dynamic_cast<SVTK_ViewWindow*>(aViews.at(i))){
78             if(SVTK_View* aView = aViewWindow->getView()){
79               aView->Display(anActor, false);
80             }
81           }
82         }
83       }
84     }
85   }
86 }
87
88 //---------------------------------------------------------------
89 namespace VVTK
90 {
91   struct TIsOneActorVisibleAction
92   {
93     bool& myResult;
94     TIsOneActorVisibleAction(bool& theResult): 
95       myResult(theResult)
96     {
97       myResult = false;
98     }
99     void
100     operator()(SALOME_Actor* theActor)
101     {
102       if(!myResult)
103         myResult = theActor->GetVisibility();
104     }
105   };
106 }
107
108 //---------------------------------------------------------------
109 bool VVTK_Viewer::isVisible( const Handle(SALOME_InteractiveObject)& theIO )
110 {
111   QVector<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 }