GSI Object Oriented Online Offline (Go4)  GO4-6.3.0
TGo4MarkerPainter.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 "TGo4MarkerPainter.h"
15 
16 #include "TVirtualPad.h"
17 #include "TH1.h"
18 #include "TList.h"
19 
20 #include "TGo4Marker.h"
21 
24  fbIsConStreamed(kTRUE)
25 {
26 }
27 
28 TGo4MarkerPainter::TGo4MarkerPainter(const char *name, const char *title) :
29  TGo4LabelPainter(name, title),
30  fbIsConStreamed(kFALSE)
31 {
32 }
33 
35 {
36  if (fxConnector) {
37  delete fxConnector;
38  fxConnector = nullptr;
39  }
40 }
41 
42 
43 void TGo4MarkerPainter::PaintLabel(Option_t *opt)
44 {
45  if (!gPad)
46  return;
47  if (fxMarker && fxMarker->HasLabel()) {
48  //------ find out initial coordinates for labels near marker boundaries:
49  Double_t xoff = 0.015 * (gPad->GetUxmax() - gPad->GetUxmin());
50  Double_t yoff = 0.015 * (gPad->GetUymax() - gPad->GetUymin()); // offset is in pad coordinates
51  Double_t xpmin = gPad->PadtoX(gPad->XtoPad(fxMarker->GetLabelX()) + xoff);
52  Double_t ypmin = gPad->PadtoY(gPad->YtoPad(fxMarker->GetLabelY()) + yoff);
53  Bool_t drx = fxMarker->IsXDraw();
54  Bool_t dry = fxMarker->IsYDraw();
55  Bool_t drxbin = fxMarker->IsXbinDraw();
56  Bool_t drybin = fxMarker->IsYbinDraw();
57  Bool_t drcont = fxMarker->IsContDraw();
58  TString fmt = fxMarker->GetNumFormat();
59  SetX0(xpmin);
60  SetY0(ypmin); // initial coordinates are real axis coordinates
61  SetLineColor(fxMarker->GetMarkerColor());
62  // SetTextColor(fxMarker->GetMarkerColor());
63  TString cap = fxMarker->GetName();
64  TH1 *his = fxMarker->GetHistogram();
65  if (his) {
66  cap += ":";
67  cap += his->GetName();
68  }
69  SetCaption(cap.Data());
70  TGo4LabelPainter::PaintLabel(); // this creates new label
71  if (drx) {
72  TString fmt1 = "X = ";
73  fmt1.Append(fmt);
74  AddToLabel(TString::Format(fmt1.Data(), fxMarker->GetX()).Data());
75  }
76  if (dry) {
77  TString fmt2 = "Y = ";
78  fmt2.Append(fmt);
79  AddToLabel(TString::Format(fmt2.Data(), fxMarker->GetY()).Data());
80  }
81  if (drxbin)
82  AddToLabel(TString::Format("Xbin = %d", fxMarker->GetXbin()).Data());
83  if (drybin)
84  AddToLabel(TString::Format("Ybin = %d", fxMarker->GetYbin()).Data());
85  if (drcont)
86  AddToLabel(TString::Format("C = %d", fxMarker->GetCont()).Data());
87  RePaintLabel();
89  } // if(fxMarker && fxMarker->HasLabel())
90  else {
91  UnPaintLabel();
92  }
93 }
94 
96 {
97  if(!gPad) return;
99  UnPaintConnector(opt);
100 }
101 
102 
104 {
105  if (fbIsConStreamed && fxConnector) {
106  // case of Connector was streamed from file: not yet in cleanup list!
107  fxConnector->SetOwner(this);
108  fbIsConStreamed = kFALSE;
109  return kTRUE;
110  }
112  // our label was deleted by user mouse menu just before
114  fxConnector = nullptr; // reset reference, will re-create label on next paint
115  return kFALSE;
116  }
117 
118  return fxConnector != nullptr;
119 }
120 
122 {
123  if(!gPad) return;
124  if(fxMarker && fxMarker->HasConnector()) {
125  Double_t xmark = 0;
126  Double_t ymark = 0;
127  Double_t xmark0 = fxMarker->GetX();
128  Double_t ymark0 = fxMarker->GetY();
129  Double_t xlab, ylab;
130  Double_t xlablo = GetLabelXlo();
131  Double_t ylablo = GetLabelYlo();
132  Double_t xlabup = GetLabelXup();
133  Double_t ylabup = GetLabelYup();
134  Double_t xlabmid = 0.5 * (xlabup + xlablo);
135  Double_t ylabmid = 0.5 * (ylabup + ylablo);
136  xlablo = gPad->PadtoX(xlablo);
137  ylablo = gPad->PadtoY(ylablo);
138  xlabup = gPad->PadtoX(xlabup);
139  ylabup = gPad->PadtoY(ylabup);
140  xlabmid = gPad->PadtoX(xlabmid);
141  ylabmid = gPad->PadtoY(ylabmid);
142  // evaluate connection to nearest label edge or side centre:
143  if(TMath::Abs(xlablo-xmark0) < TMath::Abs(xlabup-xmark0))
144  {
145  if(TMath::Abs(xlablo-xmark0) < TMath::Abs(xlabmid-xmark0))
146  xlab=xlablo;
147  else
148  xlab=xlabmid;
149  }
150  else
151  {
152  if(TMath::Abs(xlabup-xmark0) < TMath::Abs(xlabmid-xmark0))
153  xlab=xlabup;
154  else
155  xlab=xlabmid;
156  }
157 
158  if(TMath::Abs(ylablo-ymark0) < TMath::Abs(ylabup-ymark0))
159  {
160  if(TMath::Abs(ylablo-ymark0) < TMath::Abs(ylabmid-ymark0))
161  ylab=ylablo;
162  else
163  ylab=ylabmid;
164  }
165  else
166  {
167  if(TMath::Abs(ylabup-ymark0) < TMath::Abs(ylabmid-ymark0))
168  ylab=ylabup;
169  else
170  ylab=ylabmid;
171  }
172  // offset from marker center:
173  Double_t f = 0.92; // fraction of direct distance between marker and label
174  // we calculate connector geometry in pad coordinates for log scale!
175  Double_t xmark_pad = 0;
176  Double_t ymark_pad = 0;
177  Double_t xlab_pad = gPad->XtoPad(xlab);
178  Double_t ylab_pad = gPad->YtoPad(ylab);
179  Double_t xmark0_pad = gPad->XtoPad(xmark0);
180  Double_t ymark0_pad = gPad->YtoPad(ymark0);
181  if(xlab_pad > xmark0_pad)
182  xmark_pad = xlab_pad-f*(xlab_pad-xmark0_pad);
183  else
184  xmark_pad = xlab_pad+f*(xmark0_pad-xlab_pad);
185  if(ylab_pad > ymark0_pad)
186  ymark_pad = ylab_pad-f*(ylab_pad-ymark0_pad);
187  else
188  ymark_pad = ylab_pad+f*(ymark0_pad-ylab_pad);
189 
190  xmark=gPad->PadtoX(xmark_pad); // back to real axis coordinates
191  ymark=gPad->PadtoY(ymark_pad);
192  if(!CheckConnector()) {
193  // connection line not existing or deleted by root:
194  fxConnector=new TGo4LabelConnector(xmark,ymark,xlab,ylab);
195  fxConnector->SetOwner(this);
196  fxConnector->SetLineStyle(4);
197  fxConnector->AppendPad();
198  } else {
199  // connection line is still existing:
200  if (!gPad->GetListOfPrimitives()->FindObject(fxConnector))
201  fxConnector->AppendPad();// connection line was removed from pad, we redraw it:
202  fxConnector->SetX1(xmark);
203  fxConnector->SetY1(ymark);
204  fxConnector->SetX2(xlab);
205  fxConnector->SetY2(ylab);
206  }
207  fxConnector->SetLineColor(fxMarker->GetMarkerColor());
208  //fxConnector->Paint(); // for direct update of view
209  } else {
210  UnPaintConnector(opt);
211  }
212 }
213 
215 {
216  TString option = opt;
217  if (option.Contains("reset")) {
218  // case of reset option: discard old connector line style
219  if (CheckConnector()) {
220  delete fxConnector;
221  fxConnector = nullptr;
222  }
223  }
224 }
225 
227 {
229  PaintConnector(); // pop line to front if enabled
230  if (fxMarker)
231  fxMarker->TObject::Pop(); // then pop marker
232  TGo4LabelPainter::DisplayToFront(opt); // label itself will be frontmost
233 }
Int_t GetYbin() const
Definition: TGo4Marker.cxx:173
void DisplayToFront(Option_t *opt="") override
Bool_t IsYbinDraw() const
Definition: TGo4Marker.h:81
void PaintLabel(Option_t *opt="") override
void UnPaintConnector(Option_t *opt="")
Int_t GetCont() const
Definition: TGo4Marker.cxx:180
TGo4LabelConnector * fxConnector
virtual void UnPaintLabel(Option_t *opt="")
Bool_t HasLabel() const
Definition: TGo4Marker.h:71
Bool_t IsYDraw() const
Definition: TGo4Marker.h:77
virtual void PaintLabel(Option_t *opt="")
Double_t GetLabelX() const
Definition: TGo4Marker.cxx:188
static const void * fxLastDeleted
void SetCaption(const char *txt)
Double_t GetLabelY() const
Definition: TGo4Marker.cxx:197
const char * GetName() const override
Definition: TGo4Marker.h:101
Int_t GetXbin() const
Definition: TGo4Marker.cxx:166
Bool_t IsXbinDraw() const
Definition: TGo4Marker.h:79
Bool_t HasConnector() const
Definition: TGo4Marker.h:73
TGo4Marker * fxMarker
Bool_t IsXDraw() const
Definition: TGo4Marker.h:75
TH1 * GetHistogram() const
Definition: TGo4Marker.h:98
void SetY0(Double_t y=0.)
void SetOwner(TObject *ob)
void UnPaintLabel(Option_t *opt="") override
void SetX0(Double_t x=0.)
const char * GetNumFormat() const
Definition: TGo4Marker.h:85
void AddToLabel(const char *txt)
virtual void DisplayToFront(Option_t *opt="")
void PaintConnector(Option_t *opt="")
Bool_t IsContDraw() const
Definition: TGo4Marker.h:83
virtual void RePaintLabel(Option_t *opt="")