mirror of https://gitlab.com/pamhyr/pamhyr2
Compare commits
No commits in common. "f86cd4602ca2b0bf5619f0a0f06035f8c00e8d45" and "4d20c2457a667493bfdd472b6470f7103db842d8" have entirely different histories.
f86cd4602c
...
4d20c2457a
|
|
@ -214,7 +214,7 @@ class InternalMeshing(AMeshingTool):
|
|||
ratio = (alpha[j0] - beta[j0-1]) \
|
||||
/ (beta[j0] - beta[j0-1])
|
||||
if ratio < 0.0:
|
||||
logger.warning(f"ratio négatif {ratio}")
|
||||
print(f"ratio négatif {ratio}")
|
||||
# on double le point a gauche
|
||||
p = sect2.point(start2+j0-1).copy()
|
||||
sect2.insert_point(start2+j0-1, p)
|
||||
|
|
|
|||
|
|
@ -304,10 +304,8 @@ class BoundaryConditionAdisTS(SQLSubModel):
|
|||
|
||||
if pol_id not in pid_pol:
|
||||
# ⚠️ cas important : probablement déjà migré
|
||||
logger.warning(
|
||||
f"pol_id {pol_id} not in pid_pol " +
|
||||
"→ probably already migrated"
|
||||
)
|
||||
print(f"[WARN] pol_id {pol_id} not in pid_pol " +
|
||||
f"→ probably already migrated")
|
||||
continue
|
||||
|
||||
execute(
|
||||
|
|
|
|||
|
|
@ -338,13 +338,6 @@ class PointXYZ(Point):
|
|||
self._z = float(value)
|
||||
self.modified()
|
||||
|
||||
def shift(self, x, y, z):
|
||||
self.x += x
|
||||
self.y += y
|
||||
self.z += z
|
||||
|
||||
self.modified()
|
||||
|
||||
def get_coordinate(self):
|
||||
return (self._x, self._y, self._z)
|
||||
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ from typing import List
|
|||
from functools import reduce
|
||||
from dataclasses import dataclass
|
||||
|
||||
from tools import trace, timer, flatten
|
||||
from tools import timer, flatten
|
||||
from shapely import geometry
|
||||
|
||||
from Model.Tools.PamhyrDB import SQLSubModel
|
||||
|
|
@ -396,6 +396,7 @@ class ProfileXYZ(Profile, SQLSubModel):
|
|||
|
||||
for point in self._points:
|
||||
p = point.copy()
|
||||
print(p)
|
||||
new_p._points.append(p)
|
||||
|
||||
new_p.modified()
|
||||
|
|
@ -1073,10 +1074,16 @@ class ProfileXYZ(Profile, SQLSubModel):
|
|||
|
||||
def shift(self, x, y, z):
|
||||
for p in self._points:
|
||||
p.shift(x, y, z)
|
||||
p.x = p.x + x
|
||||
p.y = p.y + y
|
||||
p.z = p.z + z
|
||||
|
||||
self.modified()
|
||||
|
||||
def modified(self):
|
||||
self.tab_up_to_date = False
|
||||
self.station_up_to_date = False
|
||||
|
||||
def add_npoints(self, npoints):
|
||||
# add npoints in a profile
|
||||
for k in range(npoints):
|
||||
|
|
|
|||
|
|
@ -52,11 +52,6 @@ class Reach(SQLSubModel):
|
|||
self._guidelines_is_valid = False
|
||||
self._guidelines = {}
|
||||
|
||||
super(Reach, self).__init__(
|
||||
id=parent.pamhyr_id,
|
||||
status=status,
|
||||
)
|
||||
|
||||
@property
|
||||
def pamhyr_id(self):
|
||||
return self._parent.pamhyr_id
|
||||
|
|
@ -65,10 +60,6 @@ class Reach(SQLSubModel):
|
|||
def _pamhyr_id(self):
|
||||
return self._parent.pamhyr_id
|
||||
|
||||
@_pamhyr_id.setter
|
||||
def _pamhyr_id(self, id):
|
||||
return
|
||||
|
||||
@classmethod
|
||||
def _db_create(cls, execute):
|
||||
return cls._create_submodel(execute)
|
||||
|
|
@ -112,9 +103,6 @@ class Reach(SQLSubModel):
|
|||
predicate=lambda obj, data: True,
|
||||
modifier=lambda obj, data: None,
|
||||
data={}):
|
||||
if predicate(self, data):
|
||||
modifier(self, data)
|
||||
|
||||
for p in self._profiles:
|
||||
p._data_traversal(predicate, modifier, data)
|
||||
|
||||
|
|
@ -211,12 +199,13 @@ class Reach(SQLSubModel):
|
|||
else:
|
||||
gi = self.get_global_profil_index(index)
|
||||
profile.num = gi
|
||||
print(f"gi = {gi}")
|
||||
self._profiles.insert(gi, profile)
|
||||
|
||||
self.modified()
|
||||
|
||||
def delete(self, indexes):
|
||||
"""Set some elements as deleted in profile list
|
||||
"""Delete some elements in profile list
|
||||
|
||||
Args:
|
||||
indexes: The list of index to delete
|
||||
|
|
@ -258,7 +247,7 @@ class Reach(SQLSubModel):
|
|||
self.modified()
|
||||
|
||||
def delete_profiles(self, profiles):
|
||||
"""Set profiles list as deleted
|
||||
"""Delete some elements in profile list
|
||||
|
||||
Args:
|
||||
profiles: The list of profile to delete
|
||||
|
|
|
|||
|
|
@ -183,6 +183,7 @@ class BasicHS(SQLSubModel):
|
|||
bhs._data = BHSValue._db_load(
|
||||
execute, data
|
||||
)
|
||||
print(f"{bhs_pid} : {deleted}")
|
||||
if deleted:
|
||||
bhs.set_as_deleted()
|
||||
|
||||
|
|
|
|||
|
|
@ -588,6 +588,8 @@ class InitialConditions(SQLSubModel):
|
|||
for data in self._data:
|
||||
data_height[data["rk"].rk] = data["height"]
|
||||
|
||||
print(data_height)
|
||||
|
||||
incline = self._reach.reach.get_incline_median_mean()
|
||||
logger.debug(f"incline = {incline}")
|
||||
|
||||
|
|
|
|||
|
|
@ -104,12 +104,6 @@ class PollutantCharacteristics(SQLSubModel):
|
|||
self._ac = value
|
||||
elif key == 8:
|
||||
self._bc = value
|
||||
self.propagate_modified()
|
||||
|
||||
def propagate_modified(self):
|
||||
self.modified()
|
||||
if hasattr(self, "_pollutant") and self._pollutant:
|
||||
self._pollutant.modified()
|
||||
|
||||
@classmethod
|
||||
def _db_create(cls, execute, ext=""):
|
||||
|
|
@ -262,12 +256,6 @@ class PollutantCharacteristics(SQLSubModel):
|
|||
if not self.must_be_saved():
|
||||
return True
|
||||
|
||||
execute(
|
||||
"DELETE FROM pollutants_characteristics " +
|
||||
f"WHERE pamhyr_id = {self.id} " +
|
||||
f"AND scenario = {self._status.scenario_id}"
|
||||
)
|
||||
|
||||
execute(
|
||||
"INSERT INTO " +
|
||||
"pollutants_characteristics(pamhyr_id, deleted, " +
|
||||
|
|
@ -324,7 +312,7 @@ class Pollutants(SQLSubModel):
|
|||
@name.setter
|
||||
def name(self, name):
|
||||
self._name = name
|
||||
self.modified()
|
||||
self._status.modified()
|
||||
|
||||
@property
|
||||
def data(self):
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@
|
|||
from tools import trace, timer
|
||||
|
||||
from Model.Except import NotImplementedMethodeError
|
||||
from Model.Tools.PamhyrListExt import PamhyrModelList
|
||||
from Model.Tools.PamhyrList import PamhyrModelList
|
||||
from Model.Pollutants.Pollutants import Pollutants
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -263,6 +263,8 @@ class Reservoir(SQLSubModel):
|
|||
cls._db_update_to_0_2_0_set_node_pid(execute, table, nodes)
|
||||
Scenario.update_db_add_scenario(execute, table)
|
||||
|
||||
print(execute(f"SELECT * FROM {table}"))
|
||||
|
||||
cls._db_create(execute, ext="_tmp")
|
||||
execute(
|
||||
f"INSERT INTO {table}_tmp " +
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@
|
|||
import os
|
||||
import logging
|
||||
|
||||
from tools import logger_exception, timer, flatten
|
||||
from tools import logger_exception
|
||||
|
||||
from Model.Tools.PamhyrDB import SQLSubModel
|
||||
|
||||
|
|
@ -35,7 +35,7 @@ class Scenario(SQLSubModel):
|
|||
"output_rk_adists",
|
||||
"boundary_condition_adists", "boundary_condition_data_adists",
|
||||
"lateral_contribution_adists", "lateral_contribution_data_adists",
|
||||
"initial_conditions_adists", "initial_conditions_adists_spec",
|
||||
"initial_conditions_adists", "initial_conditions_adists_data",
|
||||
"d90_adists", "d90_adists_spec",
|
||||
"dif_adists_spec",
|
||||
"pollutants", "pollutants_characteristics",
|
||||
|
|
@ -225,13 +225,10 @@ class Scenario(SQLSubModel):
|
|||
|
||||
return aux(self, [])
|
||||
|
||||
@timer
|
||||
def clean_deleted_data(self, execute):
|
||||
def drop_deleted_data(self, execute):
|
||||
tables = self.tables_with_deleted_column
|
||||
branch = self.get_parent_branch()
|
||||
|
||||
all_ids = []
|
||||
|
||||
for table in tables:
|
||||
if self.parent is None:
|
||||
# This scenario is the default scenario, so we can
|
||||
|
|
@ -260,23 +257,17 @@ class Scenario(SQLSubModel):
|
|||
if ids is None or len(ids) == 0:
|
||||
continue
|
||||
|
||||
ids = flatten(ids)
|
||||
|
||||
logger.debug(
|
||||
f"({self.name}) Drop deleted data into '{table}' : {ids}"
|
||||
f"(s{self.id}) Drop deleted data into '{table}' : {ids}"
|
||||
)
|
||||
|
||||
execute(
|
||||
f"DELETE FROM {table} " +
|
||||
f"WHERE scenario = {self.id} " +
|
||||
"AND pamhyr_id IN " +
|
||||
f"({', '.join(map(str, ids))})"
|
||||
f"({', '.join(map(lambda x: str(x[0]), ids))})"
|
||||
)
|
||||
|
||||
all_ids += ids
|
||||
|
||||
return all_ids
|
||||
|
||||
@property
|
||||
def id(self):
|
||||
return self._id
|
||||
|
|
|
|||
|
|
@ -16,8 +16,6 @@
|
|||
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from functools import reduce
|
||||
|
||||
from tools import logger_exception
|
||||
|
||||
from Model.Tools.PamhyrDict import PamhyrModelDict
|
||||
|
|
@ -80,12 +78,3 @@ class Scenarios(PamhyrModelDict):
|
|||
|
||||
self._dict[key].set_as_deleted()
|
||||
self._status.modified()
|
||||
|
||||
def is_leaf(self, scenario):
|
||||
return not reduce(
|
||||
lambda acc, s: (
|
||||
acc or (not s.is_deleted() and s.parent is scenario)
|
||||
),
|
||||
self._dict.values(),
|
||||
False
|
||||
)
|
||||
|
|
|
|||
|
|
@ -24,21 +24,12 @@ from datetime import datetime
|
|||
from tools import timer, timestamp
|
||||
from functools import reduce
|
||||
|
||||
from Model.Tools.PamhyrListExt import PamhyrModelList
|
||||
from Model.Tools.PamhyrDict import PamhyrModelDict
|
||||
from Model.Tools.PamhyrDB import SQLModel
|
||||
from Model.Scenarios import Scenarios
|
||||
from Model.Scenario import Scenario
|
||||
from Model.Status import StudyStatus
|
||||
from Model.Except import NotImplementedMethodeError
|
||||
from Model.River import River
|
||||
from Model.Geometry.Reach import Reach
|
||||
from Model.HydraulicStructures.HydraulicStructures import (
|
||||
HydraulicStructure
|
||||
)
|
||||
from Model.HydraulicStructures.Basic.HydraulicStructures import (
|
||||
BasicHS
|
||||
)
|
||||
|
||||
from Checker.Study import *
|
||||
|
||||
|
|
@ -459,59 +450,14 @@ class Study(SQLModel):
|
|||
data=progress
|
||||
)
|
||||
|
||||
# Clear DB for current scenario
|
||||
ids = self.status.scenario.clean_deleted_data(self.execute)
|
||||
self.memory_clean(ids)
|
||||
# Clear DB for each scenarios
|
||||
for scenar in self.scenarios.lst:
|
||||
scenar.drop_deleted_data(self.execute)
|
||||
|
||||
progress()
|
||||
|
||||
self.commit()
|
||||
|
||||
@timer
|
||||
def memory_clean(self, ids):
|
||||
if len(ids) == 0:
|
||||
return
|
||||
|
||||
reach_class = Reach
|
||||
hs_classes = [HydraulicStructure, BasicHS]
|
||||
list_classes = set(PamhyrModelList.__subclasses__())
|
||||
dict_classes = set(PamhyrModelDict.__subclasses__())
|
||||
|
||||
def modifier(obj, data):
|
||||
t = type(obj)
|
||||
|
||||
if t is reach_class:
|
||||
obj._profiles = list(
|
||||
filter(
|
||||
lambda el: el.id not in ids,
|
||||
obj._profiles
|
||||
)
|
||||
)
|
||||
elif t in hs_classes:
|
||||
obj._data = list(
|
||||
filter(
|
||||
lambda el: el.id not in ids,
|
||||
obj._data
|
||||
)
|
||||
)
|
||||
elif t in dict_classes:
|
||||
new = {}
|
||||
for key in obj._dict:
|
||||
if obj._dict[key].id not in ids:
|
||||
new[key] = obj._dict[key]
|
||||
obj._dict = new
|
||||
elif t in list_classes:
|
||||
obj._lst = list(
|
||||
filter(
|
||||
lambda el: el.id not in ids,
|
||||
obj._lst
|
||||
)
|
||||
)
|
||||
|
||||
self.river._data_traversal(
|
||||
lambda o, d: True, modifier, {}
|
||||
)
|
||||
|
||||
def sql_save_request_count(self, *args, **kargs):
|
||||
return self._count()
|
||||
|
||||
|
|
|
|||
|
|
@ -26,8 +26,6 @@ from functools import reduce
|
|||
from SQL import SQL
|
||||
from Model.Except import NotImplementedMethodeError
|
||||
|
||||
from tools import trace
|
||||
|
||||
from Model.Tools.PamhyrID import PamhyrID
|
||||
|
||||
logger = logging.getLogger()
|
||||
|
|
@ -50,9 +48,11 @@ class SQLModel(SQL):
|
|||
self._cur = self._db.cursor()
|
||||
|
||||
if is_new:
|
||||
logger.info("Create database")
|
||||
self._create() # Create db
|
||||
# self._save() # Save
|
||||
else:
|
||||
logger.info("Update database")
|
||||
self._update() # Update db scheme if necessary
|
||||
# self._load() # Load data
|
||||
|
||||
|
|
@ -313,10 +313,8 @@ class SQLSubModel(PamhyrID):
|
|||
|
||||
if node_id not in nodes:
|
||||
# ⚠️ cas important : probablement déjà migré
|
||||
logger.warning(
|
||||
f"node_id {node_id} not in nodes " +
|
||||
"→ probably already migrated"
|
||||
)
|
||||
print(f"[WARN] node_id {node_id} not in nodes " +
|
||||
f"→ probably already migrated")
|
||||
continue
|
||||
|
||||
execute(
|
||||
|
|
|
|||
|
|
@ -97,9 +97,6 @@ class PamhyrModelDict(SQLSubModel):
|
|||
Nothing
|
||||
|
||||
"""
|
||||
if predicate(self, data):
|
||||
modifier(self, data)
|
||||
|
||||
for key in self._dict:
|
||||
self._dict[key]\
|
||||
._data_traversal(predicate, modifier, data)
|
||||
|
|
|
|||
|
|
@ -100,9 +100,6 @@ class PamhyrModelList(SQLSubModel):
|
|||
Nothing
|
||||
|
||||
"""
|
||||
if predicate(self, data):
|
||||
modifier(self, data)
|
||||
|
||||
for el in self._lst:
|
||||
el._data_traversal(predicate, modifier, data)
|
||||
|
||||
|
|
|
|||
|
|
@ -107,9 +107,6 @@ class PamhyrModelList(SQLSubModel):
|
|||
Returns:
|
||||
Nothing
|
||||
"""
|
||||
if predicate(self, data):
|
||||
modifier(self, data)
|
||||
|
||||
for el in self._lst:
|
||||
el._data_traversal(predicate, modifier, data)
|
||||
|
||||
|
|
|
|||
|
|
@ -426,6 +426,7 @@ class Rubar3(CommandLineSolver):
|
|||
coeff = coeff_min
|
||||
else:
|
||||
for s in lst:
|
||||
print(s.begin_rk, s.end_rk)
|
||||
if (rk >= s.begin_rk and rk <= s.end_rk or
|
||||
rk <= s.begin_rk and rk >= s.end_rk):
|
||||
coeff = s.begin_strickler # TODO: inerpolate
|
||||
|
|
@ -472,6 +473,7 @@ class Rubar3(CommandLineSolver):
|
|||
last = profiles[-1]
|
||||
|
||||
if first not in data or last not in data:
|
||||
print(data)
|
||||
logger.error(
|
||||
"Study initial condition is not fully defined"
|
||||
)
|
||||
|
|
|
|||
|
|
@ -251,6 +251,7 @@ class GeometryReachTableModel(PamhyrTableModel):
|
|||
self.layoutChanged.emit()
|
||||
|
||||
def meshing(self, mesher, data, tableView):
|
||||
|
||||
new_profiles = mesher.meshing(
|
||||
self._data,
|
||||
**data
|
||||
|
|
@ -286,6 +287,7 @@ class GeometryReachTableModel(PamhyrTableModel):
|
|||
self.layoutChanged.emit()
|
||||
|
||||
def purge(self, np_purge):
|
||||
|
||||
self._undo.push(
|
||||
PurgeCommand(
|
||||
self._data, np_purge
|
||||
|
|
@ -294,6 +296,7 @@ class GeometryReachTableModel(PamhyrTableModel):
|
|||
self.layoutChanged.emit()
|
||||
|
||||
def shift(self, rows, dx, dy, dz):
|
||||
|
||||
self._undo.push(
|
||||
ShiftCommand(
|
||||
self._data, rows, dx, dy, dz
|
||||
|
|
@ -302,6 +305,7 @@ class GeometryReachTableModel(PamhyrTableModel):
|
|||
self.layoutChanged.emit()
|
||||
|
||||
def change_reach(self, new_reach, parent):
|
||||
|
||||
self._undo.push(
|
||||
ChangeReachCommand(
|
||||
new_reach,
|
||||
|
|
|
|||
|
|
@ -411,13 +411,13 @@ class ShiftCommand(QUndoCommand):
|
|||
def undo(self):
|
||||
for i in self._rows:
|
||||
profile = self._reach.profiles[i]
|
||||
profile.shift(
|
||||
self._reach.profiles[i].shift(
|
||||
-self._dx, -self._dy, -self._dz
|
||||
)
|
||||
|
||||
def redo(self):
|
||||
for i in self._rows:
|
||||
profile = self._reach.profiles[i]
|
||||
profile.shift(
|
||||
self._reach.profiles[i].shift(
|
||||
self._dx, self._dy, self._dz
|
||||
)
|
||||
|
|
|
|||
|
|
@ -136,18 +136,13 @@ class PlotRKC(PamhyrPlot):
|
|||
hs_color = []
|
||||
index = self.parent.tableView.selectedIndexes()
|
||||
for i, hs in enumerate(lhs):
|
||||
section = hs.input_section
|
||||
if section is None:
|
||||
continue
|
||||
|
||||
if i == index[0].row():
|
||||
color = "blue"
|
||||
hs_color.append("blue")
|
||||
elif hs.enabled:
|
||||
color = "red"
|
||||
hs_color.append("red")
|
||||
else:
|
||||
color = "darkgrey"
|
||||
|
||||
x = section.rk
|
||||
hs_color.append("darkgrey")
|
||||
x = hs.input_section.rk
|
||||
if x is not None:
|
||||
a = self.canvas.axes.annotate(
|
||||
" > " + hs.name,
|
||||
|
|
@ -156,13 +151,12 @@ class PlotRKC(PamhyrPlot):
|
|||
verticalalignment='top',
|
||||
annotation_clip=True,
|
||||
fontsize=9,
|
||||
color=color,
|
||||
color=hs_color[-1],
|
||||
)
|
||||
self.anotate_lst.append(a)
|
||||
vx.append(x)
|
||||
vymin.append(min(z_min))
|
||||
vymax.append(max(z_max))
|
||||
hs_color.append(color)
|
||||
|
||||
self.hs_vlines = self.canvas.axes.vlines(
|
||||
x=vx, ymin=vymin, ymax=vymax,
|
||||
|
|
|
|||
|
|
@ -127,7 +127,7 @@ class ComboBoxDelegate(QItemDelegate):
|
|||
)
|
||||
)
|
||||
|
||||
value = profiles[0].pamhyr_id if len(profiles) > 0 else None
|
||||
value = profiles[0].rk if len(profiles) > 0 else None
|
||||
else:
|
||||
value = text
|
||||
|
||||
|
|
@ -222,25 +222,15 @@ class TableModel(PamhyrTableModel):
|
|||
)
|
||||
)
|
||||
elif self._headers[column] == "begin_rk":
|
||||
_edge = self._lst.get(self._tab, row).reach
|
||||
_begin_rk = next(
|
||||
p for p in _edge.reach.profiles
|
||||
if p.pamhyr_id == value
|
||||
)
|
||||
self._undo.push(
|
||||
SetBeginCommand(
|
||||
self._lst, self._tab, row, _begin_rk
|
||||
self._lst, self._tab, row, value
|
||||
)
|
||||
)
|
||||
elif self._headers[column] == "end_rk":
|
||||
_edge = self._lst.get(self._tab, row).reach
|
||||
_end_rk = next(
|
||||
p for p in _edge.reach.profiles
|
||||
if p.pamhyr_id == value
|
||||
)
|
||||
self._undo.push(
|
||||
SetEndCommand(
|
||||
self._lst, self._tab, row, _end_rk
|
||||
self._lst, self._tab, row, value
|
||||
)
|
||||
)
|
||||
except Exception as e:
|
||||
|
|
|
|||
|
|
@ -925,11 +925,9 @@ class GraphWidget(QGraphicsView):
|
|||
self.scale(scaleFactor, scaleFactor)
|
||||
|
||||
def mousePressEvent(self, event):
|
||||
if self._only_display:
|
||||
if self._only_display or self.graph._status.is_read_only():
|
||||
return
|
||||
|
||||
locked = self.graph._status.is_read_only()
|
||||
|
||||
pos = self.mapToScene(event.pos())
|
||||
self.clicked = True
|
||||
|
||||
|
|
@ -938,6 +936,9 @@ class GraphWidget(QGraphicsView):
|
|||
super(GraphWidget, self).mousePressEvent(event)
|
||||
return
|
||||
|
||||
if self.graph._status.is_read_only():
|
||||
return
|
||||
|
||||
# Move item and select edge item
|
||||
if self._state == "move":
|
||||
self._selected_new_edge_src_node = None
|
||||
|
|
@ -947,41 +948,39 @@ class GraphWidget(QGraphicsView):
|
|||
edge = items[0]
|
||||
if edge:
|
||||
self.set_current_edge(edge)
|
||||
if not locked:
|
||||
if items and type(items[0]) is NodeItem:
|
||||
self._mouse_origin_x = pos.x()
|
||||
self._mouse_origin_y = pos.y()
|
||||
self._current_moved_node = items[0]
|
||||
elif items and type(items[0]) is NodeItem:
|
||||
self._mouse_origin_x = pos.x()
|
||||
self._mouse_origin_y = pos.y()
|
||||
self._current_moved_node = items[0]
|
||||
|
||||
if not locked:
|
||||
# Add nodes and edges
|
||||
if self._state == "add":
|
||||
items = self.items(event.pos())
|
||||
nodes = list(filter(lambda i: type(i) is NodeItem, items))
|
||||
if not nodes:
|
||||
self.add_node(pos)
|
||||
self.set_selected_new_edge_src_node(None)
|
||||
# Add nodes and edges
|
||||
elif self._state == "add":
|
||||
items = self.items(event.pos())
|
||||
nodes = list(filter(lambda i: type(i) is NodeItem, items))
|
||||
if not nodes:
|
||||
self.add_node(pos)
|
||||
self.set_selected_new_edge_src_node(None)
|
||||
else:
|
||||
if self.selected_new_edge_src_node() is None:
|
||||
self.set_selected_new_edge_src_node(nodes[0])
|
||||
else:
|
||||
if self.selected_new_edge_src_node() is None:
|
||||
self.set_selected_new_edge_src_node(nodes[0])
|
||||
else:
|
||||
self.add_edge(self.selected_new_edge_src_node(), nodes[0])
|
||||
self.add_edge(self.selected_new_edge_src_node(), nodes[0])
|
||||
|
||||
# Delete nodes and edges
|
||||
elif self._state == "del":
|
||||
self._selected_new_edge_src_node = None
|
||||
items = list(
|
||||
filter(
|
||||
lambda i: type(i) is NodeItem or type(i) is EdgeItem,
|
||||
self.items(event.pos())
|
||||
)
|
||||
# Delete nodes and edges
|
||||
elif self._state == "del":
|
||||
self._selected_new_edge_src_node = None
|
||||
items = list(
|
||||
filter(
|
||||
lambda i: type(i) is NodeItem or type(i) is EdgeItem,
|
||||
self.items(event.pos())
|
||||
)
|
||||
if len(items) > 0:
|
||||
item = items[0]
|
||||
if type(item) is NodeItem:
|
||||
self.del_node(item)
|
||||
elif type(item) is EdgeItem:
|
||||
self.del_edge(item)
|
||||
)
|
||||
if len(items) > 0:
|
||||
item = items[0]
|
||||
if type(item) is NodeItem:
|
||||
self.del_node(item)
|
||||
elif type(item) is EdgeItem:
|
||||
self.del_edge(item)
|
||||
|
||||
self.update()
|
||||
super(GraphWidget, self).mousePressEvent(event)
|
||||
|
|
@ -989,12 +988,10 @@ class GraphWidget(QGraphicsView):
|
|||
def mouseReleaseEvent(self, event):
|
||||
self.clicked = False
|
||||
|
||||
if self._only_display:
|
||||
if self._only_display or self.graph._status.is_read_only():
|
||||
return
|
||||
|
||||
locked = self.graph._status.is_read_only()
|
||||
|
||||
if not locked and self._state == "move":
|
||||
if self._state == "move":
|
||||
if self._current_moved_node is not None:
|
||||
pos = self.mapToScene(event.pos())
|
||||
self._undo.push(
|
||||
|
|
@ -1010,8 +1007,10 @@ class GraphWidget(QGraphicsView):
|
|||
super(GraphWidget, self).mouseReleaseEvent(event)
|
||||
|
||||
def mouseMoveEvent(self, event):
|
||||
if self.graph._status.is_read_only():
|
||||
return
|
||||
|
||||
pos = self.mapToScene(event.pos())
|
||||
locked = self.graph._status.is_read_only()
|
||||
|
||||
# Selecte item on the fly
|
||||
items = self.items(event.pos())
|
||||
|
|
|
|||
|
|
@ -48,12 +48,7 @@ _translate = QCoreApplication.translate
|
|||
|
||||
class TableModel(PamhyrTableModel):
|
||||
def _setup_lst(self):
|
||||
self._lst = list(
|
||||
filter(
|
||||
lambda dif: dif._deleted is False,
|
||||
self._data._Pollutants._lst
|
||||
)
|
||||
)
|
||||
self._lst = self._data._Pollutants
|
||||
|
||||
def rowCount(self, parent):
|
||||
return len(self._lst)
|
||||
|
|
@ -66,7 +61,7 @@ class TableModel(PamhyrTableModel):
|
|||
column = index.column()
|
||||
|
||||
if self._headers[column] == "name":
|
||||
return self._lst[row].name
|
||||
return self._lst.get(row).name
|
||||
|
||||
return QVariant()
|
||||
|
||||
|
|
@ -96,36 +91,29 @@ class TableModel(PamhyrTableModel):
|
|||
|
||||
self._undo.push(
|
||||
AddCommand(
|
||||
self._data._Pollutants, row, self._data.ic_adists
|
||||
self._lst, row, self._data.ic_adists
|
||||
)
|
||||
)
|
||||
|
||||
self._setup_lst()
|
||||
self.endInsertRows()
|
||||
self.layoutChanged.emit()
|
||||
|
||||
def delete(self, rows, parent=QModelIndex()):
|
||||
self.beginRemoveRows(parent, rows[0], rows[-1])
|
||||
|
||||
data_rows = {
|
||||
id(pol): i for i, pol in enumerate(self._data._Pollutants._lst)
|
||||
}
|
||||
self._undo.push(
|
||||
DelCommand(
|
||||
self._data._Pollutants,
|
||||
[data_rows[id(self._lst[row])] for row in rows
|
||||
if 0 <= row < len(self._lst)],
|
||||
self._data.ic_adists
|
||||
self._lst, rows, self._data.ic_adists
|
||||
)
|
||||
)
|
||||
self._setup_lst()
|
||||
|
||||
self.endRemoveRows()
|
||||
self.layoutChanged.emit()
|
||||
|
||||
def enabled(self, row, enabled, parent=QModelIndex()):
|
||||
self._undo.push(
|
||||
SetEnabledCommand(
|
||||
self._data._Pollutants, row, enabled
|
||||
self._lst, row, enabled
|
||||
)
|
||||
)
|
||||
self.layoutChanged.emit()
|
||||
|
|
|
|||
|
|
@ -57,8 +57,6 @@ class DefaultMenu(AbstractMenu):
|
|||
class ScenarioMenu(AbstractMenu):
|
||||
def run(self):
|
||||
item = self._items[0]
|
||||
scenarios = item.graph._study.scenarios
|
||||
|
||||
current_scenario = item.graph._study.status.scenario.id
|
||||
|
||||
select = self._menu.addAction(self._trad["menu_select_scenario"])
|
||||
|
|
@ -66,9 +64,7 @@ class ScenarioMenu(AbstractMenu):
|
|||
delete = None
|
||||
|
||||
if item.scenario.id != 0:
|
||||
if scenarios.is_leaf(item.scenario):
|
||||
delete = self._menu.addAction(self._trad["menu_del_scenario"])
|
||||
|
||||
delete = self._menu.addAction(self._trad["menu_del_scenario"])
|
||||
if item.scenario.id == current_scenario:
|
||||
duplicate = self._menu.addAction(
|
||||
self._trad["menu_dup_scenario"]
|
||||
|
|
|
|||
|
|
@ -426,35 +426,30 @@ class GraphWidget(QGraphicsView):
|
|||
|
||||
dlg.setWindowTitle(self._trad["mb_save_title"])
|
||||
dlg.setText(self._trad["mb_save_msg"])
|
||||
opt = QMessageBox.Cancel | QMessageBox.Save | QMessageBox.Discard
|
||||
opt = QMessageBox.Save | QMessageBox.Cancel
|
||||
|
||||
dlg.setStandardButtons(opt)
|
||||
dlg.setIcon(QMessageBox.Warning)
|
||||
dlg.button(QMessageBox.Save).setText(self._trad["Save"])
|
||||
dlg.button(QMessageBox.Discard).setText(self._trad["Don't save"])
|
||||
dlg.button(QMessageBox.Cancel).setText(self._trad["Cancel"])
|
||||
|
||||
res = dlg.exec()
|
||||
|
||||
if res == QMessageBox.Save:
|
||||
return "Save"
|
||||
return True
|
||||
elif res == QMessageBox.Cancel:
|
||||
return "Cancel"
|
||||
else:
|
||||
return "Discard"
|
||||
return False
|
||||
|
||||
def select_scenario(self, item):
|
||||
if type(item) is not ScenarioItem:
|
||||
return
|
||||
|
||||
must_save = self.dialog_save()
|
||||
if must_save == "Cancel":
|
||||
return
|
||||
must_saved = self.dialog_save()
|
||||
|
||||
def fn():
|
||||
self._close_other_window()
|
||||
|
||||
if must_save == "Save":
|
||||
if must_saved:
|
||||
self._study.save()
|
||||
|
||||
self._undo.push(
|
||||
|
|
@ -470,16 +465,9 @@ class GraphWidget(QGraphicsView):
|
|||
self.changeScenario.emit(self.sender())
|
||||
|
||||
def new_scenario(self, pos):
|
||||
must_save = self.dialog_save()
|
||||
if must_save == "Cancel":
|
||||
return
|
||||
|
||||
def fn():
|
||||
self._close_other_window()
|
||||
|
||||
if must_save == "Save":
|
||||
self._study.save()
|
||||
|
||||
self._study.save()
|
||||
self._undo.push(
|
||||
AddScenariosCommand(
|
||||
self._study,
|
||||
|
|
@ -507,16 +495,9 @@ class GraphWidget(QGraphicsView):
|
|||
self.changeScenario.emit(self.sender())
|
||||
|
||||
def duplicate_scenario(self, item):
|
||||
must_save = self.dialog_save()
|
||||
if must_save == "Cancel":
|
||||
return
|
||||
|
||||
def fn():
|
||||
self._close_other_window()
|
||||
|
||||
if must_save == "Save":
|
||||
self._study.save()
|
||||
|
||||
# self._study.save()
|
||||
self._undo.push(
|
||||
DuplicateScenariosCommand(
|
||||
self._study,
|
||||
|
|
|
|||
|
|
@ -281,7 +281,6 @@ class MainTranslate(UnitTranslate):
|
|||
self._dict["No"] = _translate("MainWindow", "No")
|
||||
self._dict["Cancel"] = _translate("MainWindow", "Cancel")
|
||||
self._dict["Save"] = _translate("MainWindow", "Save")
|
||||
self._dict["Don't save"] = _translate("MainWindow", "Don't save")
|
||||
self._dict["Close"] = _translate("MainWindow", "Close")
|
||||
self._dict["Solver"] = _translate("MainWindow", "Solver")
|
||||
|
||||
|
|
|
|||
|
|
@ -90,7 +90,6 @@ class WaitingDialog(PamhyrDialog):
|
|||
options=[],
|
||||
parent=parent
|
||||
)
|
||||
self._to_close = False
|
||||
|
||||
self._payload_fn = payload_fn
|
||||
|
||||
|
|
@ -132,7 +131,7 @@ class WaitingDialog(PamhyrDialog):
|
|||
)
|
||||
|
||||
def end_worker(self):
|
||||
self._worker_thread.quit()
|
||||
self._worker_thread.terminate()
|
||||
self._worker_thread.wait()
|
||||
|
||||
def close(self):
|
||||
|
|
@ -142,12 +141,4 @@ class WaitingDialog(PamhyrDialog):
|
|||
except Exception as e:
|
||||
logger_exception(e)
|
||||
|
||||
self._to_close = True
|
||||
|
||||
super().close()
|
||||
|
||||
def closeEvent(self, event):
|
||||
if self._to_close:
|
||||
super().closeEvent(event)
|
||||
else:
|
||||
event.ignore()
|
||||
|
|
|
|||
Loading…
Reference in New Issue