MIDAS
Loading...
Searching...
No Matches
rmidas.c
Go to the documentation of this file.
1/********************************************************************\
2
3 Name: fmidas.c
4 Created by: Stefan Ritt
5
6 Contents: ROOT based Midas GUI for histo display and experiment
7 control
8
9 $Id$
10
11\*******************************************************************/
12
13#include "TGButton.h"
14#include "TRootEmbeddedCanvas.h"
15#include "TGLayout.h"
16#include "TH2.h"
17#include "TCanvas.h"
18#include "TSocket.h"
19#include "TMessage.h"
20#include "TGMsgBox.h"
21#include "TApplication.h"
22#include "TROOT.h"
23#include "TGListBox.h"
24#include "TObjArray.h"
25#include "TObjString.h"
26#include "TGMenu.h"
27#include "TGTab.h"
28#include "TGLabel.h"
29#include "TGTextEntry.h"
30
31#ifndef ROOT_TGFrame
32#include "TGFrame.h"
33#endif
34
35/*------------------------------------------------------------------*/
36
37class TGTextDialog:public TGTransientFrame {
38
39 protected:
40 TGCompositeFrame * fF1, *fF2; // sub frames
41 TGButton *fOkButton; // ok button
42 TGButton *fCancelButton; // cancel button
43 TGLayoutHints *fL1, *fL5, *fL6, *fL21; // layout hints
44 TGTextEntry *fText; // text entry widget
45 TGTextBuffer *fBLabel; // text buffer
46 TGLabel *fLabel; // label
47 char *fRetStr; // return string
48
49 public:
50 TGTextDialog(const TGWindow * p, const TGWindow * main, UInt_t w, UInt_t h,
51 char *label, char *ret_str, UInt_t options = kVerticalFrame);
52 virtual ~ TGTextDialog();
53
54 virtual void CloseWindow();
56
57 //ClassDef(TGTextDialog, 0)
58};
59
60//ClassImp(TGTextDialog)
61
62/*------------------------------------------------------------------*/
63
65 UInt_t w, UInt_t h, char *label, char *ret_str,
66 UInt_t options):TGTransientFrame(p, main, w, h, options)
67{
68/* Create a dialog to enter a single line text entry */
69
71
73
74 fF1 = new TGCompositeFrame(this, 60, 20, kVerticalFrame | kFixedWidth);
75 fF2 = new TGCompositeFrame(this, 60, 20, kHorizontalFrame);
76
77 fOkButton = new TGTextButton(fF1, new TGHotString("&Ok"), 1);
78 fCancelButton = new TGTextButton(fF1, new TGHotString("&Cancel"), 2);
79 fF1->Resize(fOkButton->GetDefaultWidth() + 40, GetDefaultHeight());
80
81 fOkButton->Associate(this);
82 fCancelButton->Associate(this);
83
84 fL1 = new TGLayoutHints(kLHintsTop | kLHintsExpandX, 2, 2, 3, 0);
85 fL21 = new TGLayoutHints(kLHintsTop | kLHintsRight, 2, 5, 10, 0);
86
87 fF1->AddFrame(fOkButton, fL1);
88 fF1->AddFrame(fCancelButton, fL1);
90
91 fLabel = new TGLabel(fF2, new TGHotString(label));
92
93 fBLabel = new TGTextBuffer(50);
94 if (fRetStr[0])
95 fBLabel->AddText(0, fRetStr);
96 else
97 fOkButton->SetState(kButtonDisabled);
98
100 fText->Associate(this);
101 fText->Resize(220, fText->GetDefaultHeight());
102 fText->SelectAll();
103
104 fL5 = new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 3, 5, 0, 0);
105 fL6 = new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 0, 2, 0, 0);
106
107 fF2->AddFrame(fLabel, fL5);
108 fF2->AddFrame(fText, fL5);
109 AddFrame(fF2, fL1);
110
113
114 // position relative to the parent's window
115 Int_t ax, ay;
116 if (main) {
118 gVirtualX->TranslateCoordinates(main->GetId(), GetParent()->GetId(),
119 (Int_t) (((TGFrame *) main)->GetWidth() -
120 fWidth) >> 1,
121 (Int_t) (((TGFrame *) main)->GetHeight() -
122 fHeight) >> 1, ax, ay, wdum);
123 } else {
125 gVirtualX->GetWindowSize(fClient->GetRoot()->GetId(), ax, ay, root_w, root_h);
126 ax = (root_w - fWidth) >> 1;
127 ay = (root_h - fHeight) >> 1;
128 }
129
130 Move(ax, ay);
132
133 SetWindowName("Enter Text");
134
137
138 MapWindow();
139 fClient->WaitFor(this);
140}
141
142/*------------------------------------------------------------------*/
143
145{
146 // Clean up text dialog
147
148 delete fCancelButton;
149 delete fOkButton;
150 delete fText;
151 delete fLabel;
152 delete fF1;
153 delete fF2;
154 delete fL1;
155 delete fL5;
156 delete fL6;
157 delete fL21;
158}
159
160/*------------------------------------------------------------------*/
161
163{
164 // Close the dialog. On close the dialog will be deleted and cannot be
165 // re-used.
166
167 DeleteWindow();
168}
169
171{
172 const char *string;
173
174 switch (GET_MSG(msg)) {
175 case kC_COMMAND:
176 switch (GET_SUBMSG(msg)) {
177 case kCM_BUTTON:
178 switch (parm1) {
179 case 1:
180 if (fRetStr)
181 strcpy(fRetStr, fBLabel->GetString());
182 CloseWindow();
183 break;
184 case 2:
185 fRetStr[0] = 0;
186 CloseWindow();
187 break;
188 }
189 break;
190
191 default:
192 break;
193 }
194 break;
195
196 case kC_TEXTENTRY:
197 switch (GET_SUBMSG(msg)) {
198 case kTE_TEXTCHANGED:
199 string = fBLabel->GetString();
200 if (strlen(string) == 0)
201 fOkButton->SetState(kButtonDisabled);
202 else
203 fOkButton->SetState(kButtonUp);
204 break;
205 case kTE_ENTER:
206 if (fRetStr)
207 strcpy(fRetStr, fBLabel->GetString());
208 CloseWindow();
209 break;
210 default:
211 break;
212 }
213 break;
214
215 default:
216 break;
217 }
218
219 return kTRUE;
220}
221
222/*------------------------------------------------------------------*/
223
230
231/*------------------------------------------------------------------*/
232
233class RMidasFrame:public TGMainFrame {
234
235 private:
238
242
246
249
252
253 char fHost[256]; // remote host name
255
258
259 int ConnectServer();
260 void GetHistoList();
261 void GetHisto(const char *name);
262 void ClearHisto(const char *name);
263
264 public:
265 RMidasFrame(const TGWindow * p, UInt_t w, UInt_t h, char *host = "localhost");
266 ~RMidasFrame();
267
268 void CloseWindow();
270};
271
272/*------------------------------------------------------------------*/
273
275{
276 char str[80];
277
278 if (fSock) {
279 /* disconnect first */
280 fSock->Close();
281 delete fSock;
282 fSock = NULL;
283
284 SetWindowName("RMidas");
285
286 fListBox->RemoveEntries(0, 999);
287 }
288
289 if (fHost[0] == 0) {
290 new TGTextDialog(gClient->GetRoot(), this, 100, 100, "&Host name:", fHost);
291 }
292
293 /* Connect to RMidasServ */
294 fSock = new TSocket(fHost, 9090);
295
296 if (!fSock->IsValid()) {
297 sprintf(str, "Cannot connect to RMidas server on host %s, port 9090\n", fHost);
298 new TGMsgBox(gClient->GetRoot(), this, "Error", str, kMBIconExclamation, 0, NULL);
299
300 SetWindowName("RMidas");
301 return 0;
302 } else {
303 fSock->Recv(str, sizeof(str));
304 if (strncmp(str, "RMSERV", 6)) {
305 sprintf(str, "RMidas server not found on host %s, port 9090\n", fHost);
306 new TGMsgBox(gClient->GetRoot(), this, "Error", str, kMBIconExclamation, 0,
307 NULL);
308
309 fSock->Close();
310 delete fSock;
311 fSock = NULL;
312
313 SetWindowName("RMidas");
314 return 0;
315 } else {
316 sprintf(str, "RMidas connected to %s", fHost);
318 GetHistoList();
319 return 1;
320 }
321 }
322}
323
324/*------------------------------------------------------------------*/
325
327{
328 int i;
329
330 fSock->Send("LIST");
331
332 TMessage *m;
333 fSock->Recv(m);
334
335 if (fHistoNames)
336 delete fHistoNames;
337
338 fHistoNames = (TObjArray *) m->ReadObject(m->GetClass());
339
340 for (i = 0; i < fHistoNames->GetLast() + 1; i++)
341 fListBox->AddEntry((const char *) ((TObjString *) (fHistoNames->At(i)))->String(),
342 i);
343
344 fListBox->MapSubwindows();
345 fListBox->Layout();
346 delete m;
347}
348
349/*------------------------------------------------------------------*/
350
352{
353 TMessage *m;
354 char str[32];
355
356 sprintf(str, "GET %s", name);
357 fSock->Send(str);
358 fSock->Recv(m);
359
360 if (fHisto)
361 delete fHisto;
362
363 fHisto = (TH1 *) m->ReadObject(m->GetClass());
364
365 if (!fHisto)
366 printf("Histo \"%s\" not available\n", name);
367 else
368 fHisto->Draw();
369
370 fCanvas->GetCanvas()->Modified();
371 fCanvas->GetCanvas()->Update();
372
373 delete m;
374}
375
376/*------------------------------------------------------------------*/
377
379{
380 char str[32];
381
382 sprintf(str, "CLEAR %s", name);
383 fSock->Send(str);
384 fSock->Recv(str, sizeof(str));
385}
386
387/*------------------------------------------------------------------*/
388
390 char *host):TGMainFrame(p, w, h)
391{
392 /* save host name */
393 if (host)
394 strcpy(fHost, host);
395 else
396 fHost[0] = 0;
397 fSock = NULL;
398
399 /* Create Menus */
400 fMenuFile = new TGPopupMenu(fClient->GetRoot());
401 fMenuFile->AddEntry("&Connect to ...", M_FILE_CONNECT);
402 fMenuFile->AddEntry("E&xit", M_FILE_EXIT);
403 fMenuFile->Associate(this);
404
405 fMenuBar = new TGMenuBar(this, 1, 1, kHorizontalFrame);
406 fMenuBar->AddPopup("&File", fMenuFile,
407 new TGLayoutHints(kLHintsTop | kLHintsLeft, 0, 4, 0, 0));
408
411
412 /* Create tab widget */
413 fTab = new TGTab(this, 600, 400);
414
415 /*---- histo tab ----*/
416
417 TGCompositeFrame *tf = fTab->AddTab("Histo");
419
420 /* Create a horizonal frame containing histo selection tree and canvas */
421 fHorz1 = new TGHorizontalFrame(fTabHisto, 600, 400);
422 fTabHisto->AddFrame(fHorz1,
423 new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 3, 3, 3, 0));
424
425 /* Create ListBox widget */
426 fListBox = new TGListBox(fHorz1, 1);
427 fListBox->Resize(100, 400);
428 fListBox->Associate(this);
429 fHorz1->AddFrame(fListBox, new TGLayoutHints(kLHintsExpandY, 0, 0, 0, 0));
430
431 /* Create an embedded canvas and add to the main frame, centered in x and y */
432 fCanvas = new TRootEmbeddedCanvas("Canvas", fHorz1, 400, 400);
433 fHorz1->AddFrame(fCanvas,
434 new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 0, 0, 0, 0));
435
436 /* Create a horizonal frame containing text buttons */
437 fHorz2 = new TGHorizontalFrame(fTabHisto, 600, 30);
438 fTabHisto->AddFrame(fHorz2, new TGLayoutHints(kLHintsExpandX, 0, 0, 0, 0));
439
440 /* Create "Update" button */
441 fBUpdate = new TGTextButton(fHorz2, "Update", B_UPDATE);
442 fBUpdate->Associate(this);
443 fHorz2->AddFrame(fBUpdate, new TGLayoutHints(kLHintsCenterX, 10, 10, 4, 4));
444
445 /* Create "Clear" button */
446 fBClear = new TGTextButton(fHorz2, "Clear", B_CLEAR);
447 fBClear->Associate(this);
448 fHorz2->AddFrame(fBClear, new TGLayoutHints(kLHintsCenterX, 10, 10, 4, 4));
449
450 tf->AddFrame(fTabHisto, new TGLayoutHints(kLHintsTop | kLHintsLeft, 0, 0, 0, 0));
451
452 /*---- status tab ----*/
453
454 tf = fTab->AddTab("Status");
456 /*
457 fHorz3 = new TGHorizontalFrame(fTabStatus, 600, 400);
458 fTabStatus->AddFrame(fHorz3, new TGLayoutHints(kLHintsExpandX|kLHintsExpandY, 0, 0, 0, 0));
459 fHorz3->AddFrame(new TGLabel(fTabStatus, "Test"), new TGLayoutHints(kLHintsExpandX|kLHintsExpandY, 0, 0, 0, 0));
460 */
461 fTabStatus->
462 AddFrame(new TGLabel(fTabStatus, "Here will come the experiment status display"),
463 new TGLayoutHints(kLHintsTop, 100, 100, 100, 0));
464 tf->AddFrame(fTabStatus, new TGLayoutHints(kLHintsTop | kLHintsLeft, 0, 0, 0, 0));
465
466 /*--------------------*/
467
469
470 SetWindowName("RMidas");
471
474 MapWindow();
475
476 fHisto = 0;
477 fHistoNames = 0;
478
479 /* connect to MRootServer */
481}
482
484{
485 // Got close message for this MainFrame. Terminate the application
486 // or returns from the TApplication event loop (depending on the
487 // argument specified in TApplication::Run()).
488
489 gApplication->Terminate(0);
490}
491
493{
494 // Process messages coming from widgets associated with the dialog.
495
496 switch (GET_MSG(msg)) {
497 case kC_COMMAND:
498
499 switch (GET_SUBMSG(msg)) {
500 case kCM_MENU:
501 switch (param1) {
502 case M_FILE_EXIT:
503 CloseWindow();
504 break;
505
506 case M_FILE_CONNECT:
507 fHost[0] = 0;
509 break;
510 }
511 break;
512
513 case kCM_BUTTON:
514 switch (param1) {
515 case B_UPDATE:
516 if (fHisto)
517 GetHisto((char *) fHisto->GetName());
518 break;
519
520 case B_CLEAR:
521 if (fHisto) {
522 ClearHisto((char *) fHisto->GetName());
523 GetHisto((char *) fHisto->GetName());
524 }
525 break;
526 }
527 break;
528
529 case kCM_LISTBOX:
530 GetHisto((const char *) ((TObjString *) (fHistoNames->At(param2)))->String());
531 break;
532
533
534 case kCM_TAB:
535 //printf("Tab item %ld activated\n", param1);
536 break;
537 }
538 break;
539
540 }
541
542 return kTRUE;
543}
544
546{
547 // Clean up
548
549 delete fMenuBar;
550 delete fMenuFile;
551 delete fHisto;
552 delete fHistoNames;
553 delete fSock;
554 delete fBUpdate;
555 delete fHorz1;
556 delete fHorz2;
557 delete fCanvas;
558}
559
560void rmidas()
561{
562 new RMidasFrame(gClient->GetRoot(), 200, 200, "pc2948");
563}
564
565int main(int argc, char **argv)
566{
567 TApplication theApp("RMidas", &argc, argv);
568
569 if (gROOT->IsBatch()) {
570 printf("%s: cannot run in batch mode\n", argv[0]);
571 return 1;
572 }
573
574 new RMidasFrame(gClient->GetRoot(), 200, 200, argv[1]);
575
576 theApp.Run();
577
578 return 0;
579}
TGHorizontalFrame * fHorz1
Definition rmidas.c:243
RMidasFrame(const TGWindow *p, UInt_t w, UInt_t h, char *host="localhost")
Definition rmidas.c:389
TRootEmbeddedCanvas * fCanvas
Definition rmidas.c:248
void GetHistoList()
Definition rmidas.c:326
void GetHisto(const char *name)
Definition rmidas.c:351
char fHost[256]
Definition rmidas.c:253
TGTab * fTab
Definition rmidas.c:239
void ClearHisto(const char *name)
Definition rmidas.c:378
TGCompositeFrame * fTabHisto
Definition rmidas.c:240
void CloseWindow()
Definition rmidas.c:483
TGHorizontalFrame * fHorz3
Definition rmidas.c:245
TObjArray * fHistoNames
Definition rmidas.c:256
TGHorizontalFrame * fHorz2
Definition rmidas.c:244
TGCompositeFrame * fTabStatus
Definition rmidas.c:241
TGPopupMenu * fMenuFile
Definition rmidas.c:237
TSocket * fSock
Definition rmidas.c:254
TGTextButton * fBClear
Definition rmidas.c:251
int ConnectServer()
Definition rmidas.c:274
~RMidasFrame()
Definition rmidas.c:545
TH1 * fHisto
Definition rmidas.c:257
TGMenuBar * fMenuBar
Definition rmidas.c:236
TGListBox * fListBox
Definition rmidas.c:247
TGTextButton * fBUpdate
Definition rmidas.c:250
Bool_t ProcessMessage(Long_t msg, Long_t param1, Long_t param2)
Definition rmidas.c:492
TGButton * fCancelButton
Definition rmidas.c:42
TGCompositeFrame * fF2
Definition rmidas.c:40
virtual Bool_t ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2)
Definition rmidas.c:170
TGTextDialog(const TGWindow *p, const TGWindow *main, UInt_t w, UInt_t h, char *label, char *ret_str, UInt_t options=kVerticalFrame)
Definition rmidas.c:64
virtual ~TGTextDialog()
Definition rmidas.c:144
TGCompositeFrame * fF1
Definition rmidas.c:40
TGLayoutHints * fL6
Definition rmidas.c:43
TGLabel * fLabel
Definition rmidas.c:46
TGLayoutHints * fL21
Definition rmidas.c:43
TGTextBuffer * fBLabel
Definition rmidas.c:45
TGLayoutHints * fL1
Definition rmidas.c:43
virtual void CloseWindow()
Definition rmidas.c:162
char * fRetStr
Definition rmidas.c:47
TGLayoutHints * fL5
Definition rmidas.c:43
TGButton * fOkButton
Definition rmidas.c:41
TGTextEntry * fText
Definition rmidas.c:44
int main()
Definition hwtest.cxx:23
INT i
Definition mdump.cxx:32
#define name(x)
Definition midas_macro.h:24
char str[256]
Definition odbhist.cxx:33
void rmidas()
Definition rmidas.c:560
RMidasCommandIdentifiers
Definition rmidas.c:224
@ B_CLEAR
Definition rmidas.c:228
@ M_FILE_CONNECT
Definition rmidas.c:226
@ B_UPDATE
Definition rmidas.c:227
@ M_FILE_EXIT
Definition rmidas.c:225
TH1X EXPRT * h1_book(const char *name, const char *title, int bins, double min, double max)
Definition rmidas.h:24