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 RenderElement* re = (RenderElement*)item->GetUserData();
218 TObject* obj = re->GetObject();
220 // A pathetic hack to get at least a bit of color coordination
221 // for RenderElementObjPtr.
222 if(item->GetColor() != re->GetMainColor()) {
223 item->SetColor(re->GetMainColor());
224 fListTree->GetClient()->NeedRedraw(fListTree);
229 fCtxMenu->Popup(x, y, obj);
234 gReve->EditRenderElement(re);
236 // This only available in classic look.
237 // Still working but slowly drifting towards obscurity (4.2006).
238 DisplayChildren(item, btn);
241 void RGBrowser::DbClickListItem(TGListTreeItem* item, Int_t btn)
243 static const Exc_t eH("RGBrowser::DbClickListItem ");
245 printf("dbclick item %s\n", item->GetText());
246 RenderElement* re = (RenderElement*)item->GetUserData();
248 TObject* obj = re->GetObject();
251 // ListTreeHighlight(item);
254 RenderElementListBase* rel = dynamic_cast<RenderElementListBase*>(re);
256 Int_t ni = rel->ExpandIntoListTree(fListTree, item);
257 printf("%s expanded by %d\n", eH.Data(), ni);
262 if(obj->IsA()->InheritsFrom("TGeoNode")){
263 TGeoNode* n = (TGeoNode*) obj->IsA()->DynamicCast( TGeoNode::Class(), obj );
265 if(item->GetFirstChild() == 0 && n->GetNdaughters()){
266 UpdateListItems(item, btn);
270 DisplayChildren(item,0);
273 /**************************************************************************/
275 void RGBrowser::ExportToCINT(Text_t* var_name, TObject* obj)
277 const char* cname = obj->IsA()->GetName();
278 gROOT->ProcessLine(Form("%s* %s = (%s*) %p;", cname, var_name, cname, obj));
281 void RGBrowser::DisplayChildren(TGListTreeItem *item, Int_t btn)
283 // Only classic mode provides direct children editing.
284 if(fDisplayFrame == 0)
287 fDisplayFrame->DestroySubwindows();
288 fDisplayFrame->Cleanup();
289 printf("DisplayChildren item %s List %d btn=%d\n", item->GetText(),fDisplayFrame->GetList()->GetEntries(), btn);
291 if(item->GetFirstChild() == 0) return;
298 TGListTreeItem *child = item->GetFirstChild();
300 child = child->GetNextSibling();
305 fDisplayFrame->Resize(fw, fh);
306 TGXYLayout* xyl = new TGXYLayout(fDisplayFrame);
307 fDisplayFrame->SetLayoutManager(xyl);
314 child = item->GetFirstChild();
319 TGTextButton* b1 = new TGTextButton( fDisplayFrame, Form("%s",child->GetText()));
321 b1->SetTextJustify(kTextLeft | kTextCenterY);
322 lh = new TGXYLayoutHints(x, y, wW, wH,0); lh->SetPadLeft(2); lh->SetPadRight(2);
323 fDisplayFrame->AddFrame(b1,lh);
326 TGCheckButton* b2 = new TGCheckButton(fDisplayFrame, "Draw");
328 b2->SetTextJustify(kTextLeft | kTextCenterY);
329 lh = new TGXYLayoutHints(x, y, wW, wH,0); lh->SetPadLeft(2); lh->SetPadRight(2);
330 fDisplayFrame->AddFrame(b2, lh);
333 RenderElement* re = (RenderElement*)child->GetUserData();
334 TObject* obj = re->GetObject();
338 Track* track = dynamic_cast<Track*>(obj); // (Track*) obj->IsA()->DynamicCast(Track::Class(), obj );
339 PointSet* hcont = dynamic_cast<PointSet*>(obj);
340 TrackList* tcont = dynamic_cast<TrackList*>(obj);
341 TGeoNode* gnode = dynamic_cast<TGeoNode*>(obj);
347 // printf("display children track \n");
348 b2->SetOn(track->GetRnrElement());
349 b2->Connect("Toggled(Bool_t)", "Reve::Track", track, "SetRnrElement(Bool_t)");
356 // connect to toggle signal
358 //printf("add label to %s %d\n", cont->GetName(), cont->GetNPoints());
359 TGLabel* b3 = new TGLabel(fDisplayFrame, Form("%d", hcont->GetN()));
360 b3->SetTextJustify(kTextLeft | kTextCenterY);
362 lh = new TGXYLayoutHints(x, y, wW, wH,0); lh->SetPadLeft(2); lh->SetPadRight(2);
363 fDisplayFrame->AddFrame(b3, lh);
367 TGColorSelect* b4 = new TGColorSelect(fDisplayFrame, TColor::Number2Pixel(hcont->GetMainColor()));
369 lh = new TGXYLayoutHints(x, y, wW, wH,0); lh->SetPadLeft(2); lh->SetPadRight(2);
370 fDisplayFrame->AddFrame(b4,lh);
371 b4->Connect("ColorSelected(Pixel_t)",
372 "Reve::PointSet", hcont, "SetMainColor(Pixel_t)");
376 ReveValuator* ne = new ReveValuator(fDisplayFrame, hcont->GetMarkerStyle());
378 lh = new TGXYLayoutHints(x, y, wW, wH,0); lh->SetPadLeft(2); lh->SetPadRight(2);
379 ne->Connect("ValueSet(Long_t)", "Reve::RGBrowser", this, "SetMarkerStyle(Long_t)");
380 ne->SetUserData(hcont);
381 fDisplayFrame->AddFrame(ne,lh);
383 //connect to container
384 b2->SetUserData(hcont);
385 b2->SetOn(hcont->GetRnrElement());
386 b2->Connect("Toggled(Bool_t)", "Reve::PointSet", hcont, "SetRnrElement(Bool_t)");
394 //printf("add label to %s %d\n", cont->GetName(), cont->GetNPoints());
395 TGLabel* b3 = new TGLabel(fDisplayFrame, Form("%d", tcont->GetNTracks()));
396 b3->SetTextJustify(kTextLeft | kTextCenterY);
398 lh = new TGXYLayoutHints(x, y, wW, wH,0); lh->SetPadLeft(2); lh->SetPadRight(2);
399 fDisplayFrame->AddFrame(b3, lh);
403 TGColorSelect* b4 = new TGColorSelect(fDisplayFrame, TColor::Number2Pixel(tcont->GetMainColor()));
405 lh = new TGXYLayoutHints(x, y, wW, wH,0); lh->SetPadLeft(2); lh->SetPadRight(2);
406 fDisplayFrame->AddFrame(b4,lh);
407 b4->Connect("ColorSelected(Pixel_t)",
408 "Reve::TrackList", tcont, "SetMainColor(Pixel_t)");
411 ReveValuator* ne1 = new ReveValuator(fDisplayFrame, tcont->GetRnrStyle()->fMaxR);
412 ne1->SetUserData(tcont);
413 ne1->Connect("ValueSet(Long_t)", "Reve::RGBrowser", this, "SetMaxR(Long_t)");
414 // ne1->SetToolTipText("Maximum radius [cm]");
416 lh = new TGXYLayoutHints(x, y, wW, wH,0); lh->SetPadLeft(2); lh->SetPadRight(2);
417 fDisplayFrame->AddFrame(ne1,lh);
421 ReveValuator* ne2 = new ReveValuator(fDisplayFrame, tcont->GetRnrStyle()->fMaxZ);
422 ne2->SetUserData(tcont);
423 ne2->Connect("ValueSet(Long_t)", "Reve::RGBrowser", this, "SetMaxZ(Long_t)");
424 // ne2->SetToolTipText("Maximum z [cm]");
426 lh = new TGXYLayoutHints(x, y, wW, wH,0); lh->SetPadLeft(2); lh->SetPadRight(2);
427 fDisplayFrame->AddFrame(ne2,lh);
431 ReveValuator* ne3 = new ReveValuator(fDisplayFrame, tcont->GetRnrStyle()->fMaxOrbs);
432 ne3->SetUserData(tcont);
433 ne3->Connect("ValueSet(Long_t)", "Reve::RGBrowser", this, "SetMaxOrbs(Long_t)");
434 // ne3->SetToolTipText("Maximum number of orbits");
436 lh = new TGXYLayoutHints(x, y, wW, wH,0); lh->SetPadLeft(2); lh->SetPadRight(2);
437 fDisplayFrame->AddFrame(ne3,lh);
441 TGCheckButton* dau = new TGCheckButton(fDisplayFrame, "Daughters");
442 dau->SetOn(tcont->GetRnrStyle()->fFitDaughters);
443 dau->SetUserData(tcont);
444 dau->Connect("Toggled(Bool_t)", "Reve::TrackList", tcont, "SetFitDaughters(Bool_t)");
446 lh = new TGXYLayoutHints(x, y, wW, wH,0); lh->SetPadLeft(2); lh->SetPadRight(2);
447 fDisplayFrame->AddFrame(dau,lh);
451 TGCheckButton* dec = new TGCheckButton(fDisplayFrame, "Decay");
452 dec->SetOn(tcont->GetRnrStyle()->fFitDaughters);
453 dec->SetUserData(tcont);
454 dec->Connect("Toggled(Bool_t)", "Reve::TrackList", tcont, "SetFitDecay(Bool_t)");
456 lh = new TGXYLayoutHints(x, y, wW, wH,0); lh->SetPadLeft(2); lh->SetPadRight(2);
457 fDisplayFrame->AddFrame(dec,lh);
459 //connect to container
460 b2->SetUserData(tcont);
461 //b2->SetOn(tcont->GetRnrTracks());
462 //b2->Connect("Toggled(Bool_t)", "Reve::TrackList", tcont, "SetRnrTracks(Bool_t)");
463 b2->SetOn(tcont->GetRnrElement());
464 b2->Connect("Toggled(Bool_t)", "Reve::TrackList", tcont, "SetRnrElement(Bool_t)");
471 TGeoVolume* vol = gnode->GetVolume();
472 b2->SetOn(gnode->IsVisible());
473 b2->Connect("Toggled(Bool_t)", "Reve::RGBrowser", this,"NodeVis(Bool_t)");
474 b2->SetUserData(gnode);
477 TGCheckButton* b3 = new TGCheckButton(fDisplayFrame, "VisibleDaughters");
478 b3->SetTextJustify(kTextLeft | kTextCenterY);
480 lh = new TGXYLayoutHints(x, y, wW, wH,0); lh->SetPadLeft(2); lh->SetPadRight(2);
481 fDisplayFrame->AddFrame(b3,lh);
482 b3->SetOn(vol->IsVisibleDaughters());
483 b3->Connect("Toggled(Bool_t)", "Reve::RGBrowser", this, "VolumeDaughterVis(Bool_t)");
484 b3->SetUserData(vol);
488 ReveColorSelect* b4 = new ReveColorSelect(fDisplayFrame, TColor::Number2Pixel(vol->GetLineColor()));
490 lh = new TGXYLayoutHints(x, y, wW, wH,0); lh->SetPadLeft(2); lh->SetPadRight(2);
491 fDisplayFrame->AddFrame(b4,lh);
492 b4->Connect("ColorSelected(Pixel_t)", "Reve::RGBrowser", this, "SetVolumeColor(UInt_t)");
493 b4->SetUserData(vol);
497 ReveValuator* ne = new ReveValuator(fDisplayFrame, vol->GetTransparency());
498 ne->Connect("ValueSet(Long_t)", "Reve::RGBrowser", this, "SetTransparency(Long_t)");
499 ne->SetUserData(vol);
502 lh = new TGXYLayoutHints(x, y, wW, wH,0); lh->SetPadLeft(2); lh->SetPadRight(2);
503 fDisplayFrame->AddFrame(ne,lh);
510 child = child->GetNextSibling();
512 fDisplayFrame->MapSubwindows();
513 fDisplayFrame->MapWindow();
517 /**************************************************************************/
519 /**************************************************************************/
521 void RGBrowser::SetTransparency(Long_t )
523 ReveValuator& rv = *(ReveValuator*)gTQSender;
524 // printf("VSet idx=%d, double value=%lf, part=%p\n", val, rv.GetNumber(), rv.GetUserData());
525 TGeoVolume* vol = (TGeoVolume*) rv.GetUserData();
527 // printf("set volume user data %d \n",val);
528 vol->SetTransparency(char(rv.GetNumber()));
532 TList* list = fDisplayFrame->GetList();
535 while ((fel = (TGFrameElement*)nextin())){
536 // printf("RGBrowser::SetTransparency %s in fDisplayFrame\n", fel->fFrame->GetName());
537 cw = dynamic_cast<ReveValuator*>(fel->fFrame);
540 TGeoVolume* v = dynamic_cast<TGeoVolume*>((RenderElement*)cw->GetUserData());
542 cw->SetNumber(v->GetTransparency());
549 /**************************************************************************/
551 void RGBrowser::SetVolumeColor(UInt_t pixel)
554 TColor::Pixel2RGB(pixel, r, g, b);
556 TGColorSelect* w = (TGColorSelect*) gTQSender;
557 TGeoVolume* vol = (TGeoVolume*) w->GetUserData();
558 Int_t col = TColor::GetColor(pixel);
559 vol->SetLineColor(col);
563 TList* list = fDisplayFrame->GetList();
565 while ((fel = (TGFrameElement*)nextin())){
566 // printf("%s in fDisplayFrame\n", fel->fFrame->GetName());
567 cw = dynamic_cast<ReveColorSelect*>(fel->fFrame);
569 TGeoVolume* cv = dynamic_cast<TGeoVolume*>((TObject*)cw->GetUserData());
571 // printf("TGColorSelect %d %d\n",pixel, cv->GetLineColor());
572 cw->UpdateColor(TColor::Number2Pixel(cv->GetLineColor()));
576 gClient->NeedRedraw(fDisplayFrame);
580 void RGBrowser::NodeVis(Bool_t vis)
582 TGCheckButton& rv = *(TGCheckButton*)gTQSender;
583 TGeoNode* node = (TGeoNode*) rv.GetUserData();
585 Reve::PadHolder pHolder(false, gReve->GetCC());
586 node->SetVisibility(vis);
591 void RGBrowser::VolumeDaughterVis(Bool_t vis)
593 TGCheckButton& rv = *(TGCheckButton*)gTQSender;
594 // printf("VSet idx=%d, double value=%lf, part=%p\n", val, rv.GetNumber(), rv.GetUserData());
595 TGeoVolume* vol = (TGeoVolume*) rv.GetUserData();
597 Reve::PadHolder pHolder(false, gReve->GetCC());
598 vol->VisibleDaughters(vis);
603 /**************************************************************************/
604 /**************************************************************************/
606 void RGBrowser::SetMaxR(Long_t )
608 ReveValuator* rv = (ReveValuator*) gTQSender;
609 TrackList* tc = (TrackList*) rv->GetUserData();
611 tc->SetMaxR(rv->GetNumber());
615 void RGBrowser::SetMaxZ(Long_t )
617 ReveValuator* rv = (ReveValuator*) gTQSender;
618 TrackList* tc = (TrackList*) rv->GetUserData();
620 tc->SetMaxZ(rv->GetNumber());
624 void RGBrowser::SetMaxOrbs(Long_t )
626 ReveValuator* rv = (ReveValuator*) gTQSender;
627 TrackList* tc = (TrackList*) rv->GetUserData();
629 tc->SetMaxOrbs(rv->GetNumber());
633 /**************************************************************************/
634 /**************************************************************************/
636 void RGBrowser::SetMarkerStyle(Long_t )
638 ReveValuator* rv = (ReveValuator*) gTQSender;
639 PointSet* pc = (PointSet*) rv->GetUserData();
641 Reve::PadHolder pHolder(false, gReve->GetCC());
642 pc->SetMarkerStyle(short(rv->GetNumber()));
647 /**************************************************************************/
648 /**************************************************************************/
650 void RGBrowser::UpdateListItems(TGListTreeItem* item, Int_t )
652 if (item->GetUserData()) {
653 // ListTreeHighlight(item);
654 RenderElement* re = (RenderElement*)item->GetUserData();
655 TObject* obj = re->GetObject();
658 if(obj->IsA()->InheritsFrom("TGeoNode")){
660 fListTree->DeleteChildren(item);
661 TGeoNode* n = (TGeoNode*) obj->IsA()->DynamicCast( TGeoNode::Class(), obj );
662 //printf("adding items\n");
663 if (n->GetNdaughters()) {
664 for (Int_t i=0; i< n->GetNdaughters(); i++) {
666 title.Form("%d : %s[%d]", i,
667 n->GetDaughter(i)->GetVolume()->GetName(),
668 n->GetDaughter(i)->GetNdaughters());
670 TGListTreeItem* child = fListTree->AddItem( item, title.Data());
671 child->SetUserData( n->GetDaughter(i));
679 /**************************************************************************/
680 /**************************************************************************/
681 /**************************************************************************/
682 /**************************************************************************/
684 /**************************************************************************/
686 /**************************************************************************/
688 ReveValuator::~ReveValuator()