Commit f1d82b2f authored by Pierre-Antoine Rouby's avatar Pierre-Antoine Rouby
Browse files

LC: Update with functional window LC and Edit.

Showing with 183 additions and 48 deletions
+183 -48
...@@ -38,7 +38,7 @@ class LateralContribution(object): ...@@ -38,7 +38,7 @@ class LateralContribution(object):
self._name = name self._name = name
@property @property
def bctype(self): def lctype(self):
return self._type return self._type
@property @property
......
...@@ -30,6 +30,9 @@ class Graph(object): ...@@ -30,6 +30,9 @@ class Graph(object):
def edges(self): def edges(self):
return self._edges return self._edges
def edges_names(self):
return list(map(lambda e: e.name, self._edges))
def nodes_counts(self): def nodes_counts(self):
return len(self._nodes) return len(self._nodes)
...@@ -63,6 +66,19 @@ class Graph(object): ...@@ -63,6 +66,19 @@ class Graph(object):
return node[0] 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): def _add_node(self, node):
self._nodes.append(node) self._nodes.append(node)
self._nodes_ids += 1 self._nodes_ids += 1
......
...@@ -7,12 +7,8 @@ from Model.Network.Graph import Graph ...@@ -7,12 +7,8 @@ from Model.Network.Graph import Graph
from Model.Geometry.Profile import Profile from Model.Geometry.Profile import Profile
from Model.Geometry.Reach import Reach from Model.Geometry.Reach import Reach
from Model.BoundaryCondition.BoundaryCondition import ( from Model.BoundaryCondition.BoundaryConditionList import BoundaryConditionList
BoundaryCondition from Model.LateralContribution.LateralContributionList import LateralContributionList
)
from Model.BoundaryCondition.BoundaryConditionList import (
BoundaryConditionList
)
class RiverNode(Node): class RiverNode(Node):
...@@ -60,11 +56,16 @@ class River(Graph): ...@@ -60,11 +56,16 @@ class River(Graph):
self._current_reach = None self._current_reach = None
self._boundary_condition = BoundaryConditionList() self._boundary_condition = BoundaryConditionList()
self._lateral_contribution = LateralContributionList()
@property @property
def boundary_condition(self): def boundary_condition(self):
return self._boundary_condition return self._boundary_condition
@property
def lateral_contribution(self):
return self._lateral_contribution
def has_current_reach(self): def has_current_reach(self):
return self._current_reach is not None return self._current_reach is not None
......
...@@ -49,13 +49,13 @@ class DelCommand(QUndoCommand): ...@@ -49,13 +49,13 @@ class DelCommand(QUndoCommand):
self._data = data self._data = data
self._rows = rows self._rows = rows
self._bc = [] self._lc = []
for row in rows: for row in rows:
self._bc.append((row, self._data.get_i(row))) self._lc.append((row, self._data.get_i(row)))
self._bc.sort() self._lc.sort()
def undo(self): def undo(self):
for row, el in self._bc: for row, el in self._lc:
self._data.insert(row, el) self._data.insert(row, el)
def redo(self): def redo(self):
...@@ -114,19 +114,19 @@ class MoveCommand(QUndoCommand): ...@@ -114,19 +114,19 @@ class MoveCommand(QUndoCommand):
class PasteCommand(QUndoCommand): class PasteCommand(QUndoCommand):
def __init__(self, data, row, bcs): def __init__(self, data, row, lcs):
QUndoCommand.__init__(self) QUndoCommand.__init__(self)
self._data = data self._data = data
self._row = row self._row = row
self._bcs = bcs self._lcs = lcs
self._bcs.reverse() self._lcs.reverse()
def undo(self): def undo(self):
self._data.delete(self._bcs) self._data.delete(self._lcs)
def redo(self): def redo(self):
for bc in self._bcs: for bc in self._lcs:
self._data.insert(self._row, bc) self._data.insert(self._row, bc)
...@@ -136,12 +136,12 @@ class DuplicateCommand(QUndoCommand): ...@@ -136,12 +136,12 @@ class DuplicateCommand(QUndoCommand):
self._data = data self._data = data
self._rows = rows self._rows = rows
self._bc = deepcopy(bc) self._lc = deepcopy(bc)
self._bc.reverse() self._lc.reverse()
def undo(self): def undo(self):
self._data.delete(self._bc) self._data.delete(self._lc)
def redo(self): def redo(self):
for bc in self._bcs: for bc in self._lcs:
self._data.insert(self._rows[0], bc) self._data.insert(self._rows[0], bc)
...@@ -38,7 +38,7 @@ class EditLateralContributionWindow(ASubMainWindow, ListedSubWindow): ...@@ -38,7 +38,7 @@ class EditLateralContributionWindow(ASubMainWindow, ListedSubWindow):
self.compute_title() self.compute_title()
super(EditLateralContributionWindow, self).__init__( super(EditLateralContributionWindow, self).__init__(
name=self._title, ui="EditLateralContributions", parent=parent name=self._title, ui="EditLateralContribution", parent=parent
) )
self.ui.setWindowTitle(self._title) self.ui.setWindowTitle(self._title)
...@@ -50,13 +50,13 @@ class EditLateralContributionWindow(ASubMainWindow, ListedSubWindow): ...@@ -50,13 +50,13 @@ class EditLateralContributionWindow(ASubMainWindow, ListedSubWindow):
def compute_title(self): def compute_title(self):
if self._data is not None: 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")) else _translate("LateralContribution", "Not associate"))
self._title = ( self._title = (
_translate("Edit boundary condition", self._title) + _translate("Edit Lateral contribution", self._title) +
f" - {self._study.name} " + f" - {self._study.name} " +
f" - {self._data.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): def setup_sc(self):
......
...@@ -16,7 +16,7 @@ from PyQt5.QtWidgets import ( ...@@ -16,7 +16,7 @@ from PyQt5.QtWidgets import (
) )
from View.LateralContribution.UndoCommand import ( from View.LateralContribution.UndoCommand import (
SetNameCommand, SetNodeCommand, SetTypeCommand, SetNameCommand, SetEdgeCommand, SetTypeCommand,
AddCommand, DelCommand, SortCommand, AddCommand, DelCommand, SortCommand,
MoveCommand, PasteCommand, DuplicateCommand, MoveCommand, PasteCommand, DuplicateCommand,
) )
...@@ -45,8 +45,8 @@ class ComboBoxDelegate(QItemDelegate): ...@@ -45,8 +45,8 @@ class ComboBoxDelegate(QItemDelegate):
map( map(
lambda k: long_types[k], lambda k: long_types[k],
filter( filter(
lambda k: self._tab in BC_types[k].compatibility(), lambda k: self._tab in LC_types[k].compatibility(),
BC_types.keys() LC_types.keys()
) )
) )
) )
...@@ -56,7 +56,7 @@ class ComboBoxDelegate(QItemDelegate): ...@@ -56,7 +56,7 @@ class ComboBoxDelegate(QItemDelegate):
else: else:
self.editor.addItems( self.editor.addItems(
[_translate("LateralContribution", "Not associate")] + [_translate("LateralContribution", "Not associate")] +
self._data.nodes_names() self._data.edges_names()
) )
self.editor.setCurrentText(index.data(Qt.DisplayRole)) self.editor.setCurrentText(index.data(Qt.DisplayRole))
...@@ -90,7 +90,7 @@ class TableModel(QAbstractTableModel): ...@@ -90,7 +90,7 @@ class TableModel(QAbstractTableModel):
self._data = data self._data = data
self._undo = undo self._undo = undo
self._tab = tab self._tab = tab
self._lcs = self._data.boundary_condition self._lcs = self._data.lateral_contribution
def flags(self, index): def flags(self, index):
options = Qt.ItemIsEnabled | Qt.ItemIsSelectable options = Qt.ItemIsEnabled | Qt.ItemIsSelectable
...@@ -114,10 +114,10 @@ class TableModel(QAbstractTableModel): ...@@ -114,10 +114,10 @@ class TableModel(QAbstractTableModel):
if self._headers[column] == "name": if self._headers[column] == "name":
return self._lcs.get(self._tab, row).name return self._lcs.get(self._tab, row).name
elif self._headers[column] == "type": 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] return long_types[t]
elif self._headers[column] == "node": elif self._headers[column] == "edge":
n = self._lcs.get(self._tab, row).node n = self._lcs.get(self._tab, row).edge
if n is None: if n is None:
return _translate("LateralContribution", "Not associate") return _translate("LateralContribution", "Not associate")
return n.name return n.name
...@@ -147,13 +147,13 @@ class TableModel(QAbstractTableModel): ...@@ -147,13 +147,13 @@ class TableModel(QAbstractTableModel):
key = next(k for k, v in long_types.items() if v == value) key = next(k for k, v in long_types.items() if v == value)
self._undo.push( self._undo.push(
SetTypeCommand( 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( self._undo.push(
SetNodeCommand( SetEdgeCommand(
self._lcs, self._tab,row, self._data.node(value) self._lcs, self._tab,row, self._data.edge(value)
) )
) )
......
...@@ -26,21 +26,21 @@ class SetNameCommand(QUndoCommand): ...@@ -26,21 +26,21 @@ class SetNameCommand(QUndoCommand):
def redo(self): def redo(self):
self._lcs.get(self._tab, self._index).name = self._new self._lcs.get(self._tab, self._index).name = self._new
class SetNodeCommand(QUndoCommand): class SetEdgeCommand(QUndoCommand):
def __init__(self, lcs, tab, index, node): def __init__(self, lcs, tab, index, edge):
QUndoCommand.__init__(self) QUndoCommand.__init__(self)
self._lcs = lcs self._lcs = lcs
self._tab = tab self._tab = tab
self._index = index self._index = index
self._old = self._lcs.get(self._tab, self._index).node self._old = self._lcs.get(self._tab, self._index).edge
self._new = node self._new = edge
def undo(self): 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): 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): class SetTypeCommand(QUndoCommand):
def __init__(self, lcs, tab, index, _type): def __init__(self, lcs, tab, index, _type):
......
...@@ -23,7 +23,7 @@ from PyQt5.QtWidgets import ( ...@@ -23,7 +23,7 @@ from PyQt5.QtWidgets import (
) )
from View.LateralContribution.UndoCommand import ( from View.LateralContribution.UndoCommand import (
SetNameCommand, SetNodeCommand, SetTypeCommand, SetNameCommand, SetEdgeCommand, SetTypeCommand,
AddCommand, DelCommand, SortCommand, AddCommand, DelCommand, SortCommand,
MoveCommand, PasteCommand, DuplicateCommand, MoveCommand, PasteCommand, DuplicateCommand,
) )
...@@ -88,9 +88,9 @@ class LateralContributionWindow(ASubMainWindow, ListedSubWindow): ...@@ -88,9 +88,9 @@ class LateralContributionWindow(ASubMainWindow, ListedSubWindow):
tab = t, tab = t,
parent=self parent=self
) )
self._delegate_node = ComboBoxDelegate( self._delegate_edge = ComboBoxDelegate(
data = self._study.river, data = self._study.river,
mode = "node", mode = "edge",
tab = t, tab = t,
parent=self parent=self
) )
...@@ -99,7 +99,7 @@ class LateralContributionWindow(ASubMainWindow, ListedSubWindow): ...@@ -99,7 +99,7 @@ class LateralContributionWindow(ASubMainWindow, ListedSubWindow):
1, self._delegate_type 1, self._delegate_type
) )
table.setItemDelegateForColumn( table.setItemDelegateForColumn(
2, self._delegate_node 2, self._delegate_edge
) )
table.setSelectionBehavior(QAbstractItemView.SelectRows) table.setSelectionBehavior(QAbstractItemView.SelectRows)
......
...@@ -20,10 +20,10 @@ long_types = { ...@@ -20,10 +20,10 @@ long_types = {
table_headers = { table_headers = {
"name": _translate("LateralContribution", "Name"), "name": _translate("LateralContribution", "Name"),
"type": _translate("LateralContribution", "Type"), "type": _translate("LateralContribution", "Type"),
"node": _translate("LateralContribution", "Node") "edge": _translate("LateralContribution", "Edge")
} }
BC_types = { LC_types = {
"ND": NotDefined, "ND": NotDefined,
"PC": PonctualContribution, "PC": PonctualContribution,
"TZ": TimeOverZ, "TZ": TimeOverZ,
......
<?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>
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment