Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
TGeoTrd1Editor.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 TGeoTrd1Editor
13 \ingroup Geometry_builder
14 
15 Editor for a TGeoTrd1.
16 
17 \image html geom_trd1_pic.png
18 
19 \image html geom_trd1_ed.png
20 
21 */
22 
23 #include "TGeoTrd1Editor.h"
24 #include "TGeoTabManager.h"
25 #include "TGeoTrd1.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(TGeoTrd1Editor);
38 
39 enum ETGeoTrd1Wid {
40  kTRD1_NAME, kTRD1_X1, kTRD1_X2, kTRD1_Y, kTRD1_Z,
41  kTRD1_APPLY, kTRD1_UNDO
42 };
43 
44 ////////////////////////////////////////////////////////////////////////////////
45 /// Constructor for trd1 editor
46 
47 TGeoTrd1Editor::TGeoTrd1Editor(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 = fDyi = 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), kTRD1_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("Trd1 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, kTRD1_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, kTRD1_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 dy
94  TGCompositeFrame *f2 = new TGCompositeFrame(compxyz, 118, 10, kHorizontalFrame |
95  kLHintsExpandX | kFixedWidth | kOwnBackground);
96  f2->AddFrame(new TGLabel(f2, "DY"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
97  fEDy = new TGNumberEntry(f2, 0., 5, kTRD1_Y);
98  fEDy->SetNumAttr(TGNumberFormat::kNEAPositive);
99  nef = (TGTextEntry*)fEDy->GetNumberEntry();
100  nef->SetToolTipText("Enter the half-length in Y");
101  fEDy->Associate(this);
102  f2->AddFrame(fEDy, 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 dz
106  TGCompositeFrame *f3 = new TGCompositeFrame(compxyz, 118, 10, kHorizontalFrame |
107  kLHintsExpandX | kFixedWidth | kOwnBackground);
108  f3->AddFrame(new TGLabel(f3, "DZ"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
109  fEDz = new TGNumberEntry(f3, 0., 5, kTRD1_Z);
110  fEDz->SetNumAttr(TGNumberFormat::kNEAPositive);
111  nef = (TGTextEntry*)fEDz->GetNumberEntry();
112  nef->SetToolTipText("Enter the half-length in Z");
113  fEDz->Associate(this);
114  f3->AddFrame(fEDz, new TGLayoutHints(kLHintsLeft | kLHintsExpandX , 2, 2, 4, 4));
115  compxyz->AddFrame(f3, new TGLayoutHints(kLHintsLeft | kLHintsExpandX , 2, 2, 4, 4));
116 
117  compxyz->Resize(150,30);
118  AddFrame(compxyz, new TGLayoutHints(kLHintsLeft, 6, 6, 4, 4));
119 
120  // Delayed draw
121  f1 = new TGCompositeFrame(this, 155, 10, kHorizontalFrame | kFixedWidth | kSunkenFrame);
122  fDelayed = new TGCheckButton(f1, "Delayed draw");
123  f1->AddFrame(fDelayed, new TGLayoutHints(kLHintsLeft , 2, 2, 4, 4));
124  AddFrame(f1, new TGLayoutHints(kLHintsLeft, 6, 6, 4, 4));
125 
126  // Buttons
127  f1 = new TGCompositeFrame(this, 155, 10, kHorizontalFrame | kFixedWidth);
128  fApply = new TGTextButton(f1, "Apply");
129  f1->AddFrame(fApply, new TGLayoutHints(kLHintsLeft, 2, 2, 4, 4));
130  fApply->Associate(this);
131  fUndo = new TGTextButton(f1, "Undo");
132  f1->AddFrame(fUndo, new TGLayoutHints(kLHintsRight , 2, 2, 4, 4));
133  fUndo->Associate(this);
134  AddFrame(f1, new TGLayoutHints(kLHintsLeft, 6, 6, 4, 4));
135  fUndo->SetSize(fApply->GetSize());
136 }
137 
138 ////////////////////////////////////////////////////////////////////////////////
139 /// Destructor
140 
141 TGeoTrd1Editor::~TGeoTrd1Editor()
142 {
143  TGFrameElement *el;
144  TIter next(GetList());
145  while ((el = (TGFrameElement *)next())) {
146  if (el->fFrame->IsComposite())
147  TGeoTabManager::Cleanup((TGCompositeFrame*)el->fFrame);
148  }
149  Cleanup();
150 }
151 
152 ////////////////////////////////////////////////////////////////////////////////
153 /// Connect signals to slots.
154 
155 void TGeoTrd1Editor::ConnectSignals2Slots()
156 {
157  fApply->Connect("Clicked()", "TGeoTrd1Editor", this, "DoApply()");
158  fUndo->Connect("Clicked()", "TGeoTrd1Editor", this, "DoUndo()");
159  fShapeName->Connect("TextChanged(const char *)", "TGeoTrd1Editor", this, "DoModified()");
160  fEDx1->Connect("ValueSet(Long_t)", "TGeoTrd1Editor", this, "DoDx1()");
161  fEDx2->Connect("ValueSet(Long_t)", "TGeoTrd1Editor", this, "DoDx2()");
162  fEDy->Connect("ValueSet(Long_t)", "TGeoTrd1Editor", this, "DoDy()");
163  fEDz->Connect("ValueSet(Long_t)", "TGeoTrd1Editor", this, "DoDz()");
164  fEDx1->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoTrd1Editor", this, "DoModified()");
165  fEDx2->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoTrd1Editor", this, "DoModified()");
166  fEDy->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoTrd1Editor", this, "DoModified()");
167  fEDz->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoTrd1Editor", this, "DoModified()");
168  fInit = kFALSE;
169 }
170 
171 
172 ////////////////////////////////////////////////////////////////////////////////
173 /// Connect to the selected object.
174 
175 void TGeoTrd1Editor::SetModel(TObject* obj)
176 {
177  if (obj == 0 || (obj->IsA()!=TGeoTrd1::Class())) {
178  SetActive(kFALSE);
179  return;
180  }
181  fShape = (TGeoTrd1*)obj;
182  fDxi1 = fShape->GetDx1();
183  fDxi2 = fShape->GetDx2();
184  fDyi = fShape->GetDy();
185  fDzi = fShape->GetDz();
186  const char *sname = fShape->GetName();
187  if (!strcmp(sname, fShape->ClassName())) fShapeName->SetText("-no_name");
188  else {
189  fShapeName->SetText(sname);
190  fNamei = sname;
191  }
192  fEDx1->SetNumber(fDxi1);
193  fEDx2->SetNumber(fDxi2);
194  fEDy->SetNumber(fDyi);
195  fEDz->SetNumber(fDzi);
196  fApply->SetEnabled(kFALSE);
197  fUndo->SetEnabled(kFALSE);
198 
199 
200  if (fInit) ConnectSignals2Slots();
201  SetActive();
202 }
203 
204 ////////////////////////////////////////////////////////////////////////////////
205 /// Check if shape drawing is delayed.
206 
207 Bool_t TGeoTrd1Editor::IsDelayed() const
208 {
209  return (fDelayed->GetState() == kButtonDown);
210 }
211 
212 ////////////////////////////////////////////////////////////////////////////////
213 /// Perform name change.
214 
215 void TGeoTrd1Editor::DoName()
216 {
217  DoModified();
218 }
219 
220 ////////////////////////////////////////////////////////////////////////////////
221 /// Slot for applying modifications.
222 
223 void TGeoTrd1Editor::DoApply()
224 {
225  const char *name = fShapeName->GetText();
226  if (strcmp(name,fShape->GetName())) fShape->SetName(name);
227  Double_t dx1 = fEDx1->GetNumber();
228  Double_t dx2 = fEDx2->GetNumber();
229  Double_t dy = fEDy->GetNumber();
230  Double_t dz = fEDz->GetNumber();
231  Double_t param[4];
232  param[0] = dx1;
233  param[1] = dx2;
234  param[2] = dy;
235  param[3] = dz;
236  fShape->SetDimensions(param);
237  fShape->ComputeBBox();
238  fUndo->SetEnabled();
239  fApply->SetEnabled(kFALSE);
240  if (fPad) {
241  if (gGeoManager && gGeoManager->GetPainter() && gGeoManager->GetPainter()->IsPaintingShape()) {
242  fShape->Draw();
243  fPad->GetView()->ShowAxis();
244  } else Update();
245  }
246 }
247 
248 ////////////////////////////////////////////////////////////////////////////////
249 /// Slot for signaling modifications.
250 
251 void TGeoTrd1Editor::DoModified()
252 {
253  fApply->SetEnabled();
254 }
255 
256 ////////////////////////////////////////////////////////////////////////////////
257 /// Slot for undoing last operation.
258 
259 void TGeoTrd1Editor::DoUndo()
260 {
261  fEDx1->SetNumber(fDxi1);
262  fEDx2->SetNumber(fDxi2);
263  fEDy->SetNumber(fDyi);
264  fEDz->SetNumber(fDzi);
265  DoApply();
266  fUndo->SetEnabled(kFALSE);
267  fApply->SetEnabled(kFALSE);
268 }
269 
270 ////////////////////////////////////////////////////////////////////////////////
271 /// Slot for dx1.
272 
273 void TGeoTrd1Editor::DoDx1()
274 {
275  Double_t dx1 = fEDx1->GetNumber();
276  Double_t dx2 = fEDx2->GetNumber();
277  if (dx1<0) {
278  dx1 = 0;
279  fEDx1->SetNumber(dx1);
280  }
281  if (dx1<1.e-6 && dx2<1.e-6) {
282  dx1 = 0.1;
283  fEDx1->SetNumber(dx1);
284  }
285  DoModified();
286  if (!IsDelayed()) DoApply();
287 }
288 
289 ////////////////////////////////////////////////////////////////////////////////
290 /// Slot for dx2.
291 
292 void TGeoTrd1Editor::DoDx2()
293 {
294  Double_t dx1 = fEDx1->GetNumber();
295  Double_t dx2 = fEDx2->GetNumber();
296  if (dx2<0) {
297  dx2 = 0;
298  fEDx2->SetNumber(dx2);
299  }
300  if (dx1<1.e-6 && dx2<1.e-6) {
301  dx2 = 0.1;
302  fEDx2->SetNumber(dx2);
303  }
304  DoModified();
305  if (!IsDelayed()) DoApply();
306 }
307 
308 ////////////////////////////////////////////////////////////////////////////////
309 /// Slot for dy.
310 
311 void TGeoTrd1Editor::DoDy()
312 {
313  Double_t dy = fEDy->GetNumber();
314  if (dy<=0) {
315  dy = 0.1;
316  fEDy->SetNumber(dy);
317  }
318  DoModified();
319  if (!IsDelayed()) DoApply();
320 }
321 
322 ////////////////////////////////////////////////////////////////////////////////
323 /// Slot for dz.
324 
325 void TGeoTrd1Editor::DoDz()
326 {
327  Double_t dz = fEDz->GetNumber();
328  if (dz<=0) {
329  dz = 0.1;
330  fEDz->SetNumber(dz);
331  }
332  DoModified();
333  if (!IsDelayed()) DoApply();
334 }
335 
336