internal_sigs = [signal.format(sig="q_synt{}".format(x)) for x in range(len(jks[0]))] y_outs = [y_out.format(sig="y{}".format(x+1), formula=ys[x]) for x in range(len(ys))] processes = [process.format(sig="q_synt{}".format(x), j_input=js[x], k_input=ks[x]) for x in range(len(js))] return document.format( ports="\n".join(signals), internal_sigs="\n".join(internal_sigs), y_outs="\n".join(y_outs), processes="\n".join(processes)) if __name__ == '__main__': s = u'\u25cbX\u2081\u2191\xb9Y\u2081X\u2082\u2191\xb2Y\u2082\u2193\xb9Y\u2083\u2193\xb2Y\u2084\u25cf' p = LSAAnalyser(parse(s)) p.analysis() conn, sigs = machine.make_machine(p.matrix, p.barenodes) mc = machine.encode_machine(conn, sigs) tbl = build_table(*mc) jks = jk(tbl) # ks = [generate_formula("K_{%d}" % (i), jk) for i, jk in enumerate(jks[1])] js = [generate_formula_vhdl(jk) for i, jk in enumerate(jks[0])] ks = [generate_formula_vhdl(jk) for i, jk in enumerate(jks[1])] # ys = [generate_formula("Y_{%d}" % (i), jk) for i, jk in enumerate(jks[1])] # print js # print js print p.in_signals vhdl(jks, len(p.in_signals), len(p.out_signals))
def _fill_signals(self): if self.model: self.ui.listSignals.clear() signals = sorted([ conditionname([x]) for x in self.model.in_signals + self.model.out_signals ]) self.ui.listSignals.insertItems(0, QtCore.QStringList(signals)) self.ui.listNodes.clear() nodes = sorted("%d: %d" % (k, x) for k, x in self.model.signals.iteritems()) self.ui.listNodes.insertItems(0, QtCore.QStringList(nodes)) machine = None if self.machine: machine = self.machine if machine: self.ui.listTransitions.clear() num = graph.renumerate(machine[0]) trans = [ "%d -> %d : %s" % (num.get_id(x[0] + 1), num.get_id(x[1] + 1), conditionname(x[2])) for x in machine[0] ] self.ui.listTransitions.insertItems(0, QtCore.QStringList(trans)) self.ui.listSignalsMachine.clear() nodes = sorted("%4d: %s" % (num.get_id(k + 1), conditionname(x)) for k, x in machine[1].iteritems()) self.ui.listSignalsMachine.insertItems(0, QtCore.QStringList(nodes)) if self.model: if len(self.model.barenodes) < 10: matrix = "" for i in self.model.matrix: matrix += ','.join(["%6s" % (x) for x in i]) + "\n" self.log(matrix) # model = QtCode.QStandartItemModel(2,3,self) model = MatrixModel(self.ui.matrix, self.model) self.ui.matrix.setModel(model) self.ui.matrix.resizeColumnsToContents() self.ui.listLoops.clear() node_names = { k: nodename(k, {k: x}) for k, x in self.model.barenodes.iteritems() } lines = [ '->'.join([node_names[i + 1] for i in l]) for l in self.model.find_loops() ] self.ui.listLoops.insertItems(0, QtCore.QStringList(lines)) self.ui.listPaths.clear() lines = [ '->'.join([node_names[i + 1] for i in l]) for l in self.model.find_paths() ] self.ui.listPaths.insertItems(0, QtCore.QStringList(lines)) if self.tr_table and self.model: jks = mtable.jk(self.tr_table) q_count = len(self.tr_table[0].q) x_count = len(self.model.in_signals) y_count = len(self.model.out_signals) funcs = [mtable.generate_formula("J_{%d}" % (i+1), jk) for i, jk in enumerate(jks[0])] + \ [mtable.generate_formula("J_{%dm}" % (i+1), mtable.minimize(jk, q_count, x_count)) for i, jk in enumerate(jks[0])] + \ [mtable.generate_formula("K_{%d}" % (i+1), jk) for i, jk in enumerate(jks[1])] + \ [mtable.generate_formula("K_{%dm}" % (i+1), mtable.minimize(jk, q_count, x_count)) for i, jk in enumerate(jks[1])] + \ [mtable.generate_formula("Y_{%d}" % (i+1), jk) for i, jk in enumerate(jks[2])] + \ [mtable.generate_formula("Y_{%dm}" % (i+1), mtable.minimize(jk, q_count, x_count)) for i, jk in enumerate(jks[2])] # mtable.latexmath2png.math2png(funcs, os.getcwd(), prefix = "adcs_") mtable.latexmath2png.math2png(funcs, os.getcwd(), prefix="adcs_") tr_model = TransitionModel(self.ui.tr_table, self.tr_table, self.model, jks) self.ui.tr_table.setModel(tr_model) self.ui.tr_table.resizeColumnsToContents() self.ui.vhdl_text.setPlainText(vhdl.vhdl(jks, x_count, y_count))
] processes = [ process.format(sig="q_synt{}".format(x), j_input=js[x], k_input=ks[x]) for x in range(len(js)) ] return document.format(ports="\n".join(signals), internal_sigs="\n".join(internal_sigs), y_outs="\n".join(y_outs), processes="\n".join(processes)) if __name__ == '__main__': s = u'\u25cbX\u2081\u2191\xb9Y\u2081X\u2082\u2191\xb2Y\u2082\u2193\xb9Y\u2083\u2193\xb2Y\u2084\u25cf' p = LSAAnalyser(parse(s)) p.analysis() conn, sigs = machine.make_machine(p.matrix, p.barenodes) mc = machine.encode_machine(conn, sigs) tbl = build_table(*mc) jks = jk(tbl) # ks = [generate_formula("K_{%d}" % (i), jk) for i, jk in enumerate(jks[1])] js = [generate_formula_vhdl(jk) for i, jk in enumerate(jks[0])] ks = [generate_formula_vhdl(jk) for i, jk in enumerate(jks[1])] # ys = [generate_formula("Y_{%d}" % (i), jk) for i, jk in enumerate(jks[1])] # print js # print js print p.in_signals vhdl(jks, len(p.in_signals), len(p.out_signals))
def _fill_signals(self): if self.model: self.ui.listSignals.clear() signals = sorted([conditionname([x]) for x in self.model.in_signals + self.model.out_signals]) self.ui.listSignals.insertItems(0, QtCore.QStringList(signals)) self.ui.listNodes.clear() nodes = sorted("%d: %d" % (k,x) for k,x in self.model.signals.iteritems()) self.ui.listNodes.insertItems(0, QtCore.QStringList(nodes)) machine = None if self.machine: machine = self.machine if machine: self.ui.listTransitions.clear() num = graph.renumerate(machine[0]) trans = ["%d -> %d : %s" % (num.get_id(x[0]+1), num.get_id(x[1]+1), conditionname(x[2])) for x in machine[0]] self.ui.listTransitions.insertItems(0, QtCore.QStringList(trans)) self.ui.listSignalsMachine.clear() nodes = sorted("%4d: %s" % (num.get_id(k+1),conditionname(x)) for k,x in machine[1].iteritems()) self.ui.listSignalsMachine.insertItems(0, QtCore.QStringList(nodes)) if self.model: if len(self.model.barenodes) < 10: matrix = "" for i in self.model.matrix: matrix += ','.join(["%6s" % (x) for x in i]) + "\n" self.log(matrix) # model = QtCode.QStandartItemModel(2,3,self) model = MatrixModel(self.ui.matrix, self.model) self.ui.matrix.setModel(model) self.ui.matrix.resizeColumnsToContents() self.ui.listLoops.clear() node_names = {k:nodename(k, {k: x}) for k,x in self.model.barenodes.iteritems()} lines = ['->'.join([node_names[i+1] for i in l]) for l in self.model.find_loops()] self.ui.listLoops.insertItems(0, QtCore.QStringList(lines)) self.ui.listPaths.clear() lines = ['->'.join([node_names[i+1] for i in l]) for l in self.model.find_paths()] self.ui.listPaths.insertItems(0, QtCore.QStringList(lines)) if self.tr_table and self.model: jks = mtable.jk(self.tr_table) q_count = len(self.tr_table[0].q) x_count = len(self.model.in_signals) y_count = len(self.model.out_signals) funcs = [mtable.generate_formula("J_{%d}" % (i+1), jk) for i, jk in enumerate(jks[0])] + \ [mtable.generate_formula("J_{%dm}" % (i+1), mtable.minimize(jk, q_count, x_count)) for i, jk in enumerate(jks[0])] + \ [mtable.generate_formula("K_{%d}" % (i+1), jk) for i, jk in enumerate(jks[1])] + \ [mtable.generate_formula("K_{%dm}" % (i+1), mtable.minimize(jk, q_count, x_count)) for i, jk in enumerate(jks[1])] + \ [mtable.generate_formula("Y_{%d}" % (i+1), jk) for i, jk in enumerate(jks[2])] + \ [mtable.generate_formula("Y_{%dm}" % (i+1), mtable.minimize(jk, q_count, x_count)) for i, jk in enumerate(jks[2])] # mtable.latexmath2png.math2png(funcs, os.getcwd(), prefix = "adcs_") mtable.latexmath2png.math2png(funcs, os.getcwd(), prefix = "adcs_") tr_model = TransitionModel(self.ui.tr_table, self.tr_table, self.model, jks) self.ui.tr_table.setModel(tr_model) self.ui.tr_table.resizeColumnsToContents() self.ui.vhdl_text.setPlainText(vhdl.vhdl(jks, x_count, y_count))