12.15 Plug-in Software Development Kit (SDK)

The plug-in system is supported only by VEGA ZZ. A plug-in is a DLL that must be placed in the Plugin directory and it's loaded automatically when VEGA ZZ starts. This DLL must have three exported functions:

 

VGP_EXTERN VGP_PLUGINFO * VGP_EXPORT Init(VGP_VEGAINFO *);
VGP_EXTERN VG_BOOL VGP_EXPORT Free(void);
VGP_EXTERN VG_BOOL VGP_EXPORT Call(VG_UWORD, void *);

 

All definitions, constants and macros are included in plugin.h header file.

 

12.15.1 Function description

VGP_EXTERN VGP_PLUGINFO * VGP_EXPORT Init(VGP_VEGAINFO *)

 

It's the first function that VEGA ZZ calls to initialize the plug-in. It must contain the initialization code for the plug-in. VEGA ZZ passes the pointer to VGP_VEGAINFO structure in which are present some useful information:

typedef struct {
  VG_UWORD      Version;            /* VEGA version                             */
  VG_UWORD      Release;            /* VEGA release                             */
  VG_ULONG      *GlobErr;           /* Pointer to global error variable         */
  char          *ErrStr;            /* Pointer to error string                  */
  ATOMO         **BegAtm;           /* Pointer to the pointer of the atom list  */
  ATOMO         **LastAtm;          /* Pointer to the pointer to the last atom  */
  VG_ULONG      *TotalAtm;          /* Pointer to the number of atoms variable  */
  VG_SURFACE    **BegSrf;           /* Pointer to the ponter of the surf. list  */
  char          *Result;            /* Pointer to the result string             */
  void          *Custom;            /* For custom plug-in (don't use it !)      */
  void          *Res1;              /* Reserved pointer (don't use it !)        */
  void          *Res2;              /* Reserved pointer (don't use it !)        */
  HDC           hDC;                /* Device context of the main window        */
  HGLRC         hRC;                /* Rendering context of the main window     */
  HMENU         hMenu;              /* Handle of the main menu                  */
  HMENU         hPopUpMenu;         /* Handle of the popup menu                 */
  HWND          hWnd;               /* Handle of the main window                */
  char          IniFile[MAX_PATH];  /* Plug-in .ini file with full path         */
  char          PrgPath[MAX_PATH];  /* Program path \ terminated                */
} VGP_VEGAINFO;

You must remember that this structure is read-only and the reserved pointers are for future uses.
The user-defined plug-in must return the pointer to VGP_PLUGINFO structure that VEGA ZZ manage it without writing anything.

typedef struct {
  VG_UWORD      Version;            /* Plug-in version                          */
  VG_UWORD      Release;            /* Plug-in release                          */
  VG_UWORD      VegaVer;            /* Minimum VEGA version required            */
  VG_UWORD      VegaRel;            /* Minimum VEGA release required            */
  VG_UWORD      Type;               /* Plug-in type                             */
  char          *Name;              /* Plug-in name                             */
  char          *Copyright;         /* Copyright message                        */
  VGP_FUNC      *FuncList;          /* List of the functions                    */
} VGP_PLUGINFO;

In this structure you can specify the version and the release of the plug-in, the minimum required version and release of VEGA ZZ (VegaVer and VegaRel), the plug-in type (Type),  the plug-in name (Name), the copyright message (Copyright) and the exported function list (FuncList). The plug-in type can be:

 

Value Constant name Description
0 VGP_TYPE_GENERIC Generic plug-in
1 VGP_TYPE_CALC Calculation plug-in
2 VGP_TYPE_CONSOLE Console plug-in
3 VGP_TYPE_RENDER Rendering plug-in
4 VGP_TYPE_CUSTOM Custom plug-in (for internal use only)

 

At the present time, only the VGP_TYPE_GENERIC is available for the user.

FuncList is a vector in which is included the entry for each user-defined function that VEGA ZZ can call.

typedef struct {
  char          *MenuItem;          /* Menu item string                         */
  VG_UWORD      MenuPos;            /* Menu item to call the plug-in function   */
  HBITMAP       MenuBmp;            /* 16x16 bitmap handle for menu icon        */
  VG_BOOL       MenuEnabled;        /* Set to TRUE to enable from the beginning */
  VG_ULONG      MenuAct;            /* Menu activation                          */
  VG_UWORD      Function;           /* Function code                            */
} VGP_FUNC;

MenuItem is the pointer to the string that is shown in the main menu that can be used to activate the specific function. VEGA ZZ calls Call function using Function as argument. Function is the function code associated to the menu item. The reserved function codes are:

 

Value Constant name Description
0 VGP_FUNC_NONE None
1 VGP_FUNC_ABOUT About function (called when you press the About button in the plug-in manager).
2 VGP_FUNC_CONFIG Configure function (called when you press the Configure button in the plug-in manager).
3 VGP_FUNC_HELP Help function (called when you press the Help button in the plug-in manager).

 

