Ejemplo n.º 1
0
class Ui_bombaCurva(QtGui.QDialog):
    def __init__(self, curva=[], parent=None):
        """curva: Parametro opcional indicando la curva de la bomba"""
        super(Ui_bombaCurva, self).__init__(parent)
        self.setWindowTitle(QtGui.QApplication.translate("pychemqt", "Pump curves dialog"))
        self.showMaximized()

        self.gridLayout = QtGui.QGridLayout(self)
        self.botones = QtGui.QDialogButtonBox(QtGui.QDialogButtonBox.Apply|QtGui.QDialogButtonBox.Open|QtGui.QDialogButtonBox.Save|QtGui.QDialogButtonBox.Reset, QtCore.Qt.Vertical)
        self.botones.clicked.connect(self.botones_clicked)
        self.gridLayout.addWidget(self.botones,1,1,3,1)
        self.gridLayout.addItem(QtGui.QSpacerItem(10,10,QtGui.QSizePolicy.Fixed,QtGui.QSizePolicy.Fixed),1,2,3,1)
        self.gridLayout.addWidget(QtGui.QLabel(QtGui.QApplication.translate("pychemqt", "Curves")),1,3)
        self.lista=QtGui.QComboBox()
        self.lista.currentIndexChanged.connect(self.cambiarCurvaVista)
        self.gridLayout.addWidget(self.lista,1,4)
        self.gridLayout.addWidget(QtGui.QLabel(QtGui.QApplication.translate("pychemqt", "Diameter")),2,3)
        self.diametro=Entrada_con_unidades(int, width=60, textounidad='"')
        self.gridLayout.addWidget(self.diametro,2,4)
        self.gridLayout.addWidget(QtGui.QLabel(QtGui.QApplication.translate("pychemqt", "RPM")),3,3)
        self.rpm=Entrada_con_unidades(int, width=60, textounidad="rpm")
        self.gridLayout.addWidget(self.rpm,3,4)
        self.gridLayout.addItem(QtGui.QSpacerItem(20,20,QtGui.QSizePolicy.Fixed,QtGui.QSizePolicy.Fixed),4,1,1,4)

        self.Tabla=Tabla(4, horizontalHeader=[QtGui.QApplication.translate("pychemqt", "Flowrate"), QtGui.QApplication.translate("pychemqt", "Head"), QtGui.QApplication.translate("pychemqt", "Power"), QtGui.QApplication.translate("pychemqt", "NPSH")], verticalOffset=1, filas=1, stretch=False)
        self.Tabla.setColumnWidth(0, 100)
        self.unidadesCaudal = QtGui.QComboBox()
        self.Tabla.setCellWidget(0, 0, self.unidadesCaudal)
        self.Tabla.setColumnWidth(1, 80)
        self.unidadesCarga = QtGui.QComboBox()
        self.Tabla.setCellWidget(0, 1, self.unidadesCarga)
        self.Tabla.setColumnWidth(2, 80)
        self.unidadesPotencia = QtGui.QComboBox()
        self.Tabla.setCellWidget(0, 2, self.unidadesPotencia)
        self.Tabla.setColumnWidth(3, 80)
        self.unidadesNPSH = QtGui.QComboBox()
        self.Tabla.setCellWidget(0, 3, self.unidadesNPSH)
        self.Tabla.setRowHeight(0, 24)
        self.Tabla.setFixedWidth(360)
        self.Tabla.setConnected()
        self.Tabla.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOn)
        self.gridLayout.addWidget(self.Tabla,5,1,1,4)
        self.gridLayout.addItem(QtGui.QSpacerItem(20,20,QtGui.QSizePolicy.Fixed,QtGui.QSizePolicy.Fixed),1,5,5,1)

        self.checkCarga = QtGui.QCheckBox(QtGui.QApplication.translate("pychemqt", "Heat"))
        self.gridLayout.addWidget(self.checkCarga,1,6)
        self.checkPotencia = QtGui.QCheckBox(QtGui.QApplication.translate("pychemqt", "Power"))
        self.gridLayout.addWidget(self.checkPotencia,1,7)
        self.checkNPSH = QtGui.QCheckBox(QtGui.QApplication.translate("pychemqt", "NPSH"))
        self.gridLayout.addWidget(self.checkNPSH,1,8)
        self.rejilla = QtGui.QCheckBox(QtGui.QApplication.translate("pychemqt", "Grid"))
        self.rejilla.toggled.connect(self.rejilla_toggled)
        self.gridLayout.addWidget(self.rejilla,1,9)
        self.gridLayout.addItem(QtGui.QSpacerItem(1000,20,QtGui.QSizePolicy.Expanding,QtGui.QSizePolicy.Fixed),1,10)
        self.Plot = Plot(self, width=5, height=1, dpi=100)
        self.gridLayout.addWidget(self.Plot,2,6,4,5)
        

        self.buttonBox = QtGui.QDialogButtonBox(QtGui.QDialogButtonBox.Ok|QtGui.QDialogButtonBox.Cancel)
        self.buttonBox.accepted.connect(self.accept)
        self.buttonBox.rejected.connect(self.reject)
        self.gridLayout.addWidget(self.buttonBox,6,9,1,2)
        
        if curva:
            self.curvas=curva
            for i in curva:
                self.lista.addItem(str(i[0])+'", '+str(i[1])+" rpm")
            self.lista.setCurrentIndex(self.lista.count()-1)
            self.cambiarCurvaVista(self.lista.count()-1)

