On 15/09/2016 at 03:43, xxxxxxxx wrote:
Hi Ian,
when the selection state of a node changes, there are basically two things happening:
a) A CoreMessage EVMSG_GRAPHVIEWCHANGED is sent, which you can receive in the dialog hosting your GraphView. This is probably the right place, if you want to for example update a CustomGuiDescription, which is exposing the parameters of the nodes.
b) A message hook gets called by GvWorld. You can register your own GvHook during PluginStart() with RegisterHook(), which provides means for a couple of different hooks, in this case you are interested in the message hook.
This could roughly look like so:
static Bool MessageHookFunc(GvMessHook &hook)
{
if (hook.id == GV_MESSAGE_NODE_CREATED)
{
BaseList2D* newNode = hook.mess.GetLink(GV_MESSAGE_FIRST_DATA_ID, hook.document);
GePrint("Node created: " + newNode->GetName());
}
else if (hook.id == GV_MESSAGE_PORT_RENAMED)
{
GePrint("port renamed");
}
else if ((hook.id == GV_MESSAGE_NODE_SELECTED) || (hook.id == GV_MESSAGE_NODE_DESELECTED))
{
BaseList2D* const selectedNode = hook.mess.GetLink(GV_MESSAGE_FIRST_DATA_ID, hook.document);
const Int32 operatorId = hook.mess.GetInt32(GV_MESSAGE_FIRST_DATA_ID + 1);
const Int32 ownerId = hook.mess.GetInt32(GV_MESSAGE_FIRST_DATA_ID + 2);
GePrint("Node selection change: " + selectedNode->GetName());
}
else
{
GePrint("Message ID: " + String::IntToString(hook.id));
}
return true;
}
Bool RegisterGVHook()
{
GvHook h;
h.hook_name = "My Hook";
h.hook_id = ID_MY_HOOK; // unique plugin ID, may be the same as the owner id, if a unique plugin ID is used for owner
h.owner_id = ID_GV_GENERAL_OWNER; // use to restrict callback to certain nodes (see op_owner of GvRegisterOperatorPlugin())
h.message = MessageHookFunc;
return GvGetWorld()->RegisterHook(h, nullptr);
}
Note: In this way your message hook will be called for all other general nodes as well. Use owner Id as mentioned in comments to restrict this.