Requirements
The operating process of the digital circuit is briefly simulated, and the potential (simplified to L and h) is realized by C # WinForm.
Logical part of thinking
- The circuit is a graph structure, based on C # characteristics, Design node Class (node) and wire Class (Wired), and is generic.
- Because the circuit element can contain multiple node, the Super class unit (inherited from node, management node) is designed.
- The state of the circuit device has the status of L and H, so there is a state change and calculation, so the status Class (state) and the Mutable class (the original state and the new state) are designed.
- Each Circuit object (node, unit, wire) has a unique number, so design the Markable class (based on UUID).
- Nodes and units can handle events (click, Draw, and so on), adding interactive interface iinteractive and emulation interface isimuate.
- Design nodes and units to gain focus and lose focus events, triggered by onstateupdated and onvalueupdated.
- Constructing a new component can be overridden by deriving node and overloading it.
Interface section
- Using Directui idea to draw, API uses GDI + 's graphics, constructs the primitive method to refer to from @vczh C + + GUI Library/gaclib.
- Constructs the renderer factory graphicsrendererfactory and the entity factory Graphicselementfactory, the renderer holds the drawing handle (for GDI + does not need to hold the handle, and the GDI + object has a caching mechanism), and the entity holds the properties of the graphic.
- Each component has a separate Igraphicselement entity drawing interface collection to draw the image.
Core algorithms
Adopt state update mechanism, similar state machine, parallel optimization. (This algorithm is still defective and has a cyclic refresh problem)
Public Virtual void Update () { = = a.active). AsParallel (). ForAll (A = a.activate (activatetype.filterunit)); = a.active). AsParallel (). ForAll (A = a.advance (advancetype.nodetowire)); = a.active). AsParallel (). ForAll (A = a.advance (advancetype.nodetowire)); = a.active). AsParallel (). ForAll (A = a.advance (advancetype.wiretonode)); = a.active). AsParallel (). ForAll (A = a.advance (advancetype.wiretonode)); }
Test
Source
Https://github.com/bajdcc/SimuCircult
Class Library: Simucircult
Interface: WINSC
Analog Series (i)--digital circuit