Logo ROOT  
Reference Guide
Loading...
Searching...
No Matches
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
15Editor 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 "TVirtualPad.h"
29#include "TView.h"
30#include "TMath.h"
31#include "TGButton.h"
32#include "TGTextEntry.h"
33#include "TGNumberEntry.h"
34#include "TGLabel.h"
35
36
38
39////////////////////////////////////////////////////////////////////////////////
40/// Constructor for Hype editor
41
42TGeoHypeEditor::TGeoHypeEditor(const TGWindow *p, Int_t width, Int_t height, UInt_t options, Pixel_t back)
43 : TGeoGedFrame(p, width, height, options | kVerticalFrame, back)
44{
45 fShape = nullptr;
46 fRini = fRouti = fStIni = fStOuti = 0.0;
47 fNamei = "";
50
51 // TextEntry for shape name
52 MakeTitle("Name");
53 fShapeName = new TGTextEntry(this, new TGTextBuffer(50), kHYPE_NAME);
54 fShapeName->Resize(135, fShapeName->GetDefaultHeight());
55 fShapeName->SetToolTipText("Enter the hyperboloid name");
56 fShapeName->Associate(this);
58
59 TGTextEntry *nef;
60 MakeTitle("Dimensions");
61 // Number entry for Rin
63 f1->AddFrame(new TGLabel(f1, "Rin"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
64 fERin = new TGNumberEntry(f1, 0., 5, kHYPE_RIN);
66 fERin->Resize(100, fERin->GetDefaultHeight());
67 nef = (TGTextEntry *)fERin->GetNumberEntry();
68 nef->SetToolTipText("Enter the inner radius ");
69 fERin->Associate(this);
70 f1->AddFrame(fERin, new TGLayoutHints(kLHintsRight, 2, 2, 4, 4));
71 AddFrame(f1, new TGLayoutHints(kLHintsLeft, 2, 2, 4, 4));
72
73 // Number entry for Rout
74 f1 = new TGCompositeFrame(this, 155, 10, kHorizontalFrame | kFixedWidth);
75 f1->AddFrame(new TGLabel(f1, "Rout"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
76 fERout = new TGNumberEntry(f1, 0., 5, kHYPE_ROUT);
78 fERout->Resize(100, fERout->GetDefaultHeight());
79 nef = (TGTextEntry *)fERout->GetNumberEntry();
80 nef->SetToolTipText("Enter the outer radius");
81 fERout->Associate(this);
82 f1->AddFrame(fERout, new TGLayoutHints(kLHintsRight, 2, 2, 4, 4));
83 AddFrame(f1, new TGLayoutHints(kLHintsLeft, 2, 2, 4, 4));
84
85 // Number entry for Dz
86 f1 = new TGCompositeFrame(this, 155, 10, kHorizontalFrame | kFixedWidth);
87 f1->AddFrame(new TGLabel(f1, "Dz"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
88 fEDz = new TGNumberEntry(f1, 0., 5, kHYPE_DZ);
90 fEDz->Resize(100, fEDz->GetDefaultHeight());
91 nef = (TGTextEntry *)fEDz->GetNumberEntry();
92 nef->SetToolTipText("Enter the half-length in Dz");
93 fEDz->Associate(this);
94 f1->AddFrame(fEDz, new TGLayoutHints(kLHintsRight, 2, 2, 4, 4));
95 AddFrame(f1, new TGLayoutHints(kLHintsLeft, 2, 2, 4, 4));
96
97 // Number entry for StIn.
98 f1 = new TGCompositeFrame(this, 155, 10, kHorizontalFrame | kFixedWidth);
99 f1->AddFrame(new TGLabel(f1, "StIn"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
100 fEStIn = new TGNumberEntry(f1, 0., 5, kHYPE_STIN);
101 fEStIn->Resize(100, fEStIn->GetDefaultHeight());
102 nef = (TGTextEntry *)fEStIn->GetNumberEntry();
103 nef->SetToolTipText("Enter the stereo angle for inner surface");
104 fEStIn->Associate(this);
105 f1->AddFrame(fEStIn, new TGLayoutHints(kLHintsRight, 2, 2, 4, 4));
106 AddFrame(f1, new TGLayoutHints(kLHintsLeft, 2, 2, 4, 4));
107
108 // Number entry for StOut.
109 f1 = new TGCompositeFrame(this, 155, 10, kHorizontalFrame | kFixedWidth);
110 f1->AddFrame(new TGLabel(f1, "StOut"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
111 fEStOut = new TGNumberEntry(f1, 0., 5, kHYPE_STOUT);
113 fEStOut->Resize(100, fEStOut->GetDefaultHeight());
114 nef = (TGTextEntry *)fEStOut->GetNumberEntry();
115 nef->SetToolTipText("Enter the stereo angle for outer surface");
116 fEStOut->Associate(this);
117 f1->AddFrame(fEStOut, new TGLayoutHints(kLHintsRight, 2, 2, 4, 4));
118 AddFrame(f1, new TGLayoutHints(kLHintsLeft, 2, 2, 4, 4));
119
120 // Delayed draw
122 fDelayed = new TGCheckButton(f1, "Delayed draw");
123 f1->AddFrame(fDelayed, new TGLayoutHints(kLHintsLeft, 2, 2, 4, 4));
124 AddFrame(f1, new TGLayoutHints(kLHintsLeft, 6, 6, 4, 4));
125
126 // Buttons
127 f1 = new TGCompositeFrame(this, 155, 10, kHorizontalFrame | kFixedWidth);
128 fApply = new TGTextButton(f1, "Apply");
129 f1->AddFrame(fApply, new TGLayoutHints(kLHintsLeft, 2, 2, 4, 4));
130 fApply->Associate(this);
131 fUndo = new TGTextButton(f1, "Undo");
132 f1->AddFrame(fUndo, new TGLayoutHints(kLHintsRight, 2, 2, 4, 4));
133 fUndo->Associate(this);
134 AddFrame(f1, new TGLayoutHints(kLHintsLeft, 6, 6, 4, 4));
135 fUndo->SetSize(fApply->GetSize());
136}
137
138////////////////////////////////////////////////////////////////////////////////
139/// Destructor
140
142{
143 TGFrameElement *el;
144 TIter next(GetList());
145 while ((el = (TGFrameElement *)next())) {
146 if (el->fFrame->IsComposite())
148 }
149 Cleanup();
150}
151
152////////////////////////////////////////////////////////////////////////////////
153/// Connect signals to slots.
154
156{
157 fApply->Connect("Clicked()", "TGeoHypeEditor", this, "DoApply()");
158 fUndo->Connect("Clicked()", "TGeoHypeEditor", this, "DoUndo()");
159 fShapeName->Connect("TextChanged(const char *)", "TGeoHypeEditor", this, "DoModified()");
160 fERin->Connect("ValueSet(Long_t)", "TGeoHypeEditor", this, "DoRin()");
161 fERout->Connect("ValueSet(Long_t)", "TGeoHypeEditor", this, "DoRout()");
162 fEDz->Connect("ValueSet(Long_t)", "TGeoHypeEditor", this, "DoDz()");
163 fEStIn->Connect("ValueSet(Long_t)", "TGeoHypeEditor", this, "DoStIn()");
164 fEStOut->Connect("ValueSet(Long_t)", "TGeoHypeEditor", this, "DoStOut()");
165 fERin->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoHypeEditor", this, "DoModified()");
166 fERout->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoHypeEditor", this, "DoModified()");
167 fEDz->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoHypeEditor", this, "DoModified()");
168 fEStIn->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoHypeEditor", this, "DoModified()");
169 fEStOut->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoHypeEditor", this, "DoModified()");
170 fInit = kFALSE;
171}
172
173////////////////////////////////////////////////////////////////////////////////
174/// Connect to the selected object.
175
177{
178 if (obj == nullptr || (obj->IsA() != TGeoHype::Class())) {
180 return;
181 }
182 fShape = (TGeoHype *)obj;
183 fRini = fShape->GetRmin();
184 fRouti = fShape->GetRmax();
185 fDzi = fShape->GetDz();
186 fStIni = fShape->GetStIn();
187 fStOuti = fShape->GetStOut();
188 const char *sname = fShape->GetName();
189 if (!strcmp(sname, fShape->ClassName()))
190 fShapeName->SetText("-no_name");
191 else {
192 fShapeName->SetText(sname);
193 fNamei = sname;
194 }
195 fERin->SetNumber(fRini);
196 fERout->SetNumber(fRouti);
197 fEDz->SetNumber(fDzi);
198 fEStIn->SetNumber(fStIni);
199 fEStOut->SetNumber(fStOuti);
200 fApply->SetEnabled(kFALSE);
201 fUndo->SetEnabled(kFALSE);
202
203 if (fInit)
205 SetActive();
206}
207
208////////////////////////////////////////////////////////////////////////////////
209/// Check if shape drawing is delayed.
210
212{
213 return (fDelayed->GetState() == kButtonDown);
214}
215
216////////////////////////////////////////////////////////////////////////////////
217/// Slot for name.
218
220{
221 DoModified();
222}
223
224////////////////////////////////////////////////////////////////////////////////
225/// Slot for applying current settings.
226
228{
229 const char *name = fShapeName->GetText();
230 if (strcmp(name, fShape->GetName()))
231 fShape->SetName(name);
232 Double_t rin = fERin->GetNumber();
233 Double_t rout = fERout->GetNumber();
234 Double_t dz = fEDz->GetNumber();
235 Double_t stin = fEStIn->GetNumber();
236 Double_t stout = fEStOut->GetNumber();
237 Double_t tin = TMath::Tan(stin * TMath::DegToRad());
238 Double_t tout = TMath::Tan(stout * TMath::DegToRad());
239 if ((dz <= 0) || (rin < 0) || (rin > rout) ||
240 (rin * rin + tin * tin * dz * dz > rout * rout + tout * tout * dz * dz)) {
241 fUndo->SetEnabled();
242 fApply->SetEnabled(kFALSE);
243 return;
244 }
245 Double_t param[5];
246 param[0] = dz;
247 param[1] = rin;
248 param[2] = stin;
249 param[3] = rout;
250 param[4] = stout;
251 fShape->SetDimensions(param);
252 fShape->ComputeBBox();
253 fUndo->SetEnabled();
254 fApply->SetEnabled(kFALSE);
255 if (fPad) {
256 if (gGeoManager && gGeoManager->GetPainter() && gGeoManager->GetPainter()->IsPaintingShape()) {
257 TView *view = fPad->GetView();
258 if (!view) {
259 fShape->Draw();
260 fPad->GetView()->ShowAxis();
261 } else {
262 view->SetRange(-fShape->GetDX(), -fShape->GetDY(), -fShape->GetDZ(), fShape->GetDX(), fShape->GetDY(),
263 fShape->GetDZ());
264 Update();
265 }
266 } else
267 Update();
268 }
269}
270
271////////////////////////////////////////////////////////////////////////////////
272/// Slot for notifying modifications.
273
275{
276 fApply->SetEnabled();
277}
278
279////////////////////////////////////////////////////////////////////////////////
280/// Slot for undoing last operation.
281
283{
284 fERin->SetNumber(fRini);
285 fERout->SetNumber(fRouti);
286 fEDz->SetNumber(fDzi);
287 fEStIn->SetNumber(fStIni);
288 fEStOut->SetNumber(fStOuti);
289 DoApply();
290 fUndo->SetEnabled(kFALSE);
291 fApply->SetEnabled(kFALSE);
292}
293
294////////////////////////////////////////////////////////////////////////////////
295/// Slot for Rin.
296
298{
299 Double_t rin = fERin->GetNumber();
300 Double_t rout = fERout->GetNumber();
301 Double_t dz = fEDz->GetNumber();
302 Double_t stin = fEStIn->GetNumber();
303 Double_t stout = fEStOut->GetNumber();
304 Double_t tin = TMath::Tan(stin * TMath::DegToRad());
305 Double_t tout = TMath::Tan(stout * TMath::DegToRad());
306 if (rin < 0) {
307 rin = 0;
308 fERin->SetNumber(rin);
309 }
310 Double_t rinmax = TMath::Sqrt((rout * rout + tout * tout * dz * dz) / (tin * tin * dz * dz));
311 rinmax = TMath::Min(rinmax, rout);
312 if (rin > rinmax) {
313 rin = rinmax - 1.e-6;
314 fERin->SetNumber(rin);
315 }
316 DoModified();
317 if (!IsDelayed())
318 DoApply();
319}
320
321////////////////////////////////////////////////////////////////////////////////
322/// Slot for Rout.
323
325{
326 Double_t rin = fERin->GetNumber();
327 Double_t rout = fERout->GetNumber();
328 Double_t dz = fEDz->GetNumber();
329 Double_t stin = fEStIn->GetNumber();
330 Double_t stout = fEStOut->GetNumber();
331 Double_t tin = TMath::Tan(stin * TMath::DegToRad());
332 Double_t tout = TMath::Tan(stout * TMath::DegToRad());
333 Double_t routmin = TMath::Sqrt((rin * rin + tin * tin * dz * dz) / (tout * tout * dz * dz));
334 routmin = TMath::Max(routmin, rin);
335 if (rout < routmin) {
336 rout = routmin + 1.e-6;
337 fERout->SetNumber(rout);
338 }
339 DoModified();
340 if (!IsDelayed())
341 DoApply();
342}
343
344////////////////////////////////////////////////////////////////////////////////
345/// Slot for Z.
346
348{
349 Double_t rin = fERin->GetNumber();
350 Double_t rout = fERout->GetNumber();
351 Double_t dz = fEDz->GetNumber();
352 Double_t stin = fEStIn->GetNumber();
353 Double_t stout = fEStOut->GetNumber();
354 if (TMath::Abs(stin - stout) < 1.e-6) {
355 stin = stout + 1.;
356 fEStIn->SetNumber(stin);
357 }
358 Double_t tin = TMath::Tan(stin * TMath::DegToRad());
359 Double_t tout = TMath::Tan(stout * TMath::DegToRad());
360 if (dz <= 0) {
361 dz = 0.1;
362 fEDz->SetNumber(dz);
363 }
364 Double_t dzmax = TMath::Sqrt((rout * rout - rin * rin) / (tin * tin - tout * tout));
365 if (dz > dzmax) {
366 dz = dzmax;
367 fEDz->SetNumber(dz);
368 }
369 DoModified();
370 if (!IsDelayed())
371 DoApply();
372}
373
374////////////////////////////////////////////////////////////////////////////////
375/// Slot for StIn.
376
378{
379 Double_t rin = fERin->GetNumber();
380 Double_t rout = fERout->GetNumber();
381 Double_t dz = fEDz->GetNumber();
382 Double_t stin = fEStIn->GetNumber();
383 Double_t stout = fEStOut->GetNumber();
384 if (stin >= 90) {
385 stin = 89.;
386 fEStIn->SetNumber(stin);
387 }
388 Double_t tin = TMath::Tan(stin * TMath::DegToRad());
389 Double_t tout = TMath::Tan(stout * TMath::DegToRad());
390 Double_t tinmax = TMath::Sqrt(tout * tout + (rout * rout - rin * rin) / (dz * dz));
391 if (tin > tinmax) {
392 tin = tinmax - 1.e-6;
393 stin = TMath::RadToDeg() * TMath::ATan(tin);
394 fEStIn->SetNumber(stin);
395 }
396 DoModified();
397 if (!IsDelayed())
398 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())
431 DoApply();
432}
@ kSunkenFrame
Definition GuiTypes.h:384
@ kVerticalFrame
Definition GuiTypes.h:382
@ kFixedWidth
Definition GuiTypes.h:388
@ kHorizontalFrame
Definition GuiTypes.h:383
ULong_t Pixel_t
Pixel value.
Definition GuiTypes.h:41
int Int_t
Signed integer 4 bytes (int).
Definition RtypesCore.h:59
unsigned int UInt_t
Unsigned integer 4 bytes (unsigned int).
Definition RtypesCore.h:60
bool Bool_t
Boolean (0=false, 1=true) (bool).
Definition RtypesCore.h:77
constexpr Bool_t kFALSE
Definition RtypesCore.h:108
double Double_t
Double 8 bytes.
Definition RtypesCore.h:73
constexpr Bool_t kTRUE
Definition RtypesCore.h:107
@ kButtonDown
Definition TGButton.h:54
@ kLHintsRight
Definition TGLayout.h:26
@ kLHintsLeft
Definition TGLayout.h:24
char name[80]
Definition TGX11.cxx:148
ETGeoHypeWid
@ kHYPE_APPLY
@ kHYPE_UNDO
@ kHYPE_NAME
@ kHYPE_DZ
@ kHYPE_RIN
@ kHYPE_STOUT
@ kHYPE_STIN
@ kHYPE_ROUT
externTGeoManager * gGeoManager
Selects different options.
Definition TGButton.h:264
virtual void AddFrame(TGFrame *f, TGLayoutHints *l=nullptr)
Add frame to the composite frame using the specified layout hints.
Definition TGFrame.cxx:1109
virtual TList * GetList() const
Definition TGFrame.h:312
virtual void Cleanup()
Cleanup and delete all objects contained in this composite frame.
Definition TGFrame.cxx:959
TGCompositeFrame(const TGCompositeFrame &)=delete
TGFrame * fFrame
Definition TGLayout.h:112
virtual Bool_t IsComposite() const
Definition TGFrame.h:214
This class handles GUI labels.
Definition TGLabel.h:24
This class describes layout hints used by the layout classes.
Definition TGLayout.h:50
TGNumberEntry is a number entry input widget with up/down buttons.
@ kNEAPositive
Positive number.
A text buffer is used in several widgets, like TGTextEntry, TGFileDialog, etc.
Yield an action as soon as it is clicked.
Definition TGButton.h:142
A TGTextEntry is a one line text input widget.
Definition TGTextEntry.h:24
virtual void SetToolTipText(const char *text, Long_t delayms=500)
Set tool tip text associated with this text entry.
ROOT GUI Window base class.
Definition TGWindow.h:23
Bool_t fInit
init flag for setting signals/slots
Definition TGedFrame.h:47
virtual void MakeTitle(const char *title)
Create attribute frame title.
Definition TGedFrame.cxx:94
void Update() override
Override Update from TGedFrame as fGedEditor can be null.
TVirtualPad * fPad
TGeoGedFrame(const TGWindow *p=nullptr, Int_t width=140, Int_t height=30, UInt_t options=kChildFrame, Pixel_t back=GetDefaultFrameBackground())
Constructor.
virtual void SetActive(Bool_t active=kTRUE)
Set active GUI attribute frames related to the selected object.
void DoUndo()
Slot for undoing last operation.
TGTextEntry * fShapeName
Bool_t IsDelayed() const
Check if shape drawing is delayed.
virtual void ConnectSignals2Slots()
Connect signals to slots.
TGeoHype * fShape
TGCheckButton * fDelayed
TGNumberEntry * fEStIn
void DoRin()
Slot for Rin.
TGTextButton * fUndo
void DoRout()
Slot for Rout.
void DoModified()
Slot for notifying modifications.
TGNumberEntry * fEStOut
void DoStOut()
Slot for StOut.
void SetModel(TObject *obj) override
Connect to the selected object.
TGTextButton * fApply
TGNumberEntry * fERout
void DoName()
Slot for name.
TGNumberEntry * fEDz
void DoDz()
Slot for Z.
void DoStIn()
Slot for StIn.
Bool_t fIsShapeEditable
void DoApply()
Slot for applying current settings.
TGNumberEntry * fERin
TGeoHypeEditor(const TGWindow *p=nullptr, Int_t width=140, Int_t height=30, UInt_t options=kChildFrame, Pixel_t back=GetDefaultFrameBackground())
Constructor for Hype editor.
~TGeoHypeEditor() override
Destructor.
static TClass * Class()
static void Cleanup(TGCompositeFrame *frame)
Static method to cleanup hierarchically all daughters of a composite frame.
Mother of all ROOT objects.
Definition TObject.h:42
virtual TClass * IsA() const
Definition TObject.h:248
See TView3D.
Definition TView.h:25
virtual void SetRange(const Double_t *min, const Double_t *max)=0
TF1 * f1
Definition legend1.C:11
Short_t Max(Short_t a, Short_t b)
Returns the largest of a and b.
Definition TMathBase.h:249
Double_t ATan(Double_t)
Returns the principal value of the arc tangent of x, expressed in radians.
Definition TMath.h:651
constexpr Double_t DegToRad()
Conversion from degree to radian: .
Definition TMath.h:82
Double_t Sqrt(Double_t x)
Returns the square root of x.
Definition TMath.h:673
Short_t Min(Short_t a, Short_t b)
Returns the smallest of a and b.
Definition TMathBase.h:197
Double_t Tan(Double_t)
Returns the tangent of an angle of x radians.
Definition TMath.h:611
constexpr Double_t RadToDeg()
Conversion from radian to degree: .
Definition TMath.h:75
Short_t Abs(Short_t d)
Returns the absolute value of parameter Short_t d.
Definition TMathBase.h:122