Groot
Groot copied to clipboard
Can we export the tree structure as a figure.
Thanks for your great work. I have a behavior tree with some son node, and want to save the structure as a figure. If i direct screenshot, the image equality is poor. So dose this ui tool provide the save as figure func? I just find the save as xml func. Thanks for your advice.
I was facing this problem myself as I was trying to generate nice figures for a paper.
It turns out that you can use the QSvgGenerator class for saving an svg view of the tree (https://doc.qt.io/qt-5/qtsvg-svggenerator-example.html).
void GraphicContainer::saveSvgFile(const QString path)
{
QSvgGenerator generator;
QRectF rect = _scene->itemsBoundingRect();
generator.setFileName(path);
generator.setSize(QSize(rect.width(), rect.height()));
generator.setViewBox(rect);
QPainter painter;
painter.begin(&generator);
_scene->render(&painter, rect, rect);
}
In order to have vector images, we also need to disable the drop shadow and the cache (https://forum.qt.io/topic/6008/how-to-save-a-qgraphicsscene-to-an-svg-file).
This allows us to generate:
After a bit of tweaking:
Notice that we still have some weird additional space after the names, which I haven't figured out yet.
Check https://github.com/Affonso-Gui/Groot/commit/0ca13500d3e095bd9fa9ff44cb5b161acc9ba150 and https://github.com/Affonso-Gui/Groot/commit/be5442d730c2b63c9b0890071e32722e1432f253 for a working example.
Thanks for your help!
So @Affonso-Gui showed how it could be implemented and even demonstrated a working example. This doesn't mean this issue is fully closed now is it?
Sure, repoened it and wait for more solutions.
The saveSvgFile
function itself should be pretty harmless, but I think there are three main points that still need to be considered if we are planning on actually implementing this feature.
- Shading and Cache: hopefully can be disabled just for the save and then re-enabled?
- Palletes: having colors is great for developing, but somewhat more questionable for external use.
- Interfacing: probably not worth an additional button at the side or top bars. Maybe a right-click option?
Oh, and of course the weird additional spacing (different fonts when displaying on canvas vs on the svg image?)
- I like the default colors :slightly_smiling_face: . Nobody works on black-and-white screens anymore :wink:
- Idealy a commandline-option. Would be great to have a generation command:
Groot tree.xml --output-svg
. Ideal for automated documenation generation.
- Fair enough. Just for clarity, I was thinking of black-and-white as a save-time-only feature, though.
- Not sure, I also like the possibility of tweaking the position of each node to my liking before saving.
Although the command line option does make 1 (and 2) much easier, we could just start the program with save configurations and get the job done.