]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
selection on object browser for med in 'Mesh edges to shapes' dialog
authorPaul RASCLE <paul.rascle@openfields.fr>
Thu, 26 Nov 2020 18:25:27 +0000 (19:25 +0100)
committerYOANN AUDOUIN <B61570@dsp0919998.atlas.edf.fr>
Fri, 11 Dec 2020 14:53:30 +0000 (15:53 +0100)
src/HYDROTools/plugins/fitShapePointsToMeshEdgesDialog.py
src/HYDROTools/plugins/meshEdgesToShapes.ui
src/HYDROTools/plugins/meshEdgesToShapesDialog.py

index e94853363ca53bde64c92b1d3bcafe1cbec0f6a1..e15e0e69af085c008e36719d2b1d6f23732fb203 100644 (file)
@@ -37,13 +37,13 @@ from salome.hydrotools.hydroGeoMeshUtils import importPolylines
 
 import tempfile
 
-#import sysconfig
-#pythonVersion = 'python' + sysconfig.get_python_version()
 hydro_root = os.path.join(os.environ['HYDRO_ROOT_DIR'], 'share', 'salome', 'plugins', 'hydro', 'plugins')
 hydro_resources = os.path.join(os.environ['HYDRO_ROOT_DIR'], 'share', 'salome', 'resources', 'hydro')
 
 class fitShapePointsToMeshEdgesDialog(QDialog):
     """
+    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.
     """
 
     def __init__(self, parent = None, modal = 0):
index 244709d2cbb14f9b74467db29ae8f7fde7189bea..cd75f2351c6924ec7e02b4b9c36b3408857dabf1 100644 (file)
           </property>
          </widget>
         </item>
+        <item>
+         <widget class="QToolButton" name="tb_medFile">
+          <property name="toolTip">
+           <string>Select a shape in the HYDRO object browser</string>
+          </property>
+          <property name="text">
+           <string>...</string>
+          </property>
+         </widget>
+        </item>
         <item>
          <widget class="QLineEdit" name="le_medFile"/>
         </item>
index 67b2ed3bfa999e0c85e08af26703a944b11ed6d1..1cf70c87cf2dfff9a30548642bab14f7a1f3ee50 100644 (file)
@@ -21,6 +21,11 @@ import salome
 
 salome.salome_init()
 
+import SalomePyQt
+sgPyQt = SalomePyQt.SalomePyQt()
+import libSALOME_Swig
+salome_gui = libSALOME_Swig.SALOMEGUI_Swig()
+
 from PyQt5.QtCore import *
 from PyQt5.QtGui import *
 from PyQt5.QtWidgets import *
@@ -31,12 +36,16 @@ import json
 from salome.hydrotools.shapesGroups import freeBordersGroup, exploreEdgeGroups
 from salome.hydrotools.hydroGeoMeshUtils import importPolylines
 
-#import sysconfig
-#pythonVersion = 'python' + sysconfig.get_python_version()
+import  SMESH, SALOMEDS
+from salome.smesh import smeshBuilder
+
 hydro_root = os.path.join(os.environ['HYDRO_ROOT_DIR'], 'share', 'salome', 'plugins', 'hydro', 'plugins')
+hydro_resources = os.path.join(os.environ['HYDRO_ROOT_DIR'], 'share', 'salome', 'resources', 'hydro')
 
 class meshEdgesToShapesDialog(QDialog):
     """
+    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.
     """
 
     def __init__(self, parent = None, modal = 0):
@@ -45,6 +54,8 @@ class meshEdgesToShapesDialog(QDialog):
 
         # Connections
         self.pb_medFile.clicked.connect(self.on_med_file_browse)
+        self.tb_medFile.setIcon(QIcon(QPixmap(os.path.join(hydro_resources, "icon_select.png"))))
+        self.tb_medFile.clicked.connect(self.on_select_med_file)
         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)
@@ -53,9 +64,40 @@ class meshEdgesToShapesDialog(QDialog):
         self.medFile = None
         self.outDir = None
         
+    def get_selected_mesh(self):
+        """
+        Select a mesh in the object browser and return associated filename
+        """
+        nbsel = salome.sg.SelectedCount()
+        if nbsel != 1:
+            return ""
+        sel=salome.sg.getSelected(0)
+        so=salome.myStudy.FindObjectID(sel)
+        if so is None:
+            return ""
+        obj=so.GetObject()
+        smesh = smeshBuilder.New()
+        smesh.SetEnablePublish( False )
+        mesh1 = smesh.Mesh()
+        smesh.SetEnablePublish( True )
+        if not isinstance(obj, type(mesh1.GetMesh())):
+            return ""
+        filename = obj.GetMesh().GetMEDFileInfo().fileName
+        return filename
+    
+    def on_select_med_file(self):
+        """
+        set selected mesh filename on dialog
+        """
+        filename = self.get_selected_mesh()
+        print("selected mesh: %s"%filename)
+        if filename != "":
+            self.medFile = filename
+            self.le_medFile.setText(self.medFile)
+        
     def on_med_file_browse(self):
         """
-        Select MED file
+        Select MED file in file system
         """
         print("on_med_file_browse")
         self.medFile, filt = QFileDialog.getOpenFileName(self, self.tr("Input MED file"), "", self.tr("MED files (*.med)"))
@@ -130,8 +172,11 @@ class meshEdgesToShapesDialog(QDialog):
         a = os.path.splitext(medFile)
         medFileOut = os.path.join(outDir, os.path.basename(a[0]) + '_brd' + a[1])
         print(medFileOut)
+        smesh = smeshBuilder.New()
+        smesh.SetEnablePublish( False )
         medFileOut = freeBordersGroup(medFile, medFileOut)
         exploreEdgeGroups(medFileOut, outDir, offsetX, offsetY)
+        smesh.SetEnablePublish( True )
         if not isOutMedKept:
             print("remove", medFileOut)
             os.remove(medFileOut)
@@ -161,8 +206,6 @@ class meshEdgesToShapesDialog(QDialog):
 
 def execDialog(context):
     print("execDialog")
-  # get context study, salomeGui
-    study = context.study
-    sg = context.sg
-    dlg = meshEdgesToShapesDialog()
-    dlg.exec_()        
+    desktop = sgPyQt.getDesktop()
+    dlg = meshEdgesToShapesDialog(desktop)
+    dlg.show()