Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can we export the tree structure as a figure. #152

Open
zhen-liu-github opened this issue Jun 2, 2022 · 9 comments
Open

Can we export the tree structure as a figure. #152

zhen-liu-github opened this issue Jun 2, 2022 · 9 comments

Comments

@zhen-liu-github
Copy link

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.

@Affonso-Gui
Copy link
Contributor

Affonso-Gui commented Sep 14, 2022

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:
test

After a bit of tweaking:
test2

Notice that we still have some weird additional space after the names, which I haven't figured out yet.

Check Affonso-Gui@0ca1350 and Affonso-Gui@be5442d for a working example.

@zhen-liu-github
Copy link
Author

Thanks for your help!

@Timple
Copy link
Contributor

Timple commented Sep 15, 2022

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?

@zhen-liu-github
Copy link
Author

Sure, repoened it and wait for more solutions.

@Affonso-Gui
Copy link
Contributor

Affonso-Gui commented Sep 15, 2022

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.

  1. Shading and Cache: hopefully can be disabled just for the save and then re-enabled?
  2. Palletes: having colors is great for developing, but somewhat more questionable for external use.
  3. Interfacing: probably not worth an additional button at the side or top bars. Maybe a right-click option?

@Affonso-Gui
Copy link
Contributor

Oh, and of course the weird additional spacing (different fonts when displaying on canvas vs on the svg image?)

@Timple
Copy link
Contributor

Timple commented Sep 15, 2022

  1. I like the default colors 🙂 . Nobody works on black-and-white screens anymore 😉
  2. Idealy a commandline-option. Would be great to have a generation command: Groot tree.xml --output-svg. Ideal for automated documenation generation.

@Affonso-Gui
Copy link
Contributor

  1. Fair enough. Just for clarity, I was thinking of black-and-white as a save-time-only feature, though.
  2. Not sure, I also like the possibility of tweaking the position of each node to my liking before saving.

@Affonso-Gui
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants