]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
automatic load shapes from dialog 'Mesh edges to shapes'
authorPaul RASCLE <paul.rascle@openfields.fr>
Thu, 26 Nov 2020 14:13:26 +0000 (15:13 +0100)
committerYOANN AUDOUIN <B61570@dsp0919998.atlas.edf.fr>
Fri, 11 Dec 2020 14:53:30 +0000 (15:53 +0100)
src/HYDROTools/plugins/meshEdgesToShapes.ui
src/HYDROTools/plugins/meshEdgesToShapesDialog.py
src/HYDROTools/shapesGroups.py

index 2319c56cd9e7fbe64a45b03b84dbabd6ccc51cce..244709d2cbb14f9b74467db29ae8f7fde7189bea 100644 (file)
@@ -7,7 +7,7 @@
     <x>0</x>
     <y>0</y>
     <width>814</width>
-    <height>369</height>
+    <height>389</height>
    </rect>
   </property>
   <property name="windowTitle">
         </property>
        </widget>
       </item>
+      <item>
+       <widget class="QCheckBox" name="cb_loadFreeBorders">
+        <property name="text">
+         <string>Load free borders shape</string>
+        </property>
+       </widget>
+      </item>
+      <item>
+       <widget class="QCheckBox" name="cb_loadOthers">
+        <property name="text">
+         <string>Load all other edge shapes</string>
+        </property>
+       </widget>
+      </item>
      </layout>
     </widget>
    </item>
index e17579ca975663c052ecbebf26994d513b9ef556..67b2ed3bfa999e0c85e08af26703a944b11ed6d1 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 *
+import json
 
 from salome.hydrotools.shapesGroups import freeBordersGroup, exploreEdgeGroups
+from salome.hydrotools.hydroGeoMeshUtils import importPolylines
 
 #import sysconfig
 #pythonVersion = 'python' + sysconfig.get_python_version()
@@ -114,6 +120,8 @@ class meshEdgesToShapesDialog(QDialog):
         offsetX = self.dsb_offsetX.value()
         offsetY = self.dsb_offsetY.value()
         isOutMedKept = self.cb_keepOutMed.isChecked()
+        isLoadFreeBorders = self.cb_loadFreeBorders.isChecked()
+        isLoadOthers = self.cb_loadOthers.isChecked()
         self.accept()
         print(medFile)
         print(outDir)
@@ -127,6 +135,24 @@ class meshEdgesToShapesDialog(QDialog):
         if not isOutMedKept:
             print("remove", medFileOut)
             os.remove(medFileOut)
+        shapesListFile = os.path.join(outDir, "shapesList.json")
+        fileShapes = []
+        with open(shapesListFile, 'r') as f:
+            fileShapes = json.load(f)
+        print(fileShapes)
+        hydro_doc = HYDROData_Document.Document()
+        l = []
+        if isLoadFreeBorders:
+            l = l + [ a for a in fileShapes if "FreeBorders.shp" in a]
+        if isLoadOthers:
+            l = l + [ a for a in fileShapes if "FreeBorders.shp" not in a]
+        for fileShape in l:
+            a = os.path.splitext(os.path.basename(fileShape))            
+            shapeName = a[0]
+            shapes = importPolylines(hydro_doc, fileShape, shapeName, 0, 0)
+        if salome.sg.hasDesktop():
+            salome.sg.updateObjBrowser()
+            
 
     def on_reject(self):
         print("reject")
index f4673d800e977a5d1ee196980532d34b4b93be10..a5ffb49716a072afd7a78cd99fed460280986c5d 100644 (file)
@@ -12,7 +12,7 @@ import medcoupling as mc
 import shapefile
 import math
 import os
-
+import json
 
 def freeBordersGroup(meshFileIn, meshFileOut=""):
     """
@@ -159,6 +159,7 @@ def writeShapeLines(mcMesh, grpName, nodeChains, outputDirectory, offsetX=0., of
         w.line([chaincoords])
         w.record(chainName)
     w.close()
+    return shapeFileName + '.shp'
 
 
 def writeShapePoints(mcMesh, grpName, nodeChains, outputDirectory, offsetX=0., offsetY=0.):
@@ -216,12 +217,16 @@ def exploreEdgeGroups(meshFile, outputDirectory="", offsetX=0., offsetY=0.):
 
     groups = [mcMesh.getGroup(d1, name) for name in grp_names] # list of groups in their name order
 
+    filenames = []
     for (grp, grpName) in zip(groups, grp_names):
         fullGrpName = prefix + '_' + grpName
         nodeChains = explodeGroup(grp, fullGrpName)
-        writeShapeLines(mcMesh, fullGrpName, nodeChains, outputDirectory, offsetX, offsetY)
+        filename = writeShapeLines(mcMesh, fullGrpName, nodeChains, outputDirectory, offsetX, offsetY)
         writeShapePoints(mcMesh, fullGrpName, nodeChains, outputDirectory, offsetX, offsetY)
-
+        filenames.append(filename)
+    shapesListFile = os.path.join(outputDirectory, "shapesList.json")
+    with open(shapesListFile, 'w') as f:
+        json.dump(filenames, f)
 
 def fitShapePointsToMesh(freeBorderShapefile, shapefileToAdjust, outputDirectory="", splitFreeBorder=True, splitShapeAdjusted=True):
     """