Logo ROOT  
Reference Guide
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
26 Specialization of TGedEditor for proper update propagation to TEveManager.
27 */
28 
30 
33 
35 
36 ////////////////////////////////////////////////////////////////////////////////
37 /// Constructor.
38 
40  TGedEditor(canvas, width, height),
41  fElement (0),
42  fObject (0)
43 {
44  // Remove old name-frame -- it is created in TGedEditor constructor
45  // so virtuals are not active yet.
47  TGedFrame* nf = CreateNameFrame(fTabContainer, "Style");
48  nf->SetGedEditor(this);
49  nf->SetModelClass(0);
51 
52  // Fix priority for TAttMarkerEditor.
53  TClass* amClass = TClass::GetClass("TAttMarker");
54  TClass* edClass = TClass::GetClass("TAttMarkerEditor");
55  TGWindow *exroot = (TGWindow*) fClient->GetRoot();
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(0);
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(0);
93 
94  if (gDNDManager) {
95  if (gDNDManager->GetMainFrame() == this)
97  }
98  DeleteWindow();
99 }
100 
101 ////////////////////////////////////////////////////////////////////////////////
102 /// Create name-frame for a tab.
103 
104 TGedFrame* 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 : 0;
115 }
116 
117 ////////////////////////////////////////////////////////////////////////////////
118 /// Show a TEveElement in editor.
119 
121 {
122  static const TEveException eh("TEveGedEditor::DisplayElement ");
123 
124  fElement = re;
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  {
159  }
160 
161  gEve->Redraw3D();
162 }
163 
164 ////////////////////////////////////////////////////////////////////////////////
165 /// Static function to create a new extra editor.
166 
168 {
170  {
171  new TGMsgBox(gClient->GetDefaultRoot(), gEve->GetMainWindow(),
172  "Clutter warning",
173  "Maximum number of extra editors reached.",
174  kMBIconStop, kMBOk);
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 ");
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 ");
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();
237  }
238 }
239 
240 ////////////////////////////////////////////////////////////////////////////////
241 /// Return context menu object shared among eve-ged-editors.
242 
244 {
245  if (fgContextMenu == 0)
246  fgContextMenu = new TContextMenu("", "");
247  return fgContextMenu;
248 }
249 
250 /** \class TEveGedNameFrame
251 \ingroup TEve
252 Specialization of TGedNameFrame used in EVE.
253 It provides the ability to undock given editor for easier use.
254 Support 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(0)
266 {
267  fNCButton = new TEveGedNameTextButton(this);
268  fNCButton->SetTextColor(0x0020a0);
270  fNCButton->Connect("Clicked()", "TEveGedNameFrame", this, "SpawnEditorClone()");
271 }
272 
273 ////////////////////////////////////////////////////////////////////////////////
274 /// Destructor.
275 
277 {
278 }
279 
280 ////////////////////////////////////////////////////////////////////////////////
281 /// Set model object.
282 
284 {
285  if (obj)
286  {
287  fNCButton->SetText(Form("%s [%s]", obj->GetName(), obj->ClassName()));
290  }
291  else
292  {
293  fNCButton->SetText("No object selected.");
296  }
297 }
298 
299 ////////////////////////////////////////////////////////////////////////////////
300 /// Create a new floating editor with current object.
301 
303 {
305 }
306 
307 /** \class TEveGedNameTextButton
308 \ingroup TEve
309 Specialization of TGTextButton for EVE name frame.
310 It opens a context-menu on right-click.
311 */
312 
314 
315 ////////////////////////////////////////////////////////////////////////////////
316 /// Constructor.
317 
319  TGTextButton(p, ""),
320  fFrame(p)
321 {
322  gVirtualX->GrabButton(fId, kAnyButton, kAnyModifier,
324  kNone, kNone);
325 }
326 
327 ////////////////////////////////////////////////////////////////////////////////
328 /// Destructor.
329 
331 {
332 }
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  {
347  TEveElement *el = eged->GetEveElement();
348  if (el)
350  el->GetObject(eh));
351  return 1;
352  }
353  else if (event->fCode == kButton1)
354  {
355  return TGTextButton::HandleButton(event);
356  }
357  else
358  {
359  return 0;
360  }
361 }
TGButton::SetToolTipText
virtual void SetToolTipText(const char *text, Long_t delayms=400)
Set tool tip text associated with this button.
Definition: TGButton.cxx:398
Event_t::fType
EGEventType fType
Definition: GuiTypes.h:174
TGTextButton::SetTextColor
virtual void SetTextColor(Pixel_t color, Bool_t global=kFALSE)
Changes text color.
Definition: TGButton.cxx:871
TGButton::SetEnabled
virtual void SetEnabled(Bool_t e=kTRUE)
Set enabled or disabled state of button.
Definition: TGButton.cxx:412
TGWindow
Definition: TGWindow.h:31
TEveElement
Definition: TEveElement.h:35
kTRUE
const Bool_t kTRUE
Definition: RtypesCore.h:91
TEveGedEditor::fgMaxExtraEditors
static Int_t fgMaxExtraEditors
Definition: TEveGedEditor.h:40
TEveGedNameFrame::TEveGedNameFrame
TEveGedNameFrame(const TEveGedNameFrame &)
kAnyModifier
const Mask_t kAnyModifier
Definition: GuiTypes.h:209
TEveElement::GetEditorObject
virtual TObject * GetEditorObject(const TEveException &eh) const
Definition: TEveElement.h:199
TEveGedEditor::DestroyEditors
static void DestroyEditors()
Destroys all editors. Called from EVE termination.
Definition: TEveGedEditor.cxx:230
TGedEditor::SetModel
virtual void SetModel(TVirtualPad *pad, TObject *obj, Int_t event, Bool_t force=kFALSE)
Activate object editors according to the selected object.
Definition: TGedEditor.cxx:350
TGedFrame::GetGedEditor
TGedEditor * GetGedEditor()
Definition: TGedFrame.h:77
TEveElement::PropagateVizParamsToProjecteds
virtual void PropagateVizParamsToProjecteds()
Propagate visualization parameters to dependent elements.
Definition: TEveElement.cxx:427
TEveGedEditor::fgContextMenu
static TContextMenu * fgContextMenu
Definition: TEveGedEditor.h:43
gVirtualX
#define gVirtualX
Definition: TVirtualX.h:338
kAnyButton
@ kAnyButton
Definition: GuiTypes.h:213
kLHintsTop
@ kLHintsTop
Definition: TGLayout.h:40
ClassImp
#define ClassImp(name)
Definition: Rtypes.h:364
Form
char * Form(const char *fmt,...)
TGMsgBox
Definition: TGMsgBox.h:63
TEveGedEditor::SetModel
virtual void SetModel(TVirtualPad *pad, TObject *obj, Int_t event, Bool_t force=kFALSE)
Set model object.
Definition: TEveGedEditor.cxx:142
TObject::Info
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
Definition: TObject.cxx:864
TEveGedNameFrame
Definition: TEveGedEditor.h:77
TContextMenu::Popup
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.
Definition: TContextMenu.cxx:411
width
include TDocParser_001 C image html pict1_TDocParser_001 png width
Definition: TDocParser.cxx:121
TGTextButton
Definition: TGButton.h:142
TEveGedEditor::GetEveElement
TEveElement * GetEveElement() const
Return eve-element if it is the model object.
Definition: TEveGedEditor.cxx:112
Int_t
int Int_t
Definition: RtypesCore.h:45
TEveGedEditor
Definition: TEveGedEditor.h:26
TClass::GetDataMemberOffset
Long_t GetDataMemberOffset(const char *membername) const
return offset for member name.
Definition: TClass.cxx:3356
TGClient::SetRoot
void SetRoot(TGWindow *root=0)
Sets the current root (i.e.
Definition: TGClient.cxx:245
TEveGedEditor::Update
virtual void Update(TGedFrame *gframe=0)
Virtual method from TGedEditor, called on every change.
Definition: TEveGedEditor.cxx:153
TEveGedNameFrame::SetModel
virtual void SetModel(TObject *obj)
Set model object.
Definition: TEveGedEditor.cxx:283
TClass.h
kButton1
@ kButton1
Definition: GuiTypes.h:213
TGedFrame::SetModelClass
void SetModelClass(TClass *mcl)
Definition: TGedFrame.h:84
TGMainFrame::SetWindowName
void SetWindowName(const char *name=0)
Set window name. This is typically done via the window manager.
Definition: TGFrame.cxx:1749
TEveElement.h
TVirtualX.h
TGedFrame::SetGedEditor
virtual void SetGedEditor(TGedEditor *ed)
Definition: TGedFrame.h:86
TGDNDManager::GetMainFrame
TGFrame * GetMainFrame() const
Definition: TGDNDManager.h:163
TEveGedEditor::CloseWindow
virtual void CloseWindow()
Called from window-manger close button.
Definition: TEveGedEditor.cxx:85
TObject::GetTitle
virtual const char * GetTitle() const
Returns title of object.
Definition: TObject.cxx:403
TMap::Add
void Add(TObject *obj)
This function may not be used (but we need to provide it since it is a pure virtual in TCollection).
Definition: TMap.cxx:54
TGDNDManager.h
TEveGedNameTextButton
Definition: TEveGedEditor.h:103
kButtonPressMask
const Mask_t kButtonPressMask
Definition: GuiTypes.h:160
TGedEditor::fTabContainer
TGCompositeFrame * fTabContainer
Definition: TGedEditor.h:57
gEve
R__EXTERN TEveManager * gEve
Definition: TEveManager.h:243
TEveGedEditor::DisplayObject
void DisplayObject(TObject *obj)
Show a TObject in editor.
Definition: TEveGedEditor.cxx:132
bool
TEveGedEditor::~TEveGedEditor
virtual ~TEveGedEditor()
Destructor.
Definition: TEveGedEditor.cxx:75
gClient
#define gClient
Definition: TGClient.h:166
TEveGedEditor::ElementChanged
static void ElementChanged(TEveElement *el)
Element was changed. Update editors showing it.
Definition: TEveGedEditor.cxx:190
TList::First
virtual TObject * First() const
Return the first object in the list. Returns 0 when list is empty.
Definition: TList.cxx:658
TContextMenu
Definition: TContextMenu.h:44
TEveGedEditor.h
TObject::GetName
virtual const char * GetName() const
Returns name of object.
Definition: TObject.cxx:359
TEveGedNameTextButton::HandleButton
virtual Bool_t HandleButton(Event_t *event)
Handle button.
Definition: TEveGedEditor.cxx:337
kNone
const Handle_t kNone
Definition: GuiTypes.h:87
TContextMenu.h
TGFrame::DeleteWindow
virtual void DeleteWindow()
Delete window.
Definition: TGFrame.cxx:261
TGedEditor::fModel
TObject * fModel
Definition: TGedEditor.h:59
TEveGedEditor::GetContextMenu
static TContextMenu * GetContextMenu()
Return context menu object shared among eve-ged-editors.
Definition: TEveGedEditor.cxx:243
kLHintsNormal
@ kLHintsNormal
Definition: TGLayout.h:45
TList::FirstLink
virtual TObjLink * FirstLink() const
Definition: TList.h:108
TEveGedNameTextButton::fFrame
TEveGedNameFrame * fFrame
Definition: TEveGedEditor.h:109
TEveElement::ElementChanged
virtual void ElementChanged(Bool_t update_scenes=kTRUE, Bool_t redraw=kFALSE)
Call this after an element has been changed so that the state can be propagated around the framework.
Definition: TEveElement.cxx:1852
TClass::New
void * New(ENewType defConstructor=kClassNew, Bool_t quiet=kFALSE) const
Return a pointer to a newly allocated object of this class.
Definition: TClass.cxx:4881
TGTextButton::SetText
virtual void SetText(TGHotString *new_label)
Set new button text.
Definition: TGButton.cxx:597
kButton3
@ kButton3
Definition: GuiTypes.h:213
TGButton::HandleButton
virtual Bool_t HandleButton(Event_t *event)
Handle mouse button event.
Definition: TGButton.cxx:283
TGObject::fId
Handle_t fId
Definition: TGObject.h:36
TSeqCollection::RemoveFirst
virtual void RemoveFirst()
Definition: TSeqCollection.h:50
Event_t::fCode
UInt_t fCode
Definition: GuiTypes.h:179
kFALSE
const Bool_t kFALSE
Definition: RtypesCore.h:92
TEveGedNameFrame::SpawnEditorClone
void SpawnEditorClone()
Create a new floating editor with current object.
Definition: TEveGedEditor.cxx:302
kButtonPress
@ kButtonPress
Definition: GuiTypes.h:59
gDebug
R__EXTERN Int_t gDebug
Definition: RtypesCore.h:119
TGButton::fTip
TGToolTip * fTip
Definition: TGButton.h:79
kButtonReleaseMask
const Mask_t kButtonReleaseMask
Definition: GuiTypes.h:161
TGCompositeFrame::RemoveAll
virtual void RemoveAll()
Remove all frames from composite frame.
Definition: TGFrame.cxx:1116
TGLayoutHints
Definition: TGLayout.h:57
TClass::GetClass
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:2925
TGDNDManager::SetMainFrame
void SetMainFrame(TGFrame *main)
Definition: TGDNDManager.h:164
TEveGedEditor::SpawnNewEditor
static void SpawnNewEditor(TObject *obj)
Static function to create a new extra editor.
Definition: TEveGedEditor.cxx:167
Event_t::fXRoot
Int_t fXRoot
Definition: GuiTypes.h:178
TCollection::IsEmpty
virtual Bool_t IsEmpty() const
Definition: TCollection.h:186
TObject::Warning
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition: TObject.cxx:876
gDNDManager
R__EXTERN TGDNDManager * gDNDManager
Definition: TGDNDManager.h:203
Event_t::fYRoot
Int_t fYRoot
Definition: GuiTypes.h:178
TEveGedEditor::fgExtraEditors
static TList * fgExtraEditors
Definition: TEveGedEditor.h:41
unsigned int
kMBOk
@ kMBOk
Definition: TGMsgBox.h:44
TEveGedEditor::fElement
TEveElement * fElement
Definition: TEveGedEditor.h:35
TEveGedEditor::TEveGedEditor
TEveGedEditor(const TEveGedEditor &)
TGedFrame
Definition: TGedFrame.h:33
TGedEditor::GetModel
virtual TObject * GetModel() const
Definition: TGedEditor.h:90
TEveManager.h
kButton1Down
@ kButton1Down
Definition: Buttons.h:23
TQObject::Connect
Bool_t Connect(const char *signal, const char *receiver_class, void *receiver, const char *slot)
Non-static method is used to connect from the signal of this object to the receiver slot.
Definition: TQObject.cxx:864
TVirtualPad
Definition: TVirtualPad.h:50
TEveException
Definition: TEveUtil.h:101
TCanvas
Definition: TCanvas.h:23
TGedEditor::fFrameMap
TMap fFrameMap
Definition: TGedEditor.h:48
TList::Remove
virtual TObject * Remove(TObject *obj)
Remove object from the list.
Definition: TList.cxx:821
TGMsgBox.h
TEveGedNameFrame::fNCButton
TGTextButton * fNCButton
Definition: TEveGedEditor.h:84
TGObject::fClient
TGClient * fClient
Definition: TGObject.h:37
TCollection::GetSize
virtual Int_t GetSize() const
Return the capacity of the collection, i.e.
Definition: TCollection.h:182
TClass
Definition: TClass.h:80
TEveGedEditor::ElementDeleted
static void ElementDeleted(TEveElement *el)
Element is being deleted. Close editors showing it.
Definition: TEveGedEditor.cxx:206
TList::Add
virtual void Add(TObject *obj)
Definition: TList.h:87
TObject
Definition: TObject.h:37
TEveManager::GetMainWindow
TGWindow * GetMainWindow() const
Get the main window, i.e. EVE-browser.
Definition: TEveManager.cxx:249
TGToolTip.h
TEveManager::Redraw3D
void Redraw3D(Bool_t resetCameras=kFALSE, Bool_t dropLogicals=kFALSE)
Definition: TEveManager.h:168
TGButton::fState
EButtonState fState
Definition: TGButton.h:75
Event_t
Definition: GuiTypes.h:173
TEveElement::GetObject
virtual TObject * GetObject(const TEveException &eh) const
Get a TObject associated with this render-element.
Definition: TEveElement.cxx:937
kLHintsExpandX
@ kLHintsExpandX
Definition: TGLayout.h:43
TGedFrame::fGedEditor
TGedEditor * fGedEditor
Definition: TGedFrame.h:54
TEveGedEditor::CreateNameFrame
virtual TGedFrame * CreateNameFrame(const TGWindow *parent, const char *tab_name)
Create name-frame for a tab.
Definition: TEveGedEditor.cxx:104
TGedEditor::SetFrameCreator
static void SetFrameCreator(TGedEditor *e)
Set the TGedEditor that currently creates TGedFrames.
Definition: TGedEditor.cxx:94
TEveGedEditor::fObject
TObject * fObject
Definition: TEveGedEditor.h:36
TGClient::GetRoot
const TGWindow * GetRoot() const
Returns current root (i.e.
Definition: TGClient.cxx:225
TEveGedNameFrame::~TEveGedNameFrame
virtual ~TEveGedNameFrame()
Destructor.
Definition: TEveGedEditor.cxx:276
TGToolTip::Hide
void Hide()
Hide tool tip window.
Definition: TGToolTip.cxx:247
TEveGedNameTextButton::TEveGedNameTextButton
TEveGedNameTextButton(const TEveGedNameTextButton &)
TEveGedEditor::DisplayElement
void DisplayElement(TEveElement *re)
Show a TEveElement in editor.
Definition: TEveGedEditor.cxx:120
kMBIconStop
@ kMBIconStop
Definition: TGMsgBox.h:39
TObject::ClassName
virtual const char * ClassName() const
Returns name of class to which the object belongs.
Definition: TObject.cxx:130
TGCompositeFrame::AddFrame
virtual void AddFrame(TGFrame *f, TGLayoutHints *l=0)
Add frame to the composite frame using the specified layout hints.
Definition: TGFrame.cxx:1102
TEveGedNameTextButton::~TEveGedNameTextButton
virtual ~TEveGedNameTextButton()
Destructor.
Definition: TEveGedEditor.cxx:330
TGedEditor
Definition: TGedEditor.h:41
kButtonDisabled
@ kButtonDisabled
Definition: TGButton.h:62
TList
Definition: TList.h:44
int
TGedEditor::fPad
TVirtualPad * fPad
Definition: TGedEditor.h:60