Logo ROOT   6.08/07
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 //////////////////////////////////////////////////////////////////////////
13 // //
14 // TGeoTrd1Editor //
15 // //
16 //////////////////////////////////////////////////////////////////////////
17 //Begin_Html
18 /*
19 <img src="gif/trd1_pic.gif">
20 */
21 //End_Html
22 //Begin_Html
23 /*
24 <img src="gif/trd1_ed.jpg">
25 */
26 //End_Html
27 
28 #include "TGeoTrd1Editor.h"
29 #include "TGeoTabManager.h"
30 #include "TGeoTrd1.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 
47 };
48 
49 ////////////////////////////////////////////////////////////////////////////////
50 /// Constructor for trd1 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 = fDyi = fDzi = 0.0;
58  fNamei = "";
61 
62  // TextEntry for shape name
63  MakeTitle("Name");
64  fShapeName = new TGTextEntry(this, new TGTextBuffer(50), kTRD1_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("Trd1 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, kTRD1_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, kTRD1_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 dy
99  TGCompositeFrame *f2 = new TGCompositeFrame(compxyz, 118, 10, kHorizontalFrame |
101  f2->AddFrame(new TGLabel(f2, "DY"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
102  fEDy = new TGNumberEntry(f2, 0., 5, kTRD1_Y);
104  nef = (TGTextEntry*)fEDy->GetNumberEntry();
105  nef->SetToolTipText("Enter the half-lenth in Y");
106  fEDy->Associate(this);
107  f2->AddFrame(fEDy, 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 dz
111  TGCompositeFrame *f3 = new TGCompositeFrame(compxyz, 118, 10, kHorizontalFrame |
113  f3->AddFrame(new TGLabel(f3, "DZ"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
114  fEDz = new TGNumberEntry(f3, 0., 5, kTRD1_Z);
116  nef = (TGTextEntry*)fEDz->GetNumberEntry();
117  nef->SetToolTipText("Enter the half-lenth in Z");
118  fEDz->Associate(this);
119  f3->AddFrame(fEDz, new TGLayoutHints(kLHintsLeft | kLHintsExpandX , 2, 2, 4, 4));
120  compxyz->AddFrame(f3, new TGLayoutHints(kLHintsLeft | kLHintsExpandX , 2, 2, 4, 4));
121 
122  compxyz->Resize(150,30);
123  AddFrame(compxyz, new TGLayoutHints(kLHintsLeft, 6, 6, 4, 4));
124 
125  // Delayed draw
126  f1 = new TGCompositeFrame(this, 155, 10, kHorizontalFrame | kFixedWidth | kSunkenFrame);
127  fDelayed = new TGCheckButton(f1, "Delayed draw");
128  f1->AddFrame(fDelayed, new TGLayoutHints(kLHintsLeft , 2, 2, 4, 4));
129  AddFrame(f1, new TGLayoutHints(kLHintsLeft, 6, 6, 4, 4));
130 
131  // Buttons
132  f1 = new TGCompositeFrame(this, 155, 10, kHorizontalFrame | kFixedWidth);
133  fApply = new TGTextButton(f1, "Apply");
134  f1->AddFrame(fApply, new TGLayoutHints(kLHintsLeft, 2, 2, 4, 4));
135  fApply->Associate(this);
136  fUndo = new TGTextButton(f1, "Undo");
137  f1->AddFrame(fUndo, new TGLayoutHints(kLHintsRight , 2, 2, 4, 4));
138  fUndo->Associate(this);
139  AddFrame(f1, new TGLayoutHints(kLHintsLeft, 6, 6, 4, 4));
141 }
142 
143 ////////////////////////////////////////////////////////////////////////////////
144 /// Destructor
145 
147 {
148  TGFrameElement *el;
149  TIter next(GetList());
150  while ((el = (TGFrameElement *)next())) {
151  if (el->fFrame->IsComposite())
153  }
154  Cleanup();
155 }
156 
157 ////////////////////////////////////////////////////////////////////////////////
158 /// Connect signals to slots.
159 
161 {
162  fApply->Connect("Clicked()", "TGeoTrd1Editor", this, "DoApply()");
163  fUndo->Connect("Clicked()", "TGeoTrd1Editor", this, "DoUndo()");
164  fShapeName->Connect("TextChanged(const char *)", "TGeoTrd1Editor", this, "DoModified()");
165  fEDx1->Connect("ValueSet(Long_t)", "TGeoTrd1Editor", this, "DoDx1()");
166  fEDx2->Connect("ValueSet(Long_t)", "TGeoTrd1Editor", this, "DoDx2()");
167  fEDy->Connect("ValueSet(Long_t)", "TGeoTrd1Editor", this, "DoDy()");
168  fEDz->Connect("ValueSet(Long_t)", "TGeoTrd1Editor", this, "DoDz()");
169  fEDx1->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoTrd1Editor", this, "DoModified()");
170  fEDx2->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoTrd1Editor", this, "DoModified()");
171  fEDy->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoTrd1Editor", this, "DoModified()");
172  fEDz->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoTrd1Editor", this, "DoModified()");
173  fInit = kFALSE;
174 }
175 
176 
177 ////////////////////////////////////////////////////////////////////////////////
178 /// Connect to the selected object.
179 
181 {
182  if (obj == 0 || (obj->IsA()!=TGeoTrd1::Class())) {
183  SetActive(kFALSE);
184  return;
185  }
186  fShape = (TGeoTrd1*)obj;
187  fDxi1 = fShape->GetDx1();
188  fDxi2 = fShape->GetDx2();
189  fDyi = fShape->GetDy();
190  fDzi = fShape->GetDz();
191  const char *sname = fShape->GetName();
192  if (!strcmp(sname, fShape->ClassName())) fShapeName->SetText("-no_name");
193  else {
194  fShapeName->SetText(sname);
195  fNamei = sname;
196  }
199  fEDy->SetNumber(fDyi);
200  fEDz->SetNumber(fDzi);
203 
204 
206  SetActive();
207 }
208 
209 ////////////////////////////////////////////////////////////////////////////////
210 /// Check if shape drawing is delayed.
211 
213 {
214  return (fDelayed->GetState() == kButtonDown);
215 }
216 
217 ////////////////////////////////////////////////////////////////////////////////
218 /// Perform name change.
219 
221 {
222  DoModified();
223 }
224 
225 ////////////////////////////////////////////////////////////////////////////////
226 /// Slot for applying modifications.
227 
229 {
230  const char *name = fShapeName->GetText();
231  if (strcmp(name,fShape->GetName())) fShape->SetName(name);
232  Double_t dx1 = fEDx1->GetNumber();
233  Double_t dx2 = fEDx2->GetNumber();
234  Double_t dy = fEDy->GetNumber();
235  Double_t dz = fEDz->GetNumber();
236  Double_t param[4];
237  param[0] = dx1;
238  param[1] = dx2;
239  param[2] = dy;
240  param[3] = dz;
241  fShape->SetDimensions(param);
242  fShape->ComputeBBox();
243  fUndo->SetEnabled();
245  if (fPad) {
247  fShape->Draw();
248  fPad->GetView()->ShowAxis();
249  } else Update();
250  }
251 }
252 
253 ////////////////////////////////////////////////////////////////////////////////
254 /// Slot for signaling modifications.
255 
257 {
258  fApply->SetEnabled();
259 }
260 
261 ////////////////////////////////////////////////////////////////////////////////
262 /// Slot for undoing last operation.
263 
265 {
268  fEDy->SetNumber(fDyi);
269  fEDz->SetNumber(fDzi);
270  DoApply();
273 }
274 
275 ////////////////////////////////////////////////////////////////////////////////
276 /// Slot for dx1.
277 
279 {
280  Double_t dx1 = fEDx1->GetNumber();
281  Double_t dx2 = fEDx2->GetNumber();
282  if (dx1<0) {
283  dx1 = 0;
284  fEDx1->SetNumber(dx1);
285  }
286  if (dx1<1.e-6 && dx2<1.e-6) {
287  dx1 = 0.1;
288  fEDx1->SetNumber(dx1);
289  }
290  DoModified();
291  if (!IsDelayed()) DoApply();
292 }
293 
294 ////////////////////////////////////////////////////////////////////////////////
295 /// Slot for dx2.
296 
298 {
299  Double_t dx1 = fEDx1->GetNumber();
300  Double_t dx2 = fEDx2->GetNumber();
301  if (dx2<0) {
302  dx2 = 0;
303  fEDx2->SetNumber(dx2);
304  }
305  if (dx1<1.e-6 && dx2<1.e-6) {
306  dx2 = 0.1;
307  fEDx2->SetNumber(dx2);
308  }
309  DoModified();
310  if (!IsDelayed()) DoApply();
311 }
312 
313 ////////////////////////////////////////////////////////////////////////////////
314 /// Slot for dy.
315 
317 {
318  Double_t dy = fEDy->GetNumber();
319  if (dy<=0) {
320  dy = 0.1;
321  fEDy->SetNumber(dy);
322  }
323  DoModified();
324  if (!IsDelayed()) DoApply();
325 }
326 
327 ////////////////////////////////////////////////////////////////////////////////
328 /// Slot for dz.
329 
331 {
332  Double_t dz = fEDz->GetNumber();
333  if (dz<=0) {
334  dz = 0.1;
335  fEDz->SetNumber(dz);
336  }
337  DoModified();
338  if (!IsDelayed()) DoApply();
339 }
340 
341 
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:59
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
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
const Bool_t kFALSE
Definition: Rtypes.h:92
virtual Bool_t IsComposite() const
Definition: TGFrame.h:275
const char * Class
Definition: TXMLSetup.cxx:64
A trapezoid with only x length varying with z.
Definition: TGeoTrd1.h:19
Double_t GetDx2() const
Definition: TGeoTrd1.h:58
static void Cleanup(TGCompositeFrame *frame)
Static method to cleanup hirarchically 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:188
virtual ~TGeoTrd1Editor()
Destructor.
ULong_t Pixel_t
Definition: GuiTypes.h:41
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:385
virtual EButtonState GetState() const
Definition: TGButton.h:116
TGTextButton * fApply
virtual TView * GetView() const =0
TGTextButton * fUndo
virtual const char * GetName() const
Get the shape name.
Definition: TGeoShape.cxx:250
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:1137
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:315
virtual void Associate(const TGWindow *w)
Definition: TGWidget.h:90
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:125
virtual void ShowAxis()=0
const std::string sname
Definition: testIO.cxx:45
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.
TGDimension GetSize() const
Definition: TGFrame.h:293
void DoDz()
Slot for dz.
const char * GetText() const
Definition: TGTextEntry.h:140
virtual UInt_t GetDefaultHeight() const
Definition: TGFrame.h:254
ETGeoTrd1Wid
#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 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:55
TGNumberEntryField * GetNumberEntry() const
double f2(const double *x)
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:60
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:57
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 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