Salome HOME
trying to fix selection mecanism in OCC Viewer: Selection is OK, but broken after...
[modules/hydro.git] / src / HYDROTools / plugins / fitShapePointsToMeshEdgesDialog.py
1 #  Copyright (C) 2012-2013 EDF
2 #
3 #  This file is part of SALOME HYDRO module.
4 #
5 #  SALOME HYDRO module is free software: you can redistribute it and/or modify
6 #  it under the terms of the GNU General Public License as published by
7 #  the Free Software Foundation, either version 3 of the License, or
8 #  (at your option) any later version.
9 #
10 #  SALOME HYDRO module is distributed in the hope that it will be useful,
11 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
12 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 #  GNU General Public License for more details.
14 #
15 #  You should have received a copy of the GNU General Public License
16 #  along with SALOME HYDRO module.  If not, see <http://www.gnu.org/licenses/>.
17
18 import os
19 import sys
20
21 from PyQt5.QtCore import *
22 from PyQt5.QtGui import *
23 from PyQt5.QtWidgets import *
24 from PyQt5 import uic
25
26 from salome.hydrotools.shapesGroups import fitShapePointsToMesh
27
28 #import sysconfig
29 #pythonVersion = 'python' + sysconfig.get_python_version()
30 hydro_root = os.path.join(os.environ['HYDRO_ROOT_DIR'], 'share', 'salome', 'plugins', 'hydro', 'plugins')
31
32 class fitShapePointsToMeshEdgesDialog(QDialog):
33     """
34     """
35
36     def __init__(self, parent = None, modal = 0):
37         QDialog.__init__(self, parent)
38         uic.loadUi(os.path.join(hydro_root, 'fitShapePointsToMeshEdges.ui'), self )
39
40         # Connections
41         self.pb_meshEdges.clicked.connect(self.on_meshEdges_browse)
42         self.pb_shapeToAdjust.clicked.connect(self.on_shapeToAdjust_browse)
43         self.pb_help.clicked.connect(self.on_help)
44         self.pb_ok.accepted.connect(self.on_accept)
45         self.pb_ok.rejected.connect(self.on_reject)
46         self.meshEdges = None
47         self.shapeToAdjust = None
48         
49     def on_meshEdges_browse(self):
50         """
51         Select Shapefile of mesh edges
52         """
53         print("on_meshEdges_browse")
54         self.meshEdges, filt = QFileDialog.getOpenFileName(self, self.tr("shapefile of mesh border edges"), "", self.tr("shapefiles (*.shp)"))
55         print(self.meshEdges)
56         if not self.meshEdges:
57             return
58         self.le_meshEdges.setText(self.meshEdges)
59         
60     def on_shapeToAdjust_browse(self):
61         """
62         Select shapefile to adjust
63         """
64         print("on_shapeToAdjust_browse")
65         self.shapeToAdjust, filt = QFileDialog.getOpenFileName(self, self.tr("shapefile to adjust"), "", self.tr("shapefiles (*.shp)"))
66         print(self.shapeToAdjust)
67         if not self.shapeToAdjust:
68             return
69         self.le_shapeToAdjust.setText(self.shapeToAdjust)
70         
71     def on_help(self):
72         """
73         display a help message
74         """
75         msg = """
76         <h2>Fit shape points to mesh edges dialog</h2>
77
78         This dialog is used to adjust a shapefile crossing another shapefile corresponding to edges of a mesh, for instance the free borders.
79         the shapeFile to adjust must be a closed line or polygon crossing the free border shapefile in 2 points.
80         <br><br>
81         The algorithm find in the shapefile to adjust and in the free border shapefile the two closest pairs of corresponding points 
82         and move the points in the shapefile to adjust to correspond to the points found in the free border shapefile.
83         <br>
84         If requested, it splits the free border shapefile and/or the shapefile adjusted in two parts, at their intersection.
85         <br>
86         The shapefile adusted is written in the directory of the shapefile to adjust, with a suffix '_adj'.
87         <br>
88         The split free border shapefile is written in the directory of the free border shapefile, with a suffix '_split'.
89         <br><br>         
90         Below is the description of the dialog controls.
91
92         <h3>Mesh edges shapefile</h3>
93         This field allows selection of a shapefile (via the standard file open dialog).
94         <h3>Shapefile to adjust</h3>
95         This field allows selection of a shapefile (via the standard file open dialog).
96         <h3>Split mesh edges shapefile</h3>
97         If this checkbox is checked, the mesh edges shapefile is split at the intersection with the other shapefile.
98          <h3>Split shapefile to adjust</h3>
99         If this checkbox is checked, the shapefile to adjust is split at the intersection with the other shapefile.
100         """
101         QMessageBox.about(self, self.tr("About fit shape points to mesh edges dialog"), msg);
102        
103    
104     def on_accept(self):
105         print("accept")
106         meshEdges = self.le_meshEdges.text()
107         shapeToAdjust = self.le_shapeToAdjust.text()
108         isMeshEdgesSplit = self.cb_splitMeshEdges.isChecked()
109         isShapeToAdjustSplit = self.cb_splitShapeToAdjust.isChecked()
110         self.accept()
111         print(meshEdges)
112         print(shapeToAdjust)
113         print(isMeshEdgesSplit)
114         print(isShapeToAdjustSplit)
115         fitShapePointsToMesh(meshEdges, shapeToAdjust, "", isMeshEdgesSplit, isShapeToAdjustSplit)
116
117     def on_reject(self):
118         print("reject")
119         self.reject()
120         
121
122 def execDialog(context):
123     print("execDialog")
124   # get context study, salomeGui
125     study = context.study
126     sg = context.sg
127     dlg = fitShapePointsToMeshEdgesDialog()
128     dlg.exec_()