Logo ROOT   6.16/01
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
37enum ETF1Wid {
41};
42
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");
62 fParLabel = new TGLabel(f3a, "");
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);
100 ((TGTextEntry*)fSldMinX)->SetToolTipText("Lower bound along x-axis");
101 fSldMinX->Resize(65,20);
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();
151
152 fNP = fF1->GetNpar();
153 fParLabel->SetText(Form("Npar: %d", fNP));
155
157
158 if (!fNP)
160 else
162
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);
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;
216 fGedEditor->GetPad()->cd();
217
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));
230 fSldMinX->SetNumber(x->GetBinLowEdge(x->GetFirst()));
231 fSldMaxX->SetNumber(x->GetBinUpEdge(x->GetLast()));
235 Update();
236
237 } else {
238 x->SetRange((Int_t)((fSliderX->GetMinPosition())+0.5),
239 (Int_t)((fSliderX->GetMaxPosition())+0.5));
240 fSldMinX->SetNumber(x->GetBinLowEdge(x->GetFirst()));
241 fSldMaxX->SetNumber(x->GetBinUpEdge(x->GetLast()));
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;
259 fGedEditor->GetPad()->cd();
260
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));
271 fSldMinX->SetNumber(x->GetBinLowEdge(x->GetFirst()));
272 fSldMaxX->SetNumber(x->GetBinUpEdge(x->GetLast()));
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;
292 fGedEditor->GetPad()->cd();
293
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));
304 fSldMinX->SetNumber(x->GetBinLowEdge(x->GetFirst()));
305 fSldMaxX->SetNumber(x->GetBinUpEdge(x->GetLast()));
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;
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,
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
void Class()
Definition: Class.C:29
ULong_t Pixel_t
Definition: GuiTypes.h:39
int Int_t
Definition: RtypesCore.h:41
unsigned int UInt_t
Definition: RtypesCore.h:42
const Bool_t kFALSE
Definition: RtypesCore.h:88
double Double_t
Definition: RtypesCore.h:55
const Bool_t kTRUE
Definition: RtypesCore.h:87
#define ClassImp(name)
Definition: Rtypes.h:363
include TDocParser_001 C image html pict1_TDocParser_001 png width
Definition: TDocParser.cxx:121
ETF1Wid
Definition: TF1Editor.cxx:37
@ kTF1_DRW
Definition: TF1Editor.cxx:40
@ kTF1_TIT
Definition: TF1Editor.cxx:38
@ kTF1_XMAX
Definition: TF1Editor.cxx:39
@ kTF1_XSLD
Definition: TF1Editor.cxx:39
@ kTF1_NPX
Definition: TF1Editor.cxx:38
@ kTF1_PAR
Definition: TF1Editor.cxx:40
@ kTF1_XMIN
Definition: TF1Editor.cxx:39
@ kButtonDown
Definition: TGButton.h:54
@ kButtonDisabled
Definition: TGButton.h:56
@ kButtonUp
Definition: TGButton.h:53
#define gClient
Definition: TGClient.h:166
@ kVerticalFrame
Definition: TGFrame.h:59
@ kFixedWidth
Definition: TGFrame.h:65
@ kHorizontalFrame
Definition: TGFrame.h:60
@ kLHintsRight
Definition: TGLayout.h:33
@ kLHintsLeft
Definition: TGLayout.h:31
@ kLHintsCenterY
Definition: TGLayout.h:35
@ kLHintsBottom
Definition: TGLayout.h:36
@ kLHintsTop
Definition: TGLayout.h:34
@ kLHintsExpandX
Definition: TGLayout.h:37
char * Form(const char *fmt,...)
#define gPad
Definition: TVirtualPad.h:286
Class to manage histogram axis.
Definition: TAxis.h:30
virtual void Set(Int_t nbins, Double_t xmin, Double_t xmax)
Initialize axis with fix bins.
Definition: TAxis.cxx:717
The ROOT global object gROOT contains a list of all defined classes.
Definition: TClass.h:75
TGCheckButton * fDrawMode
Definition: TF1Editor.h:41
virtual void ActivateBaseClassEditors(TClass *cl)
Exclude TAttFillEditor from this interface.
Definition: TF1Editor.cxx:341
virtual void DoXRange()
Slot connected to min/max settings of the slider range.
Definition: TF1Editor.cxx:318
virtual void DoParameterSettings()
Slot connected to the function parameter(s) settings.
Definition: TF1Editor.cxx:179
virtual void DoSliderXReleased()
Slot connected to the x-Slider.
Definition: TF1Editor.cxx:285
virtual void DoXPoints()
Slot connected to the number of points setting.
Definition: TF1Editor.cxx:192
virtual void DoSliderXMoved()
Slot connected to the x-Slider range for function redrawing.
Definition: TF1Editor.cxx:209
virtual ~TF1Editor()
Destructor of TF1 editor.
Definition: TF1Editor.cxx:117
TGLabel * fParLabel
Definition: TF1Editor.h:40
virtual void DoSliderXPressed()
Slot connected to the x-Slider.
Definition: TF1Editor.cxx:252
Int_t fNP
Definition: TF1Editor.h:39
TGNumberEntryField * fSldMinX
Definition: TF1Editor.h:45
TGDoubleHSlider * fSliderX
Definition: TF1Editor.h:44
TGNumberEntry * fNXpoints
Definition: TF1Editor.h:43
TF1 * fF1
Definition: TF1Editor.h:37
TGNumberEntryField * fSldMaxX
Definition: TF1Editor.h:46
virtual void SetModel(TObject *obj)
Pick up the function parameters and options.
Definition: TF1Editor.cxx:140
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
TGTextButton * fSetPars
Definition: TF1Editor.h:42
TGTextEntry * fTitle
Definition: TF1Editor.h:38
virtual void ConnectSignals2Slots()
Connect signals to slots.
Definition: TF1Editor.cxx:124
1-Dim function class
Definition: TF1.h:211
virtual TH1 * GetHistogram() const
Return a pointer to the histogram used to visualise the function.
Definition: TF1.cxx:1559
virtual void SetRange(Double_t xmin, Double_t xmax)
Initialize the upper and lower bounds to draw the function.
Definition: TF1.cxx:3512
virtual Int_t GetNpar() const
Definition: TF1.h:465
virtual void SetNpx(Int_t npx=100)
Set the number of points used to draw the function.
Definition: TF1.cxx:3426
virtual void GetRange(Double_t *xmin, Double_t *xmax) const
Return range of a generic N-D function.
Definition: TF1.cxx:2257
virtual void Draw(Option_t *option="")
Draw this function with its current attributes.
Definition: TF1.cxx:1312
virtual Int_t GetNpx() const
Definition: TF1.h:474
virtual void SetToolTipText(const char *text, Long_t delayms=400)
Set tool tip text associated with this button.
Definition: TGButton.cxx:395
virtual EButtonState GetState() const
Definition: TGButton.h:112
virtual void SetState(EButtonState state, Bool_t emit=kFALSE)
Set button state.
Definition: TGButton.cxx:185
void NeedRedraw(TGWindow *w, Bool_t force=kFALSE)
Set redraw flags.
Definition: TGClient.cxx:372
TGCompositeFrame(const TGCompositeFrame &)
virtual void AddFrame(TGFrame *f, TGLayoutHints *l=0)
Add frame to the composite frame using the specified layout hints.
Definition: TGFrame.cxx:1099
virtual Float_t GetMaxPosition() const
virtual Float_t GetMinPosition() const
virtual void SetRange(Float_t min, Float_t max)
virtual void SetPosition(Float_t min, Float_t max)
virtual UInt_t GetDefaultHeight() const
Definition: TGFrame.h:238
virtual void Resize(UInt_t w=0, UInt_t h=0)
Resize the frame.
Definition: TGFrame.cxx:587
virtual void SetText(TGString *newText)
Set new text in label.
Definition: TGLabel.cxx:177
virtual Double_t GetNumber() const
Get the numeric value (floating point representation).
virtual void SetState(Bool_t state)
Set the active state.
virtual void SetNumber(Double_t val)
Set the numeric value (floating point representation).
virtual void SetNumber(Double_t val)
TGNumberEntryField * GetNumberEntry() const
virtual Double_t GetNumber() const
TGClient * fClient
Definition: TGObject.h:37
void SetEnabled(Bool_t flag=kTRUE)
Definition: TGTextEntry.h:164
virtual void SetToolTipText(const char *text, Long_t delayms=500)
Set tool tip text associated with this text entry.
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 const TGWindow * GetMainFrame() const
Returns top level main frame.
Definition: TGWindow.cxx:133
virtual TVirtualPad * GetPad() const
Definition: TGedEditor.h:89
void ExcludeClassEditor(TClass *cl, Bool_t recurse=kFALSE)
Exclude editor for class cl from current construction.
Definition: TGedEditor.cxx:578
virtual void ActivateBaseClassEditors(TClass *cl)
Provide list of editors for base-classes.
Definition: TGedFrame.cxx:168
TGedEditor * fGedEditor
Definition: TGedFrame.h:54
Bool_t fInit
Definition: TGedFrame.h:53
virtual void MakeTitle(const char *title)
Create attribute frame title.
Definition: TGedFrame.cxx:96
virtual void Update()
Update the current pad when an attribute is changed via GUI.
Definition: TGedFrame.cxx:73
Bool_t fAvoidSignal
Definition: TGedFrame.h:56
TAxis * GetXaxis()
Get the behaviour adopted by the object about the statoverflows. See EStatOverflows for more informat...
Definition: TH1.h:316
virtual const char * GetTitle() const
Returns title of object.
Definition: TNamed.h:48
Mother of all ROOT objects.
Definition: TObject.h:37
virtual Option_t * GetDrawOption() const
Get option used by the graphics system to draw this object.
Definition: TObject.cxx:341
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition: TObject.cxx:443
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:867
Basic string class.
Definition: TString.h:131
void ToUpper()
Change string to upper case.
Definition: TString.cxx:1113
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition: TString.h:619
TVirtualPad is an abstract base class for the Pad and Canvas classes.
Definition: TVirtualPad.h:50
virtual TVirtualPad * cd(Int_t subpadnumber=0)=0
TText * text
int main(int argc, char **argv)
Double_t x[n]
Definition: legend1.C:17