The user functions must have a function code greater than 100 (e.g. 101, 102, etc) and no limits are present about the number of them.

MenuPos is the code that you can use to set the menu in which the item will be shown. The vertical position is selected by VEGA ZZ at the end of the standard menu item. The following tables shows the MenuPos values:

 

Value Constant name Menu name
0 VGP_MPOS_NONE Invisible menu item
1 VGP_MPOS_EDIT Edit
2 VGP_MPOS_VIEW View
3 VGP_MPOS_CALC Calculate
4 VGP_MPOS_TOOLS Tools
5 VGP_MPOS_HELP Help
6 VGP_MPOS_POPUP Popup
7 VGP_MPOS_PLUGCFG Plug-in configuration submenu
8 VGP_MPOS_FILEOPEN File (open) menu
9 VGP_MPOS_FILESAVE File (save) menu
10 VGP_MPOS_BIOTOOLS Bioinformatics
11 VGP_MPOS_COLOR Color submenu
12 VGP_MPOS_DISPLAY Display submenu
13 VGP_MPOS_PROTCHK Protein check submenu

 

MenuBmp is the handle of the 16x16 bitmap that is shown at the left of the item in the menu. If NULL, no bitmap is shown. A good idea is to store the bitmap in the resources of the DLL.
 

Example:

In the .rc file:

MMPIC_USER01 BITMAP "icon_16.bmp"
...

The initialization  code can be:

VGP_FUNC FuncList[] = {
  {"My function", VGP_MPOS_TOOLS, NULL, TRUE , VGP_CM_ALL , VGP_FUNC_USER_01},
  /**** Don't delete the last line ****/
  {NULL            , VGP_MPOS_NONE   , NULL, FALSE, VGP_CM_NONE, VGP_FUNC_NONE   }
};
...
PlugInfo.FuncList[1].MenuBmp = LoadBitmap(GetModuleHandle("MyPlugin.dll"),
                                          MAKEINTRESOURCE(MMPIC_USER01));
...

If MenuEnabled is TRUE (0),  the menu item is already enabled when VEGA starts. If it's FALSE (0), the item is disabled. The activation can be changed trough MenuAct variable. The following table shows the activation conditions:

 

Value Constant name Condition
0 VGP_CM_NONE Never
1 VGP_CM_NEW The New command is executed
2 VGP_CM_MOLE The molecule is loaded
4 VGP_CM_DEMO The demo mode is activated
8 VGP_CM_CALC A calculation is performed
16 VGP_CM_SURF A surface is loaded
32 VGP_CM_TRJA The trajectory analysis is started
64 VGP_CM_PKMS Measure picking
128 VGP_CM_NOEDIT No molecule edit
256 VGP_CM_SAVETRJ Trajectory saving
512 VGP_CM_MANUAL Manual control

 

You can combine more than one condition using the or operator (e.g. VGP_CM_NEW|VGP_CM_MOLE). If you want the item always enable, use the special VGP_CM_ALL constant.

 

IMPORTANT:
You must remember to end the VGP_FUNC array  with a null item, because it's used by VEGA ZZ to detect the last item.

 

 

VGP_EXTERN VG_BOOL VGP_EXPORT Free(void)

 

This function is called by VEGA to release all resources when the program is closing. In this subroutine you can include all code to free the resources that are used by your plug-in.

 

 

VGP_EXTERN VG_BOOL VGP_EXPORT Call(VG_UWORD, void *)

 

It's the core of the plug-in because this function select the  code associated with a specific menu item. When you select a plug-in menu item or press a button in the plug-in manager, VEGA ZZ calls this subroutine passing the function code and a void pointer that is reserved for future uses. A generic Call() function could be:

/**** Generic Call function ****/

VGP_EXTERN VG_BOOL VGP_EXPORT Call(VG_UWORD Func, void *Arg)
{
  switch(Func) {

  case VGP_FUNC_ABOUT:          /* About the plug-in           */
    printf("About\n");
    break;

  case VGP_FUNC_CONFIG:         /* Configure the plug-in       */
    printf("Configuration\n");
    break;

  case VGP_FUNC_HELP:           /* Show the help               */
    printf("Help\n");
    break;

  case VGP_FUNC_USER_01:        /* Activate the first function */
    printf("Function 1 activated\n");
    break;

  /**** If needed, you can insert other cases ****/

  } /* End of switch */

  return TRUE;
}

The Call() function should return a value: TRUE (1) if it's executed without errors, FALSE (0) if an error occurs.

 

12.15.2 How to read/write the atom list

VEGA ZZ stores the atom information in a memory list. Each atom has a its memory space allocated by calloc().  The end signal of the list is a null pointer to next atom structure. In the VGP_VEGAINFO structure you can find the pointer to the pointer to the first element in the atom list (**BegAtm), the pointer to the pointer to the last element (**LastAtm) and the pointer to the total number of atoms in memory (*TotalAtm).
This is a simple code to read the atom list:

