]> git.uio.no Git - u/mrichter/AliRoot.git/blame - EVE/Reve/RGBrowser.cxx
Record changes.
[u/mrichter/AliRoot.git] / EVE / Reve / RGBrowser.cxx
CommitLineData
5a5a1232 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>
5b457dfa 30#include <TGPicture.h>
5a5a1232 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
44using namespace Reve;
45using namespace Reve;
46
47/**************************************************************************/
48
49void 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
d8b49185 59void 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
ef6dd14a 71RGBrowser::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)
5a5a1232 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));
6d955b9c 104 fListTree->SetAutoCheckBoxPic(kFALSE);
5a5a1232 105 fTreeView->SetContainer(fListTree);
106
107 lo= new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX | kLHintsExpandY,
108 2, 2, 2, 2);
109 fSelectionFrame->AddFrame(fTreeView, lo);
110
111 lo = new TGLayoutHints(kLHintsTop | kLHintsExpandX | kLHintsExpandY);
112 fV1->AddFrame(fSelectionFrame, lo);
113
114 // Classic look vars:
115 fCanvasWindow = 0;
116 fDisplayFrame = 0;
117
118 //display frame
119
120 lo = new TGLayoutHints(kLHintsExpandX | kLHintsExpandY);
121 AddFrame(fMainFrame, lo);
122
123
124 SetWindowName("Reve List Browser");
125 MapSubwindows();
126 //Resize(GetDefaultSize()); // this is used here to init layout algoritme
127
128 //MapWindow();
129
130 // popup menu
131
5b457dfa 132 fCtxMenu = new TContextMenu("", "");
133
5a5a1232 134
135 //-- CINT export now declared in RenderElement with *MENU*
136 // SetupCintExport(PointSet::Class());
137 // SetupCintExport(Track::Class());
138 // SetupCintExport(TrackList::Class());
139
140 fListTree->Connect("Clicked(TGListTreeItem*, Int_t, Int_t, Int_t)", "Reve::RGBrowser",
141 this, "ItemClicked(TGListTreeItem*, Int_t, Int_t, Int_t)");
142 fListTree->Connect("DoubleClicked(TGListTreeItem*, Int_t)", "Reve::RGBrowser",
143 this, "DbClickListItem(TGListTreeItem*,Int_t )");
144 //fListTree->Connect("Clicked(TGListTreeItem*, Int_t)", "Reve::RGBrowser",
145 // this, "DisplayChildren(TGListTreeItem*, Int_t)");
146
147 //---------------------------------------------
148 // WARNING ... this Connect goes to *gReve*!
149 fListTree->Connect("Checked(TObject*,Bool_t)", "Reve::RGTopFrame",
150 gReve, "RenderElementChecked(TObject*, Bool_t)");
151}
152
153/**************************************************************************/
154
907e69dc 155void RGBrowser::SetupClassicLook(RGEditor*& editor, TCanvas* glpad)
5a5a1232 156{
157 fCanvasWindow = new TGCanvas(fV2, 25, 250);
158 fDisplayFrame = new TGCompositeFrame(fCanvasWindow->GetViewPort(), 0, 0,kVerticalFrame, TGFrame::GetWhitePixel() );
159 fCanvasWindow->SetContainer(fDisplayFrame);
160 fDisplayFrame->SetCleanup(kDeepCleanup);
161
162 fV2->AddFrame(fCanvasWindow, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 0, 0, 2, 2));
163 fV2->MapSubwindows();
d8b49185 164
907e69dc 165 editor = new RGEditor(glpad);
a8600b56 166 editor->GetTGCanvas()->ChangeOptions(0);
907e69dc 167 editor->SetWindowName("Reve Editor");
168}
d8b49185 169
907e69dc 170void RGBrowser::SetupEditorLook(RGEditor*& editor, TCanvas* glpad)
5a5a1232 171{
907e69dc 172 fClient->SetRoot(fV2);
173 editor = new RGEditor(glpad);
a8600b56 174 editor->GetTGCanvas()->ChangeOptions(0);
907e69dc 175 fV2->RemoveFrame(editor);
176 fV2->AddFrame(editor, new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX | kLHintsExpandY, 0, 0, 2, 2));
177 fClient->SetRoot();
178
179 /*
180 editor->UnmapWindow();
181 fV2->AddFrame(editor, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 0, 0, 2, 2));
182 Int_t x, y;
183 CalculateReparentXY(fV2, x, y);
184 editor->ReparentWindow(fV2, x, y);
185 */
5a5a1232 186
187 fV2->MapSubwindows();
188}
189
907e69dc 190void RGBrowser::SetupGLViewerLook(RGEditor*& editor, TCanvas* glpad)
5a5a1232 191{
192 TGLayoutHints *lo;
193
194 TGLSAViewer* v = new TGLSAViewer(fV2, glpad);
195 v->GetFrame()->SetMinWidth(200);
196 lo = new TGLayoutHints(kLHintsLeft | kLHintsExpandX | kLHintsExpandY);
197 fV2->AddFrame(v->GetFrame(), lo);
198 glpad->SetViewer3D(v);
199
200 fSelectionFrame->Resize(fSelectionFrame->GetWidth(), fSelectionFrame->GetHeight()/2);
201
202 TGHSplitter *splitter = new TGHSplitter(fV1);
203 lo = new TGLayoutHints(kLHintsTop | kLHintsExpandX, 4, 2, 2, 0);
204 fSelectionFrame->AddFrame(splitter, lo);
907e69dc 205
206 fClient->SetRoot(fV1);
207 editor = new RGEditor(glpad);
a8600b56 208 editor->GetTGCanvas()->ChangeOptions(0);
5a5a1232 209 editor->ChangeOptions(editor->GetOptions() | kFixedHeight);
907e69dc 210 fV1->RemoveFrame(editor);
211 fV1->AddFrame(editor, new TGLayoutHints(kLHintsTop | kLHintsExpandX, 0,2,2,2));
212 fClient->SetRoot();
213
214 /*
215 editor->UnmapWindow();
216 editor->ChangeOptions(editor->GetOptions() | kFixedHeight);
217 lo = new TGLayoutHints(kLHintsTop | kLHintsExpandX, 0,2,2,2);
218 fV1->AddFrame(editor, lo);
219 Int_t x, y;
220 CalculateReparentXY(fV1, x, y);
221 editor->ReparentWindow(fV1, x, y);
222 */
5a5a1232 223
224 splitter->SetFrame(editor, kFALSE);
225
226 fV1->MapSubwindows();
227 v->GetFrame()->MapWindow();
228}
229
230
231/**************************************************************************/
232/**************************************************************************/
233
234void RGBrowser::RedrawListTree()
235{
236 gClient->NeedRedraw(fListTree);
237}
238
239/**************************************************************************/
240
241void RGBrowser::ItemClicked(TGListTreeItem *item, Int_t btn, Int_t x, Int_t y)
242{
243 //printf("ItemClicked item %s List %d btn=%d, x=%d, y=%d\n",
244 // item->GetText(),fDisplayFrame->GetList()->GetEntries(), btn, x, y);
245
092578a7 246 RenderElement* re = (RenderElement*)item->GetUserData();
247 if(re == 0) return;
248 TObject* obj = re->GetObject();
249
5a5a1232 250 if(btn == 3) {
a8600b56 251 // If control pressed, show menu for renderelement itself.
252 // event->fState & kKeyControlMask
253 // ??? how do i get current event?
5a5a1232 254 if (obj) {
255 fCtxMenu->Popup(x, y, obj);
256 }
257 return;
258 }
259
092578a7 260 gReve->EditRenderElement(re);
5a5a1232 261}
262
263void RGBrowser::DbClickListItem(TGListTreeItem* item, Int_t btn)
264{
265 static const Exc_t eH("RGBrowser::DbClickListItem ");
266
907e69dc 267 // printf("dbclick item %s\n", item->GetText());
092578a7 268 RenderElement* re = (RenderElement*)item->GetUserData();
269 if(re == 0) return;
270 TObject* obj = re->GetObject();
5a5a1232 271
272 if (obj) {
273 // ListTreeHighlight(item);
274
5b457dfa 275 re->ExpandIntoListTree(fListTree, item);
5a5a1232 276
277 // browse geonodes
278 if(obj->IsA()->InheritsFrom("TGeoNode")){
279 TGeoNode* n = (TGeoNode*) obj->IsA()->DynamicCast( TGeoNode::Class(), obj );
280 // initialization
281 if(item->GetFirstChild() == 0 && n->GetNdaughters()){
282 UpdateListItems(item, btn);
283 }
284 }
285 }
5a5a1232 286}
287
288/**************************************************************************/
289
290void RGBrowser::ExportToCINT(Text_t* var_name, TObject* obj)
291{
292 const char* cname = obj->IsA()->GetName();
293 gROOT->ProcessLine(Form("%s* %s = (%s*) %p;", cname, var_name, cname, obj));
294}
5a5a1232 295/**************************************************************************/
296
297void RGBrowser::UpdateListItems(TGListTreeItem* item, Int_t )
298{
299 if (item->GetUserData()) {
300 // ListTreeHighlight(item);
092578a7 301 RenderElement* re = (RenderElement*)item->GetUserData();
302 TObject* obj = re->GetObject();
5a5a1232 303
304 // geometry tree
305 if(obj->IsA()->InheritsFrom("TGeoNode")){
306 // delete exisiting
307 fListTree->DeleteChildren(item);
308 TGeoNode* n = (TGeoNode*) obj->IsA()->DynamicCast( TGeoNode::Class(), obj );
309 //printf("adding items\n");
310 if (n->GetNdaughters()) {
311 for (Int_t i=0; i< n->GetNdaughters(); i++) {
312 TString title;
313 title.Form("%d : %s[%d]", i,
314 n->GetDaughter(i)->GetVolume()->GetName(),
315 n->GetDaughter(i)->GetNdaughters());
316
317 TGListTreeItem* child = fListTree->AddItem( item, title.Data());
318 child->SetUserData( n->GetDaughter(i));
319 }
320 }
321 }
322 }
323}
5b457dfa 324
325/**************************************************************************/