]> git.uio.no Git - u/mrichter/AliRoot.git/blame - EVE/EveBase/AliEveMacroExecutorWindow.cxx
Move MultiView.C into EveBase class AliEveMultiView.
[u/mrichter/AliRoot.git] / EVE / EveBase / AliEveMacroExecutorWindow.cxx
CommitLineData
f6afd0e1 1// @(#)root/eve:$Id$
2// Author: Matevz Tadel 2007
3
4/**************************************************************************
5 * Copyright(c) 1998-2008, ALICE Experiment at CERN, all rights reserved. *
6 * See http://aliceinfo.cern.ch/Offline/AliRoot/License.html for *
7 * full copyright notice. *
8 **************************************************************************/
9
10#include "AliEveMacroExecutorWindow.h"
11#include "AliEveMacroExecutor.h"
12#include "AliEveMacro.h"
13#include "AliEveEventManager.h"
14
15#include <TGedEditor.h>
7b2d546e 16#include <TGLabel.h>
f6afd0e1 17#include <TGListBox.h>
7b2d546e 18#include <TGTextEntry.h>
f6afd0e1 19#include <Buttons.h>
20
7b2d546e 21#include <TPRegexp.h>
22
4578afcb 23class AliEveMEWListBox : public TGListBox
f6afd0e1 24{
25public:
4578afcb 26 AliEveMEWListBox(const TGWindow* p = 0, Int_t id = -1) : TGListBox(p, id)
27 {
28 if (gfGC == 0)
29 {
30 const TGGC& old = TGTextLBEntry::GetDefaultGC();
31
32 gfFont = gClient->GetFontPool()->GetFont("-*-lucidatypewriter-*-*-*-*-12-*-*-*-*-*-iso8859-1");
33 gfGC = gClient->GetGCPool()->GetGC((GCValues_t*) old.GetAttributes(), kTRUE);
34 gfGC->SetFont(gVirtualX->GetFontHandle(gfFont->GetFontStruct()));
35 }
36 }
37
38 using TGListBox::AddEntry;
39 virtual void AddEntry(const char* s, Int_t id)
40 {
41 static const Pixel_t gkBackground[] = { 0x00ffffff, 0xf5f7f8 };
42
43 TGTextLBEntry *lbe = new TGTextLBEntry(fLbc, new TGString(s), id,
44 gfGC->GetGC(), gfFont->GetFontStruct());
45 fItemVsize = TMath::Max(fItemVsize, lbe->GetDefaultHeight());
46 fLbc->AddEntry(lbe, new TGLayoutHints(kLHintsExpandX | kLHintsTop));
47 // Need to set it here as the above line sets it to white (for some strange reason).
48 lbe->SetBackgroundColor(gkBackground[id%2]);
49 }
50
51protected:
52 static TGGC *gfGC;
53 static TGFont *gfFont;
3607f2fb 54
55private:
56 AliEveMEWListBox(const AliEveMEWListBox&); // Not implemented
57 AliEveMEWListBox& operator=(const AliEveMEWListBox&); // Not implemented
f6afd0e1 58};
59
4578afcb 60TGGC *AliEveMEWListBox::gfGC = 0;
61TGFont *AliEveMEWListBox::gfFont = 0;
62
63
7b2d546e 64class AliEveMEWEditor : public TGedEditor
f6afd0e1 65{
f6afd0e1 66public:
7b2d546e 67 AliEveMEWEditor(AliEveMacroExecutorWindow* w) : TGedEditor(0), fMEW(w) {}
68 virtual ~AliEveMEWEditor() {}
f6afd0e1 69 virtual void Update(TGedFrame* gframe=0)
70 {
71 TGedEditor::Update(gframe);
72 fMEW->PopulateMacros();
73 }
7b2d546e 74 virtual void Refresh()
75 {
76 SetModel(fPad, fModel, kButton1Down);
77 }
3607f2fb 78protected:
79 AliEveMacroExecutorWindow* fMEW;
80private:
81 AliEveMEWEditor(const AliEveMEWEditor&); // Not implemented
82 AliEveMEWEditor& operator=(const AliEveMEWEditor&); // Not implemented
f6afd0e1 83};
f6afd0e1 84
85//______________________________________________________________________________
86// Full description of AliEveMacroExecutorWindow
87//
88
89ClassImp(AliEveMacroExecutorWindow)
90
91//______________________________________________________________________________
92AliEveMacroExecutorWindow::AliEveMacroExecutorWindow(AliEveMacroExecutor* master) :
93 TGMainFrame(gClient->GetRoot()), fM(master),
7b2d546e 94 fMainFrame(0), fCtrlFrame(0), fListBox(0), fEditor(0),
3607f2fb 95 fSelectTags(0),
96 fBoxContents()
f6afd0e1 97{
98 // Constructor.
99
100 fMainFrame = new TGVerticalFrame(this);
101 AddFrame(fMainFrame, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));
102
4578afcb 103 // TGHorizontalFrame *f = 0;
104 TGButton *b = 0;
f6afd0e1 105 {
7b2d546e 106 fCtrlFrame = MkHFrame(fMainFrame);
107 fCtrlFrame->Resize(400, 22);
f6afd0e1 108
7b2d546e 109 b = new TGTextButton(fCtrlFrame, "Reload event");
f6afd0e1 110 fCtrlFrame->AddFrame(b);
111 b->Connect("Clicked()", "AliEveMacroExecutorWindow", this,
112 "DoReloadEvent()");
7b2d546e 113
4578afcb 114 MkLabel(fCtrlFrame, "Select: ", 48);
115 fSelectTags = new TGTextEntry(fCtrlFrame);
116 fCtrlFrame->AddFrame(fSelectTags, new TGLayoutHints(kLHintsNormal));//|kLHintsExpandX));
117 fSelectTags->Connect("ReturnPressed()", "AliEveMacroExecutorWindow", this,
7b2d546e 118 "DoSelectTags()");
119 b = new TGTextButton(fCtrlFrame, "Select");
120 fCtrlFrame->AddFrame(b);
121 b->Connect("Clicked()", "AliEveMacroExecutorWindow", this,
122 "DoSelectTags()");
123
124 b = new TGTextButton(fCtrlFrame, "Enable all");
125 fCtrlFrame->AddFrame(b);
126 b->Connect("Clicked()", "AliEveMacroExecutorWindow", this,
127 "DoEnableAll()");
128
129 b = new TGTextButton(fCtrlFrame, "Disable all");
130 fCtrlFrame->AddFrame(b);
131 b->Connect("Clicked()", "AliEveMacroExecutorWindow", this,
132 "DoDisableAll()");
f6afd0e1 133 }
134
4578afcb 135 fListBox = new AliEveMEWListBox(fMainFrame);
f6afd0e1 136 fMainFrame->AddFrame(fListBox, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));
137 fListBox->Resize(400, 400);
138 fListBox->Connect("Selected(Int_t)", "AliEveMacroExecutorWindow", this,
139 "DoMacroSelected(Int_t)");
140
141 fMainFrame->SetEditDisabled(kEditEnable);
142 fMainFrame->SetEditable();
7b2d546e 143 fEditor = new AliEveMEWEditor(this);
f6afd0e1 144 fEditor->SetGlobal(kFALSE);
145 fMainFrame->SetEditable(kEditDisable);
146 fMainFrame->SetEditable(kFALSE);
147 {
148 TGFrameElement *el = 0;
149 TIter next(fMainFrame->GetList());
150 while ((el = (TGFrameElement *) next())) {
151 if (el->fFrame == fEditor)
152 if (el->fLayout) {
153 el->fLayout->SetLayoutHints(kLHintsExpandX);
154 el->fLayout->SetPadLeft(1); el->fLayout->SetPadRight(1);
155 el->fLayout->SetPadTop(2); el->fLayout->SetPadBottom(2);
156 break;
157 }
158 }
159 }
4578afcb 160 fEditor->Resize(400, 150);
f6afd0e1 161 fEditor->ChangeOptions(fEditor->GetOptions() | kFixedHeight);
162
163 Resize(400, 700);
164
165 SetCleanup(kDeepCleanup);
166 Layout();
167 MapSubwindows();
168 MapWindow();
169
4d62585e 170 AliEveEventManager::GetMaster()->Connect("NewEventLoaded()", "AliEveMacroExecutorWindow", this,
f6afd0e1 171 "NewEventLoaded()");
172}
173
174AliEveMacroExecutorWindow::~AliEveMacroExecutorWindow()
175{
176 // Destructor.
177
4d62585e 178 AliEveEventManager::GetMaster()->Disconnect("NewEventLoaded()", this);
f6afd0e1 179}
180
181/******************************************************************************/
182
183void AliEveMacroExecutorWindow::PopulateMacros(Bool_t keep_selected)
184{
185 // Populate list-box (or whatever will replace it) with all macros.
186 // prototype: no selection, sorting
187
188 // printf("AliEveMacroExecutorWindow::PopulateMacros()\n");
189
190 AliEveMacro* ex_sel = 0;
191 if (keep_selected && fListBox->GetSelected() != -1)
192 ex_sel = fBoxContents[fListBox->GetSelected()];
193
194 fListBox->RemoveAll();
195 fBoxContents.clear();
196
7b2d546e 197 TPMERegexp *regexp = 0;
198 TString select = fSelectTags->GetText();
199 if ( ! select.IsNull())
200 {
68ca2fe7 201 regexp = new TPMERegexp(select, "io");
7b2d546e 202 }
f6afd0e1 203
204 TIter next(fM->fMacros);
205 AliEveMacro *mac;
206 Int_t id = 0;
207 Int_t sel_id = -1;
208 while ((mac = (AliEveMacro*) next()))
209 {
7b2d546e 210 if (regexp && regexp->Match(mac->GetTags()) == 0)
211 continue;
f6afd0e1 212 if (mac == ex_sel)
213 sel_id = id;
7b2d546e 214
f6afd0e1 215 fListBox->AddEntry(mac->FormForDisplay(), id++);
216 fBoxContents.push_back(mac);
217 }
218
219 if (sel_id != -1)
220 fListBox->Select(sel_id);
221
222 fListBox->MapSubwindows();
223 fListBox->Layout();
224}
225
7b2d546e 226void AliEveMacroExecutorWindow::SetActiveStateOfShownMacros(Bool_t active)
227{
228 // Set active-state of all shown macros to active.
229 // Automatically refreshes the list and editor.
230
231 for (std::vector<AliEveMacro*>::iterator m = fBoxContents.begin(); m != fBoxContents.end(); ++m)
232 (*m)->SetActive(active);
233 PopulateMacros();
234 fEditor->Refresh();
235}
236
f6afd0e1 237/******************************************************************************/
238
239void AliEveMacroExecutorWindow::NewEventLoaded()
240{
241 // Slot called after a new event has been loaded
242
243 // !!! Once we have exit status from the macro, can update GUI showing this.
244}
245
246void AliEveMacroExecutorWindow::DoReloadEvent()
247{
248 // Slot for reload-event.
249
4d62585e 250 AliEveEventManager::GetMaster()->GotoEvent(AliEveEventManager::GetMaster()->GetEventId());
f6afd0e1 251}
252
7b2d546e 253void AliEveMacroExecutorWindow::DoSelectTags()
254{
255 // Slot for select-tags.
256
257 PopulateMacros();
258}
259
f6afd0e1 260void AliEveMacroExecutorWindow::DoMacroSelected(Int_t mid)
261{
262 // Slot for macro-selected.
263
264 fEditor->SetModel(0, fBoxContents[mid], kButton1Down);
265}
7b2d546e 266
267/******************************************************************************/
268
269TGHorizontalFrame* AliEveMacroExecutorWindow::MkHFrame(TGCompositeFrame* p)
270{
271 // Make standard horizontal frame.
272
273 if (p == 0)
274 p = this;
275 TGHorizontalFrame* f = new TGHorizontalFrame(p);
276 p->AddFrame(f, new TGLayoutHints(kLHintsNormal|kLHintsExpandX));
277 return f;
278}
279
280TGLabel* AliEveMacroExecutorWindow::MkLabel(TGCompositeFrame* p, const char* txt, Int_t width,
281 Int_t lo, Int_t ro, Int_t to, Int_t bo)
282{
283 // Make standard label.
284
285 TGLabel *l = new TGLabel(p, txt);
286 p->AddFrame(l, new TGLayoutHints(kLHintsNormal, lo,ro,to,bo));
287 l->SetTextJustify(kTextRight);
288 l->SetWidth(width);
289 l->ChangeOptions(l->GetOptions() | kFixedWidth);
290 return l;
291}