def CriaEnvelope(self, processo, canvas=None): lista = [] subprocessos = processo.childNodes for indice in range(subprocessos.length): if subprocessos.item(indice).nodeName != "#text": if subprocessos.item(indice).getAttribute("repr") == "env": shape = self.CriaEnvelope(subprocessos.item(indice), canvas) lista.append(shape) elif subprocessos.item(indice).getAttribute("repr") == "iterativo": shape = self.CriaIterativo(subprocessos.item(indice), canvas) lista.append(shape) elif subprocessos.item(indice).getAttribute("repr") != "detproj": shape = self.CriaProcessos(subprocessos.item(indice), canvas) lista.append(shape) funcoes = qGMFunc.qGMFunc() if processo.getAttribute("tipo") == "nondet1": env = funcoes.CriaSND(lista, canvas) if processo.getAttribute("tipo") == "paralelo": env = funcoes.CriaPP(lista, canvas) if processo.getAttribute("tipo") == "seq": env = funcoes.Sequencial(lista, canvas) return env
def SalvarEnvelope(self, arq, obj): funcoes = qGMFunc.qGMFunc() posic = funcoes.PosicaotoString(obj.getposicao()) tmp = obj.getshapesall() if obj.getrepr() == "nondet": arq.write('<process repr="env" tipo="' + (obj.getrepr() + "1") + '" pos="' + posic + '">\n') param = "" for element in tmp: if element.gettipo() == "macro": if param == "": param = element.getParametro() else: param += ";" + element.getParametro() arq.write('<process repr="detproj" parametro="' + param + '"></process>\n') else: arq.write('<process repr="env" tipo="' + obj.getrepr() + '" pos="' + posic + '">\n') for indice in tmp: if indice.gettipo() == "terminicio": self.SalvarTermInicio(arq, indice) elif indice.gettipo() == "termfim": self.SalvarTermFim(arq, indice) elif indice.gettipo() == "envelope": self.SalvarEnvelope(arq, indice) elif indice.gettipo() == "conselem": self.SalvarConsElem(arq, indice) elif indice.gettipo() == "projection": self.SalvarProjectionComponent(arq, indice) elif indice.gettipo() == "probability": self.SalvarProbabilityComponent(arq, indice) elif indice.gettipo() == "iterativo": self.SalvarIterativo(arq, indice) elif indice.gettipo() == "partquantum": self.SalvarQuantumProcess(arq, indice) elif indice.gettipo() == "macro": childs = indice.getChilds() self.SalvarMacro(arq, indice) # Save the macro for child in childs: if child.gettipo() == "envelope": self.SalvarEnvelope(arq, child) # Save the process representation of the macro elif child.gettipo() == "iterativo": self.SalvarIterativo(arq, child) arq.write("</process>\n") arq.write("</process>\n")
def BuildCircuit(self, steps, state): self.parent.Desmarca() self.parent.ordem = [] funcoes = qGMFunc.qGMFunc() self.RepresentationChoice() self.parent.applyToAll = 1 shapes = [] for indice in range(len(steps)): steps[indice] = self.ArrumaOperacoes(steps[indice]) shapes.append(self.CriaOperacoes(steps[indice])) self.parent.applyToAll = 0 circuit = None if self.representation == "Proc. Synchronization": circuit = "sync" shape = self.parent.Sequencial(None, shapes, self.parent.rightwin, circuit) if shape == None: shape = self.parent.shapes[len(self.parent.shapes) - 1] x = 900 + (shape.gettamx()/2) y = 1200 + (shape.gettamy()/2) shape.SetX(x) shape.SetY(y) shape.ajuste(x, y) dc = wx.ClientDC(self.parent) self.parent.rightwin.PrepareDC(dc) self.parent.LimpaTela() self.parent.DimensionaAreaDesenho(shape) self.parent.rightwin.Refresh() qme = qME.Memoria( None, -1, qME.Memoria.translate.translateById("memory_main_title") ) qme.Centre() qme.Show(1) qme.SetFields(state)
def SalvarArq(self, arquivo, shapes): # Salvar Arquivo try: arq = open(arquivo, "w") posicao = [] for indice in shapes: if indice.gettipo() not in ["terminicio", "termfim", "macro"]: posicao.append(indice.getposicao()) funcoes = qGMFunc.qGMFunc() posic = funcoes.arrumaPosicao(posicao) posic = funcoes.PosicaotoString(posic) arq.write('<save arq="' + arquivo + '" pos="' + posic + '">\n') for indice in shapes: if indice.gettipo() == "terminicio": self.SalvarTermInicio(arq, indice) elif indice.gettipo() == "termfim": self.SalvarTermFim(arq, indice) elif indice.gettipo() == "envelope": self.SalvarEnvelope(arq, indice) elif indice.gettipo() == "iterativo": self.SalvarIterativo(arq, indice) elif indice.gettipo() == "macro": ## Gets the processes representation of the macro ## child = indice.getChilds() self.SalvarMacro(arq, indice) # Save the macro if child.gettipo() == "envelope": self.SalvarEnvelope(arq, child) # Save the process representation of the macro elif child.gettipo() == "iterativo": self.SalvarIterativo(arq, child) elif child.gettipo() == "partquantum": self.SalvarQuantumProcess(arq, child) arq.write("</process>\n") elif indice.gettipo() == "conselem": self.SalvarConsElem(arq, indice) elif indice.gettipo() == "partquantum": self.SalvarQuantumProcess(arq, indice) elif indice.gettipo() == "projection": self.SalvarProjectionComponent(arq, indice) elif indice.gettipo() == "probability": self.SalvarProbabilityComponent(arq, indice) arq.write("</save>\n") arq.close except UnboundLocalError: pass
def CriaPP(self, operations): funcoes = qGMFunc.qGMFunc() desenho = qGMDraw.qGMDraw() position = [1, 1] lista = [] parametro = "" for pos in range ((2**self.qubits)): shape = ConsElem.ConsElem( str(self.qubits), operations, str(pos), "BLACK", position[0], position[1], self.parent.rightwin ) shape.setParametro( parametro ) desenho.Draw2( shape, position[0], position[1], self.parent.rightwin ) lista.append(shape) while (len(lista) != 1): envs = [] for indice in range (0,len(lista),2): objs = [lista[indice], lista[indice + 1]] envs.append (funcoes.CriaPP( objs, self.parent.rightwin )) lista = envs return lista[0]
def SalvarIterativo(self, arq, obj): funcoes = qGMFunc.qGMFunc() subobj = obj.getObjeto() x = subobj.GetX() y = subobj.GetY() arq.write( '<process repr="iterativo" tipo="' + obj.getrepr() + '" range="' + obj.getRange() + '" acao="' + obj.getAcao() + '" x="' + str(x) + '" y="' + str(y) + '" cor="' + str(obj.getColor()) + '">\n' ) if subobj.gettipo() == "envelope": self.SalvarEnvelope(arq, subobj) if subobj.gettipo() == "conselem": self.SalvarConsElem(arq, subobj) if subobj.gettipo() == "projection": self.SalvarProjectionComponent(arq, subobj) if subobj.gettipo() == "somdet": self.SalvarSomDet(arq, subobj) if subobj.gettipo() == "universal": self.SalvarUniversal(arq, subobj) if subobj.gettipo() == "existencial": self.SalvarExistencial(arq, subobj) if subobj.gettipo() == "macro": self.SalvarMacro(arq, subobj) if subobj.gettipo() == "iterativo": self.SavarIterativo(arq, subobj) arq.write("</process>\n")
def handleSlideshow( self, slideshow, canvas ): funcoes = qGMFunc.qGMFunc() circuit = slideshow.firstChild for child in circuit.childNodes: if child.nodeName == "initialState": self.qubits = int(child.getAttribute("qubits")) s_qubits = child.getAttribute("state") if child.nodeName == "simulation": simulation = child.getElementsByTagName("step") steps = [] for indice in range (simulation.length): processos = simulation.item(indice)._get_childNodes() lista = "" for indice in range (processos.length): if processos.item( indice ).nodeName == "gate": name = processos.item( indice ).getAttribute("name") name = self.GateName(name) lista = lista + "," + name steps.append(lista[1:len(lista)]) self.BuildCircuit(steps, s_qubits)