00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "TF1Editor.h"
00021 #include "TGedEditor.h"
00022 #include "TH1.h"
00023 #include "TF1.h"
00024 #include "TGTextEntry.h"
00025 #include "TGToolTip.h"
00026 #include "TGLabel.h"
00027 #include "TGDoubleSlider.h"
00028 #include "TString.h"
00029 #include "TGNumberEntry.h"
00030 #include "TG3DLine.h"
00031 #include "TFunctionParametersDialog.h"
00032 #include "TCanvas.h"
00033
00034
00035 ClassImp(TF1Editor)
00036
00037 enum ETF1Wid {
00038 kTF1_TIT, kTF1_NPX,
00039 kTF1_XSLD, kTF1_XMIN, kTF1_XMAX,
00040 kTF1_PAR, kTF1_DRW
00041 };
00042
00043 TF1Editor::TF1Editor(const TGWindow *p, Int_t width, Int_t height,
00044 UInt_t options, Pixel_t back)
00045 : TGedFrame(p, width, height, options | kVerticalFrame, back)
00046 {
00047
00048
00049 MakeTitle("Function");
00050
00051 fTitle = new TGTextEntry(this, new TGTextBuffer(50), kTF1_TIT);
00052 fTitle->Resize(137, fTitle->GetDefaultHeight());
00053 fTitle->SetEnabled(kFALSE);
00054 fTitle->SetToolTipText(Form("Function expression or predefined name"));
00055 AddFrame(fTitle, new TGLayoutHints(kLHintsLeft,3, 2, 2, 3));
00056
00057 TGCompositeFrame *f3a = new TGCompositeFrame(this, 137, 20, kHorizontalFrame);
00058 AddFrame(f3a, new TGLayoutHints(kLHintsTop, 0, 1, 3, 0));
00059 fDrawMode = new TGCheckButton(f3a, "Update", kTF1_DRW);
00060 fDrawMode->SetToolTipText("Immediate function redrawing");
00061 f3a->AddFrame(fDrawMode, new TGLayoutHints(kLHintsLeft | kLHintsBottom, 3, 1, 1, 0));
00062 fParLabel = new TGLabel(f3a, "");
00063 f3a->AddFrame(fParLabel, new TGLayoutHints(kLHintsRight | kLHintsBottom, 25, 2, 1, 0));
00064
00065 TGCompositeFrame *f3 = new TGCompositeFrame(this, 137, 20, kHorizontalFrame | kFixedWidth);
00066 fSetPars = new TGTextButton(f3, "Set Parameters...", kTF1_PAR);
00067 f3->AddFrame(fSetPars, new TGLayoutHints(kLHintsRight | kLHintsTop | kLHintsExpandX,
00068 0, 1, 5, 0));
00069 fSetPars->SetToolTipText("Open a dialog for parameter(s) settings");
00070 AddFrame(f3, new TGLayoutHints(kLHintsTop | kLHintsLeft, 3, 2, 2, 3));
00071
00072 MakeTitle("X-Range");
00073
00074 TGCompositeFrame *f4 = new TGCompositeFrame(this, 80, 20, kHorizontalFrame);
00075 TGCompositeFrame *f4a = new TGCompositeFrame(f4, 66, 20, kVerticalFrame | kFixedWidth);
00076 TGLabel *fNpxLabel = new TGLabel(f4a, "Points: ");
00077 f4a->AddFrame(fNpxLabel, new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 3, 0, 5, 1));
00078 f4->AddFrame(f4a, new TGLayoutHints(kLHintsTop | kLHintsLeft, 0, 1, 0, 0));
00079
00080 TGCompositeFrame *f4b = new TGCompositeFrame(f4, 40, 20, kVerticalFrame);
00081 fNXpoints = new TGNumberEntry(f4b, 100, 7, kTF1_NPX,
00082 TGNumberFormat::kNESInteger,
00083 TGNumberFormat::kNEANonNegative,
00084 TGNumberFormat::kNELLimitMinMax,4,100000);
00085 fNXpoints->GetNumberEntry()->SetToolTipText("Points along x-axis (4-100 000)");
00086 f4b->AddFrame(fNXpoints, new TGLayoutHints(kLHintsLeft, 0, 0, 1, 0));
00087 f4->AddFrame(f4b, new TGLayoutHints(kLHintsTop | kLHintsRight, 0, 1, 0, 0));
00088 AddFrame(f4, new TGLayoutHints(kLHintsTop | kLHintsLeft, 0, 1, 0, 0));
00089
00090 TGCompositeFrame *f5 = new TGCompositeFrame(this, 80, 20, kHorizontalFrame);
00091 fSliderX = new TGDoubleHSlider(f5, 1, 2);
00092 fSliderX->Resize(137,20);
00093 f5->AddFrame(fSliderX, new TGLayoutHints(kLHintsLeft));
00094 AddFrame(f5, new TGLayoutHints(kLHintsTop, 3, 7, 4, 1));
00095
00096 TGCompositeFrame *f6 = new TGCompositeFrame(this, 80, 20, kHorizontalFrame);
00097 fSldMinX = new TGNumberEntryField(f6, kTF1_XMIN, 0.0,
00098 TGNumberFormat::kNESRealFour,
00099 TGNumberFormat::kNEAAnyNumber);
00100 ((TGTextEntry*)fSldMinX)->SetToolTipText("Lower bound along x-axis");
00101 fSldMinX->Resize(65,20);
00102 fSldMinX->SetState(kFALSE);
00103 f6->AddFrame(fSldMinX, new TGLayoutHints(kLHintsLeft));
00104 fSldMaxX = new TGNumberEntryField(f6, kTF1_XMAX, 0.0,
00105 TGNumberFormat::kNESRealFour,
00106 TGNumberFormat::kNEAAnyNumber);
00107 ((TGTextEntry*)fSldMaxX)->SetToolTipText("Upper bound along x-axis");
00108 fSldMaxX->SetState(kFALSE);
00109 fSldMaxX->Resize(65,20);
00110 f6->AddFrame(fSldMaxX, new TGLayoutHints(kLHintsLeft, 4, 0, 0, 0));
00111 AddFrame(f6, new TGLayoutHints(kLHintsTop, 3, 3, 5, 0));
00112 }
00113
00114
00115 TF1Editor::~TF1Editor()
00116 {
00117
00118 }
00119
00120
00121 void TF1Editor::ConnectSignals2Slots()
00122 {
00123
00124
00125 fNXpoints->Connect("ValueSet(Long_t)", "TF1Editor", this, "DoXPoints()");
00126 (fNXpoints->GetNumberEntry())->Connect("ReturnPressed()", "TF1Editor",
00127 this, "DoXPoints()");
00128 fSetPars->Connect("Clicked()", "TF1Editor", this, "DoParameterSettings()");
00129 fSliderX->Connect("Pressed()","TF1Editor", this,"DoSliderXPressed()");
00130 fSliderX->Connect("Released()","TF1Editor", this,"DoSliderXReleased()");
00131 fSliderX->Connect("PositionChanged()","TF1Editor", this,"DoSliderXMoved()");
00132
00133 fInit = kFALSE;
00134 }
00135
00136
00137 void TF1Editor::SetModel(TObject* obj)
00138 {
00139
00140 if (obj == 0 || !obj->InheritsFrom(TF1::Class())) {
00141 return;
00142 }
00143
00144 fF1 = (TF1*)obj;
00145 fAvoidSignal = kTRUE;
00146
00147 const char *text = fF1->GetTitle();
00148 fTitle->SetText(text);
00149
00150 fNP = fF1->GetNpar();
00151 fParLabel->SetText(Form("Npar: %d", fNP));
00152 fClient->NeedRedraw(fParLabel);
00153
00154 fNXpoints->SetNumber(fF1->GetNpx());
00155
00156 if (!fNP)
00157 fSetPars->SetState(kButtonDisabled, kFALSE);
00158 else
00159 fSetPars->SetState(kButtonUp, kFALSE);
00160
00161 TAxis *x = fF1->GetHistogram()->GetXaxis();
00162 Int_t nx = x->GetNbins();
00163 Int_t nxbinmin = x->GetFirst();
00164 Int_t nxbinmax = x->GetLast();
00165 fSliderX->SetRange(1,nx);
00166 fSliderX->SetPosition((Double_t)nxbinmin,(Double_t)nxbinmax);
00167 fSldMinX->SetNumber(x->GetBinLowEdge(nxbinmin));
00168 fSldMaxX->SetNumber(x->GetBinUpEdge(nxbinmax));
00169
00170 if (fInit) ConnectSignals2Slots();
00171 fAvoidSignal = kFALSE;
00172 }
00173
00174
00175 void TF1Editor::DoParameterSettings()
00176 {
00177
00178
00179 TGMainFrame *main = (TGMainFrame *)GetMainFrame();
00180 Double_t rmin = fSldMinX->GetNumber();
00181 Double_t rmax = fSldMaxX->GetNumber();
00182 new TFunctionParametersDialog(gClient->GetDefaultRoot(), main,
00183 fF1, fGedEditor->GetPad(), rmin, rmax);
00184
00185 }
00186
00187
00188 void TF1Editor::DoXPoints()
00189 {
00190
00191
00192 if (fAvoidSignal) return;
00193 Double_t rmin, rmax;
00194 fF1->GetRange(rmin, rmax);
00195 fF1->SetRange(fSldMinX->GetNumber(), fSldMaxX->GetNumber());
00196 fF1->SetNpx((Int_t)fNXpoints->GetNumber());
00197 fF1->GetHistogram()->GetXaxis()->Set((Int_t)fNXpoints->GetNumber(),
00198 fSldMinX->GetNumber(),
00199 fSldMaxX->GetNumber());
00200 Update();
00201 fF1->SetRange(rmin, rmax);
00202 }
00203
00204
00205 void TF1Editor::DoSliderXMoved()
00206 {
00207
00208
00209 if (fAvoidSignal) return;
00210
00211 TVirtualPad *save = 0;
00212 save = gPad;
00213 gPad = fGedEditor->GetPad();
00214 fGedEditor->GetPad()->cd();
00215
00216 fF1->SetNpx((Int_t)fNXpoints->GetNumber());
00217 TAxis *x = fF1->GetHistogram()->GetXaxis();
00218
00219 if (fDrawMode->GetState() == kButtonDown) {
00220 TString opt = fF1->GetDrawOption();
00221 opt.ToUpper();
00222 if (!opt.Contains("SAME"))
00223 opt += "SAME";
00224 fF1->Draw(opt);
00225
00226 x->SetRange((Int_t)((fSliderX->GetMinPosition())+0.5),
00227 (Int_t)((fSliderX->GetMaxPosition())+0.5));
00228 fSldMinX->SetNumber(x->GetBinLowEdge(x->GetFirst()));
00229 fSldMaxX->SetNumber(x->GetBinUpEdge(x->GetLast()));
00230 fClient->NeedRedraw(fSliderX,kTRUE);
00231 fClient->NeedRedraw(fSldMinX,kTRUE);
00232 fClient->NeedRedraw(fSldMaxX,kTRUE);
00233 Update();
00234
00235 } else {
00236 x->SetRange((Int_t)((fSliderX->GetMinPosition())+0.5),
00237 (Int_t)((fSliderX->GetMaxPosition())+0.5));
00238 fSldMinX->SetNumber(x->GetBinLowEdge(x->GetFirst()));
00239 fSldMaxX->SetNumber(x->GetBinUpEdge(x->GetLast()));
00240 fClient->NeedRedraw(fSliderX,kTRUE);
00241 fClient->NeedRedraw(fSldMinX,kTRUE);
00242 fClient->NeedRedraw(fSldMaxX,kTRUE);
00243 }
00244 if(save) gPad = save;
00245 }
00246
00247
00248 void TF1Editor::DoSliderXPressed()
00249 {
00250
00251
00252 if (fAvoidSignal || (fDrawMode->GetState() == kButtonDown)) return;
00253
00254 TVirtualPad *save = 0;
00255 save = gPad;
00256 gPad = fGedEditor->GetPad();
00257 fGedEditor->GetPad()->cd();
00258
00259 fF1->SetNpx((Int_t)fNXpoints->GetNumber());
00260 TAxis *x = fF1->GetHistogram()->GetXaxis();
00261 TString opt = fF1->GetDrawOption();
00262 opt.ToUpper();
00263 if (!opt.Contains("SAME"))
00264 opt += "SAME";
00265 fF1->Draw(opt);
00266
00267 x->SetRange((Int_t)((fSliderX->GetMinPosition())+0.5),
00268 (Int_t)((fSliderX->GetMaxPosition())+0.5));
00269 fSldMinX->SetNumber(x->GetBinLowEdge(x->GetFirst()));
00270 fSldMaxX->SetNumber(x->GetBinUpEdge(x->GetLast()));
00271 fClient->NeedRedraw(fSliderX,kTRUE);
00272 fClient->NeedRedraw(fSldMinX,kTRUE);
00273 fClient->NeedRedraw(fSldMaxX,kTRUE);
00274 Update();
00275
00276 if(save) gPad = save;
00277
00278 }
00279
00280
00281 void TF1Editor::DoSliderXReleased()
00282 {
00283
00284
00285 if (fAvoidSignal || (fDrawMode->GetState() == kButtonDown)) return;
00286
00287 TVirtualPad *save = 0;
00288 save = gPad;
00289 gPad = fGedEditor->GetPad();
00290 fGedEditor->GetPad()->cd();
00291
00292 fF1->SetNpx((Int_t)fNXpoints->GetNumber());
00293 TAxis *x = fF1->GetHistogram()->GetXaxis();
00294 TString opt = fF1->GetDrawOption();
00295 opt.ToUpper();
00296 if (!opt.Contains("SAME"))
00297 opt += "SAME";
00298 fF1->Draw(opt);
00299
00300 x->SetRange((Int_t)((fSliderX->GetMinPosition())+0.5),
00301 (Int_t)((fSliderX->GetMaxPosition())+0.5));
00302 fSldMinX->SetNumber(x->GetBinLowEdge(x->GetFirst()));
00303 fSldMaxX->SetNumber(x->GetBinUpEdge(x->GetLast()));
00304 fClient->NeedRedraw(fSliderX,kTRUE);
00305 fClient->NeedRedraw(fSldMinX,kTRUE);
00306 fClient->NeedRedraw(fSldMaxX,kTRUE);
00307 Update();
00308
00309 if(save) gPad = save;
00310 }
00311
00312
00313
00314 void TF1Editor::DoXRange()
00315 {
00316
00317
00318 if (fAvoidSignal) return;
00319 TAxis *x = fF1->GetHistogram()->GetXaxis();
00320 Int_t nx = x->GetNbins();
00321 Double_t width = x->GetBinWidth(1);
00322 Double_t lowLimit = x->GetBinLowEdge(1);
00323 Double_t upLimit = x->GetBinUpEdge(nx);
00324 if ((fSldMinX->GetNumber()+width/2) < (lowLimit))
00325 fSldMinX->SetNumber(lowLimit);
00326 if ((fSldMaxX->GetNumber()-width/2) > (upLimit))
00327 fSldMaxX->SetNumber(upLimit);
00328 x->SetRangeUser(fSldMinX->GetNumber()+width/2,
00329 fSldMaxX->GetNumber()-width/2);
00330 Int_t nxbinmin = x->GetFirst();
00331 Int_t nxbinmax = x->GetLast();
00332 fSliderX->SetPosition((Double_t)(nxbinmin),(Double_t)(nxbinmax));
00333 Update();
00334 }
00335
00336
00337 void TF1Editor::ActivateBaseClassEditors(TClass* cl)
00338 {
00339
00340
00341 fGedEditor->ExcludeClassEditor(TAttFill::Class());
00342 TGedFrame::ActivateBaseClassEditors(cl);
00343 }
00344