Net Customisation User Guide
Net Customisation User Guide
NET Customisation
User Guide
AVEVA Solutions Ltd
Disclaimer
Information of a technical nature, and particulars of the product and its use, is given by AVEVA
Solutions Ltd and its subsidiaries without warranty. AVEVA Solutions Ltd and its subsidiaries disclaim
any and all warranties and conditions, expressed or implied, to the fullest extent permitted by law.
Neither the author nor AVEVA Solutions Ltd, or any of its subsidiaries, shall be liable to any person or
entity for any actions, claims, loss or damage arising from the use or possession of any information,
particulars, or errors in this publication, or any incorrect use of the product, whatsoever.
Copyright
Copyright and all other intellectual property rights in this manual and the associated software, and every
part of it (including source code, object code, any data contained in it, the manual and any other
documentation supplied with it) belongs to AVEVA Solutions Ltd or its subsidiaries.
All other rights are reserved to AVEVA Solutions Ltd and its subsidiaries. The information contained in
this document is commercially sensitive, and shall not be copied, reproduced, stored in a retrieval
system, or transmitted without the prior written permission of AVEVA Solutions Ltd Where such
permission is granted, it expressly requires that this Disclaimer and Copyright notice is prominently
displayed at the beginning of every copy that is made.
The manual and associated documentation may not be adapted, reproduced, or copied, in any material
or electronic form, without the prior written permission of AVEVA Solutions Ltd. The user may also not
reverse engineer, decompile, copy, or adapt the associated software. Neither the whole, nor part of the
product described in this publication may be incorporated into any third-party software, product,
machine, or system without the prior written permission of AVEVA Solutions Ltd, save as permitted by
law. Any such unauthorised action is strictly prohibited, and may give rise to civil liabilities and criminal
prosecution.
The AVEVA products described in this guide are to be installed and operated strictly in accordance with
the terms and conditions of the respective licence agreements, and in accordance with the relevant
User Documentation. Unauthorised or unlicensed use of the product is strictly prohibited.
AVEVA Solutions Ltd, High Cross, Madingley Road, Cambridge, CB3 0HB, United Kingdom
Trademarks
AVEVA and Tribon are registered trademarks of AVEVA Solutions Ltd or its subsidiaries. Unauthorised
use of the AVEVA or Tribon trademarks is strictly forbidden.
AVEVA product names are trademarks or registered trademarks of AVEVA Solutions Ltd or its
subsidiaries, registered in the UK, Europe and other countries (worldwide).
The copyright, trade mark rights, or other intellectual property rights in any other product, its name or
logo belongs to its respective owner.
.NET Customisation User Guide
Contents Page
.NET Customisation
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1:1
About this Guide . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1:1
.NET Customisation Architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1:1
Common Application Framework Interfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1:2
Database Interfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1:2
Geometry Interfaces. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1:3
Shared Interfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1:3
Utilities Interfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1:4
Graphics Interfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1:4
Sample Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1:4
AttributeBrowserAddin . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1:4
ExamplesAddin . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1:4
NetGridExample . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1:4
PMLNetExample . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1:4
PMLGridExample . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1:5
Reference Documentation. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1:5
Compatibility with future versions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1:5
i 12.0
.NET Customisation User Guide
ii 12.0
.NET Customisation User Guide
iii 12.0
.NET Customisation User Guide
PMLNet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5:1
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5:1
Design Details . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5:1
Using PMLNet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5:1
Limitations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5:2
Object Names . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5:3
Query Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5:3
Global Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5:4
Method Arguments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5:4
Method Overloading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5:5
Custom Attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5:5
Private Data and Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5:6
Scope ............................................................................ 5:6
Instantiation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5:7
ToString() Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5:7
Method Names . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5:7
Double Precision . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5:7
Events ............................................................................ 5:7
Error Handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5:8
Rules for Calling .NET . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5:8
Tracing ............................................................................ 5:9
.NET Controls. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5:9
Creating a Container . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5:9
Hosting .NET Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5:10
Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5:10
Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5:10
PMLGridExample . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5:10
PMLNetExample . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5:10
iv 12.0
.NET Customisation User Guide
Introduction
1 Introduction
The above diagram illustrates the two new methods of customisation using .NET
technology. The first is via the concept of a .NET Addin and the second using PML.NET.
Both methods provide a mechanism whereby a .NET assembly (dll) can be dynamically
loaded into a module at runtime.
1:1 12.0
.NET Customisation User Guide
Introduction
Namespace: Aveva.ApplicationFramework
• AddinManager: This class provides properties and methods for the management of
ApplicationFramework Addins.
• ServiceManager: This class defines an interface which provides a means by which the
various components of the ApplicationFramework can publish their services. The
ServiceManager also acts as a service provider responding to requests for services. It
can also be used by applications and application addins to publish additional services.
• SettingsManager: This class provides properties and methods for the management of
application settings which are stored in settings groups which are persisted between
sessions.
Namespace: Aveva.ApplicationFramework.Presentation
• CommandBarManager: This provides access to the menus and commandbars of a
CAF based application. It also has methods to load the definition of menus and
commandbars from User Interface customisation (UIC) files.
• CommandManager: This class defines an interface to provide the presentation
framework client with a mechanism for the management of command objects which
can be associated with Tools or other User interface objects. The action of invoking a
tool (e.g clicking a ButtonTool) will cause the execution of the associated command
object. It is possible to associated the same command object with a number of different
user interface objects (e.g. ButtonTool on a Menu and a LinkLabel) thereby allowing for
the centralisation of these user interface objects action within a command. Various
state-like properties of a command (e.g. enabled/checked) would also be reflected in all
user interface objects associated with a command. For example, disabling a command
would cause all associated user interface objects to be disabled. User interface objects
are associated with a command via a CommandExecutor derived class.
• ResourceManager: This class defines an interface to provide Addins with a simplified
mechanism to access localizable resources.The ResourceManager provides a number
of methods which allows an addin to then access the various types of resources (string,
image, cursor, icon etc.) which resource files may contain.
• WindowManager: This provides access to the main application window, the StatusBar
and a collection of MDI and docked windows. It also provides the addin writer with
methods to create MDI and docked windows to host user controls.
Namespace: Aveva.Pdms.Database
• DatabaseService: The sole purpose of this class is to open a project.
1:2 12.0
.NET Customisation User Guide
Introduction
1:3 12.0
.NET Customisation User Guide
Introduction
1.3.1 AttributeBrowserAddin
A zip file (Samples.zip) containing the samples can be found in the installation directory.
This example project creates an addin which implements a very simple database element
attribute browser. It also illustrates the implementation of a command object to control the
visibility of the docked window created by the addin.
1.3.2 ExamplesAddin
A zip file (Samples.zip) containing the samples can be found in the installation directory.
.NET API Examples can be found in the ExamplesAddin project below the Samples
directory. This is a C# addin which adds a ComboBoxTool on a Toolbar to the main menu.
Each entry in the list runs a particular example. This can be loaded by adding the
ExamplesAddin to the applications addin config file. Since these examples create and claim
Design elements they need to be run in a Design multi-write database. There is an example
config file in the ExamplesAddin directory.
1.3.3 NetGridExample
A zip file (Samples.zip) containing the samples can be found in the installation directory. An
example of a .NET C# addin containing an AVEVA Grid Control.
1.3.4 PMLNetExample
A zip file (Samples.zip) containing the samples can be found in the installation directory. An
example of a .NET class that has been made PML callable.
1:4 12.0
.NET Customisation User Guide
Introduction
1.3.5 PMLGridExample
A zip file (Samples.zip) containing the samples can be found in the installation directory. An
example of an AVEVA Grid Control hosted on a PML form.
1:5 12.0
.NET Customisation User Guide
Introduction
1:6 12.0
.NET Customisation User Guide
How to Write an Addin
The diagram in Figure 2 illustrates the main steps needed to create a .NET addin and
configure a CAF based module to load the new addin. The following sections detail these
various steps beginning with the writing of a .NET assembly which implements your addin.
2:1 12.0
.NET Customisation User Guide
How to Write an Addin
What distinguishes an addin from any other .NET assembly is that an addin must contain a
class which implements the IAddin interface. When the CAF loads and starts an addin it
interrogates the assembly for the class which implements this interface, creates an instance
of this class and calls the IAddin.Start method.
The following code is a simple example of a class which implements the IAddin interface.
This is the AttributeBrowserAddin.cs file which is part of the AttributeBrowserAddin sample
project which can be found in the samples directory. The Start method performs the
initialization of the Addin.
using System;
using System.Collections.Generic;
using System.Text;
// Add additional using statements
using Aveva.ApplicationFramework;
using Aveva.ApplicationFramework.Presentation;
namespace Aveva.Presentation.AttributeBrowserAddin
{
public class AttributeBrowserAddin : IAddin
{
#region IAddin Members
2:2 12.0
.NET Customisation User Guide
How to Write an Addin
#endregion
}
}
Figure 2:2. AttributeBrowserAddin Sample - AttributeBrowserAddin.cs
The above code shows the use of the ServiceManager.GetService method to retrieve the
WindowManager service and the use of the CreateDockedWindow method to create a
docked window to host the AttributeListControl. The first argument, Key, to the
CreateDockedWindow method needs to be a unique window identifier. To help avoid
clashes between docked windows created by addins running within the same application
then it is recommended to adopt the <CompanyName>.<AddinName>.<WindowName>
naming convention for this property.
An MDI window can be created via use of the WindowManager.CreateMdiWindow method.
As illustrated in this example, an important step when creating docked windows is the
correct setting of the SaveLayout property. This property controls whether information about
2:3 12.0
.NET Customisation User Guide
How to Write an Addin
the layout and docking position is saved between application sessions. The code defines
the default docking position as DockedPosition.Right, but the user can interactively change
this and the persistence of this user preference between sessions is desirable. One aspect
of the saving (serialisation) and restoring (de-serialisation) of this layout data is that this only
works if only those docked windows for which there is layout information are present when
the layout data is de-serialized. Therefore it is important that any docked window created
during addin startup has this property set to true. If there is a mismatch between the number
of docked windows in existence when the layout data is de-serialized then you will get one
of the following warning message then the application starts up:
Warning: Loading Window Layout - Missing DockedWindow:
Aveva.AttributeBrowserWarning: Failed to restore docked
window layout
Warning: Loading Window Layout - Extra DockedWindow:
Aveva.AttributeBrowserWarning: Failed to restore docked
window layout
You should only see these warnings when either adding or removing an addin from a
module.
• IWindow Interface
The DockedWindow and MdiWindow both implement the IWindow interface which has the
following methods and properties:
void Hide() - Conceals the window from the user.
void Show() - Displays the window to the user.
void Float() - Displays the window as a floating window.
void Dock() - Docks the window within the main window.
void Close() - Destroys the window removing it from the windows collection.
System.Windows.Forms.Control Control - Gets the control displayed in the window.
bool Enabled - Gets or sets whether the window is enabled.
bool Floatable - Gets or sets whether the window is floatable.
int Height - Gets or sets the height of the window.
bool IsFloating - Gets the floating state of a window.
string Key - Gets the Key of the window in the WindowsCollection.
string Title - Gets or sets the title/caption of the window.
bool Visible - Gets or sets the visible state of the window.
int Width - Gets or sets the width of the window.
Size MaximumSize - Get or sets the maximum size of the window.
Size MinimumSize - Get or sets the minimum size of the window.
• Window Events
The Docked and MDI Windows also support a number of events such as Closed, Activated,
Deactivated, Resized.
2:4 12.0
.NET Customisation User Guide
How to Write an Addin
• WindowManager Events
The window manager also supports two events:
event System.EventHandler WindowLayoutLoaded - Occurs at startup just after the
window layout has been loaded. This event can be used to update the state of commands
which are being used to manage the visibility of a docked window. (see the
ShowAttributeBrowserCommand.cs in the AttributeBrowserAddin sample)
event WindowEventHandler WindowAdded - Occurs when a new docked or MDI window
is created.
• The StatusBar
The CAF also provides the addin writer with an interface to the StatusBar located at be
bottom of the main application window.
2:5 12.0
.NET Customisation User Guide
How to Write an Addin
Figure 2:4. : Code to create a StatusBar Panel containing the project name.
The StatusBarTextPanel object has a number of properties which control its content and
behaviour. It also supports PanelClick and PanelDoubleClick events. For details of these
please refer to the reference help file.
2:6 12.0
.NET Customisation User Guide
How to Write an Addin
constructor for a Command class should set the base class Key property which is used to
reference the command from within a UIC file.
The Command base class has the following methods and properties which can be
overridden by a derived Command class.
void Execute() : This method must be overridden to provide the command execution
functionality.
CommandState GetState() : This method is called by the CAF to update the state of the
contents of a context menu. The returned value is a CommandState enumeration for
various states of a command. This enumeration can be treated as a bit field; that is, a set of
flags. Bit fields can be combined using a bitwise OR operation. The command state is then
reflected by the user interface.
String Description : A description for the command.
void Refresh(string context) : This method will be called whenever the
CommandManager.ApplicationContext property is changed. This gives the command
the opportunity to update its Enabled or Visible state in response to this context change.
This command state change would then be reflected in the user interface.
The Command base class also has a number of properties which are use to update the
command state following user interface changes or vice-versa.
bool Checked: If associated with a user interface entity such as a StateButtonTool then this
property and the corresponding state of the user interface entity are kept synchronised.
bool Enabled: Changes to this property are reflected in all associated user interface
entities.
ArrayList List: This property allows a command to communicate a list of string values to
the user interface. This can be used when a command is associated with for example a
ComboBoxTool.
int SelectedIndex: This property is updated to indicate which item from a list has been
selected by the user.
object Value: This property holds the currently value of an associated user interface entity.
bool ValueChanged: Before calling the execute method the CAF sets this property if the
value of the user interface entity has changed. The flag is cleared when execution has
finished.
bool Visible: Changes to this property are reflected in all associated user interface entities.
Registering a command with the CAF is done by adding an instance of a command class to
the CommandManagers.Commands collection.
ShowAttributeBrowserCommand showCommand = new
ShowAttributeBrowserCommand(attributeListWindow);
commandManager.Commands.Add(showCommand);
using System;
using System.Collections.Generic;
using System.Text;
using Aveva.ApplicationFramework.Presentation;
namespace Aveva.Presentation.AttributeBrowserAddin
{
/// <summary>
2:7 12.0
.NET Customisation User Guide
How to Write an Addin
2:8 12.0
.NET Customisation User Guide
How to Write an Addin
2:9 12.0
.NET Customisation User Guide
How to Write an Addin
the application executable. It has a filename of the form <Module Name>Addins.xml. For
example the AVEVA PDMS module Design has a file called DesignAddins.xml. The content
of this file is reproduced below. By default the addins are also expected to be in the same
directory as the application executable. You can however specify the full path to the addin
assembly including the use of UNC pathnames. If during addin development you do not
wish to modify the addin configuration file in the install directory (this is particularly likely to
be the case if you are using a server based installation) then the default location of the addin
configuration file can be overridden using the environment variable CAF_ADDINS_PATH.
You can then edit a copy of the file and point this environment variable at the directory you
copy it to.
<?xml version="1.0" encoding="utf-8"?>
<ArrayOfString xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<string>ExplorerAddin</string>
<string>DrawListAddin</string>
<string>MyDataAddin</string>
<string>HistoryAddin</string>
<string>ReferenceListAddin</string>
<string>PipeCheckAddin</string>
<string>OutputAddin</string>
<string>FindAddin</string>
<string>AttributesAddin</string>
<string>C:\Documents and Settings\User1\My Documents\Visual Studio
2005\AttributeBrowserAddin\AttributeBrowserAddin\bin\Debug\Attribute-
BrowserAddin</string>
</ArrayOfString>
2:10 12.0
.NET Customisation User Guide
Menu and Command Bar Customisation
User access to functionality provided via an addin is normally provided through the use of
menus and/or tools on a commandbar. Reference was made earlier, in the section about
addin commands, that the CAF provides a mechanism to allow the menus and
commandbars for an application to be defined in a "User Interface Customisation" (UIC) file.
This section provides details of how a CAF based application can be configured to load a
UIC file, and how the UIC file can be edited using the applications interactive user interface
customisation tool.
3:1 12.0
.NET Customisation User Guide
Menu and Command Bar Customisation
As well as adding to the customisation configuration file an addin can also load a UIC file
directly using the AddUICustomisationFile method of the CommandBarManager.
// Load a UIC file for the AttributeBrowser.
CommandBarManager commandBarManager = (CommandBarManager)serviceM-
anager.GetService(typeof(CommandBarManager));
commandBarManager.AddUICustomizationFile("AttributeBrowser.uic",
"AttributeBrowser");
This UIC file will be loaded before those define in the Customisation configuration file, so it
must create its own menu or commandbar to host its tools.
3:2 12.0
.NET Customisation User Guide
Menu and Command Bar Customisation
3:3 12.0
.NET Customisation User Guide
Menu and Command Bar Customisation
Any number of levels of customisation file can be defined either using the module
customisation configuration file or the CommandBarManager.
AddUICustomizationFile() method, and they are layered on-top of each other in the
order they appear in the list. Selecting an entry in the list will update the tree view (3) and
listview (4) with all configuration information defined in the selected file and those above it.
Any items in the tree or listview which are not defined in the currently active customisation
file are displayed with an italic font in grey. Any customisation file which a user does not
have write access to does not appear in the drop-down list, but its contents are included in
the tree and list of tools.
Here the Button "Save" is defined in the "ConnectionMap" customisation file. It is displayed
in italics along with the "Schematic Model Viewer" Command Bar since these items are not
defined in the currently selected customisation file.
The selected customisation file will also be made the active customisation file and any edits
will only be possible to customisation information defined in this file.
The tree is populated with a representation of the Active Customisation file: CommandBars
and their contents: Menubars and their entries and Context Menus defined in each of the
3:4 12.0
.NET Customisation User Guide
Menu and Command Bar Customisation
configuration files above and including the currently selected file. It also contains a list of the
currently loaded resource files. The Tree View supports the following user interactions:
The context menu for the CommandBars Node contains the following operations:
New Command Bar - Creates a new CommandBar with unique default name
(CommandBar<N>).
The context menu for a CommandBar node contains the following operations:
Delete - Delete the CommandBar. If the CommandBar contains tools then a
confirmation MessageBox is displayed.
3:5 12.0
.NET Customisation User Guide
Menu and Command Bar Customisation
The context menu for the MenuBar node contains the following operations:
New Menu - Creates a new MenuTool with a unique default name (Menu<N>).
The context menu for the Context Menus node contains the following operations:
New Menu - Creates a new MenuTool with a unique default name (Menu<N>).
The context menu for a Tool node contains the following operations:
First in group - Marks the tool instance as being the first in a group. It then gets a
separator drawn above it.
Delete - Removes the tool instance from the MenuTool or CommandBar.
The list is populated with each of the tools defined in each of the configuration files above
and including the currently selected file.
The list supports the following user interactions:
3:6 12.0
.NET Customisation User Guide
Menu and Command Bar Customisation
Delete - Deletes the currently selected tool. If the selected tool is not editable then the
delete operation is disabled. If the tool has been used then a warning message is
displayed to confirm that the delete should be carried out.
3:7 12.0
.NET Customisation User Guide
Menu and Command Bar Customisation
Creates a new tool of the required type with a unique default name (Tool<N>) and adds it to
the list.
• Tool Types
When placed on a CommandBar the Button tool can have either an icon or a text caption. In
a menu both the caption and the icon, if one is defined are displayed. The button tool simply
executes the associated command when clicked.
The ComboBox tool allows selection from a list of items. The associated command provides
the list via its List property.
The ControlContainer supports the hosting of any WinForms control. Here it is shown
hosting a ProgressBar. The control it should host is set via the Control property which
presents a list of the controls registered with the CAF using the
CommandBarManager.Controls Hashtable property.
ProgressBar progBar = new ProgressBar();
progBar.Value = 50;
commandBarManager.Controls.Add("ProgressBar",progBar);
3:8 12.0
.NET Customisation User Guide
Menu and Command Bar Customisation
The FontList tool allows selection of a font from a pulldown list of installed fonts.
The Label tool allows the addition of a static icon and/or caption.
The List tool can only be use in a menu and will create a menu entry for each of the items
returned from the List property of the associated Command object. This is typically used to
implement a MRU list of files.
The MdiWindowList tool can also only be added to a menu. It supports the standard
operations on the applications MDI Windows.
3:9 12.0
.NET Customisation User Guide
Menu and Command Bar Customisation
The property grid allows editing the various properties of the tools and CommandBars. The
tree view (3) or the list of command (4) is kept up to date with any property changes.
3:10 12.0
.NET Customisation User Guide
Menu and Command Bar Customisation
The command property can be changed by clicking on the button displayed when selecting
the command property. This will display the following dialog:
By default the command type is set to Macro. The uses a special command class to invoke
the entered single PML command. This enables the PML developer to use the interactive
customisation tool to create their own menus and commandbars without needing to write C#
command classes.
Changing the command type to "Core Command" will change the dialog to:
3:11 12.0
.NET Customisation User Guide
Menu and Command Bar Customisation
Here a list of the currently loaded CAF Command objects is displayed for selection.
OK - Saves any modified customisation files and updates the application user interface with
any changes and closes the customisation dialog.
Cancel - Restores the application user interface to state defined by customisation files if any
changes have been applied and closes the customisation dialog.
3:12 12.0
.NET Customisation User Guide
Menu and Command Bar Customisation
The resource editor enables each of the currently loaded resource sets to be edited. It
supports String, Icon and Bitmap resources. Each resource set can comprise of a number of
resource files, comprising of the "Invariant Language" resource file and any number of
locale specific resource files.
3:13 12.0
.NET Customisation User Guide
Menu and Command Bar Customisation
Paste a resource.
3:14 12.0
.NET Customisation User Guide
Menu and Command Bar Customisation
Delete a resource.
Add a new resource (Icons and Bitmaps only). New bitmaps or icons can be added by drag-
and-drop from a windows explorer. The resource id is generated from the filename
capitalised and prefixed with "ID_". If there is a clash with an exiting resource then the
following dialog will request confirmation of replacement.
String resource can be added for modified by editing them in the grid.
Add a new locale specific resource file to the resource file set.
Choosing a locale from the list of locales will add a new resource file specific for this locale.
This can then be selected for editing.
3:15 12.0
.NET Customisation User Guide
Menu and Command Bar Customisation
The caption and icon properties can be set on a tool in the tool list by drag-and-drop from
the resource editor onto the tool.
3:16 12.0
.NET Customisation User Guide
Database Interface
4 Database Interface
4.1.1 DbElementType
• Overview
There is a single class for all element types.
The purpose of the class is to:
• Instances of the class identify the element type. i.e. methods on other classes take a
DbElementType as an argument rather than a string to denote an Element type. The
DbElementType has 'value' semantics for comparison purposes. i.e. comparing of two
DbElementTypes will always return true if they refer to the same type, even if they are
different objects.
• Access the metadata associated with element types.
External to PDMS, the hash value can be used to uniquely identify an Element type. The
hash value is a 32 bit integer.
• Constructors
In C# a DbElementType object may be obtained in one of three ways:
1. Use the globally defined instances in DbElementTypeInstance. This is the
recommended and easiest way to obtain a DbElementType.
4:1 12.0
.NET Customisation User Guide
Database Interface
• Methods
The methods allow the Element type metadata to be accessed. E.g.
• Name
• Description
• BaseType (for UDETs)
• List of attributes
• List of UDAs
• Allowed members
• Allowed owners
• Types that may appear above this element type
• Types that may appear below this element type
• Element types that may be referenced from a given attribute on this element type
• Database types in which it occurs
• Related ENUMS
DbNounManual- Manual category
DbType - DB type
4:2 12.0
.NET Customisation User Guide
Database Interface
4.1.2 DbAttribute
• Overview
This is very similar to DbElementType. There is a single class for all attributes.
The purpose of the class is to:
• Access the metadata (i.e. data about data) associated with attributes. E.g. type, name,
length
• Identify attributes. i.e. methods on other classes should always take a DbAttribute
rather than a string as an argument to denote the attribute. Any comparison of attribute
identity should be done by comparing DbAttribute objects.
The class should not be confused with the attribute value. The actual Attribute value for a
particular Element can only be accessed via the DbElement class. Comparing two
DbAttributes just compares whether they identify the same attribute, the comparison
does not look at attribute values in any way.
External to PDMS, the hash value can be used to uniquely identify an Attribute. The hash
value is a 32 bit integer.
• Constructors
In C# a DbAttribute object may be obtained in the following ways:
1. Use globally defined instances. Each attribute has a globally declared instance in the
DbAttributeInstance class. This is the standard way of specifying an attribute.
2. Look up the DbAttribute given the attribute name. This is only needed for UDAs, since
all other attributes can be obtained from the global instances. The colon must be
included as part of the name.
3. Look up the DbAttribute given the attribute hash value. Generally this is only needed if
reading the hash value from an external system.
4. Various methods on other classes, such as DbElement, will return a list of
DbAttributesTypes.
• Methods
The methods allow the following metadata to be accessed:
Attribute Type
Units
Name
Description
Category
Size
Allowed Values
Allowed ranges
Is a UDA
4:3 12.0
.NET Customisation User Guide
Database Interface
Is a pseudo attribute
Example:
Find the type of attribute XLEN. We use the global instance of XLEN on the
DbAttributeInstance class.
using ATT=Aveva.Pdms.Database.DbAttributeInstance;
DbAttributeType xlenTyp= ATT.XLEN.Type;
• Related ENUMS
DbAttributeUnit- Type of units, e.g. distance or bore or none.
DbAttributeType – Type of attribute. One of
INTEGER = 1,
DOUBLE = 2,
BOOL = 3,
STRING = 4,
ELEMENT = 5,
DIRECTION = 7,
POSITION = 8,
ORIENTATION = 9
DbAttributeQualifier – used to determine what sort of qualifier an
attribute has
4.1.3 DbElementTypeInstance
This class contains instances of DbElementType for every element type in PDMS. These
instances may be used wherever a DbElementType is expected. E.g. if a method
MyMethod() takes an DbElementType, then you could write:
e.g.
MyMethod(Aveva.Pdms.Database.DbElementTypeInstance.EQUIPMENT);
It is often convenient to add a using statement for these instances. E.g.
using NOUN=Aveva.Pdms.Database.DbElementTypeInstance;
MyMethod(NOUN.EQUIPMENT);
4.1.4 DbAttributeInstance
This class contains instances of DbAttribute for every element type in PDMS. These
instances may be used wherever a DbAttribute is expected. E.g. if a method MyMethod()
takes a DbAttribute, you could write:
e.g.
MyMethod(Aveva.Pdms.Database.DbAttributeInstance.XLEN);
It is often convenient to add a using statement for these instances. E.g
4:4 12.0
.NET Customisation User Guide
Database Interface
using ATT=Aveva.Pdms.Database.DbAttributeInstance;
MyMethod(ATT.XLEN);
• Overview
This section describes the DbElement class. The DbElement class is the most widely used
class and it covers a large proportion of the database functionality that will be used in
practise.
The methods fall into the following groups:
• Navigation
• Querying of attributes
• Database modifications
• Storage of rules and expressions
• Comparison across sessions
DbElement is a generic object that represents all database elements regardless of their
type.
• Constructors
An instance of a DbElement may be obtained as follows:
• There is a static GetElement() method with no arguments to return a 'null'
DbElement.
• There is a static GetElement() method which returns a DbElement given a name.
This name should include the '/'.
• There is a static GetElement() method which returns a DbElement given a ref(two
long int array) and type. This is only needed where a reference has been stored
externally to PDMS.
• There are many methods on various classes which return DbElements
e.g.
DbElement vess1 = DbElement.GetElement("/VESS1");
• Identity
The DbElement object encapsulates the identity of the database object. Any comparison of
database objects must be done using DbElements. The DbElement has 'value' semantics
for comparison purposes. i.e. comparing of two DbElements will always return true if they
refer to the same element, even if they are different objects. DbElement instances should
be used in all cases where the identity of an element is being passed or stored.
A DbElement can be identified externally to PDMS by a combination of the ref number
AND type. The ref number is a two long integer, for example: =123/4567.
4:5 12.0
.NET Customisation User Guide
Database Interface
• Element Validity
A DbElement need not represent a 'valid' element. There are a number of reasons why a
DbElement might be invalid:
• The element is in a DB not opened.
• The element has been deleted.
There is a IsValid()method to test if a DbElement is valid.
If the DbElement is invalid then all attribute access and database navigation will fail for that
DbElement.
• Error Handling
The error handling techniques used are:
1. Some methods raise a PdmsException
2. Some methods return false if the operation can not be done.
3. For navigation operations, if the navigation does not succeed then a 'null' element is
returned. A null element can be tested using the 'IsNull' method. It will have a reference
of =0/0.
Note: The error handling philosophy is likely to change at PDMS 12.1.
• Basic Properties
DbElement has the following basic methods:
ToString()- Returns the Name of the element. If unnamed, it returns the constructed
name.
GetElementType()- Returns the DbElementType.
There are a number of pseudo attributes that return slight variations on name and type, as
below.
Type related:
Name Related:
4:6 12.0
.NET Customisation User Guide
Database Interface
4.2.2 Navigation
• Basic Navigation
There are basic methods to navigate the primary hierarchy. e.g. consider the following
hierarchy:
4:7 12.0
.NET Customisation User Guide
Database Interface
• Secondary Hierarchies
Standard navigation methods do not work for descending a secondary hierarchy. Pseudo
attribute SMEMB must be used. E.g. to get the design elements below a GPSET, you must
query the SMEMB attribute on the GPSET.
Pseudo attributes relating to secondary hierarchies are:
4:8 12.0
.NET Customisation User Guide
Database Interface
The difference between SMEMB and SEXPND is that SEXPND allows for recursive
secondary hierarchies. Where there are no recursive possibilities, SMEMB and SEXPND
will be the same. The following example illustrates the difference between SMEMB and
SEXPND:
In the example there are two secondary nodes S1, S2. S1 holds element A, C, and S2 holds
S1,D,G.
For S1,
SMEMB returns A,C
SEXPND returns A,C
For S2,
SMEMB returns S1,D, G
SEXPND returns A,C, D, G
• Basic Mechanism
The attributes available on for a DbElement will depend on its type. E.g. a site will have
different attributes to a branch. For this reason attributes are accessed through generic
methods rather than specific methods. These generic methods pass in the identity of the
attribute being queried (a DbAttribute object). There are separate methods for each attribute
type (int, double etc), plus separate methods for single values or arrays.
e.g.
4:9 12.0
.NET Customisation User Guide
Database Interface
using ATT=Aveva.Pdms.Database.DbAttributeInstance;
double length=myEle.GetDouble(ATT.XLEN);
This call returns the value of attribute XLEN. If 'myEle' is not a BOX then an exception will be raised.
If there is any doubt as to whether 'myEle' is a BOX or not, then there are a set of methods that return
false if the attribute does not exists. E.g.
e.g.
using ATT=Aveva.Pdms.Database.DbAttributeInstance;
double length;
if (!myEle.GetValidDouble(ATT_XLEN,length)) {
// handle error in some way
}
In addition there is a IsAttributeValid() method that can be used to test if an attribute is valid
or not.
The basic mechanism works for all attributes including UDAs and pseudo attributes.
The attribute types supported are:
int, int[]
double, double[]
bool, bool[]
string, string[]
DbElement, DbElement[]
DbElementType, DbElementType[]
DbAttribute, DbAttribute[]
Position
Direction
Orientation
Expression
Note: The methods that are called GetAttribute, GetAttributeArray are the
'getattribute' methods that return DbAttributes. Similarly the GetElement,
GetElementArray methods are the 'getattribute' methods that return
DbElements. This is confusing since GetElement is also the name of the method
to return a DbElement given a name. We may change the names of these in the
future.
4:10 12.0
.NET Customisation User Guide
Database Interface
• Qualifier
Many attributes take a qualifier. The qualifier is the extra information to make the query.
Examples of where a qualifier is used are:
1. Querying a ppoint position (PPOS) requires the ppoint number
2. The ATTMOD attribute can be used to query when an attribute was modified but it
needs to be given the identity of the attribute.
3. A direction/position may be queried with respect to another element
The definition of what pseudo attributes take what qualifier is described in the data model
reference manual.
The DbQualifier class represents the qualifier. This can hold any type of qualifier, i.e. int,
double,string, DbElementType, Attribute, position, direction, orientation. It can hold multiple
qualifier values, although few current attributes require multiple valued qualifiers. There is a
separate method to set the WRT element.
There is a set of query routines that take a qualifier as an extra argument.
e.g. to query the bore of ppoint 1:
DbQualifier qual=new DbQualifier();
qual.Add(1);
double bore=myele.GetDouble(ATT.PPBO, qual);
• Overview
The following modifications are allowed:
4:11 12.0
.NET Customisation User Guide
Database Interface
• Set attribute
• Create element
• Delete element
• Copy element
• Change type
• Move element
4:12 12.0
.NET Customisation User Guide
Database Interface
Call the legality checking routines to ensure that the modification is valid - These
checks are made by the plugged in application specific code. Thus potentially any error
could be raised.
• Claiming Elements
If a DB has been set up to be 'implicit' the user will claim elements as needed without having
to do explicit claims.
There are some methods on DbElement to claim/release individual elements or a hierarchy
of elements. If working on a hierarchy of elements, and errors occur, then the system will
still do what it can.
There are also methods on the MDB class to claim/release a list of elements. Performance
is improved by claiming or releasing elements in bulk, thus in general the MDB methods
should be used rather than the ones on DbElement.
The granularity of claim is at the level of primary element. This is described in the data
management reference manual.
4:13 12.0
.NET Customisation User Guide
Database Interface
• Set Attribute
As for getting attributes, there is a family of methods for setting attributes depending on the
attribute type.
ele.SetAttribute(ATT.DESC, "Example description");
There are no methods that take a qualifier.
The code should always be prepared to handle any exceptions raised.
There is a boolean method IsAttributeSetable to test if a given attribute may be set.
This does not take the new value, so it is possible that the actual setting will still fail if the
new value is invalid.
• Creating Element
Creation is relatively straightforward. Elements can be created:
• Below a given element
• After a given element
• Before a given element
If creating an element below a given element then the position in the list must be given. E.g.
DbElement myNewPipe=myZoneElement.Create(1,NOUN.PIPE);
This creates a new PIPE below 'myZoneElement' as the first member. If the position is
beyond the end of the current members list, it will create it at the end.
An exception will be raised if the required type of element cannot be created at the required
point.
There is a boolean method IsCreatable to test if an element of a given type could be created
at the required location.
Deleting element
The method to delete an element is Delete(). e.g.
MyEle.Delete();
All descendants in the primary hierarchy will be deleted. It will not delete elements in any
secondary hierarchies.
There is a boolean method IsHierarchyDeleteable to test if an
element can be deleted.
Copy
As with Delete, the standard COPY method copies the primary hierarchy. The following
points are relevant when copying:
• Certain attributes are not copied. e.g. NAME.
• For Name attributes, automatic renaming is possible
• The element may be copied to an existing element, or as a new element.
• Cross references within the copied hierarchy are automatically updated to the copied
element. References external to the copied hierarchy are left unchanged.
There are further details in the reference manuals.
An example of the DbElement method is:
myEle1.Copy(myEle2);
myEle1.CreateCopyHierarchyAfter(myEle2,copyoption);
4:14 12.0
.NET Customisation User Guide
Database Interface
The first example copies 'myEle2' on top of myEle1. The second example copies myEle2
and all its descendants to a new element after myEle1.
There are methods to:
• Copy a single element to an existing element
• Copy an element and all its descendents to an existing element
• Copy an element and all its descendents to a new element
• Copy common attributes ('CopyLike') between existing elements
There is a separate class DbCopyOption to hold the options when doing a copy. These
options are only available when copying an element and all its descendents.
The element types must match if copying to an existing element.
There is a boolean method IsCopyable to test if an element can be copied.
• Moving Element
An element can be moved to a different location in the primary hierarchy. There are
methods to:
• Inset before a given element
• Insert after a given element
• Insert into members list at the last position
Currently an element may only be moved within the same database.
An error will be raised if the element is not allowed at the new location.
There is a boolean method IsInsertable to test if an element can be moved.
Currently there is not an exposed C# method for moving elements between DBs. This will
be exposed shortly.
• Changing Type
It is possible to change the type of certain elements.
When a type is changed, the attributes are copied from the old to the new value. Any
attributes not valid for the new type are lost. Thus a round trip of changing back to the
original type may represent a loss of data.
4:15 12.0
.NET Customisation User Guide
Database Interface
• Database Expressions
Database expressions are PML1 expressions. E.g (XLEN * 1000 ). Expressions are of the
following type:
• Double
• DbElement
• Bool
• String
• Position
• Direction
• Orientation
Database expressions are stored in various places in PDMS as follows:
• As part of a rule
• Parameterisation of the catalogue
There is a DbExpression class to hold an expression. An DbExpression may be obtained in
one of the following ways:
• Use the static method internalParse() that creates a DbExpression from a
string. e.g. internalParse("XLEN * 100" )
• Retrieve an expression from a rule
• Retrieve an expression from a catalogue parameter
Having got an DbExpression there are two things that can be done with it:
1. Turn it back into text
2. Evaluate it against a given element
The methods to evaluate an expression against an element are on the DbElement class.
There are different methods depending on the expected result of the expression. The
4:16 12.0
.NET Customisation User Guide
Database Interface
method names start with 'Evaluate'. The method that returns a double has an argument for
the units (distance/bore/none). The result will always be in millimetres (mm). E.g.
DbExpression expr = DbExpression.Parse("DIAM OF PREV + 2");
double dval;
DbAttributeUnit units = DbAttributeUnit.DIST;
dval = nozz1.EvaluateDouble(expr4, units);
In this case the core system can work out that it is a distance, since DIAM is a distance.
Thus although we specified that it was a distance, it was not strictly needed. Thus if the
distance units were inch or finch then the '+2' would be interpreted as '+2inches'.
However consider:
DbExpression expr = DbExpression.Parse("10");
double dval;
DbAttributeUnit units = DbAttributeUnit.DIST;
dval = nozz1.EvaluateDouble(expr4, units);
In this case we do not know if "10" is 10mm or 10 inches. We must tell the system that it is a
'distance' unit. The system then interrogates the current distance units to return the result. If
the current distance units is mm, then dval will be 10.0. If the current distance units is inch/
finch then "10" is interpreted to mean 10 inches and is hence returned as 254. N.B. if the
value is required to be formatted for output, then it must be converted back in all cases. A
method will be added to return values in local units at a later point.
• Rules
PDMS rules consist of an expression and a dynamic/static flag. When constructing a rule,
the expression type is also needed.
There are methods on DbElement to:
• Set a rule for any attribute.
• Get a rule for any attribute
• Evaluate a rule
• Verify that the rule result is up to date
4:17 12.0
.NET Customisation User Guide
Database Interface
There are however a number of pseudo attributes that can be accessed as follows:
4:18 12.0
.NET Customisation User Guide
Database Interface
4.3 Filters/Iterators
4.3.1 Iterators
The DBElementCollection class can be used to iterate through the database hierarchy.
The iterator is created with a root element and an optional filter. There are then methods to
step through the hierarchy and return the element at the current location.
E.g. to look for all nozzles below a given element
TypeFilter filt = new TypeFilter(DbElementTypeInstance.NOZZLE);
DBElementCollection collection;
collection = new DBElementCollection(ele, filt);
The collection can the be iterated through using foreach
foreach (DbElement ele in collection)
{
…. Do something
}
The iterator class has been written to avoid unnecessarily scanning parts of the database
that will not match the filter. e.g. if looking for all boxes then the iterator will not bother to look
below pipes.
4.3.2 Filters
There are a variety of ready built filter classes available. The main ones are:
TypeFilter - True for given Element type(s)
AttributeFalseFilter - True if given attribute is false
AttributeTrueFilter - True if given attribute is true
AttributeRefFilter - True if given attribute value matches given DbElement
AndFilter - AND two existing filters.
OrFilter - OR two existing filters
BelowFilter - Filter to test if element is below an element for which the given filter is true.
4:19 12.0
.NET Customisation User Guide
Database Interface
Tables consist of a list of key/value pairs. The key may be a string (ntable), integer (itable)
or reference (ftable). The 'value' part of the pair is always the refno of the element having
that attribute value. e.g. internally a name table may look something like:
…..
Janet = 123/456
John = 321/543
Jonathon = 111/321
…
Thus for a given name, the corresponding element can rapidly be found without having to
scan the entire MDB.
The keys in a name table must be unique. Integer and reference tables may contain the
same key many times. e.g. internally a reference table may look like:
….
=123/456 =234/555
=123/456 =222/333
=123/456 =211/999
=123/458 =203/909
In the above table, element =123/456 has appeared in the table three times. This means
that three different elements were all referencing =123/456 for this particular attribute. This
is common. e.g. catalogue references are reference tables, and for these there may be
hundreds of elements referencing the same catalogue component. A further point worth
noting with respect to tables:
• Each DB has its own table. The entries in that table are for 'values' in that DB. Thus for
the above ftable, =234/555 etc must be in this DB. However =123/456, =123/458 may
be in a different DB. Indeed there may well be further references to =123/458 from
other DBs. Hence to find all references to =123/456 we need to check the tables in
each opened DB.
4:20 12.0
.NET Customisation User Guide
Database Interface
There are also methods to return all entries for a given key. This is particularly useful for
reference tables; these are methods of the MDB class.
In C# there is a NameTable class. An example of C# code that looks for all names starting
with the letter 'B' is as follows:
string nam1=new string(“/B”);
string nam2=new string(“/C”);
NameTable ntable = new MdbNameTable(db, DBAttribute.NAME, nam1, nam2);
using (ntable)
{
foreach (Element ele in ntable)
{
// Do something here with each element
}
}
Freeing search tokens
Dabacon allocates search tokens when scanning tables. It has a limited number of search
tokens. If you get to the end of the table then the token is freed automatically. However if
you stop the search before you get to the end then you must explicitly free the token.
The IDispose method is used to free the underlying Dabacon token. Therefore ALWAYS
scan the Dabacon table within a 'using' block to ensure that the Dispose method is called. If
the underlying token is not freed then errors will be output to the PDMS command line of the
form:
"xx dabacon search tokens - Expected none "
The error generating code does not actually free the tokens. So typically you will see the
number climb as more tokens are used up and not freed. The messages will be generated
until the database is closed.
4:21 12.0
.NET Customisation User Guide
Database Interface
4.5.2 DB Functionality
When an MDB is opened, a DB class instance is created for each opened DB.
The functionality offered by this class falls into the following categories:
• Query the properties of the DB. e.g. number, MULTIWRITE or not
• Returning the world element for that DB
• Session information. e.g. when was the session written and by whom. There is a
DbSession object that holds details on a database session.
• Return the DbElement in the system DB that represents this DB. This DbElement can
then be used to query system attributes and additional pseudo attributes. The
additional pseudo attributes available on the DbElement representing the DB are
described below:
4:22 12.0
.NET Customisation User Guide
Database Interface
In addition for any DbElement in any DB, the following pseudo attributes provide information
on the current DB:
4.6 Events
4:23 12.0
.NET Customisation User Guide
Database Interface
4:24 12.0
.NET Customisation User Guide
Database Interface
double y=ele.GetDouble(ATT.YLEN);
double z=ele.GetDouble(ATT.ZLEN);
// Result of UDA must be returned
return (x * y * z);
}
An instance of the delegate containing the method must then be created and registered with
PDMS.
There are separate methods to register the different types of delegates. There are also
separate methods to add a plugger for a particular element type. E.g. the two methods to
add a GetDoubleDelegate are:
public static void AddGetDoubleAttribute(DbAttribute att,GetIntDelegate
plug)
public static void AddGetDoubleAttribute(DbAttribute att, DbElementType
type, GetIntDelegate plug)
An example of registering a delegate is:
using System;
using NOUN=Aveva.Pdms.Database.DbElementTypeInstance;
using Ps=Aveva.Pdms.Database.DbPseudoAttribute;
namespace Aveva.PDMS.Shared.Tests
{
static public void RegisterDelegate()
{
// get uda attribute
DbAttribute uda=DbAttribute.GetDbAttribute(":VOLUME");
4:25 12.0
.NET Customisation User Guide
Database Interface
• Pre and Post events for local changes. i.e. changes affecting the current view of the
data. These will be Getwork, undo, redo.
• Pre and Post events for changes affecting the data on the DB. These will be Savework,
refresh, drop, flush, refresh. These will pass the list of changes. For 'global' DBs, if the
parent extract is at a different location, the flush event will be raised by the child extract.
Note: In this case the flush could still fail at the parent. Alternatively the daemon needs to
raise the flush event.
4:26 12.0
.NET Customisation User Guide
PMLNet
5 PMLNet
5.1 Introduction
PMLNet allows you to instantiate and invoke methods on .NET objects from PML proxy
objects. PML proxy class definitions are created from .NET class definitions at run time.
These proxy classes present the same methods as the .NET class which are described
using custom attributes. Proxy methods are passed arguments of known types which are
marshalled to the corresponding method on to the .NET instance. The PML proxy objects
behave just like any other PML object.
5:1 12.0
.NET Customisation User Guide
PMLNet
• Limitations
• Only .NET classes which are marked as PMLNetCallable and adhere to certain rules
can be called from PML (these rules are described later)
• Module switching does not persist .NET objects. Core PML objects defined in
FORTRAN or C++ are not persisted either.
• Passing other PML system/user objects to .NET e.g. DIRECTION, ORIENTATION, …
is not possible. It is possible to pass database references to .NET either as an array or
String. It is also possible to pass an existing instance of a PML Net Proxy to .NET.
• It is not possible to call directly PML objects from .NET. The only way to call PML from
.NET is via events.
• It is not possible to enter 'partial' namespaces as you might in C# and expect them to
be concatenated.
E.g. the sequence:
USING NAMESPACE ‘Aveva.PDMS’
!netobj = object namespace.NETObject ( )
will give an error.
Objects and Namespaces
In order to identify and load a particular class definition the PML proxy class is assumed to
have the same name as the .NET class (PML callable classes must be case independent).
This class name is passed to the PMLNetEngine which creates the .NET instance e.g.
!a = object netobject()
creates an instance of the .NET class netobject. To specify in which assembly this class is
defined and resolve any name clashes the user needs to also specify the namespace in
which the .NET class is defined using the following syntax:
USING NAMESPACE <string>
Where <string> is the namespace in which the class is defined.
5:2 12.0
.NET Customisation User Guide
PMLNet
e.g. 'AVEVA.PDMS.PMLNetExample'
The namespace is considered to be case independent. This namespace will remain current
until it goes out of scope (e.g. at end of macro). When the user types:
!netobj = object NetObject ( )
then all namespaces in the current scope will be searched to find a match. In this example,
if 'Aveva.PDMS. PMLNetExample' is not currently in scope, then the error:
(46,87) PML: Object definition for NETOBJECT could not be found.
will be raised.
• Object Names
Object names can consist of any alpha but not numeric characters (this restriction is
imposed by PML). They are treated as case-independent. However, it is no longer
necessary to define them in upper case - any mixture of upper and lower case letters will
have the same effect.
• Query Methods
The query methods on an object have been enhanced as follows:
(a) Querying an object will show the namespace name as well as the object name:
e.g.
q var !x
< AVEVA.PDMS.NAMESPACE.NETOBJECT>
AVEVA.PDMS.NAMESPACE.NETOBJECT
(b) There is a new query method to list all the methods of an object (including constructors)
Q METH/ODS
e.g.
q meth !x
<AVEVA.PDMS.NAMESPACE.NETOBJECT>AVEVA.PDMS.NAMESPACE.NETOBJECT
NETOBJECT ( )
NETOBJECT (REAL)
ADD (REAL)
REMOVE(REAL)
ASSIGN(AVEVA.PDMS.NAMESPACE.NETOBJECT)
DOSOMETHING(REAL, REAL, REAL)
Note that query methods will not list the methods on objects of type ANY, even though such
methods are available on all objects.
5:3 12.0
.NET Customisation User Guide
PMLNet
• Global Method
There is a new global method on all objects:
.methods()
which returns a list of the methods on the object as an array of strings.
e.g.
!arr = !x.methods()
q var !x
returns:
<ARRAY>
[1] <STRING> 'NETOBJECT ( )'
[2] <STRING> 'NETOBJECT (REAL)'
[3] <STRING> 'ADD (REAL)'
[4] <STRING> 'REMOVE(REAL)'
[5] <STRING> 'ASSIGN(AVEVA.PDMS.NAMESPACE.NETOBJECT)'
[6] <STRING> 'DOSOMETHING(REAL, REAL, REAL)'
Importing an assembly
Before an instance of a .NET object can be instantiated the assembly containing the class
definition must be loaded. This is done using the IMPORT syntax as follows
IMPORT <string>
• Method Arguments
Only PML variables of the following types may be passed to methods on .NET classes. In
the table below the PML variable type is in the left column and the .NET equivalent variable
type is in the right column. Data is marshalled in both directions between PML and .NET by
the PMLNetEngine.
PML .NET
REAL double
STRING string
BOOLEAN bool
5:4 12.0
.NET Customisation User Guide
PMLNet
PML .NET
ARRAY (these can be sparse and Hashtable
multi-dimensional)
OBJECT Any existing PML Net PMLNetCallable class
instance
Arguments to PML Proxy methods are passed by reference so can be in/out parameters (in
.NET output arguments must be passed by reference).
Value Semantics
PML Gadgets and DB elements have reference semantics when they are copied whereas
all other objects have value semantics when they are copied. This is controlled by the
Assign() method on the .NET class. So, for example if the Assign() method here copies the
value then
!a = object netobject()
!a.val(1)
!b = !a
!b.val(2)
then
q var !a.val() returns 1
and
q var !b.val() returns 2
• Method Overloading
Overloading of methods is supported for all variable types in PML so a .NET Proxy can be
created from a .NET class which has overloaded methods.
• Custom Attributes
The custom attribute [PMLNetCallable()] is used to describe the PML interface for a .NET
class. This metadata allows the PML callable assemblies to be self-describing. This clearly
defines the class and allows an assembly to expose a subset of its public interface to PML.
The PMLNetEngine uses this metadata to decide which .NET class definitions can be
created in PML. Reflection is used to load an assembly and create PML class definitions. All
classes and methods for which PML Proxy class definitions will be created must be marked
as PMLNetCallable. The assembly itself must also be marked as PMLNetCallable.
So, a PML callable .NET class in C# looks like this:
[PMLNetCallable()]
namespace PMLNet
{
[PMLNetCallable ()]
public class PMLNetExample
5:5 12.0
.NET Customisation User Guide
PMLNet
{
[PMLNetCallable ()]
public PMLNetExample()
{
}
[PMLNetCallable ()]
public void DoSomething(double x, double y, double z)
{
z = x + y;
}
}
}
This class has a default constructor and a single method. Both the constructor and method
are marked as PMLNetCallable along with the class itself.
The assembly itself must also be marked as PMLNetCallable. This is normally done in the
AssemblyInfo file as follows
using Aveva.PDMS.PMLNet;
[assembly: PMLNetCallable()]
• Scope
PML variables are of two kinds: global and local. Global variables last for a whole session
(or until you delete them). A local variable can be used only from within one PML function or
macro. The lifetime of the .NET instance is controlled by the scope of the PML proxy.
5:6 12.0
.NET Customisation User Guide
PMLNet
• Instantiation
Classes can have any number of overloaded constructors but must have a default
constructor which is marked as PMLNetCallable. The PML Proxy constructor instantiates an
instance of the underlying .NET class. When the proxy goes out of scope the destructor
destroys the underlying .NET instance.
• ToString() Method
The string() method is available on all PML objects. For a .NET Proxy this will call the
ToString() method on the .NET instance. If the ToString() method is overridden on the .NET
class then this will be called.
• Method Names
PML is case independent, so it is not possible to have MyMethod() and MYMETHOD() in
.NET. PML will report non-unique object/method names.
• Double Precision
Doubles are used in PMLNet to store reals and ints so doubles must be used in .NET
(integers are not available in PML)
• Events
Events on PMLNet objects may be subscribed to from PML. A PML callback on a particular
instance may be added to an event on another PMLNet instance. Events are defined by a
.NET component by associating the delegate PMLNetEventHandler with the event. This
delegate has the signature
__delegate void PMLNetEventHandler(ArrayList __gc *args);
Where args is an array of event arguments of any PMLNet type (see table of valid types).
The following code associates this delegate with an event
[PMLNetCallable()]
public class PMLNetExample
{
[PMLNetCallable()]
public event PMLNetDelegate.PMLNetEventHandler PMLNetExampleEvent;
[PMLNetCallable()]
public PMLNetExample ()
{
}
[PMLNetCallable()]
public void Assign(PMLNetExample that)
{
}
[PMLNetCallable()]
public void RaiseExampleEvent()
{
ArrayList args = new ArrayList();
args.Add("PMLNetExampleEvent ");
5:7 12.0
.NET Customisation User Guide
PMLNet
args.Add("A");
if (PMLNetExampleEvent!= null)
PMLNetExampleEvent(args);
}
}
This event can then be caught in PML by adding an appropriate callback to the instance raising the
event
!n = object pmlnetexample()
!c = object netcallback()
• Error Handling
Exception handling is placed around the Invoke method to handle .NET method invocation
exceptions like TargetException, ArgumentException etc. The result of catching such an
exception is to ultimately return a PMLError object from PMLNetProxy::Invoke() which
results in a PML exception (1000,n) being thrown where 1000 is the module number for
PMLNet. .NET can throw its own PML exceptions. The exception to throw is
PMLNetException. For example
throw new PMLNetException(1000, 1, "PMLNetExample Exception");
This may then be handled inside a PML macro i.e.
handle(1000,1)
…
endhandle
Any other exception within the loaded assembly itself is caught by the global exception
handler inside PDMS.
5:8 12.0
.NET Customisation User Guide
PMLNet
• Tracing
In order to output trace to a log file and the console window add the following lines to the
exe's config file
<system.diagnostics>
<switches>
<add name="PMLNetTraceSwitch" value="4" />
</switches>
</system.diagnostics>
<appSettings>
<add key="PMLNetTraceLog" value="C:\temp\PMLNetTrace.log" />
</appSettings>
This will create the file PMLNetTrace.log in C:\temp and log all the valid class definitions as
they are imported.
• Creating a Container
A container on a form that can host the .NET control can be created in the following way in
the form setup
container .exampleContainer PmlNetControl 'example' dock fill width 30
height 20
which can be docked and positioned.
5:9 12.0
.NET Customisation User Guide
PMLNet
• Events
Events on the control are supported by PML delegates already described. These allow you
to add popup menus to the control for example. Events may be subscribed to by adding an
event handler as follows to the .NET control
!this. exampleControl.addeventhandler('OnPopup', !this,
'rightClickGrid')
where the method to call when the event is fired is defined as follows
define method .rightClickGrid(!data is ARRAY)
!this.exampleContainer.popup = !this.examplePopup
!this.exampleContainer.showPopup(!data[0], !data[1])
endmethod
and the menu shown by the method which is added to the container is defined as follows
menu .examplePopup popup
!this.examplePopup.add( 'CALLBACK', 'Add to 3D View',
'!this.addToThreeDView()' )
5.2.3 Examples
The following examples are available in the Samples directory -
• PMLGridExample
Example of a .NET grid hosted on a PML form
• PMLNetExample
Example of a PML Callable assembly
5:10 12.0
.NET Customisation User Guide
AVEVA C# Grid Control
6.1 Introduction
This section describes how to use an instance of an Aveva C# Grid Control on a C# form.
The example which is used in this documentation is supplied with the product. The Visual
Studio project containing the source code is located in the following directory:
Samples\NetGridExample
Note: That you can only use the Aveva C# Grid Control on your own Visual Studio form if
you have a design time licence for Infragistics version 6.1.
Note: That you can run this C# Addin with PDMS without having an Infragistics licence.
6:1 12.0
.NET Customisation User Guide
AVEVA C# Grid Control
The example C# code collects all the Equipment items within the current project and lists
them inside the grid along with attribute values for Name, Type, and Owner.
The data in the grid can be selected, sorted and filtered.
Note: The following features of the example addin. These features make use of the
published Grid Control API (see the section below entitled "AVEVA Grid Control
API").
1. The data in the grid can be exported to a Microsoft Excel file (XLS) by entering a path
name in the text box beneath the grid and by clicking on the "Export to Excel" button.
2. The grid content can be previewed and printed by clicking on the "Print Preview"
button.
3. The colour of the first row in the grid can be set either by choosing a colour in the drop
down list, or by typing a valid colour into it.
4. The number of selected rows in the grid is written to a read-only text box. Note that this
feature makes use of an event on the grid. (See the section below entitled "Adding an
event to the C# Grid Control").
5. Notice that there are two different context menus available on the grid. One is available
when equipment items are selected:
6:2 12.0
.NET Customisation User Guide
AVEVA C# Grid Control
And the other menu is available from the header bar at the top of the grid:
Note: That these menu options will only become available once you have made some
modifications to the Design.uic file through menu customisation. See below for
instructions on how to do this.
6:3 12.0
.NET Customisation User Guide
AVEVA C# Grid Control
Note that you could also create your own toolbar which contained a menu item to open/
close the addin.
6:4 12.0
.NET Customisation User Guide
AVEVA C# Grid Control
The grid can be populated with non-database data from a Microsoft Excel file. The first row
of the Microsoft Excel file will supply the headings for the grid and the other rows will supply
the row data.
The following data source is available for this method of working. See the AVEVA Grid
Control API below for further information.
• NetDataSource(String TableName, string PathName)
To add the menus you will need to do the following in the Menu Customisation utility:
1. Add a new Context Menu, which has its name property set to: NewAddin.SelectMenu.
This name is used by the code to locate the set of menus to display when the user
makes a context menu selection on one or more equipment items in the grid. The C#
method below from the addin class, is the code which loads the menu. The menus
which you create in the Menu Customisation Utility will be stored in the Design.uic file.
6:5 12.0
.NET Customisation User Guide
AVEVA C# Grid Control
{
MenuTool menu = (MenuTool)mCommandBarManager.Root-
Tools[contextMenuKey];
mAddinControl.SelectionMenu = menu;
}
contextMenuKey = "NewAddin.HeaderMenu";
if(mCommandBarManager.RootTools.Contains(contextMenuKey))
{
MenuTool menu = (MenuTool)mCommandBarManager.Root-
Tools[contextMenuKey];
mAddinControl.HeaderMenu = menu;
}
}
2. Create a button and set the command to AVEVA.DrawList.Add. When this menu is
used in the Addin it will add the selected equipment item(s) to the 3D view.
3. Assign the button to the context menu named NewAddin.SelectMenu. You can create
other menu options (either from existing PDMS commands which have been exposed,
or from existing PML methods and functions) in the same way and assign these to the
context menu.
4. Create a second Context menu named NewAddin.HeaderMenu. This name is used by
the code to locate the set of menus to display when the user makes a context menu
selection on the header bar in the grid.
5. Create a button and set the command to AVEVA.Grid.ExportToExcel. When this menu
is used in the Addin it will export the grid data to a Microsoft Excel file.
6. Assign the button to the context menu named NewAddin.HeaderMenu. You can create
other menu options in the same way and assign these to the context menu.
6:6 12.0
.NET Customisation User Guide
AVEVA C# Grid Control
fourth argument of the array (Array[3]) can be set to false by the calling application in order
to disallow the new value of the cell.
Note: This event is the opportunity for the calling code to make a synchronising change to
any related data source. In the case where the related data is Dabacon element/
attribute data, the BeforeCellUpdate event should arrange for the Dabacon element/
attribute to be modified appropriately. A convenient way to do this is to use the
NetGridControl.DoDabaconCellUpdate(Array) function to perform the modification.
Simply pass the Array to this function as an argument. If the function is unable to
perform the modification for any reason the Array[3] and Array[4] values will be set to
indicate the problem.
3. AfterSelectChange(Array)
1. Array[0] contains the ID of each of the selected rows
An array of selected items is passed through to the calling application. See the example C#
code snippet below. The example code shows that the number of selected items is written to
a text box.
private void netGridControl1_AfterSelectChange(System.Collections.ArrayLst
args)
{
//Print the number of the selected rows in textbox2
if (args == null)
{
return;
}
Hashtable al = new Hashtable();
al = (Hashtable)args[0];
if (al == null)
{
return;
}
this.textBox2.Text = al.Count.ToString();
}
Refer to Events for Event handling
6:7 12.0
.NET Customisation User Guide
AVEVA C# Grid Control
Note: That you can only use the Aveva C# Grid Control on your own Visual Studio form if
you have a design time licence for Infragistics version 6.1.
6:8 12.0
.NET Customisation User Guide
AVEVA C# Grid Control
6:9 12.0
.NET Customisation User Guide
AVEVA C# Grid Control
6:10 12.0
.NET Customisation User Guide
AVEVA C# Grid Control
6:11 12.0
.NET Customisation User Guide
AVEVA C# Grid Control
6:12 12.0
.NET Customisation User Guide
AVEVA C# Grid Control
Character Description
# Digit placeholder. Character must be numeric (0-9) and entry is
required.
. Decimal placeholder. The actual character used is the one specified as
the decimal placeholder by the system's international settings. This
character is treated as a literal for masking purposes.
, Thousands separator. The actual character used is the one specified as
the thousands separator by the system's international settings. This
character is treated as a literal for masking purposes.
: Time separator. The actual character used is the one specified as the
time separator by the system's international settings. This character is
treated as a literal for masking purposes
/ Date separator. The actual character used is the one specified as the
date separator by the system's international settings. This character is
treated as a literal for masking purposes.
\ Treat the next character in the mask string as a literal. This allows you
to include the '#', '&', 'A', and '?' characters in the mask. This character
is treated as a literal for masking purposes.
& Character placeholder. Valid values for this placeholder are ANSI
characters in the following ranges: 32-126 and 128-255 (keyboard and
foreign symbol characters).
> Convert all the characters that follow to uppercase.
6:13 12.0
.NET Customisation User Guide
AVEVA C# Grid Control
Character Description
< Convert all the characters that follow to lowercase.
A Alphanumeric character placeholder. For example: a-z, A-Z, or 0-9.
Character entry is required.
a Alphanumeric character placeholder. For example: a-z, A-Z, or 0-9.
Character entry is not required.
9 Digit placeholder. Character must be numeric (0-9) but entry is not
required.
- Optional minus sign to indicate negative numbers. Must appear at the
beginning of the mask string.
C Character or space placeholder. Character entry is not required. This
operates exactly like the '&' placeholder, and ensures compatibility with
Microsoft Access.
? Letter placeholder. For example: a-z or A-Z. Character entry is not
required.
Literal All other symbols are displayed as literals; that is, they appear as
themselves.
n Digit placeholder. A group of n's can be used to create a numeric
section where numbers are entered from right to left. Character must be
numeric (0-9) but entry is not required.
mm, dd, yy Combination of these three special strings can be used to define a date
mask. mm for month, dd for day, yy for two digit year and yyyy for four
digit year. Examples: mm/dd/yyyy, yyyy/mm/dd, mm/yy.
hh, mm, ss, tt Combination of these three special strings can be used to define a time
mask. hh for hour, mm for minute, ss for second, and tt for AP/PM.
Examples: hh:mm, hh:mm tt, hh:mm:ss.
6:14 12.0