Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TGeoSphereEditor.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 TGeoSphereEditor
13\ingroup Geometry_builder
14
15Editor for a TGeoSphere.
16
17\image html geom_sphe_pic.png
18
19\image html geom_sphe_ed.png
20
21*/
22
23#include "TGeoSphereEditor.h"
24#include "TGeoTabManager.h"
25#include "TGeoSphere.h"
26#include "TGeoManager.h"
27#include "TVirtualGeoPainter.h"
28#include "TVirtualPad.h"
29#include "TView.h"
30#include "TGButton.h"
31#include "TGTextEntry.h"
32#include "TGNumberEntry.h"
33#include "TGLabel.h"
34#include "TGDoubleSlider.h"
35
37
42};
43
44////////////////////////////////////////////////////////////////////////////////
45/// Constructor for sphere editor
46
48 Int_t height, UInt_t options, Pixel_t back)
49 : TGeoGedFrame(p, width, height, options | kVerticalFrame, back)
50{
51 fShape = 0;
53 fNamei = "";
56 fLock = kFALSE;
57
58 // TextEntry for shape name
59 MakeTitle("Name");
60 fShapeName = new TGTextEntry(this, new TGTextBuffer(50), kSPHERE_NAME);
62 fShapeName->SetToolTipText("Enter the sphere name");
63 fShapeName->Associate(this);
65
66 TGTextEntry *nef;
67 MakeTitle("Sphere dimensions");
68 TGCompositeFrame *compxyz = new TGCompositeFrame(this, 118, 30, kVerticalFrame | kRaisedFrame);
69 // Number entry for rmin
70 TGCompositeFrame *f1 = new TGCompositeFrame(compxyz, 118, 10, kHorizontalFrame |
72 f1->AddFrame(new TGLabel(f1, "Rmin"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
73 fERmin = new TGNumberEntry(f1, 0., 5, kSPHERE_RMIN);
76 nef->SetToolTipText("Enter the inner radius");
77 fERmin->Associate(this);
79 f1->AddFrame(fERmin, new TGLayoutHints(kLHintsRight , 2, 2, 4, 4));
80 compxyz->AddFrame(f1, new TGLayoutHints(kLHintsLeft | kLHintsExpandX , 2, 2, 4, 4));
81
82 // Number entry for Rmax
83 f1 = new TGCompositeFrame(compxyz, 118, 10, kHorizontalFrame |
85 f1->AddFrame(new TGLabel(f1, "Rmax"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
86 fERmax = new TGNumberEntry(f1, 0., 5, kSPHERE_RMAX);
89 nef->SetToolTipText("Enter the outer radius");
90 fERmax->Associate(this);
92 f1->AddFrame(fERmax, new TGLayoutHints(kLHintsRight, 2, 2, 4, 4));
93 compxyz->AddFrame(f1, new TGLayoutHints(kLHintsLeft | kLHintsExpandX , 2, 2, 4, 4));
94 AddFrame(compxyz, new TGLayoutHints(kLHintsLeft, 2, 2, 2, 2));
95
96 MakeTitle("Phi/theta range");
97 TGCompositeFrame *f11 = new TGCompositeFrame(this, 150,200, kHorizontalFrame);
98 compxyz = new TGCompositeFrame(f11, 75, 200, kHorizontalFrame | kRaisedFrame);
99 // Vertical slider
100 fSPhi = new TGDoubleVSlider(compxyz,140);
101 fSPhi->SetRange(0.,720.);
102 compxyz->AddFrame(fSPhi, new TGLayoutHints(kLHintsLeft | kLHintsExpandY, 2, 2, 4, 4));
103 f1 = new TGCompositeFrame(compxyz, 50, 200, kVerticalFrame);
104 f1->AddFrame(new TGLabel(f1, "Phi min."), new TGLayoutHints(kLHintsTop | kLHintsLeft, 2, 2, 2, 2));
105 fEPhi1 = new TGNumberEntry(f1, 0., 5, kSPHERE_PHI1);
109 nef->SetToolTipText("Enter the phi1 value");
110 fEPhi1->Associate(this);
111 f1->AddFrame(fEPhi1, new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX, 2, 2, 2, 2));
112
113 fEPhi2 = new TGNumberEntry(f1, 0., 5, kSPHERE_PHI2);
117 nef->SetToolTipText("Enter the phi2 value");
118 fEPhi2->Associate(this);
120 f1->AddFrame(fEPhi2, new TGLayoutHints(kLHintsBottom | kLHintsLeft | kLHintsExpandX, 2, 2, 2, 2));
121 f1->AddFrame(new TGLabel(f1, "Phi max."), new TGLayoutHints(kLHintsBottom | kLHintsLeft, 2, 2, 2, 2));
122 compxyz->AddFrame(f1, new TGLayoutHints(kLHintsLeft | kLHintsExpandX | kLHintsExpandY, 2, 2, 2, 2));
123
124 compxyz->Resize(75,150);
125 f11->AddFrame(compxyz, new TGLayoutHints(kLHintsLeft, 0,0,0,0));
126
127 compxyz = new TGCompositeFrame(f11, 75, 200, kHorizontalFrame | kRaisedFrame);
128 // Vertical slider
129 fSTheta = new TGDoubleVSlider(compxyz,140);
130 fSTheta->SetRange(0.,180.);
131 compxyz->AddFrame(fSTheta, new TGLayoutHints(kLHintsLeft | kLHintsExpandY, 2, 2, 4, 4));
132 f1 = new TGCompositeFrame(compxyz, 50, 200, kVerticalFrame);
133 f1->AddFrame(new TGLabel(f1, "Theta min."), new TGLayoutHints(kLHintsTop | kLHintsLeft, 2, 2, 2, 2));
138 nef->SetToolTipText("Enter the theta1 value");
139 fETheta1->Associate(this);
140 f1->AddFrame(fETheta1, new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX, 2, 2, 2, 2));
141
146 nef->SetToolTipText("Enter the theta2 value");
147 fETheta2->Associate(this);
148 f1->AddFrame(fETheta2, new TGLayoutHints(kLHintsBottom | kLHintsLeft | kLHintsExpandX, 2, 2, 2, 2));
149 f1->AddFrame(new TGLabel(f1, "Theta max."), new TGLayoutHints(kLHintsBottom | kLHintsLeft, 2, 2, 2, 2));
150 compxyz->AddFrame(f1, new TGLayoutHints(kLHintsLeft | kLHintsExpandX | kLHintsExpandY, 2, 2, 2, 2));
151
152 compxyz->Resize(75,150);
153 f11->AddFrame(compxyz, new TGLayoutHints(kLHintsRight, 0, 0, 0, 0));
154
155 AddFrame(f11, new TGLayoutHints(kLHintsLeft, 0, 0, 0, 0));
156
157 // Delayed draw
159 fDelayed = new TGCheckButton(f1, "Delayed draw");
160 f1->AddFrame(fDelayed, new TGLayoutHints(kLHintsLeft , 2, 2, 4, 4));
161 AddFrame(f1, new TGLayoutHints(kLHintsLeft, 6, 6, 4, 4));
162
163 // Buttons
164 f1 = new TGCompositeFrame(this, 155, 10, kHorizontalFrame | kFixedWidth);
165 fApply = new TGTextButton(f1, "Apply");
166 f1->AddFrame(fApply, new TGLayoutHints(kLHintsLeft, 2, 2, 4, 4));
167 fApply->Associate(this);
168 fUndo = new TGTextButton(f1, "Undo");
169 f1->AddFrame(fUndo, new TGLayoutHints(kLHintsRight , 2, 2, 4, 4));
170 fUndo->Associate(this);
171 AddFrame(f1, new TGLayoutHints(kLHintsLeft, 6, 6, 4, 4));
173}
174
175////////////////////////////////////////////////////////////////////////////////
176/// Destructor.
177
179{
180 TGFrameElement *el;
181 TIter next(GetList());
182 while ((el = (TGFrameElement *)next())) {
183 if (el->fFrame->IsComposite())
185 }
186 Cleanup();
187}
188
189////////////////////////////////////////////////////////////////////////////////
190/// Connect signals to slots.
191
193{
194 fApply->Connect("Clicked()", "TGeoSphereEditor", this, "DoApply()");
195 fUndo->Connect("Clicked()", "TGeoSphereEditor", this, "DoUndo()");
196 fShapeName->Connect("TextChanged(const char *)", "TGeoSphereEditor", this, "DoModified()");
197 fERmin->Connect("ValueSet(Long_t)", "TGeoSphereEditor", this, "DoRmin()");
198 fERmax->Connect("ValueSet(Long_t)", "TGeoSphereEditor", this, "DoRmax()");
199 fEPhi1->Connect("ValueSet(Long_t)", "TGeoSphereEditor", this, "DoPhi1()");
200 fEPhi2->Connect("ValueSet(Long_t)", "TGeoSphereEditor", this, "DoPhi2()");
201 fETheta1->Connect("ValueSet(Long_t)", "TGeoSphereEditor", this, "DoTheta1()");
202 fETheta2->Connect("ValueSet(Long_t)", "TGeoSphereEditor", this, "DoTheta2()");
203 fSPhi->Connect("PositionChanged()", "TGeoSphereEditor", this, "DoPhi()");
204 fSTheta->Connect("PositionChanged()", "TGeoSphereEditor", this, "DoTheta()");
205 fInit = kFALSE;
206}
207
208
209////////////////////////////////////////////////////////////////////////////////
210/// Connect to a given sphere.
211
213{
214 if (obj == 0 || (obj->IsA()!=TGeoSphere::Class())) {
216 return;
217 }
218 fShape = (TGeoSphere*)obj;
219 fRmini = fShape->GetRmin();
220 fRmaxi = fShape->GetRmax();
221 fPhi1i = fShape->GetPhi1();
222 fPhi2i = fShape->GetPhi2();
225 fNamei = fShape->GetName();
235
238
240 SetActive();
241}
242
243////////////////////////////////////////////////////////////////////////////////
244/// Check if shape drawing is delayed.
245
247{
248 return (fDelayed->GetState() == kButtonDown);
249}
250
251////////////////////////////////////////////////////////////////////////////////
252/// Slot for name.
253
255{
256 DoModified();
257}
258
259////////////////////////////////////////////////////////////////////////////////
260/// Slot for applying modifications.
261
263{
264 const char *name = fShapeName->GetText();
265 if (strcmp(name,fShape->GetName())) fShape->SetName(name);
266 Double_t rmin = fERmin->GetNumber();
267 Double_t rmax = fERmax->GetNumber();
268 Double_t phi1 = fEPhi1->GetNumber();
269 Double_t phi2 = fEPhi2->GetNumber();
270 if ((phi2-phi1) > 360.001) {
271 phi1 = 0.;
272 phi2 = 360.;
273 fEPhi1->SetNumber(phi1);
274 fEPhi2->SetNumber(phi2);
275 fLock = kTRUE;
276 fSPhi->SetPosition(phi1,phi2);
277 fLock = kFALSE;
278 }
279 Double_t theta1 = fETheta1->GetNumber();
280 Double_t theta2 = fETheta2->GetNumber();
281 fShape->SetSphDimensions(rmin, rmax, theta1,theta2,phi1,phi2);
283 fUndo->SetEnabled();
285 if (fPad) {
287 fShape->Draw();
288 fPad->GetView()->ShowAxis();
289 } else Update();
290 }
291}
292
293////////////////////////////////////////////////////////////////////////////////
294/// Slot for signaling modifications.
295
297{
299}
300
301////////////////////////////////////////////////////////////////////////////////
302/// Slot for undoing last operation.
303
305{
314 DoApply();
317}
318
319////////////////////////////////////////////////////////////////////////////////
320/// Slot for Rmin.
321
323{
324 Double_t rmin = fERmin->GetNumber();
325 Double_t rmax = fERmax->GetNumber();
326 if (rmin <= 0.) {
327 rmin = 0.;
328 fERmin->SetNumber(rmin);
329 }
330 if (rmin >= rmax) {
331 rmin = rmax - 0.1;
332 fERmin->SetNumber(rmin);
333 }
334 DoModified();
335 if (!IsDelayed()) DoApply();
336}
337
338////////////////////////////////////////////////////////////////////////////////
339/// Slot for Rmax.
340
342{
343 Double_t rmin = fERmin->GetNumber();
344 Double_t rmax = fERmax->GetNumber();
345 if (rmax <= 0.) {
346 rmax = 0.1;
347 fERmax->SetNumber(rmax);
348 }
349 if (rmax < rmin+1.e-10) {
350 rmax = rmin + 0.1;
351 fERmax->SetNumber(rmax);
352 }
353 DoModified();
354 if (!IsDelayed()) DoApply();
355}
356
357////////////////////////////////////////////////////////////////////////////////
358/// Slot for phi1.
359
361{
362 Double_t phi1 = fEPhi1->GetNumber();
363 Double_t phi2 = fEPhi2->GetNumber();
364 if (phi1 > 360-1.e-10) {
365 phi1 = 0.;
366 fEPhi1->SetNumber(phi1);
367 }
368 if (phi2<phi1+1.e-10) {
369 phi1 = phi2 - 0.1;
370 fEPhi1->SetNumber(phi1);
371 }
372 if (!fLock) {
373 DoModified();
374 fLock = kTRUE;
375 fSPhi->SetPosition(phi1,phi2);
376 } else fLock = kFALSE;
377 if (!IsDelayed()) DoApply();
378}
379
380////////////////////////////////////////////////////////////////////////////////
381/// Slot for phi2.
382
384{
385 Double_t phi1 = fEPhi1->GetNumber();
386 Double_t phi2 = fEPhi2->GetNumber();
387 if (phi2-phi1 > 360.) {
388 phi2 -= 360.;
389 fEPhi2->SetNumber(phi2);
390 }
391 if (phi2<phi1+1.e-10) {
392 phi2 = phi1 + 0.1;
393 fEPhi2->SetNumber(phi2);
394 }
395 if (!fLock) {
396 DoModified();
397 fLock = kTRUE;
398 fSPhi->SetPosition(phi1,phi2);
399 } else fLock = kFALSE;
400 if (!IsDelayed()) DoApply();
401}
402
403////////////////////////////////////////////////////////////////////////////////
404/// Slot for phi slider.
405
407{
408 if (!fLock) {
409 DoModified();
410 fLock = kTRUE;
412 fLock = kTRUE;
414 } else fLock = kFALSE;
415 if (!IsDelayed()) DoApply();
416}
417
418////////////////////////////////////////////////////////////////////////////////
419/// Slot for theta1.
420
422{
423 Double_t theta1 = fETheta1->GetNumber();
424 Double_t theta2 = fETheta2->GetNumber();
425 if (theta2<theta1+1.e-10) {
426 theta2 = theta1 + 0.1;
427 fETheta2->SetNumber(theta2);
428 }
429 if (!fLock) {
430 DoModified();
431 fLock = kTRUE;
432 fSTheta->SetPosition(theta1,theta2);
433 } else fLock = kFALSE;
434 if (!IsDelayed()) DoApply();
435}
436
437////////////////////////////////////////////////////////////////////////////////
438/// Slot for theta2.
439
441{
442 Double_t theta1 = fETheta1->GetNumber();
443 Double_t theta2 = fETheta2->GetNumber();
444 if (theta2<theta1+1.e-10) {
445 theta1 = theta2 - 0.1;
446 fETheta1->SetNumber(theta1);
447 }
448 if (!fLock) {
449 DoModified();
450 fLock = kTRUE;
451 fSTheta->SetPosition(theta1,theta2);
452 } else fLock = kFALSE;
453 if (!IsDelayed()) DoApply();
454}
455
456////////////////////////////////////////////////////////////////////////////////
457/// Slot for theta slider.
458
460{
461 if (!fLock) {
462 DoModified();
463 fLock = kTRUE;
465 fLock = kTRUE;
467 } else fLock = kFALSE;
468 if (!IsDelayed()) DoApply();
469}
@ kRaisedFrame
Definition GuiTypes.h:384
@ kSunkenFrame
Definition GuiTypes.h:383
@ kVerticalFrame
Definition GuiTypes.h:381
@ kFixedWidth
Definition GuiTypes.h:387
@ kFitWidth
Definition GuiTypes.h:386
@ kHorizontalFrame
Definition GuiTypes.h:382
@ kOwnBackground
Definition GuiTypes.h:391
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
@ kLHintsExpandY
Definition TGLayout.h:31
@ kLHintsLeft
Definition TGLayout.h:24
@ kLHintsBottom
Definition TGLayout.h:29
@ kLHintsTop
Definition TGLayout.h:27
@ kLHintsExpandX
Definition TGLayout.h:30
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
R__EXTERN TGeoManager * gGeoManager
ETGeoSphereWid
@ kSPHERE_UNDO
@ kSPHERE_PHI1
@ kSPHERE_THETA1
@ kSPHERE_APPLY
@ kSPHERE_THETA
@ kSPHERE_NAME
@ kSPHERE_THETA2
@ kSPHERE_PHI2
@ kSPHERE_PHI
@ kSPHERE_RMIN
@ kSPHERE_RMAX
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
virtual Float_t GetMaxPosition() const
virtual Float_t GetMinPosition() const
virtual void SetRange(Float_t min, Float_t max)
virtual void SetPosition(Float_t min, Float_t max)
Dragging the slider will generate the event:
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
@ kNEANonNegative
Non-negative 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
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.
TVirtualGeoPainter * GetPainter() const
virtual const char * GetName() const
Get the shape name.
virtual void Draw(Option_t *option="")
Draw this shape.
Editor for a TGeoSphere.
TGNumberEntry * fEPhi2
virtual ~TGeoSphereEditor()
Destructor.
TGCheckButton * fDelayed
virtual void ConnectSignals2Slots()
Connect signals to slots.
TGeoSphereEditor(const TGWindow *p=nullptr, Int_t width=140, Int_t height=30, UInt_t options=kChildFrame, Pixel_t back=GetDefaultFrameBackground())
Constructor for sphere editor.
TGNumberEntry * fERmax
void DoTheta1()
Slot for theta1.
void DoRmin()
Slot for Rmin.
TGNumberEntry * fETheta1
TGNumberEntry * fETheta2
virtual void SetModel(TObject *obj)
Connect to a given sphere.
void DoName()
Slot for name.
TGNumberEntry * fERmin
void DoPhi2()
Slot for phi2.
TGDoubleVSlider * fSPhi
Bool_t IsDelayed() const
Check if shape drawing is delayed.
void DoTheta()
Slot for theta slider.
void DoModified()
Slot for signaling modifications.
void DoTheta2()
Slot for theta2.
TGTextEntry * fShapeName
void DoPhi()
Slot for phi slider.
TGeoSphere * fShape
TGNumberEntry * fEPhi1
TGDoubleVSlider * fSTheta
void DoPhi1()
Slot for phi1.
void DoRmax()
Slot for Rmax.
virtual void DoUndo()
Slot for undoing last operation.
TGTextButton * fUndo
virtual void DoApply()
Slot for applying modifications.
TGTextButton * fApply
TGeoSphere are not just balls having internal and external radii, but sectors of a sphere having defi...
Definition TGeoSphere.h:18
Double_t GetPhi1() const
Definition TGeoSphere.h:74
void SetSphDimensions(Double_t rmin, Double_t rmax, Double_t theta1, Double_t theta2, Double_t phi1, Double_t phi2)
Set spherical segment dimensions.
Double_t GetPhi2() const
Definition TGeoSphere.h:75
virtual Double_t GetRmin() const
Definition TGeoSphere.h:70
virtual void ComputeBBox()
compute bounding box of the sphere
Double_t GetTheta2() const
Definition TGeoSphere.h:73
virtual Double_t GetRmax() const
Definition TGeoSphere.h:71
Double_t GetTheta1() const
Definition TGeoSphere.h:72
static TClass * Class()
static void Cleanup(TGCompositeFrame *frame)
Static method to cleanup hierarchically all daughters of a composite frame.
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 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
virtual void ShowAxis()=0
virtual Bool_t IsPaintingShape() const =0
virtual TView * GetView() const =0
TF1 * f1
Definition legend1.C:11