Logo ROOT   6.14/05
Reference Guide
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 
38 
42 };
43 
44 ////////////////////////////////////////////////////////////////////////////////
45 /// Constructor for trd1 editor
46 
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 = "";
56 
57  // TextEntry for shape name
58  MakeTitle("Name");
59  fShapeName = new TGTextEntry(this, new TGTextBuffer(50), kTRD1_NAME);
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");
68 
69  // Number entry for dx1
70  TGCompositeFrame *f1 = new TGCompositeFrame(compxyz, 118, 10, kHorizontalFrame |
72  f1->AddFrame(new TGLabel(f1, "DX1"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
73  fEDx1 = new TGNumberEntry(f1, 0., 5, kTRD1_X1);
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 |
84  f1->AddFrame(new TGLabel(f1, "DX2"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
85  fEDx2 = new TGNumberEntry(f1, 0., 5, kTRD1_X2);
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 |
96  f2->AddFrame(new TGLabel(f2, "DY"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
97  fEDy = new TGNumberEntry(f2, 0., 5, kTRD1_Y);
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 |
108  f3->AddFrame(new TGLabel(f3, "DZ"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
109  fEDz = new TGNumberEntry(f3, 0., 5, kTRD1_Z);
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));
136 }
137 
138 ////////////////////////////////////////////////////////////////////////////////
139 /// Destructor
140 
142 {
143  TGFrameElement *el;
144  TIter next(GetList());
145  while ((el = (TGFrameElement *)next())) {
146  if (el->fFrame->IsComposite())
148  }
149  Cleanup();
150 }
151 
152 ////////////////////////////////////////////////////////////////////////////////
153 /// Connect signals to slots.
154 
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 
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  }
194  fEDy->SetNumber(fDyi);
195  fEDz->SetNumber(fDzi);
198 
199 
201  SetActive();
202 }
203 
204 ////////////////////////////////////////////////////////////////////////////////
205 /// Check if shape drawing is delayed.
206 
208 {
209  return (fDelayed->GetState() == kButtonDown);
210 }
211 
212 ////////////////////////////////////////////////////////////////////////////////
213 /// Perform name change.
214 
216 {
217  DoModified();
218 }
219 
220 ////////////////////////////////////////////////////////////////////////////////
221 /// Slot for applying modifications.
222 
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();
240  if (fPad) {
242  fShape->Draw();
243  fPad->GetView()->ShowAxis();
244  } else Update();
245  }
246 }
247 
248 ////////////////////////////////////////////////////////////////////////////////
249 /// Slot for signaling modifications.
250 
252 {
253  fApply->SetEnabled();
254 }
255 
256 ////////////////////////////////////////////////////////////////////////////////
257 /// Slot for undoing last operation.
258 
260 {
263  fEDy->SetNumber(fDyi);
264  fEDz->SetNumber(fDzi);
265  DoApply();
268 }
269 
270 ////////////////////////////////////////////////////////////////////////////////
271 /// Slot for dx1.
272 
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 
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 
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 
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 
virtual void Resize(UInt_t w=0, UInt_t h=0)
Resize the frame.
Definition: TGFrame.cxx:587
Double_t GetDy() const
Definition: TGeoTrd1.h:57
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
void DoModified()
Slot for signaling modifications.
virtual void ConnectSignals2Slots()
Connect signals to slots.
TGNumberEntry * fEDx1
virtual void ComputeBBox()
compute bounding box for a trd1
Definition: TGeoTrd1.cxx:131
virtual void SetNumber(Double_t val)
virtual Bool_t IsPaintingShape() const =0
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
virtual Bool_t IsComposite() const
Definition: TGFrame.h:259
A trapezoid with only x length varying with z.
Definition: TGeoTrd1.h:17
Double_t GetDx2() const
Definition: TGeoTrd1.h:56
static void Cleanup(TGCompositeFrame *frame)
Static method to cleanup hierarchically all daughters of a composite frame.
Bool_t IsDelayed() const
Check if shape drawing is delayed.
virtual const char * ClassName() const
Returns name of class to which the object belongs.
Definition: TObject.cxx:128
virtual ~TGeoTrd1Editor()
Destructor.
ULong_t Pixel_t
Definition: GuiTypes.h:39
void Class()
Definition: Class.C:29
void DoApply()
Slot for applying modifications.
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
virtual EButtonState GetState() const
Definition: TGButton.h:112
TGTextButton * fApply
virtual TView * GetView() const =0
TGTextButton * fUndo
virtual const char * GetName() const
Get the shape name.
Definition: TGeoShape.cxx:248
TGeoTrd1 * fShape
TGNumberEntry * fEDx2
TGNumberEntry * fEDz
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.
TGNumberEntry * fEDy
virtual void SetSize(const TGDimension &s)
Definition: TGFrame.h:299
virtual void Associate(const TGWindow *w)
Definition: TGWidget.h:84
virtual void SetDimensions(Double_t *param)
set trd1 params in one step :
Definition: TGeoTrd1.cxx:655
void DoDy()
Slot for dy.
void DoUndo()
Slot for undoing last operation.
unsigned int UInt_t
Definition: RtypesCore.h:42
TGFrame * fFrame
Definition: TGLayout.h:119
virtual void ShowAxis()=0
void SetNumAttr(EAttribute attr=kNEAAnyNumber)
TGeoTrd1Editor(const TGWindow *p=0, Int_t width=140, Int_t height=30, UInt_t options=kChildFrame, Pixel_t back=GetDefaultFrameBackground())
Constructor for trd1 editor.
const Bool_t kFALSE
Definition: RtypesCore.h:88
TGDimension GetSize() const
Definition: TGFrame.h:277
void DoDz()
Slot for dz.
const char * GetText() const
Definition: TGTextEntry.h:134
virtual UInt_t GetDefaultHeight() const
Definition: TGFrame.h:238
ETGeoTrd1Wid
#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
Editor for a TGeoTrd1.
virtual Double_t GetNumber() const
you should not use this method at all Int_t Int_t Double_t Double_t Double_t e
Definition: TRolke.cxx:630
TGTextEntry * fShapeName
virtual void AddFrame(TGFrame *f, TGLayoutHints *l=0)
Add frame to the composite frame using the specified layout hints.
Definition: TGFrame.cxx:1099
TGCheckButton * fDelayed
Mother of all ROOT objects.
Definition: TObject.h:37
Bool_t fInit
Definition: TGedFrame.h:53
TGNumberEntryField * GetNumberEntry() const
TF1 * f1
Definition: legend1.C:11
virtual void Update()
Override Update from TGedFrame as fGedEditor can be null.
Bool_t fIsShapeEditable
Double_t GetDz() const
Definition: TGeoTrd1.h:58
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...
Double_t GetDx1() const
Definition: TGeoTrd1.h:55
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 DoDx1()
Slot for dx1.
virtual void MakeTitle(const char *title)
Create attribute frame title.
Definition: TGedFrame.cxx:96
virtual void SetModel(TObject *obj)
Connect to the selected object.
void DoName()
Perform name change.
void DoDx2()
Slot for dx2.
char name[80]
Definition: TGX11.cxx:109
Common base class for geombuilder editors.
Definition: TGeoGedFrame.h:13