def gate_from_name(name, fen): gb.debug("Création d'une SOUS gate {}".format(name)) with open("lib/structs/" + name, "r") as f: data = f.readlines() final_gate = New_gate(fen, name) final_inputs, final_outputs = [], [] nodes = dict() for line in data: # Création de la table de relation id : node element, name, infos1, infos2 = line.split(":") if element == "Gate": load_hidden_gate_from_line(nodes, line, fen) elif element == "Node": # si c'est une node "main", on la crée if name == "main_input": node = Hidden_input_node(final_gate, fen) nodes[int(infos1)] = node final_inputs += [node] elif name == "main_output": node = Hidden_output_node(final_gate, fen) nodes[int(infos1)] = node final_outputs += [node] update_links(data, nodes) Gate.__init__(final_gate, final_inputs, final_outputs) return final_gate
def update_all(self): """ Deux update sont nécéssaire pour que les flip flop marchent Un update se fait en 3 étapes : 1) On update les nodes d'entrée, afin de mettre à jour leur date de MAJ et mettre à jour l'affichage, meme de celles qui ne sont pas reliées 2) On update toutes les gates, afin de mettre à jour les gates, meme celles qui ne sont pas connectées 3) On update en partant des nodes de sortie """ t_in = time.perf_counter() gb.PRE_UPDATE() # 1) for node in self.main_gate.inputs: node.need_previous() # 2) for gate in self.gates: for output_node in gate.outputs: output_node.need_previous() # 3) for node in self.main_gate.outputs: node.need_previous() t_out = time.perf_counter() gb.debug("update time = {}".format(t_out - t_in))
def create_gate(self, evt): gb.debug("Création d'une Gate {}".format(self.gate_name)) if self.gate_name == "AND": gate_from_and(self.fen) return if self.gate_name == "NOT": gate_from_not(self.fen) return with open("lib/structs/" + self.gate_name, "r") as f: data = f.readlines() final_gate = New_gate(self.fen, self.gate_name) final_inputs, final_outputs = [], [] nodes = dict() for line in data: # Création de la table de relation id : node element, name, infos1, infos2 = line.split(":") if element == "Gate": load_hidden_gate_from_line(nodes, line, self.fen) elif element == "Node": # si c'est une node "main", on la crée if name == "main_input": node = Input_node(final_gate, self.fen) nodes[int(infos1)] = node final_inputs += [node] elif name == "main_output": node = Output_node(final_gate, self.fen) nodes[int(infos1)] = node final_outputs += [node] update_links(data, nodes) Gate.__init__(final_gate, final_inputs, final_outputs) update_gate_aff(self.fen, final_gate)
def debug(node): gb.debug("[NEED] {} {} {} id = {}".format(node.get_type(), node.gate.name, node.active, node.id))
def clic(self, evt): gb.debug("_____________________________________________")
def disable_bindings(self): gb.debug("Bindings disabled") for to_unbind in self.bindings: self.unbind(to_unbind)
def enable_bindings(self): gb.debug("Bindings enabled") for to_bind in self.bindings: self.bind(to_bind, self.bindings[to_bind])
def GB_INFO(evt): gb.debug("____________________________________________") gb.debug("Nombre totale de portes créées : {}".format(gb.GATE_NUMBER)) gb.debug("Nombre totale de node créées : {}".format(gb.NODE_NUMBER)) gb.debug("Nombre de nodes mises à jour sur la dernière update : {}".format( gb.UPDATE_NUMBER))