ROOT  6.06/09
Reference Guide
TGeoTorusEditor.cxx
Go to the documentation of this file.
1 // @(#):$Id$
2 // Author: M.Gheata
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2002, 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 // TGeoTorusEditor //
15 // //
16 //////////////////////////////////////////////////////////////////////////
17 //Begin_Html
18 /*
19 <img src="gif/torus_pic.gif">
20 */
21 //End_Html
22 //Begin_Html
23 /*
24 <img src="gif/torus_ed.jpg">
25 */
26 //End_Html
27 
28 #include "TGeoTorusEditor.h"
29 #include "TGeoTabManager.h"
30 #include "TGeoTorus.h"
31 #include "TGeoManager.h"
32 #include "TVirtualGeoPainter.h"
33 #include "TPad.h"
34 #include "TView.h"
35 #include "TGTab.h"
36 #include "TGComboBox.h"
37 #include "TGButton.h"
38 #include "TGTextEntry.h"
39 #include "TGNumberEntry.h"
40 #include "TGLabel.h"
41 
43 
44 enum ETGeoTorusWid {
45  kTORUS_NAME, kTORUS_R, kTORUS_RMIN, kTORUS_RMAX, kTORUS_PHI1,
46  kTORUS_DPHI, kTORUS_APPLY, kTORUS_UNDO
47 };
48 
49 ////////////////////////////////////////////////////////////////////////////////
50 /// Constructor for torus editor
51 
53  Int_t height, UInt_t options, Pixel_t back)
54  : TGeoGedFrame(p, width, height, options | kVerticalFrame, back)
55 {
56  fShape = 0;
57  fRi = fRmini = fRmaxi = fPhi1i = fDphii = 0.0;
58  fNamei = "";
61 
62  // TextEntry for shape name
63  MakeTitle("Name");
64  fShapeName = new TGTextEntry(this, new TGTextBuffer(50), kTORUS_NAME);
66  fShapeName->SetToolTipText("Enter the torus name");
67  fShapeName->Associate(this);
68  AddFrame(fShapeName, new TGLayoutHints(kLHintsLeft, 3, 1, 2, 5));
69 
70  TGTextEntry *nef;
71  MakeTitle("Dimensions");
72  // Number entry for R.
74  f1->AddFrame(new TGLabel(f1, "R"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
75  fER = new TGNumberEntry(f1, 0., 5, kTORUS_R);
77  fER->Resize(100, fER->GetDefaultHeight());
78  nef = (TGTextEntry*)fER->GetNumberEntry();
79  nef->SetToolTipText("Enter the axial radius R");
80  fER->Associate(this);
81  f1->AddFrame(fER, new TGLayoutHints(kLHintsRight, 2, 2, 4, 4));
82  AddFrame(f1, new TGLayoutHints(kLHintsLeft, 2, 2, 4, 4));
83 
84  // Number entry for rmin.
85  f1 = new TGCompositeFrame(this, 155, 10, kHorizontalFrame | kFixedWidth);
86  f1->AddFrame(new TGLabel(f1, "Rmin"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
87  fERmin = new TGNumberEntry(f1, 0., 5, kTORUS_RMIN);
91  nef->SetToolTipText("Enter the inner radius Rmin");
92  fERmin->Associate(this);
93  f1->AddFrame(fERmin, new TGLayoutHints(kLHintsRight, 2, 2, 4, 4));
94  AddFrame(f1, new TGLayoutHints(kLHintsLeft, 2, 2, 4, 4));
95 
96  // Number entry for rmax
97  f1 = new TGCompositeFrame(this, 155, 10, kHorizontalFrame | kFixedWidth);
98  f1->AddFrame(new TGLabel(f1, "Rmax"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
99  fERmax = new TGNumberEntry(f1, 0., 5, kTORUS_RMAX);
102  nef = (TGTextEntry*)fERmax->GetNumberEntry();
103  nef->SetToolTipText("Enter the outer radius Rmax");
104  fERmax->Associate(this);
105  f1->AddFrame(fERmax, new TGLayoutHints(kLHintsRight, 2, 2, 4, 4));
106  AddFrame(f1, new TGLayoutHints(kLHintsLeft, 2, 2, 4, 4));
107 
108  // Number entry for Phi1
109  f1 = new TGCompositeFrame(this, 155, 10, kHorizontalFrame | kFixedWidth);
110  f1->AddFrame(new TGLabel(f1, "Phi1"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
111  fEPhi1 = new TGNumberEntry(f1, 0., 5, kTORUS_PHI1);
114  nef = (TGTextEntry*)fEPhi1->GetNumberEntry();
115  nef->SetToolTipText("Enter the starting phi angle[deg]");
116  fEPhi1->Associate(this);
117  f1->AddFrame(fEPhi1, new TGLayoutHints(kLHintsRight, 2, 2, 4, 4));
118  AddFrame(f1, new TGLayoutHints(kLHintsLeft, 2, 2, 4, 4));
119 
120  // Number entry for Dphi
121  f1 = new TGCompositeFrame(this, 155, 10, kHorizontalFrame | kFixedWidth);
122  f1->AddFrame(new TGLabel(f1, "Dphi"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
123  fEDphi = new TGNumberEntry(f1, 0., 5, kTORUS_DPHI);
126  nef = (TGTextEntry*)fEDphi->GetNumberEntry();
127  nef->SetToolTipText("Enter the extent phi Dphi [deg]");
128  fEDphi->Associate(this);
129  f1->AddFrame(fEDphi, new TGLayoutHints(kLHintsRight, 2, 2, 4, 4));
130  AddFrame(f1, new TGLayoutHints(kLHintsLeft, 2, 2, 4, 4));
131 
132  // Delayed draw
133  f1 = new TGCompositeFrame(this, 155, 10, kHorizontalFrame | kFixedWidth | kSunkenFrame);
134  fDelayed = new TGCheckButton(f1, "Delayed draw");
135  f1->AddFrame(fDelayed, new TGLayoutHints(kLHintsLeft , 2, 2, 4, 4));
136  AddFrame(f1, new TGLayoutHints(kLHintsLeft, 6, 6, 4, 4));
137 
138  // Buttons
139  f1 = new TGCompositeFrame(this, 155, 10, kHorizontalFrame | kFixedWidth);
140  fApply = new TGTextButton(f1, "Apply");
141  f1->AddFrame(fApply, new TGLayoutHints(kLHintsLeft, 2, 2, 4, 4));
142  fApply->Associate(this);
143  fUndo = new TGTextButton(f1, "Undo");
144  f1->AddFrame(fUndo, new TGLayoutHints(kLHintsRight , 2, 2, 4, 4));
145  fUndo->Associate(this);
146  AddFrame(f1, new TGLayoutHints(kLHintsLeft, 6, 6, 4, 4));
148 }
149 
150 ////////////////////////////////////////////////////////////////////////////////
151 /// Destructor
152 
154 {
155  TGFrameElement *el;
156  TIter next(GetList());
157  while ((el = (TGFrameElement *)next())) {
158  if (el->fFrame->IsComposite())
160  }
161  Cleanup();
162 }
163 
164 ////////////////////////////////////////////////////////////////////////////////
165 /// Connect signals to slots.
166 
168 {
169  fApply->Connect("Clicked()", "TGeoTorusEditor", this, "DoApply()");
170  fUndo->Connect("Clicked()", "TGeoTorusEditor", this, "DoUndo()");
171  fShapeName->Connect("TextChanged(const char *)", "TGeoTorusEditor", this, "DoModified()");
172  fER->Connect("ValueSet(Long_t)", "TGeoTorusEditor", this, "DoR()");
173  fERmin->Connect("ValueSet(Long_t)", "TGeoTorusEditor", this, "DoRmin()");
174  fERmax->Connect("ValueSet(Long_t)", "TGeoTorusEditor", this, "DoRmax()");
175  fEPhi1->Connect("ValueSet(Long_t)", "TGeoTorusEditor", this, "DoPhi1()");
176  fEDphi->Connect("ValueSet(Long_t)", "TGeoTorusEditor", this, "DoDphi()");
177  fER->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoTorusEditor", this, "DoModified()");
178  fERmin->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoTorusEditor", this, "DoModified()");
179  fERmax->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoTorusEditor", this, "DoModified()");
180  fEPhi1->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoTorusEditor", this, "DoModified()");
181  fEDphi->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoTorusEditor", this, "DoModified()");
182  fInit = kFALSE;
183 }
184 
185 
186 ////////////////////////////////////////////////////////////////////////////////
187 /// Connect to the selected object.
188 
190 {
191  if (obj == 0 || (obj->IsA()!=TGeoTorus::Class())) {
192  SetActive(kFALSE);
193  return;
194  }
195  fShape = (TGeoTorus*)obj;
196  fRi = fShape->GetR();
197  fRmini = fShape->GetRmin();
198  fRmaxi = fShape->GetRmax();
199  fPhi1i = fShape->GetPhi1();
200  fDphii = fShape->GetDphi();
201  const char *sname = fShape->GetName();
202  if (!strcmp(sname, fShape->ClassName())) fShapeName->SetText("-no_name");
203  else {
204  fShapeName->SetText(sname);
205  fNamei = sname;
206  }
207  fER->SetNumber(fRi);
214 
216  SetActive();
217 }
218 
219 ////////////////////////////////////////////////////////////////////////////////
220 /// Check if shape drawing is delayed.
221 
223 {
224  return (fDelayed->GetState() == kButtonDown);
225 }
226 
227 ////////////////////////////////////////////////////////////////////////////////
228 /// Slot for name.
229 
231 {
232  DoModified();
233 }
234 
235 ////////////////////////////////////////////////////////////////////////////////
236 /// Slot for applying current settings.
237 
239 {
240  const char *name = fShapeName->GetText();
241  if (strcmp(name,fShape->GetName())) fShape->SetName(name);
242  Double_t r = fER->GetNumber();
243  Double_t rmax = fERmax->GetNumber();
244  Double_t rmin = fERmin->GetNumber();
245  Double_t phi = fEPhi1->GetNumber();
246  Double_t dphi = fEDphi->GetNumber();
247  Double_t param[5];
248  param[0] = r;
249  param[1] = rmin;
250  param[2] = rmax;
251  param[3] = phi;
252  param[4] = dphi;
253  fShape->SetDimensions(param);
254  fShape->ComputeBBox();
255  fUndo->SetEnabled();
257  if (fPad) {
259  TView *view = fPad->GetView();
260  if (!view) {
261  fShape->Draw();
262  fPad->GetView()->ShowAxis();
263  } else {
264  view->SetRange(-fShape->GetDX(), -fShape->GetDY(), -fShape->GetDZ(),
265  fShape->GetDX(), fShape->GetDY(), fShape->GetDZ());
266  Update();
267  }
268  } else Update();
269  }
270 }
271 
272 ////////////////////////////////////////////////////////////////////////////////
273 /// Slot for notifying modifications.
274 
276 {
277  fApply->SetEnabled();
278 }
279 
280 ////////////////////////////////////////////////////////////////////////////////
281 /// Slot for undoing last operation.
282 
284 {
285  fER->SetNumber(fRi);
290  DoApply();
293 }
294 
295 ////////////////////////////////////////////////////////////////////////////////
296 /// Slot for R.
297 
299 {
300  Double_t r = fER->GetNumber();
301  Double_t rmax = fERmax->GetNumber();
302  if (r<rmax) {
303  r = rmax;
304  fER->SetNumber(r);
305  }
306  DoModified();
307  if (!IsDelayed()) DoApply();
308 }
309 
310 ////////////////////////////////////////////////////////////////////////////////
311 /// Slot for Rmin.
312 
314 {
315  Double_t rmin = fERmin->GetNumber();
316  Double_t rmax = fERmax->GetNumber();
317  if (rmin>rmax) {
318  rmin = rmax-0.1;
319  fERmin->SetNumber(rmin);
320  }
321  DoModified();
322  if (!IsDelayed()) DoApply();
323 }
324 
325 ////////////////////////////////////////////////////////////////////////////////
326 /// Slot for Rmax.
327 
329 {
330  Double_t r = fER->GetNumber();
331  Double_t rmin = fERmin->GetNumber();
332  Double_t rmax = fERmax->GetNumber();
333  if (rmax<=rmin) {
334  rmax = rmin+0.1;
335  fERmax->SetNumber(rmax);
336  }
337  if (rmax>r) {
338  rmax = r;
339  fERmax->SetNumber(rmax);
340  }
341  DoModified();
342  if (!IsDelayed()) DoApply();
343 }
344 
345 ////////////////////////////////////////////////////////////////////////////////
346 /// Slot for phi.
347 
349 {
350  Double_t phi = fEPhi1->GetNumber();
351  if (phi<0 || phi>360) {
352  phi = 0;
353  fEPhi1->SetNumber(phi);
354  }
355  DoModified();
356  if (!IsDelayed()) DoApply();
357 }
358 
359 ////////////////////////////////////////////////////////////////////////////////
360 /// Slot for Dphi.
361 
363 {
364  Double_t dphi = fEDphi->GetNumber();
365  if (dphi<=0 || dphi>360) {
366  dphi = 1;
367  fEDphi->SetNumber(dphi);
368  }
369  DoModified();
370  if (!IsDelayed()) DoApply();
371 }
372 
virtual void Resize(UInt_t w=0, UInt_t h=0)
Resize the frame.
Definition: TGFrame.cxx:587
TGCheckButton * fDelayed
TGTextButton * fApply
void DoDphi()
Slot for Dphi.
void DoApply()
Slot for applying current settings.
void DoUndo()
Slot for undoing last operation.
ClassImp(TSeqCollection) Int_t TSeqCollection TIter next(this)
Return index of object in collection.
Double_t GetR() const
Definition: TGeoTorus.h:82
ClassImp(TGeoTorusEditor) enum ETGeoTorusWid
virtual Bool_t IsComposite() const
Definition: TGFrame.h:275
virtual void SetToolTipText(const char *text, Long_t delayms=500)
Set tool tip text associated with this text entry.
virtual void SetName(const char *name)
Change (i.e.
Definition: TNamed.cxx:128
virtual void SetNumber(Double_t val)
See TView3D.
Definition: TView.h:36
Double_t GetDphi() const
Definition: TGeoTorus.h:86
virtual void SetRange(const Double_t *min, const Double_t *max)=0
virtual Bool_t IsPaintingShape() const =0
virtual TList * GetList() const
Definition: TGFrame.h:385
TGNumberEntry * fERmin
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
const Bool_t kFALSE
Definition: Rtypes.h:92
TGeoTorusEditor(const TGWindow *p=0, Int_t width=140, Int_t height=30, UInt_t options=kChildFrame, Pixel_t back=GetDefaultFrameBackground())
Constructor for torus editor.
virtual Double_t GetDY() const
Definition: TGeoBBox.h:83
TGNumberEntry * fEPhi1
virtual void ConnectSignals2Slots()
Connect signals to slots.
virtual Double_t GetDZ() const
Definition: TGeoBBox.h:84
static void Cleanup(TGCompositeFrame *frame)
Static method to cleanup hirarchically all daughters of a composite frame.
TGNumberEntry * fERmax
TGNumberEntryField * GetNumberEntry() const
ULong_t Pixel_t
Definition: GuiTypes.h:41
void Class()
Definition: Class.C:29
Double_t GetRmax() const
Definition: TGeoTorus.h:84
void DoR()
Slot for R.
const char * GetText() const
Definition: TGTextEntry.h:140
TVirtualGeoPainter * GetPainter() const
Definition: TGeoManager.h:193
virtual void SetActive(Bool_t active=kTRUE)
Set active GUI attribute frames related to the selected object.
TGCompositeFrame(const TGCompositeFrame &)
void DoModified()
Slot for notifying modifications.
Double_t GetPhi1() const
Definition: TGeoTorus.h:85
virtual ~TGeoTorusEditor()
Destructor.
TGeoTorus * fShape
virtual TView * GetView() const =0
void DoPhi1()
Slot for phi.
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 Associate(const TGWindow *w)
Make w the window that will receive the generated messages.
void DoRmin()
Slot for Rmin.
TGNumberEntry * fER
virtual Double_t GetDX() const
Definition: TGeoBBox.h:82
virtual void SetSize(const TGDimension &s)
Definition: TGFrame.h:315
ROOT::R::TRInterface & r
Definition: Object.C:4
virtual EButtonState GetState() const
Definition: TGButton.h:116
Bool_t IsDelayed() const
Check if shape drawing is delayed.
TGTextButton * fUndo
virtual const char * ClassName() const
Returns name of class to which the object belongs.
Definition: TObject.cxx:187
virtual void Associate(const TGWindow *w)
Definition: TGWidget.h:90
unsigned int UInt_t
Definition: RtypesCore.h:42
TGFrame * fFrame
Definition: TGLayout.h:125
virtual void ShowAxis()=0
const std::string sname
Definition: testIO.cxx:45
virtual const char * GetName() const
Get the shape name.
Definition: TGeoShape.cxx:247
void SetNumAttr(EAttribute attr=kNEAAnyNumber)
R__EXTERN TGeoManager * gGeoManager
Definition: TGeoManager.h:556
double Double_t
Definition: RtypesCore.h:55
virtual void SetModel(TObject *obj)
Connect to the selected object.
virtual void SetEnabled(Bool_t e=kTRUE)
Set enabled or disabled state of button.
Definition: TGButton.cxx:409
TGDimension GetSize() const
Definition: TGFrame.h:293
virtual void SetDimensions(Double_t *param)
Set torus dimensions starting from a list.
Definition: TGeoTorus.cxx:771
virtual void AddFrame(TGFrame *f, TGLayoutHints *l=0)
Add frame to the composite frame using the specified layout hints.
Definition: TGFrame.cxx:1099
#define name(a, b)
Definition: linkTestLib0.cpp:5
Mother of all ROOT objects.
Definition: TObject.h:58
virtual void ComputeBBox()
Compute bounding box of the torus.
Definition: TGeoTorus.cxx:110
Bool_t fInit
Definition: TGedFrame.h:55
virtual UInt_t GetDefaultHeight() const
Definition: TGFrame.h:254
TGNumberEntry * fEDphi
TF1 * f1
Definition: legend1.C:11
void DoRmax()
Slot for Rmax.
virtual void Update()
Override Update from TGedFrame as fGedEditor can be null.
virtual Double_t GetNumber() const
UInt_t GetDefaultHeight() 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...
TVirtualPad * fPad
Definition: TGeoGedFrame.h:28
virtual void Cleanup()
Cleanup and delete all objects contained in this composite frame.
Definition: TGFrame.cxx:949
virtual void Draw(Option_t *option="")
Draw this shape.
Definition: TGeoShape.cxx:719
const Bool_t kTRUE
Definition: Rtypes.h:91
TObject * obj
TGTextEntry * fShapeName
Double_t GetRmin() const
Definition: TGeoTorus.h:83
virtual void MakeTitle(const char *title)
Create attribute frame title.
Definition: TGedFrame.cxx:96
void DoName()
Slot for name.