New class TPCLoader providing (graphical) interface for navigation through the TPC...
[u/mrichter/AliRoot.git] / EVE / Alieve / TPCLoaderEditor.cxx
1 // $Header$
2
3 #include "TPCLoaderEditor.h"
4 #include <Alieve/TPCLoader.h>
5 #include <Reve/RGTopFrame.h>
6 #include <Reve/RGValuators.h>
7
8 #include <TSystem.h>
9 #include <TVirtualPad.h>
10 #include <TColor.h>
11
12 #include <TGLabel.h>
13 #include <TGButton.h>
14 #include <TGTextEntry.h>
15 #include <TGNumberEntry.h>
16 #include <TGFileDialog.h>
17
18 using namespace Reve;
19 using namespace Alieve;
20
21 //______________________________________________________________________
22 // TPCLoaderEditor
23 //
24
25 ClassImp(TPCLoaderEditor)
26
27 TPCLoaderEditor::TPCLoaderEditor(const TGWindow *p, Int_t id, Int_t width, Int_t height,
28                                  UInt_t options, Pixel_t back) :
29   TGedFrame(p, id, width, height, options | kVerticalFrame, back)
30 {
31   fM = 0;
32   MakeTitle("TPCLoader");
33
34   Int_t labelW = 42;
35   {
36     TGHorizontalFrame* f = new TGHorizontalFrame(this);
37     TGHorizontalFrame* g = new TGHorizontalFrame(f, labelW, 0, kFixedWidth);
38     TGLabel* l = new TGLabel(g, "File: ");
39     g->AddFrame(l, new TGLayoutHints(kLHintsLeft, 0,0,4,0));
40     f->AddFrame(g);
41     fFile = new TGTextEntry(f);
42     fFile->SetWidth(140);
43     f->AddFrame(fFile);
44     fFile->Connect("DoubleClicked()",
45                    "Alieve::TPCLoaderEditor", this, "FileSelect()");
46     fFile->Connect("TextChanged(const char *)",
47                    "Alieve::TPCLoaderEditor", this, "FileChanged()");
48     fOpenFile = new TGTextButton(f, "Open");
49     f->AddFrame(fOpenFile);
50     fOpenFile->Connect("Clicked()",
51                        "Alieve::TPCLoaderEditor", this, "DoOpen()");
52     AddFrame(f);
53   }
54
55   fEvent = new RGValuator(this, "Event:", 110, 0);
56   fEvent->SetShowSlider(kFALSE);
57   fEvent->SetLabelWidth(labelW);
58   fEvent->SetNELength(6);
59   fEvent->Build();
60   fEvent->SetLimits(0, 1000);
61   fEvent->SetToolTip("Current event number");
62   fEvent->Connect("ValueSet(Double_t)",
63                   "Alieve::TPCLoaderEditor", this, "DoEvent()");
64   AddFrame(fEvent);
65
66   fUpdateSectors = new TGTextButton(this, "Update Sectors");
67   AddFrame(fUpdateSectors, new TGLayoutHints(kLHintsExpandX, 8,8,8,0));
68   fUpdateSectors->Connect("Clicked()",
69                      "Alieve::TPCLoaderEditor", this, "DoUpdateSectors()");
70   {
71     TGHorizontalFrame* f = new TGHorizontalFrame(this);
72     fCreateSectors3D = new TGTextButton(f, "Create 3D");
73     f->AddFrame(fCreateSectors3D, new TGLayoutHints(kLHintsExpandX, 0,4,0,0));
74     fCreateSectors3D->Connect("Clicked()",
75                      "Alieve::TPCLoaderEditor", this, "DoCreateSectors3D()");
76     fDeleteSectors3D = new TGTextButton(f, "Delete 3D");
77     f->AddFrame(fDeleteSectors3D, new TGLayoutHints(kLHintsExpandX, 4,0,0,0));
78     fDeleteSectors3D->Connect("Clicked()",
79                      "Alieve::TPCLoaderEditor", this, "DoDeleteSectors3D()");
80     AddFrame(f, new TGLayoutHints(kLHintsExpandX, 8,8,8,0));
81   }
82
83   // Register the editor.
84   TClass *cl = TPCLoader::Class();
85   TGedElement *ge = new TGedElement;
86   ge->fGedFrame = this;
87   ge->fCanvas = 0;
88   cl->GetEditorList()->Add(ge);
89 }
90
91 TPCLoaderEditor::~TPCLoaderEditor()
92 {}
93
94 /**************************************************************************/
95
96 void TPCLoaderEditor::SetModel(TVirtualPad* pad, TObject* obj, Int_t /*event*/)
97 {
98   fModel = 0;
99   fPad   = 0;
100
101   if (!obj || !obj->InheritsFrom(TPCLoader::Class()) || obj->InheritsFrom(TVirtualPad::Class())) {
102     SetActive(kFALSE);
103     return;
104   }
105
106   fModel = obj;
107   fPad   = pad;
108
109   fM = dynamic_cast<TPCLoader*>(fModel);
110
111   fFile->SetText(fM->fFile);
112   fEvent->SetValue(fM->fEvent);
113   fEvent->SetEnabled(fM->fEvent >= 0);
114     
115   SetActive();
116 }
117
118 /**************************************************************************/
119 /**************************************************************************/
120
121 namespace {
122 const char *tpcfiletypes[] = {
123    "Root files",  "*.root",
124    "All files",   "*.*",
125     0,               0
126 };
127 }
128
129 void TPCLoaderEditor::FileSelect()
130 {
131   TGFileInfo fi;
132   fi.fFileTypes = tpcfiletypes;
133   new TGFileDialog(fClient->GetRoot(), gReve, kFDOpen, &fi);
134   if (!fi.fFilename) return;
135   fFile->SetText(gSystem->BaseName(fi.fFilename));
136 }
137
138 void TPCLoaderEditor::FileChanged()
139 {
140   fM->fFile = fFile->GetText();
141 }
142
143 void TPCLoaderEditor::DoOpen()
144 {
145   fM->OpenFile();
146   SetModel(fPad, fModel, 0);
147 }
148
149 /**************************************************************************/
150
151 void TPCLoaderEditor::DoEvent()
152 {
153   fM->GotoEvent((Int_t) fEvent->GetValue());
154   SetModel(fPad, fModel, 0);
155 }
156
157 /**************************************************************************/
158
159 void TPCLoaderEditor::DoUpdateSectors()
160 {
161   fM->UpdateSectors();
162 }
163
164 void TPCLoaderEditor::DoCreateSectors3D()
165 {
166   fM->CreateSectors3D();
167 }
168
169
170 void TPCLoaderEditor::DoDeleteSectors3D()
171 {
172   fM->DeleteSectors3D();
173 }
174