On 01/09/2016 at 02:42, xxxxxxxx wrote:
Hi Ian,
even if you chose to take another approach, I'll add my findings here for completeness.
So with FillPortsMenu() you can override the menus in the top corners of a node. There are only two things to be considered: The menu is overwritten completely, so if has already ports defined in a resource file, one has to list these in the menu manually. Furthermore all menu IDs need to be greater or equal first_menu_id, otherwise it won't work.
So FillPortsMenu() could look like so:
Int32 GvOperatorDataExample::FillPortsMenu(GvNode* bn, BaseContainer& names, BaseContainer &ids, GvValueID value_type, GvPortIO port, Int32 first_menu_id)
{
// Init defaults for inputs (port == GV_PORT_INPUT)
Int32 portIdBase = ID_DYNAMIC_IN_PORT_BASE;
Int32 menuIdBase = 0; // Different menu IDs for in and out in order to be able to differentiate in Message() (if the message is needed at all)
String nameBase = "My in port #";
Int32 numPorts = 2;
if (port == GV_PORT_OUTPUT)
{
portIdBase = ID_DYNAMIC_OUT_PORT_BASE;
menuIdBase = 1000;
nameBase = "My out port #";
numPorts = 3;
}
for (Int32 idxPort = 0; idxPort < numPorts; ++idxPort)
{
const Int32 menuId = first_menu_id + menuIdBase + idxPort;
const Int32 portId = portIdBase + idxPort;
String nameMenuEntry = nameBase + String::IntToString(idxPort);
// Deactivate entries for existing ports
GvPort* port = nullptr;
if (portIdBase < ID_DYNAMIC_OUT_PORT_BASE)
port = bn->GetInPortFirstMainID(portId);
else
port = bn->GetOutPortFirstMainID(portId);
if (port)
nameMenuEntry += "&d&";
names.SetString(menuId, nameMenuEntry);
ids.SetInt32(menuId, portId);
}
return numPorts; // Number of added entries
}
If you need to, you could react to the user clicking a menu entry by the message GV_MESSAGE_PORTS_MENU described in my last post. But you actually don't have to. All you need to do to make it work, is to implement iGetPortDescription() and care for the ports there:
For example like so, only inports shown:
if ((id >= ID_DYNAMIC_IN_PORT_BASE) && (id < (ID_DYNAMIC_IN_PORT_BASE + ID_DYNAMIC_PORT_RANGE)))
{
pd->name = "My custom in port " + String::IntToString(id - ID_DYNAMIC_IN_PORT_BASE);
pd->flags = (GvPortDescFlags)(GV_PORTDESCRIPTION_PORTONLY);
pd->data_id = ID_GV_DATA_TYPE_INTEGER;
pd->ports_min = 0; // only needed with GV_PORTDESCRIPTION_MULTIPLE
pd->ports_max = 0;
pd->parent_id = bn->GetNodeID();
return true;
}