Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
TGeoEltuEditor.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 TGeoEltuEditor
13 \ingroup Geometry_builder
14 
15 Editor for a TGeoEltu.
16 
17 \image html geom_eltu_pic.png
18 
19 \image html geom_eltu_ed.png
20 
21 */
22 
23 #include "TGeoEltuEditor.h"
24 #include "TGeoTabManager.h"
25 #include "TGeoEltu.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 
37 ClassImp(TGeoEltuEditor);
38 
39 enum ETGeoEltuWid {
40  kELTU_NAME, kELTU_A, kELTU_B, kELTU_DZ,
41  kELTU_APPLY, kELTU_UNDO
42 };
43 
44 ////////////////////////////////////////////////////////////////////////////////
45 /// Constructor for para editor
46 
47 TGeoEltuEditor::TGeoEltuEditor(const TGWindow *p, Int_t width,
48  Int_t height, UInt_t options, Pixel_t back)
49  : TGeoGedFrame(p, width, height, options | kVerticalFrame, back)
50 {
51  fShape = 0;
52  fAi = fBi = fDzi = 0.0;
53  fNamei = "";
54  fIsModified = kFALSE;
55  fIsShapeEditable = kTRUE;
56 
57  // TextEntry for shape name
58  MakeTitle("Name");
59  fShapeName = new TGTextEntry(this, new TGTextBuffer(50), kELTU_NAME);
60  fShapeName->Resize(135, fShapeName->GetDefaultHeight());
61  fShapeName->SetToolTipText("Enter the elliptical tube name");
62  fShapeName->Associate(this);
63  AddFrame(fShapeName, new TGLayoutHints(kLHintsLeft, 3, 1, 2, 5));
64 
65  TGTextEntry *nef;
66  MakeTitle("Dimensions");
67  // Number entry for A
68  TGCompositeFrame *f1 = new TGCompositeFrame(this, 155, 10, kHorizontalFrame | kFixedWidth);
69  f1->AddFrame(new TGLabel(f1, "A"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
70  fEA = new TGNumberEntry(f1, 0., 5, kELTU_A);
71  fEA->SetNumAttr(TGNumberFormat::kNEAPositive);
72  fEA->Resize(100, fEA->GetDefaultHeight());
73  nef = (TGTextEntry*)fEA->GetNumberEntry();
74  nef->SetToolTipText("Enter the semi-axis of the ellipse along x");
75  fEA->Associate(this);
76  f1->AddFrame(fEA, new TGLayoutHints(kLHintsRight, 2, 2, 4, 4));
77  AddFrame(f1, new TGLayoutHints(kLHintsLeft, 2, 2, 4, 4));
78 
79  // Number entry for B
80  f1 = new TGCompositeFrame(this, 155, 10, kHorizontalFrame | kFixedWidth);
81  f1->AddFrame(new TGLabel(f1, "B"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
82  fEB = new TGNumberEntry(f1, 0., 5, kELTU_B);
83  fEB->SetNumAttr(TGNumberFormat::kNEAPositive);
84  fEB->Resize(100, fEB->GetDefaultHeight());
85  nef = (TGTextEntry*)fEB->GetNumberEntry();
86  nef->SetToolTipText("Enter the semi-axis of the ellipse along y");
87  fEB->Associate(this);
88  f1->AddFrame(fEB, new TGLayoutHints(kLHintsRight, 2, 2, 4, 4));
89  AddFrame(f1, new TGLayoutHints(kLHintsLeft, 2, 2, 4, 4));
90 
91  // Number entry for dz
92  f1 = new TGCompositeFrame(this, 155, 10, kHorizontalFrame | kFixedWidth);
93  f1->AddFrame(new TGLabel(f1, "Dz"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
94  fEDz = new TGNumberEntry(f1, 0., 5, kELTU_DZ);
95  fEDz->SetNumAttr(TGNumberFormat::kNEAPositive);
96  fEDz->Resize(100, fEDz->GetDefaultHeight());
97  nef = (TGTextEntry*)fEDz->GetNumberEntry();
98  nef->SetToolTipText("Enter the half-length in Z");
99  fEDz->Associate(this);
100  f1->AddFrame(fEDz, new TGLayoutHints(kLHintsRight, 2, 2, 4, 4));
101  AddFrame(f1, new TGLayoutHints(kLHintsLeft, 2, 2, 4, 4));
102 
103  // Delayed draw
104  f1 = new TGCompositeFrame(this, 155, 10, kHorizontalFrame | kFixedWidth | kSunkenFrame);
105  fDelayed = new TGCheckButton(f1, "Delayed draw");
106  f1->AddFrame(fDelayed, new TGLayoutHints(kLHintsLeft , 2, 2, 4, 4));
107  AddFrame(f1, new TGLayoutHints(kLHintsLeft, 6, 6, 4, 4));
108 
109  // Buttons
110  f1 = new TGCompositeFrame(this, 155, 10, kHorizontalFrame | kFixedWidth);
111  fApply = new TGTextButton(f1, "Apply");
112  f1->AddFrame(fApply, new TGLayoutHints(kLHintsLeft, 2, 2, 4, 4));
113  fApply->Associate(this);
114  fUndo = new TGTextButton(f1, "Undo");
115  f1->AddFrame(fUndo, new TGLayoutHints(kLHintsRight , 2, 2, 4, 4));
116  fUndo->Associate(this);
117  AddFrame(f1, new TGLayoutHints(kLHintsLeft, 6, 6, 4, 4));
118  fUndo->SetSize(fApply->GetSize());
119 }
120 
121 ////////////////////////////////////////////////////////////////////////////////
122 /// Destructor
123 
124 TGeoEltuEditor::~TGeoEltuEditor()
125 {
126  TGFrameElement *el;
127  TIter next(GetList());
128  while ((el = (TGFrameElement *)next())) {
129  if (el->fFrame->IsComposite())
130  TGeoTabManager::Cleanup((TGCompositeFrame*)el->fFrame);
131  }
132  Cleanup();
133 }
134 
135 ////////////////////////////////////////////////////////////////////////////////
136 /// Connect signals to slots.
137 
138 void TGeoEltuEditor::ConnectSignals2Slots()
139 {
140  fApply->Connect("Clicked()", "TGeoEltuEditor", this, "DoApply()");
141  fUndo->Connect("Clicked()", "TGeoEltuEditor", this, "DoUndo()");
142  fShapeName->Connect("TextChanged(const char *)", "TGeoEltuEditor", this, "DoModified()");
143  fEA->Connect("ValueSet(Long_t)", "TGeoEltuEditor", this, "DoA()");
144  fEB->Connect("ValueSet(Long_t)", "TGeoEltuEditor", this, "DoB()");
145  fEDz->Connect("ValueSet(Long_t)", "TGeoEltuEditor", this, "DoDz()");
146  fEA->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoEltuEditor", this, "DoModified()");
147  fEB->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoEltuEditor", this, "DoModified()");
148  fEDz->GetNumberEntry()->Connect("TextChanged(const char *)", "TGeoEltuEditor", this, "DoModified()");
149  fInit = kFALSE;
150 }
151 
152 ////////////////////////////////////////////////////////////////////////////////
153 /// Connect to the selected object.
154 
155 void TGeoEltuEditor::SetModel(TObject* obj)
156 {
157  if (obj == 0 || (obj->IsA()!=TGeoEltu::Class())) {
158  SetActive(kFALSE);
159  return;
160  }
161  fShape = (TGeoEltu*)obj;
162  fAi = fShape->GetA();
163  fBi = fShape->GetB();
164  fDzi = fShape->GetDz();
165  const char *sname = fShape->GetName();
166  if (!strcmp(sname, fShape->ClassName())) fShapeName->SetText("-no_name");
167  else {
168  fShapeName->SetText(sname);
169  fNamei = sname;
170  }
171  fEA->SetNumber(fAi);
172  fEB->SetNumber(fBi);
173  fEDz->SetNumber(fDzi);
174  fApply->SetEnabled(kFALSE);
175  fUndo->SetEnabled(kFALSE);
176 
177  if (fInit) ConnectSignals2Slots();
178  SetActive();
179 }
180 
181 ////////////////////////////////////////////////////////////////////////////////
182 /// Slot for name.
183 
184 void TGeoEltuEditor::DoName()
185 {
186  DoModified();
187 }
188 
189 ////////////////////////////////////////////////////////////////////////////////
190 /// Check if shape drawing is delayed.
191 
192 Bool_t TGeoEltuEditor::IsDelayed() const
193 {
194  return (fDelayed->GetState() == kButtonDown);
195 }
196 
197 ////////////////////////////////////////////////////////////////////////////////
198 /// Slot for applying current settings.
199 
200 void TGeoEltuEditor::DoApply()
201 {
202  const char *name = fShapeName->GetText();
203  if (strcmp(name,fShape->GetName())) fShape->SetName(name);
204  Double_t a = fEA->GetNumber();
205  Double_t b = fEB->GetNumber();
206  Double_t z = fEDz->GetNumber();
207  Double_t param[3];
208  param[0] = a;
209  param[1] = b;
210  param[2] = z;
211  fShape->SetDimensions(param);
212  fShape->ComputeBBox();
213  fUndo->SetEnabled();
214  fApply->SetEnabled(kFALSE);
215  if (fPad) {
216  if (gGeoManager && gGeoManager->GetPainter() && gGeoManager->GetPainter()->IsPaintingShape()) {
217  TView *view = fPad->GetView();
218  if (!view) {
219  fShape->Draw();
220  fPad->GetView()->ShowAxis();
221  } else {
222  view->SetRange(-fShape->GetDX(), -fShape->GetDY(), -fShape->GetDZ(),
223  fShape->GetDX(), fShape->GetDY(), fShape->GetDZ());
224  Update();
225  }
226  } else Update();
227  }
228 }
229 
230 ////////////////////////////////////////////////////////////////////////////////
231 /// Slot for notifying modifications.
232 
233 void TGeoEltuEditor::DoModified()
234 {
235  fApply->SetEnabled();
236 }
237 
238 ////////////////////////////////////////////////////////////////////////////////
239 /// Slot for undoing last operation.
240 
241 void TGeoEltuEditor::DoUndo()
242 {
243  fEA->SetNumber(fAi);
244  fEB->SetNumber(fBi);
245  fEDz->SetNumber(fDzi);
246  DoApply();
247  fUndo->SetEnabled(kFALSE);
248  fApply->SetEnabled(kFALSE);
249 }
250 
251 ////////////////////////////////////////////////////////////////////////////////
252 /// Slot for A.
253 
254 void TGeoEltuEditor::DoA()
255 {
256  Double_t a = fEA->GetNumber();
257  if (a <= 0) {
258  a = 0.1;
259  fEA->SetNumber(a);
260  }
261  DoModified();
262  if (!IsDelayed()) DoApply();
263 }
264 
265 ////////////////////////////////////////////////////////////////////////////////
266 /// Slot for B.
267 
268 void TGeoEltuEditor::DoB()
269 {
270  Double_t b = fEB->GetNumber();
271  if (b <= 0) {
272  b = 0.1;
273  fEB->SetNumber(b);
274  }
275  DoModified();
276  if (!IsDelayed()) DoApply();
277 }
278 
279 ////////////////////////////////////////////////////////////////////////////////
280 /// Slot for Z.
281 
282 void TGeoEltuEditor::DoDz()
283 {
284  Double_t z = fEDz->GetNumber();
285  if (z <= 0) {
286  z = 0.1;
287  fEDz->SetNumber(z);
288  }
289  DoModified();
290  if (!IsDelayed()) DoApply();
291 }
292