| 1 | /* ======================================================================== *\
|
|---|
| 2 | !
|
|---|
| 3 | ! *
|
|---|
| 4 | ! * This file is part of MARS, the MAGIC Analysis and Reconstruction
|
|---|
| 5 | ! * Software. It is distributed to you in the hope that it can be a useful
|
|---|
| 6 | ! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
|
|---|
| 7 | ! * It is distributed WITHOUT ANY WARRANTY.
|
|---|
| 8 | ! *
|
|---|
| 9 | ! * Permission to use, copy, modify and distribute this software and its
|
|---|
| 10 | ! * documentation for any purpose is hereby granted without fee,
|
|---|
| 11 | ! * provided that the above copyright notice appear in all copies and
|
|---|
| 12 | ! * that both that copyright notice and this permission notice appear
|
|---|
| 13 | ! * in supporting documentation. It is provided "as is" without express
|
|---|
| 14 | ! * or implied warranty.
|
|---|
| 15 | ! *
|
|---|
| 16 | !
|
|---|
| 17 | !
|
|---|
| 18 | ! Author(s): Thomas Bretz, 4/2003 <mailto:tbretz@astro-uni-wuerzburg.de>
|
|---|
| 19 | !
|
|---|
| 20 | ! Copyright: MAGIC Software Development, 2003
|
|---|
| 21 | !
|
|---|
| 22 | !
|
|---|
| 23 | \* ======================================================================== */
|
|---|
| 24 |
|
|---|
| 25 | /////////////////////////////////////////////////////////////////////////////
|
|---|
| 26 | //
|
|---|
| 27 | // MStatusDisplay
|
|---|
| 28 | //
|
|---|
| 29 | // upon an idea of Robert Wagner
|
|---|
| 30 | //
|
|---|
| 31 | /////////////////////////////////////////////////////////////////////////////
|
|---|
| 32 | #include "MStatusDisplay.h"
|
|---|
| 33 |
|
|---|
| 34 | #include <iostream.h>
|
|---|
| 35 |
|
|---|
| 36 | #include <TCanvas.h> // TCanvas
|
|---|
| 37 | #include <TSystem.h> // gSystem
|
|---|
| 38 |
|
|---|
| 39 | #include <TGTab.h> // TGTab
|
|---|
| 40 | #include <TGLabel.h> // TGLabel
|
|---|
| 41 | #include <TGButton.h> // TGPictureButton
|
|---|
| 42 | #include <TGProgressBar.h> // TGHProgressBar
|
|---|
| 43 |
|
|---|
| 44 | #include <TRootEmbeddedCanvas.h> // TRootEmbeddedCanvas
|
|---|
| 45 |
|
|---|
| 46 | #include "MGList.h"
|
|---|
| 47 |
|
|---|
| 48 | ClassImp(MStatusDisplay);
|
|---|
| 49 |
|
|---|
| 50 | void MStatusDisplay::AddProgressBar()
|
|---|
| 51 | {
|
|---|
| 52 | TGLayoutHints *laybar=new TGLayoutHints(kLHintsExpandX, 10,10,10,10);
|
|---|
| 53 | fList->Add(laybar);
|
|---|
| 54 |
|
|---|
| 55 | fBar=new TGHProgressBar(this);
|
|---|
| 56 | fBar->ShowPosition();
|
|---|
| 57 | AddFrame(fBar, laybar);
|
|---|
| 58 | fList->Add(fBar);
|
|---|
| 59 | }
|
|---|
| 60 |
|
|---|
| 61 | enum {
|
|---|
| 62 | kPicMagic,
|
|---|
| 63 | kPicMars
|
|---|
| 64 | };
|
|---|
| 65 |
|
|---|
| 66 | void MStatusDisplay::AddTabs()
|
|---|
| 67 | {
|
|---|
| 68 | fTab = new TGTab(this, 300, 300);
|
|---|
| 69 |
|
|---|
| 70 | //
|
|---|
| 71 | // Create Tab1
|
|---|
| 72 | //
|
|---|
| 73 | TGCompositeFrame *f = fTab->AddTab("-=MARS=-");
|
|---|
| 74 |
|
|---|
| 75 | /*
|
|---|
| 76 | TGHorizontalFrame *hf = new TGHorizontalFrame(f, 1, 1);
|
|---|
| 77 |
|
|---|
| 78 | TGLayoutHints *lay = new TGLayoutHints(kLHintsNormal|kLHintsExpandX|kLHintsExpandY, 10., 10., 10., 10.);
|
|---|
| 79 | fList->Add(lay);
|
|---|
| 80 | f->AddFrame(hf, lay);
|
|---|
| 81 |
|
|---|
| 82 | const TGPicture *pic1 = fList->GetPicture("magiclogo.xpm");
|
|---|
| 83 | if (pic1)
|
|---|
| 84 | {
|
|---|
| 85 | TGPictureButton *magic = new TGPictureButton(hf, pic1, kPicMagic);
|
|---|
| 86 | fList->Add(magic);
|
|---|
| 87 | magic->Associate(this);
|
|---|
| 88 |
|
|---|
| 89 | TGLayoutHints *lay1 = new TGLayoutHints(kLHintsLeft|kLHintsTop, 10., 10., 20., 10.);
|
|---|
| 90 | fList->Add(lay1);
|
|---|
| 91 | hf->AddFrame(magic, lay1);
|
|---|
| 92 | }
|
|---|
| 93 | */
|
|---|
| 94 | const TGPicture *pic2 = fList->GetPicture("marslogo.xpm");
|
|---|
| 95 | if (pic2)
|
|---|
| 96 | {
|
|---|
| 97 | TGPictureButton *mars = new TGPictureButton(f, pic2, kPicMars);
|
|---|
| 98 | fList->Add(mars);
|
|---|
| 99 | mars->Associate(this);
|
|---|
| 100 |
|
|---|
| 101 | TGLayoutHints *lay2 = new TGLayoutHints(kLHintsCenterX|kLHintsCenterY, 10., 10., 10., 10.);
|
|---|
| 102 | fList->Add(lay2);
|
|---|
| 103 | f->AddFrame(mars, lay2);
|
|---|
| 104 | }
|
|---|
| 105 |
|
|---|
| 106 | //
|
|---|
| 107 | // Crete second gui elemet for tab1 (TGVertical Frame)
|
|---|
| 108 | //
|
|---|
| 109 | TGLayoutHints *laytabs = new TGLayoutHints(kLHintsNormal|kLHintsExpandX|kLHintsExpandY, 10, 10, 10, 10);
|
|---|
| 110 | AddFrame(fTab, laytabs);
|
|---|
| 111 |
|
|---|
| 112 | fList->Add(fTab);
|
|---|
| 113 | fList->Add(laytabs);
|
|---|
| 114 | }
|
|---|
| 115 |
|
|---|
| 116 | void MStatusDisplay::AddStatusLine1()
|
|---|
| 117 | {
|
|---|
| 118 | TGCompositeFrame *f = new TGCompositeFrame(this, 1, 1, kSunkenFrame);
|
|---|
| 119 |
|
|---|
| 120 | fLine1 = new TGLabel(f, "");
|
|---|
| 121 |
|
|---|
| 122 | TGLayoutHints *lay = new TGLayoutHints(kLHintsNormal|kLHintsExpandX, 5, 5, 2, 2);
|
|---|
| 123 | f->AddFrame(fLine1, lay);
|
|---|
| 124 | AddFrame(f, lay);
|
|---|
| 125 |
|
|---|
| 126 | fList->Add(f);
|
|---|
| 127 | fList->Add(fLine1);
|
|---|
| 128 | fList->Add(lay);
|
|---|
| 129 | }
|
|---|
| 130 |
|
|---|
| 131 | void MStatusDisplay::AddStatusLine2()
|
|---|
| 132 | {
|
|---|
| 133 | TGCompositeFrame *f = new TGCompositeFrame(this, 1, 1, kSunkenFrame);
|
|---|
| 134 |
|
|---|
| 135 | fLine2 = new TGLabel(f, "");
|
|---|
| 136 |
|
|---|
| 137 | TGLayoutHints *lay = new TGLayoutHints(kLHintsNormal|kLHintsExpandX, 5, 5, 2, 2);
|
|---|
| 138 | f->AddFrame(fLine2, lay);
|
|---|
| 139 | AddFrame(f, lay);
|
|---|
| 140 |
|
|---|
| 141 | fList->Add(f);
|
|---|
| 142 | fList->Add(fLine2);
|
|---|
| 143 | fList->Add(lay);
|
|---|
| 144 | }
|
|---|
| 145 |
|
|---|
| 146 | void MStatusDisplay::SetStatusLine1(const char *txt)
|
|---|
| 147 | {
|
|---|
| 148 | fLine1->SetText(txt);
|
|---|
| 149 | }
|
|---|
| 150 |
|
|---|
| 151 | void MStatusDisplay::SetStatusLine2(const char *txt)
|
|---|
| 152 | {
|
|---|
| 153 | fLine2->SetText(txt);
|
|---|
| 154 | }
|
|---|
| 155 |
|
|---|
| 156 | // --------------------------------------------------------------------------
|
|---|
| 157 | //
|
|---|
| 158 | // Default constructor. Opens a window with a progress bar. Get a pointer
|
|---|
| 159 | // to the bar by calling GetBar. This pointer can be used for the
|
|---|
| 160 | // eventloop.
|
|---|
| 161 | //
|
|---|
| 162 | // Be carefull: killing or closing the window while the progress meter
|
|---|
| 163 | // is still in use may cause segmentation faults. Please kill the window
|
|---|
| 164 | // always by deleting the corresponding object.
|
|---|
| 165 | //
|
|---|
| 166 | MStatusDisplay::MStatusDisplay() : TGTransientFrame(gClient->GetRoot(), gClient->GetRoot(), 1, 1)
|
|---|
| 167 | {
|
|---|
| 168 | fList = new MGList;
|
|---|
| 169 | fList->SetOwner();
|
|---|
| 170 |
|
|---|
| 171 | SetWMSizeHints(640, 480, 1280, 1024, 10, 10); // set the smallest and biggest size of the Main frame
|
|---|
| 172 | Move(rand()%100+50, rand()%100+50);
|
|---|
| 173 |
|
|---|
| 174 | fLayCanvas = new TGLayoutHints(kLHintsExpandX|kLHintsExpandY, 3, 3, 3, 3);
|
|---|
| 175 | fList->Add(fLayCanvas);
|
|---|
| 176 |
|
|---|
| 177 | AddTabs();
|
|---|
| 178 | AddProgressBar();
|
|---|
| 179 | AddStatusLine1();
|
|---|
| 180 | AddStatusLine2();
|
|---|
| 181 |
|
|---|
| 182 | MapSubwindows();
|
|---|
| 183 |
|
|---|
| 184 | Layout();
|
|---|
| 185 |
|
|---|
| 186 | SetWindowName("Status Display");
|
|---|
| 187 | SetIconName("Status Display");
|
|---|
| 188 |
|
|---|
| 189 | MapWindow();
|
|---|
| 190 | }
|
|---|
| 191 |
|
|---|
| 192 | // --------------------------------------------------------------------------
|
|---|
| 193 | //
|
|---|
| 194 | // Destruct the window with all its tiles. Also the Progress Bar object
|
|---|
| 195 | // is deleted.
|
|---|
| 196 | //
|
|---|
| 197 | MStatusDisplay::~MStatusDisplay()
|
|---|
| 198 | {
|
|---|
| 199 | delete fList;
|
|---|
| 200 | }
|
|---|
| 201 |
|
|---|
| 202 | TCanvas *MStatusDisplay::GetCanvas(TGCompositeFrame *cf)
|
|---|
| 203 | {
|
|---|
| 204 | TIter Next(cf->GetList());
|
|---|
| 205 |
|
|---|
| 206 | TGFrameElement *f;
|
|---|
| 207 | while ((f=(TGFrameElement*)Next()))
|
|---|
| 208 | if (f->fFrame->InheritsFrom(TRootEmbeddedCanvas::Class()))
|
|---|
| 209 | return ((TRootEmbeddedCanvas*)f->fFrame)->GetCanvas();
|
|---|
| 210 |
|
|---|
| 211 | return NULL;
|
|---|
| 212 | }
|
|---|
| 213 |
|
|---|
| 214 | TCanvas *MStatusDisplay::GetCanvas(int i)
|
|---|
| 215 | {
|
|---|
| 216 | if (i<0 || i>=fTab->GetNumberOfTabs())
|
|---|
| 217 | {
|
|---|
| 218 | cout << "MStatusDisplay::GetCanvas: Out of range." << endl;
|
|---|
| 219 | return NULL;
|
|---|
| 220 | }
|
|---|
| 221 |
|
|---|
| 222 | return GetCanvas(fTab->GetTabContainer(i));
|
|---|
| 223 | }
|
|---|
| 224 |
|
|---|
| 225 | TCanvas *MStatusDisplay::GetCanvas(const TString &name)
|
|---|
| 226 | {
|
|---|
| 227 | TGFrameElement *f;
|
|---|
| 228 | TIter Next(fTab->GetList());
|
|---|
| 229 | while ((f=(TGFrameElement*)Next()))
|
|---|
| 230 | {
|
|---|
| 231 | TObject *frame = f->fFrame;
|
|---|
| 232 | if (!frame->InheritsFrom(TGTabElement::Class()))
|
|---|
| 233 | continue;
|
|---|
| 234 |
|
|---|
| 235 | TGTabElement *tab = (TGTabElement*)frame;
|
|---|
| 236 | if (tab->GetString()==name)
|
|---|
| 237 | break;
|
|---|
| 238 | }
|
|---|
| 239 |
|
|---|
| 240 | // Search for the next TGCompositeFrame in the list
|
|---|
| 241 | while ((f=(TGFrameElement*)Next()))
|
|---|
| 242 | {
|
|---|
| 243 | TObject *frame = f->fFrame;
|
|---|
| 244 | if (frame->InheritsFrom(TGCompositeFrame::Class()))
|
|---|
| 245 | return GetCanvas((TGCompositeFrame*)frame);
|
|---|
| 246 | }
|
|---|
| 247 |
|
|---|
| 248 | return NULL;
|
|---|
| 249 | }
|
|---|
| 250 |
|
|---|
| 251 | TCanvas &MStatusDisplay::AddTab(const char *name)
|
|---|
| 252 | {
|
|---|
| 253 | TGCompositeFrame *f = fTab->AddTab(name);
|
|---|
| 254 |
|
|---|
| 255 | TRootEmbeddedCanvas *ec = new TRootEmbeddedCanvas(name, f, 100, 100, 0);
|
|---|
| 256 | f->AddFrame(ec, fLayCanvas);
|
|---|
| 257 | fList->Add(ec);
|
|---|
| 258 |
|
|---|
| 259 | TCanvas &c = *ec->GetCanvas();
|
|---|
| 260 |
|
|---|
| 261 | c.SetFillColor(/*165*/17);
|
|---|
| 262 | c.SetBorderMode(0);
|
|---|
| 263 |
|
|---|
| 264 | MapSubwindows();
|
|---|
| 265 | Layout();
|
|---|
| 266 | // MapWindow();
|
|---|
| 267 |
|
|---|
| 268 | cout << "Adding Tab '" << name << "' (TCanvas=" << &c << ")" << ec << endl;
|
|---|
| 269 |
|
|---|
| 270 | return c;
|
|---|
| 271 | }
|
|---|
| 272 |
|
|---|
| 273 | Bool_t MStatusDisplay::ProcessMessage(Long_t msg, Long_t mp1, Long_t mp2)
|
|---|
| 274 | {
|
|---|
| 275 | cout << "Msg: " << GET_MSG(msg) << " Submsg:" << GET_SUBMSG(msg) << " Mp1=";
|
|---|
| 276 | cout << mp1 << " Mp2=" << mp2 << endl;
|
|---|
| 277 |
|
|---|
| 278 | return kTRUE;
|
|---|
| 279 | }
|
|---|
| 280 |
|
|---|
| 281 | void MStatusDisplay::CloseWindow()
|
|---|
| 282 | {
|
|---|
| 283 | // Got close message for this MainFrame. Calls parent CloseWindow()
|
|---|
| 284 | // (which destroys the window) and terminate the application.
|
|---|
| 285 | // The close message is generated by the window manager when its close
|
|---|
| 286 | // window menu item is selected.
|
|---|
| 287 |
|
|---|
| 288 | // CloseWindow must be overwritten because otherwise CloseWindow
|
|---|
| 289 | // and the destructor are calling DestroyWindow which seems to be
|
|---|
| 290 | // in conflict with the TRootEmbeddedCanvas.
|
|---|
| 291 | delete this;
|
|---|
| 292 | }
|
|---|
| 293 |
|
|---|