StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
PadControlPanel.C
1 //*-- Author : Valery Fine 25/05/99 (E-mail: fine@bnl.gov)
2 //
3 // Copyright (C) Valery Fine, Brookhaven National Laboratory, 1999. All right reserved
4 //
5 // $Id: PadControlPanel.C,v 1.20 2003/10/09 18:11:54 perev Exp $
6 //
7 
9 //
10 // This macro generates a Controlbar panel:
11 // begin_html <P ALIGN=CENTER> <IMG SRC="gif/PadControlPanel.gif" ></P> end_html
12 //
13 // To execute an item, click with the left mouse button.
14 //
15 // Just start this macro wheneven you want:
16 //
17 // From Root/Cint macro:
18 // --------------------
19 // .x PadControlPanel.C
20 // .L PadControlPanel.C
21 // or
22 // gROOT->LoadMacro("PadControlPanel.C");
23 //
24 // From the compiled C++ code:
25 // --------------------
26 // gROOT->LoadMacro("PadControlPanel.C");
27 //
28 // After that one may "click" <4 views> button to get from the single "view"
29 // the expanded view as follows:
30 // begin_html <P ALIGN=CENTER> <IMG SRC="gif/FourStarView.gif" ></P> end_html
31 // To cutomize the default bar the dirived class with the custom void UserBar()
32 // method can be done.
33 // TGButtonGroup *Bar(){ return fBar;}
34 // method can be used.
35 //
36 // Example:
37 // TGButtonGroup *myBar = __aa__.Bar();
38 // myBar->AddButton("My custom","printf(\"here is my custom action\n\");","To add your own action replace the second parameter");
39 //
40 // Note: If you don't like what it does make your private copy
41 // ==== change it with your favorite text editor and load it right
42 // away.
43 // NO EXTRA STEP like : compilation, linking, loading required
44 //
46 
48 //
49 // PadControl panel is the set of the static methods to control
50 // TView of any "current" TPad with some "primitive"
51 // operation:
52 //
54 TGButtonGroup *mainBar=0;
55 
56 TVirtualPad *qPad(){ return TVirtualPad::Pad() ;}
57 
59  private:
60  TGButtonGroup *fBar;
61  TGLayoutHints *fL1;
62 
63 protected:
64 
65 
66 //_______________________________________________________________________________________
67  void AddButt(const Char_t *buttonName, const Char_t *command)
68  {
69  TGTextButton *tb = new TGTextButton(fBar,buttonName,command);
70  fBar->AddFrame(tb,fL1);
71  }
72 
73 public:
74 
75 
76 StPadControlPanel() { Build();}
77 //_______________________________________________________________________________________
78 void Build()
79 {
80  const char *fills[] = {
81  "Black background", "StPadControlPanel::SetBackround(kBlack);"
82  ,"White background", "StPadControlPanel::SetBackround (19);"
83  ,"Adjust scales", "StPadControlPanel::AdjustScales ();"
84  ,"Centered", "StPadControlPanel::Centered3DImages();"
85  ,"Scale +", "StPadControlPanel::Inscrease3DScale();"
86  ,"Scale -", "StPadControlPanel::Decrease3DScale ();"
87  ,"Top View (X-Y)", "StPadControlPanel::TopView ();"
88  ,"Side View (Y-Z)", "StPadControlPanel::SideView ();"
89  ,"Front View (X-Z)", "StPadControlPanel::FrontView ();"
90  ,"4 views", "StPadControlPanel::MakeFourView();"
91  ,"Add Axes", "StPadControlPanel::AddAxes ();"
92  ,"Rulers", "StPadControlPanel::ToggleRulers();"
93  ,"Zoom", "StPadControlPanel::ToggleZoom ();"
94  ,"ReDraw canvas", "StEventDisplayMaker::MakeLoop(1);"
95  ,"Next event", "StEventDisplayMaker::MakeLoop(2);"
96  ,"End of Chain", "StEventDisplayMaker::MakeLoop(3);"
97  ,0};
98 
99 
100  fBar = new TGButtonGroup(gClient->GetRoot(), "Pad Control Panel");
101  mainBar=fBar;
102  gVirtualX->SetWindowName(fBar->GetId(),"Pad");
103  fL1 = new TGLayoutHints(kLHintsCenterY | kLHintsExpandX, 1, 1, 1, 1);
104  for (int i=0;fills[i];i+=2) {AddButt(fills[i],fills[i+1]);}
105 
106  fBar->Show();
107 }
108 //_______________________________________________________________________________________
109 ~StPadControlPanel(){ delete fBar; delete fL1;}
110 //_______________________________________________________________________________________
111  TGButtonGroup *Bar() const { return fBar;}
112 
113 //_______________________________________________________________________________________
114 static void SetBackround(Color_t color, TVirtualPad *pad=0)
115 {
116  TVirtualPad *thisPad = pad;
117  if (!thisPad) thisPad = qPad();
118  if (thisPad) {
119  thisPad->SetFillColor(color);
120  thisPad->Modified();
121  thisPad->Update();
122  }
123 }
124 
125 //_______________________________________________________________________________________
126 static void SetBackroundStyle(TVirtualPad *pad=0)
127 {
128  TVirtualPad *thisPad = pad;
129  if (!thisPad) thisPad = qPad();
130  if (thisPad) thisPad->SetFillAttributes();
131 }
132 
133 //_______________________________________________________________________________________
134 static void RotateView(Float_t phi, Float_t theta, TVirtualPad *pad=0)
135 {
136  TVirtualPad *thisPad = pad;
137  if (!thisPad) thisPad = qPad();
138  if (thisPad) {
139  TView *view = thisPad->GetView();
140  if (view) {
141  Int_t iret;
142  Float_t p = phi;
143  Float_t t = theta;
144  view->SetView(p, t, 0, iret);
145  thisPad->SetPhi(-90-p);
146  thisPad->SetTheta(90-t);
147  thisPad->Modified();
148  thisPad->Update();
149  }
150  }
151 }
152 
153 //_______________________________________________________________________________________
154 static void SideView(TVirtualPad *pad=0){
155  RotateView(0,90.0,pad);
156 }
157 //_______________________________________________________________________________________
158 static void FrontView(TVirtualPad *pad=0){
159  RotateView(270.0,90.0,pad);
160 }
161 //_______________________________________________________________________________________
162 static void TopView(TVirtualPad *pad=0){
163  RotateView(270.0,0.0,pad);
164 }
165 //_______________________________________________________________________________________
166 static void ToggleRulers(TVirtualPad *pad=0)
167 {
168  TAxis3D::ToggleRulers(pad);
169 }
170 
171 //_______________________________________________________________________________________
172 static void ToggleZoom(TVirtualPad *pad=0)
173 {
174  TAxis3D::ToggleZoom(pad);
175 }
176 
177 //_______________________________________________________________________________________
178 static void AddGrid()
179 {
180  TVirtualPad *thisPad = qPad();
181 
182  if (thisPad) {
183 
184  TView *view = thisPad->GetView();
185  if (!view) return;
186  Double_t min[3],max[3];
187  view->GetRange(min,max);
188 
189  TList *list = thisPad->GetListOfPrimitives();
190  TString histName = thisPad->GetName();
191  TH2F *m_DummyHist = 0;
192  const Char_t *dummyName = "Axis3D";
193  histName += dummyName;
194  m_DummyHist = list->FindObject(histName.Data());
195  if (!m_DummyHist) {
196  m_DummyHist = new TH2F(histName.Data(),"",1,min[0],max[0],1,min[1],max[1]);
197  m_DummyHist->SetDirectory(0);
198  m_DummyHist->Draw("surf,same");
199  }
200  m_DummyHist->GetXaxis()->SetLimits(min[0],max[0]);
201  m_DummyHist->GetYaxis()->SetLimits(min[1],max[1]);
202  m_DummyHist->GetZaxis()->SetLimits(min[2],max[2]);
203 
204  thisPad->Modified();
205  thisPad->Update();
206  }
207 }
208 //_______________________________________________________________________________________
209 static void AdjustScales()
210 {
211  TVirtualPad *thisPad = qPad();
212  if (thisPad) {
213  TView *view = thisPad->GetView();
214  if (!view) return;
215  Double_t min[3],max[3];
216  view->GetRange(min,max);
217  int i;
218  Double_t maxSide = 0;
219  // Find the largest side
220  for (i=0;i<3; i++) maxSide = TMath::Max(maxSide,max[i]-min[i]);
221  //Adjust scales:
222  for (i=0;i<3; i++) max[i] += maxSide - (max[i]-min[i]);
223  view->SetRange(min,max);
224  thisPad->Modified();
225  thisPad->Update();
226  }
227 }
228 //_______________________________________________________________________________________
229 static void Centered3DImages()
230 {
231  // This macro prints out the sizes of the sekected 3d pad
232  TVirtualPad *thisPad = qPad();
233  if (thisPad) {
234  TView *view = thisPad->GetView();
235  if (!view) return;
236  Double_t min[3],max[3];
237  view->GetRange(min,max);
238  int i;
239  for (i=0;i<3; i++) min[i]=-max[i];
240  view->SetRange(min,max);
241  thisPad->Modified();
242  thisPad->Update();
243  }
244 }
245 
246 //_______________________________________________________________________________________
247 static void Decrease3DScale()
248 {
249  TVirtualPad *thisPad = qPad();
250  if (thisPad) {
251  TView *view = thisPad->GetView();
252  if (!view) return;
253  Double_t min[3],max[3];
254  view->GetRange(min,max);
255  int i;
256  for (i=0;i<3; i++) {max[i] /= 0.8; min[i]=max[i]*0.1;}
257  view->SetRange(min,max);
258  thisPad->Modified();
259  thisPad->Update();
260  }
261 }
262 
263 //_______________________________________________________________________________________
264 static void Inscrease3DScale()
265 {
266  TVirtualPad *thisPad = qPad();
267  if (thisPad) {
268  TView *view = thisPad->GetView();
269  if (!view) return;
270  Double_t min[3],max[3];
271  view->GetRange(min,max);
272  int i;
273  for (i=0;i<3; i++) {max[i] *= 0.8; min[i]=max[i]*0.1;}
274  view->SetRange(min,max);
275  thisPad->Modified();
276  thisPad->Update();
277  }
278 }
279 //_______________________________________________________________________________________
280 void MakeFourView(TVirtualPad *pad=0)
281 {
282 // Creates 4 pads view of the pad (or qPad)
283 // ------------------------------
284 // | | |
285 // | | |
286 // | | |
287 // | Front | Top |
288 // | view | view |
289 // | | |
290 // | | |
291 // | | |
292 // ---------------+-------------
293 // | | |
294 // | | |
295 // | | |
296 // | Side | Spacial |
297 // | view | view |
298 // | | |
299 // | | |
300 // | | |
301 // ------------------------------
302 // begin_html <P ALIGN=CENTER> <IMG SRC="gif/FourStarView.gif" ></P> end_html
303 //
304  TVirtualPad *thisPad = pad;
305  if (!thisPad) thisPad = qPad();
306  TView *view = 0;
307  TList *thisPrimitives = 0;
308  if (thisPad && (thisPrimitives = thisPad->GetListOfPrimitives()) && (view = thisPad->GetView()) )
309  {
310  Double_t min[3],max[3];
311  view->GetRange(min,max);
312  Int_t system = view->GetSystem();
313  TCanvas *c = new TCanvas(" 4 views", thisPad->GetTitle(),600,600);
314  c->Divide(2,2);
315  TIter *next= new TIter(thisPrimitives);
316  for (int i =1; i <= 4; i++) {
317  c->cd(i);
318  TList *newPrimitives = qPad()->GetListOfPrimitives();
319  TObject *obj = 0;
320  while (obj = next->Next()) newPrimitives->Add(obj);
321  TView *newView = new TView(system);
322  newView->SetRange(min,max);
323  next->Reset();
324  }
325  delete next;
326  // set separate view;
327  // Fron view
328  Int_t j = 1;
329  c->cd(j++); FrontView();
330  c->cd(j++); TopView();
331  c->cd(j++); SideView();
332  c->cd(j++); RotateView(-30.0,60.0,0);
333  c->Modified();
334  c->Update();
335  }
336 }
337 //_______________________________________________________________________________________
338 void AddAxes(TVirtualPad *pad=0)
339 {
340  // Add red, green, blue - X, Y, Z axice to the "pad"
341  TVirtualPad *thisPad = pad;
342  if (!thisPad) thisPad = qPad();
343  if (thisPad) {
344  if (!gROOT->GetClass("St_PolyLine3D")) gSystem->Load("St_base");
345  if ( gROOT->GetClass("St_PolyLine3D")) gROOT->ProcessLineFast("St_PolyLine3D::Axis();");
346  }
347 }
348 };
349 
350 StPadControlPanel __StPadControlPanel__;
351 
352 
353 // $Log: PadControlPanel.C,v $
354 // Revision 1.20 2003/10/09 18:11:54 perev
355 // calculate gPad pointer
356 //
357 // Revision 1.19 2001/09/01 23:36:57 perev
358 // WindowName added
359 //
360 // Revision 1.18 2001/09/01 19:58:14 perev
361 // scripts for StEvent draw inside of StEventDisplayMaker
362 //
363 // Revision 1.17 2000/08/21 22:25:46 fine
364 // XYZ labels were added to the panel buttons
365 //
366 // Revision 1.16 2000/07/17 17:35:30 fine
367 // Adjusted to new ROOT requirements: float / double
368 //
369 // Revision 1.15 1999/12/09 20:42:47 fine
370 // Zoom
371 //
372 // Revision 1.14 1999/11/30 20:09:52 fine
373 // new static method to present rulers
374 //
375 // Revision 1.13 1999/11/30 03:00:00 fine
376 // Ruler button has been introduced
377 //
378 // Revision 1.12 1999/11/13 23:31:34 fine
379 // Constant kWhite has been replaced with number 19 due some bug wity 2.23
380 //
381 // Revision 1.11 1999/07/13 00:34:16 fine
382 // new button has been added to draw 3D axes
383 //
384 // Revision 1.10 1999/06/11 19:14:01 fine
385 // Some extra protections agaist of view == 0
386 //
387 // Revision 1.9 1999/06/11 18:17:55 fine
388 // View have been standardtized
389 //
390 // Revision 1.8 1999/06/11 01:27:37 fine
391 // TIter fixed
392 //
393 // Revision 1.7 1999/06/10 19:44:16 fine
394 // AdjustScale button jas been introduced
395 //
396 // Revision 1.6 1999/06/10 03:40:53 fine
397 // New button to draw 3D axice added
398 //
399 // Revision 1.5 1999/06/03 00:35:34 fine
400 // Comments clean up
401 //
402 // Revision 1.4 1999/06/03 00:27:53 fine
403 // 4 view control has been activated
404 //
405 // Revision 1.3 1999/06/02 22:25:12 fine
406 // 4 view command has been introduced
407 //
408 // Revision 1.2 1999/06/02 16:30:12 fine
409 // Clean up
410 //
411 // Revision 1.1 1999/05/29 20:55:11 fine
412 // macro to control any 3D view
413 //
414