Logo ROOT  
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/** \class TF1Editor
14 \ingroup ged
15
16GUI 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 "TGLabel.h"
26#include "TGDoubleSlider.h"
27#include "TString.h"
28#include "TGNumberEntry.h"
29#include "TG3DLine.h"
31#include "TVirtualPad.h"
32
33
35
36enum ETF1Wid {
40};
41
43 UInt_t options, Pixel_t back)
44 : TGedFrame(p, width, height, options | kVerticalFrame, back)
45{
46 // Constructor of TF1 editor.
47
48 MakeTitle("Function");
49
50 fTitle = new TGTextEntry(this, new TGTextBuffer(50), kTF1_TIT);
53 fTitle->SetToolTipText(Form("Function expression or predefined name"));
54 AddFrame(fTitle, new TGLayoutHints(kLHintsLeft,3, 2, 2, 3));
55
56 TGCompositeFrame *f3a = new TGCompositeFrame(this, 137, 20, kHorizontalFrame);
57 AddFrame(f3a, new TGLayoutHints(kLHintsTop, 0, 1, 3, 0));
58 fDrawMode = new TGCheckButton(f3a, "Update", kTF1_DRW);
59 fDrawMode->SetToolTipText("Immediate function redrawing");
61 fParLabel = new TGLabel(f3a, "");
63
65 fSetPars = new TGTextButton(f3, "Set Parameters...", kTF1_PAR);
67 0, 1, 5, 0));
68 fSetPars->SetToolTipText("Open a dialog for parameter(s) settings");
69 AddFrame(f3, new TGLayoutHints(kLHintsTop | kLHintsLeft, 3, 2, 2, 3));
70
71 MakeTitle("X-Range");
72
73 TGCompositeFrame *f4 = new TGCompositeFrame(this, 80, 20, kHorizontalFrame);
75 TGLabel *fNpxLabel = new TGLabel(f4a, "Points: ");
76 f4a->AddFrame(fNpxLabel, new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 3, 0, 5, 1));
77 f4->AddFrame(f4a, new TGLayoutHints(kLHintsTop | kLHintsLeft, 0, 1, 0, 0));
78
79 TGCompositeFrame *f4b = new TGCompositeFrame(f4, 40, 20, kVerticalFrame);
80 fNXpoints = new TGNumberEntry(f4b, 100, 7, kTF1_NPX,
84 fNXpoints->GetNumberEntry()->SetToolTipText("Points along x-axis (4-100 000)");
85 f4b->AddFrame(fNXpoints, new TGLayoutHints(kLHintsLeft, 0, 0, 1, 0));
86 f4->AddFrame(f4b, new TGLayoutHints(kLHintsTop | kLHintsRight, 0, 1, 0, 0));
87 AddFrame(f4, new TGLayoutHints(kLHintsTop | kLHintsLeft, 0, 1, 0, 0));
88
89 TGCompositeFrame *f5 = new TGCompositeFrame(this, 80, 20, kHorizontalFrame);
90 fSliderX = new TGDoubleHSlider(f5, 1, 2);
91 fSliderX->Resize(137,20);
93 AddFrame(f5, new TGLayoutHints(kLHintsTop, 3, 7, 4, 1));
94
95 TGCompositeFrame *f6 = new TGCompositeFrame(this, 80, 20, kHorizontalFrame);
99 ((TGTextEntry*)fSldMinX)->SetToolTipText("Lower bound along x-axis");
100 fSldMinX->Resize(65,20);
106 ((TGTextEntry*)fSldMaxX)->SetToolTipText("Upper bound along x-axis");
108 fSldMaxX->Resize(65,20);
109 f6->AddFrame(fSldMaxX, new TGLayoutHints(kLHintsLeft, 4, 0, 0, 0));
110 AddFrame(f6, new TGLayoutHints(kLHintsTop, 3, 3, 5, 0));
111}
112
113////////////////////////////////////////////////////////////////////////////////
114/// Destructor of TF1 editor.
115
117{
118}
119
120////////////////////////////////////////////////////////////////////////////////
121/// Connect signals to slots.
122
124{
125 fNXpoints->Connect("ValueSet(Long_t)", "TF1Editor", this, "DoXPoints()");
126 (fNXpoints->GetNumberEntry())->Connect("ReturnPressed()", "TF1Editor",
127 this, "DoXPoints()");
128 fSetPars->Connect("Clicked()", "TF1Editor", this, "DoParameterSettings()");
129 fSliderX->Connect("Pressed()","TF1Editor", this,"DoSliderXPressed()");
130 fSliderX->Connect("Released()","TF1Editor", this,"DoSliderXReleased()");
131 fSliderX->Connect("PositionChanged()","TF1Editor", this,"DoSliderXMoved()");
132
133 fInit = kFALSE;
134}
135
136////////////////////////////////////////////////////////////////////////////////
137/// Pick up the function parameters and options.
138
140{
141 if (obj == 0 || !obj->InheritsFrom(TF1::Class())) {
142 return;
143 }
144
145 fF1 = (TF1*)obj;
147
148 const char *text = fF1->GetTitle();
150
151 fNP = fF1->GetNpar();
152 fParLabel->SetText(Form("Npar: %d", fNP));
154
156
157 if (!fNP)
159 else
161
163 Int_t nx = x->GetNbins();
164 Int_t nxbinmin = x->GetFirst();
165 Int_t nxbinmax = x->GetLast();
166 fSliderX->SetRange(1,nx);
167 fSliderX->SetPosition((Double_t)nxbinmin,(Double_t)nxbinmax);
168 fSldMinX->SetNumber(x->GetBinLowEdge(nxbinmin));
169 fSldMaxX->SetNumber(x->GetBinUpEdge(nxbinmax));
170
173}
174
175////////////////////////////////////////////////////////////////////////////////
176/// Slot connected to the function parameter(s) settings.
177
179{
181 Double_t rmin = fSldMinX->GetNumber();
182 Double_t rmax = fSldMaxX->GetNumber();
183 new TFunctionParametersDialog(gClient->GetDefaultRoot(), main,
184 fF1, fGedEditor->GetPad(), rmin, rmax);
185
186}
187
188////////////////////////////////////////////////////////////////////////////////
189/// Slot connected to the number of points setting.
190
192{
193 if (fAvoidSignal) return;
194 Double_t rmin, rmax;
195 fF1->GetRange(rmin, rmax);
201 Update();
202 fF1->SetRange(rmin, rmax);
203}
204
205////////////////////////////////////////////////////////////////////////////////
206/// Slot connected to the x-Slider range for function redrawing.
207
209{
210 if (fAvoidSignal) return;
211
212 TVirtualPad *save = 0;
213 save = gPad;
215 fGedEditor->GetPad()->cd();
216
219
220 if (fDrawMode->GetState() == kButtonDown) {
221 TString opt = fF1->GetDrawOption();
222 opt.ToUpper();
223 if (!opt.Contains("SAME"))
224 opt += "SAME";
225 fF1->Draw(opt);
226
227 x->SetRange((Int_t)((fSliderX->GetMinPosition())+0.5),
228 (Int_t)((fSliderX->GetMaxPosition())+0.5));
229 fSldMinX->SetNumber(x->GetBinLowEdge(x->GetFirst()));
230 fSldMaxX->SetNumber(x->GetBinUpEdge(x->GetLast()));
234 Update();
235
236 } else {
237 x->SetRange((Int_t)((fSliderX->GetMinPosition())+0.5),
238 (Int_t)((fSliderX->GetMaxPosition())+0.5));
239 fSldMinX->SetNumber(x->GetBinLowEdge(x->GetFirst()));
240 fSldMaxX->SetNumber(x->GetBinUpEdge(x->GetLast()));
244 }
245 if(save) gPad = save;
246}
247
248////////////////////////////////////////////////////////////////////////////////
249/// Slot connected to the x-Slider.
250
252{
253 if (fAvoidSignal || (fDrawMode->GetState() == kButtonDown)) return;
254
255 TVirtualPad *save = 0;
256 save = gPad;
258 fGedEditor->GetPad()->cd();
259
262 TString opt = fF1->GetDrawOption();
263 opt.ToUpper();
264 if (!opt.Contains("SAME"))
265 opt += "SAME";
266 fF1->Draw(opt);
267
268 x->SetRange((Int_t)((fSliderX->GetMinPosition())+0.5),
269 (Int_t)((fSliderX->GetMaxPosition())+0.5));
270 fSldMinX->SetNumber(x->GetBinLowEdge(x->GetFirst()));
271 fSldMaxX->SetNumber(x->GetBinUpEdge(x->GetLast()));
275 Update();
276
277 if(save) gPad = save;
278
279}
280
281////////////////////////////////////////////////////////////////////////////////
282/// Slot connected to the x-Slider.
283
285{
286 if (fAvoidSignal || (fDrawMode->GetState() == kButtonDown)) return;
287
288 TVirtualPad *save = 0;
289 save = gPad;
291 fGedEditor->GetPad()->cd();
292
295 TString opt = fF1->GetDrawOption();
296 opt.ToUpper();
297 if (!opt.Contains("SAME"))
298 opt += "SAME";
299 fF1->Draw(opt);
300
301 x->SetRange((Int_t)((fSliderX->GetMinPosition())+0.5),
302 (Int_t)((fSliderX->GetMaxPosition())+0.5));
303 fSldMinX->SetNumber(x->GetBinLowEdge(x->GetFirst()));
304 fSldMaxX->SetNumber(x->GetBinUpEdge(x->GetLast()));
308 Update();
309
310 if(save) gPad = save;
311}
312
313
314////////////////////////////////////////////////////////////////////////////////
315/// Slot connected to min/max settings of the slider range.
316
318{
319 if (fAvoidSignal) return;
321 Int_t nx = x->GetNbins();
322 Double_t width = x->GetBinWidth(1);
323 Double_t lowLimit = x->GetBinLowEdge(1);
324 Double_t upLimit = x->GetBinUpEdge(nx);
325 if ((fSldMinX->GetNumber()+width/2) < (lowLimit))
326 fSldMinX->SetNumber(lowLimit);
327 if ((fSldMaxX->GetNumber()-width/2) > (upLimit))
328 fSldMaxX->SetNumber(upLimit);
329 x->SetRangeUser(fSldMinX->GetNumber()+width/2,
331 Int_t nxbinmin = x->GetFirst();
332 Int_t nxbinmax = x->GetLast();
333 fSliderX->SetPosition((Double_t)(nxbinmin),(Double_t)(nxbinmax));
334 Update();
335}
336
337////////////////////////////////////////////////////////////////////////////////
338/// Exclude TAttFillEditor from this interface.
339
341{
344}
345
void Class()
Definition: Class.C:29
@ kVerticalFrame
Definition: GuiTypes.h:381
@ kFixedWidth
Definition: GuiTypes.h:387
@ kHorizontalFrame
Definition: GuiTypes.h:382
ULong_t Pixel_t
Pixel value.
Definition: GuiTypes.h:40
int Int_t
Definition: RtypesCore.h:45
unsigned int UInt_t
Definition: RtypesCore.h:46
const Bool_t kFALSE
Definition: RtypesCore.h:101
double Double_t
Definition: RtypesCore.h:59
const Bool_t kTRUE
Definition: RtypesCore.h:100
#define ClassImp(name)
Definition: Rtypes.h:364
include TDocParser_001 C image html pict1_TDocParser_001 png width
Definition: TDocParser.cxx:121
ETF1Wid
Definition: TF1Editor.cxx:36
@ kTF1_DRW
Definition: TF1Editor.cxx:39
@ kTF1_TIT
Definition: TF1Editor.cxx:37
@ kTF1_XMAX
Definition: TF1Editor.cxx:38
@ kTF1_XSLD
Definition: TF1Editor.cxx:38
@ kTF1_NPX
Definition: TF1Editor.cxx:37
@ kTF1_PAR
Definition: TF1Editor.cxx:39
@ kTF1_XMIN
Definition: TF1Editor.cxx:38
@ kButtonDown
Definition: TGButton.h:54
@ kButtonDisabled
Definition: TGButton.h:56
@ kButtonUp
Definition: TGButton.h:53
#define gClient
Definition: TGClient.h:157
@ kLHintsRight
Definition: TGLayout.h:26
@ kLHintsLeft
Definition: TGLayout.h:24
@ kLHintsCenterY
Definition: TGLayout.h:28
@ kLHintsBottom
Definition: TGLayout.h:29
@ kLHintsTop
Definition: TGLayout.h:27
@ kLHintsExpandX
Definition: TGLayout.h:30
char * Form(const char *fmt,...)
#define gPad
Definition: TVirtualPad.h:288
int main(int argc, char *argv[])
Definition: cef_main.cxx:54
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:731
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition: TClass.h:80
GUI for TF1 attributes and parameters.
Definition: TF1Editor.h:27
TGCheckButton * fDrawMode
immediate function redraw (if selected)
Definition: TF1Editor.h:34
virtual void ActivateBaseClassEditors(TClass *cl)
Exclude TAttFillEditor from this interface.
Definition: TF1Editor.cxx:340
virtual void DoXRange()
Slot connected to min/max settings of the slider range.
Definition: TF1Editor.cxx:317
virtual void DoParameterSettings()
Slot connected to the function parameter(s) settings.
Definition: TF1Editor.cxx:178
virtual void DoSliderXReleased()
Slot connected to the x-Slider.
Definition: TF1Editor.cxx:284
virtual void DoXPoints()
Slot connected to the number of points setting.
Definition: TF1Editor.cxx:191
virtual void DoSliderXMoved()
Slot connected to the x-Slider range for function redrawing.
Definition: TF1Editor.cxx:208
virtual ~TF1Editor()
Destructor of TF1 editor.
Definition: TF1Editor.cxx:116
TGLabel * fParLabel
label for number of parameters
Definition: TF1Editor.h:33
virtual void DoSliderXPressed()
Slot connected to the x-Slider.
Definition: TF1Editor.cxx:251
Int_t fNP
number of function parameters
Definition: TF1Editor.h:32
TGNumberEntryField * fSldMinX
contains minimum value of x-axis
Definition: TF1Editor.h:38
TGDoubleHSlider * fSliderX
slider to set x-axis range
Definition: TF1Editor.h:37
TGNumberEntry * fNXpoints
number of points along x-axis
Definition: TF1Editor.h:36
TF1 * fF1
selected TF1 object
Definition: TF1Editor.h:30
TGNumberEntryField * fSldMaxX
contains maximum value of x-axis
Definition: TF1Editor.h:39
virtual void SetModel(TObject *obj)
Pick up the function parameters and options.
Definition: TF1Editor.cxx:139
TF1Editor(const TGWindow *p=0, Int_t width=140, Int_t height=30, UInt_t options=kChildFrame, Pixel_t back=GetDefaultFrameBackground())
Definition: TF1Editor.cxx:42
TGTextButton * fSetPars
open 'Set Parameters' dialog
Definition: TF1Editor.h:35
TGTextEntry * fTitle
function title
Definition: TF1Editor.h:31
virtual void ConnectSignals2Slots()
Connect signals to slots.
Definition: TF1Editor.cxx:123
1-Dim function class
Definition: TF1.h:213
virtual TH1 * GetHistogram() const
Return a pointer to the histogram used to visualise the function Note that this histogram is managed ...
Definition: TF1.cxx:1580
virtual void SetRange(Double_t xmin, Double_t xmax)
Initialize the upper and lower bounds to draw the function.
Definition: TF1.cxx:3539
virtual Int_t GetNpar() const
Definition: TF1.h:481
virtual void SetNpx(Int_t npx=100)
Set the number of points used to draw the function.
Definition: TF1.cxx:3453
virtual void GetRange(Double_t *xmin, Double_t *xmax) const
Return range of a generic N-D function.
Definition: TF1.cxx:2275
virtual void Draw(Option_t *option="")
Draw this function with its current attributes.
Definition: TF1.cxx:1328
virtual Int_t GetNpx() const
Definition: TF1.h:490
This class is used for function parameter settings.
virtual void SetToolTipText(const char *text, Long_t delayms=400)
Set tool tip text associated with this button.
Definition: TGButton.cxx:445
virtual EButtonState GetState() const
Definition: TGButton.h:112
virtual void SetState(EButtonState state, Bool_t emit=kFALSE)
Set button state.
Definition: TGButton.cxx:235
Selects different options.
Definition: TGButton.h:264
void NeedRedraw(TGWindow *w, Bool_t force=kFALSE)
Set redraw flags.
Definition: TGClient.cxx:372
The base class for composite widgets (menu bars, list boxes, etc.).
Definition: TGFrame.h:287
virtual void AddFrame(TGFrame *f, TGLayoutHints *l=0)
Add frame to the composite frame using the specified layout hints.
Definition: TGFrame.cxx:1117
TGCompositeFrame(const TGCompositeFrame &)=delete
Dragging the slider will generate the event:
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:191
virtual void Resize(UInt_t w=0, UInt_t h=0)
Resize the frame.
Definition: TGFrame.cxx:605
This class handles GUI labels.
Definition: TGLabel.h:24
virtual void SetText(TGString *newText)
Set new text in label.
Definition: TGLabel.cxx:180
This class describes layout hints used by the layout classes.
Definition: TGLayout.h:50
Defines top level windows that interact with the system Window Manager.
Definition: TGFrame.h:398
virtual void SetNumber(Double_t val, Bool_t emit=kTRUE)
Set the numeric value (floating point representation).
virtual Double_t GetNumber() const
Get the numeric value (floating point representation).
virtual void SetState(Bool_t state)
Set the active state.
TGNumberEntry is a number entry input widget with up/down buttons.
TGNumberEntryField * GetNumberEntry() const
virtual Double_t GetNumber() const
virtual void SetNumber(Double_t val, Bool_t emit=kTRUE)
@ kNEANonNegative
Non-negative number.
Definition: TGNumberEntry.h:42
@ kNEAAnyNumber
Attributes of number entry field.
Definition: TGNumberEntry.h:41
@ kNESInteger
Style of number entry field.
Definition: TGNumberEntry.h:25
@ kNESRealFour
Fixed fraction real, four digit.
Definition: TGNumberEntry.h:29
@ kNELLimitMinMax
Both lower and upper limits.
Definition: TGNumberEntry.h:50
TGClient * fClient
Connection to display server.
Definition: TGObject.h:27
A text buffer is used in several widgets, like TGTextEntry, TGFileDialog, etc.
Definition: TGTextBuffer.h:19
Yield an action as soon as it is clicked.
Definition: TGButton.h:142
A TGTextEntry is a one line text input widget.
Definition: TGTextEntry.h:24
void SetEnabled(Bool_t flag=kTRUE)
Definition: TGTextEntry.h:149
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.
ROOT GUI Window base class.
Definition: TGWindow.h:23
virtual const TGWindow * GetMainFrame() const
Returns top level main frame.
Definition: TGWindow.cxx:152
virtual TVirtualPad * GetPad() const
Definition: TGedEditor.h:78
void ExcludeClassEditor(TClass *cl, Bool_t recurse=kFALSE)
Exclude editor for class cl from current construction.
Definition: TGedEditor.cxx:574
Base frame for implementing GUI - a service class.
Definition: TGedFrame.h:27
virtual void ActivateBaseClassEditors(TClass *cl)
Provide list of editors for base-classes.
Definition: TGedFrame.cxx:167
TGedEditor * fGedEditor
manager of this frame
Definition: TGedFrame.h:48
Bool_t fInit
init flag for setting signals/slots
Definition: TGedFrame.h:47
virtual void MakeTitle(const char *title)
Create attribute frame title.
Definition: TGedFrame.cxx:95
virtual void Update()
Update the current pad when an attribute is changed via GUI.
Definition: TGedFrame.cxx:72
Bool_t fAvoidSignal
flag for executing slots
Definition: TGedFrame.h:50
TAxis * GetXaxis()
Get the behaviour adopted by the object about the statoverflows. See EStatOverflows for more informat...
Definition: TH1.h:320
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:343
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition: TObject.cxx:445
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:869
Basic string class.
Definition: TString.h:136
void ToUpper()
Change string to upper case.
Definition: TString.cxx:1163
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition: TString.h:624
TVirtualPad is an abstract base class for the Pad and Canvas classes.
Definition: TVirtualPad.h:51
virtual TVirtualPad * cd(Int_t subpadnumber=0)=0
TText * text
Double_t x[n]
Definition: legend1.C:17