diff --git a/src/Model/BoundaryCondition/BoundaryConditionTypes.py b/src/Model/BoundaryCondition/BoundaryConditionTypes.py index 963e88e72d58463e2c62b84be9d11733acd3e0a3..af3c91fdd5228bed070fab8633d5c34b71b0c316 100644 --- a/src/Model/BoundaryCondition/BoundaryConditionTypes.py +++ b/src/Model/BoundaryCondition/BoundaryConditionTypes.py @@ -89,6 +89,9 @@ class Solid(BoundaryCondition): def __init__(self, id:int = -1, name:str = "", status = None): super(Solid, self).__init__(id=id, name=name, status=status) + self.d50 = 0.002 + self.sigma = 1 + self._type = "SL" self._header = ["time", "solid"] self._types = [TimeOverDischarge.time_convert, float] diff --git a/src/Solver/Mage.py b/src/Solver/Mage.py index 697f8809ea6cbf7d9fec2e71b41f03dbd1dd5507..6ed03e66016cf0ae9573b99b7eb11149ac180bad 100644 --- a/src/Solver/Mage.py +++ b/src/Solver/Mage.py @@ -554,13 +554,23 @@ class Mage8(Mage): files.append(f"{name}.QSO") for bound in bounds: + # File header name = f"{bound.node.id:3}".replace(" ", "x") f.write(f"* {bound.node.name} ({name}) {bound.bctype}\n") - f.write(f"${name} 0.002 1 default\n") - # f.write(f"${name}\n") + + d50 = bound.d50 + sigma = bound.sigma + + if len(bound.data) == 0: + f.write(f"${name} {d50} {sigma} default\n") + else: + f.write(f"${name} {d50} {sigma}\n") + + # Table header header = bound.header f.write(f"*{header[0]:>9}|{header[1]:>10}\n") + # Data for d in bound.data: f.write(f"{d[0]:10.3f}{d[1]:10.3f}\n") diff --git a/src/View/BoundaryCondition/Edit/UndoCommand.py b/src/View/BoundaryCondition/Edit/UndoCommand.py index 4bb2605fc94213a2b70559807b79ca4e1425613c..b30331a167039f8a201f017460b4984e1ddd42f2 100644 --- a/src/View/BoundaryCondition/Edit/UndoCommand.py +++ b/src/View/BoundaryCondition/Edit/UndoCommand.py @@ -16,6 +16,8 @@ # -*- coding: utf-8 -*- +import logging + from copy import deepcopy from tools import trace, timer @@ -25,6 +27,8 @@ from PyQt5.QtWidgets import ( from Model.BoundaryCondition.BoundaryCondition import BoundaryCondition +logger = logging.getLogger() + class SetDataCommand(QUndoCommand): def __init__(self, data, index, column, new_value): QUndoCommand.__init__(self) @@ -42,6 +46,32 @@ class SetDataCommand(QUndoCommand): def redo(self): self._data._set_i_c_v(self._index, self._column, self._new) +class SetMetaDataCommand(QUndoCommand): + def __init__(self, data, column, new_value): + QUndoCommand.__init__(self) + + self._data = data + self._column = column + if self._column == "d50": + self._old = self._data.d50 + elif self._column == "sigma": + self._old = self._data.sigma + + self._new = float(new_value) + + def undo(self): + if self._column == "d50": + self._data.d50 = self._old + elif self._column == "sigma": + self._data.sigma = self._old + + def redo(self): + if self._column == "d50": + self._data.d50 = self._new + elif self._column == "sigma": + self._data.sigma = self._new + + class AddCommand(QUndoCommand): def __init__(self, data, index): QUndoCommand.__init__(self) diff --git a/src/View/BoundaryCondition/Edit/Window.py b/src/View/BoundaryCondition/Edit/Window.py index 652aa22d41a082d33b16ab9a932a481a91e07d85..7f35759f99bd966624aa0a5ee4a33675eac6803d 100644 --- a/src/View/BoundaryCondition/Edit/Window.py +++ b/src/View/BoundaryCondition/Edit/Window.py @@ -18,33 +18,77 @@ from tools import timer, trace -from View.ASubWindow import ASubMainWindow +from View.ASubWindow import ASubMainWindow, AWidget from View.ListedSubWindow import ListedSubWindow from PyQt5.QtGui import ( QKeySequence, ) +from PyQt5 import QtCore from PyQt5.QtCore import ( Qt, QVariant, QAbstractTableModel, QCoreApplication, + pyqtSlot, pyqtSignal, ) from PyQt5.QtWidgets import ( QDialogButtonBox, QPushButton, QLineEdit, QFileDialog, QTableView, QAbstractItemView, QUndoStack, QShortcut, QAction, QItemDelegate, - QHeaderView, + QHeaderView, QDoubleSpinBox, QVBoxLayout, ) from View.Plot.MplCanvas import MplCanvas from View.Plot.navigation_toolbar_2qt import PamHyrNavigationToolbar2QT from View.BoundaryCondition.translate import long_types +from View.BoundaryCondition.Edit.UndoCommand import SetMetaDataCommand from View.BoundaryCondition.Edit.Table import TableModel, ExTimeDelegate from View.BoundaryCondition.Edit.Plot import Plot _translate = QCoreApplication.translate +class WD50Sigma(AWidget): + d50Changed = pyqtSignal(float) + sigmaChanged = pyqtSignal(float) + + def __init__(self, parent=None): + super(WD50Sigma, self).__init__( + ui="d50sigma", + parent=parent + ) + self.parent = parent + + self.spinBox_d50 = self.find(QDoubleSpinBox, "doubleSpinBox_d50") + self.spinBox_sigma = self.find(QDoubleSpinBox, "doubleSpinBox_sigma") + + self.spinBox_d50.valueChanged.connect(self.valueChangedD50) + self.spinBox_sigma.valueChanged.connect(self.valueChangedSigma) + + def set_d50(self, d50): + self.spinBox_d50.valueChanged.disconnect(self.valueChangedD50) + self.spinBox_d50.setValue(float(d50)) + self.spinBox_d50.valueChanged.connect(self.valueChangedD50) + + def get_d50(self): + return float(self.spinBox_d50.value()) + + def set_sigma(self, sigma): + self.spinBox_sigma.valueChanged.disconnect(self.valueChangedSigma) + self.spinBox_sigma.setValue(float(sigma)) + self.spinBox_sigma.valueChanged.connect(self.valueChangedSigma) + + def get_sigma(self): + return float(self.spinBox_sigma.value()) + + @QtCore.pyqtSlot(float) + def valueChangedD50(self, value): + self.d50Changed.emit(value) + + @QtCore.pyqtSlot(float) + def valueChangedSigma(self, value): + self.sigmaChanged.emit(value) + class EditBoundaryConditionWindow(ASubMainWindow, ListedSubWindow): def __init__(self, title="Edit boundary condition", data=None, study=None, parent=None): @@ -63,6 +107,7 @@ class EditBoundaryConditionWindow(ASubMainWindow, ListedSubWindow): self.setup_sc() self.setup_table() self.setup_plot() + self.setup_data() self.setup_connections() def compute_title(self): @@ -84,6 +129,17 @@ class EditBoundaryConditionWindow(ASubMainWindow, ListedSubWindow): self.copy_sc = QShortcut(QKeySequence.Copy, self) self.paste_sc = QShortcut(QKeySequence.Paste, self) + def setup_data(self): + self._is_solid = self._data.bctype == "SL" + + if self._is_solid: + layout = self.find(QVBoxLayout, "verticalLayout_table") + self._d50sigma = WD50Sigma(parent = self) + layout.addWidget(self._d50sigma) + + self._d50sigma.set_d50(self._data.d50) + self._d50sigma.set_sigma(self._data.sigma) + def setup_table(self): table = self.find(QTableView, "tableView") self._table = TableModel( @@ -138,6 +194,31 @@ class EditBoundaryConditionWindow(ASubMainWindow, ListedSubWindow): self._table.dataChanged.connect(self.update) + if self._is_solid: + self._d50sigma.d50Changed.connect(self.d50_changed) + self._d50sigma.sigmaChanged.connect(self.sigma_changed) + + def d50_changed(self, value): + self._undo_stack.push( + SetMetaDataCommand( + self._data, + "d50", value + ) + ) + + def sigma_changed(self, value): + self._undo_stack.push( + SetMetaDataCommand( + self._data, + "sigma", value + ) + ) + + def widget_update(self): + if self._is_solid: + self._d50sigma.set_d50(self._data.d50) + self._d50sigma.set_sigma(self._data.sigma) + def update(self): self.plot.update() @@ -221,7 +302,9 @@ class EditBoundaryConditionWindow(ASubMainWindow, ListedSubWindow): def undo(self): self._table.undo() self.plot.update() + self.widget_update() def redo(self): self._table.redo() self.plot.update() + self.widget_update() diff --git a/src/View/ui/EditBoundaryConditions.ui b/src/View/ui/EditBoundaryConditions.ui index 1fabe5fc870a517c42f024aa6836889eb8b69ebb..7f615964b58f66b85b2bfb96bd91ce39599be269 100644 --- a/src/View/ui/EditBoundaryConditions.ui +++ b/src/View/ui/EditBoundaryConditions.ui @@ -26,22 +26,22 @@ <layout class="QGridLayout" name="gridLayout"> <item row="0" column="0"> <widget class="QSplitter" name="splitter"> - <property name="sizePolicy"> - <sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> <property name="orientation"> <enum>Qt::Horizontal</enum> </property> - <widget class="QTableView" name="tableView"> - <property name="minimumSize"> - <size> - <width>0</width> - <height>200</height> - </size> - </property> + <widget class="QWidget" name="verticalLayoutWidget_2"> + <layout class="QVBoxLayout" name="verticalLayout_table"> + <item> + <widget class="QTableView" name="tableView"> + <property name="minimumSize"> + <size> + <width>0</width> + <height>200</height> + </size> + </property> + </widget> + </item> + </layout> </widget> <widget class="QWidget" name="verticalLayoutWidget"> <layout class="QVBoxLayout" name="verticalLayout"/> diff --git a/src/View/ui/Widgets/d50sigma.ui b/src/View/ui/Widgets/d50sigma.ui new file mode 100644 index 0000000000000000000000000000000000000000..d1af908b9cd03702ac6042059fd5920f31f0ac7e --- /dev/null +++ b/src/View/ui/Widgets/d50sigma.ui @@ -0,0 +1,70 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>Form</class> + <widget class="QWidget" name="Form"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>256</width> + <height>46</height> + </rect> + </property> + <property name="windowTitle"> + <string>Form</string> + </property> + <property name="locale"> + <locale language="English" country="Europe"/> + </property> + <layout class="QGridLayout" name="gridLayout"> + <item row="0" column="0"> + <widget class="QSplitter" name="splitter"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <widget class="QWidget" name=""> + <layout class="QHBoxLayout" name="horizontalLayout"> + <item> + <widget class="QLabel" name="label_d50"> + <property name="text"> + <string>D50</string> + </property> + </widget> + </item> + <item> + <widget class="QDoubleSpinBox" name="doubleSpinBox_d50"> + <property name="locale"> + <locale language="English" country="Europe"/> + </property> + <property name="decimals"> + <number>4</number> + </property> + </widget> + </item> + </layout> + </widget> + <widget class="QWidget" name=""> + <layout class="QHBoxLayout" name="horizontalLayout_2"> + <item> + <widget class="QLabel" name="label_sigma"> + <property name="text"> + <string>Sigma</string> + </property> + </widget> + </item> + <item> + <widget class="QDoubleSpinBox" name="doubleSpinBox_sigma"> + <property name="decimals"> + <number>4</number> + </property> + </widget> + </item> + </layout> + </widget> + </widget> + </item> + </layout> + </widget> + <resources/> + <connections/> +</ui>