source: trunk/Mars/mbase/MStatusDisplay.h@ 17127

Last change on this file since 17127 was 15257, checked in by tbretz, 12 years ago
Removed some unsused parameters from the header to avoid compiler warnings.
File size: 11.5 KB
Line 
1#ifndef MARS_MStatusDisplay
2#define MARS_MStatusDisplay
3
4#ifndef MARS_MAGIC
5#include "MAGIC.h"
6#endif
7
8#ifndef ROOT_TGFrame
9#include <TGFrame.h>
10#endif
11
12#ifndef ROOT_TTimer
13#include <TTimer.h>
14#endif
15
16#ifndef ROOT_TImage
17#include <TImage.h>
18#endif
19
20class MLog;
21class MGList;
22class MGMenuBar;
23class MStatusArray;
24class MParContainer;
25
26class TPad;
27class TTimer;
28class TMutex;
29class TCanvas;
30class TVirtualPS;
31
32class TGTab;
33class TGTextView;
34class TGStatusBar;
35class TGPopupMenu;
36class TGTabElement;
37class TGProgressBar;
38class TGHProgressBar;
39class TGCompositeFrame;
40class TRootEmbeddedCanvas;
41
42class MStatusDisplay : public TGMainFrame
43{
44 friend class MStatusArray;
45public:
46 typedef enum {
47 // kFile
48 kFileBrowser, kFileCanvas, kFileTab, kFileOpen, kFileSave, kFileSaveAs,
49 kFileSaveAsPS, kFileSaveAsPDF, kFileSaveAsSVG, kFileSaveAsRoot,
50 kFileSaveAsPNG, kFileSaveAsGIF, kFileSaveAsJPG, kFileSaveAsXPM,
51 kFileSaveAsBMP, kFileSaveAsCSV, kFileSaveAsTIFF, kFileSaveAsPlainRoot,
52 kFileSaveAsXML, kFileSaveAsC, kFilePrint, kFilePrinterName,
53 kFileClose, kFileExit, kFileReset,
54 // kLoop
55 kLoopNone, kLoopPause, kLoopStep, kLoopStop,
56 // kTab
57 kTabSave, kTabSaveAs, kTabSaveAsPS, kTabSaveAsPDF, kTabSaveAsSVG,
58 kTabSaveAsRoot, kTabSaveAsPNG, kTabSaveAsGIF, kTabSaveAsJPG,
59 kTabSaveAsXPM, kTabSaveAsBMP, kTabSaveAsCSV, kTabSaveAsTIFF,
60 kTabSaveAsXML, kTabSaveAsC, kTabSaveAsPlainRoot,
61 kTabPrint, kTabNext, kTabPrevious, kTabRemove,
62 // kSize
63 kSize640, kSize768, kSize800, kSize960, kSize1024, kSize1152,
64 kSize1280, kSize1400, kSize1600, kSizeOptimum,
65 // kLog
66 kLogCopy, kLogClear, kLogSelect, kLogFind, kLogSave, kLogAppend,
67 kLogPrint,
68 // kPic
69 kPicMagic, kPicMars,
70 // kGui
71 kSearch, kTabs,
72 // kLastElement
73 kLastElement
74 } Status_t;
75
76 enum
77 {
78 // TGMainFrame::kDontCallClose = BIT(14)
79 kExitLoopOnExit = BIT(15),
80 kExitLoopOnClose = BIT(16)
81 };
82
83protected:
84 TString fName; // status display identifier (name) (gROOT->FindObject())
85 TString fTitle; // status display title
86
87 MLog *fLog;
88 MGList *fList;
89 TGCompositeFrame *fUserFrame;
90
91 Bool_t ProcessMessage(Long_t msg, Long_t mp1, Long_t mp2);
92
93private:
94 TGHProgressBar *fBar;
95 TGTab *fTab;
96 TGLayoutHints *fLayCanvas;
97
98 TTimer fTimer;
99 TMutex *fMutex;
100
101 MGMenuBar *fMenuBar;
102 TGStatusBar *fStatusBar;
103
104 Status_t fStatus;
105
106 Int_t fLogIdx;
107 TTimer fLogTimer;
108 TGTextView *fLogBox;
109
110 FontStruct_t fFont;
111
112 UInt_t fIsLocked;
113
114 TList *fBatch; //!
115
116 // GUI setup
117 void AddMenuBar();
118 void AddUserFrame();
119 void AddTabs();
120 void AddProgressBar();
121 void AddStatusBar();
122 void AddMarsTab();
123 void AddLogTab();
124
125 // GUI event handling
126 Bool_t ProcessMessageCommandMenu(Long_t mp1);
127 Bool_t ProcessMessageCommand(Long_t submsg, Long_t mp1, Long_t mp2);
128 Bool_t ProcessMessageTextview(Long_t submsg, Long_t mp1, Long_t mp2);
129 Bool_t ProcessMessageUser(Long_t submsg, Long_t mp1, Long_t mp2);
130 Bool_t Close();
131 void CloseWindow();
132 Bool_t HandleConfigureNotify(Event_t *);
133
134 // Access to the tabs
135 TGCompositeFrame *GetTabContainer(const char *name) const;
136 TGTabElement *GetTabTab(const char *name) const;
137
138 // Display update
139 Bool_t HandleTimer(TTimer *timer=NULL);
140 void UpdateTab(TGCompositeFrame *f);
141 void UpdateMemory() const;
142
143 // Display helper functions
144 void RemoveTab(int i);
145 void SetStatusLine(const char *txt, Int_t idx);
146
147 // Menu helper functions
148 TGPopupMenu *GetPopup(const char *name);
149
150 // Drawing helper
151 void DrawClonePad(TCanvas &newc, TCanvas &oldc) const;
152 void GetCanvasRange(Int_t &from, Int_t &to, Int_t num=-1) const;
153
154 // MStatusArray interface
155 Bool_t Display(const TObjArray &list, const char *tab=0);
156 void FillArray(MStatusArray &list, Int_t num=-1) const;
157
158 // I/O helper function
159 const TString &AddExtension(TString &name, const TString &ext, Int_t num=-1) const;
160
161 TCanvas *InitWriteTab(Int_t num, TString &name);
162 TCanvas *InitWriteTab(Int_t num) { TString s; return InitWriteTab(num, s); }
163 Int_t InitWriteDisplay(Int_t num, TString &name, const TString &ext);
164
165 void UpdatePSHeader(const TString &name) const;
166
167 Bool_t SaveAsImage(Int_t num, TString name, TImage::EImageFileTypes type);
168 Int_t SaveAsVGF(Int_t num, TString name, const TString addon, const TString ext);
169
170 void PSToolsRange(TVirtualPS &vps, Float_t w, Float_t h) const;
171 void PSToolsTextNDC(TVirtualPS &vps, Double_t u, Double_t v, const char *string) const;
172 TString PrintDialog(TString &p, TString &c, TString &t, const char *ext=0);
173
174public:
175 MStatusDisplay(Int_t w=-1, Int_t h=-1, Long_t t=1000);
176 virtual ~MStatusDisplay();
177
178 // Name and title handling
179 virtual void SetName(const char *name) { fName = name; }
180 virtual void SetTitle(const char *title="") { SetTitle(title, kTRUE); }
181 virtual const char *GetName() const { return fName.Data(); }
182 virtual const char *GetTitle() const { return fTitle.Data(); }
183
184 virtual void SetTitle(const char *title, Bool_t replace)
185 {
186 if (fTitle.IsNull() || replace) fTitle = title;
187 }
188
189 // Getter / display access
190 Bool_t HasCanvas(const TCanvas *c) const;
191 TCanvas *GetCanvas(int i) const;
192 TCanvas *GetCanvas(const TString &name) const;
193 TVirtualPad *GetFullPad(const Int_t canvas, const Int_t pad);
194
195 Bool_t CdCanvas(const TString &name);
196 Bool_t CheckTabForCanvas(int num) const;
197
198 TObject *FindObjectInCanvas(const char *obj, const char *base, const char *canv) const;
199 TObject *FindObjectInCanvas(const char *obj, const char *canv) const { return FindObjectInCanvas(obj, obj, canv); }
200 TObject *FindObject(const char *obj, const char *base) const { return FindObjectInCanvas(obj, base, 0); }
201 TObject *FindObject(const char *obj) const { return FindObjectInCanvas(obj, obj, 0); }
202 TObject *FindObject(const TObject *) const { return 0; }
203
204 Int_t GetNumTabs() const;
205
206 void PrintContent(Option_t *o="") const;
207
208 // Display Manipulation
209 TCanvas &AddTab(const char *name, const char *title=0);
210 TGCompositeFrame *AddRawTab(const char *name);
211
212 void SetProgressBarPosition(Float_t p, Bool_t upd=kFALSE);
213 TGProgressBar *GetBar() const { return (TGProgressBar*)fBar; }
214
215 void SetStatusLine1(const char *txt) { SetStatusLine(txt, 0); }
216 void SetStatusLine2(const char *txt) { SetStatusLine(txt, 1); }
217 void SetStatusLine2(const MParContainer &cont);
218
219 void Reset();
220 void SetNoContextMenu(Bool_t flag=kTRUE);
221
222 // Update handling
223 void StartUpdate(Int_t millisec=-1);
224 void StopUpdate();
225 void SetUpdateTime(Long_t t);
226
227 void Update() { HandleTimer(&fTimer); HandleTimer(&fLogTimer); }
228
229 // Log stream interface
230 void SetLogStream(MLog *log, Bool_t enable=kFALSE);
231
232 // Size options
233 void SetCanvasWidth(UInt_t w);
234 void SetCanvasHeight(UInt_t h);
235
236 void SetDisplayWidth(UInt_t w);
237 void SetDisplayHeight(UInt_t h);
238
239 void SetOptimumSize();
240 void SetDisplaySize(UInt_t w, UInt_t h);
241
242 // Graphics output
243 Int_t SaveAsPS(TString name="", const TString addon="") { return SaveAsVGF(-1, name, addon, "ps"); }
244 Int_t SaveAsPDF(TString name="", const TString addon="") { return SaveAsVGF(-1, name, addon, "pdf"); }
245 Int_t SaveAsSVG(TString name="", const TString addon="") { return SaveAsVGF(-1, name, addon, "svg"); }
246 Bool_t SaveAsPNG(TString name="") { return SaveAsPNG(-1, name); }
247 Bool_t SaveAsGIF(TString name="") { return SaveAsGIF(-1, name); }
248 Bool_t SaveAsXPM(TString name="") { return SaveAsXPM(-1, name); }
249 Bool_t SaveAsJPG(TString name="") { return SaveAsJPG(-1, name); }
250 Bool_t SaveAsTIFF(TString name="") { return SaveAsTIFF(-1, name); }
251 Bool_t SaveAsBMP(TString name="") { return SaveAsBMP(-1, name); }
252 Bool_t SaveAsXML(TString name="") { return SaveAsXML(-1, name); }
253 Bool_t SaveAsC(TString name="") { return SaveAsC(-1, name); }
254 Int_t SaveAsRoot(TString name="") { return SaveAsRoot(-1, name); }
255 Int_t SaveAsPlainRoot(TString name="") { return SaveAsRoot(-1, name, kTRUE); }
256 Int_t SaveAs(TString name) { return SaveAs(-1, name); }
257
258 Bool_t SaveAsCSV(TString name="", Char_t delim='\t') { return SaveAsCSV(-1, name, delim); }
259 Int_t PrintPS() { return PrintPS(-1); }
260
261 void SaveAs(const char *c, const Option_t *o) const;
262
263 Int_t SaveAsPS(Int_t num, TString name="", const TString addon="") { return SaveAsVGF(num, name, addon, "ps"); }
264 Int_t SaveAsPDF(Int_t num, TString name="", const TString addon="") { return SaveAsVGF(num, name, addon, "pdf"); }
265 Int_t SaveAsSVG(Int_t num, TString name="", const TString addon="") { return SaveAsVGF(num, name, addon, "svg"); }
266 Bool_t SaveAsPNG(Int_t num, TString name="") { return SaveAsImage(num, name, TImage::kPng); }
267 Bool_t SaveAsGIF(Int_t num, TString name="") { return SaveAsImage(num, name, TImage::kGif); }
268 Bool_t SaveAsXPM(Int_t num, TString name="") { return SaveAsImage(num, name, TImage::kXpm); }
269 Bool_t SaveAsJPG(Int_t num, TString name="") { return SaveAsImage(num, name, TImage::kJpeg); }
270 Bool_t SaveAsTIFF(Int_t num, TString name="") { return SaveAsImage(num, name, TImage::kTiff); }
271 Bool_t SaveAsBMP(Int_t num, TString name="") { return SaveAsImage(num, name, TImage::kBmp); }
272 Bool_t SaveAsXML(Int_t num, TString name="") { return SaveAsImage(num, name, TImage::kXml); }
273 Bool_t SaveAsC(Int_t num, TString name="");
274 Int_t SaveAsRoot(Int_t num, TString name="", Bool_t plain=kFALSE);
275 Int_t SaveAsPlainRoot(Int_t num, TString name="") { return SaveAsRoot(num, name, kTRUE); }
276 Int_t SaveAs(Int_t num, TString name);
277
278 Bool_t SaveAsCSV(Int_t num, TString name="", Char_t delim='\t');
279 //Bool_t SaveAsXML(Int_t num, TString name="",);
280 Int_t PrintPS(Int_t num, const char *p=0, const char *cmd=0, const char *tmp=0);
281 Bool_t PrintLog(const char *p=0, const char *c=0);
282
283 Bool_t SaveLogAsPS(const char *name) const;
284
285 // I/O
286 Int_t SaveAs(Int_t num=-1);
287 Int_t Open(TString fname, const char *name="MStatusDisplay");
288 Int_t Open();
289
290 // Root I/O
291 Int_t Write(Int_t num, const char *name="MStatusDisplay", Option_t *opt="") const;
292
293 Int_t Read(const char *name, const char *tab);
294 Int_t Read(const char *name="MStatusDisplay") { return Read(name, 0); }
295 Int_t Write(const char *name="MStatusDisplay", Int_t =0, Int_t =0) { return Write(-1, name); }
296 Int_t Write(const char *name="MStatusDisplay", Int_t =0, Int_t =0) const { return Write(-1, name); }
297
298 // Eventloop interface
299 Status_t CheckStatus() const { return fStatus; }
300 void ClearStatus() { fStatus=kLoopPause; ProcessMessageCommandMenu(kLoopPause); }
301 void SetPause() { fStatus=kLoopNone; ProcessMessageCommandMenu(kLoopPause); }
302 void SetLoopStep() { SetPause(); fStatus = kLoopStep; }
303
304 void Lock() { fIsLocked++; }
305 void UnLock() { if (fIsLocked>0) fIsLocked--; }
306
307 // GUI event handling
308 void EventInfo(Int_t event, Int_t px, Int_t py, TObject *selected);
309 Bool_t HandleEvent(Event_t *event);
310
311 // Public helper functions
312 static TRootEmbeddedCanvas *GetEmbeddedCanvas(TGCompositeFrame &cf);
313 static TCanvas *GetCanvas(TGCompositeFrame &f);
314
315 ClassDef(MStatusDisplay, 0) // Window for a status display
316};
317
318#endif
Note: See TracBrowser for help on using the repository browser.