VGP_VEGAINFO *VgInfo;    /* Initialized by Init() */
void MyReadAtm(void)
{
  ATOMO    *Atm;
  for(Atm = *VgInfo -> BegAtm; Atm; Atm = Atm -> Ptr) {

    /* Print the atom name and the coordinates */

    printf("%4.4s %f %f %f\n", Atm -> Name.C, Atm -> x, Atm -> y, Atm -> z);
  }
}

For more information about the ATOMO structure, see vgtypes.h header file.

 

12.15.3 How VEGA ZZ can be controlled by a plug-in

VEGA ZZ can be controlled by a plug-in using the standard windows messaging system. You can use this simple subroutine:

VGP_VEGAINFO *VgInfo;    /* Initialized by Init() */
/**** Send a VEGA command ****/

VG_ULONG SendVegaCmd(char *Com)
{
  COPYDATASTRUCT        Cds;

  Cds.dwData = 0;
  Cds.lpData = (void*)Com;
  Cds.cbData = strlen(Com) + 1;

  return SendMessage(VgInfo -> hWnd, WM_COPYDATA, NULL, (LPARAM)&Cds);
}

The argument is the string of the command to send to VEGA ZZ. If the command fails, the function return the global error code, otherwise return 0. If the sent command returns a value, you can read it trough the Result string pointer in VGP_VEGAINFO structure.

 

12.15.6 Saving/loading the plug-in configuration

As convention, the plug-in configuration should be loaded and saved in ...\VEGA ZZ\Config\Plugins.ini file. To manage this file, use GetPrivateProfileString() and WritePrivateProfileString() API functions. 

 

12.15.7 The null plug-in

This is a simple example of a plug-in that performs anything but is useful as skeleton to build your plug-in.


/*******************************************
****         VEGA Plug-in System        ****
****              Main code             ****
**** (c) 2002-2012, Alessandro Pedretti ****
*******************************************/


#include "..\plugin.h"

/**** Global variables ****/

VGP_VEGAINFO    *VgInfo;

/**** Description of the functions ****/
/**** All items are optional       ****/

VGP_FUNC FuncList[] = {
  {NULL          , VGP_MPOS_NONE   , NULL, TRUE , VGP_CM_NONE, VGP_FUNC_ABOUT  },
  {"Null Config.", VGP_MPOS_PLUGCFG, NULL, TRUE , VGP_CM_ALL , VGP_FUNC_CONFIG },
  {"Null Help"   , VGP_MPOS_HELP   , NULL, TRUE , VGP_CM_ALL , VGP_FUNC_HELP   },
  {"Start Null"  , VGP_MPOS_EDIT   , NULL, FALSE, VGP_CM_MOLE, VGP_FUNC_USER_01},

  /**** Don't delete the last line ****/

  {NULL          , VGP_MPOS_NONE   , NULL, FALSE, VGP_CM_NONE, VGP_FUNC_NONE   }
};

/**** Plug-in info structure ****/

VGP_PLUGINFO PlugInfo = {
  1,                            /* Plug-in version                         */
  0,                            /* Plug-in release                         */
  1,                            /* Minimum VEGA version required           */
  4,                            /* Minimum VEGA release required           */

  VGP_TYPE_GENERIC,             /* Plug-in type                            */
  "Null",                       /* Plug-in name                            */
  "Alessandro Pedretti",        /* Copyright message                       */
  FuncList                      /* List of the functions                   */
};


/**** Plug-in initialization ****/

VGP_EXTERN VGP_PLUGINFO * VGP_EXPORT Init(VGP_VEGAINFO *VegaInfo)
{
  VgInfo = VegaInfo;

  /* Enter here your initialization code */
  /* if needed.                          */

  printf("Null: Initialization\n");

  return &PlugInfo;
}


/**** Execute the plug-in function ****/

VGP_EXTERN VG_BOOL VGP_EXPORT Call(VG_UWORD Func, void *Arg)
{
  switch(Func) {

  case VGP_FUNC_ABOUT:          /* About the plug-in           */
    printf("Null: About\n");
    break;

  case VGP_FUNC_CONFIG:         /* Configure the plug-in       */
    printf("Null: Configuration\n");
    break;

  case VGP_FUNC_HELP:           /* Show the help               */
    printf("Null: Help\n");
    break;

  case VGP_FUNC_USER_01:        /* Activate the first function */
    printf("Null: Activated\n");
    break;
  } /* End of switch */

  return TRUE;
}


/**** Deallocate the resources ****/

VGP_EXTERN VG_BOOL VGP_EXPORT Free(void)
{
  printf("Null: Release all resources\n");

  return TRUE;
}

You can find a more complex example in Dhrystone plug-in source code, included in the SDK.