1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176
|
/*=========================================================================
Program: ParaView
Module: vtkSMStateLoader.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.
=========================================================================*/
/**
* @class vtkSMStateLoader
* @brief Utility class to load state from XML
*
* vtkSMStateLoader can load server manager state from a given
* vtkPVXMLElement. This element is usually populated by a vtkPVXMLParser.
* @sa
* vtkPVXMLParser vtkPVXMLElement
*/
#ifndef vtkSMStateLoader_h
#define vtkSMStateLoader_h
#include "vtkPVServerManagerCoreModule.h" //needed for exports
#include "vtkSMDeserializerXML.h"
#include <map> // needed for API
#include <string> // needed for API
class vtkPVXMLElement;
class vtkSMProxy;
class vtkSMProxyLocator;
struct vtkSMStateLoaderInternals;
class VTKPVSERVERMANAGERCORE_EXPORT vtkSMStateLoader : public vtkSMDeserializerXML
{
public:
static vtkSMStateLoader* New();
vtkTypeMacro(vtkSMStateLoader, vtkSMDeserializerXML);
void PrintSelf(ostream& os, vtkIndent indent) VTK_OVERRIDE;
/**
* Load the state from the given root element.
*/
int LoadState(vtkPVXMLElement* rootElement, bool keepOriginalId = false);
//@{
/**
* Get/Set the proxy locator to use. Default is
* vtkSMProxyLocator will be used.
*/
void SetProxyLocator(vtkSMProxyLocator* loc);
vtkGetObjectMacro(ProxyLocator, vtkSMProxyLocator);
//@}
//@{
/**
* Allow the loader to keep the mapping between the id from the loaded state
* to the current proxy attributed id.
*/
vtkSetMacro(KeepIdMapping, int);
vtkGetMacro(KeepIdMapping, int);
vtkBooleanMacro(KeepIdMapping, int);
//@}
//@{
/**
* Return an array of ids. The ids are stored in the following order
* and the size of the array is provided as argument.
* [key, value, key, value, ...]
* The array is kept internaly using a std::vector
*/
vtkTypeUInt32* GetMappingArray(int& size);
protected:
vtkSMStateLoader();
~vtkSMStateLoader();
//@}
/**
* The rootElement must be the \c \<ServerManagerState/\> xml element.
* If rootElement is not a \c \<ServerManagerState/\> element, then we try to
* locate the first \c \<ServerManagerState/\> nested element and load that.
* Load the state from the given root element.
*/
virtual int LoadStateInternal(vtkPVXMLElement* rootElement);
/**
* Called after a new proxy is created. The main responsibility of this method
* is to ensure that proxy gets a GlobalId (either automatically or using the
* id from the state if LoadState() was called with \c keepOriginalId set to
* true). It also called vtkSMProxy::UpdateVTKObjects() and
* vtkSMProxy::UpdatePipelineInformation() (if applicable) to ensure that the
* state loaded on the proxy is "pushed" and any info properties updated.
* We also create a list to track the order in which proxies are created.
* This order is a dependency order too and hence helps us register proxies in
* order of dependencies.
*/
virtual void CreatedNewProxy(vtkTypeUInt32 id, vtkSMProxy* proxy) VTK_OVERRIDE;
/**
* Overridden so that when new views are to be created, we create views
* suitable for the connection.
*/
virtual vtkSMProxy* CreateProxy(
const char* xmlgroup, const char* xmlname, const char* subProxyName = NULL) VTK_OVERRIDE;
virtual int HandleProxyCollection(vtkPVXMLElement* collectionElement);
virtual void HandleCustomProxyDefinitions(vtkPVXMLElement* element);
int HandleLinks(vtkPVXMLElement* linksElement);
virtual int BuildProxyCollectionInformation(vtkPVXMLElement*);
//@{
/**
* This method scans through the internal data structure built
* during BuildProxyCollectionInformation() and registers the proxy.
* The DS keeps info
* about each proxy ID and the groups and names
* the proxy should be registered as (as indicated in the state file).
*/
virtual void RegisterProxy(vtkTypeUInt32 id, vtkSMProxy* proxy);
virtual void RegisterProxyInternal(const char* group, const char* name, vtkSMProxy* proxy);
//@}
/**
* Update a proxy's registration group and name before it gets registered.
* Default implementation handles helper group group names.
* Returns false to skip registering the proxy.
* @param[in,out] group proxy registration group
* @param[in,out] name proxy registration name
* @param[in] proxy proxy being registered
* @returns true to continue registering the proxy, false to skip registering it.
*/
virtual bool UpdateRegistrationInfo(std::string& group, std::string& name, vtkSMProxy* proxy);
/**
* Return the xml element for the state of the proxy with the given id.
* This is used by NewProxy() when the proxy with the given id
* is not located in the internal CreatedProxies map.
*/
virtual vtkPVXMLElement* LocateProxyElement(vtkTypeUInt32 id) VTK_OVERRIDE;
/**
* Used by LocateProxyElement(). Recursively tries to locate the
* proxy state element for the proxy.
*/
vtkPVXMLElement* LocateProxyElementInternal(vtkPVXMLElement* root, vtkTypeUInt32 id);
/**
* Checks the root element for version. If failed, return false.
*/
virtual bool VerifyXMLVersion(vtkPVXMLElement* rootElement);
/**
* Returns the first proxy already registered using any of the registration
* (group, name) assigned to the proxy with the given id in the state file.
*/
vtkSMProxy* LocateExistingProxyUsingRegistrationName(vtkTypeUInt32 id);
vtkPVXMLElement* ServerManagerStateElement;
vtkSMProxyLocator* ProxyLocator;
int KeepIdMapping;
private:
vtkSMStateLoader(const vtkSMStateLoader&) VTK_DELETE_FUNCTION;
void operator=(const vtkSMStateLoader&) VTK_DELETE_FUNCTION;
vtkSMStateLoaderInternals* Internal;
};
#endif
|