source: trunk/Mars/mbase/MGTask.cc@ 20003

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