From: Paul RASCLE Date: Thu, 13 Aug 2020 11:05:39 +0000 (+0200) Subject: dialog mesh edges to shapes X-Git-Tag: SH_V2_2_0~83 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=0d12bf2b09fadfcaa27b568d4e33fd987f413fb6;p=modules%2Fhydro.git dialog mesh edges to shapes --- diff --git a/CMakeLists.txt b/CMakeLists.txt index a51eeff2..9c8dbcd8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -188,10 +188,14 @@ SET(SALOME_HYDRO_INSTALL_RES_SCRIPTS "${SALOME_INSTALL_RES}/hydro" CACHE PATH "Install path: SALOME HYDRO scripts") SET(SALOME_HYDRO_INSTALL_SAMPLES share/salome/hydrosamples CACHE PATH "Install path: SALOME HYDRO samples") +SET(SALOME_HYDRO_INSTALL_PLUGINS share/salome/plugins/hydro CACHE PATH + "Install path: SALOME HYDRO plugins") + MARK_AS_ADVANCED( SALOME_HYDRO_INSTALL_RES_DATA SALOME_HYDRO_INSTALL_RES_SCRIPTS SALOME_HYDRO_INSTALL_SAMPLES + SALOME_HYDRO_INSTALL_PLUGINS ) # Sources diff --git a/src/HYDROGUI/HYDROGUI_Module.cxx b/src/HYDROGUI/HYDROGUI_Module.cxx index f52320a7..96823ea6 100755 --- a/src/HYDROGUI/HYDROGUI_Module.cxx +++ b/src/HYDROGUI/HYDROGUI_Module.cxx @@ -16,6 +16,8 @@ // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // +#include + #include "HYDROGUI_Module.h" #include "HYDROGUI.h" @@ -181,6 +183,24 @@ bool HYDROGUI_Module::activateModule( SUIT_Study* theStudy ) setMenuShown( true ); setToolShown( true ); + // import Python module that manages HYDRO plugins (need to be here because SalomePyQt API uses active module) + PyGILState_STATE gstate = PyGILState_Ensure(); + PyObject* pluginsmanager = PyImport_ImportModuleNoBlock((char*)"salome_pluginsmanager"); + if ( !pluginsmanager ) { + PyErr_Print(); + } + else { + PyObject* result = + PyObject_CallMethod(pluginsmanager, (char*)"initialize", (char*)"isss", 1, "hydro", + tr("MEN_DESK_HYDRO").toUtf8().data(), + tr("Python plugins").toUtf8().data()); + if ( !result ) + PyErr_Print(); + Py_XDECREF(result); + } + PyGILState_Release(gstate); + // end of GEOM plugins loading + #ifndef DISABLE_PYCONSOLE aDesktop->tabifyDockWidget( HYDROGUI_Tool::WindowDock( anApp->getWindow( LightApp_Application::WT_PyConsole ) ), HYDROGUI_Tool::WindowDock( anApp->getWindow( LightApp_Application::WT_LogWindow ) ) ); diff --git a/src/HYDROGUI/resources/HYDROGUI_msg_en.ts b/src/HYDROGUI/resources/HYDROGUI_msg_en.ts index dc4465a1..7b5e6aad 100755 --- a/src/HYDROGUI/resources/HYDROGUI_msg_en.ts +++ b/src/HYDROGUI/resources/HYDROGUI_msg_en.ts @@ -1,6 +1,6 @@ - + - + @default @@ -337,11 +337,11 @@ All supported formats (*.brep *.iges *.igs *.step *.stp) INCLUDED_OBJECTS Included objects - + ALREADY_INCLUDED_OBJECTS Already included objects (can't be excluded) - + AVAILABLE_GROUPS Available groups @@ -608,7 +608,7 @@ Do you want to continue? Export image to file - + HYDROGUI_InputPanel @@ -632,7 +632,7 @@ Do you want to continue? Help - + HYDROGUI_Wizard @@ -648,7 +648,7 @@ Do you want to continue? Finish - + HYDROGUI_ImportBathymetryDlg @@ -672,7 +672,7 @@ Do you want to continue? Invert altitude values - + HYDROGUI_ImportBathymetryOp @@ -693,9 +693,9 @@ file cannot be correctly imported for a Bathymetry definition. '%1' All files cannot be correctly imported for a Bathymetry definition. - + - + HYDROGUI_ImportImageDlg @@ -779,7 +779,7 @@ All files cannot be correctly imported for a Bathymetry definition.Image georeferencement files (*.grf);;All files (*.* *) - + HYDROGUI_ImportImageOp @@ -848,7 +848,7 @@ Would you like to remove all references from the image? The image file is not chosen - + HYDROGUI_Module @@ -881,7 +881,7 @@ Would you like to remove all references from the image? DSK_EDIT_IMMERSIBLE_ZONE - Edit immersible zone + Edit immersible zone DSK_CREATE_STREAM @@ -2050,7 +2050,7 @@ Would you like to remove all references from the image? Polyline arrow size - + HYDROGUI_PolylineOp @@ -2153,7 +2153,7 @@ Would you like to remove all references from the image? Hide all - + HYDROGUI_ObserveImageOp @@ -2161,7 +2161,7 @@ Would you like to remove all references from the image? Observe image - + HYDROGUI_PolylineDlg @@ -2177,7 +2177,7 @@ Would you like to remove all references from the image? Name - + HYDROGUI_Poly3DDlg @@ -2213,7 +2213,7 @@ Would you like to remove all references from the image? U: %1, Z: %2 - + HYDROGUI_ProfileDlg @@ -2306,7 +2306,7 @@ Would you like to remove all references from the image? Transparent - + HYDROGUI_TwoImagesOp @@ -2499,7 +2499,7 @@ file cannot be correctly imported for an Obstacle definition. HYDRO_ - + HYDROGUI_GeomObjectDlg @@ -2709,7 +2709,7 @@ file cannot be correctly imported for an Obstacle definition. ATTRS_ISNT_SELECTED Attribute isn't selected - + DBF_LOAD_ERR_MESS Cannot open DBF file or it's corrupted @@ -2788,7 +2788,7 @@ file cannot be correctly imported for an Obstacle definition. - + HYDROGUI_ImportSinusXOp @@ -2857,7 +2857,7 @@ file cannot be correctly imported for an Obstacle definition. Cannot export polylines of different kind - + HYDROGUI_GeoreferencementDlg @@ -2897,7 +2897,7 @@ file cannot be correctly imported for an Obstacle definition. Y2 - + HYDROGUI_GeoreferencementOp @@ -2917,7 +2917,7 @@ file cannot be correctly imported for an Obstacle definition. Do you want to store table data in the data model? - + HYDROGUI_SetColorOp @@ -3063,17 +3063,17 @@ file cannot be correctly imported for an Obstacle definition. INVALID_PROFILES - Invalid profiles: + Invalid profiles: %1 EXISTING_PROFILES - Existing profiles: + Existing profiles: %1 NOT_INTERSECTED_PROFILES - Not intersected with the hydraulic axis: + Not intersected with the hydraulic axis: %1 @@ -3323,9 +3323,9 @@ Polyline should consist from one not closed curve. LAND_COVER_MAP_SELECTED_FACES - + This operation is performed on a set of land covers selected in the 3D Viewer. - + Number of selected land covers: @@ -3429,7 +3429,7 @@ Polyline should consist from one not closed curve. Translation of an obstacle - + HYDROGUI_RunBrowser @@ -3514,7 +3514,7 @@ Polyline should consist from one not closed curve. Incorrect input - + HYDROGUI_PriorityTableModel @@ -3622,7 +3622,7 @@ Polyline should consist from one not closed curve. Can't obtain stream oject \"%1\" - + HYDROGUI_RecognizeContoursDlg @@ -3860,14 +3860,6 @@ Polyline should consist from one not closed curve. TYPE Type - - - AS_BATHY - As bathymetry - - - AS_BATHY - As bathymetry AS_POLYXY @@ -3902,7 +3894,7 @@ Polyline should consist from one not closed curve. Ok - + HYDROGUI_SIProgressIndicator @@ -3948,7 +3940,7 @@ Polyline should consist from one not closed curve. COMPLETED Completed - + CANCELLING Cancelling... @@ -3960,10 +3952,10 @@ Polyline should consist from one not closed curve. HYDROGUI_ImportPolylineDlg POLYLINES_3D_IN_FILES - The shp file contains polyline3D objects (ARCZ). -They have been imported as polylineXY only, -but can be imported with Z part (additional profile and bathymetry). -If checkbox of corresponding polyline in the table below is checked + The shp file contains polyline3D objects (ARCZ). +They have been imported as polylineXY only, +but can be imported with Z part (additional profile and bathymetry). +If checkbox of corresponding polyline in the table below is checked then it will be imported with Z part, otherwise as PolylineXY only diff --git a/src/HYDROTools/CMakeLists.txt b/src/HYDROTools/CMakeLists.txt index b3b04c9e..013d25b6 100644 --- a/src/HYDROTools/CMakeLists.txt +++ b/src/HYDROTools/CMakeLists.txt @@ -29,6 +29,19 @@ SET(PYFILES changeCoords.py ) +# --- plugins dialogs + +ADD_SUBDIRECTORY(plugins) +ADD_SUBDIRECTORY(testPlugin) + +# --- plugin scripts / static + +SET(plugin_SCRIPTS + hydro_plugins.py +) + # --- rules --- SALOME_INSTALL_SCRIPTS("${PYFILES}" ${SALOME_INSTALL_PYTHON}/salome/hydrotools) + +SALOME_INSTALL_SCRIPTS("${plugin_SCRIPTS}" ${SALOME_HYDRO_INSTALL_PLUGINS}) diff --git a/src/HYDROTools/hydro_plugins.py b/src/HYDROTools/hydro_plugins.py new file mode 100644 index 00000000..11eb9f49 --- /dev/null +++ b/src/HYDROTools/hydro_plugins.py @@ -0,0 +1,43 @@ +# -*- coding: utf-8 -*- +# Copyright (C) 2011-2019 EDF R&D +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library 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 +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# +# Author : Guillaume Boulant (EDF) +# +import salome_pluginsmanager +import os +from qtsalome import QIcon + +try: + from plugins import meshEdgesToShapesDialog + salome_pluginsmanager.AddFunction('Mesh edges to shapes', + 'Create shapefiles from mesh edges groups and borders', + meshEdgesToShapesDialog.execDialog) +except Exception as e: + salome_pluginsmanager.logger.info('ERROR: meshEdgesToShapes plug-in is unavailable: {}'.format(e)) + pass + +try: + from testPlugin import testDialog + salome_pluginsmanager.AddFunction('test Dialog', + 'test Dialog not implemented', + testDialog.execDialog) +except Exception as e: + salome_pluginsmanager.logger.info('ERROR: test plug-in is unavailable: {}'.format(e)) + pass + diff --git a/src/HYDROTools/plugins/CMakeLists.txt b/src/HYDROTools/plugins/CMakeLists.txt new file mode 100644 index 00000000..2509e46b --- /dev/null +++ b/src/HYDROTools/plugins/CMakeLists.txt @@ -0,0 +1,32 @@ +# 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 . + +# --- Python files --- + +SET(PLUGIN_SCRIPTS + __init__.py + meshEdgesToShapesDialog.py +) + +SET(UIFILES + meshEdgesToShapes.ui +) + +# --- rules --- + +SALOME_INSTALL_SCRIPTS("${PLUGIN_SCRIPTS}" ${SALOME_HYDRO_INSTALL_PLUGINS}/plugins) +INSTALL( FILES ${UIFILES} DESTINATION ${SALOME_HYDRO_INSTALL_PLUGINS}/plugins) diff --git a/src/HYDROTools/plugins/__init__.py b/src/HYDROTools/plugins/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/src/HYDROTools/plugins/meshEdgesToShapes.ui b/src/HYDROTools/plugins/meshEdgesToShapes.ui new file mode 100644 index 00000000..20bef9ce --- /dev/null +++ b/src/HYDROTools/plugins/meshEdgesToShapes.ui @@ -0,0 +1,326 @@ + + + Dialog + + + + 0 + 0 + 814 + 369 + + + + Mesh Edges to Shapes + + + Qt::LeftToRight + + + + + + 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 + + + + + + + + + + + + + Output + + + + + + + + + 0 + 0 + + + + Output dir: + + + + + + + directory to store shapefiles and output mesh file if kept + + + + + + + + 0 + 0 + + + + ... + + + + + + + + + Keep Output MED File + + + + + + + + + + Qt::Vertical + + + + 20 + 66 + + + + + + + + + + + 0 + 0 + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 0 + 0 + + + + Help + + + + + + + + + + + pb_ok + rejected() + Dialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + pb_ok + accepted() + Dialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + diff --git a/src/HYDROTools/plugins/meshEdgesToShapesDialog.py b/src/HYDROTools/plugins/meshEdgesToShapesDialog.py new file mode 100644 index 00000000..e17579ca --- /dev/null +++ b/src/HYDROTools/plugins/meshEdgesToShapesDialog.py @@ -0,0 +1,142 @@ +# 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 + +from salome.hydrotools.shapesGroups import freeBordersGroup, exploreEdgeGroups + +#import sysconfig +#pythonVersion = 'python' + sysconfig.get_python_version() +hydro_root = os.path.join(os.environ['HYDRO_ROOT_DIR'], 'share', 'salome', 'plugins', 'hydro', 'plugins') + +class meshEdgesToShapesDialog(QDialog): + """ + """ + + def __init__(self, parent = None, modal = 0): + QDialog.__init__(self, parent) + uic.loadUi(os.path.join(hydro_root, 'meshEdgesToShapes.ui'), self ) + + # Connections + self.pb_medFile.clicked.connect(self.on_med_file_browse) + self.pb_outDir.clicked.connect(self.on_outputDir_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.cb_keepOutMed.setChecked(True) + self.medFile = None + self.outDir = None + + def on_med_file_browse(self): + """ + Select MED file + """ + print("on_med_file_browse") + self.medFile, filt = QFileDialog.getOpenFileName(self, self.tr("Input MED file"), "", self.tr("MED files (*.med)")) + print(self.medFile) + if not self.medFile: + return + self.le_medFile.setText(self.medFile) + + def on_outputDir_browse(self): + """ + Select OutputDirectory + """ + print("on_ouptutDir_browse") + self.outDir = QFileDialog.getExistingDirectory(self, self.tr("Output Directory"), "") + print(self.outDir) + if not self.outDir: + return + self.le_outDir.setText(self.outDir) + + def on_help(self): + """ + display a help message + """ + msg = """ +

