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