From 564985154d34930186b48175dcb248fc0333f1b5 Mon Sep 17 00:00:00 2001 From: Paul RASCLE Date: Sat, 15 Aug 2020 00:24:34 +0200 Subject: [PATCH] dialogue change coordinates --- src/HYDROGUI/HYDROSOLVERGUI.py | 18 + src/salome_hydro/CMakeLists.txt | 2 + src/salome_hydro/changeCoords.ui | 488 +++++++++++++++++++++++++ src/salome_hydro/changeCoordsDialog.py | 179 +++++++++ 4 files changed, 687 insertions(+) create mode 100644 src/salome_hydro/changeCoords.ui create mode 100644 src/salome_hydro/changeCoordsDialog.py diff --git a/src/HYDROGUI/HYDROSOLVERGUI.py b/src/HYDROGUI/HYDROSOLVERGUI.py index 6facd59..d80a6c5 100755 --- a/src/HYDROGUI/HYDROSOLVERGUI.py +++ b/src/HYDROGUI/HYDROSOLVERGUI.py @@ -36,6 +36,7 @@ import HYDROSOLVER_ORB from salome.hydro.interpolz_gui import InterpolzDlg from salome.hydro.assignStrickler_gui import assignStricklerDlg +from salome.hydro.changeCoordsDialog import changeCoordsDialog from salome.hydro.gui_utils import HSGUIException, wait_cursor, \ get_and_check_selected_file_path import salome.hydro.study as hydro_study @@ -84,6 +85,8 @@ class GUIcontext: EDIT_PARAM_STUDY_ID = 964 GEN_PARAM_STUDY_PYTHON_ID = 965 GEN_PARAM_STUDY_YACS_ID = 966 + + CHANGECOORDS_PY_ID = 967 def __init__(self): # create top-level menu @@ -92,6 +95,15 @@ class GUIcontext: # create toolbar tid = sgPyQt.createTool("Hydro") # create actions and fill menu and toolbar with actions + act = sgPyQt.createAction(\ + GUIcontext.CHANGECOORDS_PY_ID, + "Change coordinates", + "Change coordinates", + "Change mesh coordinates", + "generate_interpolz_py.png") + sgPyQt.createMenu(act, mid) + sgPyQt.createTool(act, tid) + act = sgPyQt.createAction(\ GUIcontext.GENERATE_INTERPOLZ_PY_ID, "Generate interpolz.py", @@ -483,6 +495,11 @@ def generate_assignStrickler_py(): dlg = assignStricklerDlg(desktop) dlg.show() +def changeCoords_py(): + desktop = sgPyQt.getDesktop() + dlg = changeCoordsDialog(desktop) + dlg.show() + ### # Open dialog for boundary conditions edition ### @@ -518,6 +535,7 @@ dict_command = { GUIcontext.EDIT_TELMA_CAS_ID: edit_telma_cas, GUIcontext.GENERATE_INTERPOLZ_PY_ID: generate_interpolz_py, GUIcontext.GENERATE_ASSIGNSTRICKLER_PY_ID: generate_assignStrickler_py, + GUIcontext.CHANGECOORDS_PY_ID: changeCoords_py, GUIcontext.EDIT_LIQUID_BOUNDARY_FILE_ID: edit_liquid_boundary_file, GUIcontext.EDIT_BOUNDARY_CONDITIONS_FILE_ID: edit_boundary_conditions_file, GUIcontext.EDIT_BREACHES_FILE_ID: edit_breaches_file, diff --git a/src/salome_hydro/CMakeLists.txt b/src/salome_hydro/CMakeLists.txt index f0b8cd9..a8fdfdf 100644 --- a/src/salome_hydro/CMakeLists.txt +++ b/src/salome_hydro/CMakeLists.txt @@ -29,11 +29,13 @@ SET(PYFILES generate_interpolz.py assignStrickler_gui.py interpolz_gui.py + changeCoordsDialog.py ) SET(UIFILES assignStrickler.ui interpolz.ui + changeCoords.ui ) SET(TEMPLFILES diff --git a/src/salome_hydro/changeCoords.ui b/src/salome_hydro/changeCoords.ui new file mode 100644 index 0000000..1216cd9 --- /dev/null +++ b/src/salome_hydro/changeCoords.ui @@ -0,0 +1,488 @@ + + + Dialog + + + + 0 + 0 + 704 + 459 + + + + Change Coordinates + + + Qt::LeftToRight + + + + + + Change coordinates system + + + + + + + Input + + + + + + + + + 0 + 0 + + + + MED file + + + + + + + + + + + 0 + 0 + + + + ... + + + + + + + + + + + + 0 + 0 + + + + Offset X + + + + + + + + 0 + 0 + + + + X coordinate of origin of input mesh + + + Qt::LeftToRight + + + 0 + + + -10000000.000000000000000 + + + 10000000.000000000000000 + + + 10000.000000000000000 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 0 + 0 + + + + Offset Y + + + + + + + + 0 + 0 + + + + Y coordinate of origin of input mesh + + + 0 + + + -10000000.000000000000000 + + + 10000000.000000000000000 + + + 10000.000000000000000 + + + QAbstractSpinBox::DefaultStepType + + + 0.000000000000000 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + 0 + 0 + + + + Coord System + + + + + + + + 0 + 0 + + + + + + + + + + + + + Output + + + + + + + + + 0 + 0 + + + + MED File + + + + + + + directory to store shapefiles and output mesh file if kept + + + + + + + + 0 + 0 + + + + ... + + + + + + + + + + + + 0 + 0 + + + + Offset X + + + + + + + + 0 + 0 + + + + X coordinate of origin of input mesh + + + Qt::LeftToRight + + + 0 + + + -10000000.000000000000000 + + + 10000000.000000000000000 + + + 10000.000000000000000 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 0 + 0 + + + + Offset Y + + + + + + + + 0 + 0 + + + + Y coordinate of origin of input mesh + + + 0 + + + -10000000.000000000000000 + + + 10000000.000000000000000 + + + 10000.000000000000000 + + + QAbstractSpinBox::DefaultStepType + + + 0.000000000000000 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + 0 + 0 + + + + Coord System + + + + + + + + + + + + + + + Qt::Vertical + + + + 20 + 66 + + + + + + + + + + + 0 + 0 + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 0 + 0 + + + + Help + + + + + + + + + + + cb_changeCoordSystem + toggled(bool) + cmb_systemIn + setVisible(bool) + + + 348 + 20 + + + 348 + 181 + + + + + cb_changeCoordSystem + toggled(bool) + cmb_systemOut + setVisible(bool) + + + 348 + 20 + + + 348 + 355 + + + + + diff --git a/src/salome_hydro/changeCoordsDialog.py b/src/salome_hydro/changeCoordsDialog.py new file mode 100644 index 0000000..177a1c7 --- /dev/null +++ b/src/salome_hydro/changeCoordsDialog.py @@ -0,0 +1,179 @@ +# Copyright (C) 2012-2013 EDF +# +# This file is part of SALOME HYDRO module. +# +# SALOME HYDRO module is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# SALOME HYDRO module is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with SALOME HYDRO module. If not, see . + +import os +import sys + +from PyQt5.QtCore import * +from PyQt5.QtGui import * +from PyQt5.QtWidgets import * +from PyQt5 import uic + +import pyproj +from pyproj import CRS + +from salome.hydrotools.changeCoords import changeCoords + +import sysconfig +pythonVersion = 'python' + sysconfig.get_python_version() +hydro_solver_root = os.path.join(os.environ['HYDROSOLVER_ROOT_DIR'], 'lib', pythonVersion, 'site-packages', 'salome', 'salome', 'hydro') + +class changeCoordsDialog(QDialog): + """ + """ + + def __init__(self, parent = None, modal = 0): + QDialog.__init__(self, parent) + uic.loadUi(os.path.join(hydro_solver_root, 'changeCoords.ui'), self ) + + # Connections + self.pb_medFileIn.clicked.connect(self.on_med_file_in_browse) + self.pb_medFileOut.clicked.connect(self.on_med_file_out_browse) + self.pb_help.clicked.connect(self.on_help) + self.pb_ok.accepted.connect(self.on_accept) + self.pb_ok.rejected.connect(self.on_reject) + self.medFileIn = None + self.medFileOut = None + EPSG_list = (2154, 27561, 27562, 27563, 27564, 27571, 27572, 27573, 27574 ) + for epsg in EPSG_list: + crs_code = CRS.from_epsg(epsg) + codeName = str(epsg) + ' ' + crs_code.name + self.cmb_systemIn.addItem(codeName) + self.cmb_systemOut.addItem(codeName) + self.cb_changeCoordSystem.setChecked(True) + self.cb_changeCoordSystem.setChecked(False) + + def on_med_file_in_browse(self): + """ + Select input MED file + """ + print("on_med_file_in_browse") + self.medFileIn, filt = QFileDialog.getOpenFileName(self, self.tr("Input MED file"), "", self.tr("MED files (*.med)")) + print(self.medFileIn) + if not self.medFileIn: + return + self.le_medFileIn.setText(self.medFileIn) + a = os.path.splitext(self.medFileIn) + self.medFileOut = a[0] + '_coo' + a[1] + self.le_medFileOut.setText(self.medFileOut) + + def on_med_file_out_browse(self): + """ + Select output MED file + """ + print("on_med_file_out_browse") + self.medFileOut, filt = QFileDialog.getSaveFileName(self, self.tr("Output MED file"), "", self.tr("MED files (*.med)")) + print(self.medFileOut) + if not self.medFileOut: + return + self.le_medFileOut.setText(self.medFileOut) + + def on_help(self): + """ + display a help message + """ + msg = """ +

