]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EVE/EveBase/AliEveMacroExecutorWindow.cxx
Prototype implementation of tags for macro selection.
[u/mrichter/AliRoot.git] / EVE / EveBase / AliEveMacroExecutorWindow.cxx
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>
16 #include <TGLabel.h>
17 #include <TGListBox.h>
18 #include <TGTextEntry.h>
19 #include <Buttons.h>
20
21 #include <TPRegexp.h>
22
23 class AliEveMEWEntry : public TGTextLBEntry
24 {
25 public:
26   static void SetFont() { fgDefaultFont = gClient->GetFontPool()->GetFont("-*-lucidatypewriter-*-*-*-*-12-*-*-*-*-*-iso8859-1"); }
27 };
28
29 class AliEveMEWEditor : public TGedEditor
30 {
31 protected:
32   AliEveMacroExecutorWindow* fMEW;
33
34 public:
35   AliEveMEWEditor(AliEveMacroExecutorWindow* w) : TGedEditor(0), fMEW(w) {}
36   virtual ~AliEveMEWEditor() {}
37   virtual void Update(TGedFrame* gframe=0)
38   {
39     TGedEditor::Update(gframe);
40     fMEW->PopulateMacros();
41   }
42   virtual void Refresh()
43   {
44     SetModel(fPad, fModel, kButton1Down);
45   }
46 };
47
48 //______________________________________________________________________________
49 // Full description of AliEveMacroExecutorWindow
50 //
51
52 ClassImp(AliEveMacroExecutorWindow)
53
54 //______________________________________________________________________________
55 AliEveMacroExecutorWindow::AliEveMacroExecutorWindow(AliEveMacroExecutor* master) :
56   TGMainFrame(gClient->GetRoot()), fM(master),
57   fMainFrame(0), fCtrlFrame(0), fListBox(0), fEditor(0),
58   fSelectTags(0)
59 {
60   // Constructor.
61
62   fMainFrame = new TGVerticalFrame(this);
63   AddFrame(fMainFrame, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));
64
65   TGHorizontalFrame *f = 0;
66   TGButton* b = 0;
67   {
68     fCtrlFrame = MkHFrame(fMainFrame);
69     fCtrlFrame->Resize(400, 22);
70
71     b = new TGTextButton(fCtrlFrame, "Reload event");
72     fCtrlFrame->AddFrame(b);
73     b->Connect("Clicked()", "AliEveMacroExecutorWindow", this,
74                "DoReloadEvent()");
75
76     MkLabel(fCtrlFrame, "Select:", 64);
77     fSelectTags = new TGTextEntry(f);
78     f->AddFrame(fSelectTags, new TGLayoutHints(kLHintsNormal));//|kLHintsExpandX));
79     fSelectTags->Connect("ReturnPressed()", "AliEveMacroEditor", this,
80                          "DoSelectTags()");
81     b = new TGTextButton(fCtrlFrame, "Select");
82     fCtrlFrame->AddFrame(b);
83     b->Connect("Clicked()", "AliEveMacroExecutorWindow", this,
84                "DoSelectTags()");
85
86     b = new TGTextButton(fCtrlFrame, "Enable all");
87     fCtrlFrame->AddFrame(b);
88     b->Connect("Clicked()", "AliEveMacroExecutorWindow", this,
89                "DoEnableAll()");
90
91     b = new TGTextButton(fCtrlFrame, "Disable all");
92     fCtrlFrame->AddFrame(b);
93     b->Connect("Clicked()", "AliEveMacroExecutorWindow", this,
94                "DoDisableAll()");
95   }
96
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)");
102
103   fMainFrame->SetEditDisabled(kEditEnable);
104   fMainFrame->SetEditable();
105   fEditor = new AliEveMEWEditor(this);
106   fEditor->SetGlobal(kFALSE);
107   fMainFrame->SetEditable(kEditDisable);
108   fMainFrame->SetEditable(kFALSE);
109   {
110     TGFrameElement *el = 0;
111     TIter next(fMainFrame->GetList());
112     while ((el = (TGFrameElement *) next())) {
113       if (el->fFrame == fEditor)
114         if (el->fLayout) {
115           el->fLayout->SetLayoutHints(kLHintsExpandX);
116           el->fLayout->SetPadLeft(1); el->fLayout->SetPadRight(1);
117           el->fLayout->SetPadTop(2);  el->fLayout->SetPadBottom(2);
118           break;
119         }
120     }
121   }
122   fEditor->Resize(400, 160);
123   fEditor->ChangeOptions(fEditor->GetOptions() | kFixedHeight);
124
125   Resize(400, 700);
126
127   SetCleanup(kDeepCleanup);
128   Layout();
129   MapSubwindows();
130   MapWindow();
131
132   gAliEveEvent->Connect("NewEventLoaded()", "AliEveMacroExecutorWindow", this,
133                         "NewEventLoaded()");
134 }
135
136 AliEveMacroExecutorWindow::~AliEveMacroExecutorWindow()
137 {
138   // Destructor.
139
140   gAliEveEvent->Disconnect("NewEventLoaded()", this);
141 }
142
143 /******************************************************************************/
144
145 void AliEveMacroExecutorWindow::PopulateMacros(Bool_t keep_selected)
146 {
147   // Populate list-box (or whatever will replace it) with all macros.
148   // prototype: no selection, sorting
149
150   // printf("AliEveMacroExecutorWindow::PopulateMacros()\n");
151
152   AliEveMacro* ex_sel = 0;
153   if (keep_selected && fListBox->GetSelected() != -1)
154     ex_sel = fBoxContents[fListBox->GetSelected()];
155
156   fListBox->RemoveAll();
157   fBoxContents.clear();
158
159   AliEveMEWEntry::SetFont(); 
160
161   TPMERegexp *regexp = 0;
162   TString     select = fSelectTags->GetText();
163   if ( ! select.IsNull())
164   {
165     regexp = new TPMERegexp(select, "io");
166   }
167
168   TIter next(fM->fMacros);
169   AliEveMacro *mac;
170   Int_t        id =  0;
171   Int_t    sel_id = -1;
172   while ((mac = (AliEveMacro*) next()))
173   {
174     if (regexp && regexp->Match(mac->GetTags()) == 0)
175       continue;
176     if (mac == ex_sel)
177       sel_id = id;
178
179     fListBox->AddEntry(mac->FormForDisplay(), id++);
180     fBoxContents.push_back(mac);
181   }
182
183   if (sel_id != -1)
184     fListBox->Select(sel_id);
185
186   fListBox->MapSubwindows();
187   fListBox->Layout();
188 }
189
190 void AliEveMacroExecutorWindow::SetActiveStateOfShownMacros(Bool_t active)
191 {
192   // Set active-state of all shown macros to active.
193   // Automatically refreshes the list and editor.
194
195   for (std::vector<AliEveMacro*>::iterator m = fBoxContents.begin(); m != fBoxContents.end(); ++m)
196     (*m)->SetActive(active);
197   PopulateMacros();
198   fEditor->Refresh();
199 }
200
201 /******************************************************************************/
202
203 void AliEveMacroExecutorWindow::NewEventLoaded()
204 {
205   // Slot called after a new event has been loaded
206
207   // !!! Once we have exit status from the macro, can update GUI showing this.
208 }
209
210 void AliEveMacroExecutorWindow::DoReloadEvent()
211 {
212   // Slot for reload-event.
213
214   gAliEveEvent->GotoEvent(gAliEveEvent->GetEventId());
215 }
216
217 void AliEveMacroExecutorWindow::DoSelectTags()
218 {
219   // Slot for select-tags.
220
221   PopulateMacros();
222 }
223
224 void AliEveMacroExecutorWindow::DoMacroSelected(Int_t mid)
225 {
226   // Slot for macro-selected.
227
228   fEditor->SetModel(0, fBoxContents[mid], kButton1Down);
229 }
230
231 /******************************************************************************/
232
233 TGHorizontalFrame* AliEveMacroExecutorWindow::MkHFrame(TGCompositeFrame* p)
234 {
235   // Make standard horizontal frame.
236
237   if (p == 0)
238     p = this;
239   TGHorizontalFrame* f = new TGHorizontalFrame(p);
240   p->AddFrame(f, new TGLayoutHints(kLHintsNormal|kLHintsExpandX));
241   return f;
242 }
243
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)
246 {
247   // Make standard label.
248
249   TGLabel *l = new TGLabel(p, txt);
250   p->AddFrame(l, new TGLayoutHints(kLHintsNormal, lo,ro,to,bo));
251   l->SetTextJustify(kTextRight);
252   l->SetWidth(width);
253   l->ChangeOptions(l->GetOptions() | kFixedWidth);
254   return l;
255 }