From edc6af2762256d22da007a18b7a57a6b8da3a491 Mon Sep 17 00:00:00 2001 From: Dominik Demuth Date: Thu, 1 Jun 2023 20:09:11 +0200 Subject: [PATCH] fictive cp and tnmh model --- src/gui_qt/_py/tnmh_dialog.py | 61 +++++---- src/gui_qt/dsc/glass_dialog.py | 43 ++++++- src/resources/_ui/tnmh_dialog.ui | 213 +++++++++++++++++-------------- 3 files changed, 195 insertions(+), 122 deletions(-) diff --git a/src/gui_qt/_py/tnmh_dialog.py b/src/gui_qt/_py/tnmh_dialog.py index d1d29e9..c698e63 100644 --- a/src/gui_qt/_py/tnmh_dialog.py +++ b/src/gui_qt/_py/tnmh_dialog.py @@ -17,19 +17,27 @@ class Ui_Dialog(object): Dialog.resize(1176, 714) self.gridLayout = QtWidgets.QGridLayout(Dialog) self.gridLayout.setObjectName("gridLayout") + self.buttonBox = QtWidgets.QDialogButtonBox(Dialog) + self.buttonBox.setOrientation(QtCore.Qt.Horizontal) + self.buttonBox.setStandardButtons(QtWidgets.QDialogButtonBox.Cancel|QtWidgets.QDialogButtonBox.Ok) + self.buttonBox.setObjectName("buttonBox") + self.gridLayout.addWidget(self.buttonBox, 2, 3, 1, 1) self.graphicsView = PlotWidget(Dialog) - sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.MinimumExpanding) + sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.MinimumExpanding, QtWidgets.QSizePolicy.MinimumExpanding) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth(self.graphicsView.sizePolicy().hasHeightForWidth()) self.graphicsView.setSizePolicy(sizePolicy) self.graphicsView.setObjectName("graphicsView") self.gridLayout.addWidget(self.graphicsView, 0, 3, 1, 1) + self.graphicsView_2 = PlotWidget(Dialog) + self.graphicsView_2.setObjectName("graphicsView_2") + self.gridLayout.addWidget(self.graphicsView_2, 1, 3, 1, 1) self.formLayout = QtWidgets.QFormLayout() self.formLayout.setObjectName("formLayout") self.label = QtWidgets.QLabel(Dialog) self.label.setObjectName("label") - self.formLayout.setWidget(0, QtWidgets.QFormLayout.LabelRole, self.label) + self.formLayout.setWidget(1, QtWidgets.QFormLayout.LabelRole, self.label) self.lineEdit = QtWidgets.QLineEdit(Dialog) sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Maximum, QtWidgets.QSizePolicy.Fixed) sizePolicy.setHorizontalStretch(0) @@ -37,10 +45,10 @@ class Ui_Dialog(object): sizePolicy.setHeightForWidth(self.lineEdit.sizePolicy().hasHeightForWidth()) self.lineEdit.setSizePolicy(sizePolicy) self.lineEdit.setObjectName("lineEdit") - self.formLayout.setWidget(0, QtWidgets.QFormLayout.FieldRole, self.lineEdit) + self.formLayout.setWidget(1, QtWidgets.QFormLayout.FieldRole, self.lineEdit) self.label_2 = QtWidgets.QLabel(Dialog) self.label_2.setObjectName("label_2") - self.formLayout.setWidget(1, QtWidgets.QFormLayout.LabelRole, self.label_2) + self.formLayout.setWidget(2, QtWidgets.QFormLayout.LabelRole, self.label_2) self.lineEdit_3 = QtWidgets.QLineEdit(Dialog) sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Maximum, QtWidgets.QSizePolicy.Fixed) sizePolicy.setHorizontalStretch(0) @@ -48,10 +56,10 @@ class Ui_Dialog(object): sizePolicy.setHeightForWidth(self.lineEdit_3.sizePolicy().hasHeightForWidth()) self.lineEdit_3.setSizePolicy(sizePolicy) self.lineEdit_3.setObjectName("lineEdit_3") - self.formLayout.setWidget(1, QtWidgets.QFormLayout.FieldRole, self.lineEdit_3) + self.formLayout.setWidget(2, QtWidgets.QFormLayout.FieldRole, self.lineEdit_3) self.label_3 = QtWidgets.QLabel(Dialog) self.label_3.setObjectName("label_3") - self.formLayout.setWidget(2, QtWidgets.QFormLayout.LabelRole, self.label_3) + self.formLayout.setWidget(3, QtWidgets.QFormLayout.LabelRole, self.label_3) self.lineEdit_2 = QtWidgets.QLineEdit(Dialog) sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Maximum, QtWidgets.QSizePolicy.Fixed) sizePolicy.setHorizontalStretch(0) @@ -59,10 +67,10 @@ class Ui_Dialog(object): sizePolicy.setHeightForWidth(self.lineEdit_2.sizePolicy().hasHeightForWidth()) self.lineEdit_2.setSizePolicy(sizePolicy) self.lineEdit_2.setObjectName("lineEdit_2") - self.formLayout.setWidget(2, QtWidgets.QFormLayout.FieldRole, self.lineEdit_2) + self.formLayout.setWidget(3, QtWidgets.QFormLayout.FieldRole, self.lineEdit_2) self.label_4 = QtWidgets.QLabel(Dialog) self.label_4.setObjectName("label_4") - self.formLayout.setWidget(3, QtWidgets.QFormLayout.LabelRole, self.label_4) + self.formLayout.setWidget(4, QtWidgets.QFormLayout.LabelRole, self.label_4) self.lineEdit_4 = QtWidgets.QLineEdit(Dialog) sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Maximum, QtWidgets.QSizePolicy.Fixed) sizePolicy.setHorizontalStretch(0) @@ -70,19 +78,13 @@ class Ui_Dialog(object): sizePolicy.setHeightForWidth(self.lineEdit_4.sizePolicy().hasHeightForWidth()) self.lineEdit_4.setSizePolicy(sizePolicy) self.lineEdit_4.setObjectName("lineEdit_4") - self.formLayout.setWidget(3, QtWidgets.QFormLayout.FieldRole, self.lineEdit_4) - self.pushButton = QtWidgets.QPushButton(Dialog) - self.pushButton.setObjectName("pushButton") - self.formLayout.setWidget(4, QtWidgets.QFormLayout.SpanningRole, self.pushButton) - self.listWidget_2 = QtWidgets.QListWidget(Dialog) - self.listWidget_2.setObjectName("listWidget_2") - self.formLayout.setWidget(5, QtWidgets.QFormLayout.SpanningRole, self.listWidget_2) - self.gridLayout.addLayout(self.formLayout, 0, 1, 1, 1) - self.buttonBox = QtWidgets.QDialogButtonBox(Dialog) - self.buttonBox.setOrientation(QtCore.Qt.Horizontal) - self.buttonBox.setStandardButtons(QtWidgets.QDialogButtonBox.Cancel|QtWidgets.QDialogButtonBox.Ok) - self.buttonBox.setObjectName("buttonBox") - self.gridLayout.addWidget(self.buttonBox, 1, 3, 1, 1) + self.formLayout.setWidget(4, QtWidgets.QFormLayout.FieldRole, self.lineEdit_4) + self.pushButton_2 = QtWidgets.QPushButton(Dialog) + self.pushButton_2.setObjectName("pushButton_2") + self.formLayout.setWidget(0, QtWidgets.QFormLayout.SpanningRole, self.pushButton_2) + self.gridLayout.addLayout(self.formLayout, 0, 1, 2, 1) + self.verticalLayout = QtWidgets.QVBoxLayout() + self.verticalLayout.setObjectName("verticalLayout") self.listWidget = QtWidgets.QListWidget(Dialog) sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Maximum, QtWidgets.QSizePolicy.Expanding) sizePolicy.setHorizontalStretch(0) @@ -90,7 +92,19 @@ class Ui_Dialog(object): sizePolicy.setHeightForWidth(self.listWidget.sizePolicy().hasHeightForWidth()) self.listWidget.setSizePolicy(sizePolicy) self.listWidget.setObjectName("listWidget") - self.gridLayout.addWidget(self.listWidget, 0, 0, 1, 1) + self.verticalLayout.addWidget(self.listWidget) + self.pushButton = QtWidgets.QPushButton(Dialog) + self.pushButton.setObjectName("pushButton") + self.verticalLayout.addWidget(self.pushButton) + self.listWidget_2 = QtWidgets.QListWidget(Dialog) + sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Maximum, QtWidgets.QSizePolicy.Maximum) + sizePolicy.setHorizontalStretch(0) + sizePolicy.setVerticalStretch(0) + sizePolicy.setHeightForWidth(self.listWidget_2.sizePolicy().hasHeightForWidth()) + self.listWidget_2.setSizePolicy(sizePolicy) + self.listWidget_2.setObjectName("listWidget_2") + self.verticalLayout.addWidget(self.listWidget_2) + self.gridLayout.addLayout(self.verticalLayout, 0, 0, 2, 1) self.retranslateUi(Dialog) self.buttonBox.accepted.connect(Dialog.accept) # type: ignore @@ -104,5 +118,6 @@ class Ui_Dialog(object): self.label_2.setText(_translate("Dialog", "β")) self.label_3.setText(_translate("Dialog", "ΔH/R / K")) self.label_4.setText(_translate("Dialog", "x")) - self.pushButton.setText(_translate("Dialog", "PushButton")) + self.pushButton_2.setText(_translate("Dialog", "Fictive Cp")) + self.pushButton.setText(_translate("Dialog", "Calculate Tg")) from pyqtgraph import PlotWidget diff --git a/src/gui_qt/dsc/glass_dialog.py b/src/gui_qt/dsc/glass_dialog.py index bbf2a15..7e0301a 100644 --- a/src/gui_qt/dsc/glass_dialog.py +++ b/src/gui_qt/dsc/glass_dialog.py @@ -21,13 +21,15 @@ class TgCalculator(QtWidgets.QDialog, Ui_Dialog): self._dsc = {} self._tg_baselines = {} - self._tg_value_plot = [] + self._tg_value_plot = {} self.limits = RegionItem(), RegionItem() for lim in self.limits: self.graphicsView.addItem(lim) self.add_sets() + self.listWidget.itemClicked.connect(self.show_tg_values) + def __call__(self): self.clear() self.add_sets() @@ -100,11 +102,46 @@ class TgCalculator(QtWidgets.QDialog, Ui_Dialog): lines.append(plt) self._tg_baselines[key] = lines tg_plot = PlotItem(array(list(tg_results.values())), pen=None, symbolBrush=color, symbol='o') - self._tg_value_plot.append(tg_plot) + self._tg_value_plot[key] = (tg_results, tg_plot) self.graphicsView.addItem(tg_plot) + def show_tg_values(self, item): + values, _ = self._tg_value_plot.get(item.data(QtCore.Qt.UserRole), ({}, None)) + + if values is not None: + self.listWidget_2.clear() + for name, pos in values.items(): + tg_item = QtWidgets.QListWidgetItem(f'{name.capitalize()}: {pos[0]:.2f} K') + self.listWidget_2.addItem(tg_item) + + @QtCore.pyqtSlot(name='on_pushButton_2_clicked') + def get_fictive(self): + baselines = tuple(lim.getRegion() for lim in self.limits) + if baselines[0][0] > baselines[1][0]: + baselines = baselines[1], baselines[0] + + for idx in range(self.listWidget.count()): + item = self.listWidget.item(idx) + key = item.data(QtCore.Qt.UserRole) + color = item.foreground() + _, data = self._dsc[key] + cp, tg = data.get_fictive_cp(*baselines) + + plt = PlotItem(cp.x, cp.y) + plt.set_line(color=color.color()) + self.graphicsView_2.addItem(plt) + + self._tg_value_plot[key][0]['fictive'] = (tg, 0) + tg_plot = PlotItem(array(list(self._tg_value_plot[key][0].values())), pen=None, symbolBrush=color, symbol='o') + self.graphicsView.addItem(tg_plot) + + res = data.calculate_tnmh([100, 0.5, 1, 2e5], *baselines, return_fictive=False) + plt = PlotItem(res.x, res.y) + print(res.pprint()) + plt.set_line(style=2, color=color.color()) + self.graphicsView_2.addItem(plt) + def close(self) -> bool: self.clear() - return super().close() diff --git a/src/resources/_ui/tnmh_dialog.ui b/src/resources/_ui/tnmh_dialog.ui index 7b3787a..c57d7ba 100644 --- a/src/resources/_ui/tnmh_dialog.ui +++ b/src/resources/_ui/tnmh_dialog.ui @@ -14,99 +14,7 @@ Dialog - - - - - 0 - 0 - - - - - - - - - - τ<sub>g</sub> / s - - - - - - - - 0 - 0 - - - - - - - - β - - - - - - - - 0 - 0 - - - - - - - - ΔH/R / K - - - - - - - - 0 - 0 - - - - - - - - x - - - - - - - - 0 - 0 - - - - - - - - PushButton - - - - - - - - - + Qt::Horizontal @@ -116,16 +24,129 @@ - - + + - + 0 0 + + + + + + + + + τ<sub>g</sub> / s + + + + + + + + 0 + 0 + + + + + + + + β + + + + + + + + 0 + 0 + + + + + + + + ΔH/R / K + + + + + + + + 0 + 0 + + + + + + + + x + + + + + + + + 0 + 0 + + + + + + + + Fictive Cp + + + + + + + + + + + + 0 + 0 + + + + + + + + Calculate Tg + + + + + + + + 0 + 0 + + + + + +