vtkSMRemoteObject.h 6.64 KB
Newer Older
Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14
/*=========================================================================

  Program:   ParaView
  Module:    vtkSMRemoteObject.h

  Copyright (c) Kitware, Inc.
  All rights reserved.
  See Copyright.txt or http://www.paraview.org/HTML/Copyright.html for details.

     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
     PURPOSE.  See the above copyright notice for more information.

=========================================================================*/
15 16 17 18 19 20 21 22
/**
 * @class   vtkSMRemoteObject
 * @brief   baseclass for all proxy-objects that have counter
 * parts on server as well as client processes.
 *
 * Abstract class involved in ServerManager class hierarchy that has a
 * corresponding SIObject which can be local or remote.
*/
Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
23

24 25
#ifndef vtkSMRemoteObject_h
#define vtkSMRemoteObject_h
Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
26

27
#include "vtkPVServerManagerCoreModule.h" //needed for exports
28
#include "vtkSMMessageMinimal.h"          // needed for vtkSMMessage
29
#include "vtkSMSessionObject.h"
30
#include "vtkWeakPointer.h" // needed for vtkWeakPointer
Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
31

32
class vtkClientServerStream;
Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
33
class vtkSMSession;
34
class vtkSMProxyLocator;
35
class vtkSMLoadStateContext;
Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
36

