]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
selection on object browser for shapes in fitShapesPointsToMesheEdges dialog
authorPaul RASCLE <paul.rascle@openfields.fr>
Wed, 25 Nov 2020 17:56:27 +0000 (18:56 +0100)
committerYOANN AUDOUIN <B61570@dsp0919998.atlas.edf.fr>
Fri, 11 Dec 2020 14:53:30 +0000 (15:53 +0100)
src/HYDROGUI/resources/icon_select.png
src/HYDROTools/hydroGeoMeshUtils.py
src/HYDROTools/plugins/fitShapePointsToMeshEdges.ui
src/HYDROTools/plugins/fitShapePointsToMeshEdgesDialog.py

index cd126ad011ec15a1e57f0975bfec3862e667fdec..4af5214ebf8dfd3245c9cbe7a2aeabb963af42ce 100644 (file)
Binary files a/src/HYDROGUI/resources/icon_select.png and b/src/HYDROGUI/resources/icon_select.png differ
index 5089394ad89d3c7c3df9cc0f6cd077b322159ce6..6da1a4efd8488c0897870f06b662499a0e084d34 100644 (file)
@@ -63,28 +63,32 @@ def importPolylines(document, shapeFile, shapeName, iSpline, displayLevel):
         shapeType = 1 # polyline
     shapes = []
     isShapeFound = True
-    shape = document.FindObjectByName(shapeName) # single shape
-    if shape is not None:
-        for i in range(shape.NbSections()):
-            shape.SetSectionType(i, shapeType)
-            shape.Update()
-            shape.SetZLevel(displayLevel)
-        shapes.append(shape)    
+    print("importPolylines %s %s"%(shapeName, shapeType))
     index = 0  # for multiple shapes
     while isShapeFound:
         shapeNameIndex = shapeName + "_%d" % index
         index = index + 1
-        print(shapeNameIndex)
+        print("try name %s"%shapeNameIndex)
         shape = document.FindObjectByName(shapeNameIndex)
-        print(shape)
         if shape is None:
             isShapeFound = False
         else:
+            print("found %s"%shapeNameIndex)
             for i in range(shape.NbSections()):
                 shape.SetSectionType(i, shapeType)
                 shape.Update()
                 shape.SetZLevel(displayLevel)
-            shapes.append(shape)    
+            shapes.append(shape)
+    if index <= 1: # no multiple shapes, try single shape  
+        print("try name %s"%shapeName)
+        shape = document.FindObjectByName(shapeName) # single shape
+        if shape is not None:
+            print("found %s"%shapeName)
+            for i in range(shape.NbSections()):
+                shape.SetSectionType(i, shapeType)
+                shape.Update()
+                shape.SetZLevel(displayLevel)
+            shapes.append(shape)
     return shapes
 
 def importBathymetry(document, bathyName, bathyPath):
index b3f617d3f3465be30a1b324bac8d5d856e8906be..de18cd81d340edab7ab6081b00024ec9b899c41b 100644 (file)
   <property name="layoutDirection">
    <enum>Qt::LeftToRight</enum>
   </property>
-  <layout class="QVBoxLayout" name="verticalLayout_3">
+  <layout class="QVBoxLayout" name="verticalLayout">
    <item>
     <widget class="QGroupBox" name="groupBox">
      <property name="title">
       <string>Input</string>
      </property>
-     <layout class="QVBoxLayout" name="verticalLayout">
+     <layout class="QHBoxLayout" name="horizontalLayout_3">
       <item>
        <layout class="QGridLayout" name="gridLayout">
         <item row="0" column="0">
          </widget>
         </item>
         <item row="0" column="1">
-         <widget class="QLineEdit" name="le_meshEdges"/>
+         <widget class="QToolButton" name="tb_meshEdges">
+          <property name="toolTip">
+           <string>Select a shape in the HYDRO object browser</string>
+          </property>
+          <property name="text">
+           <string>...</string>
+          </property>
+         </widget>
         </item>
         <item row="0" column="2">
+         <widget class="QLineEdit" name="le_meshEdges"/>
+        </item>
+        <item row="0" column="3">
          <widget class="QToolButton" name="pb_meshEdges">
           <property name="sizePolicy">
            <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
@@ -49,6 +59,9 @@
             <verstretch>0</verstretch>
            </sizepolicy>
           </property>
+          <property name="toolTip">
+           <string>Select a shapefile in the file system</string>
+          </property>
           <property name="text">
            <string>...</string>
           </property>
          </widget>
         </item>
         <item row="1" column="1">
-         <widget class="QLineEdit" name="le_shapeToAdjust"/>
+         <widget class="QToolButton" name="tb_shapeToAdjust">
+          <property name="toolTip">
+           <string>Select a shape in the HYDRO object browser</string>
+          </property>
+          <property name="text">
+           <string>...</string>
+          </property>
+         </widget>
         </item>
         <item row="1" column="2">
+         <widget class="QLineEdit" name="le_shapeToAdjust"/>
+        </item>
+        <item row="1" column="3">
          <widget class="QToolButton" name="pb_shapeToAdjust">
           <property name="sizePolicy">
            <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
             <verstretch>0</verstretch>
            </sizepolicy>
           </property>
