forked from root-project/root
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TEveViewer.cxx
671 lines (540 loc) · 19.4 KB
/
TEveViewer.cxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
// @(#)root/eve:$Id$
// Authors: Matevz Tadel & Alja Mrak-Tadel: 2006, 2007
/*************************************************************************
* Copyright (C) 1995-2007, Rene Brun and Fons Rademakers. *
* All rights reserved. *
* *
* For the licensing terms see $ROOTSYS/LICENSE. *
* For the list of contributors see $ROOTSYS/README/CREDITS. *
*************************************************************************/
#include "TEveViewer.h"
#include "TEveScene.h"
#include "TEveSceneInfo.h"
#include "TEveManager.h"
#include "TEveSelection.h"
#include "TGLFormat.h"
#include "TGLSAViewer.h"
#include "TGLEmbeddedViewer.h"
#include "TGLScenePad.h"
#include "TGLEventHandler.h"
#include "TApplication.h"
#include "TEnv.h"
#include "TVirtualX.h"
/** \class TEveViewer
\ingroup TEve
Eve representation of TGLViewer.
The gl-viewer is owned by this class and is deleted in destructor.
The frame is not deleted, it is expected that the gl-viewer implementation
will delete that. TGLSAViewer and TGEmbeddedViewer both do so.
This could be an optional argument to SetGLViewer. A frame could be
passed as well.
When stand-alone viewer is requested, it will come up with menu-hiding
enabled by default. If you dislike this, add the following line to rootrc
file (or set corresponding gEnv entry in application initialization):
~~~ {.cpp}
Eve.Viewer.HideMenus: off
~~~
*/
ClassImp(TEveViewer);
Bool_t TEveViewer::fgInitInternal = kFALSE;
Bool_t TEveViewer::fgRecreateGlOnDockOps = kFALSE;
////////////////////////////////////////////////////////////////////////////////
/// Constructor.
///
/// The base-class TEveWindowFrame is constructed without a frame so
/// a default composite-frame is instantiated and stored in fGUIFrame.
/// Cleanup is set to no-cleanup as viewers need to be zapped with some
/// more care.
TEveViewer::TEveViewer(const char* n, const char* t) :
TEveWindowFrame(0, n, t),
fGLViewer (0),
fGLViewerFrame (0)
{
SetChildClass(TEveSceneInfo::Class());
fGUIFrame->SetCleanup(kNoCleanup); // the gl-viewer's frame deleted elsewhere.
if (!fgInitInternal)
{
InitInternal();
}
}
////////////////////////////////////////////////////////////////////////////////
/// Destructor.
TEveViewer::~TEveViewer()
{
fGLViewer->SetEventHandler(0);
fGLViewerFrame->UnmapWindow();
GetGUICompositeFrame()->RemoveFrame(fGLViewerFrame);
fGLViewerFrame->ReparentWindow(gClient->GetDefaultRoot());
TTimer::SingleShot(150, "TGLViewer", fGLViewer, "Delete()");
}
////////////////////////////////////////////////////////////////////////////////
/// Initialize static data-members according to running conditions.
void TEveViewer::InitInternal()
{
// Determine if display is running on a mac.
// This also works for ssh connection mac->linux.
fgRecreateGlOnDockOps = (gVirtualX->SupportsExtension("Apple-WM") == 1);
fgInitInternal = kTRUE;
}
////////////////////////////////////////////////////////////////////////////////
/// Virtual function called before a window is undocked.
/// On mac we have to force recreation of gl-context.
void TEveViewer::PreUndock()
{
TEveWindowFrame::PreUndock();
if (fgRecreateGlOnDockOps)
{
// Mac only: TGLWidget can be already deleted
// in case of recursive delete
if (fGLViewer->GetGLWidget())
{
fGLViewer->DestroyGLWidget();
}
}
}
////////////////////////////////////////////////////////////////////////////////
/// Virtual function called after a window is docked.
/// On mac we have to force recreation of gl-context.
void TEveViewer::PostDock()
{
if (fgRecreateGlOnDockOps) {
fGLViewer->CreateGLWidget();
}
TEveWindowFrame::PostDock();
}
////////////////////////////////////////////////////////////////////////////////
/// Return TEveViewer icon.
const TGPicture* TEveViewer::GetListTreeIcon(Bool_t)
{
return TEveElement::fgListTreeIcons[1];
}
////////////////////////////////////////////////////////////////////////////////
/// Set TGLViewer that is represented by this object.
/// The old gl-viewer is deleted.
void TEveViewer::SetGLViewer(TGLViewer* viewer, TGFrame* frame)
{
delete fGLViewer;
fGLViewer = viewer;
fGLViewerFrame = frame;
fGLViewer->SetSmartRefresh(kTRUE);
}
////////////////////////////////////////////////////////////////////////////////
/// Spawn new GLViewer and adopt it.
TGLSAViewer* TEveViewer::SpawnGLViewer(TGedEditor* ged, Bool_t stereo, Bool_t quad_buf)
{
static const TEveException kEH("TEveViewer::SpawnGLViewer ");
TGCompositeFrame* cf = GetGUICompositeFrame();
TGLFormat *form = 0;
if (stereo && quad_buf)
{
form = new TGLFormat;
form->SetStereo(kTRUE);
}
cf->SetEditable(kTRUE);
TGLSAViewer* v = 0;
try
{
v = new TGLSAViewer(cf, 0, ged, form);
}
catch (std::exception&)
{
Error("SpawnGLViewer", "Insufficient support from the graphics hardware. Aborting.");
gApplication->Terminate(1);
}
cf->SetEditable(kFALSE);
v->ToggleEditObject();
v->DisableCloseMenuEntries();
if (gEnv->GetValue("Eve.Viewer.HideMenus", 1) == 1)
{
v->EnableMenuBarHiding();
}
SetGLViewer(v, v->GetFrame());
if (stereo)
v->SetStereo(kTRUE, quad_buf);
if (fEveFrame == 0)
PreUndock();
return v;
}
////////////////////////////////////////////////////////////////////////////////
/// Spawn new GLViewer and adopt it.
TGLEmbeddedViewer* TEveViewer::SpawnGLEmbeddedViewer(TGedEditor* ged, Int_t border)
{
static const TEveException kEH("TEveViewer::SpawnGLEmbeddedViewer ");
TGCompositeFrame* cf = GetGUICompositeFrame();
TGLEmbeddedViewer* v = new TGLEmbeddedViewer(cf, 0, ged, border);
SetGLViewer(v, v->GetFrame());
cf->AddFrame(fGLViewerFrame, new TGLayoutHints(kLHintsNormal | kLHintsExpandX | kLHintsExpandY));
fGLViewerFrame->MapWindow();
if (fEveFrame == 0)
PreUndock();
return v;
}
////////////////////////////////////////////////////////////////////////////////
/// Redraw viewer immediately.
void TEveViewer::Redraw(Bool_t resetCameras)
{
if (resetCameras) fGLViewer->PostSceneBuildSetup(kTRUE);
fGLViewer->RequestDraw(TGLRnrCtx::kLODHigh);
}
////////////////////////////////////////////////////////////////////////////////
/// Switch stereo mode.
/// This only works TGLSAViewers and, of course, with stereo support
/// provided by the OpenGL driver.
void TEveViewer::SwitchStereo()
{
TGLSAViewer *v = dynamic_cast<TGLSAViewer*>(fGLViewer);
if (!v) {
Warning("SwitchStereo", "Only supported for TGLSAViewer.");
return;
}
v->DestroyGLWidget();
TGLFormat *f = v->GetFormat();
switch_stereo:
f->SetStereo(!f->IsStereo());
v->SetStereo(f->IsStereo());
try
{
v->CreateGLWidget();
}
catch (std::exception&)
{
Error("SwitchStereo", "Insufficient support from the graphics hardware. Reverting.");
goto switch_stereo;
}
}
////////////////////////////////////////////////////////////////////////////////
/// Add 'scene' to the list of scenes.
void TEveViewer::AddScene(TEveScene* scene)
{
static const TEveException eh("TEveViewer::AddScene ");
TGLSceneInfo* glsi = fGLViewer->AddScene(scene->GetGLScene());
if (glsi != 0) {
TEveSceneInfo* si = new TEveSceneInfo(this, scene, glsi);
AddElement(si);
} else {
throw(eh + "scene already in the viewer.");
}
}
////////////////////////////////////////////////////////////////////////////////
/// Remove element 'el' from the list of children and also remove
/// appropriate GLScene from GLViewer's list of scenes.
/// Virtual from TEveElement.
void TEveViewer::RemoveElementLocal(TEveElement* el)
{
fGLViewer->RemoveScene(((TEveSceneInfo*)el)->GetGLScene());
}
////////////////////////////////////////////////////////////////////////////////
/// Remove all children, forwarded to GLViewer.
/// Virtual from TEveElement.
void TEveViewer::RemoveElementsLocal()
{
fGLViewer->RemoveAllScenes();
}
////////////////////////////////////////////////////////////////////////////////
/// Object to be edited when this is selected, returns the TGLViewer.
/// Virtual from TEveElement.
TObject* TEveViewer::GetEditorObject(const TEveException& eh) const
{
if (!fGLViewer)
throw(eh + "fGLViewer not set.");
return fGLViewer;
}
////////////////////////////////////////////////////////////////////////////////
/// Receive a pasted object. TEveViewer only accepts objects of
/// class TEveScene.
/// Virtual from TEveElement.
Bool_t TEveViewer::HandleElementPaste(TEveElement* el)
{
static const TEveException eh("TEveViewer::HandleElementPaste ");
TEveScene* scene = dynamic_cast<TEveScene*>(el);
if (scene != 0) {
AddScene(scene);
return kTRUE;
} else {
Warning(eh.Data(), "class TEveViewer only accepts TEveScene paste argument.");
return kFALSE;
}
}
/** \class TEveViewerList
\ingroup TEve
List of Viewers providing common operations on TEveViewer collections.
*/
ClassImp(TEveViewerList);
////////////////////////////////////////////////////////////////////////////////
TEveViewerList::TEveViewerList(const char* n, const char* t) :
TEveElementList(n, t),
fShowTooltip (kTRUE),
fBrightness(0),
fUseLightColorSet(kFALSE)
{
// Constructor.
SetChildClass(TEveViewer::Class());
Connect();
}
////////////////////////////////////////////////////////////////////////////////
/// Destructor.
TEveViewerList::~TEveViewerList()
{
Disconnect();
}
////////////////////////////////////////////////////////////////////////////////
/// Call base-class implementation.
/// If compound is open and compound of the new element is not set,
/// the el's compound is set to this.
void TEveViewerList::AddElement(TEveElement* el)
{
TEveElementList::AddElement(el);
el->IncParentIgnoreCnt();
}
////////////////////////////////////////////////////////////////////////////////
/// Decompoundofy el, call base-class version.
void TEveViewerList::RemoveElementLocal(TEveElement* el)
{
el->DecParentIgnoreCnt();
TEveElementList::RemoveElementLocal(el);
}
////////////////////////////////////////////////////////////////////////////////
/// Decompoundofy children, call base-class version.
void TEveViewerList::RemoveElementsLocal()
{
for (List_i i=fChildren.begin(); i!=fChildren.end(); ++i)
{
(*i)->DecParentIgnoreCnt();
}
TEveElementList::RemoveElementsLocal();
}
////////////////////////////////////////////////////////////////////////////////
/// Connect to TGLViewer class-signals.
void TEveViewerList::Connect()
{
TQObject::Connect("TGLViewer", "MouseOver(TObject*,UInt_t)",
"TEveViewerList", this, "OnMouseOver(TObject*,UInt_t)");
TQObject::Connect("TGLViewer", "ReMouseOver(TObject*,UInt_t)",
"TEveViewerList", this, "OnReMouseOver(TObject*,UInt_t)");
TQObject::Connect("TGLViewer", "UnMouseOver(TObject*,UInt_t)",
"TEveViewerList", this, "OnUnMouseOver(TObject*,UInt_t)");
TQObject::Connect("TGLViewer", "Clicked(TObject*,UInt_t,UInt_t)",
"TEveViewerList", this, "OnClicked(TObject*,UInt_t,UInt_t)");
TQObject::Connect("TGLViewer", "ReClicked(TObject*,UInt_t,UInt_t)",
"TEveViewerList", this, "OnReClicked(TObject*,UInt_t,UInt_t)");
TQObject::Connect("TGLViewer", "UnClicked(TObject*,UInt_t,UInt_t)",
"TEveViewerList", this, "OnUnClicked(TObject*,UInt_t,UInt_t)");
}
////////////////////////////////////////////////////////////////////////////////
/// Disconnect from TGLViewer class-signals.
void TEveViewerList::Disconnect()
{
TQObject::Disconnect("TGLViewer", "MouseOver(TObject*,UInt_t)",
this, "OnMouseOver(TObject*,UInt_t)");
TQObject::Disconnect("TGLViewer", "ReMouseOver(TObject*,UInt_t)",
this, "OnReMouseOver(TObject*,UInt_t)");
TQObject::Disconnect("TGLViewer", "UnMouseOver(TObject*,UInt_t)",
this, "OnUnMouseOver(TObject*,UInt_t)");
TQObject::Disconnect("TGLViewer", "Clicked(TObject*,UInt_t,UInt_t)",
this, "OnClicked(TObject*,UInt_t,UInt_t)");
TQObject::Disconnect("TGLViewer", "ReClicked(TObject*,UInt_t,UInt_t)",
this, "OnReClicked(TObject*,UInt_t,UInt_t)");
TQObject::Disconnect("TGLViewer", "UnClicked(TObject*,UInt_t,UInt_t)",
this, "OnUnClicked(TObject*,UInt_t,UInt_t)");
}
////////////////////////////////////////////////////////////////////////////////
/// Repaint viewers that are tagged as changed.
void TEveViewerList::RepaintChangedViewers(Bool_t resetCameras, Bool_t dropLogicals)
{
for (List_i i=fChildren.begin(); i!=fChildren.end(); ++i)
{
TGLViewer* glv = ((TEveViewer*)*i)->GetGLViewer();
if (glv->IsChanged())
{
if (resetCameras) glv->PostSceneBuildSetup(kTRUE);
if (dropLogicals) glv->SetSmartRefresh(kFALSE);
glv->RequestDraw(TGLRnrCtx::kLODHigh);
if (dropLogicals) glv->SetSmartRefresh(kTRUE);
}
}
}
////////////////////////////////////////////////////////////////////////////////
/// Repaint all viewers.
void TEveViewerList::RepaintAllViewers(Bool_t resetCameras, Bool_t dropLogicals)
{
for (List_i i=fChildren.begin(); i!=fChildren.end(); ++i)
{
TGLViewer* glv = ((TEveViewer*)*i)->GetGLViewer();
if (resetCameras) glv->PostSceneBuildSetup(kTRUE);
if (dropLogicals) glv->SetSmartRefresh(kFALSE);
glv->RequestDraw(TGLRnrCtx::kLODHigh);
if (dropLogicals) glv->SetSmartRefresh(kTRUE);
}
}
////////////////////////////////////////////////////////////////////////////////
/// Delete annotations from all viewers.
void TEveViewerList::DeleteAnnotations()
{
for (List_i i=fChildren.begin(); i!=fChildren.end(); ++i)
{
TGLViewer* glv = ((TEveViewer*)*i)->GetGLViewer();
glv->DeleteOverlayAnnotations();
}
}
////////////////////////////////////////////////////////////////////////////////
/// Callback done from a TEveScene destructor allowing proper
/// removal of the scene from affected viewers.
void TEveViewerList::SceneDestructing(TEveScene* scene)
{
for (List_i i=fChildren.begin(); i!=fChildren.end(); ++i)
{
TEveViewer* viewer = (TEveViewer*) *i;
List_i j = viewer->BeginChildren();
while (j != viewer->EndChildren())
{
TEveSceneInfo* sinfo = (TEveSceneInfo*) *j;
++j;
if (sinfo->GetScene() == scene)
viewer->RemoveElement(sinfo);
}
}
}
////////////////////////////////////////////////////////////////////////////////
/// Show / hide tooltip for various MouseOver events.
/// Must be called from slots where sender is TGLEventHandler.
void TEveViewerList::HandleTooltip()
{
if (fShowTooltip)
{
TGLViewer *glw = dynamic_cast<TGLViewer*>((TQObject*) gTQSender);
TGLEventHandler *glh = (TGLEventHandler*) glw->GetEventHandler();
if (gEve->GetHighlight()->NumChildren() == 1)
{
TString title(gEve->GetHighlight()->FirstChild()->GetHighlightTooltip());
if ( ! title.IsNull())
glh->TriggerTooltip(title);
}
else
{
glh->RemoveTooltip();
}
}
}
////////////////////////////////////////////////////////////////////////////////
/// Slot for global TGLViewer::MouseOver() signal.
///
/// The attempt is made to determine the TEveElement being
/// represented by the physical shape and global highlight is updated
/// accordingly.
///
/// If TEveElement::IsPickable() returns false, the element is not
/// highlighted.
///
/// Highlight is always in single-selection mode.
void TEveViewerList::OnMouseOver(TObject *obj, UInt_t /*state*/)
{
TEveElement *el = dynamic_cast<TEveElement*>(obj);
if (el && !el->IsPickable())
el = 0;
void *qsender = gTQSender;
gEve->GetHighlight()->UserPickedElement(el, kFALSE);
gTQSender = qsender;
HandleTooltip();
}
////////////////////////////////////////////////////////////////////////////////
/// Slot for global TGLViewer::ReMouseOver().
///
/// The obj is dyn-casted to the TEveElement and global selection is
/// updated accordingly.
///
/// If TEveElement::IsPickable() returns false, the element is not
/// selected.
void TEveViewerList::OnReMouseOver(TObject *obj, UInt_t /*state*/)
{
TEveElement* el = dynamic_cast<TEveElement*>(obj);
if (el && !el->IsPickable())
el = 0;
void *qsender = gTQSender;
gEve->GetHighlight()->UserRePickedElement(el);
gTQSender = qsender;
HandleTooltip();
}
////////////////////////////////////////////////////////////////////////////////
/// Slot for global TGLViewer::UnMouseOver().
///
/// The obj is dyn-casted to the TEveElement and global selection is
/// updated accordingly.
///
/// If TEveElement::IsPickable() returns false, the element is not
/// selected.
void TEveViewerList::OnUnMouseOver(TObject *obj, UInt_t /*state*/)
{
TEveElement* el = dynamic_cast<TEveElement*>(obj);
if (el && !el->IsPickable())
el = 0;
void *qsender = gTQSender;
gEve->GetHighlight()->UserUnPickedElement(el);
gTQSender = qsender;
HandleTooltip();
}
////////////////////////////////////////////////////////////////////////////////
/// Slot for global TGLViewer::Clicked().
///
/// The obj is dyn-casted to the TEveElement and global selection is
/// updated accordingly.
///
/// If TEveElement::IsPickable() returns false, the element is not
/// selected.
void TEveViewerList::OnClicked(TObject *obj, UInt_t /*button*/, UInt_t state)
{
TEveElement* el = dynamic_cast<TEveElement*>(obj);
if (el && !el->IsPickable())
el = 0;
gEve->GetSelection()->UserPickedElement(el, state & kKeyControlMask);
}
////////////////////////////////////////////////////////////////////////////////
/// Slot for global TGLViewer::ReClicked().
///
/// The obj is dyn-casted to the TEveElement and global selection is
/// updated accordingly.
///
/// If TEveElement::IsPickable() returns false, the element is not
/// selected.
void TEveViewerList::OnReClicked(TObject *obj, UInt_t /*button*/, UInt_t /*state*/)
{
TEveElement* el = dynamic_cast<TEveElement*>(obj);
if (el && !el->IsPickable())
el = 0;
gEve->GetSelection()->UserRePickedElement(el);
}
////////////////////////////////////////////////////////////////////////////////
/// Slot for global TGLViewer::UnClicked().
///
/// The obj is dyn-casted to the TEveElement and global selection is
/// updated accordingly.
///
/// If TEveElement::IsPickable() returns false, the element is not
/// selected.
void TEveViewerList::OnUnClicked(TObject *obj, UInt_t /*button*/, UInt_t /*state*/)
{
TEveElement* el = dynamic_cast<TEveElement*>(obj);
if (el && !el->IsPickable())
el = 0;
gEve->GetSelection()->UserUnPickedElement(el);
}
////////////////////////////////////////////////////////////////////////////////
/// Set color brightness.
void TEveViewerList::SetColorBrightness(Float_t b)
{
TEveUtil::SetColorBrightness(b, 1);
}
////////////////////////////////////////////////////////////////////////////////
/// Switch background color.
void TEveViewerList::SwitchColorSet()
{
fUseLightColorSet = ! fUseLightColorSet;
for (List_i i=fChildren.begin(); i!=fChildren.end(); ++i)
{
TGLViewer* glv = ((TEveViewer*)*i)->GetGLViewer();
if ( fUseLightColorSet)
glv->UseLightColorSet();
else
glv->UseDarkColorSet();
glv->RequestDraw(TGLRnrCtx::kLODHigh);
}
}