00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include "TGo4ConditionEditor.h"
00016
00017 #include <QMessageBox>
00018 #include <QMenu>
00019 #include <QtCore/QSignalMapper>
00020 #include <QToolTip>
00021
00022 #include "TH1.h"
00023 #include "TCutG.h"
00024 #include "TClass.h"
00025 #include "TPad.h"
00026 #include "TGo4Log.h"
00027 #include "TGo4Condition.h"
00028 #include "TGo4Slot.h"
00029 #include "TGo4WinCond.h"
00030 #include "TGo4PolyCond.h"
00031 #include "TGo4CondArray.h"
00032 #include "TGo4ViewPanel.h"
00033 #include "TGo4BrowserProxy.h"
00034 #include "TGo4AnalysisProxy.h"
00035
00036
00037 TGo4ConditionEditor::TGo4ConditionEditor(QWidget *parent, const char* name) :
00038 QGo4Widget(parent, name)
00039 {
00040 setupUi(this);
00041
00042 #if QT_VERSION >= QT_VERSION_CHECK(4,6,0)
00043 LCDCounts->setDigitCount(10);
00044 LCDTrueCounts->setDigitCount(10);
00045 #else
00046 LCDCounts->setNumDigits(10);
00047 LCDTrueCounts->setNumDigits(10);
00048 #endif
00049
00050 setWindowTitle("Condition editor");
00051 ResetWidget();
00052 fiSelectedIndex = -1;
00053 parentWidget()->adjustSize();
00054 fbDrawOnNextRefresh = false;
00055 fiLastChangeValue = -1;
00056 CutTable->setContextMenuPolicy(Qt::CustomContextMenu);
00057 }
00058
00059
00060 bool TGo4ConditionEditor::IsAcceptDrag(const char* itemname, TClass* cl, int kind)
00061 {
00062 if (cl==0) return false;
00063 bool res = cl->InheritsFrom(TGo4Condition::Class());
00064
00065 return res;
00066 }
00067
00068 void TGo4ConditionEditor::DropItem(const char* itemname, TClass* cl, int kind)
00069 {
00070 if (cl==0) return;
00071
00072 if (cl->InheritsFrom(TGo4Condition::Class()))
00073 WorkWithCondition(itemname);
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093 }
00094
00095 void TGo4ConditionEditor::linkedObjectUpdated(const char* linkname, TObject* obj)
00096 {
00097 if (strcmp(linkname,"Condition")==0) {
00098 TGo4Condition* cond = dynamic_cast<TGo4Condition*> (obj);
00099 if (cond!=0) cond->SetChanged(kFALSE);
00100 }
00101
00102 RefreshWidget(false);
00103 }
00104
00105 void TGo4ConditionEditor::linkedObjectRemoved(const char* linkname)
00106 {
00107 if (strcmp(linkname,"Condition")==0)
00108 ShootCloseWidget(true);
00109 }
00110
00111 void TGo4ConditionEditor::WorkWithCondition(const char* itemname)
00112 {
00113 const char* conditemname = GetLinkedName("Condition");
00114
00115 TGo4Condition* con = dynamic_cast<TGo4Condition*> (GetLinked("Condition",0));
00116 if ((con!=0) && (con->IsChanged()!=0) && (strcmp(conditemname,itemname)!=0)) {
00117
00118 int res = QMessageBox::warning(this, "Condition editor",
00119 QString("Current condition ")+conditemname+" is modified!\n"+
00120 "New condition " + itemname+ " selected.",
00121 QString("Continue with current"),
00122 QString("Start with new"), QString::null, 0);
00123
00124 if (res==0) return;
00125
00126 }
00127
00128 if ((conditemname==0) || (strcmp(conditemname,itemname)!=0)) {
00129 ResetWidget();
00130 CondNameLbl->setText(itemname);
00131 AddLink(itemname, "Condition");
00132 }
00133
00134 QString iconname = ":/icons/right.png";
00135 QString tooltip = "Refresh condition from analysis";
00136 if (!BrowserItemRemote(itemname)) {
00137 iconname = ":/icons/refresh.png";
00138 tooltip = "Refresh condition from source";
00139 }
00140 RefreshButton->setIcon( QIcon(iconname) );
00141 RefreshButton->setToolTip(tooltip);
00142
00143 TGo4ViewPanel* panel = WhereItemDrawn(itemname);
00144
00145 if (panel==0) {
00146 GetLinked("Condition", 2);
00147 fbDrawOnNextRefresh = true;
00148 fiSelectedIndex = -1;
00149 } else {
00150 TPad* pad = panel->FindPadWithItem(itemname);
00151 fiSelectedIndex = panel->GetSelectedMarkerIndex(pad);
00152 panel->setFocus();
00153 }
00154
00155 RefreshWidget(false);
00156
00157 setFocus();
00158 }
00159
00160 void TGo4ConditionEditor::ResetWidget()
00161 {
00162 QGo4Widget::ResetWidget();
00163 CondNameLbl->setText("");
00164 CondClassLbl->setText("");
00165
00166 PleaseUpdateLabel->setVisible(false);
00167
00168 ArrayAllButton->setVisible(false);
00169 ArrayElements->setVisible(false);
00170
00171 HistogramChk->setVisible(false);
00172 HistogramChk->setChecked(false);
00173 HistogramChk->setText("null");
00174 HistogramChk->setEnabled(false);
00175
00176 CondVisibleChk->setVisible(false);
00177 DrawInfoLbl->setText("");
00178 CondTabs->setEnabled(false);
00179
00180 LCDCounts->display(0);
00181 LCDTrueCounts->display(0);
00182
00183 Win1_low->setDisabled(true);
00184 Win1_up->setDisabled(true);
00185 Win2_low->setDisabled(true);
00186 Win2_up->setDisabled(true);
00187
00188 ResultCombo->setEnabled(false);
00189 InvertCombo->setEnabled(false);
00190
00191 CondTabs->setTabEnabled(1, false);
00192 }
00193
00194 void TGo4ConditionEditor::RefreshWidget(bool checkindex)
00195 {
00196 TGo4Condition* cond = dynamic_cast<TGo4Condition*>(GetLinked("Condition", 0));
00197 if (cond==0) return;
00198
00199 const char* conditemname = GetLinkedName("Condition");
00200 TGo4ViewPanel* panel = WhereItemDrawn(conditemname);
00201 TPad* pad = panel==0 ? 0 : panel->FindPadWithItem(conditemname);
00202
00203 PleaseUpdateLabel->setVisible(cond->IsChanged()!=0);
00204 fiLastChangeValue = cond->IsChanged();
00205
00206 QString hitemname;
00207 TH1* histo = 0;
00208 if ((panel!=0) && (pad!=0)) {
00209 histo = panel->GetPadHistogram(pad);
00210 hitemname = panel->GetDrawObjectLinkName(pad, histo);
00211 if (checkindex) {
00212 QString selname = panel->GetSelectedMarkerName(pad);
00213 int selindex = panel->GetSelectedMarkerIndex(pad);
00214 if (selname==cond->GetName())
00215 fiSelectedIndex = selindex;
00216 }
00217 }
00218 if (histo==0) histo = dynamic_cast<TH1*>(GetLinked("Histogram", 0));
00219
00220 fbTypingMode = false;
00221
00222 TGo4CondArray* arr = dynamic_cast<TGo4CondArray*> (cond);
00223
00224 ArrayAllButton->setVisible(arr!=0);
00225 ArrayElements->setVisible(arr!=0);
00226 if (arr==0) {
00227 fiSelectedIndex = -1;
00228 } else {
00229 ArrayElements->setMaximum(arr->GetNumber()-1);
00230 if (fiSelectedIndex>=arr->GetNumber()-1)
00231 fiSelectedIndex=arr->GetNumber()-1;
00232 ArrayElements->setValue(fiSelectedIndex);
00233
00234 cond = SelectedCondition();
00235 }
00236
00237 ModifyButton->setVisible((panel!=0) && ((arr==0) || (fiSelectedIndex>=0)));
00238
00239 TGo4WinCond* wcond = dynamic_cast<TGo4WinCond*> (cond);
00240 TGo4PolyCond* pcond = dynamic_cast<TGo4PolyCond*> (cond);
00241
00242 if (wcond!=0)
00243 if (wcond->GetDimension()==2)
00244 CondClassLbl->setText("Win 2-D ");
00245 else
00246 CondClassLbl->setText("Win 1-D ");
00247 else
00248 if (pcond!=0)
00249 CondClassLbl->setText("Polygon ");
00250 else
00251 CondClassLbl->setText("");
00252
00253 QString infolbl;
00254
00255 const char* hname = cond->GetLinkedHistogram();
00256 if ((hname==0) || (*hname==0)) {
00257 HistogramChk->setChecked(false);
00258 HistogramChk->setText("null");
00259 HistogramChk->setEnabled(false);
00260
00261 } else {
00262 HistogramChk->setChecked(cond->IsHistogramLink());
00263 HistogramChk->setText(hname);
00264 HistogramChk->setEnabled(true);
00265 infolbl = "Hist: ";
00266 if (hitemname.length()>0)
00267 infolbl += hitemname;
00268 else
00269 infolbl += hname;
00270
00271 }
00272
00273 CondVisibleChk->setVisible(true);
00274 CondVisibleChk->setChecked(cond->IsVisible());
00275
00276 if (panel!=0) {
00277 if (infolbl.length()>0) infolbl+=" ";
00278 infolbl += "Drawn: ";
00279 infolbl += panel->objectName();
00280 if ((pad!=0) && (pad!=(TPad*)panel->GetCanvas())) {
00281 infolbl += ", ";
00282 infolbl += pad->GetName();
00283 }
00284 }
00285 DrawInfoLbl->setText(infolbl);
00286
00287 CondTabs->setEnabled(true);
00288
00289 ResultCombo->setEnabled(true);
00290 InvertCombo->setEnabled(true);
00291
00292 if(cond->IsEnabled())
00293 ResultCombo->setCurrentIndex(0);
00294 else
00295 if (cond->FixedResult())
00296 ResultCombo->setCurrentIndex(1);
00297 else
00298 ResultCombo->setCurrentIndex(2);
00299
00300 if(cond->IsTrue()) InvertCombo->setCurrentIndex(0);
00301 else InvertCombo->setCurrentIndex(1);
00302
00303 LCDCounts->display(cond->Counts());
00304 LCDTrueCounts->display(cond->TrueCounts());
00305
00306 double ratio = 0;
00307 if (cond->Counts()>0)
00308 ratio = 1.*cond->TrueCounts() / cond->Counts();
00309 QString sratio;
00310 if ((ratio>=0.) && (ratio<=100.))
00311 sratio.sprintf("%4.2f%s",ratio*100.,"%");
00312 else
00313 sratio = "?.?? %";
00314 PercentLabel->setText(sratio);
00315
00316 CondLimits->setChecked(cond->IsLimitsDraw());
00317 CondLabel->setChecked(cond->IsLabelDraw());
00318
00319 Win1_low->setText(QString::number(cond->GetXLow()));
00320 Win1_up->setText(QString::number(cond->GetXUp()));
00321
00322 if (cond->GetDimension()==2) {
00323 Win2_low->setText(QString::number(cond->GetYLow()));
00324 Win2_up->setText(QString::number(cond->GetYUp()));
00325 } else {
00326 Win2_low->setText("");
00327 Win2_up->setText("");
00328 }
00329
00330 if (wcond!=0) {
00331 Win1_low->setEnabled(true);
00332 Win1_up->setEnabled(true);
00333 Win2_low->setEnabled(wcond->GetDimension()==2);
00334 Win2_up->setEnabled(wcond->GetDimension()==2);
00335 } else {
00336 Win1_low->setDisabled(true);
00337 Win1_up->setDisabled(true);
00338 Win2_low->setDisabled(true);
00339 Win2_up->setDisabled(true);
00340 }
00341
00342 CondTabs->setTabEnabled(1, (pcond!=0));
00343 if ((pcond==0) && (CondTabs->currentIndex()==1))
00344 CondTabs->setCurrentIndex(0);
00345 if (pcond!=0) FillCutWidget(pcond->GetCut(kFALSE));
00346
00347 IntBox->setChecked(cond->IsIntDraw());
00348 MaxCBox->setChecked(cond->IsCMaxDraw());
00349 MaxXBox->setChecked(cond->IsXMaxDraw());
00350 MaxYBox->setChecked(cond->IsYMaxDraw());
00351
00352 XMeanBox->setChecked(cond->IsXMeanDraw());
00353 YMeanBox->setChecked(cond->IsYMeanDraw());
00354 XRMSBox->setChecked(cond->IsXRMSDraw());
00355 YRMSBox->setChecked(cond->IsYRMSDraw());
00356
00357 IntBox->setText(QString("Integr: ") + QString::number(cond->GetIntegral(histo,"")));
00358 MaxXBox->setText(QString("MaxX: ") + QString::number(cond->GetXMax(histo)));
00359 MaxYBox->setText(QString("MaxY: ") + QString::number(cond->GetYMax(histo)));
00360 MaxCBox->setText(QString("Max: ") + QString::number(cond->GetCMax(histo)));
00361
00362 XMeanBox->setText(QString("XMean: ") + QString::number(cond->GetMean(histo, 1)));
00363 XRMSBox->setText(QString("XRMS: ") + QString::number(cond->GetRMS(histo, 1)));
00364 YMeanBox->setText(QString("YMean: ") + QString::number(cond->GetMean(histo, 2)));
00365 YRMSBox->setText(QString("YRMS: ") + QString::number(cond->GetRMS(histo, 2)));
00366
00367 fbTypingMode = true;
00368
00369 if (fbDrawOnNextRefresh) {
00370 fbDrawOnNextRefresh = false;
00371 TString hitemname;
00372 if ((panel==0) && HistogramChk->isChecked() &&
00373 Browser()->DefineRelatedObject(conditemname, hname, hitemname))
00374 DrawCondition(false);
00375 }
00376 }
00377
00378 TGo4Condition* TGo4ConditionEditor::SelectedCondition()
00379 {
00380 TGo4Condition* cond = dynamic_cast<TGo4Condition*>(GetLinked("Condition", 0));
00381 if (cond==0) return 0;
00382
00383 TGo4CondArray* arr = dynamic_cast<TGo4CondArray*> (cond);
00384
00385 if ((arr==0) || (fiSelectedIndex==-1)) return cond;
00386
00387 if (fiSelectedIndex<arr->GetNumber())
00388 return arr->At(fiSelectedIndex);
00389
00390 return cond;
00391 }
00392
00393 void TGo4ConditionEditor::PleaseUpdateSlot()
00394 {
00395 TGo4Condition* cond = dynamic_cast<TGo4Condition*> (GetLinked("Condition",0));
00396 SetChangeFlag(true);
00397 PleaseUpdateLabel->setVisible(true);
00398 }
00399
00400 void TGo4ConditionEditor::SelectedCond(int t)
00401 {
00402 if (!fbTypingMode) return;
00403 if (fiSelectedIndex==t) return;
00404
00405 fiSelectedIndex = t;
00406 RefreshWidget(false);
00407 RedrawCondition();
00408 }
00409
00410 void TGo4ConditionEditor::ArrayAll()
00411 {
00412 ArrayElements->setValue(-1);
00413 }
00414
00415 void TGo4ConditionEditor::SetResultMode( int mode )
00416 {
00417 TGo4Condition* cond = SelectedCondition();
00418 if (!fbTypingMode || (cond==0)) return;
00419 switch (mode) {
00420 case 0: cond->Enable(); break;
00421 case 1: cond->Disable(kTRUE); break;
00422 case 2: cond->Disable(kFALSE ); break;
00423 default: cond->Enable(); break;
00424 }
00425 PleaseUpdateSlot();
00426 }
00427
00428 void TGo4ConditionEditor::SetInvertMode( int mode )
00429 {
00430 TGo4Condition* cond = SelectedCondition();
00431 if (!fbTypingMode || (cond==0)) return;
00432 cond->Invert(mode==1);
00433 PleaseUpdateSlot();
00434 }
00435
00436 void TGo4ConditionEditor::ClearCounters()
00437 {
00438 const char* conditemname = GetLinkedName("Condition");
00439 TGo4Condition* con = dynamic_cast<TGo4Condition*> (GetLinked("Condition",0));
00440
00441 if ((con==0) || (conditemname==0)) return;
00442
00443 TString objname;
00444 TGo4AnalysisProxy* an = Browser()->DefineAnalysisObject(conditemname, objname);
00445 if (an!=0) {
00446 an->ClearAnalysisObject(objname.Data());
00447 GetLinked("Condition", 2);
00448 } else {
00449 con->ResetCounts();
00450 PleaseUpdateSlot();
00451 RefreshWidget(false);
00452 }
00453 }
00454
00455 void TGo4ConditionEditor::LimitsChanged(const QString& )
00456 {
00457 UpdateLimits();
00458 }
00459
00460 void TGo4ConditionEditor::LimitsReturnPressed()
00461 {
00462 if (UpdateLimits())
00463 RedrawCondition();
00464 }
00465
00466 bool TGo4ConditionEditor::UpdateLimits()
00467 {
00468 TGo4Condition* cond = SelectedCondition();
00469 if (!fbTypingMode || (cond==0)) return false;
00470
00471 bool okx1, okx2, res = false;
00472 Double_t x1 = Win1_low->text().toDouble(&okx1);
00473 Double_t x2 = Win1_up->text().toDouble(&okx2);
00474
00475 if (cond->GetDimension()==2) {
00476 bool oky1, oky2;
00477 Double_t y1 = Win2_low->text().toDouble(&oky1);
00478 Double_t y2 = Win2_up->text().toDouble(&oky2);
00479 if (okx1 && okx2 && oky1 && oky2) {
00480 cond->SetValues(x1, x2, y1, y2);
00481 res = true;
00482 }
00483 } else
00484 if (okx1 && okx2) {
00485 cond->SetValues(x1, x2);
00486 res = true;
00487 }
00488 if (res) PleaseUpdateSlot();
00489 return res;
00490 }
00491
00492 void TGo4ConditionEditor::ChangeConditionProperty(int id, bool on)
00493 {
00494 TGo4Condition* cond = SelectedCondition();
00495 if (!fbTypingMode || (cond==0)) return;
00496 switch(id) {
00497 case 0: cond->SetLabelDraw(on); break;
00498 case 1: cond->SetLimitsDraw(on); break;
00499 case 2: cond->SetIntDraw(on); break;
00500 case 3: cond->SetXMeanDraw(on); break;
00501 case 4: cond->SetXRMSDraw(on); break;
00502 case 5: cond->SetYRMSDraw(on); break;
00503 case 6: cond->SetYMeanDraw(on); break;
00504 case 7: cond->SetXMaxDraw(on); break;
00505 case 8: cond->SetYMaxDraw(on); break;
00506 case 9: cond->SetCMaxDraw(on); break;
00507 case 10: cond->SetVisible(on); break;
00508 default: return;
00509 }
00510 PleaseUpdateSlot();
00511 RedrawCondition();
00512 }
00513
00514
00515 void TGo4ConditionEditor::SetLabel( bool on )
00516 {
00517 ChangeConditionProperty(0, on);
00518 }
00519
00520
00521 void TGo4ConditionEditor::SetDrawLimits( bool on )
00522 {
00523 ChangeConditionProperty(1, on);
00524 }
00525
00526 void TGo4ConditionEditor::SetIntDraw( bool on )
00527 {
00528 ChangeConditionProperty(2, on);
00529 }
00530
00531 void TGo4ConditionEditor::SetXMeanDraw( bool on )
00532 {
00533 ChangeConditionProperty(3, on);
00534 }
00535
00536 void TGo4ConditionEditor::SetXRMSDraw( bool on )
00537 {
00538 ChangeConditionProperty(4, on);
00539 }
00540
00541 void TGo4ConditionEditor::SetYRMSDraw( bool on )
00542 {
00543 ChangeConditionProperty(5, on);
00544 }
00545
00546 void TGo4ConditionEditor::SetYMeanDraw( bool on )
00547 {
00548 ChangeConditionProperty(6, on);
00549 }
00550
00551 void TGo4ConditionEditor::SetXMaxDraw( bool on )
00552 {
00553 ChangeConditionProperty(7, on);
00554 }
00555
00556 void TGo4ConditionEditor::SetYMaxDraw( bool on )
00557 {
00558 ChangeConditionProperty(8, on);
00559 }
00560
00561 void TGo4ConditionEditor::SetCMaxDraw( bool on )
00562 {
00563 ChangeConditionProperty(9, on);
00564 }
00565
00566 void TGo4ConditionEditor::SetCondVisible(bool on)
00567 {
00568 ChangeConditionProperty(10, on);
00569 }
00570
00571
00572 void TGo4ConditionEditor::enterEvent( QEvent * )
00573 {
00574 TGo4Condition* cond = dynamic_cast<TGo4Condition*>(GetLinked("Condition", 0));
00575 if (cond==0) return;
00576 if (fiLastChangeValue==cond->IsChanged()) return;
00577
00578 RefreshWidget(true);
00579 }
00580
00581 void TGo4ConditionEditor::leaveEvent( QEvent * )
00582 {
00583 }
00584
00585 void TGo4ConditionEditor::RefreshClicked()
00586 {
00587 GetLinked("Condition", 2);
00588 RefreshWidget(false);
00589 }
00590
00591 void TGo4ConditionEditor::DisplayPressed()
00592 {
00593 DrawCondition(true);
00594 }
00595
00596 void TGo4ConditionEditor::SetChangeFlag(bool changed)
00597 {
00598 TGo4Condition* cond = dynamic_cast<TGo4Condition*> (GetLinked("Condition",0));
00599 if (cond!=0) cond->SetChanged(changed);
00600 }
00601
00602 void TGo4ConditionEditor::UpdatePressed()
00603 {
00604 if (PrepareForAnalysis()) {
00605 const char* conditem = GetLinkedName("Condition");
00606 if (UpdateItemInAnalysis(conditem) && BrowserItemRemote(conditem))
00607 RefreshClicked();
00608 else {
00609 SetChangeFlag(false);
00610 RefreshWidget(false);
00611 }
00612 }
00613 }
00614
00615 void TGo4ConditionEditor::SaveCondition()
00616 {
00617 if (PrepareForAnalysis())
00618 if (SaveItemToFile(GetLinkedName("Condition"), "Conditions")) {
00619 SetChangeFlag(false);
00620 RefreshWidget(false);
00621 }
00622 }
00623
00624 void TGo4ConditionEditor::DrawCondition(bool useactive)
00625 {
00626 TGo4Condition* cond = dynamic_cast<TGo4Condition*>(GetLinked("Condition", 0));
00627 if (cond==0) return;
00628
00629 const char* conditemname = GetLinkedName("Condition");
00630 if (conditemname==0) return;
00631
00632 TGo4ViewPanel* panel = 0;
00633
00634 if (useactive) panel = LastActivePanel();
00635 if (panel!=0) {
00636 DrawItem(conditemname, panel, 0, false, 0);
00637 RedrawCondition();
00638 RefreshWidget(false);
00639 panel->setFocus();
00640 setFocus();
00641 return;
00642 }
00643
00644 panel = WhereItemDrawn(conditemname);
00645 TPad* pad = panel==0 ? 0 : panel->FindPadWithItem(conditemname);
00646
00647 if (panel!=0) {
00648 if (pad!=0)
00649 RedrawCondition();
00650 else {
00651 DrawItem(conditemname, panel, panel->GetActivePad(), false, 0);
00652 panel->SetSelectedMarker(pad, cond->GetName(), fiSelectedIndex);
00653 panel->MarkPadModified(pad);
00654 panel->ShootRepaintTimer(pad);
00655 }
00656 panel->setFocus();
00657 setFocus();
00658 return;
00659 }
00660
00661 const char* hname = 0;
00662 if (cond->IsHistogramLink())
00663 hname = cond->GetLinkedHistogram();
00664 TString hitemname;
00665
00666 TGo4BrowserProxy* br = Browser();
00667
00668 if (hname!=0)
00669 if (br->DefineRelatedObject(conditemname, hname, hitemname)) {
00670 panel = DrawItem(hitemname.Data(), 0);
00671 RemoveLink("Histogram");
00672 AddLink(hitemname.Data(), "Histogram");
00673 DrawItem(conditemname, panel, 0, false, 0);
00674 RefreshWidget(false);
00675 RedrawCondition();
00676 panel->setFocus();
00677 setFocus();
00678 }
00679 }
00680
00681 void TGo4ConditionEditor::RedrawCondition()
00682 {
00683 const char* conditemname = GetLinkedName("Condition");
00684 if (conditemname==0) return;
00685
00686 TGo4Condition* cond = dynamic_cast<TGo4Condition*>(GetLinked("Condition", 0));
00687 if (cond==0) return;
00688
00689 TGo4ViewPanel* panel = WhereItemDrawn(conditemname);
00690 if (panel==0) return;
00691
00692 TPad* pad = panel->FindPadWithItem(conditemname);
00693 if (pad==0) return;
00694
00695 panel->SetSelectedMarker(pad, cond->GetName(), fiSelectedIndex);
00696 panel->MarkPadModified(pad);
00697 panel->ShootRepaintTimer(pad);
00698 }
00699
00700 void TGo4ConditionEditor::PrintConditionLog()
00701 {
00702 TGo4Condition* cond = dynamic_cast<TGo4Condition*>(GetLinked("Condition", 0));
00703 if (cond!=0) cond->Print("go4log-limits-stats");
00704 }
00705
00706 bool TGo4ConditionEditor::PrepareForAnalysis()
00707 {
00708 TGo4Condition* cond = dynamic_cast<TGo4Condition*>(GetLinked("Condition", 0));
00709 if (cond==0) return false;
00710
00711 SetChangeFlag(false);
00712
00713 const char* hname = cond->GetLinkedHistogram();
00714 if ((hname!=0) && (strlen(hname)!=0)) {
00715 TString foldername, objname;
00716 TGo4Slot::ProduceFolderAndName(hname, foldername, objname);
00717 cond->SetHistogram(objname.Data());
00718 }
00719 return true;
00720 }
00721
00722 void TGo4ConditionEditor::ModifyButton_clicked()
00723 {
00724 TGo4Condition* cond = dynamic_cast<TGo4Condition*>(GetLinked("Condition", 0));
00725 if (cond==0) return;
00726
00727 const char* conditemname = GetLinkedName("Condition");
00728 TGo4ViewPanel* panel = WhereItemDrawn(conditemname);
00729 TPad* pad = panel==0 ? 0 : panel->FindPadWithItem(conditemname);
00730
00731 if ((panel==0) || (pad==0)) return;
00732
00733 panel->SetActivePad(pad);
00734
00735 panel->setFocus();
00736
00737 panel->SetSelectedMarker(pad, cond->GetName(), fiSelectedIndex);
00738
00739 panel->StartConditionEditing(pad);
00740 }
00741
00742 void TGo4ConditionEditor::FillCutWidget(TCutG* cut)
00743 {
00744 bool old = fbTypingMode;
00745 fbTypingMode = false;
00746
00747 if (cut==0) {
00748 CutTable->setRowCount(0);
00749 NPointsSpin->setValue(0);
00750 } else {
00751 CutTable->setRowCount(cut->GetN());
00752 NPointsSpin->setValue(cut->GetN());
00753 for (int n=0;n<cut->GetN();n++) {
00754 Double_t x,y;
00755 cut->GetPoint(n, x,y);
00756 CutTable->setItem(n, 0, new QTableWidgetItem(QString::number(x)));
00757 CutTable->setItem(n, 1, new QTableWidgetItem(QString::number(y)));
00758 CutTable->setVerticalHeaderItem(n, new QTableWidgetItem(QString::number(n)));
00759 }
00760 }
00761
00762 fbTypingMode = old;
00763 }
00764
00765 void TGo4ConditionEditor::NPointsSpin_valueChanged(int npoint)
00766 {
00767 if (!fbTypingMode) return;
00768
00769 TGo4PolyCond* pcond = dynamic_cast<TGo4PolyCond*> (SelectedCondition());
00770 if (pcond==0) return;
00771
00772 TCutG* cut = pcond->GetCut(kFALSE);
00773
00774 if (cut==0) {
00775 cut = new TCutG("conditioncut", npoint);
00776 Double_t x=0., y=0.;
00777 for (int n=0;n<npoint-1; n++)
00778 cut->SetPoint(n, n*10, n*10);
00779 cut->GetPoint(0, x, y);
00780 cut->SetPoint(npoint-1, x, y);
00781 pcond->SetValues(cut);
00782 } else {
00783 if (npoint==0) {
00784 pcond->SetValues(0);
00785 cut = 0;
00786 } else {
00787 int old = cut->GetN();
00788 Double_t x=0., y=0.;
00789 if (old>1) cut->GetPoint(old-2, x, y);
00790 cut->Set(npoint);
00791 for(int n= (old-1>=0 ? old-1 : 0); n<npoint-1; n++)
00792 cut->SetPoint(n, x, y+(n-old+2)*10);
00793 cut->GetPoint(0, x, y);
00794 cut->SetPoint(npoint-1, x, y);
00795 }
00796 }
00797
00798 PleaseUpdateSlot();
00799
00800 FillCutWidget(cut);
00801
00802 RedrawCondition();
00803 }
00804
00805 void TGo4ConditionEditor::CutTable_valueChanged( int nrow, int ncol)
00806 {
00807 if (!fbTypingMode) return;
00808
00809 TGo4PolyCond* pcond = dynamic_cast<TGo4PolyCond*> (SelectedCondition());
00810 TCutG* cut = pcond==0 ? 0 : pcond->GetCut(kFALSE);
00811 if (cut==0) return;
00812
00813 bool ok;
00814 double zn = CutTable->item(nrow, ncol)->text().toDouble(&ok);
00815
00816 if (!ok) return;
00817 if (ncol==0) cut->GetX()[nrow] = zn;
00818 else cut->GetY()[nrow] = zn;
00819 if ((nrow==0) || (nrow==cut->GetN()-1)) {
00820 int nrow1 = (nrow==0) ? cut->GetN()-1 : 0;
00821 fbTypingMode = false;
00822 CutTable->setItem(nrow1, ncol, new QTableWidgetItem(CutTable->item(nrow, ncol)->text()));
00823 if (ncol==0) cut->GetX()[nrow1] = zn;
00824 else cut->GetY()[nrow1] = zn;
00825 fbTypingMode = true;
00826 }
00827
00828 PleaseUpdateSlot();
00829
00830 RedrawCondition();
00831 }
00832
00833
00834 void TGo4ConditionEditor::CutTable_contextMenuRequested( const QPoint & pos )
00835 {
00836 if (!fbTypingMode) return;
00837
00838 QTableWidgetItem* item = CutTable->itemAt (pos);
00839
00840 TGo4PolyCond* pcond = dynamic_cast<TGo4PolyCond*> (SelectedCondition());
00841 TCutG* cut = pcond==0 ? 0 : pcond->GetCut(kFALSE);
00842 if ((cut==0) || (item==0)) return;
00843
00844 int nrow = CutTable->row(item);
00845
00846 QMenu menu(this);
00847 QSignalMapper map(this);
00848 AddIdAction(&menu, &map, "Insert point", nrow);
00849
00850 AddIdAction(&menu, &map, "Delete point", nrow+1000000, (nrow>0) && (nrow<cut->GetN()-1));
00851 connect(&map, SIGNAL(mapped(int)), this, SLOT(ContextMenuSlot(int)));
00852 menu.exec(CutTable->mapToGlobal(pos));
00853 }
00854
00855 void TGo4ConditionEditor::ContextMenuSlot(int id)
00856 {
00857 TGo4PolyCond* pcond = dynamic_cast<TGo4PolyCond*> (SelectedCondition());
00858 TCutG* cut = pcond==0 ? 0 : pcond->GetCut(kFALSE);
00859 if (cut==0) return;
00860
00861 if (id>=1000000) {
00862 id-=1000000;
00863 cut->RemovePoint(id);
00864 } else {
00865 Int_t npoints = cut->GetN();
00866 if (id>=npoints) return;
00867 cut->Set(npoints+1);
00868
00869 Double_t x,y;
00870
00871 for(int n=npoints;n>id;n--) {
00872 cut->GetPoint(n-1, x, y);
00873 cut->SetPoint(n, x, y);
00874 }
00875
00876 if (id>0) {
00877 Double_t x1, y1;
00878 cut->GetPoint(id-1, x1, y1);
00879 cut->SetPoint(id, (x1+x)/2., (y+y1)/2.);
00880 }
00881 }
00882
00883 FillCutWidget(cut);
00884
00885 PleaseUpdateSlot();
00886
00887 RedrawCondition();
00888 }