Change mesh coordinates dialog

+ + This dialog is used to change the nodes coordinates in a mesh. It is used either for a simple translation, a change of coordinates system + (for instance from Lambert II to Lambert-93), or a combination. +

+ The modified mesh is saved in a new file. +
+ If there is a change of coordinates system, the input mesh is first translated, when it uses a local origin. + After the change of coordinates system, the output mesh can be translated (new local origin). +
+ When there is only a simple translation, the operation is: Xout = Xin + offsetXin -offsetXout, Yout = Yin + offsetYin -offsetYout. +

+ Below is the description of the dialog controls. + +

Change coordinates system

+ If this checkbox is checked, the output mesh will be removed after calculation of the shapes. + +

Input MED file

+ This field allows the selection of a med file (via the standard file open dialog). + The filling of this field is mandatory. + +

Input offsetX, offsetY

+ These fields are used to set the Origin of the local coordinates system of the input mesh, if any. + +

Input Coord System

+ This combo box is use to select the coordinate system of the input mesh. + +

Output MED file

+ This field allows the definition of a med file (via the standard file save dialog). + The filling of this field is mandatory. + +

Output offsetX, offsetY

+ These fields are used to set the Origin of the local coordinates system of the output mesh, if any. + +

Output Coord System

+ This combo box is use to select the coordinate system of the output mesh. + """ + QMessageBox.about(self, self.tr("About mesh edges to shapes dialog"), msg); + + + def on_accept(self): + print("accept") + #TODO check medfile in and out not empty + #TODO preset for medFileOut + medFileIn = self.le_medFileIn.text() + medFileOut = self.le_medFileOut.text() + offsetXin = self.dsb_offsetXin.value() + offsetYin = self.dsb_offsetYin.value() + offsetXout = self.dsb_offsetXout.value() + offsetYout = self.dsb_offsetYout.value() + isChangeCoordSystem = self.cb_changeCoordSystem.isChecked() + epsgIn = 2154 + epsgOut = 2154 + if isChangeCoordSystem: + epsgIn = int(self.cmb_systemIn.currentText().split()[0]) + epsgOut = int(self.cmb_systemOut.currentText().split()[0]) + print(medFileIn) + print(medFileOut) + print(isChangeCoordSystem) + print(offsetXin, offsetYin) + print(offsetXout, offsetYout) + print(epsgIn, epsgOut) + if not os.path.isfile(medFileIn): + msgBox = QMessageBox() + msgBox.setText( "Input MED file does not exist" ) + msgBox.exec_() + return + dir = os.path.dirname(medFileOut) + base = os.path.basename(medFileOut) + ext = os.path.splitext(medFileOut)[1] + if not os.path.isdir(dir) or (base == "") or (ext.lower() != ".med"): + msgBox = QMessageBox() + msgBox.setText( "Output MED file is not a valid path" ) + msgBox.exec_() + return + self.accept() + changeCoords(medFileIn, medFileOut, epsgIn, epsgOut, offsetXin, offsetYin, offsetXout, offsetYout) + + def on_reject(self): + print("reject") + self.reject() + + +def execDialog(context): + print("execDialog") + # get context study, salomeGui + study = context.study + sg = context.sg + dlg = changeCoordsDialog() + dlg.exec_() -- 2.30.2