2 // Author: Matevz Tadel 2007
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 **************************************************************************/
10 #include "AliEveMacroExecutorWindow.h"
11 #include "AliEveMacroExecutor.h"
12 #include "AliEveMacro.h"
13 #include "AliEveEventManager.h"
15 #include <TGedEditor.h>
17 #include <TGListBox.h>
18 #include <TGTextEntry.h>
23 class AliEveMEWEntry : public TGTextLBEntry
26 static void SetFont() { fgDefaultFont = gClient->GetFontPool()->GetFont("-*-lucidatypewriter-*-*-*-*-12-*-*-*-*-*-iso8859-1"); }
29 class AliEveMEWEditor : public TGedEditor
32 AliEveMacroExecutorWindow* fMEW;
35 AliEveMEWEditor(AliEveMacroExecutorWindow* w) : TGedEditor(0), fMEW(w) {}
36 virtual ~AliEveMEWEditor() {}
37 virtual void Update(TGedFrame* gframe=0)
39 TGedEditor::Update(gframe);
40 fMEW->PopulateMacros();
42 virtual void Refresh()
44 SetModel(fPad, fModel, kButton1Down);
48 //______________________________________________________________________________
49 // Full description of AliEveMacroExecutorWindow
52 ClassImp(AliEveMacroExecutorWindow)
54 //______________________________________________________________________________
55 AliEveMacroExecutorWindow::AliEveMacroExecutorWindow(AliEveMacroExecutor* master) :
56 TGMainFrame(gClient->GetRoot()), fM(master),
57 fMainFrame(0), fCtrlFrame(0), fListBox(0), fEditor(0),
62 fMainFrame = new TGVerticalFrame(this);
63 AddFrame(fMainFrame, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));
65 TGHorizontalFrame *f = 0;
68 fCtrlFrame = MkHFrame(fMainFrame);
69 fCtrlFrame->Resize(400, 22);
71 b = new TGTextButton(fCtrlFrame, "Reload event");
72 fCtrlFrame->AddFrame(b);
73 b->Connect("Clicked()", "AliEveMacroExecutorWindow", this,
76 MkLabel(fCtrlFrame, "Select:", 64);
77 fSelectTags = new TGTextEntry(f);
78 f->AddFrame(fSelectTags, new TGLayoutHints(kLHintsNormal));//|kLHintsExpandX));
79 fSelectTags->Connect("ReturnPressed()", "AliEveMacroEditor", this,
81 b = new TGTextButton(fCtrlFrame, "Select");
82 fCtrlFrame->AddFrame(b);
83 b->Connect("Clicked()", "AliEveMacroExecutorWindow", this,
86 b = new TGTextButton(fCtrlFrame, "Enable all");
87 fCtrlFrame->AddFrame(b);
88 b->Connect("Clicked()", "AliEveMacroExecutorWindow", this,
91 b = new TGTextButton(fCtrlFrame, "Disable all");
92 fCtrlFrame->AddFrame(b);
93 b->Connect("Clicked()", "AliEveMacroExecutorWindow", this,
97 fListBox = new TGListBox(fMainFrame);
98 fMainFrame->AddFrame(fListBox, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));
99 fListBox->Resize(400, 400);
100 fListBox->Connect("Selected(Int_t)", "AliEveMacroExecutorWindow", this,
101 "DoMacroSelected(Int_t)");
103 fMainFrame->SetEditDisabled(kEditEnable);
104 fMainFrame->SetEditable();
105 fEditor = new AliEveMEWEditor(this);
106 fEditor->SetGlobal(kFALSE);
107 fMainFrame->SetEditable(kEditDisable);
108 fMainFrame->SetEditable(kFALSE);
110 TGFrameElement *el = 0;
111 TIter next(fMainFrame->GetList());
112 while ((el = (TGFrameElement *) next())) {
113 if (el->fFrame == fEditor)
115 el->fLayout->SetLayoutHints(kLHintsExpandX);
116 el->fLayout->SetPadLeft(1); el->fLayout->SetPadRight(1);
117 el->fLayout->SetPadTop(2); el->fLayout->SetPadBottom(2);
122 fEditor->Resize(400, 160);
123 fEditor->ChangeOptions(fEditor->GetOptions() | kFixedHeight);
127 SetCleanup(kDeepCleanup);
132 gAliEveEvent->Connect("NewEventLoaded()", "AliEveMacroExecutorWindow", this,
136 AliEveMacroExecutorWindow::~AliEveMacroExecutorWindow()
140 gAliEveEvent->Disconnect("NewEventLoaded()", this);
143 /******************************************************************************/
145 void AliEveMacroExecutorWindow::PopulateMacros(Bool_t keep_selected)
147 // Populate list-box (or whatever will replace it) with all macros.
148 // prototype: no selection, sorting
150 // printf("AliEveMacroExecutorWindow::PopulateMacros()\n");
152 AliEveMacro* ex_sel = 0;
153 if (keep_selected && fListBox->GetSelected() != -1)
154 ex_sel = fBoxContents[fListBox->GetSelected()];
156 fListBox->RemoveAll();
157 fBoxContents.clear();
159 AliEveMEWEntry::SetFont();
161 TPMERegexp *regexp = 0;
162 TString select = fSelectTags->GetText();
163 if ( ! select.IsNull())
165 regexp = new TPMERegexp(select, "io");
168 TIter next(fM->fMacros);
172 while ((mac = (AliEveMacro*) next()))
174 if (regexp && regexp->Match(mac->GetTags()) == 0)
179 fListBox->AddEntry(mac->FormForDisplay(), id++);
180 fBoxContents.push_back(mac);
184 fListBox->Select(sel_id);
186 fListBox->MapSubwindows();
190 void AliEveMacroExecutorWindow::SetActiveStateOfShownMacros(Bool_t active)
192 // Set active-state of all shown macros to active.
193 // Automatically refreshes the list and editor.
195 for (std::vector<AliEveMacro*>::iterator m = fBoxContents.begin(); m != fBoxContents.end(); ++m)
196 (*m)->SetActive(active);
201 /******************************************************************************/
203 void AliEveMacroExecutorWindow::NewEventLoaded()
205 // Slot called after a new event has been loaded
207 // !!! Once we have exit status from the macro, can update GUI showing this.
210 void AliEveMacroExecutorWindow::DoReloadEvent()
212 // Slot for reload-event.
214 gAliEveEvent->GotoEvent(gAliEveEvent->GetEventId());
217 void AliEveMacroExecutorWindow::DoSelectTags()
219 // Slot for select-tags.
224 void AliEveMacroExecutorWindow::DoMacroSelected(Int_t mid)
226 // Slot for macro-selected.
228 fEditor->SetModel(0, fBoxContents[mid], kButton1Down);
231 /******************************************************************************/
233 TGHorizontalFrame* AliEveMacroExecutorWindow::MkHFrame(TGCompositeFrame* p)
235 // Make standard horizontal frame.
239 TGHorizontalFrame* f = new TGHorizontalFrame(p);
240 p->AddFrame(f, new TGLayoutHints(kLHintsNormal|kLHintsExpandX));
244 TGLabel* AliEveMacroExecutorWindow::MkLabel(TGCompositeFrame* p, const char* txt, Int_t width,
245 Int_t lo, Int_t ro, Int_t to, Int_t bo)
247 // Make standard label.
249 TGLabel *l = new TGLabel(p, txt);
250 p->AddFrame(l, new TGLayoutHints(kLHintsNormal, lo,ro,to,bo));
251 l->SetTextJustify(kTextRight);
253 l->ChangeOptions(l->GetOptions() | kFixedWidth);