Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
TGeoVolumeEditor.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 TGeoVolumeEditor
13 \ingroup Geometry_builder
14 
15 Editor for geometry volumes and assemblies of volumes. Besides the volume
16 name and line attributes, a TGeoVolume has the following editable categories
17 split vertically by a shutter:
18 
19  - Properties: one can edit the shape and medium components from here. It is
20  also possible to change the existing ones.
21  - Daughters: the main category allowing defining, editing, removing or
22  positioning daughter volumes inside the current edited volume. To add a
23  daughter, one needs to select first a volume and a matrix. Currently no check
24  is performed if the daughter volume creates an extrusion (illegal for tracking).
25  To remove or change the position of an existing daughter, one should simply
26  select the desired daughter from the combo box with the existing ones, then
27  simply click the appropriate button.
28  - Visualization: One can set the visibility of the volume and of its daughters,
29  set the visibility depth and the view type. Selecting "All" will draw the
30  volume and all visible daughters down to the selected level starting from the
31  edited volume. Selecting "Leaves" will draw just the deepest daughters within
32  the selected visibility level, without displaying the containers, while "Only"
33  will just draw the edited volume.
34  - Division: The category becomes active only if there are no daughters of the
35  edited volume added by normal positioning (e.g. from <Daughters> category). The
36  minimum allowed starting value for the selected division axis is automatically
37  selected, while the slicing step is set to 0 - meaning that only the number
38  of slices matter.
39 */
40 
41 #include "TGeoVolumeEditor.h"
42 #include "TGeoVolume.h"
43 #include "TGeoPatternFinder.h"
44 #include "TGeoManager.h"
45 #include "TGeoMatrix.h"
46 #include "TVirtualPad.h"
47 #include "TGTab.h"
48 #include "TGComboBox.h"
49 #include "TGButton.h"
50 #include "TGButtonGroup.h"
51 #include "TGTextEntry.h"
52 #include "TGNumberEntry.h"
53 #include "TGLabel.h"
54 #include "TGShutter.h"
55 #include "TG3DLine.h"
56 #include "TGeoTabManager.h"
57 #include "TGedEditor.h"
58 
59 ClassImp(TGeoVolumeEditor);
60 
61 enum ETGeoVolumeWid {
62  kVOL_NAME, kVOL_TITLE, kVOL_SHAPE_SELECT, kVOL_MEDIA_SELECT, kVOL_NODE_SELECT,
63  kVOL_VOL_SELECT, kVOL_MATRIX_SELECT, kVOL_EDIT_SHAPE, kVOL_EDIT_MEDIUM, kVOL_NODEID,
64  kVOL_APPLY, kVOL_CANCEL, kVOL_UNDO, kVOL_VISLEVEL, kVOL_DIVSTART, kVOL_DIVEND,
65  kVOL_DIVSTEP, kVOL_DIVN, kCAT_GENERAL, kCAT_DAUGHTERS, kCAT_DIVISION, kCAT_VIS,
66  kDIV_NAME
67 };
68 
69 ////////////////////////////////////////////////////////////////////////////////
70 /// Constructor for volume editor.
71 
72 TGeoVolumeEditor::TGeoVolumeEditor(const TGWindow *p, Int_t width,
73  Int_t height, UInt_t options, Pixel_t back)
74  : TGeoGedFrame(p, width, height, options | kVerticalFrame, back)
75 {
76  fGeometry = 0;
77  fVolume = 0;
78 
79  fIsModified = kFALSE;
80  fIsAssembly = kFALSE;
81  fIsDivided = kFALSE;
82 
83  // TGShutter for categories
84  fCategories = new TGShutter(this, kSunkenFrame);
85  TGCompositeFrame *container, *f1;
86  Pixel_t color;
87  TGLabel *label;
88 
89  // General settings
90  TGShutterItem *si = new TGShutterItem(fCategories, new TGHotString("Properties"),kCAT_GENERAL);
91  container = (TGCompositeFrame*)si->GetContainer();
92  container->SetBackgroundColor(GetDefaultFrameBackground());
93  fCategories->AddItem(si);
94 
95  // TextEntry for volume name
96  f1 = new TGCompositeFrame(container, 155, 10, kHorizontalFrame | kFixedWidth);
97  f1->AddFrame(label = new TGLabel(f1, "Volume name"), new TGLayoutHints(kLHintsLeft, 1, 1, 0, 0));
98  f1->AddFrame(new TGHorizontal3DLine(f1), new TGLayoutHints(kLHintsExpandX, 5, 5, 7, 7));
99  gClient->GetColorByName("#ff0000", color);
100  label->SetTextColor(color);
101  container->AddFrame(f1, new TGLayoutHints(kLHintsTop, 0, 0, 2, 0));
102  fVolumeName = new TGTextEntry(container, "", kVOL_NAME);
103  fVolumeName->SetDefaultSize(135, fVolumeName->GetDefaultHeight());
104  fVolumeName->SetToolTipText("Enter the volume name");
105  container->AddFrame(fVolumeName, new TGLayoutHints(kLHintsLeft | kLHintsExpandX, 3, 1, 2, 5));
106 
107  // Current shape
108  f1 = new TGCompositeFrame(container, 155, 10, kHorizontalFrame | kFixedWidth);
109  f1->AddFrame(label = new TGLabel(f1, "Shape and medium"), new TGLayoutHints(kLHintsLeft, 1, 1, 0, 0));
110  f1->AddFrame(new TGHorizontal3DLine(f1), new TGLayoutHints(kLHintsExpandX, 5, 5, 7, 7));
111  gClient->GetColorByName("#ff0000", color);
112  label->SetTextColor(color);
113  container->AddFrame(f1, new TGLayoutHints(kLHintsTop, 0, 0, 10, 0));
114  f1 = new TGCompositeFrame(container, 155, 30, kHorizontalFrame);
115  fSelectedShape = 0;
116  fLSelShape = new TGLabel(f1, "Select shape");
117  gClient->GetColorByName("#0000ff", color);
118  fLSelShape->SetTextColor(color);
119  fLSelShape->ChangeOptions(kSunkenFrame | kDoubleBorder);
120  f1->AddFrame(fLSelShape, new TGLayoutHints(kLHintsLeft | kLHintsExpandX | kLHintsExpandY, 1, 1, 2, 2));
121  fBSelShape = new TGPictureButton(f1, fClient->GetPicture("rootdb_t.xpm"), kVOL_SHAPE_SELECT);
122  fBSelShape->SetToolTipText("Replace with one of the existing shapes");
123  fBSelShape->Associate(this);
124  f1->AddFrame(fBSelShape, new TGLayoutHints(kLHintsLeft, 1, 1, 2, 2));
125  fEditShape = new TGTextButton(f1, "Edit");
126  f1->AddFrame(fEditShape, new TGLayoutHints(kLHintsLeft, 1, 1, 2, 2));
127  fEditShape->SetToolTipText("Edit selected shape");
128  fEditShape->Associate(this);
129  container->AddFrame(f1, new TGLayoutHints(kLHintsLeft | kLHintsExpandX, 2, 2, 0, 0));
130 
131  // Current medium
132  f1 = new TGCompositeFrame(container, 155, 30, kHorizontalFrame);
133  fSelectedMedium = 0;
134  fLSelMedium = new TGLabel(f1, "Select medium");
135  gClient->GetColorByName("#0000ff", color);
136  fLSelMedium->SetTextColor(color);
137  fLSelMedium->ChangeOptions(kSunkenFrame | kDoubleBorder);
138  f1->AddFrame(fLSelMedium, new TGLayoutHints(kLHintsLeft | kLHintsExpandX | kLHintsExpandY, 1, 1, 2, 2));
139  fBSelMedium = new TGPictureButton(f1, fClient->GetPicture("rootdb_t.xpm"), kVOL_MEDIA_SELECT);
140  fBSelMedium->SetToolTipText("Replace with one of the existing media");
141  fBSelMedium->Associate(this);
142  f1->AddFrame(fBSelMedium, new TGLayoutHints(kLHintsLeft, 1, 1, 2, 2));
143  fEditMedium = new TGTextButton(f1, "Edit");
144  f1->AddFrame(fEditMedium, new TGLayoutHints(kLHintsLeft, 1, 1, 2, 2));
145  fEditMedium->SetToolTipText("Edit selected medium");
146  fEditMedium->Associate(this);
147  container->AddFrame(f1, new TGLayoutHints(kLHintsLeft | kLHintsExpandX, 2, 2, 0, 0));
148 
149  // List of daughters
150  si = new TGShutterItem(fCategories, new TGHotString("Daughters"),kCAT_DAUGHTERS);
151  container = (TGCompositeFrame*)si->GetContainer();
152  container->SetBackgroundColor(GetDefaultFrameBackground());
153  fCategories->AddItem(si);
154 
155  // Existing daughters
156  f1 = new TGCompositeFrame(container, 155, 10, kHorizontalFrame | kFixedWidth);
157  f1->AddFrame(label = new TGLabel(f1, "Existing daughters"), new TGLayoutHints(kLHintsLeft, 1, 1, 0, 0));
158  f1->AddFrame(new TGHorizontal3DLine(f1), new TGLayoutHints(kLHintsExpandX, 5, 5, 7, 7));
159  gClient->GetColorByName("#ff0000", color);
160  label->SetTextColor(color);
161  container->AddFrame(f1, new TGLayoutHints(kLHintsTop, 0, 0, 2, 0));
162 
163  f1 = new TGCompositeFrame(container, 155, 30, kHorizontalFrame | kRaisedFrame);
164  fNodeList = new TGComboBox(f1, kVOL_NODE_SELECT);
165  fNodeList->Resize(100, fVolumeName->GetDefaultHeight());
166  fNodeList->Associate(this);
167  f1->AddFrame(fNodeList, new TGLayoutHints(kLHintsLeft, 3, 1, 2, 5));
168  container->AddFrame(f1, new TGLayoutHints(kLHintsLeft, 2, 2, 0, 2));
169  // Buttons for editing matrix and removing node
170  f1 = new TGCompositeFrame(container, 155, 30, kHorizontalFrame | kSunkenFrame | kFixedWidth);
171  fEditMatrix = new TGTextButton(f1, "Position");
172  f1->AddFrame(fEditMatrix, new TGLayoutHints(kLHintsLeft, 2, 2, 2, 2));
173  fEditMatrix->SetToolTipText("Edit the position of selected node");
174  fEditMatrix->Associate(this);
175  fRemoveNode = new TGTextButton(f1, "Remove");
176  f1->AddFrame(fRemoveNode, new TGLayoutHints(kLHintsRight, 2, 2, 2, 2));
177  fRemoveNode->SetToolTipText("Remove the selected node. Cannot undo !)");
178  fRemoveNode->Associate(this);
179  container->AddFrame(f1, new TGLayoutHints(kLHintsLeft, 2, 2, 0, 2));
180 
181  // Adding daughters
182  f1 = new TGCompositeFrame(container, 155, 10, kHorizontalFrame | kFixedWidth);
183  f1->AddFrame(label = new TGLabel(f1, "Add daughter"), new TGLayoutHints(kLHintsLeft, 1, 1, 0, 0));
184  f1->AddFrame(new TGHorizontal3DLine(f1), new TGLayoutHints(kLHintsExpandX, 5, 5, 7, 7));
185  gClient->GetColorByName("#ff0000", color);
186  label->SetTextColor(color);
187  container->AddFrame(f1, new TGLayoutHints(kLHintsTop, 0, 0, 10, 0));
188 
189  // Select from existing volumes
190  f1 = new TGCompositeFrame(container, 155, 30, kHorizontalFrame | kFixedWidth);
191  fSelectedVolume = 0;
192  fLSelVolume = new TGLabel(f1, "Select volume");
193  gClient->GetColorByName("#0000ff", color);
194  fLSelVolume->SetTextColor(color);
195  fLSelVolume->ChangeOptions(kSunkenFrame | kDoubleBorder);
196  f1->AddFrame(fLSelVolume, new TGLayoutHints(kLHintsLeft | kLHintsExpandX | kLHintsExpandY, 1, 1, 2, 2));
197  fBSelVolume = new TGPictureButton(f1, fClient->GetPicture("rootdb_t.xpm"), kVOL_VOL_SELECT);
198  fBSelVolume->SetToolTipText("Select one of the existing volumes");
199  fBSelVolume->Associate(this);
200  f1->AddFrame(fBSelVolume, new TGLayoutHints(kLHintsRight, 1, 1, 2, 2));
201  container->AddFrame(f1, new TGLayoutHints(kLHintsLeft, 2, 2, 0, 2));
202 
203  // Matrix selection for nodes
204  f1 = new TGCompositeFrame(container, 155, 30, kHorizontalFrame | kFixedWidth);
205  fSelectedMatrix = 0;
206  fLSelMatrix = new TGLabel(f1, "Select matrix");
207  gClient->GetColorByName("#0000ff", color);
208  fLSelMatrix->SetTextColor(color);
209  fLSelMatrix->ChangeOptions(kSunkenFrame | kDoubleBorder);
210  f1->AddFrame(fLSelMatrix, new TGLayoutHints(kLHintsLeft | kLHintsExpandX | kLHintsExpandY, 1, 1, 2, 2));
211  fBSelMatrix = new TGPictureButton(f1, fClient->GetPicture("rootdb_t.xpm"), kVOL_MATRIX_SELECT);
212  fBSelMatrix->SetToolTipText("Select one of the existing matrices");
213  fBSelMatrix->Associate(this);
214  f1->AddFrame(fBSelMatrix, new TGLayoutHints(kLHintsRight, 1, 1, 2, 2));
215  container->AddFrame(f1, new TGLayoutHints(kLHintsLeft, 2, 2, 0, 2));
216 
217  // Copy number
218  f1 = new TGCompositeFrame(container, 155, 30, kHorizontalFrame | kFixedWidth);
219  f1->AddFrame(new TGLabel(f1, "Node id"), new TGLayoutHints(kLHintsLeft, 1, 1, 6, 0));
220  fCopyNumber = new TGNumberEntry(f1, 0., 5, kVOL_NODEID);
221  fCopyNumber->SetNumStyle(TGNumberFormat::kNESInteger);
222  fCopyNumber->SetNumAttr(TGNumberFormat::kNEANonNegative);
223  fCopyNumber->Resize(20,fCopyNumber->GetDefaultHeight());
224  TGTextEntry *nef = (TGTextEntry*)fCopyNumber->GetNumberEntry();
225  nef->SetToolTipText("Enter node copy number");
226  fCopyNumber->Associate(this);
227  f1->AddFrame(fCopyNumber, new TGLayoutHints(kLHintsLeft, 2, 2, 2, 2));
228  fAddNode = new TGTextButton(f1, "Add");
229  f1->AddFrame(fAddNode, new TGLayoutHints(kLHintsRight, 2, 2, 2, 2));
230  fAddNode->Associate(this);
231  container->AddFrame(f1, new TGLayoutHints(kLHintsLeft, 2, 2, 0, 2));
232 
233  // Visualization
234  si = new TGShutterItem(fCategories, new TGHotString("Visualization"),kCAT_VIS);
235  container = (TGCompositeFrame*)si->GetContainer();
236  container->SetBackgroundColor(GetDefaultFrameBackground());
237  fCategories->AddItem(si);
238 
239  f1 = new TGCompositeFrame(container, 155, 10, kHorizontalFrame | kFixedWidth);
240  f1->AddFrame(label = new TGLabel(f1, "Visibility"), new TGLayoutHints(kLHintsLeft, 1, 1, 0, 0));
241  f1->AddFrame(new TGHorizontal3DLine(f1), new TGLayoutHints(kLHintsExpandX, 5, 5, 7, 7));
242 // gClient->GetColorByName("#ff0000", color);
243 // label->SetTextColor(color);
244  container->AddFrame(f1, new TGLayoutHints(kLHintsTop, 0, 0, 2, 0));
245 
246  f1 = new TGCompositeFrame(container, 155, 10, kHorizontalFrame | kFixedWidth | kSunkenFrame | kDoubleBorder);
247  fBVis[0] = new TGCheckButton(f1, "Volume");
248  fBVis[1] = new TGCheckButton(f1, "Nodes");
249  f1->AddFrame(fBVis[0], new TGLayoutHints(kLHintsLeft, 2, 2, 0 ,0));
250  f1->AddFrame(fBVis[1], new TGLayoutHints(kLHintsRight, 2, 2, 0 ,0));
251  container->AddFrame(f1, new TGLayoutHints(kLHintsLeft, 2, 2, 0, 0));
252 
253  f1 = new TGCompositeFrame(container, 155, 10, kHorizontalFrame | kFixedWidth);
254  f1->AddFrame(new TGLabel(f1, "Depth"), new TGLayoutHints(kLHintsLeft, 2, 2, 4, 0));
255 // gClient->GetColorByName("#0000ff", color);
256 // label->SetTextColor(color);
257  fEVisLevel = new TGNumberEntry(f1, 0, 5, kVOL_VISLEVEL);
258  fEVisLevel->SetNumStyle(TGNumberFormat::kNESInteger);
259  fEVisLevel->SetNumAttr(TGNumberFormat::kNEAPositive);
260  fEVisLevel->Resize(40,fEVisLevel->GetDefaultHeight());
261  nef = (TGTextEntry*)fEVisLevel->GetNumberEntry();
262  nef->SetToolTipText("Set visibility level here");
263  fEVisLevel->SetNumber(3);
264  fEVisLevel->Associate(this);
265  f1->AddFrame(fEVisLevel, new TGLayoutHints(kLHintsLeft, 2, 2, 0 ,0));
266  fBAuto = new TGCheckButton(f1,"Auto");
267  f1->AddFrame(fBAuto, new TGLayoutHints(kLHintsRight, 0, 0, 2, 0));
268  container->AddFrame(f1, new TGLayoutHints(kLHintsLeft, 2, 2, 4, 4));
269 
270  TString stitle = "View";
271  TGButtonGroup *bg = new TGVButtonGroup(container, stitle);
272  fBView[0] = new TGRadioButton(bg, "All");
273  fBView[1] = new TGRadioButton(bg, "Leaves");
274  fBView[2] = new TGRadioButton(bg, "Only");
275  bg->SetRadioButtonExclusive();
276  bg->Show();
277  container->AddFrame(bg, new TGLayoutHints(kLHintsLeft, 2, 2, 0, 0));
278 
279  f1 = new TGCompositeFrame(container, 155, 10, kHorizontalFrame | kFixedWidth | kSunkenFrame | kDoubleBorder);
280  fBRaytrace = new TGCheckButton(f1,"Raytrace");
281  f1->AddFrame(fBRaytrace, new TGLayoutHints(kLHintsLeft, 2, 2, 2, 2));
282  container->AddFrame(f1, new TGLayoutHints(kLHintsLeft, 2, 2, 4, 4));
283 
284  // Division
285  si = new TGShutterItem(fCategories, new TGHotString("Division"),kCAT_DIVISION);
286  container = (TGCompositeFrame*)si->GetContainer();
287  container->SetBackgroundColor(GetDefaultFrameBackground());
288  fCategories->AddItem(si);
289  // TextEntry for division name
290  f1 = new TGCompositeFrame(container, 155, 10, kHorizontalFrame | kFixedWidth);
291  f1->AddFrame(label = new TGLabel(f1, "Division name"), new TGLayoutHints(kLHintsLeft, 1, 1, 0, 0));
292  f1->AddFrame(new TGHorizontal3DLine(f1), new TGLayoutHints(kLHintsExpandX, 5, 5, 7, 7));
293  gClient->GetColorByName("#ff0000", color);
294  label->SetTextColor(color);
295  container->AddFrame(f1, new TGLayoutHints(kLHintsTop, 0, 0, 2, 0));
296  fDivName = new TGTextEntry(container, new TGTextBuffer(50), kDIV_NAME);
297  fDivName->Resize(135, fVolumeName->GetDefaultHeight());
298  fDivName->SetToolTipText("Enter the volume name");
299  container->AddFrame(fDivName, new TGLayoutHints(kLHintsLeft, 3, 1, 2, 5));
300  // Axis selection
301  stitle = "Axis";
302  f1 = new TGCompositeFrame(container, 155, 10, kHorizontalFrame | kFixedWidth);
303  bg = new TGVButtonGroup(f1, stitle);
304  fBDiv[0] = new TGRadioButton(bg, "Axis 1");
305  fBDiv[1] = new TGRadioButton(bg, "Axis 2");
306  fBDiv[2] = new TGRadioButton(bg, "Axis 3");
307  bg->Insert(fBDiv[0]);
308  bg->Insert(fBDiv[1]);
309  bg->Insert(fBDiv[2]);
310  bg->SetRadioButtonExclusive();
311  f1->AddFrame(bg, new TGLayoutHints(kLHintsLeft, 2, 2, 0, 0));
312  fApplyDiv = new TGTextButton(f1, "Apply");
313  fApplyDiv->SetToolTipText("Apply new division settings");
314  f1->AddFrame(fApplyDiv, new TGLayoutHints(kLHintsRight, 0, 2, 30, 0));
315  container->AddFrame(f1, new TGLayoutHints(kLHintsLeft, 0, 0, 0, 0));
316  // Division range
317  f1 = new TGCompositeFrame(container, 155, 10, kHorizontalFrame | kFixedWidth);
318  f1->AddFrame(label = new TGLabel(f1, "Division parameters"), new TGLayoutHints(kLHintsLeft, 1, 1, 0, 0));
319  f1->AddFrame(new TGHorizontal3DLine(f1), new TGLayoutHints(kLHintsExpandX, 5, 5, 7, 7));
320 // gClient->GetColorByName("#ff0000", color);
321 // label->SetTextColor(color);
322  container->AddFrame(f1, new TGLayoutHints(kLHintsTop, 0, 0, 2, 0));
323  f1 = new TGCompositeFrame(container, 155, 10, kHorizontalFrame | kFixedWidth);
324  f1->AddFrame(label = new TGLabel(f1, "From"), new TGLayoutHints(kLHintsLeft, 2, 2, 4, 0));
325 // gClient->GetColorByName("#0000ff", color);
326 // label->SetTextColor(color);
327  fEDivFrom = new TGNumberEntry(f1, 0, 5, kVOL_DIVSTART);
328 // fEDivFrom->SetNumStyle(TGNumberFormat::kNESInteger);
329 // fEDivFrom->SetNumAttr(TGNumberFormat::kNEAPositive);
330  fEDivFrom->Resize(100,fEDivFrom->GetDefaultHeight());
331  nef = (TGTextEntry*)fEDivFrom->GetNumberEntry();
332  nef->SetToolTipText("Set start value");
333  fEDivFrom->Associate(this);
334  f1->AddFrame(fEDivFrom, new TGLayoutHints(kLHintsRight, 2, 2, 0 ,0));
335  container->AddFrame(f1, new TGLayoutHints(kLHintsLeft, 2, 2, 4, 4));
336 
337  f1 = new TGCompositeFrame(container, 155, 10, kHorizontalFrame | kFixedWidth);
338  f1->AddFrame(label = new TGLabel(f1, "Step"), new TGLayoutHints(kLHintsLeft, 2, 2, 4, 0));
339 // gClient->GetColorByName("#0000ff", color);
340 // label->SetTextColor(color);
341  fEDivStep = new TGNumberEntry(f1, 0, 5, kVOL_DIVSTEP);
342 // fEDivFrom->SetNumStyle(TGNumberFormat::kNESInteger);
343  fEDivStep->SetNumAttr(TGNumberFormat::kNEANonNegative);
344  fEDivStep->Resize(100,fEDivStep->GetDefaultHeight());
345  nef = (TGTextEntry*)fEDivStep->GetNumberEntry();
346  nef->SetToolTipText("Set division step");
347  fEDivStep->Associate(this);
348  f1->AddFrame(fEDivStep, new TGLayoutHints(kLHintsRight, 2, 2, 0 ,0));
349  container->AddFrame(f1, new TGLayoutHints(kLHintsLeft, 2, 2, 4, 4));
350 
351  f1 = new TGCompositeFrame(container, 155, 10, kHorizontalFrame |kFixedWidth);
352  f1->AddFrame(label = new TGLabel(f1, "Nslices"), new TGLayoutHints(kLHintsLeft, 2, 2, 4, 0));
353 // gClient->GetColorByName("#0000ff", color);
354 // label->SetTextColor(color);
355  fEDivN = new TGNumberEntry(f1, 0, 5, kVOL_DIVN);
356  fEDivN->SetNumStyle(TGNumberFormat::kNESInteger);
357  fEDivN->SetNumAttr(TGNumberFormat::kNEAPositive);
358  fEDivN->Resize(100,fEDivN->GetDefaultHeight());
359  nef = (TGTextEntry*)fEDivN->GetNumberEntry();
360  nef->SetToolTipText("Set number of slices");
361  fEDivN->Associate(this);
362  f1->AddFrame(fEDivN, new TGLayoutHints(kLHintsRight, 2, 2, 0 ,0));
363  container->AddFrame(f1, new TGLayoutHints(kLHintsLeft, 2, 2, 4, 4));
364 
365 
366  fCategories->Resize(163,340);
367  AddFrame(fCategories, new TGLayoutHints(kLHintsLeft | kLHintsExpandX | kLHintsExpandY, 0, 0, 4, 4));
368 
369  fCategories->Layout();
370  fCategories->SetDefaultSize(GetDefaultWidth(), GetDefaultHeight());
371 }
372 
373 ////////////////////////////////////////////////////////////////////////////////
374 /// Destructor
375 
376 TGeoVolumeEditor::~TGeoVolumeEditor()
377 {
378  TGCompositeFrame *cont;
379  cont = (TGCompositeFrame*)fCategories->GetItem("Properties")->GetContainer();
380  TGeoTabManager::Cleanup(cont);
381  fCategories->GetItem("Properties")->SetCleanup(0);
382  cont = (TGCompositeFrame*)fCategories->GetItem("Daughters")->GetContainer();
383  TGeoTabManager::Cleanup(cont);
384  fCategories->GetItem("Daughters")->SetCleanup(0);
385  cont = (TGCompositeFrame*)fCategories->GetItem("Visualization")->GetContainer();
386  TGeoTabManager::Cleanup(cont);
387  fCategories->GetItem("Visualization")->SetCleanup(0);
388  cont = (TGCompositeFrame*)fCategories->GetItem("Division")->GetContainer();
389  TGeoTabManager::Cleanup(cont);
390  fCategories->GetItem("Division")->SetCleanup(0);
391 
392  delete fBView[0]; delete fBView[1]; delete fBView[2];
393  delete fBDiv [0]; delete fBDiv [1]; delete fBDiv [2];
394  Cleanup();
395 }
396 
397 ////////////////////////////////////////////////////////////////////////////////
398 /// Connect signals to slots.
399 
400 void TGeoVolumeEditor::ConnectSignals2Slots()
401 {
402  fVolumeName->Connect("TextChanged(const char *)", "TGeoVolumeEditor", this, "DoVolumeName()");
403  fDivName->Connect("TextChanged(const char *)", "TGeoVolumeEditor", this, "DoDivName()");
404  fEditMedium->Connect("Clicked()", "TGeoVolumeEditor", this, "DoEditMedium()");
405  fEditShape->Connect("Clicked()", "TGeoVolumeEditor", this, "DoEditShape()");
406  fEditMatrix->Connect("Clicked()", "TGeoVolumeEditor", this, "DoEditMatrix()");
407  fAddNode->Connect("Clicked()", "TGeoVolumeEditor", this, "DoAddNode()");
408  fRemoveNode->Connect("Clicked()", "TGeoVolumeEditor", this, "DoRemoveNode()");
409  fBSelShape->Connect("Clicked()", "TGeoVolumeEditor", this, "DoSelectShape()");
410  fBSelMedium->Connect("Clicked()", "TGeoVolumeEditor", this, "DoSelectMedium()");
411  fBSelVolume->Connect("Clicked()", "TGeoVolumeEditor", this, "DoSelectVolume()");
412  fBSelMatrix->Connect("Clicked()", "TGeoVolumeEditor", this, "DoSelectMatrix()");
413  fBVis[0]->Connect("Clicked()", "TGeoVolumeEditor", this, "DoVisVolume()");
414  fBVis[1]->Connect("Clicked()", "TGeoVolumeEditor", this, "DoVisDaughters()");
415  fBAuto->Connect("Clicked()", "TGeoVolumeEditor", this, "DoVisAuto()");
416  fEVisLevel->Connect("ValueSet(Long_t)", "TGeoVolumeEditor", this, "DoVisLevel()");
417  fBView[0]->Connect("Clicked()", "TGeoVolumeEditor", this, "DoViewAll()");
418  fBView[1]->Connect("Clicked()", "TGeoVolumeEditor", this, "DoViewLeaves()");
419  fBView[2]->Connect("Clicked()", "TGeoVolumeEditor", this, "DoViewOnly()");
420  fBDiv[0]->Connect("Clicked()", "TGeoVolumeEditor", this, "DoDivSelAxis()");
421  fBDiv[1]->Connect("Clicked()", "TGeoVolumeEditor", this, "DoDivSelAxis()");
422  fBDiv[2]->Connect("Clicked()", "TGeoVolumeEditor", this, "DoDivSelAxis()");
423  fEDivFrom->Connect("ValueSet(Long_t)", "TGeoVolumeEditor", this, "DoDivFromTo()");
424  fEDivStep->Connect("ValueSet(Long_t)", "TGeoVolumeEditor", this, "DoDivStep()");
425  fEDivN->Connect("ValueSet(Long_t)", "TGeoVolumeEditor", this, "DoDivN()");
426  fBRaytrace->Connect("Clicked()", "TGeoVolumeEditor", this, "DoRaytrace()");
427  fApplyDiv->Connect("Clicked()", "TGeoVolumeEditor", this, "DoApplyDiv()");
428 }
429 
430 ////////////////////////////////////////////////////////////////////////////////
431 /// Connect to the picked volume.
432 
433 void TGeoVolumeEditor::SetModel(TObject* obj)
434 {
435  if (obj == 0 || !obj->InheritsFrom(TGeoVolume::Class())) {
436  SetActive(kFALSE);
437  return;
438  }
439  fVolume = (TGeoVolume*)obj;
440  fGeometry = fVolume->GetGeoManager();
441  const char *vname = fVolume->GetName();
442  fVolumeName->SetText(vname);
443  fSelectedShape = fVolume->GetShape();
444  if (fSelectedShape) fLSelShape->SetText(fSelectedShape->GetName());
445  fSelectedMedium = fVolume->GetMedium();
446  if (fSelectedMedium) fLSelMedium->SetText(fSelectedMedium->GetName());
447 
448  fNodeList->RemoveEntries(0, fNodeList->GetNumberOfEntries()+1);
449  TIter next2(fVolume->GetNodes());
450  TGeoNode *node;
451  Int_t icrt = 0;
452  while ((node=(TGeoNode*)next2()))
453  fNodeList->AddEntry(node->GetName(), icrt++);
454  fNodeList->Select(0);
455  fCopyNumber->SetNumber(fVolume->GetNdaughters()+1);
456  if (!fVolume->GetNdaughters() || fVolume->GetFinder()) {
457  fEditMatrix->SetEnabled(kFALSE);
458  fRemoveNode->SetEnabled(kFALSE);
459  } else {
460  fEditMatrix->SetEnabled(kTRUE);
461  fRemoveNode->SetEnabled(kTRUE);
462  }
463  if (!fSelectedVolume) fAddNode->SetEnabled(kFALSE);
464  if (fVolume->IsAssembly()) {
465  fBSelShape->SetEnabled(kFALSE);
466  fBSelMedium->SetEnabled(kFALSE);
467  }
468  fBVis[0]->SetState((fVolume->IsVisible())?kButtonDown:kButtonUp);
469  fBVis[1]->SetState((fVolume->IsVisibleDaughters())?kButtonDown:kButtonUp);
470  fBView[0]->SetState((fVolume->IsVisContainers())?kButtonDown:kButtonUp, kTRUE);
471  fBView[1]->SetState((fVolume->IsVisLeaves())?kButtonDown:kButtonUp, kTRUE);
472  fBView[2]->SetState((fVolume->IsVisOnly())?kButtonDown:kButtonUp, kTRUE);
473  fBRaytrace->SetState((fVolume->IsRaytracing())?kButtonDown:kButtonUp);
474  fBAuto->SetState((fGeometry->GetVisLevel())?kButtonUp:kButtonDown);
475  fEVisLevel->SetNumber(fGeometry->GetVisLevel());
476  fApplyDiv->SetEnabled(kFALSE);
477  if ((!fVolume->GetFinder() && fVolume->GetNdaughters()) || fVolume->IsAssembly()) {
478  fCategories->GetItem("Division")->GetButton()->SetEnabled(kFALSE);
479  } else {
480  fCategories->GetItem("Division")->GetButton()->SetEnabled(kTRUE);
481  Double_t start=0., step=0., end = 0.;
482  Int_t ndiv = 2, iaxis = 1;
483  TString axis_name;
484  for (Int_t i=0; i<3; i++) {
485  axis_name = fVolume->GetShape()->GetAxisName(i+1);
486  fBDiv[i]->SetText(axis_name);
487  }
488 
489  if (fVolume->GetFinder()) {
490  fDivName->SetText(fVolume->GetNode(0)->GetVolume()->GetName());
491  iaxis = fVolume->GetFinder()->GetDivAxis();
492  start = fVolume->GetFinder()->GetStart();
493  step = fVolume->GetFinder()->GetStep();
494  ndiv = fVolume->GetFinder()->GetNdiv();
495  } else {
496  fDivName->SetText("Enter name");
497  fSelectedShape->GetAxisRange(iaxis,start,end);
498  step = 0;
499  }
500  fBDiv[iaxis-1]->SetState(kButtonDown, kTRUE);
501  fEDivFrom->SetNumber(start);
502  fEDivStep->SetNumber(step);
503  fEDivN->SetNumber(ndiv);
504  }
505 
506  if (fInit) ConnectSignals2Slots();
507  SetActive();
508  if (GetParent()==fTabMgr->GetVolumeTab()) fTab->Layout();
509 }
510 
511 ////////////////////////////////////////////////////////////////////////////////
512 /// Add editors to fGedFrame and exclude TLineEditor.
513 
514 void TGeoVolumeEditor::ActivateBaseClassEditors(TClass* cl)
515 {
516  fGedEditor->ExcludeClassEditor(TAttFill::Class());
517  TGedFrame::ActivateBaseClassEditors(cl);
518 }
519 
520 ////////////////////////////////////////////////////////////////////////////////
521 /// Modify volume name.
522 
523 void TGeoVolumeEditor::DoVolumeName()
524 {
525  fVolume->SetName(fVolumeName->GetText());
526 }
527 
528 ////////////////////////////////////////////////////////////////////////////////
529 /// Select a new shape.
530 
531 void TGeoVolumeEditor::DoSelectShape()
532 {
533  TGeoShape *shape = fSelectedShape;
534  new TGeoShapeDialog(fBSelShape, gClient->GetRoot(), 200,300);
535  fSelectedShape = (TGeoShape*)TGeoShapeDialog::GetSelected();
536  if (fSelectedShape) fLSelShape->SetText(fSelectedShape->GetName());
537  else fSelectedShape = shape;
538 }
539 
540 ////////////////////////////////////////////////////////////////////////////////
541 /// Select a new medium.
542 
543 void TGeoVolumeEditor::DoSelectMedium()
544 {
545  TGeoMedium *med = fSelectedMedium;
546  new TGeoMediumDialog(fBSelMedium, gClient->GetRoot(), 200,300);
547  fSelectedMedium = (TGeoMedium*)TGeoMediumDialog::GetSelected();
548  if (fSelectedMedium) fLSelMedium->SetText(fSelectedMedium->GetName());
549  else fSelectedMedium = med;
550 }
551 
552 ////////////////////////////////////////////////////////////////////////////////
553 /// Select a matrix for positioning.
554 
555 void TGeoVolumeEditor::DoSelectMatrix()
556 {
557  TGeoMatrix *matrix = fSelectedMatrix;
558  new TGeoMatrixDialog(fBSelMatrix, gClient->GetRoot(), 200,300);
559  fSelectedMatrix = (TGeoMatrix*)TGeoMatrixDialog::GetSelected();
560  if (fSelectedMatrix) fLSelMatrix->SetText(fSelectedMatrix->GetName());
561  else fSelectedMatrix = matrix;
562 }
563 
564 ////////////////////////////////////////////////////////////////////////////////
565 /// Select a daughter volume.
566 
567 void TGeoVolumeEditor::DoSelectVolume()
568 {
569  TGeoVolume *vol = fSelectedVolume;
570  new TGeoVolumeDialog(fBSelVolume, gClient->GetRoot(), 200,300);
571  fSelectedVolume = (TGeoVolume*)TGeoVolumeDialog::GetSelected();
572  if (fSelectedVolume) fLSelVolume->SetText(fSelectedVolume->GetName());
573  else fSelectedVolume = vol;
574  if (fSelectedVolume)
575  fAddNode->SetEnabled(kTRUE);
576 }
577 
578 
579 ////////////////////////////////////////////////////////////////////////////////
580 /// Edit the shape of the volume.
581 
582 void TGeoVolumeEditor::DoEditShape()
583 {
584  fTabMgr->GetShapeEditor(fVolume->GetShape());
585 }
586 
587 ////////////////////////////////////////////////////////////////////////////////
588 /// Edit the medium of the volume.
589 
590 void TGeoVolumeEditor::DoEditMedium()
591 {
592  fTabMgr->GetMediumEditor(fVolume->GetMedium());
593 }
594 
595 ////////////////////////////////////////////////////////////////////////////////
596 /// Edit the position of the selected node.
597 
598 void TGeoVolumeEditor::DoEditMatrix()
599 {
600  if (!fVolume->GetNdaughters()) return;
601  Int_t i = fNodeList->GetSelected();
602  if (i<0) return;
603  fTabMgr->GetMatrixEditor(fVolume->GetNode(i)->GetMatrix());
604 }
605 
606 ////////////////////////////////////////////////////////////////////////////////
607 /// Add a daughter.
608 
609 void TGeoVolumeEditor::DoAddNode()
610 {
611  if (!fSelectedVolume || fVolume->GetFinder()) return;
612  Int_t icopy = fCopyNumber->GetIntNumber();
613  fVolume->AddNode(fSelectedVolume, icopy, fSelectedMatrix);
614  Int_t nd = fVolume->GetNdaughters();
615  fNodeList->AddEntry(fVolume->GetNode(nd-1)->GetName(), nd-1);
616  fNodeList->Select(nd-1);
617  fCopyNumber->SetNumber(nd+1);
618  if (fSelectedMatrix) fEditMatrix->SetEnabled(kTRUE);
619  fRemoveNode->SetEnabled(kTRUE);
620  fGeometry->SetTopVisible();
621  fEditMatrix->SetEnabled(kTRUE);
622  fRemoveNode->SetEnabled(kTRUE);
623  Update();
624 }
625 
626 ////////////////////////////////////////////////////////////////////////////////
627 /// Remove a daughter.
628 
629 void TGeoVolumeEditor::DoRemoveNode()
630 {
631  if (!fVolume->GetNdaughters() || fVolume->GetFinder()) {
632  fRemoveNode->SetEnabled(kFALSE);
633  fEditMatrix->SetEnabled(kFALSE);
634  return;
635  }
636  Int_t i = fNodeList->GetSelected();
637  if (i<0) return;
638  fVolume->RemoveNode(fVolume->GetNode(i));
639  fNodeList->RemoveEntries(0, fNodeList->GetNumberOfEntries()+1);
640  TIter next(fVolume->GetNodes());
641  TGeoNode *node;
642  i = 0;
643  while ((node=(TGeoNode*)next()))
644  fNodeList->AddEntry(node->GetName(), i++);
645  fNodeList->Select(0);
646  fCopyNumber->SetNumber(fVolume->GetNdaughters()+1);
647  if (!fVolume->GetNdaughters()) {
648  fRemoveNode->SetEnabled(kFALSE);
649  fEditMatrix->SetEnabled(kFALSE);
650  fCategories->GetItem("Division")->GetButton()->SetEnabled(kTRUE);
651  Double_t start=0., step=0., end=0.;
652  Int_t ndiv = 2, iaxis = 1;
653  fSelectedShape->GetAxisRange(iaxis,start,end);
654  step = end-start;
655  fBDiv[iaxis-1]->SetState(kButtonDown, kTRUE);
656  fEDivFrom->SetNumber(start);
657  fEDivStep->SetNumber(step);
658  fEDivN->SetNumber(ndiv);
659  }
660  Update();
661 }
662 
663 ////////////////////////////////////////////////////////////////////////////////
664 /// Slot for setting volume visible/invisible.
665 
666 void TGeoVolumeEditor::DoVisVolume()
667 {
668  Bool_t on = (fBVis[0]->GetState()==kButtonDown)?kTRUE:kFALSE;
669  if (fVolume->IsVisible() == on) return;
670  fVolume->SetVisibility(on);
671  Update();
672 }
673 
674 ////////////////////////////////////////////////////////////////////////////////
675 /// Slot for setting daughters visible/invisible.
676 
677 void TGeoVolumeEditor::DoVisDaughters()
678 {
679  Bool_t on = (fBVis[1]->GetState()==kButtonDown)?kTRUE:kFALSE;
680  if (fVolume->IsVisibleDaughters() == on) return;
681  fVolume->VisibleDaughters(on);
682  Update();
683 }
684 
685 ////////////////////////////////////////////////////////////////////////////////
686 /// Slot for setting visibility depth auto.
687 
688 void TGeoVolumeEditor::DoVisAuto()
689 {
690  Bool_t on = (fBAuto->GetState()==kButtonDown)?kTRUE:kFALSE;
691  if ((fGeometry->GetVisLevel()==0) == on) return;
692  if (on) fGeometry->SetVisLevel(0);
693  else fGeometry->SetVisLevel(fEVisLevel->GetIntNumber());
694  Update();
695 }
696 
697 ////////////////////////////////////////////////////////////////////////////////
698 /// Slot for visibility level.
699 
700 void TGeoVolumeEditor::DoVisLevel()
701 {
702  fBAuto->SetState(kButtonUp);
703  fGeometry->SetVisLevel(fEVisLevel->GetIntNumber());
704  Update();
705 }
706 
707 ////////////////////////////////////////////////////////////////////////////////
708 /// Slot for viewing volume and containers.
709 
710 void TGeoVolumeEditor::DoViewAll()
711 {
712  Bool_t on = (fBView[0]->GetState()==kButtonDown)?kTRUE:kFALSE;
713  if (!on) return;
714  if (fVolume->IsVisContainers() == on) return;
715  if (fVolume->IsRaytracing()) {
716  fVolume->Raytrace(kFALSE);
717  fBRaytrace->SetState(kButtonUp);
718  }
719  fVolume->SetVisContainers(on);
720  Update();
721 }
722 
723 ////////////////////////////////////////////////////////////////////////////////
724 /// Slot for viewing last leaves only.
725 
726 void TGeoVolumeEditor::DoViewLeaves()
727 {
728  Bool_t on = (fBView[1]->GetState()==kButtonDown)?kTRUE:kFALSE;
729  if (!on) return;
730  if (fVolume->IsVisLeaves() == on) return;
731  if (fVolume->IsRaytracing()) {
732  fVolume->Raytrace(kFALSE);
733  fBRaytrace->SetState(kButtonUp);
734  }
735  fVolume->SetVisLeaves(on);
736  Update();
737 }
738 
739 ////////////////////////////////////////////////////////////////////////////////
740 /// Slot for viewing volume only.
741 
742 void TGeoVolumeEditor::DoViewOnly()
743 {
744  Bool_t on = (fBView[2]->GetState()==kButtonDown)?kTRUE:kFALSE;
745  if (!on) return;
746  if (fVolume->IsVisOnly() == on) return;
747  if (fVolume->IsRaytracing()) {
748  fVolume->Raytrace(kFALSE);
749  fBRaytrace->SetState(kButtonUp);
750  }
751  fVolume->SetVisOnly(on);
752  Update();
753 }
754 
755 ////////////////////////////////////////////////////////////////////////////////
756 /// Slot for raytracing.
757 
758 void TGeoVolumeEditor::DoRaytrace()
759 {
760  Bool_t on = (fBRaytrace->GetState()==kButtonDown)?kTRUE:kFALSE;
761  if (fVolume->IsRaytracing() == on) return;
762  fVolume->Raytrace(on);
763  Update();
764 }
765 
766 ////////////////////////////////////////////////////////////////////////////////
767 /// Modify division name.
768 
769 void TGeoVolumeEditor::DoDivName()
770 {
771  fApplyDiv->SetEnabled(kTRUE);
772 }
773 
774 ////////////////////////////////////////////////////////////////////////////////
775 /// Change division axis and preserve number of slices.
776 
777 void TGeoVolumeEditor::DoDivSelAxis()
778 {
779  Int_t iaxis = 1;
780  for (Int_t i=0; i<3; i++) {
781  if (fBDiv[i]->GetState()!=kButtonDown) continue;
782  iaxis = i+1;
783  break;
784  }
785  TGeoShape *shape = fVolume->GetShape();
786  if (!shape) {
787  fApplyDiv->SetEnabled(kFALSE);
788  return;
789  }
790  Double_t xlo, xhi;
791  shape->GetAxisRange(iaxis, xlo, xhi);
792  if (xhi <= xlo) {
793  fApplyDiv->SetEnabled(kFALSE);
794  return;
795  }
796  fEDivFrom->SetNumber(xlo);
797  fEDivStep->SetNumber(0);
798  fApplyDiv->SetEnabled(kTRUE);
799 }
800 
801 ////////////////////////////////////////////////////////////////////////////////
802 /// Handle division range modification.
803 
804 void TGeoVolumeEditor::DoDivFromTo()
805 {
806  Double_t min, max, xlo, xhi, step;
807  Int_t iaxis = 1;
808  Int_t ndiv;
809  for (Int_t i=0; i<3; i++) {
810  if (fBDiv[i]->GetState()!=kButtonDown) continue;
811  iaxis = i+1;
812  break;
813  }
814  TGeoShape *shape = fVolume->GetShape();
815  if (!shape) {
816  fApplyDiv->SetEnabled(kFALSE);
817  return;
818  }
819  shape->GetAxisRange(iaxis, xlo, xhi);
820  if (xhi-xlo <= 0) {
821  fApplyDiv->SetEnabled(kFALSE);
822  return;
823  }
824  min = fEDivFrom->GetNumber();
825  step = fEDivStep->GetNumber();
826  ndiv = fEDivN->GetIntNumber();
827  if (min<xlo) {
828  min = xlo;
829  fEDivFrom->SetNumber(xlo);
830  }
831  max = min + ndiv*step;
832  if (max>xhi) {
833  max = xhi;
834  step = (max-min)/ndiv;
835  fEDivStep->SetNumber(step);
836  }
837  if (min>=max) {
838  fApplyDiv->SetEnabled(kFALSE);
839  return;
840  }
841  fApplyDiv->SetEnabled(kTRUE);
842 }
843 
844 ////////////////////////////////////////////////////////////////////////////////
845 /// Handle division step modification.
846 
847 void TGeoVolumeEditor::DoDivStep()
848 {
849  Double_t min, max, xlo, xhi;
850  Int_t iaxis = 1;
851  for (Int_t i=0; i<3; i++) {
852  if (fBDiv[i]->GetState()!=kButtonDown) continue;
853  iaxis = i+1;
854  break;
855  }
856  TGeoShape *shape = fVolume->GetShape();
857  if (!shape) {
858  fApplyDiv->SetEnabled(kFALSE);
859  return;
860  }
861  shape->GetAxisRange(iaxis, xlo, xhi);
862  if (xhi-xlo <= 0) {
863  fApplyDiv->SetEnabled(kFALSE);
864  return;
865  }
866  min = fEDivFrom->GetNumber();
867  Double_t step = fEDivStep->GetNumber();
868  Int_t ndiv = fEDivN->GetIntNumber();
869  max = min + ndiv*step;
870 
871  // Check if ndiv*step < max-min
872  if (max <= xhi) {
873  fApplyDiv->SetEnabled(kTRUE);
874  return;
875  }
876  // Step too big - set value to fit range
877  max = xhi;
878  step = (max-min)/ndiv;
879  fEDivStep->SetNumber(step);
880  if (step < 0) {
881  fApplyDiv->SetEnabled(kFALSE);
882  return;
883  }
884  fApplyDiv->SetEnabled(kTRUE);
885 }
886 
887 ////////////////////////////////////////////////////////////////////////////////
888 /// Handle division N modification.
889 
890 void TGeoVolumeEditor::DoDivN()
891 {
892  Double_t min, max, xlo, xhi;
893  Int_t iaxis = 1;
894  for (Int_t i=0; i<3; i++) {
895  if (fBDiv[i]->GetState()!=kButtonDown) continue;
896  iaxis = i+1;
897  break;
898  }
899  TGeoShape *shape = fVolume->GetShape();
900  if (!shape) {
901  fApplyDiv->SetEnabled(kFALSE);
902  return;
903  }
904  shape->GetAxisRange(iaxis, xlo, xhi);
905  if (xhi-xlo <= 0) {
906  fApplyDiv->SetEnabled(kFALSE);
907  return;
908  }
909  Double_t step = fEDivStep->GetNumber();
910  // If step=0 it is discounted
911  if (step==0) {
912  fApplyDiv->SetEnabled(kTRUE);
913  return;
914  }
915  Int_t ndiv = fEDivN->GetIntNumber();
916  min = fEDivFrom->GetNumber();
917  max = min + ndiv*step;
918  // Check if ndiv*step < max-min
919  if (max <= xhi) {
920  fApplyDiv->SetEnabled(kTRUE);
921  return;
922  }
923  max = xhi;
924  ndiv = (Int_t)((max-min)/step);
925  fEDivN->SetNumber(ndiv);
926  fApplyDiv->SetEnabled(kTRUE);
927 }
928 
929 ////////////////////////////////////////////////////////////////////////////////
930 /// Apply current division settings
931 
932 void TGeoVolumeEditor::DoApplyDiv()
933 {
934  Double_t xlo, xhi, step;
935  Int_t iaxis = 1;
936  Int_t ndiv;
937  for (Int_t i=0; i<3; i++) {
938  if (fBDiv[i]->GetState()!=kButtonDown) continue;
939  iaxis = i+1;
940  break;
941  }
942  TGeoShape *shape = fVolume->GetShape();
943  if (!shape) {
944  fApplyDiv->SetEnabled(kFALSE);
945  return;
946  }
947  shape->GetAxisRange(iaxis, xlo, xhi);
948  if (xhi-xlo <= 0) {
949  fApplyDiv->SetEnabled(kFALSE);
950  return;
951  }
952  xlo = fEDivFrom->GetNumber();
953  step = fEDivStep->GetNumber();
954  ndiv = fEDivN->GetIntNumber();
955  TGeoPatternFinder *finder = fVolume->GetFinder();
956  if (finder) {
957  // we have to remove first the existing division
958  TObjArray *nodes = fVolume->GetNodes();
959  nodes->Delete();
960  nodes->Clear();
961  delete finder;
962  fVolume->SetFinder(0);
963  }
964  fVolume->Divide(fDivName->GetText(), iaxis, ndiv, xlo, step);
965  fApplyDiv->SetEnabled(kFALSE);
966  fGeometry->SetTopVisible();
967  Update();
968 // fVolume->Draw();
969 }