Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
TGeoTrapEditor.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 TGeoTrapEditor
13 \ingroup Geometry_builder
14 
15 Editor for a TGeoTrap.
16 
17 \image html geom_trap_pic.png
18 
19 \image html geom_trap_ed.png
20 
21 */
22 
23 #include "TGeoTrapEditor.h"
24 #include "TGeoTabManager.h"
25 #include "TGeoArb8.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(TGeoTrapEditor);
38 
39 enum ETGeoTrapWid {
40  kTRAP_NAME, kTRAP_H1, kTRAP_BL1, kTRAP_TL1, kTRAP_DZ, kTRAP_ALPHA1,
41  kTRAP_SC1, kTRAP_SC2, kTRAP_THETA, kTRAP_PHI, kTRAP_APPLY, kTRAP_UNDO
42 };
43 
44 ////////////////////////////////////////////////////////////////////////////////
45 /// Constructor for para editor
46 
47 TGeoTrapEditor::TGeoTrapEditor(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  fH1i = fBl1i = fTl1i = fDzi = fAlpha1i = fThetai = fPhii = fSci = 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), kTRAP_NAME);
60  fShapeName->Resize(135, fShapeName->GetDefaultHeight());
61  fShapeName->SetToolTipText("Enter the parallelepiped 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 H1
68  TGCompositeFrame *f1 = new TGCompositeFrame(this, 155, 10, kHorizontalFrame | kFixedWidth);
69  f1->AddFrame(new TGLabel(f1, "DY"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
70  fEH1 = new TGNumberEntry(f1, 0., 5, kTRAP_H1);
71  fEH1->SetNumAttr(TGNumberFormat::kNEAPositive);
72  fEH1->Resize(100, fEH1->GetDefaultHeight());
73  nef = (TGTextEntry*)fEH1->GetNumberEntry();
74  nef->SetToolTipText("Enter the half length in y at low z");
75  fEH1->Associate(this);
76  f1->AddFrame(fEH1, new TGLayoutHints(kLHintsRight, 2, 2, 4, 4));
77  AddFrame(f1, new TGLayoutHints(kLHintsLeft, 2, 2, 4, 4));
78 
79  // Number entry for Bl1
80  f1 = new TGCompositeFrame(this, 155, 10, kHorizontalFrame | kFixedWidth);
81  f1->AddFrame(new TGLabel(f1, "DX1"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
82  fEBl1 = new TGNumberEntry(f1, 0., 5, kTRAP_BL1);
83  fEBl1->SetNumAttr(TGNumberFormat::kNEAPositive);
84  fEBl1->Resize(100, fEBl1->GetDefaultHeight());
85  nef = (TGTextEntry*)fEBl1->GetNumberEntry();
86  nef->SetToolTipText("Enter the half length in x at low z and y low edge");
87  fEBl1->Associate(this);
88  f1->AddFrame(fEBl1, new TGLayoutHints(kLHintsRight, 2, 2, 4, 4));
89  AddFrame(f1, new TGLayoutHints(kLHintsLeft, 2, 2, 4, 4));
90 
91  // Number entry for Tl1
92  f1 = new TGCompositeFrame(this, 155, 10, kHorizontalFrame | kFixedWidth);
93  f1->AddFrame(new TGLabel(f1, "DX2"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
94  fETl1 = new TGNumberEntry(f1, 0., 5, kTRAP_TL1);
95  fETl1->SetNumAttr(TGNumberFormat::kNEAPositive);
96  fETl1->Resize(100, fETl1->GetDefaultHeight());
97  nef = (TGTextEntry*)fETl1->GetNumberEntry();
98  nef->SetToolTipText("Enter the half length in x at low z and y high edge");
99  fETl1->Associate(this);
100  f1->AddFrame(fETl1, new TGLayoutHints(kLHintsRight, 2, 2, 4, 4));
101  AddFrame(f1, new TGLayoutHints(kLHintsLeft, 2, 2, 4, 4));
102 
103  // Number entry for scale factor
104  f1 = new TGCompositeFrame(this, 155, 10, kHorizontalFrame | kFixedWidth);
105  f1->AddFrame(new TGLabel(f1, "SC1"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
106  fESc1 = new TGNumberEntry(f1, 0., 5, kTRAP_SC1);
107  fESc1->SetNumAttr(TGNumberFormat::kNEAPositive);
108  fESc1->Resize(100, fESc1->GetDefaultHeight());
109  nef = (TGTextEntry*)fESc1->GetNumberEntry();
110  nef->SetToolTipText("Enter the scale factor for lower Z face");
111  fESc1->Associate(this);
112  f1->AddFrame(fESc1, new TGLayoutHints(kLHintsRight, 2, 2, 4, 4));
113  AddFrame(f1, new TGLayoutHints(kLHintsLeft, 2, 2, 4, 4));
114 
115  // Number entry for scale factor
116  f1 = new TGCompositeFrame(this, 155, 10, kHorizontalFrame | kFixedWidth);
117  f1->AddFrame(new TGLabel(f1, "SC2"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
118  fESc2 = new TGNumberEntry(f1, 0., 5, kTRAP_SC2);
119  fESc2->SetNumAttr(TGNumberFormat::kNEAPositive);
120  fESc2->Resize(100, fESc2->GetDefaultHeight());
121  nef = (TGTextEntry*)fESc2->GetNumberEntry();
122  nef->SetToolTipText("Enter the scale factor for upper Z face");
123  fESc2->Associate(this);
124  f1->AddFrame(fESc2, new TGLayoutHints(kLHintsRight, 2, 2, 4, 4));
125  AddFrame(f1, new TGLayoutHints(kLHintsLeft, 2, 2, 4, 4));
126 
127  // Number entry for dz
128  f1 = new TGCompositeFrame(this, 155, 10, kHorizontalFrame | kFixedWidth);
129  f1->AddFrame(new TGLabel(f1, "DZ"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
130  fEDz = new TGNumberEntry(f1, 0., 5, kTRAP_DZ);
131  fEDz->SetNumAttr(TGNumberFormat::kNEAPositive);
132  fEDz->Resize(100, fEDz->GetDefaultHeight());
133  nef = (TGTextEntry*)fEDz->GetNumberEntry();
134  nef->SetToolTipText("Enter the half-length in Z");
135  fEDz->Associate(this);
136  f1->AddFrame(fEDz, new TGLayoutHints(kLHintsRight, 2, 2, 4, 4));
137  AddFrame(f1, new TGLayoutHints(kLHintsLeft, 2, 2, 4, 4));
138 
139  // Number entry for Alpha1
140  f1 = new TGCompositeFrame(this, 155, 10, kHorizontalFrame | kFixedWidth);
141  f1->AddFrame(new TGLabel(f1, "ALPHA"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
142  fEAlpha1 = new TGNumberEntry(f1, 0., 5, kTRAP_ALPHA1);
143  fEAlpha1->Resize(100, fEAlpha1->GetDefaultHeight());
144  nef = (TGTextEntry*)fEAlpha1->GetNumberEntry();
145  nef->SetToolTipText("Enter angle between centers of x edges an y axis at low z");
146  fEAlpha1->Associate(this);
147  f1->AddFrame(fEAlpha1, new TGLayoutHints(kLHintsRight, 2, 2, 4, 4));
148  AddFrame(f1, new TGLayoutHints(kLHintsLeft, 2, 2, 4, 4));
149 
150  // Number entry for Theta
151  f1 = new TGCompositeFrame(this, 155, 10, kHorizontalFrame | kFixedWidth);
152  f1->AddFrame(new TGLabel(f1, "Theta"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
153  fETheta = new TGNumberEntry(f1, 0., 5, kTRAP_THETA);
154  fETheta->SetNumAttr(TGNumberFormat::kNEAPositive);
155  fETheta->Resize(100, fETheta->GetDefaultHeight());
156  nef = (TGTextEntry*)fETheta->GetNumberEntry();
157  nef->SetToolTipText("Enter initial theta");
158  fETheta->Associate(this);
159  f1->AddFrame(fETheta, new TGLayoutHints(kLHintsRight, 2, 2, 4, 4));
160  AddFrame(f1, new TGLayoutHints(kLHintsLeft, 2, 2, 4, 4));
161 
162  // Number entry for Phi
163  f1 = new TGCompositeFrame(this, 155, 10, kHorizontalFrame | kFixedWidth);
164  f1->AddFrame(new TGLabel(f1, "Phi"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
165  fEPhi = new TGNumberEntry(f1, 0., 5, kTRAP_PHI);
166  fEPhi->SetNumAttr(TGNumberFormat::kNEAPositive);
167  fEPhi->Resize(100, fEPhi->GetDefaultHeight());
168  nef = (TGTextEntry*)fEPhi->GetNumberEntry();
169  nef->SetToolTipText("Enter initial phi");
170  fEPhi->Associate(this);
171  f1->AddFrame(fEPhi, new TGLayoutHints(kLHintsRight, 2, 2, 4, 4));
172  AddFrame(f1, new TGLayoutHints(kLHintsLeft, 2, 2, 4, 4));
173 
174  // Delayed draw
175  fDFrame = new TGCompositeFrame(this, 155, 10, kHorizontalFrame | kFixedWidth | kSunkenFrame);
176  fDelayed = new TGCheckButton(fDFrame, "Delayed draw");
177  fDFrame->AddFrame(fDelayed, new TGLayoutHints(kLHintsLeft , 2, 2, 4, 4));
178  AddFrame(fDFrame, new TGLayoutHints(kLHintsLeft, 6, 6, 4, 4));
179 
180  // Buttons
181  fBFrame = new TGCompositeFrame(this, 155, 10, kHorizontalFrame | kFixedWidth);
182  fApply = new TGTextButton(fBFrame, "Apply");
183  fBFrame->AddFrame(fApply, new TGLayoutHints(kLHintsLeft, 2, 2, 4, 4));
184  fApply->Associate(this);
185  fUndo = new TGTextButton(fBFrame, "Undo");
186  fBFrame->AddFrame(fUndo, new TGLayoutHints(kLHintsRight , 2, 2, 4, 4));
187  fUndo->Associate(this);
188  AddFrame(fBFrame, new TGLayoutHints(kLHintsLeft, 6, 6, 4, 4));
189  fUndo->SetSize(fApply->GetSize());
190 }
191 
192 ////////////////////////////////////////////////////////////////////////////////
193 /// Destructor
194 
195 TGeoTrapEditor::~TGeoTrapEditor()
196 {
197  TGFrameElement *el;
198  TIter next(GetList());
199  while ((el = (TGFrameElement *)next())) {
200  if (el->fFrame->IsComposite())
201  TGeoTabManager::Cleanup((TGCompositeFrame*)el->fFrame);
202  }
203  Cleanup();
204 }
205 
206 ////////////////////////////////////////////////////////////////////////////////
207 /// Connect signals to slots.
208 
209 void TGeoTrapEditor::ConnectSignals2Slots()
210 {
211  fApply->Connect("Clicked()", "TGeoTrapEditor", this, "DoApply()");
212  fUndo->Connect("Clicked()", "TGeoTrapEditor", this, "DoUndo()");
213  fShapeName->Connect("TextChanged(const char *)", "TGeoTrapEditor", this, "DoModified()");
214  fEH1->Connect("ValueSet(Long_t)", "TGeoTrapEditor", this, "DoH1()");
215  fEBl1->Connect("ValueSet(Long_t)", "TGeoTrapEditor", this, "DoBl1()");
216  fETl1->Connect("ValueSet(Long_t)", "TGeoTrapEditor", this, "DoTl1()");
217  fEDz->Connect("ValueSet(Long_t)", "TGeoTrapEditor", this, "DoDz()");
218  fESc1->Connect("ValueSet(Long_t)", "TGeoTrapEditor", this, "DoSc1()");
219  fESc2->Connect("ValueSet(Long_t)", "TGeoTrapEditor", this, "DoSc2()");
220  fEAlpha1->Connect("ValueSet(Long_t)", "TGeoTrapEditor", this, "DoAlpha1()");
221  fETheta->Connect("ValueSet(Long_t)", "TGeoTrapEditor", this, "DoTheta()");
222  fEPhi->Connect("ValueSet(Long_t)", "TGeoTrapEditor", this, "DoPhi()");
223  fEH1->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoTrapEditor", this, "DoModified()");
224  fEBl1->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoTrapEditor", this, "DoModified()");
225  fETl1->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoTrapEditor", this, "DoModified()");
226  fEDz->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoTrapEditor", this, "DoModified()");
227  fESc1->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoTrapEditor", this, "DoModified()");
228  fESc2->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoTrapEditor", this, "DoModified()");
229  fEAlpha1->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoTrapEditor", this, "DoModified()");
230  fETheta->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoTrapEditor", this, "DoModified()");
231  fEPhi->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoTrapEditor", this, "DoModified()");
232  fInit = kFALSE;
233 }
234 
235 ////////////////////////////////////////////////////////////////////////////////
236 /// Connect to the selected object.
237 
238 void TGeoTrapEditor::SetModel(TObject* obj)
239 {
240  if (obj == 0 || (obj->IsA()!=TGeoTrap::Class())) {
241  SetActive(kFALSE);
242  return;
243  }
244  fShape = (TGeoTrap*)obj;
245  fH1i = fShape->GetH1();
246  fBl1i = fShape->GetBl1();
247  fTl1i = fShape->GetTl1();
248  fDzi = fShape->GetDz();
249  Double_t h2i = fShape->GetH2();
250 // Double_t bl2i = fShape->GetBl2();
251 // Double_t tl2i = fShape->GetTl2();
252  fSci = h2i/fH1i;
253  fAlpha1i = fShape->GetAlpha1();
254  fThetai = fShape->GetTheta();
255  fPhii = fShape->GetPhi();
256  const char *sname = fShape->GetName();
257  if (!strcmp(sname, fShape->ClassName())) fShapeName->SetText("-no_name");
258  else {
259  fShapeName->SetText(sname);
260  fNamei = sname;
261  }
262  fEH1->SetNumber(fH1i);
263  fEBl1->SetNumber(fBl1i);
264  fETl1->SetNumber(fTl1i);
265  fEDz->SetNumber(fDzi);
266  fESc1->SetNumber(1.);
267  fESc2->SetNumber(fSci);
268  fEAlpha1->SetNumber(fAlpha1i);
269  fETheta->SetNumber(fThetai);
270  fEPhi->SetNumber(fPhii);
271  fApply->SetEnabled(kFALSE);
272  fUndo->SetEnabled(kFALSE);
273 
274  if (fInit) ConnectSignals2Slots();
275  SetActive();
276 }
277 
278 ////////////////////////////////////////////////////////////////////////////////
279 /// Check if shape drawing is delayed.
280 
281 Bool_t TGeoTrapEditor::IsDelayed() const
282 {
283  return (fDelayed->GetState() == kButtonDown);
284 }
285 
286 ////////////////////////////////////////////////////////////////////////////////
287 /// Slot for name.
288 
289 void TGeoTrapEditor::DoName()
290 {
291  DoModified();
292 }
293 
294 ////////////////////////////////////////////////////////////////////////////////
295 /// Slot for applying current settings.
296 
297 void TGeoTrapEditor::DoApply()
298 {
299  const char *name = fShapeName->GetText();
300  if (strcmp(name,fShape->GetName())) fShape->SetName(name);
301  Double_t sc1 = fESc1->GetNumber();
302  Double_t sc2 = fESc2->GetNumber();
303  Double_t h1 = sc1*fEH1->GetNumber();
304  Double_t bl1 = sc1*fEBl1->GetNumber();
305  Double_t tl1 = sc1*fETl1->GetNumber();
306  Double_t h2 = sc2*fEH1->GetNumber();
307  Double_t bl2 = sc2*fEBl1->GetNumber();
308  Double_t tl2 = sc2*fETl1->GetNumber();
309  Double_t dz = fEDz->GetNumber();
310  Double_t alpha1 = fEAlpha1->GetNumber();
311  Double_t theta = fETheta->GetNumber();
312  Double_t phi = fEPhi->GetNumber();
313  Double_t param[11];
314  param[0] = dz;
315  param[1] = theta;
316  param[2] = phi;
317  param[3] = h1;
318  param[7] = h2;
319  param[4] = bl1;
320  param[8] = bl2;
321  param[5] = tl1;
322  param[9] = tl2;
323  param[6] = alpha1;
324  param[10] = alpha1;
325  fShape->SetDimensions(param);
326  fShape->ComputeBBox();
327  fUndo->SetEnabled();
328  fApply->SetEnabled(kFALSE);
329  if (fPad) {
330  if (gGeoManager && gGeoManager->GetPainter() && gGeoManager->GetPainter()->IsPaintingShape()) {
331  TView *view = fPad->GetView();
332  if (!view) {
333  fShape->Draw();
334  fPad->GetView()->ShowAxis();
335  } else {
336  view->SetRange(-fShape->GetDX(), -fShape->GetDY(), -fShape->GetDZ(),
337  fShape->GetDX(), fShape->GetDY(), fShape->GetDZ());
338  Update();
339  }
340  } else Update();
341  }
342 }
343 
344 ////////////////////////////////////////////////////////////////////////////////
345 /// Slot for notifying modifications.
346 
347 void TGeoTrapEditor::DoModified()
348 {
349  fApply->SetEnabled();
350 }
351 
352 ////////////////////////////////////////////////////////////////////////////////
353 /// Slot for undoing last operation.
354 
355 void TGeoTrapEditor::DoUndo()
356 {
357  fEH1->SetNumber(fH1i);
358  fEBl1->SetNumber(fBl1i);
359  fETl1->SetNumber(fTl1i);
360  fESc1->SetNumber(1.);
361  fESc2->SetNumber(fSci);
362  fEDz->SetNumber(fDzi);
363  fEAlpha1->SetNumber(fAlpha1i);
364  fETheta->SetNumber(fThetai);
365  fEPhi->SetNumber(fPhii);
366  DoApply();
367  fUndo->SetEnabled(kFALSE);
368  fApply->SetEnabled(kFALSE);
369 }
370 
371 ////////////////////////////////////////////////////////////////////////////////
372 /// Slot for H1.
373 
374 void TGeoTrapEditor::DoH1()
375 {
376  Double_t h1 = fEH1->GetNumber();
377  if (h1<=0) {
378  h1 = 0.1;
379  fEH1->SetNumber(h1);
380  }
381  DoModified();
382  if (!IsDelayed()) DoApply();
383 }
384 
385 ////////////////////////////////////////////////////////////////////////////////
386 /// Slot for Bl1.
387 
388 void TGeoTrapEditor::DoBl1()
389 {
390  Double_t bl1 = fEBl1->GetNumber();
391  if (bl1<=0) {
392  bl1 = 0.1;
393  fEBl1->SetNumber(bl1);
394  }
395  DoModified();
396  if (!IsDelayed()) DoApply();
397 }
398 
399 ////////////////////////////////////////////////////////////////////////////////
400 /// Slot for Tl1.
401 
402 void TGeoTrapEditor::DoTl1()
403 {
404  Double_t tl1 = fETl1->GetNumber();
405  if (tl1<=0) {
406  tl1 = 0.1;
407  fETl1->SetNumber(tl1);
408  }
409  DoModified();
410  if (!IsDelayed()) DoApply();
411 }
412 
413 ////////////////////////////////////////////////////////////////////////////////
414 /// Slot for Z.
415 
416 void TGeoTrapEditor::DoDz()
417 {
418  Double_t dz = fEDz->GetNumber();
419  if (dz<=0) {
420  dz = 0.1;
421  fEDz->SetNumber(dz);
422  }
423  DoModified();
424  if (!IsDelayed()) DoApply();
425 }
426 
427 ////////////////////////////////////////////////////////////////////////////////
428 /// Slot for H2.
429 
430 void TGeoTrapEditor::DoSc1()
431 {
432  Double_t sc1 = fESc1->GetNumber();
433  if (sc1<=0) {
434  sc1 = 0.1;
435  fESc1->SetNumber(sc1);
436  }
437  DoModified();
438  if (!IsDelayed()) DoApply();
439 }
440 
441 ////////////////////////////////////////////////////////////////////////////////
442 /// Slot for H2.
443 
444 void TGeoTrapEditor::DoSc2()
445 {
446  Double_t sc2 = fESc2->GetNumber();
447  if (sc2<=0) {
448  sc2 = 0.1;
449  fESc2->SetNumber(sc2);
450  }
451  DoModified();
452  if (!IsDelayed()) DoApply();
453 }
454 
455 ////////////////////////////////////////////////////////////////////////////////
456 /// Slot for alpha1.
457 
458 void TGeoTrapEditor::DoAlpha1()
459 {
460  Double_t alpha1 = fEAlpha1->GetNumber();
461  if (TMath::Abs(alpha1)>=90) {
462  alpha1 = 89.9*TMath::Sign(1.,alpha1);
463  fEAlpha1->SetNumber(alpha1);
464  }
465  DoModified();
466  if (!IsDelayed()) DoApply();
467 }
468 
469 ////////////////////////////////////////////////////////////////////////////////
470 /// Slot for theta.
471 
472 void TGeoTrapEditor::DoTheta()
473 {
474  Double_t theta = fETheta->GetNumber();
475  if (theta<0) {
476  theta = 0;
477  fETheta->SetNumber(theta);
478  }
479  if (theta>180) {
480  theta = 180;
481  fETheta->SetNumber(theta);
482  }
483  DoModified();
484  if (!IsDelayed()) DoApply();
485 }
486 
487 ////////////////////////////////////////////////////////////////////////////////
488 /// Slot for phi.
489 
490 void TGeoTrapEditor::DoPhi()
491 {
492  Double_t phi = fEPhi->GetNumber();
493  if (phi<0 || phi>360) {
494  phi = 0;
495  fEPhi->SetNumber(phi);
496  }
497  DoModified();
498  if (!IsDelayed()) DoApply();
499 }
500 
501 ClassImp(TGeoGtraEditor);
502 
503 enum ETGeoGtraWid {
504  kGTRA_TWIST
505 };
506 
507 /** \class TGeoGtraEditor
508 \ingroup Geometry_builder
509 
510 Editor for a TGeoGtra.
511 
512 \image html geom_gtra_pic.png
513 
514 \image html geom_gtra_ed.png
515 
516 */
517 
518 ////////////////////////////////////////////////////////////////////////////////
519 /// Constructor for gtra editor
520 
521 TGeoGtraEditor::TGeoGtraEditor(const TGWindow *p, Int_t width,
522  Int_t height, UInt_t options, Pixel_t back)
523  : TGeoTrapEditor(p, width, height, options, back)
524 {
525  fTwisti = 0;
526  TGTextEntry *nef;
527  // Number entry for Twist angle
528  TGCompositeFrame *f1 = new TGCompositeFrame(this, 155, 10, kHorizontalFrame | kFixedWidth);
529  f1->AddFrame(new TGLabel(f1, "TWIST"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
530  fETwist = new TGNumberEntry(f1, 0., 5, kGTRA_TWIST);
531  fETwist->Resize(100, fETwist->GetDefaultHeight());
532  nef = (TGTextEntry*)fETwist->GetNumberEntry();
533  nef->SetToolTipText("Enter twist angle");
534  fETwist->Associate(this);
535  f1->AddFrame(fETwist, new TGLayoutHints(kLHintsRight, 2, 2, 4, 4));
536  AddFrame(f1, new TGLayoutHints(kLHintsLeft, 2, 2, 4, 4));
537  TGeoTabManager::MoveFrame(fDFrame, this);
538  TGeoTabManager::MoveFrame(fBFrame, this);
539  fETwist->Connect("ValueSet(Long_t)", "TGeoGtraEditor", this, "DoTwist()");
540  nef->Connect("TextChanged(const char *)", "TGeoGtraEditor", this, "DoModified()");
541 }
542 ////////////////////////////////////////////////////////////////////////////////
543 /// Destructor
544 
545 TGeoGtraEditor::~TGeoGtraEditor()
546 {
547  TGFrameElement *el;
548  TIter next(GetList());
549  while ((el = (TGFrameElement *)next())) {
550  if (el->fFrame->IsComposite())
551  TGeoTabManager::Cleanup((TGCompositeFrame*)el->fFrame);
552  }
553  Cleanup();
554 }
555 
556 ////////////////////////////////////////////////////////////////////////////////
557 /// Connect to a given twisted trapezoid.
558 
559 void TGeoGtraEditor::SetModel(TObject* obj)
560 {
561  if (obj == 0 || (obj->IsA()!=TGeoGtra::Class())) {
562  SetActive(kFALSE);
563  return;
564  }
565  fShape = (TGeoTrap*)obj;
566  fH1i = fShape->GetH1();
567  fBl1i = fShape->GetBl1();
568  fTl1i = fShape->GetTl1();
569  fDzi = fShape->GetDz();
570  Double_t h2i = fShape->GetH2();
571 // Double_t bl2i = fShape->GetBl2();
572 // Double_t tl2i = fShape->GetTl2();
573  fSci = h2i/fH1i;
574  fAlpha1i = fShape->GetAlpha1();
575  fThetai = fShape->GetTheta();
576  fPhii = fShape->GetPhi();
577  fTwisti = ((TGeoGtra*)fShape)->GetTwistAngle();
578  const char *sname = fShape->GetName();
579  if (!strcmp(sname, fShape->ClassName())) fShapeName->SetText("-no_name");
580  else {
581  fShapeName->SetText(sname);
582  fNamei = sname;
583  }
584  fEH1->SetNumber(fH1i);
585  fEBl1->SetNumber(fBl1i);
586  fETl1->SetNumber(fTl1i);
587  fEDz->SetNumber(fDzi);
588  fESc1->SetNumber(1.);
589  fESc2->SetNumber(fSci);
590  fEAlpha1->SetNumber(fAlpha1i);
591  fETheta->SetNumber(fThetai);
592  fEPhi->SetNumber(fPhii);
593  fETwist->SetNumber(fTwisti);
594  fApply->SetEnabled(kFALSE);
595  fUndo->SetEnabled(kFALSE);
596 
597  if (fInit) ConnectSignals2Slots();
598  SetActive();
599 }
600 
601 ////////////////////////////////////////////////////////////////////////////////
602 /// Slot for applying current settings.
603 
604 void TGeoGtraEditor::DoApply()
605 {
606  const char *name = fShapeName->GetText();
607  if (strcmp(name,fShape->GetName())) fShape->SetName(name);
608  Double_t sc1 = fESc1->GetNumber();
609  Double_t sc2 = fESc2->GetNumber();
610  Double_t h1 = sc1*fEH1->GetNumber();
611  Double_t bl1 = sc1*fEBl1->GetNumber();
612  Double_t tl1 = sc1*fETl1->GetNumber();
613  Double_t h2 = sc2*fEH1->GetNumber();
614  Double_t bl2 = sc2*fEBl1->GetNumber();
615  Double_t tl2 = sc2*fETl1->GetNumber();
616  Double_t dz = fEDz->GetNumber();
617  Double_t alpha1 = fEAlpha1->GetNumber();
618  Double_t theta = fETheta->GetNumber();
619  Double_t phi = fEPhi->GetNumber();
620  Double_t twist = fETwist->GetNumber();
621  Double_t param[12];
622  param[0] = dz;
623  param[1] = theta;
624  param[2] = phi;
625  param[3] = h1;
626  param[7] = h2;
627  param[4] = bl1;
628  param[8] = bl2;
629  param[5] = tl1;
630  param[9] = tl2;
631  param[6] = alpha1;
632  param[10] = alpha1;
633  param[11] = twist;
634  TGeoGtra *shape = (TGeoGtra*)fShape;
635  shape->SetDimensions(param);
636  shape->ComputeBBox();
637  fUndo->SetEnabled();
638  fApply->SetEnabled(kFALSE);
639  if (fPad) {
640  if (gGeoManager && gGeoManager->GetPainter() && gGeoManager->GetPainter()->IsPaintingShape()) {
641  TView *view = fPad->GetView();
642  if (!view) {
643  fShape->Draw();
644  fPad->GetView()->ShowAxis();
645  } else {
646  view->SetRange(-fShape->GetDX(), -fShape->GetDY(), -fShape->GetDZ(),
647  fShape->GetDX(), fShape->GetDY(), fShape->GetDZ());
648  Update();
649  }
650  } else Update();
651  }
652 }
653 
654 ////////////////////////////////////////////////////////////////////////////////
655 /// Slot for undoing last operation.
656 
657 void TGeoGtraEditor::DoUndo()
658 {
659  fEH1->SetNumber(fH1i);
660  fEBl1->SetNumber(fBl1i);
661  fETl1->SetNumber(fTl1i);
662  fESc1->SetNumber(1.);
663  fESc2->SetNumber(fSci);
664  fEDz->SetNumber(fDzi);
665  fEAlpha1->SetNumber(fAlpha1i);
666  fETheta->SetNumber(fThetai);
667  fEPhi->SetNumber(fPhii);
668  fETwist->SetNumber(fTwisti);
669  DoApply();
670  fUndo->SetEnabled(kFALSE);
671  fApply->SetEnabled(kFALSE);
672 }
673 
674 ////////////////////////////////////////////////////////////////////////////////
675 /// Change the twist angle.
676 
677 void TGeoGtraEditor::DoTwist()
678 {
679  Double_t twist = fETwist->GetNumber();
680  if (twist<=-180 || twist>=180) {
681  twist = 0.;
682  fETwist->SetNumber(twist);
683  }
684  DoModified();
685  if (!IsDelayed()) DoApply();
686 }