37
class VTKPVSERVERMANAGERCORE_EXPORT vtkSMRemoteObject : public vtkSMSessionObject
Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
38
{
Kitware Robot's avatar
Kitware Robot committed
39 40 41
  // My friends are...
  friend class vtkSMStateHelper; // To pull state
  friend class vtkSMStateLoader; // To set GlobalId as the originals
42

Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
43
public:
Kitware Robot's avatar
Kitware Robot committed
44
  vtkTypeMacro(vtkSMRemoteObject, vtkSMSessionObject);
45
  void PrintSelf(ostream& os, vtkIndent indent) override;
Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
46

47 48 49
  //@{
  /**
   * Get/Set the location where the underlying VTK-objects are created. The
luz paz's avatar
luz paz committed
50
   * value can be constructed by or-ing vtkSMSession::ServerFlags
51
   */
Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
52 53
  vtkSetMacro(Location, vtkTypeUInt32);
  vtkGetMacro(Location, vtkTypeUInt32);
54
  //@}
Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
55

56 57 58 59
  /**
   * Override the SetSession so if the object already have an ID
   * we automatically register it to the associated session
   */
60
  void SetSession(vtkSMSession*) override;
Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
61

62 63 64 65 66
  //@{
  /**
   * Get the global unique id for this object. If none is set and the session is
   * valid, a new global id will be assigned automatically.
   */
67
  virtual vtkTypeUInt32 GetGlobalID();
68
  const char* GetGlobalIDAsString();
69
  //@}
Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
70

71 72 73 74
  /**
   * Allow the user to test if the RemoteObject has already a GlobalID without
   * assigning a new one to it.
   */
75 76
  bool HasGlobalID();

77 78 79 80 81
  //@{
  /**
   * Allow user to set the remote object to be discard for Undo/Redo
   * action. By default, any remote object is Undoable.
   */
Sebastien Jourdain's avatar
Sebastien Jourdain committed
82
  vtkBooleanMacro(Prototype, bool);
Kitware Robot's avatar
Kitware Robot committed
83
  bool IsPrototype() { return this->Prototype; }
Sebastien Jourdain's avatar
Sebastien Jourdain committed
84
  vtkSetMacro(Prototype, bool);
85 86 87 88 89 90
  //@}

  /**
   * This method return the full object state that can be used to create that
   * object from scratch.
   * This method will be used to fill the undo stack.
luz paz's avatar
luz paz committed
91
   * If not overridden this will return NULL.
92
   */
Kitware Robot's avatar
Kitware Robot committed
93
  virtual const vtkSMMessage* GetFullState() { return NULL; }
94

95 96 97 98 99 100 101 102
  //@{
  /**
   * This method is used to initialise the object to the given state
   * If the definitionOnly Flag is set to True the proxy won't load the
   * properties values and just setup the new proxy hierarchy with all subproxy
   * globalID set. This allow to split the load process in 2 step to prevent
   * invalid state when property refere to a sub-proxy that does not exist yet.
   */
Kitware Robot's avatar
Kitware Robot committed
103 104 105 106 107
  virtual void LoadState(const vtkSMMessage* msg, vtkSMProxyLocator* locator)
  {
    (void)msg;
    (void)locator;
  }
108 109 110 111 112 113 114 115 116
  //@}

  /**
   * Allow to switch off any push of state change to the server for that
   * particular object.
   * This is used when we load a state based on a server notification. In that
   * particular case, the server is already aware of that new state, so we keep
   * those changes local.
   */
117 118
  virtual void EnableLocalPushOnly();

119
  /**
luz paz's avatar
luz paz committed
120
   * Enable the given remote object to communicate its state normally to the
121 122
   * server location.
   */
123 124
  virtual void DisableLocalPushOnly();

125 126 127 128
  /**
   * Let the session be aware that even if the Location is client only,
   * the message should not be send to the server for a general broadcast
   */
129
  virtual bool IsLocalPushOnly() { return this->ClientOnlyLocationFlag; }
130

Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
131
protected:
132 133 134
  /**
   * Default constructor.
   */
Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
135 136
  vtkSMRemoteObject();

137 138 139
  /**
   * Destructor.
   */
140
  ~vtkSMRemoteObject() override;
Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
141

142 143 144 145
  /**
   * Subclasses can call this method to send a message to its state
   * object on  the server processes specified.
   */
Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
146 147
  void PushState(vtkSMMessage* msg);

148 149 150 151 152
  /**
   * Subclasses can call this method to pull the state from the
   * state-object on the server processes specified. Returns true on successful
   * fetch. The message is updated with the fetched state.
   */
Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
153 154
  bool PullState(vtkSMMessage* msg);

155 156 157
  /**
   * Set the GlobalUniqueId
   */
158
  void SetGlobalID(vtkTypeUInt32 guid);
Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
159 160 161 162 163

  // Global-ID for this vtkSMRemoteObject. This is assigned when needed.
  // Assigned at :
  // - First push
  // - or when the RemoteObject is created by the ProcessModule remotely.
164
  // - or when state is loaded from protobuf messages
Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
165 166
  vtkTypeUInt32 GlobalID;

167
  // Location flag identify the processes on which the vtkSIObject
Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
168 169 170
  // corresponding to this vtkSMRemoteObject exist.
  vtkTypeUInt32 Location;

Sebastien Jourdain's avatar
Sebastien Jourdain committed
171 172 173 174
  // Allow remote object to be discard for any state management such as
  // Undo/Redo, Register/UnRegister (in ProxyManager) and so on...
  bool Prototype;

175 176 177 178 179 180 181
  // Field that store the Disable/EnableLocalPushOnly() state information
  bool ClientOnlyLocationFlag;

  // Convenient method used to return either the local Location or a filtered
  // version of it based on the ClientOnlyLocationFlag
  vtkTypeUInt32 GetFilteredLocation();

Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
182
private:
183 184
  vtkSMRemoteObject(const vtkSMRemoteObject&) = delete;
  void operator=(const vtkSMRemoteObject&) = delete;
185

186
  char* GlobalIDString;
Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
187 188
};

Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
189 190 191 192 193 194 195 196 197 198 199 200 201
/// This defines a manipulator for the vtkClientServerStream that can be used
/// to indicate to the interpreter that the placeholder is to be replaced by
/// the vtkSIProxy instance for the given vtkSMProxy instance.
/// e.g.
/// \code
/// vtkClientServerStream stream;
/// stream << vtkClientServerStream::Invoke
///        << SIOBJECT(proxyA)
///        << "MethodName"
///        << vtkClientServerStream::End;
/// \endcode
/// Will result in calling the vtkSIProxy::MethodName() when the stream in
/// interpreted.
202
class VTKPVSERVERMANAGERCORE_EXPORT SIOBJECT
203 204
{
  vtkSMRemoteObject* Reference;
205
  friend VTKPVSERVERMANAGERCORE_EXPORT vtkClientServerStream& operator<<(
206
    vtkClientServerStream& stream, const SIOBJECT& manipulator);
Kitware Robot's avatar
Kitware Robot committed
207

208
public:
Kitware Robot's avatar
Kitware Robot committed
209 210 211 212
  SIOBJECT(vtkSMRemoteObject* rmobject)
    : Reference(rmobject)
  {
  }
213 214
};

Kitware Robot's avatar
Kitware Robot committed
215 216
VTKPVSERVERMANAGERCORE_EXPORT vtkClientServerStream& operator<<(
  vtkClientServerStream& stream, const SIOBJECT& manipulator);
217

218
#endif // #ifndef vtkSMRemoteObject_h