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
29
32
34
35////////////////////////////////////////////////////////////////////////////////
36/// Constructor.
37
39 TGedEditor(canvas, width, height),
40 fElement (nullptr),
41 fObject (nullptr)
42{
43 // Remove old name-frame -- it is created in TGedEditor constructor
44 // so virtuals are not active yet.
45 fTabContainer->RemoveAll();
47 nf->SetGedEditor(this);
48 nf->SetModelClass(nullptr);
49 fTabContainer->AddFrame(nf, new TGLayoutHints(kLHintsTop | kLHintsExpandX, 2, 2, 2, 2));
50
51 // Fix priority for TAttMarkerEditor.
52 TClass* amClass = TClass::GetClass("TAttMarker");
53 TClass* edClass = TClass::GetClass("TAttMarkerEditor");
54 TGWindow *exroot = (TGWindow*) fClient->GetRoot();
55 fClient->SetRoot(fTabContainer);
56 SetFrameCreator(this);
57 TGedFrame *frame = reinterpret_cast<TGedFrame*>(edClass->New());
58 frame->SetModelClass(amClass);
59 {
60 Int_t off = edClass->GetDataMemberOffset("fPriority");
61 if (off == 0)
62 Warning("TEveGedEditor::TEveGedEditor", "Can't fix priority for TAttMarkerEditor.\n");
63 else
64 * (Int_t*) (((char*)frame) + off) = 1;
65 }
66 SetFrameCreator(nullptr);
67 fClient->SetRoot(exroot);
68 fFrameMap.Add(amClass, frame);
69}
70
71////////////////////////////////////////////////////////////////////////////////
72/// Destructor.
73
75{
76 if (gDebug > 0)
77 Info("TEveGedEditor::~TEveGedEditor", "%p going down.", this);
78}
79
80////////////////////////////////////////////////////////////////////////////////
81/// Called from window-manger close button.
82/// Unregister from global list and delete the window.
83
85{
86 if (gDebug > 0)
87 Info("TEveGedEditor::CloseWindow", "%p closing.", this);
88
89 fgExtraEditors->Remove(this);
90
91 DisplayElement(nullptr);
92
93 if (gDNDManager) {
94 if (gDNDManager->GetMainFrame() == this)
95 gDNDManager->SetMainFrame(nullptr);
96 }
98}
99
100////////////////////////////////////////////////////////////////////////////////
101/// Create name-frame for a tab.
102
103TGedFrame* TEveGedEditor::CreateNameFrame(const TGWindow* parent, const char* /*tab_name*/)
104{
105 return new TEveGedNameFrame(parent);
106}
107
108////////////////////////////////////////////////////////////////////////////////
109/// Return eve-element if it is the model object.
110
112{
113 return (fModel == fObject) ? fElement : nullptr;
114}
115
116////////////////////////////////////////////////////////////////////////////////
117/// Show a TEveElement in editor.
118
120{
121 static const TEveException eh("TEveGedEditor::DisplayElement ");
122
123 fElement = re;
124 fObject = fElement ? fElement->GetEditorObject(eh) : nullptr;
126}
127
128////////////////////////////////////////////////////////////////////////////////
129/// Show a TObject in editor.
130
132{
133 fElement = dynamic_cast<TEveElement*>(obj);
134 fObject = obj;
136}
137
138////////////////////////////////////////////////////////////////////////////////
139/// Set model object.
140
142{
143 fElement = dynamic_cast<TEveElement*>(obj);
144 fObject = obj;
145 TGedEditor::SetModel(pad, obj, event, force);
146}
147
148////////////////////////////////////////////////////////////////////////////////
149/// Virtual method from TGedEditor, called on every change.
150/// Propagates changes to TEveElement and TEveManager.
151
153{
154 if (fElement)
155 {
156 fElement->ElementChanged();
157 fElement->PropagateVizParamsToProjecteds();
158 }
159
160 gEve->Redraw3D();
161}
162
163////////////////////////////////////////////////////////////////////////////////
164/// Static function to create a new extra editor.
165
167{
168 if (fgExtraEditors->GetSize() >= fgMaxExtraEditors)
169 {
170 new TGMsgBox(gClient->GetDefaultRoot(), gEve->GetMainWindow(),
171 "Clutter warning",
172 "Maximum number of extra editors reached.",
174 }
175
176 if (obj)
177 {
178 TEveGedEditor *ed = new TEveGedEditor();
179 ed->DisplayObject(obj);
180 ed->SetWindowName(Form("GED %s", obj->GetName()));
181
182 fgExtraEditors->Add(ed);
183 }
184}
185
186////////////////////////////////////////////////////////////////////////////////
187/// Element was changed. Update editors showing it.
188
190{
191 TObject *eobj = el->GetEditorObject("TEveGedEditor::ElementChanged ");
192 TObjLink *lnk = fgExtraEditors->FirstLink();
193 while (lnk)
194 {
195 TEveGedEditor *ed = (TEveGedEditor*) lnk->GetObject();
196 if (ed->GetModel() == eobj)
197 ed->DisplayElement(el);
198 lnk = lnk->Next();
199 }
200}
201
202////////////////////////////////////////////////////////////////////////////////
203/// Element is being deleted. Close editors showing it.
204
206{
207 TObject *eobj = el->GetEditorObject("TEveGedEditor::ElementChanged ");
208 TObjLink *lnk = fgExtraEditors->FirstLink();
209 while (lnk)
210 {
211 TEveGedEditor *ed = (TEveGedEditor*) lnk->GetObject();
212 if (ed->GetModel() == eobj)
213 {
214 TObjLink *next = lnk->Next();
215 ed->DeleteWindow();
216 fgExtraEditors->Remove(lnk);
217 lnk = next;
218 }
219 else
220 {
221 lnk = lnk->Next();
222 }
223 }
224}
225
226////////////////////////////////////////////////////////////////////////////////
227/// Destroys all editors. Called from EVE termination.
228
230{
231 while ( ! fgExtraEditors->IsEmpty())
232 {
234 ed->DeleteWindow();
235 fgExtraEditors->RemoveFirst();
236 }
237}
238
239////////////////////////////////////////////////////////////////////////////////
240/// Return context menu object shared among eve-ged-editors.
241
243{
244 if (fgContextMenu == nullptr)
245 fgContextMenu = new TContextMenu("", "");
246 return fgContextMenu;
247}
248
249/** \class TEveGedNameFrame
250\ingroup TEve
251Specialization of TGedNameFrame used in EVE.
252It provides the ability to undock given editor for easier use.
253Support for that is also provided from the TEveManager.
254*/
255
256
257////////////////////////////////////////////////////////////////////////////////
258/// Constructor.
259
261 UInt_t options) :
262 TGedFrame(p, width, height, options),
263 fNCButton(nullptr)
264{
266 fNCButton->SetTextColor(0x0020a0);
268 fNCButton->Connect("Clicked()", "TEveGedNameFrame", this, "SpawnEditorClone()");
269}
270
271////////////////////////////////////////////////////////////////////////////////
272/// Destructor.
273
277
278////////////////////////////////////////////////////////////////////////////////
279/// Set model object.
280
282{
283 if (obj)
284 {
285 fNCButton->SetText(Form("%s [%s]", obj->GetName(), obj->ClassName()));
286 fNCButton->SetToolTipText(obj->GetTitle());
287 fNCButton->SetEnabled(kTRUE);
288 }
289 else
290 {
291 fNCButton->SetText("No object selected.");
292 fNCButton->SetToolTipText(nullptr);
293 fNCButton->SetEnabled(kFALSE);
294 }
295}
296
297////////////////////////////////////////////////////////////////////////////////
298/// Create a new floating editor with current object.
299
304
305/** \class TEveGedNameTextButton
306\ingroup TEve
307Specialization of TGTextButton for EVE name frame.
308It opens a context-menu on right-click.
309*/
310
311
312////////////////////////////////////////////////////////////////////////////////
313/// Constructor.
314
323
324////////////////////////////////////////////////////////////////////////////////
325/// Destructor.
326
330
331////////////////////////////////////////////////////////////////////////////////
332/// Handle button.
333
335{
336 static const TEveException eh("TEveGedNameTextButton::HandleButton ");
337
338 if (fTip) fTip->Hide();
339 if (fState == kButtonDisabled) return kTRUE;
340
341 if (event->fCode == kButton3 && event->fType == kButtonPress)
342 {
343 TEveGedEditor *eged = (TEveGedEditor*) fFrame->GetGedEditor();
344 TEveElement *el = eged->GetEveElement();
345 if (el)
347 el->GetObject(eh));
348 return true;
349 }
350 else if (event->fCode == kButton1)
351 {
352 return TGTextButton::HandleButton(event);
353 }
354 else
355 {
356 return false;
357 }
358}
@ kButton1Down
Definition Buttons.h:17
@ kButtonPress
Definition GuiTypes.h:61
const Mask_t kButtonPressMask
Definition GuiTypes.h:162
const Mask_t kAnyModifier
Definition GuiTypes.h:211
const Handle_t kNone
Definition GuiTypes.h:89
const Mask_t kButtonReleaseMask
Definition GuiTypes.h:163
@ kButton3
Definition GuiTypes.h:215
@ kButton1
Definition GuiTypes.h:215
@ kAnyButton
Definition GuiTypes.h:215
int Int_t
Signed integer 4 bytes (int).
Definition RtypesCore.h:59
unsigned int UInt_t
Unsigned integer 4 bytes (unsigned int).
Definition RtypesCore.h:60
bool Bool_t
Boolean (0=false, 1=true) (bool).
Definition RtypesCore.h:77
constexpr Bool_t kFALSE
Definition RtypesCore.h:108
constexpr Bool_t kTRUE
Definition RtypesCore.h:107
void Info(const char *location, const char *msgfmt,...)
Use this function for informational messages.
Definition TError.cxx:241
void Warning(const char *location, const char *msgfmt,...)
Use this function in warning situations.
Definition TError.cxx:252
externTEveManager * gEve
@ kButtonDisabled
Definition TGButton.h:56
#define gClient
Definition TGClient.h:157
externTGDNDManager * 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
Int_t gDebug
Definition TROOT.cxx:777
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
Definition TString.cxx:2496
#define gVirtualX
Definition TVirtualX.h:375
The Canvas class.
Definition TCanvas.h:23
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition TClass.h:84
void * New(ENewType defConstructor=kClassNew, Bool_t quiet=kFALSE) const
Return a pointer to a newly allocated object of this class.
Definition TClass.cxx:5048
Longptr_t GetDataMemberOffset(const char *membername) const
return offset for member name.
Definition TClass.cxx:3539
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:2994
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:324
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:1109
virtual void DeleteWindow()
Delete window.
Definition TGFrame.cxx:268
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:1780
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:42
virtual const char * GetName() const
Returns name of object.
Definition TObject.cxx:462
virtual const char * ClassName() const
Returns name of class to which the object belongs.
Definition TObject.cxx:227
virtual const char * GetTitle() const
Returns title of object.
Definition TObject.cxx:507
TVirtualPad is an abstract base class for the Pad and Canvas classes.
Definition TVirtualPad.h:51
Event structure.
Definition GuiTypes.h:175
EGEventType fType
of event (see EGEventType)
Definition GuiTypes.h:176
Int_t fXRoot
Definition GuiTypes.h:180
Int_t fYRoot
coordinates relative to root
Definition GuiTypes.h:180
UInt_t fCode
key or button code
Definition GuiTypes.h:181