ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups 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 //////////////////////////////////////////////////////////////////////////
13 // //
14 // TGeoTrd2Editor //
15 // //
16 //////////////////////////////////////////////////////////////////////////
17 //Begin_Html
18 /*
19 <img src="gif/trd2_pic.gif">
20 */
21 //End_Html
22 //Begin_Html
23 /*
24 <img src="gif/trd2_ed.jpg">
25 */
26 //End_Html
27 
28 #include "TGeoTrd2Editor.h"
29 #include "TGeoTabManager.h"
30 #include "TGeoTrd2.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 
44 enum ETGeoTrd2Wid {
45  kTRD2_NAME, kTRD2_X1, kTRD2_X2, kTRD2_Y1, kTRD2_Y2, kTRD2_Z,
46  kTRD2_APPLY, kTRD2_UNDO
47 };
48 
49 ////////////////////////////////////////////////////////////////////////////////
50 /// Constructor for trd2 editor
51 
53  Int_t height, UInt_t options, Pixel_t back)
54  : TGeoGedFrame(p, width, height, options | kVerticalFrame, back)
55 {
56  fShape = 0;
57  fDxi1 = fDxi2 = fDyi1 = fDyi2 = fDzi = 0.0;
58  fNamei = "";
61 
62  // TextEntry for shape name
63  MakeTitle("Name");
64  fShapeName = new TGTextEntry(this, new TGTextBuffer(50), kTRD2_NAME);
66  fShapeName->SetToolTipText("Enter the box name");
67  fShapeName->Associate(this);
68  AddFrame(fShapeName, new TGLayoutHints(kLHintsLeft, 3, 1, 2, 5));
69 
70  TGTextEntry *nef;
71  MakeTitle("Trd2 dimensions");
73 
74  // Number entry for dx1
75  TGCompositeFrame *f1 = new TGCompositeFrame(compxyz, 118, 10, kHorizontalFrame |
77  f1->AddFrame(new TGLabel(f1, "DX1"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
78  fEDx1 = new TGNumberEntry(f1, 0., 5, kTRD2_X1);
80  nef = (TGTextEntry*)fEDx1->GetNumberEntry();
81  nef->SetToolTipText("Enter the half-lenth in X1");
82  fEDx1->Associate(this);
83  f1->AddFrame(fEDx1, new TGLayoutHints(kLHintsLeft | kLHintsExpandX , 2, 2, 4, 4));
84  compxyz->AddFrame(f1, new TGLayoutHints(kLHintsLeft | kLHintsExpandX , 2, 2, 4, 4));
85 
86  // Number entry for dx2
87  f1 = new TGCompositeFrame(compxyz, 118, 10, kHorizontalFrame |
89  f1->AddFrame(new TGLabel(f1, "DX2"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
90  fEDx2 = new TGNumberEntry(f1, 0., 5, kTRD2_X2);
92  nef = (TGTextEntry*)fEDx2->GetNumberEntry();
93  nef->SetToolTipText("Enter the half-lenth in X2");
94  fEDx2->Associate(this);
95  f1->AddFrame(fEDx2, new TGLayoutHints(kLHintsLeft | kLHintsExpandX , 2, 2, 4, 4));
96  compxyz->AddFrame(f1, new TGLayoutHints(kLHintsLeft | kLHintsExpandX , 2, 2, 4, 4));
97 
98  // Number entry for dy1
99  TGCompositeFrame *f2 = new TGCompositeFrame(compxyz, 118, 10, kHorizontalFrame |
101  f2->AddFrame(new TGLabel(f2, "DY1"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
102  fEDy1 = new TGNumberEntry(f2, 0., 5, kTRD2_Y1);
104  nef = (TGTextEntry*)fEDy1->GetNumberEntry();
105  nef->SetToolTipText("Enter the half-lenth in Y1");
106  fEDy1->Associate(this);
107  f2->AddFrame(fEDy1, new TGLayoutHints(kLHintsLeft | kLHintsExpandX , 2, 2, 4, 4));
108  compxyz->AddFrame(f2, new TGLayoutHints(kLHintsLeft | kLHintsExpandX , 2, 2, 4, 4));
109 
110  // Number entry for dy2
111  f2 = new TGCompositeFrame(compxyz, 118, 10, kHorizontalFrame |
113  f2->AddFrame(new TGLabel(f2, "DY2"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
114  fEDy2 = new TGNumberEntry(f2, 0., 5, kTRD2_Y2);
116  nef = (TGTextEntry*)fEDy2->GetNumberEntry();
117  nef->SetToolTipText("Enter the half-lenth in Y2");
118  fEDy2->Associate(this);
119  f2->AddFrame(fEDy2, new TGLayoutHints(kLHintsLeft | kLHintsExpandX , 2, 2, 4, 4));
120  compxyz->AddFrame(f2, new TGLayoutHints(kLHintsLeft | kLHintsExpandX , 2, 2, 4, 4));
121 
122  // Number entry for dz
123  TGCompositeFrame *f3 = new TGCompositeFrame(compxyz, 118, 10, kHorizontalFrame |
125  f3->AddFrame(new TGLabel(f3, "DZ"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
126  fEDz = new TGNumberEntry(f3, 0., 5, kTRD2_Z);
128  nef = (TGTextEntry*)fEDz->GetNumberEntry();
129  nef->SetToolTipText("Enter the half-lenth in Z");
130  fEDz->Associate(this);
131  f3->AddFrame(fEDz, new TGLayoutHints(kLHintsLeft | kLHintsExpandX , 2, 2, 4, 4));
132  compxyz->AddFrame(f3, new TGLayoutHints(kLHintsLeft | kLHintsExpandX , 2, 2, 4, 4));
133 
134  compxyz->Resize(150,30);
135  AddFrame(compxyz, new TGLayoutHints(kLHintsLeft, 6, 6, 4, 4));
136 
137  // Delayed draw
138  f1 = new TGCompositeFrame(this, 155, 10, kHorizontalFrame | kFixedWidth | kSunkenFrame);
139  fDelayed = new TGCheckButton(f1, "Delayed draw");
140  f1->AddFrame(fDelayed, new TGLayoutHints(kLHintsLeft , 2, 2, 4, 4));
141  AddFrame(f1, new TGLayoutHints(kLHintsLeft, 6, 6, 4, 4));
142 
143  // Buttons
144  f1 = new TGCompositeFrame(this, 155, 10, kHorizontalFrame | kFixedWidth);
145  fApply = new TGTextButton(f1, "Apply");
146  f1->AddFrame(fApply, new TGLayoutHints(kLHintsLeft, 2, 2, 4, 4));
147  fApply->Associate(this);
148  fUndo = new TGTextButton(f1, "Undo");
149  f1->AddFrame(fUndo, new TGLayoutHints(kLHintsRight , 2, 2, 4, 4));
150  fUndo->Associate(this);
151  AddFrame(f1, new TGLayoutHints(kLHintsLeft, 6, 6, 4, 4));
153 }
154 
155 ////////////////////////////////////////////////////////////////////////////////
156 /// Destructor.
157 
159 {
160  TGFrameElement *el;
161  TIter next(GetList());
162  while ((el = (TGFrameElement *)next())) {
163  if (el->fFrame->IsComposite())
165  }
166  Cleanup();
167 }
168 
169 ////////////////////////////////////////////////////////////////////////////////
170 /// Connect signals to slots.
171 
173 {
174  fApply->Connect("Clicked()", "TGeoTrd2Editor", this, "DoApply()");
175  fUndo->Connect("Clicked()", "TGeoTrd2Editor", this, "DoUndo()");
176  fShapeName->Connect("TextChanged(const char *)", "TGeoTrd2Editor", this, "DoModified()");
177  fEDx1->Connect("ValueSet(Long_t)", "TGeoTrd2Editor", this, "DoDx1()");
178  fEDx2->Connect("ValueSet(Long_t)", "TGeoTrd2Editor", this, "DoDx2()");
179  fEDy1->Connect("ValueSet(Long_t)", "TGeoTrd2Editor", this, "DoDy1()");
180  fEDy2->Connect("ValueSet(Long_t)", "TGeoTrd2Editor", this, "DoDy2()");
181  fEDz->Connect("ValueSet(Long_t)", "TGeoTrd2Editor", this, "DoDz()");
182  fEDx1->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoTrd2Editor", this, "DoModified()");
183  fEDx2->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoTrd2Editor", this, "DoModified()");
184  fEDy1->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoTrd2Editor", this, "DoModified()");
185  fEDy2->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoTrd2Editor", this, "DoModified()");
186  fEDz->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoTrd2Editor", this, "DoModified()");
187  fInit = kFALSE;
188 }
189 
190 
191 ////////////////////////////////////////////////////////////////////////////////
192 /// Connect to the selected object.
193 
195 {
196  if (obj == 0 || (obj->IsA()!=TGeoTrd2::Class())) {
197  SetActive(kFALSE);
198  return;
199  }
200  fShape = (TGeoTrd2*)obj;
201  fDxi1 = fShape->GetDx1();
202  fDxi2 = fShape->GetDx2();
203  fDyi1 = fShape->GetDy1();
204  fDyi2 = fShape->GetDy2();
205  fDzi = fShape->GetDz();
206  const char *sname = fShape->GetName();
207  if (!strcmp(sname, fShape->ClassName())) fShapeName->SetText("-no_name");
208  else {
209  fShapeName->SetText(sname);
210  fNamei = sname;
211  }
216  fEDz->SetNumber(fDzi);
219 
221  SetActive();
222 }
223 
224 ////////////////////////////////////////////////////////////////////////////////
225 /// Check if shape drawing is delayed.
226 
228 {
229  return (fDelayed->GetState() == kButtonDown);
230 }
231 
232 ////////////////////////////////////////////////////////////////////////////////
233 /// Perform name change.
234 
236 {
237  DoModified();
238 }
239 
240 ////////////////////////////////////////////////////////////////////////////////
241 /// Slot for applying modifications.
242 
244 {
245  const char *name = fShapeName->GetText();
246  if (strcmp(name,fShape->GetName())) fShape->SetName(name);
247  Double_t dx1 = fEDx1->GetNumber();
248  Double_t dx2 = fEDx2->GetNumber();
249  Double_t dy1 = fEDy1->GetNumber();
250  Double_t dy2 = fEDy2->GetNumber();
251  Double_t dz = fEDz->GetNumber();
252  Double_t param[5];
253  param[0] = dx1;
254  param[1] = dx2;
255  param[2] = dy1;
256  param[3] = dy2;
257  param[4] = dz;
258  fShape->SetDimensions(param);
259  fShape->ComputeBBox();
260  fUndo->SetEnabled();
262  if (fPad) {
264  fShape->Draw();
265  fPad->GetView()->ShowAxis();
266  } else Update();
267  }
268 }
269 
270 ////////////////////////////////////////////////////////////////////////////////
271 /// Slot for signaling modifications.
272 
274 {
275  fApply->SetEnabled();
276 }
277 
278 ////////////////////////////////////////////////////////////////////////////////
279 /// Slot for undoing last operation.
280 
282 {
287  fEDz->SetNumber(fDzi);
288  DoApply();
291 }
292 
293 ////////////////////////////////////////////////////////////////////////////////
294 /// Slot for dx1.
295 
297 {
298  Double_t dx1 = fEDx1->GetNumber();
299  Double_t dx2 = fEDx2->GetNumber();
300  if (dx1<0) {
301  dx1 = 0;
302  fEDx1->SetNumber(dx1);
303  }
304  if (dx1<1.e-6 && dx2<1.e-6) {
305  dx1 = 0.1;
306  fEDx1->SetNumber(dx1);
307  }
308  DoModified();
309  if (!IsDelayed()) DoApply();
310 }
311 
312 ////////////////////////////////////////////////////////////////////////////////
313 /// Slot for dx2.
314 
316 {
317  Double_t dx1 = fEDx1->GetNumber();
318  Double_t dx2 = fEDx2->GetNumber();
319  if (dx2<0) {
320  dx2 = 0;
321  fEDx2->SetNumber(dx2);
322  }
323  if (dx1<1.e-6 && dx2<1.e-6) {
324  dx2 = 0.1;
325  fEDx2->SetNumber(dx2);
326  }
327  DoModified();
328  if (!IsDelayed()) DoApply();
329 }
330 
331 ////////////////////////////////////////////////////////////////////////////////
332 /// Slot for dy1.
333 
335 {
336  Double_t dy1 = fEDy1->GetNumber();
337  Double_t dy2 = fEDy2->GetNumber();
338  if (dy1<0) {
339  dy1 = 0;
340  fEDy1->SetNumber(dy1);
341  }
342  if (dy1<1.e-6 && dy2<1.e-6) {
343  dy1 = 0.1;
344  fEDy1->SetNumber(dy1);
345  }
346  DoModified();
347  if (!IsDelayed()) DoApply();
348 }
349 
350 ////////////////////////////////////////////////////////////////////////////////
351 /// Slot for dy2.
352 
354 {
355  Double_t dy1 = fEDy1->GetNumber();
356  Double_t dy2 = fEDy2->GetNumber();
357  if (dy2<0) {
358  dy2 = 0;
359  fEDy2->SetNumber(dy2);
360  }
361  if (dy1<1.e-6 && dy2<1.e-6) {
362  dy2 = 0.1;
363  fEDy2->SetNumber(dy2);
364  }
365  DoModified();
366  if (!IsDelayed()) DoApply();
367 }
368 
369 ////////////////////////////////////////////////////////////////////////////////
370 /// Slot for dz.
371 
373 {
374  Double_t dz = fEDz->GetNumber();
375  if (dz<=0) {
376  dz = 0.1;
377  fEDz->SetNumber(dz);
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
ClassImp(TSeqCollection) Int_t TSeqCollection TIter next(this)
Return index of object in collection.
void DoApply()
Slot for applying modifications.
TGTextButton * fUndo
virtual Bool_t IsComposite() const
Definition: TGFrame.h:275
virtual void SetToolTipText(const char *text, Long_t delayms=500)
Set tool tip text associated with this text entry.
TGNumberEntry * fEDy2
virtual void SetName(const char *name)
Change (i.e.
Definition: TNamed.cxx:128
tuple f2
Definition: surfaces.py:24
TGNumberEntry * fEDx2
void f3()
Definition: na49.C:50
void DoUndo()
Slot for undoing last operation.
virtual void SetNumber(Double_t val)
virtual Bool_t IsPaintingShape() const =0
virtual TList * GetList() const
Definition: TGFrame.h:385
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
const Bool_t kFALSE
Definition: Rtypes.h:92
TGNumberEntry * fEDy1
void DoDx2()
Slot for dx2.
Double_t GetDy1() const
Definition: TGeoTrd2.h:69
void DoDx1()
Slot for dx1.
static void Cleanup(TGCompositeFrame *frame)
Static method to cleanup hirarchically all daughters of a composite frame.
Double_t GetDx1() const
Definition: TGeoTrd2.h:67
virtual void ConnectSignals2Slots()
Connect signals to slots.
TGNumberEntryField * GetNumberEntry() const
ULong_t Pixel_t
Definition: GuiTypes.h:41
TGeoTrd2 * fShape
void Class()
Definition: Class.C:29
const char * GetText() const
Definition: TGTextEntry.h:140
TVirtualGeoPainter * GetPainter() const
Definition: TGeoManager.h:193
virtual void SetActive(Bool_t active=kTRUE)
Set active GUI attribute frames related to the selected object.
TGNumberEntry * fEDz
TGCompositeFrame(const TGCompositeFrame &)
virtual void ComputeBBox()
compute bounding box for a trd2
Definition: TGeoTrd2.cxx:133
virtual void SetModel(TObject *obj)
Connect to the selected object.
virtual TView * GetView() const =0
Double_t GetDy2() const
Definition: TGeoTrd2.h:70
void DoModified()
Slot for signaling modifications.
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:1135
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
Double_t GetDz() const
Definition: TGeoTrd2.h:71
TGeoTrd2Editor(const TGWindow *p=0, Int_t width=140, Int_t height=30, UInt_t options=kChildFrame, Pixel_t back=GetDefaultFrameBackground())
Constructor for trd2 editor.
void DoDy2()
Slot for dy2.
virtual EButtonState GetState() const
Definition: TGButton.h:116
virtual const char * ClassName() const
Returns name of class to which the object belongs.
Definition: TObject.cxx:187
virtual void Associate(const TGWindow *w)
Definition: TGWidget.h:90
unsigned int UInt_t
Definition: RtypesCore.h:42
void DoDy1()
Slot for dy1.
TGFrame * fFrame
Definition: TGLayout.h:125
virtual void ShowAxis()=0
Bool_t IsDelayed() const
Check if shape drawing is delayed.
const std::string sname
Definition: testIO.cxx:45
TGCheckButton * fDelayed
void DoName()
Perform name change.
virtual const char * GetName() const
Get the shape name.
Definition: TGeoShape.cxx:247
void SetNumAttr(EAttribute attr=kNEAAnyNumber)
virtual void SetDimensions(Double_t *param)
set arb8 params in one step :
Definition: TGeoTrd2.cxx:686
R__EXTERN TGeoManager * gGeoManager
Definition: TGeoManager.h:556
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
TGDimension GetSize() const
Definition: TGFrame.h:293
Double_t GetDx2() const
Definition: TGeoTrd2.h:68
virtual void AddFrame(TGFrame *f, TGLayoutHints *l=0)
Add frame to the composite frame using the specified layout hints.
Definition: TGFrame.cxx:1099
TGTextEntry * fShapeName
TGNumberEntry * fEDx1
#define name(a, b)
Definition: linkTestLib0.cpp:5
ClassImp(TGeoTrd2Editor) enum ETGeoTrd2Wid
Mother of all ROOT objects.
Definition: TObject.h:58
Bool_t fIsShapeEditable
Bool_t fInit
Definition: TGedFrame.h:55
virtual UInt_t GetDefaultHeight() const
Definition: TGFrame.h:254
TF1 * f1
Definition: legend1.C:11
virtual void Update()
Override Update from TGedFrame as fGedEditor can be null.
TGTextButton * fApply
virtual Double_t GetNumber() const
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:720
TObject * obj
virtual void MakeTitle(const char *title)
Create attribute frame title.
Definition: TGedFrame.cxx:96
void DoDz()
Slot for dz.
virtual ~TGeoTrd2Editor()
Destructor.