]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TGeant4/TG4ListTreeFrame.cxx
Noninitialized pointers set to 0 (J. Belikov)
[u/mrichter/AliRoot.git] / TGeant4 / TG4ListTreeFrame.cxx
1 // $Id$
2 // Category: interfaces
3 //
4 // Author: D. Adamova
5 //
6 //========================================================
7 //
8 //------------TG4ListTreeFrame.cxx--------------------------------//
9 //--------- Frame for the ListTree container---//
10 //
11 //========================================================= 
12  
13 #include "TG4ListTreeFrame.h"
14 #include "TG4GuiVolume.h"
15 #include "TG4Globals.h"
16
17 #include <TGListTree.h>
18 #include <TGCanvas.h>
19 #include <TGTab.h>
20
21 #include <G4LogicalVolume.hh>
22 #include <G4UImanager.hh>
23
24 ClassImp(TG4ListTreeFrame)
25
26 TG4ListTreeFrame::TG4ListTreeFrame( TGTab* Tab, TGMainFrame* ActionFrame)
27 {
28 //------>canvas for the ListTree
29    TGCompositeFrame* parent= Tab->AddTab("Volumes");
30    fCanvasWindow = new TGCanvas( parent, 400, 240);   
31    ULong_t back= TGFrame::GetWhitePixel(); 
32    fCanvasWindow->ChangeBackground(back);
33  
34 //----->ListTree for the logical volumes
35    fVolumesListTree= new TGListTree(fCanvasWindow->GetViewPort(), 10, 10, kHorizontalFrame);
36    fVolumesListTree->Associate(ActionFrame);
37 //------->container for the ListTree
38    fCanvasWindow->SetContainer(fVolumesListTree);
39
40    TGLayoutHints *lCanvasLayout = new TGLayoutHints(kLHintsExpandX | kLHintsExpandY);
41    parent->AddFrame(fCanvasWindow, lCanvasLayout);
42    
43 }
44
45 TG4ListTreeFrame::TG4ListTreeFrame(const TG4ListTreeFrame& ltf) 
46 {
47 // Dummy copy constructor 
48   TG4Globals::Exception(
49     "Attempt to use TG4ListTreeFrame copy constructor.");
50 }
51
52 TG4ListTreeFrame& TG4ListTreeFrame::operator=(const TG4ListTreeFrame& ltf)
53 {
54   // check assignement to self
55   if (this == &ltf) return *this;
56
57   TG4Globals::Exception(
58     "Attempt to assign  singleton.");
59     
60   return *this;  
61 }    
62
63 TG4ListTreeFrame::~TG4ListTreeFrame()
64 {
65 //---> liquidator 
66
67    G4cout << "\n Now in  TG4ListTreeFrame destructor \n" << G4endl;
68    delete fCanvasWindow;
69    delete fVolumesListTree;   
70
71 }
72
73 TGListTreeItem*  TG4ListTreeFrame::
74 AddItem(TObject* obj, TGListTreeItem* parent, const char* name, 
75                        const TGPicture* open, const TGPicture* closed)
76 {
77 //----->Add item to the list tree
78     return fVolumesListTree->AddItem(parent, name, obj, open, closed);
79
80   
81 Bool_t TG4ListTreeFrame::ProcessSubMessage(Long_t msg, Long_t parm1)
82 {
83 //---> Processes events generated by the ListTree widget
84
85         switch (GET_SUBMSG(msg)) {
86
87 //----->Cases to Handle mouse click
88    //-->case 1 
89         case kCT_ITEMCLICK: 
90     //---> Button 1: Select volume
91             if (parm1 == kButton1){
92             TGListTreeItem* item = fVolumesListTree->GetSelected();
93              if (item) {
94              
95              TG4GuiVolume* volume=((TG4GuiVolume*) item->GetUserData());   
96              G4LogicalVolume* lvolume = volume->GetLogicalVolume();
97
98               if  ( lvolume ) {
99                G4cout << "The selected logical volume name is   " 
100                     << lvolume->GetName() << G4endl;
101                   };
102               };
103             }; 
104               
105     //---> Button 3: Draw Volume
106             if (parm1 == kButton3){
107              TGListTreeItem* item = fVolumesListTree->GetSelected();
108              if (item){
109                 DrawSelectedVolume(item);};
110             }; 
111                   
112             break;
113             
114    //-->case 2      
115         case kCT_ITEMDBLCLICK:
116             if (parm1 == kButton1) {
117                 if (fVolumesListTree->GetSelected() != 0) {
118                     gClient->NeedRedraw(fVolumesListTree);
119                 };
120             };
121             break;
122    //-->default for GET_SUBMSG      
123         default:
124             break;
125         }
126         
127     return kTRUE;       
128 }
129
130 void  TG4ListTreeFrame::DrawSelectedVolume(TGListTreeItem* item)
131 {
132 //---> draw the volume belonging to the item
133
134   TG4GuiVolume* volume=((TG4GuiVolume*) item->GetUserData());
135   G4LogicalVolume* lvolume = volume->GetLogicalVolume();             
136 //-------->>>>>>inserted part for getting parent and number of daughters
137   TGListTreeItem* iParent = item -> GetParent();
138   G4int noDght, ii;
139   G4int icopy = 0;
140   G4String parentName, lName;
141     
142   if (iParent) {
143     
144       TG4GuiVolume* vParent   = ((TG4GuiVolume*) iParent->GetUserData());
145       G4LogicalVolume* lvParent = vParent->GetLogicalVolume();
146       parentName = lvParent->GetName();
147       noDght = lvParent->GetNoDaughters();
148 //------>>>> end of getting parent and number of daughters
149
150    //------->>>>inserted for getting no on copies
151       ii = 0;
152       while ( ii < noDght){
153          if ( lvParent->GetDaughter(ii)->GetLogicalVolume() ==  lvolume )
154               icopy++;  
155      
156              ii++;
157           };
158    //------>>>> end of getting no of copies
159
160       lName = lvolume->GetName();
161   }
162 //------->>>>> case of iParent = 0        
163   else {
164       lName = "ALIC";
165       icopy = 1;
166   };
167      
168   G4cout << "For logical volume   " << lName << "   "
169          << "the number of copies is :!   "  << icopy << endl;
170 //------> looping over number of copies
171    ii=0;              
172    while ( ii < icopy) { 
173       G4String lCommand = "/vis/scene/add/volume  " ;
174       lCommand += lName;
175       lCommand += "  ";
176       TG4Globals::AppendNumberToString( lCommand, ii);
177       lCommand += "  -1";
178       G4cout << "!!!!ADD VOLUME COMMAND IS!!!!   " << lCommand << G4endl;
179       G4UImanager::GetUIpointer()->ApplyCommand( lCommand );
180       G4UImanager::GetUIpointer()->ApplyCommand(
181                   "/control/execute vis_cont.mac");
182       ii++;
183       };
184       
185 }
186
187