Logo ROOT   6.14/05
Reference Guide
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 /** \class TGeoTrd2Editor
13 \ingroup Geometry_builder
14 
15 Editor for a TGeoTrd2.
16 
17 \image html geom_trd2_pic.png
18 
19 \image html geom_trd2_ed.png
20 
21 */
22 
23 #include "TGeoTrd2Editor.h"
24 #include "TGeoTabManager.h"
25 #include "TGeoTrd2.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 trd2 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 = fDyi1 = fDyi2 = fDzi = 0.0;
53  fNamei = "";
56 
57  // TextEntry for shape name
58  MakeTitle("Name");
59  fShapeName = new TGTextEntry(this, new TGTextBuffer(50), kTRD2_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("Trd2 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, kTRD2_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, kTRD2_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 dy1
94  TGCompositeFrame *f2 = new TGCompositeFrame(compxyz, 118, 10, kHorizontalFrame |
96  f2->AddFrame(new TGLabel(f2, "DY1"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
97  fEDy1 = new TGNumberEntry(f2, 0., 5, kTRD2_Y1);
99  nef = (TGTextEntry*)fEDy1->GetNumberEntry();
100  nef->SetToolTipText("Enter the half-length in Y1");
101  fEDy1->Associate(this);
102  f2->AddFrame(fEDy1, 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 dy2
106  f2 = new TGCompositeFrame(compxyz, 118, 10, kHorizontalFrame |
108  f2->AddFrame(new TGLabel(f2, "DY2"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
109  fEDy2 = new TGNumberEntry(f2, 0., 5, kTRD2_Y2);
111  nef = (TGTextEntry*)fEDy2->GetNumberEntry();
112  nef->SetToolTipText("Enter the half-length in Y2");
113  fEDy2->Associate(this);
114  f2->AddFrame(fEDy2, new TGLayoutHints(kLHintsLeft | kLHintsExpandX , 2, 2, 4, 4));
115  compxyz->AddFrame(f2, new TGLayoutHints(kLHintsLeft | kLHintsExpandX , 2, 2, 4, 4));
116 
117  // Number entry for dz
118  TGCompositeFrame *f3 = new TGCompositeFrame(compxyz, 118, 10, kHorizontalFrame |
120  f3->AddFrame(new TGLabel(f3, "DZ"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
121  fEDz = new TGNumberEntry(f3, 0., 5, kTRD2_Z);
123  nef = (TGTextEntry*)fEDz->GetNumberEntry();
124  nef->SetToolTipText("Enter the half-length in Z");
125  fEDz->Associate(this);
126  f3->AddFrame(fEDz, new TGLayoutHints(kLHintsLeft | kLHintsExpandX , 2, 2, 4, 4));
127  compxyz->AddFrame(f3, new TGLayoutHints(kLHintsLeft | kLHintsExpandX , 2, 2, 4, 4));
128 
129  compxyz->Resize(150,30);
130  AddFrame(compxyz, new TGLayoutHints(kLHintsLeft, 6, 6, 4, 4));
131 
132  // Delayed draw
133  f1 = new TGCompositeFrame(this, 155, 10, kHorizontalFrame | kFixedWidth | kSunkenFrame);
134  fDelayed = new TGCheckButton(f1, "Delayed draw");
135  f1->AddFrame(fDelayed, new TGLayoutHints(kLHintsLeft , 2, 2, 4, 4));
136  AddFrame(f1, new TGLayoutHints(kLHintsLeft, 6, 6, 4, 4));
137 
138  // Buttons
139  f1 = new TGCompositeFrame(this, 155, 10, kHorizontalFrame | kFixedWidth);
140  fApply = new TGTextButton(f1, "Apply");
141  f1->AddFrame(fApply, new TGLayoutHints(kLHintsLeft, 2, 2, 4, 4));
142  fApply->Associate(this);
143  fUndo = new TGTextButton(f1, "Undo");
144  f1->AddFrame(fUndo, new TGLayoutHints(kLHintsRight , 2, 2, 4, 4));
145  fUndo->Associate(this);
146  AddFrame(f1, new TGLayoutHints(kLHintsLeft, 6, 6, 4, 4));
148 }
149 
150 ////////////////////////////////////////////////////////////////////////////////
151 /// Destructor.
152 
154 {
155  TGFrameElement *el;
156  TIter next(GetList());
157  while ((el = (TGFrameElement *)next())) {
158  if (el->fFrame->IsComposite())
160  }
161  Cleanup();
162 }
163 
164 ////////////////////////////////////////////////////////////////////////////////
165 /// Connect signals to slots.
166 
168 {
169  fApply->Connect("Clicked()", "TGeoTrd2Editor", this, "DoApply()");
170  fUndo->Connect("Clicked()", "TGeoTrd2Editor", this, "DoUndo()");
171  fShapeName->Connect("TextChanged(const char *)", "TGeoTrd2Editor", this, "DoModified()");
172  fEDx1->Connect("ValueSet(Long_t)", "TGeoTrd2Editor", this, "DoDx1()");
173  fEDx2->Connect("ValueSet(Long_t)", "TGeoTrd2Editor", this, "DoDx2()");
174  fEDy1->Connect("ValueSet(Long_t)", "TGeoTrd2Editor", this, "DoDy1()");
175  fEDy2->Connect("ValueSet(Long_t)", "TGeoTrd2Editor", this, "DoDy2()");
176  fEDz->Connect("ValueSet(Long_t)", "TGeoTrd2Editor", this, "DoDz()");
177  fEDx1->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoTrd2Editor", this, "DoModified()");
178  fEDx2->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoTrd2Editor", this, "DoModified()");
179  fEDy1->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoTrd2Editor", this, "DoModified()");
180  fEDy2->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoTrd2Editor", this, "DoModified()");
181  fEDz->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoTrd2Editor", this, "DoModified()");
182  fInit = kFALSE;
183 }
184 
185 
186 ////////////////////////////////////////////////////////////////////////////////
187 /// Connect to the selected object.
188 
190 {
191  if (obj == 0 || (obj->IsA()!=TGeoTrd2::Class())) {
192  SetActive(kFALSE);
193  return;
194  }
195  fShape = (TGeoTrd2*)obj;
196  fDxi1 = fShape->GetDx1();
197  fDxi2 = fShape->GetDx2();
198  fDyi1 = fShape->GetDy1();
199  fDyi2 = fShape->GetDy2();
200  fDzi = fShape->GetDz();
201  const char *sname = fShape->GetName();
202  if (!strcmp(sname, fShape->ClassName())) fShapeName->SetText("-no_name");
203  else {
204  fShapeName->SetText(sname);
205  fNamei = sname;
206  }
211  fEDz->SetNumber(fDzi);
214 
216  SetActive();
217 }
218 
219 ////////////////////////////////////////////////////////////////////////////////
220 /// Check if shape drawing is delayed.
221 
223 {
224  return (fDelayed->GetState() == kButtonDown);
225 }
226 
227 ////////////////////////////////////////////////////////////////////////////////
228 /// Perform name change.
229 
231 {
232  DoModified();
233 }
234 
235 ////////////////////////////////////////////////////////////////////////////////
236 /// Slot for applying modifications.
237 
239 {
240  const char *name = fShapeName->GetText();
241  if (strcmp(name,fShape->GetName())) fShape->SetName(name);
242  Double_t dx1 = fEDx1->GetNumber();
243  Double_t dx2 = fEDx2->GetNumber();
244  Double_t dy1 = fEDy1->GetNumber();
245  Double_t dy2 = fEDy2->GetNumber();
246  Double_t dz = fEDz->GetNumber();
247  Double_t param[5];
248  param[0] = dx1;
249  param[1] = dx2;
250  param[2] = dy1;
251  param[3] = dy2;
252  param[4] = dz;
253  fShape->SetDimensions(param);
254  fShape->ComputeBBox();
255  fUndo->SetEnabled();
257  if (fPad) {
259  fShape->Draw();
260  fPad->GetView()->ShowAxis();
261  } else Update();
262  }
263 }
264 
265 ////////////////////////////////////////////////////////////////////////////////
266 /// Slot for signaling modifications.
267 
269 {
270  fApply->SetEnabled();
271 }
272 
273 ////////////////////////////////////////////////////////////////////////////////
274 /// Slot for undoing last operation.
275 
277 {
282  fEDz->SetNumber(fDzi);
283  DoApply();
286 }
287 
288 ////////////////////////////////////////////////////////////////////////////////
289 /// Slot for dx1.
290 
292 {
293  Double_t dx1 = fEDx1->GetNumber();
294  Double_t dx2 = fEDx2->GetNumber();
295  if (dx1<0) {
296  dx1 = 0;
297  fEDx1->SetNumber(dx1);
298  }
299  if (dx1<1.e-6 && dx2<1.e-6) {
300  dx1 = 0.1;
301  fEDx1->SetNumber(dx1);
302  }
303  DoModified();
304  if (!IsDelayed()) DoApply();
305 }
306 
307 ////////////////////////////////////////////////////////////////////////////////
308 /// Slot for dx2.
309 
311 {
312  Double_t dx1 = fEDx1->GetNumber();
313  Double_t dx2 = fEDx2->GetNumber();
314  if (dx2<0) {
315  dx2 = 0;
316  fEDx2->SetNumber(dx2);
317  }
318  if (dx1<1.e-6 && dx2<1.e-6) {
319  dx2 = 0.1;
320  fEDx2->SetNumber(dx2);
321  }
322  DoModified();
323  if (!IsDelayed()) DoApply();
324 }
325 
326 ////////////////////////////////////////////////////////////////////////////////
327 /// Slot for dy1.
328 
330 {
331  Double_t dy1 = fEDy1->GetNumber();
332  Double_t dy2 = fEDy2->GetNumber();
333  if (dy1<0) {
334  dy1 = 0;
335  fEDy1->SetNumber(dy1);
336  }
337  if (dy1<1.e-6 && dy2<1.e-6) {
338  dy1 = 0.1;
339  fEDy1->SetNumber(dy1);
340  }
341  DoModified();
342  if (!IsDelayed()) DoApply();
343 }
344 
345 ////////////////////////////////////////////////////////////////////////////////
346 /// Slot for dy2.
347 
349 {
350  Double_t dy1 = fEDy1->GetNumber();
351  Double_t dy2 = fEDy2->GetNumber();
352  if (dy2<0) {
353  dy2 = 0;
354  fEDy2->SetNumber(dy2);
355  }
356  if (dy1<1.e-6 && dy2<1.e-6) {
357  dy2 = 0.1;
358  fEDy2->SetNumber(dy2);
359  }
360  DoModified();
361  if (!IsDelayed()) DoApply();
362 }
363 
364 ////////////////////////////////////////////////////////////////////////////////
365 /// Slot for dz.
366 
368 {
369  Double_t dz = fEDz->GetNumber();
370  if (dz<=0) {
371  dz = 0.1;
372  fEDz->SetNumber(dz);
373  }
374  DoModified();
375  if (!IsDelayed()) DoApply();
376 }
377 
378 
Double_t GetDy2() const
Definition: TGeoTrd2.h:59
virtual void Resize(UInt_t w=0, UInt_t h=0)
Resize the frame.
Definition: TGFrame.cxx:587
void DoApply()
Slot for applying modifications.
TGTextButton * fUndo
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.
TGNumberEntry * fEDy2
virtual void SetName(const char *name)
Set the name of the TNamed.
Definition: TNamed.cxx:140
TGNumberEntry * fEDx2
void DoUndo()
Slot for undoing last operation.
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
Double_t GetDx2() const
Definition: TGeoTrd2.h:57
virtual Bool_t IsComposite() const
Definition: TGFrame.h:259
TGNumberEntry * fEDy1
void DoDx2()
Slot for dx2.
void DoDx1()
Slot for dx1.
static void Cleanup(TGCompositeFrame *frame)
Static method to cleanup hierarchically all daughters of a composite frame.
virtual void ConnectSignals2Slots()
Connect signals to slots.
virtual const char * ClassName() const
Returns name of class to which the object belongs.
Definition: TObject.cxx:128
ULong_t Pixel_t
Definition: GuiTypes.h:39
void Class()
Definition: Class.C:29
TGeoTrd2 * fShape
virtual void SetActive(Bool_t active=kTRUE)
Set active GUI attribute frames related to the selected object.
TGNumberEntry * fEDz
TGCompositeFrame(const TGCompositeFrame &)
virtual TList * GetList() const
Definition: TGFrame.h:369
virtual void ComputeBBox()
compute bounding box for a trd2
Definition: TGeoTrd2.cxx:134
virtual EButtonState GetState() const
Definition: TGButton.h:112
virtual void SetModel(TObject *obj)
Connect to the selected object.
virtual TView * GetView() const =0
void DoModified()
Slot for signaling modifications.
virtual const char * GetName() const
Get the shape name.
Definition: TGeoShape.cxx:248
A trapezoid with both x and y lengths varying with z.
Definition: TGeoTrd2.h:17
Editor for a TGeoTrd2.
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
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.
Bool_t IsDelayed() const
Check if shape drawing is delayed.
virtual void Associate(const TGWindow *w)
Definition: TGWidget.h:84
Double_t GetDz() const
Definition: TGeoTrd2.h:60
unsigned int UInt_t
Definition: RtypesCore.h:42
void DoDy1()
Slot for dy1.
TGFrame * fFrame
Definition: TGLayout.h:119
virtual void ShowAxis()=0
TGCheckButton * fDelayed
void DoName()
Perform name change.
void SetNumAttr(EAttribute attr=kNEAAnyNumber)
virtual void SetDimensions(Double_t *param)
set arb8 params in one step :
Definition: TGeoTrd2.cxx:687
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
#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 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
Double_t GetDy1() const
Definition: TGeoTrd2.h:58
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
Mother of all ROOT objects.
Definition: TObject.h:37
Bool_t fIsShapeEditable
Double_t GetDx1() const
Definition: TGeoTrd2.h:56
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.
TGTextButton * fApply
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
virtual void MakeTitle(const char *title)
Create attribute frame title.
Definition: TGedFrame.cxx:96
void DoDz()
Slot for dz.
char name[80]
Definition: TGX11.cxx:109
ETGeoTrd2Wid
Common base class for geombuilder editors.
Definition: TGeoGedFrame.h:13
virtual ~TGeoTrd2Editor()
Destructor.