Logo ROOT   6.08/07
Reference Guide
TGeoParaEditor.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 // TGeoParaEditor //
15 // //
16 //////////////////////////////////////////////////////////////////////////
17 //Begin_Html
18 /*
19 <img src="gif/para_pic.gif">
20 */
21 //End_Html
22 //Begin_Html
23 /*
24 <img src="gif/para_ed.jpg">
25 */
26 //End_Html
27 
28 #include "TGeoParaEditor.h"
29 #include "TGeoTabManager.h"
30 #include "TGeoPara.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 para 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  fXi = fYi = fZi = fAlphai = fThetai = fPhii = 0.0;
58  fNamei = "";
61 
62  // TextEntry for shape name
63  MakeTitle("Name");
64  fShapeName = new TGTextEntry(this, new TGTextBuffer(50), kPARA_NAME);
66  fShapeName->SetToolTipText("Enter the parallelipiped name");
67  fShapeName->Associate(this);
68  AddFrame(fShapeName, new TGLayoutHints(kLHintsLeft, 3, 1, 2, 5));
69 
70  TGTextEntry *nef;
71  MakeTitle("Dimensions");
72  // Number entry for dx
74  f1->AddFrame(new TGLabel(f1, "DX"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
75  fEDx = new TGNumberEntry(f1, 0., 5, kPARA_X);
77  fEDx->Resize(100, fEDx->GetDefaultHeight());
78  nef = (TGTextEntry*)fEDx->GetNumberEntry();
79  nef->SetToolTipText("Enter the half-lenth in X");
80  fEDx->Associate(this);
81  f1->AddFrame(fEDx, new TGLayoutHints(kLHintsRight, 2, 2, 4, 4));
82  AddFrame(f1, new TGLayoutHints(kLHintsLeft, 2, 2, 4, 4));
83 
84  // Number entry for dy
85  f1 = new TGCompositeFrame(this, 155, 10, kHorizontalFrame | kFixedWidth);
86  f1->AddFrame(new TGLabel(f1, "DY"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
87  fEDy = new TGNumberEntry(f1, 0., 5, kPARA_Y);
89  fEDy->Resize(100, fEDy->GetDefaultHeight());
90  nef = (TGTextEntry*)fEDy->GetNumberEntry();
91  nef->SetToolTipText("Enter the half-lenth in Y");
92  fEDy->Associate(this);
93  f1->AddFrame(fEDy, new TGLayoutHints(kLHintsRight, 2, 2, 4, 4));
94  AddFrame(f1, new TGLayoutHints(kLHintsLeft, 2, 2, 4, 4));
95 
96  // Number entry for dz
97  f1 = new TGCompositeFrame(this, 155, 10, kHorizontalFrame | kFixedWidth);
98  f1->AddFrame(new TGLabel(f1, "Dz"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
99  fEDz = new TGNumberEntry(f1, 0., 5, kPARA_Z);
101  fEDz->Resize(100, fEDz->GetDefaultHeight());
102  nef = (TGTextEntry*)fEDz->GetNumberEntry();
103  nef->SetToolTipText("Enter the half-lenth in Z");
104  fEDz->Associate(this);
105  f1->AddFrame(fEDz, new TGLayoutHints(kLHintsRight, 2, 2, 4, 4));
106  AddFrame(f1, new TGLayoutHints(kLHintsLeft, 2, 2, 4, 4));
107 
108  // Number entry for Alpha
109  f1 = new TGCompositeFrame(this, 155, 10, kHorizontalFrame | kFixedWidth);
110  f1->AddFrame(new TGLabel(f1, "Alpha"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
111  fEAlpha = new TGNumberEntry(f1, 0., 5, kPARA_ALPHA);
114  nef->SetToolTipText("Enter the angle with respect to Y axis [deg]");
115  fEAlpha->Associate(this);
116  f1->AddFrame(fEAlpha, new TGLayoutHints(kLHintsRight, 2, 2, 4, 4));
117  AddFrame(f1, new TGLayoutHints(kLHintsLeft, 2, 2, 4, 4));
118 
119  // Number entry for Theta
120  f1 = new TGCompositeFrame(this, 155, 10, kHorizontalFrame | kFixedWidth);
121  f1->AddFrame(new TGLabel(f1, "Theta"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
122  fETheta = new TGNumberEntry(f1, 0., 5, kPARA_THETA);
126  nef->SetToolTipText("Enter the theta angle of the para axis [deg]");
127  fETheta->Associate(this);
128  f1->AddFrame(fETheta, new TGLayoutHints(kLHintsRight, 2, 2, 4, 4));
129  AddFrame(f1, new TGLayoutHints(kLHintsLeft, 2, 2, 4, 4));
130 
131  // Number entry for Phi
132  f1 = new TGCompositeFrame(this, 155, 10, kHorizontalFrame | kFixedWidth);
133  f1->AddFrame(new TGLabel(f1, "Phi"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
134  fEPhi = new TGNumberEntry(f1, 0., 5, kPARA_PHI);
137  nef = (TGTextEntry*)fEPhi->GetNumberEntry();
138  nef->SetToolTipText("Enter the phi angle of the para axis [deg]");
139  fEPhi->Associate(this);
140  f1->AddFrame(fEPhi, new TGLayoutHints(kLHintsRight, 2, 2, 4, 4));
141  AddFrame(f1, new TGLayoutHints(kLHintsLeft, 2, 2, 4, 4));
142 
143  // Delayed draw
144  f1 = new TGCompositeFrame(this, 155, 10, kHorizontalFrame | kFixedWidth | kSunkenFrame);
145  fDelayed = new TGCheckButton(f1, "Delayed draw");
146  f1->AddFrame(fDelayed, new TGLayoutHints(kLHintsLeft , 2, 2, 4, 4));
147  AddFrame(f1, new TGLayoutHints(kLHintsLeft, 6, 6, 4, 4));
148 
149  // Buttons
150  f1 = new TGCompositeFrame(this, 155, 10, kHorizontalFrame | kFixedWidth);
151  fApply = new TGTextButton(f1, "Apply");
152  f1->AddFrame(fApply, new TGLayoutHints(kLHintsLeft, 2, 2, 4, 4));
153  fApply->Associate(this);
154  fUndo = new TGTextButton(f1, "Undo");
155  f1->AddFrame(fUndo, new TGLayoutHints(kLHintsRight , 2, 2, 4, 4));
156  fUndo->Associate(this);
157  AddFrame(f1, new TGLayoutHints(kLHintsLeft, 6, 6, 4, 4));
159 }
160 
161 ////////////////////////////////////////////////////////////////////////////////
162 /// Destructor
163 
165 {
166  TGFrameElement *el;
167  TIter next(GetList());
168  while ((el = (TGFrameElement *)next())) {
169  if (el->fFrame->IsComposite())
171  }
172  Cleanup();
173 }
174 
175 ////////////////////////////////////////////////////////////////////////////////
176 /// Connect signals to slots.
177 
179 {
180  fApply->Connect("Clicked()", "TGeoParaEditor", this, "DoApply()");
181  fUndo->Connect("Clicked()", "TGeoParaEditor", this, "DoUndo()");
182  fShapeName->Connect("TextChanged(const char *)", "TGeoParaEditor", this, "DoModified()");
183  fEDx->Connect("ValueSet(Long_t)", "TGeoParaEditor", this, "DoX()");
184  fEDy->Connect("ValueSet(Long_t)", "TGeoParaEditor", this, "DoY()");
185  fEDz->Connect("ValueSet(Long_t)", "TGeoParaEditor", this, "DoZ()");
186  fEAlpha->Connect("ValueSet(Long_t)", "TGeoParaEditor", this, "DoAlpha()");
187  fETheta->Connect("ValueSet(Long_t)", "TGeoParaEditor", this, "DoTheta()");
188  fEPhi->Connect("ValueSet(Long_t)", "TGeoParaEditor", this, "DoPhi()");
189  fEDx->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoParaEditor", this, "DoModified()");
190  fEDy->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoParaEditor", this, "DoModified()");
191  fEDz->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoParaEditor", this, "DoModified()");
192  fEAlpha->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoParaEditor", this, "DoModified()");
193  fETheta->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoParaEditor", this, "DoModified()");
194  fEPhi->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoParaEditor", this, "DoModified()");
195  fInit = kFALSE;
196 }
197 
198 
199 ////////////////////////////////////////////////////////////////////////////////
200 /// Connect to the selected object.
201 
203 {
204  if (obj == 0 || (obj->IsA()!=TGeoPara::Class())) {
205  SetActive(kFALSE);
206  return;
207  }
208  fShape = (TGeoPara*)obj;
209  fXi = fShape->GetX();
210  fYi = fShape->GetY();
211  fZi = fShape->GetZ();
212  fAlphai = fShape->GetAlpha();
213  fThetai = fShape->GetTheta();
214  fPhii = fShape->GetPhi();
215  const char *sname = fShape->GetName();
216  if (!strcmp(sname, fShape->ClassName())) fShapeName->SetText("-no_name");
217  else {
218  fShapeName->SetText(sname);
219  fNamei = sname;
220  }
221  fEDx->SetNumber(fXi);
222  fEDy->SetNumber(fYi);
223  fEDz->SetNumber(fZi);
229 
231  SetActive();
232 }
233 
234 ////////////////////////////////////////////////////////////////////////////////
235 /// Check if shape drawing is delayed.
236 
238 {
239  return (fDelayed->GetState() == kButtonDown);
240 }
241 
242 ////////////////////////////////////////////////////////////////////////////////
243 /// Slot for name.
244 
246 {
247  DoModified();
248 }
249 
250 ////////////////////////////////////////////////////////////////////////////////
251 /// Slot for applying current settings.
252 
254 {
255  const char *name = fShapeName->GetText();
256  if (strcmp(name,fShape->GetName())) fShape->SetName(name);
257  Double_t dx = fEDx->GetNumber();
258  Double_t dy = fEDy->GetNumber();
259  Double_t dz = fEDz->GetNumber();
260  Double_t alpha = fEAlpha->GetNumber();
261  Double_t theta = fETheta->GetNumber();
262  Double_t phi = fEPhi->GetNumber();
263  Double_t param[6];
264  param[0] = dx;
265  param[1] = dy;
266  param[2] = dz;
267  param[3] = alpha;
268  param[4] = theta;
269  param[5] = phi;
270  fShape->SetDimensions(param);
271  fShape->ComputeBBox();
272  fUndo->SetEnabled();
274  if (fPad) {
276  TView *view = fPad->GetView();
277  if (!view) {
278  fShape->Draw();
279  fPad->GetView()->ShowAxis();
280  } else {
281  view->SetRange(-fShape->GetDX(), -fShape->GetDY(), -fShape->GetDZ(),
282  fShape->GetDX(), fShape->GetDY(), fShape->GetDZ());
283  Update();
284  }
285  } else Update();
286  }
287 }
288 
289 ////////////////////////////////////////////////////////////////////////////////
290 /// Slot for notifying modifications.
291 
293 {
294  fApply->SetEnabled();
295 }
296 
297 ////////////////////////////////////////////////////////////////////////////////
298 /// Slot for undoing last operation.
299 
301 {
302  fEDx->SetNumber(fXi);
303  fEDy->SetNumber(fYi);
304  fEDz->SetNumber(fZi);
308  DoApply();
311 }
312 
313 ////////////////////////////////////////////////////////////////////////////////
314 /// Slot for X.
315 
317 {
318  Double_t dx = fEDx->GetNumber();
319  if (dx<=0) {
320  dx = 0.1;
321  fEDx->SetNumber(dx);
322  }
323  DoModified();
324  if (!IsDelayed()) DoApply();
325 }
326 
327 ////////////////////////////////////////////////////////////////////////////////
328 /// Slot for Y.
329 
331 {
332  Double_t dy = fEDy->GetNumber();
333  if (dy<=0) {
334  dy = 0.1;
335  fEDy->SetNumber(dy);
336  }
337  DoModified();
338  if (!IsDelayed()) DoApply();
339 }
340 
341 ////////////////////////////////////////////////////////////////////////////////
342 /// Slot for Z.
343 
345 {
346  Double_t dz = fEDz->GetNumber();
347  if (dz<=0) {
348  dz = 0.1;
349  fEDz->SetNumber(dz);
350  }
351  DoModified();
352  if (!IsDelayed()) DoApply();
353 }
354 
355 ////////////////////////////////////////////////////////////////////////////////
356 /// Slot for alpha.
357 
359 {
360  Double_t alpha = fEAlpha->GetNumber();
361  if (TMath::Abs(alpha)>=90) {
362  alpha = 89.9*TMath::Sign(1.,alpha);
363  fEAlpha->SetNumber(alpha);
364  }
365  DoModified();
366  if (!IsDelayed()) DoApply();
367 }
368 
369 ////////////////////////////////////////////////////////////////////////////////
370 /// Slot for theta.
371 
373 {
374  Double_t theta = fETheta->GetNumber();
375  if (theta<0) {
376  theta = 0;
377  fETheta->SetNumber(theta);
378  }
379  if (theta>180) {
380  theta = 180;
381  fETheta->SetNumber(theta);
382  }
383  DoModified();
384  if (!IsDelayed()) DoApply();
385 }
386 
387 ////////////////////////////////////////////////////////////////////////////////
388 /// Slot for phi.
389 
391 {
392  Double_t phi = fEPhi->GetNumber();
393  if (phi<0 || phi>360) {
394  phi = 0;
395  fEPhi->SetNumber(phi);
396  }
397  DoModified();
398  if (!IsDelayed()) DoApply();
399 }
400 
virtual void Resize(UInt_t w=0, UInt_t h=0)
Resize the frame.
Definition: TGFrame.cxx:587
TGNumberEntry * fEPhi
T1 Sign(T1 a, T2 b)
Definition: TMathBase.h:155
void DoX()
Slot for X.
void DoModified()
Slot for notifying modifications.
virtual void SetDimensions(Double_t *param)
Set dimensions starting from an array.
Definition: TGeoPara.cxx:592
void DoZ()
Slot for Z.
virtual Double_t GetDX() const
Definition: TGeoBBox.h:72
Bool_t IsDelayed() const
Check if shape drawing is delayed.
void DoApply()
Slot for applying current settings.
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
Double_t GetPhi() const
Definition: TGeoPara.h:68
virtual void SetNumber(Double_t val)
See TView3D.
Definition: TView.h:29
virtual ~TGeoParaEditor()
Destructor.
virtual void SetRange(const Double_t *min, const Double_t *max)=0
void DoPhi()
Slot for phi.
virtual Bool_t IsPaintingShape() const =0
void DoUndo()
Slot for undoing last operation.
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
void DoAlpha()
Slot for alpha.
const char * Class
Definition: TXMLSetup.cxx:64
Short_t Abs(Short_t d)
Definition: TMathBase.h:110
virtual void ComputeBBox()
compute bounding box
Definition: TGeoPara.cxx:158
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
ULong_t Pixel_t
Definition: GuiTypes.h:41
virtual void SetActive(Bool_t active=kTRUE)
Set active GUI attribute frames related to the selected object.
TGCompositeFrame(const TGCompositeFrame &)
TGeoPara * fShape
TGTextButton * fUndo
virtual TList * GetList() const
Definition: TGFrame.h:385
virtual EButtonState GetState() const
Definition: TGButton.h:116
ETGeoParaWid
void DoY()
Slot for Y.
virtual TView * GetView() const =0
TGeoParaEditor(const TGWindow *p=0, Int_t width=140, Int_t height=30, UInt_t options=kChildFrame, Pixel_t back=GetDefaultFrameBackground())
Constructor for para editor.
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.
Parallelepiped class.
Definition: TGeoPara.h:19
Double_t GetX() const
Definition: TGeoPara.h:63
TGTextEntry * fShapeName
virtual void SetSize(const TGDimension &s)
Definition: TGFrame.h:315
void DoTheta()
Slot for theta.
Double_t GetAlpha() const
Definition: TGeoPara.h:66
Double_t GetY() const
Definition: TGeoPara.h:64
Double_t fThetai
virtual void Associate(const TGWindow *w)
Definition: TGWidget.h:90
TGNumberEntry * fEDz
unsigned int UInt_t
Definition: RtypesCore.h:42
TGCheckButton * fDelayed
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
Double_t fAlphai
TGNumberEntry * fETheta
void SetNumAttr(EAttribute attr=kNEAAnyNumber)
virtual void SetModel(TObject *obj)
Connect to the selected object.
TGTextButton * fApply
TGNumberEntry * fEDx
TGDimension GetSize() const
Definition: TGFrame.h:293
const char * GetText() const
Definition: TGTextEntry.h:140
virtual UInt_t GetDefaultHeight() const
Definition: TGFrame.h:254
#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
TGNumberEntry * fEDy
virtual Double_t GetNumber() const
virtual void ConnectSignals2Slots()
Connect signals to slots.
virtual void AddFrame(TGFrame *f, TGLayoutHints *l=0)
Add frame to the composite frame using the specified layout hints.
Definition: TGFrame.cxx:1099
TGNumberEntry * fEAlpha
Mother of all ROOT objects.
Definition: TObject.h:37
Bool_t fInit
Definition: TGedFrame.h:55
TGNumberEntryField * GetNumberEntry() const
void DoName()
Slot for name.
TF1 * f1
Definition: legend1.C:11
virtual void Update()
Override Update from TGedFrame as fGedEditor can be null.
Double_t GetTheta() const
Definition: TGeoPara.h:67
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 GetZ() const
Definition: TGeoPara.h:65
Bool_t fIsShapeEditable
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
const Bool_t kTRUE
Definition: Rtypes.h:91
virtual void MakeTitle(const char *title)
Create attribute frame title.
Definition: TGedFrame.cxx:96
char name[80]
Definition: TGX11.cxx:109
UInt_t GetDefaultHeight() const
virtual Double_t GetDZ() const
Definition: TGeoBBox.h:74