diff --git a/src/main/python/DockWidgets/DockWidgetMaterialStream.py b/src/main/python/DockWidgets/DockWidgetMaterialStream.py index 061e201..e85bc9d 100644 --- a/src/main/python/DockWidgets/DockWidgetMaterialStream.py +++ b/src/main/python/DockWidgets/DockWidgetMaterialStream.py @@ -53,10 +53,22 @@ def __init__(self, name, comptype, obj, container, parent=None): self.name_type = None self.container = container - header = QTreeWidgetItem(['Compound', 'Value', 'Unit']) - self.mTreeWidget.setHeaderItem(header) - self.lTreeWidget.setHeaderItem(header) - self.vTreeWidget.setHeaderItem(header) + # dropdown + self._composition_basis_options = [ + 'Mole Fraction', 'Mass Fraction', 'Mole Flow', 'Mass Flow' + ] + for opt in self._composition_basis_options: + self.cbCompositionBasis.addItem(opt) + self.cbCompositionBasis.setCurrentIndex(0) + self.cbCompositionBasis.currentIndexChanged.connect( + self._on_composition_basis_changed + ) + + # Storage for amounts results: { basis_name: { phase_no: [(compound, value)] } } + # phase_no: 1=Mixture, 2=Liquid, 3=Vapour + self._amounts_data = {} + for basis in self._composition_basis_options: + self._amounts_data[basis] = {1: [], 2: [], 3: []} # --- Corrected Thermo Package file reading --- if getattr(sys, 'frozen', False): @@ -298,12 +310,17 @@ def show_result(ms_lst): i.results_category(i.name) def clear_results(self): - self.mTreeWidget.clear() + # Clear amounts tables + self.amountsMixtureTable.setRowCount(0) + self.amountsLiquidTable.setRowCount(0) + self.amountsVapourTable.setRowCount(0) + # Clear phase properties tables self.mTableWidget.setRowCount(0) - self.lTreeWidget.clear() self.lTableWidget.setRowCount(0) - self.vTreeWidget.clear() self.vTableWidget.setRowCount(0) + # Reset stored amounts data + for basis in self._composition_basis_options: + self._amounts_data[basis] = {1: [], 2: [], 3: []} # result data tab def results_category(self,name): @@ -325,59 +342,41 @@ def _safe_result(val): p = {"Pressure":"P", "Temperature":"T","Vapour Phase Mole Fraction":"xvap", "Phase Molar Enthalpy":"H_p", "Phase Molar Entropy":"S_p", "Molar Flow Rate":"F_p","Mass Flow Rate":"Fm_p"} - # Amounts Tab + # Amounts Tab — populate _amounts_data dict if obj.type == 'MaterialStream': + # Reset stored data + for basis in self._composition_basis_options: + self._amounts_data[basis] = {1: [], 2: [], 3: []} + ll = [] # list for basis names for basis in d: propertyname = name + '.' + d[basis] - #print("basis ", basis, propertyname) for i in result[0]: if (propertyname in i): ll.append(i) - #print(ll) - j = 0 namee = 'none' - #print("namee ", namee) - #initialization for treewidgets - lroot = 1 - mroot = 1 - vroot = 1 - - for i,k in enumerate(ll): + for i, k in enumerate(ll): ind = result[0].index(k) - #print("index ", ind) - #print("str ", k) resultval = str(result[-1][ind]) - #print("######Resultsfetch####",resultval) - #print(k[k.find(".")+1:k.find("[")]) obj.variables[k.split('.')[1]]['value'] = resultval if namee not in k: - mroot = QTreeWidgetItem(self.mTreeWidget, [ms_lst[j]]) - lroot = QTreeWidgetItem(self.lTreeWidget, [ms_lst[j]]) - vroot = QTreeWidgetItem(self.vTreeWidget, [ms_lst[j]]) namee = klst[j] - phase_no = int(k[k.index(',') - 1]) # phase no is from modelica list - compound_no = int(k[k.index(',') + 1]) - 1 # compound is from python list - - if phase_no == 1: - child = QTreeWidgetItem(mroot, [compound_selected[compound_no], _safe_result(resultval), - obj.variables[k.split('.')[1]]['unit']]) - elif phase_no == 2: - child = QTreeWidgetItem(lroot, [compound_selected[compound_no], _safe_result(resultval), - obj.variables[k.split('.')[1]]['unit']]) - elif phase_no == 3: - child = QTreeWidgetItem(vroot, [compound_selected[compound_no], _safe_result(resultval), - obj.variables[k.split('.')[1]]['unit']]) - if (compound_no + 1) == len(compound_selected): - j += 1 - # drop down default behaviour is set to expanded - self.mTreeWidget.expandAll() - self.lTreeWidget.expandAll() - self.vTreeWidget.expandAll() + phase_no = int(k[k.index(',') - 1]) # phase no from modelica list + compound_no = int(k[k.index(',') + 1]) - 1 # compound from python list + + self._amounts_data[ms_lst[j]][phase_no].append( + (compound_selected[compound_no], _safe_result(resultval)) + ) + + if phase_no == 3 and (compound_no + 1) == len(compound_selected): + j += 1 + + # Refresh the visible amounts tables for the currently selected basis + self._on_composition_basis_changed() # Phase Properties Tab phaseResLst = [] @@ -513,4 +512,23 @@ def normalize(self): except Exception as e: print(f"[UI] Submit failed for {self.name}: {e}") print(e) - \ No newline at end of file + + # ------------------- Amounts: Composition Basis switching ------------------- + def _on_composition_basis_changed(self, index=None): + """Refresh the three Amounts phase tables for the currently selected basis.""" + basis = self.cbCompositionBasis.currentText() + data = self._amounts_data.get(basis, {1: [], 2: [], 3: []}) + self._populate_amounts_table(self.amountsMixtureTable, data.get(1, [])) + self._populate_amounts_table(self.amountsLiquidTable, data.get(2, [])) + self._populate_amounts_table(self.amountsVapourTable, data.get(3, [])) + + @staticmethod + def _populate_amounts_table(table, rows): + """Fill a QTableWidget with (compound, value) rows.""" + table.setRowCount(0) + for compound, value in rows: + row_pos = table.rowCount() + table.insertRow(row_pos) + table.setItem(row_pos, 0, QTableWidgetItem(compound)) + table.setItem(row_pos, 1, QTableWidgetItem(str(value))) + table.resizeColumnsToContents() diff --git a/src/main/ui/DockWidgets/DockWidgetMaterialStream.ui b/src/main/ui/DockWidgets/DockWidgetMaterialStream.ui index 8b9df28..d64dee5 100644 --- a/src/main/ui/DockWidgets/DockWidgetMaterialStream.ui +++ b/src/main/ui/DockWidgets/DockWidgetMaterialStream.ui @@ -156,333 +156,347 @@ - - - Results - - - - - - - 0 - 0 - - - - - 8 - 75 - true - - - - QToolBox{ - background: white; - border: 1px solid gray; - selection-background-color: rgb(255, 170, 127); -} - - - - 0 - - - - - 0 - 0 - 341 - 518 - + + + Results + + + + + + + 0 + 0 + - - QWidget{ - background: white; -} + + 0 - - Mixture - - - - - - false - - - QTabWidget{ - background: rgb(240, 240, 240); -} - - - QTabWidget::North - - - QTabWidget::Triangular - - - 0 - - - Qt::ElideNone - - - - Amounts - - - - - - false - - - 150 - - - false - - - - 1 + + + + Amounts + + + + + + + + Composition Basis: + + + + 0 + 0 + + + + + + + + + 0 + 0 + + + + + + + + + + + 0 + 0 + + + + 0 + + + + + Mixture + + + + + + 2 - - - - - - - - Phase Properties - - - - - - 3 - - - false - - - 100 - - - false - - - true - - - false - - - - Attribute + + QAbstractItemView::NoEditTriggers - - - - Value + + true - - - - Unit + + QAbstractItemView::SelectRows - - - - - - - - - - - - - 0 - 0 - 341 - 518 - - - - QWidget{ - background: white; -} - - - Liquid - - - - - - QTabWidget{ - background: rgb(240, 240, 240); -} - - - QTabWidget::Triangular - - - 0 - - - - Amounts - - - - - - 150 - - - - 1 + + true + + + false + + + + Compound + + + + + Value + + + + + + + + + + Liquid + + + + + + 2 - - - - - - - - Phase Properties - - - - - - 3 - - - 100 - - - true - - - - Attribute + + QAbstractItemView::NoEditTriggers - - - - Value + + true - - - - Unit + + QAbstractItemView::SelectRows - - - - - - - - - - - - - 0 - 0 - 137 - 96 - - - - QWidget{ - background: white; - -} - - - Vapour - - - - - - QTabWidget{ - background: rgb(240, 240, 240); -} - - - QTabWidget::Triangular - - - 0 - - - - Amounts - - - - - - 150 - - - - 1 + + true + + + false + + + + Compound + + + + + Value + + + + + + + + + + Vapour + + + + + + 2 - - - - + + QAbstractItemView::NoEditTriggers + + + true + + + QAbstractItemView::SelectRows + + + true + + + false + + + + Compound + + + + + Value + + + + + + - - - Phase Properties - - - - - - 3 - - - 100 - - - true - - - - Attribute + + + + + + + Phase Properties + + + + + + + 0 + 0 + + + + + 8 + 75 + true + + + + QToolBox{ + background: white; + border: 1px solid gray; + selection-background-color: rgb(255, 170, 127); +} + + + + 0 + + + + + QWidget{ background: white; } + + + Mixture + + + + + + 3 - - - - Value + + 100 + + + true + + + + Attribute + + + + + Value + + + + + Unit + + + + + + + + + + QWidget{ background: white; } + + + Liquid + + + + + + 3 - - - - Unit + + 100 + + + true + + + + Attribute + + + + + Value + + + + + Unit + + + + + + + + + + QWidget{ background: white; } + + + Vapour + + + + + + 3 - - - - + + 100 + + + true + + + + Attribute + + + + + Value + + + + + Unit + + + + + + - - - + + + - - - - + + +