Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
TGeoNodeEditor.cxx
Go to the documentation of this file.
1 // @(#):$Id: b94274447e46ae2cf700c562e57c3c38c6612b74 $
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 TGeoNodeEditor
13 \ingroup Geometry_builder
14 
15 Editor class for TGeoNode objects.
16 
17 */
18 
19 #include "TGeoNodeEditor.h"
20 #include "TGedEditor.h"
21 #include "TGeoManager.h"
22 #include "TGeoMatrix.h"
23 #include "TGeoNode.h"
24 #include "TPad.h"
25 #include "TGTab.h"
26 #include "TGComboBox.h"
27 #include "TGButton.h"
28 #include "TGTextEntry.h"
29 #include "TGNumberEntry.h"
30 #include "TGLabel.h"
31 #include "TGeoTabManager.h"
32 
33 ClassImp(TGeoNodeEditor);
34 
35 enum ETGeoNodeWid {
36  kNODE_NAME, kNODE_ID, kNODE_VOLSEL, kNODE_MVOLSEL,
37  kNODE_MATRIX, kNODE_EDIT_VOL, kNODE_EDIT_MATRIX
38 };
39 
40 ////////////////////////////////////////////////////////////////////////////////
41 /// Constructor for node editor
42 
43 TGeoNodeEditor::TGeoNodeEditor(const TGWindow *p, Int_t width,
44  Int_t height, UInt_t options, Pixel_t back)
45  : TGeoGedFrame(p, width, height, options | kVerticalFrame, back)
46 {
47  fNode = 0;
48  fIsEditable = kTRUE;
49  Pixel_t color;
50 
51  // TextEntry for medium name
52  TGTextEntry *nef;
53  MakeTitle("Name");
54  TGCompositeFrame *f1 = new TGCompositeFrame(this, 140, 30, kHorizontalFrame | kRaisedFrame);
55  fNodeName = new TGTextEntry(f1, new TGTextBuffer(50), kNODE_NAME);
56  fNodeName->Resize(100, fNodeName->GetDefaultHeight());
57  fNodeName->SetToolTipText("Enter the node name");
58  fNodeName->Associate(this);
59  f1->AddFrame(fNodeName, new TGLayoutHints(kLHintsLeft, 3, 1, 2, 5));
60  f1->AddFrame(new TGLabel(f1, "ID"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
61  fNodeNumber = new TGNumberEntry(f1, 0., 1, kNODE_ID);
62  nef = (TGTextEntry*)fNodeNumber->GetNumberEntry();
63  nef->SetToolTipText("Enter the node copy number");
64  fNodeNumber->Associate(this);
65  f1->AddFrame(fNodeNumber, new TGLayoutHints(kLHintsLeft | kLHintsExpandX , 2, 2, 4, 4));
66  AddFrame(f1, new TGLayoutHints(kLHintsLeft, 3, 3, 2, 5));
67 
68 
69 // Mother volume selection
70  MakeTitle("Mother volume");
71  f1 = new TGCompositeFrame(this, 155, 30, kHorizontalFrame | kFixedWidth);
72  fSelectedMother = 0;
73  fLSelMother = new TGLabel(f1, "Select mother");
74  gClient->GetColorByName("#0000ff", color);
75  fLSelMother->SetTextColor(color);
76  fLSelMother->ChangeOptions(kSunkenFrame | kDoubleBorder);
77  f1->AddFrame(fLSelMother, new TGLayoutHints(kLHintsLeft | kLHintsExpandX | kLHintsExpandY, 1, 1, 2, 2));
78  fBSelMother = new TGPictureButton(f1, fClient->GetPicture("rootdb_t.xpm"), kNODE_MVOLSEL);
79  fBSelMother->SetToolTipText("Select one of the existing volumes");
80  fBSelMother->Associate(this);
81  f1->AddFrame(fBSelMother, new TGLayoutHints(kLHintsLeft, 1, 1, 2, 2));
82  fEditMother = new TGTextButton(f1, "Edit");
83  f1->AddFrame(fEditMother, new TGLayoutHints(kLHintsRight, 1, 1, 1, 1));
84  fEditMother->Associate(this);
85  AddFrame(f1, new TGLayoutHints(kLHintsLeft, 2, 2, 0, 2));
86 
87 // Volume selection
88  MakeTitle("Volume");
89  f1 = new TGCompositeFrame(this, 155, 30, kHorizontalFrame | kFixedWidth);
90  fSelectedVolume = 0;
91  fLSelVolume = new TGLabel(f1, "Select volume");
92  gClient->GetColorByName("#0000ff", color);
93  fLSelVolume->SetTextColor(color);
94  fLSelVolume->ChangeOptions(kSunkenFrame | kDoubleBorder);
95  f1->AddFrame(fLSelVolume, new TGLayoutHints(kLHintsLeft | kLHintsExpandX | kLHintsExpandY, 1, 1, 2, 2));
96  fBSelVolume = new TGPictureButton(f1, fClient->GetPicture("rootdb_t.xpm"), kNODE_VOLSEL);
97  fBSelVolume->SetToolTipText("Select one of the existing volumes");
98  fBSelVolume->Associate(this);
99  f1->AddFrame(fBSelVolume, new TGLayoutHints(kLHintsLeft, 1, 1, 2, 2));
100  fEditVolume = new TGTextButton(f1, "Edit");
101  f1->AddFrame(fEditVolume, new TGLayoutHints(kLHintsRight, 1, 1, 1, 1));
102  fEditVolume->Associate(this);
103  AddFrame(f1, new TGLayoutHints(kLHintsLeft, 2, 2, 0, 2));
104 
105 // Matrix selection
106  MakeTitle("Matrix");
107  f1 = new TGCompositeFrame(this, 155, 30, kHorizontalFrame | kFixedWidth);
108  fSelectedMatrix = 0;
109  fLSelMatrix = new TGLabel(f1, "Select matrix");
110  gClient->GetColorByName("#0000ff", color);
111  fLSelMatrix->SetTextColor(color);
112  fLSelMatrix->ChangeOptions(kSunkenFrame | kDoubleBorder);
113  f1->AddFrame(fLSelMatrix, new TGLayoutHints(kLHintsLeft | kLHintsExpandX | kLHintsExpandY, 1, 1, 2, 2));
114  fBSelMatrix = new TGPictureButton(f1, fClient->GetPicture("rootdb_t.xpm"), kNODE_MATRIX);
115  fBSelMatrix->SetToolTipText("Select one of the existing matrices");
116  fBSelMatrix->Associate(this);
117  f1->AddFrame(fBSelMatrix, new TGLayoutHints(kLHintsLeft, 1, 1, 2, 2));
118  fEditMatrix = new TGTextButton(f1, "Edit");
119  f1->AddFrame(fEditMatrix, new TGLayoutHints(kLHintsRight, 1, 1, 1, 1));
120  fEditMatrix->Associate(this);
121  AddFrame(f1, new TGLayoutHints(kLHintsLeft, 2, 2, 0, 2));
122 
123  // Buttons
124  f1 = new TGCompositeFrame(this, 155, 10, kHorizontalFrame | kFixedWidth);
125  fApply = new TGTextButton(f1, "Apply");
126  f1->AddFrame(fApply, new TGLayoutHints(kLHintsLeft, 2, 2, 4, 4));
127  fApply->Associate(this);
128  fUndo = new TGTextButton(f1, "Undo");
129  f1->AddFrame(fUndo, new TGLayoutHints(kLHintsRight , 2, 2, 4, 4));
130  fUndo->Associate(this);
131  AddFrame(f1, new TGLayoutHints(kLHintsLeft, 6, 6, 4, 4));
132  fUndo->SetSize(fApply->GetSize());
133 }
134 
135 ////////////////////////////////////////////////////////////////////////////////
136 /// Destructor
137 
138 TGeoNodeEditor::~TGeoNodeEditor()
139 {
140  TGFrameElement *el;
141  TIter next(GetList());
142  while ((el = (TGFrameElement *)next())) {
143  if (el->fFrame->IsComposite())
144  TGeoTabManager::Cleanup((TGCompositeFrame*)el->fFrame);
145  }
146  Cleanup();
147 }
148 
149 ////////////////////////////////////////////////////////////////////////////////
150 /// Connect signals to slots.
151 
152 void TGeoNodeEditor::ConnectSignals2Slots()
153 {
154  fBSelMother->Connect("Clicked()", "TGeoNodeEditor", this, "DoSelectMother()");
155  fBSelVolume->Connect("Clicked()", "TGeoNodeEditor", this, "DoSelectVolume()");
156  fBSelMatrix->Connect("Clicked()", "TGeoNodeEditor", this, "DoSelectMatrix()");
157  fApply->Connect("Clicked()", "TGeoNodeEditor", this, "DoApply()");
158  fUndo->Connect("Clicked()", "TGeoNodeEditor", this, "DoUndo()");
159  fEditMother->Connect("Clicked()", "TGeoNodeEditor", this, "DoEditMother()");
160  fEditVolume->Connect("Clicked()", "TGeoNodeEditor", this, "DoEditVolume()");
161  fEditMatrix->Connect("Clicked()", "TGeoNodeEditor", this, "DoEditMatrix()");
162  fNodeName->Connect("TextChanged(const char *)", "TGeoNodeEditor", this, "DoNodeName()");
163  fInit = kFALSE;
164 }
165 
166 
167 ////////////////////////////////////////////////////////////////////////////////
168 /// Connect to a editable object.
169 
170 void TGeoNodeEditor::SetModel(TObject* obj)
171 {
172  if (obj == 0 || !obj->InheritsFrom(TGeoNode::Class())) {
173  SetActive(kFALSE);
174  return;
175  }
176  fNode = (TGeoNode*)obj;
177  const char *sname = fNode->GetName();
178  fNodeName->SetText(sname);
179 
180  fNodeNumber->SetNumber(fNode->GetNumber());
181 
182  fSelectedMother = fNode->GetMotherVolume();
183  if (fSelectedMother) fLSelMother->SetText(fSelectedMother->GetName());
184  fSelectedVolume = fNode->GetVolume();
185  if (fSelectedVolume) fLSelVolume->SetText(fSelectedVolume->GetName());
186  fSelectedMatrix = fNode->GetMatrix();
187  if (fSelectedMatrix) fLSelMatrix->SetText(fSelectedMatrix->GetName());
188 
189  fApply->SetEnabled(kFALSE);
190  fUndo->SetEnabled(kFALSE);
191 
192  if (fInit) ConnectSignals2Slots();
193  SetActive();
194 }
195 
196 ////////////////////////////////////////////////////////////////////////////////
197 /// Select the mother volume.
198 
199 void TGeoNodeEditor::DoSelectMother()
200 {
201  TGeoVolume *vol = fSelectedMother;
202  new TGeoVolumeDialog(fBSelMother, gClient->GetRoot(), 200,300);
203  fSelectedMother = (TGeoVolume*)TGeoVolumeDialog::GetSelected();
204  if (fSelectedMother) fLSelMother->SetText(fSelectedMother->GetName());
205  else fSelectedMother = vol;
206 }
207 
208 ////////////////////////////////////////////////////////////////////////////////
209 /// Select the volume.
210 
211 void TGeoNodeEditor::DoSelectVolume()
212 {
213  TGeoVolume *vol = fSelectedVolume;
214  new TGeoVolumeDialog(fBSelVolume, gClient->GetRoot(), 200,300);
215  fSelectedVolume = (TGeoVolume*)TGeoVolumeDialog::GetSelected();
216  if (fSelectedVolume) fLSelVolume->SetText(fSelectedVolume->GetName());
217  else fSelectedVolume = vol;
218 }
219 
220 ////////////////////////////////////////////////////////////////////////////////
221 /// Select the matrix.
222 
223 void TGeoNodeEditor::DoSelectMatrix()
224 {
225  TGeoMatrix *matrix = fSelectedMatrix;
226  new TGeoMatrixDialog(fBSelMatrix, gClient->GetRoot(), 200,300);
227  fSelectedMatrix = (TGeoMatrix*)TGeoMatrixDialog::GetSelected();
228  if (fSelectedMatrix) fLSelMatrix->SetText(fSelectedMatrix->GetName());
229  else fSelectedMatrix = matrix;
230 }
231 
232 ////////////////////////////////////////////////////////////////////////////////
233 /// Edit the mother volume.
234 
235 void TGeoNodeEditor::DoEditMother()
236 {
237  if (!fSelectedMother) {
238  fTabMgr->SetVolTabEnabled(kFALSE);
239  return;
240  }
241  fTabMgr->SetVolTabEnabled();
242  fTabMgr->GetVolumeEditor(fSelectedMother);
243  fTabMgr->SetTab();
244  fSelectedMother->Draw();
245 }
246 
247 ////////////////////////////////////////////////////////////////////////////////
248 /// Edit selected volume.
249 
250 void TGeoNodeEditor::DoEditVolume()
251 {
252  if (!fSelectedVolume) {
253  fTabMgr->SetVolTabEnabled(kFALSE);
254  return;
255  }
256  fTabMgr->SetVolTabEnabled();
257  fTabMgr->GetVolumeEditor(fSelectedVolume);
258  fTabMgr->SetTab();
259  fSelectedVolume->Draw();
260 }
261 
262 ////////////////////////////////////////////////////////////////////////////////
263 /// Edit selected material.
264 
265 void TGeoNodeEditor::DoEditMatrix()
266 {
267  if (!fSelectedMatrix) return;
268  fTabMgr->GetMatrixEditor(fSelectedMatrix);
269 }
270 
271 ////////////////////////////////////////////////////////////////////////////////
272 /// Change node name.
273 
274 void TGeoNodeEditor::DoNodeName()
275 {
276  const char *name = fNodeName->GetText();
277  if (!name[0] || !strcmp(name, fNode->GetName())) return;
278  fNode->SetName(name);
279 }
280 
281 ////////////////////////////////////////////////////////////////////////////////
282 /// Change node copy number
283 
284 void TGeoNodeEditor::DoNodeNumber()
285 {
286 }
287 
288 ////////////////////////////////////////////////////////////////////////////////
289 /// Slot for applying modifications.
290 
291 void TGeoNodeEditor::DoApply()
292 {
293 }
294 
295 ////////////////////////////////////////////////////////////////////////////////
296 /// Slot for undoing last operation.
297 
298 void TGeoNodeEditor::DoUndo()
299 {
300 }
301