+          <property name="toolTip">
+           <string>Select a shapefile in the file system</string>
+          </property>
           <property name="text">
            <string>...</string>
           </property>
index 937562c7ee3ba333011c8791a1c1866896e8fa8a..dc9e646f40bcdbcb36f308be0504f3a697b0ebab 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 *
@@ -30,9 +35,12 @@ from HYDROPy import *
 from salome.hydrotools.shapesGroups import fitShapePointsToMesh
 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):
     """
@@ -43,6 +51,10 @@ class fitShapePointsToMeshEdgesDialog(QDialog):
         uic.loadUi(os.path.join(hydro_root, 'fitShapePointsToMeshEdges.ui'), self )
 
         # Connections
+        self.tb_meshEdges.clicked.connect(self.on_select_meshEdges)
+        self.tb_shapeToAdjust.clicked.connect(self.on_select_shapeToAdjust)
+        self.tb_meshEdges.setIcon(QIcon(QPixmap(os.path.join(hydro_resources, "icon_select.png"))))
+        self.tb_shapeToAdjust.setIcon(QIcon(QPixmap(os.path.join(hydro_resources, "icon_select.png"))))
         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)
@@ -51,7 +63,55 @@ class fitShapePointsToMeshEdgesDialog(QDialog):
         self.pb_ok.rejected.connect(self.on_reject)
         self.meshEdges = None
         self.shapeToAdjust = None
+        self.tmpdir = tempfile.mkdtemp()
+        print("tmpdir=",self.tmpdir)
+
+        
+    def get_selected_polyline(self):
+        """
+        Select a polyline2D in the HYDRO object browser
+        """
+        ind = SalomePyQt.SalomePyQt.getObjectBrowser().selectionModel().selectedIndexes()
+        doc = HYDROData_Document.Document()
+        for i in ind:
+            if i.column()==0:
+                name = str(i.data())
+                case = doc.FindObjectByName( name )
+                if isinstance(case, HYDROData_PolylineXY):
+                    print("selected %s"%name)
+                    return name
+        return None
+    
+    def on_select_meshEdges(self):
+        """
+        Get selected Polyline in the HYDRO object browser
+        """
+        name = self.get_selected_polyline()
+        if name is None:
+            return 
+        doc = HYDROData_Document.Document()
+        polyXY = doc.FindObjectByName(name)
+        if polyXY is None:
+            return
+        self.meshEdges = os.path.join(self.tmpdir, name + ".shp")
+        res = HYDROData_PolylineXY.ExportShapeXY(doc, self.meshEdges, [polyXY])
+        self.le_meshEdges.setText(self.meshEdges)
         
+    def on_select_shapeToAdjust(self):
+        """
+        Get selected Polyline in the HYDRO object browser
+        """
+        name = self.get_selected_polyline()
+        if name is None:
+            return 
+        doc = HYDROData_Document.Document()
+        polyXY = doc.FindObjectByName(name)
+        if polyXY is None:
+            return
+        self.shapeToAdjust = os.path.join(self.tmpdir, name + ".shp")
+        res = HYDROData_PolylineXY.ExportShapeXY(doc, self.shapeToAdjust, [polyXY])
+        self.le_shapeToAdjust.setText(self.shapeToAdjust)
+
     def on_meshEdges_browse(self):
         """
         Select Shapefile of mesh edges
@@ -130,6 +190,11 @@ class fitShapePointsToMeshEdgesDialog(QDialog):
         isSplineMeshEdges = self.cb_splineMeshEdges.isChecked()
         isSplineShapeToAdjust = self.cb_splineShapeToAdjust.isChecked()
         outdir = self.le_outDir.text()
+        if not os.path.isdir(outdir):
+            msgBox = QMessageBox()
+            msgBox.setText( "Output directory is not set, please select" )
+            msgBox.exec_()
+            return
         self.accept()
         print(meshEdges)
         print(shapeToAdjust)
@@ -143,13 +208,15 @@ class fitShapePointsToMeshEdgesDialog(QDialog):
             if isMeshEdgesSplit:
                 ext = "_split"
             meshEdgesShapefile = os.path.join(outdir, a[0] + ext + a[1]) 
-            shapeName = a[0] + ext
+            shapeName = a[0] #+ ext + "_PolyXY"
+            print("isSplineMeshEdges %s"%isSplineMeshEdges)
             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
+            shapeName = a[0] #+ ext + "_PolyXY"
+            print("isSplineShapeToAdjust %s"%isSplineShapeToAdjust)
             adjustedShapes = importPolylines(hydro_doc, adjustedShapefile, shapeName, isSplineShapeToAdjust, 0)
         if salome.sg.hasDesktop():
             salome.sg.updateObjBrowser()
@@ -162,8 +229,6 @@ class fitShapePointsToMeshEdgesDialog(QDialog):
 
 def execDialog(context):
     print("execDialog")
-  # get context study, salomeGui
-    study = context.study
-    sg = context.sg
-    dlg = fitShapePointsToMeshEdgesDialog()
-    dlg.exec_()        
+    desktop = sgPyQt.getDesktop()
+    dlg = fitShapePointsToMeshEdgesDialog(desktop)
+    dlg.show()