This section provides the necessary steps to create a project in Visual Studio which STK will recognize as a valid UI plugin.
Select the save Location for the project and click OK.
Add a reference to the library containing the AGI UI Plugins type definitions (AgUiPlugins.dll).
Add using directives for the three AGI.Ui namespaces, as well as the System.Runtime.InteropServices namespace (which promotes interaction with external type libraries):
[C#] |
---|
using AGI.Ui.Application; using AGI.Ui.Core; using AGI.Ui.Plugins; using System.Runtime.InteropServices; |
[Visual Basic .NET] |
---|
Imports AGI.Ui.Application Imports AGI.Ui.Core Imports AGI.Ui.Plugins Imports System.Runtime.InteropServices |
The GUID, ProgID, and ClassInterface attributes must be defined for the class.
The GUID is a Globally Unique IDentifier, used to uniquely identify your component in the Windows registry. On the Visual Studio Tools menu, use the Create GUID function to generate a new GUID for your plugin. If you are using Visual Studio Express Edition and do not see this option, click here.
The ProgID is a unique string used to identify your plugin to STK. AGI recommends a "MyCompanyName.MyPluginName" convention.
The ClassInterface defines whether the public methods and properties of class are exposed to COM clients. In most cases, the "None" class interface type will suffice. Use of the AgUtPlugin library requires the "AutoDispatch" type, as described in a later section.
The attribute definition will resemble this format:
[C#] |
---|
namespace MySampleUIPlugin { [Guid("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx")] [ProgId("MyCompany.MySampleUIPlugin")] [ClassInterface(ClassInterfaceType.None)] public class MySampleUIPlugin { ... |
[Visual Basic .NET] |
---|
<Guid("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"), _ ProgId("MyCompany.MySampleUIPlugin"), _ ClassInterface(ClassInterfaceType.None)> _ Public Class MySampleUIPlugin ... |
Ensure that the types in the assembly are visible and accessible to COM components. For this example, set the ComVisible attribute to true for the entire assembly (if desired, you can override for individual types and type members in the public class).
[C#] |
---|
[assembly: ComVisible(true)] |
[Visual Basic .NET] |
---|
<Assembly: ComVisible(True)> |
If you are using a COM UI plugin, your plugin must expose a COM object (a COM-callable wrapper for your application) so that the plugin can communicate with STK. There are two options for registering your COM UI plugin as a COM component: use Visual Studio settings to register at build, or use the command prompt to register your plugin. Either option requires administrative privileges on your machine.
To use the Visual Studio settings to register your plugin at build time:
Depending on your configuration, you might get a build error:
“Cannot register assembly "<filpath>\MySampleUIPlugin.dll" - access denied. Please make sure you're running the application as administrator. Access to the registry key 'HKEY_CLASSES_ROOT\MyCompany.MySampleUIPlugin' is denied.”
If you get this error:
The plugin only needs to be registered once, so you can turn off the Register for COM interop flag and run under normal user privileges for rest of the project.
If you are using a .NET UI plugin, you do not need to register it.
STK uses an XML manifest file to discover and load plugins at run-time. Using either Visual Studio or a text editor, create a new XML file. AGI recommends naming the XML file with the same name as your plugin (MySampleUiPlugin.xml). Below are examples of the required format for COM UI plugins and .NET UI plugins. Note that for COM UI plugins, the ProgID specified in the XML manifest must match the ProgID specified in the class attributes.
<?xml version = "1.0"?> <AGIRegistry version = "1.0"> <CategoryRegistry> <Category Name = "UiPlugins"> <UiPlugin ProgID = "MyCompany.MySampleUIPlugin" DisplayName = "MySampleUiPlugin"> </UiPlugin> </Category> </CategoryRegistry> </AGIRegistry>
<?xml version = "1.0"?> <AGIRegistry version = "1.0"> <CategoryRegistry> <Category Name = "UiPlugins"> <NETUiPlugin DisplayName="Rectangular Sensor UI Plugin (Examples)" TypeName="RectangularSensorPlugin.RectangularSensorPlugin" AssemblyName="RectangularSensorPlugin, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" CodeBase="C:\ProgramData\DeveloperKit\CodeSamples\Extend\Ui.Plugins\CSharp\RectangularSensorPlugin\RectangularSensorPlugin\bin\Debug"> </NETUiPlugin> </Category> </CategoryRegistry> </AGIRegistry>
This XML file must be saved in one of these three locations, where STK will see it:
STK User Config Plugins directory (usually My Documents\STK 11\Config\Plugins)
Plugins registered here will be available only to the single user with access to this My Documents folder. Usually does not require administrative privileges.
All Users Application folder (C:\ProgramData\AGI\STK 11\Plugins on Windows 7 and Vista, or C:\Documents and Settings\All Users\Application Data\AGI\STK 11\Plugins on Windows XP)
Plugins registered here will be available to all STK users on this machine. Usually does not require administrative privileges.
STK install directory (usually C:\Program Files (x86)\AGI\STK 11\Plugins)
Plugins registered here will be available to all STK users on this machine. Usually requires administrative privileges to save/modify files here.
For more detailed information and additional options for creating the XML manifest, refer to the Registration with a Plugin Point (i.e. Category registration) help topic.
The next step is to change the class to implement the IAgUiPlugin interface.
[C#] |
---|
private IAgUiPluginSite m_psite; |
[Visual Basic .NET] |
---|
Dim m_psite As IAgUiPluginSite |
[C#] |
---|
public class MySampleUIPlugin: IAgUiPlugin |
[Visual Basic .NET] |
---|
Public Class MySampleUIPlugin Implements IAgUiPlugin |
This will implement the IAgUiPlugin interface, exposing its members.
[C#] |
---|
public void OnStartup (IAgUiPluginSite PluginSite) { m_psite = PluginSite; } |
[Visual Basic .NET] |
---|
Public Sub OnStartup(PluginSite As AGI.Ui.Plugins.IAgUiPluginSite) Implements AGI.Ui.Plugins.IAgUiPlugin.OnStartup m_psite = PluginSite End Sub |
[C#] |
---|
public void OnShutdown () { m_psite = null; } |
[Visual Basic .NET] |
---|
Public Sub OnShutdown() Implements AGI.Ui.Plugins.IAgUiPlugin.OnShutDown m_psite = Nothing End Sub |
The OnInitializeToolbar and OnDisplayContextMenu methods are addressed in the topic Add a Toolbar Button or Menu Item. The OnDisplayConfigPage method is addressed in the topic Add a Custom Config Page.
The Active flag is enabled when a valid UI plugin is running. If the "Active" flag is not enabled, open the STK Message Viewer and look for any related error messages. Check that:
|
STK Programming Interface 11.0.1