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
41};
42
43////////////////////////////////////////////////////////////////////////////////
44/// Constructor for Hype editor
45
47 Int_t height, UInt_t options, Pixel_t back)
48 : TGeoGedFrame(p, width, height, options | kVerticalFrame, back)
49{
50 fShape = 0;
51 fRini = fRouti = fStIni = fStOuti = 0.0;
52 fNamei = "";
55
56 // TextEntry for shape name
57 MakeTitle("Name");
58 fShapeName = new TGTextEntry(this, new TGTextBuffer(50), kHYPE_NAME);
60 fShapeName->SetToolTipText("Enter the hyperboloid name");
61 fShapeName->Associate(this);
63
64 TGTextEntry *nef;
65 MakeTitle("Dimensions");
66 // Number entry for Rin
68 f1->AddFrame(new TGLabel(f1, "Rin"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
69 fERin = new TGNumberEntry(f1, 0., 5, kHYPE_RIN);
73 nef->SetToolTipText("Enter the inner radius ");
74 fERin->Associate(this);
75 f1->AddFrame(fERin, new TGLayoutHints(kLHintsRight, 2, 2, 4, 4));
76 AddFrame(f1, new TGLayoutHints(kLHintsLeft, 2, 2, 4, 4));
77
78 // Number entry for Rout
79 f1 = new TGCompositeFrame(this, 155, 10, kHorizontalFrame | kFixedWidth);
80 f1->AddFrame(new TGLabel(f1, "Rout"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
81 fERout = new TGNumberEntry(f1, 0., 5, kHYPE_ROUT);
85 nef->SetToolTipText("Enter the outer radius");
86 fERout->Associate(this);
87 f1->AddFrame(fERout, new TGLayoutHints(kLHintsRight, 2, 2, 4, 4));
88 AddFrame(f1, new TGLayoutHints(kLHintsLeft, 2, 2, 4, 4));
89
90 // Number entry for Dz
91 f1 = new TGCompositeFrame(this, 155, 10, kHorizontalFrame | kFixedWidth);
92 f1->AddFrame(new TGLabel(f1, "Dz"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
93 fEDz = new TGNumberEntry(f1, 0., 5, kHYPE_DZ);
97 nef->SetToolTipText("Enter the half-length in Dz");
98 fEDz->Associate(this);
99 f1->AddFrame(fEDz, new TGLayoutHints(kLHintsRight, 2, 2, 4, 4));
100 AddFrame(f1, new TGLayoutHints(kLHintsLeft, 2, 2, 4, 4));
101
102 // Number entry for StIn.
103 f1 = new TGCompositeFrame(this, 155, 10, kHorizontalFrame | kFixedWidth);
104 f1->AddFrame(new TGLabel(f1, "StIn"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
105 fEStIn = new TGNumberEntry(f1, 0., 5, kHYPE_STIN);
108 nef->SetToolTipText("Enter the stereo angle for inner surface");
109 fEStIn->Associate(this);
110 f1->AddFrame(fEStIn, new TGLayoutHints(kLHintsRight, 2, 2, 4, 4));
111 AddFrame(f1, new TGLayoutHints(kLHintsLeft, 2, 2, 4, 4));
112
113 // Number entry for StOut.
114 f1 = new TGCompositeFrame(this, 155, 10, kHorizontalFrame | kFixedWidth);
115 f1->AddFrame(new TGLabel(f1, "StOut"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
116 fEStOut = new TGNumberEntry(f1, 0., 5, kHYPE_STOUT);
120 nef->SetToolTipText("Enter the stereo angle for outer surface");
121 fEStOut->Associate(this);
122 f1->AddFrame(fEStOut, new TGLayoutHints(kLHintsRight, 2, 2, 4, 4));
123 AddFrame(f1, new TGLayoutHints(kLHintsLeft, 2, 2, 4, 4));
124
125 // Delayed draw
127 fDelayed = new TGCheckButton(f1, "Delayed draw");
128 f1->AddFrame(fDelayed, new TGLayoutHints(kLHintsLeft , 2, 2, 4, 4));
129 AddFrame(f1, new TGLayoutHints(kLHintsLeft, 6, 6, 4, 4));
130
131 // Buttons
132 f1 = new TGCompositeFrame(this, 155, 10, kHorizontalFrame | kFixedWidth);
133 fApply = new TGTextButton(f1, "Apply");
134 f1->AddFrame(fApply, new TGLayoutHints(kLHintsLeft, 2, 2, 4, 4));
135 fApply->Associate(this);
136 fUndo = new TGTextButton(f1, "Undo");
137 f1->AddFrame(fUndo, new TGLayoutHints(kLHintsRight , 2, 2, 4, 4));
138 fUndo->Associate(this);
139 AddFrame(f1, new TGLayoutHints(kLHintsLeft, 6, 6, 4, 4));
141}
142
143////////////////////////////////////////////////////////////////////////////////
144/// Destructor
145
147{
148 TGFrameElement *el;
149 TIter next(GetList());
150 while ((el = (TGFrameElement *)next())) {
151 if (el->fFrame->IsComposite())
153 }
154 Cleanup();
155}
156
157////////////////////////////////////////////////////////////////////////////////
158/// Connect signals to slots.
159
161{
162 fApply->Connect("Clicked()", "TGeoHypeEditor", this, "DoApply()");
163 fUndo->Connect("Clicked()", "TGeoHypeEditor", this, "DoUndo()");
164 fShapeName->Connect("TextChanged(const char *)", "TGeoHypeEditor", this, "DoModified()");
165 fERin->Connect("ValueSet(Long_t)", "TGeoHypeEditor", this, "DoRin()");
166 fERout->Connect("ValueSet(Long_t)", "TGeoHypeEditor", this, "DoRout()");
167 fEDz->Connect("ValueSet(Long_t)", "TGeoHypeEditor", this, "DoDz()");
168 fEStIn->Connect("ValueSet(Long_t)", "TGeoHypeEditor", this, "DoStIn()");
169 fEStOut->Connect("ValueSet(Long_t)", "TGeoHypeEditor", this, "DoStOut()");
170 fERin->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoHypeEditor", this, "DoModified()");
171 fERout->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoHypeEditor", this, "DoModified()");
172 fEDz->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoHypeEditor", this, "DoModified()");
173 fEStIn->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoHypeEditor", this, "DoModified()");
174 fEStOut->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoHypeEditor", this, "DoModified()");
175 fInit = kFALSE;
176}
177
178
179////////////////////////////////////////////////////////////////////////////////
180/// Connect to the selected object.
181
183{
184 if (obj == 0 || (obj->IsA()!=TGeoHype::Class())) {
186 return;
187 }
188 fShape = (TGeoHype*)obj;
189 fRini = fShape->GetRmin();
190 fRouti = fShape->GetRmax();
191 fDzi = fShape->GetDz();
192 fStIni = fShape->GetStIn();
194 const char *sname = fShape->GetName();
195 if (!strcmp(sname, fShape->ClassName())) fShapeName->SetText("-no_name");
196 else {
197 fShapeName->SetText(sname);
198 fNamei = sname;
199 }
207
209 SetActive();
210}
211
212////////////////////////////////////////////////////////////////////////////////
213/// Check if shape drawing is delayed.
214
216{
217 return (fDelayed->GetState() == kButtonDown);
218}
219
220////////////////////////////////////////////////////////////////////////////////
221/// Slot for name.
222
224{
225 DoModified();
226}
227
228////////////////////////////////////////////////////////////////////////////////
229/// Slot for applying current settings.
230
232{
233 const char *name = fShapeName->GetText();
234 if (strcmp(name,fShape->GetName())) fShape->SetName(name);
235 Double_t rin = fERin->GetNumber();
236 Double_t rout = fERout->GetNumber();
237 Double_t dz = fEDz->GetNumber();
238 Double_t stin = fEStIn->GetNumber();
239 Double_t stout = fEStOut->GetNumber();
240 Double_t tin = TMath::Tan(stin*TMath::DegToRad());
241 Double_t tout = TMath::Tan(stout*TMath::DegToRad());
242 if ((dz<=0) || (rin<0) || (rin>rout) ||
243 (rin*rin+tin*tin*dz*dz > rout*rout+tout*tout*dz*dz)) {
244 fUndo->SetEnabled();
246 return;
247 }
248 Double_t param[5];
249 param[0] = dz;
250 param[1] = rin;
251 param[2] = stin;
252 param[3] = rout;
253 param[4] = stout;
254 fShape->SetDimensions(param);
256 fUndo->SetEnabled();
258 if (fPad) {
260 TView *view = fPad->GetView();
261 if (!view) {
262 fShape->Draw();
263 fPad->GetView()->ShowAxis();
264 } else {
265 view->SetRange(-fShape->GetDX(), -fShape->GetDY(), -fShape->GetDZ(),
266 fShape->GetDX(), fShape->GetDY(), fShape->GetDZ());
267 Update();
268 }
269 } else Update();
270 }
271}
272
273////////////////////////////////////////////////////////////////////////////////
274/// Slot for notifying modifications.
275
277{
279}
280
281////////////////////////////////////////////////////////////////////////////////
282/// Slot for undoing last operation.
283
285{
291 DoApply();
294}
295
296////////////////////////////////////////////////////////////////////////////////
297/// Slot for Rin.
298
300{
301 Double_t rin = fERin->GetNumber();
302 Double_t rout = fERout->GetNumber();
303 Double_t dz = fEDz->GetNumber();
304 Double_t stin = fEStIn->GetNumber();
305 Double_t stout = fEStOut->GetNumber();
306 Double_t tin = TMath::Tan(stin*TMath::DegToRad());
307 Double_t tout = TMath::Tan(stout*TMath::DegToRad());
308 if (rin<0) {
309 rin = 0;
310 fERin->SetNumber(rin);
311 }
312 Double_t rinmax = TMath::Sqrt((rout*rout+tout*tout*dz*dz)/(tin*tin*dz*dz));
313 rinmax = TMath::Min(rinmax, rout);
314 if (rin > rinmax) {
315 rin = rinmax-1.e-6;
316 fERin->SetNumber(rin);
317 }
318 DoModified();
319 if (!IsDelayed()) 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()) 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()) DoApply();
371}
372
373////////////////////////////////////////////////////////////////////////////////
374/// Slot for StIn.
375
377{
378 Double_t rin = fERin->GetNumber();
379 Double_t rout = fERout->GetNumber();
380 Double_t dz = fEDz->GetNumber();
381 Double_t stin = fEStIn->GetNumber();
382 Double_t stout = fEStOut->GetNumber();
383 if (stin >= 90) {
384 stin = 89.;
385 fEStIn->SetNumber(stin);
386 }
387 Double_t tin = TMath::Tan(stin*TMath::DegToRad());
388 Double_t tout = TMath::Tan(stout*TMath::DegToRad());
389 Double_t tinmax = TMath::Sqrt(tout*tout+(rout*rout-rin*rin)/(dz*dz));
390 if (tin>tinmax) {
391 tin = tinmax-1.e-6;
392 stin = TMath::RadToDeg()*TMath::ATan(tin);
393 fEStIn->SetNumber(stin);
394 }
395 DoModified();
396 if (!IsDelayed()) DoApply();
397}
398
399////////////////////////////////////////////////////////////////////////////////
400/// Slot for StOut.
401
403{
404 Double_t rin = fERin->GetNumber();
405 Double_t rout = fERout->GetNumber();
406 Double_t dz = fEDz->GetNumber();
407 Double_t stin = fEStIn->GetNumber();
408 Double_t stout = fEStOut->GetNumber();
409 if (stout > 90) {
410 stout = 89;
411 fEStOut->SetNumber(stout);
412 }
413 Double_t tin = TMath::Tan(stin*TMath::DegToRad());
414 Double_t tout = TMath::Tan(stout*TMath::DegToRad());
415 Double_t tinmin = TMath::Sqrt((rout*rout-rin*rin)/(dz*dz));
416 if (tin < tinmin) {
417 tin = tinmin;
418 stin = TMath::RadToDeg()*TMath::ATan(tin);
419 fEStIn->SetNumber(stin);
420 }
421 Double_t toutmin = TMath::Sqrt(tin*tin -tinmin*tinmin);
422 if (tout < toutmin) {
423 tout = toutmin+1.e-6;
424 stout = TMath::RadToDeg()*TMath::ATan(tout);
425 fEStOut->SetNumber(stout);
426 }
427 DoModified();
428 if (!IsDelayed()) DoApply();
429}
@ 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:74
virtual Double_t GetDZ() const
Definition TGeoBBox.h:76
virtual Double_t GetDY() const
Definition TGeoBBox.h:75
Common base class for geombuilder editors.
virtual void Update()
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.
virtual void SetModel(TObject *obj)
Connect to the selected object.
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.
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.
virtual ~TGeoHypeEditor()
Destructor.
A hyperboloid is represented as a solid limited by two planes perpendicular to the Z axis (top and bo...
Definition TGeoHype.h:18
static TClass * Class()
virtual void SetDimensions(Double_t *param)
Set dimensions of the hyperboloid starting from an array.
Definition TGeoHype.cxx:839
Double_t GetStIn() const
Definition TGeoHype.h:71
virtual void ComputeBBox()
Compute bounding box of the hyperboloid.
Definition TGeoHype.cxx:167
Double_t GetStOut() const
Definition TGeoHype.h:72
TVirtualGeoPainter * GetPainter() const
virtual const char * GetName() const
Get the shape name.
virtual void Draw(Option_t *option="")
Draw this shape.
static void Cleanup(TGCompositeFrame *frame)
Static method to cleanup hierarchically all daughters of a composite frame.
virtual Double_t GetRmin() const
Definition TGeoTube.h:69
virtual Double_t GetDz() const
Definition TGeoTube.h:71
virtual Double_t GetRmax() const
Definition TGeoTube.h:70
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:245
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:638
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:660
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:598
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