]>
Commit | Line | Data |
---|---|---|
5a5a1232 | 1 | #include "RGTopFrame.h" |
2 | ||
3 | #include "RGBrowser.h" | |
4 | #include "RGEditor.h" | |
5 | #include "VSDSelector.h" | |
6 | ||
7 | #include <Reve/RenderElement.h> | |
8 | ||
9 | #include <TGMenu.h> | |
10 | #include <TGTab.h> | |
11 | #include <TGToolBar.h> | |
12 | #include <TGLabel.h> | |
13 | #include <TGTextEntry.h> | |
14 | #include <TGSplitter.h> | |
15 | #include <TRootEmbeddedCanvas.h> | |
16 | ||
17 | #include <TGLSAViewer.h> | |
18 | #include <TH1F.h> | |
19 | #include <TView.h> | |
20 | ||
21 | #include <TROOT.h> | |
22 | #include <TFile.h> | |
23 | #include <TStyle.h> | |
24 | #include <TPad.h> | |
25 | #include <TCanvas.h> | |
26 | #include <TSystem.h> | |
27 | #include <TRint.h> | |
28 | #include <TVirtualX.h> | |
29 | #include <TPolyLine3D.h> | |
30 | #include <TPolyMarker3D.h> | |
31 | #include <TEnv.h> | |
32 | #include <TStyle.h> | |
33 | #include <KeySymbols.h> | |
34 | #include "TVirtualGL.h" | |
35 | #include "TPluginManager.h" | |
36 | ||
37 | #include <iostream> | |
38 | ||
39 | using namespace Reve; | |
40 | using namespace Reve; | |
41 | ||
42 | Reve::RGTopFrame* gReve = 0; | |
43 | ||
44 | namespace { | |
45 | ||
46 | enum RGBrowserMT { | |
47 | M_LAYOUT_1, | |
48 | M_LAYOUT_2, | |
49 | M_LAYOUT_3 | |
50 | }; | |
51 | ||
52 | const char *xpm_names[] = { | |
53 | "lay1.xpm", | |
54 | "lay2.xpm", | |
55 | "lay3.xpm", | |
56 | 0 | |
57 | }; | |
58 | ||
59 | ToolBarData_t tb_data[] = { | |
60 | { "", "Standard list layout", kFALSE, M_LAYOUT_1, NULL }, | |
61 | { "", "TParticle latout", kFALSE, M_LAYOUT_2, NULL }, | |
62 | { "", "TGeo layout", kFALSE, M_LAYOUT_3, NULL }, | |
63 | { NULL, NULL, 0, 0, NULL } | |
64 | }; | |
65 | ||
66 | } // unnamed namespace | |
67 | ||
68 | /**************************************************************************/ | |
69 | ||
70 | ||
71 | void RGTopFrame::Init(){ | |
915dabe1 | 72 | fCC = 0; |
73 | fHistoCanvas = 0; | |
74 | fSelector = 0; | |
75 | fBrowser = 0; | |
76 | fStatusBar = 0; | |
77 | fVSDFile = ""; | |
78 | ||
79 | fEditor = 0; | |
80 | ||
81 | fCurrentEvent = 0; | |
82 | fCurrentEventLTI = 0; | |
83 | fGeometryLTI = 0; | |
5a5a1232 | 84 | |
85 | fRedrawDisabled = false; | |
86 | fTimerActive = false; | |
87 | fRedrawTimer.Connect("Timeout()", "Reve::RGTopFrame", this, "DoRedraw3D()"); | |
88 | } | |
89 | ||
90 | ||
91 | RGTopFrame::RGTopFrame(const TGWindow *p, UInt_t w, UInt_t h, LookType_e look) | |
92 | : TGMainFrame(p, w, h) | |
93 | { | |
94 | Init(); | |
95 | TGLayoutHints *fL0 = new TGLayoutHints(kLHintsCenterX |kLHintsCenterY | kLHintsExpandY| kLHintsExpandX); | |
96 | TGLayoutHints *fL1 = new TGLayoutHints(kLHintsCenterX |kLHintsCenterY | kLHintsExpandY| kLHintsExpandX,2,0,2,2); | |
97 | TGLayoutHints* fL2 = new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX | kLHintsExpandY, | |
98 | 2, 2, 2, 2); | |
99 | TGCompositeFrame* fMainFrame = new TGCompositeFrame(this, w, h,kHorizontalFrame | kRaisedFrame); | |
100 | fMainFrame->SetCleanup(kDeepCleanup); | |
101 | TGVerticalFrame* fV2 = new TGVerticalFrame(fMainFrame, GetWidth()-40, GetHeight()-40, kSunkenFrame); | |
102 | ||
103 | fMainFrame->AddFrame(fV2, fL1); | |
104 | ||
105 | // ??? TGCanvas* fCanvasWindow = new TGCanvas(fV2,w,h); | |
106 | TGTab* fDisplayFrame = new TGTab(fV2, GetWidth(), GetHeight()); | |
107 | ||
108 | // browser tab | |
109 | TGCompositeFrame* tFrame1 = fDisplayFrame->AddTab("Object Browser"); | |
110 | fBrowser = new RGBrowser(tFrame1, w, h); | |
111 | tFrame1->AddFrame(fBrowser, fL2); | |
112 | ||
113 | // tree selection tab | |
114 | TGCompositeFrame* tFrame2 = fDisplayFrame->AddTab("Tree Selections"); | |
115 | fSelector = new VSDSelector(fBrowser->GetListTree(), tFrame2); | |
116 | ||
117 | // canvas | |
118 | Reve::PushPad(); | |
119 | TGCompositeFrame* tFrame3 = fDisplayFrame->AddTab("Canvas"); | |
120 | TRootEmbeddedCanvas* fEmbeddedCanvas3 = new TRootEmbeddedCanvas("fEmbeddedCanvas3", tFrame3, 580, 360); | |
121 | tFrame3->AddFrame(fEmbeddedCanvas3, fL2); | |
122 | fEmbeddedCanvas3->GetCanvas()->SetBorderMode(0); | |
123 | fCC = fEmbeddedCanvas3->GetCanvas(); | |
124 | // fCC->SetFillColor(1); | |
5a5a1232 | 125 | Reve::PopPad(); |
126 | ||
5a5a1232 | 127 | // histo canvas |
128 | TGCompositeFrame* frame4 = fDisplayFrame->AddTab("HistoCanvas"); | |
129 | TRootEmbeddedCanvas* ecanvas4 = new TRootEmbeddedCanvas("HistoCanvas", frame4, 580, 360); | |
130 | frame4->AddFrame(ecanvas4, fL2); | |
131 | fHistoCanvas = ecanvas4->GetCanvas(); | |
132 | fHistoCanvas->SetBorderMode(0); | |
133 | ||
5a5a1232 | 134 | fV2->AddFrame(fDisplayFrame, fL0); |
135 | AddFrame(fMainFrame, fL0); | |
136 | ||
137 | // Create status bar | |
138 | Int_t parts[] = {45, 45, 10}; | |
139 | fStatusBar = new TGStatusBar(this, 50, 10, kHorizontalFrame); | |
140 | fStatusBar->SetParts(parts, 3); | |
141 | TGLayoutHints* fL6 = new TGLayoutHints(kLHintsBottom| kLHintsExpandX, 0, 0, 0, 0); | |
142 | AddFrame(fStatusBar, fL6); | |
143 | fStatusBar->SetText("GUI created", 0); | |
144 | ||
145 | MapSubwindows(); | |
146 | ||
147 | /**************************************************************************/ | |
148 | /**************************************************************************/ | |
149 | ||
150 | fEditor = new RGEditor(fCC); | |
151 | fEditor->GetCan()->ChangeOptions(0); | |
152 | ||
153 | switch(look) { | |
154 | case LT_Classic: { | |
155 | fBrowser->SetupClassicLook(); | |
156 | // Need push/pop pad around here? Not. | |
157 | fCC->GetViewer3D("ogl"); | |
158 | break; | |
159 | } | |
160 | ||
161 | case LT_Editor: { | |
162 | fBrowser->SetupEditorLook(fEditor); | |
163 | fCC->GetViewer3D("ogl"); | |
164 | break; | |
165 | } | |
166 | ||
167 | case LT_GLViewer: { | |
168 | printf("LT_GLViewer this option currently somewhat broken!\n"); | |
169 | fBrowser->SetupGLViewerLook(fEditor, fCC); | |
170 | printf("Crap1 %d %d\n", GetWidth(), GetHeight()); | |
171 | break; | |
172 | } | |
173 | ||
174 | default: { | |
175 | printf("RGTopFrame unknown look-type, ignoring.\n"); | |
176 | break; | |
177 | } | |
178 | } | |
179 | ||
180 | TGLViewer* glv = dynamic_cast<TGLViewer*>(fCC->GetViewer3D()); | |
181 | if(glv) { | |
182 | glv->SetSmartRefresh(true); | |
183 | } | |
184 | ||
185 | /**************************************************************************/ | |
186 | /**************************************************************************/ | |
187 | ||
188 | fGeometryLTI = GetListTree()->AddItem(0, "Geometry"); | |
189 | GetListTree()->OpenItem(fGeometryLTI); | |
190 | ||
191 | Resize(GetDefaultSize()); // this is used here to init layout algorithm | |
192 | SetWindowName("Reve"); | |
193 | MapWindow(); | |
194 | ||
195 | fEditor->DisplayObject(0); | |
196 | ||
197 | gSystem->ProcessEvents(); | |
198 | } | |
199 | ||
200 | /**************************************************************************/ | |
201 | ||
202 | TGListTree* RGTopFrame::GetListTree() | |
203 | { | |
204 | return fBrowser->GetListTree(); | |
205 | } | |
206 | ||
207 | TGListTreeItem* RGTopFrame::GetEventTreeItem() | |
208 | { | |
209 | // return fBrowser->GetListTree()->FindItemByPathname("Event"); | |
210 | return fCurrentEventLTI; | |
211 | } | |
212 | ||
213 | TGListTreeItem* RGTopFrame::GetGlobalTreeItem() | |
214 | { | |
215 | return fGeometryLTI; | |
216 | } | |
217 | ||
218 | /**************************************************************************/ | |
219 | // Editor | |
220 | /**************************************************************************/ | |
221 | ||
222 | void RGTopFrame::EditRenderElement(RenderElement* rnr_element) | |
223 | { | |
224 | static const Exc_t eH("RGTopFrame::EditRenderElement "); | |
225 | ||
226 | TObject* tobj = 0; | |
092578a7 | 227 | if(rnr_element) tobj = rnr_element->GetObject(); |
5a5a1232 | 228 | fEditor->DisplayObject(tobj); |
229 | } | |
230 | ||
231 | /**************************************************************************/ | |
232 | // 3D Pad management | |
233 | /**************************************************************************/ | |
234 | ||
235 | void RGTopFrame::RegisterRedraw3D() | |
236 | { | |
237 | fRedrawTimer.Start(0, kTRUE); | |
238 | fTimerActive = true; | |
239 | } | |
240 | ||
241 | void RGTopFrame::DoRedraw3D() | |
242 | { | |
243 | // printf("RGTopFrame::DoRedraw3D redraw triggered\n"); | |
244 | fCC->Modified(); | |
245 | fCC->Update(); | |
246 | fTimerActive = false; | |
247 | } | |
248 | ||
249 | /**************************************************************************/ | |
250 | ||
251 | int RGTopFrame::SpawnGuiAndRun(int argc, char **argv) | |
252 | { | |
253 | LookType_e revemode = LT_Editor; | |
254 | if(argc >= 3 && strcmp(argv[1], "-revemode")==0) { | |
255 | LookType_e m = LookType_e(atoi(argv[2])); | |
256 | if(m >= LT_Classic && m <= LT_GLViewer) | |
257 | revemode = m; | |
258 | printf("revemode = %d\n", revemode); | |
259 | } | |
260 | ||
261 | TRint theApp("App", &argc, argv); | |
262 | Int_t w = 800; | |
263 | Int_t h = 600; | |
264 | ||
265 | gReve = new RGTopFrame(gClient->GetRoot(), w, h, revemode); | |
266 | run_loop: | |
267 | try { | |
268 | theApp.Run(); | |
269 | } | |
270 | catch(std::string exc) { | |
271 | gReve->GetStatusBar()->SetText(exc.c_str()); | |
272 | goto run_loop; | |
273 | } | |
274 | return 0; | |
275 | } | |
276 | ||
277 | /**************************************************************************/ | |
278 | /**************************************************************************/ | |
279 | ||
280 | TGListTreeItem* RGTopFrame::AddEvent(TObject* event) | |
281 | { | |
092578a7 | 282 | fCurrentEvent = event; |
283 | RenderElementObjPtr* rnrEv = new RenderElementObjPtr(event); | |
284 | fCurrentEventLTI = rnrEv->AddIntoListTree(GetListTree(), 0); | |
5a5a1232 | 285 | GetListTree()->OpenItem(fCurrentEventLTI); |
286 | return fCurrentEventLTI; | |
287 | } | |
288 | ||
289 | TGListTreeItem* RGTopFrame::AddRenderElement(RenderElement* rnr_element) | |
290 | { | |
092578a7 | 291 | return AddRenderElement(GetEventTreeItem(), rnr_element); |
5a5a1232 | 292 | } |
293 | ||
294 | TGListTreeItem* RGTopFrame::AddRenderElement(TGListTreeItem* parent, | |
295 | RenderElement* rnr_element) | |
296 | { | |
297 | static const Exc_t eH("RGTopFrame::AddRenderElement "); | |
298 | ||
299 | // Here could route rnr-element to several browsers/pads. | |
300 | ||
301 | TGListTreeItem* newitem = | |
302 | rnr_element->AddIntoListTree(GetListTree(), parent); | |
303 | NotifyBrowser(); | |
304 | ||
305 | return newitem; | |
306 | } | |
307 | ||
308 | TGListTreeItem* RGTopFrame::AddGlobalRenderElement(RenderElement* rnr_element) | |
309 | { | |
092578a7 | 310 | return AddGlobalRenderElement(GetGlobalTreeItem(), rnr_element); |
5a5a1232 | 311 | } |
312 | ||
092578a7 | 313 | TGListTreeItem* RGTopFrame::AddGlobalRenderElement(TGListTreeItem* parent, |
5a5a1232 | 314 | RenderElement* rnr_element) |
315 | { | |
316 | static const Exc_t eH("RGTopFrame::AddGlobalRenderElement "); | |
317 | ||
318 | // Here could route rnr-element to several browsers/pads. | |
319 | ||
320 | TGListTreeItem* newitem = | |
092578a7 | 321 | rnr_element->AddIntoListTree(GetListTree(), parent); |
5a5a1232 | 322 | NotifyBrowser(); |
323 | ||
324 | return newitem; | |
325 | } | |
326 | ||
327 | /**************************************************************************/ | |
328 | ||
329 | void RGTopFrame::DrawRenderElement(RenderElement* rnr_element, TVirtualPad* pad) | |
330 | { | |
331 | if(pad == 0) pad = GetCC(); | |
332 | { Reve::PadHolder pHolder(false, pad); | |
333 | rnr_element->GetObject()->Draw(); | |
334 | } | |
335 | Redraw3D(); | |
336 | } | |
337 | ||
338 | /**************************************************************************/ | |
339 | ||
340 | void RGTopFrame::RenderElementChecked(TObject* obj, Bool_t state) | |
341 | { | |
092578a7 | 342 | // Item's user-data is blindly casted into TObject. |
343 | // We recast it blindly back into the render element. | |
344 | ||
345 | RenderElement* rnrEl = (RenderElement*) obj; | |
346 | rnrEl->SetRnrElement(state); | |
5a5a1232 | 347 | } |
348 | ||
349 | /**************************************************************************/ | |
350 | ||
351 | void RGTopFrame::NotifyBrowser(TGListTreeItem* parent) | |
352 | { | |
353 | TGListTree* l_tree = GetListTree(); | |
354 | if(parent) | |
355 | l_tree->OpenItem(parent); | |
356 | l_tree->GetClient()->NeedRedraw(l_tree); | |
357 | } | |
358 | ||
359 | /**************************************************************************/ | |
360 | // GeoManager registration | |
361 | /**************************************************************************/ | |
362 | ||
363 | TGeoManager* RGTopFrame::GetGeometry(const TString& filename) | |
364 | { | |
365 | static const Exc_t eH("RGTopFrame::GetGeometry "); | |
366 | ||
367 | TString exp_filename = filename; | |
368 | gSystem->ExpandPathName(exp_filename); | |
369 | printf("%s loading: '%s' -> '%s'.\n", eH.Data(), | |
370 | filename.Data(), exp_filename.Data()); | |
371 | ||
372 | std::map<TString, TGeoManager*>::iterator g = fGeometries.find(filename); | |
373 | if(g != fGeometries.end()) { | |
374 | return g->second; | |
375 | } else { | |
376 | if(gSystem->AccessPathName(exp_filename, kReadPermission)) | |
377 | throw(eH + "file '" + exp_filename + "' not readable."); | |
378 | gGeoManager = 0; | |
379 | TGeoManager::Import(filename); | |
380 | if(gGeoManager == 0) | |
381 | throw(eH + "GeoManager import failed."); | |
382 | gGeoManager->GetTopVolume()->VisibleDaughters(1); | |
383 | ||
384 | // Import colors exported by Gled, if they exist. | |
385 | { | |
386 | TFile f(exp_filename, "READ"); | |
387 | TObjArray* collist = (TObjArray*) f.Get("ColorList"); | |
388 | f.Close(); | |
389 | if(collist != 0) { | |
390 | TSeqCollection* glist = gROOT->GetListOfColors(); | |
391 | glist->Clear(); | |
392 | glist->AddAll(collist); | |
393 | } | |
394 | } | |
395 | ||
396 | fGeometries[filename] = gGeoManager; | |
397 | return gGeoManager; | |
398 | } | |
399 | } |