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