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

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