GSI Object Oriented Online Offline (Go4)  GO4-6.3.0
TGo4WinCondPainter.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 "TGo4WinCondPainter.h"
15 
16 #include "TVirtualPad.h"
17 #include "TROOT.h"
18 
19 #include "TGo4WinCond.h"
20 #include "TGo4WinCondView.h"
21 
24  fxBox(nullptr)
25 {
26 }
27 
28 TGo4WinCondPainter::TGo4WinCondPainter(const char *name, const char *title) :
29  TGo4ConditionPainter(name,title),
30  fxBox(nullptr)
31 {
32 }
33 
35 {
37  if (fxBox) {
38  delete fxBox;
39  fxBox = nullptr;
40  }
41 }
42 
43 
45 {
46  if (!gPad)
47  return;
48  TObject *boxinpad = gPad->GetListOfPrimitives()->FindObject(fxBox);
49  if (fxBox && boxinpad && fxBox->IsAtExecuteMouseEvent())
50  return; // JAM suppress resetting coordinates during mouse modification of box
51  double xpmin = 0, xpmax = 0, ypmin = 0, ypmax = 0;
52  int dim = 0;
53  TGo4WinCond *wconny = dynamic_cast<TGo4WinCond *>(fxCondition);
54  if (wconny && wconny->IsVisible()) {
55  wconny->GetValues(dim, xpmin, xpmax, ypmin, ypmax);
56 
57  // for loaded window conditions, we have to correct limits
58  // otherwise, this would yield wrong statistics from work histogram
59  // root would correct box limits only on first edge resize!
60  if (xpmin > xpmax) {
61  if (wconny->GetDimension() > 1) // keep dimension!
62  wconny->SetValues(xpmax, xpmin, ypmin, ypmax);
63  else
64  wconny->SetValues(xpmax, xpmin);
65  }
66  if (ypmin > ypmax) {
67  if (wconny->GetDimension() > 1) // keep dimension!
68  wconny->SetValues(xpmin, xpmax, ypmax, ypmin);
69  }
70 
71  // std::cout <<"\nBefore toPad:"<< std::endl;
72  // std::cout <<" xpmin="<<xpmin << std::endl;
73  // std::cout <<" xpmax="<<xpmax << std::endl;
74  // std::cout <<" ypmin="<<ypmin << std::endl;
75  // std::cout <<" ypmax="<<ypmax << std::endl;
76 
77  if (dim == 1) {
78  ypmin = gPad->PadtoY(gPad->GetUymin());
79  ypmax = gPad->PadtoY(gPad->GetUymax());
80  }
81 
82  // if(!fxBox || !boxinpad)
83  // user might have deleted box from pad by mouse even if fxBox != nullptr
84  // JAM 2016: this is a memory leak! for each condition update we get new condition view
85  // better: suppress Delete in mouse menu in QtROOT interface (disregard plain ROOT browser here :-))
86  if (!fxBox) {
87  fxBox = new TGo4WinCondView(xpmin, ypmin, xpmax, ypmax);
88  } else {
89  fxBox->SetX1(xpmin);
90  fxBox->SetY1(ypmin);
91  fxBox->SetX2(xpmax);
92  fxBox->SetY2(ypmax);
93  }
94  fxBox->SetCondition(wconny);
95  if (!strcmp(opt, "fixstyle")) {
96  // reproduce condition colors always
97  // this mode will prevent the user from changing box color interactively
98  fxBox->SetLineWidth(wconny->GetLineWidth());
99  fxBox->SetLineColor(wconny->GetLineColor());
100  fxBox->SetLineStyle(wconny->GetLineStyle());
101  fxBox->SetFillColor(wconny->GetFillColor());
102  fxBox->SetFillStyle(wconny->GetFillStyle());
103  }
104  if (!boxinpad) {
105  fxBox->SetLineWidth(wconny->GetLineWidth());
106  fxBox->SetLineColor(wconny->GetLineColor());
107  fxBox->SetLineStyle(wconny->GetLineStyle());
108  fxBox->SetFillColor(wconny->GetFillColor());
109  fxBox->SetFillStyle(wconny->GetFillStyle());
110  fxBox->AppendPad(); // only append to pad if not already there
111  // this is necessary for the Pop() in array painter
112  }
113  fxBox->Paint(); // for condarrays
114 
115  } // if(wconny && wconny->IsVisible())
116  else {
118  }
119 }
120 
122 {
123 
124  gROOT->GetListOfCanvases()->RecursiveRemove(fxBox);
125  // we do not delete view, but restore graphics properties though invisible
126  TString option(opt);
127  if (option.Contains("reset")) {
128  // case of reset option: discard old label geometry
129  delete fxBox;
130  fxBox = nullptr;
131  }
132 }
133 
135 {
136  if (fxBox)
137  fxBox->Pop(); // box to front
138  TGo4LabelPainter::DisplayToFront(opt); // label itself will be frontmost
139 }
void PaintCondition(Option_t *opt="") override
void SetValues(Double_t low1, Double_t up1) override
TGo4Condition * fxCondition
void Paint(Option_t *opt="") override
void GetValues(Int_t &dim, Double_t &x1, Double_t &y1, Double_t &x2, Double_t &y2) override
Bool_t IsAtExecuteMouseEvent() const
TGo4WinCondView * fxBox
void SetCondition(TGo4WinCond *condition)
void DisplayToFront(Option_t *opt="") override
Int_t GetDimension() const
void UnPaintCondition(Option_t *opt="") override
virtual void DisplayToFront(Option_t *opt="")
virtual Bool_t IsVisible() const