]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
automatic load of shapes from dialog 'adjust shapefile to mesh'
authorPaul RASCLE <paul.rascle@openfields.fr>
Mon, 23 Nov 2020 18:11:33 +0000 (19:11 +0100)
committerYOANN AUDOUIN <B61570@dsp0919998.atlas.edf.fr>
Fri, 11 Dec 2020 14:53:30 +0000 (15:53 +0100)
src/HYDROTools/plugins/fitShapePointsToMeshEdges.ui
src/HYDROTools/plugins/fitShapePointsToMeshEdgesDialog.py

index 98c9796ee384f96c4bfd78d809eb828ec7d74def..b3f617d3f3465be30a1b324bac8d5d856e8906be 100644 (file)
@@ -7,7 +7,7 @@
     <x>0</x>
     <y>0</y>
     <width>817</width>
-    <height>265</height>
+    <height>344</height>
    </rect>
   </property>
   <property name="windowTitle">
@@ -16,7 +16,7 @@
   <property name="layoutDirection">
    <enum>Qt::LeftToRight</enum>
   </property>
-  <layout class="QVBoxLayout" name="verticalLayout_2">
+  <layout class="QVBoxLayout" name="verticalLayout_3">
    <item>
     <widget class="QGroupBox" name="groupBox">
      <property name="title">
         </item>
        </layout>
       </item>
+     </layout>
+    </widget>
+   </item>
+   <item>
+    <widget class="QGroupBox" name="groupBox_2">
+     <property name="title">
+      <string>Output</string>
+     </property>
+     <layout class="QVBoxLayout" name="verticalLayout_2">
+      <item>
+       <layout class="QHBoxLayout" name="horizontalLayout_2">
+        <item>
+         <widget class="QLabel" name="lb_outDir">
+          <property name="sizePolicy">
+           <sizepolicy hsizetype="Maximum" vsizetype="Preferred">
+            <horstretch>0</horstretch>
+            <verstretch>0</verstretch>
+           </sizepolicy>
+          </property>
+          <property name="text">
+           <string>Output dir:</string>
+          </property>
+         </widget>
+        </item>
+        <item>
+         <widget class="QLineEdit" name="le_outDir">
+          <property name="statusTip">
+           <string>directory to store shapefiles and output mesh file if kept</string>
+          </property>
+         </widget>
+        </item>
+        <item>
+         <widget class="QToolButton" name="pb_outDir">
+          <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>
         </item>
         <item row="0" column="1">
+         <widget class="QCheckBox" name="cb_loadMeshEdges">
+          <property name="text">
+           <string>load result</string>
+          </property>
+         </widget>
+        </item>
+        <item row="0" column="2">
+         <widget class="QCheckBox" name="cb_splineMeshEdges">
+          <property name="text">
+           <string>load as spline</string>
+          </property>
+         </widget>
+        </item>
+        <item row="0" column="3">
          <spacer name="horizontalSpacer_2">
           <property name="orientation">
            <enum>Qt::Horizontal</enum>
           </property>
           <property name="sizeHint" stdset="0">
            <size>
-            <width>40</width>
+            <width>333</width>
             <height>20</height>
            </size>
           </property>
          </widget>
         </item>
         <item row="1" column="1">
+         <widget class="QCheckBox" name="cb_loadShapeToAdjust">
+          <property name="text">
+           <string>load result</string>
+          </property>
+         </widget>
+        </item>
+        <item row="1" column="2">
+         <widget class="QCheckBox" name="cb_splineShapeToAdjust">
+          <property name="text">
+           <string>load as spline</string>
+          </property>
+         </widget>
+        </item>
+        <item row="1" column="3">
          <spacer name="horizontalSpacer_3">
           <property name="orientation">
            <enum>Qt::Horizontal</enum>
           </property>
           <property name="sizeHint" stdset="0">
            <size>
-            <width>40</width>
+            <width>333</width>
             <height>20</height>
            </size>
           </property>
index dc7d3a630455909e7f96e176d8e703edf3e993ff..937562c7ee3ba333011c8791a1c1866896e8fa8a 100644 (file)
 
 import os
 import sys
+import salome
+
+salome.salome_init()
 
 from PyQt5.QtCore import *
 from PyQt5.QtGui import *
 from PyQt5.QtWidgets import *
 from PyQt5 import uic
+from HYDROPy import *
 
 from salome.hydrotools.shapesGroups import fitShapePointsToMesh
+from salome.hydrotools.hydroGeoMeshUtils import importPolylines
 
 #import sysconfig
 #pythonVersion = 'python' + sysconfig.get_python_version()
@@ -40,6 +45,7 @@ class fitShapePointsToMeshEdgesDialog(QDialog):
         # Connections
         self.pb_meshEdges.clicked.connect(self.on_meshEdges_browse)
         self.pb_shapeToAdjust.clicked.connect(self.on_shapeToAdjust_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)
@@ -67,6 +73,18 @@ class fitShapePointsToMeshEdgesDialog(QDialog):
         if not self.shapeToAdjust:
             return
         self.le_shapeToAdjust.setText(self.shapeToAdjust)
+        self.le_outDir.setText(os.path.dirname(self.shapeToAdjust))
+        
+    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):
         """
@@ -83,7 +101,7 @@ class fitShapePointsToMeshEdgesDialog(QDialog):
         <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'.
+        The shapefile adusted is written by default 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>         
@@ -107,12 +125,35 @@ class fitShapePointsToMeshEdgesDialog(QDialog):
         shapeToAdjust = self.le_shapeToAdjust.text()
         isMeshEdgesSplit = self.cb_splitMeshEdges.isChecked()
         isShapeToAdjustSplit = self.cb_splitShapeToAdjust.isChecked()
+        isLoadMeshEdges = self.cb_loadMeshEdges.isChecked()
+        isLoadShapeToAdjust = self.cb_loadShapeToAdjust.isChecked()
+        isSplineMeshEdges = self.cb_splineMeshEdges.isChecked()
+        isSplineShapeToAdjust = self.cb_splineShapeToAdjust.isChecked()
+        outdir = self.le_outDir.text()
         self.accept()
         print(meshEdges)
         print(shapeToAdjust)
         print(isMeshEdgesSplit)
         print(isShapeToAdjustSplit)
-        fitShapePointsToMesh(meshEdges, shapeToAdjust, "", isMeshEdgesSplit, isShapeToAdjustSplit)
+        fitShapePointsToMesh(meshEdges, shapeToAdjust, outdir, isMeshEdgesSplit, isShapeToAdjustSplit)
+        hydro_doc = HYDROData_Document.Document()
+        if isLoadMeshEdges:
+            a = os.path.splitext(os.path.basename(meshEdges))
+            ext = ""
+            if isMeshEdgesSplit:
+                ext = "_split"
+            meshEdgesShapefile = os.path.join(outdir, a[0] + ext + a[1]) 
+            shapeName = a[0] + ext
+            meshEdgesShapes = importPolylines(hydro_doc, meshEdgesShapefile, shapeName, isSplineMeshEdges, 0)
+        if isLoadShapeToAdjust:            
+            a = os.path.splitext(os.path.basename(shapeToAdjust))            
+            ext = "_adj"
+            adjustedShapefile = os.path.join(outdir, a[0] + ext + a[1]) 
+            shapeName = a[0] + ext
+            adjustedShapes = importPolylines(hydro_doc, adjustedShapefile, shapeName, isSplineShapeToAdjust, 0)
+        if salome.sg.hasDesktop():
+            salome.sg.updateObjBrowser()
+
 
     def on_reject(self):
         print("reject")