00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include "TGo4ViewPanel.h"
00015
00016 #include <math.h>
00017
00018 #include "TH1.h"
00019 #include "TH2.h"
00020 #include "TH3.h"
00021 #include "TVirtualPadEditor.h"
00022 #include "TVirtualX.h"
00023 #include "RVersion.h"
00024 #include "Riostream.h"
00025 #include "THStack.h"
00026 #include "TGraph.h"
00027 #include "TMultiGraph.h"
00028 #include "TColor.h"
00029 #include "TCanvas.h"
00030 #include "TPad.h"
00031 #include "TFrame.h"
00032 #include "TArrayD.h"
00033 #include "TCutG.h"
00034 #include "TArrow.h"
00035 #include "TList.h"
00036 #include "TLatex.h"
00037 #include "TPaveStats.h"
00038 #include "TPaveLabel.h"
00039 #include "TLegend.h"
00040 #include "TLegendEntry.h"
00041 #include "TStyle.h"
00042 #include "TROOT.h"
00043 #include "TMath.h"
00044 #include "TClass.h"
00045 #include "TSystem.h"
00046
00047 #include "TGCanvas.h"
00048 #include "TGTab.h"
00049
00050 #ifndef __NOGO4GED__
00051 #include "TGedEditor.h"
00052 #endif
00053
00054 #include <QMenuBar>
00055 #include <QStatusBar>
00056 #include <QFileDialog>
00057 #include <QTimer>
00058 #include <QInputDialog>
00059 #include <QToolTip>
00060 #include <QTime>
00061 #include <QMenu>
00062 #include <QtCore/QSignalMapper>
00063
00064 #include "QRootWindow.h"
00065 #include "QRootCanvas.h"
00066 #include "QRootApplication.h"
00067
00068 #include "TGo4Picture.h"
00069 #include "TGo4Fitter.h"
00070 #include "TGo4Marker.h"
00071 #include "TGo4Condition.h"
00072 #include "TGo4WinCond.h"
00073 #include "TGo4PolyCond.h"
00074 #include "TGo4CondArray.h"
00075 #include "TGo4WinCondView.h"
00076 #include "TGo4PolyCondView.h"
00077 #include "TGo4LockGuard.h"
00078 #include "TGo4MdiArea.h"
00079 #include "TGo4ASImage.h"
00080 #include "TGo4PrintWidget.h"
00081 #include "TGo4Proxy.h"
00082 #include "TGo4Slot.h"
00083 #include "TGo4ObjectProxy.h"
00084 #include "TGo4LinkProxy.h"
00085 #include "TGo4DrawObjProxy.h"
00086 #include "TGo4DrawCloneProxy.h"
00087 #include "TGo4Iter.h"
00088 #include "TGo4ObjectManager.h"
00089 #include "TGo4BrowserProxy.h"
00090 #include "TGo4QSettings.h"
00091
00092 const char* NoStackDrawOption = "nostack, ";
00093
00094 TGo4ViewPanel::TGo4ViewPanel(QWidget *parent, const char* name) :
00095 QGo4Widget(parent, name)
00096 {
00097 setupUi(this);
00098
00099 fPanelName = objectName();
00100
00101 fxActivePad = 0;
00102
00103 fbEditorFrameVisible = false;
00104 fiSkipRedrawCounter = 0;
00105 fxRepaintTimerPad = 0;
00106 fxDoubleClickTimerPad = 0;
00107 fbFreezeTitle = false;
00108 fFreezedTitle = "";
00109 fbApplyToAllFlag = false;
00110 fbCanvasCrosshair = false;
00111 fbCanvasEventstatus = false;
00112
00113 fbCloneFlag = true;
00114 fbModifiedSignalFlag = false;
00115 fbLeaveFocusAfterCondEnd = false;
00116
00117
00118 fbMarkEditorVisible = false;
00119 fbTypingMode = true;
00120 MarkerPanel->setVisible(false);
00121 fiMouseMode = kMouseROOT;
00122 fiPickCounter = 0;
00123 fbPickAgain = false;
00124
00125 setWindowTitle(GetPanelName());
00126 fxQCanvas->setObjectName(GetPanelName());
00127 fxQCanvas->getCanvas()->SetName(GetPanelName());
00128
00129
00130
00131
00132 fSelectMenu = 0;
00133 fSelectMap = 0;
00134 fxRooteditor = 0;
00135 fxPeditor = 0;
00136 fDummyHisto = 0;
00137
00138 fMenuBar = new QMenuBar(MenuFrame);
00139 fMenuBar->setMinimumWidth(50);
00140
00141 #if (QT_VERSION >= 0x040600)
00142 fMenuBar->setNativeMenuBar(kFALSE);
00143 #endif
00144
00145 QMenu* fileMenu = fMenuBar->addMenu("F&ile");
00146 fileMenu->addAction("&Save as...", this, SLOT(SaveCanvas()));
00147 fileMenu->addAction("Print...", this, SLOT(PrintCanvas()));
00148 fileMenu->addAction("Produce &Picture", this, SLOT(ProducePicture()));
00149 fileMenu->addAction("Produce &Graph from markers", this,
00150 SLOT(ProduceGraphFromMarkers()));
00151
00152
00153
00154
00155 fileMenu->addAction("Cl&ose", this, SLOT(close()));
00156
00157
00158 QMenu* editMenu = fMenuBar->addMenu("&Edit");
00159
00160 AddChkAction(editMenu, "Show marker &editor", fbMarkEditorVisible, this,
00161 SLOT(SetMarkerPanel()));
00162
00163 QAction* act = AddChkAction(editMenu, "Show &ROOT attributes editor",
00164 fbEditorFrameVisible, this, SLOT(StartRootEditor()));
00165 #ifdef __NOGO4GED__
00166 act->setEnabled(false);
00167 #else
00168 act->setEnabled(QRootApplication::IsRootCanvasMenuEnabled());
00169 #endif
00170
00171
00172 fbCanvasEventstatus = go4sett->getPadEventStatus();
00173 AddChkAction(editMenu, "Show &event status", fbCanvasEventstatus, this,
00174 SLOT(ShowEventStatus()));
00175
00176 editMenu->addAction("Start &condition editor", this,
00177 SLOT(StartConditionEditor()));
00178 editMenu->addSeparator();
00179 editMenu->addAction("&1:1 coordinates ratio", this,
00180 SLOT(RectangularRatio()));
00181 editMenu->addAction("&Default pad margins", this, SLOT(DefaultPadMargin()));
00182 editMenu->addSeparator();
00183 editMenu->addAction("Clear &markers", this, SLOT(ClearAllMarkers()));
00184 editMenu->addAction("Clear &pad", this, SLOT(ClearActivePad()));
00185 editMenu->addAction("Clear c&anvas", this, SLOT(ClearCanvas()));
00186
00187 fSelectMap = new QSignalMapper(this);
00188 connect(fSelectMap, SIGNAL(mapped(int)), this,
00189 SLOT(SelectMenuItemActivated(int)));
00190 fSelectMenu = fMenuBar->addMenu("&Select");
00191
00192 fOptionsMap = new QSignalMapper(this);
00193 fOptionsMenu = fMenuBar->addMenu("&Options");
00194 connect(fOptionsMenu, SIGNAL(aboutToShow()), this,
00195 SLOT(AboutToShowOptionsMenu()));
00196 connect(fOptionsMap, SIGNAL(mapped(int)), this,
00197 SLOT(OptionsMenuItemActivated(int)));
00198
00199 AddIdAction(fOptionsMenu, fOptionsMap, "&Crosshair", CrosshairId);
00200 AddIdAction(fOptionsMenu, fOptionsMap, "Super&impose", SuperimposeId);
00201 AddIdAction(fOptionsMenu, fOptionsMap, "Histogram &Statistics",
00202 StatisticsId);
00203 AddIdAction(fOptionsMenu, fOptionsMap, "Multiplot &Legend", SetLegendId);
00204
00205 fOptionsMenu->addSeparator();
00206 AddIdAction(fOptionsMenu, fOptionsMap, "Histogram &Title", SetTitleId);
00207 AddIdAction(fOptionsMenu, fOptionsMap, "Draw Time", DrawTimeId);
00208 AddIdAction(fOptionsMenu, fOptionsMap, "Draw Date", DrawDateId);
00209 AddIdAction(fOptionsMenu, fOptionsMap, "Draw item name", DrawItemnameId);
00210 fOptionsMenu->addSeparator();
00211 AddIdAction(fOptionsMenu, fOptionsMap, "&X-Axis displays time", AxisTimeDisplayId);
00212 AddIdAction(fOptionsMenu, fOptionsMap, "Set X-Axis time format...", SetTimeFormatId);
00213 fOptionsMenu->addSeparator();
00214 AddIdAction(fOptionsMenu, fOptionsMap, "&Keep Viewpanel Title", FreezeTitleId);
00215 AddIdAction(fOptionsMenu, fOptionsMap, "Set &Viewpanel Title...", SetTitleTextId);
00216
00217 QCheckBox* box1 = new QCheckBox("Apply to all", MenuFrame);
00218 box1->setObjectName("ApplyToAllCheck");
00219 connect(box1, SIGNAL(toggled(bool)), this, SLOT(ApplyToAllToggled(bool)));
00220
00221 fAutoScaleCheck = new QCheckBox("AutoScale", MenuFrame);
00222 fAutoScaleCheck->setObjectName("AutoScaleCheck");
00223 connect(fAutoScaleCheck, SIGNAL(toggled(bool)), this, SLOT(AutoScaleToggled(bool)));
00224
00225 QHBoxLayout* menugrid = new QHBoxLayout(0);
00226 menugrid->setMargin(0);
00227 menugrid->setSpacing(0);
00228 menugrid->addWidget(fMenuBar, 10, Qt::AlignLeft);
00229 menugrid->addWidget(box1, 1, Qt::AlignRight);
00230 menugrid->addWidget(fAutoScaleCheck, 1, Qt::AlignRight);
00231
00232 gridLayout->addLayout(menugrid, 0, 0, 1, 2);
00233
00234
00235 CanvasStatus = new QStatusBar(this);
00236 gridLayout->addWidget(CanvasStatus, 3, 0, 1, 2);
00237 CanvasStatus->setVisible(false);
00238
00239 EditorFrame->setVisible(fbEditorFrameVisible);
00240
00241 connect(GetQCanvas(), SIGNAL(SelectedPadChanged(TPad*)), this,
00242 SLOT(SetActivePad(TPad*)));
00243 connect(GetQCanvas(), SIGNAL(PadClicked(TPad*)), this,
00244 SLOT(PadClickedSlot(TPad*)));
00245 connect(GetQCanvas(), SIGNAL(PadDoubleClicked(TPad*)), this,
00246 SLOT(PadDoubleClickedSlot(TPad*)));
00247 connect(GetQCanvas(), SIGNAL(MenuCommandExecuted(TObject*, const char*)),
00248 this, SLOT(MenuCommandExecutedSlot(TObject*, const char*)));
00249 connect(GetQCanvas(), SIGNAL(CanvasLeaveEvent()), this,
00250 SLOT(RefreshButtons()));
00251 connect(GetQCanvas(), SIGNAL(CanvasUpdated()), this,
00252 SLOT(CanvasUpdatedSlot()));
00253 }
00254
00255 TGo4ViewPanel::~TGo4ViewPanel()
00256 {
00257 TGo4LockGuard lock(0, true);
00258
00259
00260 if (fxPeditor != 0) {
00261 fxPeditor->DeleteEditors();
00262 delete fxPeditor;
00263 fxPeditor = 0;
00264 }
00265
00266 if (fDummyHisto != 0) {
00267 delete fDummyHisto;
00268 fDummyHisto = 0;
00269 }
00270
00271
00272
00273
00274 ProcessMarkersClear(GetCanvas(), true);
00275
00276 GetCanvas()->Clear();
00277
00278 fxRepaintTimerPad = 0;
00279
00280 CallPanelFunc(panel_Deleted);
00281
00282 if (gPad != 0)
00283 if (IsPanelPad((TPad*) gPad))
00284 gPad = 0;
00285
00286 if (gROOT->GetSelectedPad() != 0)
00287 if (IsPanelPad((TPad*) gROOT->GetSelectedPad()))
00288 gROOT->SetSelectedPad(0);
00289 }
00290
00291 const char* TGo4ViewPanel::GetPanelName()
00292 {
00293 fbaPanelName = fPanelName.toLatin1();
00294 return fbaPanelName.constData();
00295 }
00296
00297 void TGo4ViewPanel::SetPanelName(const char* newname)
00298 {
00299 fPanelName = newname;
00300 }
00301
00302 TGo4Slot* TGo4ViewPanel::GetPanelSlot()
00303 {
00304 return GetTopSlot(true);
00305 }
00306
00307 TGo4Slot* TGo4ViewPanel::AddNewSlot(const char* name, TGo4Slot* parent)
00308 {
00309 if (parent == 0)
00310 parent = GetPanelSlot();
00311 return new TGo4Slot(parent, name, "title");
00312 }
00313
00314 void TGo4ViewPanel::ResetWidget()
00315 {
00316
00317 }
00318
00319 void TGo4ViewPanel::linkedObjectUpdated(const char* linkname, TObject* obj)
00320 {
00321 if (linkname == 0)
00322 return;
00323
00324 if (strcmp(linkname, "PadRangeAxisChanged") == 0) {
00325 PadRangeAxisChanged(GetActivePad());
00326 } else if (strcmp(linkname, "PadModified") == 0) {
00327 if (IsRedrawBlocked())
00328 return;
00329 if (!fbModifiedSignalFlag)
00330 QTimer::singleShot(1, this, SLOT(ProcessPadModifiedSignal()));
00331 fbModifiedSignalFlag = true;
00332 }
00333 }
00334
00335 void TGo4ViewPanel::linkedUpdated(TGo4Slot* slot, TObject* obj)
00336 {
00337 if (slot == 0)
00338 return;
00339
00340 if (IsRedrawBlocked())
00341 return;
00342
00343 Int_t kind = GetDrawKind(slot);
00344
00345 TGo4Slot* padslot = slot;
00346 if (kind != kind_PadSlot)
00347 padslot = slot->GetParent();
00348
00349 if (((kind > 0) && (kind < 100)) || (kind == kind_Condition)
00350 || (kind == kind_Latex)) {
00351 TGo4Picture* padopt = GetPadOptions(padslot);
00352
00353 if (padopt != 0) {
00354 padopt->SetContentModified(true);
00355 padopt->SetPadModified();
00356
00357
00358
00359 ShootRepaintTimer();
00360 }
00361 }
00362 }
00363
00364 void TGo4ViewPanel::linkedRemoved(TGo4Slot* slot, TObject* obj)
00365 {
00366 if (slot == 0)
00367 return;
00368
00369 if (IsRedrawBlocked())
00370 return;
00371
00372 int kind = GetDrawKind(slot);
00373
00374 if (kind == kind_ThisPad) {
00375 TPad* pad = (TPad*) obj;
00376 if (pad != 0)
00377 PadDeleted(pad);
00378 return;
00379 }
00380
00381 TGo4Slot* padslot = slot;
00382 if (kind != kind_PadSlot)
00383 padslot = slot->GetParent();
00384
00385 CheckObjectsAssigments(GetSlotPad(padslot), padslot);
00386
00387 if (((kind > 0) && (kind < 100)) || (kind == kind_Condition)
00388 || (kind == kind_Latex)) {
00389 CleanupGedEditor();
00390 TGo4Picture* padopt = GetPadOptions(padslot);
00391 if (padopt != 0) {
00392 padopt->SetPadModified();
00393 ShootRepaintTimer();
00394 }
00395 }
00396 }
00397
00398 bool TGo4ViewPanel::IsAcceptDrag(const char * itemname, TClass * cl, int kind)
00399 {
00400 if (cl == 0)
00401 return false;
00402 int cando = Browser()->ItemCanDo(itemname);
00403 return TGo4BrowserProxy::CanDrawItem(cando)
00404 || cl->InheritsFrom(TGo4Condition::Class());
00405 }
00406
00407 void TGo4ViewPanel::DropOnPad(TPad* pad, const char * itemname, TClass * cl, int kind)
00408 {
00409 if (cl == 0) return;
00410 if (pad == 0) pad = GetCanvas();
00411
00412 if (cl->InheritsFrom(TGo4Fitter::Class())) {
00413 SetActivePad(pad);
00414 EditItem(itemname);
00415 return;
00416 }
00417 int cando = Browser()->ItemCanDo(itemname);
00418 if (!TGo4BrowserProxy::CanDrawItem(cando)
00419 && !cl->InheritsFrom(TGo4Condition::Class()))
00420 return;
00421
00422 if (AddDrawObject(pad, kind_Link, itemname, 0, false, 0) == 0) return;
00423
00424 SetActivePad(pad);
00425
00426 ShootRepaintTimer();
00427
00428 Browser()->GetBrowserObject(itemname,
00429 go4sett->getFetchDataWhenDraw() ? 2 : 1);
00430 }
00431
00432
00433
00434 void TGo4ViewPanel::CompleteInitialization()
00435 {
00436 TGo4LockGuard lock(0, true);
00437
00438
00439 UpdatePadStatus(GetCanvas(), true);
00440
00441 fAutoScaleCheck->setChecked(GetPadOptions(GetCanvas())->IsAutoScale());
00442
00443 fxRooteditor = new QRootWindow(EditorFrame, "rootwrapperwindow");
00444 QVBoxLayout* gedlayout = new QVBoxLayout(EditorFrame);
00445 gedlayout->setContentsMargins(0, 0, 0, 0);
00446 gedlayout->addWidget(fxRooteditor);
00447
00448
00449 connect(TGo4MdiArea::Instance(),
00450 SIGNAL(panelSignal(TGo4ViewPanel*, TPad*, int)), this,
00451 SLOT(panelSlot(TGo4ViewPanel*, TPad*, int)));
00452
00453
00454
00455
00456
00457 GetQCanvas()->Resize();
00458
00459 SetActivePad(GetCanvas());
00460
00461 SetPadDefaults(GetCanvas());
00462
00463
00464
00465 fbCloneFlag = go4sett->getCloneFlag();
00466 }
00467
00468 void TGo4ViewPanel::SetMouseMode(int mode)
00469 {
00470 fiMouseMode = mode;
00471 }
00472
00473 int TGo4ViewPanel::GetMouseMode()
00474 {
00475 return fiMouseMode;
00476 }
00477
00478 QString TGo4ViewPanel::GetSelectedMarkerName(TPad* pad)
00479 {
00480 TGo4Slot* padslot = GetPadSlot(pad);
00481 if (padslot == 0) return QString::null;
00482 return QString(padslot->GetPar("::SelMarker"));
00483 }
00484
00485 int TGo4ViewPanel::GetSelectedMarkerIndex(TPad* pad)
00486 {
00487 TGo4Slot* padslot = GetPadSlot(pad);
00488 if (padslot == 0) return -1;
00489 Int_t selindex = -1;
00490 if (!padslot->GetIntPar("::SelIndex", selindex)) return -1;
00491 return selindex;
00492 }
00493
00494 TGo4Slot* TGo4ViewPanel::GetSelectedSlot(TPad* pad, int* selkind, TObject** selobj)
00495 {
00496 if (selkind != 0) *selkind = kind_None;
00497 if (selobj != 0) *selobj = 0;
00498
00499 TGo4Slot* padslot = GetPadSlot(pad);
00500 QString selname = GetSelectedMarkerName(pad);
00501 int selindex = GetSelectedMarkerIndex(pad);
00502
00503 if ((padslot == 0) || (selname.length() == 0)) return 0;
00504
00505 for (int n = 0; n < padslot->NumChilds(); n++) {
00506 TGo4Slot* subslot = padslot->GetChild(n);
00507 int drawkind = GetDrawKind(subslot);
00508 TObject* obj = subslot->GetAssignedObject();
00509
00510 if ((drawkind == kind_Link) && (obj != 0)) {
00511 if (obj->InheritsFrom(TGo4Condition::Class()))
00512 drawkind = kind_Condition;
00513 }
00514
00515 if ((drawkind == kind_Marker) || (drawkind == kind_Window)
00516 || (drawkind == kind_Poly) || (drawkind == kind_Latex)
00517 || (drawkind == kind_Arrow) || (drawkind == kind_Condition)) {
00518
00519 if ((obj == 0) || (selname != obj->GetName()))
00520 continue;
00521
00522 if (drawkind == kind_Condition) {
00523 TGo4Condition* selcond = dynamic_cast<TGo4Condition*>(obj);
00524 if (obj->InheritsFrom(TGo4CondArray::Class())) {
00525 TGo4CondArray* arr = (TGo4CondArray*) obj;
00526 selcond = 0;
00527 if ((selindex >= 0) && (selindex < arr->GetNumber()))
00528 selcond = arr->At(selindex);
00529 }
00530 drawkind = kind_None;
00531 obj = selcond;
00532 if (selcond != 0)
00533 if (selcond->InheritsFrom(TGo4WinCond::Class()))
00534 drawkind = kind_Window;
00535 else if (selcond->InheritsFrom(TGo4PolyCond::Class()))
00536 drawkind = kind_Poly;
00537 }
00538 if (selkind != 0)
00539 *selkind = drawkind;
00540 if (selobj != 0)
00541 *selobj = obj;
00542 return subslot;
00543 }
00544 }
00545 return 0;
00546 }
00547
00548 bool TGo4ViewPanel::IsConditionSelected(TPad* pad)
00549 {
00550 TGo4Slot* slot = GetSelectedSlot(pad, 0, 0);
00551 if (slot == 0)
00552 return false;
00553
00554 return (GetDrawKind(slot) == kind_Condition);
00555 }
00556
00557 TPad* TGo4ViewPanel::FindPadWithItem(const char* itemname)
00558 {
00559 TGo4Iter iter(GetPanelSlot(), kTRUE);
00560 while (iter.next()) {
00561 TGo4Slot* subslot = iter.getslot();
00562 int drawkind = GetDrawKind(subslot);
00563 if ((drawkind == kind_Link) || (drawkind == kind_Condition) || (drawkind == kind_Latex)) {
00564 const char* linkname = GetLinkedName(subslot);
00565 if (linkname != 0)
00566 if (strcmp(linkname, itemname) == 0)
00567 return GetSlotPad(subslot->GetParent());
00568 }
00569 }
00570 return 0;
00571 }
00572
00573 const char* TGo4ViewPanel::GetDrawItemName(int itemcnt)
00574 {
00575 int cnt = 0;
00576
00577 TGo4Iter iter(GetPanelSlot(), kTRUE);
00578 while (iter.next()) {
00579 TGo4Slot* subslot = iter.getslot();
00580 int drawkind = GetDrawKind(subslot);
00581 if ((drawkind == kind_Link) || (drawkind == kind_Condition)) {
00582 const char* linkname = GetLinkedName(subslot);
00583 if (linkname != 0) {
00584 if (cnt++ == itemcnt) return linkname;
00585 }
00586 }
00587 }
00588
00589 return 0;
00590 }
00591
00592
00593 void TGo4ViewPanel::UndrawItemOnPanel(const char* itemname)
00594 {
00595 TGo4LockGuard lock(0, true);
00596
00597 TObjArray delslots;
00598
00599 TGo4Iter iter(GetPanelSlot(), kTRUE);
00600 while (iter.next()) {
00601 TGo4Slot* subslot = iter.getslot();
00602 int drawkind = GetDrawKind(subslot);
00603 if ((drawkind == kind_Link) || (drawkind == kind_Condition) || (drawkind == kind_Latex)) {
00604 const char* linkname = GetLinkedName(subslot);
00605 if ((linkname != 0) && (strcmp(linkname, itemname) == 0)) {
00606 delslots.Add(subslot);
00607 TGo4Slot* padslot = subslot->GetParent();
00608 TGo4Picture* padopt = GetPadOptions(padslot);
00609 if (padopt != 0)
00610 padopt->SetPadModified();
00611 }
00612 }
00613 }
00614 if (delslots.GetLast() >= 0) {
00615 delslots.Delete();
00616 ShootRepaintTimer();
00617 }
00618 }
00619
00620 void TGo4ViewPanel::SetSelectedMarker(TPad* pad, const QString& selname,
00621 int selindex)
00622 {
00623 TGo4LockGuard lock(0, true);
00624
00625 TGo4Slot* padslot = GetPadSlot(pad);
00626 if (padslot == 0)
00627 return;
00628
00629 if (selname.length() == 0)
00630 selindex = -1;
00631
00632 int oldselindex = GetSelectedMarkerIndex(pad);
00633 QString oldselname = GetSelectedMarkerName(pad);
00634
00635 TGo4Slot* oldsel = GetSelectedSlot(pad, 0, 0);
00636 if (oldsel != 0)
00637 SetSpecialDrawOption(oldsel, 0);
00638
00639 if (selname.length() > 0)
00640 padslot->SetPar("::SelMarker", selname.toLatin1().constData());
00641 else
00642 padslot->RemovePar("::SelMarker");
00643
00644 if (selindex > -1)
00645 padslot->SetIntPar("::SelIndex", selindex);
00646 else
00647 padslot->RemovePar("::SelIndex");
00648
00649 int newselkind = 0;
00650 TObject* newselobj = 0;
00651 TGo4Slot* newselslot = GetSelectedSlot(pad, &newselkind, &newselobj);
00652
00653 if ((selindex >= 0) && (newselslot != 0)) {
00654 QString drawopt("sel=");
00655 drawopt += QString::number(selindex);
00656 SetSpecialDrawOption(newselslot, drawopt.toLatin1().constData());
00657 }
00658
00659 if (((oldselindex != selindex) || (oldselname != selname))
00660 && ((oldselindex >= 0) || (selindex >= 0))) {
00661 MarkPadModified(pad);
00662 ShootRepaintTimer(pad);
00663 } else if (newselobj != 0) {
00664
00665 newselobj->Pop();
00666
00667 pad->Update();
00668 }
00669
00670 }
00671
00672 void TGo4ViewPanel::SetSelectedMarkerByMouseClick(TPad* pad, const char* name)
00673 {
00674 TGo4LockGuard lock(0, true);
00675
00676 if (!fbMarkEditorVisible) return;
00677
00678 TGo4Slot* padslot = GetPadSlot(pad);
00679 if (padslot == 0) return;
00680
00681 bool find = false;
00682
00683 for (int n = 0; n < padslot->NumChilds(); n++) {
00684 TGo4Slot* subslot = padslot->GetChild(n);
00685 int drawkind = GetDrawKind(subslot);
00686 if ((drawkind == kind_Marker) || (drawkind == kind_Window)
00687 || (drawkind == kind_Poly)) {
00688 TObject* obj = subslot->GetAssignedObject();
00689 if ((obj != 0) && (strcmp(obj->GetName(), name) == 0)) {
00690 SetSelectedMarker(pad, name, -1);
00691 SetActiveObj(pad, drawkind, subslot);
00692 find = true;
00693 break;
00694 }
00695 }
00696 if (drawkind != kind_Condition) continue;
00697 TGo4Condition* cond =
00698 dynamic_cast<TGo4Condition*>(subslot->GetAssignedObject());
00699 if (cond==0) continue;
00700
00701 if (strcmp(cond->GetName(), name) == 0) {
00702 SetSelectedMarker(pad, name, -1);
00703
00704 if (cond->InheritsFrom(TGo4PolyCond::Class()))
00705 drawkind = kind_Poly;
00706 else
00707 drawkind = kind_Window;
00708
00709 SetActiveObj(pad, drawkind, subslot);
00710 find = true;
00711 break;
00712 }
00713
00714 TGo4CondArray* arr = dynamic_cast<TGo4CondArray*>(cond);
00715 if (arr == 0)
00716 continue;
00717
00718 for (int ncon = 0; ncon < arr->GetNumber(); ncon++)
00719 if (strcmp(arr->At(ncon)->GetName(), name) == 0) {
00720 SetSelectedMarker(pad, arr->GetName(), ncon);
00721 if (arr->At(ncon)->InheritsFrom(TGo4PolyCond::Class()))
00722 drawkind = kind_Poly;
00723 else
00724 drawkind = kind_Window;
00725 SetActiveObj(pad, drawkind, subslot);
00726 find = true;
00727 break;
00728 }
00729 }
00730 if (find)
00731 RefreshButtons();
00732 }
00733
00734 void TGo4ViewPanel::StartConditionEditing(TPad* pad)
00735 {
00736 TGo4LockGuard lock(0, true);
00737
00738 int selectedkind;
00739 TGo4Slot* selslot = GetSelectedSlot(GetActivePad(), &selectedkind, 0);
00740
00741 if (selslot == 0)
00742 return;
00743
00744 if (selectedkind == kind_Window) {
00745 FreezeMode->setChecked(false);
00746 RegionB->setChecked(true);
00747 fbLeaveFocusAfterCondEnd = true;
00748 } else if (selectedkind == kind_Poly) {
00749 FreezeMode->setChecked(false);
00750 PolyB->setChecked(true);
00751 fbLeaveFocusAfterCondEnd = true;
00752 } else
00753 return;
00754
00755 MarkPadModified(pad);
00756 ShootRepaintTimer(pad);
00757 }
00758
00759 void TGo4ViewPanel::SwitchMarkerButton(int kind, bool on)
00760 {
00761 if (!fbTypingMode)
00762 return;
00763 CompleteMarkerEdit(GetActivePad());
00764 if (!on) {
00765 SetMouseMode(kMouseROOT);
00766 } else {
00767 fiPickCounter = 0;
00768 switch (kind) {
00769 case kind_Marker:
00770 SetMouseMode(kMousePickCursor);
00771 break;
00772 case kind_Window:
00773 SetMouseMode(kMousePickLimits);
00774 break;
00775 case kind_Poly:
00776 SetMouseMode(kMousePickPolygon);
00777 break;
00778 case kind_Latex:
00779 SetMouseMode(kMousePickLatex);
00780 break;
00781 case kind_Arrow:
00782 SetMouseMode(kMouseDraw);
00783 break;
00784 default:
00785 SetMouseMode(kMousePickCursor);
00786 break;
00787 }
00788 int selectedkind;
00789 TGo4Slot* selslot = GetSelectedSlot(GetActivePad(), &selectedkind, 0);
00790 if (selectedkind != kind)
00791 SetSelectedMarker(GetActivePad(), "", -1);
00792 }
00793
00794 RefreshButtons();
00795 }
00796
00797 void TGo4ViewPanel::SetCursorMode(bool on)
00798 {
00799 SwitchMarkerButton(kind_Marker, on);
00800 }
00801
00802 void TGo4ViewPanel::SetRegionMode(bool on)
00803 {
00804 SwitchMarkerButton(kind_Window, on);
00805 }
00806
00807 void TGo4ViewPanel::SetPolygonMode(bool on)
00808 {
00809 SwitchMarkerButton(kind_Poly, on);
00810 }
00811
00812 void TGo4ViewPanel::SetLateXMode(bool on)
00813 {
00814 SwitchMarkerButton(kind_Latex, on);
00815 }
00816
00817 void TGo4ViewPanel::SetDrawingMode(bool on)
00818 {
00819 SwitchMarkerButton(kind_Arrow, on);
00820 }
00821
00822 void TGo4ViewPanel::SetFreezeMouseMode(bool on)
00823 {
00824 if (!fbTypingMode)
00825 return;
00826 fbPickAgain = on;
00827 RefreshButtons();
00828 }
00829
00830 void TGo4ViewPanel::RefreshButtons()
00831 {
00832 TGo4LockGuard lock(0, true);
00833
00834 MarkerPanel->setVisible(fbMarkEditorVisible);
00835 fxQCanvas->setMaskDoubleClick(fbMarkEditorVisible);
00836
00837
00838
00839 bool iscondition = IsConditionSelected(GetActivePad());
00840
00841 fbTypingMode = false;
00842 GetConditionBtn->setVisible(iscondition);
00843 InfoConditionBtn->setVisible(iscondition);
00844 EditConditionBtn->setVisible(iscondition);
00845 SetConditionBtn->setVisible(iscondition);
00846 if (iscondition) {
00847 TGo4Slot* slot = GetSelectedSlot(GetActivePad(), 0, 0);
00848 TGo4Condition* cond =
00849 slot == 0 ? 0 : dynamic_cast<TGo4Condition*>(slot->GetAssignedObject());
00850 ModifyConditionBtn->setVisible((cond != 0) && (cond->IsChanged() != 0));
00851
00852 QString iconname = ":/icons/right.png";
00853 QString tooltip = "Refresh condition from analysis";
00854 if (!BrowserItemRemote(GetLinkedName(slot))) {
00855 iconname = ":/icons/refresh.png";
00856 tooltip = "Refresh condition from source";
00857 }
00858 GetConditionBtn->setIcon(QIcon(iconname));
00859 GetConditionBtn->setToolTip(tooltip);
00860
00861 } else
00862 ModifyConditionBtn->setVisible(false);
00863
00864 switch (GetMouseMode()) {
00865 case kMouseROOT:
00866 CursorB->setChecked(false);
00867 RegionB->setChecked(false);
00868 LatexB->setChecked(false);
00869 DrawB->setChecked(false);
00870 PolyB->setChecked(false);
00871 break;
00872 case kMousePickCursor:
00873 CursorB->setChecked(true);
00874 RegionB->setChecked(false);
00875 LatexB->setChecked(false);
00876 DrawB->setChecked(false);
00877 PolyB->setChecked(false);
00878 break;
00879 case kMousePickLimits:
00880 CursorB->setChecked(false);
00881 RegionB->setChecked(true);
00882 LatexB->setChecked(false);
00883 DrawB->setChecked(false);
00884 PolyB->setChecked(false);
00885 break;
00886 case kMousePickPolygon:
00887 CursorB->setChecked(false);
00888 RegionB->setChecked(false);
00889 LatexB->setChecked(false);
00890 DrawB->setChecked(false);
00891 PolyB->setChecked(true);
00892 break;
00893 case kMousePickLatex:
00894 CursorB->setChecked(false);
00895 RegionB->setChecked(false);
00896 LatexB->setChecked(true);
00897 DrawB->setChecked(false);
00898 PolyB->setChecked(false);
00899 break;
00900 case kMouseDraw:
00901 CursorB->setChecked(false);
00902 RegionB->setChecked(false);
00903 LatexB->setChecked(false);
00904 DrawB->setChecked(true);
00905 PolyB->setChecked(false);
00906 break;
00907 default:
00908 CursorB->setChecked(false);
00909 RegionB->setChecked(false);
00910 LatexB->setChecked(false);
00911 DrawB->setChecked(false);
00912 PolyB->setChecked(false);
00913 break;
00914 };
00915 FreezeMode->setChecked(fbPickAgain);
00916
00917 SelectedMarkerCmb->clear();
00918 SelectedMarkerCmb->addItem("new");
00919
00920 TGo4Slot* slot = GetPadSlot(GetActivePad());
00921 int findindx = -1;
00922
00923 QString selname = GetSelectedMarkerName(GetActivePad());
00924 int selindex = GetSelectedMarkerIndex(GetActivePad());
00925
00926 if (slot != 0)
00927 for (int n = 0; n < slot->NumChilds(); n++) {
00928 TGo4Slot* subslot = slot->GetChild(n);
00929 int drawkind = GetDrawKind(subslot);
00930 if ((drawkind == kind_Marker) || (drawkind == kind_Window)
00931 || (drawkind == kind_Poly) || (drawkind == kind_Condition)) {
00932 TObject* obj = subslot->GetAssignedObject();
00933 if (obj == 0)
00934 continue;
00935
00936 if (obj->InheritsFrom(TGo4CondArray::Class())) {
00937 TGo4CondArray* arr = (TGo4CondArray*) obj;
00938 for (int ncon = 0; ncon < arr->GetNumber(); ncon++) {
00939 TGo4Condition* sub = arr->At(ncon);
00940 QString fullname(arr->GetName());
00941 fullname += "/Sub";
00942 fullname += QString::number(ncon);
00943 SelectedMarkerCmb->addItem(fullname);
00944
00945 if ((selname == obj->GetName()) && (selindex == ncon))
00946 findindx = SelectedMarkerCmb->count() - 1;
00947 }
00948 } else {
00949 SelectedMarkerCmb->addItem(obj->GetName());
00950 if (selname == obj->GetName())
00951 findindx = SelectedMarkerCmb->count() - 1;
00952 }
00953 }
00954 }
00955
00956 if (findindx < 0) {
00957 findindx = 0;
00958 SetSelectedMarker(GetActivePad(), "", -1);
00959 }
00960
00961 SelectedMarkerCmb->setCurrentIndex(findindx);
00962 DelSelectedMarker->setEnabled((findindx > 0) );
00963
00964 if (fbMarkEditorVisible) {
00965 MarkerPanel->ensurePolished();
00966 MarkerPanel->update();
00967 MarkerPanel->show();
00968 }
00969 fbTypingMode = true;
00970 }
00971
00972 void TGo4ViewPanel::SelectedMarkerCmb_activated(int indx)
00973 {
00974 if (!fbTypingMode)
00975 return;
00976 if (indx == 0)
00977 SetSelectedMarker(GetActivePad(), "", -1);
00978 else {
00979 QString selname = SelectedMarkerCmb->itemText(indx);
00980 int selindex = -1;
00981 int p = selname.indexOf("/Sub");
00982 if (p > 0) {
00983 selindex = selname.mid(p + 4).toInt();
00984 selname.truncate(p);
00985 } else
00986 selindex = -1;
00987 SetSelectedMarker(GetActivePad(), selname, selindex);
00988 }
00989
00990 int drawkind = 0;
00991 TGo4Slot* slot = GetSelectedSlot(GetActivePad(), &drawkind, 0);
00992
00993 if ((slot != 0) && (drawkind > 0)) {
00994 SetActiveObj(GetActivePad(), drawkind, slot);
00995 SwitchMarkerButton(drawkind, true);
00996 } else
00997 SwitchMarkerButton(kind_Marker, false);
00998 }
00999
01000 void TGo4ViewPanel::DelSelectedMarker_clicked()
01001 {
01002 if (!fbTypingMode) return;
01003 TGo4Slot* slot = GetSelectedSlot(GetActivePad(), 0, 0);
01004 if (slot == 0) return;
01005 delete slot;
01006 SetSelectedMarker(GetActivePad(), "", -1);
01007 RedrawPanel(GetActivePad(), true);
01008 }
01009
01010 void TGo4ViewPanel::SetMarkerPanel()
01011 {
01012 fbMarkEditorVisible = !fbMarkEditorVisible;
01013 if (!fbMarkEditorVisible) {
01014
01015 CompleteMarkerEdit(GetActivePad());
01016 SetMouseMode(kMouseROOT);
01017 gROOT->SetEditorMode("");
01018 fiPickCounter = 0;
01019 }
01020 RefreshButtons();
01021 ShootRepaintTimer();
01022 }
01023
01024 void TGo4ViewPanel::LogMarkerValues()
01025 {
01026 if (!fbTypingMode)
01027 return;
01028
01029 TGo4Slot* slot = GetPadSlot(GetActivePad());
01030 if (slot == 0)
01031 return;
01032
01033 for (int n = 0; n < slot->NumChilds(); n++) {
01034 TGo4Slot* subslot = slot->GetChild(n);
01035 int drawkind = GetDrawKind(subslot);
01036 TObject* obj = subslot->GetAssignedObject();
01037 if ((drawkind < kind_Condition) || (obj == 0))
01038 continue;
01039 switch (drawkind) {
01040 case kind_Marker:
01041 obj->Print("*");
01042 break;
01043 case kind_Latex:
01044 obj->Print("*");
01045 break;
01046 case kind_Arrow:
01047 obj->Print("go4log");
01048 break;
01049 case kind_Window:
01050 case kind_Poly:
01051 case kind_Condition:
01052 obj->Print("go4log-limits-stats");
01053 break;
01054 }
01055 }
01056 }
01057
01058 void TGo4ViewPanel::ClearAllMarkers()
01059 {
01060 TGo4LockGuard lock(0, true);
01061
01062 TPad* pad = IsApplyToAllFlag() ? GetCanvas() : GetActivePad();
01063 if (pad == 0)
01064 pad = GetCanvas();
01065
01066 ProcessMarkersClear(pad, IsApplyToAllFlag());
01067
01068 RedrawPanel(pad, true);
01069 }
01070
01071 void TGo4ViewPanel::ProcessMarkersClear(TPad *pad, bool withsubpads)
01072 {
01073 if (pad == 0) return;
01074
01075 DeleteDrawObjects(pad, kind_Marker);
01076 DeleteDrawObjects(pad, kind_Window);
01077 DeleteDrawObjects(pad, kind_Poly);
01078 DeleteDrawObjects(pad, kind_Latex);
01079 DeleteDrawObjects(pad, kind_Arrow);
01080 if (!withsubpads) return;
01081
01082 TGo4Slot* slot = GetPadSlot(pad);
01083 if (slot == 0) return;
01084
01085 TGo4Iter iter(slot, true);
01086 while (iter.next()) {
01087 TPad* subpad = GetSlotPad(iter.getslot());
01088 if (subpad != 0)
01089 ProcessMarkersClear(subpad, false);
01090 }
01091 }
01092
01093 void TGo4ViewPanel::GetConditionBtn_clicked()
01094 {
01095 TGo4Slot* slot = GetSelectedSlot(GetActivePad(), 0, 0);
01096 if (GetDrawKind(slot) != kind_Condition)
01097 return;
01098 const char* itemname = GetLinkedName(slot);
01099 if (itemname == 0)
01100 return;
01101
01102 Browser()->GetBrowserObject(itemname, 2);
01103
01104 RefreshButtons();
01105 }
01106
01107 void TGo4ViewPanel::InfoConditionBtn_clicked()
01108 {
01109 TGo4Slot* slot = GetSelectedSlot(GetActivePad(), 0, 0);
01110 if (GetDrawKind(slot) != kind_Condition)
01111 return;
01112 const char* itemname = GetLinkedName(slot);
01113 if (itemname != 0)
01114 ShowItemInfo(itemname);
01115 }
01116
01117 void TGo4ViewPanel::EditConditionBtn_clicked()
01118 {
01119 TGo4Slot* slot = GetSelectedSlot(GetActivePad(), 0, 0);
01120 if (GetDrawKind(slot) != kind_Condition) return;
01121 const char* itemname = GetLinkedName(slot);
01122 if (itemname != 0)
01123 EditItem(itemname);
01124 }
01125
01126 void TGo4ViewPanel::SetConditionBtn_clicked()
01127 {
01128 TGo4Slot* slot = GetSelectedSlot(GetActivePad(), 0, 0);
01129 if (GetDrawKind(slot) != kind_Condition) return;
01130 const char* itemname = GetLinkedName(slot);
01131 if (itemname != 0) {
01132 UpdateItemInAnalysis(itemname);
01133 TGo4Condition* cond = dynamic_cast<TGo4Condition*>(slot->GetAssignedObject());
01134 if(cond!=0) cond->SetChanged(kFALSE);
01135 RefreshButtons();
01136 }
01137 }
01138
01139 void TGo4ViewPanel::SaveMarkers()
01140 {
01141 QFileDialog fd(this, "Save Markers of active pad into", QString(),
01142 "ROOT file (*.root)");
01143 fd.setFileMode(QFileDialog::AnyFile);
01144 fd.setAcceptMode(QFileDialog::AcceptSave);
01145 if (fd.exec() == QDialog::Accepted) {
01146 QStringList flst = fd.selectedFiles();
01147 if (flst.isEmpty())
01148 return;
01149
01150 QString filename = flst[0];
01151 if (!filename.endsWith(".root"))
01152 filename.append(".root");
01153
01154 }
01155 }
01156
01157 void TGo4ViewPanel::LoadMarkers()
01158 {
01159 QFileDialog fd(this, "Load Marker setup from:", QString(),
01160 "ROOT file (*.root)");
01161 fd.setFileMode(QFileDialog::ExistingFile);
01162 if (fd.exec() == QDialog::Accepted) {
01163 QStringList flst = fd.selectedFiles();
01164 if (flst.isEmpty())
01165 return;
01166 QString filename = flst[0];
01167 }
01168 }
01169
01170 void TGo4ViewPanel::SetActivePad(TPad* pad)
01171 {
01172 TGo4LockGuard lock(0, true);
01173
01174 if (fxActivePad != pad)
01175 CompleteMarkerEdit(fxActivePad);
01176
01177 raise();
01178
01179 if (pad == 0) {
01180 GetCanvas()->SetSelected(0);
01181 GetCanvas()->SetSelectedPad(0);
01182 GetQCanvas()->Update();
01183 return;
01184 }
01185
01186 fxActivePad = pad;
01187 fxActivePad->cd();
01188 GetCanvas()->SetSelectedPad(fxActivePad);
01189
01190 TGo4MdiArea::Instance()->SetSelectedPad(fxActivePad);
01191
01192 BlockPanelRedraw(true);
01193 GetQCanvas()->Update();
01194 BlockPanelRedraw(false);
01195
01196 DisplayPadStatus(fxActivePad);
01197
01198 UpdatePanelCaption();
01199 CallPanelFunc(panel_Activated, fxActivePad);
01200 }
01201
01202 void TGo4ViewPanel::PadClickedSlot(TPad* pad)
01203 {
01204 TGo4LockGuard lock(0, true);
01205
01206 SetActivePad(pad);
01207
01208 if (pad == 0)
01209 return;
01210
01211 Int_t px = pad->GetEventX();
01212 Int_t py = pad->GetEventY();
01213 Double_t x = pad->PadtoX(pad->AbsPixeltoX(px));
01214 Double_t y = pad->PadtoY(pad->AbsPixeltoY(py));
01215 bool docreate = GetSelectedMarkerName(pad).length() == 0;
01216 bool docheck = false;
01217 bool iscreated = false;
01218
01219 switch (fiMouseMode) {
01220 case kMouseROOT: {
01221 TObject *obj = GetCanvas()->GetSelected();
01222 if (obj != 0)
01223 if (obj->InheritsFrom(TGo4Marker::Class())
01224 || obj->InheritsFrom(TGo4WinCondView::Class())
01225 || obj->InheritsFrom(TGo4PolyCondView::Class()))
01226 SetSelectedMarkerByMouseClick(pad, obj->GetName());
01227
01228 break;
01229 }
01230
01231 case kMousePickCursor: {
01232
01233 gROOT->SetEditorMode("");
01234
01235 if (docreate) {
01236 TGo4Marker* mark = new TGo4Marker(x, y, 28);
01237 AddMarkerObj(pad, kind_Marker, mark);
01238 Int_t ix = TGo4Marker::GetInstances() - 1;
01239 mark->SetMarkerColor((ix) % 6 + 2);
01240 mark->SetHistogram(GetPadHistogram(pad));
01241 if (!fbPickAgain)
01242 fiMouseMode = kMouseROOT;
01243 mark->Draw("");
01244 } else {
01245 TGo4Marker* mark = dynamic_cast<TGo4Marker*>(GetActiveObj(pad, kind_Marker));
01246 if(mark!=0) {
01247 mark->SetX(x);
01248 mark->SetY(y);
01249 }
01250 if (!fbPickAgain) fiMouseMode=kMouseROOT;
01251 }
01252 pad->Modified();
01253 pad->Update();
01254
01255
01256 break;
01257 }
01258
01259 case kMousePickLimits: {
01260 gROOT->SetEditorMode("");
01261 TGo4WinCond* conny = 0;
01262 Double_t xmin(x), xmax(x), ymin(y), ymax(y);
01263 if (fiPickCounter == 0) {
01264
01265 if (docreate) {
01266 TH1* hist = GetPadHistogram(pad);
01267 bool fbTwoDimRegion = (hist != 0) && (hist->GetDimension() > 1);
01268 int ix = GetNumMarkers(pad, kind_Window);
01269 QString name = "Region " + QString::number(ix + 1);
01270 conny = new TGo4WinCond(name.toLatin1().constData());
01271 iscreated = true;
01272 if (fbTwoDimRegion)
01273 conny->SetValues(0, 0, 0, 0);
01274 else
01275 conny->SetValues(0, 0);
01276 conny->SetLineColor(ix % 6 + 2);
01277 conny->SetFillColor(ix % 6 + 2);
01278 conny->SetFillStyle(3002);
01279 conny->SetWorkHistogram(hist);
01280
01281 conny->SetYRMSDraw(fbTwoDimRegion && conny->IsXRMSDraw());
01282 conny->SetYMeanDraw(fbTwoDimRegion && conny->IsXMeanDraw());
01283 conny->SetYMaxDraw(fbTwoDimRegion && conny->IsXMaxDraw());
01284 AddMarkerObj(pad, kind_Window, conny);
01285 } else
01286 conny = dynamic_cast<TGo4WinCond*>(GetActiveObj(pad, kind_Window));
01287 if(conny==0) return;
01288 fiPickCounter++;
01289 } else
01290 if (fiPickCounter==1) {
01291 conny = dynamic_cast<TGo4WinCond*> (GetActiveObj(pad, kind_Window));
01292 if(conny==0) return;
01293 xmin = conny->GetXLow();
01294 ymin = conny->GetYLow();
01295 fiPickCounter=0;
01296 if(!fbPickAgain) fiMouseMode=kMouseROOT;
01297 docheck = true;
01298 } else {
01299 std::cout <<"TGo4ViewPanel:MouseClick() NEVER COME HERE" << std::endl;
01300 return;
01301 }
01302
01303 if (conny->GetDimension() > 1)
01304 conny->SetValues(xmin, xmax, ymin, ymax);
01305 else
01306 conny->SetValues(xmin, xmax);
01307
01308 TGo4Slot* condslot = GetSelectedSlot(pad, 0, 0);
01309 if (GetDrawKind(condslot) == kind_Condition) {
01310 TGo4Condition* maincond =
01311 dynamic_cast<TGo4Condition*>(condslot->GetAssignedObject());
01312 if (maincond!=0) maincond->SetChanged(kTRUE);
01313 }
01314
01315 conny->SetChanged(kTRUE);
01316 if (iscreated)
01317 conny->Draw("");
01318
01319 pad->Modified();
01320 pad->Update();
01321
01322 break;
01323 }
01324
01325 case kMousePickPolygon: {
01326 gROOT->SetEditorMode("");
01327 TGo4PolyCond* cond = 0;
01328
01329 if (fiPickCounter == 0) {
01330
01331 if (docreate) {
01332 TH1* hist = GetPadHistogram(pad);
01333 int ix = GetNumMarkers(pad, kind_Poly);
01334 QString name = "Polygon " + QString::number(ix + 1);
01335 cond = new TGo4PolyCond(name.toLatin1().constData());
01336 iscreated = true;
01337 AddMarkerObj(pad, kind_Poly, cond);
01338 cond->SetWorkHistogram(hist);
01339 } else {
01340 cond = dynamic_cast<TGo4PolyCond*>(GetActiveObj(pad, kind_Poly));
01341
01342 if (cond!=0) {
01343 TCutG* cut = cond->GetCut(kTRUE);
01344 delete cut;
01345 }
01346 }
01347 if(cond==0) return;
01348 fiPickCounter++;
01349 } else {
01350 cond = dynamic_cast<TGo4PolyCond*> (GetActiveObj(pad, kind_Poly));
01351 if(cond==0) return;
01352 fiPickCounter++;
01353 }
01354
01355 if (cond != 0) {
01356 TCutG* cut = cond->GetCut(kFALSE);
01357
01358
01359 if (cut == 0) {
01360 cut = new TCutG(TGo4PolyCond::NextAvailableName(), 1);
01361 cut->SetPoint(0, x, y);
01362 cond->SetValuesDirect(cut);
01363 } else {
01364 cut->InsertPoint();
01365 }
01366
01367 cond->SetChanged(kTRUE);
01368
01369 int ix = GetNumMarkers(pad, kind_Poly);
01370
01371 cond->SetLineColor(ix % 6 + 2);
01372 cond->SetFillColor(ix % 6 + 2);
01373 cond->SetFillStyle(3002);
01374 }
01375
01376
01377 TGo4Slot* condslot = GetSelectedSlot(pad, 0, 0);
01378 if (GetDrawKind(condslot) == kind_Condition) {
01379 TGo4Condition* maincond =
01380 dynamic_cast<TGo4Condition*>(condslot->GetAssignedObject());
01381 if (maincond!=0) maincond->SetChanged(kTRUE);
01382 }
01383
01384 if (iscreated)
01385 cond->Draw("");
01386
01387 pad->Modified();
01388 pad->Update();
01389
01390 break;
01391 }
01392
01393 case kMousePickLatex: {
01394 gROOT->SetEditorMode("");
01395 if (docreate) {
01396 int ix = GetNumMarkers(pad, kind_Latex);
01397 QString name = QString("Label ") + QString::number(ix + 1);
01398 bool ok;
01399 QString txt = QInputDialog::getText(this,
01400 "Enter new LaTeX label text:", name, QLineEdit::Normal,
01401 QString::null, &ok);
01402 if (ok && (txt.length() > 0)) {
01403 TLatex* latex = new TLatex(x, y, name.toLatin1().constData());
01404 latex->SetName(name.toLatin1().constData());
01405 latex->SetTitle(txt.toLatin1().constData());
01406 AddMarkerObj(pad, kind_Latex, latex);
01407 latex->Draw();
01408 } else {
01409 fiMouseMode = kMouseROOT;
01410 }
01411 } else {
01412 TLatex* latex = dynamic_cast<TLatex*>(GetActiveObj(pad, kind_Latex));
01413 if(latex!=0) {
01414 latex->SetX(x);
01415 latex->SetY(y);
01416 }
01417 }
01418 if (!fbPickAgain)
01419 fiMouseMode = kMouseROOT;
01420
01421 pad->Modified();
01422 pad->Update();
01423
01424 break;
01425 }
01426
01427 case kMouseDraw: {
01428 gROOT->SetEditorMode("");
01429 if (fiPickCounter == 0) {
01430
01431 TArrow* arrow = new TArrow(x, y, x, y, 0.02);
01432 AddMarkerObj(pad, kind_Arrow, arrow);
01433 fiPickCounter++;
01434 arrow->Draw("");
01435 } else if (fiPickCounter == 1) {
01436 TArrow* arrow = dynamic_cast<TArrow*>(GetActiveObj(pad, kind_Arrow));
01437 if(arrow!=0) {
01438 arrow->SetX2(x);
01439 arrow->SetY2(y);
01440 }
01441 if(!fbPickAgain) fiMouseMode=kMouseROOT;
01442 fiPickCounter=0;
01443 } else {
01444 std::cout <<"TGo4ViewPanel:MouseClick() NEVER COME HERE" << std::endl;
01445 return;
01446 }
01447
01448 pad->Modified();
01449 pad->Update();
01450
01451
01452 break;
01453 }
01454 }
01455
01456 if (docheck)
01457 CheckActionAtTheEnd(pad);
01458 }
01459
01460 void TGo4ViewPanel::CheckActionAtTheEnd(TPad* pad)
01461 {
01462 bool goback = true;
01463
01464
01465
01466
01467
01468
01469
01470
01471
01472
01473
01474
01475
01476
01477
01478
01479
01480
01481
01482
01483
01484 if (goback) {
01485 if (fbLeaveFocusAfterCondEnd)
01486 ServiceCall("ActivateConditionEditor");
01487 fbLeaveFocusAfterCondEnd = false;
01488
01489
01490 }
01491 }
01492
01493 bool TGo4ViewPanel::CompleteMarkerEdit(TPad* pad)
01494 {
01495 bool res = false;
01496 bool needredraw = false;
01497 bool needupdate = false;
01498 bool needrefresh = false;
01499 bool docheck = false;
01500 bool candelete = !IsConditionSelected(pad);
01501
01502 switch (fiMouseMode) {
01503 case kMousePickLimits: {
01504 if (fiPickCounter > 0) {
01505 TGo4WinCond* cond = dynamic_cast<TGo4WinCond*>(GetActiveObj(pad, kind_Window));
01506 if (cond!=0) {
01507 if (candelete) DeleteDrawObject(pad, cond);
01508 needredraw = true;
01509 }
01510 fiPickCounter = 0;
01511 if(!fbPickAgain) fiMouseMode=kMouseROOT;
01512 docheck = true;
01513 }
01514
01515 res = true;
01516 break;
01517 }
01518
01519 case kMousePickPolygon: {
01520 if (fiPickCounter>0) {
01521 TGo4PolyCond* cond = dynamic_cast<TGo4PolyCond*> (GetActiveObj(pad,kind_Poly));
01522 if (cond!=0) {
01523 bool delcond = true;
01524 TCutG* cut = cond->GetCut(kFALSE);
01525 if (cut!=0) {
01526 int n = cut->GetN();
01527 Double_t x, y;
01528 cut->GetPoint(0, x, y);
01529 delcond = (n<3);
01530
01531 if (n>=3)
01532 cut->SetPoint(n, x, y);
01533
01534 int ix = GetNumMarkers(pad, kind_Poly);
01535 cond->SetLineColor(ix%6 +2);
01536 cond->SetFillColor(ix%6 +2);
01537 cond->SetFillStyle(3002);
01538 }
01539
01540 if (delcond && candelete) {
01541 DeleteDrawObject(pad, cond);
01542 needredraw = true;
01543 } else {
01544 needupdate = true;
01545 }
01546 }
01547 if(!fbPickAgain) fiMouseMode=kMouseROOT;
01548 fiPickCounter = 0;
01549 docheck = true;
01550 }
01551
01552 needrefresh = true;
01553 res = true;
01554 break;
01555 }
01556
01557 case kMouseDraw: {
01558 if (fiPickCounter>0) {
01559 TArrow* arrow = dynamic_cast<TArrow*> (GetActiveObj(pad, kind_Arrow));
01560 if (arrow!=0) {
01561 DeleteDrawObject(pad, arrow);
01562 needredraw = true;
01563 }
01564 fiPickCounter = 0;
01565 if(!fbPickAgain) fiMouseMode=kMouseROOT;
01566 }
01567 res = true;
01568 break;
01569 }
01570 }
01571 if (needredraw)
01572 RedrawPanel(pad, true);
01573 else {
01574 if (needupdate) {
01575 pad->Modified();
01576 pad->Update();
01577 }
01578 if (needrefresh)
01579 RefreshButtons();
01580 }
01581
01582 if (docheck)
01583 CheckActionAtTheEnd(pad);
01584
01585 return res;
01586 }
01587
01588 void TGo4ViewPanel::PadDoubleClickedSlot(TPad* pad)
01589 {
01590 if (CompleteMarkerEdit(pad))
01591 return;
01592
01593 if (GetNumberOfPads(GetCanvas()) <= 1)
01594 return;
01595
01596 if (fxDoubleClickTimerPad != 0)
01597 return;
01598 fxDoubleClickTimerPad = pad;
01599 QTimer::singleShot(100, this, SLOT(ProcessPadDoubleClick()));
01600 }
01601
01602 void TGo4ViewPanel::CanvasDropEventSlot(QDropEvent* event, TPad* pad)
01603 {
01604 emit widgetService(this, service_DropEvent, (const char*) pad, event);
01605 }
01606
01607 void TGo4ViewPanel::CanvasStatusEventSlot(const char* message)
01608 {
01609 if (CanvasStatus != 0)
01610 CanvasStatus->showMessage(message);
01611 }
01612
01613 void TGo4ViewPanel::ProcessPadDoubleClick()
01614 {
01615 if (fxDoubleClickTimerPad == 0) return;
01616
01617 TGo4Picture pic;
01618 MakePictureForPad(&pic, fxDoubleClickTimerPad, true);
01619 fxDoubleClickTimerPad = 0;
01620
01621 if (pic.GetNumObjNames() == 0) return;
01622
01623 TGo4ViewPanel* newpanel = CreateViewPanel();
01624 newpanel->ProcessPictureRedraw("", newpanel->GetCanvas(), &pic);
01625 newpanel->ShootRepaintTimer();
01626 }
01627
01628 void TGo4ViewPanel::MenuCommandExecutedSlot(TObject* obj, const char* cmdname)
01629 {
01630 TPad* pad = dynamic_cast<TPad*>(obj);
01631 if (pad != 0)
01632 UpdatePadStatus(pad, true);
01633
01634 Browser()->Scan_gROOT();
01635
01636 if ((strcmp(cmdname, "UnZoom") == 0) && obj->InheritsFrom(TAxis::Class())) {
01637
01638
01639
01640 TGo4Iter iter(GetPanelSlot(), kTRUE);
01641 TGo4Slot* subslot = 0;
01642
01643 do {
01644 if (subslot == 0)
01645 subslot = GetPanelSlot();
01646 else
01647 subslot = iter.getslot();
01648
01649 TPad* subpad = GetSlotPad(subslot);
01650 if (subpad == 0)
01651 continue;
01652
01653 TGo4Slot* sislot = GetSuperimposeSlot(subslot);
01654 if (sislot == 0)
01655 continue;
01656
01657 THStack* hs = dynamic_cast<THStack*>(sislot->GetAssignedObject());
01658 if(hs==0) continue;
01659
01660 TH1* framehisto = hs->GetHistogram();
01661 if (framehisto == 0) continue;
01662
01663 if (framehisto->GetXaxis() != obj) continue;
01664
01665 TIter next(hs->GetHists());
01666 TH1* hs_h1 = 0;
01667 while ((hs_h1 = (TH1*) next()) != 0)
01668 hs_h1->GetXaxis()->UnZoom();
01669
01670 return;
01671 } while (iter.next());
01672 }
01673
01674 }
01675
01676 void TGo4ViewPanel::CanvasUpdatedSlot()
01677 {
01678 ResizeGedEditor();
01679 }
01680
01681 void TGo4ViewPanel::SaveCanvas()
01682 {
01683 ServiceCall("SavePanelCanvas");
01684 }
01685
01686 void TGo4ViewPanel::ProducePicture()
01687 {
01688 TGo4Picture* pic = new TGo4Picture(GetPanelName(), "Copy of picture");
01689
01690 MakePictureForPad(pic, GetCanvas(), false);
01691
01692 SaveObjectInMemory("", pic);
01693 }
01694
01695 void TGo4ViewPanel::ProduceGraphFromMarkers()
01696 {
01697
01698 TObjArray markers;
01699 CollectSpecialObjects(GetActivePad(), &markers, kind_Marker);
01700 Int_t npts = markers.GetEntries();
01701
01702 if (npts == 0)
01703 return;
01704
01705 TArrayD x(npts), y(npts);
01706
01707 for (Int_t j = 0; j < npts; ++j) {
01708 TGo4Marker* mark = dynamic_cast<TGo4Marker*>(markers[j]);
01709 if (mark == 0) {
01710 std::cout << "NEVER COME HERE: no marker at index " << j << std::endl;
01711 return;
01712 }
01713 x[j] = mark->GetX();
01714 y[j] = mark->GetY();
01715
01716 }
01717
01718
01719 TString grname = GetPanelName() + TString("-Markergraph");
01720 TGraph* graf = new TGraph(npts, x.GetArray(), y.GetArray());
01721 graf->SetName(grname.Data());
01722 graf->SetMarkerStyle(28);
01723 SaveObjectInMemory("", graf);
01724 }
01725
01726 void TGo4ViewPanel::MakePictureForPad(TGo4Picture* pic, TPad* pad,
01727 bool useitemname)
01728 {
01729 TGo4Picture* padopt = GetPadOptions(pad);
01730 TGo4Slot* slot = GetPadSlot(pad);
01731 if ((padopt == 0) || (slot == 0))
01732 return;
01733
01734 pic->CopyOptionsFrom(padopt);
01735
01736 if (pad == GetCanvas() && fbFreezeTitle)
01737 pic->SetTitle(fFreezedTitle.toLatin1().constData());
01738
01739 int objnamenum = 0;
01740
01741 for (int n = 0; n < slot->NumChilds(); n++) {
01742 TGo4Slot* subslot = slot->GetChild(n);
01743 int kind = GetDrawKind(subslot);
01744
01745 if ((kind == kind_Arrow) || (kind == kind_Latex) || (kind == kind_Marker)
01746 || (kind == kind_Window) || (kind == kind_Poly)
01747 || (kind == kind_Specials)) {
01748 TObject* obj = subslot->GetAssignedObject();
01749 const char* drawopt = GetSpecialDrawOption(subslot);
01750 if (obj != 0) {
01751 obj = obj->Clone();
01752 TGo4Marker* mark = dynamic_cast<TGo4Marker*>(obj);
01753 if (mark != 0)
01754 mark->DeletePainter();
01755 TGo4Condition* cond = dynamic_cast<TGo4Condition*>(obj);
01756 if (cond != 0)
01757 cond->DeletePainter();
01758 TLatex* lat = dynamic_cast<TLatex*>(obj);
01759 if (lat != 0) {
01760
01761 TGo4Proxy* prox = subslot->GetProxy();
01762 TGo4ObjectProxy* oprox = dynamic_cast<TGo4ObjectProxy*>(prox);
01763 TGo4LinkProxy* lprox = dynamic_cast<TGo4LinkProxy*>(prox);
01764 if (oprox != 0) {
01765
01766 pic->AddSpecialObject(obj, drawopt);
01767 } else if (lprox) {
01768 const char* itemname = GetLinkedName(subslot);
01769
01770 if (itemname != 0)
01771 pic->AddObjName(itemname, drawopt);
01772 delete obj;
01773 } else {
01774
01775
01776 }
01777 }
01778 else {
01779 pic->AddSpecialObject(obj, drawopt);
01780 }
01781 }
01782 continue;
01783 }
01784
01785 if ((kind != kind_Link) && (kind != kind_Condition))
01786 continue;
01787
01788 const char* drawopt = padopt->GetDrawOption(objnamenum++);
01789
01790 if (useitemname) {
01791 const char* itemname = GetLinkedName(subslot);
01792 if (itemname != 0)
01793 pic->AddObjName(itemname, drawopt);
01794 } else {
01795 TNamed* nm = dynamic_cast<TNamed*>(subslot->GetAssignedObject());
01796 if (nm!=0) pic->AddObjName(nm->GetName(), drawopt);
01797 }
01798
01799 Int_t rebinx, rebiny;
01800 if (subslot->GetIntPar("::HasRebinX", rebinx))
01801 pic->SetRebinX(rebinx);
01802 if (subslot->GetIntPar("::HasRebinY", rebiny))
01803 pic->SetRebinY(rebiny);
01804 }
01805
01806 TObjArray pads;
01807
01808 for (int n = 0; n < slot->NumChilds(); n++) {
01809 TGo4Slot* subslot = slot->GetChild(n);
01810 TPad* subpad = GetSlotPad(subslot);
01811 if (subpad != 0)
01812 pads.Add(subpad);
01813 }
01814 if (pads.GetLast() < 0)
01815 return;
01816
01817 double lastx = -1;
01818 int xcnt = 0, sizex = 1, sizey = 1;
01819 for (int n = 0; n <= pads.GetLast(); n++) {
01820 TPad* subpad = (TPad*) pads.At(n);
01821 double mitx = subpad->GetXlowNDC() + subpad->GetWNDC() / 2.;
01822 if (mitx > lastx) {
01823 xcnt++;
01824 lastx = mitx;
01825 } else {
01826 xcnt = 0;
01827 lastx = -1;
01828 }
01829 if (xcnt > sizex)
01830 sizex = xcnt;
01831 }
01832
01833 while (sizex * sizey <= pads.GetLast())
01834 sizey++;
01835
01836 pic->SetDivision(sizey, sizex);
01837
01838 for (int ny = 0; ny < sizey; ny++)
01839 for (int nx = 0; nx < sizex; nx++) {
01840 int indx = ny * sizex + nx;
01841 if (indx > pads.GetLast())
01842 break;
01843 TPad* subpad = (TPad*) pads.At(indx);
01844 MakePictureForPad(pic->Pic(ny, nx), subpad, useitemname);
01845 }
01846 }
01847
01848 void TGo4ViewPanel::PrintCanvas()
01849 {
01850 TGo4PrintWidget dlg;
01851 if (dlg.exec() != QDialog::Accepted)
01852 return;
01853
01854 go4sett->setPrinterSett(dlg.GetPrinter(), dlg.GetPrintProg());
01855
01856 QString outfile = "~/go4printout.ps";
01857 QString PrnCmd = dlg.GetPrintProg() + " -P " + dlg.GetPrinter() + " "
01858 + outfile;
01859 QString DelCmd = QString("rm -f ") + outfile;
01860
01861 GetCanvas()->Print(outfile.toLatin1().constData());
01862 gSystem->Exec(PrnCmd.toLatin1().constData());
01863 gSystem->Exec(DelCmd.toLatin1().constData());
01864 }
01865
01866 void TGo4ViewPanel::StartRootEditor()
01867 {
01868 #ifndef __NOGO4GED__
01869 fbEditorFrameVisible = !fbEditorFrameVisible;
01870 EditorFrame->setVisible(fbEditorFrameVisible);
01871 if (fbEditorFrameVisible && (fxPeditor == 0)) {
01872 TGo4LockGuard lock(0, true);
01873 SetActivePad(GetCanvas());
01874 fxRooteditor->SetResizeOnPaint(kFALSE);
01875 fxRooteditor->SetEditable();
01876 fxPeditor = TVirtualPadEditor::LoadEditor();
01877 fxPeditor->SetGlobal(kFALSE);
01878 fxRooteditor->SetEditable(kFALSE);
01879 ActivateInGedEditor(GetSelectedObject(GetActivePad(), 0));
01880 } else {
01881 ActivateInGedEditor(0);
01882 }
01883
01884 show();
01885 ResizeGedEditor();
01886 #endif
01887 }
01888
01889 void TGo4ViewPanel::StartConditionEditor()
01890 {
01891 TGo4Slot* padslot = GetPadSlot(GetActivePad());
01892 if (padslot == 0)
01893 return;
01894
01895 for (int n = 0; n < padslot->NumChilds(); n++) {
01896 TGo4Slot* subslot = padslot->GetChild(n);
01897 int drawkind = GetDrawKind(subslot);
01898 if (drawkind != kind_Condition)
01899 continue;
01900 const char* itemname = GetLinkedName(subslot);
01901 if (itemname != 0) {
01902 EditItem(itemname);
01903 return;
01904 }
01905 }
01906 }
01907
01908 void TGo4ViewPanel::RectangularRatio()
01909 {
01910 TPad *pad = GetActivePad();
01911 if (pad == 0)
01912 return;
01913
01914 double dx = fabs(pad->AbsPixeltoX(1) - pad->AbsPixeltoX(0));
01915 double dy = fabs(pad->AbsPixeltoY(1) - pad->AbsPixeltoY(0));
01916
01917 if ((dx <= 0) || (dy <= 0))
01918 return;
01919
01920 double ratio = dx / dy;
01921
01922 if (ratio < 1.) {
01923 double left = pad->GetLeftMargin();
01924 double right = pad->GetRightMargin();
01925 double change = (1. - left - right) * (1 - ratio);
01926 pad->SetLeftMargin(left + change / 2.);
01927 pad->SetRightMargin(right + change / 2.);
01928 } else {
01929 double bottom = pad->GetBottomMargin();
01930 double top = pad->GetTopMargin();
01931 double change = (1. - bottom - top) * (1. - 1 / ratio);
01932 pad->SetTopMargin(top + change / 2.);
01933 pad->SetBottomMargin(bottom + change / 2.);
01934 }
01935
01936 RedrawPanel(pad, true);
01937 }
01938
01939 void TGo4ViewPanel::DefaultPadMargin()
01940 {
01941 TPad *pad = GetActivePad();
01942 if (pad == 0)
01943 return;
01944
01945 pad->SetLeftMargin(gStyle->GetPadLeftMargin());
01946 pad->SetRightMargin(gStyle->GetPadRightMargin());
01947 pad->SetTopMargin(gStyle->GetPadTopMargin());
01948 pad->SetBottomMargin(gStyle->GetPadBottomMargin());
01949
01950 RedrawPanel(pad, true);
01951 }
01952
01953 void TGo4ViewPanel::ClearActivePad()
01954 {
01955 TPad* pad = GetActivePad();
01956 if (pad == 0)
01957 pad = GetCanvas();
01958
01959 ClearPad(pad, true, false);
01960
01961 RedrawPanel(pad, true);
01962 }
01963
01964 void TGo4ViewPanel::ClearCanvas()
01965 {
01966
01967
01968 ClearPad(GetCanvas(), true, true);
01969
01970 SetPadDefaults(GetCanvas());
01971
01972 RedrawPanel(GetCanvas(), true);
01973 }
01974
01975 void TGo4ViewPanel::AboutToShowOptionsMenu()
01976 {
01977 TPad* pad = GetActivePad();
01978 if (pad == 0)
01979 pad = GetCanvas();
01980
01981 TGo4Picture *padopt = GetPadOptions(pad);
01982
01983 SetIdAction(fOptionsMap, StatisticsId, true, padopt->IsHisStats());
01984 SetIdAction(fOptionsMap, SuperimposeId, true, padopt->IsSuperimpose());
01985 SetIdAction(fOptionsMap, SetTitleId, true, padopt->IsHisTitle());
01986 SetIdAction(fOptionsMap, DrawTimeId, padopt->IsHisTitle() && fbCloneFlag,
01987 padopt->IsTitleTime());
01988 SetIdAction(fOptionsMap, DrawDateId, padopt->IsHisTitle() && fbCloneFlag,
01989 padopt->IsTitleDate());
01990 SetIdAction(fOptionsMap, DrawItemnameId, padopt->IsHisTitle() && fbCloneFlag,
01991 padopt->IsTitleItem());
01992 SetIdAction(fOptionsMap, FreezeTitleId, true, fbFreezeTitle);
01993 SetIdAction(fOptionsMap, CrosshairId, true, fbCanvasCrosshair);
01994 SetIdAction(fOptionsMap, SetLegendId, true, padopt->IsLegendDraw());
01995 SetIdAction(fOptionsMap, AxisTimeDisplayId, true,
01996 padopt->IsXAxisTimeDisplay());
01997 }
01998
01999 void TGo4ViewPanel::SelectMenuItemActivated(int id)
02000 {
02001 TGo4LockGuard lock(0, true);
02002 if (id == BringToFrontId) {
02003 if (ShiftSelectedObjectToEnd(GetActivePad())) {
02004 MarkPadModified(GetActivePad());
02005 ShootRepaintTimer(GetActivePad());
02006 }
02007 return;
02008 }
02009
02010 int selected = TGo4Picture::PictureIndex;
02011
02012 if (id != MasterSelectId)
02013 selected = id - FirstSelectId;
02014
02015 TGo4Slot* slot = GetPadSlot(GetActivePad());
02016 if (slot == 0)
02017 return;
02018
02019 int wasselected = GetSelectedObjectIndex(slot);
02020
02021 SetSelectedObjectIndex(slot, selected);
02022
02023 if (selected != wasselected) {
02024 CallPanelFunc(panel_Updated, GetActivePad());
02025 UpdatePanelCaption();
02026 }
02027
02028 if (selected != TGo4Picture::PictureIndex)
02029 ActivateInGedEditor(GetSelectedObject(GetActivePad(), 0));
02030 }
02031
02032 void TGo4ViewPanel::ShowEventStatus()
02033 {
02034 fbCanvasEventstatus = !fbCanvasEventstatus;
02035
02036 fxQCanvas->setShowEventStatus(fbCanvasEventstatus);
02037 CanvasStatus->setVisible(fbCanvasEventstatus);
02038 if (!fbCanvasEventstatus)
02039 DisplayPadStatus(GetActivePad());
02040 }
02041
02042 void TGo4ViewPanel::UpdatePadStatus(TPad* pad, bool removeitems)
02043 {
02044 if (GetPadSlot(pad) == 0)
02045 return;
02046
02047 BlockPanelRedraw(true);
02048 ProcessPadStatusUpdate(pad, 0, removeitems);
02049 BlockPanelRedraw(false);
02050 }
02051
02052 void TGo4ViewPanel::ProcessPadStatusUpdate(TPad* pad, TGo4Slot* parent,
02053 bool removeitems)
02054 {
02055 if (pad == 0)
02056 return;
02057
02058 TGo4Slot* slot = 0;
02059
02060 bool setdefaults = false;
02061 if (parent == 0) {
02062 slot = GetPadSlot(pad);
02063 if (slot == 0)
02064 return;
02065 } else {
02066 slot = parent->FindChild(pad->GetName());
02067
02068 if (slot == 0) {
02069 slot = AddNewSlot(pad->GetName(), parent);
02070 SetDrawKind(slot, kind_PadSlot);
02071 setdefaults = true;
02072 }
02073 }
02074
02075 SetSlotPad(slot, pad);
02076
02077 TGo4Picture* padopt = GetPadOptions(slot);
02078
02079 padopt->SetPadModified();
02080
02081 bool issubpads = false;
02082
02083 bool isdupluicate = false;
02084
02085
02086
02087 do {
02088 TObjArray subpads;
02089 isdupluicate = false;
02090 TIter iter(pad->GetListOfPrimitives());
02091 TObject* obj = 0;
02092 while ((obj = iter()) != 0) {
02093 TPad* subpad = dynamic_cast<TPad*>(obj);
02094 if (subpad == 0)
02095 continue;
02096 issubpads = true;
02097 if (subpads.FindObject(subpad->GetName()) != 0)
02098 isdupluicate = true;
02099 if (!isdupluicate)
02100 subpads.Add(subpad);
02101 }
02102 if (isdupluicate) {
02103 pad->GetListOfPrimitives()->RemoveAll(&subpads);
02104 subpads.Delete();
02105 subpads.Compress();
02106 padopt->SetPadModified();
02107 }
02108
02109 } while (isdupluicate);
02110
02111
02112 for (int n = slot->NumChilds() - 1; n >= 0; n--) {
02113 TGo4Slot* subslot = slot->GetChild(n);
02114 TPad* subpad = GetSlotPad(subslot);
02115 if (subpad != 0)
02116 if (pad->GetListOfPrimitives()->FindObject(subpad) == 0)
02117 delete subslot;
02118 else
02119 issubpads = true;
02120 }
02121
02122 if (setdefaults)
02123 SetPadDefaults(pad);
02124
02125 if (!issubpads)
02126 return;
02127
02128 TIter iter(pad->GetListOfPrimitives());
02129 TObjArray removedItems;
02130 TObject* obj = 0;
02131 while ((obj = iter()) != 0) {
02132 TPad* subpad = dynamic_cast<TPad*>(obj);
02133 if (subpad != 0)
02134 ProcessPadStatusUpdate(subpad, slot, removeitems);
02135 else
02136 removedItems.Add(obj);
02137 }
02138
02139 pad->GetListOfPrimitives()->RemoveAll(&removedItems);
02140
02141 if (removeitems)
02142 ClearPadItems(slot, 0);
02143 }
02144
02145 TGo4Slot* TGo4ViewPanel::AddDrawObject(TPad* pad, int kind, const char* itemname,
02146 TObject* obj, bool owner, const char* drawopt)
02147 {
02148 TGo4Slot* padslot = GetPadSlot(pad);
02149
02150 if (padslot == 0) {
02151 if (owner) delete obj;
02152 return 0;
02153 }
02154
02155
02156
02157
02158 if (kind < 100)
02159 ClearPad(pad, false, true);
02160
02161 TGo4Slot* tgtslot = 0;
02162
02163 if (kind == kind_Link) {
02164 TClass* cl = Browser()->ItemClass(itemname);
02165 if ((cl != 0) && cl->InheritsFrom(TGo4Condition::Class()))
02166 UndrawItem(itemname);
02167
02168
02169
02170 TGo4Slot* brslot = Browser()->BrowserSlot(itemname);
02171
02172 if (brslot != 0) {
02173 tgtslot = AddNewSlot(brslot->GetName(), padslot);
02174 SetLinkedName(tgtslot, itemname);
02175 if (fbCloneFlag)
02176 tgtslot->SetProxy(new TGo4DrawCloneProxy(brslot, this));
02177 else
02178 tgtslot->SetProxy(new TGo4LinkProxy(brslot));
02179 }
02180 } else {
02181
02182 QString newslotname = itemname;
02183 if ((newslotname.length() == 0)
02184 || (padslot->FindChild(newslotname.toLatin1().constData()) != 0)) {
02185 int cnt = 0;
02186 do {
02187 if ((itemname == 0) || (*itemname == 0))
02188 newslotname = "::SpecialObject_";
02189 else
02190 newslotname = itemname;
02191 newslotname += QString::number(cnt++);
02192 } while (padslot->FindChild(newslotname.toLatin1().constData()) != 0);
02193 }
02194 tgtslot = AddNewSlot(newslotname.toLatin1().constData(), padslot);
02195 tgtslot->SetProxy(new TGo4ObjectProxy(obj, owner));
02196 }
02197
02198 if (tgtslot == 0) return 0;
02199
02200 if (kind < 100)
02201 CallPanelFunc(panel_Modified, pad);
02202
02203 tgtslot->SetPar("::FirstDraw", "true");
02204 SetDrawKind(tgtslot, kind);
02205 SetSpecialDrawOption(tgtslot, drawopt);
02206
02207 TGo4Picture* padopt = GetPadOptions(padslot);
02208 if (padopt != 0) {
02209 padopt->SetContentModified(true);
02210 padopt->SetPadModified();
02211 if ((kind < 100) && (drawopt != 0))
02212 padopt->SetDrawOption(drawopt, TGo4Picture::PictureIndex);
02213 }
02214
02215 return tgtslot;
02216 }
02217
02218 TGo4Slot* TGo4ViewPanel::GetDrawObjectSlot(TPad* pad, const char* name)
02219 {
02220 TGo4Slot* slot = GetPadSlot(pad);
02221
02222 return slot == 0 ? 0 : slot->FindChild(name);
02223 }
02224
02225 TObject* TGo4ViewPanel::GetDrawObject(TPad* pad, const char* name)
02226 {
02227 TGo4Slot* subslot = GetDrawObjectSlot(pad, name);
02228
02229 return subslot == 0 ? 0 : subslot->GetAssignedObject();
02230 }
02231
02232 void TGo4ViewPanel::DeleteDrawObject(TPad* pad, const char* name)
02233 {
02234 TGo4Slot* padslot = GetPadSlot(pad);
02235
02236 TGo4Slot* subslot = padslot == 0 ? 0 : padslot->FindChild(name);
02237
02238 if (subslot != 0) {
02239 delete subslot;
02240 TGo4Picture* padopt = GetPadOptions(padslot);
02241 if (padopt != 0)
02242 padopt->SetPadModified();
02243 }
02244 }
02245
02246 void TGo4ViewPanel::DeleteDrawObject(TPad* pad, TObject* obj)
02247 {
02248 TGo4Slot* padslot = GetPadSlot(pad);
02249 if (padslot == 0)
02250 return;
02251 for (int n = 0; n < padslot->NumChilds(); n++) {
02252 TGo4Slot* subslot = padslot->GetChild(n);
02253 if (GetDrawKind(subslot) < 0)
02254 continue;
02255 if (subslot->GetAssignedObject() == obj) {
02256 delete subslot;
02257 break;
02258 }
02259 }
02260 }
02261
02262 void TGo4ViewPanel::CollectSpecialObjects(TPad* pad, TObjArray* objs,
02263 int selectkind)
02264 {
02265 TGo4Slot* slot = GetPadSlot(pad);
02266 if ((slot == 0) || (objs == 0))
02267 return;
02268
02269 for (int n = 0; n < slot->NumChilds(); n++) {
02270 TGo4Slot* subslot = slot->GetChild(n);
02271 Int_t kind = GetDrawKind(subslot);
02272 if (kind < 0)
02273 continue;
02274 if ((kind != kind_Link) && ((selectkind < 0) || (kind == selectkind))) {
02275 TObject* obj = subslot->GetAssignedObject();
02276 if (obj != 0)
02277 objs->Add(obj);
02278 }
02279 }
02280 }
02281
02282 bool TGo4ViewPanel::DeleteDrawObjects(TPad* pad, int kindtodelete)
02283 {
02284 TGo4Slot* slot = GetPadSlot(pad);
02285 TGo4Picture* padopt = GetPadOptions(slot);
02286
02287 if ((slot == 0) || (padopt == 0))
02288 return false;
02289
02290 bool res = false;
02291
02292 for (int n = slot->NumChilds() - 1; n >= 0; n--) {
02293 TGo4Slot* subslot = slot->GetChild(n);
02294 Int_t kind = GetDrawKind(subslot);
02295 if (kind < 0)
02296 continue;
02297 if ((kind != kind_Link)
02298 && ((kindtodelete < 0) || (kind == kindtodelete))) {
02299 res = true;
02300 delete subslot;
02301 }
02302 }
02303 if (res)
02304 padopt->SetPadModified();
02305 return true;
02306 }
02307
02308 void TGo4ViewPanel::SetPadSuperImpose(TPad* pad, bool on)
02309 {
02310 TGo4Picture* padopt = GetPadOptions(pad);
02311 if (padopt != 0) {
02312 padopt->SetSuperimpose(on);
02313 padopt->SetPadModified();
02314 }
02315 }
02316
02317 void TGo4ViewPanel::ProcessPadModifiedSignal()
02318 {
02319 fbModifiedSignalFlag = false;
02320 if (GetActivePad() == 0)
02321 return;
02322
02323 if (ScanDrawOptions(GetActivePad(), GetPadSlot(GetActivePad()),
02324 GetPadOptions(GetActivePad()), true))
02325 CallPanelFunc(panel_Updated, GetActivePad());
02326 }
02327
02328 bool TGo4ViewPanel::ScanDrawOptions(TPad* pad, TGo4Slot* padslot,
02329 TGo4Picture* pic, bool onlyscan)
02330 {
02331 TGo4LockGuard lock(0, true);
02332
02333 if ((pad == 0) || (pic == 0) || (padslot == 0))
02334 return false;
02335
02336 bool optchanged = false;
02337 TObjLink* link = pad->GetListOfPrimitives()->FirstLink();
02338
02339 while (link != 0) {
02340 const char* clname = link->GetObject()->ClassName();
02341 if ((strcmp(clname, "TFrame") == 0) || (strcmp(clname, "TLegend") == 0)) {
02342 TPaveText* titl = dynamic_cast<TPaveText*>(link->GetObject());
02343 if (titl &&(strcmp(titl->GetName(),"title")==0))
02344 pic->SetTitleAttr(titl);
02345 link = link->Next();
02346 } else
02347 break;
02348 }
02349
02350
02351 if (link != 0) {
02352
02353 TString newopt(link->GetOption());
02354 Int_t drawoptindx =
02355 GetSuperimposeSlot(padslot) == 0 ? 0 : TGo4Picture::PictureIndex;
02356 TString oldopt(pic->GetDrawOption(drawoptindx));
02357
02358 while (newopt.BeginsWith(NoStackDrawOption, TString::kIgnoreCase))
02359 newopt.Remove(0, strlen(NoStackDrawOption));
02360
02361 if (!oldopt.Contains("asimage"))
02362 if ((newopt.Length() != oldopt.Length())
02363 || (newopt.CompareTo(oldopt, TString::kIgnoreCase) != 0)) {
02364 optchanged = true;
02365 pic->SetDrawOption(newopt.Data(), drawoptindx);
02366 }
02367
02368 TH1* h1 = dynamic_cast<TH1*>(link->GetObject());
02369
02370 if(h1==0) {
02371 TGraph* gr=dynamic_cast<TGraph*> (link->GetObject());
02372 if(gr) h1=gr->GetHistogram();
02373 }
02374
02375 if (h1 != 0) {
02376 TPaveStats* stats =
02377 dynamic_cast<TPaveStats*>(h1->GetListOfFunctions()->FindObject("stats"));
02378 if (h1->TestBit(TH1::kNoStats)) {
02379 pic->SetHisStats(kFALSE);
02380 } else {
02381 pic->SetHisStats(kTRUE);
02382 pic->SetStatsAttr(stats);
02383 }
02384
02385 TAxis* xax = h1->GetXaxis();
02386 pic->SetXAxisAttTime(xax->GetTimeDisplay(), xax->GetTimeFormat() ,TGo4Picture::PictureIndex);
02387
02388 }
02389
02390 }
02391
02392 if (pad->GetLogx() != pic->GetLogScale(0)) {
02393 pic->SetLogScale(0, pad->GetLogx());
02394 optchanged = true;
02395 }
02396
02397 if (pad->GetLogy() != pic->GetLogScale(1)) {
02398 pic->SetLogScale(1, pad->GetLogy());
02399 optchanged = true;
02400 }
02401
02402 if (pad->GetLogz() != pic->GetLogScale(2)) {
02403 pic->SetLogScale(2, pad->GetLogz());
02404 optchanged = true;
02405 }
02406
02407 if (pad == GetCanvas())
02408 fbCanvasCrosshair = pad->HasCrosshair();
02409
02410 TPaveText* titl =
02411 dynamic_cast<TPaveText*>(pad->GetListOfPrimitives()->FindObject("title"));
02412 if(titl) {
02413 pic->SetTitleAttr(titl);
02414 optchanged = true;
02415 }
02416
02417 TObjArray objs, objslots;
02418
02419 CollectMainDrawObjects(padslot, &objs, &objslots, 0);
02420 ScanObjectsDrawOptions(onlyscan, padslot, &objs, &objslots);
02421
02422 return optchanged;
02423 }
02424
02425 void TGo4ViewPanel::ScanObjectsDrawOptions(bool onlyscan, TGo4Slot* padslot,
02426 TObjArray* objs, TObjArray* objslots)
02427 {
02428 TGo4Picture* pic = GetPadOptions(padslot);
02429
02430 TPad* pad = GetSlotPad(padslot);
02431 if ((pad != 0) && (pic != 0))
02432 if (padslot->GetPar("::DrawOptAssigned") != 0) {
02433 pic->SetDrawAttributes(pad, TGo4Picture::PictureIndex);
02434 } else if (!onlyscan) {
02435 pic->GetDrawAttributes(pad, TGo4Picture::PictureIndex);
02436 padslot->SetPar("::DrawOptAssigned", "1");
02437 }
02438
02439 if ((padslot == 0) || (pic == 0) || (objs == 0) || (objslots == 0))
02440 return;
02441
02442 for (int n = 0; n <= objs->GetLast(); n++) {
02443 TObject* obj = objs->At(n);
02444 TGo4Slot* subslot = (TGo4Slot*) objslots->At(n);
02445
02446 if ((obj == 0) || (subslot == 0))
02447 continue;
02448
02449 if (subslot->GetPar("::DrawOptAssigned") != 0) {
02450 pic->SetDrawAttributes(obj, n);
02451 } else if (!onlyscan) {
02452 pic->GetDrawAttributes(obj, n);
02453 subslot->SetPar("::DrawOptAssigned", "1");
02454 }
02455 }
02456 }
02457
02458 void TGo4ViewPanel::CollectMainDrawObjects(TGo4Slot* slot, TObjArray* objs,
02459 TObjArray* objslots, int modifier)
02460 {
02461
02462
02463
02464 if ((slot == 0) || (objs == 0))
02465 return;
02466
02467 TObjArray mainslots;
02468
02469 int lastobjtype = 0;
02470
02471 for (int n = 0; n < slot->NumChilds(); n++) {
02472 TGo4Slot* subslot = slot->GetChild(n);
02473 Int_t kind = GetDrawKind(subslot);
02474
02475 if ((kind <= 0) || (kind >= kind_Additional))
02476 continue;
02477
02478 TObject* obj = subslot->GetAssignedObject();
02479
02480 if (obj == 0)
02481 continue;
02482
02483 int objtype = 0;
02484
02485 if (obj->InheritsFrom(TH1::Class()))
02486 objtype = 1;
02487 else if (obj->InheritsFrom(TGraph::Class()))
02488 objtype = 2;
02489 else if (obj->InheritsFrom(TMultiGraph::Class()))
02490 objtype = 3;
02491 else if (obj->InheritsFrom(THStack::Class()))
02492 objtype = 4;
02493
02494
02495
02496 if (objtype > 0) {
02497 lastobjtype = objtype;
02498 mainslots.Add(subslot);
02499 }
02500 }
02501
02502 Bool_t deletesomething = kFALSE;
02503
02504 for (int n = 0; n <= mainslots.GetLast(); n++) {
02505 TGo4Slot* subslot = (TGo4Slot*) mainslots.At(n);
02506 TObject* obj = subslot->GetAssignedObject();
02507 Int_t objtype = 0;
02508 if (obj->InheritsFrom(TH1::Class()))
02509 objtype = 1;
02510 else if (obj->InheritsFrom(TGraph::Class()))
02511 objtype = 2;
02512 else if (obj->InheritsFrom(TMultiGraph::Class()))
02513 objtype = 3;
02514 else if (obj->InheritsFrom(THStack::Class()))
02515 objtype = 4;
02516
02517
02518
02519
02520 if ((n < mainslots.GetLast())
02521 && ((modifier == 2) || ((modifier == 1) && (lastobjtype != objtype)))) {
02522 delete subslot;
02523 deletesomething = kTRUE;
02524 } else {
02525 objs->Add(obj);
02526 if (objslots != 0)
02527 objslots->Add(subslot);
02528 TGo4DrawCloneProxy* pr =
02529 dynamic_cast<TGo4DrawCloneProxy*>(subslot->GetProxy());
02530 if(pr!=0) {
02531 pr->UpdateTitle();
02532 pr->PerformRebin();
02533 }
02534 }
02535 }
02536
02537 if (deletesomething)
02538 CleanupGedEditor();
02539
02540 for (int n = 0; n < slot->NumChilds(); n++) {
02541 TGo4Slot* subslot = slot->GetChild(n);
02542
02543 Int_t kind = GetDrawKind(subslot);
02544 if ((kind >= kind_Additional) && (kind < kind_Specials)) {
02545 TObject* obj = subslot->GetAssignedObject();
02546 if (obj != 0) {
02547 objs->Add(obj);
02548 if (objslots != 0)
02549 objslots->Add(subslot);
02550 }
02551 }
02552 }
02553 }
02554
02555 TObject* TGo4ViewPanel::ProduceSuperimposeObject(TGo4Slot* padslot, TGo4Picture* padopt,
02556 TGo4Slot* sislot, TGo4Slot* legslot, TObjArray* objs,
02557 TObjArray * objslots, bool showitems)
02558 {
02559 if ((sislot == 0) || (objs == 0) || (padopt == 0)) return 0;
02560
02561 TObject* oldobj = sislot->GetAssignedObject();
02562
02563 Bool_t ishstack = kFALSE;
02564 Bool_t isgstack = kFALSE;
02565 Bool_t iserror = kFALSE;
02566 Bool_t resetcolors = kFALSE;
02567
02568 for (int n = 0; n <= objs->GetLast(); n++) {
02569 TObject* obj = objs->At(n);
02570 if (obj->InheritsFrom(TH1::Class()))
02571 ishstack = kTRUE;
02572 else if (obj->InheritsFrom(TGraph::Class()))
02573 isgstack = kTRUE;
02574 else
02575 iserror = kTRUE;
02576 }
02577
02578
02579 if (iserror || (ishstack && isgstack)) {
02580 std::cerr
02581 << "Error detected: superimpose of multiple objects with different types"
02582 << std::endl;
02583 return 0;
02584 }
02585
02586 if (ishstack) {
02587 THStack* hs = dynamic_cast<THStack*>(oldobj);
02588
02589 if (hs == 0) {
02590 hs = new THStack(objs->First()->GetName(), objs->First()->GetTitle());
02591 sislot->SetProxy(new TGo4DrawObjProxy(hs, kTRUE, kTRUE));
02592 resetcolors = kTRUE;
02593 } else {
02594 if (hs->GetHists())
02595 hs->GetHists()->Clear();
02596 }
02597
02598 for (int n = 0; n <= objs->GetLast(); n++) {
02599 TH1* histo = (TH1*) objs->At(n);
02600 TGo4Slot* objslot = (TGo4Slot*) objslots->At(n);
02601
02602 Int_t kind = GetDrawKind(objslot);
02603 Int_t objindx = padslot->GetIndexOf(objslot);
02604
02605 if (resetcolors || (kind == kind_FitModels) || (objslot->GetPar("::FirstDraw") != 0)) {
02606 histo->SetLineColor(((objindx + 7) % 9) + 1);
02607 }
02608 histo->GetXaxis()->UnZoom();
02609
02610 const char* drawopt = padopt->GetDrawOption(n);
02611 if (drawopt == 0)
02612 drawopt = GetSpecialDrawOption(objslot);
02613
02614 objslot->RemovePar("::FirstDraw");
02615
02616 hs->Add(histo, drawopt);
02617 }
02618 oldobj = hs;
02619 } else if (isgstack) {
02620 TMultiGraph* mgr = dynamic_cast<TMultiGraph*>(oldobj);
02621 if (mgr == 0) {
02622 mgr = new TMultiGraph(objs->First()->GetName(),
02623 objs->First()->GetTitle());
02624 sislot->SetProxy(new TGo4DrawObjProxy(mgr, kTRUE, kTRUE));
02625 resetcolors = kTRUE;
02626 } else if (mgr->GetListOfGraphs()) {
02627 mgr->GetListOfGraphs()->Clear();
02628 }
02629
02630 for (int n = 0; n <= objs->GetLast(); n++) {
02631 TGraph* gr = (TGraph*) objs->At(n);
02632 TGo4Slot* objslot = (TGo4Slot*) objslots->At(n);
02633
02634 Int_t kind = GetDrawKind(objslot);
02635
02636 TString drawopt = padopt->GetDrawOption(n);
02637 if (drawopt.Length() == 0)
02638 drawopt = GetSpecialDrawOption(objslot);
02639 if (drawopt.Length() == 0)
02640 drawopt = go4sett->getTGraphDrawOpt().toLatin1().constData();
02641
02642 if (n > 0) {
02643
02644 drawopt.ReplaceAll("a", "");
02645 drawopt.ReplaceAll("A", "");
02646 }
02647
02648 Bool_t first_draw = objslot->GetPar("::FirstDraw") != 0;
02649
02650 Int_t objindx = padslot->GetIndexOf(objslot);
02651
02652 if (resetcolors || (kind == kind_FitModels) || first_draw) {
02653
02654 Int_t nextcol = ((objindx + 7) % 9) + 1;
02655 gr->SetLineColor(nextcol);
02656 gr->SetMarkerColor(nextcol);
02657 }
02658
02659 if (first_draw && (n==0)) {
02660 TAxis *ax = gr->GetXaxis();
02661 if ((ax!=0) && ax->GetTimeDisplay()) {
02662 padopt->SetHisStats(kFALSE);
02663 padopt->SetXAxisTimeDisplay(kTRUE);
02664 padopt->SetXAxisTimeFormat(ax->GetTimeFormat());
02665 }
02666 }
02667
02668 objslot->RemovePar("::FirstDraw");
02669
02670 mgr->Add(gr, drawopt.Data());
02671 }
02672 oldobj = mgr;
02673 }
02674
02675 if ((ishstack || isgstack) && (legslot != 0)) {
02676 TLegend* legend = dynamic_cast<TLegend*>(legslot->GetAssignedObject());
02677
02678 if (legend == 0) {
02679 double miny = 0.94 - 0.03 * objs->GetLast();
02680 if (miny < 0.6) miny = 0.6; else if (miny>0.92) miny = 0.92;
02681 legend = new TLegend(0.6, miny, 0.95, 0.99);
02682 legend->SetBorderSize(2);
02683 legend->SetName("fitlegend");
02684 legslot->SetProxy(new TGo4ObjectProxy(legend, kTRUE));
02685 } else
02686 legend->Clear();
02687
02688 for(int n=0;n<=objs->GetLast();n++) {
02689 TObject* stob = objs->At(n);
02690
02691 const char* objname = stob->GetName();
02692
02693 if (showitems && (objslots!=0)) {
02694 const char* itemname = GetLinkedName((TGo4Slot*) objslots->At(n));
02695 if (itemname!=0) objname = itemname;
02696 }
02697
02698 TString ldrawopt = "l";
02699
02700 if (!ishstack) {
02701 ldrawopt = "";
02702 TString drawopt = padopt->GetDrawOption(n);
02703 drawopt.ToLower();
02704 if (drawopt.Contains("l")) ldrawopt+="l";
02705 if (drawopt.Contains("p")) ldrawopt+="p";
02706 }
02707
02708 if (ldrawopt.Length()==0) ldrawopt = "l";
02709
02710 legend->AddEntry(stob, objname, ldrawopt.Data());
02711 }
02712 }
02713
02714 return oldobj;
02715 }
02716
02717 void TGo4ViewPanel::Divide(int numX, int numY)
02718 {
02719 TPad* pad = GetActivePad();
02720
02721 TGo4Slot* padslot = GetPadSlot(pad);
02722 if ((pad == 0) || (padslot == 0)) return;
02723
02724 ClearPad(pad, true, true);
02725 RedrawPanel(pad, true);
02726
02727 if ((numX > 1) || (numY > 1)) {
02728 pad->Divide(numX, numY);
02729
02730 UpdatePadStatus(pad, true);
02731
02732 RedrawPanel(pad, true);
02733 }
02734
02735
02736
02737 }
02738
02739 void TGo4ViewPanel::SetSlotPad(TGo4Slot* padslot, TPad* pad)
02740 {
02741 TGo4Slot* tgtslot = padslot->FindChild("::ThisPad");
02742 if (tgtslot == 0)
02743 tgtslot = new TGo4Slot(padslot, "::ThisPad", "Special object");
02744 tgtslot->SetProxy(new TGo4ObjectProxy(pad, kFALSE));
02745 SetDrawKind(tgtslot, kind_ThisPad);
02746 ConnectPad(pad);
02747
02748 AllocatePadOptions(pad);
02749 }
02750
02751 TGo4Slot* TGo4ViewPanel::GetPadSlot(TPad* pad)
02752 {
02753 if (pad == GetCanvas())
02754 return GetPanelSlot();
02755
02756 TGo4Iter iter(GetPanelSlot(), kTRUE);
02757 while (iter.next()) {
02758 TGo4Slot* subslot = iter.getslot();
02759 if (GetDrawKind(subslot) == kind_PadSlot)
02760 if (GetSlotPad(subslot) == pad)
02761 return subslot;
02762 }
02763 return 0;
02764 }
02765
02766 TPad* TGo4ViewPanel::GetSlotPad(TGo4Slot* slot)
02767 {
02768 if (slot == 0)
02769 return 0;
02770
02771 TGo4Slot* tgtslot = slot->FindChild("::ThisPad");
02772
02773 return tgtslot == 0 ? 0 : (TPad*) tgtslot->GetAssignedObject();
02774 }
02775
02776 bool TGo4ViewPanel::IsPadHasSubPads(TGo4Slot* padslot)
02777 {
02778 if (padslot == 0)
02779 return false;
02780 for (int n = 0; n < padslot->NumChilds(); n++)
02781 if (GetSlotPad(padslot->GetChild(n)) != 0)
02782 return true;
02783 return false;
02784 }
02785
02786 bool TGo4ViewPanel::IsPadHasSubPads(TPad* pad)
02787 {
02788 return IsPadHasSubPads(GetPadSlot(pad));
02789 }
02790
02791 void TGo4ViewPanel::MarkPadModified(TPad* pad)
02792 {
02793 TGo4Picture* padopt = GetPadOptions(pad);
02794 if (padopt != 0)
02795 padopt->SetPadModified();
02796 }
02797
02798 bool TGo4ViewPanel::IsPanelPad(TPad* pad)
02799 {
02800 return GetPadSlot(pad) != 0;
02801 }
02802
02803 int TGo4ViewPanel::GetNumberOfPads(TPad* toppad)
02804 {
02805 if (toppad == 0)
02806 toppad = GetCanvas();
02807 int number = 1;
02808 TGo4Iter iter(GetPadSlot(toppad), kTRUE);
02809 while (iter.next()) {
02810 TPad* pad = GetSlotPad(iter.getslot());
02811 if (pad != 0)
02812 number++;
02813 }
02814 return number;
02815 }
02816
02817 TPad* TGo4ViewPanel::GetSubPad(TPad* toppad, int num, bool onlytoplevel)
02818 {
02819 if (toppad == 0)
02820 toppad = GetCanvas();
02821 TGo4Slot* slot = GetPadSlot(toppad);
02822 if (slot == 0)
02823 return 0;
02824
02825 int cnt = -1;
02826 if (!onlytoplevel || !IsPadHasSubPads(slot))
02827 cnt++;
02828
02829 if (num == cnt)
02830 return toppad;
02831
02832 TGo4Iter iter(slot, kTRUE);
02833 while (iter.next()) {
02834 TGo4Slot* subslot = iter.getslot();
02835 TPad* pad = GetSlotPad(subslot);
02836 if (pad == 0)
02837 continue;
02838 if (!onlytoplevel || !IsPadHasSubPads(subslot))
02839 cnt++;
02840 if (num == cnt)
02841 return pad;
02842 }
02843 return 0;
02844 }
02845
02846 void TGo4ViewPanel::ProducePadsList(TObjArray* arr, TPad* toppad)
02847 {
02848 if (arr == 0)
02849 return;
02850 if (toppad == 0)
02851 toppad = GetCanvas();
02852
02853 arr->Add(toppad);
02854
02855 TGo4Iter iter(GetPadSlot(toppad), kTRUE);
02856 while (iter.next()) {
02857 TPad* pad = GetSlotPad(iter.getslot());
02858 if (pad != 0)
02859 arr->Add(pad);
02860 }
02861 }
02862
02863 const char* TGo4ViewPanel::GetDrawObjectLinkName(TPad * pad, TObject* obj)
02864 {
02865 TGo4Slot* slot = GetPadSlot(pad);
02866 if ((pad == 0) || (slot == 0) || (obj == 0))
02867 return 0;
02868
02869 for (int n = 0; n < slot->NumChilds(); n++) {
02870 TGo4Slot* subslot = slot->GetChild(n);
02871 if (subslot->GetAssignedObject() == obj)
02872 return GetLinkedName(subslot);
02873 }
02874 return 0;
02875 }
02876
02877 TGo4Slot* TGo4ViewPanel::GetSuperimposeSlot(TGo4Slot* padslot)
02878 {
02879 return padslot == 0 ? 0 : padslot->FindChild("::Superimpose");
02880 }
02881
02882 TGo4Slot* TGo4ViewPanel::GetPadMainObjectSlot(TPad* pad)
02883 {
02884 TGo4Slot* slot = GetPadSlot(pad);
02885 if ((pad == 0) || (slot == 0))
02886 return 0;
02887
02888 for (int n = 0; n < slot->NumChilds(); n++) {
02889 TGo4Slot* subslot = slot->GetChild(n);
02890 Int_t kind = GetDrawKind(subslot);
02891 if ((kind <= 0) || (kind >= kind_Additional))
02892 continue;
02893 TObject* obj = subslot->GetAssignedObject();
02894 if (obj != 0)
02895 return subslot;
02896 }
02897 return 0;
02898 }
02899
02900 TObject* TGo4ViewPanel::GetPadMainObject(TPad* pad)
02901 {
02902 TGo4Slot* slot = GetPadMainObjectSlot(pad);
02903 return slot == 0 ? 0 : slot->GetAssignedObject();
02904 }
02905
02906 TCanvas* TGo4ViewPanel::GetCanvas()
02907 {
02908 return fxQCanvas->getCanvas();
02909 }
02910
02911 QRootCanvas* TGo4ViewPanel::GetQCanvas()
02912 {
02913 return fxQCanvas;
02914 }
02915
02916 TPad * TGo4ViewPanel::GetActivePad()
02917 {
02918 return fxActivePad;
02919 }
02920
02921 void TGo4ViewPanel::AllocatePadOptions(TPad* pad)
02922 {
02923 TGo4Slot* padslot = GetPadSlot(pad);
02924 if (padslot == 0)
02925 return;
02926
02927 TGo4Slot* tgtslot = padslot->FindChild("::PadOptions");
02928 if (tgtslot == 0) {
02929 tgtslot = new TGo4Slot(padslot, "::PadOptions", "Pad options slot");
02930 tgtslot->SetProxy(new TGo4ObjectProxy(new TGo4Picture, kTRUE));
02931 SetDrawKind(tgtslot, kind_PadOptions);
02932 }
02933 }
02934
02935 TGo4Picture* TGo4ViewPanel::GetPadOptions(TPad* pad)
02936 {
02937 return GetPadOptions(GetPadSlot(pad));
02938 }
02939
02940 TGo4Picture* TGo4ViewPanel::GetPadOptions(TGo4Slot* padslot)
02941 {
02942 if (padslot == 0)
02943 return 0;
02944 TGo4Slot* tgtslot = padslot->FindChild("::PadOptions");
02945 return (tgtslot == 0) ? 0 : (TGo4Picture*) tgtslot->GetAssignedObject();
02946 }
02947
02948 TH1* TGo4ViewPanel::GetPadHistogram(TPad *pad)
02949 {
02950 TGo4Slot* padslot = GetPadSlot(pad);
02951
02952 if ((pad == 0) || (padslot == 0))
02953 return 0;
02954
02955 TObject* obj = 0;
02956
02957 TGo4Slot* sislot = GetSuperimposeSlot(padslot);
02958 if (sislot != 0)
02959 obj = sislot->GetAssignedObject();
02960
02961 if (obj == 0)
02962 obj = GetPadMainObject(pad);
02963 if (obj == 0)
02964 return 0;
02965
02966 if (obj->InheritsFrom(TH1::Class()))
02967 return (TH1*) obj;
02968
02969 if (obj->InheritsFrom(TGraph::Class())) {
02970 TGraph* gr = dynamic_cast<TGraph*>(obj);
02971 if (gr != 0)
02972 return gr->GetHistogram();
02973 }
02974
02975 if (obj->InheritsFrom(THStack::Class())) {
02976 THStack* hs = dynamic_cast<THStack*>(obj);
02977 if (hs != 0)
02978 return hs->GetHistogram();
02979 }
02980
02981 if (obj->InheritsFrom(TMultiGraph::Class())) {
02982 TMultiGraph* mg = dynamic_cast<TMultiGraph*>(obj);
02983 if (mg) {
02984 if (mg->GetHistogram())
02985 return mg->GetHistogram();
02986
02987 TGraph* gr = 0;
02988 TIter iter(mg->GetListOfGraphs());
02989 while ((gr = (TGraph*) iter()) != 0)
02990 if (gr->GetHistogram())
02991 return gr->GetHistogram();
02992 }
02993 }
02994
02995 return 0;
02996 }
02997
02998 void TGo4ViewPanel::BlockPanelRedraw(bool on)
02999 {
03000 if (on)
03001 fiSkipRedrawCounter++;
03002 else
03003 fiSkipRedrawCounter--;
03004 }
03005
03006 bool TGo4ViewPanel::IsRedrawBlocked()
03007 {
03008 return fiSkipRedrawCounter > 0;
03009 }
03010
03011 void TGo4ViewPanel::UpdatePanelCaption()
03012 {
03013 TGo4Slot* slot = GetPadSlot(GetActivePad());
03014 if (slot == 0)
03015 return;
03016
03017 fSelectMenu->clear();
03018
03019 TGo4Slot* sislot = GetSuperimposeSlot(slot);
03020
03021 TObjArray objs, objslots;
03022 CollectMainDrawObjects(slot, &objs, &objslots, 0);
03023
03024 Int_t nselectitem = 0;
03025
03026 int selected = GetSelectedObjectIndex(slot);
03027
03028 if ((selected > objs.GetLast())
03029 || ((selected == TGo4Picture::PictureIndex) && (sislot == 0))) {
03030 SetSelectedObjectIndex(slot, 0);
03031 selected = 0;
03032 }
03033
03034 if (sislot != 0) {
03035 AddIdAction(fSelectMenu, fSelectMap, "Master object", MasterSelectId);
03036 fSelectMenu->addSeparator();
03037 nselectitem++;
03038 }
03039
03040 QString capt = GetPanelName();
03041
03042 QString fulllist = "";
03043 QString selslotname = "";
03044
03045 for (int n = 0; n <= objslots.GetLast(); n++) {
03046 TGo4Slot* subslot = (TGo4Slot*) objslots.At(n);
03047 AddIdAction(fSelectMenu, fSelectMap, objs.At(n)->GetName(),
03048 FirstSelectId + n);
03049 nselectitem++;
03050
03051 QString subslotname = subslot->GetName();
03052 if (n == selected) {
03053 subslotname = QString("[") + subslotname + QString("]");
03054 selslotname = subslotname;
03055 }
03056 if (n > 0) fulllist += ", ";
03057 fulllist += subslotname;
03058 }
03059
03060 if ((selected != TGo4Picture::PictureIndex) && (objslots.GetLast() > 0)
03061 && (selected < objslots.GetLast())) {
03062 fSelectMenu->addSeparator();
03063 AddIdAction(fSelectMenu, fSelectMap,
03064 QString("Show ") + selslotname + QString(" on top"),
03065 BringToFrontId);
03066 }
03067
03068 if ((selected == TGo4Picture::PictureIndex) && (fulllist.length() > 0))
03069 fulllist = QString("[") + fulllist + QString("]");
03070
03071 fSelectMenu->setEnabled(nselectitem > 0);
03072
03073 if (nselectitem > 0) {
03074 if (selected == TGo4Picture::PictureIndex)
03075 SetIdAction(fSelectMap, MasterSelectId, true, true);
03076 else
03077 SetIdAction(fSelectMap, FirstSelectId + selected, true, true);
03078 }
03079
03080 if (fulllist.length() > 0) {
03081 capt += ": ";
03082 capt += fulllist;
03083 }
03084
03085 if (capt.length() > 60) {
03086 capt.truncate(58);
03087 capt += "...";
03088 }
03089
03090 if (!fbFreezeTitle)
03091 setWindowTitle(capt);
03092 }
03093
03094 void TGo4ViewPanel::SetDrawKind(TGo4Slot* slot, int kind)
03095 {
03096 if (slot == 0)
03097 return;
03098 if (kind <= 0)
03099 slot->RemovePar("::DrawKind");
03100 else
03101 slot->SetIntPar("::DrawKind", kind);
03102 }
03103
03104 void TGo4ViewPanel::SetSpecialDrawOption(TGo4Slot* slot, const char* drawopt)
03105 {
03106 if (slot == 0)
03107 return;
03108 if (drawopt != 0)
03109 slot->SetPar("::DrawOpt", drawopt);
03110 else
03111 slot->RemovePar("::DrawOpt");
03112 }
03113
03114 int TGo4ViewPanel::GetDrawKind(TGo4Slot* slot)
03115 {
03116 if (slot == 0)
03117 return -1;
03118 Int_t kind;
03119 if (!slot->GetIntPar("::DrawKind", kind))
03120 return -1;
03121 return kind;
03122 }
03123
03124 const char* TGo4ViewPanel::GetSpecialDrawOption(TGo4Slot* slot)
03125 {
03126 return (slot == 0) ? 0 : slot->GetPar("::DrawOpt");
03127 }
03128
03129 void TGo4ViewPanel::SetSelectedObjectIndex(TGo4Slot* slot, int indx)
03130 {
03131 if (slot != 0)
03132 slot->SetIntPar("::SelectedObject", indx);
03133 }
03134
03135 int TGo4ViewPanel::GetSelectedObjectIndex(TGo4Slot* slot)
03136 {
03137 if (slot == 0)
03138 return 0;
03139 Int_t indx = 0;
03140 if (!slot->GetIntPar("::SelectedObject", indx))
03141 indx = 0;
03142 return indx;
03143 }
03144
03145 TObject* TGo4ViewPanel::GetSelectedObject(TPad * pad, const char** drawopt)
03146 {
03147 TGo4Slot* slot = GetPadSlot(pad);
03148 TGo4Picture* padopt = GetPadOptions(slot);
03149 if ((slot == 0) || (padopt == 0))
03150 return 0;
03151
03152 int indx = GetSelectedObjectIndex(slot);
03153
03154 TGo4Slot* sislot = GetSuperimposeSlot(slot);
03155 if ((sislot != 0) && (indx == TGo4Picture::PictureIndex)) {
03156 if (drawopt != 0)
03157 *drawopt = padopt->GetDrawOption(TGo4Picture::PictureIndex);
03158 return sislot->GetAssignedObject();
03159 }
03160
03161 TObjArray objs, objslots;
03162 CollectMainDrawObjects(slot, &objs, &objslots, 0);
03163
03164 if (objs.GetLast() < 0)
03165 return 0;
03166
03167 if ((indx > objs.GetLast()) || (indx < 0))
03168 indx = 0;
03169
03170 if (drawopt != 0) {
03171 const char* resopt = padopt->GetDrawOption(indx);
03172 if (resopt == 0)
03173 resopt = GetSpecialDrawOption((TGo4Slot*) objslots.At(indx));
03174
03175 *drawopt = resopt;
03176 }
03177
03178 return objs.At(indx);
03179 }
03180
03181 bool TGo4ViewPanel::ShiftSelectedObjectToEnd(TPad * pad)
03182 {
03183 TGo4Slot* slot = GetPadSlot(pad);
03184 TGo4Picture* padopt = GetPadOptions(slot);
03185 if ((slot == 0) || (padopt == 0))
03186 return false;
03187
03188 int indx = GetSelectedObjectIndex(slot);
03189
03190 TObjArray objs, objslots;
03191 CollectMainDrawObjects(slot, &objs, &objslots, 0);
03192
03193
03194 if ((objs.GetLast() <= 0) || (indx == objs.GetLast()))
03195 return false;
03196
03197 TGo4Slot* selslot = (TGo4Slot*) objslots.At(indx);
03198 TGo4Slot* lastslot = (TGo4Slot*) objslots.Last();
03199
03200 if (!slot->ShiftSlotAfter(selslot, lastslot))
03201 return false;
03202
03203 SetSelectedObjectIndex(slot, objs.GetLast());
03204
03205 return true;
03206 }
03207
03208 void TGo4ViewPanel::CheckObjectsAssigments(TPad * pad, TGo4Slot * padslot)
03209 {
03210 if ((pad == 0) || (padslot == 0)) return;
03211
03212 TObjArray objs, objslots;
03213 CollectMainDrawObjects(padslot, &objs, &objslots, 0);
03214
03215 int indx = GetSelectedObjectIndex(padslot);
03216 if (indx < 0) indx = 0;
03217
03218 TH1* selhisto = dynamic_cast<TH1*>((indx <= objs.GetLast()) ? objs.At(indx) : 0);
03219 if (selhisto == 0)
03220 selhisto = GetPadHistogram(pad);
03221
03222 for (int n = 0; n < padslot->NumChilds(); n++) {
03223 TGo4Slot* subslot = padslot->GetChild(n);
03224 Int_t kind = GetDrawKind(subslot);
03225 TObject* obj = subslot->GetAssignedObject();
03226 if (obj == 0) continue;
03227
03228 TGo4Marker* mark = 0;
03229 TGo4Condition* cond = 0;
03230
03231
03232 if ((kind >= kind_Specials) && (kind < kind_Other)) {
03233 if (obj->InheritsFrom(TGo4Condition::Class()))
03234 cond = (TGo4Condition*) obj;
03235 else if (obj->InheritsFrom(TGo4Marker::Class()))
03236 mark = (TGo4Marker*) obj;
03237 } else if (kind == kind_Condition)
03238 cond = dynamic_cast<TGo4Condition*>(obj);
03239
03240 TH1* oldhisto = 0;
03241
03242 if (cond != 0)
03243 oldhisto = cond->GetWorkHistogram();
03244 else if (mark != 0)
03245 oldhisto = mark->GetHistogram();
03246
03247 if (oldhisto != 0)
03248 if (objs.FindObject(oldhisto) == 0)
03249 oldhisto = 0;
03250
03251 if (oldhisto == 0)
03252 if (cond != 0)
03253 cond->SetWorkHistogram(selhisto);
03254 else if (mark != 0)
03255 mark->SetHistogram(selhisto);
03256 }
03257 }
03258
03259 void TGo4ViewPanel::SetFreezedTitle(const QString& title)
03260 {
03261 QString mycaption = GetPanelName();
03262 mycaption += ": ";
03263 mycaption += title;
03264 setWindowTitle(mycaption);
03265 fbFreezeTitle = true;
03266 fFreezedTitle = title;
03267 }
03268
03269 void TGo4ViewPanel::CheckForSpecialObjects(TPad *pad, TGo4Slot* padslot)
03270 {
03271 if ((pad == 0) || (padslot == 0))
03272 return;
03273
03274 TGo4Picture* pic = 0;
03275 TGo4Slot* picslot = 0;
03276 TCanvas* canv = 0;
03277 TGo4Slot* canvslot = 0;
03278
03279 int numcond = 0;
03280
03281 for (int n = 0; n < padslot->NumChilds(); n++) {
03282 TGo4Slot* subslot = padslot->GetChild(n);
03283 Int_t kind = GetDrawKind(subslot);
03284 if (kind == kind_Condition)
03285 numcond++;
03286
03287 TObject* obj = subslot->GetAssignedObject();
03288 if (obj == 0)
03289 continue;
03290
03291 if ((kind < 0) || (kind >= 100))
03292 continue;
03293
03294
03295 if (obj->InheritsFrom(TGo4Condition::Class())) {
03296 numcond++;
03297 TGo4Condition* cond = static_cast<TGo4Condition*>(obj);
03298 cond->SetLineColor(numcond + 1);
03299 cond->SetFillColor(numcond + 1);
03300 cond->SetFillStyle(3444);
03301 SetDrawKind(subslot, kind_Condition);
03302 continue;
03303 }
03304
03305 if (obj->InheritsFrom(TLatex::Class())) {
03306 SetDrawKind(subslot, kind_Latex);
03307 continue;
03308 }
03309
03310 if (pic == 0) {
03311 pic = dynamic_cast<TGo4Picture*>(obj);
03312 if (pic != 0)
03313 picslot = subslot;
03314 }
03315
03316 if (canv == 0) {
03317 canv = dynamic_cast<TCanvas*>(obj);
03318 if (canv != 0)
03319 canvslot = subslot;
03320 }
03321 }
03322
03323 if (pic != 0) {
03324
03325 ClearPadItems(padslot, picslot);
03326
03327
03328 ClearPad(pad, false, true);
03329
03330 ProcessPictureRedraw(GetLinkedName(picslot), pad, pic);
03331
03332 if (pad == GetCanvas())
03333 SetFreezedTitle(pic->GetTitle());
03334
03335
03336 delete picslot;
03337
03338
03339
03340 return;
03341 }
03342
03343 if (canv != 0) {
03344
03345 ClearPadItems(padslot, canvslot);
03346
03347
03348 ClearPad(pad, false, true);
03349
03350 TVirtualPad* padsav = gPad;
03351
03352 ProcessCanvasAdopt(pad, canv, GetLinkedName(canvslot));
03353
03354 if (padsav != 0)
03355 padsav->cd();
03356
03357 delete canvslot;
03358 }
03359 }
03360
03361 void TGo4ViewPanel::ProcessPictureRedraw(const char* picitemname, TPad* pad,
03362 TGo4Picture* pic)
03363 {
03364 if ((pad == 0) || (pic == 0))
03365 return;
03366
03367 if (pic->IsDivided()) {
03368 pad->Divide(pic->GetDivX(), pic->GetDivY());
03369
03370
03371 UpdatePadStatus(pad, false);
03372
03373 for (Int_t posy = 0; posy < pic->GetDivY(); posy++)
03374 for (Int_t posx = 0; posx < pic->GetDivX(); posx++) {
03375 TGo4Picture* sub = pic->FindPic(posy, posx);
03376 if (sub != 0)
03377 ProcessPictureRedraw(picitemname,
03378 (TPad*) pad->GetPad(posy * pic->GetDivX() + posx + 1),
03379 sub);
03380 }
03381
03382 return;
03383 }
03384
03385 TGo4Picture* padopt = GetPadOptions(pad);
03386 if (padopt == 0) {
03387 std::cerr << "!!!!!!!! Should not be" << std::endl;
03388 return;
03389 }
03390
03391 padopt->CopyOptionsFrom(pic);
03392
03393 padopt->GetDrawAttributes(pad, TGo4Picture::PictureIndex);
03394
03395 TGo4BrowserProxy* brcont = Browser();
03396
03397 Option_t* drawopt = pic->GetDrawOption(TGo4Picture::PictureIndex);
03398 if (drawopt != 0)
03399 pic->SetDrawOption(drawopt, TGo4Picture::PictureIndex);
03400
03401 Int_t ndraw = 0;
03402
03403 for (Int_t n = 0; n < pic->GetNumObjNames(); n++) {
03404 Option_t* drawopt = pic->GetDrawOption(n);
03405 if (drawopt != 0)
03406 pic->SetDrawOption(drawopt, n);
03407
03408 const char* objname = pic->GetObjName(n);
03409
03410 TString drawname;
03411
03412 if (brcont->DefineRelatedObject(picitemname, objname, drawname)) {
03413 TGo4Slot* slot = AddDrawObject(pad, kind_Link, drawname.Data(), 0,
03414 false, 0);
03415
03416 brcont->GetBrowserObject(drawname.Data(),
03417 go4sett->getFetchDataWhenDraw() ? 2 : 1);
03418 ndraw++;
03419
03420 if (pic->GetRebinX(n) > 1) {
03421 slot->SetIntPar("::DoRebinX", pic->GetRebinX(n));
03422 slot->SetIntPar("::HasRebinX", pic->GetRebinX(n));
03423 }
03424
03425 if (pic->GetRebinY(n) > 1) {
03426 slot->SetIntPar("::DoRebinY", pic->GetRebinY(n));
03427 slot->SetIntPar("::HasRebinY", pic->GetRebinY(n));
03428 }
03429 }
03430 }
03431
03432 if (ndraw > 1)
03433 padopt->SetSuperimpose(true);
03434
03435 TListIter iter(pic->GetSpecialObjects());
03436 TObject* obj = 0;
03437 while ((obj = iter()) != 0) {
03438 Option_t* drawopt = iter.GetOption();
03439 if (dynamic_cast<TArrow*>(obj) != 0)
03440 AddMarkerObj(pad, kind_Arrow, obj->Clone());
03441 else if (dynamic_cast<TLatex*>(obj) != 0)
03442 AddMarkerObj(pad, kind_Latex, obj->Clone());
03443 else if (dynamic_cast<TGo4Marker*>(obj) != 0)
03444 AddMarkerObj(pad, kind_Marker, obj->Clone());
03445 else if (dynamic_cast<TGo4WinCond*>(obj) != 0)
03446 AddMarkerObj(pad, kind_Window, obj->Clone());
03447 else if (dynamic_cast<TGo4PolyCond*>(obj) != 0)
03448 AddMarkerObj(pad, kind_Poly, obj->Clone());
03449 else if (dynamic_cast<TPaveLabel*>(obj) != 0)
03450 AddDrawObject(pad, kind_Specials, obj->GetName(), obj->Clone(), kTRUE,
03451 drawopt ? drawopt : "br");
03452 else
03453 AddDrawObject(pad, kind_Specials, obj->GetName(), obj->Clone(), kTRUE,
03454 drawopt);
03455 }
03456
03457 padopt->SetPadModified();
03458 }
03459
03460 void TGo4ViewPanel::ProcessCanvasAdopt(TPad* tgtpad, TPad* srcpad,
03461 const char* srcpaditemname)
03462 {
03463 if ((tgtpad == 0) || (srcpad == 0))
03464 return;
03465
03466
03467
03468 TGo4Slot* padslot = GetPadSlot(tgtpad);
03469
03470 TGo4Picture* padopt = GetPadOptions(tgtpad);
03471
03472 if ((padopt == 0) || (padslot == 0))
03473 return;
03474
03475 tgtpad->SetTickx(srcpad->GetTickx());
03476 tgtpad->SetTicky(srcpad->GetTicky());
03477 tgtpad->SetGridx(srcpad->GetGridx());
03478 tgtpad->SetGridy(srcpad->GetGridy());
03479 tgtpad->SetBorderSize(srcpad->GetBorderSize());
03480 tgtpad->SetBorderMode(srcpad->GetBorderMode());
03481 srcpad->TAttLine::Copy(*tgtpad);
03482 srcpad->TAttFill::Copy(*tgtpad);
03483 srcpad->TAttPad::Copy(*tgtpad);
03484
03485 tgtpad->SetPhi(srcpad->GetPhi());
03486 tgtpad->SetTheta(srcpad->GetTheta());
03487
03488 int nsubpads = 0, nmain = 0, mainkind = 0;
03489 TObjLink* link = srcpad->GetListOfPrimitives()->FirstLink();
03490 while (link != 0) {
03491 TObject* obj = link->GetObject();
03492 const char* drawopt = link->GetOption();
03493
03494 TH1* h1 = 0;
03495
03496 int kind = 0;
03497
03498 TPad* srcsubpad = dynamic_cast<TPad*>(obj);
03499
03500 TString itemname = TString::Format("%s/%s", srcpaditemname,
03501 obj->GetName());
03502
03503
03504
03505 if (srcsubpad != 0) {
03506 nsubpads++;
03507 QString subpadname = tgtpad->GetName();
03508 subpadname += "_";
03509 subpadname += QString::number(nsubpads);
03510
03511 Double_t xlow, ylow, xup, yup;
03512
03513 srcsubpad->GetPadPar(xlow, ylow, xup, yup);
03514
03515 tgtpad->cd();
03516 TPad* tgtsubpad = new TPad(subpadname.toLatin1().constData(),
03517 srcsubpad->GetName(), xlow, ylow, xup, yup);
03518 tgtsubpad->SetNumber(nsubpads);
03519 tgtsubpad->Draw();
03520
03521 TGo4Slot* subpadslot = AddNewSlot(tgtsubpad->GetName(), padslot);
03522 SetDrawKind(subpadslot, kind_PadSlot);
03523 SetSlotPad(subpadslot, tgtsubpad);
03524
03525 ProcessCanvasAdopt(tgtsubpad, srcsubpad, itemname.Data());
03526 } else if (dynamic_cast<TGo4Condition*>(obj) != 0) {
03527 TGo4Condition* cond = (TGo4Condition*) obj->Clone();
03528 cond->SetWorkHistogram(0);
03529 AddDrawObject(tgtpad, kind_Condition, cond->GetName(), cond, kTRUE, 0);
03530 } else if (dynamic_cast<TGo4Marker*>(obj) != 0) {
03531 TGo4Marker* mark = (TGo4Marker*) obj->Clone();
03532 mark->SetHistogram(0);
03533 AddDrawObject(tgtpad, kind_Marker, mark->GetName(), mark, kTRUE, 0);
03534 } else if (dynamic_cast<TLatex*>(obj) != 0) {
03535 AddDrawObject(tgtpad, kind_Latex, obj->GetName(), obj->Clone(), kTRUE,
03536 0);
03537 } else if (dynamic_cast<TPaveLabel*>(obj) != 0) {
03538 AddDrawObject(tgtpad, kind_Specials, obj->GetName(), obj->Clone(),
03539 kTRUE, drawopt ? drawopt : "br");
03540 } else if (dynamic_cast<TArrow*>(obj) != 0) {
03541 AddDrawObject(tgtpad, kind_Arrow, obj->GetName(), obj->Clone(), kTRUE,
03542 0);
03543 } else
03544
03545 if (dynamic_cast<TH1*>(obj) != 0) {
03546 kind = 1;
03547 h1 = (TH1*) obj;
03548 } else
03549
03550 if (dynamic_cast<TGraph*>(obj) != 0) {
03551 kind = 2;
03552 h1 = ((TGraph*) obj)->GetHistogram();
03553 } else
03554
03555 if (dynamic_cast<THStack*>(obj) != 0) {
03556 kind = 3;
03557 h1 = ((THStack*) obj)->GetHistogram();
03558 } else
03559
03560 if (dynamic_cast<TMultiGraph*>(obj) != 0) {
03561 kind = 4;
03562 h1 = ((TMultiGraph*) obj)->GetHistogram();
03563 } else {
03564
03565 }
03566
03567
03568
03569 if ((kind > 0) && ((mainkind == 0) || (kind == mainkind) && (kind < 3))) {
03570
03571
03572
03573
03574
03575 if (drawopt != 0)
03576 padopt->SetDrawOption(drawopt, nmain);
03577
03578 AddDrawObject(tgtpad, knd_Reference, obj->GetName(), obj, false, 0);
03579
03580 mainkind = kind;
03581
03582 if ((h1 != 0) && (nmain == 0)) {
03583 TakeFullRangeFromHisto(h1, padopt, nmain == 0);
03584 Int_t ndim = h1->GetDimension();
03585 TakeSelectedAxisRange(0, padopt, h1->GetXaxis());
03586 if (ndim > 1)
03587 TakeSelectedAxisRange(1, padopt, h1->GetYaxis());
03588 if (ndim > 2)
03589 TakeSelectedAxisRange(2, padopt, h1->GetZaxis());
03590 if (ndim < 3) {
03591 Double_t selmin = h1->GetMinimum();
03592 Double_t selmax = h1->GetMaximum();
03593
03594 if (selmin < selmax)
03595 padopt->SetRange(ndim, selmin, selmax);
03596
03597 padopt->SetAutoScale(
03598 !h1->TestBit(TH1::kIsZoomed) || (selmin >= selmax));
03599 }
03600 }
03601
03602 nmain++;
03603 }
03604
03605 link = link->Next();
03606 }
03607
03608 if (nmain > 1)
03609 padopt->SetSuperimpose(kTRUE);
03610
03611 if (nsubpads == 0)
03612 ScanDrawOptions(srcpad, padslot, padopt, false);
03613 }
03614
03615 void TGo4ViewPanel::RedrawPanel(TPad* pad, bool force)
03616 {
03617 if (IsRedrawBlocked()) return;
03618
03619 TGo4LockGuard lock(0, true);
03620
03621 BlockPanelRedraw(true);
03622
03623 bool isanychildmodified = false;
03624 bool ispadupdatecalled = false;
03625
03626 QTime starttm = QTime::currentTime();
03627 bool intime = true;
03628
03629
03630
03631
03632
03633
03634 do {
03635 TPad* selpad = TGo4MdiArea::Instance()->GetSelectedPad();
03636
03637 isanychildmodified = ProcessPadRedraw(pad, force);
03638
03639 TGo4MdiArea::Instance()->SetSelectedPad(selpad);
03640
03641
03642 if (isanychildmodified) {
03643 GetQCanvas()->Update();
03644 ispadupdatecalled = true;
03645 }
03646
03647 int delay = starttm.msecsTo(QTime::currentTime());
03648 intime = (delay >= 0) && (delay < 100);
03649
03650 } while (!force && isanychildmodified && intime);
03651
03652 if (GetActivePad() != 0)
03653 UpdatePanelCaption();
03654
03655 RefreshButtons();
03656
03657
03658 if (!ispadupdatecalled)
03659 GetQCanvas()->Update();
03660
03661 QCheckBox* box1 = findChild<QCheckBox*>("ApplyToAllCheck");
03662 if (box1 != 0)
03663 box1->setChecked(fbApplyToAllFlag);
03664
03665 BlockPanelRedraw(false);
03666
03667 if (!force && isanychildmodified)
03668 ShootRepaintTimer(pad);
03669 }
03670
03671 bool TGo4ViewPanel::ProcessPadRedraw(TPad* pad, bool force)
03672 {
03673 TGo4Slot* slot = GetPadSlot(pad);
03674 if (slot == 0) return false;
03675
03676 TGo4Picture* padopt = GetPadOptions(slot);
03677 if (padopt == 0) return false;
03678
03679 bool ischilds = false;
03680 bool ischildmodified = false;
03681
03682 CheckObjectsAssigments(pad, slot);
03683
03684 CheckForSpecialObjects(pad, slot);
03685
03686
03687 Int_t lastdrawnpad = 0;
03688 if (!force)
03689 if (!slot->GetIntPar("::LastDrawnPad", lastdrawnpad))
03690 lastdrawnpad = 0;
03691
03692 Int_t subpadindx = 0;
03693
03694
03695
03696
03697 for (int n = 0; n < slot->NumChilds(); n++) {
03698 subpadindx = (n + lastdrawnpad) % slot->NumChilds();
03699 TPad* subpad = GetSlotPad(slot->GetChild(subpadindx));
03700 if (subpad == 0) continue;
03701 ischilds = true;
03702 if (ProcessPadRedraw(subpad, force)) {
03703 ischildmodified = true;
03704 if (!force) break;
03705 }
03706 }
03707
03708 if (!force && ischildmodified)
03709 slot->SetIntPar("::LastDrawnPad", subpadindx);
03710 else
03711 slot->RemovePar("::LastDrawnPad");
03712
03713 if (!force && !padopt->IsPadModified())
03714 return ischildmodified;
03715
03716 bool updatecontent = padopt->IsContentModified();
03717
03718 padopt->SetPadModified(false);
03719 padopt->SetContentModified(false);
03720
03721
03722 if (ischilds) return ischildmodified;
03723
03724 pad->Clear();
03725
03726 pad->SetCrosshair(fbCanvasCrosshair);
03727 pad->SetLogx(padopt->GetLogScale(0));
03728 pad->SetLogy(padopt->GetLogScale(1));
03729 pad->SetLogz(padopt->GetLogScale(2));
03730
03731 TObjArray objs, objslots;
03732 CollectMainDrawObjects(slot, &objs, &objslots,
03733 padopt->IsSuperimpose() ? 1 : 2);
03734
03735 ScanObjectsDrawOptions(false, slot, &objs, &objslots);
03736
03737 TGo4Slot* sislot = GetSuperimposeSlot(slot);
03738 TGo4Slot* legslot = slot->FindChild("::Legend");
03739 TGo4Slot* asislot = slot->FindChild("::ASImage");
03740
03741
03742 if (objs.GetLast() < 0) {
03743 delete sislot;
03744 delete legslot;
03745 delete asislot;
03746
03747 RedrawSpecialObjects(pad, slot);
03748
03749 CallPanelFunc(panel_Updated, pad);
03750
03751
03752 return true;
03753 }
03754
03755 TH2* asihisto = 0;
03756
03757 TObject* drawobj = 0;
03758
03759
03760 Bool_t dosuperimpose = objs.GetLast() > 0;
03761
03762 const char* drawopt = padopt->GetDrawOption(0);
03763
03764 Bool_t doasiimage = (drawopt != 0) && !dosuperimpose &&
03765 objs.Last()->InheritsFrom(TH2::Class());
03766 if (doasiimage)
03767 doasiimage = TString(drawopt).Contains("asimage");
03768
03769 if (dosuperimpose) {
03770 if (sislot == 0)
03771 sislot = new TGo4Slot(slot, "::Superimpose", "place for superimpose object");
03772 if (padopt->IsLegendDraw()) {
03773 if (legslot == 0)
03774 legslot = new TGo4Slot(slot, "::Legend", "place for legends object");
03775 } else
03776 if (legslot != 0) {
03777 delete legslot;
03778 legslot = 0;
03779 }
03780
03781 drawobj = ProduceSuperimposeObject(slot, padopt, sislot, legslot, &objs,
03782 &objslots, padopt->IsTitleItem());
03783 if (drawobj == 0)
03784 dosuperimpose = kFALSE;
03785 }
03786
03787 if (!dosuperimpose) {
03788 if (sislot != 0) {
03789 delete sislot;
03790 sislot = 0;
03791 }
03792 if (legslot != 0) {
03793 delete legslot;
03794 legslot = 0;
03795 }
03796 drawobj = objs.Last();
03797 }
03798
03799 if (doasiimage) {
03800 asihisto = dynamic_cast<TH2*>(drawobj);
03801 if (asihisto == 0)
03802 doasiimage = false;
03803 else {
03804 if (asislot == 0)
03805 asislot = new TGo4Slot(slot, "::ASImage", "place for Go4 ASI image");
03806 TGo4ASImage* image =
03807 dynamic_cast<TGo4ASImage*>(asislot->GetAssignedObject());
03808 if(image==0) {
03809 image = new TGo4ASImage;
03810 asislot->SetProxy(new TGo4ObjectProxy(image, kTRUE));
03811 updatecontent = true;
03812 }
03813 if (updatecontent)
03814 image->SetHistogramContent(asihisto);
03815
03816 drawobj = image;
03817 }
03818 }
03819
03820 if (!doasiimage) {
03821 if (asislot != 0) {
03822 delete asislot;
03823 asislot = 0;
03824 }
03825 }
03826
03827 gPad = pad;
03828 if (drawobj != 0) {
03829
03830 bool first_draw = (slot->GetPar("::PadFirstDraw") == 0);
03831 if (first_draw) slot->SetPar("::PadFirstDraw", "true");
03832
03833 if (drawobj->InheritsFrom(TH1::Class())) {
03834 TH1* h1 = (TH1*) drawobj;
03835 h1->SetBit(kCanDelete, kFALSE);
03836 RedrawHistogram(pad, padopt, h1, updatecontent);
03837 } else if (drawobj->InheritsFrom(THStack::Class())) {
03838 THStack* hs = (THStack*) drawobj;
03839 RedrawStack(pad, padopt, hs, dosuperimpose, updatecontent);
03840 } else if (drawobj->InheritsFrom(TGraph::Class())) {
03841 TGraph* gr = (TGraph*) drawobj;
03842 RedrawGraph(pad, padopt, gr, updatecontent, first_draw);
03843 } else if (drawobj->InheritsFrom(TMultiGraph::Class())) {
03844 TMultiGraph* mg = (TMultiGraph*) drawobj;
03845 RedrawMultiGraph(pad, padopt, mg, dosuperimpose, updatecontent);
03846 } else if (dynamic_cast<TGo4ASImage*>(drawobj) != 0) {
03847 TGo4ASImage* ai = (TGo4ASImage*) drawobj;
03848 RedrawImage(pad, padopt, ai, asihisto, updatecontent);
03849 }
03850 }
03851
03852 if (legslot != 0)
03853 RedrawLegend(pad, padopt, legslot);
03854
03855 if (!doasiimage)
03856 RedrawSpecialObjects(pad, slot);
03857
03858 CallPanelFunc(panel_Updated, pad);
03859
03860 return true;
03861 }
03862
03863 void TGo4ViewPanel::RedrawHistogram(TPad *pad, TGo4Picture* padopt, TH1 *his,
03864 bool scancontent)
03865 {
03866 if ((pad == 0) || (padopt == 0) || (his == 0))
03867 return;
03868
03869 if (scancontent)
03870 TakeFullRangeFromHisto(his, padopt, true);
03871
03872 TString drawopt(padopt->GetDrawOption(0));
03873 if (drawopt.Length() == 0)
03874 if (his->GetDimension() == 1)
03875 drawopt = go4sett->getTH1DrawOpt().toLatin1().constData();
03876 else if (his->GetDimension() == 2)
03877 drawopt = go4sett->getTH2DrawOpt().toLatin1().constData();
03878 else if (his->GetDimension() == 3)
03879 drawopt = go4sett->getTH3DrawOpt().toLatin1().constData();
03880
03881 drawopt.ToUpper();
03882
03883 his->SetStats(padopt->IsHisStats());
03884 his->SetBit(TH1::kNoTitle, !padopt->IsHisTitle());
03885 his->Draw(drawopt.Data());
03886
03887 SetSelectedRangeToHisto(pad, his, 0, padopt, true);
03888 }
03889
03890 void TGo4ViewPanel::RedrawStack(TPad *pad, TGo4Picture* padopt, THStack * hs,
03891 bool dosuperimpose, bool scancontent)
03892 {
03893 if ((pad == 0) || (padopt == 0) || (hs == 0)) return;
03894
03895 if (scancontent) {
03896 TIter iter(hs->GetHists());
03897 TH1 *h1 = 0;
03898 bool first = true;
03899 while ((h1 = (TH1*) iter()) != 0) {
03900 TakeFullRangeFromHisto(h1, padopt, first);
03901 first = false;
03902 }
03903 }
03904
03905
03906
03907 Int_t drawoptindx = dosuperimpose ? TGo4Picture::PictureIndex : 0;
03908 TString drawopt(padopt->GetDrawOption(drawoptindx));
03909 if (drawopt.Length() == 0)
03910 drawopt = "hist";
03911 if (!drawopt.Contains(NoStackDrawOption, TString::kIgnoreCase))
03912 drawopt.Prepend(NoStackDrawOption);
03913
03914 hs->Draw(drawopt.Data());
03915 TH1* framehisto = hs->GetHistogram();
03916 if (framehisto == 0) return;
03917
03918
03919
03920 framehisto->SetStats(false);
03921 framehisto->SetBit(TH1::kNoTitle, !padopt->IsHisTitle());
03922 TH1* h1 = dynamic_cast<TH1*>(hs->GetHists() ? hs->GetHists()->First() : 0);
03923 if (h1!=0) {
03924 hs->SetTitle(h1->GetTitle());
03925 framehisto->SetTitle(h1->GetTitle());
03926 framehisto->GetXaxis()->SetTitle(h1->GetXaxis()->GetTitle());
03927 framehisto->GetYaxis()->SetTitle(h1->GetYaxis()->GetTitle());
03928 framehisto->GetZaxis()->SetTitle(h1->GetZaxis()->GetTitle());
03929 }
03930
03931 SetSelectedRangeToHisto(pad, framehisto, hs, padopt, false);
03932 }
03933
03934 void TGo4ViewPanel::RedrawGraph(TPad *pad, TGo4Picture* padopt, TGraph * gr, bool scancontent, bool first_draw)
03935 {
03936
03937
03938 if ((pad == 0) || (padopt == 0) || (gr == 0)) return;
03939
03940 if (scancontent) {
03941 TakeFullRangeFromGraph(gr, padopt, true);
03942 gr->SetEditable(kFALSE);
03943 }
03944
03945 TString drawopt = padopt->GetDrawOption(0);
03946
03947
03948 if (first_draw) {
03949 TAxis *ax = gr->GetXaxis();
03950 if ((ax!=0) && ax->GetTimeDisplay()) {
03951 padopt->SetHisStats(kFALSE);
03952 padopt->SetXAxisTimeDisplay(kTRUE);
03953 padopt->SetXAxisTimeFormat(ax->GetTimeFormat());
03954 if (drawopt.Length() == 0) {
03955 drawopt = go4sett->getTGraphDrawOpt().toLatin1().constData();
03956 padopt->SetDrawOption(drawopt);
03957 }
03958 }
03959 }
03960
03961 if (drawopt.Length() == 0)
03962 drawopt = go4sett->getTGraphDrawOpt().toLatin1().constData();
03963
03964 TH1* framehisto = gr->GetHistogram();
03965 if (framehisto == 0) {
03966 gr->Draw(drawopt.Data());
03967 framehisto = gr->GetHistogram();
03968 }
03969 if (framehisto != 0) {
03970 framehisto->SetStats(padopt->IsHisStats());
03971 framehisto->SetBit(TH1::kNoTitle, !padopt->IsHisTitle());
03972 }
03973 gr->Draw(drawopt.Data());
03974
03975 SetSelectedRangeToHisto(pad, framehisto, 0, padopt, false);
03976 }
03977
03978 void TGo4ViewPanel::RedrawMultiGraph(TPad *pad, TGo4Picture* padopt,
03979 TMultiGraph * mg, bool dosuperimpose, bool scancontent)
03980 {
03981 if ((pad == 0) || (padopt == 0) || (mg == 0)) return;
03982
03983 TIter iter(mg->GetListOfGraphs());
03984 TGraph *gr(0), *firstgr(0);
03985 bool first = true;
03986 while ((gr = (TGraph*) iter()) != 0) {
03987 if (scancontent) {
03988 gr->SetEditable(kFALSE);
03989 TakeFullRangeFromGraph(gr, padopt, first);
03990 }
03991 if (first)
03992 firstgr = gr;
03993 first = false;
03994 }
03995
03996 Int_t drawoptindx = dosuperimpose ? TGo4Picture::PictureIndex : 0;
03997 TString drawopt(padopt->GetDrawOption(drawoptindx));
03998 if (drawopt.Length() == 0)
03999 drawopt = go4sett->getTGraphDrawOpt().toLatin1().constData();
04000 if (dosuperimpose)
04001 drawopt = "";
04002
04003 TH1* framehisto =
04004 (dosuperimpose && (firstgr != 0)) ?
04005 firstgr->GetHistogram() : mg->GetHistogram();
04006
04007 if (framehisto == 0) {
04008
04009 mg->Draw(drawopt.Data());
04010 framehisto = (dosuperimpose && (firstgr != 0)) ?
04011 firstgr->GetHistogram() : mg->GetHistogram();
04012 }
04013
04014 if (framehisto != 0) {
04015 SetSelectedRangeToHisto(pad, framehisto, 0, padopt, false);
04016
04017 Double_t miny, maxy, selmin, selmax;
04018 if (padopt->GetFullRange(1, miny, maxy)
04019 && !padopt->GetRangeY(selmin, selmax)) {
04020 framehisto->SetMaximum(maxy);
04021 framehisto->SetMinimum(miny);
04022 }
04023
04024 framehisto->SetStats(kFALSE);
04025 framehisto->SetBit(TH1::kNoTitle, !padopt->IsHisTitle());
04026
04027
04028 if (firstgr != 0) {
04029 mg->SetTitle(firstgr->GetTitle());
04030 framehisto->SetTitle(firstgr->GetTitle());
04031 framehisto->GetXaxis()->SetTitle(firstgr->GetXaxis()->GetTitle());
04032 framehisto->GetYaxis()->SetTitle(firstgr->GetYaxis()->GetTitle());
04033 }
04034 mg->Draw(drawopt.Data());
04035
04036 }
04037
04038 SetSelectedRangeToHisto(pad, framehisto, 0, padopt, false);
04039 }
04040
04041 void TGo4ViewPanel::RedrawImage(TPad *pad, TGo4Picture* padopt, TGo4ASImage* im,
04042 TH2* asihisto, bool scancontent)
04043 {
04044 if ((pad == 0) || (padopt == 0) || (im == 0))
04045 return;
04046
04047 im->SetDrawData(asihisto, this, pad);
04048
04049 if (scancontent)
04050 TakeFullRangeFromHisto(asihisto, padopt, true);
04051
04052 TString drawopt(padopt->GetDrawOption(0));
04053
04054 double uminx, umaxx, uminy, umaxy;
04055 padopt->GetRange(0, uminx, umaxx);
04056 padopt->GetRange(1, uminy, umaxy);
04057 im->SetSelectedRange(uminx, umaxx, uminy, umaxy);
04058
04059 im->SetPaletteEnabled(drawopt.Contains("Z"));
04060
04061 im->Draw();
04062 }
04063
04064 void TGo4ViewPanel::RedrawLegend(TPad *pad, TGo4Picture* padopt,
04065 TGo4Slot* legslot)
04066 {
04067 if (legslot == 0) return;
04068 TLegend* legend = dynamic_cast<TLegend*>(legslot->GetAssignedObject());
04069 if(legend!=0) legend->Draw();
04070 }
04071
04072 void TGo4ViewPanel::RedrawSpecialObjects(TPad *pad, TGo4Slot* padslot)
04073 {
04074 if ((pad == 0) || (padslot == 0))
04075 return;
04076
04077 CheckObjectsAssigments(pad, padslot);
04078
04079 QString selname = GetSelectedMarkerName(pad);
04080 TObject* selectedobj = 0;
04081 const char* selectdrawopt = 0;
04082
04083 for (int n = 0; n < padslot->NumChilds(); n++) {
04084 TGo4Slot* subslot = padslot->GetChild(n);
04085
04086 Int_t kind = GetDrawKind(subslot);
04087
04088 if ((kind < kind_Specials) || (kind >= kind_Other))
04089 continue;
04090
04091 const char* drawopt = GetSpecialDrawOption(subslot);
04092
04093 TObject* obj = subslot->GetAssignedObject();
04094
04095 if (obj == 0)
04096 continue;
04097
04098 if ((selname == obj->GetName()) && (selectedobj == 0)) {
04099 selectedobj = obj;
04100 selectdrawopt = drawopt;
04101 } else
04102 obj->Draw(drawopt ? drawopt : "");
04103 }
04104
04105
04106
04107 if (selectedobj != 0)
04108 selectedobj->Draw(selectdrawopt ? selectdrawopt : "");
04109 }
04110
04111 bool TGo4ViewPanel::IsApplyToAllFlag()
04112 {
04113 return fbApplyToAllFlag;
04114 }
04115
04116 bool TGo4ViewPanel::IsFreezeTitle()
04117 {
04118 return fbFreezeTitle;
04119 }
04120
04121 void TGo4ViewPanel::ChangeDrawOptionForPad(TGo4Slot* padslot, int kind,
04122 int value, const char* drawopt)
04123 {
04124 TGo4LockGuard lock(0, true);
04125
04126 TGo4Picture* subopt = GetPadOptions(padslot);
04127 if (subopt == 0)
04128 return;
04129 switch (kind) {
04130 case 0:
04131 case 1:
04132 case 2: {
04133 int selindx = GetSelectedObjectIndex(padslot);
04134 subopt->SetDrawOption(drawopt, selindx);
04135 subopt->SetPadModified();
04136 break;
04137 }
04138 case 100: {
04139 subopt->SetPadModified();
04140 break;
04141 }
04142 case 101: {
04143 TPad* subpad = GetSlotPad(padslot);
04144 if (subpad != 0) {
04145 subpad->SetFillColor(value);
04146 if (subpad->GetFrame())
04147 subpad->GetFrame()->SetFillColor(value);
04148 }
04149 subopt->SetPadModified();
04150 break;
04151 }
04152 case 16: {
04153
04154 subopt->SetXAxisTimeFormat(drawopt);
04155 subopt->SetPadModified();
04156 break;
04157 }
04158 default:
04159 subopt->ChangeDrawOption(kind, value);
04160 }
04161 }
04162
04163 void TGo4ViewPanel::ChangeDrawOption(int kind, int value, const char* drawopt)
04164 {
04165 TGo4LockGuard lock(0, true);
04166
04167 bool scanall = IsApplyToAllFlag();
04168
04169 if (kind == 100) {
04170 gStyle->SetPalette(value);
04171 scanall = true;
04172 }
04173
04174 TPad* pad = scanall ? GetCanvas() : GetActivePad();
04175
04176 if (pad == 0)
04177 pad = GetCanvas();
04178
04179 TGo4Slot* slot = GetPadSlot(pad);
04180 if (slot == 0)
04181 return;
04182
04183 ChangeDrawOptionForPad(slot, kind, value, drawopt);
04184
04185 TGo4Iter iter(slot, true);
04186 while (iter.next())
04187 ChangeDrawOptionForPad(iter.getslot(), kind, value, drawopt);
04188
04189 RedrawPanel(pad, false);
04190 }
04191
04192 void TGo4ViewPanel::ResetPadFillColors(TPad* pad, int col)
04193 {
04194 TGo4LockGuard lock(0, true);
04195
04196 if (pad == 0)
04197 return;
04198 pad->SetFillColor((Color_t) col);
04199 TIter iter(pad->GetListOfPrimitives());
04200 TObject* obj = 0;
04201 while ((obj = iter()) != 0) {
04202 TPad* subpad = dynamic_cast<TPad*>(obj);
04203 TFrame* fram = dynamic_cast<TFrame*>(obj);
04204 if (subpad != 0)
04205 ResetPadFillColors(subpad, col);
04206 else if (fram != 0)
04207 fram->SetFillColor((Color_t) col);
04208 }
04209 }
04210
04211 void TGo4ViewPanel::ClearPad(TPad* pad, bool removeitems, bool removesubpads)
04212 {
04213 TGo4LockGuard lock(0, true);
04214
04215 BlockPanelRedraw(true);
04216 CleanupGedEditor();
04217 ProcessPadClear(pad, removeitems, removesubpads);
04218 if (GetActivePad() == 0)
04219 SetActivePad(GetCanvas());
04220 GetCanvas()->SetSelected(0);
04221 BlockPanelRedraw(false);
04222 }
04223
04224 void TGo4ViewPanel::ClearPadItems(TGo4Slot* padslot, TGo4Slot* remain)
04225 {
04226 if (padslot == 0) return;
04227
04228 for (int n = padslot->NumChilds() - 1; n >= 0; n--) {
04229 TGo4Slot* subslot = padslot->GetChild(n);
04230 int kind = GetDrawKind(subslot);
04231 if ((kind < kind_Permanet) && (subslot != remain)) {
04232 delete subslot;
04233 }
04234 }
04235 }
04236
04237 void TGo4ViewPanel::ProcessPadClear(TPad * pad, bool removeitems, bool removesubpads)
04238 {
04239 TGo4Slot* slot = GetPadSlot(pad);
04240 TGo4Picture* padopt = GetPadOptions(slot);
04241 if ((slot == 0) || (padopt == 0))
04242 return;
04243
04244
04245 padopt->SetPadModified();
04246
04247 if (removeitems)
04248 ClearPadItems(slot, 0);
04249
04250 CheckObjectsAssigments(pad, slot);
04251
04252 for (int n = slot->NumChilds() - 1; n >= 0; n--) {
04253 TGo4Slot* subslot = slot->GetChild(n);
04254
04255 TPad* subpad = GetSlotPad(subslot);
04256 if (subpad == 0)
04257 continue;
04258 ProcessPadClear(subpad, removeitems || removesubpads, removesubpads);
04259 if (!removesubpads)
04260 continue;
04261 if (fxActivePad == subpad)
04262 fxActivePad = 0;
04263
04264 delete subslot;
04265
04266 pad->GetListOfPrimitives()->Remove(subpad);
04267
04268 CallPanelFunc(panel_PadDeleted, subpad);
04269
04270 if (GetCanvas()->GetSelectedPad() == subpad)
04271 GetCanvas()->SetSelectedPad(0);
04272
04273 delete subpad;
04274 }
04275
04276 CallPanelFunc(panel_Modified, pad);
04277 }
04278
04279 void TGo4ViewPanel::SetPadDefaults(TPad* pad)
04280 {
04281 TGo4LockGuard lock(0, true);
04282
04283 if (pad == 0) return;
04284 gStyle->SetOptStat(go4sett->getOptStat());
04285 if (go4sett->getOptStatW()>0) gStyle->SetStatW(go4sett->getOptStatW()*0.01);
04286 if (go4sett->getOptStatH()>0) gStyle->SetStatH(go4sett->getOptStatH()*0.01);
04287
04288 fbCanvasCrosshair = go4sett->getPadCrosshair();
04289 fbCanvasEventstatus = go4sett->getPadEventStatus();
04290
04291 int fiPadcolorR, fiPadcolorG, fiPadcolorB;
04292 go4sett->getCanvasColor(fiPadcolorR, fiPadcolorG, fiPadcolorB);
04293 int padfillcolor = TColor::GetColor(fiPadcolorR, fiPadcolorG, fiPadcolorB);
04294
04295 if (padfillcolor != 0) {
04296
04297
04298
04299
04300 Int_t nplanes = 16;
04301 if (gVirtualX)
04302 gVirtualX->GetPlanes(nplanes);
04303 if (nplanes == 0)
04304 nplanes = 16;
04305 TColor *normal = gROOT->GetColor(padfillcolor);
04306 if (normal != 0) {
04307 Float_t h, l, s;
04308 normal->GetHLS(h, l, s);
04309 const char* cname = normal->GetName();
04310
04311 Float_t dr, dg, db, lr, lg, lb;
04312 TColor *dark = gROOT->GetColor(100 + padfillcolor);
04313 if (dark == 0) {
04314 new TColor(100 + padfillcolor, -1, -1, -1,
04315 Form("%s%s", cname, "_dark"));
04316 dark = gROOT->GetColor(100 + padfillcolor);
04317 }
04318 TColor *light = gROOT->GetColor(150 + padfillcolor);
04319 if (light == 0) {
04320 new TColor(150 + padfillcolor, -1, -1, -1,
04321 Form("%s%s", cname, "_bright"));
04322 light = gROOT->GetColor(150 + padfillcolor);
04323 }
04324
04325
04326 TColor::HLStoRGB(h, 0.7 * l, s, dr, dg, db);
04327 if (dark != 0) {
04328 if (nplanes > 8)
04329 dark->SetRGB(dr, dg, db);
04330 else
04331 dark->SetRGB(0.3, 0.3, 0.3);
04332 }
04333
04334
04335 TColor::HLStoRGB(h, 1.2 * l, s, lr, lg, lb);
04336 if (light != 0) {
04337 if (nplanes > 8)
04338 light->SetRGB(lr, lg, lb);
04339 else
04340 light->SetRGB(0.8, 0.8, 0.8);
04341 }
04342 } else {
04343 std::cerr
04344 << "TGo4ViewPanel:: Could not assign root shadow colors for number "
04345 << padfillcolor << std::endl;
04346 std::cerr << "Never come here!!!" << std::endl;
04347 }
04348 }
04349
04350 pad->SetCrosshair(fbCanvasCrosshair);
04351 pad->SetFillColor(padfillcolor);
04352
04353 fbCanvasEventstatus = !fbCanvasEventstatus;
04354 ShowEventStatus();
04355
04356 TGo4Picture* padopt = GetPadOptions(pad);
04357 if (padopt != 0) {
04358 padopt->SetDrawOption(0, TGo4Picture::PictureIndex);
04359 padopt->SetDrawOption(0, 0);
04360 padopt->SetTitleTime(go4sett->getDrawTimeFlag());
04361 padopt->SetTitleDate(go4sett->getDrawDateFlag());
04362 padopt->SetTitleItem(go4sett->getDrawItemFlag());
04363 padopt->SetHisStats(go4sett->getStatBoxVisible());
04364 }
04365 }
04366
04367 void TGo4ViewPanel::DisplayPadStatus(TPad * pad)
04368 {
04369 if (pad == 0)
04370 return;
04371 QString output = pad->GetName();
04372 output.append(": ");
04373 TGo4Picture* padopt = GetPadOptions(pad);
04374 if (padopt != 0)
04375 if (padopt->IsSuperimpose())
04376 output.append(" SuperImpose:");
04377
04378 if (IsApplyToAllFlag())
04379 output.append(" All Pads:");
04380 output.append(" Ready");
04381 if (CanvasStatus != 0)
04382 CanvasStatus->showMessage(output);
04383 }
04384
04385 void TGo4ViewPanel::MoveScale(int expandfactor, int xaction, int yaction, int zaction)
04386 {
04387 TPad* selpad = IsApplyToAllFlag() ? GetCanvas() : GetActivePad();
04388 if (selpad == 0)
04389 return;
04390
04391
04392
04393 TGo4Picture* padopt = GetPadOptions(selpad);
04394 if (padopt != 0) {
04395
04396
04397 TObject* padhist = GetPadMainObject(selpad);
04398
04399 MoveSingleScale(expandfactor, xaction, 0, padopt, padhist);
04400 MoveSingleScale(expandfactor, yaction, 1, padopt, padhist);
04401 MoveSingleScale(expandfactor, zaction, 2, padopt, padhist);
04402 if ((xaction == 0) && (yaction == 0) && (zaction == 0)) {
04403 padopt->ClearRange();
04404 padopt->SetAutoScale(true);
04405 }
04406 padopt->SetPadModified();
04407 }
04408
04409 if (IsApplyToAllFlag()) {
04410 TGo4Iter iter(GetPadSlot(selpad), kTRUE);
04411 while (iter.next()) {
04412 TPad* subpad = GetSlotPad(iter.getslot());
04413 padopt = GetPadOptions(subpad);
04414 if (padopt == 0) continue;
04415
04416 TObject* padhist = GetPadMainObject(subpad);
04417
04418 MoveSingleScale(expandfactor, xaction, 0, padopt, padhist);
04419 MoveSingleScale(expandfactor, yaction, 1, padopt, padhist);
04420 MoveSingleScale(expandfactor, zaction, 2, padopt, padhist);
04421 if ((xaction == 0) && (yaction == 0) && (zaction == 0)) {
04422 padopt->ClearRange();
04423 padopt->SetAutoScale(true);
04424 }
04425 padopt->SetPadModified();
04426 }
04427 }
04428
04429 RedrawPanel(selpad, false);
04430 }
04431
04432 void TGo4ViewPanel::MoveSingleScale(int expandfactor, int action, int naxis,
04433 TGo4Picture* padopt, TObject* padobj)
04434 {
04435 if (action <= 0) return;
04436
04437 double new_umin, new_umax, fmin, fmax, tmin, tmax;
04438 double fact = expandfactor / 100.;
04439
04440 bool sel = padopt->GetRange(naxis, new_umin, new_umax);
04441
04442 padopt->GetFullRange(naxis, fmin, fmax);
04443
04444
04445 int ndim = padopt->GetFullRangeDim();
04446
04447 if (!sel || (new_umin >= new_umax))
04448 padopt->GetFullRange(naxis, new_umin, new_umax);
04449
04450 double shift = (new_umax - new_umin) * fact;
04451
04452 if (shift <= 0) return;
04453
04454 switch (action) {
04455 case 1:
04456 if ((new_umax + shift) > fmax)
04457 shift = fmax - new_umax;
04458 new_umin += shift;
04459 new_umax += shift;
04460 break;
04461 case 2:
04462 if (new_umin - shift < fmin)
04463 shift = new_umin - fmin;
04464 new_umin -= shift;
04465 new_umax -= shift;
04466 break;
04467 case 3:
04468 if (ndim == 1) {
04469 new_umax -= shift;
04470 if (naxis < 1)
04471 new_umin += shift;
04472 }
04473 if (ndim == 2) {
04474 new_umax -= shift;
04475 if (naxis < 2)
04476 new_umin += shift;
04477 }
04478 break;
04479 case 4:
04480 if (ndim == 1) {
04481 if (naxis < 1) {
04482 tmax = (-fact * new_umin + (1. - fact) * new_umax)
04483 / (1. - 2. * fact);
04484 tmin = (-fact * new_umax + (1. - fact) * new_umin)
04485 / (1. - 2. * fact);
04486 } else {
04487 tmax = (-fact * new_umin + new_umax) / (1. - fact);
04488 tmin = (-fact * new_umax + (1. - fact) * new_umin)
04489 / (1. - 2. * fact);
04490 }
04491 }
04492 if (ndim == 2) {
04493 if (naxis < 2) {
04494 tmax = (-fact * new_umin + (1. - fact) * new_umax)
04495 / (1. - 2. * fact);
04496 tmin = (-fact * new_umax + (1. - fact) * new_umin)
04497 / (1. - 2. * fact);
04498 } else {
04499 tmax = (-fact * new_umin + new_umax) / (1. - fact);
04500 tmin = (-fact * new_umax + (1. - fact) * new_umin)
04501 / (1. - 2. * fact);
04502 }
04503 }
04504 new_umin = tmin;
04505 new_umax = tmax;
04506 if (new_umin < fmin)
04507 new_umin = fmin;
04508 if (new_umax > fmax)
04509 new_umax = fmax;
04510 break;
04511
04512 case 5: {
04513 TH1* padhist = dynamic_cast<TH1*>(padobj);
04514
04515 if (padhist==0) break;
04516
04517 if (naxis >= ndim) break;
04518
04519 TAxis* axis = padhist->GetXaxis();
04520 if (naxis==1) axis = padhist->GetYaxis();
04521 if (naxis==2) axis = padhist->GetZaxis();
04522
04523
04524 Int_t sel_l = sel ? axis->GetFirst() : 0;
04525 Int_t sel_r = sel ? axis->GetLast() : axis->GetNbins();
04526
04527 Int_t firstbin(0), lastbin(0);
04528
04529
04530 if ((ndim==1) && (naxis==0)) {
04531 for (Int_t n1 = 1; n1<=padhist->GetNbinsX(); n1++) {
04532 Double_t v = padhist->GetBinContent(n1);
04533 if (TMath::Abs(v)<1e-10) continue;
04534 if ((n1<sel_l) || (n1>sel_r)) continue;
04535 lastbin = n1;
04536 if (firstbin==0) firstbin = n1;
04537 }
04538 }
04539
04540
04541 if ((ndim==2) && (naxis<2))
04542 for (Int_t n1 = 1; n1<=padhist->GetNbinsX(); n1++)
04543 for (Int_t n2 = 1; n2<=padhist->GetNbinsY(); n2++) {
04544 Double_t v = padhist->GetBinContent(n1,n2);
04545 if (TMath::Abs(v)<1e-10) continue;
04546 Int_t bin = naxis==0 ? n1 : n2;
04547 if ((bin<sel_l) || (bin>sel_r)) continue;
04548 if ((lastbin==0) || (bin>lastbin)) lastbin = bin;
04549 if ((firstbin==0) || (bin<firstbin)) firstbin = bin;
04550 }
04551
04552
04553 if ((ndim==3) && (naxis<3))
04554 for (Int_t n1 = 1; n1<=padhist->GetNbinsX(); n1++)
04555 for (Int_t n2 = 1; n2<=padhist->GetNbinsY(); n2++)
04556 for (Int_t n3 = 1; n3<=padhist->GetNbinsZ(); n3++) {
04557 Double_t v = padhist->GetBinContent(n1,n2,n3);
04558 if (TMath::Abs(v)<1e-10) continue;
04559 Int_t bin = naxis==0 ? n1 : ((naxis==1) ? n2 : n3);
04560 if ((bin<sel_l) || (bin>sel_r)) continue;
04561 if ((lastbin==0) || (bin>lastbin)) lastbin = bin;
04562 if ((firstbin==0) || (bin<firstbin)) firstbin = bin;
04563 }
04564
04565
04566 if (firstbin>0) {
04567
04568 if (firstbin >= lastbin) { firstbin--; lastbin++; }
04569
04570 if (firstbin<=3) firstbin = 1;
04571 if (lastbin >=axis->GetNbins()-3) lastbin = axis->GetNbins();
04572
04573 Double_t left = axis->GetBinLowEdge(firstbin);
04574 Double_t right = axis->GetBinUpEdge(lastbin);
04575 Double_t margin = (right - left) * fact;
04576 left -= margin; right += margin;
04577
04578 if ((left <= new_umin) && (right >= new_umax)) return;
04579
04580 if (left > new_umin) new_umin = left;
04581 if (right < new_umax) new_umax = right;
04582 }
04583
04584 break;
04585 }
04586
04587 default:
04588 return;
04589 }
04590
04591 TakeSelectedAxisRange(naxis, padopt, new_umin, new_umax, false);
04592
04593 if (naxis == ndim)
04594 if (padopt->GetRange(naxis, new_umin, new_umax))
04595 padopt->SetAutoScale(kFALSE);
04596 }
04597
04598 void TGo4ViewPanel::TakeFullRangeFromHisto(TH1* h1, TGo4Picture* padopt, bool isfirsthisto)
04599 {
04600 if ((h1 == 0) || (padopt == 0)) return;
04601
04602 TAxis* xax = h1->GetXaxis();
04603 TAxis* yax = h1->GetYaxis();
04604 TAxis* zax = h1->GetZaxis();
04605 int ndim = h1->GetDimension();
04606
04607 if (isfirsthisto) {
04608 padopt->SetFullRangeDim(ndim);
04609 padopt->SetFullRange(0, xax->GetBinLowEdge(1),
04610 xax->GetBinUpEdge(xax->GetNbins()));
04611 if (ndim > 1)
04612 padopt->SetFullRange(1, yax->GetBinLowEdge(1),
04613 yax->GetBinUpEdge(yax->GetNbins()));
04614 else
04615 padopt->ClearFullRange(2);
04616
04617 if (ndim > 2)
04618 padopt->SetFullRange(2, zax->GetBinLowEdge(1),
04619 zax->GetBinUpEdge(zax->GetNbins()));
04620 } else
04621 ndim = padopt->GetFullRangeDim();
04622
04623 if (ndim >= 3)
04624 return;
04625
04626 Int_t dimindx = (ndim == 1) ? 1 : 2;
04627
04628 Double_t minimum = 0, maximum = 0;
04629 Bool_t first = kTRUE;
04630 if (!isfirsthisto) {
04631 padopt->GetFullRange(dimindx, minimum, maximum);
04632 first = kFALSE;
04633 }
04634
04635 for (Int_t biny = 1; biny <= yax->GetNbins(); biny++)
04636 for (Int_t binx = 1; binx <= xax->GetNbins(); binx++) {
04637 Int_t bin = h1->GetBin(binx, biny);
04638 Double_t value = h1->GetBinContent(bin);
04639 if (first) {
04640 minimum = value;
04641 maximum = value;
04642 first = kFALSE;
04643 }
04644 if (value < minimum)
04645 minimum = value;
04646 else if (value > maximum)
04647 maximum = value;
04648 }
04649
04650 padopt->SetFullRange(dimindx, minimum, maximum);
04651 }
04652
04653 void TGo4ViewPanel::TakeFullRangeFromGraph(TGraph * gr, TGo4Picture * padopt, bool isfirst)
04654 {
04655 if ((gr == 0) || (padopt == 0)) return;
04656
04657 Double_t minx(0), maxx(0), miny(0), maxy(0), xx, yy;
04658 if (isfirst) {
04659 if (gr->GetN() > 0) {
04660 gr->GetPoint(0, minx, miny);
04661 maxx = minx;
04662 maxy = miny;
04663 }
04664 } else {
04665 padopt->GetFullRange(0, minx, maxx);
04666 padopt->GetFullRange(1, miny, maxy);
04667 }
04668
04669 for (Int_t n = 0; n < gr->GetN(); n++) {
04670 gr->GetPoint(n, xx, yy);
04671 if (xx < minx)
04672 minx = xx;
04673 else if (xx > maxx)
04674 maxx = xx;
04675 if (yy < miny)
04676 miny = yy;
04677 else if (yy > maxy)
04678 maxy = yy;
04679 }
04680
04681 padopt->SetFullRangeDim(1);
04682 padopt->SetFullRange(0, minx, maxx);
04683 padopt->SetFullRange(1, miny, maxy);
04684 padopt->ClearFullRange(2);
04685 }
04686
04687 void TGo4ViewPanel::SetSelectedRangeToHisto(TPad* pad, TH1* h1, THStack* hs,
04688 TGo4Picture* padopt, bool isthishisto)
04689 {
04690
04691
04692 if ((h1 == 0) || (padopt == 0) || (pad == 0)) return;
04693
04694 int ndim = padopt->GetFullRangeDim();
04695
04696 bool autoscale = padopt->IsAutoScale();
04697
04698 double hmin(0.), hmax(0.), umin, umax;
04699
04700 TAxis* ax = h1->GetXaxis();
04701
04702 if (padopt->GetRange(0, umin, umax)) {
04703
04704
04705
04706
04707 Int_t i1 = ax->FindFixBin(umin);
04708 Int_t i2 = ax->FindFixBin(umax);
04709 if (i1<i2) ax->SetRange(i1,i2);
04710 else { ax->UnZoom(); padopt->ClearRange(0); }
04711 } else {
04712 ax->UnZoom();
04713 }
04714
04715 TAxis* ay = h1->GetYaxis();
04716
04717 if (padopt->GetRange(1, umin, umax)) {
04718 if (!autoscale && (ndim == 1)) {
04719 hmin = umin;
04720 hmax = umax;
04721 ay = 0;
04722 }
04723
04724
04725
04726
04727
04728 if (ndim>1) {
04729 Int_t i1 = ay->FindFixBin(umin);
04730 Int_t i2 = ay->FindFixBin(umax);
04731 if (i1<i2) { ay->SetRange(i1,i2); ay = 0; }
04732 }
04733 }
04734
04735 if (ay!=0) {
04736 ay->UnZoom();
04737 padopt->ClearRange(1);
04738
04739 if ((ndim==1) && (h1->GetMinimum()==0) && (h1->GetMaximum()==1)) {
04740 h1->SetMinimum();
04741 h1->SetMaximum();
04742 }
04743 }
04744
04745 TAxis* az = h1->GetZaxis();
04746 if (padopt->GetRange(2, umin, umax) && (ndim > 1)) {
04747 if (!autoscale && (ndim == 2)) {
04748 hmin = umin;
04749 hmax = umax;
04750 }
04751
04752
04753
04754
04755 Int_t i1 = az->FindFixBin(umin);
04756 Int_t i2 = az->FindFixBin(umax);
04757 if (i1<i2) { az->SetRange(i1,i2); az = 0; }
04758 }
04759
04760 if (az!=0) {
04761 az->UnZoom();
04762 padopt->ClearRange(2);
04763 }
04764
04765 if (hmin != hmax) {
04766
04767
04768 if (padopt->GetLogScale(ndim)) {
04769 if (hmax <= 0)
04770 hmax = 1.;
04771 if ((hmin <= 0) || (hmin >= hmax)) {
04772 hmin = hmax * 1e-4;
04773 if (hmin > 1.)
04774 hmin = 1;
04775 }
04776 }
04777
04778 h1->SetMinimum(hmin);
04779 h1->SetMaximum(hmax);
04780 h1->SetBit(TH1::kIsZoomed);
04781 if (hs != 0) {
04782 hs->SetMinimum(hmin);
04783 hs->SetMaximum(hmax);
04784 }
04785 } else {
04786
04787
04788 if (hs != 0) {
04789
04790 if (ndim == 1) {
04791 TIter next(hs->GetHists());
04792 TH1* hs_h1 = 0;
04793 while ((hs_h1 = (TH1*) next()) != 0) {
04794 if (padopt->GetRange(0, umin, umax)) {
04795
04796
04797
04798 TAxis* ax = hs_h1->GetXaxis();
04799 Int_t i1 = ax->FindFixBin(umin);
04800 Int_t i2 = ax->FindFixBin(umax);
04801 if (i1<i2) { ax->SetRange(i1,i2); }
04802 else { ax->UnZoom(); padopt->ClearRange(0); }
04803 } else {
04804 hs_h1->GetXaxis()->UnZoom();
04805 }
04806
04807 hs_h1->GetYaxis()->UnZoom();
04808 hs_h1->SetMinimum();
04809 hs_h1->SetMaximum();
04810 }
04811 }
04812
04813 hs->SetMinimum();
04814 hs->SetMaximum();
04815 }
04816
04817 h1->SetMinimum();
04818 h1->SetMaximum();
04819 h1->ResetBit(TH1::kIsZoomed);
04820
04821
04822
04823 if (ndim < 3) {
04824
04825 Double_t selmin = h1->GetMinimum();
04826 Double_t selmax = h1->GetMaximum();
04827
04828 if (selmin >= selmax) {
04829 padopt->ClearRange(ndim);
04830 } else {
04831 bool islogscale = (ndim == 1) && (padopt->GetLogScale(1) > 0);
04832
04833 if (islogscale) {
04834 if ((selmin > 0) && (selmax > 0)) {
04835 selmin = TMath::Log10(selmin) + TMath::Log10(0.5);
04836 selmin = TMath::Power(10, selmin);
04837 selmax = TMath::Log10(selmax)
04838 + TMath::Log10(2 * (0.9 / 0.95));
04839 selmax = TMath::Power(10, selmax);
04840 }
04841
04842 } else {
04843 Double_t yMARGIN = 0.05;
04844 #if ROOT_VERSION_CODE > ROOT_VERSION(5,0,9)
04845 yMARGIN = gStyle->GetHistTopMargin();
04846 #endif
04847 Double_t dymin = yMARGIN * (selmax - selmin);
04848 if ((selmin >= 0) && (selmin - dymin < 0))
04849 selmin = 0;
04850 else
04851 selmin -= dymin;
04852 selmax += yMARGIN * (selmax - selmin);
04853 }
04854
04855 padopt->SetRange(ndim, selmin, selmax);
04856 }
04857 }
04858
04859 }
04860
04861 if (padopt->IsHisStats() && isthishisto) {
04862 TPaveStats* stats =
04863 dynamic_cast<TPaveStats*>(h1->GetListOfFunctions()->FindObject("stats"));
04864 if (stats==0) {
04865 stats = new TPaveStats(
04866 gStyle->GetStatX()-gStyle->GetStatW(),
04867 gStyle->GetStatY()-gStyle->GetStatH(),
04868 gStyle->GetStatX(),
04869 gStyle->GetStatY(),"brNDC");
04870 stats->SetParent(h1);
04871 stats->UseCurrentStyle();
04872 stats->SetName("stats");
04873 h1->GetListOfFunctions()->Add(stats);
04874 stats->ConvertNDCtoPad();
04875 }
04876 padopt->GetStatsAttr(stats);
04877 }
04878
04879 if (padopt->IsHisTitle() && padopt->HasTitleAttr()) {
04880 TPaveText* titl =
04881 dynamic_cast<TPaveText*>(pad->GetListOfPrimitives()->FindObject("title"));
04882
04883 if (titl==0) {
04884 titl = new TPaveText(gStyle->GetTitleX()-gStyle->GetTitleW(),
04885 gStyle->GetTitleY()-gStyle->GetTitleH(),
04886 gStyle->GetTitleX(),
04887 gStyle->GetTitleY(),"blNDC");
04888 titl->UseCurrentStyle();
04889 titl->SetFillColor(gStyle->GetTitleFillColor());
04890 titl->SetFillStyle(gStyle->GetTitleStyle());
04891 titl->SetName("title");
04892 titl->SetBorderSize(gStyle->GetTitleBorderSize());
04893 titl->SetTextColor(gStyle->GetTitleTextColor());
04894 titl->SetTextFont(gStyle->GetTitleFont(""));
04895 if (gStyle->GetTitleFont("")%10 > 2)
04896 titl->SetTextSize(gStyle->GetTitleFontSize());
04897 titl->AddText(h1->GetTitle());
04898 titl->SetBit(kCanDelete);
04899 pad->GetListOfPrimitives()->Add(titl);
04900 titl->ConvertNDCtoPad();
04901 }
04902 padopt->GetTitleAttr(titl);
04903 }
04904
04905
04906 TAxis* xax = h1->GetXaxis();
04907 xax->SetTimeDisplay(padopt->IsXAxisTimeDisplay());
04908 xax->SetTimeFormat(padopt->GetXAxisTimeFormat());
04909
04910
04911 }
04912
04913 bool TGo4ViewPanel::GetVisibleRange(TPad* pad, int naxis, double& min, double& max)
04914 {
04915 TGo4Picture* padopt = GetPadOptions(pad);
04916 if (padopt == 0) return false;
04917
04918 int NumDim = padopt->GetFullRangeDim();
04919
04920 if ((naxis < 0) || (naxis > NumDim)) return false;
04921
04922 bool res = padopt->GetRange(naxis, min, max);
04923 if (!res || (min >= max))
04924 res = padopt->GetFullRange(naxis, min, max);
04925 return res;
04926 }
04927
04928 bool TGo4ViewPanel::TakeSelectedAxisRange(int naxis, TGo4Picture* padopt,
04929 double selmin, double selmax, bool force)
04930 {
04931 if ((selmin == -1.) && (selmax == -1.)) return false;
04932
04933 double min, max, umin, umax;
04934
04935 bool full = padopt->GetFullRange(naxis, min, max);
04936 bool sel = padopt->GetRange(naxis, umin, umax);
04937
04938 if (!full || (min >= max) || (selmin >= selmax)) {
04939 padopt->ClearRange(naxis);
04940 return true;
04941 }
04942
04943 double delta = (max - min) / 100000.;
04944 bool changed = false;
04945
04946 if (umin < umax) {
04947 if (fabs(umin - selmin) > delta) {
04948 umin = selmin;
04949 changed = true;
04950 }
04951 if (fabs(umax - selmax) > delta) {
04952 umax = selmax;
04953 changed = true;
04954 }
04955 } else {
04956 umin = selmin;
04957 umax = selmax;
04958 changed = true;
04959 }
04960
04961 if ((selmin < min + delta) && (selmax > max - delta) && !force) {
04962 padopt->ClearRange(naxis);
04963 } else {
04964 padopt->SetRange(naxis, umin, umax);
04965 }
04966
04967 return changed;
04968 }
04969
04970 bool TGo4ViewPanel::TakeSelectedAxisRange(int naxis, TGo4Picture* padopt, TAxis* ax)
04971 {
04972 Double_t selmin, selmax;
04973
04974
04975 if (((ax->GetFirst() <= 0) && (ax->GetLast() >= ax->GetNbins() - 1))
04976 || (ax->GetFirst() >= ax->GetLast())) {
04977 selmin = -1111;
04978 selmax = -1111;
04979 } else {
04980 selmin = ax->GetBinCenter(ax->GetFirst());
04981 selmax = ax->GetBinCenter(ax->GetLast());
04982 }
04983
04984 return TakeSelectedAxisRange(naxis, padopt, selmin, selmax, false);
04985 }
04986
04987 void TGo4ViewPanel::PadRangeAxisChanged(TPad* pad)
04988 {
04989 TGo4LockGuard lock(0, true);
04990
04991 TGo4Picture* padopt = GetPadOptions(pad);
04992
04993 if (IsRedrawBlocked() || (pad == 0) || (padopt == 0)) return;
04994
04995
04996 TH1* h1 = GetPadHistogram(pad);
04997
04998 if (h1 != 0) {
04999 Int_t ndim = padopt->GetFullRangeDim();
05000
05001 TakeSelectedAxisRange(0, padopt, h1->GetXaxis());
05002 if (ndim > 1)
05003 TakeSelectedAxisRange(1, padopt, h1->GetYaxis());
05004 if (ndim > 2)
05005 TakeSelectedAxisRange(2, padopt, h1->GetZaxis());
05006 if (ndim < 3) {
05007
05008 bool iszoomed = h1->TestBit(TH1::kIsZoomed);
05009
05010 padopt->SetAutoScale(!iszoomed);
05011
05012
05013
05014 Double_t selmin = h1->GetMinimum();
05015 Double_t selmax = h1->GetMaximum();
05016
05017 if (iszoomed) {
05018 padopt->SetRange(ndim, selmin, selmax);
05019 } else if (selmin >= selmax) {
05020 padopt->ClearRange(ndim);
05021 } else {
05022
05023 bool islogscale = (ndim == 1) && (pad->GetLogy() > 0);
05024
05025 if (islogscale) {
05026 if ((selmin > 0) && (selmax > 0)) {
05027 selmin = TMath::Log10(selmin) + TMath::Log10(0.5);
05028 selmin = TMath::Power(10, selmin);
05029 selmax = TMath::Log10(selmax)
05030 + TMath::Log10(2 * (0.9 / 0.95));
05031 selmax = TMath::Power(10, selmax);
05032 }
05033
05034 } else {
05035 Double_t yMARGIN = 0.05;
05036 #if ROOT_VERSION_CODE > ROOT_VERSION(5,0,9)
05037 yMARGIN = gStyle->GetHistTopMargin();
05038 #endif
05039 Double_t dymin = yMARGIN * (selmax - selmin);
05040 if ((selmin >= 0) && (selmin - dymin < 0))
05041 selmin = 0;
05042 else
05043 selmin -= dymin;
05044 selmax += yMARGIN * (selmax - selmin);
05045 }
05046
05047 padopt->SetRange(ndim, selmin, selmax);
05048 }
05049 }
05050
05051
05052 CallPanelFunc(panel_Updated, pad);
05053 return;
05054 }
05055
05056 Double_t rxmin, rxmax, rymin, rymax;
05057 pad->GetRangeAxis(rxmin, rymin, rxmax, rymax);
05058
05059 if (pad->GetLogx() > 0) {
05060 rxmin = TMath::Power(10., rxmin);
05061 rxmax = TMath::Power(10., rxmax);
05062 }
05063
05064 if (pad->GetLogy() > 0) {
05065 rymin = TMath::Power(10., rymin);
05066 rymax = TMath::Power(10., rymax);
05067 }
05068
05069 PadRangeAxisChanged(pad, rxmin, rxmax, rymin, rymax);
05070 }
05071
05072 void TGo4ViewPanel::PadRangeAxisChanged(TPad* pad, double rxmin, double rxmax,
05073 double rymin, double rymax)
05074 {
05075 TGo4LockGuard lock(0, true);
05076
05077 if (IsRedrawBlocked() || (pad == 0)) return;
05078
05079 TGo4Picture* padopt = GetPadOptions(pad);
05080 if (padopt == 0) return;
05081
05082 TakeSelectedAxisRange(0, padopt, rxmin, rxmax, false);
05083 TakeSelectedAxisRange(1, padopt, rymin, rymax, false);
05084
05085 CallPanelFunc(panel_Updated, pad);
05086 }
05087
05088 void TGo4ViewPanel::GetSelectedRange(int& ndim, bool& autoscale, double& xmin,
05089 double& xmax, double& ymin, double& ymax, double& zmin, double& zmax)
05090 {
05091 ndim = 0;
05092 TGo4Picture* padopt = GetPadOptions(GetActivePad());
05093 if (padopt == 0) return;
05094
05095 ndim = padopt->GetFullRangeDim();
05096 autoscale = padopt->IsAutoScale();
05097
05098 GetVisibleRange(GetActivePad(), 0, xmin, xmax);
05099 GetVisibleRange(GetActivePad(), 1, ymin, ymax);
05100 GetVisibleRange(GetActivePad(), 2, zmin, zmax);
05101 }
05102
05103 void TGo4ViewPanel::SetAutoScale(bool on, TPad* selpad)
05104 {
05105 TGo4LockGuard lock(0, true);
05106
05107 bool modified = false;
05108 bool applytoall = false;
05109 bool redraw_immediately = (selpad == 0);
05110
05111 if (selpad == 0) {
05112 applytoall = IsApplyToAllFlag();
05113 selpad = applytoall ? GetCanvas() : GetActivePad();
05114 }
05115 if (selpad == 0)
05116 return;
05117
05118 TGo4Picture* padopt = GetPadOptions(selpad);
05119 if (padopt != 0) {
05120 if (on != padopt->IsAutoScale())
05121 padopt->SetPadModified();
05122 padopt->SetAutoScale(on);
05123 modified = modified || padopt->IsPadModified();
05124 }
05125
05126 if (applytoall) {
05127 TGo4Iter iter(GetPadSlot(selpad), kTRUE);
05128 while (iter.next()) {
05129 TPad* subpad = GetSlotPad(iter.getslot());
05130 padopt = GetPadOptions(subpad);
05131 if (padopt == 0)
05132 continue;
05133 if (on != padopt->IsAutoScale())
05134 padopt->SetPadModified();
05135 padopt->SetAutoScale(on);
05136 modified = modified || padopt->IsPadModified();
05137 }
05138 }
05139
05140 if (modified && redraw_immediately)
05141 RedrawPanel(selpad, false);
05142 }
05143
05144 void TGo4ViewPanel::SetSelectedRange(double xmin, double xmax, double ymin,
05145 double ymax, double zmin, double zmax)
05146 {
05147 TGo4LockGuard lock(0, true);
05148
05149 TPad* selpad = IsApplyToAllFlag() ? GetCanvas() : GetActivePad();
05150 if (selpad == 0)
05151 return;
05152
05153 TGo4Picture* padopt = GetPadOptions(selpad);
05154 if (padopt != 0) {
05155 Int_t ndim = padopt->GetFullRangeDim();
05156
05157 TakeSelectedAxisRange(0, padopt, xmin, xmax, true);
05158 if (ndim > 1)
05159 TakeSelectedAxisRange(1, padopt, ymin, ymax, true);
05160 if (ndim > 2)
05161 TakeSelectedAxisRange(2, padopt, zmin, zmax, true);
05162 if (!padopt->IsAutoScale()) {
05163 if (ndim == 1)
05164 TakeSelectedAxisRange(1, padopt, ymin, ymax, true);
05165 if (ndim == 2)
05166 TakeSelectedAxisRange(2, padopt, zmin, zmax, true);
05167 }
05168 padopt->SetPadModified();
05169 }
05170
05171 if (IsApplyToAllFlag()) {
05172 TGo4Iter iter(GetPadSlot(selpad), kTRUE);
05173 while (iter.next()) {
05174 TPad* subpad = GetSlotPad(iter.getslot());
05175 padopt = GetPadOptions(subpad);
05176 if (padopt == 0)
05177 continue;
05178 Int_t ndim = padopt->GetFullRangeDim();
05179 TakeSelectedAxisRange(0, padopt, xmin, xmax, true);
05180 if (ndim > 1)
05181 TakeSelectedAxisRange(1, padopt, ymin, ymax, true);
05182 if (ndim > 2)
05183 TakeSelectedAxisRange(2, padopt, zmin, zmax, true);
05184 if (!padopt->IsAutoScale()) {
05185 if (ndim == 1)
05186 TakeSelectedAxisRange(1, padopt, ymin, ymax, true);
05187 if (ndim == 2)
05188 TakeSelectedAxisRange(2, padopt, zmin, zmax, true);
05189 }
05190
05191 padopt->SetPadModified();
05192 }
05193 }
05194
05195 RedrawPanel(selpad, false);
05196 }
05197
05198 void TGo4ViewPanel::resizeEvent(QResizeEvent * e)
05199 {
05200
05201
05202 go4sett->storePanelSize(parentWidget(), "ViewPanel");
05203 }
05204
05205 void TGo4ViewPanel::ResizeGedEditor()
05206 {
05207 #ifndef __NOGO4GED__
05208 TGedEditor* ed = dynamic_cast<TGedEditor*>(fxPeditor);
05209 if ((ed != 0) && fbEditorFrameVisible && fxRooteditor)
05210 ed->Resize(fxRooteditor->width(), fxRooteditor->height());
05211 #endif
05212 }
05213
05214 void TGo4ViewPanel::ActivateInGedEditor(TObject* obj)
05215 {
05216 if (!fbEditorFrameVisible) return;
05217
05218 #ifndef __NOGO4GED__
05219 TGedEditor* ed = dynamic_cast<TGedEditor*>(fxPeditor);
05220 if ((ed != 0) && (obj != 0))
05221 if (!obj->InheritsFrom(THStack::Class()) && !obj->InheritsFrom(TMultiGraph::Class())) {
05222 gTQSender = GetCanvas();
05223 ed->SetModel(GetActivePad(), obj, kButton1Down);
05224 }
05225 #endif
05226 }
05227
05228 void TGo4ViewPanel::CleanupGedEditor()
05229 {
05230 #ifndef __NOGO4GED__
05231
05232 TGedEditor* ed = dynamic_cast<TGedEditor*>(fxPeditor);
05233 if (ed == 0) return;
05234 if (fDummyHisto == 0) {
05235 fDummyHisto = new TH1I("dummyhisto", "dummyhisto", 100, -10., 10.);
05236 fDummyHisto->FillRandom("gaus", 1000);
05237 fDummyHisto->SetDirectory(0);
05238 fDummyHisto->SetBit(kCanDelete, kFALSE);
05239 }
05240 gTQSender = GetCanvas();
05241 ed->SetModel(0, fDummyHisto, kButton1Down);
05242 ed->SetModel(0, GetCanvas(), kButton1Down);
05243 #endif
05244 }
05245
05246 void TGo4ViewPanel::ShootRepaintTimer()
05247 {
05248 ShootRepaintTimer(GetCanvas());
05249 }
05250
05251 void TGo4ViewPanel::ShootRepaintTimer(TPad* pad)
05252 {
05253 if (IsRepaintTimerActive()) return;
05254
05255 if (pad == 0) pad = GetCanvas();
05256
05257 fxRepaintTimerPad = pad;
05258 CallServiceFunc(service_PanelTimer);
05259 }
05260
05261 bool TGo4ViewPanel::IsRepaintTimerActive()
05262 {
05263 return fxRepaintTimerPad != 0;
05264 }
05265
05266 void TGo4ViewPanel::checkRepaintSlot()
05267 {
05268 TPad* pad = fxRepaintTimerPad;
05269 fxRepaintTimerPad = 0;
05270 if (pad != 0)
05271 RedrawPanel(pad, false);
05272 }
05273
05274 void TGo4ViewPanel::PadDeleted(TPad* pad)
05275 {
05276 TGo4Slot* slot = GetPadSlot(pad);
05277 if (slot != 0)
05278 delete slot;
05279
05280 GetCanvas()->SetSelectedPad(GetCanvas());
05281 GetCanvas()->SetSelected(GetCanvas());
05282 TGo4MdiArea::Instance()->SetSelectedPad(GetCanvas());
05283 }
05284
05285
05286
05287 int TGo4ViewPanel::GetNumMarkers(TPad* pad, int kind)
05288 {
05289 TGo4Slot* slot = GetPadSlot(pad);
05290 if (slot == 0)
05291 return 0;
05292
05293 int res = 0;
05294
05295 for (int n = 0; n < slot->NumChilds(); n++) {
05296 TGo4Slot* subslot = slot->GetChild(n);
05297 if (GetDrawKind(subslot) == kind)
05298 res++;
05299 }
05300 return res;
05301 }
05302
05303 void TGo4ViewPanel::AddMarkerObj(TPad* pad, int kind, TObject* obj)
05304 {
05305 TGo4Slot* padslot = GetPadSlot(pad);
05306 if (padslot == 0) {
05307 delete obj;
05308 return;
05309 }
05310
05311 QString basename;
05312 switch (kind) {
05313 case kind_Marker:
05314 basename = "Marker";
05315 break;
05316 case kind_Window:
05317 basename = "Window";
05318 break;
05319 case kind_Poly:
05320 basename = "Polygon";
05321 break;
05322 case kind_Latex:
05323 basename = "Latex";
05324 break;
05325 case kind_Arrow:
05326 basename = "Arrow";
05327 break;
05328 default:
05329 basename = "Something";
05330 break;
05331 }
05332
05333 QString slotname;
05334 int cnt = 0;
05335 do {
05336 slotname = basename + QString::number(cnt++);
05337 } while (padslot->FindChild(slotname.toLatin1().constData()) != 0);
05338
05339 TGo4Slot* objslot = AddDrawObject(pad, kind, slotname.toLatin1().constData(), obj, true, 0);
05340
05341 SetActiveObj(pad, kind, objslot);
05342 }
05343
05344 void TGo4ViewPanel::SetActiveObj(TPad* pad, int kind, TGo4Slot* activeslot)
05345 {
05346 TGo4Slot* slot = GetPadSlot(pad);
05347 if (slot == 0)
05348 return;
05349
05350 for (int n = 0; n < slot->NumChilds(); n++) {
05351 TGo4Slot* subslot = slot->GetChild(n);
05352 int drawkind = GetDrawKind(subslot);
05353 if (drawkind != kind)
05354 continue;
05355
05356 if (subslot != activeslot)
05357 subslot->RemovePar("::ActiveMarker");
05358 else
05359 subslot->SetPar("::ActiveMarker", "1");
05360 }
05361 }
05362
05363 TObject* TGo4ViewPanel::GetActiveObj(TPad* pad, int kind)
05364 {
05365 int selkind;
05366 TObject* selobj;
05367 TGo4Slot* selslot = GetSelectedSlot(pad, &selkind, &selobj);
05368 if ((kind == selkind) && (selobj != 0))
05369 return selobj;
05370
05371 TGo4Slot* slot = GetPadSlot(pad);
05372 if (slot == 0)
05373 return 0;
05374
05375 TObject* lastobj = 0;
05376
05377 for (int n = 0; n < slot->NumChilds(); n++) {
05378 TGo4Slot* subslot = slot->GetChild(n);
05379 int drawkind = GetDrawKind(subslot);
05380 if (drawkind != kind)
05381 continue;
05382
05383 lastobj = subslot->GetAssignedObject();
05384 if (subslot->GetPar("::ActiveMarker") != 0)
05385 return lastobj;
05386 }
05387
05388 return lastobj;
05389 }
05390
05391 QString TGo4ViewPanel::GetActiveObjName(TPad* pad, int kind)
05392 {
05393 TObject* obj = GetActiveObj(pad, kind);
05394 return (obj == 0) ? QString("null") : QString(obj->GetName());
05395 }
05396
05397 void TGo4ViewPanel::OptionsMenuItemActivated(int id)
05398 {
05399 TGo4LockGuard lock(0, true);
05400
05401 switch (id) {
05402 case CrosshairId: {
05403 fbCanvasCrosshair = !fbCanvasCrosshair;
05404 GetCanvas()->SetCrosshair(fbCanvasCrosshair);
05405
05406 #if ROOT_VERSION_CODE < ROOT_VERSION(4,0,8)
05407
05408 TGo4Iter(GetPadSlot(GetCanvas()), true);
05409 while (iter.next()) {
05410 TPad* subpad = GetSlotPad(iter.getslot());
05411 if (subpad!=0) {
05412 subpad->SetCrosshair(fbCanvasCrosshair);
05413 subpad->Modified();
05414 }
05415 }
05416 #endif
05417
05418 GetQCanvas()->Modified();
05419 GetQCanvas()->Update();
05420 CallPanelFunc(panel_Updated, GetCanvas());
05421 break;
05422 }
05423
05424 case FreezeTitleId: {
05425 fbFreezeTitle = !fbFreezeTitle;
05426 break;
05427 }
05428
05429 case SetTitleTextId: {
05430 bool ok = false;
05431 QString mycaption = windowTitle();
05432 QString oldtitle = mycaption.remove(fPanelName + ": ");
05433 QString text = QInputDialog::getText(this, GetPanelName(),
05434 "Enter Viewpanel Title:", QLineEdit::Normal, oldtitle, &ok);
05435 if (ok && !text.isEmpty())
05436 SetFreezedTitle(text);
05437 break;
05438 }
05439
05440 case SetTimeFormatId: {
05441 bool ok = false;
05442 TPad* pad = GetActivePad();
05443 if (pad == 0)
05444 pad = GetCanvas();
05445 TGo4Picture *padopt = GetPadOptions(pad);
05446 QString oldfmt = padopt->GetXAxisTimeFormat();
05447 QString text = QInputDialog::getText(this, GetPanelName(),
05448 "Enter Axis time format:", QLineEdit::Normal, oldfmt, &ok);
05449 if (ok && !text.isEmpty()) {
05450
05451
05452
05453 ChangeDrawOption(id - 1000, 0, text.toLatin1());
05454 }
05455 break;
05456 }
05457
05458 default:
05459 if (id > 1000) {
05460 QAction* act = SetIdAction(fOptionsMap, id);
05461 bool s = act ? act->isChecked() : false;
05462 ChangeDrawOption(id - 1000, s, 0);
05463 }
05464 }
05465 }
05466
05467 void TGo4ViewPanel::ApplyToAllToggled(bool on)
05468 {
05469
05470
05471 fbApplyToAllFlag = on;
05472 }
05473
05474 void TGo4ViewPanel::AutoScaleToggled(bool on)
05475 {
05476 if (IsRedrawBlocked())
05477 return;
05478
05479 SetAutoScale(on, 0);
05480 }
05481
05482 void TGo4ViewPanel::panelSlot(TGo4ViewPanel * panel, TPad * pad, int signalid)
05483 {
05484 if (panel != this)
05485 return;
05486
05487 BlockPanelRedraw(true);
05488
05489 TGo4Picture* padopt = GetPadOptions(GetActivePad());
05490 if (padopt != 0)
05491 fAutoScaleCheck->setChecked(padopt->IsAutoScale());
05492
05493 BlockPanelRedraw(false);
05494 }
05495
05496 void TGo4ViewPanel::SuperImposeToggled(bool on)
05497 {
05498 if (IsRedrawBlocked())
05499 return;
05500
05501 ChangeDrawOption(11, on, "");
05502 }