Logo ROOT   6.08/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  DeleteWindow();
94 }
95 
96 ////////////////////////////////////////////////////////////////////////////////
97 /// This is exact clone of TGFrame::DeleteWindow().
98 /// Needs to be overriden together with CloseWindow() otherwise CINT
99 /// goes kaboom in timer execution.
100 
102 {
103  if (gDebug > 0)
104  Info("TEveGedEditor::DeleteWindow", "%p shooting timer.", this);
105 
106  DisplayElement(0);
107 
108  if (gDNDManager) {
109  if (gDNDManager->GetMainFrame() == this)
111  }
113  TTimer::SingleShot(150, IsA()->GetName(), this, "ReallyDelete()");
115 }
116 
117 ////////////////////////////////////////////////////////////////////////////////
118 /// Create name-frame for a tab.
119 
120 TGedFrame* TEveGedEditor::CreateNameFrame(const TGWindow* parent, const char* /*tab_name*/)
121 {
122  return new TEveGedNameFrame(parent);
123 }
124 
125 ////////////////////////////////////////////////////////////////////////////////
126 /// Return eve-element if it is the model object.
127 
129 {
130  return (fModel == fObject) ? fElement : 0;
131 }
132 
133 ////////////////////////////////////////////////////////////////////////////////
134 /// Show a TEveElement in editor.
135 
137 {
138  static const TEveException eh("TEveGedEditor::DisplayElement ");
139 
140  fElement = re;
143 }
144 
145 ////////////////////////////////////////////////////////////////////////////////
146 /// Show a TObject in editor.
147 
149 {
150  fElement = dynamic_cast<TEveElement*>(obj);
151  fObject = obj;
153 }
154 
155 ////////////////////////////////////////////////////////////////////////////////
156 /// Set model object.
157 
159 {
160  fElement = dynamic_cast<TEveElement*>(obj);
161  fObject = obj;
162  TGedEditor::SetModel(pad, obj, event);
163 }
164 
165 ////////////////////////////////////////////////////////////////////////////////
166 /// Virtual method from TGedEditor, called on every change.
167 /// Propagates changes to TEveElement and TEveManager.
168 
170 {
171  if (fElement)
172  {
175  }
176 
177  gEve->Redraw3D();
178 }
179 
180 ////////////////////////////////////////////////////////////////////////////////
181 /// Static function to create a new extra editor.
182 
184 {
186  {
187  new TGMsgBox(gClient->GetDefaultRoot(), gEve->GetMainWindow(),
188  "Clutter warning",
189  "Maximum number of extra editors reached.",
190  kMBIconStop, kMBOk);
191  }
192 
193  if (obj)
194  {
195  TEveGedEditor *ed = new TEveGedEditor();
196  ed->DisplayObject(obj);
197  ed->SetWindowName(Form("GED %s", obj->GetName()));
198 
199  fgExtraEditors->Add(ed);
200  }
201 }
202 
203 ////////////////////////////////////////////////////////////////////////////////
204 /// Element was changed. Update 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  ed->DisplayElement(el);
215  lnk = lnk->Next();
216  }
217 }
218 
219 ////////////////////////////////////////////////////////////////////////////////
220 /// Element is being deleted. Close editors showing it.
221 
223 {
224  TObject *eobj = el->GetEditorObject("TEveGedEditor::ElementChanged ");
226  while (lnk)
227  {
228  TEveGedEditor *ed = (TEveGedEditor*) lnk->GetObject();
229  if (ed->GetModel() == eobj)
230  {
231  TObjLink *next = lnk->Next();
232  ed->DeleteWindow();
233  fgExtraEditors->Remove(lnk);
234  lnk = next;
235  }
236  else
237  {
238  lnk = lnk->Next();
239  }
240  }
241 }
242 
243 ////////////////////////////////////////////////////////////////////////////////
244 /// Destroys all editors. Called from EVE termination.
245 
247 {
248  while ( ! fgExtraEditors->IsEmpty())
249  {
251  ed->DeleteWindow();
253  }
254 }
255 
256 ////////////////////////////////////////////////////////////////////////////////
257 /// Return context menu object shared among eve-ged-editors.
258 
260 {
261  if (fgContextMenu == 0)
262  fgContextMenu = new TContextMenu("", "");
263  return fgContextMenu;
264 }
265 
266 /** \class TEveGedNameFrame
267 \ingroup TEve
268 Specialization of TGedNameFrame used in EVE.
269 It provides the ability to undock given editor for easier use.
270 Support for that is also provided from the TEveManager.
271 */
272 
274 
275 ////////////////////////////////////////////////////////////////////////////////
276 /// Constructor.
277 
279  UInt_t options) :
280  TGedFrame(p, width, height, options),
281  fNCButton(0)
282 {
283  fNCButton = new TEveGedNameTextButton(this);
284  fNCButton->SetTextColor(0x0020a0);
286  fNCButton->Connect("Clicked()", "TEveGedNameFrame", this, "SpawnEditorClone()");
287 }
288 
289 ////////////////////////////////////////////////////////////////////////////////
290 /// Destructor.
291 
293 {
294 }
295 
296 ////////////////////////////////////////////////////////////////////////////////
297 /// Set model object.
298 
300 {
301  if (obj)
302  {
303  fNCButton->SetText(Form("%s [%s]", obj->GetName(), obj->ClassName()));
306  }
307  else
308  {
309  fNCButton->SetText("No object selected.");
312  }
313 }
314 
315 ////////////////////////////////////////////////////////////////////////////////
316 /// Create a new floating editor with current object.
317 
319 {
321 }
322 
323 /** \class TEveGedNameTextButton
324 \ingroup TEve
325 Specialization of TGTextButton for EVE name frame.
326 It opens a context-menu on right-click.
327 */
328 
330 
331 ////////////////////////////////////////////////////////////////////////////////
332 /// Constructor.
333 
335  TGTextButton(p, ""),
336  fFrame(p)
337 {
338  gVirtualX->GrabButton(fId, kAnyButton, kAnyModifier,
340  kNone, kNone);
341 }
342 
343 ////////////////////////////////////////////////////////////////////////////////
344 /// Destructor.
345 
347 {
348 }
349 
350 ////////////////////////////////////////////////////////////////////////////////
351 /// Handle button.
352 
354 {
355  static const TEveException eh("TEveGedNameTextButton::HandleButton ");
356 
357  if (fTip) fTip->Hide();
358  if (fState == kButtonDisabled) return kTRUE;
359 
360  if (event->fCode == kButton3 && event->fType == kButtonPress)
361  {
363  TEveElement *el = eged->GetEveElement();
364  if (el)
366  el->GetObject(eh));
367  return 1;
368  }
369  else if (event->fCode == kButton1)
370  {
371  return TGTextButton::HandleButton(event);
372  }
373  else
374  {
375  return 0;
376  }
377 }
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:899
void DisplayObject(TObject *obj)
Show a TObject in editor.
void SetRoot(TGWindow *root=0)
Sets the current root (i.e.
Definition: TGClient.cxx:242
virtual void DeleteWindow()
This is exact clone of TGFrame::DeleteWindow().
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
Bool_t TestBit(UInt_t f) const
Definition: TObject.h:157
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:174
static void SingleShot(Int_t milliSec, const char *receiver_class, void *receiver, const char *method)
This static function calls a slot after a given time interval.
Definition: TTimer.cxx:256
TEveGedEditor(const TEveGedEditor &)
TMap fFrameMap
Definition: TGedEditor.h:56
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
const Bool_t kFALSE
Definition: Rtypes.h:92
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:166
virtual void SetModel(TVirtualPad *pad, TObject *obj, Int_t event)
Activate object editors according to the selected object.
Definition: TGedEditor.cxx:349
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 SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
Definition: TObject.cxx:739
void SpawnEditorClone()
Create a new floating editor with current object.
R__EXTERN TGDNDManager * gDNDManager
Definition: TGDNDManager.h:205
virtual const char * ClassName() const
Returns name of class to which the object belongs.
Definition: TObject.cxx:188
virtual Bool_t HandleButton(Event_t *event)
Handle mouse button event.
Definition: TGButton.cxx:280
virtual TObject * GetModel() const
Definition: TGedEditor.h:98
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:180
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:59
TGWindow * GetMainWindow() const
Get the main window, i.e. EVE-browser.
A doubly linked list.
Definition: TList.h:47
const Mask_t kButtonPressMask
Definition: GuiTypes.h:162
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:1137
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:557
static void ElementChanged(TEveElement *el)
Element was changed. Update editors showing it.
EGEventType fType
Definition: GuiTypes.h:176
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:675
virtual const char * GetName() const
Return unique name, used in SavePrimitive methods.
Definition: TGWindow.cxx:221
This class provides an interface to context sensitive popup menus.
Definition: TContextMenu.h:44
unsigned int UInt_t
Definition: RtypesCore.h:42
char * Form(const char *fmt,...)
const Handle_t kNone
Definition: GuiTypes.h:89
TObject * fObject
Definition: TEveGedEditor.h:36
Specialization of TGedNameFrame used in EVE.
Definition: TEveGedEditor.h:78
TGToolTip * fTip
Definition: TGButton.h:83
Int_t fYRoot
Definition: GuiTypes.h:180
The ROOT global object gROOT contains a list of all defined classes.
Definition: TClass.h:81
TGedEditor * GetGedEditor()
Definition: TGedFrame.h:79
TVirtualPad * fPad
Definition: TGedEditor.h:68
virtual ~TEveGedNameTextButton()
Destructor.
static TContextMenu * fgContextMenu
Definition: TEveGedEditor.h:43
#define gVirtualX
Definition: TVirtualX.h:362
virtual TObjLink * FirstLink() const
Definition: TList.h:101
virtual void SetText(TGHotString *new_label)
Set new button text.
Definition: TGButton.cxx:594
The Canvas class.
Definition: TCanvas.h:41
virtual void SetModel(TVirtualPad *pad, TObject *obj, Int_t event)
Set model object.
virtual Bool_t IsEmpty() const
Definition: TCollection.h:99
#define ClassImp(name)
Definition: Rtypes.h:279
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:163
UInt_t fCode
Definition: GuiTypes.h:181
Long_t GetDataMemberOffset(const char *membername) const
return offset for member name.
Definition: TClass.cxx:3261
TGTextButton * fNCButton
Definition: TEveGedEditor.h:85
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:2893
virtual TObject * GetObject(const TEveException &eh) const
Get a TObject associated with this render-element.
Handle_t fId
Definition: TGObject.h:40
Mother of all ROOT objects.
Definition: TObject.h:37
TObject * fModel
Definition: TGedEditor.h:67
virtual const char * GetTitle() const
Returns title of object.
Definition: TObject.cxx:460
TEveGedNameTextButton(const TEveGedNameTextButton &)
virtual void Add(TObject *obj)
Definition: TList.h:81
TGFrame * GetMainFrame() const
Definition: TGDNDManager.h:165
TGClient * fClient
Definition: TGObject.h:41
Exception class thrown by TEve classes and macros.
Definition: TEveUtil.h:102
R__EXTERN Int_t gDebug
Definition: Rtypes.h:128
TEveGedNameFrame * fFrame
EButtonState fState
Definition: TGButton.h:79
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:416
virtual Int_t GetSize() const
Definition: TCollection.h:95
const Bool_t kTRUE
Definition: Rtypes.h:91
const Mask_t kAnyModifier
Definition: GuiTypes.h:211
TGedEditor * fGedEditor
Definition: TGedFrame.h:56
TEveGedNameFrame(const TEveGedNameFrame &)
virtual TObject * GetEditorObject(const TEveException &eh) const
Definition: TEveElement.h:197
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:86
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition: TObject.cxx:911
static TList * fgExtraEditors
Definition: TEveGedEditor.h:41
TGCompositeFrame * fTabContainer
Definition: TGedEditor.h:65
Definition: TGMsgBox.h:52
virtual void SetGedEditor(TGedEditor *ed)
Definition: TGedFrame.h:88
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:4714