print.as 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466
  1. //////////////////////////////////////////
  2. // Api for SuperSlicer scripted widgets:
  3. //
  4. //////// callable Functions //////
  5. //
  6. // -- to print on the console, for debugging --
  7. // void print(string &out)
  8. // void print_float(float)
  9. //
  10. // -- to get the value of real settings --
  11. // bool get_bool(string &in key)
  12. // int get_int(string &in key)
  13. // can be used by type int and enum (return the index)
  14. // float get_float(string &in key)
  15. // can be used by type float, percent and flaot_or_percent
  16. // float get_computed_float(string &in key)
  17. // get the float computed value of the field. Useful if it's a floatOrPercent that is computable.
  18. // bool is_percent(string &in key)
  19. // void get_string(string &in key, string &out get_val)
  20. // can be used by type string and enum (return the enum_value, not the label)
  21. //
  22. // -- to set the value of real settings --
  23. // void set_bool(string &in key, bool new_val)
  24. // void set_int(string &in key, int new_val)
  25. // if an enum, it's the index
  26. // void set_float(string &in key, float new_val)
  27. // if a float_or_percent, unset the percent flag at the same time
  28. // void set_percent(string &in key, float new_val)
  29. // if a float_or_percent, set the percent flag at the same time
  30. // void set_string(string &in key, string &in new_val))
  31. // if an enum, it's one of the enum_value
  32. //
  33. // void back_initial_value(string &in key)
  34. // revert the setting to the last saved value (same as a click on the reset arrow)
  35. //
  36. // ask_for_refresh()
  37. // ask for a OPTNAME_set() if in a OPTNAME_get()
  38. //
  39. //////// Functions to define for each script widget ////////
  40. //
  41. // note that you can't call set_thing() in an OPTNAME_get(), you can only call these in an OPTNAME_set()
  42. //
  43. // type bool:
  44. // int OPTNAME_get()
  45. // will return 1 if checkd, 0 if unchecked and -1 if half-checked (not all os, will be uncehcked if not available)
  46. // void OPTNAME_set(bool set)
  47. //
  48. // type int:
  49. // int OPTNAME_get()
  50. // void OPTNAME_set(int set)
  51. //
  52. // type float & percent:
  53. // float OPTNAME_get()
  54. // void OPTNAME_set(float set)
  55. //
  56. // type float_or_percent:
  57. // float OPTNAME_get(bool &out is_percent)
  58. // void OPTNAME_set(float set, bool is_percent)
  59. //
  60. // type string:
  61. // void OPTNAME_get(string &out get)
  62. // void OPTNAME_set(string &in set)
  63. //
  64. // type enum:
  65. // int OPTNAME_get(string &out enum_value)
  66. // Only the return value is used unless it's out of bounds, then it tries to use the enum_value
  67. // void OPTNAME_set(string &in set_enum_value, int set_idx)
  68. //
  69. //
  70. //overhangs : quick set/unset like the one in prusalicer
  71. int s_overhangs_get()
  72. {
  73. if (get_float("overhangs_width_speed") == 0) return 0;
  74. float width = get_float("overhangs_width");
  75. bool percent = is_percent("overhangs_width");
  76. if((percent && width > 50.f) || ((!percent) && width > 0.2f)) return 1;
  77. return -1;
  78. }
  79. void s_overhangs_set(bool set)
  80. {
  81. if (set) {
  82. set_percent("overhangs_width_speed", 55.f);
  83. float width = get_float("overhangs_width");
  84. bool percent = is_percent("overhangs_width");
  85. if((percent && width < 50.f) || ((!percent) && width < 0.2f))
  86. set_percent("overhangs_width", 75.f);
  87. } else {
  88. set_float("overhangs_width_speed", 0.);
  89. }
  90. }
  91. void s_overhangs_reset(bool set)
  92. {
  93. back_initial_value("overhangs_width_speed");
  94. back_initial_value("overhangs_width");
  95. }
  96. // "not thick bridge" like in prusaslicer
  97. float compute_overlap()
  98. {
  99. float height = get_float("layer_height");
  100. float width = get_computed_float("solid_infill_extrusion_width");
  101. if(height <= 0) return 1;
  102. if(width <= 0) return 1;
  103. float solid_spacing = (width - height * 0.215);
  104. float solid_flow = height * solid_spacing;
  105. float bridge_spacing = sqrt(solid_flow*1.2739);
  106. float round_val = floor((bridge_spacing / solid_spacing) * 1000. + 0.5) / 1000.;
  107. return round_val;
  108. }
  109. int s_not_thick_bridge_get()
  110. {
  111. bool is_set = false;
  112. get_custom_bool(0,"not_thick_bridge", is_set);
  113. if(is_set){
  114. //set other vars
  115. ask_for_refresh();
  116. return 1;
  117. }
  118. return 0;
  119. }
  120. void s_not_thick_bridge_reset(bool set)
  121. {
  122. set_custom_bool(0,"not_thick_bridge", false);
  123. back_initial_value("bridge_type");
  124. back_initial_value("bridge_overlap");
  125. }
  126. void s_not_thick_bridge_set(bool set)
  127. {
  128. bool var_set = false;
  129. get_custom_bool(0,"not_thick_bridge", var_set);
  130. if (var_set != set) {
  131. set_custom_bool(0,"not_thick_bridge", set);
  132. }
  133. if (set) {
  134. if (get_int("bridge_type") != 2)
  135. set_int("bridge_type", 2);
  136. float overlap = compute_overlap();
  137. set_float("bridge_overlap", overlap);
  138. set_float("bridge_overlap_min", overlap);
  139. } else if (var_set != set) {
  140. back_initial_value("bridge_type");
  141. back_initial_value("bridge_overlap");
  142. back_initial_value("bridge_overlap_min");
  143. }
  144. }
  145. // seam position
  146. // spRandom [spNearest] spAligned spRear [spCustom] spCost
  147. // ("Cost-based") ("Random") ("Aligned") ("Rear")
  148. // -> Corners Nearest Random Aligned Rear Custom
  149. // spRandom spAllRandom [spNearest] spAligned spExtrAligned spRear [spCustom] spCost
  150. // ("Cost-based") ("Scattered") ("Random") ("Aligned") ("Contiguous") ("Rear")
  151. // -> Corners Nearest Scattered Random Aligned Contiguous Rear Custom
  152. float user_angle = 0;
  153. float user_travel = 0;
  154. int s_seam_position_get(string &out get_val)
  155. {
  156. int pos = get_int("seam_position");
  157. string seam_pos;
  158. get_string("seam_position", seam_pos);
  159. if(pos < 7){
  160. if (pos == 0) return 2;// Scattered
  161. if (pos == 1) return 3;// Random
  162. return pos + 1;
  163. } else {
  164. float angle = get_float("seam_angle_cost");
  165. float travel = get_float("seam_travel_cost");
  166. if(angle >= 1. && travel <= 0.8) return 0; //corner
  167. if(angle <= 1. && travel >= 1.0) return 1; //nearest
  168. user_angle = angle;
  169. user_travel = travel;
  170. }
  171. return 7;
  172. }
  173. void s_seam_position_set(string &in set_val, int idx)
  174. {
  175. if (idx == 2 ) {
  176. set_int("seam_position", 0); // Scattered
  177. } else if (idx == 3) {
  178. set_int("seam_position", 1); // Random
  179. } else if (idx == 4) {
  180. set_int("seam_position", 3); // Aligned
  181. } else if (idx == 5) {
  182. set_int("seam_position", 4); // Contiguous
  183. } else if (idx == 6) {
  184. set_int("seam_position", 5); // Rear
  185. } else if (idx <= 1) {
  186. set_int("seam_position", 7);
  187. if (idx == 0) { //corner
  188. set_percent("seam_angle_cost", 120);
  189. set_percent("seam_travel_cost", 40);
  190. } else { // == 1 // nearest
  191. set_percent("seam_angle_cost", 80);
  192. set_percent("seam_travel_cost", 100);
  193. }
  194. } else {
  195. set_int("seam_position", 7); // custom
  196. if(user_angle > 0 || user_travel > 0){
  197. set_percent("seam_angle_cost", user_angle);
  198. set_percent("seam_travel_cost", user_travel);
  199. } else {
  200. back_initial_value("seam_angle_cost");
  201. back_initial_value("seam_travel_cost");
  202. }
  203. }
  204. }
  205. // s_wall_thickness
  206. // set the perimeter_spacing & external_perimeter_spacing
  207. // as m * 2 perimeter_spacing + n * 2 * external_perimeter_spacing = o * s_wall_thickness
  208. float s_wall_thickness_get()
  209. {
  210. int nb_peri = 2;
  211. if (!get_custom_int(0,"wall_thickness_lines", nb_peri)) nb_peri = 2;
  212. float ps = get_computed_float("perimeter_extrusion_spacing");
  213. float eps = get_computed_float("external_perimeter_extrusion_spacing");
  214. //print("s_wall_thickness_get "+ps+" "+eps+" *"+nb_peri+"\n");
  215. if (nb_peri == 0) return 0; // fake 'disable'
  216. if (nb_peri < 2) nb_peri = 2; // too thin value
  217. if( eps > 100000) return 0;
  218. if( ps > 100000) return 0;
  219. return eps * 2 + (nb_peri-2) * ps;
  220. }
  221. void s_wall_thickness_set(float new_val)
  222. {
  223. float diameter = get_float("nozzle_diameter");
  224. float nb = new_val / diameter;
  225. int int_nb = int(floor(nb+0.1));
  226. //print("float "+nb+" cast into "+int_nb+"\n");
  227. if (int_nb > 1 && int_nb < 4) {
  228. float ext_spacing = new_val / int_nb;
  229. set_float("external_perimeter_extrusion_spacing", ext_spacing);
  230. set_float("perimeter_extrusion_spacing", ext_spacing);
  231. set_custom_int(0,"wall_thickness_lines", int_nb);
  232. } else if(int_nb > 3) {
  233. //try with thin external
  234. float ext_spacing = diameter;
  235. float spacing = (new_val - ext_spacing * 2) / (int_nb - 2);
  236. if (spacing > diameter * 1.5) {
  237. // too different, get back to same value
  238. ext_spacing = new_val / int_nb;
  239. spacing = ext_spacing;
  240. }
  241. set_float("external_perimeter_extrusion_spacing", ext_spacing);
  242. set_float("perimeter_extrusion_spacing", spacing);
  243. set_custom_int(0,"wall_thickness_lines", int_nb);
  244. } else if(new_val == 0) {
  245. // fake 'disable' to not confuse people susi#2700
  246. set_custom_int(0,"wall_thickness_lines", 0);
  247. back_initial_value("external_perimeter_extrusion_spacing");
  248. back_initial_value("perimeter_extrusion_spacing");
  249. } else {
  250. back_custom_initial_value(0,"wall_thickness_lines");
  251. back_initial_value("external_perimeter_extrusion_spacing");
  252. back_initial_value("perimeter_extrusion_spacing");
  253. // refresh the displayed value to a valid one
  254. ask_for_refresh();
  255. }
  256. // ask_for_refresh();
  257. }
  258. // quick settings brim
  259. float last_brim_val = 5;
  260. int s_brim_get()
  261. {
  262. float bw = get_float("brim_width");
  263. if (bw > 0) {
  264. last_brim_val = bw;
  265. return 1;
  266. }
  267. return 0;
  268. }
  269. void s_brim_set(bool new_val)
  270. {
  271. if(new_val) {
  272. float bw = get_float("brim_width");
  273. set_float("brim_width", last_brim_val);
  274. } else {
  275. set_float("brim_width", 0);
  276. }
  277. }
  278. // quick settings support
  279. int s_support_fff_get(string &out get_val)
  280. {
  281. bool support_material = get_bool("support_material");
  282. if (!support_material) { // None
  283. return 0;
  284. }
  285. bool support_material_auto = get_bool("support_material_auto");
  286. if (!support_material_auto) { // For support enforcers only
  287. return 2;
  288. }
  289. bool support_material_buildplate_only = get_bool("support_material_buildplate_only");
  290. if (support_material_buildplate_only) { // Support on build plate only
  291. return 1;
  292. }
  293. // everywhere
  294. return 3;
  295. }
  296. void s_support_fff_set(string &in new_val, int idx)
  297. {
  298. if(idx == 0) { // None
  299. back_initial_value("support_material_buildplate_only");
  300. back_initial_value("support_material_auto");
  301. set_bool("support_material", false);
  302. } else if(idx == 1) { // Support on build plate only
  303. set_bool("support_material_buildplate_only", true);
  304. set_bool("support_material_auto", true);
  305. set_bool("support_material", true);
  306. } else if(idx == 2) { // For support enforcers only
  307. set_bool("support_material_buildplate_only", false);
  308. set_bool("support_material_auto", false);
  309. set_bool("support_material", true);
  310. } else if(idx == 3) { // everywhere
  311. set_bool("support_material_buildplate_only", false);
  312. set_bool("support_material_auto", true);
  313. set_bool("support_material", true);
  314. }
  315. }
  316. //TODO to replicate prusa:
  317. // brim_type
  318. // cooling
  319. // xy compensation (both)
  320. //test:
  321. // setting:script:bool:easy:depends$enforce_full_fill_volume:label$fullfill-lol:s_fullfill
  322. // setting:script:int:easy:depends$perimeters:label$perimeters-lol:s_perimeter
  323. // setting:script:float:easy:depends$top_solid_min_thickness:label$thickness-lol:s_thickness
  324. // setting:script:percent:easy:depends$bridge_flow_ratio:label$bridgeflow-lol:s_bridgeflow
  325. // setting:script:string:easy:depends$notes:label$notes-lol:s_notes
  326. // setting:script:enum$b$bof$m$mouaif:easy:depends$no_perimeter_unsupported_algo:label$noperi-lol:s_noperi
  327. int s_fullfill_get()
  328. {
  329. if (get_bool("enforce_full_fill_volume")) return 1;
  330. return 0;
  331. }
  332. void s_fullfill_set(bool set)
  333. {
  334. set_bool("enforce_full_fill_volume", set);
  335. }
  336. int s_perimeter_get()
  337. {
  338. return get_int("perimeters");
  339. }
  340. void s_perimeter_set(int set)
  341. {
  342. set_int("perimeters", set);
  343. }
  344. float s_thickness_get()
  345. {
  346. return get_float("top_solid_min_thickness");
  347. }
  348. void s_thickness_set(float set)
  349. {
  350. set_float("top_solid_min_thickness", set);
  351. }
  352. float s_bridgeflow_get()
  353. {
  354. return get_float("bridge_flow_ratio");
  355. }
  356. void s_bridgeflow_set(float set)
  357. {
  358. set_percent("bridge_flow_ratio", set);
  359. }
  360. void s_notes_get(string &out get_val)
  361. {
  362. get_string("notes", get_val);
  363. }
  364. void s_notes_set(string &out set_val)
  365. {
  366. set_string("notes", set_val);
  367. }
  368. int s_noperi_get(string &out get_val)
  369. {
  370. return get_int("no_perimeter_unsupported_algo") == 0 ? 0 : 1;
  371. }
  372. void s_noperi_set(string &out set_val, int idx)
  373. {
  374. //set_int("no_perimeter_unsupported_algo", idx == 0 ? 0 : 3);
  375. if (idx == 0) set_int("no_perimeter_unsupported_algo",0);
  376. else set_string("no_perimeter_unsupported_algo", "filled");
  377. }
  378. // quick settings bed temp
  379. int s_bed_temp_fff_get(string &out get_val)
  380. {
  381. int bed_temperature = get_int("bed_temperature");
  382. int fl_bed_temperature = get_int("first_layer_bed_temperature");
  383. if (bed_temperature >= 70 && fl_bed_temperature >= 70) {
  384. return 0; //hot
  385. }
  386. if (bed_temperature >= 45 && fl_bed_temperature >= 45) {
  387. return 1; //mild
  388. }
  389. return 2; // cold
  390. }
  391. void s_bed_temp_fff_set(string &in new_val, int idx)
  392. {
  393. if(idx == 0) { // hot
  394. set_int("bed_temperature", 70);
  395. set_int("first_layer_bed_temperature", 75);
  396. } else if(idx == 1) { // mild
  397. set_int("bed_temperature", 45);
  398. set_int("first_layer_bed_temperature", 50);
  399. } else if(idx == 2) { // cold
  400. set_int("bed_temperature", 0);
  401. set_int("first_layer_bed_temperature", 0);
  402. }
  403. }
  404. // quick settings orientation
  405. int s_orientation_fff_get(string &out get_val)
  406. {
  407. float orientation = get_float("init_z_rotate");
  408. if (orientation == 0) {
  409. return 0; // normal
  410. }
  411. if (orientation == 45) {
  412. return 1; // 45°
  413. }
  414. return 3; // custom
  415. }
  416. void s_orientation_fff_set(string &in new_val, int idx)
  417. {
  418. if(idx == 0) { // normal
  419. set_float("init_z_rotate", 0);
  420. } else if(idx == 1) { // 45°
  421. set_float("init_z_rotate", 45);
  422. } else if(idx == 2) { // reset
  423. back_initial_value("init_z_rotate");
  424. }
  425. }