123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837 |
- from ..Script import Script
- from UM.Application import Application
- import re
- class AddCoolingProfile(Script):
- def getSettingDataString(self):
- return """{
- "name": "Advanced Cooling Fan Control",
- "key": "AddCoolingProfile",
- "metadata": {},
- "version": 2,
- "settings":
- {
- "fan_layer_or_feature":
- {
- "label": "Cooling Control by:",
- "description": "A fan percentage of ''0'' turns the fan off. Minimum Fan is 12% (when on). All layer entries are the Cura Preview number. ''By Layer'': Enter as ''Layer#/Fan%'' (foreslash is the delimiter). Your final layer speed will continue to the end of the Gcode. ''By Feature'': If you enable an 'End Layer' then the ''Final %'' is available and is the speed that will finish the file. 'By Feature' is better for large slow prints than it is for short fast prints.",
- "type": "enum",
- "options": {
- "by_layer": "Layer Numbers",
- "by_feature": "Feature Types"},
- "default_value": "by_layer"
- },
- "delete_existing_m106":
- {
- "label": "Remove M106 lines prior to inserting new.",
- "description": "If you have 2 or more instances of 'Advanced Cooling Fan Control' running (to cool a portion of a print differently), then you must uncheck this box or the followup instances will remove all the lines inserted by the first instance. Pay attention to the Start and Stop layers. Regardless of this setting: The script always removes M106 lines starting with the lowest layer number (when 'By Layer') or the starting layer number (when 'By Feature'). If you want to keep the M106 lines that Cura inserted up to the point where this post-processor will start making insertions, then un-check the box.",
- "type": "bool",
- "enabled": true,
- "value": true,
- "default_value": true
- },
- "feature_fan_start_layer":
- {
- "label": "Starting Layer",
- "description": "Layer to start the insertion at. Use the Cura preview numbers. Changes will begin at the start of that layer.",
- "type": "int",
- "default_value": 5,
- "minimum_value": 1,
- "unit": "Lay# ",
- "enabled": "fan_layer_or_feature == 'by_feature'"
- },
- "feature_fan_end_layer":
- {
- "label": "Ending Layer",
- "description": "Layer to complete the insertion at. Enter '-1' for the entire file or enter a layer number. Insertions will stop at the END of this layer. If you set an End Layer then you should set the Final % that will finish the file",
- "type": "int",
- "default_value": -1,
- "minimum_value": -1,
- "unit": "Lay# ",
- "enabled": "fan_layer_or_feature == 'by_feature'"
- },
- "layer_fan_1":
- {
- "label": "Layer/Percent #1",
- "description": "Enter as: 'LAYER / Percent' Ex: 55/100 with the layer first, then a '/' to delimit, and then the fan percentage. There are up to 8 changes. If you need more then add a second instance of this script and remember to turn off 'Remove M106 lines' in the second instance. The layer numbers in the second instance must start with a layer number higher than the last layer number in a previous script. You can't end the first script with a setting for layer 80 and then start the second script with a setting for layer 40 because 'Remove M106 lines' always starts with the lowest layer number when 'By Layer' is selected.",
- "type": "str",
- "default_value": "5/30",
- "unit": "L#/% ",
- "enabled": "fan_layer_or_feature == 'by_layer'"
- },
- "layer_fan_2":
- {
- "label": "Layer/Percent #2",
- "description": "Enter as: 'LAYER / Percent' Ex: 55/100 with the layer first, then a '/' to delimit, and then the fan percentage.",
- "type": "str",
- "default_value": "",
- "unit": "L#/% ",
- "enabled": "fan_layer_or_feature == 'by_layer'"
- },
- "layer_fan_3":
- {
- "label": "Layer/Percent #3",
- "description": "Enter as: 'LAYER / Percent' Ex: 55/100 with the layer first, then a '/' to delimit, and then the fan percentage.",
- "type": "str",
- "default_value": "",
- "unit": "L#/% ",
- "enabled": "fan_layer_or_feature == 'by_layer'"
- },
- "layer_fan_4":
- {
- "label": "Layer/Percent #4",
- "description": "Enter as: 'LAYER / Percent' Ex: 55/100 with the layer first, then a '/' to delimit, and then the fan percentage.",
- "type": "str",
- "default_value": "",
- "unit": "L#/% ",
- "enabled": "fan_layer_or_feature == 'by_layer'"
- },
- "layer_fan_5":
- {
- "label": "Layer/Percent #5",
- "description": "Enter as: 'LAYER / Percent' Ex: 55/100 with the layer first, then a '/' to delimit, and then the fan percentage.",
- "type": "str",
- "default_value": "",
- "unit": "L#/% ",
- "enabled": "fan_layer_or_feature == 'by_layer'"
- },
- "layer_fan_6":
- {
- "label": "Layer/Percent #6",
- "description": "Enter as: 'LAYER / Percent' Ex: 55/100 with the layer first, then a '/' to delimit, and then the fan percentage.",
- "type": "str",
- "default_value": "",
- "unit": "L#/% ",
- "enabled": "fan_layer_or_feature == 'by_layer'"
- },
- "layer_fan_7":
- {
- "label": "Layer/Percent #7",
- "description": "Enter as: 'LAYER / Percent' Ex: 55/100 with the layer first, then a '/' to delimit, and then the fan percentage.",
- "type": "str",
- "default_value": "",
- "unit": "L#/% ",
- "enabled": "fan_layer_or_feature == 'by_layer'"
- },
- "layer_fan_8":
- {
- "label": "Layer/Percent #8",
- "description": "Enter as: 'LAYER / Percent' Ex: 55/100 with the layer first, then a '/' to delimit, and then the fan percentage.",
- "type": "str",
- "default_value": "",
- "unit": "L#/% ",
- "enabled": "fan_layer_or_feature == 'by_layer'"
- },
- "feature_fan_skirt":
- {
- "label": "Skirt/Brim/Ooze Shield %",
- "description": "Enter the fan percentage for skirt/brim. If you are starting at a layer above 1 then this setting only affects Ooze Shields and from the Start Layer up.",
- "type": "int",
- "default_value": 0,
- "minimum_value": 0,
- "maximum_value": 100,
- "unit": "% ",
- "enabled": "fan_layer_or_feature == 'by_feature'"
- },
- "feature_fan_wall_inner":
- {
- "label": "Inner Walls %",
- "description": "Enter the fan percentage for the Wall-Inner.",
- "type": "int",
- "default_value": 35,
- "minimum_value": 0,
- "maximum_value": 100,
- "unit": "% ",
- "enabled": "fan_layer_or_feature == 'by_feature'"
- },
- "feature_fan_wall_outer":
- {
- "label": "Outer Walls %",
- "description": "Enter the fan percentage for the Wall-Outer.",
- "type": "int",
- "default_value": 75,
- "minimum_value": 0,
- "maximum_value": 100,
- "unit": "% ",
- "enabled": "fan_layer_or_feature == 'by_feature'"
- },
- "feature_fan_fill":
- {
- "label": "Infill %",
- "description": "Enter the fan percentage for the Infill.",
- "type": "int",
- "default_value": 35,
- "minimum_value": 0,
- "maximum_value": 100,
- "unit": "% ",
- "enabled": "fan_layer_or_feature == 'by_feature'"
- },
- "feature_fan_skin":
- {
- "label": "Top/Bottom (Skin) %",
- "description": "Enter the fan percentage for the Skins.",
- "type": "int",
- "default_value": 100,
- "minimum_value": 0,
- "maximum_value": 100,
- "unit": "% ",
- "enabled": "fan_layer_or_feature == 'by_feature'"
- },
- "feature_fan_support":
- {
- "label": "Support %",
- "description": "Enter the fan percentage for the Supports.",
- "type": "int",
- "default_value": 35,
- "minimum_value": 0,
- "maximum_value": 100,
- "unit": "% ",
- "enabled": "fan_layer_or_feature == 'by_feature'"
- },
- "feature_fan_support_interface":
- {
- "label": "Support Interface %",
- "description": "Enter the fan percentage for the Support Interface.",
- "type": "int",
- "default_value": 100,
- "minimum_value": 0,
- "maximum_value": 100,
- "unit": "% ",
- "enabled": "fan_layer_or_feature == 'by_feature'"
- },
- "feature_fan_prime_tower":
- {
- "label": "Prime Tower %",
- "description": "Enter the fan percentage for the Prime Tower (whether it's used or not).",
- "type": "int",
- "default_value": 35,
- "minimum_value": 0,
- "maximum_value": 100,
- "unit": "% ",
- "enabled": "fan_layer_or_feature == 'by_feature'"
- },
- "feature_fan_bridge":
- {
- "label": "Bridge %",
- "description": "Enter the fan percentage for any Bridging (whether it's used on not).",
- "type": "int",
- "default_value": 100,
- "minimum_value": 0,
- "maximum_value": 100,
- "unit": "% ",
- "enabled": "fan_layer_or_feature == 'by_feature'"
- },
- "feature_fan_combing":
- {
- "label": "Fan 'OFF' during Combing:",
- "description": "When checked will set the fan to 0% for combing moves over 5 lines long in the gcode. When un-checked the fan speed during combing is whatever the previous speed is set to.",
- "type": "bool",
- "enabled": "fan_layer_or_feature == 'by_feature'",
- "default_value": true
- },
- "feature_fan_feature_final":
- {
- "label": "Final %",
- "description": "If you choose an 'End Layer' then this is the fan speed that will carry through to the end of the gcode file. It will go into effect at the 'END' of your End layer.",
- "type": "int",
- "default_value": 35,
- "minimum_value": 0,
- "maximum_value": 100,
- "unit": "% ",
- "enabled": "(int(feature_fan_end_layer) != -1) and (fan_layer_or_feature == 'by_feature')"
- },
- "fan_enable_raft":
- {
- "label": "Enable Raft Cooling",
- "description": "Enable the fan for the raft layers. When enabled the Raft Fan Speed will continue until another Layer or Feature setting over-rides it.",
- "type": "bool",
- "default_value": false,
- "enabled": true
- },
- "fan_raft_percent":
- {
- "label": "Raft Fan %:",
- "description": "Enter the percentage for the Raft.",
- "type": "int",
- "default_value": 35,
- "minimum_value": 0,
- "maximum_value": 100,
- "unit": "% ",
- "enabled": "fan_enable_raft"
- }
- }
- }"""
- def initialize(self) -> None:
- super().initialize()
- scripts = Application.getInstance().getGlobalContainerStack().getMetaDataEntry("post_processing_scripts")
- if scripts != None:
- script_count = scripts.count("AddCoolingProfile")
- if script_count > 0:
-
- self._instance.setProperty("delete_existing_m106", "value", False)
- def execute(self, data):
-
- mycura = Application.getInstance().getGlobalContainerStack()
- t0_fan = " P0"; t1_fan = " P0"; t2_fan = " P0"; t3_fan = " P0"; is_multi_extr_print = True
-
- extruder = mycura.extruderList
-
- fan_mode = True
-
- try:
- fan_mode = not bool(extruder[0].getProperty("machine_scale_fan_speed_zero_to_one", "value"))
- except:
- pass
- bed_adhesion = (extruder[0].getProperty("adhesion_type", "value"))
- extruder_count = mycura.getProperty("machine_extruder_count", "value")
- print_sequence = str(mycura.getProperty("print_sequence", "value"))
-
- if extruder_count == 1:
- is_multi_fan = False
- is_multi_extr_print = False
- if int((extruder[0].getProperty("machine_extruder_cooling_fan_number", "value"))) > 0:
- t0_fan = " P" + str((extruder[0].getProperty("machine_extruder_cooling_fan_number", "value")))
- else:
-
- t0_fan = ""
-
- elif extruder_count > 1:
- is_multi_fan = True
- t0_fan = " P" + str((extruder[0].getProperty("machine_extruder_cooling_fan_number", "value")))
- if is_multi_fan:
- if extruder_count > 1: t1_fan = " P" + str((extruder[1].getProperty("machine_extruder_cooling_fan_number", "value")))
- if extruder_count > 2: t2_fan = " P" + str((extruder[2].getProperty("machine_extruder_cooling_fan_number", "value")))
- if extruder_count > 3: t3_fan = " P" + str((extruder[3].getProperty("machine_extruder_cooling_fan_number", "value")))
-
- fan_list = ["z"] * 16
- for num in range(0,15,2):
- fan_list[num] = len(data)
- fan_list[num + 1] = "M106 S0"
-
- by_layer_or_feature = self.getSettingValueByKey("fan_layer_or_feature")
- if by_layer_or_feature == "by_layer":
-
- feature_fan_combing = False
- fan_list[0] = self.getSettingValueByKey("layer_fan_1")
- fan_list[2] = self.getSettingValueByKey("layer_fan_2")
- fan_list[4] = self.getSettingValueByKey("layer_fan_3")
- fan_list[6] = self.getSettingValueByKey("layer_fan_4")
- fan_list[8] = self.getSettingValueByKey("layer_fan_5")
- fan_list[10] = self.getSettingValueByKey("layer_fan_6")
- fan_list[12] = self.getSettingValueByKey("layer_fan_7")
- fan_list[14] = self.getSettingValueByKey("layer_fan_8")
-
- for num in range(0,15,2):
- if "/" in fan_list[num]:
- fan_list[num + 1] = self._layer_checker(fan_list[num], "p", fan_mode)
- fan_list[num] = self._layer_checker(fan_list[num], "l", fan_mode)
-
- elif by_layer_or_feature == "by_feature":
- the_start_layer = self.getSettingValueByKey("feature_fan_start_layer") - 1
- the_end_layer = self.getSettingValueByKey("feature_fan_end_layer")
- try:
- if int(the_end_layer) != -1:
-
- if the_end_layer < the_start_layer:
- the_end_layer = the_start_layer
- except:
- the_end_layer = -1
-
- feature_name_list = []
- feature_speed_list = []
- feature_speed_list.append(self._feature_checker(self.getSettingValueByKey("feature_fan_skirt"), fan_mode)); feature_name_list.append(";TYPE:SKIRT")
- feature_speed_list.append(self._feature_checker(self.getSettingValueByKey("feature_fan_wall_inner"), fan_mode)); feature_name_list.append(";TYPE:WALL-INNER")
- feature_speed_list.append(self._feature_checker(self.getSettingValueByKey("feature_fan_wall_outer"), fan_mode)); feature_name_list.append(";TYPE:WALL-OUTER")
- feature_speed_list.append(self._feature_checker(self.getSettingValueByKey("feature_fan_fill"), fan_mode)); feature_name_list.append(";TYPE:FILL")
- feature_speed_list.append(self._feature_checker(self.getSettingValueByKey("feature_fan_skin"), fan_mode)); feature_name_list.append(";TYPE:SKIN")
- feature_speed_list.append(self._feature_checker(self.getSettingValueByKey("feature_fan_support"), fan_mode)); feature_name_list.append(";TYPE:SUPPORT")
- feature_speed_list.append(self._feature_checker(self.getSettingValueByKey("feature_fan_support_interface"), fan_mode)); feature_name_list.append(";TYPE:SUPPORT-INTERFACE")
- feature_speed_list.append(self._feature_checker(self.getSettingValueByKey("feature_fan_prime_tower"), fan_mode)); feature_name_list.append(";TYPE:PRIME-TOWER")
- feature_speed_list.append(self._feature_checker(self.getSettingValueByKey("feature_fan_bridge"), fan_mode)); feature_name_list.append(";BRIDGE")
- feature_speed_list.append(self._feature_checker(self.getSettingValueByKey("feature_fan_feature_final"), fan_mode)); feature_name_list.append("FINAL_FAN")
- feature_fan_combing = self.getSettingValueByKey("feature_fan_combing")
- if the_end_layer > -1 and by_layer_or_feature == "by_feature":
-
- the_end_is_enabled = True
- else:
-
- the_end_is_enabled = False
- if the_end_layer == -1 or the_end_is_enabled == False:
- the_end_layer = len(data) + 2
-
- raft_start_index = 0
- number_of_raft_layers = 0
- layer_0_index = 0
-
- for l_num in range(1,10,1):
- layer = data[l_num]
- if ";LAYER:-" in layer:
- number_of_raft_layers += 1
- if raft_start_index == 0:
- raft_start_index = l_num
- if ";LAYER:0" in layer:
- layer_0_index = l_num
- break
-
- if is_multi_fan:
- T0_used = False
- T1_used = False
- T2_used = False
- T3_used = False
-
- for num in range(1,len(data)-1,1):
- lines = data[num]
- if "T0" in lines:
- T0_used = True
- if "T1" in lines:
- T1_used = True
- if "T2" in lines:
- T2_used = True
- if "T3" in lines:
- T3_used = True
- is_multi_extr_print = True if sum([T0_used, T1_used, T2_used, T3_used]) > 1 else False
-
- init_fan = t0_fan
- if not is_multi_extr_print:
- startup = data[1]
- lines = startup.split("\n")
- for line in lines:
- if line == "T1":
- t0_fan = t1_fan
- elif line == "T2":
- t0_fan = t2_fan
- elif line == "T3":
- t0_fan = t3_fan
- elif is_multi_extr_print:
-
- startup = data[1]
- lines = startup.split("\n")
- for line in lines:
- if line == "T0":
- init_fan = t0_fan
- elif line == "T1":
- init_fan = t1_fan
- elif line == "T2":
- init_fan = t2_fan
- elif line == "T3":
- init_fan = t3_fan
- else:
- init_fan = ""
-
- raft_enabled = self.getSettingValueByKey("fan_enable_raft")
- if raft_enabled and bed_adhesion == "raft":
- fan_sp_raft = self._feature_checker(self.getSettingValueByKey("fan_raft_percent"), fan_mode)
- else:
- fan_sp_raft = "M106 S0"
-
-
- delete_existing_m106 = self.getSettingValueByKey("delete_existing_m106")
- if delete_existing_m106:
-
- start_from = int(raft_start_index)
- else:
- if by_layer_or_feature == "by_layer":
- altered_start_layer = str(len(data))
-
- for num in range(0,15,2):
- try:
- if int(fan_list[num]) < int(altered_start_layer):
- altered_start_layer = int(fan_list[num])
- except:
- pass
- elif by_layer_or_feature == "by_feature":
- altered_start_layer = int(the_start_layer) - 1
- start_from = int(layer_0_index) + int(altered_start_layer)
-
- for l_index in range(int(start_from), len(data) - 1, 1):
- data[l_index] = re.sub(re.compile("M106(.*)\n"), "", data[l_index])
- data[l_index] = re.sub(re.compile("M107(.*)\n"), "", data[l_index])
-
- if raft_enabled and bed_adhesion == "raft":
- if print_sequence == "one_at_a_time":
- for r_index in range(2,len(data)-2,1):
- lines = data[r_index].split("\n")
- if not raft_enabled or bed_adhesion != "raft":
- if ";LAYER:0" in data[r_index] or ";LAYER:-" in data[r_index]:
- lines.insert(1, "M106 S0" + str(t0_fan))
- if raft_enabled and bed_adhesion == "raft":
- if ";LAYER:-" in data[r_index]:
-
- lines.insert(1, fan_sp_raft + str(t0_fan))
-
- if ";LAYER:0" in data[r_index]:
- lines.insert(1,"M106 S0" + str(t0_fan))
- data[r_index] = "\n".join(lines)
- elif print_sequence == "all_at_once":
- layer = data[raft_start_index]
- lines = layer.split("\n")
- if ";LAYER:-" in layer:
-
- lines.insert(1, fan_sp_raft + str(init_fan))
- layer = "\n".join(lines)
- data[raft_start_index] = layer
- layer = data[layer_0_index]
- lines = layer.split("\n")
-
- lines.insert(1, "M106 S0" + str(init_fan))
- data[layer_0_index] = "\n".join(lines)
- else:
- for r_index in range(2,len(data)-2,1):
- lines = data[r_index].split("\n")
- if ";LAYER:0" in data[r_index] or ";LAYER:-" in data[r_index]:
- if not "0" in fan_list:
- lines.insert(1, "M106 S0" + str(t0_fan))
- data[r_index] = "\n".join(lines)
-
- temp_startup = data[1].split("\n")
- temp_startup.insert(len(temp_startup)-2,"M106 S0" + str(t0_fan))
-
- if is_multi_fan:
- if extruder_count > 1 and t1_fan != t0_fan: temp_startup.insert(len(temp_startup)-2,"M106 S0" + str(t1_fan))
- if extruder_count > 2 and t2_fan != t1_fan and t2_fan != t0_fan: temp_startup.insert(len(temp_startup)-2,"M106 S0" + str(t2_fan))
- if extruder_count > 3 and t3_fan != t2_fan and t3_fan != t1_fan and t3_fan != t0_fan: temp_startup.insert(len(temp_startup)-2,"M106 S0" + str(t3_fan))
- data[1] = "\n".join(temp_startup)
-
-
- if feature_fan_combing:
- for layer_num in range(2,len(data)):
- layer = data[layer_num]
- data[layer_num] = re.sub(";MESH:NOMESH", ";MESH:NONMESH", layer)
- data = self._add_travel_comment(data, layer_0_index)
-
- if by_layer_or_feature == "by_layer" and not is_multi_fan:
- return self._single_fan_by_layer(data, layer_0_index, fan_list, t0_fan)
-
- if by_layer_or_feature == "by_layer" and is_multi_fan:
- return self._multi_fan_by_layer(data, layer_0_index, fan_list, t0_fan, t1_fan, t2_fan, t3_fan)
-
- if by_layer_or_feature == "by_feature" and (not is_multi_fan or not is_multi_extr_print):
- return self._single_fan_by_feature(data, layer_0_index, the_start_layer, the_end_layer, the_end_is_enabled, fan_list, t0_fan, feature_speed_list, feature_name_list, feature_fan_combing)
-
- if by_layer_or_feature == "by_feature" and is_multi_fan:
- return self._multi_fan_by_feature(data, layer_0_index, the_start_layer, the_end_layer, the_end_is_enabled, fan_list, t0_fan, t1_fan, t2_fan, t3_fan, feature_speed_list, feature_name_list, feature_fan_combing)
-
- def _single_fan_by_layer(self, data: str, layer_0_index: int, fan_list: str, t0_fan: str)->str:
- layer_number = "0"
- single_fan_data = data
- for l_index in range(layer_0_index,len(single_fan_data)-1,1):
- layer = single_fan_data[l_index]
- fan_lines = layer.split("\n")
- for fan_line in fan_lines:
- if ";LAYER:" in fan_line:
- layer_number = str(fan_line.split(":")[1])
-
- for num in range(0,15,2):
- if layer_number == str(fan_list[num]):
- layer = layer.replace(fan_lines[0],fan_lines[0] + "\n" + fan_list[num + 1] + str(t0_fan))
- single_fan_data[l_index] = layer
- return single_fan_data
-
- def _multi_fan_by_layer(self, data: str, layer_0_index: int, fan_list: str, t0_fan: str, t1_fan: str, t2_fan: str, t3_fan: str)->str:
- multi_fan_data = data
- layer_number = "0"
- current_fan_speed = "0"
- prev_fan = str(t0_fan)
- this_fan = str(t0_fan)
- start_index = str(len(multi_fan_data))
- for num in range(0,15,2):
-
- try:
- if int(fan_list[num]) < int(start_index):
- start_index = str(fan_list[num])
- except:
- pass
-
- start_index = int(start_index) + int(layer_0_index)
-
- for num in range(1,int(start_index),1):
- layer = multi_fan_data[num]
- lines = layer.split("\n")
- for line in lines:
- if line == "T0":
- prev_fan = this_fan
- this_fan = t0_fan
- elif line == "T1":
- prev_fan = this_fan
- this_fan = t1_fan
- elif line == "T2":
- prev_fan = this_fan
- this_fan = t2_fan
- elif line == "T3":
- prev_fan = this_fan
- this_fan = t3_fan
- for l_index in range(int(start_index),len(multi_fan_data)-1,1):
- modified_data = ""
- layer = multi_fan_data[l_index]
- fan_lines = layer.split("\n")
- for fan_line in fan_lines:
-
- if fan_line.startswith("T"):
- if fan_line == "T0": this_fan = str(t0_fan)
- if fan_line == "T1": this_fan = str(t1_fan)
- if fan_line == "T2": this_fan = str(t2_fan)
- if fan_line == "T3": this_fan = str(t3_fan)
- modified_data += "M106 S0" + prev_fan + "\n"
- modified_data += fan_line + "\n"
- modified_data += "M106 S" + str(current_fan_speed) + this_fan + "\n"
- prev_fan = this_fan
- elif ";LAYER:" in fan_line:
- modified_data += fan_line + "\n"
- layer_number = str(fan_line.split(":")[1])
- for num in range(0,15,2):
- if layer_number == str(fan_list[num]):
- modified_data += fan_list[num + 1] + this_fan + "\n"
- current_fan_speed = str(fan_list[num + 1].split("S")[1])
- current_fan_speed = str(current_fan_speed.split(" ")[0])
- else:
- modified_data += fan_line + "\n"
- if modified_data.endswith("\n"): modified_data = modified_data[0:-1]
- multi_fan_data[l_index] = modified_data
- return multi_fan_data
-
- def _single_fan_by_feature(self, data: str, layer_0_index: int, the_start_layer: str, the_end_layer: str, the_end_is_enabled: str, fan_list: str, t0_fan: str, feature_speed_list: str, feature_name_list: str, feature_fan_combing: bool)->str:
- single_fan_data = data
- layer_number = "0"
- index = 1
-
- for l_index in range(layer_0_index,len(single_fan_data)-1,1):
- modified_data = ""
- layer = single_fan_data[l_index]
- lines = layer.split("\n")
- for line in lines:
- if ";LAYER:" in line:
- layer_number = str(line.split(":")[1])
- if int(layer_number) >= int(the_start_layer) and int(layer_number) < int(the_end_layer)-1:
- temp = line.split(" ")[0]
- try:
- name_index = feature_name_list.index(temp)
- except:
- name_index = -1
- if name_index != -1:
- modified_data += feature_speed_list[name_index] + t0_fan + "\n"
- elif ";MESH:NONMESH" in line:
- if feature_fan_combing == True:
- modified_data += "M106 S0" + t0_fan + "\n"
- modified_data += line + "\n"
-
- if line == ";LAYER:" + str(the_end_layer) and the_end_is_enabled == True:
- modified_data += feature_speed_list[len(feature_speed_list) - 1] + t0_fan + "\n"
- if modified_data.endswith("\n"): modified_data = modified_data[0: - 1]
- single_fan_data[l_index] = modified_data
- return single_fan_data
-
- def _multi_fan_by_feature(self, data: str, layer_0_index: int, the_start_layer: str, the_end_layer: str, the_end_is_enabled: str, fan_list: str, t0_fan: str, t1_fan: str, t2_fan: str, t3_fan: str, feature_speed_list: str, feature_name_list: str, feature_fan_combing: bool)->str:
- multi_fan_data = data
- layer_number = "0"
- start_index = 1
- prev_fan = t0_fan
- this_fan = t0_fan
- modified_data = ""
- current_fan_speed = "0"
- for my_index in range(1, len(multi_fan_data) - 1, 1):
- layer = multi_fan_data[my_index]
- if ";LAYER:" + str(the_start_layer) + "\n" in layer:
- start_index = int(my_index) - 1
- break
-
- for num in range(1,start_index,1):
- layer = multi_fan_data[num]
- lines = layer.split("\n")
- for line in lines:
- if line == "T0":
- prev_fan = this_fan
- this_fan = t0_fan
- elif line == "T1":
- prev_fan = this_fan
- this_fan = t1_fan
- elif line == "T2":
- prev_fan = this_fan
- this_fan = t2_fan
- elif line == "T3":
- prev_fan = this_fan
- this_fan = t3_fan
-
- for l_index in range(start_index,start_index + 1,1):
- layer = multi_fan_data[l_index]
- lines = layer.split("\n")
- for line in lines:
- if line.startswith("T"):
- if line == "T0": this_fan = t0_fan
- if line == "T1": this_fan = t1_fan
- if line == "T2": this_fan = t2_fan
- if line == "T3": this_fan = t3_fan
- prev_fan = this_fan
-
- for l_index in range(start_index+1,len(multi_fan_data)-1,1):
- layer = multi_fan_data[l_index]
- lines = layer.split("\n")
- for line in lines:
- if line.startswith("T"):
- if line == "T0": this_fan = t0_fan
- if line == "T1": this_fan = t1_fan
- if line == "T2": this_fan = t2_fan
- if line == "T3": this_fan = t3_fan
-
- modified_data += "M106 S0" + prev_fan + "\n"
- modified_data += line + "\n"
-
- modified_data += "M106 S" + str(current_fan_speed) + this_fan + "\n"
- prev_fan = this_fan
- if ";LAYER:" in line:
- layer_number = str(line.split(":")[1])
- modified_data += line + "\n"
- if int(layer_number) >= int(the_start_layer):
- temp = line.split(" ")[0]
- try:
- name_index = feature_name_list.index(temp)
- except:
- name_index = -1
- if name_index != -1:
- modified_data += line + "\n" + feature_speed_list[name_index] + this_fan + "\n"
-
- current_fan_speed = str(feature_speed_list[name_index].split("S")[1])
- elif ";MESH:NONMESH" in line:
- if feature_fan_combing == True:
- modified_data += line + "\n"
- modified_data += "M106 S0" + this_fan + "\n"
- current_fan_speed = "0"
- else:
- modified_data += line + "\n"
-
-
- elif line == ";LAYER:" + str(the_end_layer):
- modified_data += feature_speed_list[len(feature_speed_list) - 1] + this_fan + "\n"
- for set_speed in range(0, len(feature_speed_list) - 2):
- feature_speed_list[set_speed] = feature_speed_list[len(feature_speed_list) - 1]
- else:
-
- if not line.startswith("T") and not line.startswith(";LAYER:"): modified_data += line + "\n"
- if modified_data.endswith("\n"): modified_data = modified_data[0: - 1]
- multi_fan_data[l_index] = modified_data
- modified_data = ""
- return multi_fan_data
-
- def _layer_checker(self, fan_string: str, ty_pe: str, fan_mode: bool) -> str:
- fan_string_l = str(fan_string.split("/")[0])
- try:
- if int(fan_string_l) <= 1: fan_string_l = "1"
- if fan_string_l == "": fan_string_l = str(len(data))
- except ValueError:
- fan_string_l = str(len(data))
- fan_string_l = str(int(fan_string_l) - 1)
- fan_string_p = str(fan_string.split("/")[1])
- if fan_string_p == "": fan_string_p = "0"
- try:
- if int(fan_string_p) < 0: fan_string_p = "0"
- if int(fan_string_p) > 100: fan_string_p = "100"
- except ValueError:
- fan_string_p = "0"
-
- if int(fan_string_p) < 12 and int(fan_string_p) != 0:
- fan_string_p = "12"
- fan_layer_line = str(fan_string_l)
- if fan_mode:
- fan_percent_line = "M106 S" + str(round(int(fan_string_p) * 2.55))
- else:
- fan_percent_line = "M106 S" + str(round(int(fan_string_p) / 100, 1))
- if ty_pe == "l":
- return str(fan_layer_line)
- elif ty_pe == "p":
- return fan_percent_line
-
- def _feature_checker(self, fan_feat_string: int, fan_mode: bool) -> str:
- if fan_feat_string < 0: fan_feat_string = 0
-
- if fan_feat_string > 0 and fan_feat_string < 12: fan_feat_string = 12
- if fan_feat_string > 100: fan_feat_string = 100
- if fan_mode:
- fan_sp_feat = "M106 S" + str(round(fan_feat_string * 2.55))
- else:
- fan_sp_feat = "M106 S" + str(round(fan_feat_string / 100, 1))
- return fan_sp_feat
-
- def _add_travel_comment(self, comment_data: str, lay_0_index: str) -> str:
- for lay_num in range(int(lay_0_index), len(comment_data)-1,1):
- layer = comment_data[lay_num]
- lines = layer.split("\n")
-
- new_data = lines
- g0_count = 0
- g0_index = -1
- feature_type = ";TYPE:SUPPORT"
- is_travel = False
- for index, line in enumerate(lines):
- insert_index = 0
- if ";TYPE:" in line:
- feature_type = line
- is_travel = False
- g0_count = 0
- if ";MESH:NONMESH" in line:
- is_travel = True
- g0_count = 0
- if line.startswith("G0 ") and not is_travel:
- g0_count += 1
- if g0_index == -1:
- g0_index = lines.index(line)
- elif not line.startswith("G0 ") and not is_travel:
-
- if g0_count > 5:
- if not is_travel:
- new_data.insert(g0_index + insert_index, ";MESH:NONMESH")
- insert_index += 1
-
- new_data.insert(g0_index + g0_count + 1, feature_type)
- insert_index += 1
- g0_count = 0
- g0_index = -1
- is_travel = False
- elif g0_count <= 5:
- g0_count = 0
- g0_index = -1
- is_travel = False
- comment_data[lay_num] = "\n".join(new_data)
- return comment_data
|