2 #include "RGTopFrame.h"
5 #include "VSDSelector.h"
6 #include <Reve/PointSet.h>
7 #include <Reve/Track.h>
15 #include <TVirtualX.h>
18 #include <TApplication.h>
20 #include <TEventList.h>
21 #include <TClassMenuItem.h>
24 #include <TPolyMarker3D.h>
27 #include <TGSplitter.h>
28 #include <TGStatusBar.h>
30 #include <TGToolBar.h>
32 #include <TGXYLayout.h>
33 #include <TGNumberEntry.h>
34 #include <KeySymbols.h>
36 #include <TGLSAViewer.h>
37 #include <TGLSAFrame.h>
40 #include <TGeoVolume.h>
46 /**************************************************************************/
48 void RGBrowser::SetupCintExport(TClass* cl)
51 TList* l = cl->GetMenuList();
52 TClassMenuItem* n = new TClassMenuItem(TClassMenuItem::kPopupUserFunction, cl,
53 "Export to CINT", "ExportToCINT", this, "const char*,TObject*", 1);
58 void RGBrowser::CalculateReparentXY(TGObject* parent, Int_t& x, Int_t& y)
62 gVirtualX->GetWindowSize(parent->GetId(), x, y, w, h);
63 gVirtualX->TranslateCoordinates(parent->GetId(),
64 gClient->GetDefaultRoot()->GetId(),
65 0, 0, x, y, childdum);
68 /**************************************************************************/
70 RGBrowser::RGBrowser(const TGWindow *p, UInt_t w, UInt_t h)
71 : TGCompositeFrame(p, w, h)
73 fMainFrame = new TGCompositeFrame(this, 100, 10, kHorizontalFrame | kRaisedFrame);
74 fMainFrame->SetCleanup(kDeepCleanup);
75 fV1 = new TGVerticalFrame(fMainFrame, 250, 10, kSunkenFrame | kFixedWidth);
76 fV2 = new TGVerticalFrame(fMainFrame, 50, 10, kSunkenFrame);
79 lo = new TGLayoutHints(kLHintsLeft | kLHintsExpandY,2,0,2,2);
80 fMainFrame->AddFrame(fV1, lo);
82 TGVSplitter *splitter = new TGVSplitter(fMainFrame);
83 splitter->SetFrame(fV1, kTRUE);
84 fMainFrame->AddFrame(splitter,
85 new TGLayoutHints(kLHintsLeft | kLHintsExpandY, 1,1,2,2));
87 lo = new TGLayoutHints(kLHintsRight | kLHintsExpandX | kLHintsExpandY,0,2,2,4);
88 fMainFrame->AddFrame(fV2, lo);
91 fSelectionFrame = new TGCompositeFrame(fV1, 250, 10, kVerticalFrame);
92 fTreeView = new TGCanvas(fSelectionFrame, 250, 10, kSunkenFrame | kDoubleBorder);
93 fListTree = new TGListTree(fTreeView->GetViewPort(), 250, 10, kHorizontalFrame);
94 fListTree->SetCanvas(fTreeView);
95 fListTree->Associate(this);
96 fListTree->SetColorMode(TGListTree::EColorMarkupMode(TGListTree::kColorUnderline | TGListTree::kColorBox));
97 fTreeView->SetContainer(fListTree);
99 lo= new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX | kLHintsExpandY,
101 fSelectionFrame->AddFrame(fTreeView, lo);
103 lo = new TGLayoutHints(kLHintsTop | kLHintsExpandX | kLHintsExpandY);
104 fV1->AddFrame(fSelectionFrame, lo);
106 // Classic look vars:
112 lo = new TGLayoutHints(kLHintsExpandX | kLHintsExpandY);
113 AddFrame(fMainFrame, lo);
116 SetWindowName("Reve List Browser");
118 //Resize(GetDefaultSize()); // this is used here to init layout algoritme
124 fCtxMenu = new TContextMenu("Pepe", "Moroder");
126 //-- CINT export now declared in RenderElement with *MENU*
127 // SetupCintExport(PointSet::Class());
128 // SetupCintExport(Track::Class());
129 // SetupCintExport(TrackList::Class());
131 fListTree->Connect("Clicked(TGListTreeItem*, Int_t, Int_t, Int_t)", "Reve::RGBrowser",
132 this, "ItemClicked(TGListTreeItem*, Int_t, Int_t, Int_t)");
133 fListTree->Connect("DoubleClicked(TGListTreeItem*, Int_t)", "Reve::RGBrowser",
134 this, "DbClickListItem(TGListTreeItem*,Int_t )");
135 //fListTree->Connect("Clicked(TGListTreeItem*, Int_t)", "Reve::RGBrowser",
136 // this, "DisplayChildren(TGListTreeItem*, Int_t)");
138 //---------------------------------------------
139 // WARNING ... this Connect goes to *gReve*!
140 fListTree->Connect("Checked(TObject*,Bool_t)", "Reve::RGTopFrame",
141 gReve, "RenderElementChecked(TObject*, Bool_t)");
144 /**************************************************************************/
146 void RGBrowser::SetupClassicLook()
148 fCanvasWindow = new TGCanvas(fV2, 25, 250);
149 fDisplayFrame = new TGCompositeFrame(fCanvasWindow->GetViewPort(), 0, 0,kVerticalFrame, TGFrame::GetWhitePixel() );
150 fCanvasWindow->SetContainer(fDisplayFrame);
151 fDisplayFrame->SetCleanup(kDeepCleanup);
153 fV2->AddFrame(fCanvasWindow, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 0, 0, 2, 2));
154 fV2->MapSubwindows();
159 void RGBrowser::SetupEditorLook(RGEditor* editor)
161 editor->UnmapWindow();
162 fV2->AddFrame(editor, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 0, 0, 2, 2));
164 CalculateReparentXY(fV2, x, y);
165 editor->ReparentWindow(fV2, x, y);
167 fV2->MapSubwindows();
170 void RGBrowser::SetupGLViewerLook(RGEditor* editor, TVirtualPad* glpad)
174 TGLSAViewer* v = new TGLSAViewer(fV2, glpad);
175 v->GetFrame()->SetMinWidth(200);
176 lo = new TGLayoutHints(kLHintsLeft | kLHintsExpandX | kLHintsExpandY);
177 fV2->AddFrame(v->GetFrame(), lo);
178 glpad->SetViewer3D(v);
180 fSelectionFrame->Resize(fSelectionFrame->GetWidth(), fSelectionFrame->GetHeight()/2);
182 TGHSplitter *splitter = new TGHSplitter(fV1);
183 lo = new TGLayoutHints(kLHintsTop | kLHintsExpandX, 4, 2, 2, 0);
184 fSelectionFrame->AddFrame(splitter, lo);
186 editor->UnmapWindow();
187 editor->ChangeOptions(editor->GetOptions() | kFixedHeight);
188 lo = new TGLayoutHints(kLHintsTop | kLHintsExpandX, 0,2,2,2);
189 fV1->AddFrame(editor, lo);
191 CalculateReparentXY(fV1, x, y);
192 editor->ReparentWindow(fV1, x, y);
194 splitter->SetFrame(editor, kFALSE);
196 fV1->MapSubwindows();
197 v->GetFrame()->MapWindow();
201 /**************************************************************************/
202 /**************************************************************************/
204 void RGBrowser::RedrawListTree()
206 gClient->NeedRedraw(fListTree);
209 /**************************************************************************/
211 void RGBrowser::ItemClicked(TGListTreeItem *item, Int_t btn, Int_t x, Int_t y)
213 //printf("ItemClicked item %s List %d btn=%d, x=%d, y=%d\n",
214 // item->GetText(),fDisplayFrame->GetList()->GetEntries(), btn, x, y);
216 TObject* obj = (TObject*)item->GetUserData();
220 fCtxMenu->Popup(x, y, obj);
226 RenderElement* re = dynamic_cast<RenderElement*>(obj);
227 gReve->EditRenderElement(re);
230 // This only available in classic look.
231 // Still working but slowly drifting towards obscurity (4.2006).
232 DisplayChildren(item, btn);
235 void RGBrowser::DbClickListItem(TGListTreeItem* item, Int_t btn)
237 static const Exc_t eH("RGBrowser::DbClickListItem ");
239 printf("dbclick item %s\n", item->GetText());
240 TObject* obj = (TObject*)item->GetUserData();
243 // ListTreeHighlight(item);
246 RenderElementListBase* rel = dynamic_cast<RenderElementListBase*>(obj);
248 Int_t ni = rel->ExpandIntoListTree(fListTree, item);
249 printf("%s expanded by %d\n", eH.Data(), ni);
254 if(obj->IsA()->InheritsFrom("TGeoNode")){
255 TGeoNode* n = (TGeoNode*) obj->IsA()->DynamicCast( TGeoNode::Class(), obj );
257 if(item->GetFirstChild() == 0 && n->GetNdaughters()){
258 UpdateListItems(item, btn);
262 DisplayChildren(item,0);
265 /**************************************************************************/
267 void RGBrowser::ExportToCINT(Text_t* var_name, TObject* obj)
269 const char* cname = obj->IsA()->GetName();
270 gROOT->ProcessLine(Form("%s* %s = (%s*) %p;", cname, var_name, cname, obj));
273 void RGBrowser::DisplayChildren(TGListTreeItem *item, Int_t btn)
275 // Only classic mode provides direct children editing.
276 if(fDisplayFrame == 0)
279 fDisplayFrame->DestroySubwindows();
280 fDisplayFrame->Cleanup();
281 printf("DisplayChildren item %s List %d btn=%d\n", item->GetText(),fDisplayFrame->GetList()->GetEntries(), btn);
283 if(item->GetFirstChild() == 0) return;
290 TGListTreeItem *child = item->GetFirstChild();
292 child = child->GetNextSibling();
297 fDisplayFrame->Resize(fw, fh);
298 TGXYLayout* xyl = new TGXYLayout(fDisplayFrame);
299 fDisplayFrame->SetLayoutManager(xyl);
306 child = item->GetFirstChild();
311 TGTextButton* b1 = new TGTextButton( fDisplayFrame, Form("%s",child->GetText()));
313 b1->SetTextJustify(kTextLeft | kTextCenterY);
314 lh = new TGXYLayoutHints(x, y, wW, wH,0); lh->SetPadLeft(2); lh->SetPadRight(2);
315 fDisplayFrame->AddFrame(b1,lh);
318 TGCheckButton* b2 = new TGCheckButton(fDisplayFrame, "Draw");
320 b2->SetTextJustify(kTextLeft | kTextCenterY);
321 lh = new TGXYLayoutHints(x, y, wW, wH,0); lh->SetPadLeft(2); lh->SetPadRight(2);
322 fDisplayFrame->AddFrame(b2, lh);
325 TObject* obj = reinterpret_cast<TObject*>(child->GetUserData());
329 Track* track = dynamic_cast<Track*>(obj); // (Track*) obj->IsA()->DynamicCast(Track::Class(), obj );
330 PointSet* hcont = dynamic_cast<PointSet*>(obj);
331 TrackList* tcont = dynamic_cast<TrackList*>(obj);
332 TGeoNode* gnode = dynamic_cast<TGeoNode*>(obj);
338 // printf("display children track \n");
339 b2->SetOn(track->GetRnrElement());
340 b2->Connect("Toggled(Bool_t)", "Reve::Track", track, "SetRnrElement(Bool_t)");
347 // connect to toggle signal
349 //printf("add label to %s %d\n", cont->GetName(), cont->GetNPoints());
350 TGLabel* b3 = new TGLabel(fDisplayFrame, Form("%d", hcont->GetN()));
351 b3->SetTextJustify(kTextLeft | kTextCenterY);
353 lh = new TGXYLayoutHints(x, y, wW, wH,0); lh->SetPadLeft(2); lh->SetPadRight(2);
354 fDisplayFrame->AddFrame(b3, lh);
358 TGColorSelect* b4 = new TGColorSelect(fDisplayFrame, TColor::Number2Pixel(hcont->GetMainColor()));
360 lh = new TGXYLayoutHints(x, y, wW, wH,0); lh->SetPadLeft(2); lh->SetPadRight(2);
361 fDisplayFrame->AddFrame(b4,lh);
362 b4->Connect("ColorSelected(Pixel_t)",
363 "Reve::PointSet", hcont, "SetMainColor(Pixel_t)");
367 ReveValuator* ne = new ReveValuator(fDisplayFrame, hcont->GetMarkerStyle());
369 lh = new TGXYLayoutHints(x, y, wW, wH,0); lh->SetPadLeft(2); lh->SetPadRight(2);
370 ne->Connect("ValueSet(Long_t)", "Reve::RGBrowser", this, "SetMarkerStyle(Long_t)");
371 ne->SetUserData(hcont);
372 fDisplayFrame->AddFrame(ne,lh);
374 //connect to container
375 b2->SetUserData(hcont);
376 b2->SetOn(hcont->GetRnrElement());
377 b2->Connect("Toggled(Bool_t)", "Reve::PointSet", hcont, "SetRnrElement(Bool_t)");
385 //printf("add label to %s %d\n", cont->GetName(), cont->GetNPoints());
386 TGLabel* b3 = new TGLabel(fDisplayFrame, Form("%d", tcont->GetNTracks()));
387 b3->SetTextJustify(kTextLeft | kTextCenterY);
389 lh = new TGXYLayoutHints(x, y, wW, wH,0); lh->SetPadLeft(2); lh->SetPadRight(2);
390 fDisplayFrame->AddFrame(b3, lh);
394 TGColorSelect* b4 = new TGColorSelect(fDisplayFrame, TColor::Number2Pixel(tcont->GetMainColor()));
396 lh = new TGXYLayoutHints(x, y, wW, wH,0); lh->SetPadLeft(2); lh->SetPadRight(2);
397 fDisplayFrame->AddFrame(b4,lh);
398 b4->Connect("ColorSelected(Pixel_t)",
399 "Reve::TrackList", tcont, "SetMainColor(Pixel_t)");
402 ReveValuator* ne1 = new ReveValuator(fDisplayFrame, tcont->GetRnrStyle()->fMaxR);
403 ne1->SetUserData(tcont);
404 ne1->Connect("ValueSet(Long_t)", "Reve::RGBrowser", this, "SetMaxR(Long_t)");
405 // ne1->SetToolTipText("Maximum radius [cm]");
407 lh = new TGXYLayoutHints(x, y, wW, wH,0); lh->SetPadLeft(2); lh->SetPadRight(2);
408 fDisplayFrame->AddFrame(ne1,lh);
412 ReveValuator* ne2 = new ReveValuator(fDisplayFrame, tcont->GetRnrStyle()->fMaxZ);
413 ne2->SetUserData(tcont);
414 ne2->Connect("ValueSet(Long_t)", "Reve::RGBrowser", this, "SetMaxZ(Long_t)");
415 // ne2->SetToolTipText("Maximum z [cm]");
417 lh = new TGXYLayoutHints(x, y, wW, wH,0); lh->SetPadLeft(2); lh->SetPadRight(2);
418 fDisplayFrame->AddFrame(ne2,lh);
422 ReveValuator* ne3 = new ReveValuator(fDisplayFrame, tcont->GetRnrStyle()->fMaxOrbs);
423 ne3->SetUserData(tcont);
424 ne3->Connect("ValueSet(Long_t)", "Reve::RGBrowser", this, "SetMaxOrbs(Long_t)");
425 // ne3->SetToolTipText("Maximum number of orbits");
427 lh = new TGXYLayoutHints(x, y, wW, wH,0); lh->SetPadLeft(2); lh->SetPadRight(2);
428 fDisplayFrame->AddFrame(ne3,lh);
432 TGCheckButton* dau = new TGCheckButton(fDisplayFrame, "Daughters");
433 dau->SetOn(tcont->GetRnrStyle()->fFitDaughters);
434 dau->SetUserData(tcont);
435 dau->Connect("Toggled(Bool_t)", "Reve::TrackList", tcont, "SetFitDaughters(Bool_t)");
437 lh = new TGXYLayoutHints(x, y, wW, wH,0); lh->SetPadLeft(2); lh->SetPadRight(2);
438 fDisplayFrame->AddFrame(dau,lh);
442 TGCheckButton* dec = new TGCheckButton(fDisplayFrame, "Decay");
443 dec->SetOn(tcont->GetRnrStyle()->fFitDaughters);
444 dec->SetUserData(tcont);
445 dec->Connect("Toggled(Bool_t)", "Reve::TrackList", tcont, "SetFitDecay(Bool_t)");
447 lh = new TGXYLayoutHints(x, y, wW, wH,0); lh->SetPadLeft(2); lh->SetPadRight(2);
448 fDisplayFrame->AddFrame(dec,lh);
450 //connect to container
451 b2->SetUserData(tcont);
452 //b2->SetOn(tcont->GetRnrTracks());
453 //b2->Connect("Toggled(Bool_t)", "Reve::TrackList", tcont, "SetRnrTracks(Bool_t)");
454 b2->SetOn(tcont->GetRnrElement());
455 b2->Connect("Toggled(Bool_t)", "Reve::TrackList", tcont, "SetRnrElement(Bool_t)");
462 TGeoVolume* vol = gnode->GetVolume();
463 b2->SetOn(gnode->IsVisible());
464 b2->Connect("Toggled(Bool_t)", "Reve::RGBrowser", this,"NodeVis(Bool_t)");
465 b2->SetUserData(gnode);
468 TGCheckButton* b3 = new TGCheckButton(fDisplayFrame, "VisibleDaughters");
469 b3->SetTextJustify(kTextLeft | kTextCenterY);
471 lh = new TGXYLayoutHints(x, y, wW, wH,0); lh->SetPadLeft(2); lh->SetPadRight(2);
472 fDisplayFrame->AddFrame(b3,lh);
473 b3->SetOn(vol->IsVisibleDaughters());
474 b3->Connect("Toggled(Bool_t)", "Reve::RGBrowser", this, "VolumeDaughterVis(Bool_t)");
475 b3->SetUserData(vol);
479 ReveColorSelect* b4 = new ReveColorSelect(fDisplayFrame, TColor::Number2Pixel(vol->GetLineColor()));
481 lh = new TGXYLayoutHints(x, y, wW, wH,0); lh->SetPadLeft(2); lh->SetPadRight(2);
482 fDisplayFrame->AddFrame(b4,lh);
483 b4->Connect("ColorSelected(Pixel_t)", "Reve::RGBrowser", this, "SetVolumeColor(UInt_t)");
484 b4->SetUserData(vol);
488 ReveValuator* ne = new ReveValuator(fDisplayFrame, vol->GetTransparency());
489 ne->Connect("ValueSet(Long_t)", "Reve::RGBrowser", this, "SetTransparency(Long_t)");
490 ne->SetUserData(vol);
493 lh = new TGXYLayoutHints(x, y, wW, wH,0); lh->SetPadLeft(2); lh->SetPadRight(2);
494 fDisplayFrame->AddFrame(ne,lh);
501 child = child->GetNextSibling();
503 fDisplayFrame->MapSubwindows();
504 fDisplayFrame->MapWindow();
508 /**************************************************************************/
510 /**************************************************************************/
512 void RGBrowser::SetTransparency(Long_t )
514 ReveValuator& rv = *(ReveValuator*)gTQSender;
515 // printf("VSet idx=%d, double value=%lf, part=%p\n", val, rv.GetNumber(), rv.GetUserData());
516 TGeoVolume* vol = (TGeoVolume*) rv.GetUserData();
518 // printf("set volume user data %d \n",val);
519 vol->SetTransparency(char(rv.GetNumber()));
524 TList* list = fDisplayFrame->GetList();
527 while ((fel = (TGFrameElement*)nextin())){
528 // printf("RGBrowser::SetTransparency %s in fDisplayFrame\n", fel->fFrame->GetName());
529 cw = dynamic_cast<ReveValuator*>(fel->fFrame);
531 TGeoVolume* v = dynamic_cast<TGeoVolume*>((TObject*)cw->GetUserData());
533 cw->SetNumber(v->GetTransparency());
540 /**************************************************************************/
542 void RGBrowser::SetVolumeColor(UInt_t pixel)
545 TColor::Pixel2RGB(pixel, r, g, b);
547 TGColorSelect* w = (TGColorSelect*) gTQSender;
548 TGeoVolume* vol = (TGeoVolume*) w->GetUserData();
549 Int_t col = TColor::GetColor(pixel);
550 vol->SetLineColor(col);
554 TList* list = fDisplayFrame->GetList();
556 while ((fel = (TGFrameElement*)nextin())){
557 // printf("%s in fDisplayFrame\n", fel->fFrame->GetName());
558 cw = dynamic_cast<ReveColorSelect*>(fel->fFrame);
560 TGeoVolume* cv = dynamic_cast<TGeoVolume*>((TObject*)cw->GetUserData());
562 // printf("TGColorSelect %d %d\n",pixel, cv->GetLineColor());
563 cw->UpdateColor(TColor::Number2Pixel(cv->GetLineColor()));
567 gClient->NeedRedraw(fDisplayFrame);
571 void RGBrowser::NodeVis(Bool_t vis)
573 TGCheckButton& rv = *(TGCheckButton*)gTQSender;
574 TGeoNode* node = (TGeoNode*) rv.GetUserData();
576 Reve::PadHolder pHolder(false, gReve->GetCC());
577 node->SetVisibility(vis);
582 void RGBrowser::VolumeDaughterVis(Bool_t vis)
584 TGCheckButton& rv = *(TGCheckButton*)gTQSender;
585 // printf("VSet idx=%d, double value=%lf, part=%p\n", val, rv.GetNumber(), rv.GetUserData());
586 TGeoVolume* vol = (TGeoVolume*) rv.GetUserData();
588 Reve::PadHolder pHolder(false, gReve->GetCC());
589 vol->VisibleDaughters(vis);
594 /**************************************************************************/
595 /**************************************************************************/
597 void RGBrowser::SetMaxR(Long_t )
599 ReveValuator* rv = (ReveValuator*) gTQSender;
600 TrackList* tc = (TrackList*) rv->GetUserData();
602 tc->SetMaxR(rv->GetNumber());
606 void RGBrowser::SetMaxZ(Long_t )
608 ReveValuator* rv = (ReveValuator*) gTQSender;
609 TrackList* tc = (TrackList*) rv->GetUserData();
611 tc->SetMaxZ(rv->GetNumber());
615 void RGBrowser::SetMaxOrbs(Long_t )
617 ReveValuator* rv = (ReveValuator*) gTQSender;
618 TrackList* tc = (TrackList*) rv->GetUserData();
620 tc->SetMaxOrbs(rv->GetNumber());
624 /**************************************************************************/
625 /**************************************************************************/
627 void RGBrowser::SetMarkerStyle(Long_t )
629 ReveValuator* rv = (ReveValuator*) gTQSender;
630 PointSet* pc = (PointSet*) rv->GetUserData();
632 Reve::PadHolder pHolder(false, gReve->GetCC());
633 pc->SetMarkerStyle(short(rv->GetNumber()));
638 /**************************************************************************/
639 /**************************************************************************/
641 void RGBrowser::UpdateListItems(TGListTreeItem* item, Int_t )
643 if (item->GetUserData()) {
644 // ListTreeHighlight(item);
645 TObject* obj = (TObject *) item->GetUserData();
648 if(obj->IsA()->InheritsFrom("TGeoNode")){
650 fListTree->DeleteChildren(item);
651 TGeoNode* n = (TGeoNode*) obj->IsA()->DynamicCast( TGeoNode::Class(), obj );
652 //printf("adding items\n");
653 if (n->GetNdaughters()) {
654 for (Int_t i=0; i< n->GetNdaughters(); i++) {
656 title.Form("%d : %s[%d]", i,
657 n->GetDaughter(i)->GetVolume()->GetName(),
658 n->GetDaughter(i)->GetNdaughters());
660 TGListTreeItem* child = fListTree->AddItem( item, title.Data());
661 child->SetUserData( n->GetDaughter(i));
669 /**************************************************************************/
670 /**************************************************************************/
671 /**************************************************************************/
672 /**************************************************************************/
674 /**************************************************************************/
676 /**************************************************************************/
678 ReveValuator::~ReveValuator()