ROOTANA
Loading...
Searching...
No Matches
TMainDisplayWindow.cxx
Go to the documentation of this file.
1#include <iostream>
2#include <cstdlib>
3
4#include <TGFileDialog.h>
6#include <TObject.h>
8
9#ifndef NO_CINT
11#endif
12
13
14
15TMainDisplayWindow::TMainDisplayWindow(const TGWindow *p,UInt_t w,UInt_t h, bool isOffline, bool updatingBasedSeconds)
16
17{
18 fIsOffline = isOffline;
19 fProcessingPaused = false;
22 fTBrowser = 0;
26
27 // Create a main frame
28 fMain = new TGMainFrame(p,w,h);
29
30 fTab = new TGTab(fMain);
31 fTab->Resize(fTab->GetDefaultSize());
32 fMain->AddFrame(fTab, new TGLayoutHints(kLHintsLeft | kLHintsTop,2,2,2,2));
33 fTab->MoveResize(2,2,300,300);
34
35 // _______________________________________________________________________________________
36 // Set up buttons for bottom of mainframe.
37
38 // Create a horizontal frame widget with buttons
39 fHframe = new TGHorizontalFrame(fMain,200,40);
40
41
42 // Set different options for bottom, depending on if using offline or online.
43 if(fIsOffline){
44
45 fNextButton = new TGTextButton(fHframe,"&Next");
46 fHframe->AddFrame(fNextButton, new TGLayoutHints(kLHintsCenterX,5,5,3,4));
47
48 if(iem_t::instance()->IsEnabled()){
49 fNextInterestingButton = new TGTextButton(fHframe,"&Next Interesting");
50 fHframe->AddFrame(fNextInterestingButton, new TGLayoutHints(kLHintsCenterX,5,5,3,4));
51 }
52
53 }else{
54
55 fNumberSkipEventButton = new TGNumberEntry(fHframe, 0, 9,999, TGNumberFormat::kNESInteger,
56 TGNumberFormat::kNEANonNegative,
57 TGNumberFormat::kNELLimitMinMax,
58 1, 100000);
59 fNumberSkipEventButton->SetIntNumber(5);
60 fHframe->AddFrame(fNumberSkipEventButton, new TGLayoutHints(kLHintsTop | kLHintsLeft, 5, 5, 5, 5));
61
62 if(updatingBasedSeconds){
63 TGLabel *labelEv = new TGLabel(fHframe, "Refresh each Xth second");
64 fHframe->AddFrame(labelEv, new TGLayoutHints(kLHintsTop | kLHintsLeft, 5, 5, 5, 5));
65 }else{
66 TGLabel *labelEv = new TGLabel(fHframe, "Plot every Xth events");
67 fHframe->AddFrame(labelEv, new TGLayoutHints(kLHintsTop | kLHintsLeft, 5, 5, 5, 5));
68 }
69 }
70
71
72 // Add the histogram reset button.
73 fResetButton = new TGTextButton(fHframe,"&Reset Histograms");
74 fHframe->AddFrame(fResetButton, new TGLayoutHints(kLHintsCenterX,5,5,3,4));
75
76 // Add pause button
77 if(!fIsOffline){
78 fPauseButton = new TGTextButton(fHframe,"&Pause updates");
79 fHframe->AddFrame(fPauseButton, new TGLayoutHints(kLHintsCenterX,5,5,3,4));
80 fPauseButton->Connect("Clicked()", "TMainDisplayWindow", this, "PauseResumeButtonAction()");
81
82 fNextButton = new TGTextButton(fHframe,"&Next");
83 fHframe->AddFrame(fNextButton, new TGLayoutHints(kLHintsCenterX,5,5,3,4));
84 fNextButton->SetEnabled(false);
85
86 if(iem_t::instance()->IsEnabled()){
87 fNextInterestingButton = new TGTextButton(fHframe,"&Next Interesting");
88 fHframe->AddFrame(fNextInterestingButton, new TGLayoutHints(kLHintsCenterX,5,5,3,4));
89 fNextInterestingButton->SetEnabled(false);
90 }
91 }
92
93 // Add buttons to save current pad or current canvas.
94 fSavePadButton = new TGTextButton(fHframe,"&Save Active Pad");
95 fSavePadButton->Connect("Clicked()", "TMainDisplayWindow", this, "SavePadButtonAction()");
96 fHframe->AddFrame(fSavePadButton, new TGLayoutHints(kLHintsCenterX,5,5,3,4));
97
98 fSaveCanvasButton = new TGTextButton(fHframe,"&Save Canvas");
99 fSaveCanvasButton->Connect("Clicked()", "TMainDisplayWindow", this, "SaveCanvasButtonAction()");
100 fHframe->AddFrame(fSaveCanvasButton, new TGLayoutHints(kLHintsCenterX,5,5,3,4));
101
102 fOpenNewTBrowser = new TGTextButton(fHframe,"&Open TBrowser");
103 fOpenNewTBrowser->Connect("Clicked()", "TMainDisplayWindow", this, "NewTBrowserButtonAction()");
104 fHframe->AddFrame(fOpenNewTBrowser, new TGLayoutHints(kLHintsCenterX,5,5,3,4));
105
106 // Disable the save buttons if online
107 if(!fIsOffline){
108 fSavePadButton->SetEnabled(false);
109 fSaveCanvasButton->SetEnabled(false);
110 fOpenNewTBrowser->SetEnabled(false);
111 }
112
113 if(fIsOffline){
114 fFreeRunningButton = new TGTextButton(fHframe,"&Free Running");
115 fHframe->AddFrame(fFreeRunningButton, new TGLayoutHints(kLHintsCenterX,5,5,3,4));
116 fFreeRunningButton->Connect("Clicked()", "TMainDisplayWindow", this, "FreeRunningButtonAction()");
117 }
118
119
120 fQuitButton = new TGTextButton(fHframe,"&Quit");
121 fHframe->AddFrame(fQuitButton, new TGLayoutHints(kLHintsCenterX,5,5,3,4));
122
123
124 fMain->AddFrame(fHframe, new TGLayoutHints(kLHintsNormal,2,2,2,2));
125
126}
127
128
129
130/// This resizing is still not working right!
131/// You can easily get a situation where resizing doesn't work. Argh.
133
134 // Resize each part of the tab.
135 for(int itab = 0; itab < fTab->GetNumberOfTabs() ; itab++){
136
137 TGCompositeFrame* frame = fTab->GetTabContainer(itab);
138
139 // This is awkward. Each composite frame actually has a bunch of elements.
140 // Try to resize all the elements that are TGFrameElements.
141 // This seems to work if the added frame is a TRootEmbeddedCanvas; not sure
142 // otherwise.
143 TList* mylist = frame->GetList();
144
145 TIter next(mylist);
146 while (TObject *obj = next()){
147
148
149 TGFrameElement *frame_element = dynamic_cast<TGFrameElement*>(obj);
150
151 if(frame_element){
152 frame_element->fFrame->Resize((frame_element->fFrame->GetDefaultSize().fWidth)
153 *(fMain->GetSize().fWidth)/(fMain->GetDefaultSize().fWidth),
154 (frame_element->fFrame->GetDefaultSize().fHeight)
155 *(fMain->GetSize().fHeight)/(fMain->GetDefaultSize().fHeight));
156
157
158 TGTab *this_tab = dynamic_cast<TGTab*>(frame_element->fFrame);
159 if(this_tab){
160 // Resize each part of the tab.
161 for(int jtab = 0; jtab < this_tab->GetNumberOfTabs() ; jtab++){
162
163 TGCompositeFrame* frame2 = this_tab->GetTabContainer(jtab);
164
165 // This is awkward. Each composite frame actually has a bunch of elements.
166 // Try to resize all the elements that are TGFrameElements.
167 // This seems to work if the added frame is a TRootEmbeddedCanvas; not sure
168 // otherwise.
169 TList* mylist2 = frame2->GetList();
170
171 TIter next2(mylist2);
172 while (TObject *obj2 = next2()){
173
174
175 TGFrameElement *frame_element = dynamic_cast<TGFrameElement*>(obj2);
176
177 if(frame_element){
178 frame_element->fFrame->Resize((frame_element->fFrame->GetDefaultSize().fWidth)
179 *(fMain->GetSize().fWidth)/(fMain->GetDefaultSize().fWidth),
180 (frame_element->fFrame->GetDefaultSize().fHeight)
181 *(fMain->GetSize().fHeight)/(fMain->GetDefaultSize().fHeight));
182 }
183 }
184 }
185
186 }
187
188
189 }else
190 std::cout << "TMainDisplayWindow::ResetSize:: Dynamic cast of obj to TGFrameElement failed." << std::endl;
191
192
193 }
194
195
196 }
197
198}
199
201
202 TGCompositeFrame* frame = fTab->GetTabContainer(index);
203
204 TList* mylist = frame->GetList();
205
206 TIter next(mylist);
207 while (TObject *obj = next()){
208 TGFrameElement *frame_element = dynamic_cast<TGFrameElement*>(obj);
209
210 if(frame_element){
211 TGTab *this_tab = dynamic_cast<TGTab*>(frame_element->fFrame);
212 if(this_tab) return this_tab;
213 }
214 }
215
216 return 0;
217
218}
219
220std::pair<int,int> TMainDisplayWindow::AddSingleTab(std::string name, TGTab * tab, int mainTabIndex){
221
222
223 // Add a new tab element, of type TGCompositeFrame
224 TGCompositeFrame *compositeFrame;
225 if(tab==0)
226 compositeFrame = fTab->AddTab(name.c_str());
227 else
228 compositeFrame = tab->AddTab(name.c_str());
229 compositeFrame->SetLayoutManager(new TGVerticalLayout(compositeFrame));
230
231 // Add a canvas within that composite frame.
232 char cname[500];
233 std::pair<int,int> index;
234 if(tab ==0){
235 sprintf(cname,"Canvas_%i",fTab->GetNumberOfTabs() - 1);
236 index.first = fTab->GetNumberOfTabs() - 1;
237 index.second = - 1;
238 }else{
239 sprintf(cname,"Canvas_%i_%i",mainTabIndex,tab->GetNumberOfTabs() - 1);
240 //sprintf(cname,"Canvas_%i_%i",fTab->GetNumberOfTabs() - 1,tab->GetNumberOfTabs() - 1);
241 index.first = mainTabIndex;
242 index.second = tab->GetNumberOfTabs() - 1;
243 }
244 TRootEmbeddedCanvas *embed_canvas = new TRootEmbeddedCanvas(cname, compositeFrame,
246 compositeFrame->AddFrame(embed_canvas, new TGLayoutHints(kLHintsTop | kLHintsExpandX,5,5,5,0));
247
248 return index;
249
250}
251
252std::pair<int,int> TMainDisplayWindow::AddCanvas(std::string subtabname, std::string tabname){
253
254 // If we want to add tab to main tab-list, tabname is empty
255 if(tabname.empty()){
256 std::cout << "Adding new canvas in tab named '" << subtabname << "'" << std::endl;
257 return AddSingleTab(subtabname);
258 }
259
260 // Otherwise we try to find an existing tab with that name.
261 TGTab *subtab = 0;
262 int mainTabIndex = 0;
263 for(int itab = 0; itab < fTab->GetNumberOfTabs() ; itab++){
264
265 if(GetTabName(fTab,itab).compare(tabname) == 0){
266 subtab = GetSubTab(itab);
267 mainTabIndex = itab;
268 }
269 }
270
271 if(subtab){
272 std::cout << "Adding new canvas in sub-tab named '" << subtabname << "' of tab " << tabname << std::endl;
273 return AddSingleTab(subtabname,subtab,mainTabIndex);
274 }
275
276 // We didn't find an existing sub-tab; create it.
277 TGCompositeFrame *compositeFrame = fTab->AddTab(tabname.c_str());
278 compositeFrame->SetLayoutManager(new TGVerticalLayout(compositeFrame));
279 subtab = new TGTab(compositeFrame);
280 compositeFrame->AddFrame(subtab, new TGLayoutHints(kLHintsLeft | kLHintsTop,2,2,2,2));
281
282 std::cout << "Creating new tab named '"<< tabname <<"'. "
283 << "Creating a new canvas in sub-tab named '" << subtabname << "'" << std::endl;
284 return AddSingleTab(subtabname,subtab,fTab->GetNumberOfTabs()-1);
285
286
287}
288
290 std::pair<int,int> tmp;
291 tmp.first = fTab->GetCurrent();
292 TGTab *subtab = GetSubTab(fTab->GetCurrent());
293 if(subtab)
294 tmp.second = subtab->GetCurrent();
295 else
296 tmp.second = -1;
297
298 return tmp;
299
300}
301
302
304
305 fMain->MapSubwindows();
306 // Initialize the layout algorithm
307 fMain->Resize(fMain->GetDefaultSize());
308 // Map main frame
309 fMain->MapWindow();
310
311
312}
313
314/// Pull the embedded canvas out of the compositeframe.
315TRootEmbeddedCanvas* GetTRootEmbeddedCanvasFromTGCompositeFrame(TGCompositeFrame* frame){
316
317 if(!frame) return 0;
318
319 TList* mylist = frame->GetList();
320
321 TIter next(mylist);
322 while (TObject *obj = next()){
323
324 TGFrameElement *frame_element = dynamic_cast<TGFrameElement*>(obj);
325
326 if(frame_element){
327
328 TGFrame* frame = frame_element->fFrame;
329 TRootEmbeddedCanvas *embed_canvas = dynamic_cast<TRootEmbeddedCanvas*>(frame);
330
331 if(embed_canvas){
332 return embed_canvas;
333 }
334 }
335 }
336
337 return 0;
338
339}
340
341TGCompositeFrame* TMainDisplayWindow::GetCompositeFrame(std::pair<int,int> index){
342
343 TGTab *subtab = GetSubTab(index.first);
344 TGCompositeFrame* frame;
345 if(subtab)
346 frame = subtab->GetTabContainer(index.second);
347 else
348 frame = fTab->GetTabContainer(index.first);
349 return frame;
350
351}
352
354 TGTab *subtab = GetSubTab(fTab->GetCurrent());
355 TGCompositeFrame* frame;
356 if(subtab)
357 frame = subtab->GetTabContainer(subtab->GetCurrent());
358 else
359 frame = fTab->GetTabContainer(fTab->GetCurrent());
360 return frame;
361}
362
364
365 TGCompositeFrame* frame = GetCurrentCompositeFrame();
367
368}
369
370
371TRootEmbeddedCanvas* TMainDisplayWindow::GetEmbeddedCanvas(const char *name){
372
373
374 // Complicated. Need to loop over all possible tabs and sub-tabs, looking for
375 // first match.
376 for(int itab = 0; itab < fTab->GetNumberOfTabs() ; itab++){
377
378 if(GetTabName(fTab, itab).compare(name) == 0){
379 TGCompositeFrame* frame = fTab->GetTabContainer(itab);
381 }
382
383 TGTab *subtab = GetSubTab(itab);
384 if(subtab){
385 for (int isubtab = 0; isubtab < subtab->GetNumberOfTabs() ; isubtab++){
386
387 //std::cout << itab << " " << isubtab << " Name! " << GetTabName(subtab, isubtab) << std::endl;
388 if(GetTabName(subtab, isubtab).compare(name) == 0){
389 TGCompositeFrame* frame = subtab->GetTabContainer(isubtab);
391 }
392 }
393 }
394 }
395
396 return 0;
397
398
399}
400
401
402
403
404
405TCanvas* TMainDisplayWindow::GetCanvas(const char *name){
406 TRootEmbeddedCanvas* embed = GetEmbeddedCanvas(name);
407 if(embed) return embed->GetCanvas();
408
409 return 0;
410}
411
412
413TGTab* TMainDisplayWindow::GetTab(std::pair<int,int> tabindex){
414
415 TGTab *tab = 0;
416 if(tabindex.second == -1)
417 tab = fTab;
418 else{
419 tab = GetSubTab(tabindex.first);
420 }
421
422 if(!tab) return 0;
423 return tab;
424
425}
426std::string TMainDisplayWindow::GetTabName(TGTab *tab, int index){
427
428 TIter nextTab(tab->GetList());
429 nextTab(); // Skip the first element. This is the overall TGCompositeFrame, not the tabbed one.
430
431 // Get the index for the current canvas
432 if(index < 0)
433 index = tab->GetCurrent();
434 TGFrameElement *el;
435 TGTabElement *tabel = 0;
436 //TGCompositeFrame *comp = 0;
437 // Loop over the number of tabs, until we find the right one.
438 for(int i = 0; i <= index; i++){
439 el = (TGFrameElement *) nextTab();
440 tabel = (TGTabElement *) el->fFrame;
441 el = (TGFrameElement *) nextTab();
442 //comp = (TGCompositeFrame *) el->fFrame;
443 }
444 if(tabel){
445 return std::string(*tabel->GetText());
446 }
447
448 return std::string("not found");
449}
450
452
453 std::pair<int,int> tabindex = GetCurrentTabIndex();
454 TGTab *tab = GetTab(tabindex);
455 if(!tab || tab->GetNumberOfTabs() == 0){
456 return std::string("not found");
457 }
458 return GetTabName(tab);
459
460
461}
462
463
465
466 std::cout << "Destructor! " << std::endl;
467 delete fMain;
468 delete fTab;
469
470}
471
472
473
474const char *filetypes[] = { "GIF files", "*.gif",
475 "JPG files", "*.jpg",
476 "PNG files", "*.png",
477 "EPS files", "*.eps",
478 0, 0 };
479
481 static TString dir(".");
482 TGFileInfo fi;
483 fi.fFileTypes = filetypes;
484 fi.fIniDir = StrDup(dir);
485 new TGFileDialog(gClient->GetRoot(), fMain, kFDSave, &fi);
486 printf("Open file: %s (dir: %s)\n", fi.fFilename,
487 fi.fIniDir);
488
489 // Resize pad while saving; to get good image resolution.fTab
490 double xl = gPad->GetXlowNDC(), xh = gPad->GetXlowNDC() + gPad->GetWNDC();
491 double yl = gPad->GetYlowNDC(), yh = gPad->GetYlowNDC() + gPad->GetHNDC();
492
493 gPad->SetPad(0,0,1.0,1.0);
494 gPad->SaveAs(fi.fFilename);
495 gPad->SetPad(xl,yl,xh,yh);
496 gPad->Update();
497
498}
499
501
502 static TString dir(".");
503 TGFileInfo fi;
504 fi.fFileTypes = filetypes;
505 fi.fIniDir = StrDup(dir);
506 new TGFileDialog(gClient->GetRoot(), fMain, kFDSave, &fi);
507 printf("Open file: %s (dir: %s)\n", fi.fFilename,
508 fi.fIniDir);
509
510 gPad->GetCanvas()->SaveAs(fi.fFilename);
511
512}
513
517
519
521 fProcessingPaused = false;
522 fPauseButton->SetText(TString("Pause updates"));
523 fSavePadButton->SetEnabled(false);
524 fSaveCanvasButton->SetEnabled(false);
525 fOpenNewTBrowser->SetEnabled(false);
526 fNextButton->SetEnabled(false);
528 }else{
529 fProcessingPaused = true;
530 fPauseButton->SetText(TString("Free Running"));
531 fSavePadButton->SetEnabled(true);
532 fSaveCanvasButton->SetEnabled(true);
533 fOpenNewTBrowser->SetEnabled(true);
534 fNextButton->SetEnabled(true);
536 }
537}
538
539
541
544 fFreeRunningButton->SetText(TString("Free Running"));
545 fSavePadButton->SetEnabled(true);
546 fSaveCanvasButton->SetEnabled(true);
547 fOpenNewTBrowser->SetEnabled(true);
548 }else{
550 fFreeRunningButton->SetText(TString("Stop FreeRun"));
551 fSavePadButton->SetEnabled(false);
552 fSaveCanvasButton->SetEnabled(false);
553 fOpenNewTBrowser->SetEnabled(false);
554 }
555}
556
557
559
560
561 TGCompositeFrame* frame = fTab->GetTabContainer(i);
562
563 // This is awkward. Each composite frame actually has a bunch of elements,
564 // one of which might be a TGTab
565 TList* mylist = frame->GetList();
566
567 TIter next(mylist);
568
569 while (TObject *obj = next()){
570 TGFrameElement *frame_element = dynamic_cast<TGFrameElement*>(obj);
571 if(frame_element){
572 TGTab *this_tab = dynamic_cast<TGTab*>(frame_element->fFrame);
573 if(this_tab){
574 return this_tab->GetNumberOfTabs();
575 }
576 }
577 }
578
579 // didn't find sub-tab, so return 0
580 return 0;
581}
ClassImp(TMainDisplayWindow) TMainDisplayWindow
TRootEmbeddedCanvas * GetTRootEmbeddedCanvasFromTGCompositeFrame(TGCompositeFrame *frame)
Pull the embedded canvas out of the compositeframe.
const char * filetypes[]
static TInterestingEventManager * instance()
std::pair< int, int > AddSingleTab(std::string name, TGTab *tab=0, int mainTabIndex=-1)
bool fProcessingFreeRunning
Is processing free-running? (offline)
std::string GetTabName(TGTab *tab, int index=-1)
TGTextButton * fNextInterestingButton
void SavePadButtonAction()
Method to call when 'save pad' button is pressed.
std::pair< int, int > GetCurrentTabIndex()
Return an pair<int> index for current tab/sub-tab;.
TGTextButton * fPauseButton
TMainDisplayWindow(const TGWindow *p, UInt_t w, UInt_t h, bool isOffline, bool updatingBasedSeconds)
TGTextButton * fOpenNewTBrowser
std::pair< int, int > AddCanvas(std::string subtabname, std::string tabname=std::string(""))
TCanvas * GetCanvas(const char *name)
Get a particular canvas based on canvas name.
void SaveCanvasButtonAction()
Method to call when 'save canvas' button is pressed.
std::string GetCurrentTabName()
Return the canvas name for the current tab.
bool fProcessingPaused
Is processing paused? (online)
TGTab * GetSubTab(int index)
TRootEmbeddedCanvas * GetEmbeddedCanvas(const char *name)
TRootEmbeddedCanvas * GetCurrentEmbeddedCanvas()
Return the current embedded canvas.
void FreeRunningButtonAction()
Method to call when 'free-running/resume' button is pressed.
TGTextButton * fSavePadButton
Buttons to make plots of current pad/canvas.
TGCompositeFrame * GetCompositeFrame(std::pair< int, int > index)
TGHorizontalFrame * fHframe
TGTextButton * fFreeRunningButton
TGTextButton * fResetButton
TGNumberEntry * fNumberSkipEventButton
TGCompositeFrame * GetCurrentCompositeFrame()
void PauseResumeButtonAction()
Method to call when 'pause/resume' button is pressed.
TGTextButton * fSaveCanvasButton