00001
00002
00003 class TGCompositeFrame;
00004 class TGFrame;
00005
00006 TGFrame *GetFrame(const TGCompositeFrame *frame,Int_t id);
00007 class FilterDialog {
00008
00009 private:
00010
00011 char **fNamVal;
00012 float *fDefs;
00013 float *fVals;
00014 int fNVals;
00015 int *fFlagg;
00016 TList *fGarb;
00017 TGMainFrame *fFrame;
00018
00019 public:
00020 FilterDialog(const char *wName=0,const char **NamVal=0,const float *defs=0, float *vals=0,int *flagg=0);
00021 ~FilterDialog();
00022
00023 void Update();
00024 void Show ();
00025 void Reset ();
00026 TGFrame *GetFrame(UInt_t id);
00027 };
00028
00029
00030 const char* NamValQQ[]={
00031 " RandomSelect = ",
00032 " RxyMin = ",
00033 " RxyMax = ",
00034 " ZMin = ",
00035 " ZMax = ",
00036 " PhiMin = ",
00037 " PhiMax = ",
00038 " PtMin = ",
00039 " PtMax = ",
00040 " QMin = ",
00041 " QMax = ",
00042 0};
00043
00044 const float DefsQQ[]={
00045 1.00,
00046 0.00,
00047 200.00,
00048 -200.00,
00049 +200.00,
00050 -180.00,
00051 +180.00,
00052 0.00,
00053 999.00,
00054 -1 ,
00055 +1 ,
00056 0};
00057
00058
00059 FilterDialog::FilterDialog(const char *wName,const char **NamVal,const float *defs, float *vals,int *flagg)
00060 {
00061 printf("*** FilterDialog::FilterDialog STARTED ***\n");
00062
00063 char cbuf[200];
00064 if (!wName) wName = "DefaultFilterDialog";
00065 fNamVal = NamVal;
00066 if(!fNamVal) fNamVal = NamValQQ;
00067 fDefs = defs;
00068 if (!fDefs) fDefs = DefsQQ;
00069 fVals = vals;
00070 if (!fVals) fVals = DefsQQ;
00071 fGarb = new TList;
00072
00073 int nCol=2,nRow;
00074 for (nRow=0;fNamVal[nRow];nRow++){};
00075 fNVals = nRow;
00076 fFlagg = flagg;
00077
00078
00079 int PixInLetX=15;
00080 int PixInLetY=30;
00081 int LetInNam =12;
00082 int LetInVal =10;
00083 int nGridX = 2;
00084 int nGridY = 2;
00085 UInt_t uHintsNam = kLHintsCenterY | kLHintsExpandX;
00086 UInt_t uHintsVal = kLHintsCenterY | kLHintsExpandX;
00087
00088
00089 fFrame = new TGMainFrame(gClient->GetRoot()
00090 ,PixInLetX*(LetInNam+LetInVal)+10,PixInLetY*(nRow+2));
00091
00092 fFrame->SetWindowName(wName);
00093
00094 TGTableLayout *lay = new TGTableLayout(fFrame,(nRow+2)*nGridY,(LetInNam+1+LetInVal+1)*nGridX);
00095 fFrame->SetLayoutManager(lay);
00096
00097 TGTextView *tw;
00098 TGTextEntry *te;
00099 TGTableLayoutHints *hi = 0;
00100 int jRowTop,jRowBot,jColLeft,jColRite;
00101 for (int iRow=0;iRow<nRow;iRow++) {
00102
00103 tw = new TGTextView(fFrame,PixInLetX*LetInNam,PixInLetY,fNamVal[iRow]);
00104 tw->SetUniqueID(1000*(iRow+1)+1);
00105 jRowTop = iRow*nGridY; jRowBot = (iRow+1)*nGridY-1;
00106 jColLeft=0; jColRite = (LetInNam+1)*nGridX-1;
00107 hi = new TGTableLayoutHints(jColLeft,jColRite,jRowTop,jRowBot,uHintsNam);
00108 fFrame->AddFrame(tw,hi);
00109
00110 sprintf(cbuf,"%+10g",fVals[iRow]);
00111 te = new TGTextEntry(fFrame,cbuf);
00112 te->SetUniqueID(1000*(iRow+1)+2);
00113 te->SetWidth( PixInLetX*LetInVal);
00114 te->SetHeight(PixInLetY);
00115 jColLeft =jColRite +1;jColRite = jColLeft+(LetInVal+1)*nGridX-1;
00116 hi = new TGTableLayoutHints(jColLeft,jColRite,jRowTop,jRowBot,uHintsVal);
00117 fFrame->AddFrame(te,hi);
00118 fGarb->Add(hi);
00119 }
00120
00121 TGTextButton *bat =0;
00122 sprintf(cbuf,"((FilterDialog*)%p)->Update();",this);
00123 bat = new TGTextButton(fFrame," OK ",cbuf);
00124 jRowTop = nRow*nGridY; jRowBot = (nRow+1)*nGridY-1;
00125 jColLeft=0; jColRite = (LetInNam+1)*nGridX-1;
00126 hi = new TGTableLayoutHints(jColLeft,jColRite,jRowTop,jRowBot,uHintsNam);
00127 fFrame->AddFrame(bat,hi);
00128 fGarb->Add(hi);
00129
00130
00131 sprintf(cbuf,"((FilterDialog*)%p)->Reset();",this);
00132 bat = new TGTextButton(fFrame,"Default Values",cbuf);
00133 jColLeft =jColRite +1;jColRite = jColLeft+(LetInVal+1)*nGridX-1;
00134 hi = new TGTableLayoutHints(jColLeft,jColRite,jRowTop,jRowBot,uHintsVal);
00135 fFrame->AddFrame(bat,hi);
00136 fGarb->Add(hi);
00137 Show();
00138 printf("*** FilterDialog::FilterDialog FINISHED ***\n");
00139 }
00140
00141 FilterDialog::~FilterDialog()
00142 {
00143 printf("*** FilterDialog::~FilterDialog STARTED ***\n");
00144 TList *list = fFrame->GetList();
00145 TListIter nextFrame(list);
00146 TGFrameElement *fe=0;
00147 while ((fe=(TGFrameElement*)nextFrame())) {delete fe->fFrame;}
00148 list->Delete();
00149
00150
00151
00152 printf("*** After Destroy ***\n");
00153 delete fFrame;
00154 fGarb->Delete();
00155 delete fGarb;
00156 printf("*** FilterDialog::~FilterDialog FINISHED ***\n");
00157 }
00158
00159
00160 void FilterDialog::Reset()
00161 {
00162 char cbuf[100];
00163 for (int irow=0; irow<fNVals; irow++) {
00164 int id = (irow+1)*1000+2;
00165 TGTextEntry *te = (TGTextEntry*)GetFrame(id);
00166 assert(te);
00167 sprintf(cbuf,"%+10g",fDefs[irow]);
00168 te->SetText(cbuf);
00169 }
00170 Show();
00171 }
00172
00173 void FilterDialog::Update()
00174 {
00175 printf("*** FilterDialog::Update STARTED ***\n");
00176 const char *txt=0;
00177 for (int irow=0; irow<fNVals; irow++) {
00178 int id = (irow+1)*1000+2;
00179 TGTextEntry *te = (TGTextEntry*)GetFrame(id);
00180 assert(te);
00181 txt = te->GetText();
00182 float f = strtod(txt,0);
00183
00184 if (fVals) fVals[irow]=f;
00185 }
00186 Show();
00187 assert(fFlagg);
00188 fFlagg[0]=0;
00189 printf("*** FilterDialog::Update FINISHED ***\n");
00190 }
00191
00192 void FilterDialog::Show()
00193 {
00194 fFrame->Layout();
00195 fFrame->MapSubwindows();
00196 fFrame->MapWindow();
00197 }
00198
00199 TGFrame *FilterDialog::GetFrame(UInt_t id)
00200 {
00201 return ::GetFrame(fFrame,id);
00202 }
00203
00204 TGFrame *GetFrame(const TGCompositeFrame *frame,UInt_t id)
00205 {
00206 TList *tl = frame->GetList();
00207 TListIter next(tl);
00208 TGFrameElement *el;
00209 while ((el = (TGFrameElement *)next())) {
00210 TGFrame *fr = el->fFrame;
00211 if (!fr) continue;
00212
00213 if (fr->GetUniqueID()==id) break;
00214 }
00215 if (!el) return 0;
00216 return el->fFrame;
00217 }
00218
00219