Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
TGeoTrd2Editor.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 TGeoTrd2Editor
13 \ingroup Geometry_builder
14 
15 Editor for a TGeoTrd2.
16 
17 \image html geom_trd2_pic.png
18 
19 \image html geom_trd2_ed.png
20 
21 */
22 
23 #include "TGeoTrd2Editor.h"
24 #include "TGeoTabManager.h"
25 #include "TGeoTrd2.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(TGeoTrd2Editor);
38 
39 enum ETGeoTrd2Wid {
40  kTRD2_NAME, kTRD2_X1, kTRD2_X2, kTRD2_Y1, kTRD2_Y2, kTRD2_Z,
41  kTRD2_APPLY, kTRD2_UNDO
42 };
43 
44 ////////////////////////////////////////////////////////////////////////////////
45 /// Constructor for trd2 editor
46 
47 TGeoTrd2Editor::TGeoTrd2Editor(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  fDxi1 = fDxi2 = fDyi1 = fDyi2 = fDzi = 0.0;
53  fNamei = "";
54  fIsModified = kFALSE;
55  fIsShapeEditable = kFALSE;
56 
57  // TextEntry for shape name
58  MakeTitle("Name");
59  fShapeName = new TGTextEntry(this, new TGTextBuffer(50), kTRD2_NAME);
60  fShapeName->Resize(135, fShapeName->GetDefaultHeight());
61  fShapeName->SetToolTipText("Enter the box name");
62  fShapeName->Associate(this);
63  AddFrame(fShapeName, new TGLayoutHints(kLHintsLeft, 3, 1, 2, 5));
64 
65  TGTextEntry *nef;
66  MakeTitle("Trd2 dimensions");
67  TGCompositeFrame *compxyz = new TGCompositeFrame(this, 118, 30, kVerticalFrame | kRaisedFrame | kDoubleBorder);
68 
69  // Number entry for dx1
70  TGCompositeFrame *f1 = new TGCompositeFrame(compxyz, 118, 10, kHorizontalFrame |
71  kLHintsExpandX | kFixedWidth | kOwnBackground);
72  f1->AddFrame(new TGLabel(f1, "DX1"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
73  fEDx1 = new TGNumberEntry(f1, 0., 5, kTRD2_X1);
74  fEDx1->SetNumAttr(TGNumberFormat::kNEAPositive);
75  nef = (TGTextEntry*)fEDx1->GetNumberEntry();
76  nef->SetToolTipText("Enter the half-length in X1");
77  fEDx1->Associate(this);
78  f1->AddFrame(fEDx1, new TGLayoutHints(kLHintsLeft | kLHintsExpandX , 2, 2, 4, 4));
79  compxyz->AddFrame(f1, new TGLayoutHints(kLHintsLeft | kLHintsExpandX , 2, 2, 4, 4));
80 
81  // Number entry for dx2
82  f1 = new TGCompositeFrame(compxyz, 118, 10, kHorizontalFrame |
83  kLHintsExpandX | kFixedWidth | kOwnBackground);
84  f1->AddFrame(new TGLabel(f1, "DX2"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
85  fEDx2 = new TGNumberEntry(f1, 0., 5, kTRD2_X2);
86  fEDx2->SetNumAttr(TGNumberFormat::kNEAPositive);
87  nef = (TGTextEntry*)fEDx2->GetNumberEntry();
88  nef->SetToolTipText("Enter the half-length in X2");
89  fEDx2->Associate(this);
90  f1->AddFrame(fEDx2, new TGLayoutHints(kLHintsLeft | kLHintsExpandX , 2, 2, 4, 4));
91  compxyz->AddFrame(f1, new TGLayoutHints(kLHintsLeft | kLHintsExpandX , 2, 2, 4, 4));
92 
93  // Number entry for dy1
94  TGCompositeFrame *f2 = new TGCompositeFrame(compxyz, 118, 10, kHorizontalFrame |
95  kLHintsExpandX | kFixedWidth | kOwnBackground);
96  f2->AddFrame(new TGLabel(f2, "DY1"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
97  fEDy1 = new TGNumberEntry(f2, 0., 5, kTRD2_Y1);
98  fEDy1->SetNumAttr(TGNumberFormat::kNEAPositive);
99  nef = (TGTextEntry*)fEDy1->GetNumberEntry();
100  nef->SetToolTipText("Enter the half-length in Y1");
101  fEDy1->Associate(this);
102  f2->AddFrame(fEDy1, new TGLayoutHints(kLHintsLeft | kLHintsExpandX , 2, 2, 4, 4));
103  compxyz->AddFrame(f2, new TGLayoutHints(kLHintsLeft | kLHintsExpandX , 2, 2, 4, 4));
104 
105  // Number entry for dy2
106  f2 = new TGCompositeFrame(compxyz, 118, 10, kHorizontalFrame |
107  kLHintsExpandX | kFixedWidth | kOwnBackground);
108  f2->AddFrame(new TGLabel(f2, "DY2"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
109  fEDy2 = new TGNumberEntry(f2, 0., 5, kTRD2_Y2);
110  fEDy2->SetNumAttr(TGNumberFormat::kNEAPositive);
111  nef = (TGTextEntry*)fEDy2->GetNumberEntry();
112  nef->SetToolTipText("Enter the half-length in Y2");
113  fEDy2->Associate(this);
114  f2->AddFrame(fEDy2, new TGLayoutHints(kLHintsLeft | kLHintsExpandX , 2, 2, 4, 4));
115  compxyz->AddFrame(f2, new TGLayoutHints(kLHintsLeft | kLHintsExpandX , 2, 2, 4, 4));
116 
117  // Number entry for dz
118  TGCompositeFrame *f3 = new TGCompositeFrame(compxyz, 118, 10, kHorizontalFrame |
119  kLHintsExpandX | kFixedWidth | kOwnBackground);
120  f3->AddFrame(new TGLabel(f3, "DZ"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
121  fEDz = new TGNumberEntry(f3, 0., 5, kTRD2_Z);
122  fEDz->SetNumAttr(TGNumberFormat::kNEAPositive);
123  nef = (TGTextEntry*)fEDz->GetNumberEntry();
124  nef->SetToolTipText("Enter the half-length in Z");
125  fEDz->Associate(this);
126  f3->AddFrame(fEDz, new TGLayoutHints(kLHintsLeft | kLHintsExpandX , 2, 2, 4, 4));
127  compxyz->AddFrame(f3, new TGLayoutHints(kLHintsLeft | kLHintsExpandX , 2, 2, 4, 4));
128 
129  compxyz->Resize(150,30);
130  AddFrame(compxyz, new TGLayoutHints(kLHintsLeft, 6, 6, 4, 4));
131 
132  // Delayed draw
133  f1 = new TGCompositeFrame(this, 155, 10, kHorizontalFrame | kFixedWidth | kSunkenFrame);
134  fDelayed = new TGCheckButton(f1, "Delayed draw");
135  f1->AddFrame(fDelayed, new TGLayoutHints(kLHintsLeft , 2, 2, 4, 4));
136  AddFrame(f1, new TGLayoutHints(kLHintsLeft, 6, 6, 4, 4));
137 
138  // Buttons
139  f1 = new TGCompositeFrame(this, 155, 10, kHorizontalFrame | kFixedWidth);
140  fApply = new TGTextButton(f1, "Apply");
141  f1->AddFrame(fApply, new TGLayoutHints(kLHintsLeft, 2, 2, 4, 4));
142  fApply->Associate(this);
143  fUndo = new TGTextButton(f1, "Undo");
144  f1->AddFrame(fUndo, new TGLayoutHints(kLHintsRight , 2, 2, 4, 4));
145  fUndo->Associate(this);
146  AddFrame(f1, new TGLayoutHints(kLHintsLeft, 6, 6, 4, 4));
147  fUndo->SetSize(fApply->GetSize());
148 }
149 
150 ////////////////////////////////////////////////////////////////////////////////
151 /// Destructor.
152 
153 TGeoTrd2Editor::~TGeoTrd2Editor()
154 {
155  TGFrameElement *el;
156  TIter next(GetList());
157  while ((el = (TGFrameElement *)next())) {
158  if (el->fFrame->IsComposite())
159  TGeoTabManager::Cleanup((TGCompositeFrame*)el->fFrame);
160  }
161  Cleanup();
162 }
163 
164 ////////////////////////////////////////////////////////////////////////////////
165 /// Connect signals to slots.
166 
167 void TGeoTrd2Editor::ConnectSignals2Slots()
168 {
169  fApply->Connect("Clicked()", "TGeoTrd2Editor", this, "DoApply()");
170  fUndo->Connect("Clicked()", "TGeoTrd2Editor", this, "DoUndo()");
171  fShapeName->Connect("TextChanged(const char *)", "TGeoTrd2Editor", this, "DoModified()");
172  fEDx1->Connect("ValueSet(Long_t)", "TGeoTrd2Editor", this, "DoDx1()");
173  fEDx2->Connect("ValueSet(Long_t)", "TGeoTrd2Editor", this, "DoDx2()");
174  fEDy1->Connect("ValueSet(Long_t)", "TGeoTrd2Editor", this, "DoDy1()");
175  fEDy2->Connect("ValueSet(Long_t)", "TGeoTrd2Editor", this, "DoDy2()");
176  fEDz->Connect("ValueSet(Long_t)", "TGeoTrd2Editor", this, "DoDz()");
177  fEDx1->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoTrd2Editor", this, "DoModified()");
178  fEDx2->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoTrd2Editor", this, "DoModified()");
179  fEDy1->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoTrd2Editor", this, "DoModified()");
180  fEDy2->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoTrd2Editor", this, "DoModified()");
181  fEDz->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoTrd2Editor", this, "DoModified()");
182  fInit = kFALSE;
183 }
184 
185 
186 ////////////////////////////////////////////////////////////////////////////////
187 /// Connect to the selected object.
188 
189 void TGeoTrd2Editor::SetModel(TObject* obj)
190 {
191  if (obj == 0 || (obj->IsA()!=TGeoTrd2::Class())) {
192  SetActive(kFALSE);
193  return;
194  }
195  fShape = (TGeoTrd2*)obj;
196  fDxi1 = fShape->GetDx1();
197  fDxi2 = fShape->GetDx2();
198  fDyi1 = fShape->GetDy1();
199  fDyi2 = fShape->GetDy2();
200  fDzi = fShape->GetDz();
201  const char *sname = fShape->GetName();
202  if (!strcmp(sname, fShape->ClassName())) fShapeName->SetText("-no_name");
203  else {
204  fShapeName->SetText(sname);
205  fNamei = sname;
206  }
207  fEDx1->SetNumber(fDxi1);
208  fEDx2->SetNumber(fDxi2);
209  fEDy1->SetNumber(fDyi1);
210  fEDy2->SetNumber(fDyi2);
211  fEDz->SetNumber(fDzi);
212  fApply->SetEnabled(kFALSE);
213  fUndo->SetEnabled(kFALSE);
214 
215  if (fInit) ConnectSignals2Slots();
216  SetActive();
217 }
218 
219 ////////////////////////////////////////////////////////////////////////////////
220 /// Check if shape drawing is delayed.
221 
222 Bool_t TGeoTrd2Editor::IsDelayed() const
223 {
224  return (fDelayed->GetState() == kButtonDown);
225 }
226 
227 ////////////////////////////////////////////////////////////////////////////////
228 /// Perform name change.
229 
230 void TGeoTrd2Editor::DoName()
231 {
232  DoModified();
233 }
234 
235 ////////////////////////////////////////////////////////////////////////////////
236 /// Slot for applying modifications.
237 
238 void TGeoTrd2Editor::DoApply()
239 {
240  const char *name = fShapeName->GetText();
241  if (strcmp(name,fShape->GetName())) fShape->SetName(name);
242  Double_t dx1 = fEDx1->GetNumber();
243  Double_t dx2 = fEDx2->GetNumber();
244  Double_t dy1 = fEDy1->GetNumber();
245  Double_t dy2 = fEDy2->GetNumber();
246  Double_t dz = fEDz->GetNumber();
247  Double_t param[5];
248  param[0] = dx1;
249  param[1] = dx2;
250  param[2] = dy1;
251  param[3] = dy2;
252  param[4] = dz;
253  fShape->SetDimensions(param);
254  fShape->ComputeBBox();
255  fUndo->SetEnabled();
256  fApply->SetEnabled(kFALSE);
257  if (fPad) {
258  if (gGeoManager && gGeoManager->GetPainter() && gGeoManager->GetPainter()->IsPaintingShape()) {
259  fShape->Draw();
260  fPad->GetView()->ShowAxis();
261  } else Update();
262  }
263 }
264 
265 ////////////////////////////////////////////////////////////////////////////////
266 /// Slot for signaling modifications.
267 
268 void TGeoTrd2Editor::DoModified()
269 {
270  fApply->SetEnabled();
271 }
272 
273 ////////////////////////////////////////////////////////////////////////////////
274 /// Slot for undoing last operation.
275 
276 void TGeoTrd2Editor::DoUndo()
277 {
278  fEDx1->SetNumber(fDxi1);
279  fEDx2->SetNumber(fDxi2);
280  fEDy1->SetNumber(fDyi1);
281  fEDy2->SetNumber(fDyi2);
282  fEDz->SetNumber(fDzi);
283  DoApply();
284  fUndo->SetEnabled(kFALSE);
285  fApply->SetEnabled(kFALSE);
286 }
287 
288 ////////////////////////////////////////////////////////////////////////////////
289 /// Slot for dx1.
290 
291 void TGeoTrd2Editor::DoDx1()
292 {
293  Double_t dx1 = fEDx1->GetNumber();
294  Double_t dx2 = fEDx2->GetNumber();
295  if (dx1<0) {
296  dx1 = 0;
297  fEDx1->SetNumber(dx1);
298  }
299  if (dx1<1.e-6 && dx2<1.e-6) {
300  dx1 = 0.1;
301  fEDx1->SetNumber(dx1);
302  }
303  DoModified();
304  if (!IsDelayed()) DoApply();
305 }
306 
307 ////////////////////////////////////////////////////////////////////////////////
308 /// Slot for dx2.
309 
310 void TGeoTrd2Editor::DoDx2()
311 {
312  Double_t dx1 = fEDx1->GetNumber();
313  Double_t dx2 = fEDx2->GetNumber();
314  if (dx2<0) {
315  dx2 = 0;
316  fEDx2->SetNumber(dx2);
317  }
318  if (dx1<1.e-6 && dx2<1.e-6) {
319  dx2 = 0.1;
320  fEDx2->SetNumber(dx2);
321  }
322  DoModified();
323  if (!IsDelayed()) DoApply();
324 }
325 
326 ////////////////////////////////////////////////////////////////////////////////
327 /// Slot for dy1.
328 
329 void TGeoTrd2Editor::DoDy1()
330 {
331  Double_t dy1 = fEDy1->GetNumber();
332  Double_t dy2 = fEDy2->GetNumber();
333  if (dy1<0) {
334  dy1 = 0;
335  fEDy1->SetNumber(dy1);
336  }
337  if (dy1<1.e-6 && dy2<1.e-6) {
338  dy1 = 0.1;
339  fEDy1->SetNumber(dy1);
340  }
341  DoModified();
342  if (!IsDelayed()) DoApply();
343 }
344 
345 ////////////////////////////////////////////////////////////////////////////////
346 /// Slot for dy2.
347 
348 void TGeoTrd2Editor::DoDy2()
349 {
350  Double_t dy1 = fEDy1->GetNumber();
351  Double_t dy2 = fEDy2->GetNumber();
352  if (dy2<0) {
353  dy2 = 0;
354  fEDy2->SetNumber(dy2);
355  }
356  if (dy1<1.e-6 && dy2<1.e-6) {
357  dy2 = 0.1;
358  fEDy2->SetNumber(dy2);
359  }
360  DoModified();
361  if (!IsDelayed()) DoApply();
362 }
363 
364 ////////////////////////////////////////////////////////////////////////////////
365 /// Slot for dz.
366 
367 void TGeoTrd2Editor::DoDz()
368 {
369  Double_t dz = fEDz->GetNumber();
370  if (dz<=0) {
371  dz = 0.1;
372  fEDz->SetNumber(dz);
373  }
374  DoModified();
375  if (!IsDelayed()) DoApply();
376 }
377 
378