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