Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
TGeoTorusEditor.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 TGeoTorusEditor
13 \ingroup Geometry_builder
14 
15 Editor for a TGeoTorus.
16 
17 \image html geom_torus_pic.png
18 
19 \image html geom_torus_ed.png
20 
21 */
22 
23 #include "TGeoTorusEditor.h"
24 #include "TGeoTabManager.h"
25 #include "TGeoTorus.h"
26 #include "TGeoManager.h"
27 #include "TVirtualGeoPainter.h"
28 #include "TPad.h"
29 #include "TView.h"
30 #include "TGTab.h"
31 #include "TGComboBox.h"
32 #include "TGButton.h"
33 #include "TGTextEntry.h"
34 #include "TGNumberEntry.h"
35 #include "TGLabel.h"
36 
37 ClassImp(TGeoTorusEditor);
38 
39 enum ETGeoTorusWid {
40  kTORUS_NAME, kTORUS_R, kTORUS_RMIN, kTORUS_RMAX, kTORUS_PHI1,
41  kTORUS_DPHI, kTORUS_APPLY, kTORUS_UNDO
42 };
43 
44 ////////////////////////////////////////////////////////////////////////////////
45 /// Constructor for torus editor
46 
47 TGeoTorusEditor::TGeoTorusEditor(const TGWindow *p, Int_t width,
48  Int_t height, UInt_t options, Pixel_t back)
49  : TGeoGedFrame(p, width, height, options | kVerticalFrame, back)
50 {
51  fShape = 0;
52  fRi = fRmini = fRmaxi = fPhi1i = fDphii = 0.0;
53  fNamei = "";
54  fIsModified = kFALSE;
55  fIsShapeEditable = kTRUE;
56 
57  // TextEntry for shape name
58  MakeTitle("Name");
59  fShapeName = new TGTextEntry(this, new TGTextBuffer(50), kTORUS_NAME);
60  fShapeName->Resize(135, fShapeName->GetDefaultHeight());
61  fShapeName->SetToolTipText("Enter the torus name");
62  fShapeName->Associate(this);
63  AddFrame(fShapeName, new TGLayoutHints(kLHintsLeft, 3, 1, 2, 5));
64 
65  TGTextEntry *nef;
66  MakeTitle("Dimensions");
67  // Number entry for R.
68  TGCompositeFrame *f1 = new TGCompositeFrame(this, 155, 10, kHorizontalFrame | kFixedWidth);
69  f1->AddFrame(new TGLabel(f1, "R"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
70  fER = new TGNumberEntry(f1, 0., 5, kTORUS_R);
71  fER->SetNumAttr(TGNumberFormat::kNEAPositive);
72  fER->Resize(100, fER->GetDefaultHeight());
73  nef = (TGTextEntry*)fER->GetNumberEntry();
74  nef->SetToolTipText("Enter the axial radius R");
75  fER->Associate(this);
76  f1->AddFrame(fER, new TGLayoutHints(kLHintsRight, 2, 2, 4, 4));
77  AddFrame(f1, new TGLayoutHints(kLHintsLeft, 2, 2, 4, 4));
78 
79  // Number entry for rmin.
80  f1 = new TGCompositeFrame(this, 155, 10, kHorizontalFrame | kFixedWidth);
81  f1->AddFrame(new TGLabel(f1, "Rmin"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
82  fERmin = new TGNumberEntry(f1, 0., 5, kTORUS_RMIN);
83  fERmin->SetNumAttr(TGNumberFormat::kNEAPositive);
84  fERmin->Resize(100, fERmin->GetDefaultHeight());
85  nef = (TGTextEntry*)fERmin->GetNumberEntry();
86  nef->SetToolTipText("Enter the inner radius Rmin");
87  fERmin->Associate(this);
88  f1->AddFrame(fERmin, new TGLayoutHints(kLHintsRight, 2, 2, 4, 4));
89  AddFrame(f1, new TGLayoutHints(kLHintsLeft, 2, 2, 4, 4));
90 
91  // Number entry for rmax
92  f1 = new TGCompositeFrame(this, 155, 10, kHorizontalFrame | kFixedWidth);
93  f1->AddFrame(new TGLabel(f1, "Rmax"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
94  fERmax = new TGNumberEntry(f1, 0., 5, kTORUS_RMAX);
95  fERmax->SetNumAttr(TGNumberFormat::kNEAPositive);
96  fERmax->Resize(100, fERmax->GetDefaultHeight());
97  nef = (TGTextEntry*)fERmax->GetNumberEntry();
98  nef->SetToolTipText("Enter the outer radius Rmax");
99  fERmax->Associate(this);
100  f1->AddFrame(fERmax, new TGLayoutHints(kLHintsRight, 2, 2, 4, 4));
101  AddFrame(f1, new TGLayoutHints(kLHintsLeft, 2, 2, 4, 4));
102 
103  // Number entry for Phi1
104  f1 = new TGCompositeFrame(this, 155, 10, kHorizontalFrame | kFixedWidth);
105  f1->AddFrame(new TGLabel(f1, "Phi1"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
106  fEPhi1 = new TGNumberEntry(f1, 0., 5, kTORUS_PHI1);
107  fEPhi1->SetNumAttr(TGNumberFormat::kNEANonNegative);
108  fEPhi1->Resize(100, fEPhi1->GetDefaultHeight());
109  nef = (TGTextEntry*)fEPhi1->GetNumberEntry();
110  nef->SetToolTipText("Enter the starting phi angle[deg]");
111  fEPhi1->Associate(this);
112  f1->AddFrame(fEPhi1, new TGLayoutHints(kLHintsRight, 2, 2, 4, 4));
113  AddFrame(f1, new TGLayoutHints(kLHintsLeft, 2, 2, 4, 4));
114 
115  // Number entry for Dphi
116  f1 = new TGCompositeFrame(this, 155, 10, kHorizontalFrame | kFixedWidth);
117  f1->AddFrame(new TGLabel(f1, "Dphi"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
118  fEDphi = new TGNumberEntry(f1, 0., 5, kTORUS_DPHI);
119  fEDphi->SetNumAttr(TGNumberFormat::kNEAPositive);
120  fEDphi->Resize(100, fEDphi->GetDefaultHeight());
121  nef = (TGTextEntry*)fEDphi->GetNumberEntry();
122  nef->SetToolTipText("Enter the extent phi Dphi [deg]");
123  fEDphi->Associate(this);
124  f1->AddFrame(fEDphi, new TGLayoutHints(kLHintsRight, 2, 2, 4, 4));
125  AddFrame(f1, new TGLayoutHints(kLHintsLeft, 2, 2, 4, 4));
126 
127  // Delayed draw
128  f1 = new TGCompositeFrame(this, 155, 10, kHorizontalFrame | kFixedWidth | kSunkenFrame);
129  fDelayed = new TGCheckButton(f1, "Delayed draw");
130  f1->AddFrame(fDelayed, new TGLayoutHints(kLHintsLeft , 2, 2, 4, 4));
131  AddFrame(f1, new TGLayoutHints(kLHintsLeft, 6, 6, 4, 4));
132 
133  // Buttons
134  f1 = new TGCompositeFrame(this, 155, 10, kHorizontalFrame | kFixedWidth);
135  fApply = new TGTextButton(f1, "Apply");
136  f1->AddFrame(fApply, new TGLayoutHints(kLHintsLeft, 2, 2, 4, 4));
137  fApply->Associate(this);
138  fUndo = new TGTextButton(f1, "Undo");
139  f1->AddFrame(fUndo, new TGLayoutHints(kLHintsRight , 2, 2, 4, 4));
140  fUndo->Associate(this);
141  AddFrame(f1, new TGLayoutHints(kLHintsLeft, 6, 6, 4, 4));
142  fUndo->SetSize(fApply->GetSize());
143 }
144 
145 ////////////////////////////////////////////////////////////////////////////////
146 /// Destructor
147 
148 TGeoTorusEditor::~TGeoTorusEditor()
149 {
150  TGFrameElement *el;
151  TIter next(GetList());
152  while ((el = (TGFrameElement *)next())) {
153  if (el->fFrame->IsComposite())
154  TGeoTabManager::Cleanup((TGCompositeFrame*)el->fFrame);
155  }
156  Cleanup();
157 }
158 
159 ////////////////////////////////////////////////////////////////////////////////
160 /// Connect signals to slots.
161 
162 void TGeoTorusEditor::ConnectSignals2Slots()
163 {
164  fApply->Connect("Clicked()", "TGeoTorusEditor", this, "DoApply()");
165  fUndo->Connect("Clicked()", "TGeoTorusEditor", this, "DoUndo()");
166  fShapeName->Connect("TextChanged(const char *)", "TGeoTorusEditor", this, "DoModified()");
167  fER->Connect("ValueSet(Long_t)", "TGeoTorusEditor", this, "DoR()");
168  fERmin->Connect("ValueSet(Long_t)", "TGeoTorusEditor", this, "DoRmin()");
169  fERmax->Connect("ValueSet(Long_t)", "TGeoTorusEditor", this, "DoRmax()");
170  fEPhi1->Connect("ValueSet(Long_t)", "TGeoTorusEditor", this, "DoPhi1()");
171  fEDphi->Connect("ValueSet(Long_t)", "TGeoTorusEditor", this, "DoDphi()");
172  fER->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoTorusEditor", this, "DoModified()");
173  fERmin->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoTorusEditor", this, "DoModified()");
174  fERmax->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoTorusEditor", this, "DoModified()");
175  fEPhi1->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoTorusEditor", this, "DoModified()");
176  fEDphi->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoTorusEditor", this, "DoModified()");
177  fInit = kFALSE;
178 }
179 
180 
181 ////////////////////////////////////////////////////////////////////////////////
182 /// Connect to the selected object.
183 
184 void TGeoTorusEditor::SetModel(TObject* obj)
185 {
186  if (obj == 0 || (obj->IsA()!=TGeoTorus::Class())) {
187  SetActive(kFALSE);
188  return;
189  }
190  fShape = (TGeoTorus*)obj;
191  fRi = fShape->GetR();
192  fRmini = fShape->GetRmin();
193  fRmaxi = fShape->GetRmax();
194  fPhi1i = fShape->GetPhi1();
195  fDphii = fShape->GetDphi();
196  const char *sname = fShape->GetName();
197  if (!strcmp(sname, fShape->ClassName())) fShapeName->SetText("-no_name");
198  else {
199  fShapeName->SetText(sname);
200  fNamei = sname;
201  }
202  fER->SetNumber(fRi);
203  fERmin->SetNumber(fRmini);
204  fERmax->SetNumber(fRmaxi);
205  fEPhi1->SetNumber(fPhi1i);
206  fEDphi->SetNumber(fDphii);
207  fApply->SetEnabled(kFALSE);
208  fUndo->SetEnabled(kFALSE);
209 
210  if (fInit) ConnectSignals2Slots();
211  SetActive();
212 }
213 
214 ////////////////////////////////////////////////////////////////////////////////
215 /// Check if shape drawing is delayed.
216 
217 Bool_t TGeoTorusEditor::IsDelayed() const
218 {
219  return (fDelayed->GetState() == kButtonDown);
220 }
221 
222 ////////////////////////////////////////////////////////////////////////////////
223 /// Slot for name.
224 
225 void TGeoTorusEditor::DoName()
226 {
227  DoModified();
228 }
229 
230 ////////////////////////////////////////////////////////////////////////////////
231 /// Slot for applying current settings.
232 
233 void TGeoTorusEditor::DoApply()
234 {
235  const char *name = fShapeName->GetText();
236  if (strcmp(name,fShape->GetName())) fShape->SetName(name);
237  Double_t r = fER->GetNumber();
238  Double_t rmax = fERmax->GetNumber();
239  Double_t rmin = fERmin->GetNumber();
240  Double_t phi = fEPhi1->GetNumber();
241  Double_t dphi = fEDphi->GetNumber();
242  Double_t param[5];
243  param[0] = r;
244  param[1] = rmin;
245  param[2] = rmax;
246  param[3] = phi;
247  param[4] = dphi;
248  fShape->SetDimensions(param);
249  fShape->ComputeBBox();
250  fUndo->SetEnabled();
251  fApply->SetEnabled(kFALSE);
252  if (fPad) {
253  if (gGeoManager && gGeoManager->GetPainter() && gGeoManager->GetPainter()->IsPaintingShape()) {
254  TView *view = fPad->GetView();
255  if (!view) {
256  fShape->Draw();
257  fPad->GetView()->ShowAxis();
258  } else {
259  view->SetRange(-fShape->GetDX(), -fShape->GetDY(), -fShape->GetDZ(),
260  fShape->GetDX(), fShape->GetDY(), fShape->GetDZ());
261  Update();
262  }
263  } else Update();
264  }
265 }
266 
267 ////////////////////////////////////////////////////////////////////////////////
268 /// Slot for notifying modifications.
269 
270 void TGeoTorusEditor::DoModified()
271 {
272  fApply->SetEnabled();
273 }
274 
275 ////////////////////////////////////////////////////////////////////////////////
276 /// Slot for undoing last operation.
277 
278 void TGeoTorusEditor::DoUndo()
279 {
280  fER->SetNumber(fRi);
281  fERmin->SetNumber(fRmini);
282  fERmax->SetNumber(fRmaxi);
283  fEPhi1->SetNumber(fPhi1i);
284  fEDphi->SetNumber(fDphii);
285  DoApply();
286  fUndo->SetEnabled(kFALSE);
287  fApply->SetEnabled(kFALSE);
288 }
289 
290 ////////////////////////////////////////////////////////////////////////////////
291 /// Slot for R.
292 
293 void TGeoTorusEditor::DoR()
294 {
295  Double_t r = fER->GetNumber();
296  Double_t rmax = fERmax->GetNumber();
297  if (r<rmax) {
298  r = rmax;
299  fER->SetNumber(r);
300  }
301  DoModified();
302  if (!IsDelayed()) DoApply();
303 }
304 
305 ////////////////////////////////////////////////////////////////////////////////
306 /// Slot for Rmin.
307 
308 void TGeoTorusEditor::DoRmin()
309 {
310  Double_t rmin = fERmin->GetNumber();
311  Double_t rmax = fERmax->GetNumber();
312  if (rmin>rmax) {
313  rmin = rmax-0.1;
314  fERmin->SetNumber(rmin);
315  }
316  DoModified();
317  if (!IsDelayed()) DoApply();
318 }
319 
320 ////////////////////////////////////////////////////////////////////////////////
321 /// Slot for Rmax.
322 
323 void TGeoTorusEditor::DoRmax()
324 {
325  Double_t r = fER->GetNumber();
326  Double_t rmin = fERmin->GetNumber();
327  Double_t rmax = fERmax->GetNumber();
328  if (rmax<=rmin) {
329  rmax = rmin+0.1;
330  fERmax->SetNumber(rmax);
331  }
332  if (rmax>r) {
333  rmax = r;
334  fERmax->SetNumber(rmax);
335  }
336  DoModified();
337  if (!IsDelayed()) DoApply();
338 }
339 
340 ////////////////////////////////////////////////////////////////////////////////
341 /// Slot for phi.
342 
343 void TGeoTorusEditor::DoPhi1()
344 {
345  Double_t phi = fEPhi1->GetNumber();
346  if (phi<0 || phi>360) {
347  phi = 0;
348  fEPhi1->SetNumber(phi);
349  }
350  DoModified();
351  if (!IsDelayed()) DoApply();
352 }
353 
354 ////////////////////////////////////////////////////////////////////////////////
355 /// Slot for Dphi.
356 
357 void TGeoTorusEditor::DoDphi()
358 {
359  Double_t dphi = fEDphi->GetNumber();
360  if (dphi<=0 || dphi>360) {
361  dphi = 1;
362  fEDphi->SetNumber(dphi);
363  }
364  DoModified();
365  if (!IsDelayed()) DoApply();
366 }
367