#            self.curva=curva[-1]
#            self.diametro.setValue(self.curva[0])
#            self.rpm.setValue(self.curva[1])
#            self.Tabla.setMatrix(self.curva[2:])
#            self.Tabla.addRow()
            self.actualizarPlot()
        else:
            self.curva=[]
            
        for i in Length.__text__:
            self.unidadesCarga.addItem(i)
            self.unidadesNPSH.addItem(i)
        for i in VolFlow.__text__:
            self.unidadesCaudal.addItem(i)
        for i in Power.__text__:
            self.unidadesPotencia.addItem(i)
            
        self.oldIndices=[0, 0, 0, 0]
        self.unidadesCaudal.currentIndexChanged.connect(partial(self.cambiar_unidades, 0, VolFlow, "VolFlow"))
        self.unidadesCarga.currentIndexChanged.connect(partial(self.cambiar_unidades, 1, Length,"Head", ))
        self.unidadesPotencia.currentIndexChanged.connect(partial(self.cambiar_unidades, 2, Power, "Power"))
        self.unidadesNPSH.currentIndexChanged.connect(partial(self.cambiar_unidades, 3, Length,"Head", ))
        
        Config=config.getMainWindowConfig()
        self.unidadesCaudal.setCurrentIndex(Config.getint("Units","QLiq"))
        self.unidadesCarga.setCurrentIndex(Config.getint("Units","Head"))
        self.unidadesPotencia.setCurrentIndex(Config.getint("Units","Power"))
        self.unidadesNPSH.setCurrentIndex(Config.getint("Units","Head"))
        
        self.checkCarga.toggled.connect(self.actualizarPlot)
        self.checkPotencia.toggled.connect(self.actualizarPlot)
        self.checkNPSH.toggled.connect(self.actualizarPlot)


    def botones_clicked(self, boton):
        if boton == self.botones.button(QtGui.QDialogButtonBox.Reset):
            self.diametro.clear()
            self.rpm.clear()
            self.Tabla.clear()
            self.checkCarga.setChecked(False)
            self.checkPotencia.setChecked(False)
            self.checkNPSH.setChecked(False)
            self.rejilla.setChecked(False)
            
        elif boton == self.botones.button(QtGui.QDialogButtonBox.Open):
            fname = unicode(QtGui.QFileDialog.getOpenFileName(self, QtGui.QApplication.translate("pychemqt", "Open curve file"), "./", "cpickle file (*.pkl);;All files (*.*)"))
            if fname:
                with open(fname, "r") as archivo:
                    curvas=cPickle.load(archivo)
                self.curvas=curvas
                self.curva=curvas[-1]
                self.lista.clear()
                self.lista.blockSignals(True)
                for i in curvas:
                    self.lista.addItem(str(i[0])+'", '+str(i[1])+" rpm")
                self.lista.blockSignals(False)
                self.lista.setCurrentIndex(self.lista.count()-1)
                self.cambiarCurvaVista(self.lista.count()-1)
                self.actualizarPlot()
                
        elif boton == self.botones.button(QtGui.QDialogButtonBox.Apply):
            txt=str(self.diametro.value)+'", '+str(self.rpm.value)+" rpm"
            indice=self.lista.findText(txt)
            if indice ==-1:
                self.lista.addItem(txt)
                self.curva=self.CalcularCurva()
                self.curvas.append(self.curva)
                self.lista.setCurrentIndex(self.lista.count()-1)
                self.actualizarPlot()
            else:
                self.curva=self.CalcularCurva()
                self.curvas[indice]=self.curva
                self.lista.setCurrentIndex(indice)
                self.actualizarPlot()
                
        else:
            fname = unicode(QtGui.QFileDialog.getSaveFileName(self, QtGui.QApplication.translate("pychemqt", "Save curve to file"), "./", "cpickle file (*.pkl)"))
            if fname:
                if fname.split(".")[-1]!="pkl":
                    fname+=".pkl"
                cPickle.dump(self.curvas, open(fname, "w"))

    def CalcularCurva(self):
        caudal=[]
        carga=[]
        potencia=[]
        NPSH=[]
        for i in range(1, self.Tabla.rowCount()-1):
            q=VolFlow(float(self.Tabla.item(i, 0).text()), VolFlow.__units__[self.unidadesCaudal.currentIndex()])
            caudal.append(q)
            h=Length(float(self.Tabla.item(i, 1).text()), Length.__units__[self.unidadesCarga.currentIndex()])
            carga.append(h)
            P=Power(float(self.Tabla.item(i, 2).text()),Power.__units__[self.unidadesPotencia.currentIndex()])
            potencia.append(P)
            n=Length(float(self.Tabla.item(i, 3).text()), Length.__units__[self.unidadesNPSH.currentIndex()])
            NPSH.append(n)
        return [self.diametro.value, self.rpm.value, caudal, carga, potencia, NPSH]

    def cambiar_unidades(self, col, unit, magn, i):
        text=self.Tabla.getColumn(col)
        old_i=self.oldIndices[col]
        self.Tabla.blockSignals(True)
        for fila in range(0, len(text)):
            a=unit(text[fila], units[magn][old_i]).__getattribute__(units[magn][i])
            self.Tabla.item(fila+1, col).setText(representacion(a))
        self.Tabla.blockSignals(False)
        self.oldIndices[col]=i
        
    def cambiarCurvaVista(self, ind):
        self.curva=self.curvas[ind]
        self.diametro.setValue(self.curva[0])
        self.rpm.setValue(self.curva[1])
        q=[VolFlow(i).__getattribute__(VolFlow.__units__[self.unidadesCaudal.currentIndex()]) for i in self.curva[2]]
        h=[Length(i).__getattribute__(Length.__units__[self.unidadesCarga.currentIndex()]) for i in self.curva[3]]
        P=[Power(i).__getattribute__(Power.__units__[self.unidadesPotencia.currentIndex()]) for i in self.curva[4]]
        n=[Length(i).__getattribute__(Length.__units__[self.unidadesNPSH.currentIndex()]) for i in self.curva[5]]
        self.Tabla.setMatrix(transpose([q, h, P, n]))
        self.Tabla.addRow()

    def actualizarPlot(self):
        #FIXME: mejorar el manejo de gráficas, básicamente empollarse matplotlib, opcional para profesionalizar el gráfico
        Carga=self.checkCarga.isChecked()
        Potencia=self.checkPotencia.isChecked()
        NPSH=self.checkNPSH.isChecked()
        self.Plot.fig.clear()
        share=None
        self.Plot.carga=[]
        self.Plot.potencia=[]
        self.Plot.npsh=[]
        total=Carga+Potencia+NPSH
        actual=1
        if Carga:
            self.Plot.ax1 = self.Plot.fig.add_subplot(total, 1, actual)
            self.Plot.ax1.grid(self.rejilla.isChecked())
            self.Plot.ax1.set_title("Curva H/Q", size='14')
            self.Plot.ax1.set_ylabel("H, m", size='12')
            share=self.Plot.ax1
            actual+=1
            for curva in self.curvas:
                Q=curva[2]
                h=curva[3]
                self.Plot.carga+=self.Plot.ax1.plot(Q, h, label=str(curva[0])+'", '+str(curva[1])+" rpm")
            self.Plot.ax1.legend()

        if Potencia:
            self.Plot.ax2 = self.Plot.fig.add_subplot(total, 1, actual, sharex=share)
            self.Plot.ax2.grid(self.rejilla.isChecked())
            self.Plot.ax2.set_ylabel("P, kW", size='12')
            share=self.Plot.ax2
            actual+=1
            for curva in self.curvas:
                Q=curva[2]
                Pot=curva[4]
                self.Plot.potencia+=self.Plot.ax2.plot(Q, Pot, label=str(curva[0])+'", '+str(curva[1])+" rpm")
            self.Plot.ax2.legend(loc='upper left')
                
        if NPSH:
            self.Plot.ax3 = self.Plot.fig.add_subplot(total, 1, actual, sharex=share)
            self.Plot.ax3.grid(self.rejilla.isChecked())
            self.Plot.ax3.set_ylabel("NPSH, m", size='12')
            for curva in self.curvas:
                Q=curva[2]
                npsh=curva[5]
                self.Plot.npsh+=self.Plot.ax3.plot(Q, npsh, label=str(curva[0])+'", '+str(curva[1])+" rpm")
            self.Plot.ax3.legend(loc='upper left')

        if share:
            share.set_xlabel("Q, $m^3/s$", horizontalalignment='left', size='12')


        
