print.as 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  1. //overhangs : quick set/unset like the one in prusalicer
  2. int s_overhangs_get()
  3. {
  4. if (get_float("overhangs_width_speed") == 0) return 0;
  5. float width = get_float("overhangs_width");
  6. bool percent = is_percent("overhangs_width");
  7. if((percent && width > 50.f) || ((!percent) && width > 0.2f)) return 1;
  8. return -1;
  9. }
  10. void s_overhangs_set(bool set)
  11. {
  12. if (set) {
  13. set_percent("overhangs_width_speed", 55.f);
  14. float width = get_float("overhangs_width");
  15. bool percent = is_percent("overhangs_width");
  16. if((percent && width < 50.f) || ((!percent) && width < 0.2f))
  17. set_percent("overhangs_width", 75.f);
  18. } else {
  19. set_float("overhangs_width_speed", 0.);
  20. }
  21. }
  22. // "not thick bridge" like in prusaslicer
  23. float compute_overlap()
  24. {
  25. float height = get_float("layer_height");
  26. float width = get_computed_float("solid_infill_extrusion_width");
  27. if(height <= 0) return 1;
  28. if(width <= 0) return 1;
  29. float solid_spacing = (width - height * 0.215);
  30. float solid_flow = height * solid_spacing;
  31. float bridge_spacing = sqrt(solid_flow*1.2739);
  32. float round_val = floor((bridge_spacing / solid_spacing) * 1000. + 0.5) / 1000.;
  33. return round_val;
  34. }
  35. int s_not_thick_bridge_get()
  36. {
  37. bool is_set = false;
  38. get_custom_bool(0,"not_thick_bridge", is_set);
  39. if(is_set){
  40. //set other vars
  41. ask_for_refresh();
  42. return 1;
  43. }
  44. return 0;
  45. }
  46. void s_not_thick_bridge_reset()
  47. {
  48. set_custom_string(0,"not_thick_bridge", "");
  49. back_initial_value("bridge_type");
  50. back_initial_value("bridge_overlap");
  51. back_initial_value("bridge_overlap_min");
  52. }
  53. void s_not_thick_bridge_set(bool set)
  54. {
  55. bool var_set = false;
  56. get_custom_bool(0,"not_thick_bridge", var_set);
  57. if (var_set != set) {
  58. set_custom_bool(0,"not_thick_bridge", set);
  59. }
  60. if (set) {
  61. if (get_int("bridge_type") != 2)
  62. set_int("bridge_type", 2);
  63. float overlap = compute_overlap();
  64. set_float("bridge_overlap", overlap);
  65. set_float("bridge_overlap_min", overlap);
  66. } else if (var_set != set) {
  67. back_initial_value("bridge_type");
  68. back_initial_value("bridge_overlap");
  69. back_initial_value("bridge_overlap_min");
  70. }
  71. }
  72. // seam position
  73. // spRandom [spNearest] spAligned spRear [spCustom] spCost
  74. // ("Cost-based") ("Random") ("Aligned") ("Rear")
  75. // -> Corners Nearest Random Aligned Rear Custom
  76. // spRandom spAllRandom [spNearest] spAligned spExtrAligned spRear [spCustom] spCost
  77. // ("Cost-based") ("Scattered") ("Random") ("Aligned") ("Contiguous") ("Rear")
  78. // -> Corners Nearest Scattered Random Aligned Contiguous Rear Custom
  79. float user_angle = 0;
  80. float user_travel = 0;
  81. int s_seam_position_get(string &out get_val)
  82. {
  83. int pos = get_int("seam_position");
  84. string seam_pos;
  85. get_string("seam_position", seam_pos);
  86. if(pos < 7){
  87. if (pos == 0) return 2;// Scattered
  88. if (pos == 1) return 3;// Random
  89. return pos + 1;
  90. } else {
  91. float angle = get_float("seam_angle_cost");
  92. float travel = get_float("seam_travel_cost");
  93. if(angle >= 1. && travel <= 0.8) return 0; //corner
  94. if(angle <= 1. && travel >= 1.0) return 1; //nearest
  95. user_angle = angle;
  96. user_travel = travel;
  97. }
  98. return 7;
  99. }
  100. void s_seam_position_set(string &in set_val, int idx)
  101. {
  102. if (idx == 2 ) {
  103. set_int("seam_position", 0); // Scattered
  104. } else if (idx == 3) {
  105. set_int("seam_position", 1); // Random
  106. } else if (idx == 4) {
  107. set_int("seam_position", 3); // Aligned
  108. } else if (idx == 5) {
  109. set_int("seam_position", 4); // Contiguous
  110. } else if (idx == 6) {
  111. set_int("seam_position", 5); // Rear
  112. } else if (idx <= 1) {
  113. set_int("seam_position", 7);
  114. if (idx == 0) { //corner
  115. set_percent("seam_angle_cost", 120);
  116. set_percent("seam_travel_cost", 40);
  117. } else { // == 1 // nearest
  118. set_percent("seam_angle_cost", 80);
  119. set_percent("seam_travel_cost", 100);
  120. }
  121. } else {
  122. set_int("seam_position", 7); // custom
  123. if(user_angle > 0 || user_travel > 0){
  124. set_percent("seam_angle_cost", user_angle);
  125. set_percent("seam_travel_cost", user_travel);
  126. } else {
  127. back_initial_value("seam_angle_cost");
  128. back_initial_value("seam_travel_cost");
  129. }
  130. }
  131. }
  132. bool s_seam_position_is_enabled()
  133. {
  134. return get_int("perimeters") > 0;
  135. }
  136. // s_wall_thickness
  137. // set the perimeter_spacing & external_perimeter_spacing
  138. // as m * 2 perimeter_spacing + n * 2 * external_perimeter_spacing = o * s_wall_thickness
  139. float s_wall_thickness_get()
  140. {
  141. int nb_peri = 2;
  142. if (!get_custom_int(0,"wall_thickness_lines", nb_peri)) nb_peri = 2;
  143. float ps = get_computed_float("perimeter_extrusion_spacing");
  144. float eps = get_computed_float("external_perimeter_extrusion_spacing");
  145. //print("s_wall_thickness_get "+ps+" "+eps+" *"+nb_peri+"\n");
  146. if (nb_peri == 0) return 0; // fake 'disable'
  147. if (nb_peri < 2) nb_peri = 2; // too thin value
  148. if( eps > 100000) return 0;
  149. if( ps > 100000) return 0;
  150. return eps * 2 + (nb_peri-2) * ps;
  151. }
  152. void s_wall_thickness_set(float new_val)
  153. {
  154. float diameter = get_float("nozzle_diameter");
  155. float nb = new_val / diameter;
  156. int int_nb = int(floor(nb+0.1));
  157. //print("float "+nb+" cast into "+int_nb+"\n");
  158. if (int_nb > 1 && int_nb < 4) {
  159. float ext_spacing = new_val / int_nb;
  160. set_float("external_perimeter_extrusion_spacing", ext_spacing);
  161. set_float("perimeter_extrusion_spacing", ext_spacing);
  162. set_custom_int(0,"wall_thickness_lines", int_nb);
  163. } else if(int_nb > 3) {
  164. //try with thin external
  165. float ext_spacing = diameter;
  166. float spacing = (new_val - ext_spacing * 2) / (int_nb - 2);
  167. if (spacing > diameter * 1.5) {
  168. // too different, get back to same value
  169. ext_spacing = new_val / int_nb;
  170. spacing = ext_spacing;
  171. }
  172. set_float("external_perimeter_extrusion_spacing", ext_spacing);
  173. set_float("perimeter_extrusion_spacing", spacing);
  174. set_custom_int(0,"wall_thickness_lines", int_nb);
  175. } else if(new_val == 0) {
  176. // fake 'disable' to not confuse people susi#2700
  177. set_custom_int(0,"wall_thickness_lines", 0);
  178. back_initial_value("external_perimeter_extrusion_spacing");
  179. back_initial_value("perimeter_extrusion_spacing");
  180. } else {
  181. back_custom_initial_value(0,"wall_thickness_lines");
  182. back_initial_value("external_perimeter_extrusion_spacing");
  183. back_initial_value("perimeter_extrusion_spacing");
  184. // refresh the displayed value to a valid one
  185. ask_for_refresh();
  186. }
  187. // ask_for_refresh();
  188. }
  189. // quick settings brim
  190. float last_brim_val = 5;
  191. int s_brim_get()
  192. {
  193. float bw = get_float("brim_width");
  194. if (bw > 0) {
  195. last_brim_val = bw;
  196. return 1;
  197. }
  198. return 0;
  199. }
  200. void s_brim_set(bool new_val)
  201. {
  202. if(new_val) {
  203. float bw = get_float("brim_width");
  204. set_float("brim_width", last_brim_val);
  205. } else {
  206. set_float("brim_width", 0);
  207. }
  208. }
  209. // quick settings support
  210. int s_support_fff_get(string &out get_val)
  211. {
  212. bool support_material = get_bool("support_material");
  213. if (!support_material) { // None
  214. return 0;
  215. }
  216. bool support_material_auto = get_bool("support_material_auto");
  217. if (!support_material_auto) { // For support enforcers only
  218. return 2;
  219. }
  220. bool support_material_buildplate_only = get_bool("support_material_buildplate_only");
  221. if (support_material_buildplate_only) { // Support on build plate only
  222. return 1;
  223. }
  224. // everywhere
  225. return 3;
  226. }
  227. void s_support_fff_set(string &in new_val, int idx)
  228. {
  229. if(idx == 0) { // None
  230. back_initial_value("support_material_buildplate_only");
  231. back_initial_value("support_material_auto");
  232. set_bool("support_material", false);
  233. } else if(idx == 1) { // Support on build plate only
  234. set_bool("support_material_buildplate_only", true);
  235. set_bool("support_material_auto", true);
  236. set_bool("support_material", true);
  237. } else if(idx == 2) { // For support enforcers only
  238. set_bool("support_material_buildplate_only", false);
  239. set_bool("support_material_auto", false);
  240. set_bool("support_material", true);
  241. } else if(idx == 3) { // everywhere
  242. set_bool("support_material_buildplate_only", false);
  243. set_bool("support_material_auto", true);
  244. set_bool("support_material", true);
  245. }
  246. }
  247. //TODO to replicate prusa:
  248. // brim_type
  249. // cooling
  250. // xy compensation (both)
  251. //test:
  252. // setting:script:bool:easy:depends$enforce_full_fill_volume:label$fullfill-lol:s_fullfill
  253. // setting:script:int:easy:depends$perimeters:label$perimeters-lol:s_perimeter
  254. // setting:script:float:easy:depends$top_solid_min_thickness:label$thickness-lol:s_thickness
  255. // setting:script:percent:easy:depends$bridge_flow_ratio:label$bridgeflow-lol:s_bridgeflow
  256. // setting:script:string:easy:depends$notes:label$notes-lol:s_notes
  257. // setting:script:enum$b$bof$m$mouaif:easy:depends$no_perimeter_unsupported_algo:label$noperi-lol:s_noperi
  258. int s_fullfill_get()
  259. {
  260. if (get_bool("enforce_full_fill_volume")) return 1;
  261. return 0;
  262. }
  263. void s_fullfill_set(bool set)
  264. {
  265. set_bool("enforce_full_fill_volume", set);
  266. }
  267. int s_perimeter_get()
  268. {
  269. return get_int("perimeters");
  270. }
  271. void s_perimeter_set(int set)
  272. {
  273. set_int("perimeters", set);
  274. }
  275. float s_thickness_get()
  276. {
  277. return get_float("top_solid_min_thickness");
  278. }
  279. void s_thickness_set(float set)
  280. {
  281. set_float("top_solid_min_thickness", set);
  282. }
  283. float s_bridgeflow_get()
  284. {
  285. return get_float("bridge_flow_ratio");
  286. }
  287. void s_bridgeflow_set(float set)
  288. {
  289. set_percent("bridge_flow_ratio", set);
  290. }
  291. void s_notes_get(string &out get_val)
  292. {
  293. get_string("notes", get_val);
  294. }
  295. void s_notes_set(string &out set_val)
  296. {
  297. set_string("notes", set_val);
  298. }
  299. int s_noperi_get(string &out get_val)
  300. {
  301. return get_int("no_perimeter_unsupported_algo") == 0 ? 0 : 1;
  302. }
  303. void s_noperi_set(string &out set_val, int idx)
  304. {
  305. //set_int("no_perimeter_unsupported_algo", idx == 0 ? 0 : 3);
  306. if (idx == 0) set_int("no_perimeter_unsupported_algo",0);
  307. else set_string("no_perimeter_unsupported_algo", "filled");
  308. }