mirror of https://gitlab.com/pamhyr/pamhyr2
Friction: Rename 'Section' to 'Friction'.
parent
1d3cf8bd94
commit
956a0714a2
|
|
@ -29,7 +29,6 @@ class SQLModel(SQL):
|
|||
self._create() # Create db
|
||||
# self._save() # Save
|
||||
else:
|
||||
logger.info("Update database")
|
||||
self._update() # Update db scheme if necessary
|
||||
# self._load() # Load data
|
||||
|
||||
|
|
|
|||
|
|
@ -4,9 +4,9 @@ from tools import trace, timer
|
|||
|
||||
from Model.DB import SQLSubModel
|
||||
|
||||
class Section(SQLSubModel):
|
||||
class Friction(SQLSubModel):
|
||||
def __init__(self, name:str = "", status = None):
|
||||
super(Section, self).__init__()
|
||||
super(Friction, self).__init__()
|
||||
|
||||
self._status = status
|
||||
|
||||
|
|
@ -20,7 +20,7 @@ class Section(SQLSubModel):
|
|||
@classmethod
|
||||
def _sql_create(cls, execute):
|
||||
execute("""
|
||||
CREATE TABLE section(
|
||||
CREATE TABLE friction(
|
||||
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||
ind INTERGER NOT NULL,
|
||||
begin_kp REAL NOT NULL,
|
||||
|
|
@ -49,7 +49,7 @@ class Section(SQLSubModel):
|
|||
|
||||
table = execute(
|
||||
"SELECT ind, begin_kp, end_kp, begin_strickler, end_strickler " +
|
||||
f"FROM section WHERE reach = {reach.id}"
|
||||
f"FROM friction WHERE reach = {reach.id}"
|
||||
)
|
||||
|
||||
for _ in table:
|
||||
|
|
@ -61,7 +61,7 @@ class Section(SQLSubModel):
|
|||
bs = next(filter(lambda s: s.id == row[3], stricklers))
|
||||
es = next(filter(lambda s: s.id == row[4], stricklers))
|
||||
|
||||
# Create section
|
||||
# Create friction
|
||||
sec = cls(status = status)
|
||||
sec.edge = reach
|
||||
sec.begin_kp = row[1]
|
||||
|
|
@ -77,7 +77,7 @@ class Section(SQLSubModel):
|
|||
ind = data["ind"]
|
||||
execute(
|
||||
"INSERT INTO " +
|
||||
"section(ind, begin_kp, end_kp, reach, begin_strickler, end_strickler) " +
|
||||
"friction(ind, begin_kp, end_kp, reach, begin_strickler, end_strickler) " +
|
||||
"VALUES (" +
|
||||
f"{ind}, {self._begin_kp}, {self._end_kp}, " +
|
||||
f"{self._edge.id}, " +
|
||||
|
|
@ -1,35 +1,47 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
import logging
|
||||
|
||||
from copy import copy
|
||||
from tools import trace, timer
|
||||
|
||||
from Model.DB import SQLSubModel
|
||||
from Model.Section.Section import Section
|
||||
from Model.Friction.Friction import Friction
|
||||
|
||||
class SectionList(SQLSubModel):
|
||||
logger = logging.getLogger()
|
||||
|
||||
class FrictionList(SQLSubModel):
|
||||
_sub_classes = [
|
||||
Section
|
||||
Friction
|
||||
]
|
||||
|
||||
def __init__(self, status = None):
|
||||
super(SectionList, self).__init__()
|
||||
super(FrictionList, self).__init__()
|
||||
|
||||
self._status = status
|
||||
self._sections = []
|
||||
self._frictions = []
|
||||
|
||||
@classmethod
|
||||
def _sql_create(cls, execute):
|
||||
return cls._create_submodel(execute)
|
||||
|
||||
@classmethod
|
||||
def _sql_update_0_0_1(cls, execute, version):
|
||||
execute("ALTER TABLE `section` RENAME TO `friction`")
|
||||
|
||||
@classmethod
|
||||
def _sql_update(cls, execute, version):
|
||||
if version == "0.0.0":
|
||||
logger.info(f"Update friction TABLE from {version}")
|
||||
cls._sql_update_0_0_1(execute, version)
|
||||
|
||||
return True
|
||||
|
||||
@classmethod
|
||||
def _sql_load(cls, execute, data = None):
|
||||
new = cls(status = data['status'])
|
||||
|
||||
new._sections = Section._sql_load(
|
||||
new._frictions = Friction._sql_load(
|
||||
execute, data
|
||||
)
|
||||
|
||||
|
|
@ -37,67 +49,67 @@ class SectionList(SQLSubModel):
|
|||
|
||||
def _sql_save(self, execute, data = None):
|
||||
reach = data["reach"]
|
||||
execute(f"DELETE FROM section WHERE reach = {reach.id}")
|
||||
execute(f"DELETE FROM friction WHERE reach = {reach.id}")
|
||||
|
||||
ok = True
|
||||
ind = 0
|
||||
for section in self._sections:
|
||||
for friction in self._frictions:
|
||||
data["ind"] = ind
|
||||
ok &= section._sql_save(execute, data = data)
|
||||
ok &= friction._sql_save(execute, data = data)
|
||||
ind += 1
|
||||
|
||||
return ok
|
||||
|
||||
def __len__(self):
|
||||
return len(self._sections)
|
||||
return len(self._frictions)
|
||||
|
||||
@property
|
||||
def sections(self):
|
||||
return self._sections.copy()
|
||||
def frictions(self):
|
||||
return self._frictions.copy()
|
||||
|
||||
def get(self, row):
|
||||
return self._sections[row]
|
||||
return self._frictions[row]
|
||||
|
||||
def set(self, row, new):
|
||||
self._sections[row] = new
|
||||
self._frictions[row] = new
|
||||
self._status.modified()
|
||||
|
||||
def new(self, index):
|
||||
n = Section(status = self._status)
|
||||
self._sections.insert(index, n)
|
||||
n = Friction(status = self._status)
|
||||
self._frictions.insert(index, n)
|
||||
self._status.modified()
|
||||
return n
|
||||
|
||||
def insert(self, index, new):
|
||||
self._sections.insert(index, new)
|
||||
self._frictions.insert(index, new)
|
||||
self._status.modified()
|
||||
|
||||
def delete(self, sections):
|
||||
for section in sections:
|
||||
self._sections.remove(section)
|
||||
def delete(self, frictions):
|
||||
for friction in frictions:
|
||||
self._frictions.remove(friction)
|
||||
self._status.modified()
|
||||
|
||||
def delete_i(self, indexes):
|
||||
sections = list(
|
||||
frictions = list(
|
||||
map(
|
||||
lambda x: x[1],
|
||||
filter(
|
||||
lambda x: x[0] in indexes,
|
||||
enumerate(self._sections)
|
||||
enumerate(self._frictions)
|
||||
)
|
||||
)
|
||||
)
|
||||
self.delete(sections)
|
||||
self.delete(frictions)
|
||||
|
||||
def sort(self, reverse=False, key=None):
|
||||
self._sections.sort(reverse=reverse, key=key)
|
||||
self._frictions.sort(reverse=reverse, key=key)
|
||||
self._status.modified()
|
||||
|
||||
def move_up(self, index):
|
||||
if index < len(self._sections):
|
||||
if index < len(self._frictions):
|
||||
next = index - 1
|
||||
|
||||
l = self._sections
|
||||
l = self._frictions
|
||||
l[index], l[next] = l[next], l[index]
|
||||
self._status.modified()
|
||||
|
||||
|
|
@ -105,6 +117,6 @@ class SectionList(SQLSubModel):
|
|||
if index >= 0:
|
||||
prev = index + 1
|
||||
|
||||
l = self._sections
|
||||
l = self._frictions
|
||||
l[index], l[prev] = l[prev], l[index]
|
||||
self._status.modified()
|
||||
|
|
@ -13,7 +13,7 @@ from Model.BoundaryCondition.BoundaryConditionList import BoundaryConditionList
|
|||
from Model.LateralContribution.LateralContributionList import LateralContributionList
|
||||
from Model.InitialConditions.InitialConditionsDict import InitialConditionsDict
|
||||
from Model.Stricklers.StricklersList import StricklersList
|
||||
from Model.Section.SectionList import SectionList
|
||||
from Model.Friction.FrictionList import FrictionList
|
||||
from Model.SolverParameters.SolverParametersList import SolverParametersList
|
||||
|
||||
from Solver.Solvers import solver_type_list
|
||||
|
|
@ -86,7 +86,7 @@ class RiverNode(Node, SQLSubModel):
|
|||
class RiverReach(Edge, SQLSubModel):
|
||||
_sub_classes = [
|
||||
Reach,
|
||||
SectionList,
|
||||
FrictionList,
|
||||
]
|
||||
|
||||
def __init__(self, id:str, name:str,
|
||||
|
|
@ -100,7 +100,7 @@ class RiverReach(Edge, SQLSubModel):
|
|||
)
|
||||
|
||||
self._reach = Reach(status=self._status, parent=self)
|
||||
self._sections = SectionList(status = self._status)
|
||||
self._frictions = FrictionList(status = self._status)
|
||||
|
||||
@classmethod
|
||||
def _sql_create(cls, execute):
|
||||
|
|
@ -121,7 +121,7 @@ class RiverReach(Edge, SQLSubModel):
|
|||
|
||||
@classmethod
|
||||
def _sql_update(cls, execute, version):
|
||||
return True
|
||||
return cls._update_submodel(execute, version)
|
||||
|
||||
@classmethod
|
||||
def _sql_load(cls, execute, data = None):
|
||||
|
|
@ -149,7 +149,7 @@ class RiverReach(Edge, SQLSubModel):
|
|||
data["parent"] = new
|
||||
new._reach = Reach._sql_load(execute, data)
|
||||
|
||||
new._sections = SectionList._sql_load(execute, data)
|
||||
new._frictions = FrictionList._sql_load(execute, data)
|
||||
|
||||
reachs.append(new)
|
||||
|
||||
|
|
@ -172,7 +172,7 @@ class RiverReach(Edge, SQLSubModel):
|
|||
|
||||
data["reach"] = self
|
||||
|
||||
objs = [self._reach, self._sections]
|
||||
objs = [self._reach, self._frictions]
|
||||
return self._save_submodel(execute, objs, data)
|
||||
|
||||
@property
|
||||
|
|
@ -180,8 +180,8 @@ class RiverReach(Edge, SQLSubModel):
|
|||
return self._reach
|
||||
|
||||
@property
|
||||
def sections(self):
|
||||
return self._sections
|
||||
def frictions(self):
|
||||
return self._frictions
|
||||
|
||||
class River(Graph, SQLSubModel):
|
||||
_sub_classes = [
|
||||
|
|
@ -286,8 +286,8 @@ class River(Graph, SQLSubModel):
|
|||
return self._reach
|
||||
|
||||
@property
|
||||
def sections(self):
|
||||
return self._sections
|
||||
def frictions(self):
|
||||
return self._frictions
|
||||
|
||||
@property
|
||||
def boundary_condition(self):
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ class Study(SQLModel):
|
|||
|
||||
def __init__(self, filename = None, init_new = True):
|
||||
# Metadata
|
||||
self._version = "0.0.0"
|
||||
self._version = "0.0.1"
|
||||
self.creation_date = datetime.now()
|
||||
self.last_modification_date = datetime.now()
|
||||
self.last_save_date = datetime.now()
|
||||
|
|
@ -194,7 +194,9 @@ class Study(SQLModel):
|
|||
if version[0] == self._version:
|
||||
return True
|
||||
|
||||
if self._update_submodel(version):
|
||||
logger.info("Update database")
|
||||
|
||||
if self._update_submodel(version[0]):
|
||||
self.execute(f"UPDATE info SET value='{self._version}' WHERE key='version'")
|
||||
return True
|
||||
|
||||
|
|
|
|||
|
|
@ -225,17 +225,17 @@ class Mage(AbstractSolver):
|
|||
|
||||
id = 1
|
||||
for edge in edges:
|
||||
sections = edge.sections
|
||||
frictions = edge.frictions
|
||||
|
||||
for section in sections.sections:
|
||||
for friction in frictions.frictions:
|
||||
num = f"{id:>3}"
|
||||
bkp = f"{section.begin_kp:>10.3f}"
|
||||
ekp = f"{section.end_kp:>10.3f}"
|
||||
bkp = f"{friction.begin_kp:>10.3f}"
|
||||
ekp = f"{friction.end_kp:>10.3f}"
|
||||
|
||||
# if section.begin_kp != section.end_kp:
|
||||
# if friction.begin_kp != friction.end_kp:
|
||||
# print("TODO")
|
||||
|
||||
strickler = section.begin_strickler
|
||||
strickler = friction.begin_strickler
|
||||
coef_1 = f"{strickler.minor:>10.3f}"
|
||||
coef_2 = f"{strickler.medium:>10.3f}"
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
)
|
||||
)
|
||||
|
||||
|
|
@ -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])
|
||||
|
|
@ -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"),
|
||||
}
|
||||
|
|
@ -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()
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
@ -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"),
|
||||
}
|
||||
|
|
@ -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">
|
||||
|
|
|
|||
Loading…
Reference in New Issue