Mesh Edges to Shapes Dialog

+ + This dialog is used to extract all groups of edges from a mesh, plus all the border (free) edges, + and write the groups as shapefiles. +

+ The free edges regroup the external border of the mesh, and all the internal borders (isles). + A group containing the free edges is added to the mesh. +
+ The mesh is saved in a new file, in an ouput directory used also to store the shapefiles. +
+ A shapefile of edges and a shapefile of points are generated for each group of edges. + The shapefiles are intended to be loaded in a SIG tool (Qgis) and should preferaby be set in a correct coordinates system. +
+ If the mesh uses a local coordinate system with an origin offset, the coordinates of this origin should be set in the dialog. +

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

MED file

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

offsetX, offsetY

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

Output directory

+ This field allows selection of a directory to store the shapes and the outputMesh. + +

Keep output MED file

+ If this checkbox is unchecked, the output mesh will be removed after calculation of the shapes. + """ + QMessageBox.about(self, self.tr("About mesh edges to shapes dialog"), msg); + + + def on_accept(self): + print("accept") + medFile = self.le_medFile.text() + outDir = self.le_outDir.text() + offsetX = self.dsb_offsetX.value() + offsetY = self.dsb_offsetY.value() + isOutMedKept = self.cb_keepOutMed.isChecked() + self.accept() + print(medFile) + print(outDir) + print(isOutMedKept) + print(offsetX, offsetY) + a = os.path.splitext(medFile) + medFileOut = os.path.join(outDir, os.path.basename(a[0]) + '_brd' + a[1]) + print(medFileOut) + medFileOut = freeBordersGroup(medFile, medFileOut) + exploreEdgeGroups(medFileOut, outDir, offsetX, offsetY) + if not isOutMedKept: + print("remove", medFileOut) + os.remove(medFileOut) + + def on_reject(self): + print("reject") + self.reject() + + +def execDialog(context): + print("execDialog") + # get context study, salomeGui + study = context.study + sg = context.sg + dlg = meshEdgesToShapesDialog() + dlg.exec_() diff --git a/src/HYDROTools/testPlugin/CMakeLists.txt b/src/HYDROTools/testPlugin/CMakeLists.txt new file mode 100644 index 00000000..229a7fd2 --- /dev/null +++ b/src/HYDROTools/testPlugin/CMakeLists.txt @@ -0,0 +1,28 @@ +# Copyright (C) 2012-2019 EDF R&D +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library 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 +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# +# --- scripts --- + +# scripts / static +SET(plugin_SCRIPTS + testDialog.py + ) + +# --- rules --- + +SALOME_INSTALL_SCRIPTS("${plugin_SCRIPTS}" ${SALOME_HYDRO_INSTALL_PLUGINS}/testPlugin) diff --git a/src/HYDROTools/testPlugin/testDialog.py b/src/HYDROTools/testPlugin/testDialog.py new file mode 100644 index 00000000..7c05c0fd --- /dev/null +++ b/src/HYDROTools/testPlugin/testDialog.py @@ -0,0 +1,35 @@ +# -*- coding: utf-8 -*- + +import sys, os +import string + +#import sysconfig +#pythonVersion = 'python' + sysconfig.get_python_version() +#hydro_solver_root = os.path.join(os.environ['HYDROSOLVER_ROOT_DIR'], 'lib', pythonVersion, 'site-packages', 'salome') + +#import salome +#salome.salome_init() + +#import HYDROPy + +from PyQt5.QtWidgets import QDialog, QFileDialog, QTableWidgetItem, QComboBox, QMessageBox +from PyQt5 import uic + +#import SalomePyQt +#import libSALOME_Swig +#salome_gui = libSALOME_Swig.SALOMEGUI_Swig() + +class testDialog(): + + def __init__(self, parent = None): + pass + + def exec_(self): + msgBox = QMessageBox() + msgBox.setText( "The test dialog is not yet implemented!" ) + msgBox.exec_() + +def execDialog(parent): + print("execDialog") + dlg = testDialog(parent) + dlg.exec_() \ No newline at end of file