Logo ROOT   6.10/09
Reference Guide
TGeoSphereEditor.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 // TGeoSphereEditor //
15 // //
16 //////////////////////////////////////////////////////////////////////////
17 //Begin_Html
18 /*
19 <img src="gif/sphe_pic.gif">
20 */
21 //End_Html
22 //Begin_Html
23 /*
24 <img src="gif/sphe_ed.jpg">
25 */
26 //End_Html
27 
28 #include "TGeoSphereEditor.h"
29 #include "TGeoTabManager.h"
30 #include "TGeoSphere.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 #include "TGDoubleSlider.h"
42 
44 
49 };
50 
51 ////////////////////////////////////////////////////////////////////////////////
52 /// Constructor for sphere editor
53 
55  Int_t height, UInt_t options, Pixel_t back)
56  : TGeoGedFrame(p, width, height, options | kVerticalFrame, back)
57 {
58  fShape = 0;
59  fRmini = fRmaxi = fTheta1i = fTheta2i = fPhi1i = fPhi2i = 0.0;
60  fNamei = "";
63  fLock = kFALSE;
64 
65  // TextEntry for shape name
66  MakeTitle("Name");
67  fShapeName = new TGTextEntry(this, new TGTextBuffer(50), kSPHERE_NAME);
69  fShapeName->SetToolTipText("Enter the sphere name");
70  fShapeName->Associate(this);
71  AddFrame(fShapeName, new TGLayoutHints(kLHintsLeft, 3, 1, 2, 5));
72 
73  TGTextEntry *nef;
74  MakeTitle("Sphere dimensions");
75  TGCompositeFrame *compxyz = new TGCompositeFrame(this, 118, 30, kVerticalFrame | kRaisedFrame);
76  // Number entry for rmin
77  TGCompositeFrame *f1 = new TGCompositeFrame(compxyz, 118, 10, kHorizontalFrame |
79  f1->AddFrame(new TGLabel(f1, "Rmin"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
80  fERmin = new TGNumberEntry(f1, 0., 5, kSPHERE_RMIN);
83  nef->SetToolTipText("Enter the inner radius");
84  fERmin->Associate(this);
86  f1->AddFrame(fERmin, new TGLayoutHints(kLHintsRight , 2, 2, 4, 4));
87  compxyz->AddFrame(f1, new TGLayoutHints(kLHintsLeft | kLHintsExpandX , 2, 2, 4, 4));
88 
89  // Number entry for Rmax
90  f1 = new TGCompositeFrame(compxyz, 118, 10, kHorizontalFrame |
92  f1->AddFrame(new TGLabel(f1, "Rmax"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
93  fERmax = new TGNumberEntry(f1, 0., 5, kSPHERE_RMAX);
96  nef->SetToolTipText("Enter the outer radius");
97  fERmax->Associate(this);
99  f1->AddFrame(fERmax, new TGLayoutHints(kLHintsRight, 2, 2, 4, 4));
100  compxyz->AddFrame(f1, new TGLayoutHints(kLHintsLeft | kLHintsExpandX , 2, 2, 4, 4));
101  AddFrame(compxyz, new TGLayoutHints(kLHintsLeft, 2, 2, 2, 2));
102 
103  MakeTitle("Phi/theta range");
104  TGCompositeFrame *f11 = new TGCompositeFrame(this, 150,200, kHorizontalFrame);
105  compxyz = new TGCompositeFrame(f11, 75, 200, kHorizontalFrame | kRaisedFrame);
106  // Vertical slider
107  fSPhi = new TGDoubleVSlider(compxyz,140);
108  fSPhi->SetRange(0.,720.);
109  compxyz->AddFrame(fSPhi, new TGLayoutHints(kLHintsLeft | kLHintsExpandY, 2, 2, 4, 4));
110  f1 = new TGCompositeFrame(compxyz, 50, 200, kVerticalFrame);
111  f1->AddFrame(new TGLabel(f1, "Phi min."), new TGLayoutHints(kLHintsTop | kLHintsLeft, 2, 2, 2, 2));
112  fEPhi1 = new TGNumberEntry(f1, 0., 5, kSPHERE_PHI1);
115  nef = (TGTextEntry*)fEPhi1->GetNumberEntry();
116  nef->SetToolTipText("Enter the phi1 value");
117  fEPhi1->Associate(this);
119 
120  fEPhi2 = new TGNumberEntry(f1, 0., 5, kSPHERE_PHI2);
123  nef = (TGTextEntry*)fEPhi2->GetNumberEntry();
124  nef->SetToolTipText("Enter the phi2 value");
125  fEPhi2->Associate(this);
128  f1->AddFrame(new TGLabel(f1, "Phi max."), new TGLayoutHints(kLHintsBottom | kLHintsLeft, 2, 2, 2, 2));
129  compxyz->AddFrame(f1, new TGLayoutHints(kLHintsLeft | kLHintsExpandX | kLHintsExpandY, 2, 2, 2, 2));
130 
131  compxyz->Resize(75,150);
132  f11->AddFrame(compxyz, new TGLayoutHints(kLHintsLeft, 0,0,0,0));
133 
134  compxyz = new TGCompositeFrame(f11, 75, 200, kHorizontalFrame | kRaisedFrame);
135  // Vertical slider
136  fSTheta = new TGDoubleVSlider(compxyz,140);
137  fSTheta->SetRange(0.,180.);
138  compxyz->AddFrame(fSTheta, new TGLayoutHints(kLHintsLeft | kLHintsExpandY, 2, 2, 4, 4));
139  f1 = new TGCompositeFrame(compxyz, 50, 200, kVerticalFrame);
140  f1->AddFrame(new TGLabel(f1, "Theta min."), new TGLayoutHints(kLHintsTop | kLHintsLeft, 2, 2, 2, 2));
141  fETheta1 = new TGNumberEntry(f1, 0., 5, kSPHERE_THETA1);
145  nef->SetToolTipText("Enter the theta1 value");
146  fETheta1->Associate(this);
148 
149  fETheta2 = new TGNumberEntry(f1, 0., 5, kSPHERE_THETA2);
153  nef->SetToolTipText("Enter the theta2 value");
154  fETheta2->Associate(this);
156  f1->AddFrame(new TGLabel(f1, "Theta max."), new TGLayoutHints(kLHintsBottom | kLHintsLeft, 2, 2, 2, 2));
157  compxyz->AddFrame(f1, new TGLayoutHints(kLHintsLeft | kLHintsExpandX | kLHintsExpandY, 2, 2, 2, 2));
158 
159  compxyz->Resize(75,150);
160  f11->AddFrame(compxyz, new TGLayoutHints(kLHintsRight, 0, 0, 0, 0));
161 
162  AddFrame(f11, new TGLayoutHints(kLHintsLeft, 0, 0, 0, 0));
163 
164  // Delayed draw
165  f1 = new TGCompositeFrame(this, 155, 10, kHorizontalFrame | kFixedWidth | kSunkenFrame);
166  fDelayed = new TGCheckButton(f1, "Delayed draw");
167  f1->AddFrame(fDelayed, new TGLayoutHints(kLHintsLeft , 2, 2, 4, 4));
168  AddFrame(f1, new TGLayoutHints(kLHintsLeft, 6, 6, 4, 4));
169 
170  // Buttons
171  f1 = new TGCompositeFrame(this, 155, 10, kHorizontalFrame | kFixedWidth);
172  fApply = new TGTextButton(f1, "Apply");
173  f1->AddFrame(fApply, new TGLayoutHints(kLHintsLeft, 2, 2, 4, 4));
174  fApply->Associate(this);
175  fUndo = new TGTextButton(f1, "Undo");
176  f1->AddFrame(fUndo, new TGLayoutHints(kLHintsRight , 2, 2, 4, 4));
177  fUndo->Associate(this);
178  AddFrame(f1, new TGLayoutHints(kLHintsLeft, 6, 6, 4, 4));
180 }
181 
182 ////////////////////////////////////////////////////////////////////////////////
183 /// Destructor.
184 
186 {
187  TGFrameElement *el;
188  TIter next(GetList());
189  while ((el = (TGFrameElement *)next())) {
190  if (el->fFrame->IsComposite())
192  }
193  Cleanup();
194 }
195 
196 ////////////////////////////////////////////////////////////////////////////////
197 /// Connect signals to slots.
198 
200 {
201  fApply->Connect("Clicked()", "TGeoSphereEditor", this, "DoApply()");
202  fUndo->Connect("Clicked()", "TGeoSphereEditor", this, "DoUndo()");
203  fShapeName->Connect("TextChanged(const char *)", "TGeoSphereEditor", this, "DoModified()");
204  fERmin->Connect("ValueSet(Long_t)", "TGeoSphereEditor", this, "DoRmin()");
205  fERmax->Connect("ValueSet(Long_t)", "TGeoSphereEditor", this, "DoRmax()");
206  fEPhi1->Connect("ValueSet(Long_t)", "TGeoSphereEditor", this, "DoPhi1()");
207  fEPhi2->Connect("ValueSet(Long_t)", "TGeoSphereEditor", this, "DoPhi2()");
208  fETheta1->Connect("ValueSet(Long_t)", "TGeoSphereEditor", this, "DoTheta1()");
209  fETheta2->Connect("ValueSet(Long_t)", "TGeoSphereEditor", this, "DoTheta2()");
210  fSPhi->Connect("PositionChanged()", "TGeoSphereEditor", this, "DoPhi()");
211  fSTheta->Connect("PositionChanged()", "TGeoSphereEditor", this, "DoTheta()");
212  fInit = kFALSE;
213 }
214 
215 
216 ////////////////////////////////////////////////////////////////////////////////
217 /// Connect to a given sphere.
218 
220 {
221  if (obj == 0 || (obj->IsA()!=TGeoSphere::Class())) {
222  SetActive(kFALSE);
223  return;
224  }
225  fShape = (TGeoSphere*)obj;
226  fRmini = fShape->GetRmin();
227  fRmaxi = fShape->GetRmax();
228  fPhi1i = fShape->GetPhi1();
229  fPhi2i = fShape->GetPhi2();
232  fNamei = fShape->GetName();
242 
245 
247  SetActive();
248 }
249 
250 ////////////////////////////////////////////////////////////////////////////////
251 /// Check if shape drawing is delayed.
252 
254 {
255  return (fDelayed->GetState() == kButtonDown);
256 }
257 
258 ////////////////////////////////////////////////////////////////////////////////
259 /// Slot for name.
260 
262 {
263  DoModified();
264 }
265 
266 ////////////////////////////////////////////////////////////////////////////////
267 /// Slot for applying modifications.
268 
270 {
271  const char *name = fShapeName->GetText();
272  if (strcmp(name,fShape->GetName())) fShape->SetName(name);
273  Double_t rmin = fERmin->GetNumber();
274  Double_t rmax = fERmax->GetNumber();
275  Double_t phi1 = fEPhi1->GetNumber();
276  Double_t phi2 = fEPhi2->GetNumber();
277  if ((phi2-phi1) > 360.001) {
278  phi1 = 0.;
279  phi2 = 360.;
280  fEPhi1->SetNumber(phi1);
281  fEPhi2->SetNumber(phi2);
282  fLock = kTRUE;
283  fSPhi->SetPosition(phi1,phi2);
284  fLock = kFALSE;
285  }
286  Double_t theta1 = fETheta1->GetNumber();
287  Double_t theta2 = fETheta2->GetNumber();
288  fShape->SetSphDimensions(rmin, rmax, theta1,theta2,phi1,phi2);
289  fShape->ComputeBBox();
290  fUndo->SetEnabled();
292  if (fPad) {
294  fShape->Draw();
295  fPad->GetView()->ShowAxis();
296  } else Update();
297  }
298 }
299 
300 ////////////////////////////////////////////////////////////////////////////////
301 /// Slot for signaling modifications.
302 
304 {
305  fApply->SetEnabled();
306 }
307 
308 ////////////////////////////////////////////////////////////////////////////////
309 /// Slot for undoing last operation.
310 
312 {
321  DoApply();
324 }
325 
326 ////////////////////////////////////////////////////////////////////////////////
327 /// Slot for Rmin.
328 
330 {
331  Double_t rmin = fERmin->GetNumber();
332  Double_t rmax = fERmax->GetNumber();
333  if (rmin <= 0.) {
334  rmin = 0.;
335  fERmin->SetNumber(rmin);
336  }
337  if (rmin >= rmax) {
338  rmin = rmax - 0.1;
339  fERmin->SetNumber(rmin);
340  }
341  DoModified();
342  if (!IsDelayed()) DoApply();
343 }
344 
345 ////////////////////////////////////////////////////////////////////////////////
346 /// Slot for Rmax.
347 
349 {
350  Double_t rmin = fERmin->GetNumber();
351  Double_t rmax = fERmax->GetNumber();
352  if (rmax <= 0.) {
353  rmax = 0.1;
354  fERmax->SetNumber(rmax);
355  }
356  if (rmax < rmin+1.e-10) {
357  rmax = rmin + 0.1;
358  if (rmin < 0.) rmin = 0.;
359  fERmax->SetNumber(rmax);
360  }
361  DoModified();
362  if (!IsDelayed()) DoApply();
363 }
364 
365 ////////////////////////////////////////////////////////////////////////////////
366 /// Slot for phi1.
367 
369 {
370  Double_t phi1 = fEPhi1->GetNumber();
371  Double_t phi2 = fEPhi2->GetNumber();
372  if (phi1 > 360-1.e-10) {
373  phi1 = 0.;
374  fEPhi1->SetNumber(phi1);
375  }
376  if (phi2<phi1+1.e-10) {
377  phi1 = phi2 - 0.1;
378  fEPhi1->SetNumber(phi1);
379  }
380  if (!fLock) {
381  DoModified();
382  fLock = kTRUE;
383  fSPhi->SetPosition(phi1,phi2);
384  } else fLock = kFALSE;
385  if (!IsDelayed()) DoApply();
386 }
387 
388 ////////////////////////////////////////////////////////////////////////////////
389 /// Slot for phi2.
390 
392 {
393  Double_t phi1 = fEPhi1->GetNumber();
394  Double_t phi2 = fEPhi2->GetNumber();
395  if (phi2-phi1 > 360.) {
396  phi2 -= 360.;
397  fEPhi2->SetNumber(phi2);
398  }
399  if (phi2<phi1+1.e-10) {
400  phi2 = phi1 + 0.1;
401  fEPhi2->SetNumber(phi2);
402  }
403  if (!fLock) {
404  DoModified();
405  fLock = kTRUE;
406  fSPhi->SetPosition(phi1,phi2);
407  } else fLock = kFALSE;
408  if (!IsDelayed()) DoApply();
409 }
410 
411 ////////////////////////////////////////////////////////////////////////////////
412 /// Slot for phi slider.
413 
415 {
416  if (!fLock) {
417  DoModified();
418  fLock = kTRUE;
420  fLock = kTRUE;
422  } else fLock = kFALSE;
423  if (!IsDelayed()) DoApply();
424 }
425 
426 ////////////////////////////////////////////////////////////////////////////////
427 /// Slot for theta1.
428 
430 {
431  Double_t theta1 = fETheta1->GetNumber();
432  Double_t theta2 = fETheta2->GetNumber();
433  if (theta2<theta1+1.e-10) {
434  theta2 = theta1 + 0.1;
435  fETheta2->SetNumber(theta2);
436  }
437  if (!fLock) {
438  DoModified();
439  fLock = kTRUE;
440  fSTheta->SetPosition(theta1,theta2);
441  } else fLock = kFALSE;
442  if (!IsDelayed()) DoApply();
443 }
444 
445 ////////////////////////////////////////////////////////////////////////////////
446 /// Slot for theta2.
447 
449 {
450  Double_t theta1 = fETheta1->GetNumber();
451  Double_t theta2 = fETheta2->GetNumber();
452  if (theta2<theta1+1.e-10) {
453  theta1 = theta2 - 0.1;
454  fETheta1->SetNumber(theta1);
455  }
456  if (!fLock) {
457  DoModified();
458  fLock = kTRUE;
459  fSTheta->SetPosition(theta1,theta2);
460  } else fLock = kFALSE;
461  if (!IsDelayed()) DoApply();
462 }
463 
464 ////////////////////////////////////////////////////////////////////////////////
465 /// Slot for theta slider.
466 
468 {
469  if (!fLock) {
470  DoModified();
471  fLock = kTRUE;
473  fLock = kTRUE;
475  } else fLock = kFALSE;
476  if (!IsDelayed()) DoApply();
477 }
virtual Float_t GetMinPosition() const
virtual void Resize(UInt_t w=0, UInt_t h=0)
Resize the frame.
Definition: TGFrame.cxx:587
Spherical shell class.
Definition: TGeoSphere.h:17
virtual Float_t GetMaxPosition() const
void DoPhi()
Slot for phi slider.
TGNumberEntry * fETheta1
TGeoSphere * fShape
TVirtualGeoPainter * GetPainter() const
Definition: TGeoManager.h:187
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)
Set the name of the TNamed.
Definition: TNamed.cxx:131
virtual void SetNumber(Double_t val)
virtual Double_t GetRmax() const
Definition: TGeoSphere.h:68
virtual Bool_t IsPaintingShape() const =0
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
virtual Bool_t IsComposite() const
Definition: TGFrame.h:259
virtual void SetModel(TObject *obj)
Connect to a given sphere.
virtual void SetRange(Float_t min, Float_t max)
Double_t GetPhi2() const
Definition: TGeoSphere.h:72
virtual void DoApply()
Slot for applying modifications.
TGNumberEntry * fEPhi1
virtual void ConnectSignals2Slots()
Connect signals to slots.
static void Cleanup(TGCompositeFrame *frame)
Static method to cleanup hirarchically all daughters of a composite frame.
Double_t GetPhi1() const
Definition: TGeoSphere.h:71
ULong_t Pixel_t
Definition: GuiTypes.h:39
void Class()
Definition: Class.C:29
TGCheckButton * fDelayed
void DoTheta2()
Slot for theta2.
ETGeoSphereWid
TGTextButton * fUndo
virtual void SetActive(Bool_t active=kTRUE)
Set active GUI attribute frames related to the selected object.
TGCompositeFrame(const TGCompositeFrame &)
void SetSphDimensions(Double_t rmin, Double_t rmax, Double_t theta1, Double_t theta2, Double_t phi1, Double_t phi2)
Set spherical segment dimensions.
virtual TList * GetList() const
Definition: TGFrame.h:369
void DoName()
Slot for name.
virtual EButtonState GetState() const
Definition: TGButton.h:112
void DoRmin()
Slot for Rmin.
virtual TView * GetView() const =0
virtual const char * GetName() const
Get the shape name.
Definition: TGeoShape.cxx:250
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
virtual void Associate(const TGWindow *w)
Make w the window that will receive the generated messages.
void DoModified()
Slot for signaling modifications.
Double_t GetTheta1() const
Definition: TGeoSphere.h:69
virtual void SetSize(const TGDimension &s)
Definition: TGFrame.h:299
virtual void Associate(const TGWindow *w)
Definition: TGWidget.h:84
TGDoubleVSlider * fSTheta
virtual void DoUndo()
Slot for undoing last operation.
TGNumberEntry * fERmin
unsigned int UInt_t
Definition: RtypesCore.h:42
TGTextButton * fApply
TGFrame * fFrame
Definition: TGLayout.h:119
virtual void ShowAxis()=0
TGNumberEntry * fERmax
void DoTheta1()
Slot for theta1.
void DoPhi1()
Slot for phi1.
void SetNumAttr(EAttribute attr=kNEAAnyNumber)
const Bool_t kFALSE
Definition: RtypesCore.h:92
TGDimension GetSize() const
Definition: TGFrame.h:277
const char * GetText() const
Definition: TGTextEntry.h:134
virtual UInt_t GetDefaultHeight() const
Definition: TGFrame.h:238
TGDoubleVSlider * fSPhi
#define ClassImp(name)
Definition: Rtypes.h:336
R__EXTERN TGeoManager * gGeoManager
Definition: TGeoManager.h:553
double Double_t
Definition: RtypesCore.h:55
virtual void SetEnabled(Bool_t e=kTRUE)
Set enabled or disabled state of button.
Definition: TGButton.cxx:409
virtual Double_t GetNumber() const
virtual void ComputeBBox()
compute bounding box of the sphere
Definition: TGeoSphere.cxx:143
TGeoSphereEditor(const TGWindow *p=0, Int_t width=140, Int_t height=30, UInt_t options=kChildFrame, Pixel_t back=GetDefaultFrameBackground())
Constructor for sphere editor.
you should not use this method at all Int_t Int_t Double_t Double_t Double_t e
Definition: TRolke.cxx:630
TGNumberEntry * fEPhi2
virtual void AddFrame(TGFrame *f, TGLayoutHints *l=0)
Add frame to the composite frame using the specified layout hints.
Definition: TGFrame.cxx:1099
void DoTheta()
Slot for theta slider.
Mother of all ROOT objects.
Definition: TObject.h:37
Bool_t fInit
Definition: TGedFrame.h:53
void DoPhi2()
Slot for phi2.
TGNumberEntryField * GetNumberEntry() const
TGNumberEntry * fETheta2
TF1 * f1
Definition: legend1.C:11
virtual void SetPosition(Float_t min, Float_t max)
virtual void Update()
Override Update from TGedFrame as fGedEditor can be null.
Bool_t IsDelayed() const
Check if shape drawing is delayed.
virtual ~TGeoSphereEditor()
Destructor.
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:26
virtual void Cleanup()
Cleanup and delete all objects contained in this composite frame.
Definition: TGFrame.cxx:949
void DoRmax()
Slot for Rmax.
virtual void Draw(Option_t *option="")
Draw this shape.
Definition: TGeoShape.cxx:723
const Bool_t kTRUE
Definition: RtypesCore.h:91
virtual void MakeTitle(const char *title)
Create attribute frame title.
Definition: TGedFrame.cxx:96
virtual Double_t GetRmin() const
Definition: TGeoSphere.h:67
UInt_t GetDefaultHeight() const
TGTextEntry * fShapeName
Double_t GetTheta2() const
Definition: TGeoSphere.h:70