Tab.cpp 108 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774
  1. #include "../../libslic3r/GCodeSender.hpp"
  2. #include "Tab.hpp"
  3. #include "PresetBundle.hpp"
  4. #include "PresetHints.hpp"
  5. #include "../../libslic3r/Utils.hpp"
  6. #include "slic3r/Utils/Http.hpp"
  7. #include "slic3r/Utils/PrintHost.hpp"
  8. #include "slic3r/Utils/Serial.hpp"
  9. #include "BonjourDialog.hpp"
  10. #include "WipeTowerDialog.hpp"
  11. #include "ButtonsDescription.hpp"
  12. #include <wx/app.h>
  13. #include <wx/button.h>
  14. #include <wx/scrolwin.h>
  15. #include <wx/sizer.h>
  16. #include <wx/bmpcbox.h>
  17. #include <wx/bmpbuttn.h>
  18. #include <wx/treectrl.h>
  19. #include <wx/imaglist.h>
  20. #include <wx/settings.h>
  21. #include <wx/filedlg.h>
  22. #include <boost/algorithm/string/predicate.hpp>
  23. #include "wxExtensions.hpp"
  24. #include <wx/wupdlock.h>
  25. #include <chrono>
  26. namespace Slic3r {
  27. namespace GUI {
  28. static wxString dots("…", wxConvUTF8);
  29. // sub new
  30. void Tab::create_preset_tab(PresetBundle *preset_bundle)
  31. {
  32. m_preset_bundle = preset_bundle;
  33. // Vertical sizer to hold the choice menu and the rest of the page.
  34. #ifdef __WXOSX__
  35. auto *main_sizer = new wxBoxSizer(wxVERTICAL);
  36. main_sizer->SetSizeHints(this);
  37. this->SetSizer(main_sizer);
  38. // Create additional panel to Fit() it from OnActivate()
  39. // It's needed for tooltip showing on OSX
  40. m_tmp_panel = new wxPanel(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxBK_LEFT | wxTAB_TRAVERSAL);
  41. auto panel = m_tmp_panel;
  42. auto sizer = new wxBoxSizer(wxVERTICAL);
  43. m_tmp_panel->SetSizer(sizer);
  44. m_tmp_panel->Layout();
  45. main_sizer->Add(m_tmp_panel, 1, wxEXPAND | wxALL, 0);
  46. #else
  47. Tab *panel = this;
  48. auto *sizer = new wxBoxSizer(wxVERTICAL);
  49. sizer->SetSizeHints(panel);
  50. panel->SetSizer(sizer);
  51. #endif //__WXOSX__
  52. // preset chooser
  53. m_presets_choice = new wxBitmapComboBox(panel, wxID_ANY, "", wxDefaultPosition, wxSize(270, -1), 0, 0,wxCB_READONLY);
  54. auto color = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW);
  55. //buttons
  56. wxBitmap bmpMenu;
  57. bmpMenu = wxBitmap(from_u8(Slic3r::var("disk.png")), wxBITMAP_TYPE_PNG);
  58. m_btn_save_preset = new wxBitmapButton(panel, wxID_ANY, bmpMenu, wxDefaultPosition, wxDefaultSize, wxBORDER_NONE);
  59. if (wxMSW) m_btn_save_preset->SetBackgroundColour(color);
  60. bmpMenu = wxBitmap(from_u8(Slic3r::var("delete.png")), wxBITMAP_TYPE_PNG);
  61. m_btn_delete_preset = new wxBitmapButton(panel, wxID_ANY, bmpMenu, wxDefaultPosition, wxDefaultSize, wxBORDER_NONE);
  62. if (wxMSW) m_btn_delete_preset->SetBackgroundColour(color);
  63. m_show_incompatible_presets = false;
  64. m_bmp_show_incompatible_presets.LoadFile(from_u8(Slic3r::var("flag-red-icon.png")), wxBITMAP_TYPE_PNG);
  65. m_bmp_hide_incompatible_presets.LoadFile(from_u8(Slic3r::var("flag-green-icon.png")), wxBITMAP_TYPE_PNG);
  66. m_btn_hide_incompatible_presets = new wxBitmapButton(panel, wxID_ANY, m_bmp_hide_incompatible_presets, wxDefaultPosition, wxDefaultSize, wxBORDER_NONE);
  67. if (wxMSW) m_btn_hide_incompatible_presets->SetBackgroundColour(color);
  68. m_btn_save_preset->SetToolTip(_(L("Save current ")) + m_title);
  69. m_btn_delete_preset->SetToolTip(_(L("Delete this preset")));
  70. m_btn_delete_preset->Disable();
  71. m_undo_btn = new wxButton(panel, wxID_ANY, "", wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT | wxNO_BORDER);
  72. m_undo_to_sys_btn = new wxButton(panel, wxID_ANY, "", wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT | wxNO_BORDER);
  73. m_question_btn = new wxButton(panel, wxID_ANY, "", wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT | wxNO_BORDER);
  74. if (wxMSW) {
  75. m_undo_btn->SetBackgroundColour(color);
  76. m_undo_to_sys_btn->SetBackgroundColour(color);
  77. m_question_btn->SetBackgroundColour(color);
  78. }
  79. m_question_btn->SetToolTip(_(L("Hover the cursor over buttons to find more information \n"
  80. "or click this button.")));
  81. // Determine the theme color of OS (dark or light)
  82. auto luma = get_colour_approx_luma(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW));
  83. // Bitmaps to be shown on the "Revert to system" aka "Lock to system" button next to each input field.
  84. m_bmp_value_lock .LoadFile(from_u8(var("sys_lock.png")), wxBITMAP_TYPE_PNG);
  85. m_bmp_value_unlock .LoadFile(from_u8(var(luma >= 128 ? "sys_unlock.png" : "sys_unlock_grey.png")), wxBITMAP_TYPE_PNG);
  86. m_bmp_non_system = &m_bmp_white_bullet;
  87. // Bitmaps to be shown on the "Undo user changes" button next to each input field.
  88. m_bmp_value_revert .LoadFile(from_u8(var(luma >= 128 ? "action_undo.png" : "action_undo_grey.png")), wxBITMAP_TYPE_PNG);
  89. m_bmp_white_bullet .LoadFile(from_u8(var("bullet_white.png")), wxBITMAP_TYPE_PNG);
  90. m_bmp_question .LoadFile(from_u8(var("question_mark_01.png")), wxBITMAP_TYPE_PNG);
  91. fill_icon_descriptions();
  92. set_tooltips_text();
  93. m_undo_btn->SetBitmap(m_bmp_white_bullet);
  94. m_undo_btn->Bind(wxEVT_BUTTON, ([this](wxCommandEvent){ on_roll_back_value(); }));
  95. m_undo_to_sys_btn->SetBitmap(m_bmp_white_bullet);
  96. m_undo_to_sys_btn->Bind(wxEVT_BUTTON, ([this](wxCommandEvent){ on_roll_back_value(true); }));
  97. m_question_btn->SetBitmap(m_bmp_question);
  98. m_question_btn->Bind(wxEVT_BUTTON, ([this](wxCommandEvent)
  99. {
  100. auto dlg = new ButtonsDescription(this, &m_icon_descriptions);
  101. if (dlg->ShowModal() == wxID_OK){
  102. // Colors for ui "decoration"
  103. for (Tab *tab : get_tabs_list()){
  104. tab->m_sys_label_clr = get_label_clr_sys();
  105. tab->m_modified_label_clr = get_label_clr_modified();
  106. tab->update_labels_colour();
  107. }
  108. }
  109. }));
  110. // Colors for ui "decoration"
  111. m_sys_label_clr = get_label_clr_sys();
  112. m_modified_label_clr = get_label_clr_modified();
  113. m_default_text_clr = get_label_clr_default();
  114. m_hsizer = new wxBoxSizer(wxHORIZONTAL);
  115. sizer->Add(m_hsizer, 0, wxBOTTOM, 3);
  116. m_hsizer->Add(m_presets_choice, 1, wxLEFT | wxRIGHT | wxTOP | wxALIGN_CENTER_VERTICAL, 3);
  117. m_hsizer->AddSpacer(4);
  118. m_hsizer->Add(m_btn_save_preset, 0, wxALIGN_CENTER_VERTICAL);
  119. m_hsizer->AddSpacer(4);
  120. m_hsizer->Add(m_btn_delete_preset, 0, wxALIGN_CENTER_VERTICAL);
  121. m_hsizer->AddSpacer(16);
  122. m_hsizer->Add(m_btn_hide_incompatible_presets, 0, wxALIGN_CENTER_VERTICAL);
  123. m_hsizer->AddSpacer(64);
  124. m_hsizer->Add(m_undo_to_sys_btn, 0, wxALIGN_CENTER_VERTICAL);
  125. m_hsizer->Add(m_undo_btn, 0, wxALIGN_CENTER_VERTICAL);
  126. m_hsizer->AddSpacer(32);
  127. m_hsizer->Add(m_question_btn, 0, wxALIGN_CENTER_VERTICAL);
  128. // m_hsizer->Add(m_cc_presets_choice, 1, wxLEFT | wxRIGHT | wxTOP | wxALIGN_CENTER_VERTICAL, 3);
  129. //Horizontal sizer to hold the tree and the selected page.
  130. m_hsizer = new wxBoxSizer(wxHORIZONTAL);
  131. sizer->Add(m_hsizer, 1, wxEXPAND, 0);
  132. //left vertical sizer
  133. m_left_sizer = new wxBoxSizer(wxVERTICAL);
  134. m_hsizer->Add(m_left_sizer, 0, wxEXPAND | wxLEFT | wxTOP | wxBOTTOM, 3);
  135. // tree
  136. m_treectrl = new wxTreeCtrl(panel, wxID_ANY, wxDefaultPosition, wxSize(185, -1),
  137. wxTR_NO_BUTTONS | wxTR_HIDE_ROOT | wxTR_SINGLE | wxTR_NO_LINES | wxBORDER_SUNKEN | wxWANTS_CHARS);
  138. m_left_sizer->Add(m_treectrl, 1, wxEXPAND);
  139. m_icons = new wxImageList(16, 16, true, 1);
  140. // Index of the last icon inserted into $self->{icons}.
  141. m_icon_count = -1;
  142. m_treectrl->AssignImageList(m_icons);
  143. m_treectrl->AddRoot("root");
  144. m_treectrl->SetIndent(0);
  145. m_disable_tree_sel_changed_event = 0;
  146. m_treectrl->Bind(wxEVT_TREE_SEL_CHANGED, &Tab::OnTreeSelChange, this);
  147. m_treectrl->Bind(wxEVT_KEY_DOWN, &Tab::OnKeyDown, this);
  148. m_presets_choice->Bind(wxEVT_COMBOBOX, ([this](wxCommandEvent e){
  149. //! Because of The MSW and GTK version of wxBitmapComboBox derived from wxComboBox,
  150. //! but the OSX version derived from wxOwnerDrawnCombo, instead of:
  151. //! select_preset(m_presets_choice->GetStringSelection().ToStdString());
  152. //! we doing next:
  153. int selected_item = m_presets_choice->GetSelection();
  154. if (m_selected_preset_item == selected_item && !m_presets->current_is_dirty())
  155. return;
  156. if (selected_item >= 0){
  157. std::string selected_string = m_presets_choice->GetString(selected_item).ToUTF8().data();
  158. if (selected_string.find("-------") == 0
  159. /*selected_string == "------- System presets -------" ||
  160. selected_string == "------- User presets -------"*/){
  161. m_presets_choice->SetSelection(m_selected_preset_item);
  162. return;
  163. }
  164. m_selected_preset_item = selected_item;
  165. select_preset(selected_string);
  166. }
  167. }));
  168. m_btn_save_preset->Bind(wxEVT_BUTTON, ([this](wxCommandEvent e){ save_preset(); }));
  169. m_btn_delete_preset->Bind(wxEVT_BUTTON, ([this](wxCommandEvent e){ delete_preset(); }));
  170. m_btn_hide_incompatible_presets->Bind(wxEVT_BUTTON, ([this](wxCommandEvent e){
  171. toggle_show_hide_incompatible();
  172. }));
  173. // Initialize the DynamicPrintConfig by default keys/values.
  174. build();
  175. rebuild_page_tree();
  176. update();
  177. }
  178. void Tab::load_initial_data()
  179. {
  180. m_config = &m_presets->get_edited_preset().config;
  181. m_bmp_non_system = m_presets->get_selected_preset_parent() ? &m_bmp_value_unlock : &m_bmp_white_bullet;
  182. m_ttg_non_system = m_presets->get_selected_preset_parent() ? &m_ttg_value_unlock : &m_ttg_white_bullet_ns;
  183. m_tt_non_system = m_presets->get_selected_preset_parent() ? &m_tt_value_unlock : &m_ttg_white_bullet_ns;
  184. }
  185. PageShp Tab::add_options_page(const wxString& title, const std::string& icon, bool is_extruder_pages/* = false*/)
  186. {
  187. // Index of icon in an icon list $self->{icons}.
  188. auto icon_idx = 0;
  189. if (!icon.empty()) {
  190. icon_idx = (m_icon_index.find(icon) == m_icon_index.end()) ? -1 : m_icon_index.at(icon);
  191. if (icon_idx == -1) {
  192. // Add a new icon to the icon list.
  193. const auto img_icon = new wxIcon(from_u8(Slic3r::var(icon)), wxBITMAP_TYPE_PNG);
  194. m_icons->Add(*img_icon);
  195. icon_idx = ++m_icon_count;
  196. m_icon_index[icon] = icon_idx;
  197. }
  198. }
  199. // Initialize the page.
  200. #ifdef __WXOSX__
  201. auto panel = m_tmp_panel;
  202. #else
  203. auto panel = this;
  204. #endif
  205. PageShp page(new Page(panel, title, icon_idx));
  206. page->SetScrollbars(1, 1, 1, 1);
  207. page->Hide();
  208. m_hsizer->Add(page.get(), 1, wxEXPAND | wxLEFT, 5);
  209. if (!is_extruder_pages)
  210. m_pages.push_back(page);
  211. page->set_config(m_config);
  212. return page;
  213. }
  214. void Tab::OnActivate()
  215. {
  216. #ifdef __WXOSX__
  217. wxWindowUpdateLocker noUpdates(this);
  218. auto size = GetSizer()->GetSize();
  219. m_tmp_panel->GetSizer()->SetMinSize(size.x + m_size_move, size.y);
  220. Fit();
  221. m_size_move *= -1;
  222. #endif // __WXOSX__
  223. }
  224. void Tab::update_labels_colour()
  225. {
  226. Freeze();
  227. //update options "decoration"
  228. for (const auto opt : m_options_list)
  229. {
  230. const wxColour *color = &m_sys_label_clr;
  231. // value isn't equal to system value
  232. if ((opt.second & osSystemValue) == 0){
  233. // value is equal to last saved
  234. if ((opt.second & osInitValue) != 0)
  235. color = &m_default_text_clr;
  236. // value is modified
  237. else
  238. color = &m_modified_label_clr;
  239. }
  240. if (opt.first == "bed_shape" || opt.first == "compatible_printers") {
  241. if (m_colored_Label != nullptr) {
  242. m_colored_Label->SetForegroundColour(*color);
  243. m_colored_Label->Refresh(true);
  244. }
  245. continue;
  246. }
  247. Field* field = get_field(opt.first);
  248. if (field == nullptr) continue;
  249. field->set_label_colour_force(color);
  250. }
  251. Thaw();
  252. auto cur_item = m_treectrl->GetFirstVisibleItem();
  253. while (cur_item){
  254. auto title = m_treectrl->GetItemText(cur_item);
  255. for (auto page : m_pages)
  256. {
  257. if (page->title() != title)
  258. continue;
  259. const wxColor *clr = !page->m_is_nonsys_values ? &m_sys_label_clr :
  260. page->m_is_modified_values ? &m_modified_label_clr :
  261. &m_default_text_clr;
  262. m_treectrl->SetItemTextColour(cur_item, *clr);
  263. break;
  264. }
  265. cur_item = m_treectrl->GetNextVisible(cur_item);
  266. }
  267. }
  268. // Update UI according to changes
  269. void Tab::update_changed_ui()
  270. {
  271. if (m_postpone_update_ui)
  272. return;
  273. const bool is_printer_type = (name() == "printer");
  274. auto dirty_options = m_presets->current_dirty_options(is_printer_type);
  275. auto nonsys_options = m_presets->current_different_from_parent_options(is_printer_type);
  276. if (is_printer_type){
  277. TabPrinter* tab = static_cast<TabPrinter*>(this);
  278. if (tab->m_initial_extruders_count != tab->m_extruders_count)
  279. dirty_options.emplace_back("extruders_count");
  280. if (tab->m_sys_extruders_count != tab->m_extruders_count)
  281. nonsys_options.emplace_back("extruders_count");
  282. }
  283. for (auto& it : m_options_list)
  284. it.second = m_opt_status_value;
  285. for (auto opt_key : dirty_options) m_options_list[opt_key] &= ~osInitValue;
  286. for (auto opt_key : nonsys_options) m_options_list[opt_key] &= ~osSystemValue;
  287. Freeze();
  288. //update options "decoration"
  289. for (const auto opt : m_options_list)
  290. {
  291. bool is_nonsys_value = false;
  292. bool is_modified_value = true;
  293. const wxBitmap *sys_icon = &m_bmp_value_lock;
  294. const wxBitmap *icon = &m_bmp_value_revert;
  295. const wxColour *color = &m_sys_label_clr;
  296. const wxString *sys_tt = &m_tt_value_lock;
  297. const wxString *tt = &m_tt_value_revert;
  298. // value isn't equal to system value
  299. if ((opt.second & osSystemValue) == 0){
  300. is_nonsys_value = true;
  301. sys_icon = m_bmp_non_system;
  302. sys_tt = m_tt_non_system;
  303. // value is equal to last saved
  304. if ((opt.second & osInitValue) != 0)
  305. color = &m_default_text_clr;
  306. // value is modified
  307. else
  308. color = &m_modified_label_clr;
  309. }
  310. if ((opt.second & osInitValue) != 0)
  311. {
  312. is_modified_value = false;
  313. icon = &m_bmp_white_bullet;
  314. tt = &m_tt_white_bullet;
  315. }
  316. if (opt.first == "bed_shape" || opt.first == "compatible_printers") {
  317. if (m_colored_Label != nullptr) {
  318. m_colored_Label->SetForegroundColour(*color);
  319. m_colored_Label->Refresh(true);
  320. }
  321. continue;
  322. }
  323. Field* field = get_field(opt.first);
  324. if (field == nullptr) continue;
  325. field->m_is_nonsys_value = is_nonsys_value;
  326. field->m_is_modified_value = is_modified_value;
  327. field->set_undo_bitmap(icon);
  328. field->set_undo_to_sys_bitmap(sys_icon);
  329. field->set_undo_tooltip(tt);
  330. field->set_undo_to_sys_tooltip(sys_tt);
  331. field->set_label_colour(color);
  332. }
  333. Thaw();
  334. wxTheApp->CallAfter([this]() {
  335. update_changed_tree_ui();
  336. });
  337. }
  338. void Tab::init_options_list()
  339. {
  340. if (!m_options_list.empty())
  341. m_options_list.clear();
  342. for (const auto opt_key : m_config->keys())
  343. m_options_list.emplace(opt_key, m_opt_status_value);
  344. }
  345. template<class T>
  346. void add_correct_opts_to_options_list(const std::string &opt_key, std::map<std::string, int>& map, TabPrinter *tab, const int& value)
  347. {
  348. T *opt_cur = static_cast<T*>(tab->m_config->option(opt_key));
  349. for (int i = 0; i < opt_cur->values.size(); i++)
  350. map.emplace(opt_key + "#" + std::to_string(i), value);
  351. }
  352. void TabPrinter::init_options_list()
  353. {
  354. if (!m_options_list.empty())
  355. m_options_list.clear();
  356. for (const auto opt_key : m_config->keys())
  357. {
  358. if (opt_key == "bed_shape"){
  359. m_options_list.emplace(opt_key, m_opt_status_value);
  360. continue;
  361. }
  362. switch (m_config->option(opt_key)->type())
  363. {
  364. case coInts: add_correct_opts_to_options_list<ConfigOptionInts >(opt_key, m_options_list, this, m_opt_status_value); break;
  365. case coBools: add_correct_opts_to_options_list<ConfigOptionBools >(opt_key, m_options_list, this, m_opt_status_value); break;
  366. case coFloats: add_correct_opts_to_options_list<ConfigOptionFloats >(opt_key, m_options_list, this, m_opt_status_value); break;
  367. case coStrings: add_correct_opts_to_options_list<ConfigOptionStrings >(opt_key, m_options_list, this, m_opt_status_value); break;
  368. case coPercents:add_correct_opts_to_options_list<ConfigOptionPercents >(opt_key, m_options_list, this, m_opt_status_value); break;
  369. case coPoints: add_correct_opts_to_options_list<ConfigOptionPoints >(opt_key, m_options_list, this, m_opt_status_value); break;
  370. default: m_options_list.emplace(opt_key, m_opt_status_value); break;
  371. }
  372. }
  373. m_options_list.emplace("extruders_count", m_opt_status_value);
  374. }
  375. void Tab::get_sys_and_mod_flags(const std::string& opt_key, bool& sys_page, bool& modified_page)
  376. {
  377. auto opt = m_options_list.find(opt_key);
  378. if (sys_page) sys_page = (opt->second & osSystemValue) != 0;
  379. if (!modified_page) modified_page = (opt->second & osInitValue) == 0;
  380. }
  381. void Tab::update_changed_tree_ui()
  382. {
  383. auto cur_item = m_treectrl->GetFirstVisibleItem();
  384. auto selection = m_treectrl->GetItemText(m_treectrl->GetSelection());
  385. while (cur_item){
  386. auto title = m_treectrl->GetItemText(cur_item);
  387. for (auto page : m_pages)
  388. {
  389. if (page->title() != title)
  390. continue;
  391. bool sys_page = true;
  392. bool modified_page = false;
  393. if (title == _("General")){
  394. std::initializer_list<const char*> optional_keys{ "extruders_count", "bed_shape" };
  395. for (auto &opt_key : optional_keys) {
  396. get_sys_and_mod_flags(opt_key, sys_page, modified_page);
  397. }
  398. }
  399. if (title == _("Dependencies")){
  400. if (name() != "printer")
  401. get_sys_and_mod_flags("compatible_printers", sys_page, modified_page);
  402. else {
  403. sys_page = m_presets->get_selected_preset_parent() ? true:false;
  404. modified_page = false;
  405. }
  406. }
  407. for (auto group : page->m_optgroups)
  408. {
  409. if (!sys_page && modified_page)
  410. break;
  411. for (t_opt_map::iterator it = group->m_opt_map.begin(); it != group->m_opt_map.end(); ++it) {
  412. const std::string& opt_key = it->first;
  413. get_sys_and_mod_flags(opt_key, sys_page, modified_page);
  414. }
  415. }
  416. const wxColor *clr = sys_page ? &m_sys_label_clr :
  417. modified_page ? &m_modified_label_clr :
  418. &m_default_text_clr;
  419. if (page->set_item_colour(clr))
  420. m_treectrl->SetItemTextColour(cur_item, *clr);
  421. page->m_is_nonsys_values = !sys_page;
  422. page->m_is_modified_values = modified_page;
  423. if (selection == title){
  424. m_is_nonsys_values = page->m_is_nonsys_values;
  425. m_is_modified_values = page->m_is_modified_values;
  426. }
  427. break;
  428. }
  429. auto next_item = m_treectrl->GetNextVisible(cur_item);
  430. cur_item = next_item;
  431. }
  432. update_undo_buttons();
  433. }
  434. void Tab::update_undo_buttons()
  435. {
  436. m_undo_btn->SetBitmap(m_is_modified_values ? m_bmp_value_revert : m_bmp_white_bullet);
  437. m_undo_to_sys_btn->SetBitmap(m_is_nonsys_values ? *m_bmp_non_system : m_bmp_value_lock);
  438. m_undo_btn->SetToolTip(m_is_modified_values ? m_ttg_value_revert : m_ttg_white_bullet);
  439. m_undo_to_sys_btn->SetToolTip(m_is_nonsys_values ? *m_ttg_non_system : m_ttg_value_lock);
  440. }
  441. void Tab::on_roll_back_value(const bool to_sys /*= true*/)
  442. {
  443. int os;
  444. if (to_sys) {
  445. if (!m_is_nonsys_values) return;
  446. os = osSystemValue;
  447. }
  448. else {
  449. if (!m_is_modified_values) return;
  450. os = osInitValue;
  451. }
  452. m_postpone_update_ui = true;
  453. auto selection = m_treectrl->GetItemText(m_treectrl->GetSelection());
  454. for (auto page : m_pages)
  455. if (page->title() == selection) {
  456. for (auto group : page->m_optgroups){
  457. if (group->title == _("Capabilities")){
  458. if ((m_options_list["extruders_count"] & os) == 0)
  459. to_sys ? group->back_to_sys_value("extruders_count") : group->back_to_initial_value("extruders_count");
  460. }
  461. if (group->title == _("Size and coordinates")){
  462. if ((m_options_list["bed_shape"] & os) == 0){
  463. to_sys ? group->back_to_sys_value("bed_shape") : group->back_to_initial_value("bed_shape");
  464. load_key_value("bed_shape", true/*some value*/, true);
  465. }
  466. }
  467. if (group->title == _("Profile dependencies") && name() != "printer"){
  468. if ((m_options_list["compatible_printers"] & os) == 0){
  469. to_sys ? group->back_to_sys_value("compatible_printers") : group->back_to_initial_value("compatible_printers");
  470. load_key_value("compatible_printers", true/*some value*/, true);
  471. bool is_empty = m_config->option<ConfigOptionStrings>("compatible_printers")->values.empty();
  472. m_compatible_printers_checkbox->SetValue(is_empty);
  473. is_empty ? m_compatible_printers_btn->Disable() : m_compatible_printers_btn->Enable();
  474. }
  475. }
  476. for (t_opt_map::iterator it = group->m_opt_map.begin(); it != group->m_opt_map.end(); ++it) {
  477. const std::string& opt_key = it->first;
  478. if ((m_options_list[opt_key] & os) == 0)
  479. to_sys ? group->back_to_sys_value(opt_key) : group->back_to_initial_value(opt_key);
  480. }
  481. }
  482. break;
  483. }
  484. m_postpone_update_ui = false;
  485. update_changed_ui();
  486. }
  487. // Update the combo box label of the selected preset based on its "dirty" state,
  488. // comparing the selected preset config with $self->{config}.
  489. void Tab::update_dirty(){
  490. m_presets->update_dirty_ui(m_presets_choice);
  491. on_presets_changed();
  492. update_changed_ui();
  493. // update_dirty_presets(m_cc_presets_choice);
  494. }
  495. void Tab::update_tab_ui()
  496. {
  497. m_selected_preset_item = m_presets->update_tab_ui(m_presets_choice, m_show_incompatible_presets);
  498. // update_tab_presets(m_cc_presets_choice, m_show_incompatible_presets);
  499. // update_presetsctrl(m_presetctrl, m_show_incompatible_presets);
  500. }
  501. // Load a provied DynamicConfig into the tab, modifying the active preset.
  502. // This could be used for example by setting a Wipe Tower position by interactive manipulation in the 3D view.
  503. void Tab::load_config(const DynamicPrintConfig& config)
  504. {
  505. bool modified = 0;
  506. for(auto opt_key : m_config->diff(config)) {
  507. m_config->set_key_value(opt_key, config.option(opt_key)->clone());
  508. modified = 1;
  509. }
  510. if (modified) {
  511. update_dirty();
  512. //# Initialize UI components with the config values.
  513. reload_config();
  514. update();
  515. }
  516. }
  517. // Reload current $self->{config} (aka $self->{presets}->edited_preset->config) into the UI fields.
  518. void Tab::reload_config(){
  519. Freeze();
  520. for (auto page : m_pages)
  521. page->reload_config();
  522. Thaw();
  523. }
  524. Field* Tab::get_field(const t_config_option_key& opt_key, int opt_index/* = -1*/) const
  525. {
  526. Field* field = nullptr;
  527. for (auto page : m_pages){
  528. field = page->get_field(opt_key, opt_index);
  529. if (field != nullptr)
  530. return field;
  531. }
  532. return field;
  533. }
  534. // Set a key/value pair on this page. Return true if the value has been modified.
  535. // Currently used for distributing extruders_count over preset pages of Slic3r::GUI::Tab::Printer
  536. // after a preset is loaded.
  537. bool Tab::set_value(const t_config_option_key& opt_key, const boost::any& value){
  538. bool changed = false;
  539. for(auto page: m_pages) {
  540. if (page->set_value(opt_key, value))
  541. changed = true;
  542. }
  543. return changed;
  544. }
  545. // To be called by custom widgets, load a value into a config,
  546. // update the preset selection boxes (the dirty flags)
  547. // If value is saved before calling this function, put saved_value = true,
  548. // and value can be some random value because in this case it will not been used
  549. void Tab::load_key_value(const std::string& opt_key, const boost::any& value, bool saved_value /*= false*/)
  550. {
  551. if (!saved_value) change_opt_value(*m_config, opt_key, value);
  552. // Mark the print & filament enabled if they are compatible with the currently selected preset.
  553. if (opt_key.compare("compatible_printers") == 0) {
  554. // Don't select another profile if this profile happens to become incompatible.
  555. m_preset_bundle->update_compatible_with_printer(false);
  556. }
  557. m_presets->update_dirty_ui(m_presets_choice);
  558. on_presets_changed();
  559. update();
  560. }
  561. extern wxFrame *g_wxMainFrame;
  562. void Tab::on_value_change(const std::string& opt_key, const boost::any& value)
  563. {
  564. if (m_event_value_change > 0) {
  565. wxCommandEvent event(m_event_value_change);
  566. std::string str_out = opt_key + " " + m_name;
  567. event.SetString(str_out);
  568. if (opt_key == "extruders_count")
  569. {
  570. int val = boost::any_cast<size_t>(value);
  571. event.SetInt(val);
  572. }
  573. g_wxMainFrame->ProcessWindowEvent(event);
  574. }
  575. if (opt_key == "fill_density")
  576. {
  577. boost::any val = get_optgroup()->get_config_value(*m_config, opt_key);
  578. get_optgroup()->set_value(opt_key, val);
  579. }
  580. if (opt_key == "support_material" || opt_key == "support_material_buildplate_only")
  581. {
  582. wxString new_selection = !m_config->opt_bool("support_material") ?
  583. _("None") :
  584. m_config->opt_bool("support_material_buildplate_only") ?
  585. _("Support on build plate only") :
  586. _("Everywhere");
  587. get_optgroup()->set_value("support", new_selection);
  588. }
  589. if (opt_key == "brim_width")
  590. {
  591. bool val = m_config->opt_float("brim_width") > 0.0 ? true : false;
  592. get_optgroup()->set_value("brim", val);
  593. }
  594. if (opt_key == "wipe_tower" || opt_key == "single_extruder_multi_material" || opt_key == "extruders_count" )
  595. update_wiping_button_visibility();
  596. update();
  597. }
  598. // Show/hide the 'purging volumes' button
  599. void Tab::update_wiping_button_visibility() {
  600. bool wipe_tower_enabled = dynamic_cast<ConfigOptionBool*>( (m_preset_bundle->prints.get_edited_preset().config ).option("wipe_tower"))->value;
  601. bool multiple_extruders = dynamic_cast<ConfigOptionFloats*>((m_preset_bundle->printers.get_edited_preset().config).option("nozzle_diameter"))->values.size() > 1;
  602. bool single_extruder_mm = dynamic_cast<ConfigOptionBool*>( (m_preset_bundle->printers.get_edited_preset().config).option("single_extruder_multi_material"))->value;
  603. if (wipe_tower_enabled && multiple_extruders && single_extruder_mm)
  604. get_wiping_dialog_button()->Show();
  605. else get_wiping_dialog_button()->Hide();
  606. (get_wiping_dialog_button()->GetParent())->Layout();
  607. }
  608. // Call a callback to update the selection of presets on the platter:
  609. // To update the content of the selection boxes,
  610. // to update the filament colors of the selection boxes,
  611. // to update the "dirty" flags of the selection boxes,
  612. // to uddate number of "filament" selection boxes when the number of extruders change.
  613. void Tab::on_presets_changed()
  614. {
  615. if (m_event_presets_changed > 0) {
  616. wxCommandEvent event(m_event_presets_changed);
  617. event.SetString(m_name);
  618. g_wxMainFrame->ProcessWindowEvent(event);
  619. }
  620. update_preset_description_line();
  621. }
  622. void Tab::update_preset_description_line()
  623. {
  624. const Preset* parent = m_presets->get_selected_preset_parent();
  625. const Preset& preset = m_presets->get_edited_preset();
  626. wxString description_line = preset.is_default ?
  627. _(L("It's a default preset.")) : preset.is_system ?
  628. _(L("It's a system preset.")) :
  629. _(L("Current preset is inherited from ")) + (parent == nullptr ?
  630. "default preset." :
  631. ":\n\t" + parent->name);
  632. if (preset.is_default || preset.is_system)
  633. description_line += "\n\t" + _(L("It can't be deleted or modified. ")) +
  634. "\n\t" + _(L("Any modifications should be saved as a new preset inherited from this one. ")) +
  635. "\n\t" + _(L("To do that please specify a new name for the preset."));
  636. if (parent && parent->vendor)
  637. {
  638. description_line += "\n\n" + _(L("Additional information:")) + "\n";
  639. description_line += "\t" + _(L("vendor")) + ": " + (name()=="printer" ? "\n\t\t" : "") + parent->vendor->name +
  640. ", ver: " + parent->vendor->config_version.to_string();
  641. if (name() == "printer"){
  642. const std::string &printer_model = preset.config.opt_string("printer_model");
  643. const std::string &default_print_profile = preset.config.opt_string("default_print_profile");
  644. const std::vector<std::string> &default_filament_profiles = preset.config.option<ConfigOptionStrings>("default_filament_profile")->values;
  645. if (!printer_model.empty())
  646. description_line += "\n\n\t" + _(L("printer model")) + ": \n\t\t" + printer_model;
  647. if (!default_print_profile.empty())
  648. description_line += "\n\n\t" + _(L("default print profile")) + ": \n\t\t" + default_print_profile;
  649. if (!default_filament_profiles.empty())
  650. {
  651. description_line += "\n\n\t" + _(L("default filament profile")) + ": \n\t\t";
  652. for (auto& profile : default_filament_profiles){
  653. if (&profile != &*default_filament_profiles.begin())
  654. description_line += ", ";
  655. description_line += profile;
  656. }
  657. }
  658. }
  659. }
  660. m_parent_preset_description_line->SetText(description_line, false);
  661. }
  662. void Tab::update_frequently_changed_parameters()
  663. {
  664. boost::any value = get_optgroup()->get_config_value(*m_config, "fill_density");
  665. get_optgroup()->set_value("fill_density", value);
  666. wxString new_selection = !m_config->opt_bool("support_material") ?
  667. _("None") :
  668. m_config->opt_bool("support_material_buildplate_only") ?
  669. _("Support on build plate only") :
  670. _("Everywhere");
  671. get_optgroup()->set_value("support", new_selection);
  672. bool val = m_config->opt_float("brim_width") > 0.0 ? true : false;
  673. get_optgroup()->set_value("brim", val);
  674. update_wiping_button_visibility();
  675. }
  676. void Tab::reload_compatible_printers_widget()
  677. {
  678. bool has_any = !m_config->option<ConfigOptionStrings>("compatible_printers")->values.empty();
  679. has_any ? m_compatible_printers_btn->Enable() : m_compatible_printers_btn->Disable();
  680. m_compatible_printers_checkbox->SetValue(!has_any);
  681. get_field("compatible_printers_condition")->toggle(!has_any);
  682. }
  683. void TabPrint::build()
  684. {
  685. m_presets = &m_preset_bundle->prints;
  686. load_initial_data();
  687. auto page = add_options_page(_(L("Layers and perimeters")), "layers.png");
  688. auto optgroup = page->new_optgroup(_(L("Layer height")));
  689. optgroup->append_single_option_line("layer_height");
  690. optgroup->append_single_option_line("first_layer_height");
  691. optgroup = page->new_optgroup(_(L("Vertical shells")));
  692. optgroup->append_single_option_line("perimeters");
  693. optgroup->append_single_option_line("spiral_vase");
  694. Line line { "", "" };
  695. line.full_width = 1;
  696. line.widget = [this](wxWindow* parent) {
  697. return description_line_widget(parent, &m_recommended_thin_wall_thickness_description_line);
  698. };
  699. optgroup->append_line(line);
  700. optgroup = page->new_optgroup(_(L("Horizontal shells")));
  701. line = { _(L("Solid layers")), "" };
  702. line.append_option(optgroup->get_option("top_solid_layers"));
  703. line.append_option(optgroup->get_option("bottom_solid_layers"));
  704. optgroup->append_line(line);
  705. optgroup = page->new_optgroup(_(L("Quality (slower slicing)")));
  706. optgroup->append_single_option_line("extra_perimeters");
  707. optgroup->append_single_option_line("ensure_vertical_shell_thickness");
  708. optgroup->append_single_option_line("avoid_crossing_perimeters");
  709. optgroup->append_single_option_line("thin_walls");
  710. optgroup->append_single_option_line("overhangs");
  711. optgroup = page->new_optgroup(_(L("Advanced")));
  712. optgroup->append_single_option_line("seam_position");
  713. optgroup->append_single_option_line("external_perimeters_first");
  714. page = add_options_page(_(L("Infill")), "infill.png");
  715. optgroup = page->new_optgroup(_(L("Infill")));
  716. optgroup->append_single_option_line("fill_density");
  717. optgroup->append_single_option_line("fill_pattern");
  718. optgroup->append_single_option_line("external_fill_pattern");
  719. optgroup = page->new_optgroup(_(L("Reducing printing time")));
  720. optgroup->append_single_option_line("infill_every_layers");
  721. optgroup->append_single_option_line("infill_only_where_needed");
  722. optgroup = page->new_optgroup(_(L("Advanced")));
  723. optgroup->append_single_option_line("solid_infill_every_layers");
  724. optgroup->append_single_option_line("fill_angle");
  725. optgroup->append_single_option_line("solid_infill_below_area");
  726. optgroup->append_single_option_line("bridge_angle");
  727. optgroup->append_single_option_line("only_retract_when_crossing_perimeters");
  728. optgroup->append_single_option_line("infill_first");
  729. page = add_options_page(_(L("Skirt and brim")), "box.png");
  730. optgroup = page->new_optgroup(_(L("Skirt")));
  731. optgroup->append_single_option_line("skirts");
  732. optgroup->append_single_option_line("skirt_distance");
  733. optgroup->append_single_option_line("skirt_height");
  734. optgroup->append_single_option_line("min_skirt_length");
  735. optgroup = page->new_optgroup(_(L("Brim")));
  736. optgroup->append_single_option_line("brim_width");
  737. page = add_options_page(_(L("Support material")), "building.png");
  738. optgroup = page->new_optgroup(_(L("Support material")));
  739. optgroup->append_single_option_line("support_material");
  740. optgroup->append_single_option_line("support_material_threshold");
  741. optgroup->append_single_option_line("support_material_enforce_layers");
  742. optgroup = page->new_optgroup(_(L("Raft")));
  743. optgroup->append_single_option_line("raft_layers");
  744. // # optgroup->append_single_option_line(get_option_("raft_contact_distance");
  745. optgroup = page->new_optgroup(_(L("Options for support material and raft")));
  746. optgroup->append_single_option_line("support_material_contact_distance");
  747. optgroup->append_single_option_line("support_material_pattern");
  748. optgroup->append_single_option_line("support_material_with_sheath");
  749. optgroup->append_single_option_line("support_material_spacing");
  750. optgroup->append_single_option_line("support_material_angle");
  751. optgroup->append_single_option_line("support_material_interface_layers");
  752. optgroup->append_single_option_line("support_material_interface_spacing");
  753. optgroup->append_single_option_line("support_material_interface_contact_loops");
  754. optgroup->append_single_option_line("support_material_buildplate_only");
  755. optgroup->append_single_option_line("support_material_xy_spacing");
  756. optgroup->append_single_option_line("dont_support_bridges");
  757. optgroup->append_single_option_line("support_material_synchronize_layers");
  758. page = add_options_page(_(L("Speed")), "time.png");
  759. optgroup = page->new_optgroup(_(L("Speed for print moves")));
  760. optgroup->append_single_option_line("perimeter_speed");
  761. optgroup->append_single_option_line("small_perimeter_speed");
  762. optgroup->append_single_option_line("external_perimeter_speed");
  763. optgroup->append_single_option_line("infill_speed");
  764. optgroup->append_single_option_line("solid_infill_speed");
  765. optgroup->append_single_option_line("top_solid_infill_speed");
  766. optgroup->append_single_option_line("support_material_speed");
  767. optgroup->append_single_option_line("support_material_interface_speed");
  768. optgroup->append_single_option_line("bridge_speed");
  769. optgroup->append_single_option_line("gap_fill_speed");
  770. optgroup = page->new_optgroup(_(L("Speed for non-print moves")));
  771. optgroup->append_single_option_line("travel_speed");
  772. optgroup = page->new_optgroup(_(L("Modifiers")));
  773. optgroup->append_single_option_line("first_layer_speed");
  774. optgroup = page->new_optgroup(_(L("Acceleration control (advanced)")));
  775. optgroup->append_single_option_line("perimeter_acceleration");
  776. optgroup->append_single_option_line("infill_acceleration");
  777. optgroup->append_single_option_line("bridge_acceleration");
  778. optgroup->append_single_option_line("first_layer_acceleration");
  779. optgroup->append_single_option_line("default_acceleration");
  780. optgroup = page->new_optgroup(_(L("Autospeed (advanced)")));
  781. optgroup->append_single_option_line("max_print_speed");
  782. optgroup->append_single_option_line("max_volumetric_speed");
  783. optgroup->append_single_option_line("max_volumetric_extrusion_rate_slope_positive");
  784. optgroup->append_single_option_line("max_volumetric_extrusion_rate_slope_negative");
  785. page = add_options_page(_(L("Multiple Extruders")), "funnel.png");
  786. optgroup = page->new_optgroup(_(L("Extruders")));
  787. optgroup->append_single_option_line("perimeter_extruder");
  788. optgroup->append_single_option_line("infill_extruder");
  789. optgroup->append_single_option_line("solid_infill_extruder");
  790. optgroup->append_single_option_line("support_material_extruder");
  791. optgroup->append_single_option_line("support_material_interface_extruder");
  792. optgroup = page->new_optgroup(_(L("Ooze prevention")));
  793. optgroup->append_single_option_line("ooze_prevention");
  794. optgroup->append_single_option_line("standby_temperature_delta");
  795. optgroup = page->new_optgroup(_(L("Wipe tower")));
  796. optgroup->append_single_option_line("wipe_tower");
  797. optgroup->append_single_option_line("wipe_tower_x");
  798. optgroup->append_single_option_line("wipe_tower_y");
  799. optgroup->append_single_option_line("wipe_tower_width");
  800. optgroup->append_single_option_line("wipe_tower_rotation_angle");
  801. optgroup->append_single_option_line("wipe_tower_bridging");
  802. optgroup->append_single_option_line("single_extruder_multi_material_priming");
  803. optgroup = page->new_optgroup(_(L("Advanced")));
  804. optgroup->append_single_option_line("interface_shells");
  805. page = add_options_page(_(L("Advanced")), "wrench.png");
  806. optgroup = page->new_optgroup(_(L("Extrusion width")));
  807. optgroup->append_single_option_line("extrusion_width");
  808. optgroup->append_single_option_line("first_layer_extrusion_width");
  809. optgroup->append_single_option_line("perimeter_extrusion_width");
  810. optgroup->append_single_option_line("external_perimeter_extrusion_width");
  811. optgroup->append_single_option_line("infill_extrusion_width");
  812. optgroup->append_single_option_line("solid_infill_extrusion_width");
  813. optgroup->append_single_option_line("top_infill_extrusion_width");
  814. optgroup->append_single_option_line("support_material_extrusion_width");
  815. optgroup = page->new_optgroup(_(L("Overlap")));
  816. optgroup->append_single_option_line("infill_overlap");
  817. optgroup = page->new_optgroup(_(L("Flow")));
  818. optgroup->append_single_option_line("bridge_flow_ratio");
  819. optgroup = page->new_optgroup(_(L("Other")));
  820. optgroup->append_single_option_line("clip_multipart_objects");
  821. optgroup->append_single_option_line("elefant_foot_compensation");
  822. optgroup->append_single_option_line("xy_size_compensation");
  823. // # optgroup->append_single_option_line("threads");
  824. optgroup->append_single_option_line("resolution");
  825. page = add_options_page(_(L("Output options")), "page_white_go.png");
  826. optgroup = page->new_optgroup(_(L("Sequential printing")));
  827. optgroup->append_single_option_line("complete_objects");
  828. line = { _(L("Extruder clearance (mm)")), "" };
  829. Option option = optgroup->get_option("extruder_clearance_radius");
  830. option.opt.width = 60;
  831. line.append_option(option);
  832. option = optgroup->get_option("extruder_clearance_height");
  833. option.opt.width = 60;
  834. line.append_option(option);
  835. optgroup->append_line(line);
  836. optgroup = page->new_optgroup(_(L("Output file")));
  837. optgroup->append_single_option_line("gcode_comments");
  838. option = optgroup->get_option("output_filename_format");
  839. option.opt.full_width = true;
  840. optgroup->append_single_option_line(option);
  841. optgroup = page->new_optgroup(_(L("Post-processing scripts")), 0);
  842. option = optgroup->get_option("post_process");
  843. option.opt.full_width = true;
  844. option.opt.height = 50;
  845. optgroup->append_single_option_line(option);
  846. page = add_options_page(_(L("Notes")), "note.png");
  847. optgroup = page->new_optgroup(_(L("Notes")), 0);
  848. option = optgroup->get_option("notes");
  849. option.opt.full_width = true;
  850. option.opt.height = 250;
  851. optgroup->append_single_option_line(option);
  852. page = add_options_page(_(L("Dependencies")), "wrench.png");
  853. optgroup = page->new_optgroup(_(L("Profile dependencies")));
  854. line = { _(L("Compatible printers")), "" };
  855. line.widget = [this](wxWindow* parent){
  856. return compatible_printers_widget(parent, &m_compatible_printers_checkbox, &m_compatible_printers_btn);
  857. };
  858. optgroup->append_line(line, &m_colored_Label);
  859. option = optgroup->get_option("compatible_printers_condition");
  860. option.opt.full_width = true;
  861. optgroup->append_single_option_line(option);
  862. line = Line{ "", "" };
  863. line.full_width = 1;
  864. line.widget = [this](wxWindow* parent) {
  865. return description_line_widget(parent, &m_parent_preset_description_line);
  866. };
  867. optgroup->append_line(line);
  868. }
  869. // Reload current config (aka presets->edited_preset->config) into the UI fields.
  870. void TabPrint::reload_config(){
  871. reload_compatible_printers_widget();
  872. Tab::reload_config();
  873. }
  874. void TabPrint::update()
  875. {
  876. Freeze();
  877. double fill_density = m_config->option<ConfigOptionPercent>("fill_density")->value;
  878. if (m_config->opt_bool("spiral_vase") &&
  879. !(m_config->opt_int("perimeters") == 1 && m_config->opt_int("top_solid_layers") == 0 &&
  880. fill_density == 0)) {
  881. wxString msg_text = _(L("The Spiral Vase mode requires:\n"
  882. "- one perimeter\n"
  883. "- no top solid layers\n"
  884. "- 0% fill density\n"
  885. "- no support material\n"
  886. "- no ensure_vertical_shell_thickness\n"
  887. "\nShall I adjust those settings in order to enable Spiral Vase?"));
  888. auto dialog = new wxMessageDialog(parent(), msg_text, _(L("Spiral Vase")), wxICON_WARNING | wxYES | wxNO);
  889. DynamicPrintConfig new_conf = *m_config;
  890. if (dialog->ShowModal() == wxID_YES) {
  891. new_conf.set_key_value("perimeters", new ConfigOptionInt(1));
  892. new_conf.set_key_value("top_solid_layers", new ConfigOptionInt(0));
  893. new_conf.set_key_value("fill_density", new ConfigOptionPercent(0));
  894. new_conf.set_key_value("support_material", new ConfigOptionBool(false));
  895. new_conf.set_key_value("support_material_enforce_layers", new ConfigOptionInt(0));
  896. new_conf.set_key_value("ensure_vertical_shell_thickness", new ConfigOptionBool(false));
  897. fill_density = 0;
  898. }
  899. else {
  900. new_conf.set_key_value("spiral_vase", new ConfigOptionBool(false));
  901. }
  902. load_config(new_conf);
  903. on_value_change("fill_density", fill_density);
  904. }
  905. if (m_config->opt_bool("wipe_tower") && m_config->opt_bool("support_material") &&
  906. m_config->opt_float("support_material_contact_distance") > 0. &&
  907. (m_config->opt_int("support_material_extruder") != 0 || m_config->opt_int("support_material_interface_extruder") != 0)) {
  908. wxString msg_text = _(L("The Wipe Tower currently supports the non-soluble supports only\n"
  909. "if they are printed with the current extruder without triggering a tool change.\n"
  910. "(both support_material_extruder and support_material_interface_extruder need to be set to 0).\n"
  911. "\nShall I adjust those settings in order to enable the Wipe Tower?"));
  912. auto dialog = new wxMessageDialog(parent(), msg_text, _(L("Wipe Tower")), wxICON_WARNING | wxYES | wxNO);
  913. DynamicPrintConfig new_conf = *m_config;
  914. if (dialog->ShowModal() == wxID_YES) {
  915. new_conf.set_key_value("support_material_extruder", new ConfigOptionInt(0));
  916. new_conf.set_key_value("support_material_interface_extruder", new ConfigOptionInt(0));
  917. }
  918. else
  919. new_conf.set_key_value("wipe_tower", new ConfigOptionBool(false));
  920. load_config(new_conf);
  921. }
  922. if (m_config->opt_bool("wipe_tower") && m_config->opt_bool("support_material") &&
  923. m_config->opt_float("support_material_contact_distance") == 0 &&
  924. !m_config->opt_bool("support_material_synchronize_layers")) {
  925. wxString msg_text = _(L("For the Wipe Tower to work with the soluble supports, the support layers\n"
  926. "need to be synchronized with the object layers.\n"
  927. "\nShall I synchronize support layers in order to enable the Wipe Tower?"));
  928. auto dialog = new wxMessageDialog(parent(), msg_text, _(L("Wipe Tower")), wxICON_WARNING | wxYES | wxNO);
  929. DynamicPrintConfig new_conf = *m_config;
  930. if (dialog->ShowModal() == wxID_YES) {
  931. new_conf.set_key_value("support_material_synchronize_layers", new ConfigOptionBool(true));
  932. }
  933. else
  934. new_conf.set_key_value("wipe_tower", new ConfigOptionBool(false));
  935. load_config(new_conf);
  936. }
  937. if (m_config->opt_bool("support_material")) {
  938. // Ask only once.
  939. if (!m_support_material_overhangs_queried) {
  940. m_support_material_overhangs_queried = true;
  941. if (!m_config->opt_bool("overhangs")/* != 1*/) {
  942. wxString msg_text = _(L("Supports work better, if the following feature is enabled:\n"
  943. "- Detect bridging perimeters\n"
  944. "\nShall I adjust those settings for supports?"));
  945. auto dialog = new wxMessageDialog(parent(), msg_text, _(L("Support Generator")), wxICON_WARNING | wxYES | wxNO | wxCANCEL);
  946. DynamicPrintConfig new_conf = *m_config;
  947. auto answer = dialog->ShowModal();
  948. if (answer == wxID_YES) {
  949. // Enable "detect bridging perimeters".
  950. new_conf.set_key_value("overhangs", new ConfigOptionBool(true));
  951. } else if (answer == wxID_NO) {
  952. // Do nothing, leave supports on and "detect bridging perimeters" off.
  953. } else if (answer == wxID_CANCEL) {
  954. // Disable supports.
  955. new_conf.set_key_value("support_material", new ConfigOptionBool(false));
  956. m_support_material_overhangs_queried = false;
  957. }
  958. load_config(new_conf);
  959. }
  960. }
  961. }
  962. else {
  963. m_support_material_overhangs_queried = false;
  964. }
  965. if (m_config->option<ConfigOptionPercent>("fill_density")->value == 100) {
  966. auto fill_pattern = m_config->option<ConfigOptionEnum<InfillPattern>>("fill_pattern")->value;
  967. std::string str_fill_pattern = "";
  968. t_config_enum_values map_names = m_config->option<ConfigOptionEnum<InfillPattern>>("fill_pattern")->get_enum_values();
  969. for (auto it : map_names) {
  970. if (fill_pattern == it.second) {
  971. str_fill_pattern = it.first;
  972. break;
  973. }
  974. }
  975. if (!str_fill_pattern.empty()){
  976. auto external_fill_pattern = m_config->def()->get("external_fill_pattern")->enum_values;
  977. bool correct_100p_fill = false;
  978. for (auto fill : external_fill_pattern)
  979. {
  980. if (str_fill_pattern.compare(fill) == 0)
  981. correct_100p_fill = true;
  982. }
  983. // get fill_pattern name from enum_labels for using this one at dialog_msg
  984. str_fill_pattern = m_config->def()->get("fill_pattern")->enum_labels[fill_pattern];
  985. if (!correct_100p_fill){
  986. wxString msg_text = _(L("The ")) + str_fill_pattern + _(L(" infill pattern is not supposed to work at 100% density.\n"
  987. "\nShall I switch to rectilinear fill pattern?"));
  988. auto dialog = new wxMessageDialog(parent(), msg_text, _(L("Infill")), wxICON_WARNING | wxYES | wxNO);
  989. DynamicPrintConfig new_conf = *m_config;
  990. if (dialog->ShowModal() == wxID_YES) {
  991. new_conf.set_key_value("fill_pattern", new ConfigOptionEnum<InfillPattern>(ipRectilinear));
  992. fill_density = 100;
  993. }
  994. else
  995. fill_density = m_presets->get_selected_preset().config.option<ConfigOptionPercent>("fill_density")->value;
  996. new_conf.set_key_value("fill_density", new ConfigOptionPercent(fill_density));
  997. load_config(new_conf);
  998. on_value_change("fill_density", fill_density);
  999. }
  1000. }
  1001. }
  1002. bool have_perimeters = m_config->opt_int("perimeters") > 0;
  1003. for (auto el : {"extra_perimeters", "ensure_vertical_shell_thickness", "thin_walls", "overhangs",
  1004. "seam_position", "external_perimeters_first", "external_perimeter_extrusion_width",
  1005. "perimeter_speed", "small_perimeter_speed", "external_perimeter_speed" })
  1006. get_field(el)->toggle(have_perimeters);
  1007. bool have_infill = m_config->option<ConfigOptionPercent>("fill_density")->value > 0;
  1008. // infill_extruder uses the same logic as in Print::extruders()
  1009. for (auto el : {"fill_pattern", "infill_every_layers", "infill_only_where_needed",
  1010. "solid_infill_every_layers", "solid_infill_below_area", "infill_extruder" })
  1011. get_field(el)->toggle(have_infill);
  1012. bool have_solid_infill = m_config->opt_int("top_solid_layers") > 0 || m_config->opt_int("bottom_solid_layers") > 0;
  1013. // solid_infill_extruder uses the same logic as in Print::extruders()
  1014. for (auto el : {"external_fill_pattern", "infill_first", "solid_infill_extruder",
  1015. "solid_infill_extrusion_width", "solid_infill_speed" })
  1016. get_field(el)->toggle(have_solid_infill);
  1017. for (auto el : {"fill_angle", "bridge_angle", "infill_extrusion_width",
  1018. "infill_speed", "bridge_speed" })
  1019. get_field(el)->toggle(have_infill || have_solid_infill);
  1020. get_field("gap_fill_speed")->toggle(have_perimeters && have_infill);
  1021. bool have_top_solid_infill = m_config->opt_int("top_solid_layers") > 0;
  1022. for (auto el : { "top_infill_extrusion_width", "top_solid_infill_speed" })
  1023. get_field(el)->toggle(have_top_solid_infill);
  1024. bool have_default_acceleration = m_config->opt_float("default_acceleration") > 0;
  1025. for (auto el : {"perimeter_acceleration", "infill_acceleration",
  1026. "bridge_acceleration", "first_layer_acceleration" })
  1027. get_field(el)->toggle(have_default_acceleration);
  1028. bool have_skirt = m_config->opt_int("skirts") > 0 || m_config->opt_float("min_skirt_length") > 0;
  1029. for (auto el : { "skirt_distance", "skirt_height" })
  1030. get_field(el)->toggle(have_skirt);
  1031. bool have_brim = m_config->opt_float("brim_width") > 0;
  1032. // perimeter_extruder uses the same logic as in Print::extruders()
  1033. get_field("perimeter_extruder")->toggle(have_perimeters || have_brim);
  1034. bool have_raft = m_config->opt_int("raft_layers") > 0;
  1035. bool have_support_material = m_config->opt_bool("support_material") || have_raft;
  1036. bool have_support_interface = m_config->opt_int("support_material_interface_layers") > 0;
  1037. bool have_support_soluble = have_support_material && m_config->opt_float("support_material_contact_distance") == 0;
  1038. for (auto el : {"support_material_threshold", "support_material_pattern", "support_material_with_sheath",
  1039. "support_material_spacing", "support_material_angle", "support_material_interface_layers",
  1040. "dont_support_bridges", "support_material_extrusion_width", "support_material_contact_distance",
  1041. "support_material_xy_spacing" })
  1042. get_field(el)->toggle(have_support_material);
  1043. for (auto el : {"support_material_interface_spacing", "support_material_interface_extruder",
  1044. "support_material_interface_speed", "support_material_interface_contact_loops" })
  1045. get_field(el)->toggle(have_support_material && have_support_interface);
  1046. get_field("support_material_synchronize_layers")->toggle(have_support_soluble);
  1047. get_field("perimeter_extrusion_width")->toggle(have_perimeters || have_skirt || have_brim);
  1048. get_field("support_material_extruder")->toggle(have_support_material || have_skirt);
  1049. get_field("support_material_speed")->toggle(have_support_material || have_brim || have_skirt);
  1050. bool have_sequential_printing = m_config->opt_bool("complete_objects");
  1051. for (auto el : { "extruder_clearance_radius", "extruder_clearance_height" })
  1052. get_field(el)->toggle(have_sequential_printing);
  1053. bool have_ooze_prevention = m_config->opt_bool("ooze_prevention");
  1054. get_field("standby_temperature_delta")->toggle(have_ooze_prevention);
  1055. bool have_wipe_tower = m_config->opt_bool("wipe_tower");
  1056. for (auto el : { "wipe_tower_x", "wipe_tower_y", "wipe_tower_width", "wipe_tower_rotation_angle", "wipe_tower_bridging"})
  1057. get_field(el)->toggle(have_wipe_tower);
  1058. m_recommended_thin_wall_thickness_description_line->SetText(
  1059. from_u8(PresetHints::recommended_thin_wall_thickness(*m_preset_bundle)));
  1060. Thaw();
  1061. }
  1062. void TabPrint::OnActivate()
  1063. {
  1064. m_recommended_thin_wall_thickness_description_line->SetText(
  1065. from_u8(PresetHints::recommended_thin_wall_thickness(*m_preset_bundle)));
  1066. Tab::OnActivate();
  1067. }
  1068. void TabFilament::build()
  1069. {
  1070. m_presets = &m_preset_bundle->filaments;
  1071. load_initial_data();
  1072. auto page = add_options_page(_(L("Filament")), "spool.png");
  1073. auto optgroup = page->new_optgroup(_(L("Filament")));
  1074. optgroup->append_single_option_line("filament_colour");
  1075. optgroup->append_single_option_line("filament_diameter");
  1076. optgroup->append_single_option_line("extrusion_multiplier");
  1077. optgroup->append_single_option_line("filament_density");
  1078. optgroup->append_single_option_line("filament_cost");
  1079. optgroup = page->new_optgroup(_(L("Temperature ")) + wxString("°C", wxConvUTF8));
  1080. Line line = { _(L("Extruder")), "" };
  1081. line.append_option(optgroup->get_option("first_layer_temperature"));
  1082. line.append_option(optgroup->get_option("temperature"));
  1083. optgroup->append_line(line);
  1084. line = { _(L("Bed")), "" };
  1085. line.append_option(optgroup->get_option("first_layer_bed_temperature"));
  1086. line.append_option(optgroup->get_option("bed_temperature"));
  1087. optgroup->append_line(line);
  1088. page = add_options_page(_(L("Cooling")), "hourglass.png");
  1089. optgroup = page->new_optgroup(_(L("Enable")));
  1090. optgroup->append_single_option_line("fan_always_on");
  1091. optgroup->append_single_option_line("cooling");
  1092. line = { "", "" };
  1093. line.full_width = 1;
  1094. line.widget = [this](wxWindow* parent) {
  1095. return description_line_widget(parent, &m_cooling_description_line);
  1096. };
  1097. optgroup->append_line(line);
  1098. optgroup = page->new_optgroup(_(L("Fan settings")));
  1099. line = { _(L("Fan speed")), "" };
  1100. line.append_option(optgroup->get_option("min_fan_speed"));
  1101. line.append_option(optgroup->get_option("max_fan_speed"));
  1102. optgroup->append_line(line);
  1103. optgroup->append_single_option_line("bridge_fan_speed");
  1104. optgroup->append_single_option_line("disable_fan_first_layers");
  1105. optgroup = page->new_optgroup(_(L("Cooling thresholds")), 250);
  1106. optgroup->append_single_option_line("fan_below_layer_time");
  1107. optgroup->append_single_option_line("slowdown_below_layer_time");
  1108. optgroup->append_single_option_line("min_print_speed");
  1109. page = add_options_page(_(L("Advanced")), "wrench.png");
  1110. optgroup = page->new_optgroup(_(L("Filament properties")));
  1111. optgroup->append_single_option_line("filament_type");
  1112. optgroup->append_single_option_line("filament_soluble");
  1113. optgroup = page->new_optgroup(_(L("Print speed override")));
  1114. optgroup->append_single_option_line("filament_max_volumetric_speed");
  1115. line = { "", "" };
  1116. line.full_width = 1;
  1117. line.widget = [this](wxWindow* parent) {
  1118. return description_line_widget(parent, &m_volumetric_speed_description_line);
  1119. };
  1120. optgroup->append_line(line);
  1121. optgroup = page->new_optgroup(_(L("Toolchange parameters with single extruder MM printers")));
  1122. optgroup->append_single_option_line("filament_loading_speed");
  1123. optgroup->append_single_option_line("filament_unloading_speed");
  1124. optgroup->append_single_option_line("filament_load_time");
  1125. optgroup->append_single_option_line("filament_unload_time");
  1126. optgroup->append_single_option_line("filament_toolchange_delay");
  1127. optgroup->append_single_option_line("filament_cooling_moves");
  1128. optgroup->append_single_option_line("filament_cooling_initial_speed");
  1129. optgroup->append_single_option_line("filament_cooling_final_speed");
  1130. optgroup->append_single_option_line("filament_minimal_purge_on_wipe_tower");
  1131. line = { _(L("Ramming")), "" };
  1132. line.widget = [this](wxWindow* parent){
  1133. auto ramming_dialog_btn = new wxButton(parent, wxID_ANY, _(L("Ramming settings"))+dots, wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT);
  1134. auto sizer = new wxBoxSizer(wxHORIZONTAL);
  1135. sizer->Add(ramming_dialog_btn);
  1136. ramming_dialog_btn->Bind(wxEVT_BUTTON, ([this](wxCommandEvent& e)
  1137. {
  1138. RammingDialog dlg(this,(m_config->option<ConfigOptionStrings>("filament_ramming_parameters"))->get_at(0));
  1139. if (dlg.ShowModal() == wxID_OK)
  1140. (m_config->option<ConfigOptionStrings>("filament_ramming_parameters"))->get_at(0) = dlg.get_parameters();
  1141. }));
  1142. return sizer;
  1143. };
  1144. optgroup->append_line(line);
  1145. page = add_options_page(_(L("Custom G-code")), "cog.png");
  1146. optgroup = page->new_optgroup(_(L("Start G-code")), 0);
  1147. Option option = optgroup->get_option("start_filament_gcode");
  1148. option.opt.full_width = true;
  1149. option.opt.height = 150;
  1150. optgroup->append_single_option_line(option);
  1151. optgroup = page->new_optgroup(_(L("End G-code")), 0);
  1152. option = optgroup->get_option("end_filament_gcode");
  1153. option.opt.full_width = true;
  1154. option.opt.height = 150;
  1155. optgroup->append_single_option_line(option);
  1156. page = add_options_page(_(L("Notes")), "note.png");
  1157. optgroup = page->new_optgroup(_(L("Notes")), 0);
  1158. optgroup->label_width = 0;
  1159. option = optgroup->get_option("filament_notes");
  1160. option.opt.full_width = true;
  1161. option.opt.height = 250;
  1162. optgroup->append_single_option_line(option);
  1163. page = add_options_page(_(L("Dependencies")), "wrench.png");
  1164. optgroup = page->new_optgroup(_(L("Profile dependencies")));
  1165. line = { _(L("Compatible printers")), "" };
  1166. line.widget = [this](wxWindow* parent){
  1167. return compatible_printers_widget(parent, &m_compatible_printers_checkbox, &m_compatible_printers_btn);
  1168. };
  1169. optgroup->append_line(line, &m_colored_Label);
  1170. option = optgroup->get_option("compatible_printers_condition");
  1171. option.opt.full_width = true;
  1172. optgroup->append_single_option_line(option);
  1173. line = Line{ "", "" };
  1174. line.full_width = 1;
  1175. line.widget = [this](wxWindow* parent) {
  1176. return description_line_widget(parent, &m_parent_preset_description_line);
  1177. };
  1178. optgroup->append_line(line);
  1179. }
  1180. // Reload current config (aka presets->edited_preset->config) into the UI fields.
  1181. void TabFilament::reload_config(){
  1182. reload_compatible_printers_widget();
  1183. Tab::reload_config();
  1184. }
  1185. void TabFilament::update()
  1186. {
  1187. Freeze();
  1188. wxString text = from_u8(PresetHints::cooling_description(m_presets->get_edited_preset()));
  1189. m_cooling_description_line->SetText(text);
  1190. text = from_u8(PresetHints::maximum_volumetric_flow_description(*m_preset_bundle));
  1191. m_volumetric_speed_description_line->SetText(text);
  1192. bool cooling = m_config->opt_bool("cooling", 0);
  1193. bool fan_always_on = cooling || m_config->opt_bool("fan_always_on", 0);
  1194. for (auto el : { "max_fan_speed", "fan_below_layer_time", "slowdown_below_layer_time", "min_print_speed" })
  1195. get_field(el)->toggle(cooling);
  1196. for (auto el : { "min_fan_speed", "disable_fan_first_layers" })
  1197. get_field(el)->toggle(fan_always_on);
  1198. Thaw();
  1199. }
  1200. void TabFilament::OnActivate()
  1201. {
  1202. m_volumetric_speed_description_line->SetText(from_u8(PresetHints::maximum_volumetric_flow_description(*m_preset_bundle)));
  1203. Tab::OnActivate();
  1204. }
  1205. wxSizer* Tab::description_line_widget(wxWindow* parent, ogStaticText* *StaticText)
  1206. {
  1207. *StaticText = new ogStaticText(parent, "");
  1208. auto font = (new wxSystemSettings)->GetFont(wxSYS_DEFAULT_GUI_FONT);
  1209. (*StaticText)->SetFont(font);
  1210. auto sizer = new wxBoxSizer(wxHORIZONTAL);
  1211. sizer->Add(*StaticText, 1, wxEXPAND|wxALL, 0);
  1212. return sizer;
  1213. }
  1214. bool Tab::current_preset_is_dirty()
  1215. {
  1216. return m_presets->current_is_dirty();
  1217. }
  1218. void TabPrinter::build()
  1219. {
  1220. m_presets = &m_preset_bundle->printers;
  1221. load_initial_data();
  1222. // to avoid redundant memory allocation / deallocation during extruders count changing
  1223. m_pages.reserve(30);
  1224. auto *nozzle_diameter = dynamic_cast<const ConfigOptionFloats*>(m_config->option("nozzle_diameter"));
  1225. m_initial_extruders_count = m_extruders_count = nozzle_diameter->values.size();
  1226. const Preset* parent_preset = m_presets->get_selected_preset_parent();
  1227. m_sys_extruders_count = parent_preset == nullptr ? 0 :
  1228. static_cast<const ConfigOptionFloats*>(parent_preset->config.option("nozzle_diameter"))->values.size();
  1229. auto page = add_options_page(_(L("General")), "printer_empty.png");
  1230. auto optgroup = page->new_optgroup(_(L("Size and coordinates")));
  1231. Line line{ _(L("Bed shape")), "" };
  1232. line.widget = [this](wxWindow* parent){
  1233. auto btn = new wxButton(parent, wxID_ANY, _(L(" Set "))+dots, wxDefaultPosition, wxDefaultSize, wxBU_LEFT | wxBU_EXACTFIT);
  1234. // btn->SetFont(Slic3r::GUI::small_font);
  1235. btn->SetBitmap(wxBitmap(from_u8(Slic3r::var("printer_empty.png")), wxBITMAP_TYPE_PNG));
  1236. auto sizer = new wxBoxSizer(wxHORIZONTAL);
  1237. sizer->Add(btn);
  1238. btn->Bind(wxEVT_BUTTON, ([this](wxCommandEvent e)
  1239. {
  1240. auto dlg = new BedShapeDialog(this);
  1241. dlg->build_dialog(m_config->option<ConfigOptionPoints>("bed_shape"));
  1242. if (dlg->ShowModal() == wxID_OK){
  1243. load_key_value("bed_shape", dlg->GetValue());
  1244. update_changed_ui();
  1245. }
  1246. }));
  1247. return sizer;
  1248. };
  1249. optgroup->append_line(line, &m_colored_Label);
  1250. optgroup->append_single_option_line("max_print_height");
  1251. optgroup->append_single_option_line("z_offset");
  1252. optgroup = page->new_optgroup(_(L("Capabilities")));
  1253. ConfigOptionDef def;
  1254. def.type = coInt,
  1255. def.default_value = new ConfigOptionInt(1);
  1256. def.label = L("Extruders");
  1257. def.tooltip = L("Number of extruders of the printer.");
  1258. def.min = 1;
  1259. Option option(def, "extruders_count");
  1260. optgroup->append_single_option_line(option);
  1261. optgroup->append_single_option_line("single_extruder_multi_material");
  1262. optgroup->m_on_change = [this, optgroup](t_config_option_key opt_key, boost::any value){
  1263. size_t extruders_count = boost::any_cast<int>(optgroup->get_value("extruders_count"));
  1264. wxTheApp->CallAfter([this, opt_key, value, extruders_count](){
  1265. if (opt_key.compare("extruders_count")==0 || opt_key.compare("single_extruder_multi_material")==0) {
  1266. extruders_count_changed(extruders_count);
  1267. update_dirty();
  1268. if (opt_key.compare("single_extruder_multi_material")==0) // the single_extruder_multimaterial was added to force pages
  1269. on_value_change(opt_key, value); // rebuild - let's make sure the on_value_change is not skipped
  1270. }
  1271. else {
  1272. update_dirty();
  1273. on_value_change(opt_key, value);
  1274. }
  1275. });
  1276. };
  1277. if (!m_no_controller)
  1278. {
  1279. optgroup = page->new_optgroup(_(L("USB/Serial connection")));
  1280. line = {_(L("Serial port")), ""};
  1281. Option serial_port = optgroup->get_option("serial_port");
  1282. serial_port.side_widget = ([this](wxWindow* parent){
  1283. auto btn = new wxBitmapButton(parent, wxID_ANY, wxBitmap(from_u8(Slic3r::var("arrow_rotate_clockwise.png")), wxBITMAP_TYPE_PNG),
  1284. wxDefaultPosition, wxDefaultSize, wxBORDER_NONE);
  1285. btn->SetToolTip(_(L("Rescan serial ports")));
  1286. auto sizer = new wxBoxSizer(wxHORIZONTAL);
  1287. sizer->Add(btn);
  1288. btn->Bind(wxEVT_BUTTON, [this](wxCommandEvent e) {update_serial_ports(); });
  1289. return sizer;
  1290. });
  1291. auto serial_test = [this](wxWindow* parent){
  1292. auto btn = m_serial_test_btn = new wxButton(parent, wxID_ANY,
  1293. _(L("Test")), wxDefaultPosition, wxDefaultSize, wxBU_LEFT | wxBU_EXACTFIT);
  1294. // btn->SetFont($Slic3r::GUI::small_font);
  1295. btn->SetBitmap(wxBitmap(from_u8(Slic3r::var("wrench.png")), wxBITMAP_TYPE_PNG));
  1296. auto sizer = new wxBoxSizer(wxHORIZONTAL);
  1297. sizer->Add(btn);
  1298. btn->Bind(wxEVT_BUTTON, [this, parent](wxCommandEvent e){
  1299. auto sender = Slic3r::make_unique<GCodeSender>();
  1300. auto res = sender->connect(
  1301. m_config->opt_string("serial_port"),
  1302. m_config->opt_int("serial_speed")
  1303. );
  1304. if (res && sender->wait_connected()) {
  1305. show_info(parent, _(L("Connection to printer works correctly.")), _(L("Success!")));
  1306. }
  1307. else {
  1308. show_error(parent, _(L("Connection failed.")));
  1309. }
  1310. });
  1311. return sizer;
  1312. };
  1313. line.append_option(serial_port);
  1314. line.append_option(optgroup->get_option("serial_speed"));
  1315. line.append_widget(serial_test);
  1316. optgroup->append_line(line);
  1317. }
  1318. optgroup = page->new_optgroup(_(L("Printer Host upload")));
  1319. optgroup->append_single_option_line("host_type");
  1320. auto printhost_browse = [this, optgroup] (wxWindow* parent) {
  1321. auto btn = m_printhost_browse_btn = new wxButton(parent, wxID_ANY, _(L(" Browse "))+dots, wxDefaultPosition, wxDefaultSize, wxBU_LEFT);
  1322. btn->SetBitmap(wxBitmap(from_u8(Slic3r::var("zoom.png")), wxBITMAP_TYPE_PNG));
  1323. auto sizer = new wxBoxSizer(wxHORIZONTAL);
  1324. sizer->Add(btn);
  1325. btn->Bind(wxEVT_BUTTON, [this, parent, optgroup](wxCommandEvent e) {
  1326. BonjourDialog dialog(parent);
  1327. if (dialog.show_and_lookup()) {
  1328. optgroup->set_value("print_host", std::move(dialog.get_selected()), true);
  1329. }
  1330. });
  1331. return sizer;
  1332. };
  1333. auto print_host_test = [this](wxWindow* parent) {
  1334. auto btn = m_print_host_test_btn = new wxButton(parent, wxID_ANY, _(L("Test")),
  1335. wxDefaultPosition, wxDefaultSize, wxBU_LEFT | wxBU_EXACTFIT);
  1336. btn->SetBitmap(wxBitmap(from_u8(Slic3r::var("wrench.png")), wxBITMAP_TYPE_PNG));
  1337. auto sizer = new wxBoxSizer(wxHORIZONTAL);
  1338. sizer->Add(btn);
  1339. btn->Bind(wxEVT_BUTTON, [this](wxCommandEvent e) {
  1340. std::unique_ptr<PrintHost> host(PrintHost::get_print_host(m_config));
  1341. if (! host) {
  1342. const auto text = wxString::Format("%s",
  1343. _(L("Could not get a valid Printer Host reference")));
  1344. show_error(this, text);
  1345. return;
  1346. }
  1347. wxString msg;
  1348. if (host->test(msg)) {
  1349. show_info(this, host->get_test_ok_msg(), _(L("Success!")));
  1350. } else {
  1351. show_error(this, host->get_test_failed_msg(msg));
  1352. }
  1353. });
  1354. return sizer;
  1355. };
  1356. Line host_line = optgroup->create_single_option_line("print_host");
  1357. host_line.append_widget(printhost_browse);
  1358. host_line.append_widget(print_host_test);
  1359. optgroup->append_line(host_line);
  1360. optgroup->append_single_option_line("printhost_apikey");
  1361. if (Http::ca_file_supported()) {
  1362. Line cafile_line = optgroup->create_single_option_line("printhost_cafile");
  1363. auto printhost_cafile_browse = [this, optgroup] (wxWindow* parent) {
  1364. auto btn = new wxButton(parent, wxID_ANY, _(L(" Browse "))+dots, wxDefaultPosition, wxDefaultSize, wxBU_LEFT);
  1365. btn->SetBitmap(wxBitmap(from_u8(Slic3r::var("zoom.png")), wxBITMAP_TYPE_PNG));
  1366. auto sizer = new wxBoxSizer(wxHORIZONTAL);
  1367. sizer->Add(btn);
  1368. btn->Bind(wxEVT_BUTTON, [this, optgroup] (wxCommandEvent e){
  1369. static const auto filemasks = _(L("Certificate files (*.crt, *.pem)|*.crt;*.pem|All files|*.*"));
  1370. wxFileDialog openFileDialog(this, _(L("Open CA certificate file")), "", "", filemasks, wxFD_OPEN | wxFD_FILE_MUST_EXIST);
  1371. if (openFileDialog.ShowModal() != wxID_CANCEL) {
  1372. optgroup->set_value("printhost_cafile", std::move(openFileDialog.GetPath()), true);
  1373. }
  1374. });
  1375. return sizer;
  1376. };
  1377. cafile_line.append_widget(printhost_cafile_browse);
  1378. optgroup->append_line(cafile_line);
  1379. auto printhost_cafile_hint = [this, optgroup] (wxWindow* parent) {
  1380. auto txt = new wxStaticText(parent, wxID_ANY,
  1381. _(L("HTTPS CA file is optional. It is only needed if you use HTTPS with a self-signed certificate.")));
  1382. auto sizer = new wxBoxSizer(wxHORIZONTAL);
  1383. sizer->Add(txt);
  1384. return sizer;
  1385. };
  1386. Line cafile_hint { "", "" };
  1387. cafile_hint.full_width = 1;
  1388. cafile_hint.widget = std::move(printhost_cafile_hint);
  1389. optgroup->append_line(cafile_hint);
  1390. }
  1391. optgroup = page->new_optgroup(_(L("Firmware")));
  1392. optgroup->append_single_option_line("gcode_flavor");
  1393. optgroup->append_single_option_line("silent_mode");
  1394. optgroup->append_single_option_line("remaining_times");
  1395. optgroup->m_on_change = [this, optgroup](t_config_option_key opt_key, boost::any value){
  1396. wxTheApp->CallAfter([this, opt_key, value](){
  1397. if (opt_key.compare("silent_mode") == 0) {
  1398. bool val = boost::any_cast<bool>(value);
  1399. if (m_use_silent_mode != val) {
  1400. m_rebuild_kinematics_page = true;
  1401. m_use_silent_mode = val;
  1402. }
  1403. }
  1404. build_extruder_pages();
  1405. update_dirty();
  1406. on_value_change(opt_key, value);
  1407. });
  1408. };
  1409. optgroup = page->new_optgroup(_(L("Advanced")));
  1410. optgroup->append_single_option_line("use_relative_e_distances");
  1411. optgroup->append_single_option_line("use_firmware_retraction");
  1412. optgroup->append_single_option_line("use_volumetric_e");
  1413. optgroup->append_single_option_line("variable_layer_height");
  1414. page = add_options_page(_(L("Custom G-code")), "cog.png");
  1415. optgroup = page->new_optgroup(_(L("Start G-code")), 0);
  1416. option = optgroup->get_option("start_gcode");
  1417. option.opt.full_width = true;
  1418. option.opt.height = 150;
  1419. optgroup->append_single_option_line(option);
  1420. optgroup = page->new_optgroup(_(L("End G-code")), 0);
  1421. option = optgroup->get_option("end_gcode");
  1422. option.opt.full_width = true;
  1423. option.opt.height = 150;
  1424. optgroup->append_single_option_line(option);
  1425. optgroup = page->new_optgroup(_(L("Before layer change G-code")), 0);
  1426. option = optgroup->get_option("before_layer_gcode");
  1427. option.opt.full_width = true;
  1428. option.opt.height = 150;
  1429. optgroup->append_single_option_line(option);
  1430. optgroup = page->new_optgroup(_(L("After layer change G-code")), 0);
  1431. option = optgroup->get_option("layer_gcode");
  1432. option.opt.full_width = true;
  1433. option.opt.height = 150;
  1434. optgroup->append_single_option_line(option);
  1435. optgroup = page->new_optgroup(_(L("Tool change G-code")), 0);
  1436. option = optgroup->get_option("toolchange_gcode");
  1437. option.opt.full_width = true;
  1438. option.opt.height = 150;
  1439. optgroup->append_single_option_line(option);
  1440. optgroup = page->new_optgroup(_(L("Between objects G-code (for sequential printing)")), 0);
  1441. option = optgroup->get_option("between_objects_gcode");
  1442. option.opt.full_width = true;
  1443. option.opt.height = 150;
  1444. optgroup->append_single_option_line(option);
  1445. page = add_options_page(_(L("Notes")), "note.png");
  1446. optgroup = page->new_optgroup(_(L("Notes")), 0);
  1447. option = optgroup->get_option("printer_notes");
  1448. option.opt.full_width = true;
  1449. option.opt.height = 250;
  1450. optgroup->append_single_option_line(option);
  1451. page = add_options_page(_(L("Dependencies")), "wrench.png");
  1452. optgroup = page->new_optgroup(_(L("Profile dependencies")));
  1453. line = Line{ "", "" };
  1454. line.full_width = 1;
  1455. line.widget = [this](wxWindow* parent) {
  1456. return description_line_widget(parent, &m_parent_preset_description_line);
  1457. };
  1458. optgroup->append_line(line);
  1459. build_extruder_pages();
  1460. if (!m_no_controller)
  1461. update_serial_ports();
  1462. }
  1463. void TabPrinter::update_serial_ports(){
  1464. Field *field = get_field("serial_port");
  1465. Choice *choice = static_cast<Choice *>(field);
  1466. choice->set_values(Utils::scan_serial_ports());
  1467. }
  1468. void TabPrinter::extruders_count_changed(size_t extruders_count){
  1469. m_extruders_count = extruders_count;
  1470. m_preset_bundle->printers.get_edited_preset().set_num_extruders(extruders_count);
  1471. m_preset_bundle->update_multi_material_filament_presets();
  1472. build_extruder_pages();
  1473. reload_config();
  1474. on_value_change("extruders_count", extruders_count);
  1475. }
  1476. void TabPrinter::append_option_line(ConfigOptionsGroupShp optgroup, const std::string opt_key)
  1477. {
  1478. auto option = optgroup->get_option(opt_key, 0);
  1479. auto line = Line{ option.opt.full_label, "" };
  1480. line.append_option(option);
  1481. if (m_use_silent_mode)
  1482. line.append_option(optgroup->get_option(opt_key, 1));
  1483. optgroup->append_line(line);
  1484. }
  1485. PageShp TabPrinter::build_kinematics_page()
  1486. {
  1487. auto page = add_options_page(_(L("Machine limits")), "cog.png", true);
  1488. if (m_use_silent_mode) {
  1489. // Legend for OptionsGroups
  1490. auto optgroup = page->new_optgroup(_(L("")));
  1491. optgroup->set_show_modified_btns_val(false);
  1492. optgroup->label_width = 230;
  1493. auto line = Line{ "", "" };
  1494. ConfigOptionDef def;
  1495. def.type = coString;
  1496. def.width = 150;
  1497. def.gui_type = "legend";
  1498. def.tooltip = L("Values in this column are for Full Power mode");
  1499. def.default_value = new ConfigOptionString{ L("Full Power") };
  1500. auto option = Option(def, "full_power_legend");
  1501. line.append_option(option);
  1502. def.tooltip = L("Values in this column are for Silent mode");
  1503. def.default_value = new ConfigOptionString{ L("Silent") };
  1504. option = Option(def, "silent_legend");
  1505. line.append_option(option);
  1506. optgroup->append_line(line);
  1507. }
  1508. std::vector<std::string> axes{ "x", "y", "z", "e" };
  1509. auto optgroup = page->new_optgroup(_(L("Maximum feedrates")));
  1510. for (const std::string &axis : axes) {
  1511. append_option_line(optgroup, "machine_max_feedrate_" + axis);
  1512. }
  1513. optgroup = page->new_optgroup(_(L("Maximum accelerations")));
  1514. for (const std::string &axis : axes) {
  1515. append_option_line(optgroup, "machine_max_acceleration_" + axis);
  1516. }
  1517. append_option_line(optgroup, "machine_max_acceleration_extruding");
  1518. append_option_line(optgroup, "machine_max_acceleration_retracting");
  1519. optgroup = page->new_optgroup(_(L("Jerk limits")));
  1520. for (const std::string &axis : axes) {
  1521. append_option_line(optgroup, "machine_max_jerk_" + axis);
  1522. }
  1523. optgroup = page->new_optgroup(_(L("Minimum feedrates")));
  1524. append_option_line(optgroup, "machine_min_extruding_rate");
  1525. append_option_line(optgroup, "machine_min_travel_rate");
  1526. return page;
  1527. }
  1528. void TabPrinter::build_extruder_pages()
  1529. {
  1530. size_t n_before_extruders = 2; // Count of pages before Extruder pages
  1531. bool is_marlin_flavor = m_config->option<ConfigOptionEnum<GCodeFlavor>>("gcode_flavor")->value == gcfMarlin;
  1532. // Add/delete Kinematics page according to is_marlin_flavor
  1533. size_t existed_page = 0;
  1534. for (int i = n_before_extruders; i < m_pages.size(); ++i) // first make sure it's not there already
  1535. if (m_pages[i]->title().find(_(L("Machine limits"))) != std::string::npos) {
  1536. if (!is_marlin_flavor || m_rebuild_kinematics_page)
  1537. m_pages.erase(m_pages.begin() + i);
  1538. else
  1539. existed_page = i;
  1540. break;
  1541. }
  1542. if (existed_page < n_before_extruders && is_marlin_flavor){
  1543. auto page = build_kinematics_page();
  1544. m_pages.insert(m_pages.begin() + n_before_extruders, page);
  1545. }
  1546. if (is_marlin_flavor)
  1547. n_before_extruders++;
  1548. size_t n_after_single_extruder_MM = 2; // Count of pages after single_extruder_multi_material page
  1549. if (m_extruders_count_old == m_extruders_count ||
  1550. (m_has_single_extruder_MM_page && m_extruders_count == 1))
  1551. {
  1552. // if we have a single extruder MM setup, add a page with configuration options:
  1553. for (int i = 0; i < m_pages.size(); ++i) // first make sure it's not there already
  1554. if (m_pages[i]->title().find(_(L("Single extruder MM setup"))) != std::string::npos) {
  1555. m_pages.erase(m_pages.begin() + i);
  1556. break;
  1557. }
  1558. m_has_single_extruder_MM_page = false;
  1559. }
  1560. if (m_extruders_count > 1 && m_config->opt_bool("single_extruder_multi_material") && !m_has_single_extruder_MM_page) {
  1561. // create a page, but pretend it's an extruder page, so we can add it to m_pages ourselves
  1562. auto page = add_options_page(_(L("Single extruder MM setup")), "printer_empty.png", true);
  1563. auto optgroup = page->new_optgroup(_(L("Single extruder multimaterial parameters")));
  1564. optgroup->append_single_option_line("cooling_tube_retraction");
  1565. optgroup->append_single_option_line("cooling_tube_length");
  1566. optgroup->append_single_option_line("parking_pos_retraction");
  1567. optgroup->append_single_option_line("extra_loading_move");
  1568. m_pages.insert(m_pages.end() - n_after_single_extruder_MM, page);
  1569. m_has_single_extruder_MM_page = true;
  1570. }
  1571. for (auto extruder_idx = m_extruders_count_old; extruder_idx < m_extruders_count; ++extruder_idx){
  1572. //# build page
  1573. char buf[MIN_BUF_LENGTH_FOR_L];
  1574. sprintf(buf, _CHB(L("Extruder %d")), extruder_idx + 1);
  1575. auto page = add_options_page(from_u8(buf), "funnel.png", true);
  1576. m_pages.insert(m_pages.begin() + n_before_extruders + extruder_idx, page);
  1577. auto optgroup = page->new_optgroup(_(L("Size")));
  1578. optgroup->append_single_option_line("nozzle_diameter", extruder_idx);
  1579. optgroup = page->new_optgroup(_(L("Layer height limits")));
  1580. optgroup->append_single_option_line("min_layer_height", extruder_idx);
  1581. optgroup->append_single_option_line("max_layer_height", extruder_idx);
  1582. optgroup = page->new_optgroup(_(L("Position (for multi-extruder printers)")));
  1583. optgroup->append_single_option_line("extruder_offset", extruder_idx);
  1584. optgroup = page->new_optgroup(_(L("Retraction")));
  1585. optgroup->append_single_option_line("retract_length", extruder_idx);
  1586. optgroup->append_single_option_line("retract_lift", extruder_idx);
  1587. Line line = { _(L("Only lift Z")), "" };
  1588. line.append_option(optgroup->get_option("retract_lift_above", extruder_idx));
  1589. line.append_option(optgroup->get_option("retract_lift_below", extruder_idx));
  1590. optgroup->append_line(line);
  1591. optgroup->append_single_option_line("retract_speed", extruder_idx);
  1592. optgroup->append_single_option_line("deretract_speed", extruder_idx);
  1593. optgroup->append_single_option_line("retract_restart_extra", extruder_idx);
  1594. optgroup->append_single_option_line("retract_before_travel", extruder_idx);
  1595. optgroup->append_single_option_line("retract_layer_change", extruder_idx);
  1596. optgroup->append_single_option_line("wipe", extruder_idx);
  1597. optgroup->append_single_option_line("retract_before_wipe", extruder_idx);
  1598. optgroup = page->new_optgroup(_(L("Retraction when tool is disabled (advanced settings for multi-extruder setups)")));
  1599. optgroup->append_single_option_line("retract_length_toolchange", extruder_idx);
  1600. optgroup->append_single_option_line("retract_restart_extra_toolchange", extruder_idx);
  1601. optgroup = page->new_optgroup(_(L("Preview")));
  1602. optgroup->append_single_option_line("extruder_colour", extruder_idx);
  1603. }
  1604. // # remove extra pages
  1605. if (m_extruders_count < m_extruders_count_old)
  1606. m_pages.erase( m_pages.begin() + n_before_extruders + m_extruders_count,
  1607. m_pages.begin() + n_before_extruders + m_extruders_count_old);
  1608. m_extruders_count_old = m_extruders_count;
  1609. rebuild_page_tree();
  1610. }
  1611. // this gets executed after preset is loaded and before GUI fields are updated
  1612. void TabPrinter::on_preset_loaded()
  1613. {
  1614. // update the extruders count field
  1615. auto *nozzle_diameter = dynamic_cast<const ConfigOptionFloats*>(m_config->option("nozzle_diameter"));
  1616. int extruders_count = nozzle_diameter->values.size();
  1617. set_value("extruders_count", extruders_count);
  1618. // update the GUI field according to the number of nozzle diameters supplied
  1619. extruders_count_changed(extruders_count);
  1620. }
  1621. void TabPrinter::update(){
  1622. Freeze();
  1623. bool en;
  1624. auto serial_speed = get_field("serial_speed");
  1625. if (serial_speed != nullptr) {
  1626. en = !m_config->opt_string("serial_port").empty();
  1627. get_field("serial_speed")->toggle(en);
  1628. if (m_config->opt_int("serial_speed") != 0 && en)
  1629. m_serial_test_btn->Enable();
  1630. else
  1631. m_serial_test_btn->Disable();
  1632. }
  1633. {
  1634. std::unique_ptr<PrintHost> host(PrintHost::get_print_host(m_config));
  1635. m_print_host_test_btn->Enable(!m_config->opt_string("print_host").empty() && host->can_test());
  1636. m_printhost_browse_btn->Enable(host->has_auto_discovery());
  1637. }
  1638. bool have_multiple_extruders = m_extruders_count > 1;
  1639. get_field("toolchange_gcode")->toggle(have_multiple_extruders);
  1640. get_field("single_extruder_multi_material")->toggle(have_multiple_extruders);
  1641. bool is_marlin_flavor = m_config->option<ConfigOptionEnum<GCodeFlavor>>("gcode_flavor")->value == gcfMarlin;
  1642. {
  1643. Field *sm = get_field("silent_mode");
  1644. if (! is_marlin_flavor)
  1645. // Disable silent mode for non-marlin firmwares.
  1646. get_field("silent_mode")->toggle(false);
  1647. if (is_marlin_flavor)
  1648. sm->enable();
  1649. else
  1650. sm->disable();
  1651. }
  1652. if (m_use_silent_mode != m_config->opt_bool("silent_mode")) {
  1653. m_rebuild_kinematics_page = true;
  1654. m_use_silent_mode = m_config->opt_bool("silent_mode");
  1655. }
  1656. for (size_t i = 0; i < m_extruders_count; ++i) {
  1657. bool have_retract_length = m_config->opt_float("retract_length", i) > 0;
  1658. // when using firmware retraction, firmware decides retraction length
  1659. bool use_firmware_retraction = m_config->opt_bool("use_firmware_retraction");
  1660. get_field("retract_length", i)->toggle(!use_firmware_retraction);
  1661. // user can customize travel length if we have retraction length or we"re using
  1662. // firmware retraction
  1663. get_field("retract_before_travel", i)->toggle(have_retract_length || use_firmware_retraction);
  1664. // user can customize other retraction options if retraction is enabled
  1665. bool retraction = (have_retract_length || use_firmware_retraction);
  1666. std::vector<std::string> vec = { "retract_lift", "retract_layer_change" };
  1667. for (auto el : vec)
  1668. get_field(el, i)->toggle(retraction);
  1669. // retract lift above / below only applies if using retract lift
  1670. vec.resize(0);
  1671. vec = { "retract_lift_above", "retract_lift_below" };
  1672. for (auto el : vec)
  1673. get_field(el, i)->toggle(retraction && m_config->opt_float("retract_lift", i) > 0);
  1674. // some options only apply when not using firmware retraction
  1675. vec.resize(0);
  1676. vec = { "retract_speed", "deretract_speed", "retract_before_wipe", "retract_restart_extra", "wipe" };
  1677. for (auto el : vec)
  1678. get_field(el, i)->toggle(retraction && !use_firmware_retraction);
  1679. bool wipe = m_config->opt_bool("wipe", i);
  1680. get_field("retract_before_wipe", i)->toggle(wipe);
  1681. if (use_firmware_retraction && wipe) {
  1682. auto dialog = new wxMessageDialog(parent(),
  1683. _(L("The Wipe option is not available when using the Firmware Retraction mode.\n"
  1684. "\nShall I disable it in order to enable Firmware Retraction?")),
  1685. _(L("Firmware Retraction")), wxICON_WARNING | wxYES | wxNO);
  1686. DynamicPrintConfig new_conf = *m_config;
  1687. if (dialog->ShowModal() == wxID_YES) {
  1688. auto wipe = static_cast<ConfigOptionBools*>(m_config->option("wipe")->clone());
  1689. for (int w = 0; w < wipe->values.size(); w++)
  1690. wipe->values[w] = false;
  1691. new_conf.set_key_value("wipe", wipe);
  1692. }
  1693. else {
  1694. new_conf.set_key_value("use_firmware_retraction", new ConfigOptionBool(false));
  1695. }
  1696. load_config(new_conf);
  1697. }
  1698. get_field("retract_length_toolchange", i)->toggle(have_multiple_extruders);
  1699. bool toolchange_retraction = m_config->opt_float("retract_length_toolchange", i) > 0;
  1700. get_field("retract_restart_extra_toolchange", i)->toggle
  1701. (have_multiple_extruders && toolchange_retraction);
  1702. }
  1703. Thaw();
  1704. }
  1705. // Initialize the UI from the current preset
  1706. void Tab::load_current_preset()
  1707. {
  1708. auto preset = m_presets->get_edited_preset();
  1709. (preset.is_default || preset.is_system) ? m_btn_delete_preset->Disable() : m_btn_delete_preset->Enable(true);
  1710. update();
  1711. // For the printer profile, generate the extruder pages.
  1712. on_preset_loaded();
  1713. // Reload preset pages with the new configuration values.
  1714. reload_config();
  1715. m_bmp_non_system = m_presets->get_selected_preset_parent() ? &m_bmp_value_unlock : &m_bmp_white_bullet;
  1716. m_ttg_non_system = m_presets->get_selected_preset_parent() ? &m_ttg_value_unlock : &m_ttg_white_bullet_ns;
  1717. m_tt_non_system = m_presets->get_selected_preset_parent() ? &m_tt_value_unlock : &m_ttg_white_bullet_ns;
  1718. m_undo_to_sys_btn->Enable(!preset.is_default);
  1719. // use CallAfter because some field triggers schedule on_change calls using CallAfter,
  1720. // and we don't want them to be called after this update_dirty() as they would mark the
  1721. // preset dirty again
  1722. // (not sure this is true anymore now that update_dirty is idempotent)
  1723. wxTheApp->CallAfter([this]{
  1724. // checking out if this Tab exists till this moment
  1725. if (!checked_tab(this))
  1726. return;
  1727. update_tab_ui();
  1728. on_presets_changed();
  1729. if (name() == "print")
  1730. update_frequently_changed_parameters();
  1731. if (m_name == "printer"){
  1732. static_cast<TabPrinter*>(this)->m_initial_extruders_count = static_cast<TabPrinter*>(this)->m_extruders_count;
  1733. const Preset* parent_preset = m_presets->get_selected_preset_parent();
  1734. static_cast<TabPrinter*>(this)->m_sys_extruders_count = parent_preset == nullptr ? 0 :
  1735. static_cast<const ConfigOptionFloats*>(parent_preset->config.option("nozzle_diameter"))->values.size();
  1736. }
  1737. m_opt_status_value = (m_presets->get_selected_preset_parent() ? osSystemValue : 0) | osInitValue;
  1738. init_options_list();
  1739. update_changed_ui();
  1740. });
  1741. }
  1742. //Regerenerate content of the page tree.
  1743. void Tab::rebuild_page_tree()
  1744. {
  1745. Freeze();
  1746. // get label of the currently selected item
  1747. auto selected = m_treectrl->GetItemText(m_treectrl->GetSelection());
  1748. auto rootItem = m_treectrl->GetRootItem();
  1749. auto have_selection = 0;
  1750. m_treectrl->DeleteChildren(rootItem);
  1751. for (auto p : m_pages)
  1752. {
  1753. auto itemId = m_treectrl->AppendItem(rootItem, p->title(), p->iconID());
  1754. m_treectrl->SetItemTextColour(itemId, p->get_item_colour());
  1755. if (p->title() == selected) {
  1756. if (!(p->title() == _(L("Machine limits")) || p->title() == _(L("Single extruder MM setup")))) // These Pages have to be updated inside OnTreeSelChange
  1757. m_disable_tree_sel_changed_event = 1;
  1758. m_treectrl->SelectItem(itemId);
  1759. m_disable_tree_sel_changed_event = 0;
  1760. have_selection = 1;
  1761. }
  1762. }
  1763. if (!have_selection) {
  1764. // this is triggered on first load, so we don't disable the sel change event
  1765. m_treectrl->SelectItem(m_treectrl->GetFirstVisibleItem());//! (treectrl->GetFirstChild(rootItem));
  1766. }
  1767. Thaw();
  1768. }
  1769. // Called by the UI combo box when the user switches profiles.
  1770. // Select a preset by a name.If !defined(name), then the default preset is selected.
  1771. // If the current profile is modified, user is asked to save the changes.
  1772. void Tab::select_preset(const std::string& preset_name /*= ""*/)
  1773. {
  1774. std::string name = preset_name;
  1775. auto force = false;
  1776. auto presets = m_presets;
  1777. // If no name is provided, select the "-- default --" preset.
  1778. if (name.empty())
  1779. name= presets->default_preset().name;
  1780. auto current_dirty = presets->current_is_dirty();
  1781. auto canceled = false;
  1782. auto printer_tab = presets->name().compare("printer")==0;
  1783. m_reload_dependent_tabs = {};
  1784. if (!force && current_dirty && !may_discard_current_dirty_preset()) {
  1785. canceled = true;
  1786. } else if(printer_tab) {
  1787. // Before switching the printer to a new one, verify, whether the currently active print and filament
  1788. // are compatible with the new printer.
  1789. // If they are not compatible and the current print or filament are dirty, let user decide
  1790. // whether to discard the changes or keep the current printer selection.
  1791. auto new_printer_preset = presets->find_preset(name, true);
  1792. auto print_presets = &m_preset_bundle->prints;
  1793. bool print_preset_dirty = print_presets->current_is_dirty();
  1794. bool print_preset_compatible = print_presets->get_edited_preset().is_compatible_with_printer(*new_printer_preset);
  1795. canceled = !force && print_preset_dirty && !print_preset_compatible &&
  1796. !may_discard_current_dirty_preset(print_presets, name);
  1797. auto filament_presets = &m_preset_bundle->filaments;
  1798. bool filament_preset_dirty = filament_presets->current_is_dirty();
  1799. bool filament_preset_compatible = filament_presets->get_edited_preset().is_compatible_with_printer(*new_printer_preset);
  1800. if (!canceled && !force) {
  1801. canceled = filament_preset_dirty && !filament_preset_compatible &&
  1802. !may_discard_current_dirty_preset(filament_presets, name);
  1803. }
  1804. if (!canceled) {
  1805. if (!print_preset_compatible) {
  1806. // The preset will be switched to a different, compatible preset, or the '-- default --'.
  1807. m_reload_dependent_tabs.push_back("print");
  1808. if (print_preset_dirty) print_presets->discard_current_changes();
  1809. }
  1810. if (!filament_preset_compatible) {
  1811. // The preset will be switched to a different, compatible preset, or the '-- default --'.
  1812. m_reload_dependent_tabs.push_back("filament");
  1813. if (filament_preset_dirty) filament_presets->discard_current_changes();
  1814. }
  1815. }
  1816. }
  1817. if (canceled) {
  1818. update_tab_ui();
  1819. // Trigger the on_presets_changed event so that we also restore the previous value in the plater selector,
  1820. // if this action was initiated from the platter.
  1821. on_presets_changed();
  1822. }
  1823. else {
  1824. if (current_dirty) presets->discard_current_changes() ;
  1825. presets->select_preset_by_name(name, force);
  1826. // Mark the print & filament enabled if they are compatible with the currently selected preset.
  1827. // The following method should not discard changes of current print or filament presets on change of a printer profile,
  1828. // if they are compatible with the current printer.
  1829. if (current_dirty || printer_tab)
  1830. m_preset_bundle->update_compatible_with_printer(true);
  1831. // Initialize the UI from the current preset.
  1832. load_current_preset();
  1833. }
  1834. }
  1835. // If the current preset is dirty, the user is asked whether the changes may be discarded.
  1836. // if the current preset was not dirty, or the user agreed to discard the changes, 1 is returned.
  1837. bool Tab::may_discard_current_dirty_preset(PresetCollection* presets /*= nullptr*/, const std::string& new_printer_name /*= ""*/)
  1838. {
  1839. if (presets == nullptr) presets = m_presets;
  1840. // Display a dialog showing the dirty options in a human readable form.
  1841. auto old_preset = presets->get_edited_preset();
  1842. auto type_name = presets->name();
  1843. auto tab = " ";
  1844. auto name = old_preset.is_default ?
  1845. _(L("Default ")) + type_name + _(L(" preset")) :
  1846. (type_name + _(L(" preset\n")) + tab + old_preset.name);
  1847. // Collect descriptions of the dirty options.
  1848. std::vector<std::string> option_names;
  1849. for(auto opt_key: presets->current_dirty_options()) {
  1850. auto opt = m_config->def()->options.at(opt_key);
  1851. std::string name = "";
  1852. if (!opt.category.empty())
  1853. name += opt.category + " > ";
  1854. name += !opt.full_label.empty() ?
  1855. opt.full_label :
  1856. opt.label;
  1857. option_names.push_back(name);
  1858. }
  1859. // Show a confirmation dialog with the list of dirty options.
  1860. std::string changes = "";
  1861. for (auto changed_name : option_names)
  1862. changes += tab + changed_name + "\n";
  1863. auto message = (!new_printer_name.empty()) ?
  1864. name + _(L("\n\nis not compatible with printer\n")) +tab + new_printer_name+ _(L("\n\nand it has the following unsaved changes:")) :
  1865. name + _(L("\n\nhas the following unsaved changes:"));
  1866. auto confirm = new wxMessageDialog(parent(),
  1867. message + "\n" +changes +_(L("\n\nDiscard changes and continue anyway?")),
  1868. _(L("Unsaved Changes")), wxYES_NO | wxNO_DEFAULT | wxICON_QUESTION);
  1869. return confirm->ShowModal() == wxID_YES;
  1870. }
  1871. void Tab::OnTreeSelChange(wxTreeEvent& event)
  1872. {
  1873. if (m_disable_tree_sel_changed_event) return;
  1874. // There is a bug related to Ubuntu overlay scrollbars, see https://github.com/prusa3d/Slic3r/issues/898 and https://github.com/prusa3d/Slic3r/issues/952.
  1875. // The issue apparently manifests when Show()ing a window with overlay scrollbars while the UI is frozen. For this reason,
  1876. // we will Thaw the UI prematurely on Linux. This means destroing the no_updates object prematurely.
  1877. #ifdef __linux__
  1878. std::unique_ptr<wxWindowUpdateLocker> no_updates(new wxWindowUpdateLocker(this));
  1879. #else
  1880. wxWindowUpdateLocker noUpdates(this);
  1881. #endif
  1882. Page* page = nullptr;
  1883. auto selection = m_treectrl->GetItemText(m_treectrl->GetSelection());
  1884. for (auto p : m_pages)
  1885. if (p->title() == selection)
  1886. {
  1887. page = p.get();
  1888. m_is_nonsys_values = page->m_is_nonsys_values;
  1889. m_is_modified_values = page->m_is_modified_values;
  1890. break;
  1891. }
  1892. if (page == nullptr) return;
  1893. for (auto& el : m_pages)
  1894. el.get()->Hide();
  1895. #ifdef __linux__
  1896. no_updates.reset(nullptr);
  1897. #endif
  1898. page->Show();
  1899. m_hsizer->Layout();
  1900. Refresh();
  1901. update_undo_buttons();
  1902. }
  1903. void Tab::OnKeyDown(wxKeyEvent& event)
  1904. {
  1905. if (event.GetKeyCode() == WXK_TAB)
  1906. m_treectrl->Navigate(event.ShiftDown() ? wxNavigationKeyEvent::IsBackward : wxNavigationKeyEvent::IsForward);
  1907. else
  1908. event.Skip();
  1909. }
  1910. // Save the current preset into file.
  1911. // This removes the "dirty" flag of the preset, possibly creates a new preset under a new name,
  1912. // and activates the new preset.
  1913. // Wizard calls save_preset with a name "My Settings", otherwise no name is provided and this method
  1914. // opens a Slic3r::GUI::SavePresetWindow dialog.
  1915. void Tab::save_preset(std::string name /*= ""*/)
  1916. {
  1917. // since buttons(and choices too) don't get focus on Mac, we set focus manually
  1918. // to the treectrl so that the EVT_* events are fired for the input field having
  1919. // focus currently.is there anything better than this ?
  1920. //! m_treectrl->OnSetFocus();
  1921. if (name.empty()) {
  1922. auto preset = m_presets->get_selected_preset();
  1923. auto default_name = preset.is_default ? "Untitled" : preset.name;
  1924. bool have_extention = boost::iends_with(default_name, ".ini");
  1925. if (have_extention)
  1926. {
  1927. size_t len = default_name.length()-4;
  1928. default_name.resize(len);
  1929. }
  1930. //[map $_->name, grep !$_->default && !$_->external, @{$self->{presets}}],
  1931. std::vector<std::string> values;
  1932. for (size_t i = 0; i < m_presets->size(); ++i) {
  1933. const Preset &preset = m_presets->preset(i);
  1934. if (preset.is_default || preset.is_system || preset.is_external)
  1935. continue;
  1936. values.push_back(preset.name);
  1937. }
  1938. auto dlg = new SavePresetWindow(parent());
  1939. dlg->build(title(), default_name, values);
  1940. if (dlg->ShowModal() != wxID_OK)
  1941. return;
  1942. name = dlg->get_name();
  1943. if (name == ""){
  1944. show_error(this, _(L("The supplied name is empty. It can't be saved.")));
  1945. return;
  1946. }
  1947. const Preset *existing = m_presets->find_preset(name, false);
  1948. if (existing && (existing->is_default || existing->is_system)) {
  1949. show_error(this, _(L("Cannot overwrite a system profile.")));
  1950. return;
  1951. }
  1952. if (existing && (existing->is_external)) {
  1953. show_error(this, _(L("Cannot overwrite an external profile.")));
  1954. return;
  1955. }
  1956. }
  1957. // Save the preset into Slic3r::data_dir / presets / section_name / preset_name.ini
  1958. m_presets->save_current_preset(name);
  1959. // Mark the print & filament enabled if they are compatible with the currently selected preset.
  1960. m_preset_bundle->update_compatible_with_printer(false);
  1961. // Add the new item into the UI component, remove dirty flags and activate the saved item.
  1962. update_tab_ui();
  1963. // Update the selection boxes at the platter.
  1964. on_presets_changed();
  1965. // If current profile is saved, "delete preset" button have to be enabled
  1966. m_btn_delete_preset->Enable(true);
  1967. if (m_name == "printer")
  1968. static_cast<TabPrinter*>(this)->m_initial_extruders_count = static_cast<TabPrinter*>(this)->m_extruders_count;
  1969. update_changed_ui();
  1970. }
  1971. // Called for a currently selected preset.
  1972. void Tab::delete_preset()
  1973. {
  1974. auto current_preset = m_presets->get_selected_preset();
  1975. // Don't let the user delete the ' - default - ' configuration.
  1976. wxString action = current_preset.is_external ? _(L("remove")) : _(L("delete"));
  1977. wxString msg = _(L("Are you sure you want to ")) + action + _(L(" the selected preset?"));
  1978. action = current_preset.is_external ? _(L("Remove")) : _(L("Delete"));
  1979. wxString title = action + _(L(" Preset"));
  1980. if (current_preset.is_default ||
  1981. wxID_YES != wxMessageDialog(parent(), msg, title, wxYES_NO | wxNO_DEFAULT | wxICON_QUESTION).ShowModal())
  1982. return;
  1983. // Delete the file and select some other reasonable preset.
  1984. // The 'external' presets will only be removed from the preset list, their files will not be deleted.
  1985. try{ m_presets->delete_current_preset(); }
  1986. catch (const std::exception &e)
  1987. {
  1988. return;
  1989. }
  1990. // Load the newly selected preset into the UI, update selection combo boxes with their dirty flags.
  1991. load_current_preset();
  1992. }
  1993. void Tab::toggle_show_hide_incompatible()
  1994. {
  1995. m_show_incompatible_presets = !m_show_incompatible_presets;
  1996. update_show_hide_incompatible_button();
  1997. update_tab_ui();
  1998. }
  1999. void Tab::update_show_hide_incompatible_button()
  2000. {
  2001. m_btn_hide_incompatible_presets->SetBitmap(m_show_incompatible_presets ?
  2002. m_bmp_show_incompatible_presets : m_bmp_hide_incompatible_presets);
  2003. m_btn_hide_incompatible_presets->SetToolTip(m_show_incompatible_presets ?
  2004. "Both compatible an incompatible presets are shown. Click to hide presets not compatible with the current printer." :
  2005. "Only compatible presets are shown. Click to show both the presets compatible and not compatible with the current printer.");
  2006. }
  2007. void Tab::update_ui_from_settings()
  2008. {
  2009. // Show the 'show / hide presets' button only for the print and filament tabs, and only if enabled
  2010. // in application preferences.
  2011. m_show_btn_incompatible_presets = get_app_config()->get("show_incompatible_presets")[0] == '1' ? true : false;
  2012. bool show = m_show_btn_incompatible_presets && m_presets->name().compare("printer") != 0;
  2013. show ? m_btn_hide_incompatible_presets->Show() : m_btn_hide_incompatible_presets->Hide();
  2014. // If the 'show / hide presets' button is hidden, hide the incompatible presets.
  2015. if (show) {
  2016. update_show_hide_incompatible_button();
  2017. }
  2018. else {
  2019. if (m_show_incompatible_presets) {
  2020. m_show_incompatible_presets = false;
  2021. update_tab_ui();
  2022. }
  2023. }
  2024. }
  2025. // Return a callback to create a Tab widget to mark the preferences as compatible / incompatible to the current printer.
  2026. wxSizer* Tab::compatible_printers_widget(wxWindow* parent, wxCheckBox** checkbox, wxButton** btn)
  2027. {
  2028. *checkbox = new wxCheckBox(parent, wxID_ANY, _(L("All")));
  2029. *btn = new wxButton(parent, wxID_ANY, _(L(" Set "))+dots, wxDefaultPosition, wxDefaultSize, wxBU_LEFT | wxBU_EXACTFIT);
  2030. (*btn)->SetBitmap(wxBitmap(from_u8(Slic3r::var("printer_empty.png")), wxBITMAP_TYPE_PNG));
  2031. auto sizer = new wxBoxSizer(wxHORIZONTAL);
  2032. sizer->Add((*checkbox), 0, wxALIGN_CENTER_VERTICAL);
  2033. sizer->Add((*btn), 0, wxALIGN_CENTER_VERTICAL);
  2034. (*checkbox)->Bind(wxEVT_CHECKBOX, ([=](wxCommandEvent e)
  2035. {
  2036. (*btn)->Enable(!(*checkbox)->GetValue());
  2037. // All printers have been made compatible with this preset.
  2038. if ((*checkbox)->GetValue())
  2039. load_key_value("compatible_printers", std::vector<std::string> {});
  2040. get_field("compatible_printers_condition")->toggle((*checkbox)->GetValue());
  2041. update_changed_ui();
  2042. }) );
  2043. (*btn)->Bind(wxEVT_BUTTON, ([this, parent, checkbox, btn](wxCommandEvent e)
  2044. {
  2045. // # Collect names of non-default non-external printer profiles.
  2046. PresetCollection *printers = &m_preset_bundle->printers;
  2047. wxArrayString presets;
  2048. for (size_t idx = 0; idx < printers->size(); ++idx)
  2049. {
  2050. Preset& preset = printers->preset(idx);
  2051. if (!preset.is_default && !preset.is_external && !preset.is_system)
  2052. presets.Add(preset.name);
  2053. }
  2054. wxMultiChoiceDialog dlg(parent,
  2055. _(L("Select the printers this profile is compatible with.")),
  2056. _(L("Compatible printers")), presets);
  2057. // # Collect and set indices of printers marked as compatible.
  2058. wxArrayInt selections;
  2059. auto *compatible_printers = dynamic_cast<const ConfigOptionStrings*>(m_config->option("compatible_printers"));
  2060. if (compatible_printers != nullptr || !compatible_printers->values.empty())
  2061. for (auto preset_name : compatible_printers->values)
  2062. for (size_t idx = 0; idx < presets.GetCount(); ++idx)
  2063. if (presets[idx].compare(preset_name) == 0)
  2064. {
  2065. selections.Add(idx);
  2066. break;
  2067. }
  2068. dlg.SetSelections(selections);
  2069. std::vector<std::string> value;
  2070. // Show the dialog.
  2071. if (dlg.ShowModal() == wxID_OK) {
  2072. selections.Clear();
  2073. selections = dlg.GetSelections();
  2074. for (auto idx : selections)
  2075. value.push_back(presets[idx].ToStdString());
  2076. if (value.empty()) {
  2077. (*checkbox)->SetValue(1);
  2078. (*btn)->Disable();
  2079. }
  2080. // All printers have been made compatible with this preset.
  2081. load_key_value("compatible_printers", value);
  2082. update_changed_ui();
  2083. }
  2084. }));
  2085. return sizer;
  2086. }
  2087. void Tab::update_presetsctrl(wxDataViewTreeCtrl* ui, bool show_incompatible)
  2088. {
  2089. if (ui == nullptr)
  2090. return;
  2091. ui->Freeze();
  2092. ui->DeleteAllItems();
  2093. auto presets = m_presets->get_presets();
  2094. auto idx_selected = m_presets->get_idx_selected();
  2095. auto suffix_modified = m_presets->get_suffix_modified();
  2096. int icon_compatible = 0;
  2097. int icon_incompatible = 1;
  2098. int cnt_items = 0;
  2099. auto root_sys = ui->AppendContainer(wxDataViewItem(0), _(L("System presets")));
  2100. auto root_def = ui->AppendContainer(wxDataViewItem(0), _(L("Default presets")));
  2101. auto show_def = get_app_config()->get("no_defaults")[0] != '1';
  2102. for (size_t i = presets.front().is_visible ? 0 : 1; i < presets.size(); ++i) {
  2103. const Preset &preset = presets[i];
  2104. if (!preset.is_visible || (!show_incompatible && !preset.is_compatible && i != idx_selected))
  2105. continue;
  2106. auto preset_name = wxString::FromUTF8((preset.name + (preset.is_dirty ? suffix_modified : "")).c_str());
  2107. wxDataViewItem item;
  2108. if (preset.is_system)
  2109. item = ui->AppendItem(root_sys, preset_name,
  2110. preset.is_compatible ? icon_compatible : icon_incompatible);
  2111. else if (show_def && preset.is_default)
  2112. item = ui->AppendItem(root_def, preset_name,
  2113. preset.is_compatible ? icon_compatible : icon_incompatible);
  2114. else
  2115. {
  2116. auto parent = m_presets->get_preset_parent(preset);
  2117. if (parent == nullptr)
  2118. item = ui->AppendItem(root_def, preset_name,
  2119. preset.is_compatible ? icon_compatible : icon_incompatible);
  2120. else
  2121. {
  2122. auto parent_name = parent->name;
  2123. wxDataViewTreeStoreContainerNode *node = ui->GetStore()->FindContainerNode(root_sys);
  2124. if (node)
  2125. {
  2126. wxDataViewTreeStoreNodeList::iterator iter;
  2127. for (iter = node->GetChildren().begin(); iter != node->GetChildren().end(); iter++)
  2128. {
  2129. wxDataViewTreeStoreNode* child = *iter;
  2130. auto child_item = child->GetItem();
  2131. auto item_text = ui->GetItemText(child_item);
  2132. if (item_text == parent_name)
  2133. {
  2134. auto added_child = ui->AppendItem(child->GetItem(), preset_name,
  2135. preset.is_compatible ? icon_compatible : icon_incompatible);
  2136. if (!added_child){
  2137. ui->DeleteItem(child->GetItem());
  2138. auto new_parent = ui->AppendContainer(root_sys, parent_name,
  2139. preset.is_compatible ? icon_compatible : icon_incompatible);
  2140. ui->AppendItem(new_parent, preset_name,
  2141. preset.is_compatible ? icon_compatible : icon_incompatible);
  2142. }
  2143. break;
  2144. }
  2145. }
  2146. }
  2147. }
  2148. }
  2149. cnt_items++;
  2150. if (i == idx_selected){
  2151. ui->Select(item);
  2152. m_cc_presets_choice->SetText(preset_name);
  2153. }
  2154. }
  2155. if (ui->GetStore()->GetChildCount(root_def) == 0)
  2156. ui->DeleteItem(root_def);
  2157. ui->Thaw();
  2158. }
  2159. void Tab::update_tab_presets(wxComboCtrl* ui, bool show_incompatible)
  2160. {
  2161. if (ui == nullptr)
  2162. return;
  2163. ui->Freeze();
  2164. ui->Clear();
  2165. auto presets = m_presets->get_presets();
  2166. auto idx_selected = m_presets->get_idx_selected();
  2167. auto suffix_modified = m_presets->get_suffix_modified();
  2168. int icon_compatible = 0;
  2169. int icon_incompatible = 1;
  2170. int cnt_items = 0;
  2171. wxDataViewTreeCtrlComboPopup* popup = wxDynamicCast(m_cc_presets_choice->GetPopupControl(), wxDataViewTreeCtrlComboPopup);
  2172. if (popup != nullptr)
  2173. {
  2174. popup->DeleteAllItems();
  2175. auto root_sys = popup->AppendContainer(wxDataViewItem(0), _(L("System presets")));
  2176. auto root_def = popup->AppendContainer(wxDataViewItem(0), _(L("Default presets")));
  2177. auto show_def = get_app_config()->get("no_defaults")[0] != '1';
  2178. for (size_t i = presets.front().is_visible ? 0 : 1; i < presets.size(); ++i) {
  2179. const Preset &preset = presets[i];
  2180. if (!preset.is_visible || (!show_incompatible && !preset.is_compatible && i != idx_selected))
  2181. continue;
  2182. auto preset_name = wxString::FromUTF8((preset.name + (preset.is_dirty ? suffix_modified : "")).c_str());
  2183. wxDataViewItem item;
  2184. if (preset.is_system)
  2185. item = popup->AppendItem(root_sys, preset_name,
  2186. preset.is_compatible ? icon_compatible : icon_incompatible);
  2187. else if (show_def && preset.is_default)
  2188. item = popup->AppendItem(root_def, preset_name,
  2189. preset.is_compatible ? icon_compatible : icon_incompatible);
  2190. else
  2191. {
  2192. auto parent = m_presets->get_preset_parent(preset);
  2193. if (parent == nullptr)
  2194. item = popup->AppendItem(root_def, preset_name,
  2195. preset.is_compatible ? icon_compatible : icon_incompatible);
  2196. else
  2197. {
  2198. auto parent_name = parent->name;
  2199. wxDataViewTreeStoreContainerNode *node = popup->GetStore()->FindContainerNode(root_sys);
  2200. if (node)
  2201. {
  2202. wxDataViewTreeStoreNodeList::iterator iter;
  2203. for (iter = node->GetChildren().begin(); iter != node->GetChildren().end(); iter++)
  2204. {
  2205. wxDataViewTreeStoreNode* child = *iter;
  2206. auto child_item = child->GetItem();
  2207. auto item_text = popup->GetItemText(child_item);
  2208. if (item_text == parent_name)
  2209. {
  2210. auto added_child = popup->AppendItem(child->GetItem(), preset_name,
  2211. preset.is_compatible ? icon_compatible : icon_incompatible);
  2212. if (!added_child){
  2213. popup->DeleteItem(child->GetItem());
  2214. auto new_parent = popup->AppendContainer(root_sys, parent_name,
  2215. preset.is_compatible ? icon_compatible : icon_incompatible);
  2216. popup->AppendItem(new_parent, preset_name,
  2217. preset.is_compatible ? icon_compatible : icon_incompatible);
  2218. }
  2219. break;
  2220. }
  2221. }
  2222. }
  2223. }
  2224. }
  2225. cnt_items++;
  2226. if (i == idx_selected){
  2227. popup->Select(item);
  2228. m_cc_presets_choice->SetText(preset_name);
  2229. }
  2230. }
  2231. if (popup->GetStore()->GetChildCount(root_def) == 0)
  2232. popup->DeleteItem(root_def);
  2233. }
  2234. ui->Thaw();
  2235. }
  2236. void Tab::fill_icon_descriptions()
  2237. {
  2238. m_icon_descriptions.push_back(t_icon_description(&m_bmp_value_lock, L("LOCKED LOCK;"
  2239. "indicates that the settings are the same as the system values for the current option group")));
  2240. m_icon_descriptions.push_back(t_icon_description(&m_bmp_value_unlock, L("UNLOCKED LOCK;"
  2241. "indicates that some settings were changed and are not equal to the system values for "
  2242. "the current option group.\n"
  2243. "Click the UNLOCKED LOCK icon to reset all settings for current option group to "
  2244. "the system values.")));
  2245. m_icon_descriptions.push_back(t_icon_description(&m_bmp_white_bullet, L("WHITE BULLET;"
  2246. "for the left button: \tindicates a non-system preset,\n"
  2247. "for the right button: \tindicates that the settings hasn't been modified.")));
  2248. m_icon_descriptions.push_back(t_icon_description(&m_bmp_value_revert, L("BACK ARROW;"
  2249. "indicates that the settings were changed and are not equal to the last saved preset for "
  2250. "the current option group.\n"
  2251. "Click the BACK ARROW icon to reset all settings for the current option group to "
  2252. "the last saved preset.")));
  2253. }
  2254. void Tab::set_tooltips_text()
  2255. {
  2256. // m_undo_to_sys_btn->SetToolTip(_(L( "LOCKED LOCK icon indicates that the settings are the same as the system values "
  2257. // "for the current option group.\n"
  2258. // "UNLOCKED LOCK icon indicates that some settings were changed and are not equal "
  2259. // "to the system values for the current option group.\n"
  2260. // "WHITE BULLET icon indicates a non system preset.\n\n"
  2261. // "Click the UNLOCKED LOCK icon to reset all settings for current option group to "
  2262. // "the system values.")));
  2263. //
  2264. // m_undo_btn->SetToolTip(_(L( "WHITE BULLET icon indicates that the settings are the same as in the last saved"
  2265. // "preset for the current option group.\n"
  2266. // "BACK ARROW icon indicates that the settings were changed and are not equal to "
  2267. // "the last saved preset for the current option group.\n\n"
  2268. // "Click the BACK ARROW icon to reset all settings for the current option group to "
  2269. // "the last saved preset.")));
  2270. // --- Tooltip text for reset buttons (for whole options group)
  2271. // Text to be shown on the "Revert to system" aka "Lock to system" button next to each input field.
  2272. m_ttg_value_lock = _(L("LOCKED LOCK icon indicates that the settings are the same as the system values "
  2273. "for the current option group"));
  2274. m_ttg_value_unlock = _(L("UNLOCKED LOCK icon indicates that some settings were changed and are not equal "
  2275. "to the system values for the current option group.\n"
  2276. "Click to reset all settings for current option group to the system values."));
  2277. m_ttg_white_bullet_ns = _(L("WHITE BULLET icon indicates a non system preset."));
  2278. m_ttg_non_system = &m_ttg_white_bullet_ns;
  2279. // Text to be shown on the "Undo user changes" button next to each input field.
  2280. m_ttg_white_bullet = _(L("WHITE BULLET icon indicates that the settings are the same as in the last saved "
  2281. "preset for the current option group."));
  2282. m_ttg_value_revert = _(L("BACK ARROW icon indicates that the settings were changed and are not equal to "
  2283. "the last saved preset for the current option group.\n"
  2284. "Click to reset all settings for the current option group to the last saved preset."));
  2285. // --- Tooltip text for reset buttons (for each option in group)
  2286. // Text to be shown on the "Revert to system" aka "Lock to system" button next to each input field.
  2287. m_tt_value_lock = _(L("LOCKED LOCK icon indicates that the value is the same as the system value."));
  2288. m_tt_value_unlock = _(L("UNLOCKED LOCK icon indicates that the value was changed and is not equal "
  2289. "to the system value.\n"
  2290. "Click to reset current value to the system value."));
  2291. // m_tt_white_bullet_ns= _(L("WHITE BULLET icon indicates a non system preset."));
  2292. m_tt_non_system = &m_ttg_white_bullet_ns;
  2293. // Text to be shown on the "Undo user changes" button next to each input field.
  2294. m_tt_white_bullet = _(L("WHITE BULLET icon indicates that the value is the same as in the last saved preset."));
  2295. m_tt_value_revert = _(L("BACK ARROW icon indicates that the value was changed and is not equal to the last saved preset.\n"
  2296. "Click to reset current value to the last saved preset."));
  2297. }
  2298. void Page::reload_config()
  2299. {
  2300. for (auto group : m_optgroups)
  2301. group->reload_config();
  2302. }
  2303. Field* Page::get_field(const t_config_option_key& opt_key, int opt_index /*= -1*/) const
  2304. {
  2305. Field* field = nullptr;
  2306. for (auto opt : m_optgroups){
  2307. field = opt->get_fieldc(opt_key, opt_index);
  2308. if (field != nullptr)
  2309. return field;
  2310. }
  2311. return field;
  2312. }
  2313. bool Page::set_value(const t_config_option_key& opt_key, const boost::any& value){
  2314. bool changed = false;
  2315. for(auto optgroup: m_optgroups) {
  2316. if (optgroup->set_value(opt_key, value))
  2317. changed = 1 ;
  2318. }
  2319. return changed;
  2320. }
  2321. // package Slic3r::GUI::Tab::Page;
  2322. ConfigOptionsGroupShp Page::new_optgroup(const wxString& title, int noncommon_label_width /*= -1*/)
  2323. {
  2324. //! config_ have to be "right"
  2325. ConfigOptionsGroupShp optgroup = std::make_shared<ConfigOptionsGroup>(this, title, m_config, true);
  2326. if (noncommon_label_width >= 0)
  2327. optgroup->label_width = noncommon_label_width;
  2328. #ifdef __WXOSX__
  2329. auto tab = GetParent()->GetParent();
  2330. #else
  2331. auto tab = GetParent();
  2332. #endif
  2333. optgroup->m_on_change = [this, tab](t_config_option_key opt_key, boost::any value){
  2334. //! This function will be called from OptionGroup.
  2335. //! Using of CallAfter is redundant.
  2336. //! And in some cases it causes update() function to be recalled again
  2337. //! wxTheApp->CallAfter([this, opt_key, value]() {
  2338. static_cast<Tab*>(tab)->update_dirty();
  2339. static_cast<Tab*>(tab)->on_value_change(opt_key, value);
  2340. //! });
  2341. };
  2342. optgroup->m_get_initial_config = [this, tab](){
  2343. DynamicPrintConfig config = static_cast<Tab*>(tab)->m_presets->get_selected_preset().config;
  2344. return config;
  2345. };
  2346. optgroup->m_get_sys_config = [this, tab](){
  2347. DynamicPrintConfig config = static_cast<Tab*>(tab)->m_presets->get_selected_preset_parent()->config;
  2348. return config;
  2349. };
  2350. optgroup->have_sys_config = [this, tab](){
  2351. return static_cast<Tab*>(tab)->m_presets->get_selected_preset_parent() != nullptr;
  2352. };
  2353. vsizer()->Add(optgroup->sizer, 0, wxEXPAND | wxALL, 10);
  2354. m_optgroups.push_back(optgroup);
  2355. return optgroup;
  2356. }
  2357. void SavePresetWindow::build(const wxString& title, const std::string& default_name, std::vector<std::string> &values)
  2358. {
  2359. auto text = new wxStaticText(this, wxID_ANY, _(L("Save ")) + title + _(L(" as:")),
  2360. wxDefaultPosition, wxDefaultSize);
  2361. m_combo = new wxComboBox(this, wxID_ANY, from_u8(default_name),
  2362. wxDefaultPosition, wxDefaultSize, 0, 0, wxTE_PROCESS_ENTER);
  2363. for (auto value : values)
  2364. m_combo->Append(from_u8(value));
  2365. auto buttons = CreateStdDialogButtonSizer(wxOK | wxCANCEL);
  2366. auto sizer = new wxBoxSizer(wxVERTICAL);
  2367. sizer->Add(text, 0, wxEXPAND | wxALL, 10);
  2368. sizer->Add(m_combo, 0, wxEXPAND | wxLEFT | wxRIGHT, 10);
  2369. sizer->Add(buttons, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 10);
  2370. wxButton* btn = static_cast<wxButton*>(FindWindowById(wxID_OK, this));
  2371. btn->Bind(wxEVT_BUTTON, [this](wxCommandEvent&) { accept(); });
  2372. m_combo->Bind(wxEVT_TEXT_ENTER, [this](wxCommandEvent&) { accept(); });
  2373. SetSizer(sizer);
  2374. sizer->SetSizeHints(this);
  2375. }
  2376. void SavePresetWindow::accept()
  2377. {
  2378. m_chosen_name = normalize_utf8_nfc(m_combo->GetValue().ToUTF8());
  2379. if (!m_chosen_name.empty()) {
  2380. const char* unusable_symbols = "<>:/\\|?*\"";
  2381. bool is_unusable_symbol = false;
  2382. bool is_unusable_postfix = false;
  2383. const std::string unusable_postfix = PresetCollection::get_suffix_modified();//"(modified)";
  2384. for (size_t i = 0; i < std::strlen(unusable_symbols); i++){
  2385. if (m_chosen_name.find_first_of(unusable_symbols[i]) != std::string::npos){
  2386. is_unusable_symbol = true;
  2387. break;
  2388. }
  2389. }
  2390. if (m_chosen_name.find(unusable_postfix) != std::string::npos)
  2391. is_unusable_postfix = true;
  2392. if (is_unusable_symbol) {
  2393. show_error(this,_(L("The supplied name is not valid;")) + "\n" +
  2394. _(L("the following characters are not allowed:")) + " <>:/\\|?*\"");
  2395. }
  2396. else if (is_unusable_postfix){
  2397. show_error(this,_(L("The supplied name is not valid;")) + "\n" +
  2398. _(L("the following postfix are not allowed:")) + "\n\t" + //unusable_postfix);
  2399. wxString::FromUTF8(unusable_postfix.c_str()));
  2400. }
  2401. else if (m_chosen_name.compare("- default -") == 0) {
  2402. show_error(this, _(L("The supplied name is not available.")));
  2403. }
  2404. else {
  2405. EndModal(wxID_OK);
  2406. }
  2407. }
  2408. }
  2409. } // GUI
  2410. } // Slic3r