GSI Object Oriented Online Offline (Go4) GO4-6.4.5
Loading...
Searching...
No Matches
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#include "TMath.h"
20
21#include "TGo4Marker.h"
22
28
29TGo4MarkerPainter::TGo4MarkerPainter(const char *name, const char *title) :
30 TGo4LabelPainter(name, title),
31 fbIsConStreamed(kFALSE)
32{
33}
34
36{
37 if (fxConnector) {
38 delete fxConnector;
39 fxConnector = nullptr;
40 }
41}
42
43
45{
46 if (!gPad)
47 return;
48 if (fxMarker && fxMarker->HasLabel()) {
49 //------ find out initial coordinates for labels near marker boundaries:
50 Double_t xoff = 0.015 * (gPad->GetUxmax() - gPad->GetUxmin());
51 Double_t yoff = 0.015 * (gPad->GetUymax() - gPad->GetUymin()); // offset is in pad coordinates
52 Double_t xpmin = gPad->PadtoX(gPad->XtoPad(fxMarker->GetLabelX()) + xoff);
53 Double_t ypmin = gPad->PadtoY(gPad->YtoPad(fxMarker->GetLabelY()) + yoff);
54 Bool_t drx = fxMarker->IsXDraw();
55 Bool_t dry = fxMarker->IsYDraw();
56 Bool_t drxbin = fxMarker->IsXbinDraw();
57 Bool_t drybin = fxMarker->IsYbinDraw();
58 Bool_t drcont = fxMarker->IsContDraw();
59 TString fmt = fxMarker->GetNumFormat();
60 SetX0(xpmin);
61 SetY0(ypmin); // initial coordinates are real axis coordinates
62 SetLineColor(fxMarker->GetMarkerColor());
63 // SetTextColor(fxMarker->GetMarkerColor());
64 TString cap = fxMarker->GetName();
65 TH1 *his = fxMarker->GetHistogram();
66 if (his) {
67 cap += ":";
68 cap += his->GetName();
69 }
70 SetCaption(cap.Data());
71 TGo4LabelPainter::PaintLabel(); // this creates new label
72 if (drx) {
73 TString fmt1 = "X = ";
74 fmt1.Append(fmt);
75 AddToLabel(TString::Format(fmt1.Data(), fxMarker->GetX()).Data());
76 }
77 if (dry) {
78 TString fmt2 = "Y = ";
79 fmt2.Append(fmt);
80 AddToLabel(TString::Format(fmt2.Data(), fxMarker->GetY()).Data());
81 }
82 if (drxbin)
83 AddToLabel(TString::Format("Xbin = %d", fxMarker->GetXbin()).Data());
84 if (drybin)
85 AddToLabel(TString::Format("Ybin = %d", fxMarker->GetYbin()).Data());
86 if (drcont)
87 AddToLabel(TString::Format("C = %d", fxMarker->GetCont()).Data());
90 } // if(fxMarker && fxMarker->HasLabel())
91 else {
93 }
94}
95
97{
98 if(!gPad) return;
100 UnPaintConnector(opt);
101}
102
103
105{
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 = nullptr; // reset reference, will re-create label on next paint
116 return kFALSE;
117 }
118
119 return fxConnector != nullptr;
120}
121
123{
124 if(!gPad) 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(xlab_pad > xmark0_pad)
183 xmark_pad = xlab_pad-f*(xlab_pad-xmark0_pad);
184 else
185 xmark_pad = xlab_pad+f*(xmark0_pad-xlab_pad);
186 if(ylab_pad > ymark0_pad)
187 ymark_pad = ylab_pad-f*(ylab_pad-ymark0_pad);
188 else
189 ymark_pad = ylab_pad+f*(ymark0_pad-ylab_pad);
190
191 xmark=gPad->PadtoX(xmark_pad); // back to real axis coordinates
192 ymark=gPad->PadtoY(ymark_pad);
193 if(!CheckConnector()) {
194 // connection line not existing or deleted by root:
195 fxConnector=new TGo4LabelConnector(xmark,ymark,xlab,ylab);
196 fxConnector->SetOwner(this);
197 fxConnector->SetLineStyle(4);
198 fxConnector->AppendPad();
199 } else {
200 // connection line is still existing:
201 if (!gPad->GetListOfPrimitives()->FindObject(fxConnector))
202 fxConnector->AppendPad();// connection line was removed from pad, we redraw it:
203 fxConnector->SetX1(xmark);
204 fxConnector->SetY1(ymark);
205 fxConnector->SetX2(xlab);
206 fxConnector->SetY2(ylab);
207 }
208 fxConnector->SetLineColor(fxMarker->GetMarkerColor());
209 //fxConnector->Paint(); // for direct update of view
210 } else {
211 UnPaintConnector(opt);
212 }
213}
214
216{
217 TString option = opt;
218 if (option.Contains("reset")) {
219 // case of reset option: discard old connector line style
220 if (CheckConnector()) {
221 delete fxConnector;
222 fxConnector = nullptr;
223 }
224 }
225}
226
228{
230 PaintConnector(); // pop line to front if enabled
231 if (fxMarker)
232 fxMarker->TObject::Pop(); // then pop marker
233 TGo4LabelPainter::DisplayToFront(opt); // label itself will be frontmost
234}
Connection line for labels that knows its author.
static const void * fxLastDeleted
set this to pointer of last deleted instance before
void SetY0(Double_t y=0.)
virtual void UnPaintLabel(Option_t *opt="")
Erase the label.
Double_t GetLabelYlo()
Reference coordinate y of label box (lower left corner).
Double_t GetLabelXup()
Reference coordinate x of label box (upper right corner).
Double_t GetLabelYup()
Reference coordinate y of label box (upper right corner).
void SetCaption(const char *txt)
virtual void PaintLabel(Option_t *opt="")
Draw the label.
virtual void DisplayToFront(Option_t *opt="")
pop all components to the front of the pad
virtual void RePaintLabel(Option_t *opt="")
refresh painting of label with current attributes
void AddToLabel(const char *txt)
Double_t GetLabelXlo()
Reference coordinate x of label box (lower left corner).
void SetX0(Double_t x=0.)
void PaintLabel(Option_t *opt="") override
Display coordinate label for this marker.
void UnPaintLabel(Option_t *opt="") override
Erase the label.
void PaintConnector(Option_t *opt="")
void UnPaintConnector(Option_t *opt="")
TGo4LabelConnector * fxConnector
Connection line between marker and label.
TGo4Marker * fxMarker
Marker to be painted.
void DisplayToFront(Option_t *opt="") override
pop all components to the front of the pad
Bool_t fbIsConStreamed
Flag to handle streamed connector from file correctly.
Bool_t CheckConnector()
Check if connector is still existing.