mirror of https://gitlab.com/pamhyr/pamhyr2
Compare commits
2 Commits
8aa0e25da2
...
879c151524
| Author | SHA1 | Date |
|---|---|---|
|
|
879c151524 | |
|
|
7990a60d8b |
|
|
@ -17,7 +17,7 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
from numpy import sign
|
from numpy import sign, interp
|
||||||
from copy import deepcopy
|
from copy import deepcopy
|
||||||
|
|
||||||
from tools import logger_color_red, logger_color_reset, logger_exception
|
from tools import logger_color_red, logger_color_reset, logger_exception
|
||||||
|
|
@ -273,7 +273,7 @@ class InternalMeshing(AMeshingTool):
|
||||||
sect2.point(start2+len2).name = tag2
|
sect2.point(start2+len2).name = tag2
|
||||||
sect2.modified()
|
sect2.modified()
|
||||||
|
|
||||||
def update_rk(self, reach,
|
def update_rk(self, reach, begin_rk, end_rk,
|
||||||
step: float = 50,
|
step: float = 50,
|
||||||
limites=[-1, -1],
|
limites=[-1, -1],
|
||||||
origin=0,
|
origin=0,
|
||||||
|
|
@ -297,15 +297,25 @@ class InternalMeshing(AMeshingTool):
|
||||||
# 1: up -> downstream
|
# 1: up -> downstream
|
||||||
# 2: down -> upstream
|
# 2: down -> upstream
|
||||||
# else: keep current orientation
|
# else: keep current orientation
|
||||||
|
old_orientation = sign(reach.profiles[-1].rk - reach.profiles[0].rk)
|
||||||
if orientation == 1:
|
if orientation == 1:
|
||||||
sgn = 1.0
|
sgn = 1.0
|
||||||
elif orientation == 2:
|
elif orientation == 2:
|
||||||
sgn = -1.0
|
sgn = -1.0
|
||||||
else:
|
else:
|
||||||
sgn = sign(reach.profiles[-1].rk - reach.profiles[0].rk)
|
sgn = old_orientation
|
||||||
|
|
||||||
rk = [0.0]*nprof
|
new_rk = [0.0]*nprof
|
||||||
rk[origin] = origin_value
|
new_rk[origin] = origin_value
|
||||||
|
|
||||||
|
frictions = reach._parent.frictions
|
||||||
|
|
||||||
|
old_begin_rk = list(map(lambda x: x * old_orientation,
|
||||||
|
begin_rk))
|
||||||
|
old_end_rk = list(map(lambda x: x * old_orientation,
|
||||||
|
end_rk))
|
||||||
|
old_rk = list(map(lambda x: x * old_orientation,
|
||||||
|
reach.get_rk()))
|
||||||
|
|
||||||
if origin < nprof - 1:
|
if origin < nprof - 1:
|
||||||
for i in range(origin+1, nprof):
|
for i in range(origin+1, nprof):
|
||||||
|
|
@ -316,7 +326,7 @@ class InternalMeshing(AMeshingTool):
|
||||||
d2 = reach.profiles[i-1].named_point(
|
d2 = reach.profiles[i-1].named_point(
|
||||||
directrices[1]
|
directrices[1]
|
||||||
).dist_2d(reach.profiles[i].named_point(directrices[1]))
|
).dist_2d(reach.profiles[i].named_point(directrices[1]))
|
||||||
rk[i] = rk[i-1] + (sgn * (d1 + d2) / 2)
|
new_rk[i] = new_rk[i-1] + (sgn * (d1 + d2) / 2)
|
||||||
if origin > 0:
|
if origin > 0:
|
||||||
for i in reversed(range(0, origin)):
|
for i in reversed(range(0, origin)):
|
||||||
# 2D
|
# 2D
|
||||||
|
|
@ -326,6 +336,11 @@ class InternalMeshing(AMeshingTool):
|
||||||
d2 = reach.profiles[i+1].named_point(
|
d2 = reach.profiles[i+1].named_point(
|
||||||
directrices[1]
|
directrices[1]
|
||||||
).dist_2d(reach.profiles[i].named_point(directrices[1]))
|
).dist_2d(reach.profiles[i].named_point(directrices[1]))
|
||||||
rk[i] = rk[i+1] - (sgn * (d1 + d2) / 2)
|
new_rk[i] = new_rk[i+1] - (sgn * (d1 + d2) / 2)
|
||||||
|
|
||||||
return rk
|
new_begin_rk = interp(old_begin_rk, old_rk, new_rk)
|
||||||
|
new_end_rk = interp(old_end_rk, old_rk, new_rk)
|
||||||
|
if abs(sgn - old_orientation) > 0.1: # orientation changed
|
||||||
|
return new_rk, new_end_rk, new_begin_rk
|
||||||
|
else:
|
||||||
|
return new_rk, new_begin_rk, new_end_rk
|
||||||
|
|
|
||||||
|
|
@ -237,22 +237,40 @@ class UpdateRKCommand(QUndoCommand):
|
||||||
self._data = data
|
self._data = data
|
||||||
self._mesher = mesher
|
self._mesher = mesher
|
||||||
self._rks = reach.get_rk()
|
self._rks = reach.get_rk()
|
||||||
|
self._frictions = [f for f in reach._parent.frictions.frictions
|
||||||
|
if f.is_full_defined()]
|
||||||
|
self._begin_rk = [f.begin_rk for f in self._frictions]
|
||||||
|
self._end_rk = [f.end_rk for f in self._frictions]
|
||||||
|
|
||||||
self._new_rks = None
|
self._new_rks = None
|
||||||
|
self._new_begin_rk = None
|
||||||
|
self._new_end_rk = None
|
||||||
|
|
||||||
def undo(self):
|
def undo(self):
|
||||||
for rk, profile in zip(self._rks, self._reach.profiles):
|
for rk, profile in zip(self._rks, self._reach.profiles):
|
||||||
profile.rk = rk
|
profile.rk = rk
|
||||||
|
|
||||||
|
for begin_rk, end_rk, friction in zip(self._begin_rk,
|
||||||
|
self._end_rk,
|
||||||
|
self._frictions):
|
||||||
|
friction.begin_rk = begin_rk
|
||||||
|
friction.end_rk = end_rk
|
||||||
|
|
||||||
def redo(self):
|
def redo(self):
|
||||||
if self._new_rks is None:
|
if self._new_rks is None:
|
||||||
self._new_rks = self._mesher.update_rk(
|
self._new_rks, self._new_begin_rk, self._new_end_rk = \
|
||||||
self._reach,
|
self._mesher.update_rk(
|
||||||
**self._data
|
self._reach, self._begin_rk, self._end_rk,
|
||||||
)
|
**self._data
|
||||||
|
)
|
||||||
|
|
||||||
for rk, profile in zip(self._new_rks, self._reach.profiles):
|
for rk, profile in zip(self._new_rks, self._reach.profiles):
|
||||||
profile.rk = rk
|
profile.rk = rk
|
||||||
|
for begin_rk, end_rk, friction in zip(self._new_begin_rk,
|
||||||
|
self._new_end_rk,
|
||||||
|
self._frictions):
|
||||||
|
friction.begin_rk = begin_rk
|
||||||
|
friction.end_rk = end_rk
|
||||||
|
|
||||||
|
|
||||||
class MeshingCommand(QUndoCommand):
|
class MeshingCommand(QUndoCommand):
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue