mirror of https://gitlab.com/pamhyr/pamhyr2
Merge branch 'hydraulics-structure' of gitlab-ssh.irstea.fr:theophile.terraz/pamhyr into hydraulics-structure
commit
4eefa88490
|
|
@ -214,31 +214,17 @@ class Profile(object):
|
||||||
self.points.insert(index, point)
|
self.points.insert(index, point)
|
||||||
self._status.modified()
|
self._status.modified()
|
||||||
|
|
||||||
def delete(self, indexes: int):
|
def delete_i(self, indexes: list):
|
||||||
"""Delete points at index
|
self._points = list(
|
||||||
|
|
||||||
Args:
|
|
||||||
indexes: List of index of points.
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
Nothing.
|
|
||||||
"""
|
|
||||||
points = set(
|
|
||||||
map(
|
map(
|
||||||
lambda e: e[1],
|
lambda e: e[1],
|
||||||
filter(
|
filter(
|
||||||
lambda e: e[0] in indexes,
|
lambda e: e[0] not in indexes,
|
||||||
enumerate(self.points)
|
enumerate(self.points)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
self.points = list(
|
|
||||||
filter(
|
|
||||||
lambda p: p not in points,
|
|
||||||
self.points
|
|
||||||
)
|
|
||||||
)
|
|
||||||
self._status.modified()
|
self._status.modified()
|
||||||
|
|
||||||
def delete_points(self, points):
|
def delete_points(self, points):
|
||||||
|
|
@ -250,7 +236,7 @@ class Profile(object):
|
||||||
Returns:
|
Returns:
|
||||||
Nothing.
|
Nothing.
|
||||||
"""
|
"""
|
||||||
self.points = list(
|
self._points = list(
|
||||||
filter(
|
filter(
|
||||||
lambda p: p not in points,
|
lambda p: p not in points,
|
||||||
self.points
|
self.points
|
||||||
|
|
@ -286,7 +272,7 @@ class Profile(object):
|
||||||
elif column == 'z':
|
elif column == 'z':
|
||||||
def predicate(p): return p.z
|
def predicate(p): return p.z
|
||||||
|
|
||||||
self.points = sorted(
|
self._points = sorted(
|
||||||
self.points,
|
self.points,
|
||||||
key=predicate,
|
key=predicate,
|
||||||
reverse=is_reversed
|
reverse=is_reversed
|
||||||
|
|
@ -298,7 +284,7 @@ class Profile(object):
|
||||||
if len(self.points) != len(indexes):
|
if len(self.points) != len(indexes):
|
||||||
logger.critical("Indexes list do not correspond to point list")
|
logger.critical("Indexes list do not correspond to point list")
|
||||||
|
|
||||||
self.points = list(
|
self._points = list(
|
||||||
map(
|
map(
|
||||||
lambda x: x[1],
|
lambda x: x[1],
|
||||||
sorted(
|
sorted(
|
||||||
|
|
|
||||||
|
|
@ -127,10 +127,6 @@ class BasicHS(SQLSubModel):
|
||||||
return new
|
return new
|
||||||
|
|
||||||
def _db_save(self, execute, data=None):
|
def _db_save(self, execute, data=None):
|
||||||
execute(
|
|
||||||
"DELETE FROM hydraulic_structures_basic " +
|
|
||||||
f"WHERE id = {self.id}"
|
|
||||||
)
|
|
||||||
hs_id = data['hs_id']
|
hs_id = data['hs_id']
|
||||||
|
|
||||||
sql = (
|
sql = (
|
||||||
|
|
|
||||||
|
|
@ -172,6 +172,11 @@ class HydraulicStructure(SQLSubModel):
|
||||||
execute(sql)
|
execute(sql)
|
||||||
|
|
||||||
data['hs_id'] = self.id
|
data['hs_id'] = self.id
|
||||||
|
execute(
|
||||||
|
"DELETE FROM hydraulic_structures_basic " +
|
||||||
|
f"WHERE hs = {self.id}"
|
||||||
|
)
|
||||||
|
|
||||||
for basic in self._data:
|
for basic in self._data:
|
||||||
basic._db_save(execute, data)
|
basic._db_save(execute, data)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -250,7 +250,7 @@ class InitialConditions(SQLSubModel):
|
||||||
)
|
)
|
||||||
|
|
||||||
if new._data is not None:
|
if new._data is not None:
|
||||||
yield new
|
return new
|
||||||
|
|
||||||
def _db_save(self, execute, data=None):
|
def _db_save(self, execute, data=None):
|
||||||
ok = True
|
ok = True
|
||||||
|
|
|
||||||
|
|
@ -93,7 +93,7 @@ class AddCommand(QUndoCommand):
|
||||||
self._point = None
|
self._point = None
|
||||||
|
|
||||||
def undo(self):
|
def undo(self):
|
||||||
self._profile.delete([self._index])
|
self._profile.delete_i([self._index])
|
||||||
|
|
||||||
def redo(self):
|
def redo(self):
|
||||||
if self._point is None:
|
if self._point is None:
|
||||||
|
|
@ -119,7 +119,7 @@ class DelCommand(QUndoCommand):
|
||||||
self._profile.insert_point(row, point)
|
self._profile.insert_point(row, point)
|
||||||
|
|
||||||
def redo(self):
|
def redo(self):
|
||||||
self._profile.delete(self._rows)
|
self._profile.delete_i(self._rows)
|
||||||
|
|
||||||
|
|
||||||
class SortCommand(QUndoCommand):
|
class SortCommand(QUndoCommand):
|
||||||
|
|
@ -181,7 +181,7 @@ class PasteCommand(QUndoCommand):
|
||||||
|
|
||||||
def undo(self):
|
def undo(self):
|
||||||
for ind in range(len(self._points)):
|
for ind in range(len(self._points)):
|
||||||
self._profile.delete([self._row])
|
self._profile.delete_i([self._row])
|
||||||
|
|
||||||
def redo(self):
|
def redo(self):
|
||||||
for point in self._points:
|
for point in self._points:
|
||||||
|
|
|
||||||
|
|
@ -135,16 +135,13 @@ class ProfileWindow(PamhyrWindow):
|
||||||
self._tablemodel.blockSignals(False)
|
self._tablemodel.blockSignals(False)
|
||||||
|
|
||||||
def index_selected_row(self):
|
def index_selected_row(self):
|
||||||
rows = self._tablemodel\
|
table = self.find(QTableView, "tableView")
|
||||||
.selectionModel()\
|
rows = table.selectionModel()\
|
||||||
.selectedRows()
|
.selectedRows()
|
||||||
if len(rows) == 0:
|
if len(rows) == 0:
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
return self._tablemodel\
|
return rows[0].row()
|
||||||
.selectionModel()\
|
|
||||||
.selectedRows()[0]\
|
|
||||||
.row()
|
|
||||||
|
|
||||||
def add(self):
|
def add(self):
|
||||||
table = self.find(QTableView, "tableView")
|
table = self.find(QTableView, "tableView")
|
||||||
|
|
@ -213,24 +210,24 @@ class ProfileWindow(PamhyrWindow):
|
||||||
|
|
||||||
self.update_plot()
|
self.update_plot()
|
||||||
|
|
||||||
def copy(self):
|
def _copy(self):
|
||||||
rows = self._tablemodel\
|
table = self.find(QTableView, "tableView")
|
||||||
.selectionModel()\
|
rows = table.selectionModel().selectedRows()
|
||||||
.selectedRows()
|
|
||||||
table = []
|
data = []
|
||||||
table.append(["x", "y", "z", "name"])
|
data.append(["x", "y", "z", "name"])
|
||||||
|
|
||||||
for row in rows:
|
for row in rows:
|
||||||
point = self._profile.point(row.row())
|
point = self._profile.point(row.row())
|
||||||
table.append(
|
data.append(
|
||||||
[
|
[
|
||||||
point.x, point.y, point.z, point.name
|
point.x, point.y, point.z, point.name
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
self.copyTableIntoClipboard(table)
|
self.copyTableIntoClipboard(data)
|
||||||
|
|
||||||
def paste(self):
|
def _paste(self):
|
||||||
header, data = self.parseClipboardTable()
|
header, data = self.parseClipboardTable()
|
||||||
|
|
||||||
if len(data) == 0:
|
if len(data) == 0:
|
||||||
|
|
@ -245,10 +242,10 @@ class ProfileWindow(PamhyrWindow):
|
||||||
self._tablemodel.paste(row, header, data)
|
self._tablemodel.paste(row, header, data)
|
||||||
self.update_plot()
|
self.update_plot()
|
||||||
|
|
||||||
def undo(self):
|
def _undo(self):
|
||||||
self._tablemodel.undo()
|
self._tablemodel.undo()
|
||||||
self.update_plot()
|
self.update_plot()
|
||||||
|
|
||||||
def redo(self):
|
def _redo(self):
|
||||||
self._tablemodel.redo()
|
self._tablemodel.redo()
|
||||||
self.update_plot()
|
self.update_plot()
|
||||||
|
|
|
||||||
|
|
@ -108,7 +108,8 @@ class PlotAC(PamhyrPlot):
|
||||||
def update(self):
|
def update(self):
|
||||||
if self.line_kp is None:
|
if self.line_kp is None:
|
||||||
self.draw()
|
self.draw()
|
||||||
else:
|
return
|
||||||
|
|
||||||
if self._current_reach is None or self._current_profile is None:
|
if self._current_reach is None or self._current_profile is None:
|
||||||
self.clear()
|
self.clear()
|
||||||
return
|
return
|
||||||
|
|
@ -119,12 +120,15 @@ class PlotAC(PamhyrPlot):
|
||||||
|
|
||||||
self.line_kp.set_data(x, z)
|
self.line_kp.set_data(x, z)
|
||||||
|
|
||||||
self.canvas.axes.set_xlim(
|
self.canvas.axes.relim()
|
||||||
left=min(x), right=max(x)
|
self.canvas.axes.autoscale_view()
|
||||||
)
|
|
||||||
|
self.canvas.figure.tight_layout()
|
||||||
self.canvas.figure.canvas.draw_idle()
|
self.canvas.figure.canvas.draw_idle()
|
||||||
|
|
||||||
def clear(self):
|
def clear(self):
|
||||||
if self.line_kp is not None:
|
if self.line_kp is not None:
|
||||||
self.line_kp.set_data([], [])
|
self.line_kp.set_data([], [])
|
||||||
|
|
||||||
|
self.canvas.figure.tight_layout()
|
||||||
self.canvas.figure.canvas.draw_idle()
|
self.canvas.figure.canvas.draw_idle()
|
||||||
|
|
|
||||||
|
|
@ -139,6 +139,10 @@ class PlotKPC(PamhyrPlot):
|
||||||
[self._current_profile.kp, self._current_profile.kp],
|
[self._current_profile.kp, self._current_profile.kp],
|
||||||
[self._current_profile.z_min(), self._current_profile.z_max()],
|
[self._current_profile.z_min(), self._current_profile.z_max()],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
self.canvas.axes.relim()
|
||||||
|
self.canvas.axes.autoscale_view()
|
||||||
|
|
||||||
self.canvas.figure.canvas.draw_idle()
|
self.canvas.figure.canvas.draw_idle()
|
||||||
|
|
||||||
def clear(self):
|
def clear(self):
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue