Logo ROOT   6.12/07
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 "TGButton.h"
17 #include "TGLabel.h"
18 #include "TGToolTip.h"
19 #include "TGDNDManager.h"
20 #include "TGMsgBox.h"
21 
22 #include "TClass.h"
23 #include "TContextMenu.h"
24 
25 /** \class TEveGedEditor
26 \ingroup TEve
27 Specialization of TGedEditor for proper update propagation to TEveManager.
28 */
29 
31 
34 
36 
37 ////////////////////////////////////////////////////////////////////////////////
38 /// Constructor.
39 
41  TGedEditor(canvas, width, height),
42  fElement (0),
43  fObject (0)
44 {
45  // Remove old name-frame -- it is created in TGedEditor constructor
46  // so virtuals are not active yet.
48  TGedFrame* nf = CreateNameFrame(fTabContainer, "Style");
49  nf->SetGedEditor(this);
50  nf->SetModelClass(0);
52 
53  // Fix priority for TAttMarkerEditor.
54  TClass* amClass = TClass::GetClass("TAttMarker");
55  TClass* edClass = TClass::GetClass("TAttMarkerEditor");
56  TGWindow *exroot = (TGWindow*) fClient->GetRoot();
58  SetFrameCreator(this);
59  TGedFrame *frame = reinterpret_cast<TGedFrame*>(edClass->New());
60  frame->SetModelClass(amClass);
61  {
62  Int_t off = edClass->GetDataMemberOffset("fPriority");
63  if (off == 0)
64  Warning("TEveGedEditor::TEveGedEditor", "Can't fix priority for TAttMarkerEditor.\n");
65  else
66  * (Int_t*) (((char*)frame) + off) = 1;
67  }
68  SetFrameCreator(0);
69  fClient->SetRoot(exroot);
70  fFrameMap.Add(amClass, frame);
71 }
72 
73 ////////////////////////////////////////////////////////////////////////////////
74 /// Destructor.
75 
77 {
78  if (gDebug > 0)
79  Info("TEveGedEditor::~TEveGedEditor", "%p going down.", this);
80 }
81 
82 ////////////////////////////////////////////////////////////////////////////////
83 /// Called from window-manger close button.
84 /// Unregister from global list and delete the window.
85 
87 {
88  if (gDebug > 0)
89  Info("TEveGedEditor::CloseWindow", "%p closing.", this);
90 
91  fgExtraEditors->Remove(this);
92 
93  DisplayElement(0);
94 
95  if (gDNDManager) {
96  if (gDNDManager->GetMainFrame() == this)
98  }
99  DeleteWindow();
100 }
101 
102 ////////////////////////////////////////////////////////////////////////////////
103 /// Create name-frame for a tab.
104 
105 TGedFrame* TEveGedEditor::CreateNameFrame(const TGWindow* parent, const char* /*tab_name*/)
106 {
107  return new TEveGedNameFrame(parent);
108 }
109 
110 ////////////////////////////////////////////////////////////////////////////////
111 /// Return eve-element if it is the model object.
112 
114 {
115  return (fModel == fObject) ? fElement : 0;
116 }
117 
118 ////////////////////////////////////////////////////////////////////////////////
119 /// Show a TEveElement in editor.
120 
122 {
123  static const TEveException eh("TEveGedEditor::DisplayElement ");
124 
125  fElement = re;
128 }
129 
130 ////////////////////////////////////////////////////////////////////////////////
131 /// Show a TObject in editor.
132 
134 {
135  fElement = dynamic_cast<TEveElement*>(obj);
136  fObject = obj;
138 }
139 
140 ////////////////////////////////////////////////////////////////////////////////
141 /// Set model object.
142 
144 {
145  fElement = dynamic_cast<TEveElement*>(obj);
146  fObject = obj;
147  TGedEditor::SetModel(pad, obj, event, force);
148 }
149 
150 ////////////////////////////////////////////////////////////////////////////////
151 /// Virtual method from TGedEditor, called on every change.
152 /// Propagates changes to TEveElement and TEveManager.
153 
155 {
156  if (fElement)
157  {
160  }
161 
162  gEve->Redraw3D();
163 }
164 
165 ////////////////////////////////////////////////////////////////////////////////
166 /// Static function to create a new extra editor.
167 
169 {
171  {
172  new TGMsgBox(gClient->GetDefaultRoot(), gEve->GetMainWindow(),
173  "Clutter warning",
174  "Maximum number of extra editors reached.",
175  kMBIconStop, kMBOk);
176  }
177 
178  if (obj)
179  {
180  TEveGedEditor *ed = new TEveGedEditor();
181  ed->DisplayObject(obj);
182  ed->SetWindowName(Form("GED %s", obj->GetName()));
183 
184  fgExtraEditors->Add(ed);
185  }
186 }
187 
188 ////////////////////////////////////////////////////////////////////////////////
189 /// Element was changed. Update editors showing it.
190 
192 {
193  TObject *eobj = el->GetEditorObject("TEveGedEditor::ElementChanged ");
195  while (lnk)
196  {
197  TEveGedEditor *ed = (TEveGedEditor*) lnk->GetObject();
198  if (ed->GetModel() == eobj)
199  ed->DisplayElement(el);
200  lnk = lnk->Next();
201  }
202 }
203 
204 ////////////////////////////////////////////////////////////////////////////////
205 /// Element is being deleted. Close editors showing it.
206 
208 {
209  TObject *eobj = el->GetEditorObject("TEveGedEditor::ElementChanged ");
211  while (lnk)
212  {
213  TEveGedEditor *ed = (TEveGedEditor*) lnk->GetObject();
214  if (ed->GetModel() == eobj)
215  {
216  TObjLink *next = lnk->Next();
217  ed->DeleteWindow();
218  fgExtraEditors->Remove(lnk);
219  lnk = next;
220  }
221  else
222  {
223  lnk = lnk->Next();
224  }
225  }
226 }
227 
228 ////////////////////////////////////////////////////////////////////////////////
229 /// Destroys all editors. Called from EVE termination.
230 
232 {
233  while ( ! fgExtraEditors->IsEmpty())
234  {
236  ed->DeleteWindow();
238  }
239 }
240 
241 ////////////////////////////////////////////////////////////////////////////////
242 /// Return context menu object shared among eve-ged-editors.
243 
245 {
246  if (fgContextMenu == 0)
247  fgContextMenu = new TContextMenu("", "");
248  return fgContextMenu;
249 }
250 
251 /** \class TEveGedNameFrame
252 \ingroup TEve
253 Specialization of TGedNameFrame used in EVE.
254 It provides the ability to undock given editor for easier use.
255 Support for that is also provided from the TEveManager.
256 */
257 
259 
260 ////////////////////////////////////////////////////////////////////////////////
261 /// Constructor.
262 
264  UInt_t options) :
265  TGedFrame(p, width, height, options),
266  fNCButton(0)
267 {
268  fNCButton = new TEveGedNameTextButton(this);
269  fNCButton->SetTextColor(0x0020a0);
271  fNCButton->Connect("Clicked()", "TEveGedNameFrame", this, "SpawnEditorClone()");
272 }
273 
274 ////////////////////////////////////////////////////////////////////////////////
275 /// Destructor.
276 
278 {
279 }
280 
281 ////////////////////////////////////////////////////////////////////////////////
282 /// Set model object.
283 
285 {
286  if (obj)
287  {
288  fNCButton->SetText(Form("%s [%s]", obj->GetName(), obj->ClassName()));
291  }
292  else
293  {
294  fNCButton->SetText("No object selected.");
297  }
298 }
299 
300 ////////////////////////////////////////////////////////////////////////////////
301 /// Create a new floating editor with current object.
302 
304 {
306 }
307 
308 /** \class TEveGedNameTextButton
309 \ingroup TEve
310 Specialization of TGTextButton for EVE name frame.
311 It opens a context-menu on right-click.
312 */
313 
315 
316 ////////////////////////////////////////////////////////////////////////////////
317 /// Constructor.
318 
320  TGTextButton(p, ""),
321  fFrame(p)
322 {
323  gVirtualX->GrabButton(fId, kAnyButton, kAnyModifier,
325  kNone, kNone);
326 }
327 
328 ////////////////////////////////////////////////////////////////////////////////
329 /// Destructor.
330 
332 {
333 }
334 
335 ////////////////////////////////////////////////////////////////////////////////
336 /// Handle button.
337 
339 {
340  static const TEveException eh("TEveGedNameTextButton::HandleButton ");
341 
342  if (fTip) fTip->Hide();
343  if (fState == kButtonDisabled) return kTRUE;
344 
345  if (event->fCode == kButton3 && event->fType == kButtonPress)
346  {
348  TEveElement *el = eged->GetEveElement();
349  if (el)
351  el->GetObject(eh));
352  return 1;
353  }
354  else if (event->fCode == kButton1)
355  {
356  return TGTextButton::HandleButton(event);
357  }
358  else
359  {
360  return 0;
361  }
362 }
static Int_t fgMaxExtraEditors
Definition: TEveGedEditor.h:40
void DisplayElement(TEveElement *re)
Show a TEveElement in editor.
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
Definition: TObject.cxx:854
void DisplayObject(TObject *obj)
Show a TObject in editor.
void SetRoot(TGWindow *root=0)
Sets the current root (i.e.
Definition: TGClient.cxx:242
static void SpawnNewEditor(TObject *obj)
Static function to create a new extra editor.
Specialization of TGedEditor for proper update propagation to TEveManager.
Definition: TEveGedEditor.h:26
void SetWindowName(const char *name=0)
Set window name. This is typically done via the window manager.
Definition: TGFrame.cxx:1746
const TGWindow * GetRoot() const
Returns current root (i.e.
Definition: TGClient.cxx:222
Specialization of TGTextButton for EVE name frame.
TEveElement * fElement
Definition: TEveGedEditor.h:35
static void DestroyEditors()
Destroys all editors. Called from EVE termination.
virtual void SetTextColor(Pixel_t color, Bool_t global=kFALSE)
Changes text color.
Definition: TGButton.cxx:868
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:53
#define gClient
Definition: TGClient.h:166
TEveGedEditor(const TEveGedEditor &)
TMap fFrameMap
Definition: TGedEditor.h:48
virtual void RemoveAll()
Remove all frames from composite frame.
Definition: TGFrame.cxx:1113
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
void Hide()
Hide tool tip window.
Definition: TGToolTip.cxx:246
void Redraw3D(Bool_t resetCameras=kFALSE, Bool_t dropLogicals=kFALSE)
Definition: TEveManager.h:168
void SetMainFrame(TGFrame *main)
Definition: TGDNDManager.h:164
static void SetFrameCreator(TGedEditor *e)
Set the TGedEditor that currently creates TGedFrames.
Definition: TGedEditor.cxx:93
virtual ~TEveGedEditor()
Destructor.
virtual ~TEveGedNameFrame()
Destructor.
virtual void PropagateVizParamsToProjecteds()
Propagate visualization parameters to dependent elements.
void SpawnEditorClone()
Create a new floating editor with current object.
R__EXTERN TGDNDManager * gDNDManager
Definition: TGDNDManager.h:203
virtual void SetModel(TVirtualPad *pad, TObject *obj, Int_t event, Bool_t force=kFALSE)
Set model object.
virtual const char * ClassName() const
Returns name of class to which the object belongs.
Definition: TObject.cxx:128
virtual Bool_t HandleButton(Event_t *event)
Handle mouse button event.
Definition: TGButton.cxx:280
virtual TObject * GetModel() const
Definition: TGedEditor.h:90
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...
static TContextMenu * GetContextMenu()
Return context menu object shared among eve-ged-editors.
Int_t fXRoot
Definition: GuiTypes.h:178
virtual void Popup(Int_t x, Int_t y, TObject *obj, TVirtualPad *c=0, TVirtualPad *p=0)
Popup context menu at given location in canvas c and pad p for selected object.
virtual void CloseWindow()
Called from window-manger close button.
TVirtualPad is an abstract base class for the Pad and Canvas classes.
Definition: TVirtualPad.h:49
TGWindow * GetMainWindow() const
Get the main window, i.e. EVE-browser.
A doubly linked list.
Definition: TList.h:44
const Mask_t kButtonPressMask
Definition: GuiTypes.h:160
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:867
virtual void SetModel(TObject *obj)
Set model object.
virtual TObject * First() const
Return the first object in the list. Returns 0 when list is empty.
Definition: TList.cxx:655
static void ElementChanged(TEveElement *el)
Element was changed. Update editors showing it.
EGEventType fType
Definition: GuiTypes.h:174
R__EXTERN TEveManager * gEve
Definition: TEveManager.h:243
virtual TGedFrame * CreateNameFrame(const TGWindow *parent, const char *tab_name)
Create name-frame for a tab.
virtual TObject * Remove(TObject *obj)
Remove object from the list.
Definition: TList.cxx:818
This class provides an interface to context sensitive popup menus.
Definition: TContextMenu.h:40
unsigned int UInt_t
Definition: RtypesCore.h:42
char * Form(const char *fmt,...)
const Handle_t kNone
Definition: GuiTypes.h:87
TObject * fObject
Definition: TEveGedEditor.h:36
Specialization of TGedNameFrame used in EVE.
Definition: TEveGedEditor.h:77
TGToolTip * fTip
Definition: TGButton.h:79
Int_t fYRoot
Definition: GuiTypes.h:178
The ROOT global object gROOT contains a list of all defined classes.
Definition: TClass.h:75
TGedEditor * GetGedEditor()
Definition: TGedFrame.h:77
TVirtualPad * fPad
Definition: TGedEditor.h:60
virtual ~TEveGedNameTextButton()
Destructor.
static TContextMenu * fgContextMenu
Definition: TEveGedEditor.h:43
#define gVirtualX
Definition: TVirtualX.h:350
virtual TObjLink * FirstLink() const
Definition: TList.h:108
const Bool_t kFALSE
Definition: RtypesCore.h:88
virtual void SetText(TGHotString *new_label)
Set new button text.
Definition: TGButton.cxx:594
The Canvas class.
Definition: TCanvas.h:31
virtual Bool_t IsEmpty() const
Definition: TCollection.h:184
#define ClassImp(name)
Definition: Rtypes.h:359
virtual void SetEnabled(Bool_t e=kTRUE)
Set enabled or disabled state of button.
Definition: TGButton.cxx:409
const Mask_t kButtonReleaseMask
Definition: GuiTypes.h:161
UInt_t fCode
Definition: GuiTypes.h:179
Long_t GetDataMemberOffset(const char *membername) const
return offset for member name.
Definition: TClass.cxx:3308
TGTextButton * fNCButton
Definition: TEveGedEditor.h:84
virtual void Update(TGedFrame *gframe=0)
Virtual method from TGedEditor, called on every change.
virtual void AddFrame(TGFrame *f, TGLayoutHints *l=0)
Add frame to the composite frame using the specified layout hints.
Definition: TGFrame.cxx:1099
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:2887
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:349
virtual TObject * GetObject(const TEveException &eh) const
Get a TObject associated with this render-element.
Handle_t fId
Definition: TGObject.h:36
Mother of all ROOT objects.
Definition: TObject.h:37
TObject * fModel
Definition: TGedEditor.h:59
virtual const char * GetTitle() const
Returns title of object.
Definition: TObject.cxx:401
TEveGedNameTextButton(const TEveGedNameTextButton &)
virtual void Add(TObject *obj)
Definition: TList.h:87
TGFrame * GetMainFrame() const
Definition: TGDNDManager.h:163
TGClient * fClient
Definition: TGObject.h:37
Exception class thrown by TEve classes and macros.
Definition: TEveUtil.h:102
R__EXTERN Int_t gDebug
Definition: Rtypes.h:86
TEveGedNameFrame * fFrame
EButtonState fState
Definition: TGButton.h:75
static void ElementDeleted(TEveElement *el)
Element is being deleted. Close editors showing it.
virtual const char * GetName() const
Returns name of object.
Definition: TObject.cxx:357
virtual Int_t GetSize() const
Definition: TCollection.h:180
virtual void DeleteWindow()
Delete window.
Definition: TGFrame.cxx:258
const Mask_t kAnyModifier
Definition: GuiTypes.h:209
TGedEditor * fGedEditor
Definition: TGedFrame.h:54
TEveGedNameFrame(const TEveGedNameFrame &)
virtual TObject * GetEditorObject(const TEveException &eh) const
Definition: TEveElement.h:197
const Bool_t kTRUE
Definition: RtypesCore.h:87
TEveElement * GetEveElement() const
Return eve-element if it is the model object.
virtual Bool_t HandleButton(Event_t *event)
Handle button.
Base class for TEveUtil visualization elements, providing hierarchy management, rendering control and...
Definition: TEveElement.h:33
virtual void SetToolTipText(const char *text, Long_t delayms=400)
Set tool tip text associated with this button.
Definition: TGButton.cxx:395
void SetModelClass(TClass *mcl)
Definition: TGedFrame.h:84
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition: TObject.cxx:866
static TList * fgExtraEditors
Definition: TEveGedEditor.h:41
TGCompositeFrame * fTabContainer
Definition: TGedEditor.h:57
Definition: TGMsgBox.h:44
virtual void SetGedEditor(TGedEditor *ed)
Definition: TGedFrame.h:86
virtual void RemoveFirst()
void * New(ENewType defConstructor=kClassNew, Bool_t quiet=kFALSE) const
Return a pointer to a newly allocated object of this class.
Definition: TClass.cxx:4792