mirror of https://gitlab.com/pamhyr/pamhyr2
Compare commits
4 Commits
1e2a123693
...
f4d3f2b28f
| Author | SHA1 | Date |
|---|---|---|
|
|
f4d3f2b28f | |
|
|
2a1c8c1e57 | |
|
|
a3da09cf5b | |
|
|
017f26c03d |
|
|
@ -47,6 +47,8 @@ class Point(SQLSubModel):
|
||||||
else:
|
else:
|
||||||
self._sl = sl
|
self._sl = sl
|
||||||
|
|
||||||
|
self.modified()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
return self._name
|
return self._name
|
||||||
|
|
@ -54,7 +56,7 @@ class Point(SQLSubModel):
|
||||||
@name.setter
|
@name.setter
|
||||||
def name(self, name):
|
def name(self, name):
|
||||||
self._name = name
|
self._name = name
|
||||||
self._status.modified()
|
self.modified()
|
||||||
|
|
||||||
def point_is_named(self):
|
def point_is_named(self):
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
|
|
@ -273,6 +273,22 @@ class PointXYZ(Point):
|
||||||
|
|
||||||
return point
|
return point
|
||||||
|
|
||||||
|
def copy(self):
|
||||||
|
new_p = PointXYZ(
|
||||||
|
id=-1,
|
||||||
|
name=self.name,
|
||||||
|
x=self.x, y=self.y, z=self.z,
|
||||||
|
profile=self.profile,
|
||||||
|
status=self._status
|
||||||
|
)
|
||||||
|
if self.is_deleted():
|
||||||
|
new_p.set_as_deleted()
|
||||||
|
|
||||||
|
new_p._sl = self.sl
|
||||||
|
|
||||||
|
new_p.modified()
|
||||||
|
return new_p
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return f"({self._x}, {self._y}, {self._z}, {self._name})"
|
return f"({self._x}, {self._y}, {self._z}, {self._name})"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -202,7 +202,7 @@ class Profile(object):
|
||||||
if point in self._points:
|
if point in self._points:
|
||||||
point.set_as_not_deleted()
|
point.set_as_not_deleted()
|
||||||
else:
|
else:
|
||||||
self.points.insert(index, point)
|
self._points.insert(index, point)
|
||||||
|
|
||||||
self.modified()
|
self.modified()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -369,6 +369,27 @@ class ProfileXYZ(Profile, SQLSubModel):
|
||||||
|
|
||||||
return profile
|
return profile
|
||||||
|
|
||||||
|
def copy(self):
|
||||||
|
new_p = ProfileXYZ(
|
||||||
|
id=-1,
|
||||||
|
name=self.name,
|
||||||
|
rk=self.rk,
|
||||||
|
reach=self.reach,
|
||||||
|
status=self._status
|
||||||
|
)
|
||||||
|
if self.is_deleted():
|
||||||
|
new_p.set_as_deleted()
|
||||||
|
|
||||||
|
new_p._sl = self.sl
|
||||||
|
|
||||||
|
for point in self._points:
|
||||||
|
p = point.copy()
|
||||||
|
print(p)
|
||||||
|
new_p._points.append(p)
|
||||||
|
|
||||||
|
new_p.modified()
|
||||||
|
return new_p
|
||||||
|
|
||||||
def point_from_data(self, header, data):
|
def point_from_data(self, header, data):
|
||||||
def float_format(s: str):
|
def float_format(s: str):
|
||||||
return float(
|
return float(
|
||||||
|
|
|
||||||
|
|
@ -126,15 +126,12 @@ class Study(SQLModel):
|
||||||
|
|
||||||
is_new = False
|
is_new = False
|
||||||
fname = fname + "." + str(self._old_save_id)
|
fname = fname + "." + str(self._old_save_id)
|
||||||
if os.path.exists(self.filename) and ".backup" not in self.filename:
|
if os.path.exists(self.filename):
|
||||||
filename = os.path.join(fdir, "_PAMHYR_", "__old__", fname)
|
filename = os.path.join(fdir, "_PAMHYR_", "__old__", fname)
|
||||||
logger.debug(f"Backup previous version copy: {filename}")
|
logger.debug(f"Backup previous version copy: {filename}")
|
||||||
shutil.copy(self.filename, filename)
|
shutil.copy(self.filename, filename)
|
||||||
self._old_save_id += 1
|
self._old_save_id += 1
|
||||||
|
|
||||||
if ".backup" in self.filename:
|
|
||||||
is_new = True
|
|
||||||
|
|
||||||
if not os.path.exists(self.filename):
|
if not os.path.exists(self.filename):
|
||||||
is_new = True
|
is_new = True
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -241,7 +241,6 @@ class GeometryProfileTableModel(PamhyrTableModel):
|
||||||
self.layoutChanged.emit()
|
self.layoutChanged.emit()
|
||||||
|
|
||||||
def reverse(self):
|
def reverse(self):
|
||||||
|
|
||||||
self._undo.push(
|
self._undo.push(
|
||||||
ReverseCommand(
|
ReverseCommand(
|
||||||
self._data
|
self._data
|
||||||
|
|
@ -259,15 +258,16 @@ class GeometryProfileTableModel(PamhyrTableModel):
|
||||||
|
|
||||||
self.layoutAboutToBeChanged.emit()
|
self.layoutAboutToBeChanged.emit()
|
||||||
|
|
||||||
|
points = list(
|
||||||
|
map(
|
||||||
|
lambda d: self._data.point_from_data(header, d),
|
||||||
|
data
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
self._undo.push(
|
self._undo.push(
|
||||||
PasteCommand(
|
PasteCommand(
|
||||||
self._data, row,
|
self._data, row, points
|
||||||
list(
|
|
||||||
map(
|
|
||||||
lambda d: self._data.point_from_data(header, d),
|
|
||||||
data
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -294,13 +294,13 @@ class ProfileWindow(PamhyrWindow):
|
||||||
rows = table.selectionModel().selectedRows()
|
rows = table.selectionModel().selectedRows()
|
||||||
|
|
||||||
data = []
|
data = []
|
||||||
data.append(["x", "y", "z", "name"])
|
data.append(["name", "x", "y", "z"])
|
||||||
|
|
||||||
for row in rows:
|
for row in rows:
|
||||||
point = self._profile.point(row.row())
|
point = self._profile.point(row.row())
|
||||||
data.append(
|
data.append(
|
||||||
[
|
[
|
||||||
point.x, point.y, point.z, point.name
|
point.name, point.x, point.y, point.z
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -158,7 +158,7 @@ class PasteCommand(QUndoCommand):
|
||||||
self._row = row
|
self._row = row
|
||||||
self._profiles = list(
|
self._profiles = list(
|
||||||
map(
|
map(
|
||||||
lambda p: deepcopy(p),
|
lambda p: p.copy(),
|
||||||
profiles
|
profiles
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
@ -180,7 +180,7 @@ class DuplicateCommand(QUndoCommand):
|
||||||
self._rows = rows
|
self._rows = rows
|
||||||
self._profiles = list(
|
self._profiles = list(
|
||||||
map(
|
map(
|
||||||
lambda p: deepcopy(p),
|
lambda p: p.copy(),
|
||||||
profiles
|
profiles
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,7 @@
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
|
import shutil
|
||||||
import logging
|
import logging
|
||||||
import subprocess
|
import subprocess
|
||||||
from queue import Queue
|
from queue import Queue
|
||||||
|
|
@ -784,26 +785,16 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
|
||||||
self.conf.set_last_study(file_name)
|
self.conf.set_last_study(file_name)
|
||||||
else:
|
else:
|
||||||
file_name = self._study.filename + ".backup"
|
file_name = self._study.filename + ".backup"
|
||||||
|
shutil.copyfile(old, file_name)
|
||||||
|
|
||||||
self._study.filename = file_name
|
self._study.filename = file_name
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# sql_request_count = self._study.sql_save_request_count()
|
|
||||||
# progress = QProgressDialog(
|
|
||||||
# "Backup...", None,
|
|
||||||
# 0, sql_request_count,
|
|
||||||
# parent=self
|
|
||||||
# )
|
|
||||||
# progress.setWindowModality(Qt.WindowModal)
|
|
||||||
# progress.setValue(0)
|
|
||||||
|
|
||||||
status = f"Backup ({file_name})..."
|
status = f"Backup ({file_name})..."
|
||||||
logger.info(status)
|
logger.info(status)
|
||||||
self.statusbar.showMessage(status, 3000)
|
self.statusbar.showMessage(status, 3000)
|
||||||
|
|
||||||
self._study.save(
|
self._study.save()
|
||||||
# progress=lambda: progress.setValue(progress.value() + 1)
|
|
||||||
)
|
|
||||||
|
|
||||||
status += " Done"
|
status += " Done"
|
||||||
logger.info(status)
|
logger.info(status)
|
||||||
|
|
@ -864,12 +855,32 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
|
||||||
if os.path.exists(backup):
|
if os.path.exists(backup):
|
||||||
file_modified_date = time.ctime(os.path.getmtime(file))
|
file_modified_date = time.ctime(os.path.getmtime(file))
|
||||||
backup_modified_date = time.ctime(os.path.getmtime(backup))
|
backup_modified_date = time.ctime(os.path.getmtime(backup))
|
||||||
|
|
||||||
if backup_modified_date > file_modified_date:
|
if backup_modified_date > file_modified_date:
|
||||||
logger.info(f"Select backup ({backup})")
|
yes = self.dialog_open_backup_study()
|
||||||
file = backup
|
|
||||||
|
if yes:
|
||||||
|
logger.info(f"Select backup ({backup})")
|
||||||
|
file = backup
|
||||||
|
|
||||||
return file
|
return file
|
||||||
|
|
||||||
|
def dialog_open_backup_study(self):
|
||||||
|
dlg = QMessageBox(self)
|
||||||
|
|
||||||
|
dlg.setWindowTitle(self._trad["mb_open_backup_title"])
|
||||||
|
dlg.setText(self._trad["mb_open_backup_msg"])
|
||||||
|
opt = QMessageBox.No | QMessageBox.Yes
|
||||||
|
|
||||||
|
dlg.setStandardButtons(opt)
|
||||||
|
dlg.setIcon(QMessageBox.Question)
|
||||||
|
dlg.button(QMessageBox.Yes).setText(self._trad["Yes"])
|
||||||
|
dlg.button(QMessageBox.No).setText(self._trad["No"])
|
||||||
|
|
||||||
|
res = dlg.exec()
|
||||||
|
|
||||||
|
return res == QMessageBox.Yes
|
||||||
|
|
||||||
def dialog_close(self):
|
def dialog_close(self):
|
||||||
dlg = QMessageBox(self)
|
dlg = QMessageBox(self)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -200,6 +200,15 @@ class MainTranslate(UnitTranslate):
|
||||||
"Do you want to open again the last open study?"
|
"Do you want to open again the last open study?"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
self._dict["mb_open_backup_title"] = _translate(
|
||||||
|
"MainWindow", "Open backup file"
|
||||||
|
)
|
||||||
|
self._dict["mb_open_backup_msg"] = _translate(
|
||||||
|
"MainWindow",
|
||||||
|
"A more recent backup file as found for this study, "
|
||||||
|
+ "do you want to open the backup file?"
|
||||||
|
)
|
||||||
|
|
||||||
self._dict["mb_close_title"] = _translate(
|
self._dict["mb_close_title"] = _translate(
|
||||||
"MainWindow", "Close without saving study"
|
"MainWindow", "Close without saving study"
|
||||||
)
|
)
|
||||||
|
|
@ -207,6 +216,7 @@ class MainTranslate(UnitTranslate):
|
||||||
"MainWindow",
|
"MainWindow",
|
||||||
"Do you want to save current study before closing it?"
|
"Do you want to save current study before closing it?"
|
||||||
)
|
)
|
||||||
|
|
||||||
self._dict["x"] = _translate("MainWindow", "X (m)")
|
self._dict["x"] = _translate("MainWindow", "X (m)")
|
||||||
self._dict["y"] = _translate("MainWindow", "Y (m)")
|
self._dict["y"] = _translate("MainWindow", "Y (m)")
|
||||||
self._dict["Yes"] = _translate("MainWindow", "Yes")
|
self._dict["Yes"] = _translate("MainWindow", "Yes")
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue