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
37
39
40////////////////////////////////////////////////////////////////////////////////
41/// Constructor for Hype editor
42
44 : TGeoGedFrame(p, width, height, options | kVerticalFrame, back)
45{
46 fShape = nullptr;
47 fRini = fRouti = fStIni = fStOuti = 0.0;
48 fNamei = "";
51
52 // TextEntry for shape name
53 MakeTitle("Name");
54 fShapeName = new TGTextEntry(this, new TGTextBuffer(50), kHYPE_NAME);
56 fShapeName->SetToolTipText("Enter the hyperboloid name");
57 fShapeName->Associate(this);
59
60 TGTextEntry *nef;
61 MakeTitle("Dimensions");
62 // Number entry for Rin
64 f1->AddFrame(new TGLabel(f1, "Rin"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
65 fERin = new TGNumberEntry(f1, 0., 5, kHYPE_RIN);
69 nef->SetToolTipText("Enter the inner radius ");
70 fERin->Associate(this);
71 f1->AddFrame(fERin, new TGLayoutHints(kLHintsRight, 2, 2, 4, 4));
72 AddFrame(f1, new TGLayoutHints(kLHintsLeft, 2, 2, 4, 4));
73
74 // Number entry for Rout
75 f1 = new TGCompositeFrame(this, 155, 10, kHorizontalFrame | kFixedWidth);
76 f1->AddFrame(new TGLabel(f1, "Rout"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
77 fERout = new TGNumberEntry(f1, 0., 5, kHYPE_ROUT);
81 nef->SetToolTipText("Enter the outer radius");
82 fERout->Associate(this);
83 f1->AddFrame(fERout, new TGLayoutHints(kLHintsRight, 2, 2, 4, 4));
84 AddFrame(f1, new TGLayoutHints(kLHintsLeft, 2, 2, 4, 4));
85
86 // Number entry for Dz
87 f1 = new TGCompositeFrame(this, 155, 10, kHorizontalFrame | kFixedWidth);
88 f1->AddFrame(new TGLabel(f1, "Dz"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
89 fEDz = new TGNumberEntry(f1, 0., 5, kHYPE_DZ);
93 nef->SetToolTipText("Enter the half-length in Dz");
94 fEDz->Associate(this);
95 f1->AddFrame(fEDz, new TGLayoutHints(kLHintsRight, 2, 2, 4, 4));
96 AddFrame(f1, new TGLayoutHints(kLHintsLeft, 2, 2, 4, 4));
97
98 // Number entry for StIn.
99 f1 = new TGCompositeFrame(this, 155, 10, kHorizontalFrame | kFixedWidth);
100 f1->AddFrame(new TGLabel(f1, "StIn"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
101 fEStIn = new TGNumberEntry(f1, 0., 5, kHYPE_STIN);
104 nef->SetToolTipText("Enter the stereo angle for inner surface");
105 fEStIn->Associate(this);
106 f1->AddFrame(fEStIn, new TGLayoutHints(kLHintsRight, 2, 2, 4, 4));
107 AddFrame(f1, new TGLayoutHints(kLHintsLeft, 2, 2, 4, 4));
108
109 // Number entry for StOut.
110 f1 = new TGCompositeFrame(this, 155, 10, kHorizontalFrame | kFixedWidth);
111 f1->AddFrame(new TGLabel(f1, "StOut"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
112 fEStOut = new TGNumberEntry(f1, 0., 5, kHYPE_STOUT);
116 nef->SetToolTipText("Enter the stereo angle for outer surface");
117 fEStOut->Associate(this);
118 f1->AddFrame(fEStOut, new TGLayoutHints(kLHintsRight, 2, 2, 4, 4));
119 AddFrame(f1, new TGLayoutHints(kLHintsLeft, 2, 2, 4, 4));
120
121 // Delayed draw
123 fDelayed = new TGCheckButton(f1, "Delayed draw");
124 f1->AddFrame(fDelayed, new TGLayoutHints(kLHintsLeft, 2, 2, 4, 4));
125 AddFrame(f1, new TGLayoutHints(kLHintsLeft, 6, 6, 4, 4));
126
127 // Buttons
128 f1 = new TGCompositeFrame(this, 155, 10, kHorizontalFrame | kFixedWidth);
129 fApply = new TGTextButton(f1, "Apply");
130 f1->AddFrame(fApply, new TGLayoutHints(kLHintsLeft, 2, 2, 4, 4));
131 fApply->Associate(this);
132 fUndo = new TGTextButton(f1, "Undo");
133 f1->AddFrame(fUndo, new TGLayoutHints(kLHintsRight, 2, 2, 4, 4));
134 fUndo->Associate(this);
135 AddFrame(f1, new TGLayoutHints(kLHintsLeft, 6, 6, 4, 4));
137}
138
139////////////////////////////////////////////////////////////////////////////////
140/// Destructor
141
143{
144 TGFrameElement *el;
145 TIter next(GetList());
146 while ((el = (TGFrameElement *)next())) {
147 if (el->fFrame->IsComposite())
149 }
150 Cleanup();
151}
152
153////////////////////////////////////////////////////////////////////////////////
154/// Connect signals to slots.
155
157{
158 fApply->Connect("Clicked()", "TGeoHypeEditor", this, "DoApply()");
159 fUndo->Connect("Clicked()", "TGeoHypeEditor", this, "DoUndo()");
160 fShapeName->Connect("TextChanged(const char *)", "TGeoHypeEditor", this, "DoModified()");
161 fERin->Connect("ValueSet(Long_t)", "TGeoHypeEditor", this, "DoRin()");
162 fERout->Connect("ValueSet(Long_t)", "TGeoHypeEditor", this, "DoRout()");
163 fEDz->Connect("ValueSet(Long_t)", "TGeoHypeEditor", this, "DoDz()");
164 fEStIn->Connect("ValueSet(Long_t)", "TGeoHypeEditor", this, "DoStIn()");
165 fEStOut->Connect("ValueSet(Long_t)", "TGeoHypeEditor", this, "DoStOut()");
166 fERin->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoHypeEditor", this, "DoModified()");
167 fERout->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoHypeEditor", this, "DoModified()");
168 fEDz->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoHypeEditor", this, "DoModified()");
169 fEStIn->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoHypeEditor", this, "DoModified()");
170 fEStOut->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoHypeEditor", this, "DoModified()");
171 fInit = kFALSE;
172}
173
174////////////////////////////////////////////////////////////////////////////////
175/// Connect to the selected object.
176
178{
179 if (obj == nullptr || (obj->IsA() != TGeoHype::Class())) {
181 return;
182 }
183 fShape = (TGeoHype *)obj;
184 fRini = fShape->GetRmin();
185 fRouti = fShape->GetRmax();
186 fDzi = fShape->GetDz();
187 fStIni = fShape->GetStIn();
189 const char *sname = fShape->GetName();
190 if (!strcmp(sname, fShape->ClassName()))
191 fShapeName->SetText("-no_name");
192 else {
193 fShapeName->SetText(sname);
194 fNamei = sname;
195 }
203
204 if (fInit)
206 SetActive();
207}
208
209////////////////////////////////////////////////////////////////////////////////
210/// Check if shape drawing is delayed.
211
213{
214 return (fDelayed->GetState() == kButtonDown);
215}
216
217////////////////////////////////////////////////////////////////////////////////
218/// Slot for name.
219
221{
222 DoModified();
223}
224
225////////////////////////////////////////////////////////////////////////////////
226/// Slot for applying current settings.
227
229{
230 const char *name = fShapeName->GetText();
231 if (strcmp(name, fShape->GetName()))
233 Double_t rin = fERin->GetNumber();
234 Double_t rout = fERout->GetNumber();
235 Double_t dz = fEDz->GetNumber();
236 Double_t stin = fEStIn->GetNumber();
237 Double_t stout = fEStOut->GetNumber();
238 Double_t tin = TMath::Tan(stin * TMath::DegToRad());
239 Double_t tout = TMath::Tan(stout * TMath::DegToRad());
240 if ((dz <= 0) || (rin < 0) || (rin > rout) ||
241 (rin * rin + tin * tin * dz * dz > rout * rout + tout * tout * dz * dz)) {
242 fUndo->SetEnabled();
244 return;
245 }
246 Double_t param[5];
247 param[0] = dz;
248 param[1] = rin;
249 param[2] = stin;
250 param[3] = rout;
251 param[4] = stout;
252 fShape->SetDimensions(param);
254 fUndo->SetEnabled();
256 if (fPad) {
258 TView *view = fPad->GetView();
259 if (!view) {
260 fShape->Draw();
261 fPad->GetView()->ShowAxis();
262 } else {
263 view->SetRange(-fShape->GetDX(), -fShape->GetDY(), -fShape->GetDZ(), fShape->GetDX(), fShape->GetDY(),
264 fShape->GetDZ());
265 Update();
266 }
267 } else
268 Update();
269 }
270}
271
272////////////////////////////////////////////////////////////////////////////////
273/// Slot for notifying modifications.
274
276{
278}
279
280////////////////////////////////////////////////////////////////////////////////
281/// Slot for undoing last operation.
282
284{
290 DoApply();
293}
294
295////////////////////////////////////////////////////////////////////////////////
296/// Slot for Rin.
297
299{
300 Double_t rin = fERin->GetNumber();
301 Double_t rout = fERout->GetNumber();
302 Double_t dz = fEDz->GetNumber();
303 Double_t stin = fEStIn->GetNumber();
304 Double_t stout = fEStOut->GetNumber();
305 Double_t tin = TMath::Tan(stin * TMath::DegToRad());
306 Double_t tout = TMath::Tan(stout * TMath::DegToRad());
307 if (rin < 0) {
308 rin = 0;
309 fERin->SetNumber(rin);
310 }
311 Double_t rinmax = TMath::Sqrt((rout * rout + tout * tout * dz * dz) / (tin * tin * dz * dz));
312 rinmax = TMath::Min(rinmax, rout);
313 if (rin > rinmax) {
314 rin = rinmax - 1.e-6;
315 fERin->SetNumber(rin);
316 }
317 DoModified();
318 if (!IsDelayed())
319 DoApply();
320}
321
322////////////////////////////////////////////////////////////////////////////////
323/// Slot for Rout.
324
326{
327 Double_t rin = fERin->GetNumber();
328 Double_t rout = fERout->GetNumber();
329 Double_t dz = fEDz->GetNumber();
330 Double_t stin = fEStIn->GetNumber();
331 Double_t stout = fEStOut->GetNumber();
332 Double_t tin = TMath::Tan(stin * TMath::DegToRad());
333 Double_t tout = TMath::Tan(stout * TMath::DegToRad());
334 Double_t routmin = TMath::Sqrt((rin * rin + tin * tin * dz * dz) / (tout * tout * dz * dz));
335 routmin = TMath::Max(routmin, rin);
336 if (rout < routmin) {
337 rout = routmin + 1.e-6;
338 fERout->SetNumber(rout);
339 }
340 DoModified();
341 if (!IsDelayed())
342 DoApply();
343}
344
345////////////////////////////////////////////////////////////////////////////////
346/// Slot for Z.
347
349{
350 Double_t rin = fERin->GetNumber();
351 Double_t rout = fERout->GetNumber();
352 Double_t dz = fEDz->GetNumber();
353 Double_t stin = fEStIn->GetNumber();
354 Double_t stout = fEStOut->GetNumber();
355 if (TMath::Abs(stin - stout) < 1.e-6) {
356 stin = stout + 1.;
357 fEStIn->SetNumber(stin);
358 }
359 Double_t tin = TMath::Tan(stin * TMath::DegToRad());
360 Double_t tout = TMath::Tan(stout * TMath::DegToRad());
361 if (dz <= 0) {
362 dz = 0.1;
363 fEDz->SetNumber(dz);
364 }
365 Double_t dzmax = TMath::Sqrt((rout * rout - rin * rin) / (tin * tin - tout * tout));
366 if (dz > dzmax) {
367 dz = dzmax;
368 fEDz->SetNumber(dz);
369 }
370 DoModified();
371 if (!IsDelayed())
372 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())
399 DoApply();
400}
401
402////////////////////////////////////////////////////////////////////////////////
403/// Slot for StOut.
404
406{
407 Double_t rin = fERin->GetNumber();
408 Double_t rout = fERout->GetNumber();
409 Double_t dz = fEDz->GetNumber();
410 Double_t stin = fEStIn->GetNumber();
411 Double_t stout = fEStOut->GetNumber();
412 if (stout > 90) {
413 stout = 89;
414 fEStOut->SetNumber(stout);
415 }
416 Double_t tin = TMath::Tan(stin * TMath::DegToRad());
417 Double_t tout = TMath::Tan(stout * TMath::DegToRad());
418 Double_t tinmin = TMath::Sqrt((rout * rout - rin * rin) / (dz * dz));
419 if (tin < tinmin) {
420 tin = tinmin;
421 stin = TMath::RadToDeg() * TMath::ATan(tin);
422 fEStIn->SetNumber(stin);
423 }
424 Double_t toutmin = TMath::Sqrt(tin * tin - tinmin * tinmin);
425 if (tout < toutmin) {
426 tout = toutmin + 1.e-6;
427 stout = TMath::RadToDeg() * TMath::ATan(tout);
428 fEStOut->SetNumber(stout);
429 }
430 DoModified();
431 if (!IsDelayed())
432 DoApply();
433}
@ kSunkenFrame
Definition GuiTypes.h:383
@ kVerticalFrame
Definition GuiTypes.h:381
@ kFixedWidth
Definition GuiTypes.h:387
@ kHorizontalFrame
Definition GuiTypes.h:382
ULong_t Pixel_t
Pixel value.
Definition GuiTypes.h:40
constexpr Bool_t kFALSE
Definition RtypesCore.h:101
constexpr Bool_t kTRUE
Definition RtypesCore.h:100
#define ClassImp(name)
Definition Rtypes.h:377
@ kButtonDown
Definition TGButton.h:54
@ kLHintsRight
Definition TGLayout.h:26
@ kLHintsLeft
Definition TGLayout.h:24
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t width
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t height
char name[80]
Definition TGX11.cxx:110
ETGeoHypeWid
@ kHYPE_APPLY
@ kHYPE_UNDO
@ kHYPE_NAME
@ kHYPE_DZ
@ kHYPE_RIN
@ kHYPE_STOUT
@ kHYPE_STIN
@ kHYPE_ROUT
R__EXTERN TGeoManager * gGeoManager
virtual EButtonState GetState() const
Definition TGButton.h:112
virtual void SetEnabled(Bool_t e=kTRUE)
Set enabled or disabled state of button.
Definition TGButton.cxx:459
Selects different options.
Definition TGButton.h:264
The base class for composite widgets (menu bars, list boxes, etc.).
Definition TGFrame.h:287
virtual void AddFrame(TGFrame *f, TGLayoutHints *l=nullptr)
Add frame to the composite frame using the specified layout hints.
Definition TGFrame.cxx:1117
virtual TList * GetList() const
Definition TGFrame.h:310
virtual void Cleanup()
Cleanup and delete all objects contained in this composite frame.
Definition TGFrame.cxx:967
TGFrame * fFrame
Definition TGLayout.h:112
virtual void SetSize(const TGDimension &s)
Definition TGFrame.h:252
void Resize(UInt_t w=0, UInt_t h=0) override
Resize the frame.
Definition TGFrame.cxx:605
virtual UInt_t GetDefaultHeight() const
Definition TGFrame.h:191
TGDimension GetSize() const
Definition TGFrame.h:230
virtual Bool_t IsComposite() const
Definition TGFrame.h:212
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.
TGNumberEntryField * GetNumberEntry() const
Get the number entry field.
void Associate(const TGWindow *w) override
Make w the window that will receive the generated messages.
void SetNumAttr(EAttribute attr=kNEAAnyNumber)
virtual Double_t GetNumber() const
virtual void SetNumber(Double_t val, Bool_t emit=kTRUE)
UInt_t GetDefaultHeight() const override
@ 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
const char * GetText() const
virtual void SetToolTipText(const char *text, Long_t delayms=500)
Set tool tip text associated with this text entry.
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.
virtual void Associate(const TGWindow *w)
Definition TGWidget.h:72
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:95
virtual Double_t GetDX() const
Definition TGeoBBox.h:79
virtual Double_t GetDZ() const
Definition TGeoBBox.h:81
virtual Double_t GetDY() const
Definition TGeoBBox.h:80
Common base class for geombuilder editors.
void Update() override
Override Update from TGedFrame as fGedEditor can be null.
TVirtualPad * fPad
virtual void SetActive(Bool_t active=kTRUE)
Set active GUI attribute frames related to the selected object.
Editor for a TGeoHype.
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.
A hyperboloid is represented as a solid limited by two planes perpendicular to the Z axis (top and bo...
Definition TGeoHype.h:17
static TClass * Class()
void ComputeBBox() override
Compute bounding box of the hyperboloid.
Definition TGeoHype.cxx:162
void SetDimensions(Double_t *param) override
Set dimensions of the hyperboloid starting from an array.
Definition TGeoHype.cxx:881
Double_t GetStIn() const
Definition TGeoHype.h:72
Double_t GetStOut() const
Definition TGeoHype.h:73
TVirtualGeoPainter * GetPainter() const
void Draw(Option_t *option="") override
Draw this shape.
const char * GetName() const override
Get the shape name.
static void Cleanup(TGCompositeFrame *frame)
Static method to cleanup hierarchically all daughters of a composite frame.
virtual Double_t GetRmin() const
Definition TGeoTube.h:72
virtual Double_t GetDz() const
Definition TGeoTube.h:74
virtual Double_t GetRmax() const
Definition TGeoTube.h:73
virtual void SetName(const char *name)
Set the name of the TNamed.
Definition TNamed.cxx:140
Mother of all ROOT objects.
Definition TObject.h:41
virtual const char * ClassName() const
Returns name of class to which the object belongs.
Definition TObject.cxx:207
virtual TClass * IsA() const
Definition TObject.h:243
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:869
See TView3D.
Definition TView.h:25
virtual void ShowAxis()=0
virtual void SetRange(const Double_t *min, const Double_t *max)=0
virtual Bool_t IsPaintingShape() const =0
virtual TView * GetView() const =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:250
Double_t ATan(Double_t)
Returns the principal value of the arc tangent of x, expressed in radians.
Definition TMath.h:640
constexpr Double_t DegToRad()
Conversion from degree to radian: .
Definition TMath.h:79
Double_t Sqrt(Double_t x)
Returns the square root of x.
Definition TMath.h:662
Short_t Min(Short_t a, Short_t b)
Returns the smallest of a and b.
Definition TMathBase.h:198
Double_t Tan(Double_t)
Returns the tangent of an angle of x radians.
Definition TMath.h:600
constexpr Double_t RadToDeg()
Conversion from radian to degree: .
Definition TMath.h:72
Short_t Abs(Short_t d)
Returns the absolute value of parameter Short_t d.
Definition TMathBase.h:123