StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
FilterDialog.C
1 
2 
3 class TGCompositeFrame;
4 class TGFrame;
5 
6 TGFrame *GetFrame(const TGCompositeFrame *frame,Int_t id);
7 class FilterDialog {
8 
9 private:
10 
11 char **fNamVal;
12 float *fDefs;
13 float *fVals;
14 int fNVals;
15 int *fFlagg;
16 TList *fGarb;
17 TGMainFrame *fFrame;
18 
19 public:
20 FilterDialog(const char *wName=0,const char **NamVal=0,const float *defs=0, float *vals=0,int *flagg=0);
21 ~FilterDialog();
22 
23 void Update();
24 void Show ();
25 void Reset (); //Reset defaults
26 TGFrame *GetFrame(UInt_t id);
27 };
28 //_______________________________________________________________________________________
29 
30 const char* NamValQQ[]={
31  " RandomSelect = ",
32  " RxyMin = ",
33  " RxyMax = ",
34  " ZMin = ",
35  " ZMax = ",
36  " PhiMin = ",
37  " PhiMax = ",
38  " PtMin = ",
39  " PtMax = ",
40  " QMin = ",
41  " QMax = ",
42  0};
43 
44 const float DefsQQ[]={
45  /* RandomSelect=*/ 1.00,
46  /* RxyMin =*/ 0.00,
47  /* RxyMax =*/ 200.00,
48  /* ZMin =*/ -200.00,
49  /* ZMax =*/ +200.00,
50  /* PhiMin =*/ -180.00,
51  /* PhiMax =*/ +180.00,
52  /* PtMin =*/ 0.00,
53  /* PtMax =*/ 999.00,
54  /* QMin =*/ -1 ,
55  /* QMax =*/ +1 ,
56  0};
57 
58 //_______________________________________________________________________________________
59 FilterDialog::FilterDialog(const char *wName,const char **NamVal,const float *defs, float *vals,int *flagg)
60 {
61  printf("*** FilterDialog::FilterDialog STARTED ***\n");
62 
63  char cbuf[200];
64  if (!wName) wName = "DefaultFilterDialog";
65  fNamVal = NamVal;
66  if(!fNamVal) fNamVal = NamValQQ;
67  fDefs = defs;
68  if (!fDefs) fDefs = DefsQQ;
69  fVals = vals;
70  if (!fVals) fVals = DefsQQ;
71  fGarb = new TList;
72 
73  int nCol=2,nRow;
74  for (nRow=0;fNamVal[nRow];nRow++){};
75  fNVals = nRow;
76  fFlagg = flagg;
77 
78 
79  int PixInLetX=15;
80  int PixInLetY=30;
81  int LetInNam =12;
82  int LetInVal =10;
83  int nGridX = 2;
84  int nGridY = 2;
85  UInt_t uHintsNam = kLHintsCenterY | kLHintsExpandX;
86  UInt_t uHintsVal = kLHintsCenterY | kLHintsExpandX;
87 
88 // TGTransientFrame *fFrame = new TGTransientFrame(gClient->GetRoot(),0
89  fFrame = new TGMainFrame(gClient->GetRoot()
90  ,PixInLetX*(LetInNam+LetInVal)+10,PixInLetY*(nRow+2));
91 
92  fFrame->SetWindowName(wName);
93 
94  TGTableLayout *lay = new TGTableLayout(fFrame,(nRow+2)*nGridY,(LetInNam+1+LetInVal+1)*nGridX);
95  fFrame->SetLayoutManager(lay);
96 
97  TGTextView *tw;
98  TGTextEntry *te;
99  TGTableLayoutHints *hi = 0;
100  int jRowTop,jRowBot,jColLeft,jColRite;
101  for (int iRow=0;iRow<nRow;iRow++) {
102 
103  tw = new TGTextView(fFrame,PixInLetX*LetInNam,PixInLetY,fNamVal[iRow]);
104  tw->SetUniqueID(1000*(iRow+1)+1);
105  jRowTop = iRow*nGridY; jRowBot = (iRow+1)*nGridY-1;
106  jColLeft=0; jColRite = (LetInNam+1)*nGridX-1;
107  hi = new TGTableLayoutHints(jColLeft,jColRite,jRowTop,jRowBot,uHintsNam);
108  fFrame->AddFrame(tw,hi);
109 
110  sprintf(cbuf,"%+10g",fVals[iRow]);
111  te = new TGTextEntry(fFrame,cbuf);
112  te->SetUniqueID(1000*(iRow+1)+2);
113  te->SetWidth( PixInLetX*LetInVal);
114  te->SetHeight(PixInLetY);
115  jColLeft =jColRite +1;jColRite = jColLeft+(LetInVal+1)*nGridX-1;
116  hi = new TGTableLayoutHints(jColLeft,jColRite,jRowTop,jRowBot,uHintsVal);
117  fFrame->AddFrame(te,hi);
118  fGarb->Add(hi);
119  }
120 
121  TGTextButton *bat =0;
122  sprintf(cbuf,"((FilterDialog*)%p)->Update();",this);
123  bat = new TGTextButton(fFrame," OK ",cbuf);
124  jRowTop = nRow*nGridY; jRowBot = (nRow+1)*nGridY-1;
125  jColLeft=0; jColRite = (LetInNam+1)*nGridX-1;
126  hi = new TGTableLayoutHints(jColLeft,jColRite,jRowTop,jRowBot,uHintsNam);
127  fFrame->AddFrame(bat,hi);
128  fGarb->Add(hi);
129 
130 
131  sprintf(cbuf,"((FilterDialog*)%p)->Reset();",this);
132  bat = new TGTextButton(fFrame,"Default Values",cbuf);
133  jColLeft =jColRite +1;jColRite = jColLeft+(LetInVal+1)*nGridX-1;
134  hi = new TGTableLayoutHints(jColLeft,jColRite,jRowTop,jRowBot,uHintsVal);
135  fFrame->AddFrame(bat,hi);
136  fGarb->Add(hi);
137  Show();
138  printf("*** FilterDialog::FilterDialog FINISHED ***\n");
139 }
140 //_______________________________________________________________________________________
141 FilterDialog::~FilterDialog()
142 {
143  printf("*** FilterDialog::~FilterDialog STARTED ***\n");
144  TList *list = fFrame->GetList();
145  TListIter nextFrame(list);
146  TGFrameElement *fe=0;
147  while ((fe=(TGFrameElement*)nextFrame())) {delete fe->fFrame;}
148  list->Delete();
149 
150 
151 
152  printf("*** After Destroy ***\n");
153  delete fFrame;
154  fGarb->Delete();
155  delete fGarb;
156  printf("*** FilterDialog::~FilterDialog FINISHED ***\n");
157 }
158 
159 //_______________________________________________________________________________________
160 void FilterDialog::Reset()
161 {
162  char cbuf[100];
163  for (int irow=0; irow<fNVals; irow++) {
164  int id = (irow+1)*1000+2;
165  TGTextEntry *te = (TGTextEntry*)GetFrame(id);
166  assert(te);
167  sprintf(cbuf,"%+10g",fDefs[irow]);
168  te->SetText(cbuf);
169  }
170  Show();
171 }
172 //_______________________________________________________________________________________
173 void FilterDialog::Update()
174 {
175  printf("*** FilterDialog::Update STARTED ***\n");
176  const char *txt=0;
177  for (int irow=0; irow<fNVals; irow++) {
178  int id = (irow+1)*1000+2;
179  TGTextEntry *te = (TGTextEntry*)GetFrame(id);
180  assert(te);
181  txt = te->GetText();
182  float f = strtod(txt,0);
183 // printf("f = %f\n",f);
184  if (fVals) fVals[irow]=f;
185  }
186  Show();
187  assert(fFlagg);
188  fFlagg[0]=0;
189  printf("*** FilterDialog::Update FINISHED ***\n");
190 }
191 //_______________________________________________________________________________________
192 void FilterDialog::Show()
193 {
194  fFrame->Layout();
195  fFrame->MapSubwindows();
196  fFrame->MapWindow();
197 }
198 //_______________________________________________________________________________________
199 TGFrame *FilterDialog::GetFrame(UInt_t id)
200 {
201  return ::GetFrame(fFrame,id);
202 }
203 //_______________________________________________________________________________________
204 TGFrame *GetFrame(const TGCompositeFrame *frame,UInt_t id)
205 {
206  TList *tl = frame->GetList();
207  TListIter next(tl);
208  TGFrameElement *el;
209  while ((el = (TGFrameElement *)next())) {
210  TGFrame *fr = el->fFrame;
211  if (!fr) continue;
212 // printf("%d -- %d\n",id,fr->GetUniqueID());
213  if (fr->GetUniqueID()==id) break;
214  }
215  if (!el) return 0;
216  return el->fFrame;
217 }
218 
219