Skip to content

Commit 0a0b7d4

Browse files
committed
update_ini: copy values from TRAJ to DISPLAY
1 parent f0a0fa6 commit 0a0b7d4

File tree

1 file changed

+31
-2
lines changed

1 file changed

+31
-2
lines changed

src/emc/ini/update_ini.py

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,17 @@ def ini_preamble():
431431
#That's the INI file done:
432432
newini.close()
433433

434+
def insert_after(key, new_line, section):
435+
match = re.search(key, section)
436+
if match:
437+
# Find the end of the line that contains the match
438+
line_end = section.find("\n", match.end())
439+
if line_end == -1: line_end = len(section) # match is on the last line
440+
else:
441+
line_end = len(section) # place it at the end
442+
new_line += "\n"
443+
return section[:line_end + 1] + new_line + section[line_end + 1:]
444+
434445
if version < "1.2":
435446
inistring, newini, all_sections = ini_preamble()
436447

@@ -452,6 +463,22 @@ def ini_preamble():
452463
section = re.sub("MAX_SPINDLE_SPEED", "MAX_SPINDLE_0_SPEED", section)
453464
if re.search("MIN_VELOCITY", section):
454465
section = re.sub("MIN_VELOCITY", "MIN_LINEAR_VELOCITY", section)
466+
467+
468+
# Copy values from TRAJ
469+
if not re.search("DEFAULT_LINEAR_VELOCITY", section):
470+
val = ini.find("TRAJ", "DEFAULT_LINEAR_VELOCITY")
471+
if val:
472+
section = insert_after("MAX_LINEAR_VELOCITY", f"DEFAULT_LINEAR_VELOCITY = {val}\n" , section)
473+
if not re.search("MIN_LINEAR_VELOCITY", section):
474+
val = ini.find("TRAJ", "MIN_LINEAR_VELOCITY")
475+
if val:
476+
section = insert_after("MAX_LINEAR_VELOCITY", f"MIN_LINEAR_VELOCITY = {val}\n" , section)
477+
if not re.search("MAX_LINEAR_VELOCITY", section):
478+
val = ini.find("TRAJ", "MAX_LINEAR_VELOCITY")
479+
if val:
480+
section = insert_after("MIN_LINEAR_VELOCITY", f"MAX_LINEAR_VELOCITY = {val}\n" , section)
481+
455482
newini.write(section)
456483

457484
# TODO update-ini 1.1 --> 1.2:
@@ -465,10 +492,12 @@ def ini_preamble():
465492
#
466493
# move [TRAJ]DEFAULT_LINEAR_VELOCITY -> [DISPLAY]DEFAULT_LINEAR_VELOCITY
467494
# move [TRAJ]MIN_LINEAR_VELOCITY -> [DISPLAY]MIN_LINEAR_VELOCITY
468-
# rename [TRAJ, DISPLAY]MIN_VELOCITY --> MIN_LINEAR_VELOCITY
495+
# ~rename [TRAJ, DISPLAY]MIN_VELOCITY --> MIN_LINEAR_VELOCITY~
469496
# copy [TRAJ]MAX_LINEAR_VELOCITY -> [DISPLAY]MAX_LINEAR_VELOCITY
470497

471-
# Problem with commented stuff!
498+
# Known bugs:
499+
# - if there is a commented DISPLAY sections before the DISPLAY section, the comments are used
500+
# - DISPLAY section must not be at the end --> empty section
472501

473502
#These sections don't need any work.
474503
copysection("FILTER")

0 commit comments

Comments
 (0)