GSI Object Oriented Online Offline (Go4)  GO4-6.1.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
TGo4FitGuiArrow.cpp
Go to the documentation of this file.
1 // $Id: TGo4FitGuiArrow.cpp 3111 2021-03-30 06:06:26Z linev $
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(0), fxOther(0), fdLineAmpl(0.), fxComp(0), fiRangeNum(0),
24  fdRangeY(0.), fdShiftX(0.), fxItem(0), fxPanel(0)
25 {
26 }
27 
28 TGo4FitGuiArrow::TGo4FitGuiArrow(Float_t arrowsize, Option_t *option) :
29  TArrow(0.,0.,0.,0.,arrowsize,option), fxType(at_none), fxModel(0), fxOther(0), fdLineAmpl(0.), fxComp(0), fiRangeNum(0),
30  fdRangeY(0.), fdShiftX(0.), fxItem(0), fxPanel(0)
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(0), fxOther(0), fdLineAmpl(0.), fxComp(0), fiRangeNum(0),
36  fdRangeY(0.), fdShiftX(0.), fxItem(0), fxPanel(0)
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  fxType = at_range;
61  fxComp = Comp;
62  fiRangeNum = num;
63  fdRangeY = rangey;
64  fdShiftX = shiftx;
65 }
66 
68 {
69  fxItem = item;
70  fxPanel = panel;
71 }
72 
74 {
75  Double_t x1 = GetX1(), x2 = GetX2(), y1 = GetY1(), y2 = GetY2();
76 
77  switch (fxType) {
78  case at_pos:
79  Double_t pos;
80  if (fxModel->GetPosition(0,pos)) {
81  SetX1(pos); SetX2(pos); SetY1(fdLineAmpl/2); SetY2(fdLineAmpl);
82  }
83  break;
84  case at_width:
85  Double_t width, ppp;
86  if ((fxModel->GetWidth(0,width)) && (fxModel->GetPosition(0,ppp))) {
87  SetX1(ppp-width); SetX2(ppp+width);
88  SetY1(fxOther->GetY1());
89  SetY2(fxOther->GetY1());
90  }
91  break;
92  case at_range:
93  Int_t typ, naxis;
94  Double_t left, right;
95  fxComp->GetRangeCondition(fiRangeNum, typ, naxis, left, right);
96  switch (typ) {
97  case 0: SetX1(left); SetX2(right); break;
98  case 1: SetX1(left); SetX2(right); break;
99  case 2: SetX1(left); SetX2(left+fdShiftX); break;
100  case 3: SetX1(right-fdShiftX); SetX2(right); break;
101  }
102  SetY1(fdRangeY); SetY2(fdRangeY);
103 
104  break;
105  }
106 
107  return (x1 != GetX1()) || (x2 != GetX2()) || (y1 != GetY1()) || (y2 != GetY2());
108 }
109 
110 Bool_t TGo4FitGuiArrow::IsAssignTo(TObject *obj)
111 {
112  return (obj!=0) && ((obj==fxModel) || (obj==fxComp));
113 }
114 
115 void TGo4FitGuiArrow::Delete(Option_t* option)
116 {
117  if ((fxType==at_pos) && (fxPanel!=0))
119 }
120 
121 void TGo4FitGuiArrow::ExecuteEvent(Int_t event, Int_t px, Int_t py)
122 {
123  TArrow::ExecuteEvent(event,px,py);
124 
125  if (event == kButton1Up)
126  TestNewPosition();
127 }
128 
130 {
131  switch (fxType) {
132 
133  case at_pos: {
134  fxModel->SetPosition(0, GetX2());
135  fdLineAmpl = (GetY1() > GetY2()) ? GetY1() : GetY2();
136  if (fxPanel)
137  fxPanel->ArrowChanged(this);
138  break;
139  }
140 
141  case at_width: {
142  Double_t width = 0;
143  fxModel->GetWidth(0, width);
144  Double_t pos = fxOther->GetX2();
145 
146  Double_t w0 = (GetX2() - GetX1()) / 2;
147  Double_t w1 = pos - GetX1();
148  Double_t w2 = GetX2() - pos;
149 
150  if (TMath::Abs(w0 - width) > 1e-10) {
151  Double_t w = width;
152  if (TMath::Abs(w1 - width) > 1e-10)
153  w = w1;
154  else
155  w = w2;
156  if (w > 0) {
157  width = w;
158  fxModel->SetWidth(0, width);
159  if (fxPanel)
160  fxPanel->ArrowChanged(this);
161  }
162  }
163  break;
164  }
165 
166  case at_range: {
167  Int_t typ, naxis;
168  Double_t left, right;
169  fxComp->GetRangeCondition(fiRangeNum, typ, naxis, left, right);
170 
171  left = GetX1() < GetX2() ? GetX1() : GetX2();
172  right = GetX1() > GetX2() ? GetX1() : GetX2();
173 
174  fxComp->SetRangeCondition(fiRangeNum, typ, naxis, left, right);
175 
176  if (fxPanel)
177  fxPanel->ArrowChanged(this);
178 
179  break;
180  }
181  }
182 }
183 
184 #ifdef __GO4WEB__
185 Bool_t TGo4FitGuiArrow::Notify()
186 {
188  TestNewPosition();
189 
190  return TObject::Notify();
191 }
192 #endif
virtual void ArrowChanged(TGo4FitGuiArrow *arr)
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)
virtual void Delete(Option_t *option="")
QFitItem * fxItem
void SetForPosition(TGo4FitModel *model, TGo4FitGuiArrow *forwidth, Double_t iLineAmpl)
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()
virtual Bool_t SetWidth(Int_t naxis, Double_t width)
virtual Bool_t GetWidth(Int_t naxis, Double_t &width)
void GetRangeCondition(Int_t n, Int_t &typ, Int_t &naxis, Double_t &left, Double_t &right) const
virtual ~TGo4FitGuiArrow()
TGo4FitPanel * fxPanel
virtual void ExecuteEvent(Int_t event, Int_t px, Int_t py)
virtual bool IsWebCanvas() const