- get node by id
I implement a function "sp_repr_lookup_id" in utils.cpp[2] which will get the node by referred id. However, sometimes the document contain duplicated node with the same id, or some node without id. So the method do not provide an unique node resolution. I believe the GSoC project also has implementation about this, too.
I used a pair of built in functions.
I start with a SPDesktop* and get a SPDocument* with sp_desktop_document(desk) (in desktop-handles.h) let's call it doc:
If I need an SPObject I use doc->getObjectById("rect1234") (in document.h) and get the node from that using ->repr if I need that as well.
If I only need an inkscape::XML::Node*, I can use sp_repr_lookup_name((doc->root)->repr, "rect1234") (in xml/repr.h).
To go the other direction (node to id) I use ->attribute("id") just like you do.
The latter is almost identical to your function, but it uses GQuark codes instead of string comparisons for extra speed, so you should probably check that out.
- use position sequences.
This is the current method I use in inkboard. For example, the string "0-3-0" means that the 1st child of the 3rd child of the 1st child of the document root.
This implementation provide a pair functions "char* sp_repr_get_abs_pos_from_node( Node *node )" and "Node* sp_repr_get_node_from_abs_pos( char* abs_pos, Node *root )" to convert between nodes and position sequence strings. This works fine, but this require both sharing document should have the same xml repr. Or it will cause the nodes into chaos.
That's a pretty straightforward representation, unfortunately it doesn't really work for my purposes. Since I return an ID to the user that they could (and probably will) save and use later. In the meantime the tree could have changed drastically, with nodes being added/removed layers reordered and so on.
It sounds like you only needs a temporary ID rather than a permanent one because it is created and then used immediately, so this system is good for a real-time application like yours.
I've taken a look at your event listener and it might be exactly what I need. I'm going to try to adapt it for sending dbus signals and I'll let you know how it goes.
Thanks for the heads up! -Soren