source: tags/Mars-V2.1.1/mbase/MStatusDisplay.h

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