]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EVE/Reve/RGBrowser.cxx
Missing initialization; fiddle with the track marker-style a bit more.
[u/mrichter/AliRoot.git] / EVE / Reve / RGBrowser.cxx
1 #include "RGBrowser.h"
2 #include "RGTopFrame.h"
3 #include "Reve.h"
4 #include "RGEditor.h"
5 #include "VSDSelector.h"
6 #include <Reve/PointSet.h>
7 #include <Reve/Track.h>
8
9 #include <Riostream.h>
10
11 #include <TROOT.h>
12 #include <TStyle.h>
13 #include <TSystem.h>
14 #include <TRint.h>
15 #include <TVirtualX.h>
16 #include <TEnv.h>
17
18 #include <TApplication.h>
19 #include <TFile.h>
20 #include <TEventList.h>
21 #include <TClassMenuItem.h>
22
23 #include <TColor.h>
24 #include <TPolyMarker3D.h>
25
26 #include <TGCanvas.h>
27 #include <TGSplitter.h>
28 #include <TGStatusBar.h>
29 #include <TGMenu.h>
30 #include <TGPicture.h>
31 #include <TGToolBar.h>
32 #include <TGLabel.h>
33 #include <TGXYLayout.h>
34 #include <TGNumberEntry.h>
35 #include <KeySymbols.h>
36
37 #include <TGLSAViewer.h>
38 #include <TGLSAFrame.h>
39 #include <TGTab.h>
40
41 #include <TGeoVolume.h>
42 #include <TGeoNode.h>
43
44 using namespace Reve;
45 using namespace Reve;
46
47 /**************************************************************************/
48
49 void RGBrowser::SetupCintExport(TClass* cl)
50 {
51  
52   TList* l = cl->GetMenuList();
53   TClassMenuItem* n = new TClassMenuItem(TClassMenuItem::kPopupUserFunction, cl,
54                                          "Export to CINT", "ExportToCINT", this, "const char*,TObject*", 1);
55
56   l->AddFirst(n);
57 }
58
59 void RGBrowser::CalculateReparentXY(TGObject* parent, Int_t& x, Int_t& y)
60 {
61   UInt_t   w, h;
62   Window_t childdum;
63   gVirtualX->GetWindowSize(parent->GetId(), x, y, w, h);
64   gVirtualX->TranslateCoordinates(parent->GetId(),
65                                   gClient->GetDefaultRoot()->GetId(),
66                                   0, 0, x, y, childdum);
67 }
68
69 /**************************************************************************/
70
71 RGBrowser::RGBrowser(const TGWindow *p, UInt_t w, UInt_t h) :
72   TGCompositeFrame(p, w, h),
73     
74   fMainFrame(0), fV1(0), fV2(0),
75   fSelectionFrame(0), fTreeView(0),
76   fCanvasWindow(0), fDisplayFrame(0),  
77   fListTree(0),
78   fCtxMenu(0)
79 {
80   fMainFrame = new TGCompositeFrame(this, 100, 10, kHorizontalFrame | kRaisedFrame);
81   fMainFrame->SetCleanup(kDeepCleanup);
82   fV1 = new TGVerticalFrame(fMainFrame, 250, 10, kSunkenFrame | kFixedWidth);
83   fV2 = new TGVerticalFrame(fMainFrame,  50, 10, kSunkenFrame);
84
85   TGLayoutHints *lo;
86   lo = new TGLayoutHints(kLHintsLeft | kLHintsExpandY,2,0,2,2);
87   fMainFrame->AddFrame(fV1, lo);
88
89   TGVSplitter *splitter = new TGVSplitter(fMainFrame);
90   splitter->SetFrame(fV1, kTRUE);
91   fMainFrame->AddFrame(splitter,
92                        new TGLayoutHints(kLHintsLeft | kLHintsExpandY, 1,1,2,2));
93    
94   lo = new TGLayoutHints(kLHintsRight | kLHintsExpandX | kLHintsExpandY,0,2,2,4);
95   fMainFrame->AddFrame(fV2, lo);
96
97   // selection frame
98   fSelectionFrame = new TGCompositeFrame(fV1, 250, 10, kVerticalFrame);
99   fTreeView = new TGCanvas(fSelectionFrame, 250, 10, kSunkenFrame | kDoubleBorder);
100   fListTree = new TGListTree(fTreeView->GetViewPort(), 250, 10, kHorizontalFrame);
101   fListTree->SetCanvas(fTreeView);
102   fListTree->Associate(this);
103   fListTree->SetColorMode(TGListTree::EColorMarkupMode(TGListTree::kColorUnderline | TGListTree::kColorBox));
104   fTreeView->SetContainer(fListTree);
105
106   lo= new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX | kLHintsExpandY,
107                         2, 2, 2, 2);
108   fSelectionFrame->AddFrame(fTreeView, lo);
109
110   lo = new TGLayoutHints(kLHintsTop | kLHintsExpandX | kLHintsExpandY);
111   fV1->AddFrame(fSelectionFrame, lo);
112  
113   // Classic look vars:
114   fCanvasWindow = 0;
115   fDisplayFrame = 0;
116  
117   //display frame
118
119   lo = new TGLayoutHints(kLHintsExpandX | kLHintsExpandY);
120   AddFrame(fMainFrame, lo);
121
122
123   SetWindowName("Reve List Browser");
124   MapSubwindows();
125   //Resize(GetDefaultSize()); // this is used here to init layout algoritme
126
127   //MapWindow();
128
129   // popup menu
130   
131   fCtxMenu = new TContextMenu("", "");
132
133
134   //-- CINT export now declared in RenderElement with *MENU*
135   // SetupCintExport(PointSet::Class());
136   // SetupCintExport(Track::Class());
137   // SetupCintExport(TrackList::Class());
138   
139   fListTree->Connect("Clicked(TGListTreeItem*, Int_t, Int_t, Int_t)", "Reve::RGBrowser", 
140                      this, "ItemClicked(TGListTreeItem*, Int_t, Int_t, Int_t)");  
141   fListTree->Connect("DoubleClicked(TGListTreeItem*, Int_t)", "Reve::RGBrowser", 
142                      this, "DbClickListItem(TGListTreeItem*,Int_t )"); 
143   //fListTree->Connect("Clicked(TGListTreeItem*, Int_t)", "Reve::RGBrowser", 
144   //                 this, "DisplayChildren(TGListTreeItem*, Int_t)");  
145
146   //---------------------------------------------
147   // WARNING ... this Connect goes to *gReve*!
148   fListTree->Connect("Checked(TObject*,Bool_t)", "Reve::RGTopFrame",
149                      gReve, "RenderElementChecked(TObject*, Bool_t)");
150 }
151
152 /**************************************************************************/
153
154 void RGBrowser::SetupClassicLook(RGEditor*& editor, TCanvas* glpad)
155 {
156   fCanvasWindow = new TGCanvas(fV2, 25, 250);
157   fDisplayFrame = new TGCompositeFrame(fCanvasWindow->GetViewPort(), 0, 0,kVerticalFrame, TGFrame::GetWhitePixel() );
158   fCanvasWindow->SetContainer(fDisplayFrame);
159   fDisplayFrame->SetCleanup(kDeepCleanup);
160
161   fV2->AddFrame(fCanvasWindow, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 0, 0, 2, 2));
162   fV2->MapSubwindows();
163
164   editor = new RGEditor(glpad);
165   editor->GetTGCanvas()->ChangeOptions(0);
166   editor->SetWindowName("Reve Editor");
167 }
168
169 void RGBrowser::SetupEditorLook(RGEditor*& editor, TCanvas* glpad)
170 {
171   fClient->SetRoot(fV2);
172   editor = new RGEditor(glpad);
173   editor->GetTGCanvas()->ChangeOptions(0);
174   fV2->RemoveFrame(editor);
175   fV2->AddFrame(editor, new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX | kLHintsExpandY, 0, 0, 2, 2));
176   fClient->SetRoot();
177
178   /*
179     editor->UnmapWindow();
180     fV2->AddFrame(editor, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 0, 0, 2, 2));
181     Int_t x, y;
182     CalculateReparentXY(fV2, x, y);
183     editor->ReparentWindow(fV2, x, y);
184   */
185
186   fV2->MapSubwindows();
187 }
188
189 void RGBrowser::SetupGLViewerLook(RGEditor*& editor, TCanvas* glpad)
190 {
191   TGLayoutHints *lo;
192
193   TGLSAViewer* v = new TGLSAViewer(fV2, glpad);
194   v->GetFrame()->SetMinWidth(200);
195   lo = new TGLayoutHints(kLHintsLeft | kLHintsExpandX | kLHintsExpandY);
196   fV2->AddFrame(v->GetFrame(), lo);
197   glpad->SetViewer3D(v);
198
199   fSelectionFrame->Resize(fSelectionFrame->GetWidth(), fSelectionFrame->GetHeight()/2);
200
201   TGHSplitter *splitter = new TGHSplitter(fV1);
202   lo = new TGLayoutHints(kLHintsTop | kLHintsExpandX, 4, 2, 2, 0);
203   fSelectionFrame->AddFrame(splitter, lo);
204
205   fClient->SetRoot(fV1);
206   editor = new RGEditor(glpad);
207   editor->GetTGCanvas()->ChangeOptions(0);
208   editor->ChangeOptions(editor->GetOptions() | kFixedHeight);
209   fV1->RemoveFrame(editor);
210   fV1->AddFrame(editor, new TGLayoutHints(kLHintsTop | kLHintsExpandX, 0,2,2,2));
211   fClient->SetRoot();
212
213   /*
214     editor->UnmapWindow();
215     editor->ChangeOptions(editor->GetOptions() | kFixedHeight);
216     lo = new TGLayoutHints(kLHintsTop | kLHintsExpandX, 0,2,2,2);
217     fV1->AddFrame(editor, lo);
218     Int_t x, y;
219     CalculateReparentXY(fV1, x, y);
220     editor->ReparentWindow(fV1, x, y);
221   */
222
223   splitter->SetFrame(editor, kFALSE);
224
225   fV1->MapSubwindows();
226   v->GetFrame()->MapWindow();
227 }
228
229
230 /**************************************************************************/
231 /**************************************************************************/
232
233 void RGBrowser::RedrawListTree()
234 {
235   gClient->NeedRedraw(fListTree);
236 }
237
238 /**************************************************************************/
239
240 void RGBrowser::ItemClicked(TGListTreeItem *item, Int_t btn, Int_t x, Int_t y)
241 {
242   //printf("ItemClicked item %s List %d btn=%d, x=%d, y=%d\n",
243   //  item->GetText(),fDisplayFrame->GetList()->GetEntries(), btn, x, y);
244
245   RenderElement* re = (RenderElement*)item->GetUserData();
246   if(re == 0) return;
247   TObject* obj = re->GetObject();
248
249   if(btn == 3) {
250     // If control pressed, show menu for renderelement itself.
251     // event->fState & kKeyControlMask
252     // ??? how do i get current event?
253     if (obj) {
254       fCtxMenu->Popup(x, y, obj);
255     }
256     return;
257   }
258
259   gReve->EditRenderElement(re);
260 }
261
262 void RGBrowser::DbClickListItem(TGListTreeItem* item, Int_t btn)
263 {
264   static const Exc_t eH("RGBrowser::DbClickListItem ");
265
266   // printf("dbclick item %s\n", item->GetText());
267   RenderElement* re = (RenderElement*)item->GetUserData();
268   if(re == 0) return;
269   TObject* obj = re->GetObject();
270
271   if (obj) {
272     //  ListTreeHighlight(item);
273
274     re->ExpandIntoListTree(fListTree, item);
275     
276     // browse geonodes
277     if(obj->IsA()->InheritsFrom("TGeoNode")){
278       TGeoNode* n = (TGeoNode*) obj->IsA()->DynamicCast( TGeoNode::Class(), obj );
279       // initialization
280       if(item->GetFirstChild() == 0 && n->GetNdaughters()){
281         UpdateListItems(item, btn);
282       }
283     }
284   }
285 }
286
287 /**************************************************************************/
288
289 void RGBrowser::ExportToCINT(Text_t* var_name, TObject* obj)
290 {
291   const char* cname = obj->IsA()->GetName();
292   gROOT->ProcessLine(Form("%s* %s = (%s*) %p;", cname, var_name, cname, obj));
293 }
294 /**************************************************************************/
295
296 void RGBrowser::UpdateListItems(TGListTreeItem* item, Int_t )
297 {
298   if (item->GetUserData()) {
299     //  ListTreeHighlight(item);
300     RenderElement* re = (RenderElement*)item->GetUserData();
301     TObject* obj = re->GetObject();
302
303     // geometry tree
304     if(obj->IsA()->InheritsFrom("TGeoNode")){
305       // delete exisiting
306       fListTree->DeleteChildren(item);
307       TGeoNode* n = (TGeoNode*) obj->IsA()->DynamicCast( TGeoNode::Class(), obj );
308       //printf("adding items\n");
309       if (n->GetNdaughters()) {
310         for (Int_t i=0; i< n->GetNdaughters(); i++) { 
311           TString title;
312           title.Form("%d : %s[%d]", i,
313                      n->GetDaughter(i)->GetVolume()->GetName(),
314                      n->GetDaughter(i)->GetNdaughters());
315
316           TGListTreeItem* child = fListTree->AddItem( item, title.Data());
317           child->SetUserData( n->GetDaughter(i));
318         }
319       }
320     }
321   }
322 }
323
324 /**************************************************************************/