KaliVeda  1.13/01
Heavy-Ion Analysis Toolkit
KVIDGUITelescopeChooserDialog.cpp
Go to the documentation of this file.
1 /*
2 $Id: KVIDGUITelescopeChooserDialog.cpp,v 1.2 2009/03/03 14:27:15 franklan Exp $
3 $Revision: 1.2 $
4 $Date: 2009/03/03 14:27:15 $
5 */
6 
7 //Created by KVClassFactory on Mon Nov 17 14:41:53 2008
8 //Author: franklan
9 
11 #include "TTimer.h"
12 
13 using namespace std;
14 
16 
17 
18 
23  const TGWindow* p, const TGWindow* main, Bool_t disable_type_select,
24  UInt_t w, UInt_t h)
25 {
26  // Create and display dialog for choosing ID telescopes
27  // cancel_pressed = kTRUE if cancel button is pressed
28 
29  fSelection = selection;
30  fMultiDet = MDA;
31 
32  if (!MDA) return;
33 
34  fCancelPress = cancel_pressed;
35  *fCancelPress = kTRUE;
36 
37  int dx = 358;
38  int xx = 400;
39 
40  // main frame
41  fMainFrame1428 = new TGTransientFrame(p, main, w, h);
42  fMainFrame1428->SetLayoutBroken(kTRUE);
43  fMainFrame1428->Connect("CloseWindow()", "KVIDGUITelescopeChooserDialog", this,
44  "DoClose()");
45  fMainFrame1428->DontCallClose(); // to avoid double deletions.
46  // use hierarchical cleaning
47  fMainFrame1428->SetCleanup(kDeepCleanup);
48 
49  // composite frame
50  TGCompositeFrame* fMainFrame979 = new TGCompositeFrame(fMainFrame1428, xx, 273, kVerticalFrame);
51  fMainFrame979->SetLayoutBroken(kTRUE);
52 
53  // combo box with list of ID telescope types
54  fComboBox994 = new TGComboBox(fMainFrame979, -1, kHorizontalFrame | kSunkenFrame | kDoubleBorder | kOwnBackground);
55 
56  //get list of ID telescope types from multidetarray
57  unique_ptr<KVUniqueNameList> id_types(MDA->GetIDTelescopeTypes());
58  // fill combo with types in list id_types
59  TIter next_type(id_types.get());
60  TObjString* type_string;
61  int entry_id = 0;
62  while ((type_string = (TObjString*)next_type())) {
63  fComboBox994->AddEntry(type_string->GetString().Data(), entry_id++);
64  }
65 
66  fComboBox994->Resize(dx, 22);
67  fComboBox994->Select(-1);
68  fMainFrame979->AddFrame(fComboBox994, new TGLayoutHints(kLHintsLeft | kLHintsTop, 2, 2, 2, 2));
69  fComboBox994->MoveResize(24, 40, dx, 22);
70  if (disable_type_select) fComboBox994->SetEnabled(kFALSE);
71 
72  TGLabel* fLabel1012 = new TGLabel(fMainFrame979, "Select ID telescope(s):");
73  fLabel1012->SetTextJustify(36);
74  fLabel1012->SetMargins(0, 0, 0, 0);
75  fLabel1012->SetWrapLength(-1);
76  fMainFrame979->AddFrame(fLabel1012, new TGLayoutHints(kLHintsLeft | kLHintsTop, 2, 2, 2, 2));
77  fLabel1012->MoveResize(24, 72, dx, 18);
78 
79  TGLabel* fLabel1013 = new TGLabel(fMainFrame979, "Select ID type:");
80  fLabel1013->SetTextJustify(36);
81  fLabel1013->SetMargins(0, 0, 0, 0);
82  fLabel1013->SetWrapLength(-1);
83  fMainFrame979->AddFrame(fLabel1013, new TGLayoutHints(kLHintsLeft | kLHintsTop, 2, 2, 2, 2));
84  fLabel1013->MoveResize(24, 8, dx, 18);
85 
86  // list box
87  fListBox980 = new TGListBox(fMainFrame979);
88  fListBox980->Resize(dx, 132);
89  // fill with dummy entries (for padding)
90  for (int i = 0; i < 10; i++) fListBox980->AddEntry(" ", i);
91  fMainFrame979->AddFrame(fListBox980, new TGLayoutHints(kLHintsLeft | kLHintsTop, 2, 2, 2, 2));
92  fListBox980->MapSubwindows();
93  fListBox980->Layout();
94  fListBox980->MoveResize(24, 104, dx, 132);
95  fListBox980->SetMultipleSelections();
96 
97  TGTextButton* fTextButton1052 = new TGTextButton(fMainFrame979, "Cancel");
98  fTextButton1052->SetTextJustify(36);
99  fTextButton1052->SetMargins(0, 0, 0, 0);
100  fTextButton1052->SetWrapLength(-1);
101  fTextButton1052->Resize(72, 24);
102  fMainFrame979->AddFrame(fTextButton1052, new TGLayoutHints(kLHintsLeft | kLHintsTop, 2, 2, 2, 2));
103  fTextButton1052->MoveResize(140, 245, 72, 24);
104 
105  TGTextButton* fTextButton1057 = new TGTextButton(fMainFrame979, "OK");
106  fTextButton1057->SetTextJustify(36);
107  fTextButton1057->SetMargins(0, 0, 0, 0);
108  fTextButton1057->SetWrapLength(-1);
109  fTextButton1057->Resize(72, 24);
110  fMainFrame979->AddFrame(fTextButton1057, new TGLayoutHints(kLHintsLeft | kLHintsTop, 2, 2, 2, 2));
111  fTextButton1057->MoveResize(220, 245, 72, 24);
112 
113  fMainFrame1428->AddFrame(fMainFrame979, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));
114  fMainFrame979->MoveResize(0, 0, xx, 273);
115 
116  fMainFrame1428->SetMWMHints(kMWMDecorAll,
117  kMWMFuncAll,
119  fMainFrame1428->MapSubwindows();
120 
121  fMainFrame1428->Resize(fMainFrame1428->GetDefaultSize());
122  fMainFrame1428->CenterOnParent();
123  fMainFrame1428->MapWindow();
124  fMainFrame1428->Resize(xx, 291);
125 
126  /**** connect signals & slots ***/
127  // choice of ID type
128  fComboBox994->Connect("Selected(const char*)", "KVIDGUITelescopeChooserDialog", this,
129  "FillTelescopeListWithType(const char*)");
130  // cancel button -> close window, leave list empty
131  fTextButton1052->Connect("Clicked()", "KVIDGUITelescopeChooserDialog", this, "DoClose()");
132  // OK button -> fill list with selected telescopes, then close window
133  fTextButton1057->Connect("Clicked()", "KVIDGUITelescopeChooserDialog", this, "GetSelection()");
134 
135  // if list already contains selected telescopes, we change state of dialog box
136  // to reflect previous selection
137  if (fSelection->GetEntries()) HighlightSelectedTelescopes();
138 
139  //nothing happens until window closes
140  gClient->WaitFor(fMainFrame1428);
141 }
142 
143 
144 
148 
150 {
151  // Destructor
152  // Delete all widgets
153 
154  if (fMainFrame1428) {
155  delete fMainFrame1428;
156  fMainFrame1428 = 0;
157  }
158 }
159 
160 
161 
163 
165 {
166  TTimer::SingleShot(150, "KVIDGUITelescopeChooserDialog", this,
167  "CloseWindow()");
168 }
169 
170 
171 
173 
175 {
176  delete this;
177 }
178 
179 
180 
183 
185 {
186  // fill TGListBox with names of all ID telescopes of given type
187 
188  fListBox980->RemoveAll();
189  fListBox980->Layout();
190  unique_ptr<KVSeqCollection> telescopes(fMultiDet->GetIDTelescopesWithType(type));
191  TIter next_tel(telescopes.get());
192  KVIDTelescope* idt;
193  int i = 0;
194  while ((idt = (KVIDTelescope*)next_tel())) {
195  fListBox980->AddEntry(idt->GetName(), i++);
196  }
197  fListBox980->SortByName();
198  fListBox980->MapSubwindows();
199  fListBox980->Layout();
200 }
201 
202 
203 
207 
209 {
210  // fill fSelection list with telescopes selected by user
211  // set cancel_pressed to kFALSE
212 
213  fSelection->Clear();
214  TList lbentries;
215  fListBox980->GetSelectedEntries(&lbentries);
216  TIter next_lbe(&lbentries);
217  TGLBEntry* lbe;
218  while ((lbe = (TGLBEntry*)next_lbe())) {
219  fSelection->Add(fMultiDet->GetIDTelescope(lbe->GetTitle()));
220  }
221  *fCancelPress = kFALSE;
222  DoClose();
223 }
224 
225 
229 
231 {
232  // Modify widgets to reflect the ID telescopes selected in the list fSelection
233 
234  // Get 'type' of first telescope
235  KVIDTelescope* id = (KVIDTelescope*)fSelection->At(0);
236  if (!id) return;
237  // look for 'type' in list of types
238  TGLBEntry* lbe = fComboBox994->FindEntry(id->GetLabel());
239  if (!lbe) {
240  cout << "<KVIDGUITelescopeChooserDialog::HighlightSelectedTelescopes()> : Type "
241  << id->GetLabel() << " not found in combo box" << endl;
242  return;
243  }
244  // make 'type' be selected entry
245  fComboBox994->Select(lbe->EntryId());
246  FillTelescopeListWithType(id->GetLabel());
247  // now 'select' telescopes
248  TIter next_tel(fSelection);
249  int first_tel = -1;
250  while ((id = (KVIDTelescope*)next_tel())) {
251  lbe = fListBox980->FindEntry(id->GetName());
252  if (lbe) {
253  if (first_tel < 0) first_tel = lbe->EntryId();
254  fListBox980->Select(lbe->EntryId());
255  }
256  }
257  // scroll down to first selected telescope
258  fListBox980->SetTopEntry(first_tel);
259 }
260 
261 
unsigned int UInt_t
kSunkenFrame
kVerticalFrame
kDoubleBorder
kHorizontalFrame
kOwnBackground
ClassImp(KVPartitionList) void KVPartitionList
Initialisation.
const Bool_t kFALSE
bool Bool_t
const Bool_t kTRUE
#define gClient
kMWMFuncAll
kMWMDecorAll
kMWMInputModeless
kDeepCleanup
kLHintsExpandY
kLHintsLeft
kLHintsTop
kLHintsExpandX
int type
const Char_t * GetLabel() const
Definition: KVBase.h:198
ID Grid Manager dialog for choice of ID telescope(s)
void FillTelescopeListWithType(const char *)
fill TGListBox with names of all ID telescopes of given type
Base class for all detectors or associations of detectors in array which can identify charged particl...
Definition: KVIDTelescope.h:83
Base class for describing the geometry of a detector array.
virtual void SetLayoutBroken(Bool_t on=kTRUE)
virtual void AddFrame(TGFrame *f, TGLayoutHints *l=0)
virtual void Resize(TGDimension size)
virtual void MoveResize(Int_t x, Int_t y, UInt_t w=0, UInt_t h=0)
Int_t EntryId() const
void SetTextJustify(Int_t tmode)
void SetMargins(Int_t left=0, Int_t right=0, Int_t top=0, Int_t bottom=0)
void SetWrapLength(Int_t wl)
virtual void SetTextJustify(Int_t tmode)
void SetWrapLength(Int_t wl)
void SetMargins(Int_t left=0, Int_t right=0, Int_t top=0, Int_t bottom=0)
virtual const char * GetName() const
const TString & GetString() const
virtual const char * GetTitle() const
Bool_t Connect(const char *signal, const char *receiver_class, void *receiver, const char *slot)
const char * Data() const
static void SingleShot(Int_t milliSec, const char *receiver_class, void *receiver, const char *method)
int main(int argc, char **argv)
TH1 * h