TFunctionParametersDialog.cxx

Go to the documentation of this file.
00001 // @(#)root/ged:$Id: TFunctionParametersDialog.cxx 20882 2007-11-19 11:31:26Z rdm $
00002 // Author: Ilka Antcheva   08/05/06
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2006, Rene Brun and Fons Rademakers.               *
00006  * All rights reserved.                                                  *
00007  *                                                                       *
00008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00010  *************************************************************************/
00011 
00012 //////////////////////////////////////////////////////////////////////////
00013 //                                                                      //
00014 //  TFunctionParametersDialog                                           //
00015 //                                                                      //
00016 //  This class is used for function parameter settings.                 //
00017 //                                                                      //
00018 //////////////////////////////////////////////////////////////////////////
00019 
00020 #include "TFunctionParametersDialog.h"
00021 #include "TTimer.h"
00022 #include "TList.h"
00023 #include "TF1.h"
00024 #include "TGButton.h"
00025 #include "TGFrame.h"
00026 #include "TGLabel.h"
00027 #include "TGLayout.h"
00028 #include "TGTextEntry.h"
00029 #include "TGMsgBox.h"
00030 #include "TGNumberEntry.h"
00031 #include "TGTripleSlider.h"
00032 #include "TVirtualPad.h"
00033 
00034 
00035 enum EParametersDialogWid {
00036    kNAME,
00037    kFIX = 10,
00038    kVAL = 20,
00039    kMIN = 30,
00040    kMAX = 40,
00041    kSLD = 50,
00042    kUPDATE = 8888,
00043    kRESET,
00044    kAPPLY,
00045    kOK,
00046    kCANCEL
00047 };
00048 
00049 ClassImp(TFunctionParametersDialog)
00050 
00051 //______________________________________________________________________________
00052 TFunctionParametersDialog::TFunctionParametersDialog(const TGWindow *p,
00053                                                      const TGWindow *main,
00054                                                      TF1 *func,
00055                                                      TVirtualPad *pad,
00056                                                      Double_t rx, Double_t ry) :
00057    TGTransientFrame(p, main, 10, 10, kVerticalFrame)
00058 {
00059    // Create the parameters' dialog of currently selected function 'func'.
00060 
00061    fFunc = func;
00062    fFpad = pad;
00063    fRXmin = rx;
00064    fRXmax = ry;
00065    fFunc->GetRange(fRangexmin, fRangexmax);
00066    fNP = fFunc->GetNpar();
00067    fHasChanges = kFALSE;
00068    fPmin = new Double_t[fNP];
00069    fPmax = new Double_t[fNP];
00070    fPval = new Double_t[fNP];
00071    fPerr = new Double_t[fNP];
00072 
00073    for (Int_t i = 0; i < fNP; i++) {
00074       fFunc->GetParLimits(i, fPmin[i], fPmax[i]);
00075       fPval[i] = fFunc->GetParameter(i);
00076       fPerr[i] = fFunc->GetParError(i);
00077    }
00078    fParNam = new TGTextEntry*[fNP];
00079    fParFix = new TGCheckButton*[fNP];
00080    fParVal = new TGNumberEntry*[fNP];
00081    fParMin = new TGNumberEntryField*[fNP];
00082    fParMax = new TGNumberEntryField*[fNP];
00083    fParSld = new TGTripleHSlider*[fNP];
00084 
00085    memset(fParNam, 0, sizeof(TGTextEntry*)*fNP);
00086    memset(fParFix, 0, sizeof(TGCheckButton*)*fNP);
00087    memset(fParVal, 0, sizeof(TGNumberEntry*)*fNP);
00088    memset(fParMin, 0, sizeof(TGNumberEntryField*)*fNP);
00089    memset(fParMax, 0, sizeof(TGNumberEntryField*)*fNP);
00090    memset(fParMax, 0, sizeof(TGTripleHSlider*)*fNP);
00091 
00092    TGCompositeFrame *f1 = new TGCompositeFrame(this, 80, 20, kHorizontalFrame);
00093    AddFrame(f1, new TGLayoutHints(kLHintsTop, 1, 1, 1, 1));
00094 
00095    // column 'Name'
00096    fContNam = new TGCompositeFrame(f1, 80, 20, kVerticalFrame | kFixedWidth);
00097    fContNam->AddFrame(new TGLabel(fContNam,"Name"),
00098                       new TGLayoutHints(kLHintsTop, 5, 0, 0, 0));
00099    for (Int_t i = 0; i < fNP; i++ ) {
00100       fParNam[i] = new TGTextEntry(fContNam, new TGTextBuffer(80), kNAME+i);
00101       fParNam[i]->SetText(Form("%s", fFunc->GetParName(i)));
00102       fParNam[i]->SetEnabled(kFALSE);
00103       fContNam->AddFrame(fParNam[i],
00104                          new TGLayoutHints(kLHintsExpandX, 5, 5, 7, 5));
00105    }
00106    f1->AddFrame(fContNam, new TGLayoutHints(kLHintsExpandX, 5, 5, 5, 5));
00107 
00108    // column 'Fix'
00109    fContFix = new TGCompositeFrame(f1, 20, 20, kVerticalFrame | kFixedWidth);
00110    fContFix->AddFrame(new TGLabel(fContFix,"Fix"),
00111                       new TGLayoutHints(kLHintsTop, 2, 0, 0, 0));
00112    for (Int_t i = 0; i < fNP; i++ ) {
00113       fParFix[i] = new TGCheckButton(fContFix, "", kFIX*fNP+i);
00114       fParFix[i]->SetToolTipText(Form("Set %s to fixed", fFunc->GetParName(i)));
00115       fContFix->AddFrame(fParFix[i], new TGLayoutHints(kLHintsLeft | kLHintsCenterY,
00116                                                        5, 5, 10, 7));
00117       if ((fPmin[i] == fPmax[i]) && (fPmin[i] || fPmax[i]))
00118          fParFix[i]->SetState(kButtonDown);
00119       else
00120          fParFix[i]->SetState(kButtonUp);
00121       fParFix[i]->Connect("Toggled(Bool_t)", "TFunctionParametersDialog", this, "DoFix(Bool_t)");
00122    }
00123    f1->AddFrame(fContFix, new TGLayoutHints(kLHintsLeft, 5, 5, 5, 5));
00124 
00125    // column 'Value'
00126    fContVal = new TGCompositeFrame(f1, 80, 20, kVerticalFrame | kFixedWidth);
00127    fContVal->AddFrame(new TGLabel(fContVal,"Value"),
00128                       new TGLayoutHints(kLHintsTop, 5, 0, 0, 0));
00129    for (Int_t i = 0; i < fNP; i++ ) {
00130       fParVal[i] = new TGNumberEntry(fContVal, 1.2E-12, 15, kVAL*fNP+i,
00131                                      TGNumberFormat::kNESReal);
00132       fParVal[i]->SetNumber(fPval[i]);
00133       fParVal[i]->SetFormat(TGNumberFormat::kNESReal, TGNumberFormat::kNEAAnyNumber); //tbs
00134       fContVal->AddFrame(fParVal[i], new TGLayoutHints(kLHintsExpandX, 5, 5, 7, 5));
00135       (fParVal[i]->GetNumberEntry())->SetToolTipText(Form("%s", fFunc->GetParName(i)));
00136       (fParVal[i]->GetNumberEntry())->Connect("ReturnPressed()", "TFunctionParametersDialog",
00137                                               this, "DoParValue()");
00138       fParVal[i]->Connect("ValueSet(Long_t)", "TFunctionParametersDialog", this, "DoParValue()");
00139    }
00140    f1->AddFrame(fContVal, new TGLayoutHints(kLHintsExpandX, 5, 5, 5, 5));
00141 
00142    // column 'Min'
00143    fContMin = new TGCompositeFrame(f1, 80, 20, kVerticalFrame | kFixedWidth);
00144    fContMin->AddFrame(new TGLabel(fContMin,"Min"),
00145                       new TGLayoutHints(kLHintsTop, 5, 0, 0, 0));
00146    for (Int_t i = 0; i < fNP; i++ ) {
00147       fParMin[i] = new TGNumberEntryField(fContMin, kMIN*fNP+i, 0.0,
00148                                           TGNumberFormat::kNESReal,
00149                                           TGNumberFormat::kNEAAnyNumber);
00150       ((TGTextEntry*)fParMin[i])->SetToolTipText(Form("Lower limit of %s",
00151                                                  fFunc->GetParName(i)));
00152       fContMin->AddFrame(fParMin[i], new TGLayoutHints(kLHintsExpandX, 5, 5, 7, 5));
00153       if (fPmin[i])
00154          fParMin[i]->SetNumber(fPmin[i]);
00155       else if (fPerr[i])
00156          fParMin[i]->SetNumber(fPval[i]-3*fPerr[i]);
00157       else if (fPval[i])
00158          fParMin[i]->SetNumber(fPval[i]-0.1*fPval[i]);
00159       else
00160          fParMin[i]->SetNumber(1.0);
00161       fParMin[i]->Connect("ReturnPressed()", "TFunctionParametersDialog", this, "DoParMinLimit()");
00162    }
00163    f1->AddFrame(fContMin, new TGLayoutHints(kLHintsExpandX, 5, 5, 5, 5));
00164 
00165    // column 'Set Range'
00166    fContSld = new TGCompositeFrame(f1, 120, 20, kVerticalFrame | kFixedWidth);
00167    fContSld->AddFrame(new TGLabel(fContSld,"Set Range"),
00168                       new TGLayoutHints(kLHintsTop, 5, 0, 0, 0));
00169    for (Int_t i = 0; i < fNP; i++ ) {
00170       fParSld[i] = new TGTripleHSlider(fContSld, 100, kDoubleScaleBoth, kSLD*fNP+i,
00171                                        kHorizontalFrame, GetDefaultFrameBackground(),
00172                                        kFALSE, kFALSE, kFALSE, kFALSE);
00173       fContSld->AddFrame(fParSld[i], new TGLayoutHints(kLHintsExpandX, 5, 5, 5, 5));
00174       fParSld[i]->SetConstrained(kTRUE);
00175    }
00176    f1->AddFrame(fContSld,  new TGLayoutHints(kLHintsExpandX, 5, 5, 5, 5));
00177 
00178    // column 'Max'
00179    fContMax = new TGCompositeFrame(f1, 80, 20, kVerticalFrame);
00180    fContMax->AddFrame(new TGLabel(fContMax,"Max"),
00181                       new TGLayoutHints(kLHintsTop, 5, 0, 0, 0));
00182    for (Int_t i = 0; i < fNP; i++ ) {
00183       fParMax[i] = new TGNumberEntryField(fContMax, kMAX*fNP+i, 0.0,
00184                                           TGNumberFormat::kNESReal,
00185                                           TGNumberFormat::kNEAAnyNumber);
00186       ((TGTextEntry*)fParMax[i])->SetToolTipText(Form("Upper limit of %s",
00187                                                  fFunc->GetParName(i)));
00188       fContMax->AddFrame(fParMax[i], new TGLayoutHints(kLHintsExpandX, 5, 5, 7, 5));
00189       if (fPmax[i])
00190          fParMax[i]->SetNumber(fPmax[i]);
00191       else if (fPerr[i])
00192          fParMax[i]->SetNumber(fPval[i]+3*fPerr[i]);
00193       else if (fPval[i])
00194          fParMax[i]->SetNumber(fPval[i]+0.1*fPval[i]);
00195       else
00196          fParMax[i]->SetNumber(1.0);
00197       if (fParMax[i]->GetNumber() < fParMin[i]->GetNumber()){
00198          Double_t temp;
00199          temp = fParMax[i]->GetNumber();
00200          fParMax[i]->SetNumber(fParMin[i]->GetNumber());
00201          fParMin[i]->SetNumber(temp);
00202       }
00203       fParMax[i]->Connect("ReturnPressed()", "TFunctionParametersDialog", this, "DoParMaxLimit()");
00204    }
00205    f1->AddFrame(fContMax, new TGLayoutHints(kLHintsExpandX, 5, 5, 5, 5));
00206 
00207 
00208    fUpdate = new TGCheckButton(this, "&Immediate preview", kUPDATE);
00209    fUpdate->SetToolTipText("Immediate function redrawing");
00210    AddFrame(fUpdate, new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 5, 5, 5, 5));
00211    fUpdate->Connect("Toggled(Bool_t)", "TFunctionParametersDialog", this, "HandleButtons(Bool_t)");
00212 
00213    TGCompositeFrame *f2 = new TGCompositeFrame(this, 270, 20, kHorizontalFrame | kFixedWidth);
00214    AddFrame(f2, new TGLayoutHints(kLHintsRight, 20, 20, 5, 1));
00215 
00216    fReset = new TGTextButton(f2, "&Reset", kRESET);
00217    f2->AddFrame(fReset, new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX,5,5,5,5));
00218    fReset->SetToolTipText("Reset the parameter settings");
00219    fReset->SetState(kButtonDisabled);
00220    fReset->Connect("Clicked()", "TFunctionParametersDialog", this, "DoReset()");
00221 
00222    fApply = new TGTextButton(f2, "&Apply", kAPPLY);
00223    f2->AddFrame(fApply, new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX,5,5,5,5));
00224    fApply->SetState(kButtonDisabled);
00225    fApply->Connect("Clicked()", "TFunctionParametersDialog", this, "DoApply()");
00226    fApply->SetToolTipText("Apply parameter settings and redraw the function");
00227 
00228    fOK = new TGTextButton(f2, "&OK", kOK);
00229    f2->AddFrame(fOK, new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX,5,5,5,5));
00230    fOK->SetToolTipText("Apply parameter settings, redraw function and close this dialog");
00231    fOK->Connect("Clicked()", "TFunctionParametersDialog", this, "DoOK()");
00232 
00233    fCancel = new TGTextButton(f2, "&Cancel", kCANCEL);
00234    f2->AddFrame(fCancel, new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX,5,5,5,5));
00235    fCancel->SetToolTipText("Close this dialog with no parameter changes");
00236    fCancel->Connect("Clicked()", "TFunctionParametersDialog", this, "DoCancel()");
00237 
00238    MapSubwindows();
00239    Resize(GetDefaultSize());
00240    CenterOnParent(kFALSE, kBottomLeft);
00241    SetWindowName(Form("Set Parameters of %s", fFunc->GetTitle()));
00242    MapWindow();
00243 
00244    for (Int_t i = 0; i < fNP; i++ ) {
00245       if (fParFix[i]->GetState() == kButtonDown) {
00246          fParVal[i]->SetState(kFALSE);
00247          fParMin[i]->SetEnabled(kFALSE);
00248          fParMax[i]->SetEnabled(kFALSE);
00249          fParSld[i]->UnmapWindow();
00250       } else {
00251          fParSld[i]->SetRange(fParMin[i]->GetNumber(), fParMax[i]->GetNumber());
00252          fParSld[i]->SetPosition(fParMin[i]->GetNumber(), fParMax[i]->GetNumber());
00253          fParSld[i]->SetPointerPosition(fPval[i]);
00254          fParSld[i]->Connect("PointerPositionChanged()", "TFunctionParametersDialog",
00255                              this, "DoSlider()");
00256          fParSld[i]->Connect("PositionChanged()", "TFunctionParametersDialog",
00257                              this, "DoSlider()");
00258       }
00259    }
00260 
00261    gClient->WaitFor(this);
00262 }
00263 
00264 //______________________________________________________________________________
00265 TFunctionParametersDialog::~TFunctionParametersDialog()
00266 {
00267    // Destructor.
00268 
00269    TGFrameElement *el;
00270    TIter next(GetList());
00271 
00272    while ((el = (TGFrameElement *)next())) {
00273       if (!strcmp(el->fFrame->ClassName(), "TGCompositeFrame")) {
00274          TGFrameElement *el1;
00275          TIter next1(((TGCompositeFrame *)el->fFrame)->GetList());
00276          while ((el1 = (TGFrameElement *)next1())) {
00277             if (!strcmp(el1->fFrame->ClassName(), "TGCompositeFrame"))
00278                ((TGCompositeFrame *)el1->fFrame)->Cleanup();
00279          }
00280          ((TGCompositeFrame *)el->fFrame)->Cleanup();
00281       }
00282    }
00283    Cleanup();
00284    delete [] fPval;
00285    delete [] fPmin;
00286    delete [] fPmax;
00287    delete [] fPerr;
00288 }
00289 
00290 //______________________________________________________________________________
00291 void TFunctionParametersDialog::CloseWindow()
00292 {
00293    // Close parameters' dialog.
00294 
00295    if (fHasChanges) {
00296       Int_t ret;
00297       const char *txt;
00298       txt = "Do you want to apply last parameters' setting?";
00299       new TGMsgBox(fClient->GetRoot(), GetMainFrame(),
00300                    "Parameters Have Been Changed", txt, kMBIconExclamation,
00301                    kMBYes | kMBNo | kMBCancel, &ret);
00302       if (ret == kMBYes) {
00303          DoOK();
00304          return;
00305       } else if (ret == kMBNo) {
00306          DoReset();
00307       } else return;
00308    }
00309    DeleteWindow();
00310 }
00311 
00312 //______________________________________________________________________________
00313 void TFunctionParametersDialog::DoCancel()
00314 {
00315    // Slot related to the Cancel button.
00316 
00317    if (fHasChanges)
00318       DoReset();
00319    TTimer::SingleShot(50, "TFunctionParametersDialog", this, "CloseWindow()");
00320 }
00321 
00322 //______________________________________________________________________________
00323 void TFunctionParametersDialog::DoFix(Bool_t on)
00324 {
00325    // Slot related to the Fix check button.
00326 
00327    fReset->SetState(kButtonUp);
00328    TGButton *bt = (TGButton *) gTQSender;
00329    Int_t id = bt->WidgetId();
00330    fHasChanges = kTRUE;
00331    for (Int_t i = 0; i < fNP; i++ ) {
00332       if (id == kFIX*fNP+i) {
00333          if (on) {
00334             if (fParVal[i]->GetNumber() != 0) {
00335                fParMin[i]->SetNumber(fParVal[i]->GetNumber());
00336                fParMin[i]->SetEnabled(kFALSE);
00337                fParMax[i]->SetNumber(fParVal[i]->GetNumber());
00338                fParMax[i]->SetEnabled(kFALSE);
00339             } else {
00340                fParMin[i]->SetNumber(1.);
00341                fParMin[i]->SetEnabled(kFALSE);
00342                fParMax[i]->SetNumber(1.);
00343                fParMax[i]->SetEnabled(kFALSE);
00344             }
00345             fParVal[i]->SetState(kFALSE);
00346             fParSld[i]->Disconnect("PointerPositionChanged()");
00347             fParSld[i]->Disconnect("PositionChanged()");
00348             fParSld[i]->UnmapWindow();
00349             fFunc->FixParameter(i, fParVal[i]->GetNumber());
00350          } else if (!fParMin[i]->IsEnabled()) {
00351             if (fPmin[i] != fPmax[i]) {
00352                if (fPmin[i])
00353                   fParMin[i]->SetNumber(fPmin[i]);
00354                else if (fPerr[i])
00355                   fParMin[i]->SetNumber(fPval[i]-3*fPerr[i]);
00356                else if (fPval[i])
00357                   fParMin[i]->SetNumber(fPval[i]-0.1*fPval[i]);
00358                else
00359                   fParMin[i]->SetNumber(1.0);
00360                if (fPmax[i])
00361                   fParMax[i]->SetNumber(fPmax[i]);
00362                else if (fPerr[i])
00363                   fParMax[i]->SetNumber(fPval[i]+3*fPerr[i]);
00364                else if (fPval[i])
00365                   fParMax[i]->SetNumber(fPval[i]+0.1*fPval[i]);
00366                else
00367                   fParMax[i]->SetNumber(1.0);
00368             } else if (fPval[i]) {
00369                fParMin[i]->SetNumber(fPval[i]-0.1*fPval[i]);
00370                fParMax[i]->SetNumber(fPval[i]+0.1*fPval[i]);
00371             } else {
00372                fParMin[i]->SetNumber(1.0);
00373                fParMax[i]->SetNumber(1.0);
00374             }
00375             if (fParMax[i]->GetNumber() < fParMin[i]->GetNumber()){
00376                Double_t temp;
00377                temp = fParMax[i]->GetNumber();
00378                fParMax[i]->SetNumber(fParMin[i]->GetNumber());
00379                fParMin[i]->SetNumber(temp);
00380             }
00381             fParMax[i]->SetEnabled(kTRUE);
00382             fParMin[i]->SetEnabled(kTRUE);
00383             fParSld[i]->MapWindow();
00384             fParVal[i]->SetState(kTRUE);
00385             fParSld[i]->SetRange(fParMin[i]->GetNumber(), fParMax[i]->GetNumber());
00386             fParSld[i]->SetPosition(fParMin[i]->GetNumber(), fParMax[i]->GetNumber());
00387             fParSld[i]->SetPointerPosition(fPval[i]);
00388             fParSld[i]->Connect("PointerPositionChanged()", "TFunctionParametersDialog",
00389                                 this, "DoSlider()");
00390             fParSld[i]->Connect("PositionChanged()", "TFunctionParametersDialog",
00391                                 this, "DoSlider()");
00392             fFunc->SetParLimits(i, fParMin[i]->GetNumber(), fParMax[i]->GetNumber());
00393          }
00394       }
00395    }
00396    if (fUpdate->GetState() == kButtonDown)
00397       RedrawFunction();
00398    else if ((fApply->GetState() == kButtonDisabled) && fHasChanges)
00399       fApply->SetState(kButtonUp);
00400 }
00401 
00402 //______________________________________________________________________________
00403 void TFunctionParametersDialog::DoOK()
00404 {
00405    // Slot related to the OK button.
00406 
00407    if (fHasChanges)
00408       RedrawFunction();
00409    fFunc->SetRange(fRangexmin, fRangexmax);
00410    TTimer::SingleShot(50, "TFunctionParametersDialog", this, "CloseWindow()");
00411 }
00412 
00413 //______________________________________________________________________________
00414 void TFunctionParametersDialog::DoApply()
00415 {
00416    // Slot related to the Preview button.
00417 
00418    RedrawFunction();
00419    fApply->SetState(kButtonDisabled);
00420    if (fReset->GetState() == kButtonDisabled)
00421       fReset->SetState(kButtonUp);
00422 }
00423 
00424 //______________________________________________________________________________
00425 void TFunctionParametersDialog::DoReset()
00426 {
00427    // Slot related to the Reset button.
00428 
00429    fHasChanges = kTRUE;
00430    Int_t k = fNP;
00431    for (Int_t i = 0; i < fNP; i++) {
00432       if (fParVal[i]->GetNumber() == fPval[i])
00433          k--;
00434       else
00435          break;
00436    }
00437 
00438    if (!k) {
00439       if (fReset->GetState() == kButtonUp)
00440          fReset->SetState(kButtonDisabled);
00441       fHasChanges = kFALSE;
00442       return;
00443    }
00444    for (Int_t i = 0; i < fNP; i++) {
00445       fFunc->SetParameter(i, fPval[i]);
00446       fFunc->SetParLimits(i, fPmin[i], fPmax[i]);
00447       fFunc->SetParError(i, fPerr[i]);
00448 
00449       if (fPmin[i])
00450          fParMin[i]->SetNumber(fPmin[i]);
00451       else if (fPerr[i])
00452          fParMin[i]->SetNumber(fPval[i]-3*fPerr[i]);
00453       else if (fPval[i])
00454          fParMin[i]->SetNumber(fPval[i]-0.1*fPval[i]);
00455       else
00456          fParMin[i]->SetNumber(1.0);
00457 
00458       if (fPmax[i])
00459          fParMax[i]->SetNumber(fPmax[i]);
00460       else if (fPerr[i])
00461          fParMax[i]->SetNumber(fPval[i]+3*fPerr[i]);
00462       else if (fPval[i])
00463          fParMax[i]->SetNumber(fPval[i]+0.1*fPval[i]);
00464       else
00465          fParMax[i]->SetNumber(1.0);
00466       if (fParMax[i]->GetNumber() < fParMin[i]->GetNumber()){
00467          Double_t temp;
00468          temp = fParMax[i]->GetNumber();
00469          fParMax[i]->SetNumber(fParMin[i]->GetNumber());
00470          fParMin[i]->SetNumber(temp);
00471       }
00472       if (fParMin[i]->GetNumber() == fParMax[i]->GetNumber()) {
00473          fParVal[i]->SetState(kFALSE);
00474          fParMin[i]->SetEnabled(kFALSE);
00475          fParMax[i]->SetEnabled(kFALSE);
00476          fParSld[i]->Disconnect("PointerPositionChanged()");
00477          fParSld[i]->Disconnect("PositionChanged()");
00478          fParSld[i]->UnmapWindow();
00479          fFunc->FixParameter(i, fParVal[i]->GetNumber());
00480          fParFix[i]->SetState(kButtonDown);
00481       } else {
00482          fParFix[i]->SetState(kButtonUp);
00483          if (!fParMax[i]->IsEnabled()) {
00484             fParMax[i]->SetEnabled(kTRUE);
00485             fParMin[i]->SetEnabled(kTRUE);
00486             fParVal[i]->SetState(kTRUE);
00487             fParSld[i]->SetRange(fParMin[i]->GetNumber(), fParMax[i]->GetNumber());
00488             fParSld[i]->SetPosition(fParMin[i]->GetNumber(), fParMax[i]->GetNumber());
00489             fParSld[i]->SetPointerPosition(fPval[i]);
00490             fParSld[i]->MapWindow();
00491             fParSld[i]->Connect("PointerPositionChanged()", "TFunctionParametersDialog",
00492                                 this, "DoSlider()");
00493             fParSld[i]->Connect("PositionChanged()", "TFunctionParametersDialog",
00494                                 this, "DoSlider()");
00495          }
00496       }
00497       fParVal[i]->SetNumber(fPval[i]);
00498 
00499       fParSld[i]->SetRange(fParMin[i]->GetNumber(), fParMax[i]->GetNumber());
00500       fParSld[i]->SetPosition(fParMin[i]->GetNumber(), fParMax[i]->GetNumber());
00501       fParSld[i]->SetPointerPosition(fPval[i]);
00502    }
00503 
00504    if (fUpdate->GetState() == kButtonDown)
00505       RedrawFunction();
00506    else if ((fApply->GetState() == kButtonDisabled) && fHasChanges)
00507       fApply->SetState(kButtonUp);
00508    fHasChanges = kFALSE;
00509    fReset->SetState(kButtonDisabled);
00510 }
00511 
00512 //______________________________________________________________________________
00513 void TFunctionParametersDialog::DoSlider()
00514 {
00515    // Slot related to the parameters' value settings.
00516 
00517    TGTripleHSlider *sl = (TGTripleHSlider *) gTQSender;
00518    Int_t id = sl->WidgetId();
00519 
00520    fHasChanges = kTRUE;
00521    for (Int_t i = 0; i < fNP; i++ ) {
00522       if (id == kSLD*fNP+i) {
00523          fFunc->SetParameter(i,fParSld[i]->GetPointerPosition());
00524          fFunc->SetParLimits(i,fParSld[i]->GetMinPosition(),
00525                                fParSld[i]->GetMaxPosition());
00526          fParMin[i]->SetNumber(fParSld[i]->GetMinPosition());
00527          fParMax[i]->SetNumber(fParSld[i]->GetMaxPosition());
00528          fParVal[i]->SetNumber(fParSld[i]->GetPointerPosition());
00529       }
00530    }
00531    if (fUpdate->GetState() == kButtonDown)
00532       RedrawFunction();
00533    else if ((fApply->GetState() == kButtonDisabled) && fHasChanges)
00534       fApply->SetState(kButtonUp);
00535    if (fReset->GetState() == kButtonDisabled)
00536       fReset->SetState(kButtonUp);
00537 }
00538 
00539 //______________________________________________________________________________
00540 void TFunctionParametersDialog::DoParValue()
00541 {
00542    // Slot related to the parameter value settings.
00543 
00544    TGNumberEntry *ne = (TGNumberEntry *) gTQSender;
00545    Int_t id = ne->WidgetId();
00546 
00547    for (Int_t i = 0; i < fNP; i++ ) {
00548       if (id == kVAL*fNP+i)  {
00549          fParSld[i]->SetPointerPosition(fParVal[i]->GetNumber());
00550          if (fParVal[i]->GetNumber() < fParMin[i]->GetNumber()) {
00551             fParMin[i]->SetNumber(fParVal[i]->GetNumber());
00552             fClient->NeedRedraw(fParMin[i]);
00553             fParSld[i]->SetRange(fParMin[i]->GetNumber(),
00554                                  fParMax[i]->GetNumber());
00555             fParSld[i]->SetPosition(fParMin[i]->GetNumber(),
00556                                     fParMax[i]->GetNumber());
00557          }
00558          if (fParVal[i]->GetNumber() > fParMax[i]->GetNumber()) {
00559             fParMax[i]->SetNumber(fParVal[i]->GetNumber());
00560             fClient->NeedRedraw(fParMax[i]);
00561             fParSld[i]->SetRange(fParMin[i]->GetNumber(),
00562                                  fParMax[i]->GetNumber());
00563             fParSld[i]->SetPosition(fParMin[i]->GetNumber(),
00564                                     fParMax[i]->GetNumber());
00565          }
00566          fClient->NeedRedraw(fParSld[i]);
00567          fFunc->SetParameter(i,fParSld[i]->GetPointerPosition());
00568          fFunc->SetParLimits(i,fParSld[i]->GetMinPosition(),
00569                                fParSld[i]->GetMaxPosition());
00570       }
00571    }
00572    fHasChanges = kTRUE;
00573    if (fUpdate->GetState() == kButtonDown)
00574       RedrawFunction();
00575    else if ((fApply->GetState() == kButtonDisabled) && fHasChanges)
00576       fApply->SetState(kButtonUp);
00577    if (fReset->GetState() == kButtonDisabled)
00578       fReset->SetState(kButtonUp);
00579 }
00580 
00581 //______________________________________________________________________________
00582 void TFunctionParametersDialog::DoParMinLimit()
00583 {
00584    // Slot related to the minumum parameter limit settings.
00585 
00586    TGNumberEntryField *ne = (TGNumberEntryField *) gTQSender;
00587    Int_t id = ne->WidgetId();
00588 
00589    for (Int_t i = 0; i < fNP; i++ ) {
00590       if (id == kMIN*fNP+i) {
00591          if (fParMin[i]->GetNumber() > fParMax[i]->GetNumber()) {
00592             Int_t ret;
00593             const char *txt;
00594             txt = "The lower parameter bound cannot be bigger then the upper one.";
00595             new TGMsgBox(fClient->GetRoot(), GetMainFrame(),
00596                          "Parameter Limits", txt, kMBIconExclamation,kMBOk,&ret);
00597             fParMin[i]->SetNumber(fParVal[i]->GetNumber());
00598             return;
00599          }
00600          fParSld[i]->SetRange(fParMin[i]->GetNumber(),
00601                               fParMax[i]->GetNumber());
00602          fParSld[i]->SetPosition(fParMin[i]->GetNumber(),
00603                                  fParMax[i]->GetNumber());
00604          fParSld[i]->SetPointerPosition(fParVal[i]->GetNumber());
00605          fClient->NeedRedraw(fParSld[i]);
00606       }
00607    }
00608    fHasChanges = kTRUE;
00609    if (fUpdate->GetState() == kButtonDown)
00610       RedrawFunction();
00611    else if ((fApply->GetState() == kButtonDisabled) && fHasChanges)
00612       fApply->SetState(kButtonUp);
00613    if (fReset->GetState() == kButtonDisabled)
00614       fReset->SetState(kButtonUp);
00615 }
00616 
00617 //______________________________________________________________________________
00618 void TFunctionParametersDialog::DoParMaxLimit()
00619 {
00620    // Slot related to the maximum parameter limit settings.
00621 
00622    TGNumberEntryField *ne = (TGNumberEntryField *) gTQSender;
00623    Int_t id = ne->WidgetId();
00624 
00625    for (Int_t i = 0; i < fNP; i++ ) {
00626       if (id == kMAX*fNP+i) {
00627          if (fParMin[i]->GetNumber() > fParMax[i]->GetNumber()) {
00628             Int_t ret;
00629             const char *txt;
00630             txt = "The lower parameter bound cannot be bigger then the upper one.";
00631             new TGMsgBox(fClient->GetRoot(), GetMainFrame(),
00632                          "Parameter Limits", txt, kMBIconExclamation,kMBOk,&ret);
00633             fParMax[i]->SetNumber(fParVal[i]->GetNumber());
00634             return;
00635          }
00636          fParSld[i]->SetRange(fParMin[i]->GetNumber(),
00637                               fParMax[i]->GetNumber());
00638          fParSld[i]->SetPosition(fParMin[i]->GetNumber(),
00639                                  fParMax[i]->GetNumber());
00640          fParSld[i]->SetPointerPosition(fParVal[i]->GetNumber());
00641          fClient->NeedRedraw(fParSld[i]);
00642       }
00643    }
00644    fHasChanges = kTRUE;
00645    if (fUpdate->GetState() == kButtonDown)
00646       RedrawFunction();
00647    else if ((fApply->GetState() == kButtonDisabled) && fHasChanges)
00648       fApply->SetState(kButtonUp);
00649    if (fReset->GetState() == kButtonDisabled)
00650       fReset->SetState(kButtonUp);
00651 }
00652 
00653 //______________________________________________________________________________
00654 void TFunctionParametersDialog::RedrawFunction()
00655 {
00656    // Redraw function graphics.
00657 
00658    TString opt = fFunc->GetDrawOption();
00659    opt.ToUpper();
00660    if (!opt.Contains("SAME"))
00661       opt += "SAME";
00662    fFunc->SetRange(fRXmin, fRXmax);
00663    fFunc->Draw(opt);
00664    fFpad->Modified();
00665    fFpad->Update();
00666    fHasChanges = kFALSE;
00667 }
00668 
00669 //______________________________________________________________________________
00670 void TFunctionParametersDialog::HandleButtons(Bool_t update)
00671 {
00672    // Handle the button dependent states in this dialog.
00673 
00674    if (update && fHasChanges)
00675       RedrawFunction();
00676    else if ((fApply->GetState() == kButtonDisabled) && fHasChanges) {
00677       fApply->SetState(kButtonUp);
00678    }
00679 }

Generated on Tue Jul 5 14:19:46 2011 for ROOT_528-00b_version by  doxygen 1.5.1