From ab276db78c845b064eb37af18fe8d12298dec6a8 Mon Sep 17 00:00:00 2001
From: Pierre-Antoine Rouby <pierre-antoine.rouby@inrae.fr>
Date: Wed, 7 Feb 2024 16:04:59 +0100
Subject: [PATCH] Meshing: Add minimal meshing option dialog.

---
 src/Meshing/Mage.py              |   2 +-
 src/View/Geometry/UndoCommand.py |   5 +-
 src/View/Geometry/Window.py      |  12 +-
 src/View/Tools/ASubWindow.py     |  25 +++-
 src/View/ui/MeshingOptions.ui    | 237 +++++++++++++++++++++++++++++++
 5 files changed, 274 insertions(+), 7 deletions(-)
 create mode 100644 src/View/ui/MeshingOptions.ui

diff --git a/src/Meshing/Mage.py b/src/Meshing/Mage.py
index 6150e59c..bd60ed1c 100644
--- a/src/Meshing/Mage.py
+++ b/src/Meshing/Mage.py
@@ -294,7 +294,7 @@ class MeshingWithMageMailleurTT(AMeshingTool):
             proc = QProcess()
             proc.setWorkingDirectory(tmp)
 
-            logger.debug(f"! mailleurTT {st_file} {m_file} {str(step)}")
+            logger.info(f"! mailleurTT {st_file} {m_file} {str(step)}")
             proc.start(
                 self._exe_path(), [st_file, m_file, str(step)]
             )
diff --git a/src/View/Geometry/UndoCommand.py b/src/View/Geometry/UndoCommand.py
index 86f3d3ea..aafd2b50 100644
--- a/src/View/Geometry/UndoCommand.py
+++ b/src/View/Geometry/UndoCommand.py
@@ -237,7 +237,10 @@ class MeshingCommand(QUndoCommand):
 
     def redo(self):
         if self._new_profiles is None:
-            self._mesher.meshing(self._reach)
+            self._mesher.meshing(
+                self._reach,
+                step=self._step
+            )
 
             self._new_profiles = self._reach.profiles.copy()
             self._new_profiles.reverse()
diff --git a/src/View/Geometry/Window.py b/src/View/Geometry/Window.py
index b69531bd..7c35818e 100644
--- a/src/View/Geometry/Window.py
+++ b/src/View/Geometry/Window.py
@@ -54,6 +54,7 @@ from View.Geometry.Table import GeometryReachTableModel
 from View.Geometry.PlotXY import PlotXY
 from View.Geometry.PlotAC import PlotAC
 from View.Geometry.PlotKPZ import PlotKPZ
+from View.Geometry.MeshingDialog import MeshingDialog
 from View.Geometry.Translate import GeometryTranslate
 from View.Geometry.Profile.Window import ProfileWindow
 
@@ -260,14 +261,17 @@ class GeometryWindow(PamhyrWindow):
 
     def edit_meshing(self):
         try:
-            self._edit_meshing()
-        except Exception:
+            dlg = MeshingDialog(parent=self)
+            if dlg.exec():
+                step = dlg.space_step
+                self._edit_meshing(step)
+        except Exception as e:
             return
 
-    def _edit_meshing(self):
+    def _edit_meshing(self, step):
         try:
             mesher = MeshingWithMageMailleurTT()
