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
50};
51
52////////////////////////////////////////////////////////////////////////////////
53/// Constructor for sphere editor
54
56 : TGeoGedFrame(p, width, height, options | kVerticalFrame, back)
57{
58 fShape = nullptr;
60 fNamei = "";
63 fLock = kFALSE;
64
65 // TextEntry for shape name
66 MakeTitle("Name");
67 fShapeName = new TGTextEntry(this, new TGTextBuffer(50), kSPHERE_NAME);
69 fShapeName->SetToolTipText("Enter the sphere name");
70 fShapeName->Associate(this);
72
73 TGTextEntry *nef;
74 MakeTitle("Sphere dimensions");
75 TGCompositeFrame *compxyz = new TGCompositeFrame(this, 118, 30, kVerticalFrame | kRaisedFrame);
76 // Number entry for rmin
78 f1->AddFrame(new TGLabel(f1, "Rmin"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
79 fERmin = new TGNumberEntry(f1, 0., 5, kSPHERE_RMIN);
82 nef->SetToolTipText("Enter the inner radius");
83 fERmin->Associate(this);
85 f1->AddFrame(fERmin, new TGLayoutHints(kLHintsRight, 2, 2, 4, 4));
86 compxyz->AddFrame(f1, new TGLayoutHints(kLHintsLeft | kLHintsExpandX, 2, 2, 4, 4));
87
88 // Number entry for Rmax
89 f1 = new TGCompositeFrame(compxyz, 118, 10, kHorizontalFrame | kFitWidth | kOwnBackground);
90 f1->AddFrame(new TGLabel(f1, "Rmax"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
91 fERmax = new TGNumberEntry(f1, 0., 5, kSPHERE_RMAX);
94 nef->SetToolTipText("Enter the outer radius");
95 fERmax->Associate(this);
97 f1->AddFrame(fERmax, new TGLayoutHints(kLHintsRight, 2, 2, 4, 4));
98 compxyz->AddFrame(f1, new TGLayoutHints(kLHintsLeft | kLHintsExpandX, 2, 2, 4, 4));
99 AddFrame(compxyz, new TGLayoutHints(kLHintsLeft, 2, 2, 2, 2));
100
101 MakeTitle("Phi/theta range");
102 TGCompositeFrame *f11 = new TGCompositeFrame(this, 150, 200, kHorizontalFrame);
103 compxyz = new TGCompositeFrame(f11, 75, 200, kHorizontalFrame | kRaisedFrame);
104 // Vertical slider
105 fSPhi = new TGDoubleVSlider(compxyz, 140);
106 fSPhi->SetRange(0., 720.);
107 compxyz->AddFrame(fSPhi, new TGLayoutHints(kLHintsLeft | kLHintsExpandY, 2, 2, 4, 4));
108 f1 = new TGCompositeFrame(compxyz, 50, 200, kVerticalFrame);
109 f1->AddFrame(new TGLabel(f1, "Phi min."), new TGLayoutHints(kLHintsTop | kLHintsLeft, 2, 2, 2, 2));
110 fEPhi1 = new TGNumberEntry(f1, 0., 5, kSPHERE_PHI1);
114 nef->SetToolTipText("Enter the phi1 value");
115 fEPhi1->Associate(this);
116 f1->AddFrame(fEPhi1, new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX, 2, 2, 2, 2));
117
118 fEPhi2 = new TGNumberEntry(f1, 0., 5, kSPHERE_PHI2);
122 nef->SetToolTipText("Enter the phi2 value");
123 fEPhi2->Associate(this);
125 f1->AddFrame(fEPhi2, new TGLayoutHints(kLHintsBottom | kLHintsLeft | kLHintsExpandX, 2, 2, 2, 2));
126 f1->AddFrame(new TGLabel(f1, "Phi max."), new TGLayoutHints(kLHintsBottom | kLHintsLeft, 2, 2, 2, 2));
127 compxyz->AddFrame(f1, new TGLayoutHints(kLHintsLeft | kLHintsExpandX | kLHintsExpandY, 2, 2, 2, 2));
128
129 compxyz->Resize(75, 150);
130 f11->AddFrame(compxyz, new TGLayoutHints(kLHintsLeft, 0, 0, 0, 0));
131
132 compxyz = new TGCompositeFrame(f11, 75, 200, kHorizontalFrame | kRaisedFrame);
133 // Vertical slider
134 fSTheta = new TGDoubleVSlider(compxyz, 140);
135 fSTheta->SetRange(0., 180.);
136 compxyz->AddFrame(fSTheta, new TGLayoutHints(kLHintsLeft | kLHintsExpandY, 2, 2, 4, 4));
137 f1 = new TGCompositeFrame(compxyz, 50, 200, kVerticalFrame);
138 f1->AddFrame(new TGLabel(f1, "Theta min."), new TGLayoutHints(kLHintsTop | kLHintsLeft, 2, 2, 2, 2));
143 nef->SetToolTipText("Enter the theta1 value");
144 fETheta1->Associate(this);
145 f1->AddFrame(fETheta1, new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX, 2, 2, 2, 2));
146
151 nef->SetToolTipText("Enter the theta2 value");
152 fETheta2->Associate(this);
153 f1->AddFrame(fETheta2, new TGLayoutHints(kLHintsBottom | kLHintsLeft | kLHintsExpandX, 2, 2, 2, 2));
154 f1->AddFrame(new TGLabel(f1, "Theta max."), new TGLayoutHints(kLHintsBottom | kLHintsLeft, 2, 2, 2, 2));
155 compxyz->AddFrame(f1, new TGLayoutHints(kLHintsLeft | kLHintsExpandX | kLHintsExpandY, 2, 2, 2, 2));
156
157 compxyz->Resize(75, 150);
158 f11->AddFrame(compxyz, new TGLayoutHints(kLHintsRight, 0, 0, 0, 0));
159
160 AddFrame(f11, new TGLayoutHints(kLHintsLeft, 0, 0, 0, 0));
161
162 // Delayed draw
164 fDelayed = new TGCheckButton(f1, "Delayed draw");
165 f1->AddFrame(fDelayed, new TGLayoutHints(kLHintsLeft, 2, 2, 4, 4));
166 AddFrame(f1, new TGLayoutHints(kLHintsLeft, 6, 6, 4, 4));
167
168 // Buttons
169 f1 = new TGCompositeFrame(this, 155, 10, kHorizontalFrame | kFixedWidth);
170 fApply = new TGTextButton(f1, "Apply");
171 f1->AddFrame(fApply, new TGLayoutHints(kLHintsLeft, 2, 2, 4, 4));
172 fApply->Associate(this);
173 fUndo = new TGTextButton(f1, "Undo");
174 f1->AddFrame(fUndo, new TGLayoutHints(kLHintsRight, 2, 2, 4, 4));
175 fUndo->Associate(this);
176 AddFrame(f1, new TGLayoutHints(kLHintsLeft, 6, 6, 4, 4));
178}
179
180////////////////////////////////////////////////////////////////////////////////
181/// Destructor.
182
184{
185 TGFrameElement *el;
186 TIter next(GetList());
187 while ((el = (TGFrameElement *)next())) {
188 if (el->fFrame->IsComposite())
190 }
191 Cleanup();
192}
193
194////////////////////////////////////////////////////////////////////////////////
195/// Connect signals to slots.
196
198{
199 fApply->Connect("Clicked()", "TGeoSphereEditor", this, "DoApply()");
200 fUndo->Connect("Clicked()", "TGeoSphereEditor", this, "DoUndo()");
201 fShapeName->Connect("TextChanged(const char *)", "TGeoSphereEditor", this, "DoModified()");
202 fERmin->Connect("ValueSet(Long_t)", "TGeoSphereEditor", this, "DoRmin()");
203 fERmax->Connect("ValueSet(Long_t)", "TGeoSphereEditor", this, "DoRmax()");
204 fEPhi1->Connect("ValueSet(Long_t)", "TGeoSphereEditor", this, "DoPhi1()");
205 fEPhi2->Connect("ValueSet(Long_t)", "TGeoSphereEditor", this, "DoPhi2()");
206 fETheta1->Connect("ValueSet(Long_t)", "TGeoSphereEditor", this, "DoTheta1()");
207 fETheta2->Connect("ValueSet(Long_t)", "TGeoSphereEditor", this, "DoTheta2()");
208 fSPhi->Connect("PositionChanged()", "TGeoSphereEditor", this, "DoPhi()");
209 fSTheta->Connect("PositionChanged()", "TGeoSphereEditor", this, "DoTheta()");
210 fInit = kFALSE;
211}
212
213////////////////////////////////////////////////////////////////////////////////
214/// Connect to a given sphere.
215
217{
218 if (obj == nullptr || (obj->IsA() != TGeoSphere::Class())) {
220 return;
221 }
222 fShape = (TGeoSphere *)obj;
223 fRmini = fShape->GetRmin();
224 fRmaxi = fShape->GetRmax();
225 fPhi1i = fShape->GetPhi1();
226 fPhi2i = fShape->GetPhi2();
229 fNamei = fShape->GetName();
239
242
243 if (fInit)
245 SetActive();
246}
247
248////////////////////////////////////////////////////////////////////////////////
249/// Check if shape drawing is delayed.
250
252{
253 return (fDelayed->GetState() == kButtonDown);
254}
255
256////////////////////////////////////////////////////////////////////////////////
257/// Slot for name.
258
260{
261 DoModified();
262}
263
264////////////////////////////////////////////////////////////////////////////////
265/// Slot for applying modifications.
266
268{
269 const char *name = fShapeName->GetText();
270 if (strcmp(name, fShape->GetName()))
272 Double_t rmin = fERmin->GetNumber();
273 Double_t rmax = fERmax->GetNumber();
274 Double_t phi1 = fEPhi1->GetNumber();
275 Double_t phi2 = fEPhi2->GetNumber();
276 if ((phi2 - phi1) > 360.001) {
277 phi1 = 0.;
278 phi2 = 360.;
279 fEPhi1->SetNumber(phi1);
280 fEPhi2->SetNumber(phi2);
281 fLock = kTRUE;
282 fSPhi->SetPosition(phi1, phi2);
283 fLock = kFALSE;
284 }
285 Double_t theta1 = fETheta1->GetNumber();
286 Double_t theta2 = fETheta2->GetNumber();
287 fShape->SetSphDimensions(rmin, rmax, theta1, theta2, phi1, phi2);
289 fUndo->SetEnabled();
291 if (fPad) {
293 fShape->Draw();
294 fPad->GetView()->ShowAxis();
295 } else
296 Update();
297 }
298}
299
300////////////////////////////////////////////////////////////////////////////////
301/// Slot for signaling modifications.
302
304{
306}
307
308////////////////////////////////////////////////////////////////////////////////
309/// Slot for undoing last operation.
310
312{
321 DoApply();
324}
325
326////////////////////////////////////////////////////////////////////////////////
327/// Slot for Rmin.
328
330{
331 Double_t rmin = fERmin->GetNumber();
332 Double_t rmax = fERmax->GetNumber();
333 if (rmin <= 0.) {
334 rmin = 0.;
335 fERmin->SetNumber(rmin);
336 }
337 if (rmin >= rmax) {
338 rmin = rmax - 0.1;
339 fERmin->SetNumber(rmin);
340 }
341 DoModified();
342 if (!IsDelayed())
343 DoApply();
344}
345
346////////////////////////////////////////////////////////////////////////////////
347/// Slot for Rmax.
348
350{
351 Double_t rmin = fERmin->GetNumber();
352 Double_t rmax = fERmax->GetNumber();
353 if (rmax <= 0.) {
354 rmax = 0.1;
355 fERmax->SetNumber(rmax);
356 }
357 if (rmax < rmin + 1.e-10) {
358 rmax = rmin + 0.1;
359 fERmax->SetNumber(rmax);
360 }
361 DoModified();
362 if (!IsDelayed())
363 DoApply();
364}
365
366////////////////////////////////////////////////////////////////////////////////
367/// Slot for phi1.
368
370{
371 Double_t phi1 = fEPhi1->GetNumber();
372 Double_t phi2 = fEPhi2->GetNumber();
373 if (phi1 > 360 - 1.e-10) {
374 phi1 = 0.;
375 fEPhi1->SetNumber(phi1);
376 }
377 if (phi2 < phi1 + 1.e-10) {
378 phi1 = phi2 - 0.1;
379 fEPhi1->SetNumber(phi1);
380 }
381 if (!fLock) {
382 DoModified();
383 fLock = kTRUE;
384 fSPhi->SetPosition(phi1, phi2);
385 } else
386 fLock = kFALSE;
387 if (!IsDelayed())
388 DoApply();
389}
390
391////////////////////////////////////////////////////////////////////////////////
392/// Slot for phi2.
393
395{
396 Double_t phi1 = fEPhi1->GetNumber();
397 Double_t phi2 = fEPhi2->GetNumber();
398 if (phi2 - phi1 > 360.) {
399 phi2 -= 360.;
400 fEPhi2->SetNumber(phi2);
401 }
402 if (phi2 < phi1 + 1.e-10) {
403 phi2 = phi1 + 0.1;
404 fEPhi2->SetNumber(phi2);
405 }
406 if (!fLock) {
407 DoModified();
408 fLock = kTRUE;
409 fSPhi->SetPosition(phi1, phi2);
410 } else
411 fLock = kFALSE;
412 if (!IsDelayed())
413 DoApply();
414}
415
416////////////////////////////////////////////////////////////////////////////////
417/// Slot for phi slider.
418
420{
421 if (!fLock) {
422 DoModified();
423 fLock = kTRUE;
425 fLock = kTRUE;
427 } else
428 fLock = kFALSE;
429 if (!IsDelayed())
430 DoApply();
431}
432
433////////////////////////////////////////////////////////////////////////////////
434/// Slot for theta1.
435
437{
438 Double_t theta1 = fETheta1->GetNumber();
439 Double_t theta2 = fETheta2->GetNumber();
440 if (theta2 < theta1 + 1.e-10) {
441 theta2 = theta1 + 0.1;
442 fETheta2->SetNumber(theta2);
443 }
444 if (!fLock) {
445 DoModified();
446 fLock = kTRUE;
447 fSTheta->SetPosition(theta1, theta2);
448 } else
449 fLock = kFALSE;
450 if (!IsDelayed())
451 DoApply();
452}
453
454////////////////////////////////////////////////////////////////////////////////
455/// Slot for theta2.
456
458{
459 Double_t theta1 = fETheta1->GetNumber();
460 Double_t theta2 = fETheta2->GetNumber();
461 if (theta2 < theta1 + 1.e-10) {
462 theta1 = theta2 - 0.1;
463 fETheta1->SetNumber(theta1);
464 }
465 if (!fLock) {
466 DoModified();
467 fLock = kTRUE;
468 fSTheta->SetPosition(theta1, theta2);
469 } else
470 fLock = kFALSE;
471 if (!IsDelayed())
472 DoApply();
473}
474
475////////////////////////////////////////////////////////////////////////////////
476/// Slot for theta slider.
477
479{
480 if (!fLock) {
481 DoModified();
482 fLock = kTRUE;
484 fLock = kTRUE;
486 } else
487 fLock = kFALSE;
488 if (!IsDelayed())
489 DoApply();
490}
@ 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.
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.
TVirtualGeoPainter * GetPainter() const
void Draw(Option_t *option="") override
Draw this shape.
const char * GetName() const override
Get the shape name.
Editor for a TGeoSphere.
TGNumberEntry * fEPhi2
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
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
void SetModel(TObject *obj) override
Connect to a given sphere.
TGNumberEntry * fEPhi1
TGDoubleVSlider * fSTheta
void DoPhi1()
Slot for phi1.
void DoRmax()
Slot for Rmax.
virtual void DoUndo()
Slot for undoing last operation.
TGTextButton * fUndo
~TGeoSphereEditor() override
Destructor.
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:17
Double_t GetPhi1() const
Definition TGeoSphere.h:76
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:77
virtual Double_t GetRmin() const
Definition TGeoSphere.h:72
void ComputeBBox() override
compute bounding box of the sphere
Double_t GetTheta2() const
Definition TGeoSphere.h:75
virtual Double_t GetRmax() const
Definition TGeoSphere.h:73
Double_t GetTheta1() const
Definition TGeoSphere.h:74
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