mirror of https://gitlab.com/pamhyr/pamhyr2
LC: Update with functional window LC and Edit.
parent
115d84d436
commit
f1d82b2f86
|
|
@ -38,7 +38,7 @@ class LateralContribution(object):
|
|||
self._name = name
|
||||
|
||||
@property
|
||||
def bctype(self):
|
||||
def lctype(self):
|
||||
return self._type
|
||||
|
||||
@property
|
||||
|
|
|
|||
|
|
@ -30,6 +30,9 @@ class Graph(object):
|
|||
def edges(self):
|
||||
return self._edges
|
||||
|
||||
def edges_names(self):
|
||||
return list(map(lambda e: e.name, self._edges))
|
||||
|
||||
def nodes_counts(self):
|
||||
return len(self._nodes)
|
||||
|
||||
|
|
@ -63,6 +66,19 @@ class Graph(object):
|
|||
|
||||
return node[0]
|
||||
|
||||
def edge(self, edge_name:str):
|
||||
edge = list(
|
||||
filter(
|
||||
lambda e: e.name == edge_name,
|
||||
self._edges
|
||||
)
|
||||
)
|
||||
|
||||
if len(edge) == 0:
|
||||
return None
|
||||
|
||||
return edge[0]
|
||||
|
||||
def _add_node(self, node):
|
||||
self._nodes.append(node)
|
||||
self._nodes_ids += 1
|
||||
|
|
|
|||
|
|
@ -7,12 +7,8 @@ from Model.Network.Graph import Graph
|
|||
from Model.Geometry.Profile import Profile
|
||||
from Model.Geometry.Reach import Reach
|
||||
|
||||
from Model.BoundaryCondition.BoundaryCondition import (
|
||||
BoundaryCondition
|
||||
)
|
||||
from Model.BoundaryCondition.BoundaryConditionList import (
|
||||
BoundaryConditionList
|
||||
)
|
||||
from Model.BoundaryCondition.BoundaryConditionList import BoundaryConditionList
|
||||
from Model.LateralContribution.LateralContributionList import LateralContributionList
|
||||
|
||||
|
||||
class RiverNode(Node):
|
||||
|
|
@ -60,11 +56,16 @@ class River(Graph):
|
|||
|
||||
self._current_reach = None
|
||||
self._boundary_condition = BoundaryConditionList()
|
||||
self._lateral_contribution = LateralContributionList()
|
||||
|
||||
@property
|
||||
def boundary_condition(self):
|
||||
return self._boundary_condition
|
||||
|
||||
@property
|
||||
def lateral_contribution(self):
|
||||
return self._lateral_contribution
|
||||
|
||||
def has_current_reach(self):
|
||||
return self._current_reach is not None
|
||||
|
||||
|
|
|
|||
|
|
@ -49,13 +49,13 @@ class DelCommand(QUndoCommand):
|
|||
self._data = data
|
||||
self._rows = rows
|
||||
|
||||
self._bc = []
|
||||
self._lc = []
|
||||
for row in rows:
|
||||
self._bc.append((row, self._data.get_i(row)))
|
||||
self._bc.sort()
|
||||
self._lc.append((row, self._data.get_i(row)))
|
||||
self._lc.sort()
|
||||
|
||||
def undo(self):
|
||||
for row, el in self._bc:
|
||||
for row, el in self._lc:
|
||||
self._data.insert(row, el)
|
||||
|
||||
def redo(self):
|
||||
|
|
@ -114,19 +114,19 @@ class MoveCommand(QUndoCommand):
|
|||
|
||||
|
||||
class PasteCommand(QUndoCommand):
|
||||
def __init__(self, data, row, bcs):
|
||||
def __init__(self, data, row, lcs):
|
||||
QUndoCommand.__init__(self)
|
||||
|
||||
self._data = data
|
||||
self._row = row
|
||||
self._bcs = bcs
|
||||
self._bcs.reverse()
|
||||
self._lcs = lcs
|
||||
self._lcs.reverse()
|
||||
|
||||
def undo(self):
|
||||
self._data.delete(self._bcs)
|
||||
self._data.delete(self._lcs)
|
||||
|
||||
def redo(self):
|
||||
for bc in self._bcs:
|
||||
for bc in self._lcs:
|
||||
self._data.insert(self._row, bc)
|
||||
|
||||
|
||||
|
|
@ -136,12 +136,12 @@ class DuplicateCommand(QUndoCommand):
|
|||
|
||||
self._data = data
|
||||
self._rows = rows
|
||||
self._bc = deepcopy(bc)
|
||||
self._bc.reverse()
|
||||
self._lc = deepcopy(bc)
|
||||
self._lc.reverse()
|
||||
|
||||
def undo(self):
|
||||
self._data.delete(self._bc)
|
||||
self._data.delete(self._lc)
|
||||
|
||||
def redo(self):
|
||||
for bc in self._bcs:
|
||||
for bc in self._lcs:
|
||||
self._data.insert(self._rows[0], bc)
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ class EditLateralContributionWindow(ASubMainWindow, ListedSubWindow):
|
|||
self.compute_title()
|
||||
|
||||
super(EditLateralContributionWindow, self).__init__(
|
||||
name=self._title, ui="EditLateralContributions", parent=parent
|
||||
name=self._title, ui="EditLateralContribution", parent=parent
|
||||
)
|
||||
|
||||
self.ui.setWindowTitle(self._title)
|
||||
|
|
@ -50,13 +50,13 @@ class EditLateralContributionWindow(ASubMainWindow, ListedSubWindow):
|
|||
|
||||
def compute_title(self):
|
||||
if self._data is not None:
|
||||
node_name = (self._data.node.name if self._data.node is not None
|
||||
edge_name = (self._data.edge.name if self._data.edge is not None
|
||||
else _translate("LateralContribution", "Not associate"))
|
||||
self._title = (
|
||||
_translate("Edit boundary condition", self._title) +
|
||||
_translate("Edit Lateral contribution", self._title) +
|
||||
f" - {self._study.name} " +
|
||||
f" - {self._data.name} " +
|
||||
f"({long_types[self._data.bctype]} - {node_name})"
|
||||
f"({long_types[self._data.lctype]} - {edge_name})"
|
||||
)
|
||||
|
||||
def setup_sc(self):
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ from PyQt5.QtWidgets import (
|
|||
)
|
||||
|
||||
from View.LateralContribution.UndoCommand import (
|
||||
SetNameCommand, SetNodeCommand, SetTypeCommand,
|
||||
SetNameCommand, SetEdgeCommand, SetTypeCommand,
|
||||
AddCommand, DelCommand, SortCommand,
|
||||
MoveCommand, PasteCommand, DuplicateCommand,
|
||||
)
|
||||
|
|
@ -45,8 +45,8 @@ class ComboBoxDelegate(QItemDelegate):
|
|||
map(
|
||||
lambda k: long_types[k],
|
||||
filter(
|
||||
lambda k: self._tab in BC_types[k].compatibility(),
|
||||
BC_types.keys()
|
||||
lambda k: self._tab in LC_types[k].compatibility(),
|
||||
LC_types.keys()
|
||||
)
|
||||
)
|
||||
)
|
||||
|
|
@ -56,7 +56,7 @@ class ComboBoxDelegate(QItemDelegate):
|
|||
else:
|
||||
self.editor.addItems(
|
||||
[_translate("LateralContribution", "Not associate")] +
|
||||
self._data.nodes_names()
|
||||
self._data.edges_names()
|
||||
)
|
||||
|
||||
self.editor.setCurrentText(index.data(Qt.DisplayRole))
|
||||
|
|
@ -90,7 +90,7 @@ class TableModel(QAbstractTableModel):
|
|||
self._data = data
|
||||
self._undo = undo
|
||||
self._tab = tab
|
||||
self._lcs = self._data.boundary_condition
|
||||
self._lcs = self._data.lateral_contribution
|
||||
|
||||
def flags(self, index):
|
||||
options = Qt.ItemIsEnabled | Qt.ItemIsSelectable
|
||||
|
|
@ -114,10 +114,10 @@ class TableModel(QAbstractTableModel):
|
|||
if self._headers[column] == "name":
|
||||
return self._lcs.get(self._tab, row).name
|
||||
elif self._headers[column] == "type":
|
||||
t = self._lcs.get(self._tab, row).bctype
|
||||
t = self._lcs.get(self._tab, row).lctype
|
||||
return long_types[t]
|
||||
elif self._headers[column] == "node":
|
||||
n = self._lcs.get(self._tab, row).node
|
||||
elif self._headers[column] == "edge":
|
||||
n = self._lcs.get(self._tab, row).edge
|
||||
if n is None:
|
||||
return _translate("LateralContribution", "Not associate")
|
||||
return n.name
|
||||
|
|
@ -147,13 +147,13 @@ class TableModel(QAbstractTableModel):
|
|||
key = next(k for k, v in long_types.items() if v == value)
|
||||
self._undo.push(
|
||||
SetTypeCommand(
|
||||
self._lcs, self._tab,row, BC_types[key]
|
||||
self._lcs, self._tab,row, LC_types[key]
|
||||
)
|
||||
)
|
||||
elif self._headers[column] == "node":
|
||||
elif self._headers[column] == "edge":
|
||||
self._undo.push(
|
||||
SetNodeCommand(
|
||||
self._lcs, self._tab,row, self._data.node(value)
|
||||
SetEdgeCommand(
|
||||
self._lcs, self._tab,row, self._data.edge(value)
|
||||
)
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -26,21 +26,21 @@ class SetNameCommand(QUndoCommand):
|
|||
def redo(self):
|
||||
self._lcs.get(self._tab, self._index).name = self._new
|
||||
|
||||
class SetNodeCommand(QUndoCommand):
|
||||
def __init__(self, lcs, tab, index, node):
|
||||
class SetEdgeCommand(QUndoCommand):
|
||||
def __init__(self, lcs, tab, index, edge):
|
||||
QUndoCommand.__init__(self)
|
||||
|
||||
self._lcs = lcs
|
||||
self._tab = tab
|
||||
self._index = index
|
||||
self._old = self._lcs.get(self._tab, self._index).node
|
||||
self._new = node
|
||||
self._old = self._lcs.get(self._tab, self._index).edge
|
||||
self._new = edge
|
||||
|
||||
def undo(self):
|
||||
self._lcs.get(self._tab, self._index).node = self._old
|
||||
self._lcs.get(self._tab, self._index).edge = self._old
|
||||
|
||||
def redo(self):
|
||||
self._lcs.get(self._tab, self._index).node = self._new
|
||||
self._lcs.get(self._tab, self._index).edge = self._new
|
||||
|
||||
class SetTypeCommand(QUndoCommand):
|
||||
def __init__(self, lcs, tab, index, _type):
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ from PyQt5.QtWidgets import (
|
|||
)
|
||||
|
||||
from View.LateralContribution.UndoCommand import (
|
||||
SetNameCommand, SetNodeCommand, SetTypeCommand,
|
||||
SetNameCommand, SetEdgeCommand, SetTypeCommand,
|
||||
AddCommand, DelCommand, SortCommand,
|
||||
MoveCommand, PasteCommand, DuplicateCommand,
|
||||
)
|
||||
|
|
@ -88,9 +88,9 @@ class LateralContributionWindow(ASubMainWindow, ListedSubWindow):
|
|||
tab = t,
|
||||
parent=self
|
||||
)
|
||||
self._delegate_node = ComboBoxDelegate(
|
||||
self._delegate_edge = ComboBoxDelegate(
|
||||
data = self._study.river,
|
||||
mode = "node",
|
||||
mode = "edge",
|
||||
tab = t,
|
||||
parent=self
|
||||
)
|
||||
|
|
@ -99,7 +99,7 @@ class LateralContributionWindow(ASubMainWindow, ListedSubWindow):
|
|||
1, self._delegate_type
|
||||
)
|
||||
table.setItemDelegateForColumn(
|
||||
2, self._delegate_node
|
||||
2, self._delegate_edge
|
||||
)
|
||||
|
||||
table.setSelectionBehavior(QAbstractItemView.SelectRows)
|
||||
|
|
|
|||
|
|
@ -20,10 +20,10 @@ long_types = {
|
|||
table_headers = {
|
||||
"name": _translate("LateralContribution", "Name"),
|
||||
"type": _translate("LateralContribution", "Type"),
|
||||
"node": _translate("LateralContribution", "Node")
|
||||
"edge": _translate("LateralContribution", "Edge")
|
||||
}
|
||||
|
||||
BC_types = {
|
||||
LC_types = {
|
||||
"ND": NotDefined,
|
||||
"PC": PonctualContribution,
|
||||
"TZ": TimeOverZ,
|
||||
|
|
|
|||
|
|
@ -0,0 +1,118 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>MainWindow</class>
|
||||
<widget class="QMainWindow" name="MainWindow">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>800</width>
|
||||
<height>450</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>MainWindow</string>
|
||||
</property>
|
||||
<property name="locale">
|
||||
<locale language="English" country="Europe"/>
|
||||
</property>
|
||||
<widget class="QWidget" name="centralwidget">
|
||||
<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"/>
|
||||
<widget class="QWidget" name="verticalLayoutWidget">
|
||||
<layout class="QVBoxLayout" name="verticalLayout"/>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QMenuBar" name="menubar">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>800</width>
|
||||
<height>22</height>
|
||||
</rect>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QToolBar" name="toolBar">
|
||||
<property name="windowTitle">
|
||||
<string>toolBar</string>
|
||||
</property>
|
||||
<attribute name="toolBarArea">
|
||||
<enum>TopToolBarArea</enum>
|
||||
</attribute>
|
||||
<attribute name="toolBarBreak">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
<addaction name="action_add"/>
|
||||
<addaction name="action_del"/>
|
||||
<addaction name="action_sort"/>
|
||||
</widget>
|
||||
<action name="action_add">
|
||||
<property name="checkable">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset>
|
||||
<normaloff>ressources/gtk-add.png</normaloff>ressources/gtk-add.png</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Add</string>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Add a new point in boundary condition or lateral contribution</string>
|
||||
</property>
|
||||
<property name="shortcut">
|
||||
<string>Ctrl+N</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="action_del">
|
||||
<property name="icon">
|
||||
<iconset>
|
||||
<normaloff>ressources/gtk-remove.png</normaloff>ressources/gtk-remove.png</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Delete</string>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Delete current selected rows</string>
|
||||
</property>
|
||||
<property name="shortcut">
|
||||
<string>Ctrl+D</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="action_sort">
|
||||
<property name="icon">
|
||||
<iconset>
|
||||
<normaloff>ressources/gtk-sort-ascending.png</normaloff>ressources/gtk-sort-ascending.png</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Sort</string>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Sort boundary condition point</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
Loading…
Reference in New Issue