From ceff5f3083ce3024e541d91bfd173f93c5eb3bc4 Mon Sep 17 00:00:00 2001 From: Theophile Terraz Date: Wed, 19 Nov 2025 15:26:09 +0100 Subject: [PATCH] debug internal mesher --- src/Meshing/Internal.py | 87 +++++++++++++++++++++----------- src/View/Geometry/Table.py | 14 ++++- src/View/Geometry/UndoCommand.py | 11 +--- 3 files changed, 73 insertions(+), 39 deletions(-) diff --git a/src/Meshing/Internal.py b/src/Meshing/Internal.py index b944246b..5aa62063 100644 --- a/src/Meshing/Internal.py +++ b/src/Meshing/Internal.py @@ -40,20 +40,20 @@ class InternalMeshing(AMeshingTool): step: float = 50, limites=[-1, -1], linear: bool = True): - if reach is None or len(reach.profiles) == 0: - return reach - if limites[0] > limites[1]: - lim = limites[1] - limites[1] = limites[0] - limites[0] = lim - elif limites[0] == limites[1]: - return reach + # pre process - # we never modify original profiles, we work on copies - m_profiles = self.st_to_m(reach, limites) - new_profiles = self.interpolate_transversal_step(m_profiles, - step) + profiles = self.get_profiles(reach, limites) + if profiles is None: + return [] + + guide_list = self.get_guide_list(reach, profiles) + if guide_list is None: + return [] + + # we never modify original profiles, we work on the copies + m_profiles = self.st_to_m(profiles, guide_list) + new_profiles = self.interpolate_transversal_step(m_profiles, step) for new_profiles2 in new_profiles: for p in new_profiles2: @@ -61,19 +61,7 @@ class InternalMeshing(AMeshingTool): return new_profiles - def st_to_m(self, reach, limites): - - gl = reach.compute_guidelines() - profiles = [reach.profile(i).copy() - for i in range(limites[0], limites[1]+1) - ] - - # we make sure that the lines are in the left-to-right order - guide_list = [ - x.name - for x in profiles[0].named_points() - if x.name in gl[0] - ] + def st_to_m(self, profiles, guide_list): gl1 = [""] + guide_list gl2 = guide_list + [""] @@ -193,23 +181,25 @@ class InternalMeshing(AMeshingTool): for i in range(len2): ltot2 += sect2.point(start2+i).dist(sect2.point(start2+i+1)) beta.append(ltot2) - beta = list(map(lambda x: x/ltot2, beta)) # current ratios - for i in range(len1 - len2): - beta.append(1.0) - beta.append(0.0) # beta[-1] if len2 < 1 or ltot2 < 0.0001: # unique point (copy len1 times) # we are at an edge of the profile for i in range(len1-len2): p = sect2.point(start2).copy() sect2.insert_point(start2, p) + len2 += 1 if tag1 == '': # left end point sect2.point(start2).name = '' if tag2 == '': # left end point sect2.point(start2+1).name = '' elif ltot1 < 0.0001: sect2.add_npoints(len1-len2) + len2 = len1 else: # regular case + beta = list(map(lambda x: x/ltot2, beta)) # current ratios + for i in range(len1 - len2): + beta.append(1.0) + beta.append(0.0) # beta[-1] # loop on the points to insert for k in range(len1-len2): trouve = False @@ -343,3 +333,42 @@ class InternalMeshing(AMeshingTool): return new_rk, new_end_rk, new_begin_rk else: return new_rk, new_begin_rk, new_end_rk + + def get_guide_list(self, reach, profiles): + + gl = reach.compute_guidelines() + + # we make sure that the lines are in the left-to-right order + guide_list = [ + [ + x.name + for x in p.named_points() + if x.name in gl[0] + ] + for p in profiles] + + # we make sure the lines never cross + for gl in guide_list: + for i in range(len(guide_list[0])): + if gl[i] != guide_list[0][i]: + return None + + return guide_list[0] + + def get_profiles(self, reach, limites): + + if reach is None or len(reach.profiles) == 0: + return None + + if limites[0] > limites[1]: + lim = limites[1] + limites[1] = limites[0] + limites[0] = lim + elif limites[0] == limites[1]: + return None + + profiles = [reach.profile(i).copy() + for i in range(limites[0], limites[1]+1) + ] + + return profiles diff --git a/src/View/Geometry/Table.py b/src/View/Geometry/Table.py index 33a7a9aa..0c2f5552 100644 --- a/src/View/Geometry/Table.py +++ b/src/View/Geometry/Table.py @@ -251,11 +251,23 @@ class GeometryReachTableModel(PamhyrTableModel): self.layoutChanged.emit() def meshing(self, mesher, data, tableView): + + new_profiles = mesher.meshing( + self._data, + **data + ) + + if new_profiles is None: + return + + if len(new_profiles) == 0: + return + self.layoutAboutToBeChanged.emit() self._undo.push( MeshingCommand( - self._data, mesher, data, tableView + self._data, new_profiles, data, tableView ) ) diff --git a/src/View/Geometry/UndoCommand.py b/src/View/Geometry/UndoCommand.py index 88fb4162..3a5da35b 100644 --- a/src/View/Geometry/UndoCommand.py +++ b/src/View/Geometry/UndoCommand.py @@ -274,15 +274,14 @@ class UpdateRKCommand(QUndoCommand): class MeshingCommand(QUndoCommand): - def __init__(self, reach, mesher, data, tableView): + def __init__(self, reach, new_profiles, data, tableView): QUndoCommand.__init__(self) self._reach = reach self._data = data self._limites = data["limites"] - self._mesher = mesher - self._new_profiles = None + self._new_profiles = new_profiles self._new_profiles_indexes = None self._tableView = tableView self._indexes = tableView.selectionModel().selection() @@ -308,12 +307,6 @@ class MeshingCommand(QUndoCommand): ) def redo(self): - if self._new_profiles is None: - self._new_profiles = self._mesher.meshing( - self._reach, - **self._data - ) - if self._new_profiles_indexes is None: k = self._limites[0] self._new_profiles_indexes = []