Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
TSpiderEditor.cxx
Go to the documentation of this file.
1 // @(#)root/treeviewer:$Id$
2 // Author: Bastien Dalla Piazza 20/07/07
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2007, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 #include "TSpiderEditor.h"
13 #include "TSpider.h"
14 #include "TGFrame.h"
15 #include "TGButton.h"
16 #include "TGNumberEntry.h"
17 #include "TGButtonGroup.h"
18 #include <Riostream.h>
19 #include "TGLabel.h"
20 #include "TGPicture.h"
21 #include "TGTextEntry.h"
22 #include "TG3DLine.h"
23 #include "TGComboBox.h"
24 #include "TGColorSelect.h"
25 #include "TGedPatternSelect.h"
26 #include "TColor.h"
27 
28 ClassImp(TSpiderEditor);
29 
30 /** \class TSpiderEditor
31 The TSpider editor class.
32 Provides the graphical user interface to the spider plots.
33 */
34 
35 enum ESpiderWid {
36  kAverage,
37  kNx,
38  kNy,
39  kPolyLines,
40  kSegment,
41  kGotoEntry,
42  kPicNext,
43  kPicPrevious,
44  kPicFollowing,
45  kPicPreceding,
46  kAddVar,
47  kDeleteVar,
48  kAvLineStyle,
49  kAvLineColor,
50  kAvLineWidth,
51  kAvFillColor,
52  kAvFillStyle
53 };
54 
55 ////////////////////////////////////////////////////////////////////////////////
56 /// Normal constructor.
57 
58 TSpiderEditor::TSpiderEditor(const TGWindow* /*p*/, Int_t /*width*/, Int_t /*height*/, UInt_t /*options*/, Pixel_t /*back*/)
59 {
60  fPriority = 1;
61  MakeTitle("Spider");
62 
63  fBgroup = new TGButtonGroup(this,2,1,0,0, "Plot type");
64  fBgroup->SetRadioButtonExclusive(kTRUE);
65  fPolyLines = new TGRadioButton(fBgroup, "PolyLine", kPolyLines);
66  fPolyLines->SetToolTipText("Set a polyline plot type");
67  fSegment = new TGRadioButton(fBgroup, "Segment", kSegment);
68  fSegment->SetToolTipText("Set a segment plot type");
69  fBgroup->ChangeOptions(kFitWidth|kChildFrame);
70  AddFrame(fBgroup, new TGLayoutHints(kLHintsCenterY | kLHintsLeft, 4, 1, 0, 0));
71 
72  TGHorizontalFrame *f1 = new TGHorizontalFrame(this);
73 
74  TGLabel *nxLabel = new TGLabel(f1,"Nx:");
75  f1->AddFrame(nxLabel, new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 3, 0, 1, 1));
76  fSetNx = new TGNumberEntryField(f1, kNx, 2,
77  TGNumberFormat::kNESInteger,
78  TGNumberFormat::kNEAPositive,
79  TGNumberFormat::kNELLimitMinMax, 0, 99);
80  fSetNx->SetToolTipText("Set the X number of plots");
81  fSetNx->Resize(30,20);
82  f1->AddFrame(fSetNx, new TGLayoutHints(kLHintsLeft, 1, 1, 1, 1));
83 
84  TGLabel *nyLabel = new TGLabel(f1,"Ny:");
85  f1->AddFrame(nyLabel, new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 3, 0, 1, 1));
86  fSetNy = new TGNumberEntryField(f1, kNy, 2,
87  TGNumberFormat::kNESInteger,
88  TGNumberFormat::kNEAPositive,
89  TGNumberFormat::kNELLimitMinMax, 0, 99);
90  fSetNy->SetToolTipText("Set the Y number of plots");
91  fSetNy->Resize(30,20);
92  f1->AddFrame(fSetNy, new TGLayoutHints(kLHintsLeft, 1, 1, 1, 1));
93  AddFrame(f1, new TGLayoutHints(kLHintsLeft,1,1,1,1));
94 
95  MakeTitle("Average");
96 
97  fDisplayAverage = new TGCheckButton(this, "Average",kAverage);
98  fDisplayAverage->SetToolTipText("Display average");
99  AddFrame(fDisplayAverage, new TGLayoutHints(kLHintsTop, 3, 1, 1, 1));
100 
101  TGHorizontalFrame *f2 = new TGHorizontalFrame(this);
102 
103  fAvLineColorSelect = new TGColorSelect(f2, 0, kAvLineColor);
104  f2->AddFrame(fAvLineColorSelect, new TGLayoutHints(kLHintsLeft, 1, 1, 1, 1));
105 
106  fAvLineWidthCombo = new TGLineWidthComboBox(f2, kAvLineWidth);
107  fAvLineWidthCombo->Resize(91, 20);
108  f2->AddFrame(fAvLineWidthCombo, new TGLayoutHints(kLHintsLeft, 3, 1, 1, 1));
109 
110  AddFrame(f2, new TGLayoutHints(kLHintsTop, 1, 1, 0, 0));
111 
112  fAvLineStyleCombo = new TGLineStyleComboBox(this, kAvLineStyle);
113  fAvLineStyleCombo->Resize(137, 20);
114  AddFrame(fAvLineStyleCombo, new TGLayoutHints(kLHintsLeft, 3, 1, 1, 1));
115 
116  TGHorizontalFrame *f2b = new TGHorizontalFrame(this);
117 
118  fAvFillColorSelect = new TGColorSelect(f2b, 0, kAvFillColor);
119  f2b->AddFrame(fAvFillColorSelect, new TGLayoutHints(kLHintsLeft, 1, 1, 1, 1));
120 
121  fAvFillPatternSelect = new TGedPatternSelect(f2b, 1, kAvFillStyle);
122  f2b->AddFrame(fAvFillPatternSelect, new TGLayoutHints(kLHintsLeft, 1, 1, 1, 1));
123 
124  AddFrame(f2b, new TGLayoutHints(kLHintsTop, 1, 1, 0, 0));
125 
126  MakeBrowse();
127 }
128 
129 ////////////////////////////////////////////////////////////////////////////////
130 /// Destructor of the TSpiderEditor.
131 
132 TSpiderEditor::~TSpiderEditor()
133 {
134  delete fPolyLines;
135  delete fSegment;
136 }
137 
138 ////////////////////////////////////////////////////////////////////////////////
139 /// Connect signals to slots.
140 
141 void TSpiderEditor::ConnectSignals2Slots()
142 {
143  fDisplayAverage->Connect("Toggled(Bool_t)", "TSpiderEditor", this, "DoDisplayAverage(Bool_t)");
144  fSetNx->Connect("ReturnPressed()", "TSpiderEditor", this, "DoSetNx()");
145  fSetNy->Connect("ReturnPressed()", "TSpiderEditor", this, "DoSetNy()");
146  fBgroup->Connect("Clicked(Int_t)","TSpiderEditor",this,"DoSetPlotType()");
147  fGotoEntry->Connect("ReturnPressed()", "TSpiderEditor", this, "DoGotoEntry()");
148  fGotoNext->Connect("Clicked()","TSpiderEditor",this,"DoGotoNext()");
149  fGotoPrevious->Connect("Clicked()","TSpiderEditor",this,"DoGotoPrevious()");
150  fGotoFollowing->Connect("Clicked()","TSpiderEditor",this,"DoGotoFollowing()");
151  fGotoPreceding->Connect("Clicked()","TSpiderEditor",this,"DoGotoPreceding()");
152  fAddVar->Connect("ReturnPressed()","TSpiderEditor",this,"DoAddVar()");
153  fDeleteVar->Connect("ReturnPressed()","TSpiderEditor",this,"DoDeleteVar()");
154  fAvLineStyleCombo->Connect("Selected(Int_t)", "TSpiderEditor", this, "DoAvLineStyle(Int_t)");
155  fAvLineWidthCombo->Connect("Selected(Int_t)", "TSpiderEditor", this, "DoAvLineWidth(Int_t)");
156  fAvLineColorSelect->Connect("ColorSelected(Pixel_t)", "TSpiderEditor", this, "DoAvLineColor(Pixel_t)");
157  fAvFillColorSelect->Connect("ColorSelected(Pixel_t)", "TSpiderEditor", this, "DoAvFillColor(Pixel_t)");
158  fAvFillPatternSelect->Connect("PatternSelected(Style_t)", "TSpiderEditor", this, "DoAvFillPattern(Style_t)");
159 
160  fInit = kFALSE;
161 }
162 
163 ////////////////////////////////////////////////////////////////////////////////
164 /// Make the Browse tab.
165 
166 void TSpiderEditor::MakeBrowse()
167 {
168  fBrowse = CreateEditorTabSubFrame("Browse");
169 
170  TGHorizontalFrame *title1 = new TGHorizontalFrame(fBrowse);
171  title1->AddFrame(new TGLabel(title1, "Entries"),
172  new TGLayoutHints(kLHintsLeft, 3, 1, 0, 0));
173  title1->AddFrame(new TGHorizontal3DLine(title1),
174  new TGLayoutHints(kLHintsExpandX, 5, 5, 7, 7));
175  fBrowse->AddFrame(title1, new TGLayoutHints(kLHintsExpandX, 0, 0, 2, 0));
176 
177  TGHorizontalFrame *f3 = new TGHorizontalFrame(fBrowse);
178 
179  TGLabel *gotoEntryLabel = new TGLabel(f3,"Go to:");
180  f3->AddFrame(gotoEntryLabel, new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 3, 18, 1, 5));
181  fGotoEntry = new TGNumberEntryField(f3, kGotoEntry, 0,
182  TGNumberFormat::kNESInteger,
183  TGNumberFormat::kNEANonNegative);
184  fGotoEntry->SetToolTipText("Jump to a specified entry");
185  fGotoEntry->Resize(60,20);
186  f3->AddFrame(fGotoEntry, new TGLayoutHints(kLHintsRight, 1, 1, 1, 1));
187 
188  fBrowse->AddFrame(f3,new TGLayoutHints(kLHintsLeft | kLHintsCenterY));
189 
190  TGHorizontalFrame *f2 = new TGHorizontalFrame(fBrowse);
191 
192  fPicPrevious = gClient->GetPicture("first_t.xpm");
193  fGotoPrevious = new TGPictureButton(f2,fPicPrevious,kPicPrevious);
194  fGotoPrevious->SetToolTipText("Jump to the last entries");
195  f2->AddFrame(fGotoPrevious,new TGLayoutHints(kLHintsCenterX | kLHintsBottom, 1, 1, 1, 1));
196 
197  fPicPreceding = gClient->GetPicture("previous_t.xpm");
198  fGotoPreceding = new TGPictureButton(f2,fPicPreceding,kPicPreceding);
199  fGotoPreceding->SetToolTipText("Jump to the last entries");
200  f2->AddFrame(fGotoPreceding,new TGLayoutHints(kLHintsCenterX | kLHintsBottom, 1, 1, 1, 1));
201 
202  fPicFollowing = gClient->GetPicture("next_t.xpm");
203  fGotoFollowing = new TGPictureButton(f2,fPicFollowing,kPicFollowing);
204  fGotoFollowing->SetToolTipText("Jump to the last entries");
205  f2->AddFrame(fGotoFollowing,new TGLayoutHints(kLHintsCenterX | kLHintsBottom, 1, 1, 1, 1));
206 
207  fPicNext = gClient->GetPicture("last_t.xpm");
208  fGotoNext = new TGPictureButton(f2,fPicNext,kPicNext);
209  fGotoNext->SetToolTipText("Jump to the next entries");
210  f2->AddFrame(fGotoNext,new TGLayoutHints(kLHintsCenterX | kLHintsBottom, 1, 1, 1, 1));
211 
212  fBrowse->AddFrame(f2,new TGLayoutHints(kLHintsCenterX | kLHintsCenterY));
213 
214  TGHorizontalFrame *title2 = new TGHorizontalFrame(fBrowse);
215 
216  title2->AddFrame(new TGLabel(title2, "Variables"),
217  new TGLayoutHints(kLHintsLeft, 3, 1, 0, 0));
218  title2->AddFrame(new TGHorizontal3DLine(title2),
219  new TGLayoutHints(kLHintsExpandX, 5, 5, 7, 7));
220  fBrowse->AddFrame(title2, new TGLayoutHints(kLHintsExpandX, 0, 0, 2, 0));
221 
222  TGHorizontalFrame *f4 = new TGHorizontalFrame(fBrowse);
223 
224  TGVerticalFrame *v1 = new TGVerticalFrame(f4);
225 
226  TGLabel *addVar = new TGLabel(v1,"Add:");
227  v1->AddFrame(addVar,new TGLayoutHints(kLHintsLeft | kLHintsCenterY));
228 
229  TGLabel *deleteVar = new TGLabel(v1,"Delete:");
230  v1->AddFrame(deleteVar,new TGLayoutHints(kLHintsLeft | kLHintsCenterY));
231 
232  f4->AddFrame(v1, new TGLayoutHints(kLHintsLeft | kLHintsTop,5,5,0,0));
233 
234  TGVerticalFrame *v2 = new TGVerticalFrame(f4);
235 
236  fAddVar = new TGTextEntry(v2, new TGTextBuffer(50), kAddVar);
237  fAddVar->Resize(60,20);
238  fAddVar->SetToolTipText("Add a variable");
239  v2->AddFrame(fAddVar, new TGLayoutHints(kLHintsRight | kLHintsTop));
240 
241  fDeleteVar = new TGTextEntry(v2, new TGTextBuffer(50), kAddVar);
242  fDeleteVar->Resize(60,20);
243  fDeleteVar->SetToolTipText("Delete a variable");
244  v2->AddFrame(fDeleteVar, new TGLayoutHints(kLHintsRight | kLHintsTop));
245 
246  f4->AddFrame(v2, new TGLayoutHints(kLHintsLeft | kLHintsTop,5,5,0,0));
247 
248  fBrowse->AddFrame(f4, new TGLayoutHints(kLHintsLeft | kLHintsCenterY));
249 }
250 
251 ////////////////////////////////////////////////////////////////////////////////
252 /// Pick up the used spider attributes.
253 
254 void TSpiderEditor::SetModel(TObject* obj)
255 {
256  if (!obj) return;
257  fSpider = dynamic_cast<TSpider*>(obj);
258  if (!fSpider) return;
259  fAvoidSignal = kTRUE;
260 
261  Bool_t av = fSpider->GetDisplayAverage();
262  if(av) fDisplayAverage->SetState(kButtonDown);
263  else fDisplayAverage->SetState(kButtonUp);
264 
265  fSetNx->SetNumber(fSpider->GetNx());
266  fSetNy->SetNumber(fSpider->GetNy());
267 
268  Bool_t seg = fSpider->GetSegmentDisplay();
269 
270  if(seg) fBgroup->SetButton(kSegment,kTRUE);
271  else fBgroup->SetButton(kPolyLines,kTRUE);
272 
273  fGotoEntry->SetNumber(fSpider->GetCurrentEntry());
274 
275  fAddVar->SetText("");
276  fDeleteVar->SetText("");
277 
278  fAvLineStyleCombo->Select(fSpider->GetAverageLineStyle());
279  fAvLineWidthCombo->Select(fSpider->GetAverageLineWidth());
280  Color_t c = fSpider->GetAverageLineColor();
281  Pixel_t p = TColor::Number2Pixel(c);
282  fAvLineColorSelect->SetColor(p);
283  c = fSpider->GetAverageFillColor();
284  p = TColor::Number2Pixel(c);
285  fAvFillColorSelect->SetColor(p,kFALSE);
286  fAvFillPatternSelect->SetPattern(fSpider->GetAverageFillStyle(),kFALSE);
287 
288  if (fInit) ConnectSignals2Slots();
289 
290  fAvoidSignal = kFALSE;
291 }
292 
293 ////////////////////////////////////////////////////////////////////////////////
294 /// Slot to add a variable.
295 
296 void TSpiderEditor::DoAddVar()
297 {
298  if (fAvoidSignal) return;
299 
300  const char * var = fAddVar->GetText();
301  fSpider->AddVariable(var);
302  Update();
303 }
304 
305 ////////////////////////////////////////////////////////////////////////////////
306 /// Slot to set the average LineStyle.
307 
308 void TSpiderEditor::DoAvLineStyle(Int_t a)
309 {
310  if (fAvoidSignal) return;
311 
312  fSpider->SetAverageLineStyle(a);
313  Update();
314 }
315 
316 ////////////////////////////////////////////////////////////////////////////////
317 /// Slot to set the average LineWidth.
318 
319 void TSpiderEditor::DoAvLineWidth(Int_t a)
320 {
321  if (fAvoidSignal) return;
322 
323  fSpider->SetAverageLineWidth(a);
324  Update();
325 }
326 
327 ////////////////////////////////////////////////////////////////////////////////
328 /// Slot to set the average LineColor.
329 
330 void TSpiderEditor::DoAvLineColor(Pixel_t a)
331 {
332  if (fAvoidSignal) return;
333 
334  fSpider->SetAverageLineColor(TColor::GetColor(a));
335  Update();
336 }
337 
338 ////////////////////////////////////////////////////////////////////////////////
339 /// Slot to set the average Fill Color.
340 
341 void TSpiderEditor::DoAvFillColor(Pixel_t a)
342 {
343  if (fAvoidSignal) return;
344 
345  fSpider->SetAverageFillColor(TColor::GetColor(a));
346  Update();
347 }
348 
349 ////////////////////////////////////////////////////////////////////////////////
350 /// Slot to set the average FillStyle.
351 
352 void TSpiderEditor::DoAvFillPattern(Style_t a)
353 {
354  if (fAvoidSignal) return;
355 
356  fSpider->SetAverageFillStyle(a);
357  Update();
358 }
359 
360 ////////////////////////////////////////////////////////////////////////////////
361 /// Slot to delete a variable.
362 
363 void TSpiderEditor::DoDeleteVar()
364 {
365  if (fAvoidSignal) return;
366 
367  const char * var = fDeleteVar->GetText();
368  fSpider->DeleteVariable(var);
369  Update();
370 }
371 
372 ////////////////////////////////////////////////////////////////////////////////
373 /// Slot Connected to the average display.
374 
375 void TSpiderEditor::DoDisplayAverage(Bool_t av)
376 {
377  if (fAvoidSignal) return;
378 
379  fSpider->SetDisplayAverage(av);
380  Update();
381 }
382 
383 ////////////////////////////////////////////////////////////////////////////////
384 /// Slot to select an entry by number.
385 
386 void TSpiderEditor::DoGotoEntry()
387 {
388  if (fAvoidSignal) return;
389  Long64_t ev = (Long64_t)fGotoEntry->GetNumber();
390  fSpider->GotoEntry(ev);
391  Update();
392 }
393 
394 ////////////////////////////////////////////////////////////////////////////////
395 /// Slot to Go to next entries.
396 
397 void TSpiderEditor::DoGotoNext()
398 {
399  if (fAvoidSignal) return;
400  fSpider->GotoNext();
401  Update();
402 }
403 
404 ////////////////////////////////////////////////////////////////////////////////
405 /// Slot to go to previous entries.
406 
407 void TSpiderEditor::DoGotoPrevious()
408 {
409  if (fAvoidSignal) return;
410  fSpider->GotoPrevious();
411  Update();
412 }
413 
414 ////////////////////////////////////////////////////////////////////////////////
415 /// Slot to go to next entry.
416 
417 void TSpiderEditor::DoGotoFollowing()
418 {
419  if (fAvoidSignal) return;
420  fSpider->GotoFollowing();
421  Update();
422 }
423 
424 ////////////////////////////////////////////////////////////////////////////////
425 /// Slot to go to last entry.
426 
427 void TSpiderEditor::DoGotoPreceding()
428 {
429  if (fAvoidSignal) return;
430  fSpider->GotoPreceding();
431  Update();
432 }
433 
434 ////////////////////////////////////////////////////////////////////////////////
435 /// Slot connected to the nx setting.
436 
437 void TSpiderEditor::DoSetNx()
438 {
439  if (fAvoidSignal) return;
440  UInt_t nx = (UInt_t)fSetNx->GetNumber();
441  fSpider->SetNx(nx);
442  Update();
443 }
444 
445 ////////////////////////////////////////////////////////////////////////////////
446 /// Slot connected to the nx setting.
447 
448 void TSpiderEditor::DoSetNy()
449 {
450  if (fAvoidSignal) return;
451  UInt_t ny = (UInt_t)fSetNy->GetNumber();
452  fSpider->SetNy(ny);
453  Update();
454 }
455 
456 ////////////////////////////////////////////////////////////////////////////////
457 /// Slot to set the plot type.
458 
459 void TSpiderEditor::DoSetPlotType()
460 {
461  if(fSegment->GetState() == kButtonDown) fSpider->SetSegmentDisplay(kTRUE);
462  else fSpider->SetSegmentDisplay(kFALSE);
463  Update();
464 }