mirror of https://gitlab.com/pamhyr/pamhyr2
Geometry: Activate export to file.
parent
1965782348
commit
63f7095508
|
|
@ -167,7 +167,7 @@ class GeometryWindow(PamhyrWindow):
|
|||
def setup_connections(self):
|
||||
actions = {
|
||||
"action_import": self.import_from_file,
|
||||
# "action_export": self.export_to_file,
|
||||
"action_export": self.export_to_file,
|
||||
"action_sort_asc": self.sort_ascending,
|
||||
"action_sort_des": self.sort_descending,
|
||||
"action_up": self.move_up,
|
||||
|
|
@ -535,21 +535,67 @@ class GeometryWindow(PamhyrWindow):
|
|||
self.update_plot_kpc()
|
||||
|
||||
def export_to_file(self):
|
||||
settings = QSettings(
|
||||
QSettings.IniFormat,
|
||||
QSettings.UserScope, 'MyOrg'
|
||||
)
|
||||
|
||||
if self._study.filename != "" or self._study.filename != None:
|
||||
default_directory = os.path.basename(self._study.filename)
|
||||
current_dir = settings.value(
|
||||
'current_directory',
|
||||
default_directory,
|
||||
type=str
|
||||
)
|
||||
|
||||
options = QFileDialog.Options()
|
||||
DEFAULT_DIRECTORY = '/home/'
|
||||
settings = QSettings(QSettings.IniFormat,
|
||||
QSettings.UserScope, 'MyOrg', )
|
||||
current_dir = settings.value(
|
||||
'current_directory', DEFAULT_DIRECTORY, type=str)
|
||||
options |= QFileDialog.DontUseNativeDialog
|
||||
|
||||
filename, filters = QFileDialog.getSaveFileName(
|
||||
self,
|
||||
filter=self._trad["file_st"] + ";; " + self._trad["file_all"],
|
||||
filter=(
|
||||
self._trad["file_st"] + ";; " +
|
||||
self._trad["file_all"]
|
||||
),
|
||||
options=options
|
||||
)
|
||||
|
||||
current_dir = os.path.split(filename)[0] or DEFAULT_DIRECTORY
|
||||
|
||||
if filename != '':
|
||||
self._table.export_reach(filename)
|
||||
self._export_to_file_st(filename)
|
||||
|
||||
def _export_to_file_st(self, filename):
|
||||
with open(filename, "w+") as f:
|
||||
f.write("* Exported from Pamhyr2\n")
|
||||
self._export_to_file_st_reach(f, self._reach)
|
||||
|
||||
def _export_to_file_st_reach(self, wfile, reach):
|
||||
pid = 0
|
||||
for profile in reach.profiles:
|
||||
self._export_to_file_st_profile(wfile, profile, pid)
|
||||
pid += 1
|
||||
|
||||
def _export_to_file_st_profile(self, wfile, profile, pid):
|
||||
num = f"{pid:>6}"
|
||||
c1 = f"{profile.code1:>6}"
|
||||
c2 = f"{profile.code2:>6}"
|
||||
t = f"{len(profile.points):>6}"
|
||||
kp = f"{profile.kp:>12f}"[0:12]
|
||||
pname = profile.name
|
||||
if profile.name == "":
|
||||
pname = f"p{profile.id:>3}".replace(" ", "0")
|
||||
name = f"{pname:<19}"
|
||||
|
||||
wfile.write(f"{num}{c1}{c2}{t} {kp} {pname}\n")
|
||||
|
||||
for point in profile.points:
|
||||
self._export_to_file_st_point(wfile, point)
|
||||
|
||||
wfile.write(f" 999.9990 999.9990 999.9990\n")
|
||||
|
||||
def _export_to_file_st_point(self, wfile, point):
|
||||
x = f"{point.x:<12.4f}"[0:12]
|
||||
y = f"{point.y:<12.4f}"[0:12]
|
||||
z = f"{point.z:<12.4f}"[0:12]
|
||||
n = f"{point.name:<3}"
|
||||
|
||||
wfile.write(f"{x} {y} {z} {n}\n")
|
||||
|
|
|
|||
Loading…
Reference in New Issue