Logo ROOT  
Reference Guide
Loading...
Searching...
No Matches
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
34
40
41TF1Editor::TF1Editor(const TGWindow *p, Int_t width, Int_t height,
42 UInt_t options, Pixel_t back)
43 : TGedFrame(p, width, height, options | kVerticalFrame, back)
44{
45 // Constructor of TF1 editor.
46
47 MakeTitle("Function");
48
49 fTitle = new TGTextEntry(this, new TGTextBuffer(50), kTF1_TIT);
50 fTitle->Resize(137, fTitle->GetDefaultHeight());
51 fTitle->SetEnabled(kFALSE);
52 fTitle->SetToolTipText(Form("Function expression or predefined name"));
53 AddFrame(fTitle, new TGLayoutHints(kLHintsLeft,3, 2, 2, 3));
54
55 TGCompositeFrame *f3a = new TGCompositeFrame(this, 137, 20, kHorizontalFrame);
56 AddFrame(f3a, new TGLayoutHints(kLHintsTop, 0, 1, 3, 0));
57 fDrawMode = new TGCheckButton(f3a, "Update", kTF1_DRW);
58 fDrawMode->SetToolTipText("Immediate function redrawing");
60 fParLabel = new TGLabel(f3a, "");
62
64 fSetPars = new TGTextButton(f3, "Set Parameters...", kTF1_PAR);
66 0, 1, 5, 0));
67 fSetPars->SetToolTipText("Open a dialog for parameter(s) settings");
68 AddFrame(f3, new TGLayoutHints(kLHintsTop | kLHintsLeft, 3, 2, 2, 3));
69
70 MakeTitle("X-Range");
71
72 TGCompositeFrame *f4 = new TGCompositeFrame(this, 80, 20, kHorizontalFrame);
74 TGLabel *fNpxLabel = new TGLabel(f4a, "Points: ");
75 f4a->AddFrame(fNpxLabel, new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 3, 0, 5, 1));
76 f4->AddFrame(f4a, new TGLayoutHints(kLHintsTop | kLHintsLeft, 0, 1, 0, 0));
77
78 TGCompositeFrame *f4b = new TGCompositeFrame(f4, 40, 20, kVerticalFrame);
79 fNXpoints = new TGNumberEntry(f4b, 100, 7, kTF1_NPX,
83 fNXpoints->GetNumberEntry()->SetToolTipText("Points along x-axis (4-100 000)");
84 f4b->AddFrame(fNXpoints, new TGLayoutHints(kLHintsLeft, 0, 0, 1, 0));
85 f4->AddFrame(f4b, new TGLayoutHints(kLHintsTop | kLHintsRight, 0, 1, 0, 0));
86 AddFrame(f4, new TGLayoutHints(kLHintsTop | kLHintsLeft, 0, 1, 0, 0));
87
88 TGCompositeFrame *f5 = new TGCompositeFrame(this, 80, 20, kHorizontalFrame);
89 fSliderX = new TGDoubleHSlider(f5, 1, 2);
90 fSliderX->Resize(137,20);
92 AddFrame(f5, new TGLayoutHints(kLHintsTop, 3, 7, 4, 1));
93
94 TGCompositeFrame *f6 = new TGCompositeFrame(this, 80, 20, kHorizontalFrame);
98 ((TGTextEntry*)fSldMinX)->SetToolTipText("Lower bound along x-axis");
99 fSldMinX->Resize(65,20);
100 fSldMinX->SetState(kFALSE);
105 ((TGTextEntry*)fSldMaxX)->SetToolTipText("Upper bound along x-axis");
106 fSldMaxX->SetState(kFALSE);
107 fSldMaxX->Resize(65,20);
108 f6->AddFrame(fSldMaxX, new TGLayoutHints(kLHintsLeft, 4, 0, 0, 0));
109 AddFrame(f6, new TGLayoutHints(kLHintsTop, 3, 3, 5, 0));
110}
111
112////////////////////////////////////////////////////////////////////////////////
113/// Destructor of TF1 editor.
114
118
119////////////////////////////////////////////////////////////////////////////////
120/// Connect signals to slots.
121
123{
124 fNXpoints->Connect("ValueSet(Long_t)", "TF1Editor", this, "DoXPoints()");
125 (fNXpoints->GetNumberEntry())->Connect("ReturnPressed()", "TF1Editor",
126 this, "DoXPoints()");
127 fSetPars->Connect("Clicked()", "TF1Editor", this, "DoParameterSettings()");
128 fSliderX->Connect("Pressed()","TF1Editor", this,"DoSliderXPressed()");
129 fSliderX->Connect("Released()","TF1Editor", this,"DoSliderXReleased()");
130 fSliderX->Connect("PositionChanged()","TF1Editor", this,"DoSliderXMoved()");
131
132 fInit = kFALSE;
133}
134
135////////////////////////////////////////////////////////////////////////////////
136/// Pick up the function parameters and options.
137
139{
140 if (obj == 0 || !obj->InheritsFrom(TF1::Class())) {
141 return;
142 }
143
144 fF1 = (TF1*)obj;
146
147 const char *text = fF1->GetTitle();
148 fTitle->SetText(text);
149
150 fNP = fF1->GetNpar();
151 fParLabel->SetText(Form("Npar: %d", fNP));
152 fClient->NeedRedraw(fParLabel);
153
154 fNXpoints->SetNumber(fF1->GetNpx());
155
156 if (!fNP)
157 fSetPars->SetState(kButtonDisabled, kFALSE);
158 else
159 fSetPars->SetState(kButtonUp, kFALSE);
160
161 TAxis *x = fF1->GetHistogram()->GetXaxis();
162 Int_t nx = x->GetNbins();
163 Int_t nxbinmin = x->GetFirst();
164 Int_t nxbinmax = x->GetLast();
165 fSliderX->SetRange(1,nx);
166 fSliderX->SetPosition((Double_t)nxbinmin,(Double_t)nxbinmax);
167 fSldMinX->SetNumber(x->GetBinLowEdge(nxbinmin));
168 fSldMaxX->SetNumber(x->GetBinUpEdge(nxbinmax));
169
172}
173
174////////////////////////////////////////////////////////////////////////////////
175/// Slot connected to the function parameter(s) settings.
176
178{
180 Double_t rmin = fSldMinX->GetNumber();
181 Double_t rmax = fSldMaxX->GetNumber();
182 new TFunctionParametersDialog(gClient->GetDefaultRoot(), main,
183 fF1, fGedEditor->GetPad(), rmin, rmax);
184
185}
186
187////////////////////////////////////////////////////////////////////////////////
188/// Slot connected to the number of points setting.
189
191{
192 if (fAvoidSignal) return;
193 Double_t rmin, rmax;
194 fF1->GetRange(rmin, rmax);
195 fF1->SetRange(fSldMinX->GetNumber(), fSldMaxX->GetNumber());
196 fF1->SetNpx((Int_t)fNXpoints->GetNumber());
197 fF1->GetHistogram()->GetXaxis()->Set((Int_t)fNXpoints->GetNumber(),
198 fSldMinX->GetNumber(),
199 fSldMaxX->GetNumber());
200 Update();
201 fF1->SetRange(rmin, rmax);
202}
203
204////////////////////////////////////////////////////////////////////////////////
205/// Slot connected to the x-Slider range for function redrawing.
206
208{
209 if (fAvoidSignal) return;
210
211 TVirtualPad::TContext ctxt(fGedEditor->GetPad(), kTRUE);
212
213 fF1->SetNpx((Int_t)fNXpoints->GetNumber());
214 TAxis *x = fF1->GetHistogram()->GetXaxis();
215
216 if (fDrawMode->GetState() == kButtonDown) {
217 TString opt = fF1->GetDrawOption();
218 opt.ToUpper();
219 if (!opt.Contains("SAME"))
220 opt += "SAME";
221 fF1->Draw(opt);
222
223 x->SetRange((Int_t)((fSliderX->GetMinPosition())+0.5),
224 (Int_t)((fSliderX->GetMaxPosition())+0.5));
225 fSldMinX->SetNumber(x->GetBinLowEdge(x->GetFirst()));
226 fSldMaxX->SetNumber(x->GetBinUpEdge(x->GetLast()));
227 fClient->NeedRedraw(fSliderX,kTRUE);
228 fClient->NeedRedraw(fSldMinX,kTRUE);
229 fClient->NeedRedraw(fSldMaxX,kTRUE);
230 Update();
231
232 } else {
233 x->SetRange((Int_t)((fSliderX->GetMinPosition())+0.5),
234 (Int_t)((fSliderX->GetMaxPosition())+0.5));
235 fSldMinX->SetNumber(x->GetBinLowEdge(x->GetFirst()));
236 fSldMaxX->SetNumber(x->GetBinUpEdge(x->GetLast()));
237 fClient->NeedRedraw(fSliderX,kTRUE);
238 fClient->NeedRedraw(fSldMinX,kTRUE);
239 fClient->NeedRedraw(fSldMaxX,kTRUE);
240 }
241}
242
243////////////////////////////////////////////////////////////////////////////////
244/// Slot connected to the x-Slider.
245
247{
248 if (fAvoidSignal || (fDrawMode->GetState() == kButtonDown)) return;
249
250 TVirtualPad::TContext ctxt(fGedEditor->GetPad(), kTRUE);
251
252 fF1->SetNpx((Int_t)fNXpoints->GetNumber());
253 TAxis *x = fF1->GetHistogram()->GetXaxis();
254 TString opt = fF1->GetDrawOption();
255 opt.ToUpper();
256 if (!opt.Contains("SAME"))
257 opt += "SAME";
258 fF1->Draw(opt);
259
260 x->SetRange((Int_t)((fSliderX->GetMinPosition())+0.5),
261 (Int_t)((fSliderX->GetMaxPosition())+0.5));
262 fSldMinX->SetNumber(x->GetBinLowEdge(x->GetFirst()));
263 fSldMaxX->SetNumber(x->GetBinUpEdge(x->GetLast()));
264 fClient->NeedRedraw(fSliderX,kTRUE);
265 fClient->NeedRedraw(fSldMinX,kTRUE);
266 fClient->NeedRedraw(fSldMaxX,kTRUE);
267 Update();
268}
269
270////////////////////////////////////////////////////////////////////////////////
271/// Slot connected to the x-Slider.
272
274{
275 if (fAvoidSignal || (fDrawMode->GetState() == kButtonDown)) return;
276
277 TVirtualPad::TContext ctxt(fGedEditor->GetPad(), kTRUE);
278
279 fF1->SetNpx((Int_t)fNXpoints->GetNumber());
280 TAxis *x = fF1->GetHistogram()->GetXaxis();
281 TString opt = fF1->GetDrawOption();
282 opt.ToUpper();
283 if (!opt.Contains("SAME"))
284 opt += "SAME";
285 fF1->Draw(opt);
286
287 x->SetRange((Int_t)((fSliderX->GetMinPosition())+0.5),
288 (Int_t)((fSliderX->GetMaxPosition())+0.5));
289 fSldMinX->SetNumber(x->GetBinLowEdge(x->GetFirst()));
290 fSldMaxX->SetNumber(x->GetBinUpEdge(x->GetLast()));
291 fClient->NeedRedraw(fSliderX,kTRUE);
292 fClient->NeedRedraw(fSldMinX,kTRUE);
293 fClient->NeedRedraw(fSldMaxX,kTRUE);
294 Update();
295}
296
297
298////////////////////////////////////////////////////////////////////////////////
299/// Slot connected to min/max settings of the slider range.
300
302{
303 if (fAvoidSignal) return;
304 TAxis *x = fF1->GetHistogram()->GetXaxis();
305 Int_t nx = x->GetNbins();
306 Double_t width = x->GetBinWidth(1);
307 Double_t lowLimit = x->GetBinLowEdge(1);
308 Double_t upLimit = x->GetBinUpEdge(nx);
309 if ((fSldMinX->GetNumber()+width/2) < (lowLimit))
310 fSldMinX->SetNumber(lowLimit);
311 if ((fSldMaxX->GetNumber()-width/2) > (upLimit))
312 fSldMaxX->SetNumber(upLimit);
313 x->SetRangeUser(fSldMinX->GetNumber()+width/2,
314 fSldMaxX->GetNumber()-width/2);
315 Int_t nxbinmin = x->GetFirst();
316 Int_t nxbinmax = x->GetLast();
317 fSliderX->SetPosition((Double_t)(nxbinmin),(Double_t)(nxbinmax));
318 Update();
319}
320
321////////////////////////////////////////////////////////////////////////////////
322/// Exclude TAttFillEditor from this interface.
323
329
@ kVerticalFrame
Definition GuiTypes.h:382
@ kFixedWidth
Definition GuiTypes.h:388
@ kHorizontalFrame
Definition GuiTypes.h:383
ULong_t Pixel_t
Pixel value.
Definition GuiTypes.h:41
int Int_t
Signed integer 4 bytes (int).
Definition RtypesCore.h:59
unsigned int UInt_t
Unsigned integer 4 bytes (unsigned int).
Definition RtypesCore.h:60
constexpr Bool_t kFALSE
Definition RtypesCore.h:108
double Double_t
Double 8 bytes.
Definition RtypesCore.h:73
constexpr Bool_t kTRUE
Definition RtypesCore.h:107
ETF1Wid
Definition TF1Editor.cxx:35
@ kTF1_DRW
Definition TF1Editor.cxx:38
@ kTF1_TIT
Definition TF1Editor.cxx:36
@ kTF1_XMAX
Definition TF1Editor.cxx:37
@ kTF1_XSLD
Definition TF1Editor.cxx:37
@ kTF1_NPX
Definition TF1Editor.cxx:36
@ kTF1_PAR
Definition TF1Editor.cxx:38
@ kTF1_XMIN
Definition TF1Editor.cxx:37
@ 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,...)
Formats a string in a circular formatting buffer.
Definition TString.cxx:2496
static TClass * Class()
Class to manage histogram axis.
Definition TAxis.h:32
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition TClass.h:84
TGCheckButton * fDrawMode
immediate function redraw (if selected)
Definition TF1Editor.h:34
virtual void DoXRange()
Slot connected to min/max settings of the slider range.
virtual void DoParameterSettings()
Slot connected to the function parameter(s) settings.
virtual void DoSliderXReleased()
Slot connected to the x-Slider.
void ActivateBaseClassEditors(TClass *cl) override
Exclude TAttFillEditor from this interface.
TF1Editor(const TGWindow *p=nullptr, Int_t width=140, Int_t height=30, UInt_t options=kChildFrame, Pixel_t back=GetDefaultFrameBackground())
Definition TF1Editor.cxx:41
virtual void DoXPoints()
Slot connected to the number of points setting.
virtual void DoSliderXMoved()
Slot connected to the x-Slider range for function redrawing.
TGLabel * fParLabel
label for number of parameters
Definition TF1Editor.h:33
virtual void DoSliderXPressed()
Slot connected to the x-Slider.
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
~TF1Editor() override
Destructor of TF1 editor.
void SetModel(TObject *obj) override
Pick up the function parameters and options.
TF1 * fF1
selected TF1 object
Definition TF1Editor.h:30
TGNumberEntryField * fSldMaxX
contains maximum value of x-axis
Definition TF1Editor.h:39
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 TF1.h:182
static TClass * Class()
This class is used for function parameter settings.
Selects different options.
Definition TGButton.h:264
virtual void AddFrame(TGFrame *f, TGLayoutHints *l=nullptr)
Add frame to the composite frame using the specified layout hints.
Definition TGFrame.cxx:1109
TGCompositeFrame(const TGCompositeFrame &)=delete
Dragging the slider will generate the event:
This class handles GUI labels.
Definition TGLabel.h:24
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:399
TGNumberEntry is a number entry input widget with up/down buttons.
@ kNEANonNegative
Non-negative number.
@ kNEAAnyNumber
Attributes of number entry field.
@ kNESInteger
Style of number entry field.
@ kNESRealFour
Fixed fraction real, four digit.
@ kNELLimitMinMax
Both lower and upper limits.
TGClient * fClient
Connection to display server.
Definition TGObject.h:25
A text buffer is used in several widgets, like TGTextEntry, TGFileDialog, etc.
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
ROOT GUI Window base class.
Definition TGWindow.h:23
virtual const TGWindow * GetMainFrame() const
Returns top level main frame.
Definition TGWindow.cxx:150
virtual void ActivateBaseClassEditors(TClass *cl)
Provide list of editors for base-classes.
TGedEditor * fGedEditor
manager of this frame
Definition TGedFrame.h:48
TGedFrame(const TGedFrame &)=delete
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:94
virtual void Update()
Update the current pad when an attribute is changed via GUI.
Definition TGedFrame.cxx:71
Bool_t fAvoidSignal
flag for executing slots
Definition TGedFrame.h:50
Mother of all ROOT objects.
Definition TObject.h:42
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition TObject.cxx:549
Basic string class.
Definition TString.h:138
void ToUpper()
Change string to upper case.
Definition TString.cxx:1202
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition TString.h:641
small helper class to store/restore gPad context in TPad methods
Definition TVirtualPad.h:61
TText * text
int main(int argc, char **argv)
Definition hadd.cxx:631
Double_t x[n]
Definition legend1.C:17