Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
TGeoTabManager.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 TGeoTabManager
13 \ingroup Geometry_builder
14 
15 Manager for all editor tabs.
16 
17 TGeoTreeDialog - Base class for dialog frames for selecting objects
18 with a tree hierarchy. Specific implementations are:
19 
20  - TGeoVolumeDialog - Special tree dialog class for selecting volumes.
21  - TGeoShapeDialog - Special tree dialog class for selecting shapes.
22  - TGeoMediumDialog - Special tree dialog class for selecting media.
23  - TGeoMaterialDialog - Special tree dialog class for selecting materials.
24  - TGeoMatrixDialog - Special tree dialog class for selecting matrices.
25  - TGeoTransientPanel - Special transient tab holding TGeo editors.
26 */
27 
28 #include "TROOT.h"
29 #include "TClass.h"
30 #include "TVirtualPad.h"
31 #include "TGeoGedFrame.h"
32 #include "TGTab.h"
33 #include "TGLabel.h"
34 #include "TGComboBox.h"
35 #include "TGListBox.h"
36 #include "TGListTree.h"
37 #include "TGTextEntry.h"
38 #include "TGCanvas.h"
39 #include "TGMimeTypes.h"
40 
41 #include "TGeoManager.h"
42 #include "TGeoShape.h"
43 #include "TGeoVolume.h"
44 #include "TGeoMedium.h"
45 #include "TGeoMaterial.h"
46 #include "TGeoMatrix.h"
47 
48 #include "TGedEditor.h"
49 #include "TGeoTabManager.h"
50 
51 TMap TGeoTabManager::fgEditorToMgrMap;
52 
53 ClassImp(TGeoTabManager);
54 
55 ////////////////////////////////////////////////////////////////////////////////
56 /// Ctor.
57 
58 TGeoTabManager::TGeoTabManager(TGedEditor *ged)
59 {
60  fGedEditor = ged;
61  fPad = ged->GetPad();
62  fTab = ged->GetTab();
63  fVolume = 0;
64  fShapePanel = 0;
65  fMediumPanel = 0;
66  fMaterialPanel = 0;
67  fMatrixPanel = 0;
68  fVolumeTab = 0;
69  fgEditorToMgrMap.Add(ged, this);
70 }
71 
72 ////////////////////////////////////////////////////////////////////////////////
73 /// Dtor.
74 
75 TGeoTabManager::~TGeoTabManager()
76 {
77  fgEditorToMgrMap.Remove(fGedEditor);
78  if (fShapePanel) delete fShapePanel;
79  if (fMaterialPanel) delete fMaterialPanel;
80  if (fMatrixPanel) delete fMatrixPanel;
81  if (fMediumPanel) delete fMediumPanel;
82 }
83 
84 ////////////////////////////////////////////////////////////////////////////////
85 /// Static method to cleanup hierarchically all daughters of a composite frame.
86 /// Does not remove the frame itself.
87 
88 void TGeoTabManager::Cleanup(TGCompositeFrame *frame)
89 {
90  TGFrameElement *el;
91  TList *list = frame->GetList();
92  Int_t nframes = list->GetSize();
93  TClass *cl;
94  for (Int_t i=0; i<nframes; i++) {
95  el = (TGFrameElement *)list->At(i);
96  cl = el->fFrame->IsA();
97  if (cl==TGCompositeFrame::Class() || cl==TGHorizontalFrame::Class() || cl==TGVerticalFrame::Class())
98  Cleanup((TGCompositeFrame*)el->fFrame);
99  }
100  frame->Cleanup();
101 }
102 
103 ////////////////////////////////////////////////////////////////////////////////
104 /// Get editor for a shape.
105 
106 void TGeoTabManager::GetShapeEditor(TGeoShape *shape)
107 {
108  if (!shape) return;
109  if (!fShapePanel) fShapePanel = new TGeoTransientPanel(fGedEditor, "Shape", shape);
110  else {
111  fShapePanel->SetModel(shape);
112  fShapePanel->Show();
113  }
114 }
115 
116 ////////////////////////////////////////////////////////////////////////////////
117 /// Get editor for a volume.
118 
119 void TGeoTabManager::GetVolumeEditor(TGeoVolume *volume)
120 {
121  if (!volume || !fVolumeTab) return;
122  GetEditors(TAttLine::Class());
123  GetEditors(TGeoVolume::Class());
124  fVolumeTab->MapSubwindows();
125  fVolumeTab->Layout();
126  SetModel(volume);
127 }
128 
129 ////////////////////////////////////////////////////////////////////////////////
130 /// Get editor for a matrix.
131 
132 void TGeoTabManager::GetMatrixEditor(TGeoMatrix *matrix)
133 {
134  if (!matrix) return;
135  if (!fMatrixPanel) fMatrixPanel = new TGeoTransientPanel(fGedEditor, "Matrix", matrix);
136  else {
137  fMatrixPanel->SetModel(matrix);
138  fMatrixPanel->Show();
139  }
140 }
141 
142 ////////////////////////////////////////////////////////////////////////////////
143 /// Get editor for a medium.
144 
145 void TGeoTabManager::GetMediumEditor(TGeoMedium *medium)
146 {
147  if (!medium) return;
148  if (!fMediumPanel) fMediumPanel = new TGeoTransientPanel(fGedEditor, "Medium", medium);
149  else {
150  fMediumPanel->SetModel(medium);
151  fMediumPanel->Show();
152  fMediumPanel->RaiseWindow();
153  }
154 }
155 
156 ////////////////////////////////////////////////////////////////////////////////
157 /// Get editor for a material.
158 
159 void TGeoTabManager::GetMaterialEditor(TGeoMaterial *material)
160 {
161  if (!material) return;
162  TString name = "Material";
163  if (material->IsMixture()) name = "Mixture";
164  if (!fMaterialPanel) fMaterialPanel = new TGeoTransientPanel(fGedEditor, name.Data(), material);
165  else {
166  fMaterialPanel->SetModel(material);
167  fMaterialPanel->Show();
168  fMaterialPanel->RaiseWindow();
169  }
170 }
171 
172 ////////////////////////////////////////////////////////////////////////////////
173 /// Get editor for a class.
174 /// Look in fVolumeTab for any object deriving from TGedFrame,
175 
176 void TGeoTabManager::GetEditors(TClass *cl)
177 {
178  TClass *class2 = TClass::GetClass(TString::Format("%sEditor",cl->GetName()));
179  if (class2 && class2->InheritsFrom(TGedFrame::Class())) {
180  TGFrameElement *fr;
181  TIter next(fVolumeTab->GetList());
182  while ((fr = (TGFrameElement *) next())) if (fr->fFrame->IsA() == class2) return;
183  TGClient *client = fGedEditor->GetClient();
184  TGWindow *exroot = (TGWindow*) client->GetRoot();
185  client->SetRoot(fVolumeTab);
186  TGedEditor::SetFrameCreator(fGedEditor);
187  TGedFrame* gfr = reinterpret_cast<TGedFrame*>(class2->New());
188  gfr->SetModelClass(cl);
189  TGedEditor::SetFrameCreator(0);
190  client->SetRoot(exroot);
191  fVolumeTab->AddFrame(gfr, new TGLayoutHints(kLHintsTop | kLHintsExpandX, 0, 0, 2, 2));
192  gfr->MapSubwindows();
193  }
194 }
195 
196 ////////////////////////////////////////////////////////////////////////////////
197 /// Static method to return the tab manager currently appended to the pad or create one
198 /// if not existing.
199 
200 TGeoTabManager *TGeoTabManager::GetMakeTabManager(TGedEditor *ged)
201 {
202  if (!ged) return NULL;
203  TPair *pair = (TPair*) fgEditorToMgrMap.FindObject(ged);
204  if (pair) {
205  return (TGeoTabManager*) pair->Value();
206  } else {
207  TGeoTabManager *tabmgr = new TGeoTabManager(ged); // added to fgEditorToMgrMap in ctor
208  return tabmgr;
209  }
210 }
211 
212 ////////////////////////////////////////////////////////////////////////////////
213 /// Get index for a given tab element.
214 
215 Int_t TGeoTabManager::GetTabIndex() const
216 {
217  Int_t ntabs = fTab->GetNumberOfTabs();
218  TString tabname = "Volume";
219 
220  TGTabElement *tel;
221  for (Int_t i=0; i<ntabs; i++) {
222  tel = fTab->GetTabTab(i);
223  if (tel && !strcmp(tel->GetString(),tabname.Data())) return i;
224  }
225  return 0;
226 }
227 
228 ////////////////////////////////////////////////////////////////////////////////
229 /// Move frame fr at the end of the list of parent p.
230 
231 void TGeoTabManager::MoveFrame(TGCompositeFrame *fr, TGCompositeFrame *p)
232 {
233  TList *list = p->GetList();
234  TIter next(list);
235  TGFrameElement *el = 0;
236  while ((el=(TGFrameElement*)next())) {
237  if (el->fFrame == fr) break;
238  }
239  if (el) {
240  list->Remove(el);
241  list->Add(el);
242  }
243 }
244 
245 ////////////////////////////////////////////////////////////////////////////////
246 /// Enable/disable tabs
247 
248 void TGeoTabManager::SetVolTabEnabled(Bool_t flag)
249 {
250  fTab->SetEnabled(GetTabIndex(), flag);
251 }
252 
253 ////////////////////////////////////////////////////////////////////////////////
254 /// Send the SetModel signal to all editors in the tab TYPE.
255 
256 void TGeoTabManager::SetModel(TObject *model)
257 {
258  TGCompositeFrame *tab = fVolumeTab;
259  fVolume = (TGeoVolume*)model;
260  TGFrameElement *el;
261  TIter next(tab->GetList());
262  while ((el = (TGFrameElement *) next())) {
263  if ((el->fFrame)->InheritsFrom(TGedFrame::Class())) {
264  ((TGedFrame *)(el->fFrame))->SetModel(model);
265  }
266  }
267 }
268 
269 ////////////////////////////////////////////////////////////////////////////////
270 /// Set a given tab element as active one.
271 
272 void TGeoTabManager::SetTab()
273 {
274  fTab->SetTab(GetTabIndex());
275 }
276 
277 ClassImp(TGeoTreeDialog);
278 
279 TObject *TGeoTreeDialog::fgSelectedObj = 0;
280 
281 ////////////////////////////////////////////////////////////////////////////////
282 ///static; return selected object
283 
284 TObject *TGeoTreeDialog::GetSelected()
285 {
286  return fgSelectedObj;
287 }
288 
289 ////////////////////////////////////////////////////////////////////////////////
290 /// Constructor
291 
292 TGeoTreeDialog::TGeoTreeDialog(TGFrame *caller, const TGWindow *main, UInt_t w, UInt_t h)
293  :TGTransientFrame(main, main, w, h)
294 {
295  fgSelectedObj = 0;
296  fCanvas = new TGCanvas(this, 100, 200, kSunkenFrame | kDoubleBorder);
297  fLT = new TGListTree(fCanvas->GetViewPort(), 100, 200);
298  fLT->Associate(this);
299  fCanvas->SetContainer(fLT);
300  AddFrame(fCanvas, new TGLayoutHints(kLHintsLeft | kLHintsExpandX | kLHintsExpandY, 2,2,2,2));
301  f1 = new TGCompositeFrame(this, 100, 10, kHorizontalFrame | kLHintsExpandX);
302  fObjLabel = new TGLabel(f1, "Selected: -none-");
303  Pixel_t color;
304  gClient->GetColorByName("#0000ff", color);
305  fObjLabel->SetTextColor(color);
306  fObjLabel->ChangeOptions(kSunkenFrame | kDoubleBorder);
307  f1->AddFrame(fObjLabel, new TGLayoutHints(kLHintsLeft | kLHintsExpandX | kLHintsExpandY, 2,2,2,2));
308  fClose = new TGTextButton(f1, "&Close");
309  fClose->Associate(this);
310  f1->AddFrame(fClose, new TGLayoutHints(kLHintsRight, 2,2,2,2));
311  AddFrame(f1, new TGLayoutHints(kLHintsBottom | kLHintsExpandX, 2,2,2,2));
312 
313  Int_t ww = caller->GetWidth();
314  Window_t wdum;
315  Int_t ax, ay;
316  gVirtualX->TranslateCoordinates(caller->GetId(), main->GetId(), 0,0,ax,ay,wdum);
317  Move(ax + ww, ay);
318  SetWMPosition(ax, ay);
319 
320 }
321 
322 ////////////////////////////////////////////////////////////////////////////////
323 /// Destructor
324 
325 TGeoTreeDialog::~TGeoTreeDialog()
326 {
327  delete fClose;
328  delete fObjLabel;
329  delete f1;
330  delete fLT;
331  delete fCanvas;
332 }
333 
334 ////////////////////////////////////////////////////////////////////////////////
335 /// Update dialog to reflect current clicked object.
336 
337 void TGeoTreeDialog::DoSelect(TGListTreeItem *item)
338 {
339  static TString name;
340  if (!item || !item->GetUserData()) {
341  fgSelectedObj = 0;
342  name = "Selected: -none-";
343  fObjLabel->SetText(name);
344  return;
345  }
346  fgSelectedObj = (TObject *)item->GetUserData();
347  if (fgSelectedObj) {
348  name = TString::Format("Selected %s", fgSelectedObj->GetName());
349  fObjLabel->SetText(name);
350  }
351 }
352 
353 ClassImp(TGeoVolumeDialog);
354 
355 ////////////////////////////////////////////////////////////////////////////////
356 /// Ctor.
357 
358 TGeoVolumeDialog::TGeoVolumeDialog(TGFrame *caller, const TGWindow *main, UInt_t w, UInt_t h)
359  :TGeoTreeDialog(caller, main, w, h)
360 {
361  BuildListTree();
362  ConnectSignalsToSlots();
363  MapSubwindows();
364  Layout();
365  SetWindowName("Volume dialog");
366  MapWindow();
367  gClient->WaitForUnmap(this);
368 }
369 
370 ////////////////////////////////////////////////////////////////////////////////
371 /// Build volume specific list tree.
372 
373 void TGeoVolumeDialog::BuildListTree()
374 {
375  const TGPicture *pic_fld = gClient->GetPicture("folder_t.xpm");
376  const TGPicture *pic_fldo = gClient->GetPicture("ofolder_t.xpm");
377  const TGPicture *pic_file = gClient->GetPicture("mdi_default.xpm");
378  const TGPicture *pic_fileo = gClient->GetPicture("fileopen.xpm");
379  TGListTreeItem *parent_item=0;
380  TGeoVolume *parent_vol = gGeoManager->GetMasterVolume();
381  TGeoVolume *vol;
382  // Existing volume hierarchy
383  parent_item = fLT->AddItem(parent_item, "Volume hierarchy", pic_fldo, pic_fld);
384  parent_item->SetTipText("Select a volume from the existing hierarchy");
385  fLT->OpenItem(parent_item);
386  if (parent_vol) {
387  if (!parent_vol->GetNdaughters()) {
388  parent_item = fLT->AddItem(parent_item, parent_vol->GetName(), parent_vol, pic_fileo, pic_file);
389  parent_item->SetTipText("Master volume");
390  fLT->SetSelected(parent_item);
391  } else {
392  parent_item = fLT->AddItem(parent_item, parent_vol->GetName(), parent_vol, pic_fldo, pic_fld);
393  parent_item->SetTipText("Master volume");
394  fLT->SetSelected(parent_item);
395  }
396  }
397  parent_item = fLT->AddItem(NULL, "Other volumes", pic_fldo, pic_fld);
398  parent_item->SetTipText("Select a volume from the list of unconnected volumes");
399  TIter next1(gGeoManager->GetListOfVolumes());
400  Bool_t found = kFALSE;
401  while ((vol=(TGeoVolume*)next1())) {
402  if (vol->IsAdded()) continue;
403  fLT->AddItem(parent_item, vol->GetName(), vol, pic_fileo, pic_file);
404  found = kTRUE;
405  }
406  if (found) {
407 // fLT->OpenItem(parent_item);
408  if (!parent_vol) fLT->SetSelected(parent_item->GetFirstChild());
409  }
410 }
411 
412 ////////////////////////////////////////////////////////////////////////////////
413 /// Handle close button.
414 
415 void TGeoVolumeDialog::DoClose()
416 {
417  DeleteWindow();
418 }
419 
420 ////////////////////////////////////////////////////////////////////////////////
421 /// Handle item click.
422 /// Iterate daughters
423 
424 void TGeoVolumeDialog::DoItemClick(TGListTreeItem *item, Int_t btn)
425 {
426  if (btn!=kButton1) return;
427  DoSelect(item);
428  if (!item || !item->GetUserData()) return;
429  const TGPicture *pic_fld = gClient->GetPicture("folder_t.xpm");
430  const TGPicture *pic_fldo = gClient->GetPicture("ofolder_t.xpm");
431  const TGPicture *pic_file = gClient->GetPicture("mdi_default.xpm");
432  const TGPicture *pic_fileo = gClient->GetPicture("fileopen.xpm");
433  TGeoVolume *parent_vol = (TGeoVolume*)item->GetUserData();
434  TGeoVolume *vol;
435  TGeoNode *crtnode;
436  TGListTreeItem *daughter_item;
437  Int_t i,j,ind,icopy;
438  Int_t nd = parent_vol->GetNdaughters();
439  for (i=0; i<nd; i++) {
440  icopy = 0;
441  crtnode = parent_vol->GetNode(i);
442  vol = crtnode->GetVolume();
443  // check if the volume is replicated in the parent
444  ind = parent_vol->GetIndex(crtnode);
445  for (j=0; j<ind; j++) if (parent_vol->GetNode(j)->GetVolume() == vol) break;
446  if (i<ind) continue;
447  icopy++;
448  for (j=ind+1; j<nd; j++) if (parent_vol->GetNode(j)->GetVolume() == vol) icopy++;
449  daughter_item = fLT->AddItem(item, ((icopy>1)?(TString::Format("%s (%i)",vol->GetName(),icopy)).Data():vol->GetName()),
450  vol,((vol->GetNdaughters())?pic_fldo:pic_fileo), ((vol->GetNdaughters())?pic_fld:pic_file));
451  if (strlen(vol->GetTitle())) daughter_item->SetTipText(vol->GetTitle());
452  }
453  if (nd) gClient->NeedRedraw(fLT);
454 }
455 
456 ////////////////////////////////////////////////////////////////////////////////
457 /// Connect signals to slots.
458 
459 void TGeoVolumeDialog::ConnectSignalsToSlots()
460 {
461  fClose->Connect("Clicked()", "TGeoVolumeDialog", this, "DoClose()");
462  fLT->Connect("Clicked(TGListTreeItem *, Int_t)", "TGeoVolumeDialog", this,
463  "DoItemClick(TGListTreeItem *, Int_t)");
464 }
465 
466 ClassImp(TGeoShapeDialog);
467 
468 ////////////////////////////////////////////////////////////////////////////////
469 /// Ctor.
470 
471 TGeoShapeDialog::TGeoShapeDialog(TGFrame *caller, const TGWindow *main, UInt_t w, UInt_t h)
472  :TGeoTreeDialog(caller, main, w, h)
473 {
474  BuildListTree();
475  ConnectSignalsToSlots();
476  MapSubwindows();
477  Layout();
478  SetWindowName("Shape dialog");
479  MapWindow();
480  gClient->WaitForUnmap(this);
481 }
482 
483 ////////////////////////////////////////////////////////////////////////////////
484 /// Build shape specific list tree.
485 
486 void TGeoShapeDialog::BuildListTree()
487 {
488  const TGPicture *pic_fld = gClient->GetPicture("folder_t.xpm");
489  const TGPicture *pic_fldo = gClient->GetPicture("ofolder_t.xpm");
490  const TGPicture *pic_shape;
491  TGListTreeItem *parent_item=0;
492  TGeoShape *shape;
493  const char *shapename;
494  TString fld_name;
495  Int_t nshapes = gGeoManager->GetListOfShapes()->GetEntriesFast();
496  if (!nshapes) return;
497  // Existing shapes
498  for (Int_t i=0; i<nshapes; i++) {
499  shape = (TGeoShape*)gGeoManager->GetListOfShapes()->At(i);
500  if (!shape) continue;
501  shapename = shape->IsA()->GetName();
502  pic_shape = fClient->GetMimeTypeList()->GetIcon(shapename, kTRUE);
503  fld_name = shapename; // e.g. "TGeoBBox"
504  fld_name.Remove(0,4); // remove "TGeo" part -> "BBox"
505  fld_name += " Shapes";
506  parent_item = fLT->FindChildByName(NULL, fld_name.Data());
507  if (!parent_item) {
508  parent_item = fLT->AddItem(NULL, fld_name.Data(), pic_fldo, pic_fld);
509  parent_item->SetTipText(TString::Format("List of %s shapes",fld_name.Data()));
510  }
511  fLT->AddItem(parent_item, shape->GetName(), shape, pic_shape, pic_shape);
512  }
513 }
514 
515 ////////////////////////////////////////////////////////////////////////////////
516 /// Handle close button.
517 
518 void TGeoShapeDialog::DoClose()
519 {
520  DeleteWindow();
521 }
522 
523 ////////////////////////////////////////////////////////////////////////////////
524 /// Handle item click.
525 /// Iterate daughters
526 
527 void TGeoShapeDialog::DoItemClick(TGListTreeItem *item, Int_t btn)
528 {
529  if (btn!=kButton1) return;
530  DoSelect(item);
531  if (!item || !item->GetUserData()) return;
532 }
533 
534 ////////////////////////////////////////////////////////////////////////////////
535 /// Connect signals to slots.
536 
537 void TGeoShapeDialog::ConnectSignalsToSlots()
538 {
539  fClose->Connect("Clicked()", "TGeoShapeDialog", this, "DoClose()");
540  fLT->Connect("Clicked(TGListTreeItem *, Int_t)", "TGeoShapeDialog", this,
541  "DoItemClick(TGListTreeItem *, Int_t)");
542 }
543 
544 ClassImp(TGeoMediumDialog);
545 
546 ////////////////////////////////////////////////////////////////////////////////
547 /// Ctor.
548 
549 TGeoMediumDialog::TGeoMediumDialog(TGFrame *caller, const TGWindow *main, UInt_t w, UInt_t h)
550  :TGeoTreeDialog(caller, main, w, h)
551 {
552  BuildListTree();
553  ConnectSignalsToSlots();
554  MapSubwindows();
555  Layout();
556  SetWindowName("Medium dialog");
557  MapWindow();
558  gClient->WaitForUnmap(this);
559 }
560 
561 ////////////////////////////////////////////////////////////////////////////////
562 /// Build volume specific list tree.
563 
564 void TGeoMediumDialog::BuildListTree()
565 {
566  const TGPicture *pic_med = gClient->GetPicture("geomedium_t.xpm");;
567  TGeoMedium *med;
568  Int_t nmed = gGeoManager->GetListOfMedia()->GetSize();
569  if (!nmed) return;
570  // Existing media
571  for (Int_t i=0; i<nmed; i++) {
572  med = (TGeoMedium*)gGeoManager->GetListOfMedia()->At(i);
573  fLT->AddItem(NULL, med->GetName(), med, pic_med, pic_med);
574  }
575 }
576 
577 ////////////////////////////////////////////////////////////////////////////////
578 /// Handle close button.
579 
580 void TGeoMediumDialog::DoClose()
581 {
582  DeleteWindow();
583 }
584 
585 ////////////////////////////////////////////////////////////////////////////////
586 /// Handle item click.
587 /// Iterate daughters
588 
589 void TGeoMediumDialog::DoItemClick(TGListTreeItem *item, Int_t btn)
590 {
591  if (btn!=kButton1) return;
592  DoSelect(item);
593  if (!item || !item->GetUserData()) return;
594  //gClient->NeedRedraw(fLT);
595 }
596 
597 ////////////////////////////////////////////////////////////////////////////////
598 /// Connect signals to slots.
599 
600 void TGeoMediumDialog::ConnectSignalsToSlots()
601 {
602  fClose->Connect("Clicked()", "TGeoMediumDialog", this, "DoClose()");
603  fLT->Connect("Clicked(TGListTreeItem *, Int_t)", "TGeoMediumDialog", this,
604  "DoItemClick(TGListTreeItem *, Int_t)");
605 }
606 
607 ClassImp(TGeoMaterialDialog);
608 
609 ////////////////////////////////////////////////////////////////////////////////
610 /// Ctor.
611 
612 TGeoMaterialDialog::TGeoMaterialDialog(TGFrame *caller, const TGWindow *main, UInt_t w, UInt_t h)
613  :TGeoTreeDialog(caller, main, w, h)
614 {
615  BuildListTree();
616  ConnectSignalsToSlots();
617  MapSubwindows();
618  Layout();
619  SetWindowName("Material dialog");
620  MapWindow();
621  gClient->WaitForUnmap(this);
622 }
623 
624 ////////////////////////////////////////////////////////////////////////////////
625 /// Build volume specific list tree.
626 
627 void TGeoMaterialDialog::BuildListTree()
628 {
629  const TGPicture *pic_mat = gClient->GetPicture("geomaterial_t.xpm");;
630  TGeoMaterial *mat;
631  Int_t nmat = gGeoManager->GetListOfMaterials()->GetSize();
632  if (!nmat) return;
633  // Existing materials
634  for (Int_t i=0; i<nmat; i++) {
635  mat = (TGeoMaterial*)gGeoManager->GetListOfMaterials()->At(i);
636  fLT->AddItem(NULL, mat->GetName(), mat, pic_mat, pic_mat);
637  }
638 }
639 
640 ////////////////////////////////////////////////////////////////////////////////
641 /// Handle close button.
642 
643 void TGeoMaterialDialog::DoClose()
644 {
645  DeleteWindow();
646 }
647 
648 ////////////////////////////////////////////////////////////////////////////////
649 /// Handle item click.
650 /// Iterate daughters
651 
652 void TGeoMaterialDialog::DoItemClick(TGListTreeItem *item, Int_t btn)
653 {
654  if (btn!=kButton1) return;
655  DoSelect(item);
656  if (!item || !item->GetUserData()) return;
657  //gClient->NeedRedraw(fLT);
658 }
659 
660 ////////////////////////////////////////////////////////////////////////////////
661 /// Connect signals to slots.
662 
663 void TGeoMaterialDialog::ConnectSignalsToSlots()
664 {
665  fClose->Connect("Clicked()", "TGeoMaterialDialog", this, "DoClose()");
666  fLT->Connect("Clicked(TGListTreeItem *, Int_t)", "TGeoMaterialDialog", this,
667  "DoItemClick(TGListTreeItem *, Int_t)");
668 }
669 
670 ClassImp(TGeoMatrixDialog);
671 
672 ////////////////////////////////////////////////////////////////////////////////
673 /// Ctor.
674 
675 TGeoMatrixDialog::TGeoMatrixDialog(TGFrame *caller, const TGWindow *main, UInt_t w, UInt_t h)
676  :TGeoTreeDialog(caller, main, w, h)
677 {
678  BuildListTree();
679  ConnectSignalsToSlots();
680  MapSubwindows();
681  Layout();
682  SetWindowName("Matrix dialog");
683  MapWindow();
684  gClient->WaitForUnmap(this);
685 }
686 
687 ////////////////////////////////////////////////////////////////////////////////
688 /// Build matrix specific list tree.
689 
690 void TGeoMatrixDialog::BuildListTree()
691 {
692  const TGPicture *pic_tr = gClient->GetPicture("geotranslation_t.xpm");
693  const TGPicture *pic_rot = gClient->GetPicture("georotation_t.xpm");
694  const TGPicture *pic_combi = gClient->GetPicture("geocombi_t.xpm");
695  const TGPicture *pic;
696  TGListTreeItem *parent_item=0;
697  TGeoMatrix *matrix;
698  Int_t nmat = gGeoManager->GetListOfMatrices()->GetEntriesFast();
699  if (!nmat) return;
700  // Existing matrices
701  for (Int_t i=0; i<nmat; i++) {
702  matrix = (TGeoMatrix*)gGeoManager->GetListOfMatrices()->At(i);
703  if (matrix->IsIdentity()) continue;
704  if (!strcmp(matrix->IsA()->GetName(),"TGeoTranslation")) {
705  pic = pic_tr;
706  parent_item = fLT->FindChildByName(NULL, "Translations");
707  if (!parent_item) {
708  parent_item = fLT->AddItem(NULL, "Translations", pic, pic);
709  parent_item->SetTipText("List of translations");
710  }
711  } else if (!strcmp(matrix->IsA()->GetName(),"TGeoRotation")) {
712  pic = pic_rot;
713  parent_item = fLT->FindChildByName(NULL, "Rotations");
714  if (!parent_item) {
715  parent_item = fLT->AddItem(NULL, "Rotations", pic, pic);
716  parent_item->SetTipText("List of rotations");
717  }
718  } else if (!strcmp(matrix->IsA()->GetName(),"TGeoCombiTrans") ||
719  !strcmp(matrix->IsA()->GetName(),"TGeoHMatrix")) {
720  pic = pic_combi;
721  parent_item = fLT->FindChildByName(NULL, "Combined");
722  if (!parent_item) {
723  parent_item = fLT->AddItem(NULL, "Combined", pic, pic);
724  parent_item->SetTipText("List of combined transformations");
725  }
726  } else continue;
727  fLT->AddItem(parent_item, matrix->GetName(), matrix, pic, pic);
728  }
729 }
730 
731 ////////////////////////////////////////////////////////////////////////////////
732 /// Handle close button.
733 
734 void TGeoMatrixDialog::DoClose()
735 {
736  DeleteWindow();
737 }
738 
739 ////////////////////////////////////////////////////////////////////////////////
740 /// Handle item click.
741 /// Iterate daughters
742 
743 void TGeoMatrixDialog::DoItemClick(TGListTreeItem *item, Int_t btn)
744 {
745  if (btn!=kButton1) return;
746  DoSelect(item);
747  if (!item || !item->GetUserData()) return;
748  //gClient->NeedRedraw(fLT);
749 }
750 
751 ////////////////////////////////////////////////////////////////////////////////
752 /// Connect signals to slots.
753 
754 void TGeoMatrixDialog::ConnectSignalsToSlots()
755 {
756  fClose->Connect("Clicked()", "TGeoMatrixDialog", this, "DoClose()");
757  fLT->Connect("Clicked(TGListTreeItem *, Int_t)", "TGeoMatrixDialog", this,
758  "DoItemClick(TGListTreeItem *, Int_t)");
759 }
760 
761 ClassImp(TGeoTransientPanel);
762 
763 ////////////////////////////////////////////////////////////////////////////////
764 /// Transient panel ctor.
765 
766 TGeoTransientPanel::TGeoTransientPanel(TGedEditor* ged, const char *name, TObject *obj)
767  :TGMainFrame(gClient->GetRoot(),175,20)
768 {
769  fGedEditor = ged;
770  fModel = obj;
771  fCan = new TGCanvas(this, 170, 100);
772  fTab = new TGTab(fCan->GetViewPort(), 10, 10);
773  fCan->SetContainer(fTab);
774  AddFrame(fCan, new TGLayoutHints(kLHintsExpandY | kLHintsExpandX));
775  fTab->Associate(fCan);
776  fTabContainer = fTab->AddTab(name);
777  fStyle = new TGCompositeFrame(fTabContainer, 110, 30, kVerticalFrame);
778  fTabContainer->AddFrame(fStyle, new TGLayoutHints(kLHintsTop | kLHintsExpandX,\
779  5, 0, 2, 2));
780  TString wname = name;
781  wname += " Editor";
782  SetWindowName(wname.Data());
783  SetModel(fModel);
784  fClose = new TGTextButton(this, "Close");
785  AddFrame(fClose, new TGLayoutHints(kLHintsBottom | kLHintsRight, 0,10,5,5));
786  MapSubwindows();
787  Layout();
788  Resize(fTabContainer->GetDefaultWidth()+30, fTabContainer->GetDefaultHeight()+65);
789  MapWindow();
790  gROOT->GetListOfCleanups()->Add(this);
791  fClose->Connect("Clicked()", "TGeoTransientPanel", this, "Hide()");
792 }
793 
794 ////////////////////////////////////////////////////////////////////////////////
795 /// Destructor.
796 
797 TGeoTransientPanel::~TGeoTransientPanel()
798 {
799  DeleteEditors();
800  delete fTab;
801  delete fCan;
802  gROOT->GetListOfCleanups()->Remove(this);
803 }
804 
805 ////////////////////////////////////////////////////////////////////////////////
806 /// When closed via WM close button, just unmap (i.e. hide) editor
807 /// for later use.
808 
809 void TGeoTransientPanel::CloseWindow()
810 {
811  UnmapWindow();
812  gROOT->GetListOfCleanups()->Remove(this);
813 }
814 
815 ////////////////////////////////////////////////////////////////////////////////
816 /// Get editor for a class.
817 /// Look in fStyle for any object deriving from TGedFrame,
818 
819 void TGeoTransientPanel::GetEditors(TClass *cl)
820 {
821  TClass *class2 = TClass::GetClass(TString::Format("%sEditor",cl->GetName()));
822  if (class2 && class2->InheritsFrom(TGedFrame::Class())) {
823  TGFrameElement *fr;
824  TIter next(fStyle->GetList());
825  while ((fr = (TGFrameElement *) next()))
826  if (fr->fFrame->IsA() == class2) return;
827  TGClient *client = fGedEditor->GetClient();
828  TGWindow *exroot = (TGWindow*) client->GetRoot();
829  client->SetRoot(fStyle);
830  TGedEditor::SetFrameCreator(fGedEditor);
831  TGedFrame* gfr = reinterpret_cast<TGedFrame*>(class2->New());
832  gfr->SetModelClass(cl);
833  TGedEditor::SetFrameCreator(0);
834  client->SetRoot(exroot);
835  fStyle->AddFrame(gfr, new TGLayoutHints(kLHintsTop | kLHintsExpandX, 0, 0, 2, 2));
836  gfr->MapSubwindows();
837  }
838 }
839 
840 ////////////////////////////////////////////////////////////////////////////////
841 /// Update the editors in the main tab to reflect the selected object.
842 
843 void TGeoTransientPanel::SetModel(TObject *model)
844 {
845  if (!model) return;
846  fModel = model;
847  GetEditors(model->IsA());
848  TGFrameElement *el;
849  TIter next(fStyle->GetList());
850  while ((el = (TGFrameElement *) next())) {
851  if ((el->fFrame)->InheritsFrom(TGedFrame::Class())) {
852  ((TGedFrame *)(el->fFrame))->SetModel(model);
853  }
854  }
855  Resize(fTabContainer->GetDefaultWidth()+30, fTabContainer->GetDefaultHeight()+65);
856 }
857 
858 ////////////////////////////////////////////////////////////////////////////////
859 /// Hide the transient frame
860 
861 void TGeoTransientPanel::Hide()
862 {
863  UnmapWindow();
864 }
865 
866 ////////////////////////////////////////////////////////////////////////////////
867 /// Hide the transient frame
868 
869 void TGeoTransientPanel::Show()
870 {
871  MapWindow();
872 }
873 
874 ////////////////////////////////////////////////////////////////////////////////
875 /// Delete editors.
876 
877 void TGeoTransientPanel::DeleteEditors()
878 {
879  fStyle->Cleanup();
880 }
881 
882