salome_pluginsmanager.logger.info('ERROR: meshEdgesToShapes plug-in is unavailable: {}'.format(e))
pass
+try:
+ from plugins import fitShapePointsToMeshEdgesDialog
+ salome_pluginsmanager.AddFunction('Adjust shapefile',
+ 'Adjust shapefile points to mesh edges',
+ fitShapePointsToMeshEdgesDialog.execDialog)
+except Exception as e:
+ salome_pluginsmanager.logger.info('ERROR: fitShapePointsToMeshEdges plug-in is unavailable: {}'.format(e))
+ pass
+
try:
from testPlugin import testDialog
salome_pluginsmanager.AddFunction('test Dialog',
SET(PLUGIN_SCRIPTS
__init__.py
meshEdgesToShapesDialog.py
+ fitShapePointsToMeshEdgesDialog.py
)
SET(UIFILES
meshEdgesToShapes.ui
+ fitShapePointsToMeshEdges.ui
)
# --- rules ---
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>Dialog</class>
+ <widget class="QDialog" name="Dialog">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>817</width>
+ <height>265</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>Mesh Edges to Shapes</string>
+ </property>
+ <property name="layoutDirection">
+ <enum>Qt::LeftToRight</enum>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout_2">
+ <item>
+ <widget class="QGroupBox" name="groupBox">
+ <property name="title">
+ <string>Input</string>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout">
+ <item>
+ <layout class="QGridLayout" name="gridLayout">
+ <item row="0" column="0">
+ <widget class="QLabel" name="lb_meshEdges">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Maximum" vsizetype="Preferred">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="text">
+ <string>Mesh edges shapefile</string>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="1">
+ <widget class="QLineEdit" name="le_meshEdges"/>
+ </item>
+ <item row="0" column="2">
+ <widget class="QToolButton" name="pb_meshEdges">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="text">
+ <string>...</string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="0">
+ <widget class="QLabel" name="lb_shapeToAdjust">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Maximum" vsizetype="Preferred">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="text">
+ <string>Shapefile to adjust</string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="1">
+ <widget class="QLineEdit" name="le_shapeToAdjust"/>
+ </item>
+ <item row="1" column="2">
+ <widget class="QToolButton" name="pb_shapeToAdjust">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="text">
+ <string>...</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <layout class="QGridLayout" name="gridLayout_2">
+ <item row="0" column="0">
+ <widget class="QCheckBox" name="cb_splitMeshEdges">
+ <property name="text">
+ <string>Split mesh edges shapefile</string>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="1">
+ <spacer name="horizontalSpacer_2">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>40</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item row="1" column="0">
+ <widget class="QCheckBox" name="cb_splitShapeToAdjust">
+ <property name="text">
+ <string>Split shapefile to adjust</string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="1">
+ <spacer name="horizontalSpacer_3">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>40</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </widget>
+ </item>
+ <item>
+ <spacer name="verticalSpacer">
+ <property name="orientation">
+ <enum>Qt::Vertical</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>20</width>
+ <height>66</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item>
+ <layout class="QHBoxLayout" name="horizontalLayout">
+ <item>
+ <widget class="QDialogButtonBox" name="pb_ok">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Maximum" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="standardButtons">
+ <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <spacer name="horizontalSpacer">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>40</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item>
+ <widget class="QPushButton" name="pb_help">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="text">
+ <string>Help</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </widget>
+ <resources/>
+ <connections>
+ <connection>
+ <sender>pb_ok</sender>
+ <signal>rejected()</signal>
+ <receiver>Dialog</receiver>
+ <slot>reject()</slot>
+ <hints>
+ <hint type="sourcelabel">
+ <x>316</x>
+ <y>260</y>
+ </hint>
+ <hint type="destinationlabel">
+ <x>286</x>
+ <y>274</y>
+ </hint>
+ </hints>
+ </connection>
+ <connection>
+ <sender>pb_ok</sender>
+ <signal>accepted()</signal>
+ <receiver>Dialog</receiver>
+ <slot>accept()</slot>
+ <hints>
+ <hint type="sourcelabel">
+ <x>248</x>
+ <y>254</y>
+ </hint>
+ <hint type="destinationlabel">
+ <x>157</x>
+ <y>274</y>
+ </hint>
+ </hints>
+ </connection>
+ </connections>
+</ui>
--- /dev/null
+# 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 <http://www.gnu.org/licenses/>.
+
+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 fitShapePointsToMesh
+
+#import sysconfig
+#pythonVersion = 'python' + sysconfig.get_python_version()
+hydro_root = os.path.join(os.environ['HYDRO_ROOT_DIR'], 'share', 'salome', 'plugins', 'hydro', 'plugins')
+
+class fitShapePointsToMeshEdgesDialog(QDialog):
+ """
+ """
+
+ def __init__(self, parent = None, modal = 0):
+ QDialog.__init__(self, parent)
+ uic.loadUi(os.path.join(hydro_root, 'fitShapePointsToMeshEdges.ui'), self )
+
+ # Connections
+ self.pb_meshEdges.clicked.connect(self.on_meshEdges_browse)
+ self.pb_shapeToAdjust.clicked.connect(self.on_shapeToAdjust_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.meshEdges = None
+ self.shapeToAdjust = None
+
+ def on_meshEdges_browse(self):
+ """
+ Select Shapefile of mesh edges
+ """
+ print("on_meshEdges_browse")
+ self.meshEdges, filt = QFileDialog.getOpenFileName(self, self.tr("shapefile of mesh border edges"), "", self.tr("shapefiles (*.shp)"))
+ print(self.meshEdges)
+ if not self.meshEdges:
+ return
+ self.le_meshEdges.setText(self.meshEdges)
+
+ def on_shapeToAdjust_browse(self):
+ """
+ Select shapefile to adjust
+ """
+ print("on_shapeToAdjust_browse")
+ self.shapeToAdjust, filt = QFileDialog.getOpenFileName(self, self.tr("shapefile to adjust"), "", self.tr("shapefiles (*.shp)"))
+ print(self.shapeToAdjust)
+ if not self.shapeToAdjust:
+ return
+ self.le_shapeToAdjust.setText(self.shapeToAdjust)
+
+ def on_help(self):
+ """
+ display a help message
+ """
+ msg = """
+ <h2>Fit shape points to mesh edges dialog</h2>
+
+ This dialog is used to adjust a shapefile crossing another shapefile corresponding to edges of a mesh, for instance the free borders.
+ the shapeFile to adjust must be a closed line or polygon crossing the free border shapefile in 2 points.
+ <br><br>
+ The algorithm find in the shapefile to adjust and in the free border shapefile the two closest pairs of corresponding points
+ and move the points in the shapefile to adjust to correspond to the points found in the free border shapefile.
+ <br>
+ If requested, it splits the free border shapefile and/or the shapefile adjusted in two parts, at their intersection.
+ <br>
+ The shapefile adusted is written in the directory of the shapefile to adjust, with a suffix '_adj'.
+ <br>
+ The split free border shapefile is written in the directory of the free border shapefile, with a suffix '_split'.
+ <br><br>
+ Below is the description of the dialog controls.
+
+ <h3>Mesh edges shapefile</h3>
+ This field allows selection of a shapefile (via the standard file open dialog).
+ <h3>Shapefile to adjust</h3>
+ This field allows selection of a shapefile (via the standard file open dialog).
+ <h3>Split mesh edges shapefile</h3>
+ If this checkbox is checked, the mesh edges shapefile is split at the intersection with the other shapefile.
+ <h3>Split shapefile to adjust</h3>
+ If this checkbox is checked, the shapefile to adjust is split at the intersection with the other shapefile.
+ """
+ QMessageBox.about(self, self.tr("About fit shape points to mesh edges dialog"), msg);
+
+
+ def on_accept(self):
+ print("accept")
+ meshEdges = self.le_meshEdges.text()
+ shapeToAdjust = self.le_shapeToAdjust.text()
+ isMeshEdgesSplit = self.cb_splitMeshEdges.isChecked()
+ isShapeToAdjustSplit = self.cb_splitShapeToAdjust.isChecked()
+ self.accept()
+ print(meshEdges)
+ print(shapeToAdjust)
+ print(isMeshEdgesSplit)
+ print(isShapeToAdjustSplit)
+ fitShapePointsToMesh(meshEdges, shapeToAdjust, isMeshEdgesSplit, isShapeToAdjustSplit)
+
+ def on_reject(self):
+ print("reject")
+ self.reject()
+
+
+def execDialog(context):
+ print("execDialog")
+ # get context study, salomeGui
+ study = context.study
+ sg = context.sg
+ dlg = fitShapePointsToMeshEdgesDialog()
+ dlg.exec_()