11"""State generator module."""
22
3+ import math
34import pathlib
45import re
56from typing import List , Match
8182default_virtual_machine = {
8283 "absolute_position" : True ,
8384 "absolute_extrusion" : True ,
85+ "volumetric_extrusion" : False ,
8486 "units" : "SI (mm)" ,
8587 "initial_position" : None ,
8688 # general properties
@@ -207,6 +209,24 @@ def dict_list_traveler(line_dict_list: List[dict], initial_machine_setup: dict)
207209 state_list: (list[state]) all states in a list
208210
209211 """
212+
213+ def apply_extrusion (line_dict : dict , virtual_machine : dict , command : str ) -> dict :
214+ e_value = line_dict [command ]["E" ]
215+
216+ # volumetric to length conversion
217+ # (1) V = (d/2)^2 * pi * E
218+ # (2) E = V / ((d/2)^2 * pi)
219+ if virtual_machine .get ("volumetric_extrusion" , False ):
220+ # volumetric extrusion
221+ e_value = e_value / (math .pi * (virtual_machine ["filament_diam" ] / 2 ) ** 2 )
222+
223+ if virtual_machine ["absolute_extrusion" ]:
224+ virtual_machine ["E" ] = e_value
225+ else :
226+ virtual_machine ["E" ] = virtual_machine ["E" ] + e_value
227+
228+ return virtual_machine
229+
210230 state_list : List [state ] = list ()
211231
212232 virtual_machine = {
@@ -225,17 +245,15 @@ def dict_list_traveler(line_dict_list: List[dict], initial_machine_setup: dict)
225245 layer_counter = 0
226246
227247 # overwrite default values from initial machine setup
228- """TODO: depending on the setting the user should be informed that a default value is used.
229- I prepared a warning below.
230- Are all these settings necessary?"""
231248 for key in default_virtual_machine :
232249 if initial_machine_setup is not None and key in initial_machine_setup :
233250 virtual_machine [key ] = initial_machine_setup [key ]
234251 else :
235- """print (
252+ custom_print (
236253 f"The parameter '{ key } ' was not specified in your machine presets. "
237- f"Using the the default value of '{default_virtual_machine[key]}' to continue."
238- )"""
254+ f"Using the the default value of '{ default_virtual_machine [key ]} ' to continue." ,
255+ lvl = 3 ,
256+ )
239257 virtual_machine [key ] = default_virtual_machine [key ]
240258
241259 # initial state creation
@@ -298,10 +316,9 @@ def dict_list_traveler(line_dict_list: List[dict], initial_machine_setup: dict)
298316
299317 # look for extrusion commands and apply abs/rel
300318 if "E" in line_dict [command ]:
301- if virtual_machine ["absolute_extrusion" ] is True :
302- virtual_machine ["E" ] = line_dict [command ]["E" ]
303- if virtual_machine ["absolute_extrusion" ] is False : # redundant
304- virtual_machine ["E" ] = virtual_machine ["E" ] + line_dict [command ]["E" ]
319+ virtual_machine = apply_extrusion (line_dict , virtual_machine , command )
320+
321+ # feed rates in unit/min to unit/sec
305322 if "F" in line_dict [command ]:
306323 virtual_machine ["p_vel" ] = line_dict [command ]["F" ] / 60
307324
0 commit comments