GSI Object Oriented Online Offline (Go4)  GO4-6.3.0
TGo4FitGuiArrow.cpp
Go to the documentation of this file.
1 // $Id$
2 //-----------------------------------------------------------------------
3 // The GSI Online Offline Object Oriented (Go4) Project
4 // Experiment Data Processing at EE department, GSI
5 //-----------------------------------------------------------------------
6 // Copyright (C) 2000- GSI Helmholtzzentrum fuer Schwerionenforschung GmbH
7 // Planckstr. 1, 64291 Darmstadt, Germany
8 // Contact: http://go4.gsi.de
9 //-----------------------------------------------------------------------
10 // This software can be used under the license agreements as stated
11 // in Go4License.txt file which is part of the distribution.
12 //-----------------------------------------------------------------------
13 
14 #include "TGo4FitGuiArrow.h"
15 
16 #include "Buttons.h"
17 
18 #include "TGo4FitPanel.h"
19 #include "TGo4FitModel.h"
20 #include "TGo4ViewPanel.h"
21 
23  TArrow(), fxType(at_none), fxModel(nullptr), fxOther(nullptr), fdLineAmpl(0.), fxComp(nullptr), fiRangeNum(0),
24  fdRangeY(0.), fdShiftX(0.), fxItem(nullptr), fxPanel(nullptr)
25 {
26 }
27 
28 TGo4FitGuiArrow::TGo4FitGuiArrow(Float_t arrowsize, Option_t *option) :
29  TArrow(0.,0.,0.,0.,arrowsize,option), fxType(at_none), fxModel(nullptr), fxOther(nullptr), fdLineAmpl(0.), fxComp(nullptr), fiRangeNum(0),
30  fdRangeY(0.), fdShiftX(0.), fxItem(nullptr), fxPanel(nullptr)
31 {
32 }
33 
34 TGo4FitGuiArrow::TGo4FitGuiArrow(Double_t x1, Double_t y1, Double_t x2, Double_t y2, Float_t arrowsize, Option_t *option) :
35  TArrow(x1,y1,x2,y2,arrowsize,option), fxType(at_none), fxModel(nullptr), fxOther(nullptr), fdLineAmpl(0.), fxComp(nullptr), fiRangeNum(0),
36  fdRangeY(0.), fdShiftX(0.), fxItem(nullptr), fxPanel(nullptr)
37 {
38 }
39 
41 {
42 }
43 
44 void TGo4FitGuiArrow::SetForPosition(TGo4FitModel *model, TGo4FitGuiArrow* forwidth, Double_t iLineAmpl)
45 {
46  fxType = at_pos;
47  fxModel = model;
48  fxOther = forwidth;
49  fdLineAmpl = iLineAmpl;
50 }
51 
53 {
54  fxType = at_width;
55  fxModel = model;
56  fxOther = forposition;
57 }
58 
59 void TGo4FitGuiArrow::SetForRange(TGo4FitComponent *Comp, Int_t num, Double_t rangey, Double_t shiftx)
60 {
61  fxType = at_range;
62  fxComp = Comp;
63  fiRangeNum = num;
64  fdRangeY = rangey;
65  fdShiftX = shiftx;
66 }
67 
69 {
70  fxItem = item;
71  fxPanel = panel;
72 }
73 
75 {
76  Double_t x1 = GetX1(), x2 = GetX2(), y1 = GetY1(), y2 = GetY2();
77 
78  switch (fxType) {
79  case at_pos:
80  Double_t pos;
81  if (fxModel->GetPosition(0,pos)) {
82  SetX1(pos); SetX2(pos); SetY1(fdLineAmpl/2); SetY2(fdLineAmpl);
83  }
84  break;
85  case at_width:
86  Double_t width, ppp;
87  if ((fxModel->GetWidth(0,width)) && (fxModel->GetPosition(0,ppp))) {
88  SetX1(ppp-width); SetX2(ppp+width);
89  SetY1(fxOther->GetY1());
90  SetY2(fxOther->GetY1());
91  }
92  break;
93  case at_range:
94  Int_t typ, naxis;
95  Double_t left, right;
96  fxComp->GetRangeCondition(fiRangeNum, typ, naxis, left, right);
97  switch (typ) {
98  case 0: SetX1(left); SetX2(right); break;
99  case 1: SetX1(left); SetX2(right); break;
100  case 2: SetX1(left); SetX2(left+fdShiftX); break;
101  case 3: SetX1(right-fdShiftX); SetX2(right); break;
102  }
103  SetY1(fdRangeY); SetY2(fdRangeY);
104 
105  break;
106  }
107 
108  return (x1 != GetX1()) || (x2 != GetX2()) || (y1 != GetY1()) || (y2 != GetY2());
109 }
110 
111 Bool_t TGo4FitGuiArrow::IsAssignTo(TObject *obj)
112 {
113  return obj && ((obj == fxModel) || (obj == fxComp));
114 }
115 
116 void TGo4FitGuiArrow::Delete(Option_t *option)
117 {
118  if ((fxType==at_pos) && fxPanel)
120 }
121 
122 void TGo4FitGuiArrow::ExecuteEvent(Int_t event, Int_t px, Int_t py)
123 {
124  TArrow::ExecuteEvent(event,px,py);
125 
126  if (event == kButton1Up)
127  TestNewPosition();
128 }
129 
131 {
132  switch (fxType) {
133 
134  case at_pos: {
135  fxModel->SetPosition(0, GetX2());
136  fdLineAmpl = (GetY1() > GetY2()) ? GetY1() : GetY2();
137  if (fxPanel)
138  fxPanel->ArrowChanged(this);
139  break;
140  }
141 
142  case at_width: {
143  Double_t width = 0;
144  fxModel->GetWidth(0, width);
145  Double_t pos = fxOther->GetX2();
146 
147  Double_t w0 = (GetX2() - GetX1()) / 2;
148  Double_t w1 = pos - GetX1();
149  Double_t w2 = GetX2() - pos;
150 
151  if (TMath::Abs(w0 - width) > 1e-10) {
152  Double_t w = width;
153  if (TMath::Abs(w1 - width) > 1e-10)
154  w = w1;
155  else
156  w = w2;
157  if (w > 0) {
158  width = w;
159  fxModel->SetWidth(0, width);
160  if (fxPanel)
161  fxPanel->ArrowChanged(this);
162  }
163  }
164  break;
165  }
166 
167  case at_range: {
168  Int_t typ, naxis;
169  Double_t left, right;
170  fxComp->GetRangeCondition(fiRangeNum, typ, naxis, left, right);
171 
172  left = GetX1() < GetX2() ? GetX1() : GetX2();
173  right = GetX1() > GetX2() ? GetX1() : GetX2();
174 
175  fxComp->SetRangeCondition(fiRangeNum, typ, naxis, left, right);
176 
177  if (fxPanel)
178  fxPanel->ArrowChanged(this);
179 
180  break;
181  }
182  }
183 }
184 
185 #ifdef __GO4WEB__
186 Bool_t TGo4FitGuiArrow::Notify()
187 {
189  TestNewPosition();
190 
191  return TObject::Notify();
192 }
193 #endif
virtual void ArrowChanged(TGo4FitGuiArrow *arr)
void Delete(Option_t *option="") override
TGo4FitGuiArrow * fxOther
void SetRangeCondition(Int_t n, Int_t typ, Int_t naxis, Double_t left, Double_t right)
virtual Bool_t SetPosition(Int_t naxis, Double_t pos)
void SetForRange(TGo4FitComponent *Comp, Int_t num, Double_t rangey, Double_t shiftx)
QFitItem * fxItem
void SetForPosition(TGo4FitModel *model, TGo4FitGuiArrow *forwidth, Double_t iLineAmpl)
void GetRangeCondition(Int_t n, Int_t &typ, Int_t &naxis, Double_t &left, Double_t &right) const
TGo4FitComponent * fxComp
void SetForWidth(TGo4FitModel *model, TGo4FitGuiArrow *forposition)
virtual Bool_t GetPosition(Int_t naxis, Double_t &pos)
TGo4FitModel * fxModel
void SetItem(QFitItem *item, TGo4FitPanel *panel)
Bool_t IsAssignTo(TObject *obj)
virtual void DeleteModelWithPrimit(TGo4FitGuiArrow *arr)
virtual TGo4ViewPanel * ActivePanel()
void ExecuteEvent(Int_t event, Int_t px, Int_t py) override
virtual Bool_t SetWidth(Int_t naxis, Double_t width)
virtual Bool_t GetWidth(Int_t naxis, Double_t &width)
virtual ~TGo4FitGuiArrow()
virtual bool IsWebCanvas() const
TGo4FitPanel * fxPanel