00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include "TGo4FitGUIArrow.h"
00017
00018 #include <iostream.h>
00019
00020 #include "Buttons.h"
00021
00022 #include "qstring.h"
00023
00024 #include "Go4Fit/TGo4FitComponent.h"
00025 #include "Go4Fit/TGo4FitModel.h"
00026 #include "QFitItem.h"
00027 #include "TGo4FitPanelSlots.h"
00028
00029 TGo4FitGUIArrow::TGo4FitGUIArrow() :
00030 TArrow(), fxType(at_none), fxModel(0), fxOther(0), fdLineAmpl(0.), fxComp(0), fiRangeNum(0),
00031 fdRangeY(0.), fdShiftX(0.), fxItem(0), fxSlots(0), fxOwner(0)
00032 {
00033 }
00034
00035 TGo4FitGUIArrow::TGo4FitGUIArrow(Float_t arrowsize, Option_t* option) :
00036 TArrow(0.,0.,0.,0.,arrowsize,option), fxType(at_none), fxModel(0), fxOther(0), fdLineAmpl(0.), fxComp(0), fiRangeNum(0),
00037 fdRangeY(0.), fdShiftX(0.), fxItem(0), fxSlots(0), fxOwner(0)
00038 {
00039 }
00040
00041 TGo4FitGUIArrow::TGo4FitGUIArrow(Double_t x1, Double_t y1, Double_t x2, Double_t y2, Float_t arrowsize, Option_t* option) :
00042 TArrow(x1,y1,x2,y2,arrowsize,option), fxType(at_none), fxModel(0), fxOther(0), fdLineAmpl(0.), fxComp(0), fiRangeNum(0),
00043 fdRangeY(0.), fdShiftX(0.), fxItem(0), fxSlots(0), fxOwner(0)
00044 {
00045 }
00046
00047 TGo4FitGUIArrow::~TGo4FitGUIArrow()
00048 {
00049 if (fxOwner!=0) {
00050 fxOwner->Remove(this);
00051 fxOwner->Compress();
00052 }
00053 }
00054
00055 void TGo4FitGUIArrow::SetForPosition(TGo4FitModel* model, TGo4FitGUIArrow* forwidth, Double_t iLineAmpl) {
00056 fxType = at_pos;
00057 fxModel = model;
00058 fxOther = forwidth;
00059 fdLineAmpl = iLineAmpl;
00060 }
00061
00062 void TGo4FitGUIArrow::SetForWidth(TGo4FitModel* model, TGo4FitGUIArrow* forposition) {
00063 fxType = at_width;
00064 fxModel = model;
00065 fxOther = forposition;
00066 }
00067
00068 void TGo4FitGUIArrow::SetForRange(TGo4FitComponent* Comp, Int_t num, Double_t rangey, Double_t shiftx) {
00069 fxType = at_range;
00070 fxComp = Comp;
00071 fiRangeNum = num;
00072 fdRangeY = rangey;
00073 fdShiftX = shiftx;
00074 }
00075
00076 void TGo4FitGUIArrow::SetItem(QFitItem* item, TGo4FitPanelSlots* iSlots) {
00077 fxItem = item;
00078 fxSlots = iSlots;
00079 }
00080
00081 Bool_t TGo4FitGUIArrow::Locate() {
00082 Double_t x1 = GetX1(), x2 = GetX2();
00083 Double_t y1 = GetY1(), y2 = GetY2();
00084
00085 switch (fxType) {
00086 case at_pos:
00087 Double_t pos;
00088 if (fxModel->GetPosition(0,pos)) {
00089 SetX1(pos); SetX2(pos); SetY1(fdLineAmpl/2); SetY2(fdLineAmpl);
00090 }
00091 break;
00092 case at_width:
00093 Double_t width, ppp;
00094 if ((fxModel->GetWidth(0,width)) && (fxModel->GetPosition(0,ppp))) {
00095 SetX1(ppp-width); SetX2(ppp+width);
00096 SetY1(fxOther->GetY1());
00097 SetY2(fxOther->GetY1());
00098 }
00099 break;
00100 case at_range:
00101 Int_t typ, naxis;
00102 Double_t left, right;
00103 fxComp->GetRangeCondition(fiRangeNum, typ, naxis, left, right);
00104 switch (typ) {
00105 case 0: SetX1(left); SetX2(right); break;
00106 case 1: SetX1(left); SetX2(right); break;
00107 case 2: SetX1(left); SetX2(left+fdShiftX); break;
00108 case 3: SetX1(right-fdShiftX); SetX2(right); break;
00109 }
00110 SetY1(fdRangeY); SetY2(fdRangeY);
00111
00112 break;
00113 }
00114
00115 return (x1 != GetX1()) || (x2 != GetX2()) || (y1 != GetY1()) || (y2 != GetY2());
00116 }
00117
00118 Bool_t TGo4FitGUIArrow::IsAssignTo(TObject* obj) {
00119 return (obj!=0) && ((obj==fxModel) || (obj==fxComp));
00120 }
00121
00122 void TGo4FitGUIArrow::DeleteModel() {
00123 if ((fxType==at_pos) && (fxSlots!=0))
00124 fxSlots->DeleteModelWithPrimit(this);
00125 }
00126
00127 void TGo4FitGUIArrow::ExecuteEvent(Int_t event, Int_t px, Int_t py) {
00128 TArrow::ExecuteEvent(event,px,py);
00129 if (event!=kButton1Up) return;
00130
00131 switch (fxType) {
00132
00133 case at_pos:
00134 {
00135
00136 fxModel->SetPosition(0, GetX2());
00137 fdLineAmpl = (GetY1()>GetY2()) ? GetY1() : GetY2();
00138
00139 if (Locate()) Paint();
00140
00141 if (fxOther!=0)
00142 if (fxOther->Locate()) fxOther->Paint();
00143
00144 if (fxSlots) fxSlots->ArrowChanged(this);
00145
00146 }
00147 break;
00148 case at_width:
00149 {
00150 Double_t width = 0;
00151 fxModel->GetWidth(0,width);
00152 Double_t pos = fxOther->GetX2();
00153
00154 Double_t w0 = (GetX2()-GetX1())/2;
00155 Double_t w1 = pos-GetX1();
00156 Double_t w2 = GetX2()-pos;
00157
00158 if (TMath::Abs(w0-width)>1e-10) {
00159 Double_t w = width;
00160 if (TMath::Abs(w1-width)>1e-10) w=w1; else w=w2;
00161 if (w>0) {
00162 width=w; fxModel->SetWidth(0,width);
00163 if (fxSlots) fxSlots->ArrowChanged(this);
00164 }
00165 }
00166
00167 if (Locate()) Paint();
00168
00169 }
00170 break;
00171 case at_range:
00172 {
00173 Int_t typ, naxis;
00174 Double_t left, right;
00175 fxComp->GetRangeCondition(fiRangeNum,typ,naxis,left,right);
00176
00177 left = GetX1()<GetX2() ? GetX1() : GetX2();
00178 right = GetX1()>GetX2() ? GetX1() : GetX2();
00179
00180 fxComp->SetRangeCondition(fiRangeNum,typ,naxis,left,right);
00181
00182 if (fxSlots) fxSlots->ArrowChanged(this);
00183
00184 if (Locate()) Paint();
00185
00186 }
00187 break;
00188 }
00189 }
00190
00191