example_loadergpi.cpp

This is an example on how to create a loader plug-in using the new GPI object model.

00001 #include <ShapeUpAPI.h>
00002 
00003 SURESULT __cdecl HookFunc(SUHANDLE hWorkspace, int hookType, SUHookData *args);
00004 
00005 // Every plug-in needs an instance of SUExport called suapi
00006 SUExport suapi;
00007 
00008 size_t __cdecl fnVersion()
00009 {
00010     return SHAPEUP_API_VERSION;
00011 }
00012 
00013 const GUID* __cdecl fnGUID()
00014 {
00015     // CREATE YOUR OWN GUID !!
00016     // {97F4EA41-7D7E-42c1-B555-2D4C86C912A7}
00017     static const GUID guid = 
00018         { 0x97f4ea41, 0x7d7e, 0x42c1, { 0xb5, 0x55, 0x2d, 0x4c, 0x86, 0xc9, 0x12, 0xa7 } };
00019     return &guid;
00020 }
00021 
00022 SURESULT __cdecl fnInit(SUExport *pExport)
00023 {
00024     AFX_MANAGE_STATE(AfxGetStaticModuleState());
00025 
00026     pExport->import.pszName = "Test of GPI and ShapeUp API";
00027     pExport->import.pszDescription = "Test of GPI and ShapeUp API\nGPI Test";
00028     pExport->import.pszInfo = "Copyright (c) 2007";
00029     pExport->import.pszPluginVersion = "1.00";
00030 
00031     // Now keep the entire struct which is the actual ShapeUp API
00032     // (we need the function pointers later)
00033     ::memcpy(&suapi, pExport, sizeof(SUExport));
00034 
00035     // Set-up our hook callback
00036     pExport->import.pfnHook = HookFunc;
00037 
00038     // Add our load layer menu item
00039     ShapeUp_AddLoadLayerHook(0, "Example Loader", "A random point loader", NULL, NULL);
00040 
00041     return SURESULT_OK;
00042 }
00043 
00044 // ShapeUp will call this function when an event occurs
00045 SURESULT __cdecl HookFunc(SUHANDLE hWorkspace, int hookType, SUHookData *args)
00046 {
00047     AFX_MANAGE_STATE(AfxGetStaticModuleState());
00048 
00049     switch (hookType)
00050     {
00051     case HOOKTYPE_MENUITEM:
00052         // Only add stuff if we have an active workspace
00053         if (hWorkspace != NULL)
00054         {
00055             // args is really a SUMenuItemHookData*
00056 
00057             // TODO: Load data here
00058 
00059             SUWorkspace workspace(hWorkspace);
00060             SUTheme theme = workspace.CreateNewTheme(Shape_Point, "New Point layer");
00061 
00062             theme.AddAttribute(ATTRIBUTETYPE_STRING, "ObjectName", NULL);
00063 
00064             for (int i = 0; i < numberOfPoints; ++i)
00065             {
00066                 SUShape shape = theme.AddShape(shapeData[i]);
00067                 shape.SetAttribute(theme, 0, "A name");
00068             }
00069         }
00070         return SURESULT_OK;
00071     default:
00072         break;
00073     }
00074 
00075     return SURESULT_OK;
00076 }

Generated on Thu Apr 15 10:55:32 2010 for ShapeUp API by  doxygen 1.5.2