Blazor-Diagrams / Blazor.Diagrams

A fully customizable and extensible all-purpose diagrams library for Blazor
https://blazor-diagrams.zhaytam.com
MIT License
921 stars 177 forks source link

Execution Engine question #203

Closed kiranmaya closed 1 year ago

kiranmaya commented 2 years ago

Hi, after creating the add two number nodes, how to execute it?. say it has result out return float, how to read that value.

zHaytam commented 2 years ago

Hello, you will have to figure that on your own based on your application and requirements. A custom engine can easily execute your nodes since you have access to everything you need. It just depends on how you want to run it and show it etc...

kiranmaya commented 2 years ago

@zHaytam can provide me a simple example of two nodes.I don't know where to start, how to connect two instances in a sequence etc.

314159265meow commented 2 years ago

Hello, as part of the evaluation of this library I did something like that. Animation

The problem is that it was part of a bigger project and I can't just post the code here. I will try to give you a gist of how I did it:

Each node is a custom node that implements a Process() method.
The ports are custom ports with an IsInput and a Value property.

"Run Engine" selects all starting nodes (those with 0 links on the input ports and at least one output link). and calls the Process() method for each of these. In the process method the node either uses it's state (e.g. value of the checkbox or input field) or the Value property of it's connected ports to determine it's own Value.
After that I take all connected nodes from the current nodes, do the same process again till there are no nodes left.

This is not the best way to do it, usually you want your data separate from your presentation, e.g. to run your "engine" without graphical representation, but it was fun and quick to implement. I will see if I can copy the relevant parts to a new project and post it here later.

kiranmaya commented 2 years ago

@314159265meow Yep , this is exactly what i am looking for .plz share if feasible. After that, I take all connected nodes from the current nodes, and do the same process again till there are no nodes left. I m not getting this , any ideas, on how to move value from one node to another node. say I have List nodesProcess, here looping and process calling is fine, but how to grab to out pin value pass it to, which output pin from a current node is transferred to next node input.

314159265meow commented 2 years ago

Hi, sorry for the delay, I had to work on some other projects the past days.

You can check out the demo here https://github.com/314159265meow/engine-demo

Please keep in mind that this was a "for fun" project from over a year ago. I just copied the code now and fixed some errors. There are still a lot of bugs, e.g. you should only connect nodes in order of processing, otherwise the program will become stuck in a loop. But you should be able to do the same thing as in the image above.

About your question you can have a look at the AdderNode.Process() method.

After reading this code again I think this could be done much more easily (and I see some bugs), but in general you want to:

Hope this helps a bit.

kiranmaya commented 2 years ago

@314159265meow Thanks for the share, will check it out.