Logo ROOT   6.14/05
Reference Guide
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 
38 
43 };
44 
45 ////////////////////////////////////////////////////////////////////////////////
46 /// Constructor for volume editor.
47 
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 = "";
58 
59  // TextEntry for shape name
60  MakeTitle("Name");
61  fShapeName = new TGTextEntry(this, new TGTextBuffer(50), kBOX_NAME);
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");
70  // Number entry for dx
71  TGCompositeFrame *f1 = new TGCompositeFrame(compxyz, 118, 10, kHorizontalFrame |
73  f1->AddFrame(new TGLabel(f1, "DX"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
74  fBoxDx = new TGNumberEntry(f1, 0., 5, kBOX_X);
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 |
85  f2->AddFrame(new TGLabel(f2, "DY"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
86  fBoxDy = new TGNumberEntry(f2, 0., 5, kBOX_Y);
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 |
97  f3->AddFrame(new TGLabel(f3, "DZ"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
98  fBoxDz = new TGNumberEntry(f3, 0., 5, kBOX_Z);
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 |
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 |
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 |
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));
163 }
164 
165 ////////////////////////////////////////////////////////////////////////////////
166 /// Destructor.
167 
169 {
170  TGFrameElement *el;
171  TIter next(GetList());
172  while ((el = (TGFrameElement *)next())) {
173  if (el->fFrame->IsComposite())
175  }
176  Cleanup();
177 }
178 
179 ////////////////////////////////////////////////////////////////////////////////
180 /// Connect signals to slots.
181 
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 
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  }
226  fBoxOx->SetNumber(fOrigi[0]);
227  fBoxOy->SetNumber(fOrigi[1]);
228  fBoxOz->SetNumber(fOrigi[2]);
231 
233  SetActive();
234 }
235 
236 ////////////////////////////////////////////////////////////////////////////////
237 /// Check if shape drawing is delayed.
238 
240 {
241  return (fDelayed->GetState() == kButtonDown);
242 }
243 
244 ////////////////////////////////////////////////////////////////////////////////
245 ///Slot for name.
246 
248 {
249  DoModified();
250 }
251 
252 ////////////////////////////////////////////////////////////////////////////////
253 ///Slot for applying current parameters.
254 
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();
269  if (fPad) {
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 
289 {
290  fApply->SetEnabled();
291 }
292 
293 ////////////////////////////////////////////////////////////////////////////////
294 /// Slot for undoing last operation.
295 
297 {
301  fBoxOx->SetNumber(fOrigi[0]);
302  fBoxOy->SetNumber(fOrigi[1]);
303  fBoxOz->SetNumber(fOrigi[2]);
304  DoApply();
307 }
308 
309 ////////////////////////////////////////////////////////////////////////////////
310 ///Slot for Dx modification.
311 
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 
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 
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 
355 {
356  DoModified();
357  if (!IsDelayed()) DoApply();
358 }
359 
360 ////////////////////////////////////////////////////////////////////////////////
361 ///Slot for Oy modification.
362 
364 {
365  DoModified();
366  if (!IsDelayed()) DoApply();
367 }
368 
369 ////////////////////////////////////////////////////////////////////////////////
370 ///Slot for Oz modification.
371 
373 {
374  DoModified();
375  if (!IsDelayed()) DoApply();
376 }
377 
378 
virtual void Resize(UInt_t w=0, UInt_t h=0)
Resize the frame.
Definition: TGFrame.cxx:587
TGTextEntry * fShapeName
void DoUndo()
Slot for undoing last operation.
void DoDx()
Slot for Dx modification.
Box class.
Definition: TGeoBBox.h:17
void DoOz()
Slot for Oz modification.
virtual Double_t GetDX() const
Definition: TGeoBBox.h:70
TGNumberEntry * fBoxOx
image html pict1_TGaxis_012 png width
Define new text attributes for the label number "labNum".
Definition: TGaxis.cxx:2551
TVirtualGeoPainter * GetPainter() const
Definition: TGeoManager.h:191
virtual void SetToolTipText(const char *text, Long_t delayms=500)
Set tool tip text associated with this text entry.
virtual void SetName(const char *name)
Set the name of the TNamed.
Definition: TNamed.cxx:140
virtual void SetNumber(Double_t val)
See TView3D.
Definition: TView.h:25
virtual void SetRange(const Double_t *min, const Double_t *max)=0
virtual Bool_t IsPaintingShape() const =0
TGNumberEntry * fBoxOz
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
virtual Bool_t IsComposite() const
Definition: TGFrame.h:259
Double_t fOrigi[3]
static void Cleanup(TGCompositeFrame *frame)
Static method to cleanup hierarchically all daughters of a composite frame.
virtual const char * ClassName() const
Returns name of class to which the object belongs.
Definition: TObject.cxx:128
ETGeoBBoxWid
ULong_t Pixel_t
Definition: GuiTypes.h:39
void Class()
Definition: Class.C:29
TGNumberEntry * fBoxDx
virtual void ConnectSignals2Slots()
Connect signals to slots.
virtual void SetActive(Bool_t active=kTRUE)
Set active GUI attribute frames related to the selected object.
TGCompositeFrame(const TGCompositeFrame &)
virtual TList * GetList() const
Definition: TGFrame.h:369
Bool_t IsDelayed() const
Check if shape drawing is delayed.
virtual EButtonState GetState() const
Definition: TGButton.h:112
void DoDz()
Slot for Dz modification.
TGTextButton * fApply
void DoDy()
Slot for Dy modification.
virtual TView * GetView() const =0
TGNumberEntry * fBoxDz
virtual const char * GetName() const
Get the shape name.
Definition: TGeoShape.cxx:248
Bool_t Connect(const char *signal, const char *receiver_class, void *receiver, const char *slot)
Non-static method is used to connect from the signal of this object to the receiver slot...
Definition: TQObject.cxx:867
virtual void Associate(const TGWindow *w)
Make w the window that will receive the generated messages.
virtual void SetSize(const TGDimension &s)
Definition: TGFrame.h:299
void DoApply()
Slot for applying current parameters.
Bool_t fIsShapeEditable
virtual void Associate(const TGWindow *w)
Definition: TGWidget.h:84
unsigned int UInt_t
Definition: RtypesCore.h:42
Editor for a TGeoBBox.
virtual const Double_t * GetOrigin() const
Definition: TGeoBBox.h:73
TGFrame * fFrame
Definition: TGLayout.h:119
virtual void ShowAxis()=0
virtual Double_t GetDY() const
Definition: TGeoBBox.h:71
void SetNumAttr(EAttribute attr=kNEAAnyNumber)
void SetBoxDimensions(Double_t dx, Double_t dy, Double_t dz, Double_t *origin=0)
Set parameters of the box.
Definition: TGeoBBox.cxx:900
const Bool_t kFALSE
Definition: RtypesCore.h:88
TGDimension GetSize() const
Definition: TGFrame.h:277
const char * GetText() const
Definition: TGTextEntry.h:134
virtual UInt_t GetDefaultHeight() const
Definition: TGFrame.h:238
TGeoBBox * fShape
void DoModified()
Slot for modifying current parameters.
#define ClassImp(name)
Definition: Rtypes.h:359
R__EXTERN TGeoManager * gGeoManager
Definition: TGeoManager.h:562
double Double_t
Definition: RtypesCore.h:55
virtual void SetEnabled(Bool_t e=kTRUE)
Set enabled or disabled state of button.
Definition: TGButton.cxx:409
virtual void SetModel(TObject *obj)
Update editor for a new selected box.
virtual Double_t GetNumber() const
virtual void AddFrame(TGFrame *f, TGLayoutHints *l=0)
Add frame to the composite frame using the specified layout hints.
Definition: TGFrame.cxx:1099
Mother of all ROOT objects.
Definition: TObject.h:37
void DoOy()
Slot for Oy modification.
TGNumberEntry * fBoxDy
TGNumberEntry * fBoxOy
Bool_t fInit
Definition: TGedFrame.h:53
TGNumberEntryField * GetNumberEntry() const
TGCheckButton * fDelayed
TF1 * f1
Definition: legend1.C:11
virtual void Update()
Override Update from TGedFrame as fGedEditor can be null.
TGeoBBoxEditor(const TGWindow *p=0, Int_t width=140, Int_t height=30, UInt_t options=kChildFrame, Pixel_t back=GetDefaultFrameBackground())
Constructor for volume editor.
void DoName()
Slot for name.
virtual void SetText(const char *text, Bool_t emit=kTRUE)
Sets text entry to text, clears the selection and moves the cursor to the end of the line...
TVirtualPad * fPad
Definition: TGeoGedFrame.h:18
virtual void Cleanup()
Cleanup and delete all objects contained in this composite frame.
Definition: TGFrame.cxx:949
virtual void Draw(Option_t *option="")
Draw this shape.
Definition: TGeoShape.cxx:721
void DoOx()
Slot for Ox modification.
virtual void MakeTitle(const char *title)
Create attribute frame title.
Definition: TGedFrame.cxx:96
char name[80]
Definition: TGX11.cxx:109
TGTextButton * fUndo
Common base class for geombuilder editors.
Definition: TGeoGedFrame.h:13
virtual ~TGeoBBoxEditor()
Destructor.
virtual Double_t GetDZ() const
Definition: TGeoBBox.h:72