2. Fundamentals module - Siromanec/logic_discr GitHub Wiki
Description
It is a basic module that contains all basic mechanics and the simplest abstract classes
Classes
Pin
An abstract class for pins - objects which connect circuits or gates with each other. They are responsible for transferring signals from one gate to another.
Attributes:
- Id - each pin is unique
- _circuit - contains a reference to the owner
- _state - True or False - depends on the signal it receives
- _reaction_area - an area on canvas that is responsible for this pin
- _connected_line_tags - contains tags of lines that connect this pin
Methods:
- get_state()
- set_state()
- get_circuit()
- set_reaction_area()
- get_reaction_area()
- append_connected_line_tag()
- get_connected_line_tags()
- remove_connected_line_tag()
- check_dot() - checks whether given coordinates refer to this pin
- is_connected() - abstract method
InputPin(Pin)
A type of pin responsible for receiving signals.
Attributes:
- _parent - a pin which the current pin is “listening to”
Methods:
- update_state()
- set_parent()
- remove_parent()
- get_parent()
- is_connected() - input pin can be connected only to one other pin, so we often have to check its connection.
OutputPin(Pin)
A type of pin responsible for sending signals.
Attributes:
- _children - contains a list of input pins, which are listening to this one.
- _is_active - False if the circuit which owns this pin is not fully connected or it depends on such circuit
Methods:
- update_state()
- add_child()
- remove_child()
- get_children()
- is_connected() - True if has children
- is_active() - returns _is_active
- set_activeness() - sets _is_active
BaseCircuitElement - (BCE)
An abstract class for all elements on the board.
Attributes:
- _input_pins - a list of input pins of this gate/circuit
- _output_pins - a list of output pins of this gate/circuit
- _board - everything on the program is connected to Board() object
- Id - each gate or circuit is unique
- Img_object - contains a reference to corresponding the image on the canvas
- Img_path - a path to the image
- _img_coords
- _img_width
- _img_height
- changes_img - True if an object can change its appearance. Helps in optimization
Methods:
- get_inputs()
- get_outputs()
- get_board()
- set_img_coords()
- get_img_coords()
- set_img_width()
- get_img_width()
- set_img_height()
- get_img_height()
- get_dependent_circuits() - returns a list of other circuits, which have input pins connected to output pins of this circuit
- get_parent_circuits() - returns a list of other circuits, which have output pins connected to input pins of this circuit
- is_fully_connected() - False if exists an input pin, which have no parent
- operation() - abstract method, different for each gate. Here the logic of an element is defined.
- set_reaction_areas_for_pins() - abstract method. Sets pins’ reaction areas on relative values.
- update_reaction_areas() - abstract method. Change pins’ reaction areas on absolute values.
- check_dot_in_img() - checks whether user clicked on this element.
- update() - checks if all input pins are connected, updates them and calls operation()
- connection_problems_processing() - makes lines of the corresponding pins red if something is wrong with connections.
- destroy() - abstract method for deleting circuit, is used when some additional actions are needed to stop element’s influence on a program.
Board:
The object responsible for all interactions between elements. It links all parts into a whole.
Attributes:
- _circuits_list - contains all elements which are directly placed on the board
- _images_list - contains references to the images of placed elements
- canvas - a reference to the canvas, on which the board is drawn
- Img_cache - dictionary for optimization
Methods:
- get_canvas()
- add_to_img_list()
- clear() - deletes all elements from the board
- connect_pins()
- disconnect_pins()
- remove_element()
- create_element()
- get_circuits_list()
- get_all_pins()
- update_board() - updates all elements in the topological order
- update_images() - updates images of elements which have self.changes_img == True