Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TEveGedEditor.cxx
Go to the documentation of this file.
1// @(#)root/eve:$Id$
2// Authors: Matevz Tadel & Alja Mrak-Tadel: 2006, 2007
3
4/*************************************************************************
5 * Copyright (C) 1995-2007, Rene Brun and Fons Rademakers. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
12#include "TEveGedEditor.h"
13#include "TEveElement.h"
14#include "TEveManager.h"
15
16#include "TGToolTip.h"
17#include "TGDNDManager.h"
18#include "TGMsgBox.h"
19
20#include "TClass.h"
21#include "TContextMenu.h"
22#include "TVirtualX.h"
23
24/** \class TEveGedEditor
25\ingroup TEve
26Specialization of TGedEditor for proper update propagation to TEveManager.
27*/
28
30
33
35
36////////////////////////////////////////////////////////////////////////////////
37/// Constructor.
38
40 TGedEditor(canvas, width, height),
41 fElement (nullptr),
42 fObject (nullptr)
43{
44 // Remove old name-frame -- it is created in TGedEditor constructor
45 // so virtuals are not active yet.
46 fTabContainer->RemoveAll();
48 nf->SetGedEditor(this);
49 nf->SetModelClass(nullptr);
50 fTabContainer->AddFrame(nf, new TGLayoutHints(kLHintsTop | kLHintsExpandX, 2, 2, 2, 2));
51
52 // Fix priority for TAttMarkerEditor.
53 TClass* amClass = TClass::GetClass("TAttMarker");
54 TClass* edClass = TClass::GetClass("TAttMarkerEditor");
55 TGWindow *exroot = (TGWindow*) fClient->GetRoot();
56 fClient->SetRoot(fTabContainer);
57 SetFrameCreator(this);
58 TGedFrame *frame = reinterpret_cast<TGedFrame*>(edClass->New());
59 frame->SetModelClass(amClass);
60 {
61 Int_t off = edClass->GetDataMemberOffset("fPriority");
62 if (off == 0)
63 Warning("TEveGedEditor::TEveGedEditor", "Can't fix priority for TAttMarkerEditor.\n");
64 else
65 * (Int_t*) (((char*)frame) + off) = 1;
66 }
67 SetFrameCreator(nullptr);
68 fClient->SetRoot(exroot);
69 fFrameMap.Add(amClass, frame);
70}
71
72////////////////////////////////////////////////////////////////////////////////
73/// Destructor.
74
76{
77 if (gDebug > 0)
78 Info("TEveGedEditor::~TEveGedEditor", "%p going down.", this);
79}
80
81////////////////////////////////////////////////////////////////////////////////
82/// Called from window-manger close button.
83/// Unregister from global list and delete the window.
84
86{
87 if (gDebug > 0)
88 Info("TEveGedEditor::CloseWindow", "%p closing.", this);
89
90 fgExtraEditors->Remove(this);
91
92 DisplayElement(nullptr);
93
94 if (gDNDManager) {
95 if (gDNDManager->GetMainFrame() == this)
96 gDNDManager->SetMainFrame(nullptr);
97 }
99}
100
101////////////////////////////////////////////////////////////////////////////////
102/// Create name-frame for a tab.
103
104TGedFrame* TEveGedEditor::CreateNameFrame(const TGWindow* parent, const char* /*tab_name*/)
105{
106 return new TEveGedNameFrame(parent);
107}
108
109////////////////////////////////////////////////////////////////////////////////
110/// Return eve-element if it is the model object.
111
113{
114 return (fModel == fObject) ? fElement : nullptr;
115}
116
117////////////////////////////////////////////////////////////////////////////////
118/// Show a TEveElement in editor.
119
121{
122 static const TEveException eh("TEveGedEditor::DisplayElement ");
123
124 fElement = re;
125 fObject = fElement ? fElement->GetEditorObject(eh) : nullptr;
127}
128
129////////////////////////////////////////////////////////////////////////////////
130/// Show a TObject in editor.
131
133{
134 fElement = dynamic_cast<TEveElement*>(obj);
135 fObject = obj;
137}
138
139////////////////////////////////////////////////////////////////////////////////
140/// Set model object.
141
143{
144 fElement = dynamic_cast<TEveElement*>(obj);
145 fObject = obj;
146 TGedEditor::SetModel(pad, obj, event, force);
147}
148
149////////////////////////////////////////////////////////////////////////////////
150/// Virtual method from TGedEditor, called on every change.
151/// Propagates changes to TEveElement and TEveManager.
152
154{
155 if (fElement)
156 {
157 fElement->ElementChanged();
158 fElement->PropagateVizParamsToProjecteds();
159 }
160
161 gEve->Redraw3D();
162}
163
164////////////////////////////////////////////////////////////////////////////////
165/// Static function to create a new extra editor.
166
168{
169 if (fgExtraEditors->GetSize() >= fgMaxExtraEditors)
170 {
171 new TGMsgBox(gClient->GetDefaultRoot(), gEve->GetMainWindow(),
172 "Clutter warning",
173 "Maximum number of extra editors reached.",
175 }
176
177 if (obj)
178 {
179 TEveGedEditor *ed = new TEveGedEditor();
180 ed->DisplayObject(obj);
181 ed->SetWindowName(Form("GED %s", obj->GetName()));
182
183 fgExtraEditors->Add(ed);
184 }
185}
186
187////////////////////////////////////////////////////////////////////////////////
188/// Element was changed. Update editors showing it.
189
191{
192 TObject *eobj = el->GetEditorObject("TEveGedEditor::ElementChanged ");
193 TObjLink *lnk = fgExtraEditors->FirstLink();
194 while (lnk)
195 {
196 TEveGedEditor *ed = (TEveGedEditor*) lnk->GetObject();
197 if (ed->GetModel() == eobj)
198 ed->DisplayElement(el);
199 lnk = lnk->Next();
200 }
201}
202
203////////////////////////////////////////////////////////////////////////////////
204/// Element is being deleted. Close editors showing it.
205
207{
208 TObject *eobj = el->GetEditorObject("TEveGedEditor::ElementChanged ");
209 TObjLink *lnk = fgExtraEditors->FirstLink();
210 while (lnk)
211 {
212 TEveGedEditor *ed = (TEveGedEditor*) lnk->GetObject();
213 if (ed->GetModel() == eobj)
214 {
215 TObjLink *next = lnk->Next();
216 ed->DeleteWindow();
217 fgExtraEditors->Remove(lnk);
218 lnk = next;
219 }
220 else
221 {
222 lnk = lnk->Next();
223 }
224 }
225}
226
227////////////////////////////////////////////////////////////////////////////////
228/// Destroys all editors. Called from EVE termination.
229
231{
232 while ( ! fgExtraEditors->IsEmpty())
233 {
235 ed->DeleteWindow();
236 fgExtraEditors->RemoveFirst();
237 }
238}
239
240////////////////////////////////////////////////////////////////////////////////
241/// Return context menu object shared among eve-ged-editors.
242
244{
245 if (fgContextMenu == nullptr)
246 fgContextMenu = new TContextMenu("", "");
247 return fgContextMenu;
248}
249
250/** \class TEveGedNameFrame
251\ingroup TEve
252Specialization of TGedNameFrame used in EVE.
253It provides the ability to undock given editor for easier use.
254Support for that is also provided from the TEveManager.
255*/
256
258
259////////////////////////////////////////////////////////////////////////////////
260/// Constructor.
261
263 UInt_t options) :
264 TGedFrame(p, width, height, options),
265 fNCButton(nullptr)
266{
268 fNCButton->SetTextColor(0x0020a0);
270 fNCButton->Connect("Clicked()", "TEveGedNameFrame", this, "SpawnEditorClone()");
271}
272
273////////////////////////////////////////////////////////////////////////////////
274/// Destructor.
275
279
280////////////////////////////////////////////////////////////////////////////////
281/// Set model object.
282
284{
285 if (obj)
286 {
287 fNCButton->SetText(Form("%s [%s]", obj->GetName(), obj->ClassName()));
288 fNCButton->SetToolTipText(obj->GetTitle());
289 fNCButton->SetEnabled(kTRUE);
290 }
291 else
292 {
293 fNCButton->SetText("No object selected.");
294 fNCButton->SetToolTipText(nullptr);
295 fNCButton->SetEnabled(kFALSE);
296 }
297}
298
299////////////////////////////////////////////////////////////////////////////////
300/// Create a new floating editor with current object.
301
306
307/** \class TEveGedNameTextButton
308\ingroup TEve
309Specialization of TGTextButton for EVE name frame.
310It opens a context-menu on right-click.
311*/
312
314
315////////////////////////////////////////////////////////////////////////////////
316/// Constructor.
317
326
327////////////////////////////////////////////////////////////////////////////////
328/// Destructor.
329
333
334////////////////////////////////////////////////////////////////////////////////
335/// Handle button.
336
338{
339 static const TEveException eh("TEveGedNameTextButton::HandleButton ");
340
341 if (fTip) fTip->Hide();
342 if (fState == kButtonDisabled) return kTRUE;
343
344 if (event->fCode == kButton3 && event->fType == kButtonPress)
345 {
346 TEveGedEditor *eged = (TEveGedEditor*) fFrame->GetGedEditor();
347 TEveElement *el = eged->GetEveElement();
348 if (el)
350 el->GetObject(eh));
351 return true;
352 }
353 else if (event->fCode == kButton1)
354 {
355 return TGTextButton::HandleButton(event);
356 }
357 else
358 {
359 return false;
360 }
361}
@ kButton1Down
Definition Buttons.h:17
@ kButtonPress
Definition GuiTypes.h:60
const Mask_t kButtonPressMask
Definition GuiTypes.h:161
const Mask_t kAnyModifier
Definition GuiTypes.h:210
const Handle_t kNone
Definition GuiTypes.h:88
const Mask_t kButtonReleaseMask
Definition GuiTypes.h:162
@ kButton3
Definition GuiTypes.h:214
@ kButton1
Definition GuiTypes.h:214
@ kAnyButton
Definition GuiTypes.h:214
bool Bool_t
Definition RtypesCore.h:63
int Int_t
Definition RtypesCore.h:45
unsigned int UInt_t
Definition RtypesCore.h:46
constexpr Bool_t kFALSE
Definition RtypesCore.h:101
constexpr Bool_t kTRUE
Definition RtypesCore.h:100
#define ClassImp(name)
Definition Rtypes.h:377
void Info(const char *location, const char *msgfmt,...)
Use this function for informational messages.
Definition TError.cxx:218
void Warning(const char *location, const char *msgfmt,...)
Use this function in warning situations.
Definition TError.cxx:229
R__EXTERN TEveManager * gEve
@ kButtonDisabled
Definition TGButton.h:56
#define gClient
Definition TGClient.h:156
R__EXTERN TGDNDManager * gDNDManager
@ kLHintsNormal
Definition TGLayout.h:32
@ kLHintsTop
Definition TGLayout.h:27
@ kLHintsExpandX
Definition TGLayout.h:30
@ kMBOk
Definition TGMsgBox.h:33
@ kMBIconStop
Definition TGMsgBox.h:22
Option_t Option_t width
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t height
Int_t gDebug
Definition TROOT.cxx:622
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
Definition TString.cxx:2489
#define gVirtualX
Definition TVirtualX.h:337
The Canvas class.
Definition TCanvas.h:23
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition TClass.h:81
void * New(ENewType defConstructor=kClassNew, Bool_t quiet=kFALSE) const
Return a pointer to a newly allocated object of this class.
Definition TClass.cxx:5005
Longptr_t GetDataMemberOffset(const char *membername) const
return offset for member name.
Definition TClass.cxx:3504
static TClass * GetClass(const char *name, Bool_t load=kTRUE, Bool_t silent=kFALSE)
Static method returning pointer to TClass of the specified class name.
Definition TClass.cxx:2969
This class provides an interface to context sensitive popup menus.
virtual void Popup(Int_t x, Int_t y, TObject *obj, TVirtualPad *c=nullptr, TVirtualPad *p=nullptr)
Popup context menu at given location in canvas c and pad p for selected object.
Base class for TEveUtil visualization elements, providing hierarchy management, rendering control and...
Definition TEveElement.h:36
virtual TObject * GetEditorObject(const TEveException &eh) const
virtual TObject * GetObject(const TEveException &eh) const
Get a TObject associated with this render-element.
Exception class thrown by TEve classes and macros.
Definition TEveUtil.h:102
Specialization of TGedEditor for proper update propagation to TEveManager.
static Int_t fgMaxExtraEditors
TGedFrame * CreateNameFrame(const TGWindow *parent, const char *tab_name) override
Create name-frame for a tab.
TEveElement * GetEveElement() const
Return eve-element if it is the model object.
TObject * fObject
static void ElementDeleted(TEveElement *el)
Element is being deleted. Close editors showing it.
void DisplayElement(TEveElement *re)
Show a TEveElement in editor.
TEveElement * fElement
static TContextMenu * GetContextMenu()
Return context menu object shared among eve-ged-editors.
static TContextMenu * fgContextMenu
static TList * fgExtraEditors
void CloseWindow() override
Called from window-manger close button.
void Update(TGedFrame *gframe=nullptr) override
Virtual method from TGedEditor, called on every change.
void SetModel(TVirtualPad *pad, TObject *obj, Int_t event, Bool_t force=kFALSE) override
Set model object.
static void DestroyEditors()
Destroys all editors. Called from EVE termination.
TEveGedEditor(const TEveGedEditor &)
void DisplayObject(TObject *obj)
Show a TObject in editor.
static void ElementChanged(TEveElement *el)
Element was changed. Update editors showing it.
~TEveGedEditor() override
Destructor.
static void SpawnNewEditor(TObject *obj)
Static function to create a new extra editor.
Specialization of TGedNameFrame used in EVE.
void SpawnEditorClone()
Create a new floating editor with current object.
void SetModel(TObject *obj) override
Set model object.
TGTextButton * fNCButton
~TEveGedNameFrame() override
Destructor.
TEveGedNameFrame(const TEveGedNameFrame &)
Specialization of TGTextButton for EVE name frame.
Bool_t HandleButton(Event_t *event) override
Handle button.
~TEveGedNameTextButton() override
Destructor.
TEveGedNameFrame * fFrame
TEveGedNameTextButton(const TEveGedNameTextButton &)
Bool_t HandleButton(Event_t *event) override
Handle mouse button event.
Definition TGButton.cxx:330
EButtonState fState
button state
Definition TGButton.h:75
TGToolTip * fTip
tool tip associated with button
Definition TGButton.h:79
virtual void AddFrame(TGFrame *f, TGLayoutHints *l=nullptr)
Add frame to the composite frame using the specified layout hints.
Definition TGFrame.cxx:1117
virtual void DeleteWindow()
Delete window.
Definition TGFrame.cxx:276
This class describes layout hints used by the layout classes.
Definition TGLayout.h:50
void SetWindowName(const char *name=nullptr) override
Set window name. This is typically done via the window manager.
Definition TGFrame.cxx:1788
TGClient * fClient
Connection to display server.
Definition TGObject.h:25
Handle_t fId
X11/Win32 Window identifier.
Definition TGObject.h:24
TGTextButton(const TGTextButton &)=delete
ROOT GUI Window base class.
Definition TGWindow.h:23
TMap fFrameMap
global map of available frames
Definition TGedEditor.h:37
TVirtualPad * fPad
selected pad
Definition TGedEditor.h:49
virtual void SetModel(TVirtualPad *pad, TObject *obj, Int_t event, Bool_t force=kFALSE)
Activate object editors according to the selected object.
TGedEditor(const TGedEditor &)=delete
TGCompositeFrame * fTabContainer
main tab container
Definition TGedEditor.h:46
TObject * fModel
selected object
Definition TGedEditor.h:48
static void SetFrameCreator(TGedEditor *e)
Set the TGedEditor that currently creates TGedFrames.
virtual TObject * GetModel() const
Definition TGedEditor.h:79
Base frame for implementing GUI - a service class.
Definition TGedFrame.h:27
virtual void SetGedEditor(TGedEditor *ed)
Definition TGedFrame.h:80
TGedEditor * fGedEditor
manager of this frame
Definition TGedFrame.h:48
TGedFrame(const TGedFrame &)=delete
void SetModelClass(TClass *mcl)
Definition TGedFrame.h:78
A doubly linked list.
Definition TList.h:38
Mother of all ROOT objects.
Definition TObject.h:41
virtual const char * GetName() const
Returns name of object.
Definition TObject.cxx:439
virtual const char * ClassName() const
Returns name of class to which the object belongs.
Definition TObject.cxx:207
virtual const char * GetTitle() const
Returns title of object.
Definition TObject.cxx:483
TVirtualPad is an abstract base class for the Pad and Canvas classes.
Definition TVirtualPad.h:51
Event structure.
Definition GuiTypes.h:174
EGEventType fType
of event (see EGEventType)
Definition GuiTypes.h:175
Int_t fXRoot
Definition GuiTypes.h:179
Int_t fYRoot
coordinates relative to root
Definition GuiTypes.h:179
UInt_t fCode
key or button code
Definition GuiTypes.h:180