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

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