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

Save/Load nodes and links to json #141

Closed
aabilityuk opened this issue Dec 22, 2021 · 9 comments
Closed

Save/Load nodes and links to json #141

aabilityuk opened this issue Dec 22, 2021 · 9 comments

Comments

@aabilityuk
Copy link

Hi, dear community! Could anybody please help me to find out how to make a save/load logic for all nodes and links to/from json., It would be great to see a code sample and any advices would be appreciated!!! Thank you very much

@thedmd
Copy link
Owner

thedmd commented Dec 22, 2021

Hi, did you looked at blueprint example?

Callback are called after node state change and you can save it. To restore previous state you can call ed::RestoreNodeState().

config.LoadNodeSettings = [](ed::NodeId nodeId, char* data, void* userPointer) -> size_t
{
auto node = FindNode(nodeId);
if (!node)
return 0;
if (data != nullptr)
memcpy(data, node->State.data(), node->State.size());
return node->State.size();
};
config.SaveNodeSettings = [](ed::NodeId nodeId, const char* data, size_t size, ed::SaveReasonFlags reason, void* userPointer) -> bool
{
auto node = FindNode(nodeId);
if (!node)
return false;
node->State.assign(data, size);
TouchNode(nodeId);
return true;
};

Save/Restore state is clunky, but is getting job done. Next version may improve on the API.

@SadE54
Copy link

SadE54 commented Dec 22, 2021

Personally , I used a third party json serializer (nlohmann json). It allows me to save/process arbitrary data , including new fields for my specific application , and without touching to the node library .

@aabilityuk
Copy link
Author

aabilityuk commented Dec 23, 2021

Hi, did you looked at blueprint example?

Hi, yes i did

Callback are called after node state change and you can save it. To restore previous state you can call ed::RestoreNodeState().

Thank you for explanation, i tried to save and restore in blueprint example using the buttons, but it save and store only the location of the node.

изображение

But I need saving the whole state of all nodes,links,pins to json, then i close the program and after i start the program i want to restore all this nodes, links, pins and so on to it's state before i close the program!!!

Could you please explain me how to achieve this approach? or maybe there is a code example? Thank you

@aabilityuk
Copy link
Author

Personally , I used a third party json serializer (nlohmann json). It allows me to save/process arbitrary data , including new fields for my specific application , and without touching to the node library .

Hi, thank you for reply! is it possible to achieve the goal i posted above with nlohmann? If so could you share the example please ? Actually i strongly want to be able to make the save/restore option using the original NodeEditor without third parties libs...

@aabilityuk
Copy link
Author

aabilityuk commented Dec 25, 2021

Dear, @thedmd

please help me to make File-> save/ File-> Load. I want to be able to save/load the whole node-editor project (with all nodes, links,pins). It is very important to me and i couldn't release it without this feature. Thank you very much!!!!

@thedmd
Copy link
Owner

thedmd commented Dec 27, 2021

Node Editor does not hold more that than returned by callbacks.

Saving and loading state of your data is not in the scope of this project, rather something you need to have on your side. Blueprint example show how one can build an editor and provide mock data that is generated on the fly.

On feature/blueprint-next I started to build another example which is build on top of real functional blueprints. Bear in mind is is still work in progress and is on the stage when I do experiment with saving/loading. I didn't touch it for some time, so it may not even work out of the box.


To save/load data internally, I'm using crude_json.h in which I mimic nlohmann API. Library is simple and bare bones. No descriptive errors while parsing json, no exceptions, no full nlohmann API parity (only some API functions are implemented). Library does job done, even passed many test with an exception of one related to encoding. It works under assumption input and output is utf-8.

Save data format is considered implementation detail and may change one day. Data was never guaranteed to be in json format. At this point however it is very unlikely this will ever change due to backward compatibility.

@aabilityuk
Copy link
Author

aabilityuk commented Dec 27, 2021

@thedmd
Thank you for feed back!!! I will take a deep look on the next branch you provided and try to find a beta you made about loading/saving logic!!! What a pity there is no out of the box desigion((

And hope to see the official implementation of save/load feature

P.S.
Run the blueprint-2 example!!! It's great, that is what i am looking for... thank you for new year present!!!

@aabilityuk
Copy link
Author

aabilityuk commented Dec 27, 2021

@thedmd

Wow, it's completly different technic in compare with the first blueprints example.
Dear developer of this great library let me ask a couple questions about the new blueprints2-example:

  1. How to add picture to the node background or to the node Middle? In the previous version i used a ImGui::Image() for this task.
  2. How to add other kind of nodes: Simple, Houdini, Tree?

Thank you one more time for an excellent tool you made for public!!!!

@thedmd
Copy link
Owner

thedmd commented Dec 29, 2021

Original blueprint example hold answers to both of your question. Code drawing custom looking nodes is there.

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