GSI Object Oriented Online Offline (Go4)  GO4-5.3.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
TGo4PolyCondView.cxx
Go to the documentation of this file.
1 // $Id: TGo4PolyCondView.cxx 1855 2016-02-29 12:56:48Z adamczew $
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 für 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 "TGo4PolyCondView.h"
15 
16 #include "TCutG.h"
17 #include "TPad.h"
18 #include "Buttons.h"
19 
20 #include "TGo4PolyCond.h"
21 
24 //#define POLYCONDVIEW_UPDATE_WITHCLONE 1
25 
26 
28  TCutG(), fbExecutesMouseEvent(kFALSE),fbExecutesMouseMenu(kFALSE), fxPolyCondition(0)
29 {
30  SetCut(source);
31  SetBit(kMustCleanup);
32  //SetBit(kCanDelete, kFALSE);
33  //std::cout<< "TGo4PolyCondView "<< (long) this <<" ctor from cut"<< (long) source<< std::endl;
34  TGo4PolyCond::CleanupSpecials(); // JAM2016 - immediately take us out of special list
35 }
36 
38  TCutG(), fbExecutesMouseEvent(kFALSE),fbExecutesMouseMenu(kFALSE),fxPolyCondition(0)
39 {
40  SetBit(kMustCleanup);
41  //SetBit(kCanDelete, kFALSE);
42  //std::cout<< "TGo4PolyCondView"<< (long) this <<" default ctor"<< std::endl;
43  TGo4PolyCond::CleanupSpecials(); // JAM2016 - immediately take us out of special list
44 }
45 
46 
48 {
49  // std::cout<< "TGo4PolyCondView "<< (long) this <<" dtor"<< std::endl;
50 }
51 
52 void TGo4PolyCondView::Paint(Option_t* opt)
53 {
54 
55  //std::cout<<"TGo4PolyCondView::Paint, this="<< (long) this <<", Threadid="<< (long) pthread_self()<<", polycondition:"<< (long) fxPolyCondition<< std::endl;
56  if(fxPolyCondition) TCutG::Paint(opt);
57  // we have a valid condition set from painter.Otherwise,
58  // suppress painting of condition view without owner. This case
59  // happens after inserting canvas in go4 (separate cloning
60  // of lists of primitive members), thus leading to a
61  // second "ghost condition polygon"
62 }
63 
65 {
66  fbExecutesMouseMenu=kTRUE;
67  //std::cout<<"TGo4PolyCondView::InsertPoint, this="<< (long) this <<", Threadid="<< (long) pthread_self()<< std::endl;
68  Int_t rev = TGraph::InsertPoint();
70  fbExecutesMouseMenu=kFALSE;
71  return rev;
72 }
73 
75 {
76  fbExecutesMouseMenu=kTRUE;
77  Int_t rev = TGraph::RemovePoint();
79  fbExecutesMouseMenu=kFALSE;
80  return rev;
81 }
82 
83 void TGo4PolyCondView::ExecuteEvent(Int_t event, Int_t px, Int_t py)
84 {
85 
86  // std::cout<<"TGo4PolyCondView::ExecuteEvent, Threadid="<< (long) pthread_self()<< std::endl;
87 // TODO: do we really need this for newer ROOT versions?
88 #if 1
89 // the following is necessary to avoid bug in ROOT TGraph::ExecuteEvent
91 // that does not handle the kButton1Up after kButton1Double
92 // (temporary coordinates array not allocated for button double,
93 // thus crash in button up)
94 // we supress the button up event after button double for the moment...
95 static Bool_t ignoreNext=kFALSE;
96 if(ignoreNext)
97  {
98  //std::cout <<"PolyCondView supressing event "<<event << std::endl;
99  ignoreNext=kFALSE;
100  return;
101  }
102 if(event==kButton1Double)
103  {
104  //std::cout <<"PolyCondView supressing double click" << std::endl;
105  ignoreNext=kTRUE;
106  fbExecutesMouseEvent=kTRUE;
107  return;
108  }
110 #endif
111 
112 // JAM2016: try same mouse event locking as for window condition.
113 if(event==kButton1Down && fxPolyCondition)
114 {
115  //std::cout <<"PolyCondView ExecuteEvent for button 1 down" << std::endl;
116  fbExecutesMouseEvent=kTRUE; // only lock painting if we really touch the polygon JAM
117 }
118 
119 
120 //TGo4PolyCond::CleanupSpecials(); // JAM2016
121 TCutG::ExecuteEvent(event,px,py);
122 //TGo4PolyCond::CleanupSpecials(); // JAM 2016 avoid some intermediate TCutG objects in global list? NO!
123 if(event==kButton1Up && fxPolyCondition)
124  {
125  //std::cout <<"PolyCondView ExecuteEvent for button 1 up" << std::endl;
126  Pop(); // do condition under edit into foreground, for condarray
128  {
129  UpdateCondition();
130  }
131  fxPolyCondition->ResetLabel("pop"); // always pop our label to foreground
132 
133  fbExecutesMouseEvent=kFALSE; //end update lock
134  }// if(event==...)
135 }
136 
138 {
139 if(fxPolyCondition==0) return kFALSE;
140 Bool_t needsupdate=kFALSE;
141 Double_t epsilon=fxPolyCondition->GetUpdateEpsilon();
142 TCutG* concut=fxPolyCondition->GetCut(kFALSE);
143 // check if update is needed:
144 if(concut)
145  {
146  Int_t oldmaxpoints=concut->GetN();
147  Int_t newmaxpoints=GetN();
148  if(oldmaxpoints!=newmaxpoints)
149  {
150  needsupdate=kTRUE;
151  }
152  else
153  {
154  for(Int_t point=0; point<oldmaxpoints; ++point)
155  {
156  Double_t xn=0;
157  Double_t yn=0;
158  Double_t xo=0;
159  Double_t yo=0;
160  concut->GetPoint(point,xo,yo);
161  GetPoint(point,xn,yn);
162  if(TMath::Abs(xo-xn) > epsilon)
163  {
164  needsupdate=kTRUE;
165  break;
166  }
167  if(TMath::Abs(yo-yn) > epsilon)
168  {
169  needsupdate=kTRUE;
170  break;
171  }
172  }//for
173  } // if(oldmaxpoints!=...)
174  }// if(concut)
175 return needsupdate;
176 }
177 
179 {
180  if(fxPolyCondition==0) return;
181  //std::cout<< "TGo4PolyCondView "<< (long) this <<" ::UpdateCondition"<< std::endl;
182 
183 #ifdef POLYCONDVIEW_UPDATE_WITHCLONE
184 
185  TCutG* ccut = CreateCut();
186  fxPolyCondition->SetValues(ccut);
187  delete ccut;
188  //std::cout<< "TGo4PolyCondView::UpdateCondition has deleted intermediat TCutG "<< (long) ccut<< std::endl;
189 // fxPolyCondition->SetValuesDirect(ccut); // change ownership of ccut
191 #else
192  fxPolyCondition->SetValues(this); // probably this is problematic if update with cloning is enabled in condition class!
193 #endif
194  fxPolyCondition->SetChanged(kTRUE);
195 }
196 
197 
198 void TGo4PolyCondView::SetCut(TCutG* source)
199 {
200  // std::cout<< "TGo4PolyCondView "<< (long) this <<" ::SetCut from cut"<< (long) source<< std::endl;
201 
202  if(source==0)
203  {
204  Set(0); // clear array of points
205  SetPoint(0,0,0); //dummy to suppress empty graph warnings
206  }
207  else {
208  Int_t pn=source->GetN();
209  Set(pn); // set to new number of points
210  Double_t xp=0;
211  Double_t yp=0;
212  for(Int_t i=0; i<pn; ++i) {
213  source->GetPoint(i,xp,yp);
214  SetPoint(i,xp,yp);
215  }
216  }
217 }
218 
219 
221 {
222  TCutG* result = new TCutG;
223  result->SetBit(kMustCleanup);
224  //result->SetBit(kCanDelete,kFALSE);
225  TGo4PolyCond::CleanupSpecials(); // JAM2016 - immediately take us out of special list
226  Int_t pn = GetN();
227  Double_t xp=0;
228  Double_t yp=0;
229  for(Int_t i=0; i<pn; ++i) {
230  GetPoint(i,xp,yp);
231  result->SetPoint(i,xp,yp);
232  }
233  result->SetLineColor(GetLineColor());
234  result->SetLineWidth(GetLineWidth());
235  result->SetLineStyle(GetLineStyle());
236  result->SetFillColor(GetFillColor());
237  result->SetFillStyle(GetFillStyle());
238  return result;
239 }
240 
241 const char* TGo4PolyCondView::GetName() const
242 {
243  if(fxPolyCondition)
244  return (fxPolyCondition->GetName());
245  else
246  return (TCutG::GetName()); // JAM2016
247 }
248 
249 void TGo4PolyCondView::SetName(const char* nam)
250 {
251  if(fxPolyCondition) fxPolyCondition->SetName(nam);
252  TCutG::SetName(nam); // JAM2016
253 }
254 
256 {
258 }
260 {
262 }
263 
265 {
267 }
268 
270 {
272 }
273 
275 {
277 }
278 
280 {
282 }
283 
285 {
287 }
288 
290 {
292 }
293 
295 {
297 }
298 
300 {
302 }
303 
305 {
307 }
308 
310 {
312 }
313 
315 {
317 }
Double_t GetUpdateEpsilon()
virtual void SetChanged(Bool_t on)
virtual Int_t RemovePoint()
virtual void SetLimitsDraw(Bool_t on)
void SetYMeanDraw(Bool_t on)
virtual void UpdateCondition()
virtual void SetYRMSDraw(Bool_t on)
void SetLabelDraw(Bool_t on)
static void CleanupSpecials()
void SetYRMSDraw(Bool_t on)
virtual void SetXMaxDraw(Bool_t on)
virtual void SetYMaxDraw(Bool_t on)
virtual void Paint(Option_t *opt)
virtual const char * GetName() const
virtual void SetValues(Double_t *x, Double_t *y, Int_t len)
TCutG * GetCut(Bool_t changeowner)
TGo4PolyCond * fxPolyCondition
virtual Int_t InsertPoint()
void SetCMaxDraw(Bool_t on)
virtual void SetIntDraw(Bool_t on)
void SetXMeanDraw(Bool_t on)
void SetXRMSDraw(Bool_t on)
virtual void SetYMeanDraw(Bool_t on)
void SetCut(TCutG *source)
void ResetLabel(Option_t *opt="reset")
virtual void SetXMeanDraw(Bool_t on)
void SetLimitsDraw(Bool_t on)
Bool_t IsOwnedByEditor()
void SetName(const char *nam)
virtual void SetLabelDraw(Bool_t on)
void SetXMaxDraw(Bool_t on)
virtual void ExecuteEvent(Int_t event, Int_t px, Int_t py)
virtual void SetXRMSDraw(Bool_t on)
void SetYMaxDraw(Bool_t on)
void SetIntDraw(Bool_t on)
virtual ~TGo4PolyCondView()
virtual void SetCMaxDraw(Bool_t on)