]>
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> | |
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 | ||
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 | ||
d8b49185 | 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 | ||
ef6dd14a | 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) | |
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 | 155 | void 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 | 170 | void RGBrowser::SetupEditorLook(RGEditor*& editor, TCanvas* glpad) |
5a5a1232 | 171 | { |
1ce2faeb | 172 | fV2->SetEditDisabled(kEditEnable); |
173 | fV2->SetEditable(); | |
907e69dc | 174 | editor = new RGEditor(glpad); |
a8600b56 | 175 | editor->GetTGCanvas()->ChangeOptions(0); |
1ce2faeb | 176 | fV2->SetEditable(kEditDisable); |
177 | fV2->SetEditable(kFALSE); | |
178 | ||
179 | TGFrameElement *el = 0; | |
180 | TIter next(fV2->GetList()); | |
181 | while ((el = (TGFrameElement *)next())) { | |
182 | if (el->fFrame == editor) | |
183 | if (el->fLayout) { | |
184 | el->fLayout->SetLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX | kLHintsExpandY); | |
185 | el->fLayout->SetPadLeft(0); | |
186 | el->fLayout->SetPadRight(0); | |
187 | el->fLayout->SetPadTop(2); | |
188 | el->fLayout->SetPadBottom(2); | |
189 | break; | |
190 | } | |
191 | } | |
5a5a1232 | 192 | |
193 | fV2->MapSubwindows(); | |
194 | } | |
195 | ||
907e69dc | 196 | void RGBrowser::SetupGLViewerLook(RGEditor*& editor, TCanvas* glpad) |
5a5a1232 | 197 | { |
5a5a1232 | 198 | |
1ce2faeb | 199 | TGFrameElement *el = 0; |
200 | fV2->SetEditDisabled(kEditEnable); | |
201 | fV2->SetEditable(); | |
5a5a1232 | 202 | TGLSAViewer* v = new TGLSAViewer(fV2, glpad); |
203 | v->GetFrame()->SetMinWidth(200); | |
1ce2faeb | 204 | v->GetFrame()->SetCleanup(kNoCleanup); |
205 | fV2->SetEditable(kEditDisable); | |
206 | fV2->SetEditable(kFALSE); | |
5a5a1232 | 207 | glpad->SetViewer3D(v); |
1ce2faeb | 208 | TIter next2(fV2->GetList()); |
209 | while ((el = (TGFrameElement *)next2())) { | |
210 | if (el->fFrame == v->GetFrame()) { | |
211 | el->fLayout = new TGLayoutHints(kLHintsLeft | kLHintsExpandX | kLHintsExpandY); | |
212 | break; | |
213 | } | |
214 | } | |
5a5a1232 | 215 | fSelectionFrame->Resize(fSelectionFrame->GetWidth(), fSelectionFrame->GetHeight()/2); |
216 | ||
217 | TGHSplitter *splitter = new TGHSplitter(fV1); | |
1ce2faeb | 218 | fV1->AddFrame(splitter, new TGLayoutHints(kLHintsTop | kLHintsExpandX, 4, 2, 2, 0)); |
907e69dc | 219 | |
1ce2faeb | 220 | fV1->SetEditDisabled(kEditEnable); |
221 | fV1->SetEditable(); | |
907e69dc | 222 | editor = new RGEditor(glpad); |
1ce2faeb | 223 | editor->SetGlobal(kFALSE); |
a8600b56 | 224 | editor->GetTGCanvas()->ChangeOptions(0); |
5a5a1232 | 225 | editor->ChangeOptions(editor->GetOptions() | kFixedHeight); |
1ce2faeb | 226 | fV1->SetEditable(kEditDisable); |
227 | fV1->SetEditable(kFALSE); | |
228 | ||
229 | TIter next(fV1->GetList()); | |
230 | while ((el = (TGFrameElement *)next())) { | |
231 | if (el->fFrame == editor) | |
232 | if (el->fLayout) { | |
233 | el->fLayout->SetLayoutHints(kLHintsTop | kLHintsExpandX); | |
234 | el->fLayout->SetPadLeft(0); | |
235 | el->fLayout->SetPadRight(2); | |
236 | el->fLayout->SetPadTop(2); | |
237 | el->fLayout->SetPadBottom(2); | |
238 | break; | |
239 | } | |
240 | } | |
5a5a1232 | 241 | splitter->SetFrame(editor, kFALSE); |
5a5a1232 | 242 | fV1->MapSubwindows(); |
5a5a1232 | 243 | } |
244 | ||
245 | ||
246 | /**************************************************************************/ | |
247 | /**************************************************************************/ | |
248 | ||
249 | void RGBrowser::RedrawListTree() | |
250 | { | |
251 | gClient->NeedRedraw(fListTree); | |
252 | } | |
253 | ||
254 | /**************************************************************************/ | |
255 | ||
256 | void RGBrowser::ItemClicked(TGListTreeItem *item, Int_t btn, Int_t x, Int_t y) | |
257 | { | |
258 | //printf("ItemClicked item %s List %d btn=%d, x=%d, y=%d\n", | |
259 | // item->GetText(),fDisplayFrame->GetList()->GetEntries(), btn, x, y); | |
260 | ||
092578a7 | 261 | RenderElement* re = (RenderElement*)item->GetUserData(); |
262 | if(re == 0) return; | |
263 | TObject* obj = re->GetObject(); | |
264 | ||
5a5a1232 | 265 | if(btn == 3) { |
a8600b56 | 266 | // If control pressed, show menu for renderelement itself. |
267 | // event->fState & kKeyControlMask | |
268 | // ??? how do i get current event? | |
5a5a1232 | 269 | if (obj) { |
270 | fCtxMenu->Popup(x, y, obj); | |
271 | } | |
272 | return; | |
273 | } | |
274 | ||
092578a7 | 275 | gReve->EditRenderElement(re); |
5a5a1232 | 276 | } |
277 | ||
278 | void RGBrowser::DbClickListItem(TGListTreeItem* item, Int_t btn) | |
279 | { | |
280 | static const Exc_t eH("RGBrowser::DbClickListItem "); | |
281 | ||
907e69dc | 282 | // printf("dbclick item %s\n", item->GetText()); |
092578a7 | 283 | RenderElement* re = (RenderElement*)item->GetUserData(); |
284 | if(re == 0) return; | |
285 | TObject* obj = re->GetObject(); | |
5a5a1232 | 286 | |
287 | if (obj) { | |
288 | // ListTreeHighlight(item); | |
289 | ||
5b457dfa | 290 | re->ExpandIntoListTree(fListTree, item); |
5a5a1232 | 291 | |
292 | // browse geonodes | |
293 | if(obj->IsA()->InheritsFrom("TGeoNode")){ | |
294 | TGeoNode* n = (TGeoNode*) obj->IsA()->DynamicCast( TGeoNode::Class(), obj ); | |
295 | // initialization | |
296 | if(item->GetFirstChild() == 0 && n->GetNdaughters()){ | |
297 | UpdateListItems(item, btn); | |
298 | } | |
299 | } | |
300 | } | |
5a5a1232 | 301 | } |
302 | ||
303 | /**************************************************************************/ | |
304 | ||
305 | void RGBrowser::ExportToCINT(Text_t* var_name, TObject* obj) | |
306 | { | |
307 | const char* cname = obj->IsA()->GetName(); | |
308 | gROOT->ProcessLine(Form("%s* %s = (%s*) %p;", cname, var_name, cname, obj)); | |
309 | } | |
5a5a1232 | 310 | /**************************************************************************/ |
311 | ||
312 | void RGBrowser::UpdateListItems(TGListTreeItem* item, Int_t ) | |
313 | { | |
314 | if (item->GetUserData()) { | |
315 | // ListTreeHighlight(item); | |
092578a7 | 316 | RenderElement* re = (RenderElement*)item->GetUserData(); |
317 | TObject* obj = re->GetObject(); | |
5a5a1232 | 318 | |
319 | // geometry tree | |
320 | if(obj->IsA()->InheritsFrom("TGeoNode")){ | |
321 | // delete exisiting | |
322 | fListTree->DeleteChildren(item); | |
323 | TGeoNode* n = (TGeoNode*) obj->IsA()->DynamicCast( TGeoNode::Class(), obj ); | |
324 | //printf("adding items\n"); | |
325 | if (n->GetNdaughters()) { | |
326 | for (Int_t i=0; i< n->GetNdaughters(); i++) { | |
327 | TString title; | |
328 | title.Form("%d : %s[%d]", i, | |
329 | n->GetDaughter(i)->GetVolume()->GetName(), | |
330 | n->GetDaughter(i)->GetNdaughters()); | |
331 | ||
332 | TGListTreeItem* child = fListTree->AddItem( item, title.Data()); | |
333 | child->SetUserData( n->GetDaughter(i)); | |
334 | } | |
335 | } | |
336 | } | |
337 | } | |
338 | } | |
5b457dfa | 339 | |
340 | /**************************************************************************/ |