00001
00002
00003
00004
00005
00006
00007
00008
00009
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
00027
00028
00029
00030
00031
00032
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
00048
00049
00050
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
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
00081
00082 if (gDebug > 0)
00083 Info("TEveGedEditor::~TEveGedEditor", "%p going down.", this);
00084 }
00085
00086
00087 void TEveGedEditor::CloseWindow()
00088 {
00089
00090
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
00104
00105
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* )
00123 {
00124
00125
00126 return new TEveGedNameFrame(parent);
00127 }
00128
00129
00130 TEveElement* TEveGedEditor::GetEveElement() const
00131 {
00132
00133
00134 return (fModel == fObject) ? fElement : 0;
00135 }
00136
00137
00138 void TEveGedEditor::DisplayElement(TEveElement* re)
00139 {
00140
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
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
00165
00166 fElement = dynamic_cast<TEveElement*>(obj);
00167 fObject = obj;
00168 TGedEditor::SetModel(pad, obj, event);
00169 }
00170
00171
00172 void TEveGedEditor::Update(TGedFrame* )
00173 {
00174
00175
00176
00177 if (fElement)
00178 {
00179 fElement->ElementChanged();
00180 fElement->PropagateVizParamsToProjecteds();
00181 }
00182
00183 gEve->Redraw3D();
00184 }
00185
00186
00187
00188
00189
00190
00191 void TEveGedEditor::SpawnNewEditor(TObject* obj)
00192 {
00193
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
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
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
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
00270
00271 if (fgContextMenu == 0)
00272 fgContextMenu = new TContextMenu("", "");
00273 return fgContextMenu;
00274 }
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
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
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
00307 }
00308
00309
00310 void TEveGedNameFrame::SetModel(TObject* obj)
00311 {
00312
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
00332
00333 TEveGedEditor::SpawnNewEditor(fGedEditor->GetModel());
00334 }
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346 ClassImp(TEveGedNameTextButton);
00347
00348
00349 TEveGedNameTextButton::TEveGedNameTextButton(TEveGedNameFrame* p) :
00350 TGTextButton(p, ""),
00351 fFrame(p)
00352 {
00353
00354
00355 gVirtualX->GrabButton(fId, kAnyButton, kAnyModifier,
00356 kButtonPressMask | kButtonReleaseMask,
00357 kNone, kNone);
00358 }
00359
00360
00361 TEveGedNameTextButton::~TEveGedNameTextButton()
00362 {
00363
00364 }
00365
00366
00367 Bool_t TEveGedNameTextButton::HandleButton(Event_t* event)
00368 {
00369
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 }