source: trunk/MagicSoft/Mars/mbase/MGTask.cc@ 1076

Last change on this file since 1076 was 1076, checked in by tbretz, 23 years ago
*** empty log message ***
File size: 5.3 KB
Line 
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 11/2001 (tbretz@uni-sw.gwdg.de)
19!
20! Copyright: MAGIC Software Development, 2000-2001
21!
22!
23\* ======================================================================== */
24
25/////////////////////////////////////////////////////////////////////////////
26// //
27// MGTask //
28// //
29// A MTask with several enhancments for a graphical interface. //
30// //
31/////////////////////////////////////////////////////////////////////////////
32
33#include "MGTask.h"
34
35#include <TMethod.h>
36
37#include "MLog.h"
38#include "MGGroupFrame.h"
39
40ClassImp(MGTask);
41
42// --------------------------------------------------------------------------
43//
44// Default constructor. Initialized fFrame with NULL.
45//
46MGTask::MGTask(const char *name, const char *title)
47 : fFrame(NULL)
48{
49 fName = name ? name : "MGTask";
50 fTitle = title ? title : "Base class for all tasks with graphical I/O.";
51}
52
53// --------------------------------------------------------------------------
54//
55// Deletes the GUI if one was created.
56//
57MGTask::~MGTask()
58{
59 if (fFrame)
60 delete fFrame;
61}
62
63// --------------------------------------------------------------------------
64//
65// Hides the graphical interface if existing and calls
66// MTask::CallPreProcess
67//
68Bool_t MGTask::CallPreProcess(MParList *plist)
69{
70 HideGui();
71
72 return MTask::CallPreProcess(plist);
73}
74
75// --------------------------------------------------------------------------
76//
77// Shows the graphical interface if existing and calls
78// MTask::CallPostProcess
79//
80Bool_t MGTask::CallPostProcess()
81{
82 ShowGui();
83
84 return MTask::CallPostProcess();
85}
86
87// --------------------------------------------------------------------------
88//
89// Get the Widget from the MGGroupFrame (GUI) with the Id id.
90//
91TObject *MGTask::FindWidget(Int_t id) const
92{
93 return fFrame->FindWidget(id);
94}
95
96// --------------------------------------------------------------------------
97//
98// Process a message. Redirect gui events (eg by calling
99// TGButton->Associate()) to the MGGroupFrame when Creating the GUI in
100// CreateGuiElements. And process the messages in the overwritten
101// ProcessMessage function.
102//
103Bool_t MGTask::ProcessMessage(Int_t msg, Int_t submsg, Long_t param1, Long_t param2)
104{
105 fLog->setf(ios::showbase);
106 *fLog << "Task " << GetDescriptor() << " received gui msg " << hex;
107 *fLog << msg << " " << submsg << " " << param1 << " " << param2 << endl;
108 return kTRUE;
109}
110
111// --------------------------------------------------------------------------
112//
113// Show the gui (and its gui elements) of the task if existing.
114//
115void MGTask::ShowGui()
116{
117 if (fFrame)
118 fFrame->MapWindow();
119}
120
121// --------------------------------------------------------------------------
122//
123// Hide the gui (and its gui elements) of the task if existing.
124//
125void MGTask::HideGui()
126{
127 if (fFrame)
128 fFrame->UnmapWindow();
129}
130
131// --------------------------------------------------------------------------
132//
133// Check whether a gui for this task was already created.
134// If not create a MGGroupFrame to group the gui elements and add it
135// to the given frame with the given layout hints.
136// Now call the overwritten function CreateGuiElements to fill the group
137// frame.
138//
139void MGTask::CreateGui(TGCompositeFrame *f, TGLayoutHints *layout)
140{
141 //
142 // Check whether frame already exists
143 //
144 if (fFrame)
145 {
146 *fLog << GetDescriptor() << ": Gui already created... skipped." << endl;
147 return;
148 }
149
150 //
151 // Check whether a gui is implemented for this class
152 // - IsA gives a pointer to the dictionary entry of the mostly
153 // inherited class of this Task
154 // - GetMethodAllAny checks for the existance of CreateGuiElements
155 // in the class and all its base classes
156 // - now get the dictionary entry of the corresponding class
157 // (in which the mathos was found)
158 // - if method isn't overwritten the result is the dictionary
159 // entry for MGTask.
160 //
161 TMethod *method = IsA()->GetMethodAllAny("CreateGuiElements");
162 if (method->GetClass() == MGTask::Class())
163 {
164 *fLog << "Sorry, " << GetDescriptor();
165 *fLog << " doesn't override CreateGuiElements." << endl;
166 return;
167 }
168
169 //
170 // create group frame
171 //
172 fFrame = new MGGroupFrame(this, f, ClassName());
173 f->AddFrame(fFrame, layout);
174
175 //
176 // add gui elements
177 //
178 CreateGuiElements(fFrame);
179}
Note: See TracBrowser for help on using the repository browser.