print.as 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. //////////////////////////////////////////
  2. // Api for SuperSlicer scripted widgets:
  3. //
  4. //// Functions callable ////
  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. // bool is_percent(string &in key)
  17. // void get_string(string &in key, string &out get_val)
  18. // can be used by type string and enum (return the enum_value, not the label)
  19. //
  20. // -- to set the value of real settings --
  21. // void set_bool(string &in, bool new_val)
  22. // void set_int(string &in, int new_val)
  23. // if an enum, it's the index
  24. // void set_float(string &in, float new_val)
  25. // if a float_or_percent, unset the percent flag at the same time
  26. // void set_percent(string &in, float new_val)
  27. // if a float_or_percent, set the percent flag at the same time
  28. // void set_string(string &in, string &in new_val))
  29. // if an enum, it's one of the enum_value
  30. //
  31. //// Functions to define for each script widget ////
  32. //
  33. // type bool:
  34. // int OPTNAME_get()
  35. // will return 1 if checkd, 0 if unchecked and -1 if half-checked (not all os, will be uncehcked if not available)
  36. // void OPTNAME_set(bool set)
  37. //
  38. // type int:
  39. // int OPTNAME_get()
  40. // void OPTNAME_set(int set)
  41. //
  42. // type float & percent:
  43. // float OPTNAME_get()
  44. // void OPTNAME_set(float set)
  45. //
  46. // type float_or_percent:
  47. // float OPTNAME_get(bool &out is_percent)
  48. // void OPTNAME_set(float set, bool is_percent)
  49. //
  50. // type string:
  51. // void OPTNAME_get(string &out get)
  52. // void OPTNAME_set(string &in set)
  53. //
  54. // type enum:
  55. // int OPTNAME_get(string &out enum_value)
  56. // Only the return value is used unless it's out of bounds, then it tries to use the enum_value
  57. // void OPTNAME_set(string &in set_enum_value, int set_idx)
  58. //
  59. //
  60. int s_overhangs_get()
  61. {
  62. if (get_float("overhangs_width_speed") == 0) return 0;
  63. float width = get_float("overhangs_width");
  64. bool percent = is_percent("overhangs_width");
  65. if((percent && width > 50.f) || ((!percent) && width > 0.2f)) return 1;
  66. return -1;
  67. }
  68. void s_overhangs_set(bool set)
  69. {
  70. if (set) {
  71. set_percent("overhangs_width_speed", 55.f);
  72. float width = get_float("overhangs_width");
  73. bool percent = is_percent("overhangs_width");
  74. if((percent && width < 50.f) || ((!percent) && width < 0.2f))
  75. set_percent("overhangs_width", 75.f);
  76. } else {
  77. set_float("overhangs_width_speed", 0.);
  78. }
  79. }
  80. //test:
  81. // setting:script:bool:easy:depends$enforce_full_fill_volume:label$fullfill-lol:s_fullfill
  82. // setting:script:int:easy:depends$perimeters:label$perimeters-lol:s_perimeter
  83. // setting:script:float:easy:depends$top_solid_min_thickness:label$thickness-lol:s_thickness
  84. // setting:script:percent:easy:depends$bridge_flow_ratio:label$bridgeflow-lol:s_bridgeflow
  85. // setting:script:string:easy:depends$notes:label$notes-lol:s_notes
  86. // setting:script:enum$b$bof$m$mouaif:easy:depends$no_perimeter_unsupported_algo:label$noperi-lol:s_noperi
  87. int s_fullfill_get()
  88. {
  89. if (get_bool("enforce_full_fill_volume")) return 1;
  90. return 0;
  91. }
  92. void s_fullfill_set(bool set)
  93. {
  94. set_bool("enforce_full_fill_volume", set);
  95. }
  96. int s_perimeter_get()
  97. {
  98. return get_int("perimeters");
  99. }
  100. void s_perimeter_set(int set)
  101. {
  102. set_int("perimeters", set);
  103. }
  104. float s_thickness_get()
  105. {
  106. return get_float("top_solid_min_thickness");
  107. }
  108. void s_thickness_set(float set)
  109. {
  110. set_float("top_solid_min_thickness", set);
  111. }
  112. float s_bridgeflow_get()
  113. {
  114. return get_float("bridge_flow_ratio");
  115. }
  116. void s_bridgeflow_set(float set)
  117. {
  118. set_percent("bridge_flow_ratio", set);
  119. }
  120. void s_notes_get(string &out get_val)
  121. {
  122. get_string("notes", get_val);
  123. }
  124. void s_notes_set(string &out set_val)
  125. {
  126. set_string("notes", set_val);
  127. }
  128. int s_noperi_get(string &out get_val)
  129. {
  130. return get_int("no_perimeter_unsupported_algo") == 0 ? 0 : 1;
  131. }
  132. void s_noperi_set(string &out set_val, int idx)
  133. {
  134. //set_int("no_perimeter_unsupported_algo", idx == 0 ? 0 : 3);
  135. if (idx == 0) set_int("no_perimeter_unsupported_algo",0);
  136. else set_string("no_perimeter_unsupported_algo", "filled");
  137. }