mirror of
https://git.mirrors.martin98.com/https://github.com/Ultimaker/Cura
synced 2025-08-15 18:25:54 +08:00
Convert identation to spaces for line_length_checker script
This commit is contained in:
parent
0ddc6e1c58
commit
e9d1e91ec2
@ -20,45 +20,45 @@ def getValue(line: str, key: str, default = None):
|
|||||||
return default
|
return default
|
||||||
|
|
||||||
def analyse(gcode, distance_to_report, print_layers = False):
|
def analyse(gcode, distance_to_report, print_layers = False):
|
||||||
lines_found = 0
|
lines_found = 0
|
||||||
previous_x = 0
|
previous_x = 0
|
||||||
previous_y = 0
|
previous_y = 0
|
||||||
dist_squared = distance_to_report * distance_to_report
|
dist_squared = distance_to_report * distance_to_report
|
||||||
current_layer = 0
|
current_layer = 0
|
||||||
for line in gcode.split("\n"):
|
for line in gcode.split("\n"):
|
||||||
if not line.startswith("G1"):
|
if not line.startswith("G1"):
|
||||||
if line.startswith(";LAYER:"):
|
if line.startswith(";LAYER:"):
|
||||||
previous_x = 0
|
previous_x = 0
|
||||||
previous_y = 0
|
previous_y = 0
|
||||||
current_layer += 1
|
current_layer += 1
|
||||||
continue
|
continue
|
||||||
current_x = getValue(line, "X")
|
current_x = getValue(line, "X")
|
||||||
current_y = getValue(line, "Y")
|
current_y = getValue(line, "Y")
|
||||||
if current_x is None or current_y is None:
|
if current_x is None or current_y is None:
|
||||||
continue
|
continue
|
||||||
diff_x = current_x - previous_x
|
diff_x = current_x - previous_x
|
||||||
diff_y = current_y - previous_y
|
diff_y = current_y - previous_y
|
||||||
if diff_x * diff_x + diff_y * diff_y < dist_squared:
|
if diff_x * diff_x + diff_y * diff_y < dist_squared:
|
||||||
lines_found += 1
|
lines_found += 1
|
||||||
if print_layers:
|
if print_layers:
|
||||||
print("[!] ", distance_to_report, " layer ", current_layer, " ", previous_x, previous_y)
|
print("[!] ", distance_to_report, " layer ", current_layer, " ", previous_x, previous_y)
|
||||||
previous_y = current_y
|
previous_y = current_y
|
||||||
previous_x = current_x
|
previous_x = current_x
|
||||||
return lines_found
|
return lines_found
|
||||||
|
|
||||||
def loadAndPrettyPrint(file_name):
|
def loadAndPrettyPrint(file_name):
|
||||||
print(file_name.replace(".gcode",""))
|
print(file_name.replace(".gcode",""))
|
||||||
with open(file_name) as f:
|
with open(file_name) as f:
|
||||||
data = f.read()
|
data = f.read()
|
||||||
print("| Line length | Num segments |")
|
print("| Line length | Num segments |")
|
||||||
print("| ------------- | ------------- |")
|
print("| ------------- | ------------- |")
|
||||||
print("| 1 |", analyse(data, 1), "|")
|
print("| 1 |", analyse(data, 1), "|")
|
||||||
print("| 0.5 |", analyse(data, 0.5), "|")
|
print("| 0.5 |", analyse(data, 0.5), "|")
|
||||||
print("| 0.1 |", analyse(data, 0.1), "|")
|
print("| 0.1 |", analyse(data, 0.1), "|")
|
||||||
print("| 0.05 |", analyse(data, 0.05), "|")
|
print("| 0.05 |", analyse(data, 0.05), "|")
|
||||||
print("| 0.01 |", analyse(data, 0.01), "|")
|
print("| 0.01 |", analyse(data, 0.01), "|")
|
||||||
print("| 0.005 |", analyse(data, 0.005), "|")
|
print("| 0.005 |", analyse(data, 0.005), "|")
|
||||||
print("| 0.001 |", analyse(data, 0.001), "|")
|
print("| 0.001 |", analyse(data, 0.001), "|")
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
Loading…
x
Reference in New Issue
Block a user