Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

TGo4ConditionEditor.ui.h

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

Generated on Fri Nov 28 12:59:20 2008 for Go4-v3.04-1 by  doxygen 1.4.2