GSI Object Oriented Online Offline (Go4)  GO4-5.3.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
TGo4WinCondPainter.cxx
Go to the documentation of this file.
1 // $Id: TGo4WinCondPainter.cxx 1851 2016-02-18 15:37:24Z adamczew $
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 für 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 "TGo4WinCondPainter.h"
15 
16 #include "TVirtualPad.h"
17 #include "RVersion.h"
18 #include "TList.h"
19 #include "TROOT.h"
20 
21 #include "TGo4WinCond.h"
22 #include "TGo4WinCondView.h"
23 
26  fxBox(0)
27 {
28 }
29 
30 TGo4WinCondPainter::TGo4WinCondPainter(const char* name, const char* title) :
31  TGo4ConditionPainter(name,title),
32  fxBox(0)
33 {
34 }
35 
37 {
39  if (fxBox!=0) {
40  delete fxBox;
41  fxBox = 0;
42  }
43 }
44 
45 
47 {
48 if(gPad==0) return;
49 TObject* boxinpad=gPad->GetListOfPrimitives()->FindObject(fxBox);
50 //std::cout<<"TGo4WinCondPainter::PaintCondition with fxBox= "<<(long) fxBox<<", isatexecutemousevent="<<(fxBox?fxBox->IsAtExecuteMouseEvent():0) << std::endl;
51 if(fxBox && boxinpad && fxBox->IsAtExecuteMouseEvent()) return; // JAM supress resetting coordinates during mouse modification of box
52 double xpmin=0;
53 double xpmax=0;
54 double ypmin=0;
55 double ypmax=0;
56 int dim=0;
57 TGo4WinCond* wconny=dynamic_cast<TGo4WinCond*>(fxCondition);
58 if(wconny && wconny->IsVisible())
59  {
60  wconny->GetValues(dim, xpmin, xpmax, ypmin, ypmax);
61 
62  // for loaded window conditions, we have to correct limits
63  // otherwise, this would yield wrong statistics from work histogram
64  // root would correct box limits only on first edge resize!
65  if(xpmin>xpmax)
66  {
67  if(wconny->GetDimension()>1) // keep dimension!
68  wconny->SetValues(xpmax, xpmin, ypmin, ypmax );
69  else
70  wconny->SetValues(xpmax, xpmin);
71  }
72  if(ypmin>ypmax)
73  {
74  if(wconny->GetDimension()>1) // keep dimension!
75  wconny->SetValues(xpmin, xpmax, ypmax, ypmin );
76  }
77 
78 // std::cout <<"\nBefore toPad:"<< std::endl;
79 // std::cout <<" xpmin="<<xpmin << std::endl;
80 // std::cout <<" xpmax="<<xpmax << std::endl;
81 // std::cout <<" ypmin="<<ypmin << std::endl;
82 // std::cout <<" ypmax="<<ypmax << std::endl;
83 
84 // note: newer root versions treat log scale correctly in TBox
85 #if ROOT_VERSION_CODE < ROOT_VERSION(4,3,2)
86 
87  xpmin = gPad->XtoPad(xpmin); // for case of log scale
88  xpmax = gPad->XtoPad(xpmax);
89  if(dim==1)
90  {
91  ypmin =gPad->GetUymin();
92  ypmax =gPad->GetUymax();
93  }
94  else
95  {
96  ypmin=gPad->YtoPad(ypmin);
97  ypmax=gPad->YtoPad(ypmax);
98  }
99 
100 #else
101  if(dim==1)
102  {
103  ypmin=gPad->PadtoY(gPad->GetUymin());
104  ypmax=gPad->PadtoY(gPad->GetUymax());
105  }
106 #endif // ROOT_VERSION < 4.3.2
107 
108  //if(fxBox==0 || boxinpad==0)
109  // user might have deleted box from pad by mouse even if fxBox!=0
110  // JAM 2016: this is a memory leak! for each condition update we get new condition view
111  // better: suppress Delete in mouse menu in QtROOT interface (disregard plain ROOT browser here :-))
112  if(fxBox==0)
113  {
114  fxBox= new TGo4WinCondView(xpmin,ypmin,xpmax, ypmax);
115  //std::cout <<"TGo4WinCondPainter::PaintCondition creates new fxBox." <<std::endl;
116  }
117  else
118  {
119  fxBox->SetX1(xpmin);
120  fxBox->SetY1(ypmin);
121  fxBox->SetX2(xpmax);
122  fxBox->SetY2(ypmax);
123  }
124  fxBox->SetCondition(wconny);
125  if(!strcmp(opt,"fixstyle"))
126  {
127  // reproduce condition colors always
128  // this mode will prevent the user from changing box color interactively
129  fxBox->SetLineWidth(wconny->GetLineWidth());
130  fxBox->SetLineColor(wconny->GetLineColor());
131  fxBox->SetLineStyle(wconny->GetLineStyle());
132  fxBox->SetFillColor(wconny->GetFillColor());
133  fxBox->SetFillStyle(wconny->GetFillStyle());
134  }
135  if(boxinpad==0)
136  {
137  fxBox->SetLineWidth(wconny->GetLineWidth());
138  fxBox->SetLineColor(wconny->GetLineColor());
139  fxBox->SetLineStyle(wconny->GetLineStyle());
140  fxBox->SetFillColor(wconny->GetFillColor());
141  fxBox->SetFillStyle(wconny->GetFillStyle());
142  fxBox->AppendPad(); // only append to pad if not already there
143  // this is necessary for the Pop() in array painter
144  }
145  fxBox->Paint(); // for condarrays
146 
147  }// if(wconny && wconny->IsVisible())
148 else
149  {
151  }
152 }
153 
155 {
156 
157  gROOT->GetListOfCanvases()->RecursiveRemove(fxBox);
158  // we do not delete view, but restore graphics properties though invisible
159  TString option(opt);
160  if(option.Contains("reset")) {
161  // case of reset option: discard old label geometry
162  delete fxBox;
163  fxBox=0;
164  }
165 }
166 
168 {
169  if(fxBox) fxBox->Pop(); // box to front
170  TGo4LabelPainter::DisplayToFront(opt); // label itself will be frontmost
171 }
Bool_t IsAtExecuteMouseEvent()
Int_t GetDimension()
TGo4Condition * fxCondition
virtual void GetValues(Int_t &dim, Double_t &x1, Double_t &y1, Double_t &x2, Double_t &y2)
virtual void Paint(Option_t *opt="")
virtual void DisplayToFront(Option_t *opt="")
TGo4WinCondView * fxBox
virtual Bool_t IsVisible()
void SetCondition(TGo4WinCond *condition)
virtual void UnPaintCondition(Option_t *opt="")
virtual void SetValues(Double_t low1, Double_t up1)
virtual void PaintCondition(Option_t *opt="")
virtual void DisplayToFront(Option_t *opt="")