miroiu / nodify

Highly performant and modular controls for node-based editors designed for data-binding and MVVM.
https://miroiu.github.io/nodify
MIT License
1.38k stars 224 forks source link

[Feature] Multi-Node Copy and Paste Functionality #119

Closed LinsCodes closed 4 months ago

LinsCodes commented 4 months ago

Hi,

First of all, I would like to express my gratitude for creating such a wonderful open-source project like Nodify. It has been incredibly helpful in my work and I truly appreciate the effort and dedication put into it.

I was wondering if it would be possible to implement a feature that allows for the copy and paste of multiple nodes. This functionality would greatly enhance the usability and efficiency of the tool, especially for complex projects involving numerous nodes.

Thank you for considering this request. I look forward to your feedback.

Best regards,

hendrikp commented 4 months ago

There is a seperate branch in the PRs where such function exists, in the main one its not useful as copy&paste depend on a data model being present. The library being view model only, thus doesnt have much sense to have such function. From experience i can say its doable pretty easy once datamodel and serialization is in place (just serialize Selected nodes, and deserialize them while offseting and switching selection).

LinsCodes commented 4 months ago

Thank you for your response. I appreciate the clarification regarding the separate branch and the rationale behind not including the copy & paste functionality in the main branch. It makes sense given the view model-only nature of the library.

I am currently working on implementing this feature as well. Serializing the selected nodes has been straightforward, but I am encountering an issue with restoring the connections when pasting. I am seeking advice on how to effectively manage the connections during the deserialization process. Any insights or suggestions would be greatly appreciated.

hendrikp commented 4 months ago

e.g. each node and also each connection should have an uuid Serialize list of nodes and connections indepently. connection is start uid + connector index + enduid + connector index.

On deserialize keep track of the node uids, generate new ones for all nodes/connections, replace them in the connections to be recreated. Create then all nodes with some offset on the graph. Then recreate the connections with the exchanged uids.

LinsCodes commented 4 months ago

Thank you for sharing your approach. I was also looking into the node serialization method on the feature/new-blueprint branch, and your explanation has provided me with a clearer understanding. My previous method of serializing and restoring all connections and nodes was indeed inefficient. Your insights have been very helpful.