00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include "TGo4FitPanelSlots.h"
00017
00018 #include <fstream.h>
00019 #include <iomanip.h>
00020 #include <iostream.h>
00021
00022 #include <qwidget.h>
00023 #include <qstring.h>
00024 #include <qtable.h>
00025 #include <qtextedit.h>
00026 #include <qlabel.h>
00027 #include <qtabwidget.h>
00028 #include <qcombobox.h>
00029 #include <qlistbox.h>
00030 #include <qlistview.h>
00031 #include <qcheckbox.h>
00032 #include <qspinbox.h>
00033 #include <qpopupmenu.h>
00034 #include <qmessagebox.h>
00035 #include <qevent.h>
00036 #include <qdragobject.h>
00037 #include <qfiledialog.h>
00038 #include <qinputdialog.h>
00039 #include <qlineedit.h>
00040 #include <qworkspace.h>
00041 #include <qwidgetlist.h>
00042 #include <qwidgetstack.h>
00043 #include <qsize.h>
00044 #include <qslider.h>
00045 #include <qpushbutton.h>
00046 #include <qradiobutton.h>
00047
00048 #include "QFitItem.h"
00049 #include "QFitWidget.h"
00050 #include "QFitNamedWidget.h"
00051 #include "QFitRangeWidget.h"
00052 #include "QFitRangeCutWidget.h"
00053 #include "QFitParWidget.h"
00054 #include "QFitDependencyWidget.h"
00055 #include "QFitParCfgWidget.h"
00056 #include "QFitDataWidget.h"
00057 #include "QFitModelWidget.h"
00058 #include "QFitModelPolynomWidget.h"
00059 #include "QFitModelGauss1Widget.h"
00060 #include "QFitModelGauss2Widget.h"
00061 #include "QFitModelGaussNWidget.h"
00062 #include "QFitModelFormulaWidget.h"
00063 #include "QFitModelFunctionWidget.h"
00064 #include "QFitAmplEstimWidget.h"
00065 #include "QFitPeakFinderWidget.h"
00066 #include "QFitOutputActionWidget.h"
00067 #include "QFitMinuitWidget.h"
00068 #include "QFitMinuitResWidget.h"
00069 #include "QFitSlotWidget.h"
00070 #include "QFitterWidget.h"
00071 #include "QFitTableWidget.h"
00072 #include "QFitPrintWidget.h"
00073 #include "QFitLinearTransWidget.h"
00074 #include "QFitMatrixTransWidget.h"
00075
00076 #include "Go4LockGuard/TGo4LockGuard.h"
00077 #include "Go4Log/TGo4Log.h"
00078 #include "Go4GUIRegistry/TGo4GUIRegistry.h"
00079 #include "Go4GUI/TGo4MainWindow.h"
00080 #include "Go4GUI/TGo4DiskFileBrowserStatus.h"
00081 #include "Go4GUI/TGo4DiskFileBrowserSlots.h"
00082 #include "Go4GUI/TGo4BrowserStatus.h"
00083 #include "Go4GUI/TGo4BrowserSlots.h"
00084 #include "Go4GUI/TGo4MonitoredListStatus.h"
00085 #include "Go4GUI/TGo4MonitoredObject.h"
00086 #include "Go4GUI/TGo4PreviewPanel.h"
00087 #include "Go4GUI/TGo4PreviewPanelSlots.h"
00088 #include "Go4GUI/TGo4PadOptions.h"
00089 #include "Go4QtBaseWidgets/TGo4WorkSpace.h"
00090 #include "Go4QtBaseWidgets/TGo4QLineEdit.h"
00091
00092 #include "TGo4FitPanelStatus.h"
00093 #include "TGo4FitGUIArrow.h"
00094 #include "TGo4FitGUIDraw.h"
00095 #include "TGo4FitGUIOptions.h"
00096 #include "TGo4FitPanel.h"
00097
00098 #include "Go4Fit/TGo4Fitter.h"
00099 #include "Go4Fit/TGo4FitterAction.h"
00100 #include "Go4Fit/TGo4FitterConfig.h"
00101 #include "Go4Fit/TGo4FitterOutput.h"
00102 #include "Go4Fit/TGo4FitMinuit.h"
00103 #include "Go4Fit/TGo4FitAmplEstimation.h"
00104 #include "Go4Fit/TGo4FitPeakFinder.h"
00105 #include "Go4Fit/TGo4FitParsList.h"
00106 #include "Go4Fit/TGo4FitParameter.h"
00107 #include "Go4Fit/TGo4FitComponent.h"
00108 #include "Go4Fit/TGo4FitModel.h"
00109 #include "Go4Fit/TGo4FitModelPolynom.h"
00110 #include "Go4Fit/TGo4FitModelGauss1.h"
00111 #include "Go4Fit/TGo4FitModelGauss2.h"
00112 #include "Go4Fit/TGo4FitModelGaussN.h"
00113 #include "Go4Fit/TGo4FitModelFormula.h"
00114 #include "Go4Fit/TGo4FitModelFunction.h"
00115 #include "Go4Fit/TGo4FitModelFromData.h"
00116 #include "Go4Fit/TGo4FitData.h"
00117 #include "Go4Fit/TGo4FitDataHistogram.h"
00118 #include "Go4Fit/TGo4FitDataGraph.h"
00119 #include "Go4Fit/TGo4FitDataProfile.h"
00120 #include "Go4Fit/TGo4FitDataRidge.h"
00121 #include "Go4Fit/TGo4FitSlot.h"
00122 #include "Go4Fit/TGo4FitAxisTrans.h"
00123 #include "Go4Fit/TGo4FitLinearTrans.h"
00124 #include "Go4Fit/TGo4FitMatrixTrans.h"
00125
00126 #include "TObjArray.h"
00127 #include "TMarker.h"
00128 #include "TCanvas.h"
00129 #include "TArrow.h"
00130 #include "TStyle.h"
00131 #include "TText.h"
00132 #include "TPaveText.h"
00133 #include "TPaveStats.h"
00134 #include "TROOT.h"
00135 #include "TKey.h"
00136 #include "TMutex.h"
00137 #include "TH1.h"
00138 #include "THStack.h"
00139 #include "TCutG.h"
00140 #include "TDirectory.h"
00141 #include "TFolder.h"
00142 #include "TString.h"
00143 #include "TFile.h"
00144
00145 enum { mt_none = -1, mt_empty,
00146 mt_datalist, mt_data, mt_modellist, mt_model, mt_parslist, mt_par, mt_parcfg,
00147 mt_asslist, mt_ass, mt_rangelist, mt_range, mt_rangecut,
00148 mt_actlist, mt_action,
00149 mt_deplist,
00150 mt_depend, mt_newpars, mt_minuitres, mt_slot, mt_fitter,
00151 mt_allslots };
00152
00153 enum { wt_none = -1, wt_par, wt_data, wt_model, wt_polynom, wt_gauss1, wt_gauss2, wt_gaussn, wt_formula,
00154 wt_function, wt_fromdata, wt_range, wt_rangecut, wt_amplest, wt_peakfinder, wt_minuit, wt_output, wt_depend, wt_parcfg,
00155 wt_minuitres, wt_slot, wt_fitter, wt_named, wt_lintrans, wt_matrtrans, wt_table };
00156
00157 enum {gt_none = -1, gt_data, gt_model, gt_range, gt_ranges, gt_ass, gt_fitter };
00158
00159 enum { ListStackId = 111 } ;
00160
00161 TGo4FitPanelSlots::TGo4FitPanelSlots(const char * name, const char * title, TGo4FitPanel * p) :
00162 TGo4SlotsBaseClass(name , title), fxPanel(p) {
00163
00164 TGo4LockGuard Global;
00165 fxRegistry = TGo4GUIRegistry::Instance();
00166 fxStatus = new TGo4FitPanelStatus("TGo4FitPanelStatus", "Fit Panel Status");
00167 fxRegistry->RegisterSlotClass(this, fxStatus, p);
00168
00169 fxCurrentItem = 0;
00170
00171 fxActiveViewPanel = 0;
00172 fxActivePad = 0;
00173
00174 fxSlotStatusList = new TObjArray();
00175 fxSlotStatusList->SetOwner(kTRUE);
00176
00177 fxDrawPanel = 0;
00178 fbDrawPanelCreation = kFALSE;
00179 }
00180
00181 TGo4FitPanelSlots::~TGo4FitPanelSlots() {
00182 TGo4LockGuard Global;
00183
00184 RemovePrimitives();
00185 RemoveAllDrawObjects();
00186 CloseDrawPanel();
00187
00188 ClearSlotsStatusList();
00189
00190 fxRegistry->UnRegisterClass(this, fxStatus);
00191
00192 delete fxStatus;
00193
00194 delete fxSlotStatusList;
00195 }
00196
00197 void TGo4FitPanelSlots::SetGUI(TGo4FitPanel *GUI) {
00198 TGo4LockGuard Global;
00199 fxPanel = GUI;
00200 }
00201
00202 TGo4Status * TGo4FitPanelSlots::GetStatus() {
00203 TGo4LockGuard Global;
00204 return fxStatus;
00205 }
00206
00207 void TGo4FitPanelSlots::AddObject(TNamed *fxdata) {
00208 TGo4LockGuard Global;
00209
00210
00211 }
00212
00213 void TGo4FitPanelSlots::ActivateByFitter(TGo4Fitter* fitter) {
00214 TGo4LockGuard Global;
00215
00216 ClearSlotsStatusList();
00217
00218 fbWorkingWithPanel = kFALSE;
00219 fxActiveViewPanel = 0;
00220 fxActivePad = 0;
00221
00222 TGo4Fitter* fclone = 0;
00223 if (fitter) fclone = (TGo4Fitter*) fitter->Clone();
00224 SetFitter(fclone);
00225
00226 ChangeActivePage();
00227 }
00228
00229 void TGo4FitPanelSlots::ActivePadSelected(TGo4PreviewPanel* panel, TPad* pad)
00230 {
00231 TGo4LockGuard Global;
00232
00233 if ((panel==0) || (pad==0)) return;
00234
00235
00236
00237
00238
00239
00240 if ((panel==fxDrawPanel) || fbDrawPanelCreation) return;
00241
00242
00243
00244 bool update = fxStatus->FreezeMode();
00245
00246 if (!update && (GetFitter()!=0) && (GetFitter()->GetNumData()>1))
00247 update = true;
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257 if ( WorkingWithPanel() &&
00258 (panel==ActiveViewPanel()) &&
00259 (pad==ActivePad()) ) update=TRUE;
00260
00261
00262 if (update) {
00263 UpdateObjectReferenceInSlots(FALSE);
00264 if (fxStatus->ExtendedWidgetSelected()) UpdateItemsOfType(ot_slot);
00265 if (fxStatus->WizWidgetSelected()) fxPanel->UpdateWizStackWidget();
00266 return;
00267 }
00268
00269
00270 {
00271 RemovePrimitives();
00272 RemoveAllDrawObjects();
00273 CloseDrawPanel();
00274 ClearSlotsStatusList();
00275
00276 fbWorkingWithPanel = kTRUE;
00277 fxActiveViewPanel = panel;
00278 fxActivePad = pad;
00279
00280 UpdateSlotsStatusList();
00281
00282 UpdateActivePage();
00283 }
00284 }
00285
00286 void TGo4FitPanelSlots::ViewPanelRemoved(TGo4PreviewPanel* panel) {
00287 TGo4LockGuard Global;
00288
00289 if (panel==0) return;
00290
00291
00292
00293 RemovePanelFromSlotsStatusList(panel);
00294
00295 if (panel==fxDrawPanel) { fxDrawPanel = 0; return; }
00296
00297 if (WorkingWithPanel() && (panel==ActiveViewPanel()))
00298 {
00299 ClearSlotsStatusList();
00300 fbWorkingWithPanel = kFALSE;
00301 fxActiveViewPanel = 0;
00302 fxActivePad = 0;
00303 }
00304
00305 UpdateActivePage();
00306 }
00307
00308 void TGo4FitPanelSlots::ViewPanelPadUpdate(TGo4PreviewPanel* panel, TPad* pad)
00309 {
00310 if ( !WorkingWithPanel() ||
00311 (panel!=ActiveViewPanel() || (pad==0)) ) return;
00312
00313 RemovePrimitives();
00314
00315 CloseDrawPanel();
00316
00317 UpdateObjectReferenceInSlots(FALSE);
00318 if (fxStatus->ExtendedWidgetSelected()) UpdateItemsOfType(ot_slot);
00319 if (fxStatus->WizWidgetSelected()) fxPanel->UpdateWizStackWidget();
00320 }
00321
00322 Bool_t TGo4FitPanelSlots::WorkingWithPanel()
00323 {
00324 TGo4LockGuard Global;
00325 return fbWorkingWithPanel;
00326 }
00327
00328 Bool_t TGo4FitPanelSlots::WorkingWithOnlyPad()
00329 {
00330 TGo4LockGuard Global;
00331 if (!WorkingWithPanel()) return FALSE;
00332 TObjArray lst;
00333 FillPadsList(lst, ActivePad());
00334 return (lst.GetLast()==0);
00335 }
00336
00337 TGo4PreviewPanel* TGo4FitPanelSlots::ActiveViewPanel()
00338 {
00339 TGo4LockGuard Global;
00340 return fxActiveViewPanel;
00341 }
00342
00343 TPad* TGo4FitPanelSlots::ActivePad()
00344 {
00345 TGo4LockGuard Global;
00346 return fxActivePad;
00347 }
00348
00349 TGo4FitGUIOptions* TGo4FitPanelSlots::FitOptions()
00350 {
00351 TGo4LockGuard Global;
00352 if (WorkingWithPanel()) return GetPadFitOptions(ActiveViewPanel(), ActivePad(), FALSE);
00353 else return &(fxStatus->CommonOptions());
00354 }
00355
00356 TGo4Fitter* TGo4FitPanelSlots::GetFitter() {
00357 TGo4LockGuard Global;
00358 if (FitOptions()) return FitOptions()->GetFitter();
00359 else return 0;
00360 }
00361
00362 void TGo4FitPanelSlots::ChangeActivePage(int id) {
00363 TGo4LockGuard Global;
00364
00365 if (id>0) fxStatus->SelectedWidgetID() = id; else
00366 if ((fxStatus->SelectedWidgetID()==1) && !WorkingWithPanel())
00367 fxStatus->SelectedWidgetID()=1;
00368
00369 fxStatus->ParsWidgetShown() = kFALSE;
00370 UpdateActivePage();
00371 }
00372
00373 void TGo4FitPanelSlots::UpdateActivePage()
00374 {
00375 TGo4LockGuard Global;
00376
00377 int select = fxStatus->SelectedWidgetID();
00378 if (GetFitter()==0) select = 0;
00379
00380 if (fxStatus->ParsWidgetShown() && (select>0)) select = 100;
00381
00382 switch (select) {
00383 case 0: break;
00384 case 1: UpdateSimplePage(); break;
00385 case 2: UpdateWizardPage(); break;
00386 case 3: UpdateExtendedPage(); break;
00387 case 100: {
00388 fxPanel->FillParsWidget();
00389 if (fxStatus->SelectedWidgetID()==2) {
00390 RemovePrimitives();
00391 fxPanel->UpdateWizPaint(-1);
00392 }
00393 break;
00394 }
00395 }
00396
00397 fxPanel->ShowPanelPage(select);
00398 fxPanel->UpdateStatusBar(0);
00399 fxPanel->UpdateItemMenu();
00400 }
00401
00402 void TGo4FitPanelSlots::ChangeSettings(int id) {
00403 TGo4LockGuard Global;
00404
00405 switch(id) {
00406 case 1: fxStatus->NeedConfirmation() = !fxStatus->NeedConfirmation(); break;
00407 case 2: fxStatus->ShowPrimitives() = !fxStatus->ShowPrimitives(); break;
00408 case 3: fxStatus->FreezeMode() = !fxStatus->FreezeMode(); break;
00409 case 4: fxStatus->SaveWithReferences() = !fxStatus->SaveWithReferences(); break;
00410 case 10: fxStatus->UseCurrentRange() = !fxStatus->UseCurrentRange(); break;
00411 case 11: fxStatus->DrawModels() = !fxStatus->DrawModels(); break;
00412 case 12: fxStatus->DrawComponents() = !fxStatus->DrawComponents(); break;
00413 case 13: fxStatus->UseSamePanelForDraw() = !fxStatus->UseSamePanelForDraw(); break;
00414 case 14: fxStatus->DrawBackground() = !fxStatus->DrawBackground(); break;
00415 case 15: fxStatus->DrawInfoOnPad() = !fxStatus->DrawInfoOnPad(); break;
00416 case 16: fxStatus->RecalculateGaussWidth() = !fxStatus->RecalculateGaussWidth(); UpdateActivePage(); break;
00417 case 17: fxStatus->IntegralMode() = 0; UpdateActivePage(); break;
00418 case 18: fxStatus->IntegralMode() = 1; UpdateActivePage(); break;
00419 case 19: fxStatus->IntegralMode() = 2; UpdateActivePage(); break;
00420 case 20: fxStatus->IntegralMode() = 3; UpdateActivePage(); break;
00421 case 21: fxStatus->BuffersUsage() = 0; break;
00422 case 22: fxStatus->BuffersUsage() = 1; break;
00423 case 23: fxStatus->BuffersUsage() = 2; break;
00424 case 24: fxStatus->BuffersUsage() = 3; break;
00425 }
00426 }
00427
00428 void TGo4FitPanelSlots::Fitter_New() {
00429 TGo4LockGuard Global;
00430
00431 if (WorkingWithPanel()) {
00432 ClearSlotsStatusList();
00433
00434 fbWorkingWithPanel = kFALSE;
00435 fxActiveViewPanel = 0;
00436 fxActivePad = 0;
00437 }
00438
00439 TGo4Fitter* fitter = new TGo4Fitter("Fitter","Fitter object");
00440 SetFitter(fitter);
00441
00442 UpdateActivePage();
00443 }
00444
00445 void TGo4FitPanelSlots::Fitter_NewForActivePad(bool overwrite) {
00446 TGo4LockGuard Global;
00447
00448 ClearSlotsStatusList();
00449
00450 TGo4WorkSpace* space = dynamic_cast<TGo4WorkSpace*> (fxRegistry->GetCentralWindow());
00451 if (space==0) return;
00452 TGo4PreviewPanel* Panel = space->GetLastActiveViewPanel();
00453 if ((Panel==0) || (Panel==fxDrawPanel)) return;
00454
00455 if (Panel) {
00456 fbWorkingWithPanel = kTRUE;
00457 fxActiveViewPanel = Panel;
00458 fxActivePad = Panel->GetActivePad();
00459 }
00460
00461 if (overwrite || (GetFitter()==0))
00462 SetFitter(CreateAppropriateFitter("Fitter"));
00463 else
00464 UpdateSlotsStatusList();
00465
00466 UpdateActivePage();
00467 }
00468
00469 void TGo4FitPanelSlots::Fitter_Delete() {
00470 TGo4LockGuard Global;
00471
00472 if(fxStatus->NeedConfirmation())
00473 if ( QMessageBox::information(0,
00474 QString("Delete fitter"),
00475 QString("Are you sure?"),
00476 QMessageBox::Yes, QMessageBox::No) == QMessageBox::No ) return;
00477
00478 RemovePrimitives();
00479 RemoveAllDrawObjects();
00480 CloseDrawPanel();
00481
00482 ClearSlotsStatusList();
00483
00484 if (WorkingWithPanel()) {
00485 DeletePadFitOptions(ActiveViewPanel(), ActivePad());
00486 fbWorkingWithPanel = kFALSE;
00487 fxActiveViewPanel = 0;
00488 fxActivePad = 0;
00489 } else SetFitter(0);
00490
00491 UpdateActivePage();
00492 }
00493
00494 void TGo4FitPanelSlots::Fitter_MoveCopy(bool IsMove, bool ToPad) {
00495 TGo4LockGuard Global;
00496
00497 TGo4PreviewPanel* lastpanel = ActiveViewPanel();
00498 TPad* lastpad = ActivePad();
00499
00500 TGo4FitGUIOptions* lastoptions = FitOptions();
00501 if (lastoptions==0) return;
00502 TGo4FitGUIOptions* options = 0;
00503
00504 TGo4PreviewPanel* Panel = 0;
00505 TGo4Fitter* fitter = 0;
00506
00507 if (ToPad) {
00508 TGo4WorkSpace* space = dynamic_cast<TGo4WorkSpace*> (fxRegistry->GetCentralWindow());
00509 if (space==0) return;
00510 Panel = space->GetLastActiveViewPanel();
00511 if (Panel==0) return;
00512 if ( WorkingWithPanel() && (ActiveViewPanel()==Panel) &&
00513 (ActivePad()==Panel->GetActivePad()) ) return;
00514 } else
00515 if (!WorkingWithPanel()) return;
00516
00517 RemovePrimitives();
00518 CloseDrawPanel();
00519 ClearSlotsStatusList();
00520
00521 if (IsMove) {
00522 fitter = lastoptions->TakeFitter();
00523 if (fitter==0) return;
00524 }
00525
00526 if (ToPad) options = GetPadFitOptions(Panel, Panel->GetActivePad(), TRUE);
00527 else options = &fxStatus->CommonOptions();
00528 if (options==0) return;
00529
00530 if (IsMove) {
00531 options->CopyFrom(*lastoptions, kFALSE);
00532 options->SetFitter(fitter);
00533 if (lastpanel && lastpad)
00534 DeletePadFitOptions(lastpanel, lastpad);
00535 } else
00536 options->CopyFrom(*lastoptions, kTRUE);
00537
00538 if (!fxStatus->FreezeMode())
00539 if (ToPad) {
00540 fbWorkingWithPanel = kTRUE;
00541 fxActiveViewPanel = Panel;
00542 fxActivePad = Panel->GetActivePad();
00543 } else {
00544 fbWorkingWithPanel = kFALSE;
00545 fxActiveViewPanel = 0;
00546 fxActivePad = 0;
00547 }
00548
00549 UpdateSlotsStatusList();
00550 UpdateActivePage();
00551 }
00552
00553 void TGo4FitPanelSlots::Fitter_DropToPanel(TGo4Fitter* fitter, TGo4PreviewPanel* panel)
00554 {
00555 TGo4LockGuard Global;
00556 if ((fitter==0) || (panel==0)) return;
00557
00558 RemovePrimitives();
00559 CloseDrawPanel();
00560 ClearSlotsStatusList();
00561
00562 TGo4FitGUIOptions* options = GetPadFitOptions(panel, panel->GetActivePad(), TRUE);
00563 options->SetFitter((TGo4Fitter*)fitter->Clone());
00564
00565 if (!fxStatus->FreezeMode()) {
00566 fbWorkingWithPanel = kTRUE;
00567 fxActiveViewPanel = panel;
00568 fxActivePad = panel->GetActivePad();
00569 }
00570
00571 UpdateSlotsStatusList();
00572 UpdateActivePage();
00573 }
00574
00575
00576 void TGo4FitPanelSlots::Fitter_SaveToBrowser() {
00577 TGo4LockGuard Global;
00578
00579 TGo4Fitter* fitter = GetFitter();
00580 if (fitter==0) return;
00581
00582 TGo4BrowserSlots* browser = dynamic_cast<TGo4BrowserSlots*> (fxRegistry->GetSlotClass("TGo4BrowserSlots"));
00583 if (browser==0) return;
00584 TGo4BrowserStatus* browserstatus = dynamic_cast<TGo4BrowserStatus*> (browser->GetStatus());
00585 if (browserstatus==0) return;
00586
00587 TObject* obj = browserstatus->GetObjectfromLocalList(fitter->GetName());
00588
00589 if ((obj!=0) && fxStatus->NeedConfirmation())
00590 if ( QMessageBox::information(0,
00591 QString("Copy fitter to browser"),
00592 QString("Object with name ") + fitter->GetName() + " exists. Copy anyway?",
00593 QMessageBox::Yes, QMessageBox::No) == QMessageBox::No ) return;
00594
00595 fitter->SetSaveFlagForObjects(fxStatus->SaveWithReferences());
00596
00597 TGo4Fitter* clone = dynamic_cast<TGo4Fitter*> (fitter->Clone());
00598
00599 browser->AddLocalObject(clone);
00600 }
00601
00602 void TGo4FitPanelSlots::Fitter_SaveToFile() {
00603 TGo4LockGuard Global;
00604
00605 Cmd_SaveFitter(TRUE);
00606 }
00607
00608 void TGo4FitPanelSlots::Fitter_UseWorkspace() {
00609 RemovePrimitives();
00610 CloseDrawPanel();
00611 ClearSlotsStatusList();
00612
00613 fbWorkingWithPanel = kFALSE;
00614 fxActiveViewPanel = 0;
00615 fxActivePad = 0;
00616
00617 UpdateSlotsStatusList();
00618 UpdateActivePage();
00619 }
00620
00621
00622 void TGo4FitPanelSlots::Fitter_UpdateReferences() {
00623 TGo4LockGuard Global;
00624
00625 UpdateObjectReferenceInSlots(FALSE);
00626 UpdateActivePage();
00627 }
00628
00629 void TGo4FitPanelSlots::Fitter_PrintParameters() {
00630 TGo4LockGuard Global;
00631
00632 QTable* tab = fxPanel->ParsTable;
00633 if (tab==0) return;
00634
00635 TGo4Log::Info("Printout of fitter parameters table");
00636
00637 QString str("Name");
00638 for(int ncol=0;ncol<tab->numCols();ncol++) {
00639 str+="\t";
00640 str+=tab->horizontalHeader()->label(ncol);
00641 }
00642 TGo4Log::Info(str.ascii());
00643
00644 for(int nrow=0;nrow<tab->numRows();nrow++) {
00645 str = tab->verticalHeader()->label(nrow);
00646 for(int ncol=0;ncol<tab->numCols();ncol++) {
00647 str+="\t";
00648 str+=tab->text(nrow, ncol);
00649 }
00650 TGo4Log::Info(str.ascii());
00651 }
00652 }
00653
00654 void TGo4FitPanelSlots::Fitter_RollbackParameters() {
00655 TGo4Fitter* fitter = GetFitter();
00656 fitter->RememberPars();
00657
00658
00659 fxPanel->UpdateStatusBar(0);
00660
00661 UpdateActivePage();
00662 }
00663
00664 void TGo4FitPanelSlots::Button_WorkWithPanel() {
00665 TGo4LockGuard Global;
00666
00667 if (GetFitter()!=0) {
00668 TGo4WorkSpace* space = dynamic_cast<TGo4WorkSpace*> (fxRegistry->GetCentralWindow());
00669 if (space==0) return;
00670 TGo4PreviewPanel* panel = space->GetLastActiveViewPanel();
00671 if ((panel==0) || (panel==fxDrawPanel)) return;
00672 if ( (panel!=ActiveViewPanel()) || (panel->GetActivePad()!=ActivePad()))
00673 Fitter_MoveCopy(FALSE, TRUE);
00674 }
00675 else Fitter_NewForActivePad(FALSE);
00676 }
00677
00678 void TGo4FitPanelSlots::Button_SimpleFit(int nmodel) {
00679 TGo4LockGuard Global;
00680
00681 if (!WorkingWithOnlyPad() || (ActivePad()==0)) return;
00682
00683 TGo4Fitter* fitter = GetFitter();
00684 if ((fitter==0) || (FitOptions()==0)) return;
00685
00686 if (fitter->GetNumData()!=1) { cout << " Incorrect data" << endl; return; }
00687
00688 if (!UpdateObjectReferenceInSlots(FALSE)) return;
00689
00690 TGo4FitData* data = fitter->GetData(0);
00691 if (data==0) return;
00692
00693 data->ClearRanges();
00694 data->SetRange(0, ActivePad()->GetUxmin(), ActivePad()->GetUxmax());
00695
00696 fitter->SetMemoryUsage(1);
00697
00698 int NumDim = data->DefineDimensions();
00699
00700 TGo4FitModel* model = 0;
00701
00702 switch (nmodel) {
00703 case 0:
00704 fitter->AddPolynoms(data->GetName(), "Pol", fxPanel->Smp_PolOrderSpin->value(), NumDim);
00705 break;
00706
00707 case 1:
00708 model = CreateModel(20, 0, fitter, data);
00709 break;
00710
00711 case 2:
00712 model = CreateModel(24, 0, fitter, data);
00713 break;
00714
00715 case 3:
00716 model = CreateModel(25, 0, fitter, data);
00717 break;
00718 }
00719
00720 if (model && ((nmodel==1) || (nmodel==2))) LocateModel(model, data, FALSE);
00721
00722 FitOptions()->UseAmplEstim() = kTRUE;
00723 FitOptions()->NumMigradIter() = 500;
00724
00725 Button_PerformFit();
00726 }
00727
00728 void TGo4FitPanelSlots::Button_SimpleClear() {
00729 TGo4LockGuard Global;
00730
00731 TGo4Fitter* fitter = GetFitter();
00732 if (fitter==0) return;
00733
00734 fitter->DeleteAllModels();
00735
00736 RemovePrimitives();
00737 RemoveAllDrawObjects();
00738 }
00739
00740 void TGo4FitPanelSlots::Button_PeakFinder() {
00741 TGo4LockGuard Global;
00742
00743 if (FitOptions()==0) return;
00744
00745 TGo4Fitter* fitter = GetFitter();
00746 if (fitter==0) return;
00747
00748 TGo4FitPeakFinder* finder = FitOptions()->GetPeakFinder();
00749 if (finder==0) return;
00750
00751 TGo4FitData* data = 0;
00752 if (fxStatus->WizWidgetSelected()) data = FitOptions()->GetWizData();
00753 else data = fitter->GetData(0);
00754 if (data==0) return;
00755
00756 RemovePrimitives();
00757 RemoveAllDrawObjects();
00758
00759 if (fxStatus->UseCurrentRange())
00760 Wiz_TakeCurrentRange();
00761
00762 finder->SetDataName(data->GetName());
00763
00764 finder->SetClearModels(kTRUE);
00765
00766 fitter->SetMemoryUsage(fxStatus->BuffersUsage());
00767
00768 fxPanel->UpdateStatusBar("Start peak finder ... ");
00769
00770 fitter->DoAction(finder);
00771
00772 FitOptions()->UseAmplEstim() = kTRUE;
00773 FitOptions()->NumMigradIter() = 300;
00774
00775 fxPanel->UpdateStatusBar(0);
00776
00777 fxPanel->SetWizPaint(1);
00778 UpdateActivePage();
00779 }
00780
00781 void TGo4FitPanelSlots::Button_PerformFit() {
00782 TGo4LockGuard Global;
00783
00784 TGo4Fitter* fitter = GetFitter();
00785 if ((fitter==0) || (FitOptions()==0)) return;
00786
00787 if (!fxStatus->ExtendedWidgetSelected()) {
00788
00789 if ((FitOptions()->UseAmplEstim()) || (FitOptions()->NumMigradIter()>0)) {
00790 TGo4FitPeakFinder* finder = FitOptions()->GetPeakFinder(kFALSE);
00791 Int_t n=0;
00792 while (n<fitter->GetNumActions()) {
00793 TGo4FitterAction* action = fitter->GetAction(n);
00794 if (action==finder) n++;
00795 else fitter->DeleteAction(action);
00796 }
00797
00798 if (FitOptions()->UseAmplEstim()) fitter->AddAmplEstimation();
00799 if (FitOptions()->NumMigradIter() > 0) {
00800 TGo4FitMinuit* minuit = new TGo4FitMinuit("Minuit");
00801 QString cmd("MIGRAD ");
00802 cmd+=QString::number(FitOptions()->NumMigradIter());
00803 cmd+=" 1";
00804 minuit->AddCommand(cmd.ascii());
00805 fitter->AddAction(minuit);
00806 }
00807 }
00808
00809 if (fitter->GetNumActions() == 0)
00810 fitter->AddStandardActions();
00811 }
00812
00813 if (fxStatus->UseCurrentRange())
00814 Wiz_TakeCurrentRange();
00815
00816 fitter->SetMemoryUsage(fxStatus->BuffersUsage());
00817
00818 fitter->MemorizePars();
00819
00820 fxPanel->UpdateStatusBar("Start fitting ... ");
00821
00822 fitter->DoActions();
00823
00824 Button_FitterDraw();
00825
00826 if (fxStatus->SimpleWidgetSelected()) {
00827 RemovePrimitives();
00828 if (!fxStatus->ShowPrimitives()) return;
00829 TGo4FitData* data = fitter->GetData(0);
00830 PaintModelsFor(fitter, data, 0, TRUE);
00831 fxPanel->UpdateStatusBar(0);
00832
00833 } else UpdateActivePage();
00834 }
00835
00836 void TGo4FitPanelSlots::Button_FitterDraw(TGo4FitData* selecteddata)
00837 {
00838 TGo4LockGuard Global;
00839
00840 RemoveAllDrawObjects(FALSE);
00841
00842 TGo4Fitter* fitter = GetFitter();
00843 if ((fitter==0) || (FitOptions()==0)) return;
00844
00845 if (!fxStatus->DrawModels() &&
00846 !fxStatus->DrawComponents() &&
00847 !fxStatus->DrawBackground()) return;
00848
00849 bool UseSamePads = fxStatus->UseSamePanelForDraw();
00850 if (UseSamePads)
00851 for(Int_t n=0;n<fitter->GetNumData();n++) {
00852 TGo4FitData* data = fitter->GetData(n);
00853 if (selecteddata && (data!=selecteddata)) continue;
00854
00855 if (data->IsAnyDataTransform()) {
00856 UseSamePads = FALSE;
00857 break;
00858 }
00859
00860 TGo4FitSlotStatus* sstatus = FindSlotStatusForDraw(data, TRUE);
00861 if ((sstatus==0) || (sstatus->SourcePad()==0)) {
00862 UseSamePads = FALSE;
00863 break;
00864 }
00865 }
00866
00867 int NeedPads = 1;
00868 if(!UseSamePads) {
00869 if (fxDrawPanel==0) {
00870 TGo4MainWindow* main = static_cast <TGo4MainWindow *> (fxRegistry->GetMainWindow());
00871 fbDrawPanelCreation = kTRUE;
00872 if(main!=0) fxDrawPanel = main->ViewPanelSlot();
00873
00874 fbDrawPanelCreation = kFALSE;
00875 if (fxDrawPanel==0) return;
00876 } else fxDrawPanel->ClearAllPads();
00877
00878 if (selecteddata==0) NeedPads=fitter->GetNumData();
00879 else NeedPads=1;
00880
00881 if (NeedPads>1) {
00882 int DivX = (int)sqrt(NeedPads);
00883 int DivY = DivX;
00884 while (DivX*DivY<NeedPads) DivY++;
00885 fxDrawPanel->Divide(DivX, DivY);
00886 }
00887 }
00888
00889 TObjArray padslst;
00890 if (!UseSamePads && fxDrawPanel)
00891 FillPadsList(padslst, fxDrawPanel->GetCanvas());
00892
00893 for(Int_t n=0;n<fitter->GetNumData();n++) {
00894 TGo4FitData* data = fitter->GetData(n);
00895
00896 if (selecteddata && (data!=selecteddata)) continue;
00897
00898 TGo4FitSlotStatus* sstatus = FindSlotStatusForDraw(data, UseSamePads);
00899 if (sstatus==0) continue;
00900
00901 TPad* pad = 0;
00902 if (UseSamePads) pad = sstatus->SourcePad();
00903 else pad = dynamic_cast<TPad*> (padslst[n]);
00904 if (pad==0) continue;
00905
00906 sstatus->ClearDrawObjs();
00907
00908 if (!UseSamePads) {
00909 TObject* obj = fitter->CreateDrawObject("Data", data->GetName(), kFALSE);
00910 if (obj!=0) {
00911 TGo4FitGUIDraw* datadraw = new TGo4FitGUIDraw(obj);
00912 datadraw->SetColor(1,1);
00913 sstatus->AddDrawObj(datadraw);
00914 pad->cd();
00915 if (obj->InheritsFrom(TGraph::Class())) datadraw->Draw("AC*");
00916 else datadraw->Draw();
00917 }
00918 }
00919
00920 if (fxStatus->DrawInfoOnPad()) {
00921 Double_t x2 = 0.98, y2=0.5,
00922 x1 = x2 - gStyle->GetStatW(), y1 = y2 - gStyle->GetStatH();
00923 TPaveStats* stats = dynamic_cast<TPaveStats*> (pad->GetPrimitive("stats"));
00924 if (stats) {
00925 x1 = stats->GetX1NDC();
00926 x2 = stats->GetX2NDC();
00927 y2 = stats->GetY1NDC() - 0.05;
00928 y1 = y2 - (stats->GetY2NDC() - stats->GetY1NDC());
00929 if (y1<0.02) y1 = 0.02;
00930 }
00931 TPaveStats* info = new TPaveStats(x1,y1,x2,y2,"brNDC");
00932 info->SetFillColor(gStyle->GetStatColor());
00933 info->SetFillStyle(gStyle->GetStatStyle());
00934 info->SetBorderSize(gStyle->GetStatBorderSize());
00935 info->SetTextFont(gStyle->GetStatFont());
00936 if (gStyle->GetStatFont()%10 > 2)
00937 info->SetTextSize(gStyle->GetStatFontSize());
00938 info->SetFitFormat(gStyle->GetFitFormat());
00939 info->SetStatFormat(gStyle->GetStatFormat());
00940 info->SetTextColor(gStyle->GetStatTextColor());
00941 info->SetTextAlign(12);
00942
00943 info->SetName("fitinfo");
00944
00945 info->AddText(data->GetName());
00946 info->AddLine(0,0,0,0);
00947
00948 char t[500], tt[500];
00949
00950 if (fxPanel->LineParsChk->isChecked())
00951 info->AddText("Line | Ampl | Pos & Width");
00952
00953 for(Int_t m=0;m<fitter->GetNumModel();m++) {
00954 TGo4FitModel* model = fitter->GetModel(m);
00955 if (!model->IsAssignTo(data->GetName())) continue;
00956
00957 if (fxPanel->LineParsChk->isChecked()) {
00958 Double_t ampl, pos, width;
00959
00960 ampl = model->GetAmplValue();
00961 if (!model->GetPosition(0,pos)) pos = 0.;
00962 if (!model->GetWidth(0,width)) width = 0.;
00963
00964 snprintf(tt,500,"%7s | %s%s | %s%s %s%s",
00965 model->GetName(),
00966 "%",gStyle->GetStatFormat(),
00967 "%",gStyle->GetStatFormat(),
00968 "%",gStyle->GetStatFormat());
00969
00970 snprintf(t,500,tt,ampl,pos,width);
00971 info->AddText(t);
00972 } else {
00973 int maxparlen = 7;
00974 for(Int_t np=0;np<model->NumPars();np++) {
00975 int len = strlen(model->GetParFullName(np));
00976 if (len>maxparlen) maxparlen = len;
00977 }
00978 snprintf(tt,500,"%s%ds = %s%s","%",maxparlen,"%",gStyle->GetStatFormat());
00979
00980 for(Int_t np=0;np<model->NumPars();np++) {
00981 snprintf(t,500,tt,model->GetParFullName(np), model->GetPar(np)->GetValue());
00982 info->AddText(t);
00983 }
00984 }
00985 }
00986
00987 sstatus->AddDrawObj(info);
00988 pad->cd();
00989 info->Draw();
00990 }
00991
00992 if (fxStatus->DrawModels()) {
00993 TObject* model = fitter->CreateDrawObject("Model", data->GetName(), kTRUE);
00994 if (model!=0) {
00995 TGo4FitGUIDraw* modeldraw = new TGo4FitGUIDraw(model);
00996 modeldraw->SetColor(4,2);
00997
00998 sstatus->AddDrawObj(modeldraw);
00999 pad->cd();
01000 if (model->InheritsFrom(TGraph::Class())) modeldraw->Draw("L");
01001 else modeldraw->Draw("same");
01002 }
01003 }
01004
01005 if (fxStatus->DrawBackground()) {
01006 TObject* model = fitter->CreateDrawObject("Background", data->GetName(), kTRUE, "Background");
01007 if (model!=0) {
01008 TGo4FitGUIDraw* modeldraw = new TGo4FitGUIDraw(model);
01009 modeldraw->SetColor(6,1);
01010
01011 sstatus->AddDrawObj(modeldraw);
01012 pad->cd();
01013 if (model->InheritsFrom(TGraph::Class())) modeldraw->Draw("L");
01014 else modeldraw->Draw("same");
01015 }
01016 }
01017
01018 if (fxStatus->DrawComponents())
01019 for(Int_t m=0;m<fitter->GetNumModel();m++) {
01020 TGo4FitModel* model = fitter->GetModel(m);
01021 if (!model->IsAssignTo(data->GetName())) continue;
01022 if (model->GetGroupIndex()==0) continue;
01023 TString compname("Comp");
01024 compname+=m;
01025 TObject* comp = fitter->CreateDrawObject(compname.Data(), data->GetName(), kTRUE, model->GetName());
01026 if (comp==0) continue;
01027
01028 TGo4FitGUIDraw* compdraw = new TGo4FitGUIDraw(comp);
01029 compdraw->SetColor(6,1);
01030 sstatus->AddDrawObj(compdraw);
01031 pad->cd();
01032
01033 if (comp->InheritsFrom(TGraph::Class())) compdraw->Draw("L");
01034 else compdraw->Draw("same");
01035 }
01036
01037 pad->Modified();
01038 }
01039
01040 if (UseSamePads) UpdateAllPads(); else
01041 if (fxDrawPanel) fxDrawPanel->GetCanvas()->Update();
01042 }
01043
01044 void TGo4FitPanelSlots::Wiz_PrepareModelTypeList(QPopupMenu* menu) {
01045 TGo4LockGuard Global;
01046 if (menu) FillModelTypesList(menu,0, TRUE);
01047 }
01048
01049 TGo4FitModel* TGo4FitPanelSlots::Wiz_CreateNewModel(int id) {
01050 TGo4LockGuard Global;
01051
01052 TGo4Fitter* fitter = GetFitter();
01053 if (fitter==0) return 0;
01054
01055 TGo4FitData* data = FitOptions()->GetWizData();
01056 TGo4FitModel* model = CreateModel(id, 0, fitter, data);
01057
01058 LocateModel(model, data);
01059
01060 return model;
01061 }
01062
01063
01064 void TGo4FitPanelSlots::Wiz_PrepareDataTypeList(QPopupMenu* menu) {
01065 TGo4LockGuard Global;
01066
01067 if (menu) FillDataTypesList(menu,0);
01068 }
01069
01070
01071 TGo4FitData* TGo4FitPanelSlots::Wiz_CreateNewData(int id) {
01072 TGo4LockGuard Global;
01073
01074 TGo4Fitter* fitter = GetFitter();
01075 if (fitter==0) return 0;
01076
01077 TGo4FitData* data = CreateData(id, 0);
01078 if (data==0) return 0;
01079
01080 fitter->AddData(data);
01081
01082 UpdateSlotsStatusList();
01083
01084 return data;
01085 }
01086
01087 void TGo4FitPanelSlots::Wiz_RebuildDataList() {
01088 TGo4LockGuard Global;
01089
01090 TGo4Fitter* fitter = GetFitter();
01091 if (fitter==0) return;
01092 if ((fitter->GetNumData()>0) && fxStatus->NeedConfirmation())
01093 if ( QMessageBox::information(0,
01094 QString("Remake data list"),
01095 QString("Remove all current data?"),
01096 QMessageBox::Yes, QMessageBox::No) == QMessageBox::No ) return;
01097
01098 fitter->DeleteAllData();
01099 CreateAppropriateData(fitter);
01100
01101 UpdateSlotsStatusList();
01102 UpdateActivePage();
01103 }
01104
01105 bool TGo4FitPanelSlots::Wiz_RemoveData() {
01106 TGo4LockGuard Global;
01107
01108 TGo4Fitter* fitter = GetFitter();
01109 TGo4FitData* data = FitOptions()->GetWizData();
01110 if ((data==0) || (fitter==0)) return FALSE;
01111
01112 if(fxStatus->NeedConfirmation())
01113 if ( QMessageBox::information(0,
01114 QString("Delete data"),
01115 QString("Are you sure to delete ") + data->GetName(),
01116 QMessageBox::Yes, QMessageBox::No) == QMessageBox::No ) return FALSE;
01117
01118 fitter->RemoveData(data->GetName(), kTRUE);
01119
01120 FitOptions()->SetWizDataName("");
01121
01122 UpdateSlotsStatusList();
01123
01124 return TRUE;
01125 }
01126
01127 bool TGo4FitPanelSlots::Wiz_DataHasPad() {
01128 TGo4LockGuard Global;
01129
01130 if (FitOptions()==0) return FALSE;
01131
01132 return (FindPadWhereData(FitOptions()->GetWizData())!=0);
01133 }
01134
01135
01136 void TGo4FitPanelSlots::Wiz_UseSelectedRange() {
01137 TGo4LockGuard Global;
01138
01139 if (FitOptions()==0) return;
01140
01141 TGo4FitData* data = FitOptions()->GetWizData();
01142 TPad* pad = FindPadWhereData(data);
01143
01144 if ((pad==0) || (data==0)) return;
01145
01146 data->SetRange(0, pad->GetUxmin(), pad->GetUxmax());
01147
01148 UpdateActivePage();
01149 }
01150
01151 void TGo4FitPanelSlots::Wiz_TakeCurrentRange() {
01152 TGo4LockGuard Global;
01153
01154 TGo4Fitter* fitter = GetFitter();
01155 if (fitter==0) return;
01156
01157 for (int n=0;n<fitter->GetNumData();n++) {
01158 TGo4FitData* data = fitter->GetData(n);
01159 TPad* pad = FindPadWhereData(data);
01160 if ((pad!=0) && (data!=0)) {
01161 data->ClearRanges();
01162 data->SetRange(0, pad->GetUxmin(), pad->GetUxmax());
01163 }
01164 }
01165 }
01166
01167 void TGo4FitPanelSlots::Wiz_GetSlotSourceInfo(TGo4FitSlot* slot, QString* info) {
01168 TGo4LockGuard Global;
01169
01170 TGo4FitSlotStatus* sstatus = FindSlotStatusForSlot(slot);
01171 if ((sstatus==0) || (info==0)) return;
01172
01173 switch (sstatus->Source()) {
01174 case TGo4FitSlotStatus::fss_none:
01175 (*info) = "none";
01176 break;
01177 case TGo4FitSlotStatus::fss_owned:
01178 if(strlen(sstatus->InfoStr())==0) (*info) = "internal object";
01179 else (*info) = sstatus->InfoStr();
01180 break;
01181 case TGo4FitSlotStatus::fss_reference:
01182 if(strlen(sstatus->InfoStr())==0) {
01183 TGo4FitSlot* conslot = slot->GetConnectedSlot();
01184 if (conslot==0) (*info) = "reference to external object";
01185 else (*info) = QString("from slot ") + conslot->GetFullName();
01186 } else (*info) = sstatus->InfoStr();
01187 break;
01188 case TGo4FitSlotStatus::fss_pad:
01189 GetCombinationName(sstatus->SourcePanel(), sstatus->SourcePad(), info);
01190 break;
01191 }
01192 }
01193
01194 void TGo4FitPanelSlots::Wiz_GetModelInfo(TGo4FitModel* model, QString* info) {
01195 if ((model==0) || (info==0)) return;
01196 *info = "Model: ";
01197 *info += model->GetName();
01198 *info += " of class: ";
01199 *info += model->ClassName();
01200
01201 if (model->InheritsFrom(TGo4FitModelFormula::Class())) {
01202 TGo4FitModelFormula* formula = dynamic_cast<TGo4FitModelFormula*> (model);
01203 if (formula) {
01204 *info += "\nFormula: ";
01205 *info += formula->GetExpression();
01206 }
01207 }
01208
01209 if (model->InheritsFrom(TGo4FitModelFunction::Class())) {
01210 TGo4FitModelFunction* func = dynamic_cast<TGo4FitModelFunction*> (model);
01211 if (func) {
01212 *info += "\nFunction: ";
01213 *info += func->GetFunctionName();
01214 *info += " from: ";
01215 *info += func->GetLibraryName();
01216 }
01217 }
01218 if (fxStatus->IntegralMode()>0) {
01219 int mode = fxStatus->IntegralMode();
01220
01221 if ((mode==1) || (mode==2)) {
01222 TGo4Fitter* fitter = GetFitter();
01223 TGo4FitData* data = FitOptions() ? FitOptions()->GetWizData() : 0;
01224 if (data)
01225 if (!model->IsAssignTo(data->GetName())) data = 0;
01226 if ((data!=0) && (fitter!=0)) {
01227 if (mode==1) *info += "\nCounts="; else *info += "\nIntegral=";
01228 double v = fitter->CalculatesIntegral(data->GetName(),model->GetName(),(mode==1));
01229 *info += QString::number(v);
01230 }
01231 }
01232
01233 if (mode==3) {
01234 double v = model->Integral();
01235 if (v>0) {
01236 *info += "\nGauss integral=";
01237 *info += QString::number(v);
01238 }
01239 }
01240 }
01241 }
01242
01243 void TGo4FitPanelSlots::Wiz_ClearPaint()
01244 {
01245 TGo4LockGuard Global;
01246
01247 RemovePrimitives();
01248 }
01249
01250 bool TGo4FitPanelSlots::Wiz_PaintData()
01251 {
01252 TGo4LockGuard Global;
01253
01254 if (!fxStatus->ShowPrimitives()) return FALSE;
01255 TGo4Fitter* fitter = GetFitter();
01256 TGo4FitData* data = FitOptions()->GetWizData();
01257
01258 if (fitter && data) {
01259 TGo4FitSlotStatus* sstatus = PaintModelsFor(fitter, data, 0);
01260 if (sstatus==0) return FALSE;
01261 for(Int_t n=0;n<data->GetNumRangeCondition();n++)
01262 PaintRange(data, n, sstatus, 0);
01263 if (sstatus) sstatus->UpdatePad();
01264 return TRUE;
01265 }
01266
01267 return FALSE;
01268 }
01269
01270 bool TGo4FitPanelSlots::Wiz_PaintModel() {
01271 TGo4LockGuard Global;
01272
01273 RemovePrimitives();
01274 if (!fxStatus->ShowPrimitives()) return FALSE;
01275 TGo4Fitter* fitter = GetFitter();
01276 TGo4FitModel* model = FitOptions()->GetWizModel();
01277
01278 if ((fitter==0) || (model==0)) return FALSE;
01279
01280 bool draw = FALSE;
01281 for(Int_t n=0;n<model->NumAssigments();n++) {
01282 TGo4FitData* data = fitter->FindData(model->AssignmentName(n));
01283 TGo4FitSlotStatus* sstatus = FindSlotStatusForData(data, TRUE);
01284 if (sstatus && data)
01285 if (!data->IsAnyDataTransform()) {
01286 PaintModel(model, sstatus, 0);
01287 draw = TRUE;
01288 }
01289 }
01290
01291 UpdateAllPads();
01292 return draw;
01293 }
01294
01295 void TGo4FitPanelSlots::ListItemClicked(QListViewItem* item) {
01296 TGo4LockGuard Global;
01297
01298 QFitItem* fititem = dynamic_cast<QFitItem*> (item);
01299 if (fititem==0) return;
01300
01301 ShowItem(fititem);
01302 fxCurrentItem = fititem;
01303
01304 fxPanel->UpdateItemMenu();
01305 }
01306
01307 void TGo4FitPanelSlots::SetItemText(QFitItem* item, bool trace) {
01308 TGo4LockGuard Global;
01309
01310 if (item==0) return;
01311 QString text;
01312 if (item->Object()) text = item->Object()->GetName();
01313 switch (item->ObjectType()) {
01314 case ot_empty: text = "empty"; break;
01315 case ot_datalist: text = "Data"; break;
01316 case ot_data: break;
01317 case ot_modellist: text = "Models"; break;
01318 case ot_model: break;
01319 case ot_parslist: text = "Parameters"; break;
01320 case ot_par:
01321 case ot_parcfg: {
01322 TGo4FitParameter* par = dynamic_cast<TGo4FitParameter*> (item->Object());
01323 if (par) text += " = " + QString::number(par->GetValue());
01324 break; }
01325 case ot_asslist: text = "Assigments"; break;
01326 case ot_ass: {
01327 TGo4FitModel* model = dynamic_cast<TGo4FitModel*> (item->Object());
01328 if (model) text = model->AssignmentName(item->Tag());
01329 break; }
01330 case ot_rangelist: text = "Ranges"; break;
01331 case ot_range: {
01332 TGo4FitComponent* comp = dynamic_cast<TGo4FitComponent*> (item->Object());
01333 if ((comp==0) || (item->Tag()<0) || (item->Tag()>=comp->GetNumRangeCondition())) break;
01334
01335 Int_t typ, naxis;
01336 Double_t left, right;
01337 comp->GetRangeCondition(item->Tag(), typ, naxis, left, right);
01338 text = QString::number(naxis) + ": ";
01339
01340 switch(typ) {
01341 case 0: text+="[" + QString::number(left) + "..." + QString::number(right) + "]"; break;
01342 case 1: text+="... " + QString::number(left) + "] [" + QString::number(right) + " ..."; break;
01343 case 2: text+="[" + QString::number(left) + " ..."; break;
01344 case 3: text+="... " + QString::number(right) + "]"; break;
01345 }
01346 break; }
01347 case ot_rangecut: break;
01348 case ot_actlist: text = "Actions"; break;
01349 case ot_action: break;
01350 case ot_amplest: break;
01351 case ot_peakfinder: break;
01352 case ot_output: break;
01353 case ot_config: break;
01354 case ot_minuit: break;
01355 case ot_parinitlist: text = "Initialization"; break;
01356 case ot_pardeplist: text = "Dependency"; break;
01357 case ot_reslist: text = "Results"; break;
01358 case ot_depend: {
01359 TGo4FitDependency* depen = dynamic_cast<TGo4FitDependency*> (item->Object());
01360 if (depen==0) break;
01361 if (depen->IsResultDepend()) text = "Res" + QString::number(item->Tag());
01362 else text = depen->GetParameter().Data();
01363 text += " = ";
01364 if (depen->IsInitValue()) text += QString::number(depen->GetInitValue());
01365 else text += depen->GetExpression().Data();
01366 break; }
01367 case ot_newpars: text = "New pars"; break;
01368 case ot_parscfg: text = "Pars setup"; break;
01369 case ot_minuitres: break;
01370 case ot_slot: break;
01371 case ot_fitter: break;
01372 case ot_trans: break;
01373 case ot_lintrans: break;
01374 case ot_matrtrans: break;
01375 case ot_results: text = "Results"; break;
01376 case ot_allslots: text = "Objects"; break;
01377 }
01378
01379 item->setText(0, text);
01380
01381 if (trace && (item->Object()!=0)) {
01382 QFitItem* topitem = GetFitterItem();
01383 if (topitem==0) return;
01384
01385 QListViewItemIterator iter(topitem);
01386 while (iter.current()!=0) {
01387 QFitItem* it = dynamic_cast<QFitItem*> (iter.current());
01388 if ((it!=0) && (it!=item) &&
01389 (item->ObjectType()==it->ObjectType()) &&
01390 (item->Object()==it->Object()))
01391 it->setText(0, text);
01392 ++iter;
01393 }
01394 }
01395 }
01396
01397 void TGo4FitPanelSlots::UpdateItem(QFitItem* item, bool trace) {
01398 TGo4LockGuard Global;
01399
01400 if (item==0) return;
01401
01402 if (fxCurrentItem!=0)
01403 if (fxCurrentItem->FindInParents(item)) RemoveWidgetFromListStack();
01404
01405 while (item->firstChild())
01406 delete item->firstChild();
01407
01408 SetItemText(item, FALSE);
01409
01410 switch (item->ObjectType()) {
01411 case ot_empty: break;
01412 case ot_datalist: {
01413 TGo4Fitter* fitter = dynamic_cast<TGo4Fitter*> (item->Object());
01414 if(fitter)
01415 for(Int_t n=fitter->GetNumData()-1;n>=0;n--)
01416 new QFitItem(this, item, fitter->GetData(n), ot_data, wt_data, mt_data, gt_data, n);
01417 break; }
01418 case ot_data: {
01419 TGo4FitData* data = dynamic_cast<TGo4FitData*> (item->Object());
01420 if (data==0) break;
01421
01422 FillSlotsList(item, data->GetSlotList(), data);
01423
01424 new QFitItem(this, item, data, ot_parslist, wt_none, mt_parslist);
01425
01426 new QFitItem(this, item, data, ot_rangelist, wt_none, mt_rangelist, gt_ranges);
01427
01428 break; }
01429 case ot_modellist: {
01430 TGo4Fitter* fitter = dynamic_cast<TGo4Fitter*> (item->Object());
01431 if(fitter)
01432 for(Int_t n=fitter->GetNumModel()-1;n>=0;n--)
01433 new QFitItem(this, item, fitter->GetModel(n), ot_model, DefineModelWidgetType(fitter->GetModel(n)), mt_model, gt_model, n);
01434 break; }
01435 case ot_model: {
01436 TGo4FitModel* model = dynamic_cast<TGo4FitModel*> (item->Object());
01437 if (model==0) break;
01438
01439 FillSlotsList(item, model->GetSlotList(), model);
01440
01441 new QFitItem(this, item, model, ot_parslist, wt_none, mt_parslist);
01442
01443 new QFitItem(this, item, model, ot_rangelist, wt_none, mt_rangelist, gt_ranges);
01444
01445 new QFitItem(this, item, model, ot_asslist, wt_none, mt_asslist, gt_none);
01446
01447 break; }
01448 case ot_parslist: FillParsList(item); break;
01449 case ot_par: break;
01450 case ot_parcfg: break;
01451 case ot_asslist: {
01452 TGo4FitModel* model = dynamic_cast<TGo4FitModel*> (item->Object());
01453 if (model)
01454 for (Int_t n = model->NumAssigments()-1; n>=0; n--)
01455 new QFitItem(this, item, model, ot_ass, wt_none, mt_ass, gt_ass, n);
01456 break; }
01457 case ot_ass: break;
01458 case ot_rangelist: {
01459 TGo4FitComponent* comp = dynamic_cast<TGo4FitComponent*> (item->Object());
01460 if (comp) {
01461 for (Int_t n = comp->GetNumRangeCut()-1; n>=0; n--)
01462 new QFitItem(this, item, comp->GetRangeCut(n), ot_rangecut, wt_rangecut, mt_rangecut, gt_none, n);
01463 for (Int_t n = comp->GetNumRangeCondition()-1; n>=0; n--)
01464 new QFitItem(this, item, comp, ot_range, wt_range, mt_range, gt_range, n);
01465 }
01466 break; }
01467 case ot_range: break;
01468 case ot_rangecut: break;
01469 case ot_actlist: {
01470 TGo4Fitter* fitter = dynamic_cast<TGo4Fitter*> (item->Object());
01471 if (fitter==0) break;
01472 for (Int_t n = fitter->GetNumActions()-1; n>=0; n--) {
01473 TGo4FitterAction* action = fitter->GetAction(n);
01474 int ot = ot_action, wt = wt_named;
01475 if (action->InheritsFrom(TGo4FitterConfig::Class())) ot = ot_config; else
01476 if (action->InheritsFrom(TGo4FitAmplEstimation::Class())) { ot = ot_amplest; wt = wt_amplest; } else
01477 if (action->InheritsFrom(TGo4FitPeakFinder::Class())) { ot = ot_peakfinder; wt = wt_peakfinder; } else
01478 if (action->InheritsFrom(TGo4FitterOutput::Class())) { ot = ot_output; wt = wt_output; } else
01479 if (action->InheritsFrom(TGo4FitMinuit::Class())) { ot = ot_minuit; wt = wt_minuit; }
01480
01481 new QFitItem(this, item, action, ot, wt, mt_action);
01482 }
01483 break;
01484 }
01485 case ot_action: break;
01486 case ot_amplest: break;
01487 case ot_peakfinder: break;
01488 case ot_output: break;
01489 case ot_config: {
01490 TGo4FitterConfig* cfg = dynamic_cast<TGo4FitterConfig*> (item->Object());
01491 if (cfg==0) break;
01492 new QFitItem(this, item, &(cfg->GetResults()), ot_reslist, wt_none, mt_deplist);
01493 new QFitItem(this, item, &(cfg->GetParsDepend()), ot_pardeplist, wt_none, mt_deplist);
01494 new QFitItem(this, item, &(cfg->GetParsInit()), ot_parinitlist, wt_none, mt_deplist);
01495 new QFitItem(this, item, &(cfg->GetParsCfg()), ot_parscfg, wt_none, mt_newpars);
01496 new QFitItem(this, item, &(cfg->GetParsNew()), ot_newpars, wt_none, mt_newpars);
01497 break; }
01498 case ot_minuit: {
01499 TGo4FitMinuit* minuit = dynamic_cast<TGo4FitMinuit*> (item->Object());
01500 if (minuit==0) break;
01501 for (Int_t n=minuit->GetNumResults()-1;n>=0;n--)
01502 new QFitItem(this, item, minuit->GetResult(n), ot_minuitres, wt_minuitres, mt_minuitres);
01503 break; }
01504 case ot_parinitlist: FillDependencyList(item); break;
01505 case ot_pardeplist: FillDependencyList(item); break;
01506 case ot_reslist: FillDependencyList(item); break;
01507 case ot_depend: break;
01508 case ot_newpars: FillParsList(item); break;
01509 case ot_parscfg: {
01510 TGo4FitParsList* pars = dynamic_cast<TGo4FitParsList*> (item->Object());
01511 if (pars==0) return;
01512 for (Int_t n = pars->NumPars()-1; n>=0;n--)
01513 new QFitItem(this, item, pars->GetPar(n), ot_parcfg, wt_parcfg, mt_parcfg);
01514 break; }
01515 case ot_minuitres: break;
01516 case ot_slot: {
01517 TGo4FitSlot* slot = dynamic_cast<TGo4FitSlot*> (item->Object());
01518 if(slot==0) break;
01519
01520 TObject* obj = slot->GetObject();
01521 if (obj==0) break;
01522
01523 if (obj->InheritsFrom(TGo4FitData::Class()))
01524 new QFitItem(this, item, obj, ot_data, wt_data, mt_none);
01525 else
01526
01527 if (obj->InheritsFrom(TGo4FitModel::Class()))
01528 new QFitItem(this, item, obj, ot_model, DefineModelWidgetType(obj), mt_none);
01529 else
01530
01531 if (obj->InheritsFrom(TGo4FitLinearTrans::Class()))
01532 new QFitItem(this, item, obj, ot_lintrans, wt_lintrans, mt_none);
01533 else
01534
01535 if (obj->InheritsFrom(TGo4FitMatrixTrans::Class()))
01536 new QFitItem(this, item, obj, ot_matrtrans, wt_matrtrans, mt_none);
01537 else
01538
01539 if (obj->InheritsFrom(TGo4FitAxisTrans::Class()))
01540 new QFitItem(this, item, obj, ot_trans, wt_named, mt_none);
01541 else
01542
01543 new QFitItem(this, item, obj, ot_none, wt_none, mt_none);
01544
01545 break; }
01546 case ot_fitter: {
01547 TGo4Fitter* fitter = dynamic_cast<TGo4Fitter*> (item->Object());
01548 if (fitter==0) break;
01549
01550 new QFitItem(this, item, fitter, ot_results, wt_table);
01551 new QFitItem(this, item, fitter, ot_actlist, wt_none, mt_actlist);
01552 new QFitItem(this, item, fitter, ot_allslots, wt_none, mt_allslots);
01553 new QFitItem(this, item, fitter, ot_modellist, wt_none, mt_modellist);
01554 new QFitItem(this, item, fitter, ot_datalist, wt_none, mt_datalist);
01555 break; }
01556 case ot_trans: FillParsList(item); break;
01557 case ot_lintrans: FillParsList(item); break;
01558 case ot_matrtrans: FillParsList(item); break;
01559 case ot_results: break;
01560 case ot_allslots: {
01561 TGo4Fitter* fitter = dynamic_cast<TGo4Fitter*> (item->Object());
01562 if (fitter)
01563 FillSlotsList(item, fitter->GetSlotList(), 0);
01564 break; }
01565 }
01566
01567 if (trace && (item->Object()!=0)) {
01568 QFitItem* topitem = GetFitterItem();
01569 if (topitem==0) return;
01570
01571 QListViewItemIterator iter(topitem);
01572 while (iter.current()!=0) {
01573 QFitItem* it = dynamic_cast<QFitItem*> (iter.current());
01574 if ((it!=0) && (it!=item) &&
01575 (item->ObjectType()==it->ObjectType()) &&
01576 (item->Object()==it->Object())) UpdateItem(it, FALSE);
01577 ++iter;
01578 }
01579 }
01580 }
01581
01582 void TGo4FitPanelSlots::UpdateItemsOfType(int typ, QFitItem* parent) {
01583 TGo4LockGuard Global;
01584
01585 if (parent==0) parent = GetFitterItem();
01586
01587 QListViewItemIterator iter(parent);
01588 while (iter.current()!=0) {
01589 QFitItem* item = dynamic_cast<QFitItem*> (iter.current());
01590 if ((item!=0) && (item->ObjectType()==typ)) UpdateItem(item, FALSE);
01591 ++iter;
01592 }
01593 }
01594
01595 bool TGo4FitPanelSlots::ChangeObjectName(QFitItem* item, const char* newname) {
01596 TGo4LockGuard Global;
01597
01598 if ((item==0) || (strlen(newname)==0)) return FALSE;
01599 TNamed* obj = dynamic_cast<TNamed*> (item->Object());
01600 if (obj==0) return FALSE;
01601
01602 if (item->ObjectType()==ot_slot) return FALSE;
01603
01604 if (item->ObjectType()==ot_par)
01605 if (item->Parent()!=0)
01606 if (item->Parent()->ObjectType()==ot_parslist) {
01607 TGo4FitParsList* pars = dynamic_cast<TGo4FitParsList*> (item->Parent()->Object());
01608 if (pars->FindPar(newname)) return FALSE;
01609 }
01610
01611 if (item->ObjectType()==ot_data)
01612 if (item->Parent()!=0)
01613 if (item->Parent()->ObjectType()==ot_datalist) {
01614 TGo4Fitter* fitter = GetFitter();
01615 if ((fitter==0) || (fitter->FindData(newname))) return FALSE;
01616 fitter->ChangeDataNameInAssignments(obj->GetName(), newname);
01617 UpdateItemsOfType(ot_ass);
01618 }
01619
01620 if (item->ObjectType()==ot_model)
01621 if (item->Parent()!=0)
01622 if (item->Parent()->ObjectType()==ot_modellist) {
01623 TGo4Fitter* fitter = GetFitter();
01624 if ((fitter==0) || (fitter->FindModel(newname))) return FALSE;
01625 }
01626
01627 obj->SetName(newname);
01628
01629 return TRUE;
01630 }
01631
01632 void TGo4FitPanelSlots::FitItemDeleted(QFitItem* item) {
01633 TGo4LockGuard Global;
01634
01635 if (fxCurrentItem==item) RemoveWidgetFromListStack();
01636 }
01637
01638 void TGo4FitPanelSlots::ArrowChanged(TGo4FitGUIArrow* arr)
01639 {
01640 TGo4LockGuard Global;
01641
01642 if (arr==0) return;
01643
01644 UpdateRestPrimitives(arr);
01645
01646 if (fxStatus->ExtendedWidgetSelected()) {
01647 if ((arr->GetType()==TGo4FitGUIArrow::at_pos) ||
01648 (arr->GetType()==TGo4FitGUIArrow::at_width)) UpdateItemsOfType(ot_par, arr->GetItem());
01649
01650 if (arr->GetType()==TGo4FitGUIArrow::at_range) SetItemText(arr->GetItem(), TRUE);
01651
01652 QFitWidget* current = dynamic_cast<QFitWidget*> (fxPanel->ListStack->widget(ListStackId));
01653 if(current) current->FillWidget();
01654 }
01655
01656 if (fxStatus->WizWidgetSelected())
01657 if (fxStatus->ParsWidgetShown())
01658 fxPanel->FillParsWidget();
01659 else
01660 fxPanel->UpdateWizStackWidget();
01661
01662 UpdateAllPads();
01663 }
01664
01665 void TGo4FitPanelSlots::DeleteModelWithPrimit(TGo4FitGUIArrow* arr) {
01666 TGo4LockGuard Global;
01667
01668 if (arr==0) return;
01669 TGo4FitModel* model = arr->GetModel();
01670 if (model==0) return;
01671
01672 if (fxStatus->ExtendedWidgetSelected()) {
01673 QFitItem* item = FindItem(model, ot_model);
01674 if (item) Cmd_DeleteModel(item);
01675 } else
01676 if (Cmd_RemoveModel(model)) UpdateActivePage();
01677 }
01678
01679 bool TGo4FitPanelSlots::FillPopupForItem(QFitItem * item, QPopupMenu* menu) {
01680 TGo4LockGuard Global;
01681
01682 if((item==0) || (menu==0)) return FALSE;
01683
01684 if(item->PopupMenuType() == mt_empty) {
01685 menu->insertItem(QString("Create empty fitter"),8);
01686 if (WorkingWithPanel()) menu->insertItem(QString("Create appropriate fitter"),9);
01687 }
01688
01689 if(item->PopupMenuType() == mt_fitter) {
01690 menu->insertItem(QString("Delete fitter"),1);
01691 menu->insertItem(QString("Clear fitter"),2);
01692 menu->insertItem(QString("Save fitter"),3);
01693 menu->insertItem(QString("Save fitter as ..."),4);
01694 menu->insertItem(QString("Print ..."),5);
01695 menu->insertItem(QString("Draw"),6);
01696 menu->insertItem(QString("Memorize parameters"), 706);
01697 menu->insertItem(QString("Remember parameters"), 707);
01698
01699 }
01700
01701 if(item->PopupMenuType() == mt_data) {
01702 if (!WorkingWithPanel())
01703 menu->insertItem(QString("Remove ")+item->Object()->GetName(),101);
01704 menu->insertItem(QString("Remove assosiated models"),102);
01705 menu->insertItem(QString("Draw"),105);
01706 menu->insertItem(QString("Print"),5);
01707 }
01708
01709 if(item->PopupMenuType() == mt_datalist)
01710 if (WorkingWithPanel()) {
01711 menu->insertItem(QString("Rebuild data list"),108);
01712 } else {
01713 menu->insertItem(QString("Delete all data"),107);
01714 FillDataTypesList(menu, 110);
01715 }
01716
01717 if(item->PopupMenuType() == mt_model) {
01718 menu->insertItem(QString("Remove ")+item->Object()->GetName(),201);
01719 menu->insertItem(QString("Print"),5);
01720 }
01721
01722 if(item->PopupMenuType() == mt_modellist) {
01723 menu->insertItem(QString("Delete all models"),202);
01724 FillModelTypesList(menu, 210, TRUE);
01725 }
01726
01727 if(item->PopupMenuType() == mt_asslist) {
01728 TGo4Fitter* fitter = GetFitter();
01729 TGo4FitModel* model = dynamic_cast<TGo4FitModel*> (item->Object());
01730 if (fitter && model) {
01731 menu->insertItem(QString("Clear all assignments"), 301);
01732 menu->insertItem(QString("Assign to all data"), 302);
01733 menu->insertSeparator();
01734 for(Int_t n=0; n<fitter->GetNumData();n++)
01735 if(!model->IsAssignTo(fitter->GetDataName(n)))
01736 menu->insertItem(QString("Assign to: ") + fitter->GetDataName(n), 310+n);
01737 }
01738 }
01739
01740 if(item->PopupMenuType() == mt_ass)
01741 menu->insertItem(QString("Clear assignment to ") + item->text(0), 303);
01742
01743 if(item->PopupMenuType() == mt_range) {
01744 menu->insertItem(QString("Remove range condition"), 401);
01745 }
01746
01747 if(item->PopupMenuType() == mt_rangecut) {
01748 menu->insertItem(QString("Remove range condition"), 401);
01749 }
01750
01751 if(item->PopupMenuType() == mt_rangelist) {
01752 TGo4FitComponent* comp = dynamic_cast<TGo4FitComponent*> (item->Object());
01753 if(comp) {
01754 if (comp->IsAnyRangeLimits()>0) {
01755 menu->insertItem(QString("Clear all ranges"), 402);
01756 menu->insertSeparator();
01757 }
01758 menu->insertItem(QString("Include new range"), 403);
01759 menu->insertItem(QString("Exclude new range"), 404);
01760 menu->insertItem(QString("Add left bound"), 405);
01761 menu->insertItem(QString("Add right bound"), 406);
01762 menu->insertSeparator();
01763 menu->insertItem(QString("Add range cut"), 407);
01764 }
01765 }
01766
01767 if(item->PopupMenuType() == mt_action) {
01768 menu->insertItem(QString("Delete action"), 501);
01769 menu->insertItem(QString("Move action up"), 502);
01770 menu->insertItem(QString("Move action down"), 503);
01771 menu->insertItem(QString("Print"),5);
01772 menu->insertItem(QString("Execute"), 508);
01773 }
01774
01775 if(item->PopupMenuType() == mt_actlist) {
01776 TGo4Fitter* fitter = dynamic_cast<TGo4Fitter*> (item->Object());
01777 if(fitter) {
01778 if (fitter->GetNumActions()>0) {
01779 menu->insertItem(QString("Execute norm actions"), 504);
01780 menu->insertItem(QString("Execute all actions"), 507);
01781 menu->insertItem(QString("Delete all actions"), 505);
01782 menu->insertItem(QString("Delete output actions"), 506);
01783 menu->insertSeparator();
01784 }
01785 menu->insertItem(QString("Add config"), 510);
01786 menu->insertItem(QString("Add peak finder"), 514);
01787 menu->insertItem(QString("Add amplitude estimation"), 511);
01788 menu->insertItem(QString("Add minuit"), 512);
01789 menu->insertItem(QString("Add output"), 513);
01790 }
01791 }
01792
01793 if(item->PopupMenuType() == mt_depend) {
01794 menu->insertItem(QString("Delete item"), 601);
01795 }
01796
01797 if(item->PopupMenuType() == mt_deplist) {
01798 menu->insertItem(QString("Delete all items"), 602);
01799 menu->insertItem(QString("Insert new item"), 603);
01800 }
01801
01802 if(item->PopupMenuType() == mt_newpars) {
01803 menu->insertItem(QString("Delete all items"), 701);
01804 menu->insertItem(QString("Insert new item"), 702);
01805 }
01806
01807 if(item->PopupMenuType() == mt_parcfg)
01808 menu->insertItem(QString("Delete item"), 703);
01809
01810 if(item->PopupMenuType() == mt_par) {
01811 menu->insertItem(QString("Memorize value"), 704);
01812 menu->insertItem(QString("Remember value"), 705);
01813 }
01814
01815 if((item->PopupMenuType() == mt_parslist)) {
01816 menu->insertItem(QString("Memorize parameters"), 706);
01817 menu->insertItem(QString("Remember parameters"), 707);
01818 }
01819
01820 if(item->PopupMenuType() == mt_minuitres) {
01821 menu->insertItem(QString("Delete result entry"), 801);
01822 menu->insertItem(QString("Print"),5);
01823 }
01824
01825 if(item->PopupMenuType() == mt_slot) {
01826 TGo4FitSlot* slot = dynamic_cast<TGo4FitSlot*> (item->Object());
01827 if (slot!=0) FillPopupForSlot(slot,menu);
01828 }
01829
01830 if(item->PopupMenuType() == mt_allslots) {
01831 TGo4Fitter* fitter = dynamic_cast<TGo4Fitter*> (item->Object());
01832 if(fitter) {
01833 menu->insertItem(QString("Update slots from sources"), 904);
01834 }
01835 }
01836
01837 return (menu->count()>0);
01838 }
01839
01840 bool TGo4FitPanelSlots::ExecPopupForItem(QFitItem * item, int id) {
01841 TGo4LockGuard Global;
01842
01843 switch(id) {
01844 case 1: Cmd_DeleteFitter(); break;
01845 case 2: Cmd_ClearFitter(); break;
01846 case 3: Cmd_SaveFitter(FALSE); break;
01847 case 4: Cmd_SaveFitter(TRUE); break;
01848 case 5: Cmd_ItemPrint(item); break;
01849 case 6: Button_FitterDraw(); break;
01850 case 8: Cmd_CreateFitter(); break;
01851 case 9: Cmd_CreateAppropriateFitter(); break;
01852 case 101: Cmd_DeleteData(item); break;
01853 case 102: Cmd_DeleteAssosiatedModels(item); break;
01854 case 105: Cmd_DrawData(item); break;
01855 case 107: Cmd_DeleteAllData(item); break;
01856 case 108: Wiz_RebuildDataList(); break;
01857 case 201: Cmd_DeleteModel(item); break;
01858 case 202: Cmd_DeleteModels(item); break;
01859 case 301: Cmd_ClearAssigments(item); break;
01860 case 302: Cmd_AssignModelToAllData(item); break;
01861 case 303: Cmd_ClearAssigment(item); break;
01862 case 401: Cmd_RemoveRangeCondition(item); break;
01863 case 402: Cmd_RemoveRangeConditions(item); break;
01864 case 403:
01865 case 404:
01866 case 405:
01867 case 406:
01868 case 407: Cmd_AddRangeCondition(item, id-403); break;
01869 case 501: Cmd_DeleteAction(item); break;
01870 case 502: Cmd_MoveAction(item, -1); break;
01871 case 503: Cmd_MoveAction(item, +1); break;
01872 case 504: Cmd_ExecuteActions(item, FALSE); break;
01873 case 505: Cmd_DeleteActions(item); break;
01874 case 506: Cmd_DeleteOutputActions(item); break;
01875 case 507: Cmd_ExecuteActions(item, TRUE); break;
01876 case 508: Cmd_ExecuteAction(item); break;
01877 case 601: Cmd_DeleteDependency(item); break;
01878 case 602: Cmd_DeleteDependencies(item); break;
01879 case 603: Cmd_AddDependency(item); break;
01880 case 701: Cmd_DeletePars(item); break;
01881 case 702: Cmd_AddNewPar(item); break;
01882 case 703: Cmd_DeletePar(item); break;
01883 case 704: Cmd_MemorizePar(item); break;
01884 case 705: Cmd_RememberPar(item); break;
01885 case 706: Cmd_MemorizePars(item); break;
01886 case 707: Cmd_RememberPars(item); break;
01887 case 801: Cmd_DeleteMinuitResult(item); break;
01888 case 904: Cmd_UpdateAllSlots(item); break;
01889
01890 default:
01891 if ((id>=110) && (id<200)) Cmd_AddNewData(item,id-110); else
01892 if ((id>=210) && (id<300)) Cmd_AddNewModel(item,id-210); else
01893 if ((id>=310) && (id<400)) Cmd_AssignModelToData(item,id-310); else
01894 if ((id>=510) && (id<600)) Cmd_AddNewAction(item,id-510); else
01895 if ((id>=1000) && (id<2000)) ExecutePopupForSlot(item, 0, id);
01896 }
01897
01898 return FALSE;
01899 }
01900
01901
01902 bool TGo4FitPanelSlots::FillPopupForSlot(TGo4FitSlot* slot, QPopupMenu* menu) {
01903 TGo4LockGuard Global;
01904
01905 if ((slot==0) || (menu==0)) return FALSE;
01906
01907 TGo4FitSlotStatus* sstatus = FindSlotStatusForSlot(slot);
01908 if (sstatus==0) return FALSE;
01909
01910 if(!slot->GetOwned() && slot->IsObject())
01911 menu->insertItem(QString("Clone object in slot"), 1000);
01912
01913 if(slot->IsObject())
01914 menu->insertItem(QString("Clear object in slot"), 1001);
01915
01916 if (sstatus->Source()==TGo4FitSlotStatus::fss_pad) {
01917 QString info;
01918 Wiz_GetSlotSourceInfo(slot, &info);
01919 menu->insertItem(QString("Update from ") + info, 1002);
01920 }
01921
01922 if (!WorkingWithPanel()) {
01923 TGo4PreviewPanel* panel = 0;
01924 TGo4WorkSpace* space = dynamic_cast<TGo4WorkSpace*> (fxRegistry->GetCentralWindow());
01925 if (space) panel = space->GetLastActiveViewPanel();
01926
01927 if (panel) {
01928 TObject* obj = GetPadObject(panel, panel->GetActivePad());
01929 if (obj && slot->IsSuitable(obj)) {
01930 QString info;
01931 GetCombinationName(panel, panel->GetActivePad(), &info);
01932 QString item("Get ");
01933 item += obj->GetName();
01934 item += " from ";
01935 item += info;
01936 menu->insertItem(item, 1003);
01937 }
01938 }
01939 }
01940
01941 uint cnt=menu->count();
01942 if (cnt>0) menu->insertSeparator();
01943
01944 if (slot->GetConnectedSlot())
01945 menu->insertItem(QString("Brake connection to slot"), 1004);
01946 TGo4Fitter* fitter = GetFitter();
01947 if (fitter)
01948 for(Int_t n=0;n<fitter->NumSlots();n++) {
01949 TGo4FitSlot* sl = fitter->GetSlot(n);
01950 if (slot->CanConnectToSlot(sl) && (slot->GetConnectedSlot()!=sl))
01951 menu->insertItem(QString("Connect to ") + sl->GetFullName(), 1400 + n);
01952 }
01953
01954 if (cnt<menu->count()) menu->insertSeparator();
01955
01956 if (slot->GetClass() == TGo4FitData::Class()) FillDataTypesList(menu, 1100); else
01957 if (slot->GetClass() == TGo4FitModel::Class()) FillModelTypesList(menu, 1200, FALSE); else
01958 if (slot->GetClass() == TGo4FitAxisTrans::Class()) {
01959 menu->insertItem(QString(TGo4FitLinearTrans::Class()->GetName()), 1300);
01960 menu->insertItem(QString(TGo4FitMatrixTrans::Class()->GetName()), 1301);
01961 }
01962
01963 return (menu->count()>0);
01964 }
01965
01966 void TGo4FitPanelSlots::ExecutePopupForSlot(QFitItem* item, TGo4FitSlot* slot, int id) {
01967 TGo4LockGuard Global;
01968
01969 if (item!=0) slot = dynamic_cast<TGo4FitSlot*> (item->Object());
01970
01971 TGo4Fitter* fitter = GetFitter();
01972 if ((slot==0) || (fitter==0)) return;
01973
01974 TGo4FitSlotStatus* sstatus = FindSlotStatusForSlot(slot);
01975 if (sstatus==0) return;
01976
01977 switch (id) {
01978 case 1000: {
01979 TObject* newobj = slot->CloneObject();
01980 slot->SetObject(newobj, kTRUE);
01981 break;
01982 }
01983
01984 case 1001: {
01985
01986 if(fxStatus->NeedConfirmation())
01987 if ( QMessageBox::information(0,
01988 QString("Clear slot"),
01989 QString("Are you sure to clear object from slot ") + slot->GetName(),
01990 QMessageBox::Yes, QMessageBox::No) == QMessageBox::No ) return;
01991
01992 fitter->ClearSlot(slot, kFALSE);
01993
01994 if (item)
01995 for(Int_t i=0;i<fitter->NumSlots();i++) {
01996 QFitItem* sitem = FindItem(fitter->GetSlot(i), ot_slot);
01997 if (sitem) UpdateItem(sitem, TRUE);
01998 }
01999
02000 break; }
02001
02002 case 1002: {
02003 UpdateObjectReferenceFor(sstatus);
02004 break; }
02005
02006 case 1003: {
02007 TGo4WorkSpace* space = dynamic_cast<TGo4WorkSpace*> (fxRegistry->GetCentralWindow());
02008 if (space==0) return;
02009 TGo4PreviewPanel* panel = space->GetLastActiveViewPanel();
02010 if (panel==0) return;
02011 TObject* obj = GetPadObject(panel, panel->GetActivePad());
02012 if ((obj==0) || !slot->IsSuitable(obj)) return;
02013
02014 slot->SetObject(obj, kFALSE);
02015
02016 sstatus->SetSourcePad(panel, panel->GetActivePad());
02017
02018 break; }
02019
02020 case 1004: {
02021 slot->ClearConnectionToSlot();
02022 break;
02023 }
02024
02025 default: {
02026 TObject* obj = 0;
02027 if ((id>=1100) && (id<1200)) obj = CreateData(id-1100,"Data"); else
02028 if ((id>=1200) && (id<1300)) obj = CreateModel(id-1200, "Model"); else
02029 if (id==1300) obj = new TGo4FitLinearTrans("Trans","Linear axis transformation"); else
02030 if (id==1301) obj = new TGo4FitMatrixTrans("Trans","Matrix axis transformation"); else
02031 if (id>=1400) {
02032 TGo4FitSlot* sl = fitter->GetSlot(id-1400);
02033 slot->ConnectToSlot(sl);
02034 break;
02035 }
02036 if (obj) slot->SetObject(obj, kTRUE);
02037 }
02038 }
02039
02040 if (item) {
02041 ShowItem(item);
02042 UpdateItem(item, TRUE);
02043 item->setOpen(TRUE);
02044 } else UpdateActivePage();
02045
02046 }
02047
02048 void TGo4FitPanelSlots::DragEnterEvent(QDragEnterEvent * Event) {
02049 TGo4LockGuard Global;
02050
02051 Bool_t res = kFALSE;
02052
02053 if(!WorkingWithPanel())
02054 if ( QTextDrag::canDecode(Event) )
02055 if( (strcmp(Event->source()->name(),"FileListView")==0) ||
02056 (strcmp(Event->source()->name(),"ListViewLocal")==0) ||
02057 (strcmp(Event->source()->name(),"ListViewMonitor")==0) ) res = kTRUE;
02058
02059 if(res) Event->accept();
02060 else Event->ignore();
02061 }
02062
02063 void TGo4FitPanelSlots::DragMoveEvent(TObject* obj, int typ, QDragMoveEvent * Event) {
02064 TGo4LockGuard Global;
02065
02066 Bool_t res = (strcmp(Event->source()->name(),"FileListView")==0) ||
02067 (strcmp(Event->source()->name(),"ListViewLocal")==0) ||
02068 (strcmp(Event->source()->name(),"ListViewMonitor")==0);
02069 if (res)
02070 switch (typ) {
02071 case ot_slot: res=!WorkingWithPanel(); break;
02072 case ot_fitter: res=!WorkingWithPanel(); break;
02073 case ot_empty: res=kTRUE; break;
02074 case ot_allslots: {
02075 TGo4Fitter* fitter = dynamic_cast<TGo4Fitter*> (obj);
02076 res = (fitter && fitter->IsEmptySlots() && !WorkingWithPanel());
02077 break; }
02078 case ot_wizdatalist: res = !WorkingWithPanel(); break;
02079 default: res = kFALSE;
02080 }
02081
02082 if(res) Event->accept();
02083 else Event->ignore();
02084 }
02085
02086 bool TGo4FitPanelSlots::DropEvent(TObject* obj, int typ, QDropEvent * Event, QFitItem* item) {
02087 TGo4LockGuard Global;
02088
02089 QString source(Event->source()->name());
02090 QString name;
02091 if (!QTextDrag::decode(Event,name)) return FALSE;
02092
02093 TObject* DragedObject = 0;
02094 bool ownership;
02095 TString SourceInfo;
02096 if (!GetDropedObject(source.ascii(),name.ascii(),&DragedObject,ownership,&SourceInfo)) return FALSE;
02097
02098 if (typ==ot_empty) {
02099 if (DragedObject->InheritsFrom(TGo4Fitter::Class())) {
02100 TGo4Fitter* fitter = 0;
02101 if (ownership) fitter = dynamic_cast<TGo4Fitter*> (DragedObject);
02102 else fitter = dynamic_cast<TGo4Fitter*> (DragedObject->Clone());
02103
02104 SetFitter(fitter);
02105
02106 UpdateActivePage();
02107 return TRUE;
02108 } else {
02109 TGo4Fitter* fitter = new TGo4Fitter("Fitter", "Fitter object");
02110 TGo4FitData* data = CreateDataFor(fitter, DragedObject, ownership, TRUE);
02111
02112 if (data==0) delete fitter; else {
02113 SetFitter(fitter);
02114
02115 UpdateSlotsStatusList();
02116
02117 TGo4FitSlotStatus* sstatus = FindSlotStatusForData(data, FALSE);
02118
02119 if (sstatus)
02120 if (ownership) sstatus->SetSourceOwned(SourceInfo.Data());
02121 else sstatus->SetSourceReference(SourceInfo.Data());
02122
02123 UpdateActivePage();
02124 return TRUE;
02125 }
02126 }
02127
02128 } else
02129
02130 if (typ == ot_allslots) {
02131 TGo4Fitter* fitter = dynamic_cast<TGo4Fitter*> (obj);
02132 if (fitter!=0) {
02133 TGo4FitSlot* slot = fitter->SetObject(DragedObject, ownership);
02134 if (slot!=0) {
02135 TGo4FitSlotStatus* sstatus = FindSlotStatusForSlot(slot);
02136 if (sstatus)
02137 if (ownership) sstatus->SetSourceOwned(SourceInfo.Data());
02138 else sstatus->SetSourceReference(SourceInfo.Data());
02139 if(item) {
02140 QFitItem* sitem = FindItem(slot, ot_slot, item->Parent());
02141 if (sitem) UpdateItem(sitem, TRUE);
02142 }
02143 return TRUE;
02144 }
02145 }
02146 } else
02147
02148
02149 if (typ == ot_slot) {
02150 TGo4FitSlot* slot = dynamic_cast<TGo4FitSlot*> (obj);
02151 if((slot!=0) && slot->IsSuitable(DragedObject)) {
02152 slot->SetObject(DragedObject, ownership);
02153
02154 TGo4FitSlotStatus* sstatus = FindSlotStatusForSlot(slot);
02155 if (sstatus)
02156 if (ownership) sstatus->SetSourceOwned(SourceInfo.Data());
02157 else sstatus->SetSourceReference(SourceInfo.Data());
02158
02159 if (item) {
02160 ShowItem(item);
02161 UpdateItem(item, TRUE);
02162 item->setOpen(TRUE);
02163 } else UpdateActivePage();
02164
02165 return TRUE;
02166 }
02167 } else
02168
02169 if (typ == ot_wizdatalist) {
02170 TGo4Fitter* fitter = GetFitter();
02171
02172 if (fitter && !WorkingWithPanel()) {
02173 TGo4FitData* data = CreateDataFor(fitter, DragedObject, ownership, TRUE);
02174
02175 if (data!=0) {
02176 UpdateSlotsStatusList();
02177 TGo4FitSlotStatus* sstatus = FindSlotStatusForData(data, FALSE);
02178 if (sstatus)
02179 if (ownership) sstatus->SetSourceOwned(SourceInfo.Data());
02180 else sstatus->SetSourceReference(SourceInfo.Data());
02181
02182 UpdateActivePage();
02183 return TRUE;
02184 }
02185 }
02186 }
02187
02188
02189 if (ownership) delete DragedObject;
02190 return FALSE;
02191 }
02192
02193 void TGo4FitPanelSlots::FillPadsList(TObjArray& lst, TPad* pad) {
02194 if (pad==0) return;
02195 Int_t npad = 0;
02196 TObject* obj;
02197 TIter next(pad->GetListOfPrimitives());
02198 while((obj=next()) !=0 )
02199 if (obj->InheritsFrom(TPad::Class())) {
02200 FillPadsList(lst,dynamic_cast<TPad*> (obj));
02201 npad++;
02202 }
02203
02204 if (npad==0) lst.Add(pad);
02205 }
02206
02207 int TGo4FitPanelSlots::GetNumberOfPads() {
02208 TObjArray lst;
02209 FillPadsList(lst, ActivePad());
02210 return lst.GetLast()+1;
02211 }
02212
02213 TPad* TGo4FitPanelSlots::GetPad(int n) {
02214 TObjArray lst;
02215 FillPadsList(lst, ActivePad());
02216 if ((n>=0) && (n<=lst.GetLast())) return dynamic_cast<TPad*> (lst[n]);
02217 else return 0;
02218 }
02219
02220 TObject* TGo4FitPanelSlots::GetPadObject(TGo4PreviewPanel* panel, TPad* pad) {
02221 if ((panel==0) || (pad==0)) return 0;
02222
02223 TGraph* gr = panel->GetPadTGraph(pad);
02224 if (gr!=0) return gr;
02225
02226 THStack* hs = panel->GetPadTHStack(pad);
02227 if (hs!=0) return hs->GetHists()->First();
02228
02229 return panel->GetPadHistogram(pad);
02230 }
02231
02232 TGo4FitGUIOptions* TGo4FitPanelSlots::GetPadFitOptions(TGo4PreviewPanel* panel, TPad* pad, bool autocreate) {
02233 if ((panel==0) || (pad==0)) return 0;
02234
02235 TGo4PadOptions* opt = panel->GetPadOptions(pad);
02236 if (opt==0) return 0;
02237 TGo4FitGUIOptions* fitopt = opt->GetPadFitOptions();
02238
02239 if ((fitopt==0) && autocreate) {
02240 fitopt = new TGo4FitGUIOptions();
02241 fitopt->CopyFrom(fxStatus->CommonOptions());
02242 opt->SetPadFitOptions(fitopt);
02243 }
02244
02245 return fitopt;
02246 }
02247
02248 void TGo4FitPanelSlots::DeletePadFitOptions(TGo4PreviewPanel* panel, TPad* pad) {
02249 if ((panel==0) || (pad==0)) return;
02250
02251 TGo4PadOptions* opt = panel->GetPadOptions(pad);
02252 if (opt==0) return;
02253
02254 TGo4FitGUIOptions* fitopt = opt->GetPadFitOptions();
02255 if (fitopt==0) return;
02256
02257 opt->SetPadFitOptions(0);
02258 delete fitopt;
02259 }
02260
02261 void TGo4FitPanelSlots::ClearSlotsStatusList()
02262 {
02263 UpdateObjectReferenceInSlots(TRUE);
02264 fxSlotStatusList->Clear();
02265 }
02266
02267 void TGo4FitPanelSlots::UpdateSlotsStatusList()
02268 {
02269 TGo4Fitter* fitter = GetFitter();
02270 if (fitter==0) {
02271 fxSlotStatusList->Clear();
02272 return;
02273 }
02274
02275 TObjArray* newSlotStatusList = new TObjArray(fitter->NumSlots());
02276 newSlotStatusList->SetOwner(kTRUE);
02277
02278 for(Int_t n = 0; n<fitter->NumSlots();n++) {
02279 TGo4FitSlot* slot = fitter->GetSlot(n);
02280 if (slot==0) continue;
02281
02282 TGo4FitSlotStatus* sstatus = 0;
02283
02284 for(Int_t n1=0;n1<=fxSlotStatusList->GetLast();n1++) {
02285 sstatus = dynamic_cast<TGo4FitSlotStatus*> (fxSlotStatusList->At(n1));
02286 if (sstatus && (sstatus->Slot()==slot)) break;
02287 sstatus = 0;
02288 }
02289
02290 if (sstatus==0) {
02291 sstatus = new TGo4FitSlotStatus(slot);
02292 if (slot->GetObject())
02293 if (slot->GetOwned()) sstatus->SetSourceOwned();
02294 else sstatus->SetSourceReference();
02295 }
02296 else fxSlotStatusList->Remove(sstatus);
02297
02298 newSlotStatusList->Add(sstatus);
02299 }
02300
02301 delete fxSlotStatusList;
02302
02303 fxSlotStatusList = newSlotStatusList;
02304
02305
02306 if (WorkingWithPanel()) {
02307 TObjArray plst;
02308 FillPadsList(plst, ActivePad());
02309 Int_t npad = 0;
02310
02311 for(Int_t n=0;n<=fxSlotStatusList->GetLast();n++) {
02312 TGo4FitSlotStatus* sstatus = dynamic_cast<TGo4FitSlotStatus*> (fxSlotStatusList->At(n));
02313 if (sstatus==0) continue;
02314
02315 if ((sstatus->Source()==TGo4FitSlotStatus::fss_none) ||
02316 (sstatus->Source()==TGo4FitSlotStatus::fss_pad)) {
02317 TPad* pad = 0;
02318 if (npad<=plst.GetLast()) pad = dynamic_cast<TPad*> (plst[npad++]);
02319 if (pad) sstatus->SetSourcePad(ActiveViewPanel(), pad);
02320 }
02321 }
02322 }
02323
02324 UpdateObjectReferenceInSlots(FALSE);
02325 }
02326
02327 bool TGo4FitPanelSlots::UpdateObjectReferenceInSlots(bool clear, TObject* slotowner) {
02328 bool res = TRUE;
02329
02330 for(Int_t n=0;n<=fxSlotStatusList->GetLast();n++) {
02331 TGo4FitSlotStatus* sstatus = dynamic_cast<TGo4FitSlotStatus*> (fxSlotStatusList->At(n));
02332 if ((sstatus==0) || (sstatus->Slot()==0)) { res = FALSE; continue; }
02333 TGo4FitSlot* slot = sstatus->Slot();
02334 if ((slotowner!=0) && (slot->GetOwner()!=slotowner)) continue;
02335 if (clear) { slot->SetObject(0, kFALSE); continue; }
02336
02337 if (!UpdateObjectReferenceFor(sstatus)) res=FALSE;
02338 }
02339
02340 return res;
02341 }
02342
02343 void TGo4FitPanelSlots::UpdateRestPrimitives(TGo4FitGUIArrow* arr)
02344 {
02345 for(Int_t n=0;n<=fxSlotStatusList->GetLast();n++) {
02346 TGo4FitSlotStatus* sstatus = dynamic_cast<TGo4FitSlotStatus*> (fxSlotStatusList->At(n));
02347 if (sstatus==0) continue;
02348 if (sstatus->UpdateRestPrimitives(arr))
02349 if (sstatus->SourcePad()) sstatus->SourcePad()->Modified();
02350 }
02351 }
02352
02353 void TGo4FitPanelSlots::RemovePrimitives(TObject* obj)
02354 {
02355 for(Int_t n=0;n<=fxSlotStatusList->GetLast();n++) {
02356 TGo4FitSlotStatus* sstatus = dynamic_cast<TGo4FitSlotStatus*> (fxSlotStatusList->At(n));
02357 if (sstatus==0) continue;
02358 bool res = FALSE;
02359 if (obj==0) res = sstatus->ClearPrimitives();
02360 else res = sstatus->RemovePrimitivesFor(obj);
02361 if (res && sstatus->SourcePad())
02362 sstatus->SourcePad()->Modified();
02363 }
02364 }
02365
02366 void TGo4FitPanelSlots::UpdateAllPads()
02367 {
02368 for(Int_t n=0;n<=fxSlotStatusList->GetLast();n++) {
02369 TGo4FitSlotStatus* sstatus = dynamic_cast<TGo4FitSlotStatus*> (fxSlotStatusList->At(n));
02370 if (sstatus && sstatus->SourcePad())
02371 sstatus->SourcePad()->Update();
02372 }
02373 }
02374
02375 bool TGo4FitPanelSlots::UpdateObjectReferenceFor(TGo4FitSlotStatus* sstatus) {
02376 if (sstatus==0) return FALSE;
02377 TGo4FitSlot* slot = sstatus->Slot();
02378 if (slot==0) return FALSE;
02379 bool res = TRUE;
02380 if (sstatus->Source()==TGo4FitSlotStatus::fss_pad) {
02381 TObject* obj = GetPadObject(sstatus->SourcePanel(), sstatus->SourcePad());
02382 if (obj==0) res = FALSE;
02383 if ((obj==0) || !slot->IsSuitable(obj)) slot->SetObject(0, kFALSE);
02384 else slot->SetObject(obj, kFALSE);
02385 }
02386 return res;
02387 }
02388
02389 TGo4FitSlotStatus* TGo4FitPanelSlots::FindSlotStatusForSlot(TGo4FitSlot* slot) {
02390 if ((slot==0) || (fxSlotStatusList==0)) return 0;
02391 for(Int_t n=0;n<=fxSlotStatusList->GetLast();n++) {
02392 TGo4FitSlotStatus* sstatus = dynamic_cast<TGo4FitSlotStatus*> (fxSlotStatusList->At(n));
02393 if (sstatus && (sstatus->Slot()==slot)) return sstatus;
02394 }
02395 return 0;
02396 }
02397
02398 TGo4FitSlotStatus* TGo4FitPanelSlots::FindSlotStatusForData(TGo4FitData* data, bool withpad) {
02399 if ((data==0) || (fxSlotStatusList==0)) return 0;
02400 for(Int_t n=0;n<=fxSlotStatusList->GetLast();n++) {
02401 TGo4FitSlotStatus* sstatus = dynamic_cast<TGo4FitSlotStatus*> (fxSlotStatusList->At(n));
02402 if ((sstatus==0) || (sstatus->Slot()==0)) continue;
02403 if (sstatus->Slot()->GetOwner()==data)
02404 if (!withpad || (sstatus->Source()==TGo4FitSlotStatus::fss_pad)) return sstatus;
02405 }
02406 return 0;
02407 }
02408
02409 TPad* TGo4FitPanelSlots::FindPadWhereData(TGo4FitData* data) {
02410 TGo4FitSlotStatus* sstatus = FindSlotStatusForData(data, TRUE);
02411 if (sstatus) return sstatus->SourcePad();
02412 else return 0;
02413 }
02414
02415 TGo4FitSlotStatus* TGo4FitPanelSlots::FindSlotStatusForDraw(TGo4FitData* data, bool withpad) {
02416 if ((data==0) || (fxSlotStatusList==0)) return 0;
02417 for(Int_t n=0;n<=fxSlotStatusList->GetLast();n++) {
02418 TGo4FitSlotStatus* sstatus = dynamic_cast<TGo4FitSlotStatus*> (fxSlotStatusList->At(n));
02419 if (sstatus==0) continue;
02420 TGo4FitSlot* slot = sstatus->Slot();
02421 if (slot==0) continue;
02422 if (slot->GetOwner()!=data) continue;
02423
02424 if (withpad && (sstatus->Source()!=TGo4FitSlotStatus::fss_pad)) continue;
02425
02426 if ( (slot->GetClass()->InheritsFrom(TH1::Class())) ||
02427 (slot->GetClass()->InheritsFrom(TGraph::Class())) ) return sstatus;
02428 }
02429 return 0;
02430 }
02431
02432
02433 void TGo4FitPanelSlots::RemovePanelFromSlotsStatusList(TGo4PreviewPanel* Panel) {
02434 for(Int_t n=0;n<=fxSlotStatusList->GetLast();n++) {
02435 TGo4FitSlotStatus* sstatus = dynamic_cast<TGo4FitSlotStatus*> (fxSlotStatusList->At(n));
02436 if ((sstatus==0) || (sstatus->Slot()==0)) continue;
02437 if ((sstatus->Source()!=TGo4FitSlotStatus::fss_pad) ||
02438 (sstatus->SourcePanel()!=Panel) ) continue;
02439
02440 sstatus->ClearPrimitives();
02441 sstatus->ClearDrawObjs();
02442
02443 sstatus->SetSourceNone();
02444 sstatus->Slot()->SetObject(0, kFALSE);
02445 }
02446 }
02447
02448 void TGo4FitPanelSlots::RemoveAllDrawObjects(bool update) {
02449 for(Int_t n=0;n<=fxSlotStatusList->GetLast();n++) {
02450 TGo4FitSlotStatus* sstatus = dynamic_cast<TGo4FitSlotStatus*> (fxSlotStatusList->At(n));
02451 if ((sstatus==0) || (sstatus->Slot()==0)) continue;
02452 sstatus->ClearDrawObjs();
02453 if (update) sstatus->UpdatePad();
02454 }
02455 }
02456
02457 void TGo4FitPanelSlots::SetFitter(TGo4Fitter* fitter) {
02458 if (fitter && (FitOptions()==0)) GetPadFitOptions(ActiveViewPanel(), ActivePad(), TRUE);
02459 ClearSlotsStatusList();
02460 if (FitOptions()) FitOptions()->SetFitter(fitter);
02461 else if (fitter) delete fitter;
02462 UpdateSlotsStatusList();
02463 fxStatus->ParsWidgetShown() = kFALSE;
02464 }
02465
02466 TGo4FitData* TGo4FitPanelSlots::CreateDataFor(TGo4Fitter* fitter, TObject* obj, bool ownership, bool setobj) {
02467 if ((fitter==0) || (obj==0)) return 0;
02468
02469 TGo4FitData* data = 0;
02470 if (obj->InheritsFrom(TH1::Class()))
02471 data = new TGo4FitDataHistogram(fitter->FindNextName("Data",0,kFALSE));
02472 else
02473 if (obj->InheritsFrom(TGraph::Class()))
02474 data = new TGo4FitDataGraph(fitter->FindNextName("Data",0,kFALSE));
02475
02476 if (data!=0) {
02477 fitter->AddData(data);
02478 if (setobj) data->SetObject(obj, ownership);
02479 }
02480
02481 return data;
02482 }
02483
02484 void TGo4FitPanelSlots::CreateAppropriateData(TGo4Fitter* fitter) {
02485 if (fitter==0) return;
02486
02487 TObjArray lst;
02488 FillPadsList(lst, ActivePad());
02489
02490 for (Int_t n=0;n<=lst.GetLast();n++) {
02491 TPad* pad = dynamic_cast<TPad*> (lst[n]);
02492 TObject* obj = GetPadObject(ActiveViewPanel(), pad);
02493
02494 CreateDataFor(fitter, obj);
02495 }
02496 }
02497
02498 TGo4Fitter* TGo4FitPanelSlots::CreateAppropriateFitter(const char* name) {
02499 TGo4Fitter* fitter = new TGo4Fitter(name,"Fitter object");
02500
02501 CreateAppropriateData(fitter);
02502
02503 fitter->AddStandardActions();
02504
02505 fitter->SetMemoryUsage(3);
02506
02507 fitter->SetFitFunctionType(TGo4Fitter::ff_chi_square);
02508
02509 return fitter;
02510 }
02511
02512 void TGo4FitPanelSlots::RemoveWidgetFromListStack() {
02513 fxCurrentItem = 0;
02514 QWidget* w = fxPanel->ListStack->widget(ListStackId);
02515 if (w) {
02516 fxPanel->ListStack->removeWidget(w);
02517 delete w;
02518 }
02519 }
02520
02521 void TGo4FitPanelSlots::CloseDrawPanel() {
02522 if (fxDrawPanel) { fxDrawPanel->close(); fxDrawPanel = 0; }
02523 }
02524
02525 void TGo4FitPanelSlots::UpdateSimplePage() {
02526 RemovePrimitives();
02527
02528 PaintFitter(GetFitter(), 0, TRUE);
02529
02530 fxPanel->UpdateStatusBar(0);
02531 }
02532
02533 void TGo4FitPanelSlots::UpdateWizardPage()
02534 {
02535 RemovePrimitives();
02536
02537 TGo4Fitter* fitter = GetFitter();
02538 fxPanel->SetFillingWidget(TRUE);
02539 if (fitter) fxPanel->Wiz_FitNameEdt->setText(QString(fitter->GetName()));
02540 else fxPanel->Wiz_FitNameEdt->setText(QString(""));
02541 fxPanel->SetFillingWidget(FALSE);
02542
02543 fxPanel->UpdateWizDataList();
02544
02545 fxPanel->UpdateWizModelsList(FALSE);
02546
02547 fxPanel->UpdateWizStackWidget();
02548
02549 fxPanel->UpdateWizPaint(-1);
02550
02551 fxPanel->UpdateStatusBar(0);
02552 }
02553
02554 void TGo4FitPanelSlots::UpdateExtendedPage() {
02555 RemoveWidgetFromListStack();
02556
02557 RemovePrimitives();
02558
02559 fxPanel->FitList->clear();
02560 fxPanel->FitList->setSorting(-1);
02561 TGo4Fitter* fitter = GetFitter();
02562 if (fitter==0) {
02563 new QFitItem(this, fxPanel->FitList, 0, ot_empty, wt_none, mt_empty);
02564 } else {
02565 QFitItem* fitteritem = new QFitItem(this, fxPanel->FitList, fitter, ot_fitter, wt_fitter, mt_fitter, gt_fitter);
02566 fitteritem->setOpen(TRUE);
02567 fxPanel->FitList->setSelected(fitteritem, kTRUE);
02568 ShowItem(fitteritem);
02569 }
02570
02571 fxPanel->UpdateItemMenu();
02572
02573 fxPanel->UpdateStatusBar(0);
02574 }
02575
02576 bool TGo4FitPanelSlots::ShowItem(QFitItem* item, bool force) {
02577
02578 TGo4LockGuard Lock;
02579
02580 if (force) RemoveWidgetFromListStack();
02581
02582 bool gr = FALSE;
02583
02584 RemovePrimitives();
02585 if (fxStatus->ShowPrimitives())
02586 gr = ShowItemAsGraph(item, force);
02587
02588 bool txt = ShowItemAsText(item, force);
02589
02590 if (gr) UpdateAllPads();
02591
02592 return (gr || txt);
02593 }
02594
02595 bool TGo4FitPanelSlots::ShowItemAsText(QFitItem* item, bool force) {
02596
02597 QFitItem* widgetitem = item->DefineWidgetItem();
02598
02599 QFitWidget* oldwidget = dynamic_cast<QFitWidget*> (fxPanel->ListStack->widget(ListStackId));
02600 if ((oldwidget!=0) && (oldwidget->GetItem()==widgetitem)) {
02601 oldwidget->FillWidget();
02602 return TRUE;
02603 }
02604
02605 RemoveWidgetFromListStack();
02606
02607 QFitWidget* widget = 0;
02608
02609 if (widgetitem==0) return TRUE;
02610
02611 QWidget* owner = 0;
02612
02613 switch(widgetitem->WidgetType()) {
02614 case wt_par: widget = new QFitParWidget(owner,"Parameter"); break;
02615 case wt_range : widget = new QFitRangeWidget(owner,"Range"); break;
02616 case wt_rangecut : widget = new QFitRangeCutWidget(owner,"Range cut"); break;
02617 case wt_data : widget = new QFitDataWidget(owner,"Data object"); break;
02618 case wt_model : widget = new QFitModelWidget(owner,"Model"); break;
02619 case wt_polynom : widget = new QFitModelPolynomWidget(owner,"Polynom"); break;
02620 case wt_gauss1: widget = new QFitModelGauss1Widget(owner,"Gauss1"); break;
02621 case wt_gauss2: widget = new QFitModelGauss2Widget(owner,"Gauss2"); break;
02622 case wt_gaussn: widget = new QFitModelGaussNWidget(owner,"GaussN"); break;
02623 case wt_formula: widget = new QFitModelFormulaWidget(owner,"Formula"); break;
02624 case wt_function: widget = new QFitModelFunctionWidget(owner,"Function"); break;
02625 case wt_amplest: widget = new QFitAmplEstimWidget(owner,"Amplitude estimation"); break;
02626 case wt_peakfinder: widget = new QFitPeakFinderWidget(owner,"Peak finder"); break;
02627 case wt_output: widget = new QFitOutputActionWidget(owner,"Fitter output"); break;
02628 case wt_minuit: widget = new QFitMinuitWidget(owner,"Minuit"); break;
02629 case wt_minuitres: widget = new QFitMinuitResWidget(owner,"Minuit result"); break;
02630 case wt_depend: widget = new QFitDependencyWidget(owner,"Dependency"); break;
02631 case wt_parcfg: widget = new QFitParCfgWidget(owner,"Parameter configuration"); break;
02632 case wt_slot: widget = new QFitSlotWidget(owner,"Slot for external object"); break;
02633 case wt_fitter: widget = new QFitterWidget(owner,"Fitter"); break;
02634 case wt_named: widget = new QFitNamedWidget(owner,"Named object"); break;
02635 case wt_table: widget = new QFitTableWidget(owner,"Table"); break;
02636 case wt_lintrans: widget = new QFitLinearTransWidget(owner,"Simple transform"); break;
02637 case wt_matrtrans: widget = new QFitMatrixTransWidget(owner,"Matrix transform"); break;
02638 }
02639
02640 if (widget!=0) {
02641 widget->SetItem(widgetitem);
02642 fxPanel->ListStack->addWidget(widget, ListStackId);
02643 fxPanel->ListStack->raiseWidget(widget);
02644 }
02645
02646 return TRUE;
02647 }
02648
02649 bool TGo4FitPanelSlots::ShowItemAsGraph(QFitItem* item, bool force) {
02650 if (item==0) return FALSE;
02651
02652 QFitItem* gritem = item->DefineGraphItem();
02653
02654 if (gritem==0) return FALSE;
02655
02656 TGo4Fitter* fitter = GetFitter();
02657 if (fitter==0) return FALSE;
02658
02659 if (gritem->GraphType()==gt_fitter) {
02660 PaintFitter(fitter, gritem, FALSE);
02661 return TRUE;
02662 }
02663
02664
02665 if (gritem->GraphType()==gt_data) {
02666 TGo4FitData* data = dynamic_cast<TGo4FitData*> (gritem->Object());
02667
02668 if (data)
02669 PaintModelsFor(fitter, data, gritem->Parent()->Parent());
02670
02671 return (data!=0);
02672 }
02673
02674 if (gritem->GraphType()==gt_model) {
02675 TGo4FitModel* model = dynamic_cast<TGo4FitModel*> (gritem->Object());
02676 if (model==0) return FALSE;
02677 bool draw = FALSE;
02678 for(Int_t n=0;n<model->NumAssigments();n++) {
02679 TGo4FitData* data = fitter->FindData(model->AssignmentName(n));
02680 TGo4FitSlotStatus* sstatus = FindSlotStatusForData(data, TRUE);
02681 if (sstatus) {
02682 PaintModel(model, sstatus, gritem);
02683 draw = TRUE;
02684 }
02685 }
02686 return draw;
02687 }
02688
02689 if (gritem->GraphType()==gt_ass) {
02690 TGo4FitModel* model = dynamic_cast<TGo4FitModel*> (gritem->Parent()->Parent()->Object());
02691 if (model) {
02692 TGo4FitData* data = fitter->FindData(gritem->text(0).ascii());
02693 TGo4FitSlotStatus* sstatus = FindSlotStatusForData(data, TRUE);
02694 if (sstatus) {
02695 PaintModel(model, sstatus, gritem->Parent()->Parent());
02696 return TRUE;
02697 }
02698 }
02699 }
02700
02701 if (gritem->GraphType()==gt_range) {
02702 TGo4FitComponent* comp = dynamic_cast<TGo4FitComponent*> (gritem->Parent()->Object());
02703 if (comp==0) return FALSE;
02704 int nrange = gritem->Tag();
02705
02706 TGo4FitSlotStatus* sstatus = 0;
02707 if (comp->InheritsFrom(TGo4FitData::Class()))
02708 sstatus = FindSlotStatusForData(dynamic_cast<TGo4FitData*> (comp), TRUE);
02709 else sstatus = FindSlotStatusForModel(fitter, dynamic_cast<TGo4FitModel*> (comp));
02710
02711 if (sstatus) {
02712 PaintRange(comp, nrange, sstatus, gritem);
02713 return TRUE;
02714 }
02715 }
02716
02717 if (gritem->GraphType()==gt_ranges) {
02718 TGo4FitComponent* comp = dynamic_cast<TGo4FitComponent*> (gritem->Object());
02719 if (comp==0) return FALSE;
02720
02721 TGo4FitSlotStatus* sstatus = 0;
02722 if (comp->InheritsFrom(TGo4FitData::Class()))
02723 sstatus = FindSlotStatusForData(dynamic_cast<TGo4FitData*> (comp), TRUE);
02724 else sstatus = FindSlotStatusForModel(fitter, dynamic_cast<TGo4FitModel*> (comp));
02725
02726 if (sstatus) {
02727 QListViewItem* child = gritem->firstChild();
02728 for(int nrange=0;nrange<comp->GetNumRangeCondition();nrange++) {
02729 PaintRange(comp, nrange, sstatus, (QFitItem*)child);
02730 child = child->nextSibling();
02731 }
02732 return TRUE;
02733 }
02734 }
02735
02736 return FALSE;
02737 }
02738
02739 TGo4FitSlotStatus* TGo4FitPanelSlots::FindSlotStatusForModel(TGo4Fitter* fitter, TGo4FitModel* model) {
02740 if ((fitter==0) || (model==0)) return 0;
02741
02742 for(Int_t n=0;n<model->NumAssigments();n++) {
02743 TGo4FitData* data = fitter->FindData(model->AssignmentName(n));
02744 TGo4FitSlotStatus* sstatus = FindSlotStatusForData(data, TRUE);
02745 if (sstatus) return sstatus;
02746 }
02747 return 0;
02748 }
02749
02750 void TGo4FitPanelSlots::PaintFitter(TGo4Fitter* fitter, QFitItem* item, bool update) {
02751 if (fitter)
02752 for(Int_t nd=0;nd<fitter->GetNumData();nd++)
02753 PaintModelsFor(fitter, fitter->GetData(nd), item, update);
02754 }
02755
02756 void TGo4FitPanelSlots::PaintModel(TGo4FitModel* model, TGo4FitSlotStatus* sstatus, QFitItem* item) {
02757 if ((model==0) || (sstatus==0) || !fxStatus->ShowPrimitives()) return;
02758 if ((sstatus->SourcePanel()==0) || (sstatus->SourcePad()==0)) return;
02759
02760 TH1* histo = sstatus->SourcePanel()->GetPadHistogram(sstatus->SourcePad());
02761
02762 if ((histo==0) || (histo->GetDimension()!=1)) return;
02763
02764 TPad* pad = sstatus->SourcePad();
02765
02766 pad->cd();
02767
02768 Double_t pos ,width, ampl;
02769
02770 if (model->GetPosition(0,pos)) {
02771
02772 Int_t nbin = histo->GetXaxis()->FindBin(pos);
02773 ampl = histo->GetBinContent(nbin);
02774 Double_t limit = pad->GetUymin()*.7 + pad->GetUymax()*.3;
02775 if (ampl<limit) ampl = limit;
02776
02777 TGo4FitGUIArrow* arr = new TGo4FitGUIArrow(0.01,">");
02778 arr->SetLineColor(2);
02779 arr->SetLineWidth(1);
02780 arr->SetItem(item, this);
02781 sstatus->AddPrimitive(arr);
02782
02783 TGo4FitGUIArrow* warr = 0;
02784 if (model->GetWidth(0,width)) {
02785 warr = new TGo4FitGUIArrow(0.01,"<|>");
02786 warr->SetLineColor(2);
02787 warr->SetLineWidth(1);
02788 warr->SetForWidth(model, arr);
02789 warr->SetItem(item, this);
02790 sstatus->AddPrimitive(warr);
02791 }
02792
02793 arr->SetForPosition(model, warr, ampl);
02794
02795 arr->Locate(); arr->Draw();
02796
02797 if (warr) { warr->Locate(); warr->Draw(); }
02798 }
02799
02800 sstatus->SourcePad()->Modified();
02801 }
02802
02803 TGo4FitSlotStatus* TGo4FitPanelSlots::PaintModelsFor(TGo4Fitter* fitter, TGo4FitData* data, QFitItem* item, bool update)
02804 {
02805 if ((fitter==0) || (data==0)) return 0;
02806
02807 TGo4FitSlotStatus* sstatus = FindSlotStatusForData(data, TRUE);
02808 if (sstatus==0) return 0;
02809
02810 if (data->IsAnyDataTransform()) return 0;
02811
02812 for (Int_t nm=0;nm<fitter->GetNumModel();nm++) {
02813 TGo4FitModel* model = fitter->GetModel(nm);
02814 if (model->IsAssignTo(data->GetName())) PaintModel(model, sstatus, item);
02815 }
02816
02817 if (update && sstatus->SourcePad()) sstatus->UpdatePad();
02818
02819 return sstatus;
02820 }
02821
02822 void TGo4FitPanelSlots::PaintRange(TGo4FitComponent* comp, int nrange, TGo4FitSlotStatus* sstatus, QFitItem* item) {
02823 if ((comp==0) || (sstatus==0) || !fxStatus->ShowPrimitives()) return;
02824
02825 if ((sstatus->SourcePanel()==0) || (sstatus->SourcePad()==0)) return;
02826
02827 TH1* histo = sstatus->SourcePanel()->GetPadHistogram(sstatus->SourcePad());
02828 if ((histo==0) || (histo->GetDimension()!=1)) return;
02829
02830 double range = 0.1 * (histo->GetXaxis()->GetXmax() - histo->GetXaxis()->GetXmin());
02831
02832 double ampl = (0.07 + nrange*0.02) * (histo->GetMaximum() - histo->GetMinimum()) + histo->GetMinimum();
02833
02834 double size = 0.015;
02835
02836 sstatus->SourcePad()->cd();
02837
02838 Int_t typ, naxis;
02839 Double_t left, right;
02840
02841 comp->GetRangeCondition(nrange, typ, naxis, left, right);
02842
02843 if (naxis!=0) return;
02844
02845 TGo4FitGUIArrow* arr = 0;
02846
02847 switch (typ) {
02848 case 0: arr = new TGo4FitGUIArrow(size,"<|>"); break;
02849 case 1: arr = new TGo4FitGUIArrow(size,"-><-"); break;
02850 case 2: arr = new TGo4FitGUIArrow(size,"<"); break;
02851 case 3: arr = new TGo4FitGUIArrow(size,">"); break;
02852 }
02853
02854 if (arr!=0) {
02855 arr->SetLineColor(3);
02856 arr->SetLineWidth(3);
02857 arr->SetForRange(comp,nrange,ampl,range);
02858 arr->SetItem(item, this);
02859 arr->Locate();
02860 arr->Draw();
02861 sstatus->AddPrimitive(arr);
02862 sstatus->SourcePad()->Modified();
02863 }
02864 }
02865
02866 void TGo4FitPanelSlots::AddModelToPad(TGo4FitSlotStatus* sstatus, TObject* model) {
02867 if ((sstatus==0) || (model==0)) return;
02868 }
02869
02870 QFitItem* TGo4FitPanelSlots::GetFitterItem() {
02871 QFitItem* item = dynamic_cast<QFitItem*> (fxPanel->FitList->firstChild());
02872 if (item && (item->ObjectType()==ot_fitter)) return item;
02873 return 0;
02874 }
02875
02876 QFitItem* TGo4FitPanelSlots::FindItem(TObject* obj, int ObjectType, QFitItem* parent) {
02877 if (parent==0) parent = GetFitterItem();
02878 QListViewItemIterator iter(parent);
02879 while (iter.current()!=0) {
02880 QFitItem* item = dynamic_cast<QFitItem*> (iter.current());
02881 if (item!=0)
02882 if ((obj==0) || (item->Object()==obj))
02883 if ((ObjectType==ot_none) || (ObjectType==item->ObjectType())) return item;
02884 ++iter;
02885 }
02886 return 0;
02887 }
02888
02889 int TGo4FitPanelSlots::DefineModelWidgetType(TObject* obj) {
02890 if (obj==0) return wt_none;
02891 if (obj->InheritsFrom(TGo4FitModelPolynom::Class())) return wt_polynom;
02892 if (obj->InheritsFrom(TGo4FitModelGauss1::Class())) return wt_gauss1;
02893 if (obj->InheritsFrom(TGo4FitModelGauss2::Class())) return wt_gauss2;
02894 if (obj->InheritsFrom(TGo4FitModelGaussN::Class())) return wt_gaussn;
02895 if (obj->InheritsFrom(TGo4FitModelFormula::Class())) return wt_formula;
02896 if (obj->InheritsFrom(TGo4FitModelFunction::Class())) return wt_function;
02897 if (obj->InheritsFrom(TGo4FitModel::Class())) return wt_model;
02898 return wt_none;
02899 }
02900
02901 void TGo4FitPanelSlots::FillParsList(QFitItem* item) {
02902 if (item==0) return;
02903 TGo4FitParsList* pars = dynamic_cast<TGo4FitParsList*> (item->Object());
02904 if (pars==0) return;
02905 for (Int_t n = pars->NumPars()-1; n>=0;n--)
02906 new QFitItem(this, item, pars->GetPar(n), ot_par, wt_par, mt_par);
02907 }
02908
02909 void TGo4FitPanelSlots::FillSlotsList(QFitItem* parent, const TObjArray* lst, TObject* owner) {
02910 if ((parent==0) || (lst==0)) return;
02911 for(Int_t n = lst->GetLast();n>=0;n--) {
02912 TGo4FitSlot* slot = dynamic_cast<TGo4FitSlot*> (lst->At(n));
02913 if (slot && ((slot->GetOwner()==owner) || (owner==0)))
02914 new QFitItem(this, parent, slot, ot_slot, wt_slot, mt_slot);
02915 }
02916 }
02917
02918 void TGo4FitPanelSlots::FillDependencyList(QFitItem* parent) {
02919 if (parent==0) return;
02920
02921 TObjArray* lst = dynamic_cast<TObjArray*> (parent->Object());
02922 if (lst)
02923 for(Int_t n=lst->GetLast();n>=0;n--)
02924 new QFitItem(this, parent, lst->At(n), ot_depend, wt_depend, mt_depend, gt_none, n);
02925 }
02926
02927 void TGo4FitPanelSlots::FillModelTypesList(QPopupMenu* menu, int id, bool extend) {
02928 if (menu->count()>0) menu->insertSeparator();
02929 if (extend) {
02930 menu->insertItem(QString("Add gaussian"), id+20);
02931 menu->insertItem(QString("Add lorenzian"), id+24);
02932 menu->insertItem(QString("Add exponent"), id+25);
02933 menu->insertItem(QString("Add 1-order polynom"), id+21);
02934 menu->insertItem(QString("Add 3-order polynom"), id+22);
02935 menu->insertItem(QString("Add 7-order polynom"), id+23);
02936 menu->insertSeparator();
02937 }
02938
02939 menu->insertItem(QString("Make ") + TGo4FitModelPolynom::Class()->GetName(), id+0);
02940 menu->insertItem(QString("Make ") + TGo4FitModelGauss1::Class()->GetName(), id+1);
02941 menu->insertItem(QString("Make ") + TGo4FitModelGauss2::Class()->GetName(), id+2);
02942 menu->insertItem(QString("Make ") + TGo4FitModelGaussN::Class()->GetName(), id+3);
02943 menu->insertItem(QString("Make ") + TGo4FitModelFormula::Class()->GetName(), id+4);
02944 menu->insertItem(QString("Make ") + TGo4FitModelFunction::Class()->GetName(),id+5);
02945 menu->insertItem(QString("Make ") + TGo4FitModelFromData::Class()->GetName(),id+6);
02946 }
02947
02948 void TGo4FitPanelSlots::FillDataTypesList(QPopupMenu* menu, int id) {
02949 if (menu->count()>0) menu->insertSeparator();
02950 menu->insertItem(QString("Make ") + TGo4FitDataHistogram::Class()->GetName(), id+0);
02951 menu->insertItem(QString("Make ") + TGo4FitDataGraph::Class()->GetName(), id+1);
02952 menu->insertItem(QString("Make ") + TGo4FitDataProfile::Class()->GetName(), id+2);
02953 menu->insertItem(QString("Make ") + TGo4FitDataRidge::Class()->GetName(), id+3);
02954 }
02955
02956 void TGo4FitPanelSlots::Cmd_CreateFitter() {
02957 TGo4Fitter* fitter = new TGo4Fitter("Fitter","Fitter object");
02958 SetFitter(fitter);
02959
02960 UpdateActivePage();
02961 }
02962
02963 void TGo4FitPanelSlots::Cmd_CreateAppropriateFitter() {
02964 TGo4Fitter* fitter = CreateAppropriateFitter("Fitter");
02965 if (fitter) {
02966 SetFitter(fitter);
02967 UpdateActivePage();
02968 }
02969 }
02970
02971 void TGo4FitPanelSlots::Cmd_DeleteFitter() {
02972 if(fxStatus->NeedConfirmation())
02973 if ( QMessageBox::information(0,
02974 QString("Clear fitter"),
02975 QString("Are you sure?"),
02976 QMessageBox::Yes, QMessageBox::No) == QMessageBox::No ) return;
02977
02978 RemovePrimitives();
02979
02980 SetFitter(0);
02981
02982 if (WorkingWithPanel())
02983 DeletePadFitOptions(ActiveViewPanel(), ActivePad());
02984
02985 UpdateActivePage();
02986 }
02987
02988 void TGo4FitPanelSlots::Cmd_ClearFitter() {
02989 TGo4Fitter* fitter = GetFitter();
02990 if (fitter==0) return;
02991
02992 if(fxStatus->NeedConfirmation())
02993 if ( QMessageBox::information(0,
02994 QString("Clear fitter"),
02995 QString("Are you sure?"),
02996 QMessageBox::Yes, QMessageBox::No) == QMessageBox::No ) return;
02997
02998 fitter->Clear();
02999
03000 UpdateActivePage();
03001 }
03002
03003 void TGo4FitPanelSlots::Cmd_SaveFitter(bool ask) {
03004 TGo4Fitter* fitter = GetFitter();
03005 if (fitter==0) return;
03006
03007 QString fname(fitter->GetName());
03008 fname+=".root";
03009
03010 if(ask) {
03011 fname = QFileDialog::getSaveFileName(fname,
03012 QString("Root file (*.root)"),
03013 0,
03014 QString("save fitter dialog"),
03015 QString("Set file name to save fitter"));
03016 if (fname==QString::null) return;
03017 }
03018
03019 fitter->SetSaveFlagForObjects(fxStatus->SaveWithReferences());
03020
03021 TFile f(fname,"recreate");
03022 fitter->Write();
03023 }
03024
03025 void TGo4FitPanelSlots::Cmd_ItemPrint(QFitItem* item) {
03026 TObject* obj = item->Object();
03027 if (obj==0) return;
03028
03029 QString str("*");
03030 bool ok = TRUE;
03031 if (obj->InheritsFrom(TGo4Fitter::Class()))
03032 str = QInputDialog::getText(QString("Go4 Fit Panel"),
03033 QString("Enter parameters for Print() command"),
03034 QLineEdit::Normal, str, &ok, 0);
03035 if (!ok) return;
03036
03037 RemoveWidgetFromListStack();
03038 QFitPrintWidget* widget = new QFitPrintWidget(0, QString("Print ")+obj->GetName());
03039
03040 fxPanel->ListStack->addWidget(widget, ListStackId);
03041
03042 widget->SetDrawOption(str);
03043 widget->SetItem(item);
03044 fxPanel->ListStack->raiseWidget(widget);
03045 }
03046
03047 void TGo4FitPanelSlots::Cmd_DrawData(QFitItem * item) {
03048 TGo4FitData* data = dynamic_cast<TGo4FitData*> (item->Object());
03049 if (data) Button_FitterDraw(data);
03050 }
03051
03052 void TGo4FitPanelSlots::Cmd_DeleteData(QFitItem * item) {
03053 TGo4FitData* data = dynamic_cast<TGo4FitData*> (item->Object());
03054 TGo4Fitter* fitter = GetFitter();
03055
03056 if ((data==0) || (fitter==0)) return;
03057
03058 if(fxStatus->NeedConfirmation())
03059 if ( QMessageBox::information(0,
03060 QString("Delete data"),
03061 QString("Are you sure to delete ") + data->GetName(),
03062 QMessageBox::Yes, QMessageBox::No) == QMessageBox::No ) return;
03063
03064 fitter->RemoveData(data->GetName(),kTRUE);
03065
03066 UpdateSlotsStatusList();
03067
03068 UpdateItemsOfType(ot_allslots);
03069
03070 UpdateItem(item->Parent(), TRUE);
03071
03072 fxPanel->UpdateStatusBar(0);
03073 }
03074
03075 void TGo4FitPanelSlots::Cmd_DeleteAllData(QFitItem * item) {
03076 TGo4Fitter* fitter = GetFitter();
03077 if (fitter==0) return;
03078
03079 if(fxStatus->NeedConfirmation())
03080 if ( QMessageBox::information(0,
03081 QString("Delete all data"),
03082 QString("Are you sure to delete all data objects"),
03083 QMessageBox::Yes, QMessageBox::No) == QMessageBox::No ) return;
03084
03085 fitter->DeleteAllData();
03086
03087 UpdateSlotsStatusList();
03088
03089 UpdateItemsOfType(ot_allslots);
03090
03091 UpdateItem(item, TRUE);
03092
03093 fxPanel->UpdateStatusBar(0);
03094 }
03095
03096
03097 void TGo4FitPanelSlots::Cmd_DeleteAssosiatedModels(QFitItem * item) {
03098 if ((item==0) || (item->Parent()==0)) return;
03099 TGo4FitData* data = dynamic_cast<TGo4FitData*> (item->Object());
03100 TGo4Fitter* fitter = GetFitter();
03101
03102 if ((data==0) || (fitter==0)) return;
03103
03104 if(fxStatus->NeedConfirmation())
03105 if ( QMessageBox::information(0,
03106 QString("Delete models"),
03107 QString("Are you sure to delete models, assosiated to ") + data->GetName(),
03108 QMessageBox::Yes, QMessageBox::No) == QMessageBox::No ) return;
03109
03110 fitter->DeleteModelsAssosiatedTo(data->GetName());
03111
03112 QFitItem* mlist = FindItem(0, ot_modellist);
03113 if (mlist) UpdateItem(mlist, TRUE);
03114
03115 UpdateItemsOfType(ot_allslots);
03116
03117 ShowItem(item);
03118
03119 fxPanel->UpdateStatusBar(0);
03120 }
03121
03122 void TGo4FitPanelSlots::Cmd_DeleteModel(QFitItem * item) {
03123 TGo4FitModel* model = dynamic_cast<TGo4FitModel*> (item->Object());
03124
03125 if (Cmd_RemoveModel(model)) {
03126 RemovePrimitives(model);
03127 UpdateItemsOfType(ot_allslots);
03128 UpdateItem(item->Parent(), TRUE);
03129 fxPanel->UpdateStatusBar(0);
03130 }
03131 }
03132
03133 bool TGo4FitPanelSlots::Cmd_RemoveModel(TGo4FitModel* model) {
03134 TGo4Fitter* fitter = GetFitter();
03135 if ((model==0) || (fitter==0)) return FALSE;
03136
03137 if(fxStatus->NeedConfirmation())
03138 if ( QMessageBox::information(0,
03139 QString("Delete model"),
03140 QString("Are you sure to delete ") + model->GetName(),
03141 QMessageBox::Yes, QMessageBox::No) == QMessageBox::No ) return FALSE;
03142
03143 fitter->RemoveModel(model->GetName(), kTRUE);
03144
03145 UpdateSlotsStatusList();
03146
03147 return TRUE;
03148 }
03149
03150 void TGo4FitPanelSlots::Cmd_DeleteModels(QFitItem * item) {
03151 TGo4Fitter* fitter = GetFitter();
03152 if (fitter==0) return;
03153
03154 if(fxStatus->NeedConfirmation())
03155 if ( QMessageBox::information(0,
03156 QString("Delete all models"),
03157 QString("Are you sure to delete all models objects"),
03158 QMessageBox::Yes, QMessageBox::No) == QMessageBox::No ) return;
03159
03160 fitter->DeleteAllModels();
03161
03162 UpdateSlotsStatusList();
03163
03164 UpdateItem(item, TRUE);
03165 UpdateItemsOfType(ot_allslots);
03166 fxPanel->UpdateStatusBar(0);
03167 }
03168
03169 void TGo4FitPanelSlots::GetCombinationName(TGo4PreviewPanel* panel, TPad* pad, QString* info) {
03170 if (info==0) return;
03171 (*info) = "Panel: ";
03172 if (panel) (*info) += panel->name();
03173 (*info) += " Pad: ";
03174 if (pad) (*info) += pad->GetName();
03175
03176 }
03177
03178 TGo4FitData* TGo4FitPanelSlots::CreateData(Int_t id, const char* name) {
03179 TString dataname;
03180
03181 if (name==0) {
03182 TGo4Fitter* fitter = GetFitter();
03183 if (fitter==0) return 0;
03184 dataname = fitter->FindNextName("Data", 0, kFALSE);
03185 } else dataname = name;
03186
03187 switch(id) {
03188 case 0: return new TGo4FitDataHistogram(dataname);
03189 case 1: return new TGo4FitDataGraph(dataname);
03190 case 2: return new TGo4FitDataProfile(dataname);
03191 case 3: return new TGo4FitDataRidge(dataname);
03192 }
03193 return 0;
03194 }
03195
03196 TGo4FitModel* TGo4FitPanelSlots::CreateModel(Int_t id, const char* namebase, TGo4Fitter* fitter, TGo4FitData* data) {
03197 TString NameBase;
03198
03199 if (fitter)
03200 if ((data==0) && (fitter->GetNumData()>0)) data = fitter->GetData(0);
03201 Int_t NumDim = 0;
03202 if (data) NumDim = data->DefineDimensions();
03203 if (NumDim<=0) NumDim = 1;
03204
03205 Int_t order = 0;
03206 switch(id) {
03207 case 20:
03208 switch (NumDim) {
03209 case 1: id = 1; break;
03210 case 2: id = 2; break;
03211 default: id = 3; break;
03212 }
03213 break;
03214 case 21: order = 1; id = 7; break;
03215 case 22: order = 3; id = 7; break;
03216 case 23: order = 7; id = 7; break;
03217 }
03218
03219 if (namebase) NameBase = namebase; else
03220 switch(id) {
03221 case 0: NameBase = "Pol"; break;
03222 case 1:
03223 case 2:
03224 case 3: NameBase = "Gauss"; break;
03225 case 4: NameBase = "Form"; break;
03226 case 5: NameBase = "Func"; break;
03227 case 6: NameBase = "FromData"; break;
03228 case 7: NameBase = "Pol"; break;
03229 case 24: NameBase = "Lor"; break;
03230 case 25: NameBase = "Exp"; break;
03231 default: NameBase = "Model";
03232 }
03233
03234 TString ModelName;
03235
03236 if (fitter && (id!=7)) ModelName = fitter->FindNextName(NameBase.Data(), 0);
03237 else ModelName = NameBase;
03238
03239 TGo4FitModel* model = 0;
03240
03241 switch(id) {
03242 case 0: model = new TGo4FitModelPolynom(ModelName); break;
03243 case 1: model = new TGo4FitModelGauss1(ModelName); break;
03244 case 2: model = new TGo4FitModelGauss2(ModelName); break;
03245 case 3: model = new TGo4FitModelGaussN(ModelName, NumDim<3 ? 3 : NumDim); break;
03246 case 4: model = new TGo4FitModelFormula(ModelName); break;
03247 case 5: model = new TGo4FitModelFunction(ModelName); break;
03248 case 6: model = new TGo4FitModelFromData(ModelName); break;
03249 case 7: fitter->AddPolynoms(data ? data->GetName() : 0, NameBase.Data(), order, NumDim); break;
03250 case 24: {
03251 TGo4FitModelFormula* formula = new TGo4FitModelFormula(ModelName,"1./(1.+sq((x-Pos)/Width))",2,kTRUE);
03252 formula->SetParsNames("Ampl","Pos","Width");
03253 formula->SetPosParIndex(0, 0);
03254 formula->SetWidthParIndex(0, 1);
03255 model = formula;
03256 break;
03257 }
03258 case 25: {
03259 model = new TGo4FitModelFormula(ModelName,"exp(Koef*x)",1,kTRUE);
03260 model->SetParsNames("Ampl","Koef");
03261 break;
03262 }
03263 }
03264
03265 if (fitter && model) {
03266 if (data) model->AssignToData(data->GetName());
03267 fitter->AddModel(model);
03268 }
03269
03270 return model;
03271 }
03272
03273 void TGo4FitPanelSlots::LocateModel(TGo4FitModel* model, TGo4FitData* data, bool usepad) {
03274 TGo4Fitter* fitter = GetFitter();
03275
03276 if ((fitter==0) || (model==0)) return;
03277
03278 if (data==0)
03279 for(int n=0;n<=model->NumAssigments();n++) {
03280 data = fitter->FindData(model->AssignmentName(n));
03281 if (!usepad || FindPadWhereData(data)) break;
03282 }
03283 if (data==0) return;
03284
03285 if (!usepad && data->DefineDimensions()!=1) usepad = TRUE;
03286
03287 if (usepad) {
03288 TPad* pad = FindPadWhereData(data);
03289 if (pad) {
03290 model->SetPosition(0, (pad->GetUxmin() + pad->GetUxmax())/2.);
03291 model->SetWidth(0, TMath::Abs(pad->GetUxmax() - pad->GetUxmin())*.05);
03292 model->SetPosition(1, (pad->GetUymin() + pad->GetUymax())/2.);
03293 model->SetWidth(1, TMath::Abs(pad->GetUymax() - pad->GetUymin())*.05);
03294 }
03295 } else {
03296 Double_t mid, width;
03297 if (fitter->CalculatesMomentums(data->GetName(), kTRUE, kTRUE, mid, width)) {
03298 model->SetPosition(0, mid);
03299 model->SetWidth(0, width);
03300 }
03301 }
03302 }
03303
03304 void TGo4FitPanelSlots::Cmd_AddNewData(QFitItem * item, Int_t id) {
03305 if (item->ObjectType()!=ot_datalist) item = item->Parent();
03306 if (item->ObjectType()!=ot_datalist) return;
03307
03308 TGo4Fitter* fitter = GetFitter();
03309 if (fitter==0) return;
03310
03311 TGo4FitData* data = CreateData(id, 0);
03312 if (data==0) return;
03313
03314 fitter->AddData(data);
03315
03316 UpdateSlotsStatusList();
03317
03318 UpdateItem(item, TRUE);
03319
03320 UpdateItemsOfType(ot_allslots);
03321
03322 QFitItem* curr = FindItem(data, ot_data, item);
03323 if (curr!=0)
03324 fxPanel->FitList->setSelected(curr, TRUE);
03325 fxPanel->UpdateStatusBar(0);
03326 }
03327
03328 void TGo4FitPanelSlots::Cmd_AddNewModel(QFitItem * item, Int_t id) {
03329 if (item->ObjectType()!=ot_modellist) item = item->Parent();
03330 if (item->ObjectType()!=ot_modellist) return;
03331
03332 TGo4Fitter* fitter = GetFitter();
03333 if (fitter==0) return;
03334
03335 TGo4FitModel* model = CreateModel(id, 0, fitter);
03336 LocateModel(model);
03337
03338 UpdateSlotsStatusList();
03339
03340 UpdateItem(item, TRUE);
03341
03342 UpdateItemsOfType(ot_allslots);
03343
03344 QFitItem* curr = FindItem(model, ot_model, item);
03345 if (curr!=0)
03346 fxPanel->FitList->setSelected(curr, TRUE);
03347 fxPanel->UpdateStatusBar(0);
03348 }
03349
03350 void TGo4FitPanelSlots::Cmd_ClearAssigment(QFitItem* item) {
03351 if (item==0) return;
03352 TGo4FitModel* model = dynamic_cast<TGo4FitModel*> (item->Parent()->Object());
03353 if (model==0) return;
03354
03355 model->ClearAssignmentTo(item->text(0).ascii());
03356
03357 UpdateItemsOfType(ot_parslist, item->Parent()->Parent());
03358
03359 UpdateItem(item->Parent(), TRUE);
03360 }
03361
03362 void TGo4FitPanelSlots::Cmd_ClearAssigments(QFitItem* item) {
03363 TGo4FitModel* model = dynamic_cast<TGo4FitModel*> (item->Object());
03364 if (model==0) return;
03365
03366 model->ClearAssignments();
03367
03368 UpdateItemsOfType(ot_parslist, item->Parent());
03369
03370 UpdateItem(item, TRUE);
03371 }
03372
03373 void TGo4FitPanelSlots::Cmd_AssignModelToAllData(QFitItem* item) {
03374 TGo4FitModel* model = dynamic_cast<TGo4FitModel*> (item->Object());
03375 TGo4Fitter* fitter = GetFitter();
03376 if ((model==0) || (fitter==0)) return;
03377
03378 model->ClearAssignments();
03379 for(Int_t n=0;n<fitter->GetNumData();n++)
03380 model->AssignToData(fitter->GetDataName(n));
03381
03382 UpdateItemsOfType(ot_parslist, item->Parent());
03383
03384 UpdateItem(item, TRUE);
03385 }
03386
03387 void TGo4FitPanelSlots::Cmd_AssignModelToData(QFitItem* item, int id) {
03388 TGo4FitModel* model = dynamic_cast<TGo4FitModel*> (item->Object());
03389 TGo4Fitter* fitter = GetFitter();
03390 if ((model==0) || (fitter==0)) return;
03391
03392 model->AssignToData(fitter->GetDataName(id));
03393
03394 UpdateItemsOfType(ot_parslist, item->Parent());
03395
03396 UpdateItem(item, TRUE);
03397 }
03398
03399 void TGo4FitPanelSlots::Cmd_RemoveRangeCondition(QFitItem* item) {
03400 if (item==0) return;
03401
03402 Int_t typ = item->ObjectType();
03403
03404 if ((typ!=ot_range) && (typ!=ot_rangecut)) return;
03405
03406 int num = item->Tag();
03407
03408 if (num<0) return;
03409
03410 if(fxStatus->NeedConfirmation())
03411 if ( QMessageBox::information(0,
03412 QString("Remove condition"),
03413 QString("Are you sure to delete condition ") + item->text(0),
03414 QMessageBox::Yes, QMessageBox::No) == QMessageBox::No ) return;
03415
03416 QFitItem* parent = item->Parent();
03417 TGo4FitComponent* comp = dynamic_cast<TGo4FitComponent*> (parent->Object());
03418
03419 if (typ==ot_range) comp->RemoveRangeCondition(num);
03420 else comp->RemoveRangeCut(num);
03421
03422 UpdateItem(parent, TRUE);
03423 }
03424
03425 void TGo4FitPanelSlots::Cmd_RemoveRangeConditions(QFitItem* item) {
03426 if ((item==0) || (item->ObjectType()!=ot_rangelist)) return;
03427
03428 if(fxStatus->NeedConfirmation())
03429 if ( QMessageBox::information(0,
03430 QString("Delete conditions"),
03431 QString("Are you sure to delete all conditions"),
03432 QMessageBox::Yes, QMessageBox::No) == QMessageBox::No ) return;
03433
03434 TGo4FitComponent* comp = dynamic_cast<TGo4FitComponent*> (item->Object());
03435 comp->ClearRanges();
03436
03437 UpdateItem(item, TRUE);
03438 }
03439
03440 void TGo4FitPanelSlots::Cmd_AddRangeCondition(QFitItem* item, int id) {
03441 if ((item==0) || (item->ObjectType()!=ot_rangelist)) return;
03442
03443 TGo4FitData* data = 0;
03444
03445 if (item->Object()->InheritsFrom(TGo4FitData::Class()))
03446 data = dynamic_cast<TGo4FitData*> (item->Object());
03447 else {
03448 TGo4FitModel* model = dynamic_cast<TGo4FitModel*> (item->Object());
03449 TGo4Fitter* fitter = GetFitter();
03450 if ((model!=0) && (fitter!=0))
03451 for (Int_t n=0;n<model->NumAssigments();n++) {
03452 data = fitter->FindData(model->AssignmentName(n));
03453 if (data!=0) break;
03454 }
03455
03456 }
03457 Double_t minx = 0., maxx = 100., miny = 0., maxy = 100;
03458
03459 TPad* pad = FindPadWhereData(data);
03460 if (pad) {
03461 minx = pad->GetUxmin(); maxx = pad->GetUxmax();
03462 miny = pad->GetUymin(); maxy = pad->GetUymax();
03463 } else
03464 if (data!=0) {
03465 data->DefineScaleMinMax(0,minx,maxx);
03466 data->DefineScaleMinMax(1,miny,maxy);
03467 Double_t ddx = 0.1*(maxx-minx);
03468 minx += ddx;
03469 maxx -= ddx;
03470 Double_t ddy = 0.1*(maxy-miny);
03471 miny += ddy;
03472 maxy -= ddy;
03473 }
03474
03475 TGo4FitComponent* comp = dynamic_cast<TGo4FitComponent*> (item->Object());
03476
03477 if (id==0) comp->SetRange(0, minx, maxx); else
03478 if (id==1) comp->ExcludeRange(0, minx, maxx); else
03479 if (id==2) comp->SetRangeMin(0, minx); else
03480 if (id==3) comp->SetRangeMax(0, maxx); else
03481 if (id==4) {
03482 TString name("Cut");
03483 name+=comp->GetNumRangeCut();
03484 TCutG* cut = new TCutG(name, 5);
03485 cut->SetTitle("range cut of X and Y axis");
03486 cut->SetPoint(0, minx, miny);
03487 cut->SetPoint(1, maxx, miny);
03488 cut->SetPoint(2, maxx, maxy);
03489 cut->SetPoint(3, minx, maxy);
03490 cut->SetPoint(4, minx, miny);
03491 comp->AddRangeCut(cut);
03492 }
03493
03494 UpdateItem(item, TRUE);
03495 }
03496
03497 void TGo4FitPanelSlots::Cmd_DeleteAction(QFitItem* item) {
03498 if (item==0) return;
03499 TGo4FitterAction* action = dynamic_cast<TGo4FitterAction*> (item->Object());
03500 TGo4Fitter* fitter = GetFitter();
03501
03502 if(action && fitter) {
03503 if(fxStatus->NeedConfirmation())
03504 if ( QMessageBox::information(0,
03505 QString("Delete action"),
03506 QString("Are you sure to delete ") + item->text(0),
03507 QMessageBox::Yes, QMessageBox::No) == QMessageBox::No ) return;
03508
03509 fitter->DeleteAction(action);
03510 UpdateItem(item->Parent(), TRUE);
03511 }
03512 }
03513
03514 void TGo4FitPanelSlots::Cmd_MoveAction(QFitItem* item, int dir) {
03515 if ((item==0) || (item->Parent()==0)) return;
03516
03517 TGo4FitterAction* action = dynamic_cast<TGo4FitterAction*> (item->Object());
03518 TGo4Fitter* fitter = GetFitter();
03519
03520 if(action && fitter) {
03521 fitter->ReplaceAction(action, dir);
03522 QFitItem* parent = item->Parent();
03523 UpdateItem(parent, TRUE);
03524 item = FindItem(action);
03525 if (item!=0)
03526 fxPanel->FitList->setSelected(item, TRUE);
03527 }
03528 }
03529
03530 void TGo4FitPanelSlots::Cmd_ExecuteAction(QFitItem* item) {
03531 TGo4Fitter* fitter = GetFitter();
03532 if ((item==0) || (fitter==0)) return;
03533
03534 TGo4FitterAction* action = dynamic_cast<TGo4FitterAction*> (item->Object());
03535 if (action==0) return;
03536
03537 fitter->DoAction(action);
03538
03539 if (action->CanChangeFitter()) UpdateActivePage(); else {
03540 UpdateItem(item, TRUE);
03541 UpdateItemsOfType(ot_par);
03542 }
03543 }
03544
03545 void TGo4FitPanelSlots::Cmd_ExecuteActions(QFitItem* item, bool expert) {
03546 TGo4Fitter* fitter = GetFitter();
03547
03548 if ((item==0) || (fitter==0)) return;
03549
03550 fitter->MemorizePars();
03551
03552 fitter->DoActions(expert);
03553
03554 if (expert) UpdateActivePage(); else {
03555 UpdateItem(item, TRUE);
03556 UpdateItemsOfType(ot_par);
03557 }
03558 }
03559
03560 void TGo4FitPanelSlots::Cmd_DeleteOutputActions(QFitItem* item) {
03561 TGo4Fitter* fitter = GetFitter();
03562 if ((item==0) || (item->ObjectType()!=ot_actlist) || (fitter==0)) return;
03563
03564 if(fxStatus->NeedConfirmation())
03565 if ( QMessageBox::information(0,
03566 QString("Delete output actions"),
03567 QString("Are you sure to delete all output actions") + item->text(0),
03568 QMessageBox::Yes, QMessageBox::No) == QMessageBox::No ) return;
03569
03570 fitter->DeleteOutputActions();
03571 UpdateItem(item, TRUE);
03572 }
03573
03574 void TGo4FitPanelSlots::Cmd_DeleteActions(QFitItem* item) {
03575 TGo4Fitter* fitter = GetFitter();
03576 if ((item==0) || (item->ObjectType()!=ot_actlist) || (fitter==0)) return;
03577
03578 if(fxStatus->NeedConfirmation())
03579 if ( QMessageBox::information(0,
03580 QString("Delete all actions"),
03581 QString("Are you sure to delete all actions"),
03582 QMessageBox::Yes, QMessageBox::No) == QMessageBox::No ) return;
03583
03584 fitter->DeleteActions();
03585 UpdateItem(item, TRUE);
03586 }
03587
03588 void TGo4FitPanelSlots::Cmd_AddNewAction(QFitItem* item, int id) {
03589 TGo4Fitter* fitter = GetFitter();
03590 if ((item==0) || (item->ObjectType()!=ot_actlist) || (fitter==0)) return;
03591
03592 switch(id) {
03593 case 0: fitter->AddAction(new TGo4FitterConfig("Config","Fitter configuration")); break;
03594 case 1: fitter->AddAmplEstimation(); break;
03595 case 2: fitter->AddSimpleMinuit(); break;
03596 case 3: fitter->AddOutputAction("Print","*"); break;
03597 case 4: fitter->AddAction(new TGo4FitPeakFinder("Finder")); break;
03598 }
03599 UpdateItem(item, TRUE);
03600 }
03601
03602 void TGo4FitPanelSlots::Cmd_DeleteDependency(QFitItem* item) {
03603 if ((item==0) || (item->ObjectType()!=ot_depend)) return;
03604
03605 TGo4FitDependency* depen = dynamic_cast<TGo4FitDependency*> (item->Object());
03606 TObjArray* lst = dynamic_cast<TObjArray*> (item->Parent()->Object());
03607
03608 if((depen==0) || (lst==0)) return;
03609
03610 if(fxStatus->NeedConfirmation())
03611 if ( QMessageBox::information(0,
03612 QString("Delete dependency item"),
03613 QString("Are you sure to delete ") + item->text(0),
03614 QMessageBox::Yes, QMessageBox::No) == QMessageBox::No ) return;
03615
03616 lst->Remove(depen);
03617 lst->Compress();
03618 delete depen;
03619
03620 UpdateItem(item->Parent(), TRUE);
03621 }
03622
03623 void TGo4FitPanelSlots::Cmd_DeleteDependencies(QFitItem* item) {
03624 if (item==0) return;
03625 TObjArray* lst = dynamic_cast<TObjArray*> (item->Object());
03626 if(lst==0) return;
03627
03628 if(fxStatus->NeedConfirmation())
03629 if ( QMessageBox::information(0,
03630 QString("Delete all"),
03631 QString("Are you sure to delete all items from ") + item->text(0),
03632 QMessageBox::Yes, QMessageBox::No) == QMessageBox::No ) return;
03633
03634 lst->Clear();
03635
03636 UpdateItem(item, TRUE);
03637 }
03638
03639 void TGo4FitPanelSlots::Cmd_AddDependency(QFitItem* item) {
03640 if (item==0) return;
03641
03642 TObjArray* lst = dynamic_cast<TObjArray*> (item->Object());
03643 if(lst==0) return;
03644
03645 if(item->ObjectType()==ot_reslist) lst->Add(new TGo4FitDependency(0,0.0));
03646 else lst->Add(new TGo4FitDependency("Par1",1.0));
03647
03648 UpdateItem(item, TRUE);
03649 }
03650
03651 void TGo4FitPanelSlots::Cmd_MemorizePars(QFitItem* item) {
03652 if (item==0) return;
03653
03654 TGo4FitParsList* pars = dynamic_cast<TGo4FitParsList*> (item->Object());
03655 if (pars==0) return;
03656
03657 pars->MemorizePars();
03658 }
03659
03660 void TGo4FitPanelSlots::Cmd_RememberPars(QFitItem* item) {
03661 if (item==0) return;
03662
03663 TGo4FitParsList* pars = dynamic_cast<TGo4FitParsList*> (item->Object());
03664 if (pars==0) return;
03665
03666 pars->RememberPars();
03667
03668 UpdateItemsOfType(ot_par, item);
03669
03670 ShowItem(item);
03671 }
03672
03673 void TGo4FitPanelSlots::Cmd_DeletePars(QFitItem* item) {
03674 if (item==0) return;
03675 TGo4FitParsList* pars = dynamic_cast<TGo4FitParsList*> (item->Object());
03676 if (pars==0) return;
03677
03678 if(fxStatus->NeedConfirmation())
03679 if ( QMessageBox::information(0,
03680 QString("Delete all"),
03681 QString("Are you sure to delete all items"),
03682 QMessageBox::Yes, QMessageBox::No) == QMessageBox::No ) return;
03683
03684 pars->ClearPars();
03685
03686 UpdateItem(item, TRUE);
03687 }
03688
03689 void TGo4FitPanelSlots::Cmd_MemorizePar(QFitItem* item) {
03690 if (item==0) return;
03691 TGo4FitParameter* par = dynamic_cast<TGo4FitParameter*> (item->Object());
03692 if (par==0) return;
03693
03694 par->MemorizeValue();
03695 }
03696
03697 void TGo4FitPanelSlots::Cmd_RememberPar(QFitItem* item) {
03698 if (item==0) return;
03699 TGo4FitParameter* par = dynamic_cast<TGo4FitParameter*> (item->Object());
03700 if (par==0) return;
03701
03702 par->RememberValue();
03703
03704 SetItemText(item, TRUE);
03705
03706 ShowItem(item);
03707 }
03708
03709 void TGo4FitPanelSlots::Cmd_AddNewPar(QFitItem* item) {
03710 if (item==0) return;
03711
03712 TGo4FitParsList* pars = dynamic_cast<TGo4FitParsList*> (item->Object());
03713 if (pars==0) return;
03714
03715 TString name;
03716 int num = 0;
03717 do {
03718 name = "Par";
03719 name += num;
03720 num++;
03721 } while (pars->FindPar(name));
03722 pars->CreatePar(name.Data(),"additional parameter",0.);
03723
03724 UpdateItem(item, TRUE);
03725 }
03726
03727 void TGo4FitPanelSlots::Cmd_DeletePar(QFitItem* item) {
03728 if (item==0) return;
03729
03730 TGo4FitParameter* par = dynamic_cast<TGo4FitParameter*> (item->Object());
03731 TGo4FitParsList* pars = dynamic_cast<TGo4FitParsList*> (item->Parent()->Object());
03732 if ((pars==0) || (par==0)) return;
03733
03734 if(fxStatus->NeedConfirmation())
03735 if ( QMessageBox::information(0,
03736 QString("Delete item"),
03737 QString("Are you sure to delete ") + par->GetName(),
03738 QMessageBox::Yes, QMessageBox::No) == QMessageBox::No ) return;
03739
03740 pars->RemovePar(par);
03741
03742 UpdateItem(item->Parent(), TRUE);
03743 }
03744
03745 void TGo4FitPanelSlots::Cmd_DeleteMinuitResult(QFitItem* item) {
03746 if (item==0) return;
03747
03748 TGo4FitMinuitResult* res = dynamic_cast<TGo4FitMinuitResult*> (item->Object());
03749 TGo4FitMinuit* minuit = dynamic_cast<TGo4FitMinuit*> (item->Parent()->Object());
03750 if ((res==0) || (minuit==0)) return;
03751
03752 if(fxStatus->NeedConfirmation())
03753 if ( QMessageBox::information(0,
03754 QString("Delete result"),
03755 QString("Are you sure to delete ") + res->GetName(),
03756 QMessageBox::Yes, QMessageBox::No) == QMessageBox::No ) return;
03757
03758 minuit->RemoveResult(res);
03759 delete res;
03760
03761 UpdateItem(item->Parent(), TRUE);
03762 }
03763
03764 void TGo4FitPanelSlots::Cmd_UpdateAllSlots(QFitItem* item) {
03765 if (item==0) return;
03766
03767 UpdateObjectReferenceInSlots(FALSE);
03768
03769 QListViewItem* child = item->firstChild();
03770 while (child) {
03771 UpdateItem(dynamic_cast<QFitItem*>(child), TRUE);
03772 child = child->nextSibling();
03773 }
03774 }
03775
03776 bool TGo4FitPanelSlots::GetDropedObject(const char* source, const char* name, TObject** obj, bool& ownership, TString* SourceInfo) {
03777 ownership = FALSE;
03778 TObject* Object = 0;
03779
03780 if(strcmp(source,"FileListView")==0) {
03781 TGo4DiskFileBrowserSlots* sl = (TGo4DiskFileBrowserSlots*) fxRegistry->GetSlotClass("TGo4DiskFileBrowserSlots");
03782 TGo4DiskFileBrowserStatus* status = (TGo4DiskFileBrowserStatus*) sl->GetStatus();
03783 TFile* ActiveFile = status->GetActiveFile();
03784 if (ActiveFile) {
03785 ActiveFile->cd();
03786 if (strcmp(ActiveFile->GetName(),name)==0) Object = ActiveFile;
03787 else Object = ActiveFile->Get(name);
03788 ownership = FALSE;
03789 if (SourceInfo) (*SourceInfo) = "File browser";
03790 }
03791 } else
03792 if(strcmp(source,"ListViewLocal")==0) {
03793 TGo4BrowserSlots* s = (TGo4BrowserSlots*) fxRegistry->GetSlotClass("TGo4BrowserSlots");
03794 TGo4BrowserStatus * status = (TGo4BrowserStatus*) s->GetStatus();
03795 Object = status->GetObjectfromLocalList(name);
03796 ownership = FALSE;
03797 if (SourceInfo) (*SourceInfo) = "Memory browser";
03798 } else
03799 if (strcmp(source,"ListViewMonitor")==0) {
03800 TGo4MonitoredListStatus* status = (TGo4MonitoredListStatus* )fxRegistry->GetStatus("TGo4MonitoredListStatus");
03801 TGo4MonitoredObject* MonitoredObject = status->GetMonitoredObject(name);
03802 if(MonitoredObject!=0) {
03803 Object = MonitoredObject->GetMonitoredObject()->Clone();
03804 ownership = TRUE;
03805 }
03806 if (SourceInfo) (*SourceInfo) = "Monitoring list";
03807 }
03808
03809 (*obj) = Object;
03810 if (SourceInfo && (Object==0)) (*SourceInfo) = "none";
03811 return (Object!=0);
03812 }
03813
03814 void ScanObject(TObject* obj, TDirectory* src, TObjArray& list) {
03815 if (obj==0) return;
03816
03817 TKey* key = (src==0) ? 0 : dynamic_cast<TKey*> (obj);
03818 const TClass* cl = (key==0) ? obj->IsA() : gROOT->GetClass(key->GetClassName());
03819 if (cl==0) return;
03820
03821 if (cl->InheritsFrom(TDirectory::Class())) {
03822 TDirectory* dir = (key==0) ? dynamic_cast<TDirectory*> (obj) : dynamic_cast<TDirectory*> (src->Get(key->GetName()));
03823 if (dir==0) return;
03824 TIter iter(dir->GetListOfKeys());
03825 cout << " scan dir " << dir->GetName() << endl;
03826 TObject* kobj = 0;
03827 while ( (kobj=iter()) != 0 ) ScanObject(dynamic_cast<TKey*> (kobj), dir, list);
03828 } else
03829
03830 if (cl->InheritsFrom(TFolder::Class())) {
03831 TFolder* fold = (key==0) ? dynamic_cast<TFolder*> (obj) : dynamic_cast<TFolder*> (src->Get(key->GetName()));
03832 if (fold==0) return;
03833 TIter iter(fold->GetListOfFolders());
03834 TObject *fobj;
03835 while( (fobj=iter()) != 0) ScanObject(fobj, 0, list);
03836 } else
03837
03838 if (cl->InheritsFrom(TH1::Class())) {
03839 TObject* aobj = (key==0) ? obj : src->Get(key->GetName());
03840 if (aobj==0) return;
03841 list.Add(aobj);
03842 cout << " obj: " << aobj->GetName() << endl;
03843 } else
03844
03845 if (cl->InheritsFrom(TGraph::Class())) {
03846 TObject* aobj = (key==0) ? obj : src->Get(key->GetName());
03847 if (aobj==0) return;
03848 list.Add(aobj);
03849 cout << " obj: " << aobj->GetName() << endl;
03850 }
03851 }
03852
03853