Logo ROOT   6.14/05
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 /** \class TGeoSphereEditor
13 \ingroup Geometry_builder
14 
15 Editor for a TGeoSphere.
16 
17 \image html geom_sphe_pic.png
18 
19 \image html geom_sphe_ed.png
20 
21 */
22 
23 #include "TGeoSphereEditor.h"
24 #include "TGeoTabManager.h"
25 #include "TGeoSphere.h"
26 #include "TGeoManager.h"
27 #include "TVirtualGeoPainter.h"
28 #include "TPad.h"
29 #include "TView.h"
30 #include "TGTab.h"
31 #include "TGComboBox.h"
32 #include "TGButton.h"
33 #include "TGTextEntry.h"
34 #include "TGNumberEntry.h"
35 #include "TGLabel.h"
36 #include "TGDoubleSlider.h"
37 
39 
44 };
45 
46 ////////////////////////////////////////////////////////////////////////////////
47 /// Constructor for sphere editor
48 
50  Int_t height, UInt_t options, Pixel_t back)
51  : TGeoGedFrame(p, width, height, options | kVerticalFrame, back)
52 {
53  fShape = 0;
54  fRmini = fRmaxi = fTheta1i = fTheta2i = fPhi1i = fPhi2i = 0.0;
55  fNamei = "";
58  fLock = kFALSE;
59 
60  // TextEntry for shape name
61  MakeTitle("Name");
62  fShapeName = new TGTextEntry(this, new TGTextBuffer(50), kSPHERE_NAME);
64  fShapeName->SetToolTipText("Enter the sphere name");
65  fShapeName->Associate(this);
66  AddFrame(fShapeName, new TGLayoutHints(kLHintsLeft, 3, 1, 2, 5));
67 
68  TGTextEntry *nef;
69  MakeTitle("Sphere dimensions");
70  TGCompositeFrame *compxyz = new TGCompositeFrame(this, 118, 30, kVerticalFrame | kRaisedFrame);
71  // Number entry for rmin
72  TGCompositeFrame *f1 = new TGCompositeFrame(compxyz, 118, 10, kHorizontalFrame |
74  f1->AddFrame(new TGLabel(f1, "Rmin"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
75  fERmin = new TGNumberEntry(f1, 0., 5, kSPHERE_RMIN);
78  nef->SetToolTipText("Enter the inner radius");
79  fERmin->Associate(this);
81  f1->AddFrame(fERmin, new TGLayoutHints(kLHintsRight , 2, 2, 4, 4));
82  compxyz->AddFrame(f1, new TGLayoutHints(kLHintsLeft | kLHintsExpandX , 2, 2, 4, 4));
83 
84  // Number entry for Rmax
85  f1 = new TGCompositeFrame(compxyz, 118, 10, kHorizontalFrame |
87  f1->AddFrame(new TGLabel(f1, "Rmax"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
88  fERmax = new TGNumberEntry(f1, 0., 5, kSPHERE_RMAX);
91  nef->SetToolTipText("Enter the outer radius");
92  fERmax->Associate(this);
94  f1->AddFrame(fERmax, new TGLayoutHints(kLHintsRight, 2, 2, 4, 4));
95  compxyz->AddFrame(f1, new TGLayoutHints(kLHintsLeft | kLHintsExpandX , 2, 2, 4, 4));
96  AddFrame(compxyz, new TGLayoutHints(kLHintsLeft, 2, 2, 2, 2));
97 
98  MakeTitle("Phi/theta range");
99  TGCompositeFrame *f11 = new TGCompositeFrame(this, 150,200, kHorizontalFrame);
100  compxyz = new TGCompositeFrame(f11, 75, 200, kHorizontalFrame | kRaisedFrame);
101  // Vertical slider
102  fSPhi = new TGDoubleVSlider(compxyz,140);
103  fSPhi->SetRange(0.,720.);
104  compxyz->AddFrame(fSPhi, new TGLayoutHints(kLHintsLeft | kLHintsExpandY, 2, 2, 4, 4));
105  f1 = new TGCompositeFrame(compxyz, 50, 200, kVerticalFrame);
106  f1->AddFrame(new TGLabel(f1, "Phi min."), new TGLayoutHints(kLHintsTop | kLHintsLeft, 2, 2, 2, 2));
107  fEPhi1 = new TGNumberEntry(f1, 0., 5, kSPHERE_PHI1);
110  nef = (TGTextEntry*)fEPhi1->GetNumberEntry();
111  nef->SetToolTipText("Enter the phi1 value");
112  fEPhi1->Associate(this);
114 
115  fEPhi2 = new TGNumberEntry(f1, 0., 5, kSPHERE_PHI2);
118  nef = (TGTextEntry*)fEPhi2->GetNumberEntry();
119  nef->SetToolTipText("Enter the phi2 value");
120  fEPhi2->Associate(this);
123  f1->AddFrame(new TGLabel(f1, "Phi max."), new TGLayoutHints(kLHintsBottom | kLHintsLeft, 2, 2, 2, 2));
124  compxyz->AddFrame(f1, new TGLayoutHints(kLHintsLeft | kLHintsExpandX | kLHintsExpandY, 2, 2, 2, 2));
125 
126  compxyz->Resize(75,150);
127  f11->AddFrame(compxyz, new TGLayoutHints(kLHintsLeft, 0,0,0,0));
128 
129  compxyz = new TGCompositeFrame(f11, 75, 200, kHorizontalFrame | kRaisedFrame);
130  // Vertical slider
131  fSTheta = new TGDoubleVSlider(compxyz,140);
132  fSTheta->SetRange(0.,180.);
133  compxyz->AddFrame(fSTheta, new TGLayoutHints(kLHintsLeft | kLHintsExpandY, 2, 2, 4, 4));
134  f1 = new TGCompositeFrame(compxyz, 50, 200, kVerticalFrame);
135  f1->AddFrame(new TGLabel(f1, "Theta min."), new TGLayoutHints(kLHintsTop | kLHintsLeft, 2, 2, 2, 2));
136  fETheta1 = new TGNumberEntry(f1, 0., 5, kSPHERE_THETA1);
140  nef->SetToolTipText("Enter the theta1 value");
141  fETheta1->Associate(this);
143 
144  fETheta2 = new TGNumberEntry(f1, 0., 5, kSPHERE_THETA2);
148  nef->SetToolTipText("Enter the theta2 value");
149  fETheta2->Associate(this);
151  f1->AddFrame(new TGLabel(f1, "Theta max."), new TGLayoutHints(kLHintsBottom | kLHintsLeft, 2, 2, 2, 2));
152  compxyz->AddFrame(f1, new TGLayoutHints(kLHintsLeft | kLHintsExpandX | kLHintsExpandY, 2, 2, 2, 2));
153 
154  compxyz->Resize(75,150);
155  f11->AddFrame(compxyz, new TGLayoutHints(kLHintsRight, 0, 0, 0, 0));
156 
157  AddFrame(f11, new TGLayoutHints(kLHintsLeft, 0, 0, 0, 0));
158 
159  // Delayed draw
160  f1 = new TGCompositeFrame(this, 155, 10, kHorizontalFrame | kFixedWidth | kSunkenFrame);
161  fDelayed = new TGCheckButton(f1, "Delayed draw");
162  f1->AddFrame(fDelayed, new TGLayoutHints(kLHintsLeft , 2, 2, 4, 4));
163  AddFrame(f1, new TGLayoutHints(kLHintsLeft, 6, 6, 4, 4));
164 
165  // Buttons
166  f1 = new TGCompositeFrame(this, 155, 10, kHorizontalFrame | kFixedWidth);
167  fApply = new TGTextButton(f1, "Apply");
168  f1->AddFrame(fApply, new TGLayoutHints(kLHintsLeft, 2, 2, 4, 4));
169  fApply->Associate(this);
170  fUndo = new TGTextButton(f1, "Undo");
171  f1->AddFrame(fUndo, new TGLayoutHints(kLHintsRight , 2, 2, 4, 4));
172  fUndo->Associate(this);
173  AddFrame(f1, new TGLayoutHints(kLHintsLeft, 6, 6, 4, 4));
175 }
176 
177 ////////////////////////////////////////////////////////////////////////////////
178 /// Destructor.
179 
181 {
182  TGFrameElement *el;
183  TIter next(GetList());
184  while ((el = (TGFrameElement *)next())) {
185  if (el->fFrame->IsComposite())
187  }
188  Cleanup();
189 }
190 
191 ////////////////////////////////////////////////////////////////////////////////
192 /// Connect signals to slots.
193 
195 {
196  fApply->Connect("Clicked()", "TGeoSphereEditor", this, "DoApply()");
197  fUndo->Connect("Clicked()", "TGeoSphereEditor", this, "DoUndo()");
198  fShapeName->Connect("TextChanged(const char *)", "TGeoSphereEditor", this, "DoModified()");
199  fERmin->Connect("ValueSet(Long_t)", "TGeoSphereEditor", this, "DoRmin()");
200  fERmax->Connect("ValueSet(Long_t)", "TGeoSphereEditor", this, "DoRmax()");
201  fEPhi1->Connect("ValueSet(Long_t)", "TGeoSphereEditor", this, "DoPhi1()");
202  fEPhi2->Connect("ValueSet(Long_t)", "TGeoSphereEditor", this, "DoPhi2()");
203  fETheta1->Connect("ValueSet(Long_t)", "TGeoSphereEditor", this, "DoTheta1()");
204  fETheta2->Connect("ValueSet(Long_t)", "TGeoSphereEditor", this, "DoTheta2()");
205  fSPhi->Connect("PositionChanged()", "TGeoSphereEditor", this, "DoPhi()");
206  fSTheta->Connect("PositionChanged()", "TGeoSphereEditor", this, "DoTheta()");
207  fInit = kFALSE;
208 }
209 
210 
211 ////////////////////////////////////////////////////////////////////////////////
212 /// Connect to a given sphere.
213 
215 {
216  if (obj == 0 || (obj->IsA()!=TGeoSphere::Class())) {
217  SetActive(kFALSE);
218  return;
219  }
220  fShape = (TGeoSphere*)obj;
221  fRmini = fShape->GetRmin();
222  fRmaxi = fShape->GetRmax();
223  fPhi1i = fShape->GetPhi1();
224  fPhi2i = fShape->GetPhi2();
227  fNamei = fShape->GetName();
237 
240 
242  SetActive();
243 }
244 
245 ////////////////////////////////////////////////////////////////////////////////
246 /// Check if shape drawing is delayed.
247 
249 {
250  return (fDelayed->GetState() == kButtonDown);
251 }
252 
253 ////////////////////////////////////////////////////////////////////////////////
254 /// Slot for name.
255 
257 {
258  DoModified();
259 }
260 
261 ////////////////////////////////////////////////////////////////////////////////
262 /// Slot for applying modifications.
263 
265 {
266  const char *name = fShapeName->GetText();
267  if (strcmp(name,fShape->GetName())) fShape->SetName(name);
268  Double_t rmin = fERmin->GetNumber();
269  Double_t rmax = fERmax->GetNumber();
270  Double_t phi1 = fEPhi1->GetNumber();
271  Double_t phi2 = fEPhi2->GetNumber();
272  if ((phi2-phi1) > 360.001) {
273  phi1 = 0.;
274  phi2 = 360.;
275  fEPhi1->SetNumber(phi1);
276  fEPhi2->SetNumber(phi2);
277  fLock = kTRUE;
278  fSPhi->SetPosition(phi1,phi2);
279  fLock = kFALSE;
280  }
281  Double_t theta1 = fETheta1->GetNumber();
282  Double_t theta2 = fETheta2->GetNumber();
283  fShape->SetSphDimensions(rmin, rmax, theta1,theta2,phi1,phi2);
284  fShape->ComputeBBox();
285  fUndo->SetEnabled();
287  if (fPad) {
289  fShape->Draw();
290  fPad->GetView()->ShowAxis();
291  } else Update();
292  }
293 }
294 
295 ////////////////////////////////////////////////////////////////////////////////
296 /// Slot for signaling modifications.
297 
299 {
300  fApply->SetEnabled();
301 }
302 
303 ////////////////////////////////////////////////////////////////////////////////
304 /// Slot for undoing last operation.
305 
307 {
316  DoApply();
319 }
320 
321 ////////////////////////////////////////////////////////////////////////////////
322 /// Slot for Rmin.
323 
325 {
326  Double_t rmin = fERmin->GetNumber();
327  Double_t rmax = fERmax->GetNumber();
328  if (rmin <= 0.) {
329  rmin = 0.;
330  fERmin->SetNumber(rmin);
331  }
332  if (rmin >= rmax) {
333  rmin = rmax - 0.1;
334  fERmin->SetNumber(rmin);
335  }
336  DoModified();
337  if (!IsDelayed()) DoApply();
338 }
339 
340 ////////////////////////////////////////////////////////////////////////////////
341 /// Slot for Rmax.
342 
344 {
345  Double_t rmin = fERmin->GetNumber();
346  Double_t rmax = fERmax->GetNumber();
347  if (rmax <= 0.) {
348  rmax = 0.1;
349  fERmax->SetNumber(rmax);
350  }
351  if (rmax < rmin+1.e-10) {
352  rmax = rmin + 0.1;
353  if (rmin < 0.) rmin = 0.;
354  fERmax->SetNumber(rmax);
355  }
356  DoModified();
357  if (!IsDelayed()) DoApply();
358 }
359 
360 ////////////////////////////////////////////////////////////////////////////////
361 /// Slot for phi1.
362 
364 {
365  Double_t phi1 = fEPhi1->GetNumber();
366  Double_t phi2 = fEPhi2->GetNumber();
367  if (phi1 > 360-1.e-10) {
368  phi1 = 0.;
369  fEPhi1->SetNumber(phi1);
370  }
371  if (phi2<phi1+1.e-10) {
372  phi1 = phi2 - 0.1;
373  fEPhi1->SetNumber(phi1);
374  }
375  if (!fLock) {
376  DoModified();
377  fLock = kTRUE;
378  fSPhi->SetPosition(phi1,phi2);
379  } else fLock = kFALSE;
380  if (!IsDelayed()) DoApply();
381 }
382 
383 ////////////////////////////////////////////////////////////////////////////////
384 /// Slot for phi2.
385 
387 {
388  Double_t phi1 = fEPhi1->GetNumber();
389  Double_t phi2 = fEPhi2->GetNumber();
390  if (phi2-phi1 > 360.) {
391  phi2 -= 360.;
392  fEPhi2->SetNumber(phi2);
393  }
394  if (phi2<phi1+1.e-10) {
395  phi2 = phi1 + 0.1;
396  fEPhi2->SetNumber(phi2);
397  }
398  if (!fLock) {
399  DoModified();
400  fLock = kTRUE;
401  fSPhi->SetPosition(phi1,phi2);
402  } else fLock = kFALSE;
403  if (!IsDelayed()) DoApply();
404 }
405 
406 ////////////////////////////////////////////////////////////////////////////////
407 /// Slot for phi slider.
408 
410 {
411  if (!fLock) {
412  DoModified();
413  fLock = kTRUE;
415  fLock = kTRUE;
417  } else fLock = kFALSE;
418  if (!IsDelayed()) DoApply();
419 }
420 
421 ////////////////////////////////////////////////////////////////////////////////
422 /// Slot for theta1.
423 
425 {
426  Double_t theta1 = fETheta1->GetNumber();
427  Double_t theta2 = fETheta2->GetNumber();
428  if (theta2<theta1+1.e-10) {
429  theta2 = theta1 + 0.1;
430  fETheta2->SetNumber(theta2);
431  }
432  if (!fLock) {
433  DoModified();
434  fLock = kTRUE;
435  fSTheta->SetPosition(theta1,theta2);
436  } else fLock = kFALSE;
437  if (!IsDelayed()) DoApply();
438 }
439 
440 ////////////////////////////////////////////////////////////////////////////////
441 /// Slot for theta2.
442 
444 {
445  Double_t theta1 = fETheta1->GetNumber();
446  Double_t theta2 = fETheta2->GetNumber();
447  if (theta2<theta1+1.e-10) {
448  theta1 = theta2 - 0.1;
449  fETheta1->SetNumber(theta1);
450  }
451  if (!fLock) {
452  DoModified();
453  fLock = kTRUE;
454  fSTheta->SetPosition(theta1,theta2);
455  } else fLock = kFALSE;
456  if (!IsDelayed()) DoApply();
457 }
458 
459 ////////////////////////////////////////////////////////////////////////////////
460 /// Slot for theta slider.
461 
463 {
464  if (!fLock) {
465  DoModified();
466  fLock = kTRUE;
468  fLock = kTRUE;
470  } else fLock = kFALSE;
471  if (!IsDelayed()) DoApply();
472 }
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
image html pict1_TGaxis_012 png width
Define new text attributes for the label number "labNum".
Definition: TGaxis.cxx:2551
TGeoSphere * fShape
TVirtualGeoPainter * GetPainter() const
Definition: TGeoManager.h:191
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:140
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 hierarchically 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:248
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
Editor for a TGeoSphere.
TGNumberEntry * fERmax
void DoTheta1()
Slot for theta1.
void DoPhi1()
Slot for phi1.
void SetNumAttr(EAttribute attr=kNEAAnyNumber)
const Bool_t kFALSE
Definition: RtypesCore.h:88
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:359
R__EXTERN TGeoManager * gGeoManager
Definition: TGeoManager.h:562
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:18
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:721
const Bool_t kTRUE
Definition: RtypesCore.h:87
virtual void MakeTitle(const char *title)
Create attribute frame title.
Definition: TGedFrame.cxx:96
virtual Double_t GetRmin() const
Definition: TGeoSphere.h:67
char name[80]
Definition: TGX11.cxx:109
UInt_t GetDefaultHeight() const
TGTextEntry * fShapeName
Common base class for geombuilder editors.
Definition: TGeoGedFrame.h:13
Double_t GetTheta2() const
Definition: TGeoSphere.h:70