- Timestamp:
- 11/05/03 18:26:02 (21 years ago)
- Location:
- trunk/MagicSoft/Mars
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Mars/Changelog
r2476 r2477 3 3 2003/11/05: Wolfgang Wittek 4 4 5 * macros/CT1Analysis.C, macros/ONOFFCT1Analysis.C 5 * macros/CT1Analysis.C, macros/ONOFFCT1Analysis.C: 6 6 - current versions of the macros for the analysis of CT1 data 7 7 8 * manalysis/MMarquardt.[h,cc] 8 * manalysis/MMarquardt.[h,cc]: 9 9 - very pleliminary version of a class performing a minimization 10 10 using the Marquardt method … … 14 14 to the shower image using the maximum likelihood method 15 15 16 * mimage/M2dimFunction.[h,cc] 16 * mimage/M2dimFunction.[h,cc]: 17 17 - very pleliminary version of a container which contains the 18 18 parameters of the 2-dim function describing the shower image … … 58 58 - removed some obsolete IsUsed(idx) checks when filling the histogram 59 59 - ExecuteEvent now plots in the same canvas all the time 60 61 * mmain/MStatusDisplay.[h,cc]: 62 - added new data member fUserFrame 63 - added new member function AddUserFrame 64 - made call to ProcessEvent() and similar thread safe by 65 checking whether we run in the main thread or not. 66 - Set the progress bar range to (0,1) 67 - Added member function to set progress bar position 68 - updated comments 69 - added some workarounds for root bugs in TCanvas (sometimes 70 they call gPad->cd() indirectly when gPad==NULL) 71 - Fixed thread safety of UpdateTab() 72 - Fixed some crashes in case fTab==NULL 73 - Tried to make HandleConfigureNotify more flexible to allow 74 the new fUserFrame to work correctly - needs still some 75 investigations 76 - made fList a protected data member 77 - added new member function Update() 60 78 61 79 -
trunk/MagicSoft/Mars/mmain/MStatusDisplay.cc
r2416 r2477 72 72 #include <TDatime.h> // TDatime 73 73 #include <TRandom.h> // TRandom 74 #include <TThread.h> // TThread::Self() 74 75 #include <TBrowser.h> // TBrowser 75 76 #include <TObjArray.h> // TObjArray 76 77 #include <TPostScript.h> // TPostScript 77 78 #include <TRint.h> // gApplication, TRint::Class() 78 #include <TMethodCall.h> // TMethodCall 79 80 //#include <TRint.h> // gApplication, TRint::Class() 79 81 #include <TInterpreter.h> // gInterpreter 80 82 … … 282 284 // -------------------------------------------------------------------------- 283 285 // 286 // Adds an empty TGCompositeFrame which might be filled by the user 287 // 288 void MStatusDisplay::AddUserFrame() 289 { 290 TGLayoutHints *lay=new TGLayoutHints(kLHintsExpandX); 291 fList->Add(lay); 292 293 fUserFrame = new TGCompositeFrame(this, 1, 1); 294 AddFrame(fUserFrame, lay); 295 fList->Add(fUserFrame); 296 } 297 298 // -------------------------------------------------------------------------- 299 // 284 300 // Add the title tab 285 301 // … … 376 392 377 393 // make it visible 378 // FIXME: This is a workaround, because TApplication::Run is not thread safe against ProcessEvents 379 if (gApplication->InheritsFrom(TRint::Class())) 394 // FIXME: This is a workaround, because TApplication::Run is not 395 // thread safe against ProcessEvents. We assume, that if 396 // we are not in the Main-Thread ProcessEvents() is 397 // called by the TApplication Event Loop... 398 if (!TThread::Self()/*gApplication->InheritsFrom(TRint::Class())*/) 380 399 gClient->ProcessEventsFor(fTab); 381 400 } … … 425 444 // -------------------------------------------------------------------------- 426 445 // 427 // Add the progress bar to the GUI 446 // Add the progress bar to the GUI. The Progress Bar range is set to 447 // (0,1) as default. 428 448 // 429 449 void MStatusDisplay::AddProgressBar() … … 433 453 434 454 fBar=new TGHProgressBar(this); 455 fBar->SetRange(0, 1); 435 456 fBar->ShowPosition(); 436 457 AddFrame(fBar, laybar); … … 440 461 // -------------------------------------------------------------------------- 441 462 // 463 // Set the progress bar position between 0 and 1. The Progress bar range 464 // is assumed to be (0,1) 465 // 466 void MStatusDisplay::SetProgressBarPosition(Float_t p) 467 { 468 fBar->SetPosition(p); 469 } 470 471 // -------------------------------------------------------------------------- 472 // 442 473 // Adds the status bar to the GUI 443 474 // … … 446 477 fStatusBar = new TGStatusBar(this, 1, 1); 447 478 479 // 480 // Divide it like the 'Golden Cut' (goldener Schnitt) 448 481 // 449 482 // 1-a a … … 474 507 return; 475 508 fStatusBar->SetText(txt, 0); 476 // FIXME: This is a workaround, because TApplication::Run is not thread safe against ProcessEvents 477 if (gApplication->InheritsFrom(TRint::Class())) 509 510 // FIXME: This is a workaround, because TApplication::Run is not 511 // thread safe against ProcessEvents. We assume, that if 512 // we are not in the Main-Thread ProcessEvents() is 513 // called by the TApplication Event Loop... 514 if (!TThread::Self()/*gApplication->InheritsFrom(TRint::Class())*/) 478 515 gClient->ProcessEventsFor(fStatusBar); 479 516 } … … 488 525 return; 489 526 fStatusBar->SetText(txt, 1); 490 // FIXME: This is a workaround, because TApplication::Run is not thread safe against ProcessEvents 491 if (gApplication->InheritsFrom(TRint::Class())) 527 528 // FIXME: This is a workaround, because TApplication::Run is not 529 // thread safe against ProcessEvents. We assume, that if 530 // we are not in the Main-Thread ProcessEvents() is 531 // called by the TApplication Event Loop... 532 if (!TThread::Self()/*gApplication->InheritsFrom(TRint::Class())*/) 492 533 gClient->ProcessEventsFor(fStatusBar); 493 534 } … … 515 556 // 516 557 MStatusDisplay::MStatusDisplay(Long_t t) 517 : TGMainFrame(gClient ? gClient->GetRoot() : NULL, 1, 1), fT imer(this, t, kTRUE), fStatus(kLoopNone), fLog(&gLog), fLogIdx(-1), fLogTimer(this, 250, kTRUE), fLogBox(NULL), fIsLocked(0)558 : TGMainFrame(gClient ? gClient->GetRoot() : NULL, 1, 1), fTab(NULL), fTimer(this, t, kTRUE), fStatus(kLoopNone), fLog(&gLog), fLogIdx(-1), fLogTimer(this, 250, kTRUE), fLogBox(NULL), fIsLocked(0) 518 559 { 519 560 // … … 544 585 SetWMSizeHints(570, 480, 1280, 980, 1, 1); 545 586 Move(rand()%100+50, rand()%100+50); 546 //Resize(740, 600);547 587 Resize(570, 480); 548 588 … … 559 599 { 560 600 AddMenuBar(); 601 AddUserFrame(); 561 602 AddTabs(); 562 603 AddProgressBar(); … … 575 616 MapWindow(); 576 617 577 // FIXME: This is a workaround, because TApplication::Run is not thread safe against ProcessEvents 578 if (gApplication->InheritsFrom(TRint::Class())) 618 // FIXME: This is a workaround, because TApplication::Run is not 619 // thread safe against ProcessEvents. We assume, that if 620 // we are not in the Main-Thread ProcessEvents() is 621 // called by the TApplication Event Loop... 622 if (!TThread::Self()/*gApplication->InheritsFrom(TRint::Class())*/) 579 623 gSystem->ProcessEvents(); 580 624 } … … 587 631 MStatusDisplay::~MStatusDisplay() 588 632 { 633 #if ROOT_VERSION_CODE < ROOT_VERSION(3,10,01) 634 fTab = NULL; // See HandleEvent 635 #endif 636 589 637 // 590 638 // Delete object from global object table so it cannot … … 714 762 } 715 763 716 /*717 class MCanvas : public TRootEmbeddedCanvas718 {719 public:720 MCanvas(const char* name, const TGWindow* p, UInt_t w, UInt_t h, UInt_t o) :721 TRootEmbeddedCanvas(name, p, w, h, o) {}722 void Layout()723 {724 cout << "EmbLayout: " << GetCanvas()->GetName() << endl;725 726 // Create layout for canvas. Depending on the size of the container727 // we need to add the scrollbars.728 TRootEmbeddedCanvas::Layout();729 }730 };731 */732 733 764 TGCompositeFrame *MStatusDisplay::AddRawTab(const char *name) 734 765 { … … 742 773 743 774 // display new tab in the main frame 744 // FIXME: This is a workaround, because TApplication::Run is not thread safe against ProcessEvents 745 if (gApplication->InheritsFrom(TRint::Class())) 775 // FIXME: This is a workaround, because TApplication::Run is not 776 // thread safe against ProcessEvents. We assume, that if 777 // we are not in the Main-Thread ProcessEvents() is 778 // called by the TApplication Event Loop... 779 if (!TThread::Self()/*gApplication->InheritsFrom(TRint::Class())*/) 746 780 gClient->ProcessEventsFor(fTab); 747 781 … … 786 820 787 821 // layout and map new tab 788 //#if ROOT_VERSION_CODE < ROOT_VERSION(3,03,00)789 // MapSubwindows();790 // Layout();791 //#else792 822 Layout(); 793 823 MapSubwindows(); 794 824 Layout(); 795 //#endif796 825 797 826 // display new tab in the main frame 798 // FIXME: This is a workaround, because TApplication::Run is not thread safe against ProcessEvents 799 if (gApplication->InheritsFrom(TRint::Class())) 827 // FIXME: This is a workaround, because TApplication::Run is not 828 // thread safe against ProcessEvents. We assume, that if 829 // we are not in the Main-Thread ProcessEvents() is 830 // called by the TApplication Event Loop... 831 if (!TThread::Self()/*gApplication->InheritsFrom(TRint::Class())*/) 800 832 gClient->ProcessEventsFor(fTab); 801 833 … … 807 839 } 808 840 809 810 841 // -------------------------------------------------------------------------- 811 842 // 812 843 // Update a canvas in a tab, takes the corresponding TGCompositeFrame 813 // as an argument 844 // as an argument. This is necessary, because not all functions 845 // changing the contents of a canvas or pad can call SetModified() 846 // for the corresponding tab. If this is not called correctly the 847 // tab won't be updated calling TCanvas::Update(). So we simply 848 // redraw it by our own (instead we could recursively call 849 // TPad::Modified() for everything contained by the TCanvas and 850 // call TCanvas::Update() afterwards) 814 851 // 815 852 void MStatusDisplay::UpdateTab(TGCompositeFrame *f) … … 822 859 return; 823 860 824 // Code taken from TCanvas::Update() and TCanvas::Paint() 825 // replaces PaintModified() by Paint() 861 // 862 // If we are in a multithreaded environment (gThreadXAR) we 863 // have to make sure, that thus function is called from 864 // the main thread. 865 // 866 // NOTE: Maybe there is still need to make sure, that only 867 // one thread can update the canvas by calling UpdateTab 868 // at the same time. Could be done by a TMutex. 869 // 826 870 if (gThreadXAR) 827 871 { 828 void *arr[2] = { NULL, c }; 829 if (((*gThreadXAR)("CUPD", 2, arr, NULL))) 872 // Tell the X-Requester how to call this method 873 TString str = Form("%d", (ULong_t)f); 874 875 TMethodCall call(IsA(), "UpdateTab", "NULL"); 876 void *arr[4] = { NULL, &call, this, (void*)(const char*)str }; 877 878 // If this is not the main thread return 879 if (((*gThreadXAR)("METH", 4, arr, NULL))) 830 880 return; 831 881 } 882 883 #if ROOT_VERSION_CODE < ROOT_VERSION(3,10,01) 884 TPad *padsav = (TPad*)gPad; 885 if (!gPad) 886 c->cd(); 887 #endif 832 888 833 889 if (!c->IsBatch()) 834 890 c->FeedbackMode(kFALSE); // Goto double buffer mode 835 891 892 // 893 // Doing this ourself gives us the possibility to repaint 894 // the canvas in any case (Paint() instead of PaintModified()) 895 // 836 896 c->Paint(); // Repaint all pads 837 897 c->Flush(); // Copy all pad pixmaps to the screen 838 898 899 #if ROOT_VERSION_CODE < ROOT_VERSION(3,10,01) 900 if (padsav) 901 padsav->cd(); 902 else 903 gPad=NULL; 904 #endif 839 905 //c->SetCursor(kCross); 840 906 … … 924 990 925 991 // display new tab in the main frame 926 // FIXME: This is a workaround, because TApplication::Run is not thread safe against ProcessEvents 927 if (gApplication->InheritsFrom(TRint::Class())) 992 // FIXME: This is a workaround, because TApplication::Run is not 993 // thread safe against ProcessEvents. We assume, that if 994 // we are not in the Main-Thread ProcessEvents() is 995 // called by the TApplication Event Loop... 996 if (!TThread::Self()/*gApplication->InheritsFrom(TRint::Class())*/) 928 997 gClient->ProcessEventsFor(fTab); 929 998 … … 2005 2074 Bool_t MStatusDisplay::HandleConfigureNotify(Event_t *evt) 2006 2075 { 2007 //cout << "----- Start -----" << endl; 2076 // 2077 // The initialization of the GUI is not yet enough finished... 2078 // 2079 if (!fTab) 2080 return kTRUE; 2008 2081 2009 2082 UInt_t w = evt->fWidth; 2010 2083 UInt_t h = evt->fHeight; 2011 2084 2012 //cout << "Old: " << GetWidth() << " " << GetHeight() << " " << GetBorderWidth() << endl; 2013 //cout << "New: " << w << " " << h << endl; 2014 2015 Bool_t wchanged = w!=GetWidth(); 2085 /* 2086 cout << "Old: " << GetWidth() << " " << GetHeight() << " " << GetBorderWidth() << endl; 2087 cout << "New: " << w << " " << h << " "; 2088 cout << "New: " << GetDefaultWidth() << " " << GetDefaultHeight() << " " << endl; 2089 */ 2090 2091 //Bool_t wchanged = w!=GetWidth(); 2016 2092 Bool_t hchanged = h!=GetHeight(); 2017 2093 /* 2018 2094 if (!wchanged && !hchanged) 2019 2095 { 2020 2096 Layout(); 2021 return kTRUE; 2022 } 2097 // FIXME: Make sure that this doesn't result in endless loops. 2098 // return kTRUE; 2099 } 2100 */ 2023 2101 2024 2102 if (GetWidth()==1 && GetHeight()==1) … … 2029 2107 const UInt_t ch = GetHeight()-fTab->GetHeight(); 2030 2108 2031 // ca nculate new size of frame (canvas @ 1:sqrt(2))2109 // calculate new size of frame (canvas @ 1:sqrt(2)) 2032 2110 if (hchanged) 2033 2111 w = (UInt_t)((h-ch)*sqrt(2.)+.5)+cw; … … 2035 2113 h = (UInt_t)((w-cw)/sqrt(2.)+.5)+ch; 2036 2114 2037 //cout << "Res: " << w << " " << h << " " << evt->fX << " " << evt->fY << endl;2038 2039 2115 // resize frame 2040 2116 Resize(w, h); … … 2045 2121 Bool_t MStatusDisplay::HandleEvent(Event_t *event) 2046 2122 { 2047 /* 2048 if (event->fType!=9) 2049 { 2050 cout << "Event: " << event->fType << " "; 2051 cout << event->fX << " " << event->fY << endl; 2052 } 2053 */ 2054 /* 2055 switch (event->fType) { 2056 case kConfigureNotify: 2057 //while (gVirtualX->CheckEvent(fId, kConfigureNotify, *event)) 2058 // ; 2059 HandleConfigureNotify(event); 2060 return kTRUE; 2061 } 2062 */ 2063 // if (event->fType==kConfigureNotify && event->fX!=0 && event->fY!=0) 2064 // return kTRUE; 2065 2066 return TGMainFrame::HandleEvent(event); 2067 } 2068 2123 Bool_t rc = TGMainFrame::HandleEvent(event); 2124 2125 // 2126 // This fixes a bug in older root versions which makes 2127 // TCanvas crash if gPad==NULL. So we make sure, that 2128 // gPad!=NULL -- be carfull, this may have other side 2129 // effects. 2130 // 2131 #if ROOT_VERSION_CODE < ROOT_VERSION(3,10,01) 2132 if (!gPad && fTab) 2133 for (int i=0; i<fTab->GetNumberOfTabs(); i++) 2134 { 2135 TCanvas *c = GetCanvas(i); 2136 if (c) 2137 { 2138 c->cd(); 2139 gLog << dbg << "MStatusDisplay::HandleEvent - Workaround: gPad=" << gPad << "." << endl; 2140 break; 2141 } 2142 } 2143 #endif 2144 2145 return rc; 2146 } 2147 2148 /* 2149 // -------------------------------------------------------------------------- 2150 // 2151 // Opens a save as dialog, and tries to store the canvas 2152 // in the given output format 2153 // 2154 void MGEvtDisplay::SaveAsDialog() const 2155 { 2156 static const char *gSaveAsTypes[] = 2157 { 2158 "PostScript", "*.ps", 2159 "Encapsulated PostScript", "*.eps", 2160 "Gif files", "*.gif", 2161 "Macro files", "*.C", 2162 "ROOT files", "*.root", 2163 "All files", "*", 2164 NULL, NULL 2165 }; 2166 2167 static TString dir("."); 2168 2169 TGFileInfo fi; // fFileName and fIniDir deleted in ~TGFileInfo 2170 2171 fi.fFileTypes = (const char**)gSaveAsTypes; 2172 fi.fIniDir = StrDup(dir); 2173 2174 new TGFileDialog(fClient->GetRoot(), this, kFDSave, &fi); 2175 2176 if (!fi.fFilename) 2177 return; 2178 2179 dir = fi.fIniDir; 2180 2181 if (strstr(fi.fFilename, ".root") || 2182 strstr(fi.fFilename, ".ps") || 2183 strstr(fi.fFilename, ".eps") || 2184 strstr(fi.fFilename, ".gif")) 2185 { 2186 fCanvas->SaveAs(fi.fFilename); 2187 return; 2188 } 2189 if (strstr(fi.fFilename, ".C")) 2190 { 2191 fCanvas->SaveSource(fi.fFilename); 2192 return; 2193 } 2194 Warning("SaveAsDialog", "Unknown Extension: %s", fi.fFilename); 2195 } 2196 */ -
trunk/MagicSoft/Mars/mmain/MStatusDisplay.h
r2397 r2477 27 27 class TGProgressBar; 28 28 class TGHProgressBar; 29 class TGCompositeFrame; 29 30 class TRootEmbeddedCanvas; 30 31 … … 33 34 public: 34 35 typedef enum { 35 // KFile36 // kFile 36 37 kFileBrowser, kFileCanvas, kFileSave, kFileSaveAs, kFileSaveAsPS, 37 38 kFileSaveAsRoot, kFileSaveAsGIF, kFileSaveAsC, kFilePrint, … … 52 53 } Status_t; 53 54 55 protected: 56 MGList *fList; 57 TGCompositeFrame *fUserFrame; 58 59 Bool_t ProcessMessage(Long_t msg, Long_t mp1, Long_t mp2); 60 54 61 private: 55 MGList *fList; 56 TGHProgressBar *fBar; 57 TGTab *fTab; 58 TGLayoutHints *fLayCanvas; 62 TGHProgressBar *fBar; 63 TGTab *fTab; 64 TGLayoutHints *fLayCanvas; 59 65 60 66 TTimer fTimer; … … 78 84 79 85 void AddMenuBar(); 86 void AddUserFrame(); 87 void AddTabs(); 80 88 void AddProgressBar(); 89 void AddStatusBar(); 81 90 void AddMarsTab(); 82 91 void AddLogTab(); 83 void AddTabs();84 void AddStatusBar();85 92 86 93 TCanvas *GetCanvas(TGCompositeFrame *f) const; … … 90 97 Bool_t ProcessMessageTextview(Long_t submsg, Long_t mp1, Long_t mp2); 91 98 Bool_t ProcessMessageUser(Long_t submsg, Long_t mp1, Long_t mp2); 92 Bool_t ProcessMessage(Long_t msg, Long_t mp1, Long_t mp2);93 99 void CloseWindow(); 94 100 Bool_t HandleConfigureNotify(Event_t *); … … 119 125 void SetUpdateTime(Long_t t); 120 126 127 void SetProgressBarPosition(Float_t p); 121 128 TGProgressBar *GetBar() const { return (TGProgressBar*)fBar; } 122 129 … … 142 149 143 150 Bool_t CdCanvas(const TString &name); 151 void Update() { HandleTimer(&fTimer); HandleTimer(&fLogTimer); } 144 152 145 153 void SetNoContextMenu(Bool_t flag=kTRUE);
Note:
See TracChangeset
for help on using the changeset viewer.