Developing MIP SDK Plug-in Integrations Part 6: Background Plug-in Executing commands from a map

Let’s first go and create a map in the
Smart Client. We’ll create a new view for it first. Then, we supply an image as the
surveillance area overview. Now, we drag a controller onto it. The MIP plug-in items are under the puzzle piece icon. As we can see, the controllers we have
defined are already available. When leaving setup mode and right-clicking on the icon, there are no actions available. That’s what we need to define. The icon looks like there is an error, but it is the default icon if we don’t supply one. We’ll fix this. Let’s begin by adding an icon for our controller in the Resources of the project. Now, we can go to the plug-in definition. Just to highlight that we are not using any Client plug-ins in this project, let’s comment out or delete all the unnecessary plug-ins in the Init and Closed methods. Now, back to the Map actions. Let’s stick with the opening and closing the gate analogy, so we’ll use those two commands. Since the commands will be used both in the map and the event handler, let’s make them constants so we don’t make a mistake. We also need a member variable
for a collection of MapAlarmContextMenus. Then we go down to the Init method and add two context-menu items. These are self-explanatory. We enter the context-menu and the icon
we just added in the item node declaration. That’s all that is required for the context-menu to display the new options for this kind of item. However, selecting one will not trigger anything. Let’s take care of that next. We implement the event triggering in our Item Manager class because it already has related methods like GetOperationalState, which determines how the map displays an item. In the end, we need to trigger the SendCommand method within the background plug-in so we implement the same workflow we did in the rural action manager to get hold of the background plug-in. So let’s first take care of that. We have to edit the ItemNode declaration and pass the definition to the item manager. Now we can go to the item manager. First, let’s add the needed member variables. We are going to need the definition, a collection to keep track of operational status of items, and a message filter. Then we add the definition to the
constructor. Remember that we are passing it from the plug-in definition. In the Init method, we are creating a
message registration for triggered events, and passing them to an event handler, which we have to do next. Before that, let’s get the message
registration unregistered in the Close method. Now we can paste the event handler. There is nothing complicated with the eventhandler; it just checks for several different types of scenarios like user rights to perform an action. Basically, if the event string matches that of the context menu definition, we use the SendCommand method in our background plug-in. The _downItems collection will be used
to indicate the operational state on the map. This would, of course, depend on the application; but in our case we’re returning a warning if a gate is closed and showing a normal operation status when it’s open. Let’s implement that and then we are ready to test. We need to go to GetOperationalState and put our logic there. If the item is in the _downItems collection, it’s shown as a Warning; otherwise it’s Normal operation. Now we can build the project and make sure everything is working correctly. Let’s test if we can send commands to our controller. We’ll right-click the icon to see the context-menu. We can see both of our custom selections as expected. Let’s trigger each one. We can see that the controller simulator is receiving the messages. If we use the Close Gate command, the icon should show the warning status indicator. If we do the opposite, it should disappear. Excellent work!

Leave a Reply

Your email address will not be published. Required fields are marked *