Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
TGeoHypeEditor.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 TGeoHypeEditor
13 \ingroup Geometry_builder
14 
15 Editor for a TGeoHype.
16 
17 \image html geom_hype_pic.png
18 
19 \image html geom_hype_ed.png
20 
21 */
22 
23 #include "TGeoHypeEditor.h"
24 #include "TGeoTabManager.h"
25 #include "TGeoHype.h"
26 #include "TGeoManager.h"
27 #include "TVirtualGeoPainter.h"
28 #include "TPad.h"
29 #include "TView.h"
30 #include "TMath.h"
31 #include "TGTab.h"
32 #include "TGComboBox.h"
33 #include "TGButton.h"
34 #include "TGTextEntry.h"
35 #include "TGNumberEntry.h"
36 #include "TGLabel.h"
37 
38 ClassImp(TGeoHypeEditor);
39 
40 enum ETGeoHypeWid {
41  kHYPE_NAME, kHYPE_RIN, kHYPE_ROUT, kHYPE_DZ, kHYPE_STIN,
42  kHYPE_STOUT, kHYPE_APPLY, kHYPE_UNDO
43 };
44 
45 ////////////////////////////////////////////////////////////////////////////////
46 /// Constructor for Hype editor
47 
48 TGeoHypeEditor::TGeoHypeEditor(const TGWindow *p, Int_t width,
49  Int_t height, UInt_t options, Pixel_t back)
50  : TGeoGedFrame(p, width, height, options | kVerticalFrame, back)
51 {
52  fShape = 0;
53  fRini = fRouti = fStIni = fStOuti = 0.0;
54  fNamei = "";
55  fIsModified = kFALSE;
56  fIsShapeEditable = kTRUE;
57 
58  // TextEntry for shape name
59  MakeTitle("Name");
60  fShapeName = new TGTextEntry(this, new TGTextBuffer(50), kHYPE_NAME);
61  fShapeName->Resize(135, fShapeName->GetDefaultHeight());
62  fShapeName->SetToolTipText("Enter the hyperboloid name");
63  fShapeName->Associate(this);
64  AddFrame(fShapeName, new TGLayoutHints(kLHintsLeft, 3, 1, 2, 5));
65 
66  TGTextEntry *nef;
67  MakeTitle("Dimensions");
68  // Number entry for Rin
69  TGCompositeFrame *f1 = new TGCompositeFrame(this, 155, 10, kHorizontalFrame | kFixedWidth);
70  f1->AddFrame(new TGLabel(f1, "Rin"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
71  fERin = new TGNumberEntry(f1, 0., 5, kHYPE_RIN);
72  fERin->SetNumAttr(TGNumberFormat::kNEAPositive);
73  fERin->Resize(100, fERin->GetDefaultHeight());
74  nef = (TGTextEntry*)fERin->GetNumberEntry();
75  nef->SetToolTipText("Enter the inner radius ");
76  fERin->Associate(this);
77  f1->AddFrame(fERin, new TGLayoutHints(kLHintsRight, 2, 2, 4, 4));
78  AddFrame(f1, new TGLayoutHints(kLHintsLeft, 2, 2, 4, 4));
79 
80  // Number entry for Rout
81  f1 = new TGCompositeFrame(this, 155, 10, kHorizontalFrame | kFixedWidth);
82  f1->AddFrame(new TGLabel(f1, "Rout"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
83  fERout = new TGNumberEntry(f1, 0., 5, kHYPE_ROUT);
84  fERout->SetNumAttr(TGNumberFormat::kNEAPositive);
85  fERout->Resize(100, fERout->GetDefaultHeight());
86  nef = (TGTextEntry*)fERout->GetNumberEntry();
87  nef->SetToolTipText("Enter the outer radius");
88  fERout->Associate(this);
89  f1->AddFrame(fERout, new TGLayoutHints(kLHintsRight, 2, 2, 4, 4));
90  AddFrame(f1, new TGLayoutHints(kLHintsLeft, 2, 2, 4, 4));
91 
92  // Number entry for Dz
93  f1 = new TGCompositeFrame(this, 155, 10, kHorizontalFrame | kFixedWidth);
94  f1->AddFrame(new TGLabel(f1, "Dz"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
95  fEDz = new TGNumberEntry(f1, 0., 5, kHYPE_DZ);
96  fEDz->SetNumAttr(TGNumberFormat::kNEAPositive);
97  fEDz->Resize(100, fEDz->GetDefaultHeight());
98  nef = (TGTextEntry*)fEDz->GetNumberEntry();
99  nef->SetToolTipText("Enter the half-length in Dz");
100  fEDz->Associate(this);
101  f1->AddFrame(fEDz, new TGLayoutHints(kLHintsRight, 2, 2, 4, 4));
102  AddFrame(f1, new TGLayoutHints(kLHintsLeft, 2, 2, 4, 4));
103 
104  // Number entry for StIn.
105  f1 = new TGCompositeFrame(this, 155, 10, kHorizontalFrame | kFixedWidth);
106  f1->AddFrame(new TGLabel(f1, "StIn"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
107  fEStIn = new TGNumberEntry(f1, 0., 5, kHYPE_STIN);
108  fEStIn->Resize(100, fEStIn->GetDefaultHeight());
109  nef = (TGTextEntry*)fEStIn->GetNumberEntry();
110  nef->SetToolTipText("Enter the stereo angle for inner surface");
111  fEStIn->Associate(this);
112  f1->AddFrame(fEStIn, new TGLayoutHints(kLHintsRight, 2, 2, 4, 4));
113  AddFrame(f1, new TGLayoutHints(kLHintsLeft, 2, 2, 4, 4));
114 
115  // Number entry for StOut.
116  f1 = new TGCompositeFrame(this, 155, 10, kHorizontalFrame | kFixedWidth);
117  f1->AddFrame(new TGLabel(f1, "StOut"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
118  fEStOut = new TGNumberEntry(f1, 0., 5, kHYPE_STOUT);
119  fEStOut->SetNumAttr(TGNumberFormat::kNEAPositive);
120  fEStOut->Resize(100, fEStOut->GetDefaultHeight());
121  nef = (TGTextEntry*)fEStOut->GetNumberEntry();
122  nef->SetToolTipText("Enter the stereo angle for outer surface");
123  fEStOut->Associate(this);
124  f1->AddFrame(fEStOut, new TGLayoutHints(kLHintsRight, 2, 2, 4, 4));
125  AddFrame(f1, new TGLayoutHints(kLHintsLeft, 2, 2, 4, 4));
126 
127  // Delayed draw
128  f1 = new TGCompositeFrame(this, 155, 10, kHorizontalFrame | kFixedWidth | kSunkenFrame);
129  fDelayed = new TGCheckButton(f1, "Delayed draw");
130  f1->AddFrame(fDelayed, new TGLayoutHints(kLHintsLeft , 2, 2, 4, 4));
131  AddFrame(f1, new TGLayoutHints(kLHintsLeft, 6, 6, 4, 4));
132 
133  // Buttons
134  f1 = new TGCompositeFrame(this, 155, 10, kHorizontalFrame | kFixedWidth);
135  fApply = new TGTextButton(f1, "Apply");
136  f1->AddFrame(fApply, new TGLayoutHints(kLHintsLeft, 2, 2, 4, 4));
137  fApply->Associate(this);
138  fUndo = new TGTextButton(f1, "Undo");
139  f1->AddFrame(fUndo, new TGLayoutHints(kLHintsRight , 2, 2, 4, 4));
140  fUndo->Associate(this);
141  AddFrame(f1, new TGLayoutHints(kLHintsLeft, 6, 6, 4, 4));
142  fUndo->SetSize(fApply->GetSize());
143 }
144 
145 ////////////////////////////////////////////////////////////////////////////////
146 /// Destructor
147 
148 TGeoHypeEditor::~TGeoHypeEditor()
149 {
150  TGFrameElement *el;
151  TIter next(GetList());
152  while ((el = (TGFrameElement *)next())) {
153  if (el->fFrame->IsComposite())
154  TGeoTabManager::Cleanup((TGCompositeFrame*)el->fFrame);
155  }
156  Cleanup();
157 }
158 
159 ////////////////////////////////////////////////////////////////////////////////
160 /// Connect signals to slots.
161 
162 void TGeoHypeEditor::ConnectSignals2Slots()
163 {
164  fApply->Connect("Clicked()", "TGeoHypeEditor", this, "DoApply()");
165  fUndo->Connect("Clicked()", "TGeoHypeEditor", this, "DoUndo()");
166  fShapeName->Connect("TextChanged(const char *)", "TGeoHypeEditor", this, "DoModified()");
167  fERin->Connect("ValueSet(Long_t)", "TGeoHypeEditor", this, "DoRin()");
168  fERout->Connect("ValueSet(Long_t)", "TGeoHypeEditor", this, "DoRout()");
169  fEDz->Connect("ValueSet(Long_t)", "TGeoHypeEditor", this, "DoDz()");
170  fEStIn->Connect("ValueSet(Long_t)", "TGeoHypeEditor", this, "DoStIn()");
171  fEStOut->Connect("ValueSet(Long_t)", "TGeoHypeEditor", this, "DoStOut()");
172  fERin->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoHypeEditor", this, "DoModified()");
173  fERout->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoHypeEditor", this, "DoModified()");
174  fEDz->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoHypeEditor", this, "DoModified()");
175  fEStIn->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoHypeEditor", this, "DoModified()");
176  fEStOut->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoHypeEditor", this, "DoModified()");
177  fInit = kFALSE;
178 }
179 
180 
181 ////////////////////////////////////////////////////////////////////////////////
182 /// Connect to the selected object.
183 
184 void TGeoHypeEditor::SetModel(TObject* obj)
185 {
186  if (obj == 0 || (obj->IsA()!=TGeoHype::Class())) {
187  SetActive(kFALSE);
188  return;
189  }
190  fShape = (TGeoHype*)obj;
191  fRini = fShape->GetRmin();
192  fRouti = fShape->GetRmax();
193  fDzi = fShape->GetDz();
194  fStIni = fShape->GetStIn();
195  fStOuti = fShape->GetStOut();
196  const char *sname = fShape->GetName();
197  if (!strcmp(sname, fShape->ClassName())) fShapeName->SetText("-no_name");
198  else {
199  fShapeName->SetText(sname);
200  fNamei = sname;
201  }
202  fERin->SetNumber(fRini);
203  fERout->SetNumber(fRouti);
204  fEDz->SetNumber(fDzi);
205  fEStIn->SetNumber(fStIni);
206  fEStOut->SetNumber(fStOuti);
207  fApply->SetEnabled(kFALSE);
208  fUndo->SetEnabled(kFALSE);
209 
210  if (fInit) ConnectSignals2Slots();
211  SetActive();
212 }
213 
214 ////////////////////////////////////////////////////////////////////////////////
215 /// Check if shape drawing is delayed.
216 
217 Bool_t TGeoHypeEditor::IsDelayed() const
218 {
219  return (fDelayed->GetState() == kButtonDown);
220 }
221 
222 ////////////////////////////////////////////////////////////////////////////////
223 /// Slot for name.
224 
225 void TGeoHypeEditor::DoName()
226 {
227  DoModified();
228 }
229 
230 ////////////////////////////////////////////////////////////////////////////////
231 /// Slot for applying current settings.
232 
233 void TGeoHypeEditor::DoApply()
234 {
235  const char *name = fShapeName->GetText();
236  if (strcmp(name,fShape->GetName())) fShape->SetName(name);
237  Double_t rin = fERin->GetNumber();
238  Double_t rout = fERout->GetNumber();
239  Double_t dz = fEDz->GetNumber();
240  Double_t stin = fEStIn->GetNumber();
241  Double_t stout = fEStOut->GetNumber();
242  Double_t tin = TMath::Tan(stin*TMath::DegToRad());
243  Double_t tout = TMath::Tan(stout*TMath::DegToRad());
244  if ((dz<=0) || (rin<0) || (rin>rout) ||
245  (rin*rin+tin*tin*dz*dz > rout*rout+tout*tout*dz*dz)) {
246  fUndo->SetEnabled();
247  fApply->SetEnabled(kFALSE);
248  return;
249  }
250  Double_t param[5];
251  param[0] = dz;
252  param[1] = rin;
253  param[2] = stin;
254  param[3] = rout;
255  param[4] = stout;
256  fShape->SetDimensions(param);
257  fShape->ComputeBBox();
258  fUndo->SetEnabled();
259  fApply->SetEnabled(kFALSE);
260  if (fPad) {
261  if (gGeoManager && gGeoManager->GetPainter() && gGeoManager->GetPainter()->IsPaintingShape()) {
262  TView *view = fPad->GetView();
263  if (!view) {
264  fShape->Draw();
265  fPad->GetView()->ShowAxis();
266  } else {
267  view->SetRange(-fShape->GetDX(), -fShape->GetDY(), -fShape->GetDZ(),
268  fShape->GetDX(), fShape->GetDY(), fShape->GetDZ());
269  Update();
270  }
271  } else Update();
272  }
273 }
274 
275 ////////////////////////////////////////////////////////////////////////////////
276 /// Slot for notifying modifications.
277 
278 void TGeoHypeEditor::DoModified()
279 {
280  fApply->SetEnabled();
281 }
282 
283 ////////////////////////////////////////////////////////////////////////////////
284 /// Slot for undoing last operation.
285 
286 void TGeoHypeEditor::DoUndo()
287 {
288  fERin->SetNumber(fRini);
289  fERout->SetNumber(fRouti);
290  fEDz->SetNumber(fDzi);
291  fEStIn->SetNumber(fStIni);
292  fEStOut->SetNumber(fStOuti);
293  DoApply();
294  fUndo->SetEnabled(kFALSE);
295  fApply->SetEnabled(kFALSE);
296 }
297 
298 ////////////////////////////////////////////////////////////////////////////////
299 /// Slot for Rin.
300 
301 void TGeoHypeEditor::DoRin()
302 {
303  Double_t rin = fERin->GetNumber();
304  Double_t rout = fERout->GetNumber();
305  Double_t dz = fEDz->GetNumber();
306  Double_t stin = fEStIn->GetNumber();
307  Double_t stout = fEStOut->GetNumber();
308  Double_t tin = TMath::Tan(stin*TMath::DegToRad());
309  Double_t tout = TMath::Tan(stout*TMath::DegToRad());
310  if (rin<0) {
311  rin = 0;
312  fERin->SetNumber(rin);
313  }
314  Double_t rinmax = TMath::Sqrt((rout*rout+tout*tout*dz*dz)/(tin*tin*dz*dz));
315  rinmax = TMath::Min(rinmax, rout);
316  if (rin > rinmax) {
317  rin = rinmax-1.e-6;
318  fERin->SetNumber(rin);
319  }
320  DoModified();
321  if (!IsDelayed()) DoApply();
322 }
323 
324 ////////////////////////////////////////////////////////////////////////////////
325 /// Slot for Rout.
326 
327 void TGeoHypeEditor::DoRout()
328 {
329  Double_t rin = fERin->GetNumber();
330  Double_t rout = fERout->GetNumber();
331  Double_t dz = fEDz->GetNumber();
332  Double_t stin = fEStIn->GetNumber();
333  Double_t stout = fEStOut->GetNumber();
334  Double_t tin = TMath::Tan(stin*TMath::DegToRad());
335  Double_t tout = TMath::Tan(stout*TMath::DegToRad());
336  Double_t routmin = TMath::Sqrt((rin*rin+tin*tin*dz*dz)/(tout*tout*dz*dz));
337  routmin = TMath::Max(routmin,rin);
338  if (rout < routmin) {
339  rout = routmin+1.e-6;
340  fERout->SetNumber(rout);
341  }
342  DoModified();
343  if (!IsDelayed()) DoApply();
344 }
345 
346 ////////////////////////////////////////////////////////////////////////////////
347 /// Slot for Z.
348 
349 void TGeoHypeEditor::DoDz()
350 {
351  Double_t rin = fERin->GetNumber();
352  Double_t rout = fERout->GetNumber();
353  Double_t dz = fEDz->GetNumber();
354  Double_t stin = fEStIn->GetNumber();
355  Double_t stout = fEStOut->GetNumber();
356  if (TMath::Abs(stin-stout)<1.e-6) {
357  stin = stout+1.;
358  fEStIn->SetNumber(stin);
359  }
360  Double_t tin = TMath::Tan(stin*TMath::DegToRad());
361  Double_t tout = TMath::Tan(stout*TMath::DegToRad());
362  if (dz<=0) {
363  dz = 0.1;
364  fEDz->SetNumber(dz);
365  }
366  Double_t dzmax = TMath::Sqrt((rout*rout-rin*rin)/(tin*tin-tout*tout));
367  if (dz>dzmax) {
368  dz = dzmax;
369  fEDz->SetNumber(dz);
370  }
371  DoModified();
372  if (!IsDelayed()) DoApply();
373 }
374 
375 ////////////////////////////////////////////////////////////////////////////////
376 /// Slot for StIn.
377 
378 void TGeoHypeEditor::DoStIn()
379 {
380  Double_t rin = fERin->GetNumber();
381  Double_t rout = fERout->GetNumber();
382  Double_t dz = fEDz->GetNumber();
383  Double_t stin = fEStIn->GetNumber();
384  Double_t stout = fEStOut->GetNumber();
385  if (stin >= 90) {
386  stin = 89.;
387  fEStIn->SetNumber(stin);
388  }
389  Double_t tin = TMath::Tan(stin*TMath::DegToRad());
390  Double_t tout = TMath::Tan(stout*TMath::DegToRad());
391  Double_t tinmax = TMath::Sqrt(tout*tout+(rout*rout-rin*rin)/(dz*dz));
392  if (tin>tinmax) {
393  tin = tinmax-1.e-6;
394  stin = TMath::RadToDeg()*TMath::ATan(tin);
395  fEStIn->SetNumber(stin);
396  }
397  DoModified();
398  if (!IsDelayed()) DoApply();
399 }
400 
401 ////////////////////////////////////////////////////////////////////////////////
402 /// Slot for StOut.
403 
404 void TGeoHypeEditor::DoStOut()
405 {
406  Double_t rin = fERin->GetNumber();
407  Double_t rout = fERout->GetNumber();
408  Double_t dz = fEDz->GetNumber();
409  Double_t stin = fEStIn->GetNumber();
410  Double_t stout = fEStOut->GetNumber();
411  if (stout > 90) {
412  stout = 89;
413  fEStOut->SetNumber(stout);
414  }
415  Double_t tin = TMath::Tan(stin*TMath::DegToRad());
416  Double_t tout = TMath::Tan(stout*TMath::DegToRad());
417  Double_t tinmin = TMath::Sqrt((rout*rout-rin*rin)/(dz*dz));
418  if (tin < tinmin) {
419  tin = tinmin;
420  stin = TMath::RadToDeg()*TMath::ATan(tin);
421  fEStIn->SetNumber(stin);
422  }
423  Double_t toutmin = TMath::Sqrt(tin*tin -tinmin*tinmin);
424  if (tout < toutmin) {
425  tout = toutmin+1.e-6;
426  stout = TMath::RadToDeg()*TMath::ATan(tout);
427  fEStOut->SetNumber(stout);
428  }
429  DoModified();
430  if (!IsDelayed()) DoApply();
431 }