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