E.g. if a plug-in draws extra data on top of the map, the settings for how this is drawn can be stored in the workspace file and reused when that workspace is reopened.
{ struct MyData { int version; double precision; } data; const char *string_data = "Some data"; // Store data on workspace level SUWorkspace workspace(hWorkspace); workspace.SetSerialData(sizeof(MyData), &data); // Store data on theme level SUTheme theme(hTheme); theme.SetSerialData(strlen(string_data) + 1, string_data); }
In order to reserialize data stored, a hook funktion needs to be used, ShapeUp_AddDeserializeHook(), which enables a call to the GPI hook function when a loading operation occurrs.
A sample of the deserialize hook functionality might look like:
SURESULT __cdecl fnInit(SUExport *pExport) { ... // Set hook function pExport->import.pfnHook = MyHookFunc; // Set-up our loading hook ShapeUp_AddDeserializeHook(0); ... } SURESULT __cdecl MyHookFunc(SUHANDLE hWorkspace, int hookType, SUHookData *args) { switch (hookType) { case HOOKTYPE_DESERIALIZE: { // args is really a pointer to a SUDeserializeHookData struct SUDeserializeHookData *data = (SUDeserializeHookData*) args; // If data->hTheme == NULL we are loading a workspace, otherwise // we are loading the theme pointed to by data->hTheme if (data->hTheme == NULL) LoadWorkspaceData(hWorkspace, data); else LoadThemeData(hWorkspace, data); } break; default: break; } return SURESULT_OK; }