25dad3403974a6159a1cab2f59d69cae590d069a
[u/mrichter/AliRoot.git] / EVE / Reve / Viewer.cxx
1 // $Header$
2
3 #include "Viewer.h"
4 #include "Scene.h"
5 #include "SceneInfo.h"
6
7 #include <Reve/ReveManager.h>
8
9 #include <TGLSAViewer.h>
10 #include <TGLScenePad.h>
11
12 using namespace Reve;
13
14 //______________________________________________________________________
15 // Reve::Viewer
16 //
17
18 ClassImp(Viewer)
19
20 Viewer::Viewer(const Text_t* n, const Text_t* t) :
21   RenderElementList(n, t),
22   fGLViewer (0)
23 {
24   SetChildClass(SceneInfo::Class());
25 }
26
27 Viewer::~Viewer()
28 {}
29
30 /**************************************************************************/
31
32 void Viewer::SetGLViewer(TGLViewer* s)
33 {
34   delete fGLViewer;
35   fGLViewer = s;
36
37   fGLViewer->SetSmartRefresh(kTRUE);
38   // fGLViewer->SetResetCamerasOnUpdate(kFALSE);
39   fGLViewer->SetResetCameraOnDoubleClick(kFALSE);
40 }
41
42 void Viewer::SpawnGLViewer(const TGWindow* parent, TGedEditor* ged)
43 {
44   TGLSAViewer* v = new TGLSAViewer(parent, 0, ged);
45   v->ToggleEditObject();
46   SetGLViewer(v);
47 }
48
49 /**************************************************************************/
50
51 void Viewer::AddScene(Scene* scene)
52 {
53   static const Exc_t eH("Viewer::AddScene ");
54
55   TGLSceneInfo* glsi = fGLViewer->AddScene(scene->GetGLScene());
56   if (glsi != 0) {
57     SceneInfo* si = new SceneInfo(this, scene, glsi);
58     gReve->AddRenderElement(si, this);
59   } else {
60     throw(eH + "scene already in the viewer.");
61   }
62 }
63
64 void Viewer::RemoveElementLocal(RenderElement* el)
65 {
66   fGLViewer->RemoveScene(((SceneInfo*)el)->GetGLScene());
67 }
68
69 void Viewer::RemoveElementsLocal()
70 {
71   fGLViewer->RemoveAllScenes();
72 }
73
74 TObject* Viewer::GetEditorObject() const
75 {
76   return fGLViewer;
77 }
78
79 Bool_t Viewer::HandleElementPaste(RenderElement* el)
80 {
81   static const Exc_t eH("Viewer::HandleElementPaste ");
82
83   Scene* scene = dynamic_cast<Scene*>(el);
84   if (scene != 0) {
85     AddScene(scene);
86     return kTRUE;
87   } else {
88     Warning(eH.Data(), "class Viewer only accepts Scene paste argument.");
89     return kFALSE;
90   }
91 }
92
93 /**************************************************************************/
94 /**************************************************************************/
95 /**************************************************************************/
96
97 //______________________________________________________________________
98 // Reve::ViewerList
99 //
100
101 ClassImp(ViewerList)
102
103 ViewerList::ViewerList(const Text_t* n, const Text_t* t) :
104   RenderElementList(n, t)
105 {
106   SetChildClass(Viewer::Class());
107 }
108
109 ViewerList::~ViewerList()
110 {}
111
112 /**************************************************************************/
113
114 void ViewerList::RepaintChangedViewers(Bool_t resetCameras, Bool_t dropLogicals)
115 {
116   for (List_i i=fChildren.begin(); i!=fChildren.end(); ++i)
117   {
118     TGLViewer* glv = ((Viewer*)*i)->GetGLViewer();
119     if (glv->IsChanged())
120     {
121       // printf(" Viewer '%s' changed ... reqesting draw.\n", (*i)->GetObject()->GetName());
122
123       if (resetCameras) glv->PostSceneBuildSetup(kTRUE);
124       if (dropLogicals) glv->SetSmartRefresh(kFALSE);
125
126       glv->RequestDraw(TGLRnrCtx::kLODHigh);
127
128       if (dropLogicals) glv->SetSmartRefresh(kTRUE);
129     }
130   }
131 }
132
133 void ViewerList::RepaintAllViewers(Bool_t resetCameras, Bool_t dropLogicals)
134 {
135   for (List_i i=fChildren.begin(); i!=fChildren.end(); ++i)
136   {
137     TGLViewer* glv = ((Viewer*)*i)->GetGLViewer();
138
139     // printf(" Viewer '%s' sending redraw reqest.\n", (*i)->GetObject()->GetName());
140
141     if (resetCameras) glv->PostSceneBuildSetup(kTRUE);
142     if (dropLogicals) glv->SetSmartRefresh(kFALSE);
143
144     glv->RequestDraw(TGLRnrCtx::kLODHigh);
145
146     if (dropLogicals) glv->SetSmartRefresh(kTRUE);
147   }
148 }
149
150 /**************************************************************************/
151
152 void ViewerList::SceneDestructing(Scene* scene)
153 {
154   for (List_i i=fChildren.begin(); i!=fChildren.end(); ++i)
155   {
156     Viewer* viewer = (Viewer*) *i;
157     List_i j = viewer->BeginChildren();
158     while (j != viewer->EndChildren())
159     {
160       SceneInfo* sinfo = (SceneInfo*) *j;
161       ++j;
162       if (sinfo->GetScene() == scene)
163         gReve->RemoveRenderElement(sinfo, viewer);
164     }
165   }
166 }