Warning, file /include/root/TRecorder.h was not indexed
or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #ifndef ROOT_TRecorder
0013 #define ROOT_TRecorder
0014
0015
0016 #include "TApplication.h"
0017 #include "TError.h"
0018 #include "TTimer.h"
0019 #include "TGClient.h"
0020 #include "TGFrame.h"
0021 #include "TCanvas.h"
0022 #include "THashList.h"
0023
0024 #include <ctime>
0025 #include <iostream>
0026
0027 class TMutex;
0028 class TTree;
0029 class TFile;
0030 class TGPictureButton;
0031 class TGCheckButton;
0032 class TGLabel;
0033 class TRecorderState;
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048 class TRecEvent : public TObject
0049 {
0050 private:
0051 TTime fEventTime;
0052
0053 public:
0054
0055 enum ERecEventType {
0056 kCmdEvent,
0057 kGuiEvent,
0058 kExtraEvent
0059 };
0060
0061
0062 virtual void ReplayEvent(Bool_t showMouseCursor = kTRUE) = 0;
0063
0064
0065 virtual ERecEventType GetType() const = 0;
0066
0067 virtual TTime GetTime() const {
0068
0069 return fEventTime;
0070 }
0071
0072 virtual void SetTime(TTime t) {
0073
0074 fEventTime = t;
0075 }
0076
0077 ClassDefOverride(TRecEvent,1)
0078 };
0079
0080
0081
0082
0083
0084
0085
0086
0087
0088
0089
0090
0091 class TRecCmdEvent : public TRecEvent
0092 {
0093 private:
0094 TString fText;
0095
0096 public:
0097 TRecCmdEvent() {
0098
0099 }
0100
0101 void SetText(const char *text) {
0102
0103 fText = text;
0104 }
0105
0106 const char *GetText() const {
0107
0108 return fText.Data();
0109 }
0110
0111 ERecEventType GetType() const override {
0112
0113 return TRecEvent::kCmdEvent;
0114 }
0115
0116 void ReplayEvent(Bool_t) override {
0117
0118 std::cout << GetText() << std::endl;
0119 gApplication->ProcessLine(GetText());
0120 }
0121
0122 ClassDefOverride(TRecCmdEvent,1)
0123 };
0124
0125
0126
0127
0128
0129
0130
0131
0132
0133
0134
0135
0136 class TRecExtraEvent : public TRecEvent
0137 {
0138 private:
0139 TString fText;
0140
0141 public:
0142 TRecExtraEvent() {
0143
0144 }
0145
0146 void SetText(TString text) {
0147
0148 fText = text;
0149 }
0150
0151 TString GetText() const {
0152
0153 return fText;
0154 }
0155
0156 ERecEventType GetType() const override {
0157
0158 return TRecEvent::kExtraEvent;
0159 }
0160
0161 void ReplayEvent(Bool_t) override {
0162
0163
0164 gApplication->ProcessLine(GetText());
0165 }
0166
0167 ClassDefOverride(TRecExtraEvent,1)
0168 };
0169
0170
0171
0172
0173
0174
0175
0176
0177
0178
0179
0180 class TRecGuiEvent : public TRecEvent
0181 {
0182 protected:
0183 friend class TRecorderInactive;
0184 friend class TRecorderPaused;
0185 friend class TRecorderRecording;
0186 friend class TRecorderReplaying;
0187
0188 EGEventType fType;
0189 Window_t fWindow;
0190 Time_t fTime;
0191 Int_t fX;
0192 Int_t fY;
0193 Int_t fXRoot;
0194 Int_t fYRoot;
0195 UInt_t fCode;
0196 UInt_t fState;
0197 UInt_t fWidth;
0198 UInt_t fHeight;
0199 Int_t fCount;
0200 Bool_t fSendEvent;
0201 Handle_t fHandle;
0202 Int_t fFormat;
0203 Long_t fUser[5];
0204
0205
0206
0207 Window_t fMasked;
0208
0209 public:
0210
0211 enum EConfigureNotifyType {
0212 kCNMove = 0,
0213 kCNResize = 1,
0214 kCNMoveResize = 2,
0215 kCNFilter = 3
0216 };
0217
0218 enum ERootAtoms {
0219 kWM_DELETE_WINDOW = 10001,
0220 kROOT_MESSAGE = 10002
0221 };
0222
0223 ERecEventType GetType() const override {
0224
0225 return TRecEvent::kGuiEvent;
0226 }
0227
0228 void ReplayEvent(Bool_t showMouseCursor = kTRUE) override;
0229 static Event_t *CreateEvent(TRecGuiEvent *ge);
0230
0231 ClassDefOverride(TRecGuiEvent,1)
0232 };
0233
0234
0235
0236
0237
0238
0239
0240
0241
0242
0243
0244
0245
0246
0247
0248
0249 class TRecWinPair : public TObject
0250 {
0251 protected:
0252 friend class TRecorderReplaying;
0253
0254 Window_t fKey;
0255 Window_t fValue;
0256
0257 public:
0258
0259 TRecWinPair(Window_t key, Window_t value): fKey(key), fValue(value) {}
0260
0261 ClassDefOverride(TRecWinPair,1)
0262 };
0263
0264
0265 class TRecorder : public TObject
0266 {
0267 private:
0268 TRecorderState *fRecorderState;
0269
0270 TRecorder(const TRecorder&);
0271 TRecorder &operator=(const TRecorder&);
0272
0273 protected:
0274 friend class TRecorderState;
0275 friend class TRecorderInactive;
0276 friend class TRecorderPaused;
0277 friend class TRecorderRecording;
0278 friend class TRecorderReplaying;
0279
0280 TString fFilename;
0281
0282
0283 void ChangeState(TRecorderState *newstate, Bool_t deletePreviousState = kTRUE);
0284
0285 public:
0286
0287 enum EReplayModes {
0288 kRealtime
0289 };
0290
0291
0292 enum ERecorderState {
0293 kInactive,
0294 kRecording,
0295 kPaused,
0296 kReplaying
0297 };
0298
0299
0300 TRecorder();
0301 TRecorder(const char *filename, Option_t *option = "READ");
0302
0303
0304 ~TRecorder() override;
0305
0306 void Browse(TBrowser *) override;
0307
0308
0309 void Start(const char *filename, Option_t *option = "RECREATE", Window_t *w = nullptr, Int_t winCount = 0);
0310
0311
0312 void Stop(Bool_t guiCommand = kFALSE);
0313
0314
0315 Bool_t Replay(const char *filename, Bool_t showMouseCursor = kTRUE, TRecorder::EReplayModes mode = kRealtime);
0316
0317
0318 void Replay() { Replay(fFilename); }
0319
0320
0321 void Pause();
0322
0323
0324 void Resume();
0325
0326
0327 void ReplayStop();
0328
0329
0330 void ListCmd(const char *filename);
0331
0332
0333 void ListGui(const char *filename);
0334
0335
0336 virtual TRecorder::ERecorderState GetState() const;
0337
0338
0339 void PrevCanvases(const char *filename, Option_t *option);
0340
0341 ClassDefOverride(TRecorder,2)
0342 };
0343
0344
0345
0346
0347
0348
0349
0350
0351
0352
0353
0354
0355
0356
0357
0358
0359
0360 class TRecorderState
0361 {
0362 protected:
0363 friend class TRecorder;
0364 void ChangeState(TRecorder *r, TRecorderState *s, Bool_t deletePreviousState) { r->ChangeState(s, deletePreviousState); }
0365
0366 public:
0367 virtual ~TRecorderState() {}
0368 virtual void Start(TRecorder *, const char *, Option_t *, Window_t *, Int_t) {}
0369 virtual void Stop(TRecorder *, Bool_t ) {}
0370 virtual Bool_t Replay(TRecorder *, const char *, Bool_t, TRecorder::EReplayModes) { return false; }
0371 virtual void Pause(TRecorder *) {}
0372 virtual void Resume(TRecorder *) {}
0373 virtual void ReplayStop(TRecorder *) {}
0374
0375 virtual void ListCmd(const char *) {}
0376 virtual void ListGui(const char *) {}
0377
0378 virtual void PrevCanvases(const char *, Option_t *) {}
0379
0380 virtual TRecorder::ERecorderState GetState() const = 0;
0381
0382 ClassDef(TRecorderState, 0)
0383 };
0384
0385
0386
0387
0388
0389
0390
0391
0392
0393
0394
0395 class TRecorderReplaying : public TRecorderState
0396 {
0397 private:
0398 ~TRecorderReplaying() override;
0399 Bool_t PrepareNextEvent();
0400 Bool_t RemapWindowReferences();
0401 Bool_t CanOverlap();
0402
0403 Bool_t FilterEvent(TRecGuiEvent *e);
0404
0405 TRecorder *fRecorder;
0406
0407
0408 TFile *fFile;
0409
0410
0411 TCanvas *fCanv;
0412
0413
0414 TTimer *fTimer;
0415
0416 TTree *fWinTree;
0417 TTree *fGuiTree;
0418 TTree *fCmdTree;
0419 TTree *fExtraTree;
0420
0421 ULong64_t fWin;
0422 TRecGuiEvent *fGuiEvent;
0423 TRecCmdEvent *fCmdEvent;
0424 TRecExtraEvent *fExtraEvent;
0425
0426 Int_t fRegWinCounter;
0427 Int_t fGuiTreeCounter;
0428 Int_t fCmdTreeCounter;
0429 Int_t fExtraTreeCounter;
0430
0431 Int_t fWinTreeEntries;
0432
0433 TMutex *fMutex;
0434
0435 TList *fWindowList;
0436
0437 TRecEvent *fNextEvent;
0438
0439 TTime fPreviousEventTime;
0440
0441
0442 Bool_t fWaitingForWindow;
0443
0444
0445
0446
0447
0448 Bool_t fEventReplayed;
0449
0450
0451
0452
0453
0454 Bool_t fShowMouseCursor;
0455
0456 Bool_t fFilterStatusBar;
0457
0458 protected:
0459 friend class TRecorderInactive;
0460 friend class TRecorderPaused;
0461
0462 TRecorderReplaying(const char *filename);
0463 Bool_t Initialize(TRecorder *r, Bool_t showMouseCursor, TRecorder::EReplayModes mode);
0464
0465 public:
0466 TRecorder::ERecorderState GetState() const override { return TRecorder::kReplaying; }
0467
0468 void Pause(TRecorder *r) override;
0469 virtual void Continue();
0470 void ReplayStop(TRecorder *r) override;
0471
0472 void RegisterWindow(Window_t w);
0473 void ReplayRealtime();
0474
0475 ClassDefOverride(TRecorderReplaying, 0)
0476 };
0477
0478
0479
0480
0481
0482
0483
0484
0485
0486
0487 class TRecorderRecording: public TRecorderState
0488 {
0489 private:
0490 ~TRecorderRecording() override;
0491 Bool_t IsFiltered(Window_t id);
0492 void SetTypeOfConfigureNotify(Event_t *e);
0493 void CopyEvent(Event_t *e, Window_t wid);
0494
0495 TRecorder *fRecorder;
0496
0497
0498 TFile *fFile;
0499 TTimer *fTimer;
0500 TTimer *fMouseTimer;
0501 Long64_t fBeginPave;
0502
0503 TTree *fWinTree;
0504 TTree *fGuiTree;
0505 TTree *fCmdTree;
0506 TTree *fExtraTree;
0507
0508 ULong64_t fWin;
0509 TRecGuiEvent *fGuiEvent;
0510 TRecCmdEvent *fCmdEvent;
0511 TRecExtraEvent *fExtraEvent;
0512
0513 Bool_t fCmdEventPending;
0514
0515
0516
0517 Int_t fRegWinCounter;
0518
0519
0520 Int_t fFilteredIdsCount;
0521 Window_t *fFilteredIds;
0522
0523 Bool_t fFilterEventPave;
0524
0525 protected:
0526 friend class TRecorderInactive;
0527 TRecorderRecording(TRecorder *r, const char *filename, Option_t *option, Window_t *w, Int_t winCount);
0528
0529 Bool_t StartRecording();
0530
0531 public:
0532 TRecorder::ERecorderState GetState() const override { return TRecorder::kRecording; }
0533
0534 void Stop(TRecorder *r, Bool_t guiCommand) override;
0535
0536 void RegisterWindow(Window_t w);
0537 void RecordCmdEvent(const char *line);
0538 void RecordGuiEvent(Event_t *e, Window_t wid);
0539 void RecordGuiBldEvent(Event_t *e);
0540 void RecordGuiCNEvent(Event_t *e);
0541 void RecordMousePosition();
0542 void RecordPave(const TObject *obj);
0543 void RecordText(const TObject *obj);
0544 void FilterEventPave();
0545 void StartEditing();
0546
0547 void RecordExtraEvent(TString line, TTime extTime);
0548
0549 ClassDefOverride(TRecorderRecording, 0)
0550 };
0551
0552
0553
0554
0555
0556
0557
0558
0559
0560
0561
0562
0563 class TRecorderInactive : public TRecorderState
0564 {
0565
0566 private:
0567 TSeqCollection *fCollect;
0568
0569 public:
0570 ~TRecorderInactive() override {}
0571 TRecorderInactive() : fCollect(nullptr) {}
0572
0573 void ListCmd(const char *filename) override;
0574 void ListGui(const char *filename) override;
0575
0576 void Start(TRecorder *r, const char *filename, Option_t *option, Window_t *w = nullptr, Int_t winCount = 0) override;
0577 Bool_t Replay(TRecorder *r, const char *filename, Bool_t showMouseCursor, TRecorder::EReplayModes mode) override;
0578
0579 TRecorder::ERecorderState GetState() const override { return TRecorder::kInactive; }
0580
0581 static void DumpRootEvent(TRecGuiEvent *e, Int_t n);
0582 static long DisplayValid(Long_t n) { return ( n < 0 ? -1 : n); }
0583
0584 void PrevCanvases(const char *filename, Option_t *option) override;
0585
0586 ClassDefOverride(TRecorderInactive, 0)
0587 };
0588
0589
0590
0591
0592
0593
0594
0595
0596
0597
0598
0599
0600
0601
0602 class TRecorderPaused: public TRecorderState
0603 {
0604 private:
0605 ~TRecorderPaused() override {}
0606
0607 TRecorderReplaying *fReplayingState;
0608
0609 protected:
0610 friend class TRecorderReplaying;
0611 TRecorderPaused(TRecorderReplaying *state);
0612
0613 public:
0614 TRecorder::ERecorderState GetState() const override { return TRecorder::kPaused; }
0615
0616 void Resume(TRecorder *r) override;
0617 void ReplayStop(TRecorder *r) override;
0618
0619 ClassDefOverride(TRecorderPaused, 0)
0620 };
0621
0622
0623
0624
0625
0626
0627
0628
0629
0630 class TGRecorder : public TGMainFrame
0631 {
0632 private:
0633 TRecorder *fRecorder;
0634
0635 TGPictureButton *fStartStop;
0636 TGPictureButton *fReplay;
0637
0638 TGLabel *fStatus;
0639 TGLabel *fTimeDisplay;
0640 TGCheckButton *fCursorCheckBox;
0641
0642 TTimer *fTimer;
0643 time_t fStart, fElapsed;
0644
0645 static const Int_t fgWidgetsCount = 12;
0646 Window_t fFilteredIds[fgWidgetsCount];
0647
0648 void SetDefault();
0649
0650 public:
0651 TGRecorder(const TGWindow *p = nullptr, UInt_t w = 230, UInt_t h = 150);
0652 ~TGRecorder() override;
0653
0654 void StartStop();
0655 void Update();
0656 void Replay();
0657
0658 ClassDefOverride(TGRecorder,0)
0659 };
0660
0661 #endif