AnalysisDataServiceObserver.h 5.17 KB
Newer Older
1
2
// Mantid Repository : https://github.com/mantidproject/mantid
//
3
// Copyright © 2019 ISIS Rutherford Appleton Laboratory UKRI,
4
5
//   NScD Oak Ridge National Laboratory, European Spallation Source,
//   Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6
// SPDX - License - Identifier: GPL - 3.0 +
7
#pragma once
8
9
10
11
12
13
14
15
16
17
18
19

#include "MantidAPI/AnalysisDataService.h"
#include "MantidAPI/DllConfig.h"
#include "MantidKernel/DataService.h"
#include <Poco/NObserver.h>

using namespace Mantid::Kernel;
using namespace Mantid::API;

namespace Mantid {
namespace API {

20
21
22
23
24
25
26
27
28
29
30
31
32
33
/*
 * To use the AnalysisDataServiceObserver you will need to do a few things:
 *
 * 1. Inherit from this class in the class you wish to take effect on
 *
 * 2. Make sure that the effect you are attempting to observe has been added
 * to the AnalysisDataService itself by using the public method in this
 * class, e.g. observeAll, observeAdd, observeReplace etc.
 *
 * 3. The last thing to actually have something take effect is by overriding
 * the relevant handle function e.g. when observing all override
 * anyChangeHandle and anything done in that overriden method will happen
 * every time something changes in the AnalysisDataService.
 *
Samuel Jones's avatar
Samuel Jones committed
34
 * This works in both C++ and Python, some functionality is limited in
35
 * python, but the handlers will all be called.
36
37
 */

38
39
40
41
42
43
44
class MANTID_API_DLL AnalysisDataServiceObserver {
public:
  AnalysisDataServiceObserver();
  virtual ~AnalysisDataServiceObserver();

  void observeAll(bool turnOn = true);
  void observeAdd(bool turnOn = true);
Samuel Jones's avatar
Samuel Jones committed
45
46
  void observeReplace(bool turnOn = true);
  void observeDelete(bool turnOn = true);
47
48
49
50
51
  void observeClear(bool turnOn = true);
  void observeRename(bool turnOn = true);
  void observeGroup(bool turnOn = true);
  void observeUnGroup(bool turnOn = true);
  void observeGroupUpdate(bool turnOn = true);
Samuel Jones's avatar
Samuel Jones committed
52

53
  virtual void anyChangeHandle();
54
  virtual void addHandle(const std::string &wsName, const Workspace_sptr &ws);
Samuel Jones's avatar
Samuel Jones committed
55
  virtual void replaceHandle(const std::string &wsName,
56
57
58
                             const Workspace_sptr &ws);
  virtual void deleteHandle(const std::string &wsName,
                            const Workspace_sptr &ws);
59
60
61
  virtual void clearHandle();
  virtual void renameHandle(const std::string &wsName,
                            const std::string &newName);
62
  virtual void groupHandle(const std::string &wsName, const Workspace_sptr &ws);
63
  virtual void unGroupHandle(const std::string &wsName,
64
                             const Workspace_sptr &ws);
65
  virtual void groupUpdateHandle(const std::string &wsName,
66
                                 const Workspace_sptr &ws);
Samuel Jones's avatar
Samuel Jones committed
67

68
private:
69
70
71
72
  bool m_observingAdd{false}, m_observingReplace{false},
      m_observingDelete{false}, m_observingClear{false},
      m_observingRename{false}, m_observingGroup{false},
      m_observingUnGroup{false}, m_observingGroupUpdate{false};
Samuel Jones's avatar
Samuel Jones committed
73
74
75
76
77
78
79

  void _addHandle(
      const Poco::AutoPtr<AnalysisDataServiceImpl::AddNotification> &pNf);
  void _replaceHandle(
      const Poco::AutoPtr<AnalysisDataServiceImpl::AfterReplaceNotification>
          &pNf);
  void _deleteHandle(
80
81
82
83
84
85
86
87
88
89
90
91
92
      const Poco::AutoPtr<AnalysisDataServiceImpl::PreDeleteNotification> &pNf);
  void _clearHandle(
      const Poco::AutoPtr<AnalysisDataServiceImpl::ClearNotification> &pNf);
  void _renameHandle(
      const Poco::AutoPtr<AnalysisDataServiceImpl::RenameNotification> &pNf);
  void _groupHandle(
      const Poco::AutoPtr<AnalysisDataServiceImpl::GroupWorkspacesNotification>
          &pNf);
  void _unGroupHandle(
      const Poco::AutoPtr<
          AnalysisDataServiceImpl::UnGroupingWorkspaceNotification> &pNf);
  void _groupUpdateHandle(
      const Poco::AutoPtr<AnalysisDataServiceImpl::GroupUpdatedNotification>
Samuel Jones's avatar
Samuel Jones committed
93
          &pNf);
94
95

  /// Poco::NObserver for AddNotification.
Samuel Jones's avatar
Samuel Jones committed
96
97
  Poco::NObserver<AnalysisDataServiceObserver,
                  AnalysisDataServiceImpl::AddNotification>
98
      m_addObserver;
Samuel Jones's avatar
Samuel Jones committed
99
100
101
102
103
104
105
106

  /// Poco::NObserver for ReplaceNotification.
  Poco::NObserver<AnalysisDataServiceObserver,
                  AnalysisDataServiceImpl::AfterReplaceNotification>
      m_replaceObserver;

  /// Poco::NObserver for DeleteNotification.
  Poco::NObserver<AnalysisDataServiceObserver,
107
                  AnalysisDataServiceImpl::PreDeleteNotification>
Samuel Jones's avatar
Samuel Jones committed
108
109
110
      m_deleteObserver;

  /// Poco::NObserver for ClearNotification
111
112
113
  Poco::NObserver<AnalysisDataServiceObserver,
                  AnalysisDataServiceImpl::ClearNotification>
      m_clearObserver;
Samuel Jones's avatar
Samuel Jones committed
114
115

  /// Poco::NObserver for RenameNotification
116
117
118
  Poco::NObserver<AnalysisDataServiceObserver,
                  AnalysisDataServiceImpl::RenameNotification>
      m_renameObserver;
Samuel Jones's avatar
Samuel Jones committed
119
120

  /// Poco::NObserver for GroupNotification
121
122
123
  Poco::NObserver<AnalysisDataServiceObserver,
                  AnalysisDataServiceImpl::GroupWorkspacesNotification>
      m_groupObserver;
Samuel Jones's avatar
Samuel Jones committed
124
125

  /// Poco::NObserver for UnGroupNotification
126
127
128
129
130
131
132
133
  Poco::NObserver<AnalysisDataServiceObserver,
                  AnalysisDataServiceImpl::UnGroupingWorkspaceNotification>
      m_unGroupObserver;

  /// Poco::NObserver for GroupUpdateNotification
  Poco::NObserver<AnalysisDataServiceObserver,
                  AnalysisDataServiceImpl::GroupUpdatedNotification>
      m_groupUpdatedObserver;
134
135
136
137
};

} // namespace API
} // namespace Mantid