* FIX: user preset sync token Change-Id: Id2aa865b778ee9ac4cfddb68ceef0374507b519b Jira: none * FIX: Bitmap cache not take effect Change-Id: I972098fdbda0b4542c6c759a8f5e1f0f2a30852b Jira: STUDIO-4991 * NEW: Open HotModel Link With GetParam-From bambustudio JIRA: NO JIRA Change-Id: I4ac49bac5ee0c50988c76a38b00b7ba7dc3201f5 * NEW:AmsMaterialsSetting Support for user-preset JIRA: STUDIO-5135 Change-Id: If848047cd5dbd059d440de30989c505c361305a7 * FIX: upload custom root preset fail Change-Id: I621c8d542dd604b07cc5df63d97d7a31558d3aba Jira: none * FIX: show custom filament in AMS filament list Change-Id: I79b9f8f2f08db8c52bbed76f1ea133baff383c00 Jira: none * FIX: dailytips window and gcodeviwer legend window size issue reset to original logic of dailytips and legend window size jira: new Change-Id: Iacb016bb222ba3f87317cfbe1f2b003802d773a5 * ENH: add text translation jira: new Change-Id: I780cfb8a0a64d806b5e0a414b6598e3b7bdf52dc * FIX: Delete and search object outside the plate JIRA: 1. STUDIO-5132 Deleting object outside the plate will crash 2. STUDIO-5146 The search function cannot search for object outside the plate Signed-off-by: Kunlong Ma <kunlong.ma@bambulab.com> Change-Id: I84cb3fe990a9c2a182e7434c262466a70545280e * FIX: [5149 5142 5141 5140 5136] create printer and filament issue Jira: 5149 5142 5141 5140 5136 5149 process preset name can not show all 5142 improt configs combobox not update 5141 disable modify filament_vendor 5140 disable input Bambu and Generic vendor 5136 preset list window adjust Change-Id: I111a23996146cc16cc7f533c8616d50223d34c40 Signed-off-by: maosheng.wei <maosheng.wei@bambulab.com> * ci: update build version to 01.08.00.54 Change-Id: Ifd69c01a82f627a9c6cf4fe0d48a759563ee90e7 * FIX: print model from sdcard with p1p Change-Id: If85383ba762022ead3dd754ae02a08817b891114 Jira: none * FIX: dailytips text translation jira: STUDIO-2556 Change-Id: If44e503615b09ee1692f42ba1f998918ec5bd691 * FIX: clone shortcut key conflict with quit in macos jira: STUDIO-5166 Change-Id: I548f275bb68d3b0e6bb3cfad6fe93df09d507da3 * FIX:User preset material settings dependent on firmware JIRA: 5167 Change-Id: I82cf26848594b01155883ad0aa2e9ee77d371fb2 * ENH:update the description of nozzle detection Change-Id: Id27b25c69dc11fcf66fc82053af705906ae8c370 * FIX: [5159 5165 5171 5172] create printer and filament issue Jira: 5159 5165 5171 5172 5159 create printer dialog no refresh 5165 create printer 2 step dialog no refersh 5171 change font 5172 edit filament dialog darkUI issue input special character is prohibited '/' in preset name translate to '-' update printer combobox Change-Id: I5fa27836dab7f604f1a065c65efa099c7a2f0f96 Signed-off-by: maosheng.wei <maosheng.wei@bambulab.com> * ci: update build version to 01.08.00.55 Change-Id: If1865d561cf274719204662314de163497759e89 * FIX:fix GLmodel deconstruction causing section not to be rendered Jira: STUDIO-5156 Change-Id: Ibb2f459920989ee54f7b827352dc8893424b4de6 * FIX: missing unlock cause device or resource busy Change-Id: I87563312ea9c6ce4e4e471da7ce7a02b53b64762 * FIX: some translation Change-Id: I9758cbc758030b5a3945697a50ca4898af9fcb1b * ci: update build version to 01.08.00.56 Change-Id: Id5ee53dd2ebb0b37b6927dc58b3cca94a1f66a83 * ENH: remove PLA GLOW in A1 mini jira:[NEW] Signed-off-by: xun.zhang <xun.zhang@bambulab.com> Change-Id: Id99c1bbd4248e28df9150a85eecec831f6f32856 * ci: update build version to 01.08.00.57 Change-Id: Ib4dfa60f097128b76b95bb14ca04978619021b56 * Allow line width of nozzle diameter * 2.5 As it were, 1 mm would be disallowed but 0.99 would be allowed for 0.4 nozzle. 1 mm is the sane maximum and 0.99 is unnecessary tedious to write. * Russian translation update Russian translation Bambu Studio_v1.8.0 Beta * FIX: scale problem in needs_retraction jira:[NEW] Signed-off-by: xun.zhang <xun.zhang@bambulab.com> Change-Id: Idfbe954b22fa6aa5769c55e46874fa6a80ecbf45 (cherry picked from commit 4e853f50b748e3af11e2d64862b6ee557fda361b) * ENH: CLI: support load_assemble_list JIRA: STUDIO-4848 Change-Id: Ife11533740988331ea71eac86c370e625970cb8b * FIX: align to Y not working This is a bug introduced in 7fbb650 when solving jira STUDIO-4695. Now we use a more decent way to solve it. Change-Id: I92deffcb9fe53e8a24c93fe973446ae37df07375 (cherry picked from commit bd98430dbd15eb6c9bb4b447990e0dcf8a50eef0) * ENH: Add buried points for cut and meshboolean JIRA: NONE Signed-off-by: Kunlong Ma <kunlong.ma@bambulab.com> Change-Id: I67ce498d0c335dd7a8582f56b880c2c8314f8541 * FIX: 5092 edit filament add scrolled window Jira: 5092 Change-Id: I53ae996b04e4e2f1b1ddce6a858d505001b11615 Signed-off-by: maosheng.wei <maosheng.wei@bambulab.com> * FIX: can not select user preset when create filament Jira: XXXX github: 1936 and fix add preset for printer dialog can not show selected printer Change-Id: Id4308c6bdca17d52d4aa321db359941aa87e0e45 Signed-off-by: maosheng.wei <maosheng.wei@bambulab.com> * ENH: template filament don't be show in filament list and sort Jira: 5160 5179 Change-Id: I56a7e1897e1ef3c061dc66d318896413ca25b76b Signed-off-by: maosheng.wei <maosheng.wei@bambulab.com> * FIX: [5174] export configs dialog issue filament name too long to can not show all Jira: 5174 Change-Id: I92018c9d7f86009b78b533592d899b4b5d78c3c8 Signed-off-by: maosheng.wei <maosheng.wei@bambulab.com> * ENH: add filament Bambu TPU 95A HF 1.As title jira:[NEW] Signed-off-by: xun.zhang <xun.zhang@bambulab.com> Change-Id: I752ec43da6297a6c172679997ce68f2318a7b8fb * ENH: modify some params with filaments 1.Modify the PEI bed temperature of PLA Basic, Matte, and Tough to 65 in A1 mini. Set the bed temperature for the first layer of Bambu PETG-CF to 65 and 70 for the other layers jira:[NEW] Signed-off-by: xun.zhang <xun.zhang@bambulab.com> Change-Id: Ia902bbb7f824082d5346709d781cac64296f47a8 * ENH: add more status during printing JIRA: STUDIO-5195 Change-Id: I85b3107839c6e2fdecbc10d90a876463e284468c Signed-off-by: Stone Li <stone.li@bambulab.com> * FIX:cut imgui has overlapping rendering on Apple Jira: STUDIO-5150 Change-Id: I7969e19dc189cd617026a183067dad628208955c * FIX:not TakeSnapshot for m_start_dragging_m Jira: STUDIO-5176 Change-Id: Ia03e3e2c2664dbdcffa19ec8d0fa97dfd95e6d35 * FIX: rendered color changes Jira: STUDIO-4956 during the drag processin connectors editing state Change-Id: I3027176ea9f93a9ba9d6a2052f41aaa4adef79f1 * FIX: merge the patch from Prusa Thanks for PrusaSlicer and YuSanka Jira:STUDIO-5175 commit 510d59687b3b19c4a0f4e6540620d0694dd1b7ac Author: YuSanka <yusanka@gmail.com> Date: Thu Oct 5 14:13:14 2023 +0200 Follow-up 1b451cdf: Fixed #11415 - Connectors disappear when slicing => only when using multiple cut planes AND excluding parts Change-Id: I9ccd5b85f482d723d21fccf5e104c9e0a9cc4849 * FIX:Press ESC directly to exit after entering the profile rendering rendering is not normal,Code from PrusaSlicer,thanks for PrusaSlicer and enricoturri1966 commit a078627552f54497ed0518dc7bc349d243576d19 Author: enricoturri1966 <enricoturri@seznam.cz> Date: Mon Jan 30 14:00:02 2023 +0100 Follow-up of 1218103fd620b319c56fd08116f81b581c537188 - Fixed gizmo missbehavior when closing a gizmo by resetting the selection clicking on the scene Jira: STUDIO-5164 Change-Id: I261da9dba2a5ac37f3e263c175fbccd80d8045bd * FIX: correct the strings and move create printer dialog center Jira: 5221 5183 Change-Id: Ida4eba63f0e962ffcc8000fcc04cf20849577217 Signed-off-by: maosheng.wei <maosheng.wei@bambulab.com> * ENH: CLI: skip layer height limit validate when slicing for existing models JIRA: no jira Change-Id: I1444a28b500ca7d08ed2606eecfa5cfaf261105e * ENH:update the translation of auto refill jira:[for translation] Change-Id: Iaa7b4f3d7cd88c8b4f69a3db721ebd8ca8986eea * FIX: icon issue for copying Jira: STUDIO-4168 Icon issue when filling bed with copies Change-Id: I61a03ecae02b75602c236ed2810e9c9cfe5a19f9 (cherry picked from commit b5079f8a2e79f19f65803f23ef4fd83aff17c84a) * ENH: update some filament params 1. Modify texture bed temp to 65 2. Modify max-v-speed for ABS 3. Modify some params in Generic PA 4. Modify PLA,PVA params jira:[NEW] Signed-off-by: xun.zhang <xun.zhang@bambulab.com> Change-Id: I42584a6015b8526f6bbb93024316968198bd76ce * FIX: 3770 printable checkbox incorrect display in darkUI Jira: 3770 Change-Id: I97f67d7a0ffc41f6ee625abeecc52ee4e73cf318 * FIX:Display garbled code in AmsMaterialsSetting pop-up Change-Id: I50531e939afa7715ae376bac47172ccf7b248114 * ENH:Modifying the Line Color of Transparent Materials JIRA: STUDIO-4311,5088,4983 Change-Id: I9e63413dc9cd7d523f0f7f1a2e32c4537a84467a * FIX: crash when async delete printer file Change-Id: I92c5e812d04da263338fb0eea2fd7583cf9ecde0 Jira: STUDIO-5222 * FIX: 3733 backup time not effective Jira: 3733 Change-Id: I50c2ce156fcbd0a17aa8a6777bce04aa6093c830 Signed-off-by: maosheng.wei <maosheng.wei@bambulab.com> * FIX: enable edit and delete preset btn and fix issue Jira: XXXX Change-Id: I724d7236b28fcc4746698f094531948a8fbb5d93 Signed-off-by: maosheng.wei <maosheng.wei@bambulab.com> * FIX:send print job,file name displays error JIRA:3137 Change-Id: I1c113025d274a13fba1b845a58aada14058fadd4 * FIX: skip hold user preset from sync Change-Id: I2252246e19bd80903ad82170782ea49535d30d05 Jira: STUDIO-5185 * FIX: 5115 translations Jira: 5115 Change-Id: I21b03bdd4d28c0bb097226143177e763cf8c777f Signed-off-by: maosheng.wei <maosheng.wei@bambulab.com> * FIX: add link for ironing parameter Change-Id: I451f5549db3ac2205aa5703a2e5edc831e946af8 * FIX: scale problem in lift type decide 1. Scale the travel threshhold jira:[NEW] Signed-off-by: xun.zhang <xun.zhang@bambulab.com> Change-Id: Ib594d640fe63b0919bc9318af88577513f7dbf30 * ENH: add small perimeter speed and threshold The original param is added by Prusa. Thanks orca for adding threshold. 1. Re add small perimeter speed and threhold. github: #2221 Change-Id: I35b269b26f085d80f0edca28650bb21fc04898d7 * FIX: modify the picture of pa manual cali Jira: STUDIO-5102 Change-Id: Id87898959ad4461b7bd2505b159271f2aa589c36 * FIX: Filament preset is the same with the first one Jira: STUDIO-4519 Filament preset is the same wit the first one, it should align with the last one. Signed-off-by: wenjie.guo <wenjie.guo@bambulab.com> Change-Id: I304d0ff0fbc1c8948d410ea552e4d42b6a4e8fd9 * FIX: scoreDailog dark mode issue Jira: 4570 Change-Id: I8be97b306a1494f73e3bba678ecc864e7ff88ca3 * FIX: CLI: fix the slicing issue while only one object with multicolor using seq-print JIRA: no-jira Change-Id: Iea2d23ff8e484bf2fd58aa2f596a8e4e4292fe39 * ENH: open support wall count for normal support 1. open support wall count for normal support Enabling this option makes normal support stronger and gives better overhang quality, but also more difficult to removal. Jira: STUDIO-5192 2. fix a bug where tree support (hybrid style) may get overlapped extrusions near the walls. 3. fix a bug where raft layers can't be 1 in tree support Jira: STUDIO-5261 Change-Id: Iadc0c67a9b50b5b221c8e83d5aa22ed282018cf8 (cherry picked from commit c0bb0084e386cb70ed6e16edf93190e4b38f5b90) * FIX: compiling error on linux jira: none Change-Id: I1a4563503b5ddf74a1979cc0cee7a15b8aced904 (cherry picked from commit de52c6ca62c9f3a6314ddf5a856c1d8534329886) * ENH: add translation for small perimeter jira:[NEW] Signed-off-by: xun.zhang <xun.zhang@bambulab.com> Change-Id: I95013649e4e0c07c0f04b89a91488814c8d228cc * FIX: clone shortcut key issue on macos jira: STUDIO-5166 Change-Id: I1967da1d443ed43bd750dad8e11560688d7bd533 * FIX: custom gcode window cannot paste/ navigate jira: STUDIO-5208、STUDIO-5070 Change-Id: I4ecb9d06cf5db0ae53a4678181aae9298bac106b * ENH: modify dailytips collapse & expand interaction jira: STUDIO-5209、STUDIO-5210 Change-Id: Ifb0b998e5004d4b49390ba5a250eaf4743bf3471 * ENH:Add shortcut keys and lists for objects search JIRA: STUDIO-5157 STUDIO-5158 STUDIO-5240 Signed-off-by: Kunlong Ma <kunlong.ma@bambulab.com> Change-Id: Ic7cfaaa9b4bb8a85208bafab7fe3bafdb78f0045 * FIX:Re-calculate button with White Box displayed in dark mode JIRA: STUDIO-5098 Signed-off-by: Kunlong Ma <kunlong.ma@bambulab.com> Change-Id: I07cc6c72d5dbd03b72573cd27dd5938bb0e6a29a * NEW: display plate index when printing a task JIRA: STUDIO-2689 display on the thumbnail of the current task Change-Id: I5f1f46c56e9d1e9120a66d491551908dfad099d6 Signed-off-by: Stone Li <stone.li@bambulab.com> * ENH:fixed incorrect path prefix jira:[for file path prefix] Change-Id: Ie9e3999f02b78272e528ceceb479e746d46a7e6c * FIX: thumbnail is not clear in dark mode JIRA: STUDIO-5087 Change-Id: Ie86493ed71b5554095927f061509a1f551758b61 Signed-off-by: wenjie.guo <wenjie.guo@bambulab.com> * FIX: translation Jira: XXXX Change-Id: Id03f0d704aa852632a907ea628d1277400112062 Signed-off-by: maosheng.wei <maosheng.wei@bambulab.com> * ENH: first nozzle change to 0.4 and nozzle change to mm Jira: XXXX Change-Id: I14defd36442dbd7008e46782b08415b6244224f1 Signed-off-by: maosheng.wei <maosheng.wei@bambulab.com> * ENH:editing_window_width's value is small on the laptop Jira: STUDIO-5238 STUDIO-5265 apply_selected_connectors should check_and_update_connectors_state Change-Id: I8c2c1c920cc4d197d1908815a3e62f4962335451 * FIX: fix new_bed_shape's calculation process Jira: STUDIO-5122 Change-Id: I5f3e6a301a297123af28692c90bef6759f425b06 * ENH:update some translations jira:[STUDIO-5262] Change-Id: Idb1d3586888043ac325f272bc7a2b788adb3e9e5 * FIX: edit text command resets object settings Jira: STUDIO-4655 Signed-off-by: wenjie.guo <wenjie.guo@bambulab.com> Change-Id: Iac25c4e40f1d0d32e6d1f40e62226cc22bc96042 * ci: update build version to 01.08.00.58 Change-Id: Iacfec02aa50c617e4c9fe566319b07b30d47dce1 * FIX: remove GetUserAgent Change-Id: I92886e1f0dcb091109231a10da8c19d51178e13b Jira: STUDIO-5205 * FIX: nozzle_diameter_map data structure adjustment Change-Id: Ifb724afc0fcf974e6d331e73ecac723107a102cf * ENH:add _A and _B for perform_with_groove Jira: STUDIO-5267 Change-Id: Iee3310dfa1cd8e6680310f0af0eff5c817490813 * ENH:is_equal for min_z and max_z Jira: STUDIO-5267 Change-Id: I9493883d8be9d44e26ddc9afe62b7e9eb09c5052 * ci: update build version to 01.08.00.59 Change-Id: Ie8ed29ccf5d6c94594eb2ab8b717416fbeace3bd * FIX:Image display unclear in light mode JIRA:5161 Change-Id: I134cc64a2af0dfff60c47d0ff09d78d9c0f86b3f * FIX:fix bugs of non manifold edge Jira: STUDIO-5267 Change-Id: I8ac9a2cf96da0bc07ee00b309e65611b92fd174d * ENH:nozzle type detection jira:[STUDIO-5246] Change-Id: Ic41a2161a0e41d23f56af93ad8ec34cc83ada0e3 * ENH: upadte P1S start gcode 1.turn on MC board fan by default on P1S jira:[NEW] Signed-off-by: xun.zhang <xun.zhang@bambulab.com> Change-Id: I5b2f7868e350942fb8b7baf7d429e22a0987184a (cherry picked from commit e866a575b6b7d9552f7412f84272f4b48dfc3961) * ENH: improve support style's tooltip jira: none Change-Id: I8ee858d7052f04ce7ea6b226a500c7d1bf8a482f (cherry picked from commit 665f31c4fcde22bd894cbb4a5fb160635947f2a4) * ENH: set layer range error to warning 1. If layer range exceeds maximum/minimum layer range in printer settings,pop up a window to warn jira:[NEW] Signed-off-by: xun.zhang <xun.zhang@bambulab.com> Change-Id: I0304ee790e557ecf967f355c171993d1f51b5057 * ENH: CLI: remove the warning of layer height JIRA: no jira Change-Id: Idaceee4f52611479fc3f4238d016d891b4dc8cd1 * FIX: the word search is not translated Jira: STUDIO-5224 The world search in the device panel is not translated. Signed-off-by: wenjie.guo <wenjie.guo@bambulab.com> Change-Id: Ia3d651c2159a3aad94e10cd0a6da98848f53ee2a (cherry picked from commit 4a46a0a4750d82d49c9523f4b668a1a00c41ed83) * FIX: Bitmap will flash when sending printing task Jira: STUDIO-5278 Signed-off-by: wenjie.guo <wenjie.guo@bambulab.com> Change-Id: Ib0c8710b8d5d6b98fad043c950f054aa35bea965 * ENH:display the euler angle of rotation plane Jira: STUDIO-5268 Change-Id: I6b7b431931d60f1a9a832908400417781798c472 * ci: update build version to 01.08.00.60 Change-Id: I1c15b5c6437554c43327cd6b537f7a5860dba5a0 * ENH:cancel EnterReturnsTrue for imgui in cut Jira: STUDIO-5269 Change-Id: I2832e1dccaf9755448debe7b2bd56426f90dfe0d * ci: update build version to 01.08.00.61 Change-Id: Ib03e664a20990322c788686550c491d0139d8237 * FIX: some translation problems jira:[NEW] Signed-off-by: xun.zhang <xun.zhang@bambulab.com> Change-Id: If9f2af53b4f0bfa9469e84bcba68cc182df4a473 * add: Ukrainian lang support for 1.8 * FIX: calibration selected preset is null in some case jira: STUDIO-5258 Change-Id: Iee63593c5f833c5a43e3b1d1c9ddb82f8c69569a * FIX: create filament issue Jira: 5296 5297 5295 5302 5311 5276 5296 create filament: list has same printer 5297 create filament: filament combobox has blank options 5298 edit filament: delete last preset prompt users 5302 create filament: filament combox has cili preset 5311 create filament: printer name too long to can not show all 5276 edit filament: PLA Aero filament type filter issue add prusa vendor Revised copy Change-Id: I5dcc615ce0951b1a9953fa12283f6090f5069045 * FIX: some translation Change-Id: Icb8614a0af18f96d15f3b97c17e0f6f708296847 * FIX:cancel is_equal for slicing function Jira: STUDIO-5267 Change-Id: I66d759aa2c968f8a28a6a5d8378929754f2db689 * FIX:UI stuck due to pop-up window with wrong chamber temperature JIRA: 5304 Change-Id: I1a49a7219b7a6f5700243704c348724e7930ce1a * FIX: allow input '+' and hide edit preset btn Change-Id: I97aec7c3ac4cc8b9d6c535f0126aaa1926553d86 * ENH: handle printer direct close and not retry Change-Id: I5dd55f8085cf6383a8420ab41e614ea6ae210c78 Jira: STUDIO-5305 * ci: update build version to 01.08.00.62 Change-Id: I09716bf79354b503197c751272fd3171e0abc8fd * add: new translation to ukr for AirFlow and Prusa * add: Texture Plate name fix * FIX:add slice_facet_for_cut_mesh api for cut tool and modify section_vertices_map 's traverse Jira: STUDIO-5267 Change-Id: Ifc4b183a4e4c4fdb4f47742f14f70a1ed93fa056 Change-Id: I52bfaef8926ef967b78a6cb712a1731a1b528a24 * FIX: Make the front smaller for Czech in device panel Jira: STUDIO-5151 Signed-off-by: wenjie.guo <wenjie.guo@bambulab.com> Change-Id: I315174b55f923da069854fb4fed8cf3937b82074 * FIX: there is no object can be jumped to in notification jira: new Change-Id: Ib81bf49236952ede24a2de126051572d63916e01 * FIX: add height range, modifier in Preview pane will crash jira: STUDIO-5340 1. fix crash at add height range, modifiers in Preview from objectList 2. fix an assert hit when slicing 3. fix an assert hit when enter AssembleView 4. forbidden popup menu by right-click objectList in Preview Change-Id: I444bc76b1a4307999b387e4f60386b2d272bd308 * FIX: Black spot in the sending printing task page Jira: STUDIO-5307 Signed-off-by: wenjie.guo <wenjie.guo@bambulab.com> Change-Id: I3bd97c063ec5f0faf7d12047da39f60ce55cae4b * FIX: reset_cut_by_contours should update_buffer_data Jira: STUDIO-5376 Change-Id: I5aacb1f7b65822031d7138abd61a45b09c743531 * ENH:editing_window_width's value is small on the laptop Jira: STUDIO-5238 STUDIO-5265 Change-Id: Ia958772bcb081817da621115f99328bb62770cd5 * ENH: bumped version to 1.8.1 Change-Id: I9d25403daa5b7b8ca415c0b364670da9e0f932b0 * FIX: create filament dialog: create btn can not show all Jira: 5310 5331 Change-Id: I185272c90d9ff1c3d6b47abbefbf488d0d965cca * FIX:update custom_texture when new_shape=false Jira: STUDIO-5287 Change-Id: I3add95f9f9345c14a48cc7467513d1b3ce95f4c9 * ENH:editing_window_width's value is small on the laptop Jira: STUDIO-5238 Change-Id: I9044129f4e0c8ca7469db05b3e547fca4754342a * FIX:add slash_to_back_slash for saving file path Jira: STUDIO-5287 Change-Id: I9f3c176cd0831c793958f08601c63efac98176a4 * FIX: a button color didn't response to dark mode change jira: STUDIO-5315 Change-Id: I95489f01ccd1f77b9e95b0d0f69e5398d2e88487 * FIX: height range layers displayed in wrong position jira: STUDIO-5341 Change-Id: I83918b4624f367efa54321f1898e1176cdb04ea9 * FIX: auto arranging issues with locked plates 1. global auto arranging may put items overlap with wipe tower if some plates are locked jira: STUDIO-5329 2. items outside bed may overlap with plate boundary if it's rotated jira: STUDIO-5329 3. plate-wise auto arranging uses wrong min_obj_distance if the plate is by-layer printing but global setting is by-object printing jira: STUDIO-5330 Change-Id: I5dba2f1317e183c9aeec1cb2bd227fbddf4316e6 (cherry picked from commit db1eac41efff5f1e8d5ac0af74c6fc7ab59fc253) * FIX: a mistake in upward machine jira:[NEW] Signed-off-by: xun.zhang <xun.zhang@bambulab.com> Change-Id: Ibdb26c3d904634f322aef0dc0c7b8867d9fb5854 * FIX:a blank pop-up appears JIRA:XXXX Change-Id: Ice92b55204e4897fec024a6d99412eb810bddd4a * FIX:fixed failure in updating nozzle type jira:[STUDIO-5248] Change-Id: Iad37b5d5b76d37cb1723ef21d7c39b1e3fcaf8d7 * FIX:fixed issue with AI monitoring settings jira:[STUDIO-5082] Change-Id: I967fe3c1e9da61a55bcbfaa2a8e067dd5af18f72 * FIX:fixed issue with lan mode jira:[STUDIO-5189] Change-Id: I1d0a05f19dcea154cf3ef2b61ed0546d3581905e * FIX:update text for loading or unloading filaments jira:[STUDIO-5231] Change-Id: Ic7729c3ec012485b3d87e3d01f11e87502c67895 * FIX: Revert "ENH: do not leave a gap for top... Revert "ENH: do not leave a gap for top interface if the top z distance is 0" This reverts commit 79ea32c7cbbdb7e689637980af7c36caf42284c9. Revert reason: the supports are impossible to remove in some cases. jira: STUDIO-5385 Change-Id: I376a6f4dfd78da6dfea68b9ac3d552cddd0b4272 (cherry picked from commit 34e38b705fde7f5d7f9a3a89c96a3627ce0c998e) * ENH: improve normal support's quality 1. Add a base_interface_layer when using Supp.W 2. Fix a bug where base_angle and interface_angle are wong jira: STUDIO-5386 Change-Id: I52ab32c63b3cd1e6e2ba6463b01ae26699cf13d3 (cherry picked from commit 92ddd4a10b793572a1fa009da5b9e44fcdf81de2) * NEW:tracking stl model files jira:[STUDIO-5372] Change-Id: Idb1275b07441f0cd06c24588d5f7c20f81f1556c * FIX: edit filament dialog: preset name too long to del btn nan't show Jira: 5336 5174 and verify string normalization Change-Id: I380c3bed2bf43d01094b68979a8b67f4187c0b93 * FIX: some translation Jira: 5232 5300 5334 Change-Id: Ie474ca823011e81aab82a9809af3d6e42980496b * FIX: some translation Change-Id: Iaabe6087bed3b7d47d911cf4fb51c770804e72fb * ENH: change default tree_support_wall_count to 0 Now normal support also uses this option, so we can't default it to 1, otherwise normal supports will be too hard to remove. jira: none Change-Id: Ic5700af5c17e3a7b265c8915f28b0db35c6e06e6 (cherry picked from commit 6b84a9826da108b76569e686bd9def0b23ae29fd) * FIX:The name of the material in the error prompt is empty JIRA:STUDIO-4907 Change-Id: I3cf44f099256a51f21a44a89c89c000f734d1f36 * ci: update build version to 01.08.01.51 Change-Id: Ib20f5a12b65472102befec0a2adf82744fc29c46 * FIX: imgui textinput cannot paste on macos jira: STUDIO-5070、STUDIO-5365 Change-Id: Iea8f41e12744ecda0fbb95c1a8f2e014a7cdc384 * FIX: not cache printer file list on error Change-Id: I99843aedbf14d3d1d553ccac9b0bd26403274a82 Jira: none * FIX: thread of close BBLUserPresetExceedLimit notify Change-Id: I9698134ba1cc91fc83eac441f900d68c4c4b556a * ENH: Resolve non manifold edges by fixing model interfaces Jira: STUDIO-5124 Change-Id: I7ea86be44acb80b6c4762a76208b4a031acd0b27 * FIX:nozzle type sync jira:[STUDIO-5248] Change-Id: I63d48628832473d8d371ed643dc8528b00382531 * FIX: array bound happen in TriangleSelector::deserialize Jira: STUDIO-5170 Change-Id: I92b72a887845b462fad208f13607293b44d3d333 * FIX:cropping rendering without considering assembly views Jira: STUDIO-5260 Change-Id: Ia56cf80b305ae05f25f06ec277f85b3c5430a6df * FIX: PA for custom filament not available in BL Studio github: 2971 Change-Id: I6ccd36a183e7367d69557300f7242f5403f4bb33 * FIX: Bitmap is way too small on Mac Jira: STUDIO-5393 Signed-off-by: wenjie.guo <wenjie.guo@bambulab.com> Change-Id: I6b550669fa8cd5fc9bfa6ed96d64d19a949f01b2 * FIX: move shutdown wait to OnExit Change-Id: I70d9a2bb686525ae5273aa9d63e25691da4ab65c Jira: STUDIO-2884 * FIX: calibration manage result dialog issue on macos jira: STUDIO-4949 STUDIO-5378 Change-Id: I00abefd45a0d274a4b68bb1ab18debe8f91d169e * FIX: adjust bed shape dialog button UI style fix that button text is hard to see in dark mode jira: STUDIO-5247 Change-Id: I2cf5b3cdd2eff9b821bdf5525bec4f329fc58dd1 * FIX: 5331 rescale btn Jira: STUDIO-5331 Change-Id: If153424b8480e64b166018e3cd98c17db557d0a8 Signed-off-by: maosheng.wei <maosheng.wei@bambulab.com> * FIX: support do not generate jira:[NEW] Signed-off-by: xun.zhang <xun.zhang@bambulab.com> Change-Id: Ide9709d95203185538e280517f7aa6136beeda44 * FIX: remove not match printer config ota cache Change-Id: Ib73fc2ea31fa2186061cfcb5a170bc59b9db84ca Jira: none * FIX:cancel the variable of "checkbox_size" as a fixed value Jira: STUDIO-5150 Change-Id: I30d876d141b8b35ab4a3fee4889993d87b7c1741 * ENH:add reset_cut_by_contours in on_load function Jira:STUDIO-5269 m_connector_size_tolerance default value is 0.1f Change-Id: I6c67fff3cb0c1190e9141ed6f68fbfa848679f35 * ENH:cancel EnterReturnsTrue for imgui in cut Jira: STUDIO-5269 Change-Id: Ifc4b183a4e4c4fdb4f47742f14f70a1ed93fa056 Signed-off-by: zhou.xu <zhou.xu@bambulab.com> * FIX: dailytips should not change content frequently when slicing all jira: STUDIO-5234 Change-Id: Icb7e9c28404d9db8ebed58d937e13f89c5403b5c * FIX: objectList clone shortcut key issue jira: new Change-Id: Ia75bf58a7d53f962e1af6c2fd97497270b7eea84 * ENH:handling cases without msgs jira:[STUDIO-5401 STUDIO-5399] Change-Id: Iae651d5a19a45b0138a6aa621326a8b4a9649824 * ENH: optimize param description jira:[NEW] Signed-off-by: xun.zhang <xun.zhang@bambulab.com> Change-Id: Id0ca9224227a716b21fc0b8430722264dc319344 * ENH: add translation jira:[NEW] Signed-off-by: xun.zhang <xun.zhang@bambulab.com> Change-Id: I3b1f04fee3cd6322793794ad8b8707859f6c7d26 * FIX: close edit preset paramsDialog, mac unresponsive Jira: 5298 Change-Id: I021e00567354cfb1f2f5f1f2bf6ba1fc35b164c5 * ENH:disable AI monitoring on the p1p series Change-Id: I514bb1fb1ced6c03dd619230a9adac3be63f2de2 * ci: update build version to 01.08.01.52 Change-Id: I9f5e30d3fc4b7ef9321c522d3c18fce98f03742f * FIX: close edit preset paramsDialog, mac unresponsive Change-Id: Ic816754a20b7f6a5cdb46475750eb301fec3ad3a * FIX: organic support not work with raft only There is no raft generated when only raft enabled but no support needed. jira: none Change-Id: Ic0c9269e2f98038d85c9bc54e4a85f892dc5d764 * FIX: CLI: add object config when assemble JIRA: no jira Change-Id: I945f820fb58f2f643170b4b0b66742f6bbbdfd29 * FIX: delete preset prompt Jira: XXXX Change-Id: I6511c806c56393d4f6bd72d1c506da59675d49ff * FIX:Reorganize the assignment of variables of "m_editing_window_width" Jira: STUDIO-5238 Change-Id: If369916f3f5c21510f5f297bfd05c1230bdda7a4 * ENH: CLI: re-compute flush_volumes_matrix when it is missed Change-Id: Ie8f53c6bef003b1434de02ea14de5787b376484f * FIX: some translation for delete filament Change-Id: Ib46a8eba33f2e21016476aaab4a57a740e86b1b8 * FIX: scrolled window / del preset / edit filament issue Jira: 5092 GitHub: 1936 edit filament: just one preset, the scroll bar obscures the preset name edit filament: delete selected preset, click no, but preset be deleted from UI edit filament: serial sometimes displays incorrectly Change-Id: Ibc91609e252179de0c05ca065099756da6631165 * ci: update build version to 01.08.01.53 Change-Id: I5563a2c0812ab9a0d7727df27e17e681066ffa08 * FIX: mistake in filament vendor jira:[NEW] Signed-off-by: xun.zhang <xun.zhang@bambulab.com> Change-Id: I3af712e417379d8b98ae18feebffe465bfa1e72d * NEW:set customized materials for the A1 P1 series Change-Id: I9c34f62867c074bf9ebb315013e5e40526e0eac7 * ci: update build version to 01.08.01.54 Change-Id: I579dcee428417ae7e7f7a96bd315a7066d72d974 * FIX: the flow rate ratio crashes after load model for third party printer Jira: 5244 Change-Id: Idd829c9d99eeba9d180653ac8de4e51b9a0d6370 * FIX: The maximum value is not printed in PA line mode Jira: 5046 4951 Change-Id: Ic81f9a75ce7f088fe950fdde283ff5c942cd6e83 * ENH:add preset check for sending files Change-Id: Ia3313d281b5ce91e277b380498014ffdac5debd3 * ci: update build version to 01.08.01.55 Change-Id: Ia839344d01a43f7159f376d4147337575c4edbe1 * FIX: locale loading user preset Change-Id: I88521e4b10cb802d9253eb79a6b78b3286f15a33 Jira: STUDIO-5436 * FIX: sync user preset notify crash on exit Change-Id: I88f5dbcbd487293ea847ea6092efb61744399541 Jira: STUDIO-5413 * ci: update build version to 01.08.01.56 Change-Id: Id7a9718d5f920da50d52fd2ef220acf5d3270d3c * GUI/Field: Fix crash in color picker init (#2220) wxButton->GetBitmap() may return an invalid wxBitmap. Guard against this. * FIX: custom filament preset display in cali history issue jira: new Change-Id: I4145450a231adff542ab1a7428b3479f4074e06a * FIX: meshboolean transform result issue jira: STUDIO-5425 Change-Id: If66fe909ce4458c1b3192e4fd8a3d758fe7c7eaa * FIX: fix combobox and delete btn in filament setting enabled Jira: XXXX Change-Id: I8b659bd77ceb97c8cea9d3e5e931f4ea50822721 * ci: update build version to 01.08.01.57 Change-Id: I7a6f5439863ca81275ae8b80f1b5cf0bb36c4c0f * unix: Use canonical mime-type for 3MF files model/3mf is the canonical mime-type, but keep the application/vnd.ms-3mfdocument alias. See for details: https://gitlab.freedesktop.org/xdg/shared-mime-info/-/merge_requests/179 * FIX: fix the compiling issue under windows github: https://github.com/bambulab/BambuStudio/issues/3028 Change-Id: Iafde9d2086c0cd31aa12e39cef7ded1e19e9d3e7 * add: K1 and K1Max Support * fix: Optimized STL and PNG for plates K1 & K1Max * fix: simple version of models * FIX: Close scan_first_layer when PA line cali Jira: XXXX Change-Id: Ide5c0038f4028b8f1d445a6b2d09b705d7872fb8 * FIX: CLI: fix the wipe tower disappear issue JIRA: no jira Change-Id: I547a8468b0bea06912d5d9ceee1c8deead85e28f * FIX: the preset is the same with the first one when switching printers Jira: STUDIO-5433 Signed-off-by: wenjie.guo <wenjie.guo@bambulab.com> Change-Id: Icf1979f2bcffbc9c59a072924df5073fc3eac363 * FIX: [5504] Optimization description Jira: 5540 Change-Id: I9379f2c69b6724ec1ef5294dd3c404b0e3189486 * FIX: [5451]Directly crash when memory is low Jira: 5451 Change-Id: I5c75994e2bd556bec7ce8de6be44888e6924ff56 * ci: update build version to 01.08.01.58 Change-Id: I12b1e3ca6b07ed13f3ad42ab2f40b825cb84a8dc * ENH: CLI: refine some logic 1. set wipe tower position to default when duplicate object 2. add cli_safe check logic when switch printers JIRA: no jira Change-Id: Iebe62f8be6acd6f44743abf3b0fe92ec04c94197 * ENH: CLI: allow height shrink when printer switch to let the error generated at validate JIRA: no jira Change-Id: I94db90db858659a9254dfdc0a6eed04fd40d3768 * ENH: add support for A1 jira:[NEW] Signed-off-by: xun.zhang <xun.zhang@bambulab.com> Change-Id: I5dfd8f3b6b872c01d8093527df1a3c37b8a0d56d * ENH: refine description of interface not for base jira:[NEW] Signed-off-by: xun.zhang <xun.zhang@bambulab.com> Change-Id: Ibe11e845b90ef2caf96d5780eaaf8764755cce1d * ENH: version: bumped to 1.8.2 Change-Id: Ic9acb5607ec94188112999afa41f2052281a08f1 * ENH: update some machine settings 1. Update A1 mini start gcode 2. Update A1 load/unload filament time jira:[NEW] Signed-off-by: xun.zhang <xun.zhang@bambulab.com> Change-Id: I84825a47f2741e95ca122382e4119d35a61bdbf6 * ENH: support for head wrap detect 1.Add "in_head_wrap_detect_zone".Detect if the model projection enters a specified area. jira:[NEW] Signed-off-by: xun.zhang <xun.zhang@bambulab.com> Change-Id: I6aed5a782d2f33f023bdc19cf06dff0957828eeb * ENH: modify default head detect zone 1. Set default head detect to empty jira:[NEW] Signed-off-by: xun.zhang <xun.zhang@bambulab.com> Change-Id: I686c4c3115041471bc016cf3b0972ed730af64d3 * ENH: change head wrap detect zone Change to (156,156)-(180,180) jira:[new] Signed-off-by: xun.zhang <xun.zhang@bambulab.com> Change-Id: I7b9dec3fbf44d31311fd7eb331e52f307f45ede1 * FIX:backup iterator location Jira: STUDIO-5267 Change-Id: Id035c9225a858bb551aa4f09870fc4c6bb30b255 * NEW:compatible with p1p (plus) jira:[p1p] Change-Id: I7b30903dc0a728604c4f33c325aa79fd3bd08f68 * NEW:installed & supported p1p(plus) jira:[pip plus] Change-Id: I0a69f8629749e3076465b85f28aa39d5e7ae6277 * ENH: modify default head wrap detect zone jira:[NEW] Signed-off-by: xun.zhang <xun.zhang@bambulab.com> Change-Id: I39ccc810a19192919a21b5608d3fa2a806c787ee * FIX: excpetion when plate center is negative jira:[NEW] Signed-off-by: xun.zhang <xun.zhang@bambulab.com> Change-Id: Ia1066bd7457181711d0a59b9544d65ed502410e0 * FIX: big window's scaling causes incomplete display Jira: STUDIO-5530 Change-Id: I1d69e60658e49e43d4b3de718f2fd6739bab73ce * ENH: update: remove the comment which is not used when updating preset JIRA: no jira Change-Id: Ic930eea50a7beb78aa6dc7c53fbb5c366857e825 (cherry picked from commit e0225fc147702cf73e6eda4830a2592c7598901c) * FIX: wrong initial layer height in profile jira:[NEW] Signed-off-by: xun.zhang <xun.zhang@bambulab.com> Change-Id: I91f1779761a13f70d68ad51041b7f75ef872c138 * NEW:add N2S picture and printers JIRA: XXXX Change-Id: Id8eddd9fafd07c967abfb1543c1b01ad8c0e1b0c * ENH: rearrange machine pos on printer selection page Signed-off-by: qing.zhang <qing.zhang@bambulab.com> Change-Id: Iccc52043c232d19384487884e4071343744976a9 * ci: update build version to 01.08.02.51 Change-Id: I1985730c4ea29528a6f9b03f56c73131a07779b0 * ENH: some translations Jira: STUDIO-5434 Signed-off-by: wenjie.guo <wenjie.guo@bambulab.com> Change-Id: Ie6868728edfc40bd1d20dec6a78d8e5ea7f8edf8 * ENH: do not cancel printing job when timeout JIRA: STUDIO-5009 Change-Id: I067470173acc26d7ecd8ceb6f0e04ac7f03e3a4d Signed-off-by: Stone Li <stone.li@bambulab.com> (cherry picked from commit 7ab5817c7229c5179adca026ffacb97c2affd292) * ENH: udpate A1 series gcode 1. Update A1 mini change layer gcode 2. Update A1 start gcode jira:[NEW] Signed-off-by: xun.zhang <xun.zhang@bambulab.com> Change-Id: I131676a991f4727bca1ea2fa727f40f293d06139 * ENH:After cutting,fix non manifold edges needed confirmed by user Jira: STUDIO-5217 Change-Id: I52ba0db27ebe0b7b763c49311c7aa305bc4dcd5a * ENH: linux: refine the d-bus name github: #3075 Change-Id: Icf997f4f9203f4d429e3b6058d6d6e5f23bf29ac (cherry picked from commit 5c766bff445cefee488ba9d057121b04c8e1445d) * NEW:add "bed type to follow machine preset" function Jira: STUDIO-5535 Change-Id: I2ef99a0a783a074d9379685adde11fddfd6f8cec * NEW:add "default_bed_type" Jira: STUDIO-5535 Change-Id: Ice1262937923b62854b0196229d5fb99392470af * ENH:comment out two line code Jira: STUDIO-5535 Change-Id: I5475e4f9ec6fb7e4abdb3d950da34fadead3b606 * ENH:translate three texts Jira: STUDIO-5535 Change-Id: I00938567f0ae30bb354042769021451364bef308 * FIX: incorrect flag in A1 mini gcode jira:[NEW] Signed-off-by: xun.zhang <xun.zhang@bambulab.com> Change-Id: If587678bf0aa06c079a9d3cbff9f2c7628c5e380 * ci: update build version to 01.08.02.52 Change-Id: I2d8310b7321fefcb742d4cdbe5e4bc9a035ec45a * FIX: Allow vendors that are not entirely numerical github: #3082 Change-Id: I318f4df7f65c934ab6703e0970d775b754b24276 * ENH: update A1 series first layer speed jira:[NEW] Signed-off-by: xun.zhang <xun.zhang@bambulab.com> Change-Id: I597bcf86f202f681eccfda4306be5619d669ea5a * FIX: CLI: fix the wipe tower issue while mapping to one filament JIRA: STUDIO-5550 Change-Id: I0b8d3af09d16bdfc45cdc5951d182f7e33dc9b93 * FIX: crash when support type and style are inconsistent jira: STUDIO-5428 Change-Id: Ib1e79c71736810099e15282c30524e55e8f60f34 (cherry picked from commit aefb7fbaf25146c03bd2eb336f58ed2eb0e83ea6) * NEW:display beta version JIRA: XXXX Change-Id: I78d748e53b266c3397b1c038c3425a52c573cc88 * FIX: slice error: WipeTowerIntegration::append_tcr when print by object with multi-color Jira: XXXX Change-Id: Ic9ee2f6de45abb4a118fdb4cf89dea9ca7335094 * ci: update build version to 01.08.02.53 Change-Id: I980bff783b59fc6e9d6fd12a016c2daa2840991f * FIX: remove duplicated profiles jira:[NEW] Signed-off-by: XunZhangBambu <xun.zhang@bambulab.com> Change-Id: Iaa87233ae6c327faf43a152bdb0cd6fa8c5131d7 * FIX: translation: vendor can not be number Jira: XXXX Change-Id: I7bd45de944e8b25b30c88ab742b35d996c933966 * ci: update build version to 01.08.02.54 Change-Id: Ib83b131c533a03d6e48e9ded5e6f9ba574819756 * ENH: update A1 extruder clearance radius jira:[NEW] Signed-off-by: XunZhangBambu <xun.zhang@bambulab.com> Change-Id: I13cfb882c672083dcd1af2c1be448c5422fdbc0a * ci: update build version to 01.08.02.55 Change-Id: I8d7016d27166b457e4cdc198b61e6aa36a72b8c1 * FIX: bed_type not follow machine preset Jira: STUDIO-5578 when direct open project from https://makerworld.com/ Change-Id: I3281cf45e3057d766008487975b4585d2e277110 * ci: update build version to 01.08.02.56 Change-Id: I43cadeeb1a2fa150fa9396a63b9bc471da1500d5 * update strings * autofix mesh after cut --------- Signed-off-by: Kunlong Ma <kunlong.ma@bambulab.com> Signed-off-by: maosheng.wei <maosheng.wei@bambulab.com> Signed-off-by: xun.zhang <xun.zhang@bambulab.com> Signed-off-by: Stone Li <stone.li@bambulab.com> Signed-off-by: wenjie.guo <wenjie.guo@bambulab.com> Signed-off-by: zhou.xu <zhou.xu@bambulab.com> Signed-off-by: qing.zhang <qing.zhang@bambulab.com> Signed-off-by: XunZhangBambu <xun.zhang@bambulab.com> Co-authored-by: chunmao.guo <chunmao.guo@bambulab.com> Co-authored-by: zorro.zhang <zorro.zhang@bambulab.com> Co-authored-by: hu.wang <hu.wang@bambulab.com> Co-authored-by: liz.li <liz.li@bambulab.com> Co-authored-by: Kunlong Ma <kunlong.ma@bambulab.com> Co-authored-by: maosheng.wei <maosheng.wei@bambulab.com> Co-authored-by: gerrit <gerrit@bambulab.com> Co-authored-by: tao wang <tao.wang@bambulab.com> Co-authored-by: zhou.xu <zhou.xu@bambulab.com> Co-authored-by: xun.zhang <xun.zhang@bambulab.com> Co-authored-by: the Raz <rasmus@abc.se> Co-authored-by: Andy <andylg@yandex.ru> Co-authored-by: lane.wei <lane.wei@bambulab.com> Co-authored-by: Arthur <arthur.tang@bambulab.com> Co-authored-by: Stone Li <stone.li@bambulab.com> Co-authored-by: enricoturri1966 <enricoturri@seznam.cz> Co-authored-by: wenjie.guo <wenjie.guo@bambulab.com> Co-authored-by: zhimin.zeng <zhimin.zeng@bambulab.com> Co-authored-by: Dmytro Chystiakov <dlchistyakov@gmail.com> Co-authored-by: mia <652892+mia-0@users.noreply.github.com> Co-authored-by: Bastien Nocera <hadess@hadess.net> Co-authored-by: qing.zhang <qing.zhang@bambulab.com>
3491 lines
155 KiB
C++
3491 lines
155 KiB
C++
///|/ Copyright (c) Prusa Research 2017 - 2023 Oleksandra Iushchenko @YuSanka, Lukáš Matěna @lukasmatena, Tomáš Mészáros @tamasmeszaros, Lukáš Hejl @hejllukas, Vojtěch Bubník @bubnikv, Pavel Mikuš @Godrak, David Kocík @kocikdav, Enrico Turri @enricoturri1966, Vojtěch Král @vojtechkral
|
|
///|/ Copyright (c) 2021 Martin Budden
|
|
///|/ Copyright (c) 2021 Ilya @xorza
|
|
///|/ Copyright (c) 2019 John Drake @foxox
|
|
///|/ Copyright (c) 2018 Martin Loidl @LoidlM
|
|
///|/
|
|
///|/ PrusaSlicer is released under the terms of the AGPLv3 or higher
|
|
///|/
|
|
#include <cassert>
|
|
|
|
#include "Config.hpp"
|
|
#include "Exception.hpp"
|
|
#include "Preset.hpp"
|
|
#include "PresetBundle.hpp"
|
|
#include "AppConfig.hpp"
|
|
|
|
#ifdef _MSC_VER
|
|
#define WIN32_LEAN_AND_MEAN
|
|
#define NOMINMAX
|
|
#include <Windows.h>
|
|
#endif /* _MSC_VER */
|
|
|
|
// instead of #include "slic3r/GUI/I18N.hpp" :
|
|
#ifndef L
|
|
// !!! If you needed to translate some string,
|
|
// !!! please use _L(string)
|
|
// !!! _() - is a standard wxWidgets macro to translate
|
|
// !!! L() is used only for marking localizable string
|
|
// !!! It will be used in "xgettext" to create a Locating Message Catalog.
|
|
#define L(s) s
|
|
#endif /* L */
|
|
|
|
#include <algorithm>
|
|
#include <fstream>
|
|
#include <stdexcept>
|
|
#include <unordered_map>
|
|
#include <boost/format.hpp>
|
|
#include <boost/filesystem.hpp>
|
|
#include <boost/filesystem/fstream.hpp>
|
|
#include <boost/algorithm/string.hpp>
|
|
#include <boost/algorithm/string/predicate.hpp>
|
|
//BBS: add regex
|
|
#include <boost/algorithm/string/regex.hpp>
|
|
|
|
#include <boost/nowide/cenv.hpp>
|
|
#include <boost/nowide/convert.hpp>
|
|
#include <boost/nowide/cstdio.hpp>
|
|
#include <boost/nowide/fstream.hpp>
|
|
#include <boost/property_tree/ini_parser.hpp>
|
|
#include <boost/property_tree/ptree.hpp>
|
|
#include <boost/locale.hpp>
|
|
#include <boost/log/trivial.hpp>
|
|
|
|
#include "libslic3r.h"
|
|
#include "Utils.hpp"
|
|
#include "Time.hpp"
|
|
#include "PlaceholderParser.hpp"
|
|
|
|
using boost::property_tree::ptree;
|
|
|
|
namespace Slic3r {
|
|
|
|
//BBS: add a function to load the version from xxx.json
|
|
Semver get_version_from_json(std::string file_path)
|
|
{
|
|
try {
|
|
boost::nowide::ifstream ifs(file_path);
|
|
json j;
|
|
ifs >> j;
|
|
std::string version_str = j.at(BBL_JSON_KEY_VERSION);
|
|
|
|
auto config_version = Semver::parse(version_str);
|
|
if (! config_version) {
|
|
return Semver();
|
|
} else {
|
|
return *config_version;
|
|
}
|
|
}
|
|
catch(nlohmann::detail::parse_error &err) {
|
|
BOOST_LOG_TRIVIAL(error) << __FUNCTION__<< ": parse "<<file_path<<" got a nlohmann::detail::parse_error, reason = " << err.what();
|
|
return Semver();
|
|
//throw ConfigurationError(format("Failed loading configuration file \"%1%\": %2%", file_path, err.what()));
|
|
}
|
|
}
|
|
|
|
//BBS: add a function to load the key-values from xxx.json
|
|
int get_values_from_json(std::string file_path, std::vector<std::string>& keys, std::map<std::string, std::string>& key_values)
|
|
{
|
|
try {
|
|
boost::nowide::ifstream ifs(file_path);
|
|
json j;
|
|
ifs >> j;
|
|
|
|
for (int i=0; i < keys.size(); i++)
|
|
{
|
|
if (j.contains(keys[i])) {
|
|
std::string value = j.at(keys[i]);
|
|
key_values.emplace(keys[i], value);
|
|
}
|
|
}
|
|
}
|
|
catch(nlohmann::detail::parse_error &err) {
|
|
BOOST_LOG_TRIVIAL(error) << __FUNCTION__<< ": parse "<<file_path<<" got a nlohmann::detail::parse_error, reason = " << err.what();
|
|
//throw ConfigurationError(format("Failed loading json file \"%1%\": %2%", file_path, err.what()));
|
|
return 0;
|
|
}
|
|
return key_values.size();
|
|
}
|
|
|
|
ConfigFileType guess_config_file_type(const ptree &tree)
|
|
{
|
|
size_t app_config = 0;
|
|
size_t bundle = 0;
|
|
size_t config = 0;
|
|
for (const ptree::value_type &v : tree) {
|
|
if (v.second.empty()) {
|
|
if (
|
|
#ifdef SUPPORT_BACKGROUND_PROCESSING
|
|
v.first == "background_processing" ||
|
|
#endif
|
|
v.first == "last_export_path")
|
|
++ app_config;
|
|
else if (v.first == "nozzle_diameter" ||
|
|
v.first == "filament_diameter")
|
|
++ config;
|
|
} else if (boost::algorithm::starts_with(v.first, "print:") ||
|
|
boost::algorithm::starts_with(v.first, "filament:") ||
|
|
boost::algorithm::starts_with(v.first, "printer:") ||
|
|
v.first == "settings")
|
|
++ bundle;
|
|
else if (v.first == "presets") {
|
|
++ app_config;
|
|
++ bundle;
|
|
} else if (v.first == "recent") {
|
|
for (auto &kvp : v.second)
|
|
if (kvp.first == "settings_folder" || kvp.first == "last_opened_folder")
|
|
++ app_config;
|
|
}
|
|
}
|
|
return (app_config > bundle && app_config > config) ? CONFIG_FILE_TYPE_APP_CONFIG :
|
|
(bundle > config) ? CONFIG_FILE_TYPE_CONFIG_BUNDLE : CONFIG_FILE_TYPE_CONFIG;
|
|
}
|
|
|
|
|
|
VendorProfile VendorProfile::from_ini(const boost::filesystem::path &path, bool load_all)
|
|
{
|
|
ptree tree;
|
|
boost::filesystem::ifstream ifs(path);
|
|
boost::property_tree::read_ini(ifs, tree);
|
|
return VendorProfile::from_ini(tree, path, load_all);
|
|
}
|
|
|
|
static const std::unordered_map<std::string, std::string> pre_family_model_map {{
|
|
{ "MK3", "MK3" },
|
|
{ "MK3MMU2", "MK3" },
|
|
{ "MK2.5", "MK2.5" },
|
|
{ "MK2.5MMU2", "MK2.5" },
|
|
{ "MK2S", "MK2" },
|
|
{ "MK2SMM", "MK2" },
|
|
{ "SL1", "SL1" },
|
|
}};
|
|
|
|
VendorProfile VendorProfile::from_ini(const ptree &tree, const boost::filesystem::path &path, bool load_all)
|
|
{
|
|
static const std::string printer_model_key = "printer_model:";
|
|
static const std::string filaments_section = "default_filaments";
|
|
static const std::string materials_section = "default_sla_materials";
|
|
|
|
const std::string id = path.stem().string();
|
|
|
|
if (! boost::filesystem::exists(path)) {
|
|
throw Slic3r::RuntimeError((boost::format("Cannot load Vendor Config Bundle `%1%`: File not found: `%2%`.") % id % path).str());
|
|
}
|
|
|
|
VendorProfile res(id);
|
|
|
|
// Helper to get compulsory fields
|
|
auto get_or_throw = [&](const ptree &tree, const std::string &key) -> ptree::const_assoc_iterator
|
|
{
|
|
auto res = tree.find(key);
|
|
if (res == tree.not_found()) {
|
|
throw Slic3r::RuntimeError((boost::format("Vendor Config Bundle `%1%` is not valid: Missing secion or key: `%2%`.") % id % key).str());
|
|
}
|
|
return res;
|
|
};
|
|
|
|
// Load the header
|
|
const auto &vendor_section = get_or_throw(tree, "vendor")->second;
|
|
res.name = get_or_throw(vendor_section, "name")->second.data();
|
|
|
|
auto config_version_str = get_or_throw(vendor_section, "config_version")->second.data();
|
|
auto config_version = Semver::parse(config_version_str);
|
|
if (! config_version) {
|
|
throw Slic3r::RuntimeError((boost::format("Vendor Config Bundle `%1%` is not valid: Cannot parse config_version: `%2%`.") % id % config_version_str).str());
|
|
} else {
|
|
res.config_version = std::move(*config_version);
|
|
}
|
|
|
|
// Load URLs
|
|
const auto config_update_url = vendor_section.find("config_update_url");
|
|
if (config_update_url != vendor_section.not_found()) {
|
|
res.config_update_url = config_update_url->second.data();
|
|
}
|
|
|
|
const auto changelog_url = vendor_section.find("changelog_url");
|
|
if (changelog_url != vendor_section.not_found()) {
|
|
res.changelog_url = changelog_url->second.data();
|
|
}
|
|
|
|
if (! load_all) {
|
|
return res;
|
|
}
|
|
|
|
// Load printer models
|
|
for (auto §ion : tree) {
|
|
if (boost::starts_with(section.first, printer_model_key)) {
|
|
VendorProfile::PrinterModel model;
|
|
model.id = section.first.substr(printer_model_key.size());
|
|
model.name = section.second.get<std::string>("name", model.id);
|
|
|
|
const char *technology_fallback = boost::algorithm::starts_with(model.id, "SL") ? "SLA" : "FFF";
|
|
|
|
auto technology_field = section.second.get<std::string>("technology", technology_fallback);
|
|
if (! ConfigOptionEnum<PrinterTechnology>::from_string(technology_field, model.technology)) {
|
|
BOOST_LOG_TRIVIAL(error) << boost::format("Vendor bundle: `%1%`: Invalid printer technology field: `%2%`") % id % technology_field;
|
|
model.technology = ptFFF;
|
|
}
|
|
|
|
model.family = section.second.get<std::string>("family", std::string());
|
|
if (model.family.empty() && res.name == "BBL") {
|
|
// If no family is specified, it can be inferred for known printers
|
|
const auto from_pre_map = pre_family_model_map.find(model.id);
|
|
if (from_pre_map != pre_family_model_map.end()) { model.family = from_pre_map->second; }
|
|
}
|
|
#if 0
|
|
// Remove SLA printers from the initial alpha.
|
|
if (model.technology == ptSLA)
|
|
continue;
|
|
#endif
|
|
section.second.get<std::string>("variants", "");
|
|
const auto variants_field = section.second.get<std::string>("variants", "");
|
|
std::vector<std::string> variants;
|
|
if (Slic3r::unescape_strings_cstyle(variants_field, variants)) {
|
|
for (const std::string &variant_name : variants) {
|
|
if (model.variant(variant_name) == nullptr)
|
|
model.variants.emplace_back(VendorProfile::PrinterVariant(variant_name));
|
|
}
|
|
} else {
|
|
BOOST_LOG_TRIVIAL(error) << boost::format("Vendor bundle: `%1%`: Malformed variants field: `%2%`") % id % variants_field;
|
|
}
|
|
auto default_materials_field = section.second.get<std::string>("default_materials", "");
|
|
if (default_materials_field.empty())
|
|
default_materials_field = section.second.get<std::string>("default_filaments", "");
|
|
if (Slic3r::unescape_strings_cstyle(default_materials_field, model.default_materials)) {
|
|
Slic3r::sort_remove_duplicates(model.default_materials);
|
|
if (! model.default_materials.empty() && model.default_materials.front().empty())
|
|
// An empty material was inserted into the list of default materials. Remove it.
|
|
model.default_materials.erase(model.default_materials.begin());
|
|
} else {
|
|
BOOST_LOG_TRIVIAL(error) << boost::format("Vendor bundle: `%1%`: Malformed default_materials field: `%2%`") % id % default_materials_field;
|
|
}
|
|
model.bed_model = section.second.get<std::string>("bed_model", "");
|
|
model.bed_texture = section.second.get<std::string>("bed_texture", "");
|
|
if (! model.id.empty() && ! model.variants.empty())
|
|
res.models.push_back(std::move(model));
|
|
}
|
|
}
|
|
|
|
// Load filaments and sla materials to be installed by default
|
|
const auto filaments = tree.find(filaments_section);
|
|
if (filaments != tree.not_found()) {
|
|
for (auto &pair : filaments->second) {
|
|
if (pair.second.data() == "1") {
|
|
res.default_filaments.insert(pair.first);
|
|
}
|
|
}
|
|
}
|
|
const auto materials = tree.find(materials_section);
|
|
if (materials != tree.not_found()) {
|
|
for (auto &pair : materials->second) {
|
|
if (pair.second.data() == "1") {
|
|
res.default_sla_materials.insert(pair.first);
|
|
}
|
|
}
|
|
}
|
|
|
|
return res;
|
|
}
|
|
|
|
std::vector<std::string> VendorProfile::families() const
|
|
{
|
|
std::vector<std::string> res;
|
|
unsigned num_familiies = 0;
|
|
|
|
for (auto &model : models) {
|
|
if (std::find(res.begin(), res.end(), model.family) == res.end()) {
|
|
res.push_back(model.family);
|
|
num_familiies++;
|
|
}
|
|
}
|
|
|
|
return res;
|
|
}
|
|
|
|
// Suffix to be added to a modified preset name in the combo box.
|
|
static std::string g_suffix_modified = " (modified)";
|
|
const std::string& Preset::suffix_modified()
|
|
{
|
|
return g_suffix_modified;
|
|
}
|
|
|
|
void Preset::update_suffix_modified(const std::string& new_suffix_modified)
|
|
{
|
|
g_suffix_modified = new_suffix_modified;
|
|
}
|
|
// Remove an optional "(modified)" suffix from a name.
|
|
// This converts a UI name to a unique preset identifier.
|
|
std::string Preset::remove_suffix_modified(const std::string &name)
|
|
{
|
|
return boost::algorithm::starts_with(name, g_suffix_modified) ?
|
|
name.substr(g_suffix_modified.size()) :
|
|
name;
|
|
}
|
|
|
|
// Update new extruder fields at the printer profile.
|
|
void Preset::normalize(DynamicPrintConfig &config)
|
|
{
|
|
// BBS
|
|
auto* filament_diameter = dynamic_cast<const ConfigOptionFloats*>(config.option("filament_diameter"));
|
|
if (filament_diameter != nullptr)
|
|
// Loaded the FFF Printer settings. Verify, that all extruder dependent values have enough values.
|
|
config.set_num_filaments((unsigned int)filament_diameter->values.size());
|
|
|
|
if (config.option("filament_diameter") != nullptr) {
|
|
// This config contains single or multiple filament presets.
|
|
// Ensure that the filament preset vector options contain the correct number of values.
|
|
// BBS
|
|
size_t n = (filament_diameter == nullptr) ? 1 : filament_diameter->values.size();
|
|
const auto &defaults = FullPrintConfig::defaults();
|
|
for (const std::string &key : Preset::filament_options()) {
|
|
if (key == "compatible_prints" || key == "compatible_printers")
|
|
continue;
|
|
auto *opt = config.option(key, false);
|
|
/*assert(opt != nullptr);
|
|
assert(opt->is_vector());*/
|
|
if (opt != nullptr && opt->is_vector())
|
|
static_cast<ConfigOptionVectorBase*>(opt)->resize(n, defaults.option(key));
|
|
}
|
|
// The following keys are mandatory for the UI, but they are not part of FullPrintConfig, therefore they are handled separately.
|
|
for (const std::string &key : { "filament_settings_id" }) {
|
|
auto *opt = config.option(key, false);
|
|
assert(opt == nullptr || opt->type() == coStrings);
|
|
if (opt != nullptr && opt->type() == coStrings)
|
|
static_cast<ConfigOptionStrings*>(opt)->values.resize(n, std::string());
|
|
}
|
|
}
|
|
|
|
handle_legacy_sla(config);
|
|
}
|
|
|
|
std::string Preset::remove_invalid_keys(DynamicPrintConfig &config, const DynamicPrintConfig &default_config)
|
|
{
|
|
std::string incorrect_keys;
|
|
for (const std::string &key : config.keys())
|
|
if (! default_config.has(key)) {
|
|
if (incorrect_keys.empty())
|
|
incorrect_keys = key;
|
|
else {
|
|
incorrect_keys += ", ";
|
|
incorrect_keys += key;
|
|
}
|
|
config.erase(key);
|
|
}
|
|
return incorrect_keys;
|
|
}
|
|
|
|
std::string Preset::get_type_string(Preset::Type type)
|
|
{
|
|
switch (type) {
|
|
case Preset::Type::TYPE_FILAMENT:
|
|
return PRESET_FILAMENT_NAME;
|
|
case Preset::Type::TYPE_PRINT:
|
|
return PRESET_PRINT_NAME;
|
|
case Preset::Type::TYPE_PRINTER:
|
|
return PRESET_PRINTER_NAME;
|
|
case Preset::Type::TYPE_PHYSICAL_PRINTER:
|
|
return "physical_printer";
|
|
case Preset::Type::TYPE_INVALID:
|
|
return "invalid";
|
|
default:
|
|
return "invalid";
|
|
}
|
|
}
|
|
|
|
std::string Preset::get_iot_type_string(Preset::Type type)
|
|
{
|
|
switch (type) {
|
|
case Preset::Type::TYPE_FILAMENT:
|
|
return PRESET_IOT_FILAMENT_TYPE;
|
|
case Preset::Type::TYPE_PRINT:
|
|
return PRESET_IOT_PRINT_TYPE;
|
|
case Preset::Type::TYPE_PRINTER:
|
|
return PRESET_IOT_PRINTER_TYPE;
|
|
|
|
default:
|
|
return "invalid";
|
|
}
|
|
}
|
|
|
|
//make the type string compatibility with local and iot type string
|
|
Preset::Type Preset::get_type_from_string(std::string type_str)
|
|
{
|
|
if (type_str.compare(PRESET_PRINT_NAME) == 0 || type_str.compare(PRESET_IOT_PRINT_TYPE) == 0)
|
|
return Preset::Type::TYPE_PRINT;
|
|
else if (type_str.compare(PRESET_FILAMENT_NAME) == 0 || type_str.compare(PRESET_IOT_FILAMENT_TYPE) == 0)
|
|
return Preset::Type::TYPE_FILAMENT;
|
|
else if (type_str.compare(PRESET_PRINTER_NAME) == 0 || type_str.compare(PRESET_IOT_PRINTER_TYPE) == 0)
|
|
return Preset::Type::TYPE_PRINTER;
|
|
else
|
|
return Preset::Type::TYPE_INVALID;
|
|
}
|
|
|
|
|
|
void Preset::load_info(const std::string& file)
|
|
{
|
|
try {
|
|
boost::property_tree::ptree tree;
|
|
boost::nowide::ifstream ifs(file);
|
|
boost::property_tree::read_ini(ifs, tree);
|
|
if (tree.empty()) return;
|
|
for (const boost::property_tree::ptree::value_type &v : tree) {
|
|
if (v.first.compare("sync_info") == 0)
|
|
this->sync_info = v.second.get_value<std::string>();
|
|
else if (v.first.compare("user_id") == 0)
|
|
this->user_id = v.second.get_value<std::string>();
|
|
else if (v.first.compare("setting_id") == 0) {
|
|
this->setting_id = v.second.get_value<std::string>();
|
|
if (this->setting_id.compare("null") == 0)
|
|
this->setting_id.clear();
|
|
}
|
|
else if (v.first.compare("base_id") == 0) {
|
|
this->base_id = v.second.get_value<std::string>();
|
|
if (this->base_id.compare("null") == 0)
|
|
this->base_id.clear();
|
|
}
|
|
else if (v.first.compare("updated_time") == 0) {
|
|
std::string time = v.second.get_value<std::string>();
|
|
this->updated_time = std::atoll(time.c_str());
|
|
}
|
|
}
|
|
}
|
|
catch (...) {
|
|
return;
|
|
}
|
|
|
|
//TODO: workaround for current info file convert, will remove it later
|
|
if (this->updated_time == 0) {
|
|
this->updated_time = (long long)Slic3r::Utils::get_current_time_utc();
|
|
//this->sync_info = "update";
|
|
BOOST_LOG_TRIVIAL(info) << boost::format("old info file, updated time to %1%") % this->updated_time;
|
|
save_info();
|
|
}
|
|
}
|
|
|
|
void Preset::save_info(std::string file)
|
|
{
|
|
//BBS: add project embedded preset logic
|
|
if (this->is_project_embedded)
|
|
return;
|
|
if (file.empty()) {
|
|
fs::path idx_file(this->file);
|
|
idx_file.replace_extension(".info");
|
|
file = idx_file.string();
|
|
}
|
|
|
|
boost::nowide::ofstream c;
|
|
c.open(file, std::ios::out | std::ios::trunc);
|
|
std::string sync_info_to_save;
|
|
//BBS: hold is used for stop requesting to server this time
|
|
if (this->sync_info.compare("hold") != 0)
|
|
sync_info_to_save = this->sync_info;
|
|
c << "sync_info" << " = " << sync_info_to_save << std::endl;
|
|
c << "user_id" << " = " << this->user_id << std::endl;
|
|
c << "setting_id" << " = " << this->setting_id << std::endl;
|
|
c << "base_id" << " = " << this->base_id << std::endl;
|
|
c << "updated_time" << " = " << std::to_string(this->updated_time) << std::endl;
|
|
c.close();
|
|
}
|
|
|
|
void Preset::remove_files()
|
|
{
|
|
//BBS: add project embedded preset logic
|
|
if (this->is_project_embedded)
|
|
return;
|
|
// Erase the preset file.
|
|
boost::nowide::remove(this->file.c_str());
|
|
fs::path idx_path(this->file);
|
|
idx_path.replace_extension(".info");
|
|
if (fs::exists(idx_path))
|
|
boost::nowide::remove(idx_path.string().c_str());
|
|
}
|
|
|
|
//BBS: add logic for only difference save
|
|
void Preset::save(DynamicPrintConfig* parent_config)
|
|
{
|
|
//BBS: add project embedded preset logic
|
|
if (this->is_project_embedded)
|
|
return;
|
|
//BBS: change to json format
|
|
//this->config.save(this->file);
|
|
std::string from_str;
|
|
if (this->is_user())
|
|
from_str = std::string("User");
|
|
else if (this->is_project_embedded)
|
|
from_str = std::string("Project");
|
|
else if (this->is_system)
|
|
from_str = std::string("System");
|
|
else
|
|
from_str = std::string("Default");
|
|
|
|
boost::filesystem::create_directories(fs::path(this->file).parent_path());
|
|
|
|
//BBS: only save difference if it has parent
|
|
if (parent_config) {
|
|
DynamicPrintConfig temp_config;
|
|
std::vector<std::string> dirty_options = config.diff(*parent_config);
|
|
|
|
for (auto option: dirty_options)
|
|
{
|
|
ConfigOption *opt_src = config.option(option);
|
|
ConfigOption *opt_dst = temp_config.option(option, true);
|
|
opt_dst->set(opt_src);
|
|
}
|
|
temp_config.save_to_json(this->file, this->name, from_str, this->version.to_string(), this->custom_defined);
|
|
} else if (!filament_id.empty() && inherits().empty()) {
|
|
DynamicPrintConfig temp_config = config;
|
|
temp_config.set_key_value(BBL_JSON_KEY_FILAMENT_ID, new ConfigOptionString(filament_id));
|
|
temp_config.save_to_json(this->file, this->name, from_str, this->version.to_string(), this->custom_defined);
|
|
} else {
|
|
this->config.save_to_json(this->file, this->name, from_str, this->version.to_string(), this->custom_defined);
|
|
}
|
|
|
|
fs::path idx_file(this->file);
|
|
idx_file.replace_extension(".info");
|
|
this->save_info(idx_file.string());
|
|
}
|
|
|
|
void Preset::reload(Preset const &parent)
|
|
{
|
|
DynamicPrintConfig config;
|
|
// BBS: change to json format
|
|
// ConfigSubstitutions config_substitutions = config.load_from_ini(preset.file, substitution_rule);
|
|
std::map<std::string, std::string> key_values;
|
|
std::string reason;
|
|
ForwardCompatibilitySubstitutionRule substitution_rule = ForwardCompatibilitySubstitutionRule::Disable;
|
|
try {
|
|
ConfigSubstitutions config_substitutions = config.load_from_json(file, substitution_rule, key_values, reason);
|
|
this->config = parent.config;
|
|
this->config.apply(std::move(config));
|
|
} catch (const std::exception &err) {
|
|
BOOST_LOG_TRIVIAL(error) << boost::format("Failed loading the user-config file: %1%. Reason: %2%") % file % err.what();
|
|
}
|
|
}
|
|
|
|
// Return a label of this preset, consisting of a name and a "(modified)" suffix, if this preset is dirty.
|
|
std::string Preset::label(bool no_alias) const
|
|
{
|
|
return (this->is_dirty ? g_suffix_modified : "")
|
|
+ ((no_alias || this->alias.empty()) ? this->name : this->alias);
|
|
}
|
|
|
|
bool is_compatible_with_print(const PresetWithVendorProfile &preset, const PresetWithVendorProfile &active_print, const PresetWithVendorProfile &active_printer)
|
|
{
|
|
if (preset.vendor != nullptr && preset.vendor != active_printer.vendor)
|
|
// The current profile has a vendor assigned and it is different from the active print's vendor.
|
|
return false;
|
|
auto &condition = preset.preset.compatible_prints_condition();
|
|
auto *compatible_prints = dynamic_cast<const ConfigOptionStrings*>(preset.preset.config.option("compatible_prints"));
|
|
bool has_compatible_prints = compatible_prints != nullptr && ! compatible_prints->values.empty();
|
|
if (! has_compatible_prints && ! condition.empty()) {
|
|
try {
|
|
return PlaceholderParser::evaluate_boolean_expression(condition, active_print.preset.config);
|
|
} catch (const std::runtime_error &err) {
|
|
//FIXME in case of an error, return "compatible with everything".
|
|
printf("Preset::is_compatible_with_print - parsing error of compatible_prints_condition %s:\n%s\n", active_print.preset.name.c_str(), err.what());
|
|
return true;
|
|
}
|
|
}
|
|
return preset.preset.is_default || active_print.preset.name.empty() || ! has_compatible_prints ||
|
|
std::find(compatible_prints->values.begin(), compatible_prints->values.end(), active_print.preset.name) !=
|
|
compatible_prints->values.end();
|
|
}
|
|
|
|
//BBS: If one filament or process preset is compatible with one system printer preset,
|
|
// then we think this filament or process preset should be compatible with all
|
|
// user printer preset which is inherited from this system printer preset.
|
|
// Because printer_model and nozzle_diameter in BBL system machine preset
|
|
// can't be changed by user.
|
|
bool is_compatible_with_parent_printer(const PresetWithVendorProfile& preset, const PresetWithVendorProfile& active_printer)
|
|
{
|
|
auto *compatible_printers = dynamic_cast<const ConfigOptionStrings*>(preset.preset.config.option("compatible_printers"));
|
|
bool has_compatible_printers = compatible_printers != nullptr && ! compatible_printers->values.empty();
|
|
//BBS: FIXME only check the parent now, but should check grand-parent as well.
|
|
return has_compatible_printers &&
|
|
std::find(compatible_printers->values.begin(), compatible_printers->values.end(), active_printer.preset.inherits()) !=
|
|
compatible_printers->values.end();
|
|
}
|
|
|
|
bool is_compatible_with_printer(const PresetWithVendorProfile &preset, const PresetWithVendorProfile &active_printer, const DynamicPrintConfig *extra_config)
|
|
{
|
|
if (preset.vendor != nullptr && preset.vendor != active_printer.vendor)
|
|
// The current profile has a vendor assigned and it is different from the active print's vendor.
|
|
return false;
|
|
auto &condition = preset.preset.compatible_printers_condition();
|
|
auto *compatible_printers = dynamic_cast<const ConfigOptionStrings*>(preset.preset.config.option("compatible_printers"));
|
|
bool has_compatible_printers = compatible_printers != nullptr && ! compatible_printers->values.empty();
|
|
if (! has_compatible_printers && ! condition.empty()) {
|
|
try {
|
|
return PlaceholderParser::evaluate_boolean_expression(condition, active_printer.preset.config, extra_config);
|
|
} catch (const std::runtime_error &err) {
|
|
//FIXME in case of an error, return "compatible with everything".
|
|
printf("Preset::is_compatible_with_printer - parsing error of compatible_printers_condition %s:\n%s\n", active_printer.preset.name.c_str(), err.what());
|
|
return true;
|
|
}
|
|
}
|
|
return preset.preset.is_default || active_printer.preset.name.empty() || !has_compatible_printers ||
|
|
std::find(compatible_printers->values.begin(), compatible_printers->values.end(), active_printer.preset.name) !=
|
|
compatible_printers->values.end()
|
|
//BBS
|
|
|| (!active_printer.preset.is_system && is_compatible_with_parent_printer(preset, active_printer));
|
|
}
|
|
|
|
bool is_compatible_with_printer(const PresetWithVendorProfile &preset, const PresetWithVendorProfile &active_printer)
|
|
{
|
|
DynamicPrintConfig config;
|
|
config.set_key_value("printer_preset", new ConfigOptionString(active_printer.preset.name));
|
|
const ConfigOption *opt = active_printer.preset.config.option("nozzle_diameter");
|
|
if (opt)
|
|
config.set_key_value("num_extruders", new ConfigOptionInt((int)static_cast<const ConfigOptionFloats*>(opt)->values.size()));
|
|
return is_compatible_with_printer(preset, active_printer, &config);
|
|
}
|
|
|
|
void Preset::set_visible_from_appconfig(const AppConfig &app_config)
|
|
{
|
|
//BBS: add config related log
|
|
BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << boost::format(": name %1%, is_visible %2%")%name % is_visible;
|
|
if (vendor == nullptr) { return; }
|
|
|
|
if (type == TYPE_PRINTER) {
|
|
const std::string &model = config.opt_string("printer_model");
|
|
const std::string &variant = config.opt_string("printer_variant");
|
|
if (model.empty() || variant.empty())
|
|
return;
|
|
is_visible = app_config.get_variant(vendor->id, model, variant);
|
|
} else if (type == TYPE_FILAMENT || type == TYPE_SLA_MATERIAL) {
|
|
const std::string §ion_name = (type == TYPE_FILAMENT) ? AppConfig::SECTION_FILAMENTS : AppConfig::SECTION_MATERIALS;
|
|
if (app_config.has_section(section_name)) {
|
|
// Check whether this profile is marked as "installed" in PrusaSlicer.ini,
|
|
// or whether a profile is marked as "installed", which this profile may have been renamed from.
|
|
const std::map<std::string, std::string> &installed = app_config.get_section(section_name);
|
|
auto has = [&installed](const std::string &name) {
|
|
auto it = installed.find(name);
|
|
return it != installed.end() && ! it->second.empty();
|
|
};
|
|
is_visible = has(this->name);
|
|
for (auto it = this->renamed_from.begin(); ! is_visible && it != this->renamed_from.end(); ++ it)
|
|
is_visible = has(*it);
|
|
}
|
|
}
|
|
//BBS: add config related log
|
|
BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << boost::format(": name %1%, is_visible set to %2%")%name % is_visible;
|
|
}
|
|
|
|
std::string Preset::get_filament_type(std::string &display_filament_type)
|
|
{
|
|
return config.get_filament_type(display_filament_type);
|
|
}
|
|
|
|
std::string Preset::get_printer_type(PresetBundle *preset_bundle)
|
|
{
|
|
if (preset_bundle) {
|
|
auto config = &preset_bundle->printers.get_edited_preset().config;
|
|
std::string vendor_name;
|
|
for (auto vendor_profile : preset_bundle->vendors) {
|
|
for (auto vendor_model : vendor_profile.second.models)
|
|
if (vendor_model.name == config->opt_string("printer_model"))
|
|
{
|
|
vendor_name = vendor_profile.first;
|
|
return vendor_model.model_id;
|
|
}
|
|
}
|
|
}
|
|
return "";
|
|
}
|
|
|
|
std::string Preset::get_current_printer_type(PresetBundle *preset_bundle)
|
|
{
|
|
if (preset_bundle) {
|
|
auto config = &(this->config);
|
|
std::string vendor_name;
|
|
for (auto vendor_profile : preset_bundle->vendors) {
|
|
for (auto vendor_model : vendor_profile.second.models)
|
|
if (vendor_model.name == config->opt_string("printer_model")) {
|
|
vendor_name = vendor_profile.first;
|
|
return vendor_model.model_id;
|
|
}
|
|
}
|
|
}
|
|
return "";
|
|
}
|
|
|
|
bool Preset::has_lidar(PresetBundle *preset_bundle)
|
|
{
|
|
bool has_lidar = false;
|
|
if (preset_bundle) {
|
|
auto config = &preset_bundle->printers.get_edited_preset().config;
|
|
std::string vendor_name;
|
|
for (auto vendor_profile : preset_bundle->vendors) {
|
|
for (auto vendor_model : vendor_profile.second.models)
|
|
if (vendor_model.name == config->opt_string("printer_model")) {
|
|
vendor_name = vendor_profile.first;
|
|
break;
|
|
}
|
|
}
|
|
if (!vendor_name.empty())
|
|
has_lidar = vendor_name.compare("BBL") == 0 ? true : false;
|
|
}
|
|
return has_lidar;
|
|
}
|
|
|
|
bool Preset::is_custom_defined()
|
|
{
|
|
if (custom_defined == "1")
|
|
return true;
|
|
return false;
|
|
}
|
|
|
|
BedType Preset::get_default_bed_type(PresetBundle* preset_bundle)
|
|
{
|
|
if (config.has("default_bed_type") && !config.opt_string("default_bed_type").empty()) {
|
|
try {
|
|
std::string str_bed_type = config.opt_string("default_bed_type");
|
|
int bed_type_value = atoi(str_bed_type.c_str());
|
|
return BedType(bed_type_value);
|
|
} catch(...) {
|
|
;
|
|
}
|
|
}
|
|
|
|
std::string model_id = this->get_printer_type(preset_bundle);
|
|
if (model_id == "BL-P001" || model_id == "BL-P002" || model_id == "C13") {
|
|
return BedType::btPC;
|
|
} else if (model_id == "C11") {
|
|
return BedType::btPEI;
|
|
}
|
|
return BedType::btPEI;
|
|
}
|
|
|
|
bool Preset::has_cali_lines(PresetBundle* preset_bundle)
|
|
{
|
|
std::string model_id = this->get_printer_type(preset_bundle);
|
|
if (model_id == "BL-P001" || model_id == "BL-P002" || model_id == "C13") {
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
static std::vector<std::string> s_Preset_print_options {
|
|
"layer_height", "initial_layer_print_height", "wall_loops", "slice_closing_radius", "spiral_mode", "spiral_mode_smooth", "spiral_mode_max_xy_smoothing", "slicing_mode",
|
|
"top_shell_layers", "top_shell_thickness", "bottom_shell_layers", "bottom_shell_thickness",
|
|
"extra_perimeters_on_overhangs", "ensure_vertical_shell_thickness", "reduce_crossing_wall", "detect_thin_wall", "detect_overhang_wall", "overhang_reverse", "overhang_reverse_threshold","overhang_reverse_internal_only",
|
|
"seam_position", "staggered_inner_seams", "wall_sequence", "is_infill_first", "sparse_infill_density", "sparse_infill_pattern", "top_surface_pattern", "bottom_surface_pattern",
|
|
"infill_direction",
|
|
"minimum_sparse_infill_area", "reduce_infill_retraction","internal_solid_infill_pattern",
|
|
"ironing_type", "ironing_pattern", "ironing_flow", "ironing_speed", "ironing_spacing", "ironing_angle",
|
|
"max_travel_detour_distance",
|
|
"fuzzy_skin", "fuzzy_skin_thickness", "fuzzy_skin_point_distance", "fuzzy_skin_first_layer",
|
|
"max_volumetric_extrusion_rate_slope", "max_volumetric_extrusion_rate_slope_segment_length",
|
|
"inner_wall_speed", "outer_wall_speed", "sparse_infill_speed", "internal_solid_infill_speed",
|
|
"top_surface_speed", "support_speed", "support_object_xy_distance", "support_interface_speed",
|
|
"bridge_speed", "internal_bridge_speed", "gap_infill_speed", "travel_speed", "travel_speed_z", "initial_layer_speed",
|
|
"outer_wall_acceleration", "initial_layer_acceleration", "top_surface_acceleration", "default_acceleration", "skirt_loops", "skirt_speed", "skirt_distance", "skirt_height", "draft_shield",
|
|
"brim_width", "brim_object_gap", "brim_type", "brim_ears_max_angle", "brim_ears_detection_length", "enable_support", "support_type", "support_threshold_angle", "enforce_support_layers",
|
|
"raft_layers", "raft_first_layer_density", "raft_first_layer_expansion", "raft_contact_distance", "raft_expansion",
|
|
"support_base_pattern", "support_base_pattern_spacing", "support_expansion", "support_style",
|
|
"independent_support_layer_height",
|
|
"support_angle", "support_interface_top_layers", "support_interface_bottom_layers",
|
|
"support_interface_pattern", "support_interface_spacing", "support_interface_loop_pattern",
|
|
"support_top_z_distance", "support_on_build_plate_only","support_critical_regions_only", "bridge_no_support", "thick_bridges", "thick_internal_bridges", "max_bridge_length", "print_sequence", "support_remove_small_overhang",
|
|
"filename_format", "wall_filament", "support_bottom_z_distance",
|
|
"sparse_infill_filament", "solid_infill_filament", "support_filament", "support_interface_filament","support_interface_not_for_body",
|
|
"ooze_prevention", "standby_temperature_delta", "interface_shells", "line_width", "initial_layer_line_width",
|
|
"inner_wall_line_width", "outer_wall_line_width", "sparse_infill_line_width", "internal_solid_infill_line_width",
|
|
"top_surface_line_width", "support_line_width", "infill_wall_overlap", "bridge_flow", "internal_bridge_flow",
|
|
"elefant_foot_compensation", "elefant_foot_compensation_layers", "xy_contour_compensation", "xy_hole_compensation", "resolution", "enable_prime_tower",
|
|
"prime_tower_width", "prime_tower_brim_width", "prime_volume",
|
|
"wipe_tower_no_sparse_layers", "compatible_printers", "compatible_printers_condition", "inherits",
|
|
"flush_into_infill", "flush_into_objects", "flush_into_support",
|
|
"tree_support_branch_angle", "tree_support_angle_slow", "tree_support_wall_count", "tree_support_top_rate", "tree_support_branch_distance", "tree_support_tip_diameter",
|
|
"tree_support_branch_diameter", "tree_support_branch_diameter_angle", "tree_support_branch_diameter_double_wall",
|
|
"detect_narrow_internal_solid_infill",
|
|
"gcode_add_line_number", "enable_arc_fitting", "infill_combination", /*"adaptive_layer_height",*/
|
|
"support_bottom_interface_spacing", "enable_overhang_speed", "slowdown_for_curled_perimeters", "overhang_1_4_speed", "overhang_2_4_speed", "overhang_3_4_speed", "overhang_4_4_speed",
|
|
"initial_layer_infill_speed", "only_one_wall_top",
|
|
"timelapse_type",
|
|
"wall_generator", "wall_transition_length", "wall_transition_filter_deviation", "wall_transition_angle",
|
|
"wall_distribution_count", "min_feature_size", "min_bead_width", "post_process",
|
|
"small_perimeter_speed", "small_perimeter_threshold","bridge_angle", "filter_out_gap_fill", "travel_acceleration","inner_wall_acceleration", "min_width_top_surface",
|
|
"default_jerk", "outer_wall_jerk", "inner_wall_jerk", "infill_jerk", "top_surface_jerk", "initial_layer_jerk","travel_jerk",
|
|
"top_solid_infill_flow_ratio","bottom_solid_infill_flow_ratio","only_one_wall_first_layer", "print_flow_ratio", "seam_gap",
|
|
"role_based_wipe_speed", "wipe_speed", "accel_to_decel_enable", "accel_to_decel_factor", "wipe_on_loops",
|
|
"bridge_density", "precise_outer_wall", "overhang_speed_classic", "bridge_acceleration",
|
|
"sparse_infill_acceleration", "internal_solid_infill_acceleration", "tree_support_adaptive_layer_height", "tree_support_auto_brim",
|
|
"tree_support_brim_width", "gcode_comments", "gcode_label_objects",
|
|
"initial_layer_travel_speed", "exclude_object", "slow_down_layers", "infill_anchor", "infill_anchor_max","initial_layer_min_bead_width",
|
|
"make_overhang_printable", "make_overhang_printable_angle", "make_overhang_printable_hole_size" ,"notes",
|
|
"wipe_tower_cone_angle", "wipe_tower_extra_spacing", "wipe_tower_extruder", "wiping_volumes_extruders","wipe_tower_bridging", "single_extruder_multi_material_priming",
|
|
"wipe_tower_rotation_angle", "tree_support_branch_distance_organic", "tree_support_branch_diameter_organic", "tree_support_branch_angle_organic",
|
|
"hole_to_polyhole", "hole_to_polyhole_threshold", "hole_to_polyhole_twisted", "mmu_segmented_region_max_width", "mmu_segmented_region_interlocking_depth",
|
|
};
|
|
|
|
static std::vector<std::string> s_Preset_filament_options {
|
|
/*"filament_colour", */ "default_filament_colour","required_nozzle_HRC","filament_diameter", "filament_type", "filament_soluble", "filament_is_support",
|
|
"filament_max_volumetric_speed",
|
|
"filament_flow_ratio", "filament_density", "filament_cost", "filament_minimal_purge_on_wipe_tower",
|
|
"nozzle_temperature", "nozzle_temperature_initial_layer",
|
|
// BBS
|
|
"cool_plate_temp", "eng_plate_temp", "hot_plate_temp", "textured_plate_temp", "cool_plate_temp_initial_layer", "eng_plate_temp_initial_layer", "hot_plate_temp_initial_layer","textured_plate_temp_initial_layer",
|
|
// "bed_type",
|
|
//BBS:temperature_vitrification
|
|
"temperature_vitrification", "reduce_fan_stop_start_freq", "slow_down_for_layer_cooling", "fan_min_speed",
|
|
"fan_max_speed", "enable_overhang_bridge_fan", "overhang_fan_speed", "overhang_fan_threshold", "close_fan_the_first_x_layers", "full_fan_speed_layer", "fan_cooling_layer_time", "slow_down_layer_time", "slow_down_min_speed",
|
|
"filament_start_gcode", "filament_end_gcode",
|
|
//exhaust fan control
|
|
"activate_air_filtration","during_print_exhaust_fan_speed","complete_print_exhaust_fan_speed",
|
|
// Retract overrides
|
|
"filament_retraction_length", "filament_z_hop", "filament_z_hop_types", "filament_retract_lift_above", "filament_retract_lift_below", "filament_retract_lift_enforce", "filament_retraction_speed", "filament_deretraction_speed", "filament_retract_restart_extra", "filament_retraction_minimum_travel",
|
|
"filament_retract_when_changing_layer", "filament_wipe", "filament_retract_before_wipe",
|
|
// Profile compatibility
|
|
"filament_vendor", "compatible_prints", "compatible_prints_condition", "compatible_printers", "compatible_printers_condition", "inherits",
|
|
//BBS
|
|
"filament_wipe_distance", "additional_cooling_fan_speed",
|
|
"nozzle_temperature_range_low", "nozzle_temperature_range_high",
|
|
//SoftFever
|
|
"enable_pressure_advance", "pressure_advance","chamber_temperature", "filament_shrink", "support_material_interface_fan_speed", "filament_notes" /*,"filament_seam_gap"*/,
|
|
"filament_loading_speed", "filament_loading_speed_start", "filament_load_time",
|
|
"filament_unloading_speed", "filament_unloading_speed_start", "filament_unload_time", "filament_toolchange_delay", "filament_cooling_moves",
|
|
"filament_cooling_initial_speed", "filament_cooling_final_speed", "filament_ramming_parameters",
|
|
"filament_multitool_ramming", "filament_multitool_ramming_volume", "filament_multitool_ramming_flow", "activate_chamber_temp_control"
|
|
};
|
|
|
|
static std::vector<std::string> s_Preset_machine_limits_options {
|
|
"machine_max_acceleration_extruding", "machine_max_acceleration_retracting", "machine_max_acceleration_travel",
|
|
"machine_max_acceleration_x", "machine_max_acceleration_y", "machine_max_acceleration_z", "machine_max_acceleration_e",
|
|
"machine_max_speed_x", "machine_max_speed_y", "machine_max_speed_z", "machine_max_speed_e",
|
|
"machine_min_extruding_rate", "machine_min_travel_rate",
|
|
"machine_max_jerk_x", "machine_max_jerk_y", "machine_max_jerk_z", "machine_max_jerk_e",
|
|
};
|
|
|
|
static std::vector<std::string> s_Preset_printer_options {
|
|
"printer_technology",
|
|
"printable_area", "bed_exclude_area","bed_custom_texture", "bed_custom_model", "gcode_flavor",
|
|
"fan_kickstart", "fan_speedup_time", "fan_speedup_overhangs",
|
|
"single_extruder_multi_material", "manual_filament_change", "machine_start_gcode", "machine_end_gcode", "before_layer_change_gcode", "printing_by_object_gcode", "layer_change_gcode", "time_lapse_gcode", "change_filament_gcode", "change_extrusion_role_gcode",
|
|
"printer_model", "printer_variant", "printable_height", "extruder_clearance_radius", "extruder_clearance_height_to_lid", "extruder_clearance_height_to_rod",
|
|
"default_print_profile", "inherits",
|
|
"silent_mode",
|
|
// BBS
|
|
"scan_first_layer", "machine_load_filament_time", "machine_unload_filament_time","time_cost", "machine_pause_gcode", "template_custom_gcode",
|
|
"nozzle_type", "nozzle_hrc","auxiliary_fan", "nozzle_volume","upward_compatible_machine", "z_hop_types", "retract_lift_enforce","support_chamber_temp_control","support_air_filtration","printer_structure",
|
|
"best_object_pos","head_wrap_detect_zone",
|
|
//SoftFever
|
|
"host_type", "print_host", "printhost_apikey",
|
|
"print_host_webui",
|
|
"printhost_cafile","printhost_port","printhost_authorization_type",
|
|
"printhost_user", "printhost_password", "printhost_ssl_ignore_revoke", "thumbnails", "thumbnails_format",
|
|
"use_firmware_retraction", "use_relative_e_distances", "printer_notes",
|
|
"cooling_tube_retraction",
|
|
"cooling_tube_length", "high_current_on_filament_swap", "parking_pos_retraction", "extra_loading_move", "purge_in_prime_tower", "enable_filament_ramming",
|
|
"z_offset",
|
|
"disable_m73", "preferred_orientation"
|
|
};
|
|
|
|
static std::vector<std::string> s_Preset_sla_print_options {
|
|
"layer_height",
|
|
"faded_layers",
|
|
"supports_enable",
|
|
"support_head_front_diameter",
|
|
"support_head_penetration",
|
|
"support_head_width",
|
|
"support_pillar_diameter",
|
|
"support_small_pillar_diameter_percent",
|
|
"support_max_bridges_on_pillar",
|
|
"support_pillar_connection_mode",
|
|
"support_buildplate_only",
|
|
"support_pillar_widening_factor",
|
|
"support_base_diameter",
|
|
"support_base_height",
|
|
"support_base_safety_distance",
|
|
"support_critical_angle",
|
|
"support_max_bridge_length",
|
|
"support_max_pillar_link_distance",
|
|
"support_object_elevation",
|
|
"support_points_density_relative",
|
|
"support_points_minimal_distance",
|
|
"slice_closing_radius",
|
|
"pad_enable",
|
|
"pad_wall_thickness",
|
|
"pad_wall_height",
|
|
"pad_brim_size",
|
|
"pad_max_merge_distance",
|
|
// "pad_edge_radius",
|
|
"pad_wall_slope",
|
|
"pad_object_gap",
|
|
"pad_around_object",
|
|
"pad_around_object_everywhere",
|
|
"pad_object_connector_stride",
|
|
"pad_object_connector_width",
|
|
"pad_object_connector_penetration",
|
|
"hollowing_enable",
|
|
"hollowing_min_thickness",
|
|
"hollowing_quality",
|
|
"hollowing_closing_distance",
|
|
"filename_format",
|
|
"default_sla_print_profile",
|
|
"compatible_printers",
|
|
"compatible_printers_condition",
|
|
"inherits"
|
|
};
|
|
|
|
static std::vector<std::string> s_Preset_sla_material_options {
|
|
"material_colour",
|
|
"material_type",
|
|
"initial_layer_height",
|
|
"bottle_cost",
|
|
"bottle_volume",
|
|
"bottle_weight",
|
|
"material_density",
|
|
"exposure_time",
|
|
"initial_exposure_time",
|
|
"material_correction",
|
|
"material_correction_x",
|
|
"material_correction_y",
|
|
"material_correction_z",
|
|
"material_vendor",
|
|
"material_print_speed",
|
|
"default_sla_material_profile",
|
|
"compatible_prints", "compatible_prints_condition",
|
|
"compatible_printers", "compatible_printers_condition", "inherits"
|
|
};
|
|
|
|
static std::vector<std::string> s_Preset_sla_printer_options {
|
|
"printer_technology",
|
|
"printable_area","bed_custom_texture", "bed_custom_model", "printable_height",
|
|
"display_width", "display_height", "display_pixels_x", "display_pixels_y",
|
|
"display_mirror_x", "display_mirror_y",
|
|
"display_orientation",
|
|
"fast_tilt_time", "slow_tilt_time", "area_fill",
|
|
"relative_correction",
|
|
"relative_correction_x",
|
|
"relative_correction_y",
|
|
"relative_correction_z",
|
|
"absolute_correction",
|
|
"elefant_foot_compensation",
|
|
"elefant_foot_min_width",
|
|
"gamma_correction",
|
|
"min_exposure_time", "max_exposure_time",
|
|
"min_initial_exposure_time", "max_initial_exposure_time",
|
|
"inherits"
|
|
};
|
|
|
|
const std::vector<std::string>& Preset::print_options() { return s_Preset_print_options; }
|
|
const std::vector<std::string>& Preset::filament_options() { return s_Preset_filament_options; }
|
|
const std::vector<std::string>& Preset::machine_limits_options() { return s_Preset_machine_limits_options; }
|
|
// The following nozzle options of a printer profile will be adjusted to match the size
|
|
// of the nozzle_diameter vector.
|
|
const std::vector<std::string>& Preset::nozzle_options() { return print_config_def.extruder_option_keys(); }
|
|
const std::vector<std::string>& Preset::sla_print_options() { return s_Preset_sla_print_options; }
|
|
const std::vector<std::string>& Preset::sla_material_options() { return s_Preset_sla_material_options; }
|
|
const std::vector<std::string>& Preset::sla_printer_options() { return s_Preset_sla_printer_options; }
|
|
|
|
const std::vector<std::string>& Preset::printer_options()
|
|
{
|
|
static std::vector<std::string> s_opts = [](){
|
|
std::vector<std::string> opts = s_Preset_printer_options;
|
|
append(opts, s_Preset_machine_limits_options);
|
|
append(opts, Preset::nozzle_options());
|
|
return opts;
|
|
}();
|
|
return s_opts;
|
|
}
|
|
|
|
PresetCollection::PresetCollection(Preset::Type type, const std::vector<std::string> &keys, const Slic3r::StaticPrintConfig &defaults, const std::string &default_name) :
|
|
m_type(type),
|
|
m_edited_preset(type, "", false),
|
|
m_saved_preset(type, "", false),
|
|
m_idx_selected(0)
|
|
{
|
|
// Insert just the default preset.
|
|
this->add_default_preset(keys, defaults, default_name);
|
|
m_edited_preset.config.apply(m_presets.front().config);
|
|
update_saved_preset_from_current_preset();
|
|
}
|
|
|
|
//BBS: add operator= implemention
|
|
PresetCollection& PresetCollection::operator=(const PresetCollection &rhs)
|
|
{
|
|
m_type = rhs.m_type;
|
|
m_presets = rhs.m_presets;
|
|
m_map_alias_to_profile_name = rhs.m_map_alias_to_profile_name;
|
|
m_map_system_profile_renamed = rhs.m_map_system_profile_renamed;
|
|
m_edited_preset = rhs.m_edited_preset;
|
|
m_saved_preset = rhs.m_saved_preset;
|
|
m_idx_selected = rhs.m_idx_selected;
|
|
m_default_suppressed = rhs.m_default_suppressed;
|
|
m_num_default_presets = rhs.m_num_default_presets;
|
|
m_dir_path = rhs.m_dir_path;
|
|
|
|
return *this;
|
|
}
|
|
|
|
void PresetCollection::reset(bool delete_files)
|
|
{
|
|
//BBS: add lock logic for sync preset in background
|
|
lock();
|
|
if (m_presets.size() > m_num_default_presets) {
|
|
if (delete_files) {
|
|
// Erase the preset files.
|
|
for (Preset &preset : m_presets)
|
|
if (! preset.is_default && ! preset.is_external && ! preset.is_system) {
|
|
//BBS remove idx and ini files
|
|
preset.remove_files();
|
|
}
|
|
}
|
|
// Don't use m_presets.resize() here as it requires a default constructor for Preset.
|
|
m_presets.erase(m_presets.begin() + m_num_default_presets, m_presets.end());
|
|
this->select_preset(0);
|
|
}
|
|
//BBS: add lock logic for sync preset in background
|
|
unlock();
|
|
m_map_alias_to_profile_name.clear();
|
|
m_map_system_profile_renamed.clear();
|
|
}
|
|
|
|
void PresetCollection::add_default_preset(const std::vector<std::string> &keys, const Slic3r::StaticPrintConfig &defaults, const std::string &preset_name)
|
|
{
|
|
// Insert just the default preset.
|
|
m_presets.emplace_back(Preset(this->type(), preset_name, true));
|
|
m_presets.back().config.apply_only(defaults, keys.empty() ? defaults.keys() : keys);
|
|
m_presets.back().loaded = true;
|
|
++ m_num_default_presets;
|
|
}
|
|
|
|
// Load all presets found in dir_path.
|
|
// Throws an exception on error.
|
|
void PresetCollection::load_presets(
|
|
const std::string &dir_path, const std::string &subdir,
|
|
PresetsConfigSubstitutions& substitutions, ForwardCompatibilitySubstitutionRule substitution_rule)
|
|
{
|
|
// Don't use boost::filesystem::canonical() on Windows, it is broken in regard to reparse points,
|
|
// see https://github.com/prusa3d/PrusaSlicer/issues/732
|
|
boost::filesystem::path dir = boost::filesystem::absolute(boost::filesystem::path(dir_path) / subdir).make_preferred();
|
|
|
|
// Load custom roots first
|
|
if (fs::exists(dir / "base")) {
|
|
load_presets(dir.string(), "base", substitutions, substitution_rule);
|
|
}
|
|
|
|
//BBS: add config related logs
|
|
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(" enter, load presets from %1%, current type %2%")%dir %Preset::get_type_string(m_type);
|
|
//BBS do not parse folder if not exists
|
|
m_dir_path = dir.string();
|
|
if (!fs::exists(dir)) {
|
|
fs::create_directory(dir);
|
|
return;
|
|
}
|
|
|
|
std::string errors_cummulative;
|
|
// Store the loaded presets into a new vector, otherwise the binary search for already existing presets would be broken.
|
|
// (see the "Preset already present, not loading" message).
|
|
std::deque<Preset> presets_loaded;
|
|
//BBS: change to json format
|
|
for (auto &dir_entry : boost::filesystem::directory_iterator(dir))
|
|
{
|
|
std::string file_name = dir_entry.path().filename().string();
|
|
//if (Slic3r::is_ini_file(dir_entry)) {
|
|
if (Slic3r::is_json_file(file_name)) {
|
|
// Remove the .ini suffix.
|
|
std::string name = file_name.erase(file_name.size() - 5);
|
|
if (this->find_preset(name, false)) {
|
|
// This happens when there's is a preset (most likely legacy one) with the same name as a system preset
|
|
// that's already been loaded from a bundle.
|
|
BOOST_LOG_TRIVIAL(warning) << "Preset already present, not loading: " << name;
|
|
continue;
|
|
}
|
|
try {
|
|
Preset preset(m_type, name, false);
|
|
preset.file = dir_entry.path().string();
|
|
// Load the preset file, apply preset values on top of defaults.
|
|
try {
|
|
fs::path idx_path(preset.file);
|
|
idx_path.replace_extension(".info");
|
|
if (fs::exists(idx_path)) {
|
|
preset.load_info(idx_path.string());
|
|
}
|
|
DynamicPrintConfig config;
|
|
//BBS: change to json format
|
|
//ConfigSubstitutions config_substitutions = config.load_from_ini(preset.file, substitution_rule);
|
|
std::map<std::string, std::string> key_values;
|
|
std::string reason;
|
|
ConfigSubstitutions config_substitutions = config.load_from_json(preset.file, substitution_rule, key_values, reason);
|
|
if (! config_substitutions.empty())
|
|
substitutions.push_back({ preset.name, m_type, PresetConfigSubstitutions::Source::UserFile, preset.file, std::move(config_substitutions) });
|
|
if (!reason.empty()) {
|
|
fs::path file_path(preset.file);
|
|
if (fs::exists(file_path))
|
|
fs::remove(file_path);
|
|
file_path.replace_extension(".info");
|
|
if (fs::exists(file_path))
|
|
fs::remove(file_path);
|
|
BOOST_LOG_TRIVIAL(error) << boost::format("parse config %1% failed")%preset.file;
|
|
continue;
|
|
}
|
|
|
|
std::string version_str = key_values[BBL_JSON_KEY_VERSION];
|
|
boost::optional<Semver> version = Semver::parse(version_str);
|
|
if (!version) continue;
|
|
Semver app_version = *(Semver::parse(SLIC3R_VERSION));
|
|
if ( version->maj() != app_version.maj()) {
|
|
BOOST_LOG_TRIVIAL(warning) << "Preset incompatibla, not loading: " << name;
|
|
continue;
|
|
}
|
|
preset.version = *version;
|
|
|
|
if (key_values.find(BBL_JSON_KEY_FILAMENT_ID) != key_values.end())
|
|
preset.filament_id = key_values[BBL_JSON_KEY_FILAMENT_ID];
|
|
if (key_values.find(BBL_JSON_KEY_IS_CUSTOM) != key_values.end())
|
|
preset.custom_defined = key_values[BBL_JSON_KEY_IS_CUSTOM];
|
|
if (key_values.find("instantiation") != key_values.end())
|
|
preset.is_visible = key_values["instantiation"] != "false";
|
|
|
|
//BBS: use inherit config as the base
|
|
Preset* inherit_preset = nullptr;
|
|
ConfigOption* inherits_config = config.option(BBL_JSON_KEY_INHERITS);
|
|
|
|
// check inherits_config
|
|
if (inherits_config) {
|
|
ConfigOptionString * option_str = dynamic_cast<ConfigOptionString *> (inherits_config);
|
|
std::string inherits_value = option_str->value;
|
|
inherit_preset = this->find_preset(inherits_value, false, true);
|
|
} else {
|
|
;
|
|
}
|
|
const Preset& default_preset = this->default_preset_for(config);
|
|
if (inherit_preset) {
|
|
preset.config = inherit_preset->config;
|
|
preset.filament_id = inherit_preset->filament_id;
|
|
}
|
|
else {
|
|
// We support custom root preset now
|
|
auto inherits_config2 = dynamic_cast<ConfigOptionString *>(inherits_config);
|
|
if ((inherits_config2 && !inherits_config2->value.empty()) && !preset.is_custom_defined()) {
|
|
BOOST_LOG_TRIVIAL(error) << boost::format("can not find parent for config %1%!")%preset.file;
|
|
continue;
|
|
}
|
|
// Find a default preset for the config. The PrintPresetCollection provides different default preset based on the "printer_technology" field.
|
|
preset.config = default_preset.config;
|
|
}
|
|
preset.config.apply(std::move(config));
|
|
Preset::normalize(preset.config);
|
|
// Report configuration fields, which are misplaced into a wrong group.
|
|
std::string incorrect_keys = Preset::remove_invalid_keys(preset.config, default_preset.config);
|
|
if (!incorrect_keys.empty())
|
|
BOOST_LOG_TRIVIAL(error) << "Error in a preset file: The preset \"" <<
|
|
preset.file << "\" contains the following incorrect keys: " << incorrect_keys << ", which were removed";
|
|
preset.loaded = true;
|
|
//BBS: add some workaround for previous incorrect settings
|
|
if ((!preset.setting_id.empty())&&(preset.setting_id == preset.base_id))
|
|
preset.setting_id.clear();
|
|
//BBS: add config related logs
|
|
BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << boost::format(", preset type %1%, name %2%, path %3%, is_system %4%, is_default %5% is_visible %6%")%Preset::get_type_string(m_type) %preset.name %preset.file %preset.is_system %preset.is_default %preset.is_visible;
|
|
} catch (const std::ifstream::failure &err) {
|
|
BOOST_LOG_TRIVIAL(error) << boost::format("The user-config cannot be loaded: %1%. Reason: %2%")%preset.file %err.what();
|
|
fs::path file_path(preset.file);
|
|
if (fs::exists(file_path))
|
|
fs::remove(file_path);
|
|
file_path.replace_extension(".info");
|
|
if (fs::exists(file_path))
|
|
fs::remove(file_path);
|
|
//throw Slic3r::RuntimeError(std::string("The selected preset cannot be loaded: ") + preset.file + "\n\tReason: " + err.what());
|
|
} catch (const std::runtime_error &err) {
|
|
BOOST_LOG_TRIVIAL(error) << boost::format("Failed loading the user-config file: %1%. Reason: %2%")%preset.file %err.what();
|
|
//throw Slic3r::RuntimeError(std::string("Failed loading the preset file: ") + preset.file + "\n\tReason: " + err.what());
|
|
fs::path file_path(preset.file);
|
|
if (fs::exists(file_path))
|
|
fs::remove(file_path);
|
|
file_path.replace_extension(".info");
|
|
if (fs::exists(file_path))
|
|
fs::remove(file_path);
|
|
}
|
|
presets_loaded.emplace_back(preset);
|
|
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << __LINE__ << " load config successful and preset name is:" << preset.name;
|
|
} catch (const std::runtime_error &err) {
|
|
errors_cummulative += err.what();
|
|
errors_cummulative += "\n";
|
|
}
|
|
}
|
|
}
|
|
if (presets_loaded.size() > 0)
|
|
m_presets.insert(m_presets.end(), std::make_move_iterator(presets_loaded.begin()), std::make_move_iterator(presets_loaded.end()));
|
|
std::sort(m_presets.begin() + m_num_default_presets, m_presets.end());
|
|
//BBS: add config related logs
|
|
BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << boost::format(": loaded %1% presets from %2%, type %3%")%presets_loaded.size() %dir %Preset::get_type_string(m_type);
|
|
//this->select_preset(first_visible_idx());
|
|
if (! errors_cummulative.empty())
|
|
throw Slic3r::RuntimeError(errors_cummulative);
|
|
}
|
|
|
|
//BBS: add function to generate differed preset for save
|
|
//the pointer should be freed by the caller
|
|
Preset* PresetCollection::get_preset_differed_for_save(Preset& preset)
|
|
{
|
|
if (preset.is_system || preset.is_default)
|
|
return nullptr;
|
|
|
|
Preset* new_preset = new Preset();
|
|
*new_preset = preset;
|
|
|
|
//BBS: only save difference for user preset
|
|
std::string& inherits = preset.inherits();
|
|
Preset* parent_preset = nullptr;
|
|
if (!inherits.empty()) {
|
|
parent_preset = this->find_preset(inherits, false, true);
|
|
}
|
|
if (parent_preset) {
|
|
DynamicPrintConfig temp_config;
|
|
std::vector<std::string> dirty_options = preset.config.diff(parent_preset->config);
|
|
|
|
for (auto option: dirty_options)
|
|
{
|
|
ConfigOption *opt_src = preset.config.option(option);
|
|
ConfigOption *opt_dst = temp_config.option(option, true);
|
|
opt_dst->set(opt_src);
|
|
}
|
|
new_preset->config = temp_config;
|
|
}
|
|
|
|
return new_preset;
|
|
}
|
|
|
|
//BBS:get the differencen values to update
|
|
int PresetCollection::get_differed_values_to_update(Preset& preset, std::map<std::string, std::string>& key_values)
|
|
{
|
|
if (preset.is_system || preset.is_default || preset.is_project_embedded) {
|
|
BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << boost::format(" Error: not a user preset! Should not happen, name %1%") %preset.name;
|
|
return -1;
|
|
}
|
|
|
|
//BBS: only save difference for user preset
|
|
std::string& inherit_preset = preset.inherits();
|
|
Preset* parent_preset = nullptr;
|
|
if (!inherit_preset.empty()) {
|
|
parent_preset = this->find_preset(inherit_preset, false, true);
|
|
}
|
|
if (parent_preset) {
|
|
DynamicPrintConfig temp_config;
|
|
std::vector<std::string> dirty_options = preset.config.diff(parent_preset->config);
|
|
|
|
for (auto option: dirty_options)
|
|
{
|
|
ConfigOption *opt_src = preset.config.option(option);
|
|
if (opt_src)
|
|
key_values[option] = opt_src->serialize();
|
|
}
|
|
}
|
|
else {
|
|
for (auto iter = preset.config.cbegin(); iter != preset.config.cend(); ++iter)
|
|
{
|
|
key_values[iter->first] = iter->second->serialize();
|
|
}
|
|
}
|
|
|
|
//add other values
|
|
key_values[BBL_JSON_KEY_VERSION] = preset.version.to_string();
|
|
if (!preset.base_id.empty()) {
|
|
key_values[BBL_JSON_KEY_BASE_ID] = preset.base_id;
|
|
} else {
|
|
key_values.erase(BBL_JSON_KEY_BASE_ID);
|
|
if (get_preset_base(preset) == &preset && !preset.filament_id.empty()) {
|
|
key_values[BBL_JSON_KEY_FILAMENT_ID] = preset.filament_id;
|
|
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " uploading user preset name is: " << preset.name << "and create filament id is: " << preset.filament_id;
|
|
}
|
|
}
|
|
key_values[BBL_JSON_KEY_UPDATE_TIME] = std::to_string(preset.updated_time);
|
|
key_values[BBL_JSON_KEY_TYPE] = Preset::get_iot_type_string(preset.type);
|
|
return 0;
|
|
}
|
|
|
|
//BBS: save user presets to local
|
|
void PresetCollection::load_project_embedded_presets(std::vector<Preset*>& project_presets, const std::string& type, PresetsConfigSubstitutions& substitutions, ForwardCompatibilitySubstitutionRule rule)
|
|
{
|
|
std::string errors_cummulative;
|
|
// Store the loaded presets into a new vector, otherwise the binary search for already existing presets would be broken.
|
|
// (see the "Preset already present, not loading" message).
|
|
std::deque<Preset> presets_loaded;
|
|
std::vector<Preset*>::iterator it;
|
|
|
|
BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << boost::format(" enter, type %1% , total preset counts %2%")%Preset::get_type_string(m_type) %project_presets.size();
|
|
lock();
|
|
for (it = project_presets.begin(); it != project_presets.end(); it++) {
|
|
Preset* preset = *it;
|
|
if (preset->type != Preset::get_type_from_string(type)) continue;
|
|
if (!preset->is_project_embedded) continue;
|
|
std::string name = preset->name;
|
|
if (this->find_preset(name, false)) {
|
|
BOOST_LOG_TRIVIAL(warning) << "Preset already present, not loading: " << name;
|
|
continue;
|
|
}
|
|
try {
|
|
DynamicPrintConfig config = preset->config;
|
|
if (preset->loading_substitutions && ! preset->loading_substitutions->empty()) {
|
|
substitutions.push_back({ preset->name, m_type, PresetConfigSubstitutions::Source::ProjectFile, preset->name, std::move(*(preset->loading_substitutions))});
|
|
free(preset->loading_substitutions);
|
|
preset->loading_substitutions = NULL;
|
|
}
|
|
//BBS: use inherit config as the base
|
|
Preset* inherit_preset = nullptr;
|
|
ConfigOption* inherits_config = config.option(BBL_JSON_KEY_INHERITS);
|
|
if (inherits_config) {
|
|
ConfigOptionString * option_str = dynamic_cast<ConfigOptionString *> (inherits_config);
|
|
std::string inherits_value = option_str->value;
|
|
/*size_t pos = inherits_value.find_first_of('*');
|
|
if (pos != std::string::npos) {
|
|
inherits_value.replace(pos, 1, 1, '~');
|
|
option_str->value = inherits_value;
|
|
}*/
|
|
inherit_preset = this->find_preset(inherits_value, false, true);
|
|
}
|
|
const Preset& default_preset = this->default_preset_for(config);
|
|
if (inherit_preset) {
|
|
preset->config = inherit_preset->config;
|
|
preset->filament_id = inherit_preset->filament_id;
|
|
}
|
|
else {
|
|
// Find a default preset for the config. The PrintPresetCollection provides different default preset based on the "printer_technology" field.
|
|
preset->config = default_preset.config;
|
|
BOOST_LOG_TRIVIAL(warning) << boost::format("can not find parent for config %1%!")%preset->file;
|
|
//continue;
|
|
}
|
|
preset->config.apply(std::move(config));
|
|
Preset::normalize(preset->config);
|
|
// Report configuration fields, which are misplaced into a wrong group.
|
|
std::string incorrect_keys = Preset::remove_invalid_keys(preset->config, default_preset.config);
|
|
if (! incorrect_keys.empty())
|
|
BOOST_LOG_TRIVIAL(error) << "Error in a preset file: The preset \"" <<
|
|
preset->name << "\" contains the following incorrect keys: " << incorrect_keys << ", which were removed";
|
|
preset->loaded = true;
|
|
presets_loaded.emplace_back(*preset);
|
|
BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << boost::format(", %1% got preset, name %2%, path %3%, is_system %4%, is_default %5% is_visible %6%")%Preset::get_type_string(m_type) %preset->name %preset->file %preset->is_system %preset->is_default %preset->is_visible;
|
|
} catch (const std::runtime_error &err) {
|
|
errors_cummulative += err.what();
|
|
errors_cummulative += "\n";
|
|
}
|
|
}
|
|
|
|
m_presets.insert(m_presets.end(), std::make_move_iterator(presets_loaded.begin()), std::make_move_iterator(presets_loaded.end()));
|
|
std::sort(m_presets.begin() + m_num_default_presets, m_presets.end());
|
|
//don't select it here
|
|
//this->select_preset(first_visible_idx());
|
|
unlock();
|
|
|
|
BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << boost::format(" finished, %1% got %2% presets, errors_cummulative %3%")%Preset::get_type_string(m_type) %presets_loaded.size() %errors_cummulative;
|
|
if (! errors_cummulative.empty())
|
|
throw Slic3r::RuntimeError(errors_cummulative);
|
|
}
|
|
|
|
//BBS: get project embedded presets from
|
|
std::vector<Preset*> PresetCollection::get_project_embedded_presets()
|
|
{
|
|
std::vector<Preset*> project_presets;
|
|
|
|
lock();
|
|
for (Preset &preset : m_presets) {
|
|
//if (preset.type != Preset::get_type_from_string(type)) continue;
|
|
if (!preset.is_project_embedded) continue;
|
|
|
|
Preset* new_preset = get_preset_differed_for_save(preset);
|
|
|
|
project_presets.push_back(new_preset);
|
|
}
|
|
unlock();
|
|
BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << boost::format(" enter, type %1% , total preset counts %2%")%Preset::get_type_string(m_type) %project_presets.size();
|
|
return project_presets;
|
|
}
|
|
|
|
//BBS: reset project embedded presets
|
|
bool PresetCollection::reset_project_embedded_presets()
|
|
{
|
|
std::deque<Preset>::iterator it = m_presets.begin();
|
|
bool re_select = false;
|
|
int count = -1;
|
|
|
|
lock();
|
|
while ( it!=m_presets.end() )
|
|
{
|
|
count++;
|
|
//if (preset.type != Preset::get_type_from_string(type)) continue;
|
|
if (it->is_project_embedded) {
|
|
BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << boost::format(" type %1% , delete preset %2%")%Preset::get_type_string(m_type) % it->name;
|
|
if ((!re_select) && (m_idx_selected == count))
|
|
re_select = true;
|
|
if (m_idx_selected > count) {
|
|
m_idx_selected--;
|
|
count--;
|
|
}
|
|
it = m_presets.erase(it);
|
|
}
|
|
else
|
|
it++;
|
|
}
|
|
|
|
if (re_select)
|
|
m_idx_selected = -1;
|
|
|
|
unlock();
|
|
|
|
return re_select;
|
|
}
|
|
|
|
void PresetCollection::set_sync_info_and_save(std::string name, std::string setting_id, std::string syncinfo, long long update_time)
|
|
{
|
|
lock();
|
|
for (auto it = m_presets.begin(); it != m_presets.end(); it++) {
|
|
Preset* preset = &m_presets[it - m_presets.begin()];
|
|
if (preset->name == name) {
|
|
if (syncinfo.empty())
|
|
preset->sync_info.clear();
|
|
else
|
|
preset->sync_info = syncinfo;
|
|
if (get_preset_base(*preset) == preset) {
|
|
for (auto & preset2 : m_presets)
|
|
if (preset2.inherits() == preset->name) {
|
|
preset2.base_id = setting_id;
|
|
preset2.save_info();
|
|
}
|
|
}
|
|
preset->setting_id = setting_id;
|
|
if (update_time > 0)
|
|
preset->updated_time = update_time;
|
|
preset->sync_info == "update" ? preset->save(nullptr) : preset->save_info();
|
|
break;
|
|
}
|
|
}
|
|
unlock();
|
|
}
|
|
|
|
bool PresetCollection::need_sync(std::string name, std::string setting_id, long long update_time)
|
|
{
|
|
lock();
|
|
auto preset = find_preset(name, false, true);
|
|
bool need = preset == nullptr || preset->setting_id != setting_id || preset->updated_time < update_time;
|
|
unlock();
|
|
return need;
|
|
}
|
|
|
|
//BBS: get user presets
|
|
int PresetCollection::get_user_presets(PresetBundle *preset_bundle, std::vector<Preset> &result_presets)
|
|
{
|
|
int count = 0;
|
|
result_presets.clear();
|
|
|
|
lock();
|
|
for (Preset &preset : m_presets) {
|
|
if (!preset.is_user()) continue;
|
|
if (get_preset_base(preset) != &preset && preset.base_id.empty()) continue;
|
|
if (!preset.setting_id.empty() && preset.sync_info.empty()) continue;
|
|
//if (!preset.is_bbl_vendor_preset(preset_bundle)) continue;
|
|
if (preset.sync_info == "hold") continue;
|
|
|
|
result_presets.push_back(preset);
|
|
count++;
|
|
}
|
|
unlock();
|
|
|
|
return count;
|
|
}
|
|
|
|
//BBS: update user presets directory
|
|
void PresetCollection::update_user_presets_directory(const std::string& dir_path, const std::string& type)
|
|
{
|
|
boost::filesystem::path dir = boost::filesystem::absolute(boost::filesystem::path(dir_path) / type).make_preferred();
|
|
|
|
if (!fs::exists(dir))
|
|
fs::create_directory(dir);
|
|
|
|
m_dir_path = dir.string();
|
|
}
|
|
|
|
//BBS: save user presets to local
|
|
void PresetCollection::save_user_presets(const std::string& dir_path, const std::string& type, std::vector<std::string>& need_to_delete_list)
|
|
{
|
|
boost::filesystem::path dir = boost::filesystem::absolute(boost::filesystem::path(dir_path) / type).make_preferred();
|
|
|
|
if (!fs::exists(dir))
|
|
fs::create_directory(dir);
|
|
|
|
m_dir_path = dir.string();
|
|
|
|
std::vector<std::string> delete_name_list;
|
|
//std::map<std::string, Preset*>::iterator it;
|
|
//for (it = my_presets.begin(); it != my_presets.end(); it++) {
|
|
for (auto it = m_presets.begin(); it != m_presets.end(); it++) {
|
|
Preset* preset = &m_presets[it - m_presets.begin()];
|
|
if (!preset->is_user()) continue;
|
|
if (preset->sync_info != "save") continue;
|
|
preset->sync_info.clear();
|
|
preset->file = path_for_preset(*preset);
|
|
|
|
if (preset->is_custom_defined()) {
|
|
preset->save(nullptr);
|
|
} else {
|
|
//BBS: only save difference for user preset
|
|
std::string inherits = Preset::inherits(preset->config);
|
|
if (inherits.empty()) {
|
|
// We support custom root preset now
|
|
//BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << boost::format(" can not find inherits for %1% , should not happen")%preset->name;
|
|
//// BBS add sync info
|
|
//preset->sync_info = "delete";
|
|
//need_to_delete_list.push_back(preset->setting_id);
|
|
//delete_name_list.push_back(preset->name);
|
|
preset->save(nullptr);
|
|
continue;
|
|
}
|
|
Preset* parent_preset = this->find_preset(inherits, false, true);
|
|
if (!parent_preset) {
|
|
BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << boost::format(" can not find parent preset for %1% , inherits %2%")%preset->name %inherits;
|
|
continue;
|
|
}
|
|
|
|
if (preset->base_id.empty())
|
|
preset->base_id = parent_preset->setting_id;
|
|
preset->save(&(parent_preset->config));
|
|
}
|
|
}
|
|
|
|
for (auto delete_name: delete_name_list)
|
|
{
|
|
this->delete_preset(delete_name);
|
|
}
|
|
delete_name_list.clear();
|
|
|
|
return;
|
|
}
|
|
|
|
//BBS: load one user preset from key-values
|
|
bool PresetCollection::load_user_preset(std::string name, std::map<std::string, std::string> preset_values, PresetsConfigSubstitutions& substitutions, ForwardCompatibilitySubstitutionRule rule)
|
|
{
|
|
std::string errors_cummulative;
|
|
// Store the loaded presets into a new vector, otherwise the binary search for already existing presets would be broken.
|
|
// (see the "Preset already present, not loading" message).
|
|
//std::deque<Preset> presets_loaded;
|
|
int count = 0;
|
|
|
|
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(" enter, name %1% , total value counts %2%")%name %preset_values.size();
|
|
|
|
//if the version is not matching, skip it
|
|
if (preset_values.find(BBL_JSON_KEY_VERSION) == preset_values.end()) {
|
|
BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << boost::format("can not find version, not loading for user preset %1%")%name;
|
|
return false;
|
|
}
|
|
std::string version_str = preset_values[BBL_JSON_KEY_VERSION];
|
|
boost::optional<Semver> cloud_version = Semver::parse(version_str);
|
|
if (!cloud_version) {
|
|
BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << boost::format("invalid version %1%, not loading for user preset %2%")%version_str %name;
|
|
return false;
|
|
}
|
|
Semver app_version = *(Semver::parse(SLIC3R_VERSION));
|
|
if ( cloud_version->maj() != app_version.maj()) {
|
|
BOOST_LOG_TRIVIAL(warning)<< __FUNCTION__ << boost::format("version %1% mismatch with app version %2%, not loading for user preset %3%")%version_str %SLIC3R_VERSION %name;
|
|
return false;
|
|
}
|
|
|
|
//setting_id
|
|
if (preset_values.find(BBL_JSON_KEY_SETTING_ID) == preset_values.end()) {
|
|
BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << boost::format("can not find setting_id, not loading for user preset %1%")%name;
|
|
return false;
|
|
}
|
|
std::string cloud_setting_id = preset_values[BBL_JSON_KEY_SETTING_ID];
|
|
|
|
//update_time
|
|
long long cloud_update_time = 0;
|
|
if (preset_values.find(BBL_JSON_KEY_UPDATE_TIME) != preset_values.end()) {
|
|
cloud_update_time = std::atoll(preset_values[BBL_JSON_KEY_UPDATE_TIME].c_str());
|
|
}
|
|
|
|
//user_id
|
|
if (preset_values.find(BBL_JSON_KEY_USER_ID) == preset_values.end()) {
|
|
BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << boost::format("can not find user_id, not loading for user preset %1%")%name;
|
|
return false;
|
|
}
|
|
std::string cloud_user_id = preset_values[BBL_JSON_KEY_USER_ID];
|
|
|
|
lock();
|
|
//std::string name = preset->name;
|
|
auto iter = this->find_preset_internal(name);
|
|
bool need_update = false;
|
|
if ((iter != m_presets.end()) && (iter->name == name)) {
|
|
BOOST_LOG_TRIVIAL(info) << "Found the Preset locally: " << name;
|
|
//BBS: we should compare the time between cloud and local
|
|
if ((cloud_update_time == 0) || (cloud_update_time <= iter->updated_time)) {
|
|
if (cloud_update_time < iter->updated_time)
|
|
iter->sync_info = "update";
|
|
else
|
|
iter->sync_info.clear();
|
|
// Fixup possible data lost
|
|
iter->setting_id = cloud_setting_id;
|
|
fs::path idx_file(iter->file);
|
|
idx_file.replace_extension(".info");
|
|
iter->save_info(idx_file.string());
|
|
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format("preset %1%'s update_time is eqaul or newer, cloud update_time %2%, local update_time %3%")%name %cloud_update_time %iter->updated_time;
|
|
unlock();
|
|
return false;
|
|
}
|
|
else {
|
|
//update the one from cloud which is newer
|
|
need_update = true;
|
|
}
|
|
}
|
|
|
|
// base_id
|
|
if (preset_values.find(BBL_JSON_KEY_BASE_ID) == preset_values.end()) {
|
|
BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << boost::format("can not find base_id, not loading for user preset %1%") % name;
|
|
unlock();
|
|
return false;
|
|
}
|
|
std::string cloud_base_id = preset_values[BBL_JSON_KEY_BASE_ID];
|
|
|
|
//filament_id
|
|
std::string cloud_filament_id;
|
|
if ((m_type == Preset::TYPE_FILAMENT) && preset_values.find(BBL_JSON_KEY_FILAMENT_ID) != preset_values.end()) {
|
|
cloud_filament_id = preset_values[BBL_JSON_KEY_FILAMENT_ID];
|
|
}
|
|
|
|
DynamicPrintConfig new_config, cloud_config;
|
|
try {
|
|
ConfigSubstitutions config_substitutions = cloud_config.load_string_map(preset_values, rule);
|
|
if (! config_substitutions.empty())
|
|
substitutions.push_back({ name, m_type, PresetConfigSubstitutions::Source::UserCloud, name, std::move(config_substitutions) });
|
|
|
|
//BBS: use inherit config as the base
|
|
Preset* inherit_preset = nullptr;
|
|
ConfigOption* inherits_config = cloud_config.option(BBL_JSON_KEY_INHERITS);
|
|
if (inherits_config) {
|
|
ConfigOptionString * option_str = dynamic_cast<ConfigOptionString *> (inherits_config);
|
|
std::string inherits_value = option_str->value;
|
|
/*size_t pos = inherits_value.find_first_of('*');
|
|
if (pos != std::string::npos) {
|
|
inherits_value.replace(pos, 1, 1, '~');
|
|
option_str->value = inherits_value;
|
|
}*/
|
|
inherit_preset = this->find_preset(inherits_value, false, true);
|
|
}
|
|
const Preset& default_preset = this->default_preset_for(cloud_config);
|
|
if (inherit_preset) {
|
|
new_config = inherit_preset->config;
|
|
}
|
|
else {
|
|
// We support custom root preset now
|
|
auto inherits_config2 = dynamic_cast<ConfigOptionString *>(inherits_config);
|
|
if (inherits_config2 && !inherits_config2->value.empty()) {
|
|
//we should skip this preset here
|
|
BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << boost::format(", can not find inherit preset for user preset %1%, just skip")%name;
|
|
unlock();
|
|
return false;
|
|
}
|
|
// Find a default preset for the config. The PrintPresetCollection provides different default preset based on the "printer_technology" field.
|
|
new_config = default_preset.config;
|
|
}
|
|
new_config.apply(std::move(cloud_config));
|
|
Preset::normalize(new_config);
|
|
// Report configuration fields, which are misplaced into a wrong group.
|
|
std::string incorrect_keys = Preset::remove_invalid_keys(new_config, default_preset.config);
|
|
if (! incorrect_keys.empty())
|
|
BOOST_LOG_TRIVIAL(error) << "Error in a preset file: The preset \"" <<
|
|
name << "\" contains the following incorrect keys: " << incorrect_keys << ", which were removed";
|
|
if (need_update) {
|
|
if (iter->name == m_edited_preset.name && iter->is_dirty) {
|
|
// Keep modifies when update from remote
|
|
new_config.apply_only(m_edited_preset.config, m_edited_preset.config.diff(iter->config));
|
|
}
|
|
iter->config = new_config;
|
|
iter->updated_time = cloud_update_time;
|
|
iter->sync_info = "save";
|
|
iter->version = cloud_version.value();
|
|
iter->user_id = cloud_user_id;
|
|
iter->setting_id = cloud_setting_id;
|
|
iter->base_id = cloud_base_id;
|
|
iter->filament_id = cloud_filament_id;
|
|
//presets_loaded.emplace_back(*it->second);
|
|
BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << boost::format(", update the user preset %1% from cloud, type %2%, setting_id %3%, base_id %4%, sync_info %5% inherits %6%")
|
|
% iter->name %Preset::get_type_string(m_type) %iter->setting_id %iter->base_id %iter->sync_info %iter->inherits();
|
|
}
|
|
else {
|
|
//create a new one
|
|
Preset preset(m_type, name, false);
|
|
preset.is_system = false;
|
|
preset.loaded = true;
|
|
preset.config = new_config;
|
|
preset.updated_time = cloud_update_time;
|
|
preset.sync_info = "save";
|
|
preset.version = cloud_version.value();
|
|
preset.user_id = cloud_user_id;
|
|
preset.setting_id = cloud_setting_id;
|
|
preset.base_id = cloud_base_id;
|
|
preset.filament_id = cloud_filament_id;
|
|
|
|
size_t cur_index = iter - m_presets.begin();
|
|
m_presets.insert(iter, preset);
|
|
//m_presets.emplace_back (preset);
|
|
BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << boost::format(", insert a new user preset %1%, type %2%, setting_id %3%, base_id %4%, sync_info %5% inherits %6%")
|
|
%preset.name %Preset::get_type_string(m_type) %preset.setting_id %preset.base_id %preset.sync_info %preset.inherits();
|
|
if (cur_index <= m_idx_selected) {
|
|
m_idx_selected ++;
|
|
BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << boost::format(", increase m_idx_selected to %1%, due to user preset inserted")%m_idx_selected;
|
|
}
|
|
}
|
|
} catch (const std::runtime_error &err) {
|
|
errors_cummulative += err.what();
|
|
errors_cummulative += "\n";
|
|
}
|
|
|
|
unlock();
|
|
|
|
if (! errors_cummulative.empty())
|
|
throw Slic3r::RuntimeError(errors_cummulative);
|
|
|
|
BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << boost::format(" finished, load user preset %1% , type %2%, errors_cummulative %3%")%name %Preset::get_type_string(m_type) %errors_cummulative;
|
|
return (need_update)?false:true;
|
|
}
|
|
|
|
//re-sort and re-select
|
|
void PresetCollection::update_after_user_presets_loaded()
|
|
{
|
|
lock();
|
|
std::string selected_name = get_selected_preset_name();
|
|
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(", before sort, type %1%, selected_idx %2%, selected_name %3%") %m_type %m_idx_selected %selected_name;
|
|
std::sort(m_presets.begin() + m_num_default_presets, m_presets.end());
|
|
this->select_preset_by_name(selected_name, false);
|
|
unlock();
|
|
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(", after sort, type %1%, selected_idx %2%") %m_type %m_idx_selected;
|
|
|
|
return;
|
|
}
|
|
|
|
//BBS: validate_preset
|
|
bool PresetCollection::validate_preset(const std::string &preset_name, std::string &inherit_name)
|
|
{
|
|
std::deque<Preset>::iterator it = this->find_preset_internal(preset_name);
|
|
bool found = (it != m_presets.end()) && (it->name == preset_name) && (it->is_system || it->is_default);
|
|
if (!found) {
|
|
it = this->find_preset_renamed(preset_name);
|
|
found = it != m_presets.end() && (it->is_system || it->is_default);
|
|
}
|
|
if (!found) {
|
|
if (!inherit_name.empty()) {
|
|
it = this->find_preset_internal(inherit_name);
|
|
found = it != m_presets.end() && it->name == inherit_name && (it->is_system || it->is_default);
|
|
if (found)
|
|
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": preset_name %1%, inherit_name %2%, found inherit in list")%preset_name %inherit_name;
|
|
else
|
|
BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << boost::format(": preset_name %1%, inherit_name %2%, can not found preset and inherit in list")%preset_name %inherit_name;
|
|
}
|
|
else {
|
|
//inherit is null , should not happen , just consider it as valid
|
|
found = false;
|
|
BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << boost::format(": preset_name %1%, no inherit, set to not found")%preset_name;
|
|
}
|
|
}
|
|
else {
|
|
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": preset_name %1%, found in list")%preset_name;
|
|
}
|
|
|
|
return found;
|
|
}
|
|
|
|
|
|
// Load a preset from an already parsed config file, insert it into the sorted sequence of presets
|
|
// and select it, losing previous modifications.
|
|
Preset& PresetCollection::load_preset(const std::string &path, const std::string &name, const DynamicPrintConfig &config, bool select, Semver file_version, bool is_custom_defined)
|
|
{
|
|
DynamicPrintConfig cfg(this->default_preset().config);
|
|
cfg.apply_only(config, cfg.keys(), true);
|
|
return this->load_preset(path, name, std::move(cfg), select, file_version, is_custom_defined);
|
|
}
|
|
|
|
static bool profile_print_params_same(const DynamicPrintConfig &cfg_old, const DynamicPrintConfig &cfg_new)
|
|
{
|
|
t_config_option_keys diff = cfg_old.diff(cfg_new);
|
|
// Following keys are used by the UI, not by the slicing core, therefore they are not important
|
|
// when comparing profiles for equality. Ignore them.
|
|
for (const char *key : { "compatible_prints", "compatible_prints_condition",
|
|
"compatible_printers", "compatible_printers_condition", "inherits",
|
|
"print_settings_id", "filament_settings_id", "sla_print_settings_id", "sla_material_settings_id", "printer_settings_id",
|
|
"printer_model", "printer_variant", "default_print_profile", "default_filament_profile", "default_sla_print_profile", "default_sla_material_profile"
|
|
})
|
|
diff.erase(std::remove(diff.begin(), diff.end(), key), diff.end());
|
|
// Preset with the same name as stored inside the config exists.
|
|
return diff.empty();
|
|
}
|
|
|
|
// Load a preset from an already parsed config file, insert it into the sorted sequence of presets
|
|
// and select it, losing previous modifications.
|
|
// Only a single profile could be edited at at the same time, which introduces complexity when loading
|
|
// filament profiles for multi-extruder printers.
|
|
std::pair<Preset*, bool> PresetCollection::load_external_preset(
|
|
// Path to the profile source file (a G-code, an AMF or 3MF file, a config file)
|
|
const std::string &path,
|
|
// Name of the profile, derived from the source file name.
|
|
const std::string &name,
|
|
// Original name of the profile, extracted from the loaded config. Empty, if the name has not been stored.
|
|
const std::string &original_name,
|
|
// Config to initialize the preset from. It may contain configs of all presets merged in a single dictionary!
|
|
const DynamicPrintConfig &combined_config,
|
|
//different settings list
|
|
const std::set<std::string> &different_settings_list,
|
|
// Select the preset after loading?
|
|
LoadAndSelect select,
|
|
const Semver file_version,
|
|
const std::string filament_id)
|
|
{
|
|
// Load the preset over a default preset, so that the missing fields are filled in from the default preset.
|
|
DynamicPrintConfig cfg(this->default_preset_for(combined_config).config);
|
|
// SoftFever: ignore print connection info from project
|
|
auto keys = cfg.keys();
|
|
keys.erase(std::remove_if(keys.begin(), keys.end(),
|
|
[](std::string &val) {
|
|
return val == "print_host" || val == "print_host_webui" || val == "printhost_apikey" ||
|
|
val == "printhost_cafile";
|
|
}),
|
|
keys.end());
|
|
cfg.apply_only(combined_config, keys, true);
|
|
std::string &inherits = Preset::inherits(cfg);
|
|
|
|
//BBS: add different settings check logic, replace the old system preset's default value with new system preset's default values
|
|
std::deque<Preset>::iterator it = this->find_preset_internal(original_name);
|
|
bool found = it != m_presets.end() && it->name == original_name;
|
|
if (! found) {
|
|
// Try to match the original_name against the "renamed_from" profile names of loaded system profiles.
|
|
it = this->find_preset_renamed(original_name);
|
|
found = it != m_presets.end();
|
|
}
|
|
if (!inherits.empty() && (different_settings_list.size() > 0)) {
|
|
auto iter = this->find_preset_internal(inherits);
|
|
if (iter != m_presets.end() && iter->name == inherits) {
|
|
//std::vector<std::string> dirty_options = cfg.diff(iter->config);
|
|
for (auto &opt : keys) {
|
|
if (different_settings_list.find(opt) != different_settings_list.end())
|
|
continue;
|
|
ConfigOption *opt_src = iter->config.option(opt);
|
|
ConfigOption *opt_dst = cfg.option(opt);
|
|
if (opt_src && opt_dst && (*opt_src != *opt_dst)) {
|
|
BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << boost::format(" change key %1% from old_value %2% to inherit's value %3%, preset_name %4%, inherits_name %5%")
|
|
%opt %(opt_dst->serialize()) %(opt_src->serialize()) %original_name %inherits;
|
|
opt_dst->set(opt_src);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else if (found && it->is_system && (different_settings_list.size() > 0)) {
|
|
for (auto &opt : keys) {
|
|
if (different_settings_list.find(opt) != different_settings_list.end())
|
|
continue;
|
|
ConfigOption *opt_src = it->config.option(opt);
|
|
ConfigOption *opt_dst = cfg.option(opt);
|
|
if (opt_src && opt_dst && (*opt_src != *opt_dst)) {
|
|
BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << boost::format(" change key %1% from old_value %2% to new_value %3%, preset_name %4%")
|
|
%opt %(opt_dst->serialize()) %(opt_src->serialize()) %original_name;
|
|
opt_dst->set(opt_src);
|
|
}
|
|
}
|
|
}
|
|
|
|
//BBS: add config related logs
|
|
BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << boost::format(" enter, type %1% , path %2%, name %3%, original_name %4%, inherits %5%")%Preset::get_type_string(m_type) %path %name %original_name %inherits;
|
|
if (select == LoadAndSelect::Never) {
|
|
// Some filament profile has been selected and modified already.
|
|
// Check whether this profile is equal to the modified edited profile.
|
|
const Preset &edited = this->get_edited_preset();
|
|
if ((edited.name == original_name || edited.name == inherits) && profile_print_params_same(edited.config, cfg)) {
|
|
// Just point to that already selected and edited profile.
|
|
//BBS: add config related logs
|
|
BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << boost::format(" Just point to that already selected and edited profile %1%")%edited.name;
|
|
return std::make_pair(&(*this->find_preset_internal(edited.name)), false);
|
|
}
|
|
}
|
|
// Is there a preset already loaded with the name stored inside the config?
|
|
/*std::deque<Preset>::iterator it = this->find_preset_internal(original_name);
|
|
bool found = it != m_presets.end() && it->name == original_name;
|
|
if (! found) {
|
|
// Try to match the original_name against the "renamed_from" profile names of loaded system profiles.
|
|
it = this->find_preset_renamed(original_name);
|
|
found = it != m_presets.end();
|
|
}*/
|
|
if (found && profile_print_params_same(it->config, cfg)) {
|
|
// The preset exists and it matches the values stored inside config.
|
|
if (select == LoadAndSelect::Always)
|
|
this->select_preset(it - m_presets.begin());
|
|
//BBS: set the preset to visible
|
|
if ( !it->is_visible ) {
|
|
it->is_visible = true;
|
|
//AppConfig* app_config = get_app_config();
|
|
//if (app_config)
|
|
// app_config->set(AppConfig::SECTION_FILAMENTS, it->name, "1");
|
|
}
|
|
//BBS: add config related logs
|
|
BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << boost::format(" The preset exists and it matches the values stored inside config. using original_name %1%")%original_name;
|
|
return std::make_pair(&(*it), false);
|
|
}
|
|
if (! found && select != LoadAndSelect::Never && ! inherits.empty()) {
|
|
// Try to use a system profile as a base to select the system profile
|
|
// and override its settings with the loaded ones.
|
|
assert(it == m_presets.end());
|
|
it = this->find_preset_internal(inherits);
|
|
found = it != m_presets.end() && it->name == inherits;
|
|
if (found && profile_print_params_same(it->config, cfg)) {
|
|
// The system preset exists and it matches the values stored inside config.
|
|
if (select == LoadAndSelect::Always)
|
|
this->select_preset(it - m_presets.begin());
|
|
//BBS: set the preset to visible
|
|
if ( !it->is_visible ) {
|
|
it->is_visible = true;
|
|
//AppConfig* app_config = get_app_config();
|
|
//if (app_config)
|
|
// app_config->set(AppConfig::SECTION_FILAMENTS, it->name, "1");
|
|
}
|
|
//BBS: add config related logs
|
|
BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << boost::format(" The preset exists and it matches the values stored inside config. using inherits %1%")%inherits;
|
|
return std::make_pair(&(*it), false);
|
|
}
|
|
}
|
|
if (found) {
|
|
//BBS: only select preset for always
|
|
//if (select != LoadAndSelect::Never) {
|
|
if (select == LoadAndSelect::Always) {
|
|
// Select the existing preset and override it with new values, so that
|
|
// the differences will be shown in the preset editor against the referenced profile.
|
|
this->select_preset(it - m_presets.begin());
|
|
// The source config may contain keys from many possible preset types. Just copy those that relate to this preset.
|
|
//this->get_edited_preset().config.apply_only(combined_config, keys, true);
|
|
this->get_edited_preset().config.apply_only(cfg, keys, true);
|
|
this->update_dirty();
|
|
update_saved_preset_from_current_preset();
|
|
assert(this->get_edited_preset().is_dirty);
|
|
//BBS: set the preset to visible
|
|
if ( !it->is_visible ) {
|
|
it->is_visible = true;
|
|
//AppConfig* app_config = get_app_config();
|
|
//if (app_config)
|
|
// app_config->set(AppConfig::SECTION_FILAMENTS, it->name, "1");
|
|
}
|
|
//BBS: add config related logs
|
|
BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << boost::format(" Select the existing preset %1% and override it with new values")%it->name;
|
|
return std::make_pair(&(*it), this->get_edited_preset().is_dirty);
|
|
}
|
|
|
|
//BBS: for other filaments under AMS
|
|
if (it->is_project_embedded) {
|
|
//update the properties back to the preset
|
|
it->config.apply_only(cfg, keys, true);
|
|
it->is_dirty = false;
|
|
|
|
return std::make_pair(&(*it), false);
|
|
}
|
|
if (inherits.empty()) {
|
|
// Update the "inherits" field.
|
|
// There is a profile with the same name already loaded. Should we update the "inherits" field?
|
|
inherits = it->vendor ? it->name : it->inherits();
|
|
}
|
|
}
|
|
|
|
// The external preset does not match an internal preset, load the external preset.
|
|
std::string new_name;
|
|
//BBS: add project embedded preset logic
|
|
//BBS: refine the name logic
|
|
for (size_t idx = 0;; ++ idx) {
|
|
std::string prefix;
|
|
if (original_name.empty()) {
|
|
if (!inherits.empty()) {
|
|
if (idx == 0)
|
|
prefix = inherits;
|
|
else
|
|
prefix = inherits + "-" + std::to_string(idx);
|
|
}
|
|
else {
|
|
if (idx > 0)
|
|
prefix = std::to_string(idx);
|
|
}
|
|
} else {
|
|
std::string reduced_name = original_name;
|
|
//TODO
|
|
//boost::regex rx("3mf\(*\)");
|
|
//boost::iterator_range<std::string::iterator> result = boost::algorithm::find_regex(reduced_name, rx);
|
|
//if (!result.empty()) {
|
|
// reduced_name = std::string(result.begin(), result.end());
|
|
//}
|
|
|
|
if (idx == 0)
|
|
prefix = reduced_name;
|
|
else
|
|
prefix = reduced_name + "-" + std::to_string(idx) ;
|
|
}
|
|
//new_name = name + suffix;
|
|
new_name = prefix + "(" + name + ")";
|
|
it = this->find_preset_internal(new_name);
|
|
if (it == m_presets.end() || it->name != new_name)
|
|
// Unique profile name. Insert a new profile.
|
|
break;
|
|
if (profile_print_params_same(it->config, cfg)) {
|
|
// The preset exists and it matches the values stored inside config.
|
|
if (select == LoadAndSelect::Always)
|
|
this->select_preset(it - m_presets.begin());
|
|
//BBS: add config related logs
|
|
BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << boost::format(" The preset %1% exists and it matches the values stored inside config.")%new_name;
|
|
return std::make_pair(&(*it), false);
|
|
}
|
|
// Form another profile name.
|
|
}
|
|
// Insert a new profile.
|
|
//BBS: add project embedded preset logic
|
|
bool from_project = boost::algorithm::iends_with(name, ".3mf");
|
|
if (m_type == Preset::TYPE_PRINT)
|
|
cfg.option<ConfigOptionString >("print_settings_id", true)->value = new_name;
|
|
else if (m_type == Preset::TYPE_FILAMENT)
|
|
cfg.option<ConfigOptionStrings>("filament_settings_id", true)->values[0] = new_name;
|
|
else if (m_type == Preset::TYPE_PRINTER)
|
|
cfg.option<ConfigOptionString>("printer_settings_id", true)->value = new_name;
|
|
Preset &preset = this->load_preset(path, new_name, std::move(cfg), select == LoadAndSelect::Always);
|
|
preset.is_external = true;
|
|
preset.version = file_version;
|
|
if (!filament_id.empty())
|
|
preset.filament_id = filament_id;
|
|
else {
|
|
if (!inherits.empty()) {
|
|
Preset *parent = this->find_preset(inherits, false, true);
|
|
if (parent)
|
|
preset.filament_id = parent->filament_id;
|
|
}
|
|
}
|
|
if (from_project) {
|
|
preset.is_project_embedded = true;
|
|
}
|
|
else {
|
|
//external config
|
|
preset.file = path_for_preset(preset);
|
|
//BBS: save full config here for external
|
|
//we can not reach here
|
|
preset.save(nullptr);
|
|
}
|
|
if (&this->get_selected_preset() == &preset)
|
|
this->get_edited_preset().is_external = true;
|
|
|
|
//BBS: add config related logs
|
|
BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << boost::format(", type %1% added a preset, name %2%, path %3%, is_system %4%, is_default %5% is_external %6%")%Preset::get_type_string(m_type) %preset.name %preset.file %preset.is_system %preset.is_default %preset.is_external;
|
|
return std::make_pair(&preset, false);
|
|
}
|
|
|
|
Preset& PresetCollection::load_preset(const std::string &path, const std::string &name, DynamicPrintConfig &&config, bool select, Semver file_version, bool is_custom_defined)
|
|
{
|
|
lock();
|
|
auto it = this->find_preset_internal(name);
|
|
if (it == m_presets.end() || it->name != name) {
|
|
// The preset was not found. Create a new preset.
|
|
if (m_presets.begin() + m_idx_selected >= it)
|
|
++m_idx_selected;
|
|
it = m_presets.emplace(it, Preset(m_type, name, false));
|
|
}
|
|
Preset &preset = *it;
|
|
preset.file = path;
|
|
preset.config = std::move(config);
|
|
preset.loaded = true;
|
|
preset.is_dirty = false;
|
|
preset.custom_defined = is_custom_defined ? "1": "0";
|
|
//BBS
|
|
if (file_version.valid())
|
|
preset.version = file_version;
|
|
if (select)
|
|
this->select_preset_by_name(name, true);
|
|
unlock();
|
|
//BBS: add config related logs
|
|
BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << boost::format(", preset type %1%, name %2%, path %3%, is_system %4%, is_default %5% is_visible %6%")%Preset::get_type_string(m_type) %preset.name %preset.file %preset.is_system %preset.is_default %preset.is_visible;
|
|
return preset;
|
|
}
|
|
|
|
bool PresetCollection::clone_presets(std::vector<Preset const *> const &presets, std::vector<std::string> &failures, std::function<void(Preset &, Preset::Type &)> modifier, bool force_rewritten)
|
|
{
|
|
std::vector<Preset> new_presets;
|
|
for (auto curr_preset : presets) {
|
|
new_presets.push_back(*curr_preset);
|
|
auto &preset = new_presets.back();
|
|
preset.vendor = nullptr;
|
|
preset.renamed_from.clear();
|
|
preset.setting_id.clear();
|
|
preset.inherits().clear();
|
|
preset.is_default = false;
|
|
preset.is_system = false;
|
|
preset.is_external = false;
|
|
preset.is_visible = true;
|
|
preset.is_project_embedded = false;
|
|
modifier(preset, m_type);
|
|
if (find_preset(preset.name) && !force_rewritten) {
|
|
failures.push_back(preset.name);
|
|
}
|
|
preset.file = this->path_for_preset(preset);
|
|
if (m_type == Preset::TYPE_PRINT)
|
|
preset.config.option<ConfigOptionString>("print_settings_id", true)->value = preset.name;
|
|
else if (m_type == Preset::TYPE_FILAMENT)
|
|
preset.config.option<ConfigOptionStrings>("filament_settings_id", true)->values[0] = preset.name;
|
|
else if (m_type == Preset::TYPE_PRINTER)
|
|
preset.config.option<ConfigOptionString>("printer_settings_id", true)->value = preset.name;
|
|
}
|
|
if (!failures.empty() && !force_rewritten)
|
|
return false;
|
|
lock();
|
|
auto old_name = this->get_edited_preset().name;
|
|
for (auto preset : new_presets) {
|
|
preset.alias.clear();
|
|
auto it = this->find_preset_internal(preset.name);
|
|
assert((it == m_presets.end() || it->name != preset.name) || force_rewritten);
|
|
if (it == m_presets.end() || it->name != preset.name) {
|
|
Preset &new_preset = *m_presets.insert(it, preset);
|
|
new_preset.save(nullptr);
|
|
} else if (force_rewritten) {
|
|
*it = preset;
|
|
(*it).save(nullptr);
|
|
}
|
|
}
|
|
this->select_preset_by_name(old_name, true);
|
|
unlock();
|
|
return true;
|
|
}
|
|
|
|
bool PresetCollection::clone_presets_for_printer(std::vector<Preset const *> const &presets, std::vector<std::string> &failures, std::string const &printer, bool force_rewritten)
|
|
{
|
|
return clone_presets(presets, failures, [printer](Preset &preset, Preset::Type &type) {
|
|
std::string prefix = preset.name.substr(0, preset.name.find(" @"));
|
|
std::replace(prefix.begin(), prefix.end(), '/', '-');
|
|
preset.name = prefix + " @" + printer;
|
|
//preset.alias = "";
|
|
auto *compatible_printers = dynamic_cast<ConfigOptionStrings *>(preset.config.option("compatible_printers"));
|
|
compatible_printers->values = std::vector<std::string>{ printer };
|
|
}, force_rewritten);
|
|
}
|
|
|
|
bool PresetCollection::create_presets_from_template_for_printer(std::vector<Preset const *> const & templates,
|
|
std::vector<std::string> & failures,
|
|
std::string const & printer,
|
|
std::function<std::string(std::string)> create_filament_id,
|
|
bool force_rewritten)
|
|
{
|
|
return clone_presets(templates, failures, [printer, create_filament_id](Preset &preset, Preset::Type &type) {
|
|
std::string prefix = preset.name.substr(0, preset.name.find(" @"));
|
|
std::replace(prefix.begin(), prefix.end(), '/', '-');
|
|
preset.name = prefix + " @" + printer;
|
|
auto *compatible_printers = dynamic_cast<ConfigOptionStrings *>(preset.config.option("compatible_printers"));
|
|
compatible_printers->values = std::vector<std::string>{printer};
|
|
preset.is_visible = true;
|
|
if (type == Preset::TYPE_FILAMENT)
|
|
preset.filament_id = create_filament_id(prefix);
|
|
}, force_rewritten);
|
|
}
|
|
|
|
bool PresetCollection::clone_presets_for_filament(Preset const *const & preset,
|
|
std::vector<std::string> &failures,
|
|
std::string const & filament_name,
|
|
std::string const & filament_id,
|
|
const DynamicConfig & dynamic_config,
|
|
const std::string & compatible_printers,
|
|
bool force_rewritten)
|
|
{
|
|
std::vector<Preset const *> const presets = {preset};
|
|
return clone_presets(presets, failures, [&filament_name, &filament_id, &dynamic_config, &compatible_printers](Preset &preset, Preset::Type &type) {
|
|
preset.name = filament_name + " @" + compatible_printers;
|
|
if (type == Preset::TYPE_FILAMENT) {
|
|
preset.config.apply_only(dynamic_config, {"filament_vendor", "compatible_printers", "filament_type"},true);
|
|
|
|
preset.filament_id = filament_id;
|
|
}
|
|
},
|
|
force_rewritten);
|
|
}
|
|
|
|
std::map<std::string, std::vector<Preset const *>> PresetCollection::get_filament_presets() const
|
|
{
|
|
std::map<std::string, std::vector<Preset const *>> filament_presets;
|
|
for (auto &preset : m_presets) {
|
|
if (get_preset_base(preset) == &preset) { filament_presets[preset.filament_id].push_back(&preset); }
|
|
}
|
|
return filament_presets;
|
|
}
|
|
|
|
//BBS: add project embedded preset logic
|
|
void PresetCollection::save_current_preset(const std::string &new_name, bool detach, bool save_to_project, Preset* _curr_preset)
|
|
{
|
|
Preset curr_preset = _curr_preset ? *_curr_preset : m_edited_preset;
|
|
//BBS: add lock logic for sync preset in background
|
|
std::string final_inherits;
|
|
lock();
|
|
// 1) Find the preset with a new_name or create a new one,
|
|
// initialize it with the edited config.
|
|
auto it = this->find_preset_internal(new_name);
|
|
if (it != m_presets.end() && it->name == new_name) {
|
|
// Preset with the same name found.
|
|
Preset &preset = *it;
|
|
//BBS: add project embedded preset logic
|
|
if (preset.is_default || preset.is_system) {
|
|
//if (preset.is_default || preset.is_external || preset.is_system)
|
|
// Cannot overwrite the default preset.
|
|
//BBS: add lock logic for sync preset in background
|
|
unlock();
|
|
return;
|
|
}
|
|
// Overwriting an existing preset.
|
|
preset.config = std::move(curr_preset.config);
|
|
// The newly saved preset will be activated -> make it visible.
|
|
preset.is_visible = true;
|
|
//TODO: remove the detach logic
|
|
if (detach) {
|
|
// Clear the link to the parent profile.
|
|
preset.vendor = nullptr;
|
|
preset.inherits().clear();
|
|
preset.alias.clear();
|
|
preset.renamed_from.clear();
|
|
BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << boost::format(": save preset %1% , with detach")%new_name;
|
|
}
|
|
//BBS: add lock logic for sync preset in background
|
|
|
|
if (m_type == Preset::TYPE_PRINT)
|
|
preset.config.option<ConfigOptionString>("print_settings_id", true)->value = new_name;
|
|
else if (m_type == Preset::TYPE_FILAMENT)
|
|
preset.config.option<ConfigOptionStrings>("filament_settings_id", true)->values[0] = new_name;
|
|
else if (m_type == Preset::TYPE_PRINTER)
|
|
preset.config.option<ConfigOptionString>("printer_settings_id", true)->value = new_name;
|
|
final_inherits = preset.inherits();
|
|
unlock();
|
|
// TODO: apply change from custom root to devided presets.
|
|
if (preset.inherits().empty()) {
|
|
for (auto &preset2 : m_presets)
|
|
if (preset2.inherits() == preset.name)
|
|
preset2.reload(preset);
|
|
}
|
|
} else {
|
|
// Creating a new preset.
|
|
Preset &preset = *m_presets.insert(it, curr_preset);
|
|
std::string &inherits = preset.inherits();
|
|
std::string old_name = preset.name;
|
|
preset.name = new_name;
|
|
preset.vendor = nullptr;
|
|
preset.alias.clear();
|
|
preset.renamed_from.clear();
|
|
preset.setting_id.clear();
|
|
if (detach) {
|
|
// Clear the link to the parent profile.
|
|
inherits.clear();
|
|
BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << boost::format(": save preset %1% , with detach")%new_name;
|
|
} else {
|
|
// Inherited from a user preset. Just maintain the "inherited" flag,
|
|
// meaning it will inherit from either the system preset, or the inherited user preset.
|
|
auto base = get_preset_base(curr_preset);
|
|
inherits = base ? base->name : "";
|
|
}
|
|
preset.is_default = false;
|
|
preset.is_system = false;
|
|
preset.is_external = false;
|
|
preset.file = this->path_for_preset(preset);
|
|
// The newly saved preset will be activated -> make it visible.
|
|
preset.is_visible = true;
|
|
// Just system presets have aliases
|
|
preset.alias.clear();
|
|
//BBS: add project embedded preset logic
|
|
if (save_to_project) {
|
|
preset.is_project_embedded = true;
|
|
}
|
|
else
|
|
preset.is_project_embedded = false;
|
|
if (m_type == Preset::TYPE_PRINT)
|
|
preset.config.option<ConfigOptionString>("print_settings_id", true)->value = new_name;
|
|
else if (m_type == Preset::TYPE_FILAMENT)
|
|
preset.config.option<ConfigOptionStrings>("filament_settings_id", true)->values[0] = new_name;
|
|
else if (m_type == Preset::TYPE_PRINTER)
|
|
preset.config.option<ConfigOptionString>("printer_settings_id", true)->value = new_name;
|
|
//BBS: add lock logic for sync preset in background
|
|
final_inherits = inherits;
|
|
unlock();
|
|
}
|
|
// 2) Activate the saved preset.
|
|
this->select_preset_by_name(new_name, true);
|
|
// 2) Store the active preset to disk.
|
|
//BBS: only save difference for user preset
|
|
Preset* parent_preset = nullptr;
|
|
if (!final_inherits.empty()) {
|
|
parent_preset = this->find_preset(final_inherits, false, true);
|
|
if (parent_preset && this->get_selected_preset().base_id.empty()) {
|
|
this->get_selected_preset().base_id = parent_preset->setting_id;
|
|
}
|
|
}
|
|
if (parent_preset)
|
|
this->get_selected_preset().save(&(parent_preset->config));
|
|
else
|
|
this->get_selected_preset().save(nullptr);
|
|
}
|
|
|
|
bool PresetCollection::delete_current_preset()
|
|
{
|
|
Preset &selected = this->get_selected_preset();
|
|
if (selected.is_default)
|
|
return false;
|
|
|
|
if (get_preset_base(selected) == &selected) {
|
|
for (auto &preset2 : m_presets)
|
|
if (preset2.inherits() == selected.name)
|
|
return false;
|
|
}
|
|
|
|
//BBS: add project embedded preset logic and refine is_external
|
|
//if (! selected.is_external && ! selected.is_system) {
|
|
if (! selected.is_system) {
|
|
//BBS Erase the preset file.
|
|
selected.remove_files();
|
|
}
|
|
//BBS: add lock logic for sync preset in background
|
|
lock();
|
|
// Remove the preset from the list.
|
|
m_presets.erase(m_presets.begin() + m_idx_selected);
|
|
unlock();
|
|
|
|
// Find the next visible preset.
|
|
size_t new_selected_idx = m_idx_selected;
|
|
if (new_selected_idx < m_presets.size())
|
|
for (; new_selected_idx < m_presets.size() && ! m_presets[new_selected_idx].is_visible; ++ new_selected_idx) ;
|
|
if (new_selected_idx == m_presets.size())
|
|
for (--new_selected_idx; new_selected_idx > 0 && !m_presets[new_selected_idx].is_visible; --new_selected_idx);
|
|
this->select_preset(new_selected_idx);
|
|
return true;
|
|
}
|
|
|
|
bool PresetCollection::delete_preset(const std::string& name)
|
|
{
|
|
auto it = this->find_preset_internal(name);
|
|
|
|
Preset& preset = *it;
|
|
if (preset.is_default)
|
|
return false;
|
|
//BBS: add project embedded preset logic and refine is_external
|
|
//if (!preset.is_external && !preset.is_system) {
|
|
if (! preset.is_system) {
|
|
preset.remove_files();
|
|
}
|
|
//BBS: add lock logic for sync preset in background
|
|
lock();
|
|
m_presets.erase(it);
|
|
unlock();
|
|
|
|
return true;
|
|
}
|
|
|
|
const Preset* PresetCollection::get_selected_preset_parent() const
|
|
{
|
|
if (this->get_selected_idx() == size_t(-1))
|
|
// This preset collection has no preset activated yet. Only the get_edited_preset() is valid.
|
|
return nullptr;
|
|
|
|
const Preset &selected_preset = this->get_selected_preset();
|
|
if (get_preset_base(selected_preset) == &selected_preset)
|
|
return &selected_preset;
|
|
|
|
const Preset &edited_preset = this->get_edited_preset();
|
|
const std::string &inherits = edited_preset.inherits();
|
|
const Preset *preset = nullptr;
|
|
if (inherits.empty()) {
|
|
if (selected_preset.is_external)
|
|
return nullptr;
|
|
preset = &this->default_preset(m_type == Preset::Type::TYPE_PRINTER && edited_preset.printer_technology() == ptSLA ? 1 : 0);
|
|
} else
|
|
preset = this->find_preset(inherits, false);
|
|
if (preset == nullptr) {
|
|
// Resolve the "renamed_from" field.
|
|
assert(! inherits.empty());
|
|
auto it = this->find_preset_renamed(inherits);
|
|
if (it != m_presets.end())
|
|
preset = &(*it);
|
|
}
|
|
//BBS: add project embedded preset logic and refine is_external
|
|
return (preset == nullptr/* || preset->is_default || preset->is_external*/) ? nullptr : preset;
|
|
//return (preset == nullptr/* || preset->is_default*/ || preset->is_external) ? nullptr : preset;
|
|
}
|
|
|
|
const Preset* PresetCollection::get_preset_parent(const Preset& child) const
|
|
{
|
|
const std::string &inherits = child.inherits();
|
|
if (inherits.empty())
|
|
// return this->get_selected_preset().is_system ? &this->get_selected_preset() : nullptr;
|
|
return nullptr;
|
|
const Preset* preset = this->find_preset(inherits, false);
|
|
if (preset == nullptr) {
|
|
auto it = this->find_preset_renamed(inherits);
|
|
if (it != m_presets.end())
|
|
preset = &(*it);
|
|
}
|
|
return
|
|
// not found
|
|
(preset == nullptr/* || preset->is_default */||
|
|
// this should not happen, user profile should not derive from an external profile
|
|
//BBS: add project embedded preset logic and refine is_external
|
|
/*preset->is_external ||*/
|
|
// this should not happen, however people are creative, see GH #4996
|
|
preset == &child) ?
|
|
nullptr :
|
|
preset;
|
|
}
|
|
|
|
const Preset *PresetCollection::get_preset_base(const Preset &child) const
|
|
{
|
|
if (child.is_system || child.is_default)
|
|
return &child;
|
|
// Handle user preset
|
|
if (child.inherits().empty())
|
|
return &child; // this is user root
|
|
auto inherits = find_preset(child.inherits());
|
|
return inherits ? get_preset_base(*inherits) : nullptr;
|
|
}
|
|
|
|
// Return vendor of the first parent profile, for which the vendor is defined, or null if such profile does not exist.
|
|
PresetWithVendorProfile PresetCollection::get_preset_with_vendor_profile(const Preset &preset) const
|
|
{
|
|
const Preset *p = &preset;
|
|
const VendorProfile *v = nullptr;
|
|
do {
|
|
if (p->vendor != nullptr) {
|
|
v = p->vendor;
|
|
break;
|
|
}
|
|
p = this->get_preset_parent(*p);
|
|
} while (p != nullptr);
|
|
return PresetWithVendorProfile(preset, v);
|
|
}
|
|
|
|
const std::string& PresetCollection::get_preset_name_by_alias(const std::string& alias) const
|
|
{
|
|
for (
|
|
// Find the 1st profile name with the alias.
|
|
auto it = Slic3r::lower_bound_by_predicate(m_map_alias_to_profile_name.begin(), m_map_alias_to_profile_name.end(), [&alias](auto &l){ return l.first < alias; });
|
|
// Continue over all profile names with the same alias.
|
|
it != m_map_alias_to_profile_name.end() && it->first == alias; ++ it)
|
|
if (auto it_preset = this->find_preset_internal(it->second);
|
|
it_preset != m_presets.end() && it_preset->name == it->second &&
|
|
it_preset->is_visible && (it_preset->is_compatible || size_t(it_preset - m_presets.begin()) == m_idx_selected))
|
|
return it_preset->name;
|
|
return alias;
|
|
}
|
|
|
|
const std::string* PresetCollection::get_preset_name_renamed(const std::string &old_name) const
|
|
{
|
|
auto it_renamed = m_map_system_profile_renamed.find(old_name);
|
|
if (it_renamed != m_map_system_profile_renamed.end())
|
|
return &it_renamed->second;
|
|
return nullptr;
|
|
}
|
|
|
|
const std::string& PresetCollection::get_suffix_modified() {
|
|
return g_suffix_modified;
|
|
}
|
|
|
|
// Return a preset by its name. If the preset is active, a temporary copy is returned.
|
|
// If a preset is not found by its name, null is returned.
|
|
Preset* PresetCollection::find_preset(const std::string &name, bool first_visible_if_not_found, bool real)
|
|
{
|
|
Preset key(m_type, name, false);
|
|
auto it = this->find_preset_internal(name);
|
|
// Ensure that a temporary copy is returned if the preset found is currently selected.
|
|
return (it != m_presets.end() && it->name == key.name) ? &this->preset(it - m_presets.begin(), real) :
|
|
first_visible_if_not_found ? &this->first_visible() : nullptr;
|
|
}
|
|
|
|
// Return index of the first visible preset. Certainly at least the '- default -' preset shall be visible.
|
|
size_t PresetCollection::first_visible_idx() const
|
|
{
|
|
//BBS: set first visible filament to fla
|
|
size_t first_visible = -1;
|
|
size_t idx = m_default_suppressed ? m_num_default_presets : 0;
|
|
for (; idx < m_presets.size(); ++ idx)
|
|
if (m_presets[idx].is_visible) {
|
|
if (first_visible == -1)
|
|
first_visible = idx;
|
|
if (m_type != Preset::TYPE_FILAMENT)
|
|
break;
|
|
else {
|
|
if (m_presets[idx].name.find("PLA") != std::string::npos) {
|
|
first_visible = idx;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
if (first_visible == -1)
|
|
first_visible = 0;
|
|
return first_visible;
|
|
}
|
|
|
|
void PresetCollection::set_default_suppressed(bool default_suppressed)
|
|
{
|
|
if (m_default_suppressed != default_suppressed) {
|
|
m_default_suppressed = default_suppressed;
|
|
bool default_visible = ! default_suppressed || m_idx_selected < m_num_default_presets;
|
|
for (size_t i = 0; i < m_num_default_presets; ++ i)
|
|
m_presets[i].is_visible = default_visible;
|
|
}
|
|
}
|
|
|
|
size_t PresetCollection::update_compatible_internal(const PresetWithVendorProfile &active_printer, const PresetWithVendorProfile *active_print, PresetSelectCompatibleType unselect_if_incompatible)
|
|
{
|
|
DynamicPrintConfig config;
|
|
config.set_key_value("printer_preset", new ConfigOptionString(active_printer.preset.name));
|
|
const ConfigOption *opt = active_printer.preset.config.option("nozzle_diameter");
|
|
if (opt)
|
|
config.set_key_value("num_extruders", new ConfigOptionInt((int)static_cast<const ConfigOptionFloats*>(opt)->values.size()));
|
|
bool some_compatible = false;
|
|
for (size_t idx_preset = m_num_default_presets; idx_preset < m_presets.size(); ++ idx_preset) {
|
|
bool selected = idx_preset == m_idx_selected;
|
|
Preset &preset_selected = m_presets[idx_preset];
|
|
Preset &preset_edited = selected ? m_edited_preset : preset_selected;
|
|
|
|
const PresetWithVendorProfile this_preset_with_vendor_profile = this->get_preset_with_vendor_profile(preset_edited);
|
|
bool was_compatible = preset_edited.is_compatible;
|
|
preset_edited.is_compatible = is_compatible_with_printer(this_preset_with_vendor_profile, active_printer, &config);
|
|
some_compatible |= preset_edited.is_compatible;
|
|
if (active_print != nullptr)
|
|
preset_edited.is_compatible &= is_compatible_with_print(this_preset_with_vendor_profile, *active_print, active_printer);
|
|
if (! preset_edited.is_compatible && selected &&
|
|
(unselect_if_incompatible == PresetSelectCompatibleType::Always || (unselect_if_incompatible == PresetSelectCompatibleType::OnlyIfWasCompatible && was_compatible)))
|
|
m_idx_selected = size_t(-1);
|
|
if (selected)
|
|
preset_selected.is_compatible = preset_edited.is_compatible;
|
|
}
|
|
// Update visibility of the default profiles here if the defaults are suppressed, the current profile is not compatible and we don't want to select another compatible profile.
|
|
if (m_idx_selected >= m_num_default_presets && m_default_suppressed)
|
|
for (size_t i = 0; i < m_num_default_presets; ++ i)
|
|
m_presets[i].is_visible = ! some_compatible;
|
|
return m_idx_selected;
|
|
}
|
|
|
|
// Update a dirty flag of the current preset
|
|
// Return true if the dirty flag changed.
|
|
bool PresetCollection::update_dirty()
|
|
{
|
|
bool was_dirty = this->get_selected_preset().is_dirty;
|
|
bool is_dirty = current_is_dirty();
|
|
this->get_selected_preset().is_dirty = is_dirty;
|
|
this->get_edited_preset().is_dirty = is_dirty;
|
|
|
|
return was_dirty != is_dirty;
|
|
}
|
|
|
|
template<class T>
|
|
void add_correct_opts_to_diff(const std::string &opt_key, t_config_option_keys& vec, const ConfigBase &other, const ConfigBase &this_c)
|
|
{
|
|
const T* opt_init = static_cast<const T*>(other.option(opt_key));
|
|
const T* opt_cur = static_cast<const T*>(this_c.option(opt_key));
|
|
int opt_init_max_id = opt_init->values.size() - 1;
|
|
for (int i = 0; i < int(opt_cur->values.size()); i++)
|
|
{
|
|
int init_id = i <= opt_init_max_id ? i : 0;
|
|
if (opt_cur->values[i] != opt_init->values[init_id])
|
|
vec.emplace_back(opt_key + "#" + std::to_string(i));
|
|
}
|
|
}
|
|
|
|
// Use deep_diff to correct return of changed options, considering individual options for each extruder.
|
|
inline t_config_option_keys deep_diff(const ConfigBase &config_this, const ConfigBase &config_other)
|
|
{
|
|
t_config_option_keys diff;
|
|
for (const t_config_option_key &opt_key : config_this.keys()) {
|
|
const ConfigOption *this_opt = config_this.option(opt_key);
|
|
const ConfigOption *other_opt = config_other.option(opt_key);
|
|
if (this_opt != nullptr && other_opt != nullptr && *this_opt != *other_opt)
|
|
{
|
|
//BBS: add bed_exclude_area
|
|
if (opt_key == "printable_area" || opt_key == "bed_exclude_area" || opt_key == "compatible_prints" || opt_key == "compatible_printers" || opt_key == "thumbnails") {
|
|
// Scalar variable, or a vector variable, which is independent from number of extruders,
|
|
// thus the vector is presented to the user as a single input.
|
|
diff.emplace_back(opt_key);
|
|
} else if (opt_key == "default_filament_profile") {
|
|
// Ignore this field, it is not presented to the user, therefore showing a "modified" flag for this parameter does not help.
|
|
// Also the length of this field may differ, which may lead to a crash if the block below is used.
|
|
} else {
|
|
switch (other_opt->type()) {
|
|
case coInts: add_correct_opts_to_diff<ConfigOptionInts >(opt_key, diff, config_other, config_this); break;
|
|
case coBools: add_correct_opts_to_diff<ConfigOptionBools >(opt_key, diff, config_other, config_this); break;
|
|
case coFloats: add_correct_opts_to_diff<ConfigOptionFloats >(opt_key, diff, config_other, config_this); break;
|
|
case coStrings: add_correct_opts_to_diff<ConfigOptionStrings >(opt_key, diff, config_other, config_this); break;
|
|
case coPercents:add_correct_opts_to_diff<ConfigOptionPercents >(opt_key, diff, config_other, config_this); break;
|
|
case coPoints: add_correct_opts_to_diff<ConfigOptionPoints >(opt_key, diff, config_other, config_this); break;
|
|
// BBS
|
|
case coEnums: add_correct_opts_to_diff<ConfigOptionInts >(opt_key, diff, config_other, config_this); break;
|
|
default: diff.emplace_back(opt_key); break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return diff;
|
|
}
|
|
|
|
static constexpr const std::initializer_list<const char*> optional_keys { "compatible_prints", "compatible_printers" };
|
|
//BBS: skip these keys for dirty check
|
|
static std::set<std::string> skipped_in_dirty = {"printer_settings_id", "print_settings_id", "filament_settings_id"};
|
|
|
|
bool PresetCollection::is_dirty(const Preset *edited, const Preset *reference)
|
|
{
|
|
if (edited != nullptr && reference != nullptr) {
|
|
// Only compares options existing in both configs.
|
|
if (! reference->config.equals(edited->config, &skipped_in_dirty))
|
|
return true;
|
|
// The "compatible_printers" option key is handled differently from the others:
|
|
// It is not mandatory. If the key is missing, it means it is compatible with any printer.
|
|
// If the key exists and it is empty, it means it is compatible with no printer.
|
|
for (auto &opt_key : optional_keys)
|
|
if (reference->config.has(opt_key) != edited->config.has(opt_key))
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
std::vector<std::string> PresetCollection::dirty_options(const Preset *edited, const Preset *reference, const bool deep_compare /*= false*/)
|
|
{
|
|
std::vector<std::string> changed;
|
|
if (edited != nullptr && reference != nullptr) {
|
|
// Only compares options existing in both configs.
|
|
changed = deep_compare ?
|
|
deep_diff(edited->config, reference->config) :
|
|
reference->config.diff(edited->config);
|
|
// The "compatible_printers" option key is handled differently from the others:
|
|
// It is not mandatory. If the key is missing, it means it is compatible with any printer.
|
|
// If the key exists and it is empty, it means it is compatible with no printer.
|
|
for (auto &opt_key : optional_keys)
|
|
if (reference->config.has(opt_key) != edited->config.has(opt_key))
|
|
changed.emplace_back(opt_key);
|
|
}
|
|
return changed;
|
|
}
|
|
|
|
//BBS: add function for dirty_options_without_option_list
|
|
std::vector<std::string> PresetCollection::dirty_options_without_option_list(const Preset *edited, const Preset *reference, const std::set<std::string>& option_ignore_list, const bool deep_compare)
|
|
{
|
|
std::vector<std::string> changed;
|
|
if (edited != nullptr && reference != nullptr) {
|
|
// Only compares options existing in both configs.
|
|
changed = deep_compare ?
|
|
deep_diff(edited->config, reference->config) :
|
|
reference->config.diff(edited->config);
|
|
// The "compatible_printers" option key is handled differently from the others:
|
|
// It is not mandatory. If the key is missing, it means it is compatible with any printer.
|
|
// If the key exists and it is empty, it means it is compatible with no printer.
|
|
for (auto &opt_key : optional_keys) {
|
|
if (reference->config.has(opt_key) != edited->config.has(opt_key))
|
|
changed.emplace_back(opt_key);
|
|
}
|
|
auto iter = changed.begin();
|
|
while (iter != changed.end()) {
|
|
if (option_ignore_list.find(*iter) != option_ignore_list.end()) {
|
|
iter = changed.erase(iter);
|
|
}
|
|
else {
|
|
++iter;
|
|
}
|
|
}
|
|
}
|
|
return changed;
|
|
}
|
|
|
|
// Select a new preset. This resets all the edits done to the currently selected preset.
|
|
// If the preset with index idx does not exist, a first visible preset is selected.
|
|
Preset& PresetCollection::select_preset(size_t idx)
|
|
{
|
|
//BBS: add config related logs
|
|
BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << boost::format(": %1% try to select preset %2%")%Preset::get_type_string(m_type) %idx;
|
|
for (Preset &preset : m_presets)
|
|
preset.is_dirty = false;
|
|
if (idx >= m_presets.size())
|
|
idx = first_visible_idx();
|
|
m_idx_selected = idx;
|
|
m_edited_preset = m_presets[idx];
|
|
update_saved_preset_from_current_preset();
|
|
bool default_visible = ! m_default_suppressed || m_idx_selected < m_num_default_presets;
|
|
for (size_t i = 0; i < m_num_default_presets; ++i)
|
|
m_presets[i].is_visible = default_visible;
|
|
//BBS: add config related logs
|
|
BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << boost::format(": %1% select success, m_idx_selected %2%, name %3%, is_system %4%, is_default %5%")%Preset::get_type_string(m_type) % m_idx_selected % m_edited_preset.name % m_edited_preset.is_system % m_edited_preset.is_default;
|
|
return m_presets[idx];
|
|
}
|
|
|
|
bool PresetCollection::select_preset_by_name(const std::string &name_w_suffix, bool force)
|
|
{
|
|
//BBS: add config related logs
|
|
BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << boost::format(": %1%, try to select by name %2%, force %3%")%Preset::get_type_string(m_type) %name_w_suffix %force;
|
|
std::string name = Preset::remove_suffix_modified(name_w_suffix);
|
|
// 1) Try to find the preset by its name.
|
|
auto it = this->find_preset_internal(name);
|
|
size_t idx = 0;
|
|
if (it != m_presets.end() && it->name == name && it->is_visible)
|
|
// Preset found by its name and it is visible.
|
|
idx = it - m_presets.begin();
|
|
else {
|
|
// Find the first visible preset.
|
|
for (size_t i = m_default_suppressed ? m_num_default_presets : 0; i < m_presets.size(); ++ i)
|
|
if (m_presets[i].is_visible) {
|
|
idx = i;
|
|
break;
|
|
}
|
|
// If the first visible preset was not found, return the 0th element, which is the default preset.
|
|
}
|
|
|
|
// 2) Select the new preset.
|
|
if (m_idx_selected != idx || force) {
|
|
this->select_preset(idx);
|
|
//BBS: add config related logs
|
|
BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << boost::format(": %1%, select %2%, success")%Preset::get_type_string(m_type) %name_w_suffix;
|
|
return true;
|
|
}
|
|
|
|
//BBS: add config related logs
|
|
BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << boost::format(": %1%, select %2%, failed")%Preset::get_type_string(m_type) %name_w_suffix;
|
|
return false;
|
|
}
|
|
|
|
bool PresetCollection::select_preset_by_name_strict(const std::string &name)
|
|
{
|
|
//BBS: add config related logs
|
|
BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << boost::format(": %1%, try to select by name %2%")%Preset::get_type_string(m_type) %name;
|
|
// 1) Try to find the preset by its name.
|
|
auto it = this->find_preset_internal(name);
|
|
|
|
size_t idx = (size_t)-1;
|
|
if (it != m_presets.end() && it->name == name && it->is_visible)
|
|
// Preset found by its name.
|
|
idx = it - m_presets.begin();
|
|
// 2) Select the new preset.
|
|
if (idx != (size_t)-1) {
|
|
this->select_preset(idx);
|
|
//BBS: add config related logs
|
|
BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << boost::format(": %1%, select %2%, success")%Preset::get_type_string(m_type) %name;
|
|
return true;
|
|
}
|
|
m_idx_selected = idx;
|
|
//BBS: add config related logs
|
|
BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << boost::format(": %1%, select %2%, failed")%Preset::get_type_string(m_type) %name;
|
|
return false;
|
|
}
|
|
|
|
// Merge one vendor's presets with the other vendor's presets, report duplicates.
|
|
std::vector<std::string> PresetCollection::merge_presets(PresetCollection &&other, const VendorMap &new_vendors)
|
|
{
|
|
std::vector<std::string> duplicates;
|
|
for (Preset &preset : other.m_presets) {
|
|
if (preset.is_default || preset.is_external)
|
|
continue;
|
|
Preset key(m_type, preset.name);
|
|
auto it = std::lower_bound(m_presets.begin() + m_num_default_presets, m_presets.end(), key);
|
|
if (it == m_presets.end() || it->name != preset.name) {
|
|
if (preset.vendor != nullptr) {
|
|
// Re-assign a pointer to the vendor structure in the new PresetBundle.
|
|
auto it = new_vendors.find(preset.vendor->id);
|
|
assert(it != new_vendors.end());
|
|
preset.vendor = &it->second;
|
|
}
|
|
m_presets.emplace(it, std::move(preset));
|
|
} else
|
|
duplicates.emplace_back(std::move(preset.name));
|
|
}
|
|
return duplicates;
|
|
}
|
|
|
|
void PresetCollection::update_vendor_ptrs_after_copy(const VendorMap &new_vendors)
|
|
{
|
|
for (Preset &preset : m_presets)
|
|
if (preset.vendor != nullptr) {
|
|
assert(! preset.is_default && ! preset.is_external);
|
|
// Re-assign a pointer to the vendor structure in the new PresetBundle.
|
|
auto it = new_vendors.find(preset.vendor->id);
|
|
assert(it != new_vendors.end());
|
|
preset.vendor = &it->second;
|
|
}
|
|
}
|
|
|
|
void PresetCollection::update_map_alias_to_profile_name()
|
|
{
|
|
m_map_alias_to_profile_name.clear();
|
|
for (const Preset &preset : m_presets)
|
|
m_map_alias_to_profile_name.emplace_back(preset.alias, preset.name);
|
|
std::sort(m_map_alias_to_profile_name.begin(), m_map_alias_to_profile_name.end(), [](auto &l, auto &r) { return l.first < r.first; });
|
|
}
|
|
|
|
void PresetCollection::update_map_system_profile_renamed()
|
|
{
|
|
m_map_system_profile_renamed.clear();
|
|
for (Preset &preset : m_presets)
|
|
for (const std::string &renamed_from : preset.renamed_from) {
|
|
const auto [it, success] = m_map_system_profile_renamed.insert(std::pair<std::string, std::string>(renamed_from, preset.name));
|
|
if (! success)
|
|
BOOST_LOG_TRIVIAL(error) << boost::format("Preset name \"%1%\" was marked as renamed from \"%2%\", though preset name \"%3%\" was marked as renamed from \"%2%\" as well.") % preset.name % renamed_from % it->second;
|
|
}
|
|
}
|
|
|
|
std::string PresetCollection::name() const
|
|
{
|
|
switch (this->type()) {
|
|
case Preset::TYPE_PRINT: return L(PRESET_PRINT_NAME);
|
|
case Preset::TYPE_FILAMENT: return L(PRESET_FILAMENT_NAME);
|
|
//case Preset::TYPE_SLA_PRINT: return L("SLA print");
|
|
//case Preset::TYPE_SLA_MATERIAL: return L("SLA material");
|
|
case Preset::TYPE_PRINTER: return L(PRESET_PRINTER_NAME);
|
|
default: return "invalid";
|
|
}
|
|
}
|
|
|
|
//BBS: change directoties by design
|
|
std::string PresetCollection::section_name() const
|
|
{
|
|
switch (this->type()) {
|
|
case Preset::TYPE_PRINT: return PRESET_PRINT_NAME;
|
|
case Preset::TYPE_FILAMENT: return PRESET_FILAMENT_NAME;
|
|
//case Preset::TYPE_SLA_PRINT: return PRESET_SLA_PRINT_NAME;
|
|
//case Preset::TYPE_SLA_MATERIAL: return PRESET_SLA_MATERIALS_NAME;
|
|
case Preset::TYPE_PRINTER: return PRESET_PRINTER_NAME;
|
|
default: return "invalid";
|
|
}
|
|
}
|
|
|
|
// Used for validating the "inherits" flag when importing user's config bundles.
|
|
// Returns names of all system presets including the former names of these presets.
|
|
std::vector<std::string> PresetCollection::system_preset_names() const
|
|
{
|
|
size_t num = 0;
|
|
for (const Preset &preset : m_presets)
|
|
if (preset.is_system)
|
|
++ num;
|
|
std::vector<std::string> out;
|
|
out.reserve(num);
|
|
for (const Preset &preset : m_presets)
|
|
if (preset.is_system) {
|
|
out.emplace_back(preset.name);
|
|
out.insert(out.end(), preset.renamed_from.begin(), preset.renamed_from.end());
|
|
}
|
|
std::sort(out.begin(), out.end());
|
|
return out;
|
|
}
|
|
|
|
// Generate a file path from a profile name. Add the ".ini" suffix if it is missing.
|
|
std::string PresetCollection::path_from_name(const std::string &new_name, bool detach) const
|
|
{
|
|
//BBS: change to json format
|
|
//std::string file_name = boost::iends_with(new_name, ".ini") ? new_name : (new_name + ".ini");
|
|
std::string file_name = boost::iends_with(new_name, ".json") ? new_name : (new_name + ".json");
|
|
if (detach)
|
|
return (boost::filesystem::path(m_dir_path) / "base" / file_name).make_preferred().string();
|
|
else
|
|
return (boost::filesystem::path(m_dir_path) / file_name).make_preferred().string();
|
|
}
|
|
|
|
std::string PresetCollection::path_for_preset(const Preset &preset) const
|
|
{
|
|
return path_from_name(preset.name, get_preset_base(preset) == &preset);
|
|
}
|
|
|
|
const Preset& PrinterPresetCollection::default_preset_for(const DynamicPrintConfig &config) const
|
|
{
|
|
const ConfigOptionEnumGeneric *opt_printer_technology = config.opt<ConfigOptionEnumGeneric>("printer_technology");
|
|
return this->default_preset((opt_printer_technology == nullptr || opt_printer_technology->value == ptFFF) ? 0 : 1);
|
|
}
|
|
|
|
const Preset* PrinterPresetCollection::find_system_preset_by_model_and_variant(const std::string &model_id, const std::string& variant) const
|
|
{
|
|
if (model_id.empty()) { return nullptr; }
|
|
|
|
const auto it = std::find_if(cbegin(), cend(), [&](const Preset &preset) {
|
|
if (!preset.is_system || preset.config.opt_string("printer_model") != model_id)
|
|
return false;
|
|
if (variant.empty())
|
|
return true;
|
|
return preset.config.opt_string("printer_variant") == variant;
|
|
});
|
|
|
|
return it != cend() ? &*it : nullptr;
|
|
}
|
|
|
|
const Preset *PrinterPresetCollection::find_custom_preset_by_model_and_variant(const std::string &model_id, const std::string &variant) const
|
|
{
|
|
if (model_id.empty()) { return nullptr; }
|
|
|
|
const auto it = std::find_if(cbegin(), cend(), [&](const Preset &preset) {
|
|
if (preset.config.opt_string("printer_model") != model_id)
|
|
return false;
|
|
if (variant.empty())
|
|
return true;
|
|
return preset.config.opt_string("printer_variant") == variant;
|
|
});
|
|
|
|
return it != cend() ? &*it : nullptr;
|
|
}
|
|
|
|
bool PrinterPresetCollection::only_default_printers() const
|
|
{
|
|
for (const auto& printer : get_presets()) {
|
|
if (!boost::starts_with(printer.name,"Default") && printer.is_visible)
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
// -------------------------
|
|
// *** PhysicalPrinter ***
|
|
// -------------------------
|
|
|
|
std::string PhysicalPrinter::separator()
|
|
{
|
|
return " * ";
|
|
}
|
|
|
|
static std::vector<std::string> s_PhysicalPrinter_opts {
|
|
"preset_name", // temporary option to compatibility with older Slicer
|
|
"preset_names",
|
|
"printer_technology",
|
|
"host_type",
|
|
"print_host",
|
|
"print_host_webui",
|
|
"printhost_apikey",
|
|
"printhost_cafile",
|
|
"printhost_port",
|
|
"printhost_authorization_type",
|
|
// HTTP digest authentization (RFC 2617)
|
|
"printhost_user",
|
|
"printhost_password",
|
|
"printhost_ssl_ignore_revoke"
|
|
};
|
|
|
|
const std::vector<std::string>& PhysicalPrinter::printer_options()
|
|
{
|
|
return s_PhysicalPrinter_opts;
|
|
}
|
|
|
|
std::vector<std::string> PhysicalPrinter::presets_with_print_host_information(const PrinterPresetCollection& printer_presets)
|
|
{
|
|
std::vector<std::string> presets;
|
|
for (const Preset& preset : printer_presets)
|
|
if (has_print_host_information(preset.config))
|
|
presets.emplace_back(preset.name);
|
|
|
|
return presets;
|
|
}
|
|
|
|
bool PhysicalPrinter::has_print_host_information(const DynamicPrintConfig& config)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
const std::set<std::string>& PhysicalPrinter::get_preset_names() const
|
|
{
|
|
return preset_names;
|
|
}
|
|
|
|
// temporary workaround for compatibility with older Slicer
|
|
static void update_preset_name_option(const std::set<std::string>& preset_names, DynamicPrintConfig& config)
|
|
{
|
|
std::string name;
|
|
for (auto el : preset_names)
|
|
name += el + ";";
|
|
name.pop_back();
|
|
config.set_key_value("preset_name", new ConfigOptionString(name));
|
|
}
|
|
|
|
void PhysicalPrinter::update_preset_names_in_config()
|
|
{
|
|
if (!preset_names.empty()) {
|
|
std::vector<std::string>& values = config.option<ConfigOptionStrings>("preset_names")->values;
|
|
values.clear();
|
|
for (auto preset : preset_names)
|
|
values.push_back(preset);
|
|
|
|
// temporary workaround for compatibility with older Slicer
|
|
update_preset_name_option(preset_names, config);
|
|
}
|
|
}
|
|
|
|
void PhysicalPrinter::save(const std::string& file_name_from, const std::string& file_name_to)
|
|
{
|
|
// rename the file
|
|
boost::nowide::rename(file_name_from.data(), file_name_to.data());
|
|
this->file = file_name_to;
|
|
// save configuration
|
|
//BBS: change to save
|
|
//this->config.save(this->file);
|
|
this->config.save_to_json(this->file, std::string("Physical_Printer"), std::string("User"), std::string(SLIC3R_VERSION));
|
|
}
|
|
|
|
void PhysicalPrinter::update_from_preset(const Preset& preset)
|
|
{
|
|
config.apply_only(preset.config, printer_options(), true);
|
|
// add preset names to the options list
|
|
preset_names.emplace(preset.name);
|
|
update_preset_names_in_config();
|
|
}
|
|
|
|
void PhysicalPrinter::update_from_config(const DynamicPrintConfig& new_config)
|
|
{
|
|
config.apply_only(new_config, printer_options(), false);
|
|
|
|
const std::vector<std::string>& values = config.option<ConfigOptionStrings>("preset_names")->values;
|
|
|
|
if (values.empty())
|
|
preset_names.clear();
|
|
else {
|
|
for (const std::string& val : values)
|
|
preset_names.emplace(val);
|
|
// temporary workaround for compatibility with older Slicer
|
|
update_preset_name_option(preset_names, config);
|
|
}
|
|
}
|
|
|
|
void PhysicalPrinter::reset_presets()
|
|
{
|
|
return preset_names.clear();
|
|
}
|
|
|
|
bool PhysicalPrinter::add_preset(const std::string& preset_name)
|
|
{
|
|
return preset_names.emplace(preset_name).second;
|
|
}
|
|
|
|
bool PhysicalPrinter::delete_preset(const std::string& preset_name)
|
|
{
|
|
return preset_names.erase(preset_name) > 0;
|
|
}
|
|
|
|
PhysicalPrinter::PhysicalPrinter(const std::string& name, const DynamicPrintConfig& default_config) :
|
|
name(name), config(default_config)
|
|
{
|
|
update_from_config(config);
|
|
}
|
|
|
|
PhysicalPrinter::PhysicalPrinter(const std::string& name, const DynamicPrintConfig &default_config, const Preset& preset) :
|
|
name(name), config(default_config)
|
|
{
|
|
update_from_preset(preset);
|
|
}
|
|
|
|
void PhysicalPrinter::set_name(const std::string& name)
|
|
{
|
|
this->name = name;
|
|
}
|
|
|
|
std::string PhysicalPrinter::get_full_name(std::string preset_name) const
|
|
{
|
|
return name + separator() + preset_name;
|
|
}
|
|
|
|
std::string PhysicalPrinter::get_short_name(std::string full_name)
|
|
{
|
|
int pos = full_name.find(separator());
|
|
if (pos > 0)
|
|
boost::erase_tail(full_name, full_name.length() - pos);
|
|
return full_name;
|
|
}
|
|
|
|
std::string PhysicalPrinter::get_preset_name(std::string name)
|
|
{
|
|
int pos = name.find(separator());
|
|
boost::erase_head(name, pos + 3);
|
|
return Preset::remove_suffix_modified(name);
|
|
}
|
|
|
|
|
|
// -----------------------------------
|
|
// *** PhysicalPrinterCollection ***
|
|
// -----------------------------------
|
|
|
|
PhysicalPrinterCollection::PhysicalPrinterCollection( const std::vector<std::string>& keys)
|
|
{
|
|
// Default config for a physical printer containing all key/value pairs of PhysicalPrinter::printer_options().
|
|
for (const std::string &key : keys) {
|
|
const ConfigOptionDef *opt = print_config_def.get(key);
|
|
assert(opt);
|
|
assert(opt->default_value);
|
|
m_default_config.set_key_value(key, opt->default_value->clone());
|
|
}
|
|
}
|
|
|
|
// Load all printers found in dir_path.
|
|
// Throws an exception on error.
|
|
void PhysicalPrinterCollection::load_printers(
|
|
const std::string& dir_path, const std::string& subdir,
|
|
PresetsConfigSubstitutions& substitutions, ForwardCompatibilitySubstitutionRule substitution_rule)
|
|
{
|
|
// Don't use boost::filesystem::canonical() on Windows, it is broken in regard to reparse points,
|
|
// see https://github.com/prusa3d/PrusaSlicer/issues/732
|
|
boost::filesystem::path dir = boost::filesystem::absolute(boost::filesystem::path(dir_path) / subdir).make_preferred();
|
|
m_dir_path = dir.string();
|
|
if(!boost::filesystem::exists(dir))
|
|
return;
|
|
std::string errors_cummulative;
|
|
// Store the loaded printers into a new vector, otherwise the binary search for already existing presets would be broken.
|
|
std::deque<PhysicalPrinter> printers_loaded;
|
|
//BBS: change to json format
|
|
for (auto& dir_entry : boost::filesystem::directory_iterator(dir))
|
|
{
|
|
std::string file_name = dir_entry.path().filename().string();
|
|
//if (Slic3r::is_ini_file(dir_entry)) {
|
|
if (Slic3r::is_json_file(file_name)) {
|
|
// Remove the .json suffix.
|
|
std::string name = file_name.erase(file_name.size() - 5);
|
|
if (this->find_printer(name, false)) {
|
|
// This happens when there's is a preset (most likely legacy one) with the same name as a system preset
|
|
// that's already been loaded from a bundle.
|
|
BOOST_LOG_TRIVIAL(warning) << "Printer already present, not loading: " << name;
|
|
continue;
|
|
}
|
|
try {
|
|
PhysicalPrinter printer(name, this->default_config());
|
|
printer.file = dir_entry.path().string();
|
|
// Load the preset file, apply preset values on top of defaults.
|
|
try {
|
|
DynamicPrintConfig config;
|
|
//ConfigSubstitutions config_substitutions = config.load_from_ini(printer.file, substitution_rule);
|
|
std::map<std::string, std::string> key_values;
|
|
std::string reason;
|
|
ConfigSubstitutions config_substitutions = config.load_from_json(printer.file, substitution_rule, key_values, reason);
|
|
if (! config_substitutions.empty())
|
|
substitutions.push_back({ name, Preset::TYPE_PHYSICAL_PRINTER, PresetConfigSubstitutions::Source::UserFile, printer.file, std::move(config_substitutions) });
|
|
printer.update_from_config(config);
|
|
printer.loaded = true;
|
|
}
|
|
catch (const std::ifstream::failure& err) {
|
|
throw Slic3r::RuntimeError(std::string("The selected preset cannot be loaded: ") + printer.file + "\n\tReason: " + err.what());
|
|
}
|
|
catch (const std::runtime_error& err) {
|
|
throw Slic3r::RuntimeError(std::string("Failed loading the preset file: ") + printer.file + "\n\tReason: " + err.what());
|
|
}
|
|
printers_loaded.emplace_back(printer);
|
|
}
|
|
catch (const std::runtime_error& err) {
|
|
errors_cummulative += err.what();
|
|
errors_cummulative += "\n";
|
|
}
|
|
}
|
|
}
|
|
m_printers.insert(m_printers.end(), std::make_move_iterator(printers_loaded.begin()), std::make_move_iterator(printers_loaded.end()));
|
|
std::sort(m_printers.begin(), m_printers.end());
|
|
if (!errors_cummulative.empty())
|
|
throw Slic3r::RuntimeError(errors_cummulative);
|
|
}
|
|
|
|
void PhysicalPrinterCollection::load_printer(const std::string& path, const std::string& name, DynamicPrintConfig&& config, bool select, bool save/* = false*/)
|
|
{
|
|
auto it = this->find_printer_internal(name);
|
|
if (it == m_printers.end() || it->name != name) {
|
|
// The preset was not found. Create a new preset.
|
|
it = m_printers.emplace(it, PhysicalPrinter(name, config));
|
|
}
|
|
|
|
it->file = path;
|
|
it->config = std::move(config);
|
|
it->loaded = true;
|
|
if (select)
|
|
this->select_printer(*it);
|
|
|
|
if (save)
|
|
it->save(nullptr);
|
|
}
|
|
|
|
// if there is saved user presets, contains information about "Print Host upload",
|
|
// Create default printers with this presets
|
|
// Note! "Print Host upload" options will be cleared after physical printer creations
|
|
void PhysicalPrinterCollection::load_printers_from_presets(PrinterPresetCollection& printer_presets)
|
|
{
|
|
//BBS
|
|
#if 0
|
|
int cnt=0;
|
|
for (Preset& preset: printer_presets) {
|
|
DynamicPrintConfig& config = preset.config;
|
|
for(const char* option : legacy_print_host_options) {
|
|
if (!config.opt_string(option).empty()) {
|
|
// check if printer with those "Print Host upload" options already exist
|
|
PhysicalPrinter* existed_printer = find_printer_with_same_config(config);
|
|
if (existed_printer)
|
|
// just add preset for this printer
|
|
existed_printer->add_preset(preset.name);
|
|
else {
|
|
std::string new_printer_name = (boost::format("Printer %1%") % ++cnt ).str();
|
|
while (find_printer(new_printer_name))
|
|
new_printer_name = (boost::format("Printer %1%") % ++cnt).str();
|
|
|
|
// create new printer from this preset
|
|
PhysicalPrinter printer(new_printer_name, this->default_config(), preset);
|
|
printer.loaded = true;
|
|
save_printer(printer);
|
|
}
|
|
|
|
// erase "Print Host upload" information from the preset
|
|
for (const char *opt : legacy_print_host_options)
|
|
config.opt_string(opt).clear();
|
|
// save changes for preset
|
|
preset.save(nullptr);
|
|
|
|
// update those changes for edited preset if it's equal to the preset
|
|
Preset& edited = printer_presets.get_edited_preset();
|
|
if (preset.name == edited.name) {
|
|
for (const char *opt : legacy_print_host_options)
|
|
edited.config.opt_string(opt).clear();
|
|
}
|
|
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
#endif
|
|
}
|
|
|
|
PhysicalPrinter* PhysicalPrinterCollection::find_printer( const std::string& name, bool case_sensitive_search)
|
|
{
|
|
auto it = this->find_printer_internal(name, case_sensitive_search);
|
|
|
|
// Ensure that a temporary copy is returned if the preset found is currently selected.
|
|
auto is_equal_name = [name, case_sensitive_search](const std::string& in_name) {
|
|
if (case_sensitive_search)
|
|
return in_name == name;
|
|
return boost::to_lower_copy<std::string>(in_name) == boost::to_lower_copy<std::string>(name);
|
|
};
|
|
|
|
if (it == m_printers.end() || !is_equal_name(it->name))
|
|
return nullptr;
|
|
return &this->printer(it - m_printers.begin());
|
|
}
|
|
|
|
std::deque<PhysicalPrinter>::iterator PhysicalPrinterCollection::find_printer_internal(const std::string& name, bool case_sensitive_search/* = true*/)
|
|
{
|
|
if (case_sensitive_search)
|
|
return Slic3r::lower_bound_by_predicate(m_printers.begin(), m_printers.end(), [&name](const auto& l) { return l.name < name; });
|
|
|
|
std::string low_name = boost::to_lower_copy<std::string>(name);
|
|
|
|
size_t i = 0;
|
|
for (const PhysicalPrinter& printer : m_printers) {
|
|
if (boost::to_lower_copy<std::string>(printer.name) == low_name)
|
|
break;
|
|
i++;
|
|
}
|
|
if (i == m_printers.size())
|
|
return m_printers.end();
|
|
|
|
return m_printers.begin() + i;
|
|
}
|
|
|
|
// Generate a file path from a profile name. Add the ".ini" suffix if it is missing.
|
|
std::string PhysicalPrinterCollection::path_from_name(const std::string& new_name) const
|
|
{
|
|
//BBS: change to json format
|
|
//std::string file_name = boost::iends_with(new_name, ".ini") ? new_name : (new_name + ".ini");
|
|
std::string file_name = boost::iends_with(new_name, ".json") ? new_name : (new_name + ".json");
|
|
return (boost::filesystem::path(m_dir_path) / file_name).make_preferred().string();
|
|
}
|
|
|
|
void PhysicalPrinterCollection::save_printer(PhysicalPrinter& edited_printer, const std::string& renamed_from/* = ""*/)
|
|
{
|
|
// controll and update preset_names in edited_printer config
|
|
edited_printer.update_preset_names_in_config();
|
|
|
|
std::string name = renamed_from.empty() ? edited_printer.name : renamed_from;
|
|
// 1) Find the printer with a new_name or create a new one,
|
|
// initialize it with the edited config.
|
|
auto it = this->find_printer_internal(name);
|
|
if (it != m_printers.end() && it->name == name) {
|
|
// Printer with the same name found.
|
|
// Overwriting an existing preset.
|
|
it->config = std::move(edited_printer.config);
|
|
it->name = edited_printer.name;
|
|
it->preset_names = edited_printer.preset_names;
|
|
// sort printers and get new it
|
|
std::sort(m_printers.begin(), m_printers.end());
|
|
it = this->find_printer_internal(edited_printer.name);
|
|
}
|
|
else {
|
|
// Creating a new printer.
|
|
it = m_printers.emplace(it, edited_printer);
|
|
}
|
|
assert(it != m_printers.end());
|
|
|
|
// 2) Save printer
|
|
PhysicalPrinter& printer = *it;
|
|
if (printer.file.empty())
|
|
printer.file = this->path_from_name(printer.name);
|
|
|
|
if (printer.file == this->path_from_name(printer.name))
|
|
printer.save(nullptr);
|
|
else
|
|
// if printer was renamed, we should rename a file and than save the config
|
|
printer.save(printer.file, this->path_from_name(printer.name));
|
|
|
|
// update idx_selected
|
|
m_idx_selected = it - m_printers.begin();
|
|
}
|
|
|
|
bool PhysicalPrinterCollection::delete_printer(const std::string& name)
|
|
{
|
|
auto it = this->find_printer_internal(name);
|
|
if (it == m_printers.end())
|
|
return false;
|
|
|
|
const PhysicalPrinter& printer = *it;
|
|
// Erase the preset file.
|
|
boost::nowide::remove(printer.file.c_str());
|
|
m_printers.erase(it);
|
|
return true;
|
|
}
|
|
|
|
bool PhysicalPrinterCollection::delete_selected_printer()
|
|
{
|
|
if (!has_selection())
|
|
return false;
|
|
const PhysicalPrinter& printer = this->get_selected_printer();
|
|
|
|
// Erase the preset file.
|
|
boost::nowide::remove(printer.file.c_str());
|
|
// Remove the preset from the list.
|
|
m_printers.erase(m_printers.begin() + m_idx_selected);
|
|
// unselect all printers
|
|
unselect_printer();
|
|
|
|
return true;
|
|
}
|
|
|
|
bool PhysicalPrinterCollection::delete_preset_from_printers( const std::string& preset_name)
|
|
{
|
|
std::vector<std::string> printers_for_delete;
|
|
for (PhysicalPrinter& printer : m_printers) {
|
|
if (printer.preset_names.size() == 1 && *printer.preset_names.begin() == preset_name)
|
|
printers_for_delete.emplace_back(printer.name);
|
|
else if (printer.delete_preset(preset_name))
|
|
save_printer(printer);
|
|
}
|
|
|
|
if (!printers_for_delete.empty())
|
|
for (const std::string& printer_name : printers_for_delete)
|
|
delete_printer(printer_name);
|
|
|
|
unselect_printer();
|
|
return true;
|
|
}
|
|
|
|
// Get list of printers which have more than one preset and "preset_names" preset is one of them
|
|
std::vector<std::string> PhysicalPrinterCollection::get_printers_with_preset(const std::string& preset_name)
|
|
{
|
|
std::vector<std::string> printers;
|
|
|
|
for (auto printer : m_printers) {
|
|
if (printer.preset_names.size() == 1)
|
|
continue;
|
|
if (printer.preset_names.find(preset_name) != printer.preset_names.end())
|
|
printers.emplace_back(printer.name);
|
|
}
|
|
|
|
return printers;
|
|
}
|
|
|
|
// Get list of printers which has only "preset_names" preset
|
|
std::vector<std::string> PhysicalPrinterCollection::get_printers_with_only_preset(const std::string& preset_name)
|
|
{
|
|
std::vector<std::string> printers;
|
|
|
|
for (auto printer : m_printers)
|
|
if (printer.preset_names.size() == 1 && *printer.preset_names.begin() == preset_name)
|
|
printers.emplace_back(printer.name);
|
|
|
|
return printers;
|
|
}
|
|
|
|
std::string PhysicalPrinterCollection::get_selected_full_printer_name() const
|
|
{
|
|
return (m_idx_selected == size_t(-1)) ? std::string() : this->get_selected_printer().get_full_name(m_selected_preset);
|
|
}
|
|
|
|
void PhysicalPrinterCollection::select_printer(const std::string& full_name)
|
|
{
|
|
std::string printer_name = PhysicalPrinter::get_short_name(full_name);
|
|
auto it = this->find_printer_internal(printer_name);
|
|
if (it == m_printers.end()) {
|
|
unselect_printer();
|
|
return;
|
|
}
|
|
|
|
// update idx_selected
|
|
m_idx_selected = it - m_printers.begin();
|
|
|
|
// update name of the currently selected preset
|
|
if (printer_name == full_name)
|
|
// use first preset in the list
|
|
m_selected_preset = *it->preset_names.begin();
|
|
else
|
|
m_selected_preset = it->get_preset_name(full_name);
|
|
}
|
|
|
|
void PhysicalPrinterCollection::select_printer(const std::string& printer_name, const std::string& preset_name)
|
|
{
|
|
if (preset_name.empty())
|
|
return select_printer(printer_name);
|
|
return select_printer(printer_name + PhysicalPrinter::separator() + preset_name);
|
|
}
|
|
|
|
void PhysicalPrinterCollection::select_printer(const PhysicalPrinter& printer)
|
|
{
|
|
return select_printer(printer.name);
|
|
}
|
|
|
|
bool PhysicalPrinterCollection::has_selection() const
|
|
{
|
|
return m_idx_selected != size_t(-1);
|
|
}
|
|
|
|
void PhysicalPrinterCollection::unselect_printer()
|
|
{
|
|
m_idx_selected = size_t(-1);
|
|
m_selected_preset.clear();
|
|
}
|
|
|
|
bool PhysicalPrinterCollection::is_selected(PhysicalPrinterCollection::ConstIterator it, const std::string& preset_name) const
|
|
{
|
|
return m_idx_selected == size_t(it - m_printers.begin()) &&
|
|
m_selected_preset == preset_name;
|
|
}
|
|
|
|
|
|
namespace PresetUtils {
|
|
const VendorProfile::PrinterModel* system_printer_model(const Preset &preset)
|
|
{
|
|
const VendorProfile::PrinterModel *out = nullptr;
|
|
if (preset.vendor != nullptr) {
|
|
auto *printer_model = preset.config.opt<ConfigOptionString>("printer_model");
|
|
if (printer_model != nullptr && ! printer_model->value.empty()) {
|
|
auto it = std::find_if(preset.vendor->models.begin(), preset.vendor->models.end(), [printer_model](const VendorProfile::PrinterModel &pm) { return pm.id == printer_model->value; });
|
|
if (it != preset.vendor->models.end())
|
|
out = &(*it);
|
|
}
|
|
}
|
|
return out;
|
|
}
|
|
|
|
std::string system_printer_bed_model(const Preset& preset)
|
|
{
|
|
std::string out;
|
|
const VendorProfile::PrinterModel* pm = PresetUtils::system_printer_model(preset);
|
|
if (pm != nullptr && !pm->bed_model.empty()) {
|
|
out = Slic3r::data_dir() + "/vendor/" + preset.vendor->id + "/" + pm->bed_model;
|
|
if (!boost::filesystem::exists(boost::filesystem::path(out)))
|
|
out = Slic3r::resources_dir() + "/profiles/" + preset.vendor->id + "/" + pm->bed_model;
|
|
}
|
|
return out;
|
|
}
|
|
|
|
std::string system_printer_bed_texture(const Preset& preset)
|
|
{
|
|
std::string out;
|
|
const VendorProfile::PrinterModel* pm = PresetUtils::system_printer_model(preset);
|
|
if (pm != nullptr && !pm->bed_texture.empty()) {
|
|
out = Slic3r::data_dir() + "/vendor/" + preset.vendor->id + "/" + pm->bed_texture;
|
|
if (!boost::filesystem::exists(boost::filesystem::path(out)))
|
|
out = Slic3r::resources_dir() + "/profiles/" + preset.vendor->id + "/" + pm->bed_texture;
|
|
}
|
|
return out;
|
|
}
|
|
|
|
std::string system_printer_hotend_model(const Preset& preset)
|
|
{
|
|
std::string out;
|
|
const VendorProfile::PrinterModel* pm = PresetUtils::system_printer_model(preset);
|
|
if (pm != nullptr && !pm->hotend_model.empty()) {
|
|
out = Slic3r::data_dir() + "/vendor/" + preset.vendor->id + "/" + pm->hotend_model;
|
|
if (!boost::filesystem::exists(boost::filesystem::path(out)))
|
|
out = Slic3r::resources_dir() + "/profiles/" + preset.vendor->id + "/" + pm->hotend_model;
|
|
}
|
|
|
|
if (out.empty() ||!boost::filesystem::exists(boost::filesystem::path(out)))
|
|
out = Slic3r::resources_dir() + "/profiles/hotend.stl";
|
|
return out;
|
|
}
|
|
} // namespace PresetUtils
|
|
|
|
} // namespace Slic3r
|