#        self.Plot.ax2.set_title("Curva P/Q", size='14')
#        self.Plot.ax3.set_title("Curva NPSH/Q", size='14')
#        self.Plot.ax1.set_xlabel("Q, $m^3/s$", horizontalalignment='left', size='12')
#        self.Plot.ax2.set_xlabel("Q, $m^3/s$", horizontalalignment='left', size='12')
        #otras rpm
#        for rpm in [1200., 1500., 1800., 2100.]:
#            Q2=[]
#            h2=[]
#            for i in range(len(Q)):
#                Q2.append(Q[i]*rpm/1400)
#                h2.append(h[i]*rpm**2/1400**2)
#            self.Plot.ax1.plot(Q2, h2)


#        self.Plot.tight_layout()       #Necesita matploblib >=1.1
        self.Plot.draw()

    def rejilla_toggled(self, bool):
        self.Plot.ax1.grid(bool)
        self.Plot.ax2.grid(bool)
        self.Plot.ax3.grid(bool)
        self.Plot.draw()
Ejemplo n.º 2
0
class Ui_bombaCurva(QtGui.QDialog):
    def __init__(self, curva=[], parent=None):
        """curva: Parametro opcional indicando la curva de la bomba"""
        super(Ui_bombaCurva, self).__init__(parent)
        self.setWindowTitle(
            QtGui.QApplication.translate("pychemqt", "Pump curves dialog"))
        self.showMaximized()

        self.gridLayout = QtGui.QGridLayout(self)
        self.botones = QtGui.QDialogButtonBox(
            QtGui.QDialogButtonBox.Apply | QtGui.QDialogButtonBox.Open
            | QtGui.QDialogButtonBox.Save | QtGui.QDialogButtonBox.Reset,
            QtCore.Qt.Vertical)
        self.botones.clicked.connect(self.botones_clicked)
        self.gridLayout.addWidget(self.botones, 1, 1, 3, 1)
        self.gridLayout.addItem(
            QtGui.QSpacerItem(10, 10, QtGui.QSizePolicy.Fixed,
                              QtGui.QSizePolicy.Fixed), 1, 2, 3, 1)
        self.gridLayout.addWidget(
            QtGui.QLabel(QtGui.QApplication.translate("pychemqt", "Curves")),
            1, 3)
        self.lista = QtGui.QComboBox()
        self.lista.currentIndexChanged.connect(self.cambiarCurvaVista)
        self.gridLayout.addWidget(self.lista, 1, 4)
        self.gridLayout.addWidget(
            QtGui.QLabel(QtGui.QApplication.translate("pychemqt", "Diameter")),
            2, 3)
        self.diametro = Entrada_con_unidades(int, width=60, textounidad='"')
        self.gridLayout.addWidget(self.diametro, 2, 4)
        self.gridLayout.addWidget(
            QtGui.QLabel(QtGui.QApplication.translate("pychemqt", "RPM")), 3,
            3)
        self.rpm = Entrada_con_unidades(int, width=60, textounidad="rpm")
        self.gridLayout.addWidget(self.rpm, 3, 4)
        self.gridLayout.addItem(
            QtGui.QSpacerItem(20, 20, QtGui.QSizePolicy.Fixed,
                              QtGui.QSizePolicy.Fixed), 4, 1, 1, 4)

        self.Tabla = Tabla(
            4,
            horizontalHeader=[
                QtGui.QApplication.translate("pychemqt", "Flowrate"),
                QtGui.QApplication.translate("pychemqt", "Head"),
                QtGui.QApplication.translate("pychemqt", "Power"),
                QtGui.QApplication.translate("pychemqt", "NPSH")
            ],
            verticalOffset=1,
            filas=1,
            stretch=False)
        self.Tabla.setColumnWidth(0, 100)
        self.unidadesCaudal = QtGui.QComboBox()
        self.Tabla.setCellWidget(0, 0, self.unidadesCaudal)
        self.Tabla.setColumnWidth(1, 80)
        self.unidadesCarga = QtGui.QComboBox()
        self.Tabla.setCellWidget(0, 1, self.unidadesCarga)
        self.Tabla.setColumnWidth(2, 80)
        self.unidadesPotencia = QtGui.QComboBox()
        self.Tabla.setCellWidget(0, 2, self.unidadesPotencia)
        self.Tabla.setColumnWidth(3, 80)
        self.unidadesNPSH = QtGui.QComboBox()
        self.Tabla.setCellWidget(0, 3, self.unidadesNPSH)
        self.Tabla.setRowHeight(0, 24)
        self.Tabla.setFixedWidth(360)
        self.Tabla.setConnected()
        self.Tabla.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOn)
        self.gridLayout.addWidget(self.Tabla, 5, 1, 1, 4)
        self.gridLayout.addItem(
            QtGui.QSpacerItem(20, 20, QtGui.QSizePolicy.Fixed,
                              QtGui.QSizePolicy.Fixed), 1, 5, 5, 1)

        self.checkCarga = QtGui.QCheckBox(
            QtGui.QApplication.translate("pychemqt", "Heat"))
        self.gridLayout.addWidget(self.checkCarga, 1, 6)
        self.checkPotencia = QtGui.QCheckBox(
            QtGui.QApplication.translate("pychemqt", "Power"))
        self.gridLayout.addWidget(self.checkPotencia, 1, 7)
        self.checkNPSH = QtGui.QCheckBox(
            QtGui.QApplication.translate("pychemqt", "NPSH"))
        self.gridLayout.addWidget(self.checkNPSH, 1, 8)
        self.rejilla = QtGui.QCheckBox(
            QtGui.QApplication.translate("pychemqt", "Grid"))
        self.rejilla.toggled.connect(self.rejilla_toggled)
        self.gridLayout.addWidget(self.rejilla, 1, 9)
        self.gridLayout.addItem(
            QtGui.QSpacerItem(1000, 20, QtGui.QSizePolicy.Expanding,
                              QtGui.QSizePolicy.Fixed), 1, 10)
        self.Plot = Plot(self, width=5, height=1, dpi=100)
        self.gridLayout.addWidget(self.Plot, 2, 6, 4, 5)

        self.buttonBox = QtGui.QDialogButtonBox(
            QtGui.QDialogButtonBox.Ok | QtGui.QDialogButtonBox.Cancel)
        self.buttonBox.accepted.connect(self.accept)
        self.buttonBox.rejected.connect(self.reject)
        self.gridLayout.addWidget(self.buttonBox, 6, 9, 1, 2)

        if curva:
            self.curvas = curva
            for i in curva:
                self.lista.addItem(str(i[0]) + '", ' + str(i[1]) + " rpm")
            self.lista.setCurrentIndex(self.lista.count() - 1)
            self.cambiarCurvaVista(self.lista.count() - 1)

            #            self.curva=curva[-1]
            #            self.diametro.setValue(self.curva[0])
            #            self.rpm.setValue(self.curva[1])
            #            self.Tabla.setMatrix(self.curva[2:])
            #            self.Tabla.addRow()
            self.actualizarPlot()
        else:
            self.curva = []

        for i in Length.__text__:
            self.unidadesCarga.addItem(i)
            self.unidadesNPSH.addItem(i)
        for i in VolFlow.__text__:
            self.unidadesCaudal.addItem(i)
        for i in Power.__text__:
            self.unidadesPotencia.addItem(i)

        self.oldIndices = [0, 0, 0, 0]
        self.unidadesCaudal.currentIndexChanged.connect(
            partial(self.cambiar_unidades, 0, VolFlow, "VolFlow"))
        self.unidadesCarga.currentIndexChanged.connect(
            partial(
                self.cambiar_unidades,
                1,
                Length,
                "Head",
            ))
        self.unidadesPotencia.currentIndexChanged.connect(
            partial(self.cambiar_unidades, 2, Power, "Power"))
        self.unidadesNPSH.currentIndexChanged.connect(
            partial(
                self.cambiar_unidades,
                3,
                Length,
                "Head",
            ))

        Config = config.getMainWindowConfig()
        self.unidadesCaudal.setCurrentIndex(Config.getint("Units", "QLiq"))
        self.unidadesCarga.setCurrentIndex(Config.getint("Units", "Head"))
        self.unidadesPotencia.setCurrentIndex(Config.getint("Units", "Power"))
        self.unidadesNPSH.setCurrentIndex(Config.getint("Units", "Head"))

        self.checkCarga.toggled.connect(self.actualizarPlot)
        self.checkPotencia.toggled.connect(self.actualizarPlot)
        self.checkNPSH.toggled.connect(self.actualizarPlot)

    def botones_clicked(self, boton):
        if boton == self.botones.button(QtGui.QDialogButtonBox.Reset):
            self.diametro.clear()
            self.rpm.clear()
            self.Tabla.clear()
            self.checkCarga.setChecked(False)
            self.checkPotencia.setChecked(False)
            self.checkNPSH.setChecked(False)
            self.rejilla.setChecked(False)

        elif boton == self.botones.button(QtGui.QDialogButtonBox.Open):
            fname = unicode(
                QtGui.QFileDialog.getOpenFileName(
                    self,
                    QtGui.QApplication.translate("pychemqt",
                                                 "Open curve file"), "./",
                    "cpickle file (*.pkl);;All files (*.*)"))
            if fname:
                with open(fname, "r") as archivo:
                    curvas = cPickle.load(archivo)
                self.curvas = curvas
                self.curva = curvas[-1]
                self.lista.clear()
                self.lista.blockSignals(True)
                for i in curvas:
                    self.lista.addItem(str(i[0]) + '", ' + str(i[1]) + " rpm")
                self.lista.blockSignals(False)
                self.lista.setCurrentIndex(self.lista.count() - 1)
                self.cambiarCurvaVista(self.lista.count() - 1)
                self.actualizarPlot()

        elif boton == self.botones.button(QtGui.QDialogButtonBox.Apply):
            txt = str(self.diametro.value) + '", ' + str(
                self.rpm.value) + " rpm"
            indice = self.lista.findText(txt)
            if indice == -1:
                self.lista.addItem(txt)
                self.curva = self.CalcularCurva()
                self.curvas.append(self.curva)
                self.lista.setCurrentIndex(self.lista.count() - 1)
                self.actualizarPlot()
            else:
                self.curva = self.CalcularCurva()
                self.curvas[indice] = self.curva
                self.lista.setCurrentIndex(indice)
                self.actualizarPlot()

        else:
            fname = unicode(
                QtGui.QFileDialog.getSaveFileName(
                    self,
                    QtGui.QApplication.translate("pychemqt",
                                                 "Save curve to file"), "./",
                    "cpickle file (*.pkl)"))
            if fname:
                if fname.split(".")[-1] != "pkl":
                    fname += ".pkl"
                cPickle.dump(self.curvas, open(fname, "w"))

    def CalcularCurva(self):
        caudal = []
        carga = []
        potencia = []
        NPSH = []
        for i in range(1, self.Tabla.rowCount() - 1):
            q = VolFlow(float(self.Tabla.item(i, 0).text()),
                        VolFlow.__units__[self.unidadesCaudal.currentIndex()])
            caudal.append(q)
            h = Length(float(self.Tabla.item(i, 1).text()),
                       Length.__units__[self.unidadesCarga.currentIndex()])
            carga.append(h)
            P = Power(float(self.Tabla.item(i, 2).text()),
                      Power.__units__[self.unidadesPotencia.currentIndex()])
            potencia.append(P)
            n = Length(float(self.Tabla.item(i, 3).text()),
                       Length.__units__[self.unidadesNPSH.currentIndex()])
            NPSH.append(n)
        return [
            self.diametro.value, self.rpm.value, caudal, carga, potencia, NPSH
        ]

    def cambiar_unidades(self, col, unit, magn, i):
        text = self.Tabla.getColumn(col)
        old_i = self.oldIndices[col]
        self.Tabla.blockSignals(True)
        for fila in range(0, len(text)):
            a = unit(text[fila],
                     units[magn][old_i]).__getattribute__(units[magn][i])
            self.Tabla.item(fila + 1, col).setText(representacion(a))
        self.Tabla.blockSignals(False)
        self.oldIndices[col] = i

    def cambiarCurvaVista(self, ind):
        self.curva = self.curvas[ind]
        self.diametro.setValue(self.curva[0])
        self.rpm.setValue(self.curva[1])
        q = [
            VolFlow(i).__getattribute__(
                VolFlow.__units__[self.unidadesCaudal.currentIndex()])
            for i in self.curva[2]
        ]
        h = [
            Length(i).__getattribute__(
                Length.__units__[self.unidadesCarga.currentIndex()])
            for i in self.curva[3]
        ]
        P = [
            Power(i).__getattribute__(
                Power.__units__[self.unidadesPotencia.currentIndex()])
            for i in self.curva[4]
        ]
        n = [
            Length(i).__getattribute__(
                Length.__units__[self.unidadesNPSH.currentIndex()])
            for i in self.curva[5]
        ]
        self.Tabla.setMatrix(transpose([q, h, P, n]))
        self.Tabla.addRow()

    def actualizarPlot(self):
        #FIXME: mejorar el manejo de gráficas, básicamente empollarse matplotlib, opcional para profesionalizar el gráfico
        Carga = self.checkCarga.isChecked()
        Potencia = self.checkPotencia.isChecked()
        NPSH = self.checkNPSH.isChecked()
        self.Plot.fig.clear()
        share = None
        self.Plot.carga = []
        self.Plot.potencia = []
        self.Plot.npsh = []
        total = Carga + Potencia + NPSH
        actual = 1
        if Carga:
            self.Plot.ax1 = self.Plot.fig.add_subplot(total, 1, actual)
            self.Plot.ax1.grid(self.rejilla.isChecked())
            self.Plot.ax1.set_title("Curva H/Q", size='14')
            self.Plot.ax1.set_ylabel("H, m", size='12')
            share = self.Plot.ax1
            actual += 1
            for curva in self.curvas:
                Q = curva[2]
                h = curva[3]
                self.Plot.carga += self.Plot.ax1.plot(
                    Q, h, label=str(curva[0]) + '", ' + str(curva[1]) + " rpm")
            self.Plot.ax1.legend()

        if Potencia:
            self.Plot.ax2 = self.Plot.fig.add_subplot(total,
                                                      1,
                                                      actual,
                                                      sharex=share)
            self.Plot.ax2.grid(self.rejilla.isChecked())
            self.Plot.ax2.set_ylabel("P, kW", size='12')
            share = self.Plot.ax2
            actual += 1
            for curva in self.curvas:
                Q = curva[2]
                Pot = curva[4]
                self.Plot.potencia += self.Plot.ax2.plot(
                    Q,
                    Pot,
                    label=str(curva[0]) + '", ' + str(curva[1]) + " rpm")
            self.Plot.ax2.legend(loc='upper left')

        if NPSH:
            self.Plot.ax3 = self.Plot.fig.add_subplot(total,
                                                      1,
                                                      actual,
                                                      sharex=share)
            self.Plot.ax3.grid(self.rejilla.isChecked())
            self.Plot.ax3.set_ylabel("NPSH, m", size='12')
            for curva in self.curvas:
                Q = curva[2]
                npsh = curva[5]
                self.Plot.npsh += self.Plot.ax3.plot(
                    Q,
                    npsh,
                    label=str(curva[0]) + '", ' + str(curva[1]) + " rpm")
            self.Plot.ax3.legend(loc='upper left')

        if share:
            share.set_xlabel("Q, $m^3/s$",
                             horizontalalignment='left',
                             size='12')


