source: trunk/MagicSoft/Mars/mbase/MStatusDisplay.h@ 9492

Last change on this file since 9492 was 9185, checked in by tbretz, 16 years ago
*** empty log message ***
File size: 11.2 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,
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,
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 SaveAs(TString name) { return SaveAs(-1, name); }
256
257 Bool_t SaveAsCSV(TString name="", Char_t delim='\t') { return SaveAsCSV(-1, name, delim); }
258 Int_t PrintPS() { return PrintPS(-1); }
259
260 void SaveAs(const char *c, const Option_t *o) const;
261
262 Int_t SaveAsPS(Int_t num, TString name="", const TString addon="") { return SaveAsVGF(num, name, addon, "ps"); }
263 Int_t SaveAsPDF(Int_t num, TString name="", const TString addon="") { return SaveAsVGF(num, name, addon, "pdf"); }
264 Int_t SaveAsSVG(Int_t num, TString name="", const TString addon="") { return SaveAsVGF(num, name, addon, "svg"); }
265 Bool_t SaveAsPNG(Int_t num, TString name="") { return SaveAsImage(num, name, TImage::kPng); }
266 Bool_t SaveAsGIF(Int_t num, TString name="") { return SaveAsImage(num, name, TImage::kGif); }
267 Bool_t SaveAsXPM(Int_t num, TString name="") { return SaveAsImage(num, name, TImage::kXpm); }
268 Bool_t SaveAsJPG(Int_t num, TString name="") { return SaveAsImage(num, name, TImage::kJpeg); }
269 Bool_t SaveAsTIFF(Int_t num, TString name="") { return SaveAsImage(num, name, TImage::kTiff); }
270 Bool_t SaveAsBMP(Int_t num, TString name="") { return SaveAsImage(num, name, TImage::kBmp); }
271 Bool_t SaveAsXML(Int_t num, TString name="") { return SaveAsImage(num, name, TImage::kXml); }
272 Bool_t SaveAsC(Int_t num, TString name="");
273 Int_t SaveAsRoot(Int_t num, TString name="");
274 Int_t SaveAs(Int_t num, TString name);
275
276 Bool_t SaveAsCSV(Int_t num, TString name="", Char_t delim='\t');
277 //Bool_t SaveAsXML(Int_t num, TString name="",);
278 Int_t PrintPS(Int_t num, const char *p=0, const char *cmd=0, const char *tmp=0);
279 Bool_t PrintLog(const char *p=0, const char *c=0);
280
281 Bool_t SaveLogAsPS(const char *name) const;
282
283 // I/O
284 Int_t SaveAs(Int_t num=-1);
285 Int_t Open(TString fname, const char *name="MStatusDisplay");
286 Int_t Open();
287
288 // Root I/O
289 Int_t Write(Int_t num, const char *name="MStatusDisplay", Int_t option=0, Int_t bufsize=0) const;
290
291 Int_t Read(const char *name, const char *tab);
292 Int_t Read(const char *name="MStatusDisplay") { return Read(name, 0); }
293 Int_t Write(const char *name="MStatusDisplay", Int_t option=0, Int_t bufsize=0) { return Write(-1, name, option, bufsize); }
294 Int_t Write(const char *name="MStatusDisplay", Int_t option=0, Int_t bufsize=0) const { return Write(-1, name, option, bufsize); }
295
296 // Eventloop interface
297 Status_t CheckStatus() const { return fStatus; }
298 void ClearStatus() { fStatus = kLoopNone; }
299 void SetPause() { fStatus = kLoopPause; }
300
301 void Lock() { fIsLocked++; }
302 void UnLock() { if (fIsLocked>0) fIsLocked--; }
303
304 // GUI event handling
305 void EventInfo(Int_t event, Int_t px, Int_t py, TObject *selected);
306 Bool_t HandleEvent(Event_t *event);
307
308 // Public helper functions
309 static TRootEmbeddedCanvas *GetEmbeddedCanvas(TGCompositeFrame &cf);
310 static TCanvas *GetCanvas(TGCompositeFrame &f);
311
312 ClassDef(MStatusDisplay, 0) // Window for a status display
313};
314
315#endif
Note: See TracBrowser for help on using the repository browser.