Contents:
In the select mode, viewer can display additional custom menu items.
Registering menu items
To register a menu item, pass array of menu item objects according to specs given below:
var menuItem = { name: 'My Menu', callback: this.myFunction, context: this, iconCls: 'icon-molecule', domainId: '525' }; var menuItems = []; menuItems.push(menuItem); HD.EmbededApi.registerContextMenu(menuItems)
- name - display name for this menu item
- callbackFn - a functin that will be called when the menu item is clicked
- context - context that should be set on callback function
- iconCls - optional icon class that should be used with the menu item
domainId - optional domain ID, if provided, ID's from given domain will be added to function call arguments.
Response / Callback arguments
Provided callback function will be called with the following arguments:
var arg = { contextEntity : "ENT-120681", contextObject : Object, selectionObjects : Array, selectionEntities : Array }; //sample handler: var myFunction = function(arg) { console.log(arg); }
contextEntity - Entity that was right clicked
contextObject - Object linked to clicked entity
selectionEntities - currently selected entities
selectionObjects - currently selected objects (linked to entities)
Obtain objects with External ID / Class
Objects are returned with internal HDC id and class. To convert to external ID in a given domain, provide aditional domain ID parameter:
{HD.EmbededApi.registerContextMenu("My Item", this.myHandler, this, "my-icon-class");
HD.EmbededApi.registerContextMenu("My Item", this.myHandler, this, "my-icon-class", '523');
Response will be suplemented with EID parameters.
Using custom icons
Load your custom CSS or register ad-hoc CSS class.
Sample class that can be used to control custom image with embedded Base64 image (actual Base 64 content replaced by '...'):
Convenient online converter to Base 64
.icon-molecule { background-image: url('data:image/png;base64,...') }
Or with image reference
.ui-state-success { background-image: url('../icons/ui-icons_4eb305_256x240.png') }
Using Font Awesome icons
HDC 2.7
It is possible to use any of the Font Awesome icons listed here
For example, to use this icon:
http://fontawesome.io/icon/battery-three-quarters/
use the follwoing menu item definition:
var menuItem = { name: 'My Menu', callback: this.myFunction, context: this, iconCls: 'x-fa fa-battery-three-quarters', domainId: '525' };
HDC 2.8
Font icons are no longer supported. Since HDC version 2.8 SVG based icons are used. A new way of defining the icon must be used.
x-fa namesapce is no longer available. Please use one of these namespaces:
- fas - to be used with free "solid" icons
- far - to be used with free "regular" icons
Other namespaces are not available. The syntax is fully standard as for Font Awesome 5. Sample use:
iconCls: 'far fa-address-card'
HDC 3.4
Since version 3.4 vector icons from Font Awesome PRO are available for use. Only "Regular" icon set can be used.
Sample