#        self.Plot.ax2.set_title("Curva P/Q", size='14')
#        self.Plot.ax3.set_title("Curva NPSH/Q", size='14')
#        self.Plot.ax1.set_xlabel("Q, $m^3/s$", horizontalalignment='left', size='12')
#        self.Plot.ax2.set_xlabel("Q, $m^3/s$", horizontalalignment='left', size='12')
#otras rpm
#        for rpm in [1200., 1500., 1800., 2100.]:
#            Q2=[]
#            h2=[]
#            for i in range(len(Q)):
#                Q2.append(Q[i]*rpm/1400)
#                h2.append(h[i]*rpm**2/1400**2)
#            self.Plot.ax1.plot(Q2, h2)

#        self.Plot.tight_layout()       #Necesita matploblib >=1.1
        self.Plot.draw()

    def rejilla_toggled(self, bool):
        self.Plot.ax1.grid(bool)
        self.Plot.ax2.grid(bool)
        self.Plot.ax3.grid(bool)
        self.Plot.draw()
Ejemplo n.º 3
0
class Entrada_Datos(QtGui.QDialog):
    """Table data input dialog"""
    def __init__(self,
                 data=None,
                 t=[],
                 property=[],
                 horizontalHeader=[],
                 title="",
                 help=False,
                 helpFile="",
                 DIPPR=False,
                 tc=0,
                 tcValue=None,
                 eq=1,
                 parent=None):
        """
        title: window title
        data: mrray with original data
        t: values for x column, generally temperature
        property: values for 2...n columns
        horizontalHeader: List with column title
        help: boolean to show help button
        helpFile: Path for help file, file or url
        DIPPR: boolean to show DIPPR widget
        tc: boolean to show critical temperature (same DIPPR eq need it)
        tcValue: value for critical temperature
        eq: Value for DIPPR equation
        """
        super(Entrada_Datos, self).__init__(parent)
        self.setWindowTitle(title)
        self.columnas = len(horizontalHeader)
        self.horizontalHeader = horizontalHeader
        self.title = title
        self.helpFile = helpFile
        gridLayout = QtGui.QGridLayout(self)
        self.botonAbrir = QtGui.QPushButton(
            QtGui.QIcon(
                QtGui.QPixmap(os.environ["pychemqt"] +
                              "/images/button/fileOpen.png")),
            QtGui.QApplication.translate("pychemqt", "Open"))
        self.botonAbrir.clicked.connect(self.Abrir)
        gridLayout.addWidget(self.botonAbrir, 1, 1)
        self.botonGuardar = QtGui.QPushButton(
            QtGui.QIcon(
                QtGui.QPixmap(os.environ["pychemqt"] +
                              "/images/button/fileSave.png")),
            QtGui.QApplication.translate("pychemqt", "Save"))
        self.botonGuardar.clicked.connect(self.Guardar)
        gridLayout.addWidget(self.botonGuardar, 1, 2)
        self.botonDelete = QtGui.QPushButton(
            QtGui.QIcon(
                QtGui.QPixmap(os.environ["pychemqt"] +
                              "/images/button/clear.png")),
            QtGui.QApplication.translate("pychemqt", "Clear"))
        self.botonDelete.clicked.connect(self.Borrar)
        gridLayout.addWidget(self.botonDelete, 1, 3)
        gridLayout.addItem(
            QtGui.QSpacerItem(0, 0, QtGui.QSizePolicy.Expanding,
                              QtGui.QSizePolicy.Expanding), 1, 4)

        self.tabla = Tabla(self.columnas,
                           horizontalHeader=horizontalHeader,
                           verticalHeader=False,
                           stretch=False)
        self.tabla.setConnected()
        if data:
            self.tabla.setMatrix(data)
            self.tabla.addRow()
        elif t and property:
            self.tabla.setColumn(0, t)
            self.tabla.setColumn(1, property)
        gridLayout.addWidget(self.tabla, 2, 1, 1, 4)

        if DIPPR:
            self.eqDIPPR = eqDIPPR(eq)
            gridLayout.addWidget(self.eqDIPPR, 3, 1, 1, 4)
            self.eqDIPPR.eqDIPPR.valueChanged.connect(self.showTc)

        if tc:
            lyt = QtGui.QHBoxLayout()
            self.labelTc = QtGui.QLabel("Tc: ", self)
            lyt.addWidget(self.labelTc)
            self.tc = Entrada_con_unidades(Temperature, value=tcValue)
            lyt.addWidget(self.tc)
            lyt.addItem(
                QtGui.QSpacerItem(0, 0, QtGui.QSizePolicy.Expanding,
                                  QtGui.QSizePolicy.Expanding))
            gridLayout.addItem(lyt, 4, 1, 1, 4)
            self.showTc(1)

        if help:
            botones = QtGui.QDialogButtonBox.Help | \
                QtGui.QDialogButtonBox.Cancel | QtGui.QDialogButtonBox.Ok
        else:
            botones = QtGui.QDialogButtonBox.Cancel | QtGui.QDialogButtonBox.Ok
        self.boton = QtGui.QDialogButtonBox(botones)
        self.boton.accepted.connect(self.accept)
        self.boton.rejected.connect(self.reject)
        self.boton.helpRequested.connect(self.ayuda)
        gridLayout.addWidget(self.boton, 5, 1, 1, 4)

    def showTc(self, value):
        self.labelTc.setVisible(value in (7, 9))
        self.tc.setVisible(value in (7, 9))

    def Abrir(self):
        fname = unicode(
            QtGui.QFileDialog.getOpenFileName(
                self, QtGui.QApplication.translate("pychemqt",
                                                   "Open text file"), "./"))
        if fname:
            data = loadtxt(fname)
            self.tabla.setMatrix(data)
            self.tabla.addRow()

    def Guardar(self):
        fname = unicode(
            QtGui.QFileDialog.getSaveFileName(
                self,
                QtGui.QApplication.translate("pychemqt", "Save data to file"),
                "./"))
        if fname:
            with open(fname, 'w') as file:
                file.write("#" + self.title + "\n")
                file.write("#")
                try:
                    for i in self.horizontalHeader:
                        file.write(i + "\t")
                except UnicodeEncodeError:
                    pass
                file.write("\n")
                data = self.data
                for fila in range(len(data)):
                    for columna in range(self.tabla.columnCount()):
                        file.write(str(data[fila][columna]) + "\t")
                    file.write("\n")

    def Borrar(self):
        """Clear table"""
        self.tabla.setRowCount(1)
        self.tabla.clearContents()

    def ayuda(self):
        """Show help file"""
        Dialog = HelpView(self.windowTitle(), QtCore.QUrl(self.helpFile))
        Dialog.exec_()

    @property
    def data(self):
        return self.tabla.getMatrix()