ROOT  6.06/09
Reference Guide
TF1Editor.cxx
Go to the documentation of this file.
1 // @(#)root/ged:$Id$
2 // Author: Ilka Antcheva 21/03/06
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2004, 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 //////////////////////////////////////////////////////////////////////////
13 // //
14 // TF1Editor //
15 // //
16 // GUI for TF1 attributes and parameters. //
17 // //
18 //////////////////////////////////////////////////////////////////////////
19 
20 #include "TF1Editor.h"
21 #include "TGedEditor.h"
22 #include "TH1.h"
23 #include "TF1.h"
24 #include "TGTextEntry.h"
25 #include "TGToolTip.h"
26 #include "TGLabel.h"
27 #include "TGDoubleSlider.h"
28 #include "TString.h"
29 #include "TGNumberEntry.h"
30 #include "TG3DLine.h"
32 #include "TCanvas.h"
33 
34 
36 
37 enum ETF1Wid {
38  kTF1_TIT, kTF1_NPX,
39  kTF1_XSLD, kTF1_XMIN, kTF1_XMAX,
40  kTF1_PAR, kTF1_DRW
41 };
42 
43 TF1Editor::TF1Editor(const TGWindow *p, Int_t width, Int_t height,
44  UInt_t options, Pixel_t back)
45  : TGedFrame(p, width, height, options | kVerticalFrame, back)
46 {
47  // Constructor of TF1 editor.
48 
49  MakeTitle("Function");
50 
51  fTitle = new TGTextEntry(this, new TGTextBuffer(50), kTF1_TIT);
54  fTitle->SetToolTipText(Form("Function expression or predefined name"));
55  AddFrame(fTitle, new TGLayoutHints(kLHintsLeft,3, 2, 2, 3));
56 
57  TGCompositeFrame *f3a = new TGCompositeFrame(this, 137, 20, kHorizontalFrame);
58  AddFrame(f3a, new TGLayoutHints(kLHintsTop, 0, 1, 3, 0));
59  fDrawMode = new TGCheckButton(f3a, "Update", kTF1_DRW);
60  fDrawMode->SetToolTipText("Immediate function redrawing");
61  f3a->AddFrame(fDrawMode, new TGLayoutHints(kLHintsLeft | kLHintsBottom, 3, 1, 1, 0));
62  fParLabel = new TGLabel(f3a, "");
63  f3a->AddFrame(fParLabel, new TGLayoutHints(kLHintsRight | kLHintsBottom, 25, 2, 1, 0));
64 
66  fSetPars = new TGTextButton(f3, "Set Parameters...", kTF1_PAR);
68  0, 1, 5, 0));
69  fSetPars->SetToolTipText("Open a dialog for parameter(s) settings");
70  AddFrame(f3, new TGLayoutHints(kLHintsTop | kLHintsLeft, 3, 2, 2, 3));
71 
72  MakeTitle("X-Range");
73 
74  TGCompositeFrame *f4 = new TGCompositeFrame(this, 80, 20, kHorizontalFrame);
76  TGLabel *fNpxLabel = new TGLabel(f4a, "Points: ");
77  f4a->AddFrame(fNpxLabel, new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 3, 0, 5, 1));
78  f4->AddFrame(f4a, new TGLayoutHints(kLHintsTop | kLHintsLeft, 0, 1, 0, 0));
79 
80  TGCompositeFrame *f4b = new TGCompositeFrame(f4, 40, 20, kVerticalFrame);
81  fNXpoints = new TGNumberEntry(f4b, 100, 7, kTF1_NPX,
85  fNXpoints->GetNumberEntry()->SetToolTipText("Points along x-axis (4-100 000)");
86  f4b->AddFrame(fNXpoints, new TGLayoutHints(kLHintsLeft, 0, 0, 1, 0));
87  f4->AddFrame(f4b, new TGLayoutHints(kLHintsTop | kLHintsRight, 0, 1, 0, 0));
88  AddFrame(f4, new TGLayoutHints(kLHintsTop | kLHintsLeft, 0, 1, 0, 0));
89 
90  TGCompositeFrame *f5 = new TGCompositeFrame(this, 80, 20, kHorizontalFrame);
91  fSliderX = new TGDoubleHSlider(f5, 1, 2);
92  fSliderX->Resize(137,20);
94  AddFrame(f5, new TGLayoutHints(kLHintsTop, 3, 7, 4, 1));
95 
96  TGCompositeFrame *f6 = new TGCompositeFrame(this, 80, 20, kHorizontalFrame);
97  fSldMinX = new TGNumberEntryField(f6, kTF1_XMIN, 0.0,
100  ((TGTextEntry*)fSldMinX)->SetToolTipText("Lower bound along x-axis");
101  fSldMinX->Resize(65,20);
104  fSldMaxX = new TGNumberEntryField(f6, kTF1_XMAX, 0.0,
107  ((TGTextEntry*)fSldMaxX)->SetToolTipText("Upper bound along x-axis");
109  fSldMaxX->Resize(65,20);
110  f6->AddFrame(fSldMaxX, new TGLayoutHints(kLHintsLeft, 4, 0, 0, 0));
111  AddFrame(f6, new TGLayoutHints(kLHintsTop, 3, 3, 5, 0));
112 }
113 
114 ////////////////////////////////////////////////////////////////////////////////
115 /// Destructor of TF1 editor.
116 
118 {
119 }
120 
121 ////////////////////////////////////////////////////////////////////////////////
122 /// Connect signals to slots.
123 
125 {
126  fNXpoints->Connect("ValueSet(Long_t)", "TF1Editor", this, "DoXPoints()");
127  (fNXpoints->GetNumberEntry())->Connect("ReturnPressed()", "TF1Editor",
128  this, "DoXPoints()");
129  fSetPars->Connect("Clicked()", "TF1Editor", this, "DoParameterSettings()");
130  fSliderX->Connect("Pressed()","TF1Editor", this,"DoSliderXPressed()");
131  fSliderX->Connect("Released()","TF1Editor", this,"DoSliderXReleased()");
132  fSliderX->Connect("PositionChanged()","TF1Editor", this,"DoSliderXMoved()");
133 
134  fInit = kFALSE;
135 }
136 
137 ////////////////////////////////////////////////////////////////////////////////
138 /// Pick up the function parameters and options.
139 
141 {
142  if (obj == 0 || !obj->InheritsFrom(TF1::Class())) {
143  return;
144  }
145 
146  fF1 = (TF1*)obj;
148 
149  const char *text = fF1->GetTitle();
150  fTitle->SetText(text);
151 
152  fNP = fF1->GetNpar();
153  fParLabel->SetText(Form("Npar: %d", fNP));
155 
157 
158  if (!fNP)
160  else
162 
163  TAxis *x = fF1->GetHistogram()->GetXaxis();
164  Int_t nx = x->GetNbins();
165  Int_t nxbinmin = x->GetFirst();
166  Int_t nxbinmax = x->GetLast();
167  fSliderX->SetRange(1,nx);
168  fSliderX->SetPosition((Double_t)nxbinmin,(Double_t)nxbinmax);
169  fSldMinX->SetNumber(x->GetBinLowEdge(nxbinmin));
170  fSldMaxX->SetNumber(x->GetBinUpEdge(nxbinmax));
171 
174 }
175 
176 ////////////////////////////////////////////////////////////////////////////////
177 /// Slot connected to the function parameter(s) settings.
178 
180 {
182  Double_t rmin = fSldMinX->GetNumber();
183  Double_t rmax = fSldMaxX->GetNumber();
184  new TFunctionParametersDialog(gClient->GetDefaultRoot(), main,
185  fF1, fGedEditor->GetPad(), rmin, rmax);
186 
187 }
188 
189 ////////////////////////////////////////////////////////////////////////////////
190 /// Slot connected to the number of points setting.
191 
193 {
194  if (fAvoidSignal) return;
195  Double_t rmin, rmax;
196  fF1->GetRange(rmin, rmax);
200  fSldMinX->GetNumber(),
201  fSldMaxX->GetNumber());
202  Update();
203  fF1->SetRange(rmin, rmax);
204 }
205 
206 ////////////////////////////////////////////////////////////////////////////////
207 /// Slot connected to the x-Slider range for function redrawing.
208 
210 {
211  if (fAvoidSignal) return;
212 
213  TVirtualPad *save = 0;
214  save = gPad;
215  gPad = fGedEditor->GetPad();
216  fGedEditor->GetPad()->cd();
217 
219  TAxis *x = fF1->GetHistogram()->GetXaxis();
220 
221  if (fDrawMode->GetState() == kButtonDown) {
222  TString opt = fF1->GetDrawOption();
223  opt.ToUpper();
224  if (!opt.Contains("SAME"))
225  opt += "SAME";
226  fF1->Draw(opt);
227 
228  x->SetRange((Int_t)((fSliderX->GetMinPosition())+0.5),
229  (Int_t)((fSliderX->GetMaxPosition())+0.5));
235  Update();
236 
237  } else {
238  x->SetRange((Int_t)((fSliderX->GetMinPosition())+0.5),
239  (Int_t)((fSliderX->GetMaxPosition())+0.5));
245  }
246  if(save) gPad = save;
247 }
248 
249 ////////////////////////////////////////////////////////////////////////////////
250 /// Slot connected to the x-Slider.
251 
253 {
254  if (fAvoidSignal || (fDrawMode->GetState() == kButtonDown)) return;
255 
256  TVirtualPad *save = 0;
257  save = gPad;
258  gPad = fGedEditor->GetPad();
259  fGedEditor->GetPad()->cd();
260 
262  TAxis *x = fF1->GetHistogram()->GetXaxis();
263  TString opt = fF1->GetDrawOption();
264  opt.ToUpper();
265  if (!opt.Contains("SAME"))
266  opt += "SAME";
267  fF1->Draw(opt);
268 
269  x->SetRange((Int_t)((fSliderX->GetMinPosition())+0.5),
270  (Int_t)((fSliderX->GetMaxPosition())+0.5));
276  Update();
277 
278  if(save) gPad = save;
279 
280 }
281 
282 ////////////////////////////////////////////////////////////////////////////////
283 /// Slot connected to the x-Slider.
284 
286 {
287  if (fAvoidSignal || (fDrawMode->GetState() == kButtonDown)) return;
288 
289  TVirtualPad *save = 0;
290  save = gPad;
291  gPad = fGedEditor->GetPad();
292  fGedEditor->GetPad()->cd();
293 
295  TAxis *x = fF1->GetHistogram()->GetXaxis();
296  TString opt = fF1->GetDrawOption();
297  opt.ToUpper();
298  if (!opt.Contains("SAME"))
299  opt += "SAME";
300  fF1->Draw(opt);
301 
302  x->SetRange((Int_t)((fSliderX->GetMinPosition())+0.5),
303  (Int_t)((fSliderX->GetMaxPosition())+0.5));
309  Update();
310 
311  if(save) gPad = save;
312 }
313 
314 
315 ////////////////////////////////////////////////////////////////////////////////
316 /// Slot connected to min/max settings of the slider range.
317 
319 {
320  if (fAvoidSignal) return;
321  TAxis *x = fF1->GetHistogram()->GetXaxis();
322  Int_t nx = x->GetNbins();
323  Double_t width = x->GetBinWidth(1);
324  Double_t lowLimit = x->GetBinLowEdge(1);
325  Double_t upLimit = x->GetBinUpEdge(nx);
326  if ((fSldMinX->GetNumber()+width/2) < (lowLimit))
327  fSldMinX->SetNumber(lowLimit);
328  if ((fSldMaxX->GetNumber()-width/2) > (upLimit))
329  fSldMaxX->SetNumber(upLimit);
330  x->SetRangeUser(fSldMinX->GetNumber()+width/2,
331  fSldMaxX->GetNumber()-width/2);
332  Int_t nxbinmin = x->GetFirst();
333  Int_t nxbinmax = x->GetLast();
334  fSliderX->SetPosition((Double_t)(nxbinmin),(Double_t)(nxbinmax));
335  Update();
336 }
337 
338 ////////////////////////////////////////////////////////////////////////////////
339 /// Exclude TAttFillEditor from this interface.
340 
342 {
345 }
346 
const int nx
Definition: kalman.C:16
virtual void DoXPoints()
Slot connected to the number of points setting.
Definition: TF1Editor.cxx:192
Int_t GetFirst() const
Return first bin on the axis i.e.
Definition: TAxis.cxx:429
virtual const char * GetTitle() const
Returns title of object.
Definition: TNamed.h:52
virtual void DoSliderXReleased()
Slot connected to the x-Slider.
Definition: TF1Editor.cxx:285
virtual void Resize(UInt_t w=0, UInt_t h=0)
Resize the frame.
Definition: TGFrame.cxx:587
TF1 * fF1
Definition: TF1Editor.h:39
virtual void DoParameterSettings()
Slot connected to the function parameter(s) settings.
Definition: TF1Editor.cxx:179
virtual void SetNpx(Int_t npx=100)
Set the number of points used to draw the function.
Definition: TF1.cxx:3139
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition: TObject.cxx:487
virtual void SetState(Bool_t state)
Set the active state.
virtual void DoXRange()
Slot connected to min/max settings of the slider range.
Definition: TF1Editor.cxx:318
virtual void SetToolTipText(const char *text, Long_t delayms=500)
Set tool tip text associated with this text entry.
ClassImp(TF1Editor) enum ETF1Wid
Definition: TF1Editor.cxx:35
virtual void DoSliderXPressed()
Slot connected to the x-Slider.
Definition: TF1Editor.cxx:252
virtual void SetRange(Double_t xmin, Double_t xmax)
Initialize the upper and lower bounds to draw the function.
Definition: TF1.cxx:3223
virtual void SetNumber(Double_t val)
void ToUpper()
Change string to upper case.
Definition: TString.cxx:1101
virtual Double_t GetBinLowEdge(Int_t bin) const
Return low edge of bin.
Definition: TAxis.cxx:489
Basic string class.
Definition: TString.h:137
#define gClient
Definition: TGClient.h:174
TGTextEntry * fTitle
Definition: TF1Editor.h:40
int Int_t
Definition: RtypesCore.h:41
virtual TVirtualPad * GetPad() const
Definition: TGedEditor.h:97
const Bool_t kFALSE
Definition: Rtypes.h:92
virtual Double_t GetBinWidth(Int_t bin) const
Return bin width.
Definition: TAxis.cxx:511
virtual void Draw(Option_t *option="")
Draw this function with its current attributes.
Definition: TF1.cxx:1075
void ExcludeClassEditor(TClass *cl, Bool_t recurse=kFALSE)
Exclude editor for class cl from current construction.
Definition: TGedEditor.cxx:578
virtual void SetRange(Float_t min, Float_t max)
virtual TVirtualPad * cd(Int_t subpadnumber=0)=0
virtual TH1 * GetHistogram() const
Return a pointer to the histogram used to vusualize the function.
Definition: TF1.cxx:1297
virtual void SetRangeUser(Double_t ufirst, Double_t ulast)
Set the viewing range for the axis from ufirst to ulast (in user coordinates).
Definition: TAxis.cxx:869
virtual void SetModel(TObject *obj)
Pick up the function parameters and options.
Definition: TF1Editor.cxx:140
Double_t x[n]
Definition: legend1.C:17
TGTextButton * fSetPars
Definition: TF1Editor.h:44
Bool_t fAvoidSignal
Definition: TGedFrame.h:58
TGNumberEntryField * GetNumberEntry() const
ULong_t Pixel_t
Definition: GuiTypes.h:41
void Class()
Definition: Class.C:29
virtual Option_t * GetDrawOption() const
Get option used by the graphics system to draw this object.
Definition: TObject.cxx:399
virtual void SetText(TGString *newText)
Set new text in label.
Definition: TGLabel.cxx:177
virtual void Update()
Update the current pad when an attribute is changed via GUI.
Definition: TGedFrame.cxx:73
TGCompositeFrame(const TGCompositeFrame &)
TF1Editor(const TGWindow *p=0, Int_t width=140, Int_t height=30, UInt_t options=kChildFrame, Pixel_t back=GetDefaultFrameBackground())
Definition: TF1Editor.cxx:43
virtual void GetRange(Double_t *xmin, Double_t *xmax) const
Return range of a generic N-D function.
Definition: TF1.cxx:1976
TVirtualPad is an abstract base class for the Pad and Canvas classes.
Definition: TVirtualPad.h:59
virtual void ActivateBaseClassEditors(TClass *cl)
Exclude TAttFillEditor from this interface.
Definition: TF1Editor.cxx:341
Bool_t Connect(const char *signal, const char *receiver_class, void *receiver, const char *slot)
Non-static method is used to connect from the signal of this object to the receiver slot...
Definition: TQObject.cxx:1135
virtual void SetRange(Int_t first=0, Int_t last=0)
Set the viewing range for the axis from bin first to last.
Definition: TAxis.cxx:831
Class to manage histogram axis.
Definition: TAxis.h:36
virtual EButtonState GetState() const
Definition: TGButton.h:116
Int_t GetNbins() const
Definition: TAxis.h:125
virtual Double_t GetBinUpEdge(Int_t bin) const
Return up edge of bin.
Definition: TAxis.cxx:499
virtual void DoSliderXMoved()
Slot connected to the x-Slider range for function redrawing.
Definition: TF1Editor.cxx:209
unsigned int UInt_t
Definition: RtypesCore.h:42
char * Form(const char *fmt,...)
virtual Double_t GetNumber() const
Get the numeric value (floating point representation).
The ROOT global object gROOT contains a list of all defined classes.
Definition: TClass.h:81
TGLabel * fParLabel
Definition: TF1Editor.h:42
TGNumberEntryField * fSldMinX
Definition: TF1Editor.h:47
virtual void ConnectSignals2Slots()
Connect signals to slots.
Definition: TF1Editor.cxx:124
virtual const TGWindow * GetMainFrame() const
Returns top level main frame.
Definition: TGWindow.cxx:133
virtual Int_t GetNpx() const
Definition: TF1.h:352
int main(int argc, char *argv[])
Definition: python64.c:14
void SetEnabled(Bool_t flag=kTRUE)
Definition: TGTextEntry.h:170
double Double_t
Definition: RtypesCore.h:55
TText * text
virtual void AddFrame(TGFrame *f, TGLayoutHints *l=0)
Add frame to the composite frame using the specified layout hints.
Definition: TGFrame.cxx:1099
Int_t fNP
Definition: TF1Editor.h:41
Int_t GetLast() const
Return last bin on the axis i.e.
Definition: TAxis.cxx:440
Mother of all ROOT objects.
Definition: TObject.h:58
virtual ~TF1Editor()
Destructor of TF1 editor.
Definition: TF1Editor.cxx:117
Bool_t fInit
Definition: TGedFrame.h:55
virtual void SetNumber(Double_t val)
Set the numeric value (floating point representation).
virtual UInt_t GetDefaultHeight() const
Definition: TGFrame.h:254
TGCheckButton * fDrawMode
Definition: TF1Editor.h:43
TGClient * fClient
Definition: TGObject.h:41
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition: TString.h:567
1-Dim function class
Definition: TF1.h:149
virtual void SetPosition(Float_t min, Float_t max)
void NeedRedraw(TGWindow *w, Bool_t force=kFALSE)
Set redraw flags.
Definition: TGClient.cxx:370
#define gPad
Definition: TVirtualPad.h:288
virtual Float_t GetMinPosition() const
TGNumberEntry * fNXpoints
Definition: TF1Editor.h:45
virtual Double_t GetNumber() const
virtual Float_t GetMaxPosition() const
virtual void SetText(const char *text, Bool_t emit=kTRUE)
Sets text entry to text, clears the selection and moves the cursor to the end of the line...
virtual void Set(Int_t nbins, Double_t xmin, Double_t xmax)
Initialize axis with fix bins.
Definition: TAxis.cxx:701
const Bool_t kTRUE
Definition: Rtypes.h:91
TObject * obj
TGedEditor * fGedEditor
Definition: TGedFrame.h:56
virtual void MakeTitle(const char *title)
Create attribute frame title.
Definition: TGedFrame.cxx:96
virtual void SetToolTipText(const char *text, Long_t delayms=400)
Set tool tip text associated with this button.
Definition: TGButton.cxx:395
virtual Int_t GetNpar() const
Definition: TF1.h:349
TGDoubleHSlider * fSliderX
Definition: TF1Editor.h:46
TGNumberEntryField * fSldMaxX
Definition: TF1Editor.h:48
TAxis * GetXaxis()
Definition: TH1.h:319
virtual void SetState(EButtonState state, Bool_t emit=kFALSE)
Set button state.
Definition: TGButton.cxx:185
virtual void ActivateBaseClassEditors(TClass *cl)
Provide list of editors for base-classes.
Definition: TGedFrame.cxx:168