TEveGedEditor.cxx

Go to the documentation of this file.
00001 // @(#)root/eve:$Id: TEveGedEditor.cxx 36373 2010-10-19 17:43:35Z matevz $
00002 // Authors: Matevz Tadel & Alja Mrak-Tadel: 2006, 2007
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2007, Rene Brun and Fons Rademakers.               *
00006  * All rights reserved.                                                  *
00007  *                                                                       *
00008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00010  *************************************************************************/
00011 
00012 #include "TEveGedEditor.h"
00013 #include "TEveElement.h"
00014 #include "TEveManager.h"
00015 
00016 #include "TGButton.h"
00017 #include "TGLabel.h"
00018 #include "TGToolTip.h"
00019 #include "TGDNDManager.h"
00020 #include "TGMsgBox.h"
00021 
00022 #include "TClass.h"
00023 #include "TContextMenu.h"
00024 
00025 //==============================================================================
00026 // TEveGedEditor
00027 //==============================================================================
00028 
00029 //______________________________________________________________________________
00030 //
00031 // Specialization of TGedEditor for proper update propagation to
00032 // TEveManager.
00033 
00034 ClassImp(TEveGedEditor);
00035 
00036 Int_t   TEveGedEditor::fgMaxExtraEditors = 10;
00037 TList  *TEveGedEditor::fgExtraEditors    = new TList;
00038 
00039 TContextMenu *TEveGedEditor::fgContextMenu = 0;
00040 
00041 //______________________________________________________________________________
00042 TEveGedEditor::TEveGedEditor(TCanvas* canvas, UInt_t width, UInt_t height) :
00043    TGedEditor(canvas, width, height),
00044    fElement  (0),
00045    fObject   (0)
00046 {
00047    // Constructor.
00048 
00049    // Remove old name-frame -- it is created in TGedEditor constructor
00050    // so virtuals are not active yet.
00051    fTabContainer->RemoveAll();
00052    TGedFrame* nf = CreateNameFrame(fTabContainer, "Style");
00053    nf->SetGedEditor(this);
00054    nf->SetModelClass(0);
00055    fTabContainer->AddFrame(nf, new TGLayoutHints(kLHintsTop | kLHintsExpandX, 2, 2, 2, 2));
00056 
00057    // Fix priority for TAttMarkerEditor.
00058    TClass* amClass = TClass::GetClass("TAttMarker");
00059    TClass* edClass = TClass::GetClass("TAttMarkerEditor");
00060    TGWindow *exroot = (TGWindow*) fClient->GetRoot();
00061    fClient->SetRoot(fTabContainer);
00062    SetFrameCreator(this);
00063    TGedFrame *frame = reinterpret_cast<TGedFrame*>(edClass->New());
00064    frame->SetModelClass(amClass);
00065    {
00066       Int_t off = edClass->GetDataMemberOffset("fPriority");
00067       if (off == 0)
00068          Warning("TEveGedEditor::TEveGedEditor", "Can't fix priority for TAttMarkerEditor.\n");
00069       else
00070          * (Int_t*) (((char*)frame) + off) = 1;
00071    }
00072    SetFrameCreator(0);
00073    fClient->SetRoot(exroot);
00074    fFrameMap.Add(amClass, frame);
00075 }
00076 
00077 //______________________________________________________________________________
00078 TEveGedEditor::~TEveGedEditor()
00079 {
00080    // Destructor.
00081 
00082    if (gDebug > 0)
00083       Info("TEveGedEditor::~TEveGedEditor", "%p going down.", this);
00084 }
00085 
00086 //______________________________________________________________________________
00087 void TEveGedEditor::CloseWindow()
00088 {
00089    // Called from window-manger close button.
00090    // Unregister from global list and delete the window.
00091 
00092    if (gDebug > 0)
00093       Info("TEveGedEditor::CloseWindow", "%p closing.", this);
00094 
00095    fgExtraEditors->Remove(this);
00096 
00097    DeleteWindow();
00098 }
00099 
00100 //______________________________________________________________________________
00101 void TEveGedEditor::DeleteWindow()
00102 {
00103    // This is exact clone of TGFrame::DeleteWindow().
00104    // Needs to be overriden together with CloseWindow() otherwise CINT
00105    // goes kaboom in timer execution.
00106 
00107    if (gDebug > 0)
00108       Info("TEveGedEditor::DeleteWindow", "%p shooting timer.", this);
00109 
00110    DisplayElement(0);
00111 
00112    if (gDNDManager) {
00113       if (gDNDManager->GetMainFrame() == this)
00114          gDNDManager->SetMainFrame(0);
00115    }
00116    if (!TestBit(kDeleteWindowCalled))
00117       TTimer::SingleShot(150, IsA()->GetName(), this, "ReallyDelete()");
00118    SetBit(kDeleteWindowCalled);
00119 }
00120 
00121 //______________________________________________________________________________
00122 TGedFrame* TEveGedEditor::CreateNameFrame(const TGWindow* parent, const char* /*tab_name*/)
00123 {
00124    // Create name-frame for a tab.
00125 
00126    return new TEveGedNameFrame(parent);
00127 }
00128 
00129 //______________________________________________________________________________
00130 TEveElement* TEveGedEditor::GetEveElement() const
00131 {
00132    // Return eve-element if it is the model object.
00133 
00134    return (fModel == fObject) ? fElement : 0;
00135 }
00136 
00137 //______________________________________________________________________________
00138 void TEveGedEditor::DisplayElement(TEveElement* re)
00139 {
00140    // Show a TEveElement in editor.
00141 
00142    static const TEveException eh("TEveGedEditor::DisplayElement ");
00143 
00144    fElement = re;
00145    fObject  = fElement ? fElement->GetEditorObject(eh) : 0;
00146    TGedEditor::SetModel(fPad, fObject, kButton1Down);
00147 }
00148 
00149 //______________________________________________________________________________
00150 void TEveGedEditor::DisplayObject(TObject* obj)
00151 {
00152    // Show a TObject in editor.
00153 
00154    fElement = dynamic_cast<TEveElement*>(obj);
00155    fObject  = obj;
00156    TGedEditor::SetModel(fPad, obj, kButton1Down);
00157 }
00158 
00159 //==============================================================================
00160 
00161 //______________________________________________________________________________
00162 void TEveGedEditor::SetModel(TVirtualPad* pad, TObject* obj, Int_t event)
00163 {
00164    // Set model object.
00165 
00166    fElement = dynamic_cast<TEveElement*>(obj);
00167    fObject  = obj;
00168    TGedEditor::SetModel(pad, obj, event);
00169 }
00170 
00171 //______________________________________________________________________________
00172 void TEveGedEditor::Update(TGedFrame* /*gframe*/)
00173 {
00174    // Virtual method from TGedEditor, called on every change.
00175    // Propagates changes to TEveElement and TEveManager.
00176 
00177    if (fElement)
00178    {
00179       fElement->ElementChanged();
00180       fElement->PropagateVizParamsToProjecteds();
00181    }
00182 
00183    gEve->Redraw3D();
00184 }
00185 
00186 //------------------------------------------------------------------------------
00187 // Static functions for management of extra editors.
00188 //------------------------------------------------------------------------------
00189 
00190 //______________________________________________________________________________
00191 void TEveGedEditor::SpawnNewEditor(TObject* obj)
00192 {
00193    // Static function to create a new extra editor.
00194 
00195    if (fgExtraEditors->GetSize() >= fgMaxExtraEditors)
00196    {
00197       new TGMsgBox(gClient->GetDefaultRoot(), gEve->GetMainWindow(),
00198                    "Clutter warning", 
00199                    "Maximum number of extra editors reached.",
00200                    kMBIconStop, kMBOk);
00201    }
00202 
00203    if (obj)
00204    {
00205       TEveGedEditor *ed = new TEveGedEditor();
00206       ed->DisplayObject(obj);
00207       ed->SetWindowName(Form("GED %s", obj->GetName()));
00208 
00209       fgExtraEditors->Add(ed);
00210    }
00211 }
00212 
00213 //______________________________________________________________________________
00214 void TEveGedEditor::ElementChanged(TEveElement* el)
00215 {
00216    // Element was changed. Update editors showing it.
00217 
00218    TObject *eobj = el->GetEditorObject("TEveGedEditor::ElementChanged ");
00219    TObjLink *lnk = fgExtraEditors->FirstLink();
00220    while (lnk)
00221    {
00222       TEveGedEditor *ed = (TEveGedEditor*) lnk->GetObject();
00223       if (ed->GetModel() == eobj)
00224          ed->DisplayElement(el);
00225       lnk = lnk->Next();
00226    }
00227 }
00228 
00229 //______________________________________________________________________________
00230 void TEveGedEditor::ElementDeleted(TEveElement* el)
00231 {
00232    // Element is being deleted. Close editors showing it.
00233 
00234    TObject *eobj = el->GetEditorObject("TEveGedEditor::ElementChanged ");
00235    TObjLink *lnk = fgExtraEditors->FirstLink();
00236    while (lnk)
00237    {
00238       TEveGedEditor *ed = (TEveGedEditor*) lnk->GetObject();
00239       if (ed->GetModel() == eobj)
00240       {
00241          TObjLink *next = lnk->Next();
00242          ed->DeleteWindow();
00243          fgExtraEditors->Remove(lnk);
00244          lnk = next;
00245       }
00246       else
00247       {
00248          lnk = lnk->Next();
00249       }
00250    }
00251 }
00252 
00253 //______________________________________________________________________________
00254 void TEveGedEditor::DestroyEditors()
00255 {
00256    // Destroys all editors. Called from EVE termination.
00257 
00258    while ( ! fgExtraEditors->IsEmpty())
00259    {
00260       TEveGedEditor *ed = (TEveGedEditor*) fgExtraEditors->First();
00261       ed->DeleteWindow();
00262       fgExtraEditors->RemoveFirst();
00263    }
00264 }
00265 
00266 //______________________________________________________________________________
00267 TContextMenu* TEveGedEditor::GetContextMenu()
00268 {
00269    // Return context menu object shared among eve-ged-editors.
00270 
00271    if (fgContextMenu == 0)
00272       fgContextMenu = new TContextMenu("", "");
00273    return fgContextMenu;
00274 }
00275 
00276 
00277 //==============================================================================
00278 // TEveGedNameFrame
00279 //==============================================================================
00280 
00281 //______________________________________________________________________________
00282 //
00283 // Specialization of TGedNameFrame used in EVE.
00284 // It provides the ability to undock given editor for easier use.
00285 // Support for that is also provided from the TEveManager.
00286 
00287 ClassImp(TEveGedNameFrame);
00288 
00289 //______________________________________________________________________________
00290 TEveGedNameFrame::TEveGedNameFrame(const TGWindow *p, Int_t width, Int_t height,
00291                                    UInt_t options) :
00292    TGedFrame(p, width, height, options),
00293    fNCButton(0)
00294 {
00295    // Constructor.
00296 
00297    fNCButton = new TEveGedNameTextButton(this);
00298    fNCButton->SetTextColor(0x0020a0);
00299    AddFrame(fNCButton, new TGLayoutHints(kLHintsNormal | kLHintsExpandX));
00300    fNCButton->Connect("Clicked()", "TEveGedNameFrame", this, "SpawnEditorClone()");
00301 }
00302 
00303 //______________________________________________________________________________
00304 TEveGedNameFrame::~TEveGedNameFrame()
00305 {
00306    // Destructor.
00307 }
00308 
00309 //______________________________________________________________________________
00310 void TEveGedNameFrame::SetModel(TObject* obj)
00311 {
00312    // Set model object.
00313 
00314    if (obj)
00315    {
00316       fNCButton->SetText(Form("%s [%s]", obj->GetName(), obj->ClassName()));
00317       fNCButton->SetToolTipText(obj->GetTitle());
00318       fNCButton->SetEnabled(kTRUE);
00319    }
00320    else
00321    {
00322       fNCButton->SetText("No object selected.");
00323       fNCButton->SetToolTipText(0);
00324       fNCButton->SetEnabled(kFALSE);
00325    }
00326 }
00327 
00328 //______________________________________________________________________________
00329 void TEveGedNameFrame::SpawnEditorClone()
00330 {
00331    // Create a new floating editor with current object.
00332 
00333    TEveGedEditor::SpawnNewEditor(fGedEditor->GetModel());
00334 }
00335 
00336 
00337 //==============================================================================
00338 // TEveGedNameTextButton
00339 //==============================================================================
00340 
00341 //______________________________________________________________________________
00342 //
00343 // Specialization of TGTextButton for EVE name frame.
00344 // It opens a context-menu on right-click.
00345 
00346 ClassImp(TEveGedNameTextButton);
00347 
00348 //______________________________________________________________________________
00349 TEveGedNameTextButton::TEveGedNameTextButton(TEveGedNameFrame* p) :
00350    TGTextButton(p, ""),
00351    fFrame(p)
00352 {
00353    // Constructor.
00354 
00355    gVirtualX->GrabButton(fId, kAnyButton, kAnyModifier,
00356                          kButtonPressMask | kButtonReleaseMask,
00357                          kNone, kNone);
00358 }
00359 
00360 //______________________________________________________________________________
00361 TEveGedNameTextButton::~TEveGedNameTextButton()
00362 {
00363    // Destructor.
00364 }
00365 
00366 //______________________________________________________________________________
00367 Bool_t TEveGedNameTextButton::HandleButton(Event_t* event)
00368 {
00369    // Handle button.
00370 
00371    static const TEveException eh("TEveGedNameTextButton::HandleButton ");
00372 
00373    if (fTip) fTip->Hide();
00374    if (fState == kButtonDisabled) return kTRUE;
00375 
00376    if (event->fCode == kButton3 && event->fType == kButtonPress)
00377    {
00378       TEveGedEditor *eged = (TEveGedEditor*) fFrame->GetGedEditor();
00379       TEveElement   *el   = eged->GetEveElement();
00380       if (el)
00381          TEveGedEditor::GetContextMenu()->Popup(event->fXRoot, event->fYRoot,
00382                                                 el->GetObject(eh));
00383       return 1;
00384    }
00385    else if (event->fCode == kButton1)
00386    {
00387       return TGTextButton::HandleButton(event);
00388    }
00389    else
00390    {
00391       return 0;
00392    }
00393 }

Generated on Tue Jul 5 14:16:12 2011 for ROOT_528-00b_version by  doxygen 1.5.1