Logo ROOT   6.08/07
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 //////////////////////////////////////////////////////////////////////////
13 // //
14 // TGeoBBoxEditor //
15 // //
16 //////////////////////////////////////////////////////////////////////////
17 //Begin_Html
18 /*
19 <img src="gif/box_pic.gif">
20 */
21 //End_Html
22 //Begin_Html
23 /*
24 <img src="gif/box_ed.jpg">
25 */
26 //End_Html
27 
28 #include "TGeoBBoxEditor.h"
29 #include "TGeoTabManager.h"
30 #include "TGeoBBox.h"
31 #include "TGeoManager.h"
32 #include "TVirtualGeoPainter.h"
33 #include "TPad.h"
34 #include "TView.h"
35 #include "TGTab.h"
36 #include "TGComboBox.h"
37 #include "TGButton.h"
38 #include "TGTextEntry.h"
39 #include "TGNumberEntry.h"
40 #include "TGLabel.h"
41 
43 
48 };
49 
50 ////////////////////////////////////////////////////////////////////////////////
51 /// Constructor for volume editor.
52 
54  Int_t height, UInt_t options, Pixel_t back)
55  : TGeoGedFrame(p, width, height, options | kVerticalFrame, back)
56 {
57  fShape = 0;
58  fDxi = fDyi = fDzi = 0.0;
59  memset(fOrigi, 0, 3*sizeof(Double_t));
60  fNamei = "";
63 
64  // TextEntry for shape name
65  MakeTitle("Name");
66  fShapeName = new TGTextEntry(this, new TGTextBuffer(50), kBOX_NAME);
68  fShapeName->SetToolTipText("Enter the box name");
69  fShapeName->Associate(this);
70  AddFrame(fShapeName, new TGLayoutHints(kLHintsLeft, 3, 1, 2, 5));
71 
72  TGTextEntry *nef;
73  MakeTitle("Box half-lengths");
75  // Number entry for dx
76  TGCompositeFrame *f1 = new TGCompositeFrame(compxyz, 118, 10, kHorizontalFrame |
78  f1->AddFrame(new TGLabel(f1, "DX"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
79  fBoxDx = new TGNumberEntry(f1, 0., 5, kBOX_X);
82  nef->SetToolTipText("Enter the box half-lenth in X");
83  fBoxDx->Associate(this);
84  f1->AddFrame(fBoxDx, new TGLayoutHints(kLHintsLeft | kLHintsExpandX , 2, 2, 4, 4));
85  compxyz->AddFrame(f1, new TGLayoutHints(kLHintsLeft | kLHintsExpandX , 2, 2, 4, 4));
86 
87  // Number entry for dy
88  TGCompositeFrame *f2 = new TGCompositeFrame(compxyz, 118, 10, kHorizontalFrame |
90  f2->AddFrame(new TGLabel(f2, "DY"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
91  fBoxDy = new TGNumberEntry(f2, 0., 5, kBOX_Y);
94  nef->SetToolTipText("Enter the box half-lenth in Y");
95  fBoxDy->Associate(this);
96  f2->AddFrame(fBoxDy, new TGLayoutHints(kLHintsLeft | kLHintsExpandX , 2, 2, 4, 4));
97  compxyz->AddFrame(f2, new TGLayoutHints(kLHintsLeft | kLHintsExpandX , 2, 2, 4, 4));
98 
99  // Number entry for dx
100  TGCompositeFrame *f3 = new TGCompositeFrame(compxyz, 118, 10, kHorizontalFrame |
102  f3->AddFrame(new TGLabel(f3, "DZ"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
103  fBoxDz = new TGNumberEntry(f3, 0., 5, kBOX_Z);
105  nef = (TGTextEntry*)fBoxDz->GetNumberEntry();
106  nef->SetToolTipText("Enter the box half-lenth in Z");
107  fBoxDz->Associate(this);
108  f3->AddFrame(fBoxDz, new TGLayoutHints(kLHintsLeft | kLHintsExpandX , 2, 2, 4, 4));
109  compxyz->AddFrame(f3, new TGLayoutHints(kLHintsLeft | kLHintsExpandX , 2, 2, 4, 4));
110 
111  compxyz->Resize(150,30);
112  AddFrame(compxyz, new TGLayoutHints(kLHintsLeft, 6, 6, 4, 4));
113 
114  MakeTitle("Box origin");
115  compxyz = new TGCompositeFrame(this, 118, 30, kVerticalFrame | kRaisedFrame | kDoubleBorder);
116  // Number entry for dx
117  f1 = new TGCompositeFrame(compxyz, 118, 10, kHorizontalFrame |
119  f1->AddFrame(new TGLabel(f1, "OX"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
120  fBoxOx = new TGNumberEntry(f1, 0., 5, kBOX_OX);
121  nef = (TGTextEntry*)fBoxOx->GetNumberEntry();
122  nef->SetToolTipText("Enter the box origin X coordinate");
123  fBoxOx->Associate(this);
124  f1->AddFrame(fBoxOx, new TGLayoutHints(kLHintsLeft | kLHintsExpandX , 2, 2, 4, 4));
125  compxyz->AddFrame(f1, new TGLayoutHints(kLHintsLeft | kLHintsExpandX , 2, 2, 4, 4));
126 
127  // Number entry for dy
128  f2 = new TGCompositeFrame(compxyz, 118, 10, kHorizontalFrame |
130  f2->AddFrame(new TGLabel(f2, "OY"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
131  fBoxOy = new TGNumberEntry(f2, 0., 5, kBOX_OY);
132  nef = (TGTextEntry*)fBoxOy->GetNumberEntry();
133  nef->SetToolTipText("Enter the box origin Y coordinate");
134  fBoxOy->Associate(this);
135  f2->AddFrame(fBoxOy, new TGLayoutHints(kLHintsLeft | kLHintsExpandX , 2, 2, 4, 4));
136  compxyz->AddFrame(f2, new TGLayoutHints(kLHintsLeft | kLHintsExpandX , 2, 2, 4, 4));
137 
138  // Number entry for dx
139  f3 = new TGCompositeFrame(compxyz, 118, 10, kHorizontalFrame |
141  f3->AddFrame(new TGLabel(f3, "OZ"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
142  fBoxOz = new TGNumberEntry(f3, 0., 5, kBOX_OZ);
143  nef = (TGTextEntry*)fBoxOz->GetNumberEntry();
144  nef->SetToolTipText("Enter the box origin Z coordinate");
145  fBoxOz->Associate(this);
146  f3->AddFrame(fBoxOz, new TGLayoutHints(kLHintsLeft | kLHintsExpandX , 2, 2, 4, 4));
147  compxyz->AddFrame(f3, new TGLayoutHints(kLHintsLeft | kLHintsExpandX , 2, 2, 4, 4));
148 
149  compxyz->Resize(150,30);
150  AddFrame(compxyz, new TGLayoutHints(kLHintsLeft, 6, 6, 4, 4));
151 
152  // Delayed draw
153  f1 = new TGCompositeFrame(this, 155, 10, kHorizontalFrame | kFixedWidth | kSunkenFrame);
154  fDelayed = new TGCheckButton(f1, "Delayed draw");
155  f1->AddFrame(fDelayed, new TGLayoutHints(kLHintsLeft , 2, 2, 4, 4));
156  AddFrame(f1, new TGLayoutHints(kLHintsLeft, 6, 6, 4, 4));
157 
158  // Buttons
159  f1 = new TGCompositeFrame(this, 155, 10, kHorizontalFrame | kFixedWidth);
160  fApply = new TGTextButton(f1, "Apply");
161  f1->AddFrame(fApply, new TGLayoutHints(kLHintsLeft, 2, 2, 4, 4));
162  fApply->Associate(this);
163  fUndo = new TGTextButton(f1, "Undo");
164  f1->AddFrame(fUndo, new TGLayoutHints(kLHintsRight , 2, 2, 4, 4));
165  fUndo->Associate(this);
166  AddFrame(f1, new TGLayoutHints(kLHintsLeft, 6, 6, 4, 4));
168 }
169 
170 ////////////////////////////////////////////////////////////////////////////////
171 /// Destructor.
172 
174 {
175  TGFrameElement *el;
176  TIter next(GetList());
177  while ((el = (TGFrameElement *)next())) {
178  if (el->fFrame->IsComposite())
180  }
181  Cleanup();
182 }
183 
184 ////////////////////////////////////////////////////////////////////////////////
185 /// Connect signals to slots.
186 
188 {
189  fApply->Connect("Clicked()", "TGeoBBoxEditor", this, "DoApply()");
190  fUndo->Connect("Clicked()", "TGeoBBoxEditor", this, "DoUndo()");
191  fShapeName->Connect("TextChanged(const char *)", "TGeoBBoxEditor", this, "DoModified()");
192  fBoxDx->Connect("ValueSet(Long_t)", "TGeoBBoxEditor", this, "DoDx()");
193  fBoxDy->Connect("ValueSet(Long_t)", "TGeoBBoxEditor", this, "DoDy()");
194  fBoxDz->Connect("ValueSet(Long_t)", "TGeoBBoxEditor", this, "DoDz()");
195  fBoxDx->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoBBoxEditor", this, "DoModified()");
196  fBoxDy->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoBBoxEditor", this, "DoModified()");
197  fBoxDz->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoBBoxEditor", this, "DoModified()");
198  fBoxOx->Connect("ValueSet(Long_t)", "TGeoBBoxEditor", this, "DoOx()");
199  fBoxOy->Connect("ValueSet(Long_t)", "TGeoBBoxEditor", this, "DoOy()");
200  fBoxOz->Connect("ValueSet(Long_t)", "TGeoBBoxEditor", this, "DoOz()");
201  fBoxOx->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoBBoxEditor", this, "DoModified()");
202  fBoxOy->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoBBoxEditor", this, "DoModified()");
203  fBoxOz->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoBBoxEditor", this, "DoModified()");
204  fInit = kFALSE;
205 }
206 
207 
208 ////////////////////////////////////////////////////////////////////////////////
209 /// Update editor for a new selected box.
210 
212 {
213  if (obj == 0 || (obj->IsA()!=TGeoBBox::Class())) {
214  SetActive(kFALSE);
215  return;
216  }
217  fShape = (TGeoBBox*)obj;
218  fDxi = fShape->GetDX();
219  fDyi = fShape->GetDY();
220  fDzi = fShape->GetDZ();
221  memcpy(fOrigi, fShape->GetOrigin(), 3*sizeof(Double_t));
222  const char *sname = fShape->GetName();
223  if (!strcmp(sname, fShape->ClassName())) fShapeName->SetText("-no_name");
224  else {
225  fShapeName->SetText(sname);
226  fNamei = sname;
227  }
231  fBoxOx->SetNumber(fOrigi[0]);
232  fBoxOy->SetNumber(fOrigi[1]);
233  fBoxOz->SetNumber(fOrigi[2]);
236 
238  SetActive();
239 }
240 
241 ////////////////////////////////////////////////////////////////////////////////
242 /// Check if shape drawing is delayed.
243 
245 {
246  return (fDelayed->GetState() == kButtonDown);
247 }
248 
249 ////////////////////////////////////////////////////////////////////////////////
250 ///Slot for name.
251 
253 {
254  DoModified();
255 }
256 
257 ////////////////////////////////////////////////////////////////////////////////
258 ///Slot for applying current parameters.
259 
261 {
262  const char *name = fShapeName->GetText();
263  if (strcmp(name,fShape->GetName())) fShape->SetName(name);
264  Double_t dx = fBoxDx->GetNumber();
265  Double_t dy = fBoxDy->GetNumber();
266  Double_t dz = fBoxDz->GetNumber();
267  Double_t orig[3];
268  orig[0] = fBoxOx->GetNumber();
269  orig[1] = fBoxOy->GetNumber();
270  orig[2] = fBoxOz->GetNumber();
271  fShape->SetBoxDimensions(dx, dy, dz, orig);
272  fUndo->SetEnabled();
274  if (fPad) {
276  TView *view = fPad->GetView();
277  if (!view) {
278  fShape->Draw();
279  fPad->GetView()->ShowAxis();
280  } else {
281  const Double_t *origin = fShape->GetOrigin();
282  view->SetRange(origin[0]-fShape->GetDX(), origin[1]-fShape->GetDY(), origin[2]-fShape->GetDZ(),
283  origin[0]+fShape->GetDX(), origin[1]+fShape->GetDY(), origin[2]+fShape->GetDZ());
284  Update();
285  }
286  } else Update();
287  }
288 }
289 
290 ////////////////////////////////////////////////////////////////////////////////
291 ///Slot for modifying current parameters.
292 
294 {
295  fApply->SetEnabled();
296 }
297 
298 ////////////////////////////////////////////////////////////////////////////////
299 /// Slot for undoing last operation.
300 
302 {
306  fBoxOx->SetNumber(fOrigi[0]);
307  fBoxOy->SetNumber(fOrigi[1]);
308  fBoxOz->SetNumber(fOrigi[2]);
309  DoApply();
312 }
313 
314 ////////////////////////////////////////////////////////////////////////////////
315 ///Slot for Dx modification.
316 
318 {
319  Double_t dx = fBoxDx->GetNumber();
320  if (dx<=0) {
321  dx=0.1;
322  fBoxDx->SetNumber(dx);
323  }
324  DoModified();
325  if (!IsDelayed()) DoApply();
326 }
327 
328 ////////////////////////////////////////////////////////////////////////////////
329 ///Slot for Dy modification.
330 
332 {
333  Double_t dy = fBoxDy->GetNumber();
334  if (dy<=0) {
335  dy=0.1;
336  fBoxDy->SetNumber(dy);
337  }
338  DoModified();
339  if (!IsDelayed()) DoApply();
340 }
341 
342 ////////////////////////////////////////////////////////////////////////////////
343 ///Slot for Dz modification.
344 
346 {
347  Double_t dz = fBoxDz->GetNumber();
348  if (dz<=0) {
349  dz=0.1;
350  fBoxDz->SetNumber(dz);
351  }
352  DoModified();
353  if (!IsDelayed()) DoApply();
354 }
355 
356 ////////////////////////////////////////////////////////////////////////////////
357 ///Slot for Ox modification.
358 
360 {
361  DoModified();
362  if (!IsDelayed()) DoApply();
363 }
364 
365 ////////////////////////////////////////////////////////////////////////////////
366 ///Slot for Oy modification.
367 
369 {
370  DoModified();
371  if (!IsDelayed()) DoApply();
372 }
373 
374 ////////////////////////////////////////////////////////////////////////////////
375 ///Slot for Oz modification.
376 
378 {
379  DoModified();
380  if (!IsDelayed()) DoApply();
381 }
382 
383 
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:19
void DoOz()
Slot for Oz modification.
virtual Double_t GetDX() const
Definition: TGeoBBox.h:72
TGNumberEntry * fBoxOx
TVirtualGeoPainter * GetPainter() const
Definition: TGeoManager.h:187
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:131
virtual void SetNumber(Double_t val)
See TView3D.
Definition: TView.h:29
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
const Bool_t kFALSE
Definition: Rtypes.h:92
virtual Bool_t IsComposite() const
Definition: TGFrame.h:275
const char * Class
Definition: TXMLSetup.cxx:64
Double_t fOrigi[3]
static void Cleanup(TGCompositeFrame *frame)
Static method to cleanup hirarchically all daughters of a composite frame.
virtual const char * ClassName() const
Returns name of class to which the object belongs.
Definition: TObject.cxx:188
ETGeoBBoxWid
ULong_t Pixel_t
Definition: GuiTypes.h:41
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:385
Bool_t IsDelayed() const
Check if shape drawing is delayed.
virtual EButtonState GetState() const
Definition: TGButton.h:116
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:250
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:1137
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:315
void DoApply()
Slot for applying current parameters.
Bool_t fIsShapeEditable
virtual void Associate(const TGWindow *w)
Definition: TGWidget.h:90
unsigned int UInt_t
Definition: RtypesCore.h:42
virtual const Double_t * GetOrigin() const
Definition: TGeoBBox.h:75
TGFrame * fFrame
Definition: TGLayout.h:125
virtual void ShowAxis()=0
const std::string sname
Definition: testIO.cxx:45
virtual Double_t GetDY() const
Definition: TGeoBBox.h:73
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
TGDimension GetSize() const
Definition: TGFrame.h:293
const char * GetText() const
Definition: TGTextEntry.h:140
virtual UInt_t GetDefaultHeight() const
Definition: TGFrame.h:254
TGeoBBox * fShape
void DoModified()
Slot for modifying current parameters.
#define ClassImp(name)
Definition: Rtypes.h:279
R__EXTERN TGeoManager * gGeoManager
Definition: TGeoManager.h:554
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:55
TGNumberEntryField * GetNumberEntry() const
double f2(const double *x)
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:28
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:723
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
virtual ~TGeoBBoxEditor()
Destructor.
virtual Double_t GetDZ() const
Definition: TGeoBBox.h:74