Logo ROOT   6.08/07
Reference Guide
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 //////////////////////////////////////////////////////////////////////////
13 // //
14 // TGeoHypeEditor //
15 // //
16 //////////////////////////////////////////////////////////////////////////
17 //Begin_Html
18 /*
19 <img src="gif/hype_pic.gif">
20 */
21 //End_Html
22 //Begin_Html
23 /*
24 <img src="gif/hype_ed.jpg">
25 */
26 //End_Html
27 
28 #include "TGeoHypeEditor.h"
29 #include "TGeoTabManager.h"
30 #include "TGeoHype.h"
31 #include "TGeoManager.h"
32 #include "TVirtualGeoPainter.h"
33 #include "TPad.h"
34 #include "TView.h"
35 #include "TMath.h"
36 #include "TGTab.h"
37 #include "TGComboBox.h"
38 #include "TGButton.h"
39 #include "TGTextEntry.h"
40 #include "TGNumberEntry.h"
41 #include "TGLabel.h"
42 
44 
48 };
49 
50 ////////////////////////////////////////////////////////////////////////////////
51 /// Constructor for Hype editor
52 
54  Int_t height, UInt_t options, Pixel_t back)
55  : TGeoGedFrame(p, width, height, options | kVerticalFrame, back)
56 {
57  fShape = 0;
58  fRini = fRouti = fStIni = fStOuti = 0.0;
59  fNamei = "";
62 
63  // TextEntry for shape name
64  MakeTitle("Name");
65  fShapeName = new TGTextEntry(this, new TGTextBuffer(50), kHYPE_NAME);
67  fShapeName->SetToolTipText("Enter the hyperboloid name");
68  fShapeName->Associate(this);
69  AddFrame(fShapeName, new TGLayoutHints(kLHintsLeft, 3, 1, 2, 5));
70 
71  TGTextEntry *nef;
72  MakeTitle("Dimensions");
73  // Number entry for Rin
75  f1->AddFrame(new TGLabel(f1, "Rin"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
76  fERin = new TGNumberEntry(f1, 0., 5, kHYPE_RIN);
79  nef = (TGTextEntry*)fERin->GetNumberEntry();
80  nef->SetToolTipText("Enter the inner radius ");
81  fERin->Associate(this);
82  f1->AddFrame(fERin, new TGLayoutHints(kLHintsRight, 2, 2, 4, 4));
83  AddFrame(f1, new TGLayoutHints(kLHintsLeft, 2, 2, 4, 4));
84 
85  // Number entry for Rout
86  f1 = new TGCompositeFrame(this, 155, 10, kHorizontalFrame | kFixedWidth);
87  f1->AddFrame(new TGLabel(f1, "Rout"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
88  fERout = new TGNumberEntry(f1, 0., 5, kHYPE_ROUT);
92  nef->SetToolTipText("Enter the outer radius");
93  fERout->Associate(this);
94  f1->AddFrame(fERout, new TGLayoutHints(kLHintsRight, 2, 2, 4, 4));
95  AddFrame(f1, new TGLayoutHints(kLHintsLeft, 2, 2, 4, 4));
96 
97  // Number entry for Dz
98  f1 = new TGCompositeFrame(this, 155, 10, kHorizontalFrame | kFixedWidth);
99  f1->AddFrame(new TGLabel(f1, "Dz"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
100  fEDz = new TGNumberEntry(f1, 0., 5, kHYPE_DZ);
102  fEDz->Resize(100, fEDz->GetDefaultHeight());
103  nef = (TGTextEntry*)fEDz->GetNumberEntry();
104  nef->SetToolTipText("Enter the half-lenth in Dz");
105  fEDz->Associate(this);
106  f1->AddFrame(fEDz, new TGLayoutHints(kLHintsRight, 2, 2, 4, 4));
107  AddFrame(f1, new TGLayoutHints(kLHintsLeft, 2, 2, 4, 4));
108 
109  // Number entry for StIn.
110  f1 = new TGCompositeFrame(this, 155, 10, kHorizontalFrame | kFixedWidth);
111  f1->AddFrame(new TGLabel(f1, "StIn"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
112  fEStIn = new TGNumberEntry(f1, 0., 5, kHYPE_STIN);
114  nef = (TGTextEntry*)fEStIn->GetNumberEntry();
115  nef->SetToolTipText("Enter the stereo angle for inner surface");
116  fEStIn->Associate(this);
117  f1->AddFrame(fEStIn, new TGLayoutHints(kLHintsRight, 2, 2, 4, 4));
118  AddFrame(f1, new TGLayoutHints(kLHintsLeft, 2, 2, 4, 4));
119 
120  // Number entry for StOut.
121  f1 = new TGCompositeFrame(this, 155, 10, kHorizontalFrame | kFixedWidth);
122  f1->AddFrame(new TGLabel(f1, "StOut"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
123  fEStOut = new TGNumberEntry(f1, 0., 5, kHYPE_STOUT);
127  nef->SetToolTipText("Enter the stereo angle for outer surface");
128  fEStOut->Associate(this);
129  f1->AddFrame(fEStOut, 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()", "TGeoHypeEditor", this, "DoApply()");
170  fUndo->Connect("Clicked()", "TGeoHypeEditor", this, "DoUndo()");
171  fShapeName->Connect("TextChanged(const char *)", "TGeoHypeEditor", this, "DoModified()");
172  fERin->Connect("ValueSet(Long_t)", "TGeoHypeEditor", this, "DoRin()");
173  fERout->Connect("ValueSet(Long_t)", "TGeoHypeEditor", this, "DoRout()");
174  fEDz->Connect("ValueSet(Long_t)", "TGeoHypeEditor", this, "DoDz()");
175  fEStIn->Connect("ValueSet(Long_t)", "TGeoHypeEditor", this, "DoStIn()");
176  fEStOut->Connect("ValueSet(Long_t)", "TGeoHypeEditor", this, "DoStOut()");
177  fERin->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoHypeEditor", this, "DoModified()");
178  fERout->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoHypeEditor", this, "DoModified()");
179  fEDz->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoHypeEditor", this, "DoModified()");
180  fEStIn->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoHypeEditor", this, "DoModified()");
181  fEStOut->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoHypeEditor", this, "DoModified()");
182  fInit = kFALSE;
183 }
184 
185 
186 ////////////////////////////////////////////////////////////////////////////////
187 /// Connect to the selected object.
188 
190 {
191  if (obj == 0 || (obj->IsA()!=TGeoHype::Class())) {
192  SetActive(kFALSE);
193  return;
194  }
195  fShape = (TGeoHype*)obj;
196  fRini = fShape->GetRmin();
197  fRouti = fShape->GetRmax();
198  fDzi = fShape->GetDz();
199  fStIni = fShape->GetStIn();
200  fStOuti = fShape->GetStOut();
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  }
209  fEDz->SetNumber(fDzi);
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 rin = fERin->GetNumber();
243  Double_t rout = fERout->GetNumber();
244  Double_t dz = fEDz->GetNumber();
245  Double_t stin = fEStIn->GetNumber();
246  Double_t stout = fEStOut->GetNumber();
247  Double_t tin = TMath::Tan(stin*TMath::DegToRad());
248  Double_t tout = TMath::Tan(stout*TMath::DegToRad());
249  if ((dz<=0) || (rin<0) || (rin>rout) ||
250  (rin*rin+tin*tin*dz*dz > rout*rout+tout*tout*dz*dz)) {
251  fUndo->SetEnabled();
253  return;
254  }
255  Double_t param[5];
256  param[0] = dz;
257  param[1] = rin;
258  param[2] = stin;
259  param[3] = rout;
260  param[4] = stout;
261  fShape->SetDimensions(param);
262  fShape->ComputeBBox();
263  fUndo->SetEnabled();
265  if (fPad) {
267  TView *view = fPad->GetView();
268  if (!view) {
269  fShape->Draw();
270  fPad->GetView()->ShowAxis();
271  } else {
272  view->SetRange(-fShape->GetDX(), -fShape->GetDY(), -fShape->GetDZ(),
273  fShape->GetDX(), fShape->GetDY(), fShape->GetDZ());
274  Update();
275  }
276  } else Update();
277  }
278 }
279 
280 ////////////////////////////////////////////////////////////////////////////////
281 /// Slot for notifying modifications.
282 
284 {
285  fApply->SetEnabled();
286 }
287 
288 ////////////////////////////////////////////////////////////////////////////////
289 /// Slot for undoing last operation.
290 
292 {
295  fEDz->SetNumber(fDzi);
298  DoApply();
301 }
302 
303 ////////////////////////////////////////////////////////////////////////////////
304 /// Slot for Rin.
305 
307 {
308  Double_t rin = fERin->GetNumber();
309  Double_t rout = fERout->GetNumber();
310  Double_t dz = fEDz->GetNumber();
311  Double_t stin = fEStIn->GetNumber();
312  Double_t stout = fEStOut->GetNumber();
313  Double_t tin = TMath::Tan(stin*TMath::DegToRad());
314  Double_t tout = TMath::Tan(stout*TMath::DegToRad());
315  if (rin<0) {
316  rin = 0;
317  fERin->SetNumber(rin);
318  }
319  Double_t rinmax = TMath::Sqrt((rout*rout+tout*tout*dz*dz)/(tin*tin*dz*dz));
320  rinmax = TMath::Min(rinmax, rout);
321  if (rin > rinmax) {
322  rin = rinmax-1.e-6;
323  fERin->SetNumber(rin);
324  }
325  DoModified();
326  if (!IsDelayed()) DoApply();
327 }
328 
329 ////////////////////////////////////////////////////////////////////////////////
330 /// Slot for Rout.
331 
333 {
334  Double_t rin = fERin->GetNumber();
335  Double_t rout = fERout->GetNumber();
336  Double_t dz = fEDz->GetNumber();
337  Double_t stin = fEStIn->GetNumber();
338  Double_t stout = fEStOut->GetNumber();
339  Double_t tin = TMath::Tan(stin*TMath::DegToRad());
340  Double_t tout = TMath::Tan(stout*TMath::DegToRad());
341  Double_t routmin = TMath::Sqrt((rin*rin+tin*tin*dz*dz)/(tout*tout*dz*dz));
342  routmin = TMath::Max(routmin,rin);
343  if (rout < routmin) {
344  rout = routmin+1.e-6;
345  fERout->SetNumber(rout);
346  }
347  DoModified();
348  if (!IsDelayed()) DoApply();
349 }
350 
351 ////////////////////////////////////////////////////////////////////////////////
352 /// Slot for Z.
353 
355 {
356  Double_t rin = fERin->GetNumber();
357  Double_t rout = fERout->GetNumber();
358  Double_t dz = fEDz->GetNumber();
359  Double_t stin = fEStIn->GetNumber();
360  Double_t stout = fEStOut->GetNumber();
361  if (TMath::Abs(stin-stout)<1.e-6) {
362  stin = stout+1.;
363  fEStIn->SetNumber(stin);
364  }
365  Double_t tin = TMath::Tan(stin*TMath::DegToRad());
366  Double_t tout = TMath::Tan(stout*TMath::DegToRad());
367  if (dz<=0) {
368  dz = 0.1;
369  fEDz->SetNumber(dz);
370  }
371  Double_t dzmax = TMath::Sqrt((rout*rout-rin*rin)/(tin*tin-tout*tout));
372  if (dz>dzmax) {
373  dz = dzmax;
374  fEDz->SetNumber(dz);
375  }
376  DoModified();
377  if (!IsDelayed()) DoApply();
378 }
379 
380 ////////////////////////////////////////////////////////////////////////////////
381 /// Slot for StIn.
382 
384 {
385  Double_t rin = fERin->GetNumber();
386  Double_t rout = fERout->GetNumber();
387  Double_t dz = fEDz->GetNumber();
388  Double_t stin = fEStIn->GetNumber();
389  Double_t stout = fEStOut->GetNumber();
390  if (stin >= 90) {
391  stin = 89.;
392  fEStIn->SetNumber(stin);
393  }
394  Double_t tin = TMath::Tan(stin*TMath::DegToRad());
395  Double_t tout = TMath::Tan(stout*TMath::DegToRad());
396  Double_t tinmax = TMath::Sqrt(tout*tout+(rout*rout-rin*rin)/(dz*dz));
397  if (tin>tinmax) {
398  tin = tinmax-1.e-6;
399  stin = TMath::RadToDeg()*TMath::ATan(tin);
400  fEStIn->SetNumber(stin);
401  }
402  DoModified();
403  if (!IsDelayed()) DoApply();
404 }
405 
406 ////////////////////////////////////////////////////////////////////////////////
407 /// Slot for StOut.
408 
410 {
411  Double_t rin = fERin->GetNumber();
412  Double_t rout = fERout->GetNumber();
413  Double_t dz = fEDz->GetNumber();
414  Double_t stin = fEStIn->GetNumber();
415  Double_t stout = fEStOut->GetNumber();
416  if (stout > 90) {
417  stout = 89;
418  fEStOut->SetNumber(stout);
419  }
420  Double_t tin = TMath::Tan(stin*TMath::DegToRad());
421  Double_t tout = TMath::Tan(stout*TMath::DegToRad());
422  Double_t tinmin = TMath::Sqrt((rout*rout-rin*rin)/(dz*dz));
423  if (tin < tinmin) {
424  tin = tinmin;
425  stin = TMath::RadToDeg()*TMath::ATan(tin);
426  fEStIn->SetNumber(stin);
427  }
428  Double_t toutmin = TMath::Sqrt(tin*tin -tinmin*tinmin);
429  if (tout < toutmin) {
430  tout = toutmin+1.e-6;
431  stout = TMath::RadToDeg()*TMath::ATan(tout);
432  fEStOut->SetNumber(stout);
433  }
434  DoModified();
435  if (!IsDelayed()) DoApply();
436 }
Bool_t fIsShapeEditable
void DoApply()
Slot for applying current settings.
virtual void Resize(UInt_t w=0, UInt_t h=0)
Resize the frame.
Definition: TGFrame.cxx:587
void DoStIn()
Slot for StIn.
ETGeoHypeWid
TGTextEntry * fShapeName
virtual Double_t GetDX() const
Definition: TGeoBBox.h:72
TVirtualGeoPainter * GetPainter() const
Definition: TGeoManager.h:187
TGNumberEntry * fEStOut
virtual void SetToolTipText(const char *text, Long_t delayms=500)
Set tool tip text associated with this text entry.
TGNumberEntry * fERin
virtual void SetName(const char *name)
Set the name of the TNamed.
Definition: TNamed.cxx:131
Double_t DegToRad()
Definition: TMath.h:50
virtual void SetNumber(Double_t val)
See TView3D.
Definition: TView.h:29
virtual void ConnectSignals2Slots()
Connect signals to slots.
virtual void SetRange(const Double_t *min, const Double_t *max)=0
Double_t RadToDeg()
Definition: TMath.h:49
virtual Bool_t IsPaintingShape() const =0
Short_t Min(Short_t a, Short_t b)
Definition: TMathBase.h:170
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
const Bool_t kFALSE
Definition: Rtypes.h:92
virtual Bool_t IsComposite() const
Definition: TGFrame.h:275
const char * Class
Definition: TXMLSetup.cxx:64
TGeoHypeEditor(const TGWindow *p=0, Int_t width=140, Int_t height=30, UInt_t options=kChildFrame, Pixel_t back=GetDefaultFrameBackground())
Constructor for Hype editor.
TGNumberEntry * fEStIn
Short_t Abs(Short_t d)
Definition: TMathBase.h:110
void DoRin()
Slot for Rin.
void DoModified()
Slot for notifying modifications.
static void Cleanup(TGCompositeFrame *frame)
Static method to cleanup hirarchically all daughters of a composite frame.
virtual Double_t GetRmax() const
Definition: TGeoTube.h:69
Double_t GetStOut() const
Definition: TGeoHype.h:71
virtual void ComputeBBox()
Compute bounding box of the hyperboloid.
Definition: TGeoHype.cxx:138
virtual const char * ClassName() const
Returns name of class to which the object belongs.
Definition: TObject.cxx:188
ULong_t Pixel_t
Definition: GuiTypes.h:41
void DoUndo()
Slot for undoing last operation.
virtual void SetActive(Bool_t active=kTRUE)
Set active GUI attribute frames related to the selected object.
TGCompositeFrame(const TGCompositeFrame &)
virtual TList * GetList() const
Definition: TGFrame.h:385
virtual EButtonState GetState() const
Definition: TGButton.h:116
virtual TView * GetView() const =0
TGTextButton * fApply
void DoName()
Slot for name.
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:1137
virtual void Associate(const TGWindow *w)
Make w the window that will receive the generated messages.
virtual void SetSize(const TGDimension &s)
Definition: TGFrame.h:315
TGCheckButton * fDelayed
virtual void SetDimensions(Double_t *param)
Set dimensions of the hyperboloid starting from an array.
Definition: TGeoHype.cxx:812
virtual void Associate(const TGWindow *w)
Definition: TGWidget.h:90
Double_t fStOuti
unsigned int UInt_t
Definition: RtypesCore.h:42
Hyperboloid class defined by 5 parameters.
Definition: TGeoHype.h:19
TGFrame * fFrame
Definition: TGLayout.h:125
virtual void ShowAxis()=0
const std::string sname
Definition: testIO.cxx:45
virtual ~TGeoHypeEditor()
Destructor.
virtual Double_t GetDY() const
Definition: TGeoBBox.h:73
void SetNumAttr(EAttribute attr=kNEAAnyNumber)
TGDimension GetSize() const
Definition: TGFrame.h:293
const char * GetText() const
Definition: TGTextEntry.h:140
virtual UInt_t GetDefaultHeight() const
Definition: TGFrame.h:254
#define ClassImp(name)
Definition: Rtypes.h:279
R__EXTERN TGeoManager * gGeoManager
Definition: TGeoManager.h:554
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
you should not use this method at all Int_t Int_t Double_t Double_t Double_t e
Definition: TRolke.cxx:630
virtual void AddFrame(TGFrame *f, TGLayoutHints *l=0)
Add frame to the composite frame using the specified layout hints.
Definition: TGFrame.cxx:1099
Mother of all ROOT objects.
Definition: TObject.h:37
void DoDz()
Slot for Z.
virtual void SetModel(TObject *obj)
Connect to the selected object.
Bool_t fInit
Definition: TGedFrame.h:55
Bool_t IsDelayed() const
Check if shape drawing is delayed.
TGNumberEntryField * GetNumberEntry() const
virtual Double_t GetRmin() const
Definition: TGeoTube.h:68
Short_t Max(Short_t a, Short_t b)
Definition: TMathBase.h:202
TF1 * f1
Definition: legend1.C:11
TGeoHype * fShape
virtual void Update()
Override Update from TGedFrame as fGedEditor can be null.
void DoStOut()
Slot for StOut.
TGNumberEntry * fERout
Double_t Sqrt(Double_t x)
Definition: TMath.h:464
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:723
const Bool_t kTRUE
Definition: Rtypes.h:91
virtual void MakeTitle(const char *title)
Create attribute frame title.
Definition: TGedFrame.cxx:96
TGTextButton * fUndo
Double_t Tan(Double_t)
Definition: TMath.h:427
void DoRout()
Slot for Rout.
virtual Double_t GetDz() const
Definition: TGeoTube.h:70
char name[80]
Definition: TGX11.cxx:109
TGNumberEntry * fEDz
UInt_t GetDefaultHeight() const
virtual Double_t GetDZ() const
Definition: TGeoBBox.h:74
Double_t GetStIn() const
Definition: TGeoHype.h:70
Double_t ATan(Double_t)
Definition: TMath.h:451