]>
Commit | Line | Data |
---|---|---|
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> | |
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 | ||
d8b49185 | 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 | ||
ef6dd14a | 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) | |
5a5a1232 | 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 | ||
907e69dc | 152 | void RGBrowser::SetupClassicLook(RGEditor*& editor, TCanvas* glpad) |
5a5a1232 | 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(); | |
d8b49185 | 161 | |
907e69dc | 162 | editor = new RGEditor(glpad); |
a8600b56 | 163 | editor->GetTGCanvas()->ChangeOptions(0); |
907e69dc | 164 | editor->SetWindowName("Reve Editor"); |
165 | } | |
d8b49185 | 166 | |
907e69dc | 167 | void RGBrowser::SetupEditorLook(RGEditor*& editor, TCanvas* glpad) |
5a5a1232 | 168 | { |
907e69dc | 169 | fClient->SetRoot(fV2); |
170 | editor = new RGEditor(glpad); | |
a8600b56 | 171 | editor->GetTGCanvas()->ChangeOptions(0); |
907e69dc | 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 | */ | |
5a5a1232 | 183 | |
184 | fV2->MapSubwindows(); | |
185 | } | |
186 | ||
907e69dc | 187 | void RGBrowser::SetupGLViewerLook(RGEditor*& editor, TCanvas* glpad) |
5a5a1232 | 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); | |
907e69dc | 202 | |
203 | fClient->SetRoot(fV1); | |
204 | editor = new RGEditor(glpad); | |
a8600b56 | 205 | editor->GetTGCanvas()->ChangeOptions(0); |
5a5a1232 | 206 | editor->ChangeOptions(editor->GetOptions() | kFixedHeight); |
907e69dc | 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 | */ | |
5a5a1232 | 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 | ||
092578a7 | 243 | RenderElement* re = (RenderElement*)item->GetUserData(); |
244 | if(re == 0) return; | |
245 | TObject* obj = re->GetObject(); | |
246 | ||
5a5a1232 | 247 | if(btn == 3) { |
a8600b56 | 248 | // If control pressed, show menu for renderelement itself. |
249 | // event->fState & kKeyControlMask | |
250 | // ??? how do i get current event? | |
5a5a1232 | 251 | if (obj) { |
252 | fCtxMenu->Popup(x, y, obj); | |
253 | } | |
254 | return; | |
255 | } | |
256 | ||
092578a7 | 257 | gReve->EditRenderElement(re); |
5a5a1232 | 258 | } |
259 | ||
260 | void RGBrowser::DbClickListItem(TGListTreeItem* item, Int_t btn) | |
261 | { | |
262 | static const Exc_t eH("RGBrowser::DbClickListItem "); | |
263 | ||
907e69dc | 264 | // printf("dbclick item %s\n", item->GetText()); |
092578a7 | 265 | RenderElement* re = (RenderElement*)item->GetUserData(); |
266 | if(re == 0) return; | |
267 | TObject* obj = re->GetObject(); | |
5a5a1232 | 268 | |
269 | if (obj) { | |
270 | // ListTreeHighlight(item); | |
271 | ||
272 | { | |
092578a7 | 273 | RenderElementListBase* rel = dynamic_cast<RenderElementListBase*>(re); |
5a5a1232 | 274 | if(rel != 0) { |
73ecdbca | 275 | //Int_t ni = |
276 | rel->ExpandIntoListTree(fListTree, item); | |
277 | // printf("%s expanded by %d\n", eH.Data(), ni); | |
5a5a1232 | 278 | } |
279 | } | |
280 | ||
281 | // browse geonodes | |
282 | if(obj->IsA()->InheritsFrom("TGeoNode")){ | |
283 | TGeoNode* n = (TGeoNode*) obj->IsA()->DynamicCast( TGeoNode::Class(), obj ); | |
284 | // initialization | |
285 | if(item->GetFirstChild() == 0 && n->GetNdaughters()){ | |
286 | UpdateListItems(item, btn); | |
287 | } | |
288 | } | |
289 | } | |
5a5a1232 | 290 | } |
291 | ||
292 | /**************************************************************************/ | |
293 | ||
294 | void RGBrowser::ExportToCINT(Text_t* var_name, TObject* obj) | |
295 | { | |
296 | const char* cname = obj->IsA()->GetName(); | |
297 | gROOT->ProcessLine(Form("%s* %s = (%s*) %p;", cname, var_name, cname, obj)); | |
298 | } | |
5a5a1232 | 299 | /**************************************************************************/ |
300 | ||
301 | void RGBrowser::UpdateListItems(TGListTreeItem* item, Int_t ) | |
302 | { | |
303 | if (item->GetUserData()) { | |
304 | // ListTreeHighlight(item); | |
092578a7 | 305 | RenderElement* re = (RenderElement*)item->GetUserData(); |
306 | TObject* obj = re->GetObject(); | |
5a5a1232 | 307 | |
308 | // geometry tree | |
309 | if(obj->IsA()->InheritsFrom("TGeoNode")){ | |
310 | // delete exisiting | |
311 | fListTree->DeleteChildren(item); | |
312 | TGeoNode* n = (TGeoNode*) obj->IsA()->DynamicCast( TGeoNode::Class(), obj ); | |
313 | //printf("adding items\n"); | |
314 | if (n->GetNdaughters()) { | |
315 | for (Int_t i=0; i< n->GetNdaughters(); i++) { | |
316 | TString title; | |
317 | title.Form("%d : %s[%d]", i, | |
318 | n->GetDaughter(i)->GetVolume()->GetName(), | |
319 | n->GetDaughter(i)->GetNdaughters()); | |
320 | ||
321 | TGListTreeItem* child = fListTree->AddItem( item, title.Data()); | |
322 | child->SetUserData( n->GetDaughter(i)); | |
323 | } | |
324 | } | |
325 | } | |
326 | } | |
327 | } |