digitaljs icon indicating copy to clipboard operation
digitaljs copied to clipboard

Change number of bits after gate initialization

Open ialokim opened this issue 4 years ago • 1 comments

As the GateView and the gate's functionality currently seems to be defined once during initialization, I assume there is no way to change the number of (input or output) bits of some gate afterwards. Is that correct?

If so, do you have some idea where and how this functionality could be added? I would like to look into it, as we would like to use your library with this possibility.

ialokim avatar Jan 24 '20 21:01 ialokim

Changing the gate's input/output characteristics is currently not possible, as it risks leaving the circuit in some weird, inconsistent state, and breaking the simulation. Backbone.js, the library used by JointJS and DigitalJS for representing graphs, allows to listen to changes of model attributes. If I was adding a feature like this, I would add listeners to relevant attributes, which would respond by fixing up the graph so that it is still consistent after the change. If changing the number of bits, this would probably require disconnecting every connection to the changed input/output. (Another possibility would be to allow the invalid connection, but have the simulation detect it and display the problem in the UI in some way.) One would also need to ensure that the view gets re-rendered. As this is a functionality which seems bug-prone, tests would need to be added to verify correctness.

tilk avatar Jan 25 '20 12:01 tilk