GSI Object Oriented Online Offline (Go4) GO4-6.4.5
Loading...
Searching...
No Matches
TGo4PolyCondView.cxx
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 "TGo4PolyCondView.h"
15
16#include "TVirtualPad.h"
17#include "TMath.h"
18
21//#define POLYCONDVIEW_UPDATE_WITHCLONE 1
22
23
25 TCutG(), fbExecutesMouseEvent(kFALSE),fbExecutesMouseMenu(kFALSE), fxPolyCondition(nullptr)
26{
27 SetCut(source);
28 SetBit(kMustCleanup);
29 //SetBit(kCanDelete, kFALSE);
30 TGo4PolyCond::CleanupSpecials(); // JAM2016 - immediately take us out of special list
31}
32
34 TCutG(), fbExecutesMouseEvent(kFALSE),fbExecutesMouseMenu(kFALSE),fxPolyCondition(nullptr)
35{
36 SetBit(kMustCleanup);
37 //SetBit(kCanDelete, kFALSE);
38 TGo4PolyCond::CleanupSpecials(); // JAM2016 - immediately take us out of special list
39}
40
41
45
46void TGo4PolyCondView::Paint(Option_t *opt)
47{
48 if(fxPolyCondition) TCutG::Paint(opt);
49 // we have a valid condition set from painter.Otherwise,
50 // suppress painting of condition view without owner. This case
51 // happens after inserting canvas in go4 (separate cloning
52 // of lists of primitive members), thus leading to a
53 // second "ghost condition polygon"
54}
55
57{
58 fbExecutesMouseMenu = kTRUE;
59 Int_t rev = TGraph::InsertPoint();
62 return rev;
63}
64
66{
68 Int_t rev = TGraph::RemovePoint();
71 return rev;
72}
73
74void TGo4PolyCondView::ExecuteEvent(Int_t event, Int_t px, Int_t py)
75{
76// TODO: do we really need this for newer ROOT versions?
77#if 1
79 // the following is necessary to avoid bug in ROOT TGraph::ExecuteEvent
80 // that does not handle the kButton1Up after kButton1Double
81 // (temporary coordinates array not allocated for button double,
82 // thus crash in button up)
83 // we suppress the button up event after button double for the moment...
84 static Bool_t ignoreNext = kFALSE;
85 if (ignoreNext) {
86 ignoreNext = kFALSE;
87 return;
88 }
89 if (event == kButton1Double) {
90 ignoreNext = kTRUE;
92 return;
93 }
95#endif
96
97 // JAM2016: try same mouse event locking as for window condition.
98 if (event == kButton1Down && fxPolyCondition) {
99 fbExecutesMouseEvent = kTRUE; // only lock painting if we really touch the polygon JAM
100 }
101
102 // TGo4PolyCond::CleanupSpecials(); // JAM2016
103 TCutG::ExecuteEvent(event, px, py);
104 // TGo4PolyCond::CleanupSpecials(); // JAM 2016 avoid some intermediate TCutG objects in global list? NO!
105 if (event == kButton1Up && fxPolyCondition) {
106 Pop(); // do condition under edit into foreground, for condarray
109 }
110 fxPolyCondition->ResetLabel("pop"); // always pop our label to foreground
111
112 fbExecutesMouseEvent = kFALSE; // end update lock
113 } // if(event==...)
114}
115
117{
118 if (!fxPolyCondition)
119 return kFALSE;
120 Bool_t needsupdate = kFALSE;
121 Double_t epsilon = fxPolyCondition->GetUpdateEpsilon();
122 TCutG *concut = fxPolyCondition->GetCut(kFALSE);
123 // check if update is needed:
124 if (concut) {
125 Int_t oldmaxpoints = concut->GetN(), newmaxpoints = GetN();
126 if (oldmaxpoints != newmaxpoints) {
127 needsupdate = kTRUE;
128 } else {
129 for (Int_t point = 0; point < oldmaxpoints; ++point) {
130 Double_t xn = 0, yn = 0, xo = 0, yo = 0;
131 concut->GetPoint(point, xo, yo);
132 GetPoint(point, xn, yn);
133 if (TMath::Abs(xo - xn) > epsilon) {
134 needsupdate = kTRUE;
135 break;
136 }
137 if (TMath::Abs(yo - yn) > epsilon) {
138 needsupdate = kTRUE;
139 break;
140 }
141 } // for
142 } // if(oldmaxpoints!=...)
143 } // if(concut)
144 return needsupdate;
145}
146
148{
149 if(!fxPolyCondition) return;
150
151#ifdef POLYCONDVIEW_UPDATE_WITHCLONE
152
153 TCutG *ccut = CreateCut();
154 fxPolyCondition->SetValues(ccut);
155 delete ccut;
156// fxPolyCondition->SetValuesDirect(ccut); // change ownership of ccut
158#else
159 fxPolyCondition->SetValues(this); // probably this is problematic if update with cloning is enabled in condition class!
160#endif
161 fxPolyCondition->SetChanged();
162}
163
164
165void TGo4PolyCondView::SetCut(TCutG *source)
166{
167 if (!source) {
168 Set(0); // clear array of points
169 SetPoint(0, 0, 0); // dummy to suppress empty graph warnings
170 } else {
171 Int_t pn = source->GetN();
172 Set(pn); // set to new number of points
173 Double_t xp = 0;
174 Double_t yp = 0;
175 for (Int_t i = 0; i < pn; ++i) {
176 source->GetPoint(i, xp, yp);
177 SetPoint(i, xp, yp);
178 }
179 }
180}
181
183{
184 auto result = new TCutG;
185 result->SetBit(kMustCleanup);
186 // result->SetBit(kCanDelete,kFALSE);
187 TGo4PolyCond::CleanupSpecials(); // JAM2016 - immediately take us out of special list
188 Int_t pn = GetN();
189 Double_t xp = 0;
190 Double_t yp = 0;
191 for (Int_t i = 0; i < pn; ++i) {
192 GetPoint(i, xp, yp);
193 result->SetPoint(i, xp, yp);
194 }
195 result->SetLineColor(GetLineColor());
196 result->SetLineWidth(GetLineWidth());
197 result->SetLineStyle(GetLineStyle());
198 result->SetFillColor(GetFillColor());
199 result->SetFillStyle(GetFillStyle());
200 return result;
201}
202
203const char *TGo4PolyCondView::GetName() const
204{
206 return fxPolyCondition->GetName();
207
208 return TCutG::GetName(); // JAM2016
209}
210
211void TGo4PolyCondView::SetName(const char *nam)
212{
213 if(fxPolyCondition) fxPolyCondition->SetName(nam);
214 TCutG::SetName(nam); // JAM2016
215}
216
218{
219 if(fxPolyCondition && !fxPolyCondition->IsOwnedByEditor()) fxPolyCondition->Delete("");
220}
221
223{
224 if(fxPolyCondition) fxPolyCondition->SaveLabelStyle();
225}
226
228{
229 if(fxPolyCondition) fxPolyCondition->ResetLabel();
230}
Int_t InsertPoint() override
const char * GetName() const override
virtual void UpdateCondition()
Copy modified view values back to condition.
Bool_t fbExecutesMouseEvent
JAM this one will suppress condition repaint during execution of mouse events.
TCutG * CreateCut()
create plain cutg from this view.
void SetCut(TCutG *source)
Set this view to values of cut source.
void DeleteRegion()
Delete condition instead of view:
Int_t RemovePoint() override
Bool_t IsCutChanged() const
Check if cut on pad is changed compared with condition.
TGo4PolyCond * fxPolyCondition
pointer to viewed condition for update after graphical action
void ResetLabel()
Will reset label position to defaults.
Bool_t fbExecutesMouseMenu
JAM this one will suppress condition repaint during mouse menu execution.
void ExecuteEvent(Int_t event, Int_t px, Int_t py) override
void SetName(const char *nam) override
void Paint(Option_t *opt) override
void SaveLabelStyle()
This will save draw flags into static default setup.
static void CleanupSpecials()
Remove all references to any TCutGs from ROOT list of specials.