Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
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 
38 ClassImp(TGeoSphereEditor);
39 
40 enum ETGeoSphereWid {
41  kSPHERE_NAME, kSPHERE_RMIN, kSPHERE_RMAX, kSPHERE_THETA1,
42  kSPHERE_THETA2, kSPHERE_PHI1, kSPHERE_PHI2, kSPHERE_PHI, kSPHERE_THETA,
43  kSPHERE_APPLY, kSPHERE_UNDO
44 };
45 
46 ////////////////////////////////////////////////////////////////////////////////
47 /// Constructor for sphere editor
48 
49 TGeoSphereEditor::TGeoSphereEditor(const TGWindow *p, Int_t width,
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 = "";
56  fIsModified = kFALSE;
57  fIsShapeEditable = kTRUE;
58  fLock = kFALSE;
59 
60  // TextEntry for shape name
61  MakeTitle("Name");
62  fShapeName = new TGTextEntry(this, new TGTextBuffer(50), kSPHERE_NAME);
63  fShapeName->Resize(135, fShapeName->GetDefaultHeight());
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 |
73  kLHintsExpandX | kOwnBackground);
74  f1->AddFrame(new TGLabel(f1, "Rmin"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
75  fERmin = new TGNumberEntry(f1, 0., 5, kSPHERE_RMIN);
76  fERmin->SetNumAttr(TGNumberFormat::kNEANonNegative);
77  nef = (TGTextEntry*)fERmin->GetNumberEntry();
78  nef->SetToolTipText("Enter the inner radius");
79  fERmin->Associate(this);
80  fERmin->Resize(100, fERmin->GetDefaultHeight());
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 |
86  kLHintsExpandX | kOwnBackground);
87  f1->AddFrame(new TGLabel(f1, "Rmax"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
88  fERmax = new TGNumberEntry(f1, 0., 5, kSPHERE_RMAX);
89  fERmax->SetNumAttr(TGNumberFormat::kNEANonNegative);
90  nef = (TGTextEntry*)fERmax->GetNumberEntry();
91  nef->SetToolTipText("Enter the outer radius");
92  fERmax->Associate(this);
93  fERmax->Resize(100, fERmax->GetDefaultHeight());
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);
108  fEPhi1->Resize(30, fEPhi1->GetDefaultHeight());
109  fEPhi1->SetNumAttr(TGNumberFormat::kNEANonNegative);
110  nef = (TGTextEntry*)fEPhi1->GetNumberEntry();
111  nef->SetToolTipText("Enter the phi1 value");
112  fEPhi1->Associate(this);
113  f1->AddFrame(fEPhi1, new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX, 2, 2, 2, 2));
114 
115  fEPhi2 = new TGNumberEntry(f1, 0., 5, kSPHERE_PHI2);
116  fEPhi2->Resize(30, fEPhi2->GetDefaultHeight());
117  fEPhi2->SetNumAttr(TGNumberFormat::kNEANonNegative);
118  nef = (TGTextEntry*)fEPhi2->GetNumberEntry();
119  nef->SetToolTipText("Enter the phi2 value");
120  fEPhi2->Associate(this);
121  fEPhi2->Resize(30, fEPhi2->GetDefaultHeight());
122  f1->AddFrame(fEPhi2, new TGLayoutHints(kLHintsBottom | kLHintsLeft | kLHintsExpandX, 2, 2, 2, 2));
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);
137  fETheta1->Resize(30, fETheta1->GetDefaultHeight());
138  fETheta1->SetNumAttr(TGNumberFormat::kNEANonNegative);
139  nef = (TGTextEntry*)fETheta1->GetNumberEntry();
140  nef->SetToolTipText("Enter the theta1 value");
141  fETheta1->Associate(this);
142  f1->AddFrame(fETheta1, new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX, 2, 2, 2, 2));
143 
144  fETheta2 = new TGNumberEntry(f1, 0., 5, kSPHERE_THETA2);
145  fETheta2->Resize(30, fETheta2->GetDefaultHeight());
146  fETheta2->SetNumAttr(TGNumberFormat::kNEANonNegative);
147  nef = (TGTextEntry*)fETheta2->GetNumberEntry();
148  nef->SetToolTipText("Enter the theta2 value");
149  fETheta2->Associate(this);
150  f1->AddFrame(fETheta2, new TGLayoutHints(kLHintsBottom | kLHintsLeft | kLHintsExpandX, 2, 2, 2, 2));
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));
174  fUndo->SetSize(fApply->GetSize());
175 }
176 
177 ////////////////////////////////////////////////////////////////////////////////
178 /// Destructor.
179 
180 TGeoSphereEditor::~TGeoSphereEditor()
181 {
182  TGFrameElement *el;
183  TIter next(GetList());
184  while ((el = (TGFrameElement *)next())) {
185  if (el->fFrame->IsComposite())
186  TGeoTabManager::Cleanup((TGCompositeFrame*)el->fFrame);
187  }
188  Cleanup();
189 }
190 
191 ////////////////////////////////////////////////////////////////////////////////
192 /// Connect signals to slots.
193 
194 void TGeoSphereEditor::ConnectSignals2Slots()
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 
214 void TGeoSphereEditor::SetModel(TObject* obj)
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();
225  fTheta1i = fShape->GetTheta1();
226  fTheta2i = fShape->GetTheta2();
227  fNamei = fShape->GetName();
228  fShapeName->SetText(fShape->GetName());
229  fERmin->SetNumber(fRmini);
230  fERmax->SetNumber(fRmaxi);
231  fEPhi1->SetNumber(fPhi1i);
232  fEPhi2->SetNumber(fPhi2i);
233  fETheta1->SetNumber(fTheta1i);
234  fETheta2->SetNumber(fTheta2i);
235  fSPhi->SetPosition(fPhi1i, fPhi2i);
236  fSTheta->SetPosition(fTheta1i, fTheta2i);
237 
238  fApply->SetEnabled(kFALSE);
239  fUndo->SetEnabled(kFALSE);
240 
241  if (fInit) ConnectSignals2Slots();
242  SetActive();
243 }
244 
245 ////////////////////////////////////////////////////////////////////////////////
246 /// Check if shape drawing is delayed.
247 
248 Bool_t TGeoSphereEditor::IsDelayed() const
249 {
250  return (fDelayed->GetState() == kButtonDown);
251 }
252 
253 ////////////////////////////////////////////////////////////////////////////////
254 /// Slot for name.
255 
256 void TGeoSphereEditor::DoName()
257 {
258  DoModified();
259 }
260 
261 ////////////////////////////////////////////////////////////////////////////////
262 /// Slot for applying modifications.
263 
264 void TGeoSphereEditor::DoApply()
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();
286  fApply->SetEnabled(kFALSE);
287  if (fPad) {
288  if (gGeoManager && gGeoManager->GetPainter() && gGeoManager->GetPainter()->IsPaintingShape()) {
289  fShape->Draw();
290  fPad->GetView()->ShowAxis();
291  } else Update();
292  }
293 }
294 
295 ////////////////////////////////////////////////////////////////////////////////
296 /// Slot for signaling modifications.
297 
298 void TGeoSphereEditor::DoModified()
299 {
300  fApply->SetEnabled();
301 }
302 
303 ////////////////////////////////////////////////////////////////////////////////
304 /// Slot for undoing last operation.
305 
306 void TGeoSphereEditor::DoUndo()
307 {
308  fERmin->SetNumber(fRmini);
309  fERmax->SetNumber(fRmaxi);
310  fEPhi1->SetNumber(fPhi1i);
311  fEPhi2->SetNumber(fPhi2i);
312  fSPhi->SetPosition(fPhi1i,fPhi2i);
313  fETheta1->SetNumber(fTheta1i);
314  fETheta2->SetNumber(fTheta2i);
315  fSTheta->SetPosition(fTheta1i,fTheta2i);
316  DoApply();
317  fUndo->SetEnabled(kFALSE);
318  fApply->SetEnabled(kFALSE);
319 }
320 
321 ////////////////////////////////////////////////////////////////////////////////
322 /// Slot for Rmin.
323 
324 void TGeoSphereEditor::DoRmin()
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 
343 void TGeoSphereEditor::DoRmax()
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 
363 void TGeoSphereEditor::DoPhi1()
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 
386 void TGeoSphereEditor::DoPhi2()
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 
409 void TGeoSphereEditor::DoPhi()
410 {
411  if (!fLock) {
412  DoModified();
413  fLock = kTRUE;
414  fEPhi1->SetNumber(fSPhi->GetMinPosition());
415  fLock = kTRUE;
416  fEPhi2->SetNumber(fSPhi->GetMaxPosition());
417  } else fLock = kFALSE;
418  if (!IsDelayed()) DoApply();
419 }
420 
421 ////////////////////////////////////////////////////////////////////////////////
422 /// Slot for theta1.
423 
424 void TGeoSphereEditor::DoTheta1()
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 
443 void TGeoSphereEditor::DoTheta2()
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 
462 void TGeoSphereEditor::DoTheta()
463 {
464  if (!fLock) {
465  DoModified();
466  fLock = kTRUE;
467  fETheta1->SetNumber(fSTheta->GetMinPosition());
468  fLock = kTRUE;
469  fETheta2->SetNumber(fSTheta->GetMaxPosition());
470  } else fLock = kFALSE;
471  if (!IsDelayed()) DoApply();
472 }