-            self._table.meshing(mesher, -1)
+            self._table.meshing(mesher, step)
         except Exception as e:
             logger_exception(e)
             raise ExternFileMissingError(
diff --git a/src/View/Tools/ASubWindow.py b/src/View/Tools/ASubWindow.py
index 7ef5f964..b0eee20c 100644
--- a/src/View/Tools/ASubWindow.py
+++ b/src/View/Tools/ASubWindow.py
@@ -35,7 +35,7 @@ from PyQt5.QtWidgets import (
     QRadioButton, QComboBox, QFileDialog,
     QMessageBox, QTableView, QAction,
     QDateTimeEdit, QWidget, QPlainTextEdit,
-    QLabel,
+    QLabel, QDoubleSpinBox,
 )
 from PyQt5.QtCore import (
     QTime, QDateTime,
@@ -324,6 +324,29 @@ class ASubWindowFeatures(object):
         """
         return self.find(QSpinBox, name).value()
 
+    def set_double_spin_box(self, name: str, value: int):
+        """Set value of spinbox component
+
+        Args:
+            name: The spinbox component name
+            value: The new value
+
+        Returns:
+            Nothing
+        """
+        self.find(QDoubleSpinBox, name).setValue(value)
+
+    def get_double_spin_box(self, name: str):
+        """Get time of spin box component
+
+        Args:
+            name: The spin box component
+
+        Returns:
+            The value of spin box
+        """
+        return self.find(QDoubleSpinBox, name).value()
+
     def set_action_checkable(self, name: str, checked: bool):
         """Set value of action
 
diff --git a/src/View/ui/MeshingOptions.ui b/src/View/ui/MeshingOptions.ui
new file mode 100644
index 00000000..315a171e
--- /dev/null
+++ b/src/View/ui/MeshingOptions.ui
@@ -0,0 +1,237 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>Dialog</class>
+ <widget class="QDialog" name="Dialog">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>416</width>
+    <height>234</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>Dialog</string>
+  </property>
+  <layout class="QGridLayout" name="gridLayout">
+   <item row="0" column="0">
+    <layout class="QHBoxLayout" name="horizontalLayout_3">
+     <item>
+      <layout class="QHBoxLayout" name="horizontalLayout">
+       <item>
+        <widget class="QLabel" name="label">
+         <property name="enabled">
+          <bool>false</bool>
+         </property>
+         <property name="text">
+          <string>First cross section</string>
+         </property>
+        </widget>
+       </item>
+       <item>
+        <widget class="QComboBox" name="comboBox_begin_kp">
+         <property name="enabled">
+          <bool>false</bool>
+         </property>
+        </widget>
+       </item>
+      </layout>
+     </item>
+     <item>
+      <layout class="QHBoxLayout" name="horizontalLayout_2">
+       <item>
+        <widget class="QLabel" name="label_2">
+         <property name="enabled">
+          <bool>false</bool>
+         </property>
+         <property name="text">
+          <string>Last cross section</string>
+         </property>
+        </widget>
+       </item>
+       <item>
+        <widget class="QComboBox" name="comboBox_end_kp">
+         <property name="enabled">
+          <bool>false</bool>
+         </property>
+        </widget>
+       </item>
+      </layout>
+     </item>
+    </layout>
+   </item>
+   <item row="1" column="0">
+    <layout class="QHBoxLayout" name="horizontalLayout_6">
+     <item>
+      <layout class="QHBoxLayout" name="horizontalLayout_7">
+       <item>
+        <widget class="QLabel" name="label_5">
+         <property name="enabled">
+          <bool>false</bool>
+         </property>
+         <property name="text">
+          <string>First guide line</string>
+         </property>
+        </widget>
+       </item>
+       <item>
+        <widget class="QComboBox" name="comboBox_begin_kp_2">
+         <property name="enabled">
+          <bool>false</bool>
+         </property>
+        </widget>
+       </item>
+      </layout>
+     </item>
+     <item>
+      <layout class="QHBoxLayout" name="horizontalLayout_8">
+       <item>
+        <widget class="QLabel" name="label_6">
+         <property name="enabled">
+          <bool>false</bool>
+         </property>
+         <property name="text">
+          <string>Last guide line</string>
+         </property>
+        </widget>
+       </item>
+       <item>
+        <widget class="QComboBox" name="comboBox_end_kp_2">
+         <property name="enabled">
+          <bool>false</bool>
+         </property>
+        </widget>
+       </item>
+      </layout>
+     </item>
+    </layout>
+   </item>
+   <item row="2" column="0">
+    <layout class="QHBoxLayout" name="horizontalLayout_4">
+     <item>
+      <widget class="QLabel" name="label_3">
+       <property name="text">
+        <string>Section space step</string>
+       </property>
+      </widget>
+     </item>
+     <item>
+      <widget class="QDoubleSpinBox" name="doubleSpinBox_space_step"/>
+     </item>
+     <item>
+      <spacer name="horizontalSpacer_2">
+       <property name="orientation">
+        <enum>Qt::Horizontal</enum>
+       </property>
+       <property name="sizeHint" stdset="0">
+        <size>
+         <width>40</width>
+         <height>20</height>
+        </size>
+       </property>
+      </spacer>
+     </item>
+    </layout>
+   </item>
+   <item row="3" column="0">
+    <layout class="QHBoxLayout" name="horizontalLayout_5">
+     <item>
+      <widget class="QLabel" name="label_4">
+       <property name="enabled">
+        <bool>false</bool>
+       </property>
+       <property name="text">
+        <string>lm</string>
+       </property>
+      </widget>
+     </item>
+     <item>
+      <widget class="QComboBox" name="comboBox_lm">
+       <property name="enabled">
+        <bool>false</bool>
+       </property>
+      </widget>
+     </item>
+     <item>
+      <spacer name="horizontalSpacer_3">
+       <property name="orientation">
+        <enum>Qt::Horizontal</enum>
+       </property>
+       <property name="sizeHint" stdset="0">
+        <size>
+         <width>40</width>
+         <height>20</height>
+        </size>
+       </property>
+      </spacer>
+     </item>
+    </layout>
+   </item>
+   <item row="4" column="0">
+    <widget class="QCheckBox" name="checkBox_lplan">
+     <property name="enabled">
+      <bool>false</bool>
+     </property>
+     <property name="text">
+      <string>Lplan</string>
+     </property>
+    </widget>
+   </item>
+   <item row="5" column="0">
+    <widget class="QCheckBox" name="checkBox_linear">
+     <property name="enabled">
+      <bool>false</bool>
+     </property>
+     <property name="text">
+      <string>Linear</string>
+     </property>
+    </widget>
+   </item>
+   <item row="6" column="0">
+    <widget class="QDialogButtonBox" name="buttonBox">
+     <property name="orientation">
+      <enum>Qt::Horizontal</enum>
+     </property>
+     <property name="standardButtons">
+      <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
+     </property>
+    </widget>
+   </item>
+  </layout>
+ </widget>
+ <resources/>
+ <connections>
+  <connection>
+   <sender>buttonBox</sender>
+   <signal>accepted()</signal>
+   <receiver>Dialog</receiver>
+   <slot>accept()</slot>
+   <hints>
+    <hint type="sourcelabel">
+     <x>248</x>
+     <y>254</y>
+    </hint>
+    <hint type="destinationlabel">
+     <x>157</x>
+     <y>274</y>
+    </hint>
+   </hints>
+  </connection>
+  <connection>
+   <sender>buttonBox</sender>
+   <signal>rejected()</signal>
+   <receiver>Dialog</receiver>
+   <slot>reject()</slot>
+   <hints>
+    <hint type="sourcelabel">
+     <x>316</x>
+     <y>260</y>
+    </hint>
+    <hint type="destinationlabel">
+     <x>286</x>
+     <y>274</y>
+    </hint>
+   </hints>
+  </connection>
+ </connections>
+</ui>
-- 
GitLab