[docs]defadd_safety_printpoints(print_organizer,z_hop=10.0):"""Generates a safety print point at the interruptions of the print paths. Parameters ---------- print_organizer: :class:`compas_slicer.print_organization.BasePrintOrganizer` An instance of the BasePrintOrganizer class. z_hop: float Vertical distance (in millimeters) of the safety point above the PrintPoint. """assertcheck_assigned_extruder_toggle(print_organizer), \
'You need to set the extruder toggles first, before you can create safety points'logger.info("Generating safety print points with height "+str(z_hop)+" mm")pp_dict=print_organizer.printpoints_dictpp_copy_dict={}# should not be altering the dict that we are iterating through > copyfori,layer_keyinenumerate(pp_dict):pp_copy_dict[layer_key]={}forj,path_keyinenumerate(pp_dict[layer_key]):pp_copy_dict[layer_key][path_key]=[]fork,printpointinenumerate(pp_dict[layer_key][path_key]):# add regular printing pointspp_copy_dict[layer_key][path_key].append(printpoint)# add safety printpoints if there is an interruptionifprintpoint.extruder_toggleisFalse:# safety ppt after current printpointpp_copy_dict[layer_key][path_key].append(create_safety_printpoint(printpoint,z_hop,False))# safety ppt before next printpoint (if there exists one)next_ppt=find_next_printpoint(pp_dict,i,j,k)ifnext_ppt:ifnext_ppt.extruder_toggleisTrue:# if it is a printing pptpp_copy_dict[layer_key][path_key].append(create_safety_printpoint(next_ppt,z_hop,False))# finally, insert a safety print point at the beginning of the entire printtry:safety_printpoint=create_safety_printpoint(pp_dict['layer_0']['path_0'][0],z_hop,False)pp_copy_dict['layer_0']['path_0'].insert(0,safety_printpoint)exceptKeyErrorase:logger.exception(e)# the safety printpoint has already been added at the end since the last printpoint extruder_toggle_type is Falseprint_organizer.printpoints_dict=pp_copy_dict