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