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