/****************************************************************************** * File: embcutG.C * * Description: macro file to test embedded canvas and status bar widgets * * as well as kCutG editor mode in ROOT assigned to a button. * * This macro gives an example of how to collect the info of * * the selected canvas object and show this info via the * * status bar and how to invoke the CutG editor mode in ROOT * * when the button CutG is clicked. * * Author: Ilka Antcheva (CERN/EP/SFT) * *Site Contact: roottalk@cern.ch OR http://root.cern.ch/phpBB2/index.php * *ROOT Version: 5.06/01 * * Last Change: 04/11/2005 * ******************************************************************************/ #include #include #include #include #include #include #include #include #include #include #include #include class MyMainFrame { RQ_OBJECT("MyMainFrame") private: TGMainFrame *fMain; TRootEmbeddedCanvas *fEcan; TGStatusBar *fStatusBar; TH2D *h2; public: MyMainFrame(const TGWindow *p, UInt_t w, UInt_t h); virtual ~MyMainFrame(); void DoExit(); void DoCutG(); void DoDraw(); void SetStatusText(const char *txt, Int_t pi); void EventInfo(Int_t event, Int_t px, Int_t py, TObject *selected); }; void MyMainFrame::DoDraw() { // Draw a function if (h2) return; Printf("Slot DoDraw()"); TCanvas *c1 = fEcan->GetCanvas(); c1->SetFillColor(42); c1->SetGrid(); c1->cd(); TF2 *f2 = new TF2("f2","(xygaus + xygaus(5) + xylandau(10))",-4,4,-4,4); Double_t params[] = {130,-1.4,1.8,1.5,1, 150,2,0.5,-2,0.5, 3600,-2,0.7,-3,0.3}; f2->SetParameters(params); h2 = new TH2D("h2","xygaus + xygaus(5) + xylandau(10)",100,-4,4,100,-4,4); h2->FillRandom("f2",40000); h2->Draw(); c1->Modified(); c1->Update(); } void MyMainFrame::DoExit() { Printf("Slot DoExit()"); gApplication->Terminate(0); } void MyMainFrame::DoCutG() { TCutG *cutg = 0; gROOT->SetEditorMode("CutG"); cutg = (TCutG*)fEcan->GetCanvas()->WaitPrimitive("mycut","CutG"); } // Widget methods here... void MyMainFrame::SetStatusText(const char *txt, Int_t pi) { // Set text in status bar. fStatusBar->SetText(txt,pi); } void MyMainFrame::EventInfo(Int_t event, Int_t px, Int_t py, TObject *selected) { // Writes the event status in the status bar parts //TCanvas *c = (TCanvas *)gTQSender; const char *text0, *text1, *text3; char text2[50]; text0 = selected->GetTitle(); SetStatusText(text0,0); text1 = selected->GetName(); SetStatusText(text1,1); if (event == kKeyPress) sprintf(text2, "%c", (char) px); else sprintf(text2, "%d,%d", px, py); SetStatusText(text2,2); text3 = selected->GetObjectInfo(px,py); SetStatusText(text3,3); } MyMainFrame::MyMainFrame(const TGWindow *p, UInt_t w, UInt_t h) { // Create the main frame fMain = new TGMainFrame(p,w,h); // Create the embedded canvas fEcan = new TRootEmbeddedCanvas(0,fMain,500,400); Int_t wid = fEcan->GetCanvasWindowId(); TCanvas *myc = new TCanvas("MyCanvas", 10,10,wid); fEcan->AdoptCanvas(myc); myc->Connect("ProcessedEvent(Int_t,Int_t,Int_t,TObject*)","MyMainFrame",this, "EventInfo(Int_t,Int_t,Int_t,TObject*)"); fMain->AddFrame(fEcan, new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX | kLHintsExpandY,0,0,1,1)); // status bar Int_t parts[] = {45, 15, 10, 30}; fStatusBar = new TGStatusBar(fMain, 50, 10, kVerticalFrame); fStatusBar->SetParts(parts, 4); fStatusBar->Draw3DCorner(kFALSE); fMain->AddFrame(fStatusBar, new TGLayoutHints(kLHintsExpandX, 0, 0, 10, 0)); // Create a horizontal frame containing two buttons TGHorizontalFrame *hframe = new TGHorizontalFrame(fMain, 200, 40); TGTextButton *draw = new TGTextButton(hframe, "&Draw"); draw->Connect("Clicked()", "MyMainFrame", this, "DoDraw()"); hframe->AddFrame(draw, new TGLayoutHints(kLHintsCenterX, 5, 5, 3, 4)); TGTextButton *cutG = new TGTextButton(hframe, "&CutG"); cutG->Connect("Clicked()", "MyMainFrame", this, "DoCutG()"); hframe->AddFrame(cutG, new TGLayoutHints(kLHintsCenterX, 5, 5, 3, 4)); TGTextButton *exit = new TGTextButton(hframe, "&Exit "); exit->Connect("Pressed()", "MyMainFrame", this, "DoExit()"); hframe->AddFrame(exit, new TGLayoutHints(kLHintsCenterX, 5, 5, 3, 4)); fMain->AddFrame(hframe, new TGLayoutHints(kLHintsCenterX, 2, 2, 2, 2)); // Set a name to the main frame fMain->SetWindowName("Embedded Canvas Status Info"); fMain->MapSubwindows(); // Initialize the layout algorithm via Resize() fMain->Resize(fMain->GetDefaultSize()); // Map main frame fMain->MapWindow(); h2 = 0; } MyMainFrame::~MyMainFrame() { // Clean up main frame... delete h2; fMain->Cleanup(); delete fEcan; delete fStatusBar; delete fMain; } void embcutG() { // Popup the GUI... new MyMainFrame(gClient->GetRoot(), 200, 200); }