Friction: Rename 'Section' to 'Friction'.

This commit is contained in:
Pierre-Antoine Rouby committed 2023-07-17 11:07:19 +02:00
1 parent 1d3cf8bd94
commit 956a0714a2
16 files changed
+362 -348

No files matched your search

@@ -17,8 +17,8 @@ class PlotStricklers(APlot):
toolbar=toolbar
)
def draw_sections(self, sections, color="r"):
lst = sections
def draw_frictions(self, frictions, color="r"):
lst = frictions
lst.sort(key = lambda s: s.begin_kp)
coef = flatten(
@@ -71,10 +71,10 @@ class PlotStricklers(APlot):
left = min(kp), right = max(kp)
)
sections = self.data.sections
if len(sections) != 0:
lst = sections.sections
self.draw_sections(lst)
frictions = self.data.frictions
if len(frictions) != 0:
lst = frictions.frictions
self.draw_frictions(lst)
# HightLight
kp_min, kp_max = (-1, -1)
@@ -85,10 +85,10 @@ class PlotStricklers(APlot):
filter(
lambda s: (s.begin_kp == kp_min and
s.end_kp == kp_max),
sections.sections
frictions.frictions
)
)
self.draw_sections(lst, color="b")
self.draw_frictions(lst, color="b")
self.canvas.figure.tight_layout()
self.canvas.figure.canvas.draw_idle()
@@ -15,14 +15,14 @@ from PyQt5.QtWidgets import (
QComboBox,
)
from View.Sections.UndoCommand import (
from View.Frictions.UndoCommand import (
SetNameCommand, SetBeginCommand, SetEndCommand,
SetBeginStricklerCommand, SetEndStricklerCommand,
AddCommand, DelCommand, SortCommand,
MoveCommand, PasteCommand, DuplicateCommand,
)
from View.Sections.translate import *
from View.Frictions.translate import *
_translate = QCoreApplication.translate
@@ -39,7 +39,7 @@ class ComboBoxDelegate(QItemDelegate):
if self._mode == "stricklers":
self.editor.addItems(
[_translate("Sections", "Not defined")] +
[_translate("Frictions", "Not defined")] +
list(
map(
lambda s: str(s),
@@ -79,7 +79,7 @@ class TableModel(QAbstractTableModel):
self._data = data
self._study = study
self._undo = undo
self._sections = self._data.sections
self._frictions = self._data.frictions
def flags(self, index):
options = Qt.ItemIsEnabled | Qt.ItemIsSelectable
@@ -88,7 +88,7 @@ class TableModel(QAbstractTableModel):
return options
def rowCount(self, parent):
return len(self._sections)
return len(self._frictions)
def columnCount(self, parent):
return len(self._headers)
@@ -101,27 +101,27 @@ class TableModel(QAbstractTableModel):
column = index.column()
if self._headers[column] == "name":
return self._sections.get(row).name
return self._frictions.get(row).name
elif self._headers[column] == "begin_kp":
return self._sections.get(row).begin_kp
return self._frictions.get(row).begin_kp
elif self._headers[column] == "end_kp":
return self._sections.get(row).end_kp
return self._frictions.get(row).end_kp
elif self._headers[column] == "begin_strickler":
value = self._sections.get(row).begin_strickler
value = self._frictions.get(row).begin_strickler
if value == None:
return _translate("Sections", "Not defined")
return _translate("Frictions", "Not defined")
return str(value)
elif self._headers[column] == "end_strickler":
value = self._sections.get(row).end_strickler
value = self._frictions.get(row).end_strickler
if value == None:
return _translate("Sections", "Not defined")
return _translate("Frictions", "Not defined")
return str(value)
return QVariant()
def headerData(self, section, orientation, role):
def headerData(self, friction, orientation, role):
if role == Qt.ItemDataRole.DisplayRole and orientation == Qt.Orientation.Horizontal:
return table_headers[self._headers[section]]
return table_headers[self._headers[friction]]
return QVariant()
@@ -135,31 +135,31 @@ class TableModel(QAbstractTableModel):
if self._headers[column] == "name":
self._undo.push(
SetNameCommand(
self._sections, row, value
self._frictions, row, value
)
)
elif self._headers[column] == "begin_kp":
self._undo.push(
SetBeginCommand(
self._sections, row, value
self._frictions, row, value
)
)
elif self._headers[column] == "end_kp":
self._undo.push(
SetEndCommand(
self._sections, row, value
self._frictions, row, value
)
)
elif self._headers[column] == "begin_strickler":
self._undo.push(
SetBeginStricklerCommand(
self._sections, row, self._study.river.strickler(value)
self._frictions, row, self._study.river.strickler(value)
)
)
elif self._headers[column] == "end_strickler":
self._undo.push(
SetEndStricklerCommand(
self._sections, row, self._study.river.strickler(value)
self._frictions, row, self._study.river.strickler(value)
)
)
@@ -171,7 +171,7 @@ class TableModel(QAbstractTableModel):
self._undo.push(
AddCommand(
self._sections, row, self._data
self._frictions, row, self._data
)
)
@@ -183,7 +183,7 @@ class TableModel(QAbstractTableModel):
self._undo.push(
DelCommand(
self._sections, rows
self._frictions, rows
)
)
@@ -195,7 +195,7 @@ class TableModel(QAbstractTableModel):
self._undo.push(
SortCommand(
self._sections, False
self._frictions, False
)
)
@@ -212,7 +212,7 @@ class TableModel(QAbstractTableModel):
self._undo_stack.push(
MoveCommand(
self._sections, "up", row
self._frictions, "up", row
)
)
@@ -220,7 +220,7 @@ class TableModel(QAbstractTableModel):
self.layoutChanged.emit()
def move_down(self, index, parent=QModelIndex()):
if row > len(self._sections):
if row > len(self._frictions):
return
target = row
@@ -229,7 +229,7 @@ class TableModel(QAbstractTableModel):
self._undo_stack.push(
MoveCommand(
self._sections, "down", row
self._frictions, "down", row
)
)
+226
View File
@@ -0,0 +1,226 @@
# -*- coding: utf-8 -*-
from copy import deepcopy
from tools import trace, timer
from PyQt5.QtWidgets import (
QMessageBox, QUndoCommand, QUndoStack,
)
from Model.Friction.Friction import Friction
from Model.Friction.FrictionList import FrictionList
class SetNameCommand(QUndoCommand):
def __init__(self, frictions, index, new_value):
QUndoCommand.__init__(self)
self._frictions = frictions
self._index = index
self._old = self._frictions.get(self._index).name
self._new = new_value
def undo(self):
self._frictions.get(self._index).name = self._old
def redo(self):
self._frictions.get(self._index).name = self._new
class SetBeginCommand(QUndoCommand):
def __init__(self, frictions, index, new_value):
QUndoCommand.__init__(self)
self._frictions = frictions
self._index = index
self._old = self._frictions.get(self._index).begin_kp
self._new = new_value
def undo(self):
self._frictions.get(self._index).begin_kp = float(self._old)
def redo(self):
self._frictions.get(self._index).begin_kp = float(self._new)
class SetEndCommand(QUndoCommand):
def __init__(self, frictions, index, new_value):
QUndoCommand.__init__(self)
self._frictions = frictions
self._index = index
self._old = self._frictions.get(self._index).end_kp
self._new = new_value
def undo(self):
self._frictions.get(self._index).end_kp = float(self._old)
def redo(self):
self._frictions.get(self._index).end_kp = float(self._new)
class SetBeginStricklerCommand(QUndoCommand):
def __init__(self, frictions, index, new_value):
QUndoCommand.__init__(self)
self._frictions = frictions
self._index = index
self._old = self._frictions.get(self._index).begin_strickler
self._new = new_value
def undo(self):
self._frictions.get(self._index).begin_strickler = self._old
def redo(self):
self._frictions.get(self._index).begin_strickler = self._new
class SetEndStricklerCommand(QUndoCommand):
def __init__(self, frictions, index, new_value):
QUndoCommand.__init__(self)
self._frictions = frictions
self._index = index
self._old = self._frictions.get(self._index).end_strickler
self._new = new_value
def undo(self):
self._frictions.get(self._index).end_strickler = self._old
def redo(self):
self._frictions.get(self._index).end_strickler = self._new
class SetEdgeCommand(QUndoCommand):
def __init__(self, frictions, index, edge):
QUndoCommand.__init__(self)
self._frictions = frictions
self._index = index
self._old = self._frictions.get(self._index).edge
self._new = edge
def undo(self):
self._frictions.get(self._index).edge = self._old
def redo(self):
self._frictions.get(self._index).edge = self._new
class AddCommand(QUndoCommand):
def __init__(self, frictions, index, reach):
QUndoCommand.__init__(self)
self._frictions = frictions
self._index = index
self._reach = reach
self._new = None
def undo(self):
self._frictions.delete_i([self._index])
def redo(self):
if self._new is None:
self._new = self._frictions.new(self._index)
self._new.edge = self._reach
else:
self._frictions.insert(self._index, self._new)
class DelCommand(QUndoCommand):
def __init__(self, frictions, rows):
QUndoCommand.__init__(self)
self._frictions = frictions
self._rows = rows
self._friction = []
for row in rows:
self._friction.append((row, self._frictions.get(row)))
self._friction.sort()
def undo(self):
for row, el in self._friction:
self._frictions.insert(row, el)
def redo(self):
self._frictions.delete_i(self._rows)
class SortCommand(QUndoCommand):
def __init__(self, frictions, _reverse):
QUndoCommand.__init__(self)
self._frictions = frictions
self._reverse = _reverse
self._old = self._frictions.frictions
self._indexes = None
def undo(self):
ll = self._frictions.frictions
self._frictions.sort(
key=lambda x: self._indexes[ll.index(x)]
)
def redo(self):
self._frictions.sort(
reverse=self._reverse,
key=lambda x: x.name
)
if self._indexes is None:
self._indexes = list(
map(
lambda p: self._old.index(p),
self._frictions.frictions
)
)
self._old = None
class MoveCommand(QUndoCommand):
def __init__(self, frictions, up, i):
QUndoCommand.__init__(self)
self._frictions = frictions
self._up = up == "up"
self._i = i
def undo(self):
if self._up:
self._frictions.move_up(self._i)
else:
self._frictions.move_down(self._i)
def redo(self):
if self._up:
self._frictions.move_up(self._i)
else:
self._frictions.move_down(self._i)
class PasteCommand(QUndoCommand):
def __init__(self, frictions, row, friction):
QUndoCommand.__init__(self)
self._frictions = frictions
self._row = row
self._friction = deepcopy(friction)
self._friction.reverse()
def undo(self):
self._frictions.delete(self._friction)
def redo(self):
for friction in self._friction:
self._frictions.insert(self._row, friction)
class DuplicateCommand(QUndoCommand):
def __init__(self, frictions, rows, friction):
QUndoCommand.__init__(self)
self._frictions = frictions
self._rows = rows
self._friction = deepcopy(friction)
self._friction.reverse()
def undo(self):
self._frictions.delete(self._friction)
def redo(self):
for friction in self._frictions:
self._frictions.insert(self._rows[0], friction)
@@ -24,18 +24,18 @@ from PyQt5.QtWidgets import (
QComboBox, QVBoxLayout, QHeaderView, QTabWidget,
)
from View.Sections.UndoCommand import (
from View.Frictions.UndoCommand import (
PasteCommand, DuplicateCommand,
)
from View.Sections.Table import (
from View.Frictions.Table import (
TableModel, ComboBoxDelegate
)
from View.Plot.MplCanvas import MplCanvas
from View.Geometry.PlotKPC import PlotKPC
from View.Sections.PlotStricklers import PlotStricklers
from View.Sections.translate import *
from View.Frictions.PlotStricklers import PlotStricklers
from View.Frictions.translate import *
from View.Stricklers.Window import StricklersWindow
@@ -43,16 +43,16 @@ _translate = QCoreApplication.translate
logger = logging.getLogger()
class SectionsWindow(ASubMainWindow, ListedSubWindow):
def __init__(self, title="Sections", study=None, parent=None):
class FrictionsWindow(ASubMainWindow, ListedSubWindow):
def __init__(self, title="Frictions", study=None, parent=None):
self._study = study
self._reach = self._study.river._current_reach
self._sections = self._reach.sections
self._reach = self._study.river.current_reach()
self._frictions = self._reach.frictions
self.setup_title(title)
super(SectionsWindow, self).__init__(
name=self._title, ui="Sections", parent=parent
super(FrictionsWindow, self).__init__(
name=self._title, ui="Frictions", parent=parent
)
self.setup_sc()
@@ -174,7 +174,7 @@ class SectionsWindow(ASubMainWindow, ListedSubWindow):
if len(rows) > 0:
data = self._reach
reach = self._reach.reach
sec = self._sections.get(rows[0])
sec = self._frictions.get(rows[0])
highlight = (sec.begin_kp, sec.end_kp)
self.plot = PlotKPC(
@@ -194,7 +194,7 @@ class SectionsWindow(ASubMainWindow, ListedSubWindow):
def add(self):
rows = self.index_selected_rows()
if len(self._sections) == 0 or len(rows) == 0:
if len(self._frictions) == 0 or len(rows) == 0:
self._table.add(0)
else:
self._table.add(rows[0])
+14
View File
@@ -0,0 +1,14 @@
# -*- coding: utf-8 -*-
from PyQt5.QtCore import QCoreApplication
_translate = QCoreApplication.translate
table_headers = {
"name": _translate("Frictions", "Name"),
# "edge": _translate("Frictions", "Reach"),
"begin_kp": _translate("Frictions", "Begin kp (m)"),
"end_kp": _translate("Frictions", "End kp (m)"),
"begin_strickler": _translate("Frictions", "Begin strickler"),
"end_strickler": _translate("Frictions", "End strickler"),
}
+8 -7
View File
@@ -32,7 +32,7 @@ from View.BoundaryCondition.Window import BoundaryConditionWindow
from View.LateralContribution.Window import LateralContributionWindow
from View.InitialConditions.Window import InitialConditionsWindow
from View.Stricklers.Window import StricklersWindow
from View.Sections.Window import SectionsWindow
from View.Frictions.Window import FrictionsWindow
from View.SolverParameters.Window import SolverParametersWindow
from View.RunSolver.Window import SelectSolverWindow, SolverLogWindow
from View.CheckList.Window import CheckListWindow
@@ -62,7 +62,7 @@ define_model_action = [
"action_toolBar_network", "action_toolBar_geometry",
"action_toolBar_mesh", "action_toolBar_run_meshing_tool",
"action_toolBar_boundary_cond", "action_toolBar_lateral_contrib",
"action_toolBar_spills", "action_toolBar_sections",
"action_toolBar_spills", "action_toolBar_frictions",
"action_toolBar_stricklers", "action_toolBar_building",
"action_toolBar_initial_cond",
# Menu
@@ -144,7 +144,7 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
"action_menu_edit_geometry": self.open_geometry,
"action_menu_boundary_conditions": self.open_boundary_cond,
"action_menu_initial_conditions": self.open_initial_conditions,
"action_menu_edit_friction": self.open_sections,
"action_menu_edit_friction": self.open_frictions,
"action_menu_edit_lateral_contribution": self.open_lateral_contrib,
"action_menu_run_solver": self.run_solver,
## Help
@@ -164,12 +164,13 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
"action_toolBar_lateral_contrib": self.open_lateral_contrib,
"action_toolBar_spills": lambda: self.open_dummy("Deversement"),
"action_toolBar_stricklers": self.open_stricklers,
"action_toolBar_sections": self.open_sections,
"action_toolBar_frictions": self.open_frictions,
"action_toolBar_building": lambda: self.open_dummy("Ouvrages"),
"action_toolBar_initial_cond": self.open_initial_conditions,
}
for action in actions:
logger.debug("Setup connection : " + action)
self.findChild(QAction, action)\
.triggered.connect(actions[action])
# action.triggered.connect(actions[action])
@@ -461,14 +462,14 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
)
strick.show()
def open_sections(self):
def open_frictions(self):
if (self.model is not None and
self.model.river.has_current_reach()):
sections = SectionsWindow(
frictions = FrictionsWindow(
study = self.model,
parent = self
)
sections.show()
frictions.show()
else:
self.msg_select_reach()
-226
View File
@@ -1,226 +0,0 @@
# -*- coding: utf-8 -*-
from copy import deepcopy
from tools import trace, timer
from PyQt5.QtWidgets import (
QMessageBox, QUndoCommand, QUndoStack,
)
from Model.Section.Section import Section
from Model.Section.SectionList import SectionList
class SetNameCommand(QUndoCommand):
def __init__(self, sections, index, new_value):
QUndoCommand.__init__(self)
self._sections = sections
self._index = index
self._old = self._sections.get(self._index).name
self._new = new_value
def undo(self):
self._sections.get(self._index).name = self._old
def redo(self):
self._sections.get(self._index).name = self._new
class SetBeginCommand(QUndoCommand):
def __init__(self, sections, index, new_value):
QUndoCommand.__init__(self)
self._sections = sections
self._index = index
self._old = self._sections.get(self._index).begin_kp
self._new = new_value
def undo(self):
self._sections.get(self._index).begin_kp = float(self._old)
def redo(self):
self._sections.get(self._index).begin_kp = float(self._new)
class SetEndCommand(QUndoCommand):
def __init__(self, sections, index, new_value):
QUndoCommand.__init__(self)
self._sections = sections
self._index = index
self._old = self._sections.get(self._index).end_kp
self._new = new_value
def undo(self):
self._sections.get(self._index).end_kp = float(self._old)
def redo(self):
self._sections.get(self._index).end_kp = float(self._new)
class SetBeginStricklerCommand(QUndoCommand):
def __init__(self, sections, index, new_value):
QUndoCommand.__init__(self)
self._sections = sections
self._index = index
self._old = self._sections.get(self._index).begin_strickler
self._new = new_value
def undo(self):
self._sections.get(self._index).begin_strickler = self._old
def redo(self):
self._sections.get(self._index).begin_strickler = self._new
class SetEndStricklerCommand(QUndoCommand):
def __init__(self, sections, index, new_value):
QUndoCommand.__init__(self)
self._sections = sections
self._index = index
self._old = self._sections.get(self._index).end_strickler
self._new = new_value
def undo(self):
self._sections.get(self._index).end_strickler = self._old
def redo(self):
self._sections.get(self._index).end_strickler = self._new
class SetEdgeCommand(QUndoCommand):
def __init__(self, sections, index, edge):
QUndoCommand.__init__(self)
self._sections = sections
self._index = index
self._old = self._sections.get(self._index).edge
self._new = edge
def undo(self):
self._sections.get(self._index).edge = self._old
def redo(self):
self._sections.get(self._index).edge = self._new
class AddCommand(QUndoCommand):
def __init__(self, sections, index, reach):
QUndoCommand.__init__(self)
self._sections = sections
self._index = index
self._reach = reach
self._new = None
def undo(self):
self._sections.delete_i([self._index])
def redo(self):
if self._new is None:
self._new = self._sections.new(self._index)
self._new.edge = self._reach
else:
self._sections.insert(self._index, self._new)
class DelCommand(QUndoCommand):
def __init__(self, sections, rows):
QUndoCommand.__init__(self)
self._sections = sections
self._rows = rows
self._section = []
for row in rows:
self._section.append((row, self._sections.get(row)))
self._section.sort()
def undo(self):
for row, el in self._section:
self._sections.insert(row, el)
def redo(self):
self._sections.delete_i(self._rows)
class SortCommand(QUndoCommand):
def __init__(self, sections, _reverse):
QUndoCommand.__init__(self)
self._sections = sections
self._reverse = _reverse
self._old = self._sections.sections
self._indexes = None
def undo(self):
ll = self._sections.sections
self._sections.sort(
key=lambda x: self._indexes[ll.index(x)]
)
def redo(self):
self._sections.sort(
reverse=self._reverse,
key=lambda x: x.name
)
if self._indexes is None:
self._indexes = list(
map(
lambda p: self._old.index(p),
self._sections.sections
)
)
self._old = None
class MoveCommand(QUndoCommand):
def __init__(self, sections, up, i):
QUndoCommand.__init__(self)
self._sections = sections
self._up = up == "up"
self._i = i
def undo(self):
if self._up:
self._sections.move_up(self._i)
else:
self._sections.move_down(self._i)
def redo(self):
if self._up:
self._sections.move_up(self._i)
else:
self._sections.move_down(self._i)
class PasteCommand(QUndoCommand):
def __init__(self, sections, row, section):
QUndoCommand.__init__(self)
self._sections = sections
self._row = row
self._section = deepcopy(section)
self._section.reverse()
def undo(self):
self._sections.delete(self._section)
def redo(self):
for section in self._section:
self._sections.insert(self._row, section)
class DuplicateCommand(QUndoCommand):
def __init__(self, sections, rows, section):
QUndoCommand.__init__(self)
self._sections = sections
self._rows = rows
self._section = deepcopy(section)
self._section.reverse()
def undo(self):
self._sections.delete(self._section)
def redo(self):
for section in self._sections:
self._sections.insert(self._rows[0], section)
-14
View File
@@ -1,14 +0,0 @@
# -*- coding: utf-8 -*-
from PyQt5.QtCore import QCoreApplication
_translate = QCoreApplication.translate
table_headers = {
"name": _translate("Sections", "Name"),
# "edge": _translate("Sections", "Reach"),
"begin_kp": _translate("Sections", "Begin kp (m)"),
"end_kp": _translate("Sections", "End kp (m)"),
"begin_strickler": _translate("Sections", "Begin strickler"),
"end_strickler": _translate("Sections", "End strickler"),
}
File renamed without changes.
+4 -4
View File
@@ -292,7 +292,7 @@
<addaction name="separator"/>
<addaction name="action_toolBar_spills"/>
<addaction name="separator"/>
<addaction name="action_toolBar_sections"/>
<addaction name="action_toolBar_frictions"/>
<addaction name="separator"/>
<addaction name="action_toolBar_building"/>
<addaction name="separator"/>
@@ -858,12 +858,12 @@
<string>Edit lateral spills</string>
</property>
</action>
<action name="action_toolBar_sections">
<action name="action_toolBar_frictions">
<property name="text">
<string>Sections</string>
<string>Friction</string>
</property>
<property name="toolTip">
<string>Edit section frictions and lateral contributions</string>
<string>Edit friction frictions and lateral contributions</string>
</property>
</action>
<action name="action_toolBar_stricklers">