mirror of https://gitlab.com/pamhyr/pamhyr2
import lateral contributions from file
parent
41cffd13e0
commit
80ae4c36ad
|
|
@ -38,7 +38,7 @@ from View.LateralContribution.UndoCommand import (
|
|||
SetNameCommand, SetEdgeCommand, SetTypeCommand,
|
||||
SetBeginCommand, SetEndCommand,
|
||||
AddCommand, DelCommand, SortCommand,
|
||||
MoveCommand, PasteCommand, DuplicateCommand,
|
||||
MoveCommand, PasteCommand, DuplicateCommand, ImportCommand,
|
||||
)
|
||||
|
||||
from Model.LateralContribution.LateralContributionTypes import (
|
||||
|
|
@ -116,6 +116,9 @@ class ComboBoxDelegate(QItemDelegate):
|
|||
def setModelData(self, editor, model, index):
|
||||
text = str(editor.currentText())
|
||||
|
||||
if self._data is None:
|
||||
value = text
|
||||
else:
|
||||
if self._mode == "rk" and self._data.reach is not None:
|
||||
profiles = list(
|
||||
filter(
|
||||
|
|
@ -293,3 +296,34 @@ class TableModel(PamhyrTableModel):
|
|||
|
||||
self.endMoveRows()
|
||||
self.layoutChanged.emit()
|
||||
|
||||
def read_from_lat(self, file_name):
|
||||
logger.debug(f"Import lateral contributions from {file_name}")
|
||||
data = []
|
||||
current_reach = -1
|
||||
with open(file_name, encoding="utf-8") as lat_file:
|
||||
for line in lat_file:
|
||||
if not (line.startswith("#") or
|
||||
line.startswith("*") or
|
||||
len(line) < 1):
|
||||
line = line.split()
|
||||
if line[0] == "$":
|
||||
current_reach = int(line[1]) - 1
|
||||
if (current_reach <= len(self._data.enable_edges()) and
|
||||
current_reach > 0) :
|
||||
data.append([self._data.enable_edges()[current_reach], float(line[2]), float(line[3])])
|
||||
else:
|
||||
if (current_reach <= len(self._data.enable_edges()) and
|
||||
current_reach > 0) :
|
||||
data[-1].append([float(line[0]), float(line[1])])
|
||||
|
||||
self.layoutAboutToBeChanged.emit()
|
||||
|
||||
self._undo.push(
|
||||
ImportCommand(
|
||||
self._lst, self._tab, data
|
||||
)
|
||||
)
|
||||
|
||||
self.layoutAboutToBeChanged.emit()
|
||||
self.layoutChanged.emit()
|
||||
|
|
|
|||
|
|
@ -28,6 +28,10 @@ from Model.LateralContribution.LateralContributionList import (
|
|||
LateralContributionList
|
||||
)
|
||||
|
||||
from Model.LateralContribution.LateralContributionTypes import (
|
||||
NotDefined, LateralContrib,
|
||||
)
|
||||
|
||||
|
||||
class SetNameCommand(QUndoCommand):
|
||||
def __init__(self, lcs, tab, index, new_value):
|
||||
|
|
@ -213,36 +217,72 @@ class MoveCommand(QUndoCommand):
|
|||
|
||||
|
||||
class PasteCommand(QUndoCommand):
|
||||
def __init__(self, lcs, tab, row, bc):
|
||||
def __init__(self, lcs, tab, row, lc):
|
||||
QUndoCommand.__init__(self)
|
||||
|
||||
self._lcs = lcs
|
||||
self._tab = tab
|
||||
self._row = row
|
||||
self._lc = deepcopy(bc)
|
||||
self._lc = deepcopy(lc)
|
||||
self._lc.reverse()
|
||||
|
||||
def undo(self):
|
||||
self._lcs.delete(self._tab, self._lc)
|
||||
|
||||
def redo(self):
|
||||
for bc in self._lc:
|
||||
self._lcs.insert(self._tab, self._row, bc)
|
||||
for lc in self._lc:
|
||||
self._lcs.insert(self._tab, self._row, lc)
|
||||
|
||||
|
||||
class ImportCommand(QUndoCommand):
|
||||
def __init__(self, lcs, tab, data):
|
||||
QUndoCommand.__init__(self)
|
||||
|
||||
self._tab = tab
|
||||
self._lcs = lcs
|
||||
self._data = data
|
||||
self._old_rows = list(range(len(self._lcs.get_tab(self._tab))))
|
||||
self._new_rows = list(range(len(self._data)))
|
||||
|
||||
self._new_lc = None
|
||||
self._old_lc = []
|
||||
for row in self._old_rows:
|
||||
self._old_lc.append((row, self._lcs.get(self._tab, row)))
|
||||
|
||||
def undo(self):
|
||||
self._lcs.delete_i(self._tab, self._new_rows)
|
||||
for row, el in self._old_lc:
|
||||
self._lcs.insert(self._tab, row, el)
|
||||
|
||||
def redo(self):
|
||||
self._lcs.delete_i(self._tab, self._old_rows)
|
||||
if self._new_lc == None:
|
||||
self._new_lc = []
|
||||
for row, data in enumerate(self._data):
|
||||
new = LateralContrib(status=self._lcs._status)
|
||||
new.edge = data[0]
|
||||
new.begin_rk = data[1]
|
||||
new.end_rk = data[2]
|
||||
for i, val in enumerate(data[3:]):
|
||||
new.insert(i, val)
|
||||
self._new_lc.append(new)
|
||||
|
||||
for row, el in enumerate(self._new_lc):
|
||||
self._lcs.insert(self._tab, row, el)
|
||||
|
||||
class DuplicateCommand(QUndoCommand):
|
||||
def __init__(self, lcs, tab, rows, bc):
|
||||
def __init__(self, lcs, tab, rows, lc):
|
||||
QUndoCommand.__init__(self)
|
||||
|
||||
self._lcs = lcs
|
||||
self._tab = tab
|
||||
self._rows = rows
|
||||
self._lc = deepcopy(bc)
|
||||
self._lc = deepcopy(lc)
|
||||
self._lc.reverse()
|
||||
|
||||
def undo(self):
|
||||
self._lcs.delete(self._tab, self._lc)
|
||||
|
||||
def redo(self):
|
||||
for bc in self._lcs:
|
||||
self._lcs.insert(self._tab, self._rows[0], bc)
|
||||
for lc in self._lcs:
|
||||
self._lcs.insert(self._tab, self._rows[0], lc)
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ from tools import trace, timer
|
|||
|
||||
from View.Tools.PamhyrWindow import PamhyrWindow
|
||||
|
||||
from PyQt5 import QtWidgets
|
||||
from PyQt5.QtGui import (
|
||||
QKeySequence,
|
||||
)
|
||||
|
|
@ -29,7 +30,7 @@ from PyQt5.QtGui import (
|
|||
from PyQt5.QtCore import (
|
||||
Qt, QVariant, QAbstractTableModel,
|
||||
QCoreApplication, QModelIndex, pyqtSlot,
|
||||
QRect,
|
||||
QRect, QSettings,
|
||||
)
|
||||
|
||||
from PyQt5.QtWidgets import (
|
||||
|
|
@ -153,6 +154,8 @@ class LateralContributionWindow(PamhyrWindow):
|
|||
)
|
||||
|
||||
def setup_connections(self):
|
||||
self.find(QAction, "action_import").triggered.connect(
|
||||
self.import_from_file)
|
||||
self.find(QAction, "action_add").triggered.connect(self.add)
|
||||
self.find(QAction, "action_del").triggered.connect(self.delete)
|
||||
self.find(QAction, "action_edit").triggered.connect(self.edit)
|
||||
|
|
@ -297,3 +300,26 @@ class LateralContributionWindow(PamhyrWindow):
|
|||
parent=self
|
||||
)
|
||||
win.show()
|
||||
|
||||
def import_from_file(self):
|
||||
options = QFileDialog.Options()
|
||||
settings = QSettings(QSettings.IniFormat,
|
||||
QSettings.UserScope, 'MyOrg', )
|
||||
options |= QFileDialog.DontUseNativeDialog
|
||||
|
||||
file_types = [
|
||||
self._trad["file_lat"],
|
||||
self._trad["file_all"],
|
||||
]
|
||||
|
||||
filename, _ = QtWidgets.QFileDialog.getOpenFileName(
|
||||
self,
|
||||
self._trad["open_file"],
|
||||
"",
|
||||
";; ".join(file_types),
|
||||
options=options
|
||||
)
|
||||
|
||||
if filename != "":
|
||||
tab = self.current_tab()
|
||||
self._table[tab].read_from_lat(filename)
|
||||
|
|
|
|||
|
|
@ -52,6 +52,10 @@ class LCTranslate(MainTranslate):
|
|||
self._dict["x"] = _translate("Geometry", "X (m)")
|
||||
self._dict["y"] = _translate("Geometry", "Y (m)")
|
||||
self._dict["z"] = _translate("Geometry", "Z (m)")
|
||||
self._dict["file_lat"] = _translate(
|
||||
"LateralContribution", "Shapefile (*.LAT *.lat)")
|
||||
self._dict["file_all"] = _translate(
|
||||
"LateralContribution", "All files (*)")
|
||||
|
||||
self._sub_dict["table_headers"] = {
|
||||
"name": self._dict["name"],
|
||||
|
|
|
|||
|
|
@ -112,6 +112,18 @@
|
|||
<string>Sort points</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="action_import">
|
||||
<property name="icon">
|
||||
<iconset>
|
||||
<normaloff>ressources/import.png</normaloff>ressources/import.png</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Import</string>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Import from file</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
|
|
|
|||
|
|
@ -97,6 +97,7 @@
|
|||
<attribute name="toolBarBreak">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
<addaction name="action_import"/>
|
||||
<addaction name="action_add"/>
|
||||
<addaction name="action_del"/>
|
||||
<addaction name="action_edit"/>
|
||||
|
|
@ -162,6 +163,18 @@
|
|||
<string>Sort by names</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="action_import">
|
||||
<property name="icon">
|
||||
<iconset>
|
||||
<normaloff>ressources/import.png</normaloff>ressources/import.png</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Import</string>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Import from file</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
|
|
|
|||
Loading…
Reference in New Issue