Logo ROOT   6.14/05
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 /** \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 
39 
43 };
44 
45 ////////////////////////////////////////////////////////////////////////////////
46 /// Constructor for Hype editor
47 
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 = "";
57 
58  // TextEntry for shape name
59  MakeTitle("Name");
60  fShapeName = new TGTextEntry(this, new TGTextBuffer(50), kHYPE_NAME);
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
70  f1->AddFrame(new TGLabel(f1, "Rin"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
71  fERin = new TGNumberEntry(f1, 0., 5, kHYPE_RIN);
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);
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);
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);
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);
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));
143 }
144 
145 ////////////////////////////////////////////////////////////////////////////////
146 /// Destructor
147 
149 {
150  TGFrameElement *el;
151  TIter next(GetList());
152  while ((el = (TGFrameElement *)next())) {
153  if (el->fFrame->IsComposite())
155  }
156  Cleanup();
157 }
158 
159 ////////////////////////////////////////////////////////////////////////////////
160 /// Connect signals to slots.
161 
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 
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  }
204  fEDz->SetNumber(fDzi);
209 
211  SetActive();
212 }
213 
214 ////////////////////////////////////////////////////////////////////////////////
215 /// Check if shape drawing is delayed.
216 
218 {
219  return (fDelayed->GetState() == kButtonDown);
220 }
221 
222 ////////////////////////////////////////////////////////////////////////////////
223 /// Slot for name.
224 
226 {
227  DoModified();
228 }
229 
230 ////////////////////////////////////////////////////////////////////////////////
231 /// Slot for applying current settings.
232 
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();
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();
260  if (fPad) {
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 
279 {
280  fApply->SetEnabled();
281 }
282 
283 ////////////////////////////////////////////////////////////////////////////////
284 /// Slot for undoing last operation.
285 
287 {
290  fEDz->SetNumber(fDzi);
293  DoApply();
296 }
297 
298 ////////////////////////////////////////////////////////////////////////////////
299 /// Slot for Rin.
300 
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 
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 
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 
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 
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 }
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:70
image html pict1_TGaxis_012 png width
Define new text attributes for the label number "labNum".
Definition: TGaxis.cxx:2551
TVirtualGeoPainter * GetPainter() const
Definition: TGeoManager.h:191
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:140
virtual void SetNumber(Double_t val)
See TView3D.
Definition: TView.h:25
virtual void ConnectSignals2Slots()
Connect signals to slots.
virtual void SetRange(const Double_t *min, const Double_t *max)=0
virtual Bool_t IsPaintingShape() const =0
Short_t Min(Short_t a, Short_t b)
Definition: TMathBase.h:168
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
virtual Bool_t IsComposite() const
Definition: TGFrame.h:259
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:108
void DoRin()
Slot for Rin.
void DoModified()
Slot for notifying modifications.
static void Cleanup(TGCompositeFrame *frame)
Static method to cleanup hierarchically all daughters of a composite frame.
virtual Double_t GetRmax() const
Definition: TGeoTube.h:67
Double_t GetStOut() const
Definition: TGeoHype.h:69
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:128
ULong_t Pixel_t
Definition: GuiTypes.h:39
void Class()
Definition: Class.C:29
void DoUndo()
Slot for undoing last operation.
Editor for a TGeoHype.
virtual void SetActive(Bool_t active=kTRUE)
Set active GUI attribute frames related to the selected object.
constexpr Double_t DegToRad()
Conversion from degree to radian: .
Definition: TMath.h:82
TGCompositeFrame(const TGCompositeFrame &)
virtual TList * GetList() const
Definition: TGFrame.h:369
virtual EButtonState GetState() const
Definition: TGButton.h:112
virtual TView * GetView() const =0
TGTextButton * fApply
void DoName()
Slot for name.
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.
virtual void SetSize(const TGDimension &s)
Definition: TGFrame.h:299
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:84
Double_t fStOuti
unsigned int UInt_t
Definition: RtypesCore.h:42
Hyperboloid class defined by 5 parameters.
Definition: TGeoHype.h:17
TGFrame * fFrame
Definition: TGLayout.h:119
virtual void ShowAxis()=0
virtual ~TGeoHypeEditor()
Destructor.
virtual Double_t GetDY() const
Definition: TGeoBBox.h:71
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
#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
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
constexpr Double_t RadToDeg()
Conversion from radian to degree: .
Definition: TMath.h:74
void DoDz()
Slot for Z.
virtual void SetModel(TObject *obj)
Connect to the selected object.
Bool_t fInit
Definition: TGedFrame.h:53
Bool_t IsDelayed() const
Check if shape drawing is delayed.
TGNumberEntryField * GetNumberEntry() const
virtual Double_t GetRmin() const
Definition: TGeoTube.h:66
Short_t Max(Short_t a, Short_t b)
Definition: TMathBase.h:200
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:690
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
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
TGTextButton * fUndo
Double_t Tan(Double_t)
Definition: TMath.h:644
void DoRout()
Slot for Rout.
virtual Double_t GetDz() const
Definition: TGeoTube.h:68
char name[80]
Definition: TGX11.cxx:109
TGNumberEntry * fEDz
UInt_t GetDefaultHeight() const
Common base class for geombuilder editors.
Definition: TGeoGedFrame.h:13
virtual Double_t GetDZ() const
Definition: TGeoBBox.h:72
Double_t GetStIn() const
Definition: TGeoHype.h:68
Double_t ATan(Double_t)
Definition: TMath.h:674