Files
OrcaSlicer-KX/src/slic3r/GUI/SelectMachine.cpp
SoftFever bba367cde8 Feature/merge 1.8.2 (#3193)
* 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>
2023-12-19 23:46:19 +08:00

4478 lines
165 KiB
C++

#include "SelectMachine.hpp"
#include "I18N.hpp"
#include "libslic3r/Utils.hpp"
#include "libslic3r/Thread.hpp"
#include "libslic3r/Color.hpp"
#include "GUI.hpp"
#include "GUI_App.hpp"
#include "GUI_Preview.hpp"
#include "MainFrame.hpp"
#include "format.hpp"
#include "Widgets/ProgressDialog.hpp"
#include "Widgets/RoundedRectangle.hpp"
#include "Widgets/StaticBox.hpp"
#include "ConnectPrinter.hpp"
#include "Jobs/BoostThreadWorker.hpp"
#include "Jobs/PlaterWorker.hpp"
#include <wx/progdlg.h>
#include <wx/clipbrd.h>
#include <wx/dcgraph.h>
#include <miniz.h>
#include <algorithm>
#include "Plater.hpp"
#include "BitmapCache.hpp"
#include "BindDialog.hpp"
namespace Slic3r { namespace GUI {
wxDEFINE_EVENT(EVT_UPDATE_WINDOWS_POSITION, wxCommandEvent);
wxDEFINE_EVENT(EVT_FINISHED_UPDATE_MACHINE_LIST, wxCommandEvent);
wxDEFINE_EVENT(EVT_UPDATE_USER_MACHINE_LIST, wxCommandEvent);
wxDEFINE_EVENT(EVT_PRINT_JOB_CANCEL, wxCommandEvent);
wxDEFINE_EVENT(EVT_BIND_MACHINE, wxCommandEvent);
wxDEFINE_EVENT(EVT_UNBIND_MACHINE, wxCommandEvent);
wxDEFINE_EVENT(EVT_DISSMISS_MACHINE_LIST, wxCommandEvent);
wxDEFINE_EVENT(EVT_CONNECT_LAN_PRINT, wxCommandEvent);
wxDEFINE_EVENT(EVT_EDIT_PRINT_NAME, wxCommandEvent);
wxDEFINE_EVENT(EVT_CLEAR_IPADDRESS, wxCommandEvent);
#define INITIAL_NUMBER_OF_MACHINES 0
#define LIST_REFRESH_INTERVAL 200
#define MACHINE_LIST_REFRESH_INTERVAL 2000
#define WRAP_GAP FromDIP(2)
static wxString task_canceled_text = _L("Task canceled");
std::string get_print_status_info(PrintDialogStatus status)
{
switch(status) {
case PrintStatusInit:
return "PrintStatusInit";
case PrintStatusNoUserLogin:
return "PrintStatusNoUserLogin";
case PrintStatusInvalidPrinter:
return "PrintStatusInvalidPrinter";
case PrintStatusConnectingServer:
return "PrintStatusConnectingServer";
case PrintStatusReading:
return "PrintStatusReading";
case PrintStatusReadingFinished:
return "PrintStatusReadingFinished";
case PrintStatusReadingTimeout:
return "PrintStatusReadingTimeout";
case PrintStatusInUpgrading:
return "PrintStatusInUpgrading";
case PrintStatusNeedUpgradingAms:
return "PrintStatusNeedUpgradingAms";
case PrintStatusInSystemPrinting:
return "PrintStatusInSystemPrinting";
case PrintStatusInPrinting:
return "PrintStatusInPrinting";
case PrintStatusDisableAms:
return "PrintStatusDisableAms";
case PrintStatusAmsMappingSuccess:
return "PrintStatusAmsMappingSuccess";
case PrintStatusAmsMappingInvalid:
return "PrintStatusAmsMappingInvalid";
case PrintStatusAmsMappingU0Invalid:
return "PrintStatusAmsMappingU0Invalid";
case PrintStatusAmsMappingValid:
return "PrintStatusAmsMappingValid";
case PrintStatusAmsMappingByOrder:
return "PrintStatusAmsMappingByOrder";
case PrintStatusRefreshingMachineList:
return "PrintStatusRefreshingMachineList";
case PrintStatusSending:
return "PrintStatusSending";
case PrintStatusSendingCanceled:
return "PrintStatusSendingCanceled";
case PrintStatusLanModeNoSdcard:
return "PrintStatusLanModeNoSdcard";
case PrintStatusNoSdcard:
return "PrintStatusNoSdcard";
case PrintStatusUnsupportedPrinter:
return "PrintStatusUnsupportedPrinter";
case PrintStatusTimelapseNoSdcard:
return "PrintStatusTimelapseNoSdcard";
case PrintStatusNotSupportedPrintAll:
return "PrintStatusNotSupportedPrintAll";
}
return "unknown";
}
MachineObjectPanel::MachineObjectPanel(wxWindow *parent, wxWindowID id, const wxPoint &pos, const wxSize &size, long style, const wxString &name)
{
wxPanel::Create(parent, id, pos, SELECT_MACHINE_ITEM_SIZE, style, name);
Bind(wxEVT_PAINT, &MachineObjectPanel::OnPaint, this);
SetBackgroundColour(StateColor::darkModeColorFor(*wxWHITE));
m_unbind_img = ScalableBitmap(this, "unbind", 18);
m_edit_name_img = ScalableBitmap(this, "edit_button", 18);
m_select_unbind_img = ScalableBitmap(this, "unbind_selected", 18);
m_printer_status_offline = ScalableBitmap(this, "printer_status_offline", 12);
m_printer_status_busy = ScalableBitmap(this, "printer_status_busy", 12);
m_printer_status_idle = ScalableBitmap(this, "printer_status_idle", 12);
m_printer_status_lock = ScalableBitmap(this, "printer_status_lock", 16);
m_printer_in_lan = ScalableBitmap(this, "printer_in_lan", 16);
this->Bind(wxEVT_ENTER_WINDOW, &MachineObjectPanel::on_mouse_enter, this);
this->Bind(wxEVT_LEAVE_WINDOW, &MachineObjectPanel::on_mouse_leave, this);
this->Bind(wxEVT_LEFT_UP, &MachineObjectPanel::on_mouse_left_up, this);
#ifdef __APPLE__
wxPlatformInfo platformInfo;
auto major = platformInfo.GetOSMajorVersion();
auto minor = platformInfo.GetOSMinorVersion();
auto micro = platformInfo.GetOSMicroVersion();
//macos 13.1.0
if (major >= 13 && minor >= 1 && micro >= 0) {
m_is_macos_special_version = true;
}
#endif
}
MachineObjectPanel::~MachineObjectPanel() {}
void MachineObjectPanel::show_bind_dialog()
{
if (wxGetApp().is_user_login()) {
BindMachineDialog dlg;
dlg.update_machine_info(m_info);
dlg.ShowModal();
}
}
void MachineObjectPanel::set_printer_state(PrinterState state)
{
m_state = state;
Refresh();
}
void MachineObjectPanel::show_edit_printer_name(bool show)
{
m_show_edit = show;
Refresh();
}
void MachineObjectPanel::show_printer_bind(bool show, PrinterBindState state)
{
m_show_bind = show;
m_bind_state = state;
Refresh();
}
void MachineObjectPanel::OnPaint(wxPaintEvent &event)
{
wxPaintDC dc(this);
doRender(dc);
}
void MachineObjectPanel::render(wxDC &dc)
{
#ifdef __WXMSW__
wxSize size = GetSize();
wxMemoryDC memdc;
wxBitmap bmp(size.x, size.y);
memdc.SelectObject(bmp);
memdc.Blit({0, 0}, size, &dc, {0, 0});
{
wxGCDC dc2(memdc);
doRender(dc2);
}
memdc.SelectObject(wxNullBitmap);
dc.DrawBitmap(bmp, 0, 0);
#else
doRender(dc);
#endif
}
void MachineObjectPanel::doRender(wxDC &dc)
{
auto left = 10;
wxSize size = GetSize();
dc.SetPen(*wxTRANSPARENT_PEN);
auto dwbitmap = m_printer_status_offline;
if (m_state == PrinterState::IDLE) { dwbitmap = m_printer_status_idle; }
if (m_state == PrinterState::BUSY) { dwbitmap = m_printer_status_busy; }
if (m_state == PrinterState::OFFLINE) { dwbitmap = m_printer_status_offline; }
if (m_state == PrinterState::LOCK) { dwbitmap = m_printer_status_lock; }
if (m_state == PrinterState::IN_LAN) { dwbitmap = m_printer_in_lan; }
// dc.DrawCircle(left, size.y / 2, 3);
dc.DrawBitmap(dwbitmap.get_bitmap(), wxPoint(left, (size.y - dwbitmap.GetSize().y) / 2));
left += dwbitmap.GetSize().x + 8;
dc.SetFont(Label::Body_13);
dc.SetBackgroundMode(wxTRANSPARENT);
dc.SetTextForeground(StateColor::darkModeColorFor(SELECT_MACHINE_GREY900));
wxString dev_name = "";
if (m_info) {
dev_name = from_u8(m_info->dev_name);
if (m_state == PrinterState::IN_LAN) {
dev_name += _L("(LAN)");
}
}
auto sizet = dc.GetTextExtent(dev_name);
auto text_end = 0;
if (m_show_edit) {
text_end = size.x - m_unbind_img.GetSize().x - 30;
}
else {
text_end = size.x - m_unbind_img.GetSize().x;
}
wxString finally_name = dev_name;
if (sizet.x > (text_end - left)) {
auto limit_width = text_end - left - dc.GetTextExtent("...").x - 15;
for (auto i = 0; i < dev_name.length(); i++) {
auto curr_width = dc.GetTextExtent(dev_name.substr(0, i));
if (curr_width.x >= limit_width) {
finally_name = dev_name.substr(0, i) + "...";
break;
}
}
}
dc.DrawText(finally_name, wxPoint(left, (size.y - sizet.y) / 2));
if (m_hover || m_is_macos_special_version) {
if (m_hover && !m_is_macos_special_version) {
dc.SetPen(SELECT_MACHINE_BRAND);
dc.SetBrush(*wxTRANSPARENT_BRUSH);
dc.DrawRectangle(0, 0, size.x, size.y);
}
if (m_show_bind) {
if (m_bind_state == ALLOW_UNBIND) {
left = size.x - m_unbind_img.GetSize().x - 6;
dc.DrawBitmap(m_unbind_img.get_bitmap(), left, (size.y - m_unbind_img.GetSize().y) / 2);
}
}
if (m_show_edit) {
left = size.x - m_unbind_img.GetSize().x - 6 - m_edit_name_img.GetSize().x - 6;
dc.DrawBitmap(m_edit_name_img.get_bitmap(), left, (size.y - m_edit_name_img.GetSize().y) / 2);
}
}
}
void MachineObjectPanel::update_machine_info(MachineObject *info, bool is_my_devices)
{
m_info = info;
m_is_my_devices = is_my_devices;
Refresh();
}
void MachineObjectPanel::on_mouse_enter(wxMouseEvent &evt)
{
m_hover = true;
Refresh();
}
void MachineObjectPanel::on_mouse_leave(wxMouseEvent &evt)
{
m_hover = false;
Refresh();
}
void MachineObjectPanel::on_mouse_left_up(wxMouseEvent &evt)
{
if (m_is_my_devices) {
// show edit
if (m_show_edit) {
auto edit_left = GetSize().x - m_unbind_img.GetSize().x - 6 - m_edit_name_img.GetSize().x - 6;
auto edit_right = edit_left + m_edit_name_img.GetSize().x;
auto edit_top = (GetSize().y - m_edit_name_img.GetSize().y) / 2;
auto edit_bottom = (GetSize().y - m_edit_name_img.GetSize().y) / 2 + m_edit_name_img.GetSize().y;
if ((evt.GetPosition().x >= edit_left && evt.GetPosition().x <= edit_right) && evt.GetPosition().y >= edit_top && evt.GetPosition().y <= edit_bottom) {
wxCommandEvent event(EVT_EDIT_PRINT_NAME);
event.SetEventObject(this);
wxPostEvent(this, event);
return;
}
}
if (m_show_bind) {
auto left = GetSize().x - m_unbind_img.GetSize().x - 6;
auto right = left + m_unbind_img.GetSize().x;
auto top = (GetSize().y - m_unbind_img.GetSize().y) / 2;
auto bottom = (GetSize().y - m_unbind_img.GetSize().y) / 2 + m_unbind_img.GetSize().y;
if ((evt.GetPosition().x >= left && evt.GetPosition().x <= right) && evt.GetPosition().y >= top && evt.GetPosition().y <= bottom) {
wxCommandEvent event(EVT_UNBIND_MACHINE, GetId());
event.SetEventObject(this);
GetEventHandler()->ProcessEvent(event);
} else {
if (m_info) {
wxGetApp().mainframe->jump_to_monitor(m_info->dev_id);
}
//wxGetApp().mainframe->SetFocus();
wxCommandEvent event(EVT_DISSMISS_MACHINE_LIST);
event.SetEventObject(this->GetParent());
wxPostEvent(this->GetParent(), event);
}
return;
}
if (m_info && m_info->is_lan_mode_printer()) {
if (m_info->has_access_right() && m_info->is_avaliable()) {
wxGetApp().mainframe->jump_to_monitor(m_info->dev_id);
} else {
wxCommandEvent event(EVT_CONNECT_LAN_PRINT);
event.SetEventObject(this);
wxPostEvent(this, event);
}
} else {
wxGetApp().mainframe->jump_to_monitor(m_info->dev_id);
}
} else {
if (m_info && m_info->is_lan_mode_printer()) {
wxCommandEvent event(EVT_CONNECT_LAN_PRINT);
event.SetEventObject(this);
wxPostEvent(this, event);
} else {
wxCommandEvent event(EVT_BIND_MACHINE);
event.SetEventObject(this);
wxPostEvent(this, event);
}
}
}
SelectMachinePopup::SelectMachinePopup(wxWindow *parent)
: PopupWindow(parent, wxBORDER_NONE | wxPU_CONTAINS_CONTROLS), m_dismiss(false)
{
#ifdef __WINDOWS__
SetDoubleBuffered(true);
#endif //__WINDOWS__
SetSize(SELECT_MACHINE_POPUP_SIZE);
SetMinSize(SELECT_MACHINE_POPUP_SIZE);
SetMaxSize(SELECT_MACHINE_POPUP_SIZE);
Freeze();
wxBoxSizer *m_sizer_main = new wxBoxSizer(wxVERTICAL);
SetBackgroundColour(SELECT_MACHINE_GREY400);
m_scrolledWindow = new wxScrolledWindow(this, wxID_ANY, wxDefaultPosition, SELECT_MACHINE_LIST_SIZE, wxHSCROLL | wxVSCROLL);
m_scrolledWindow->SetBackgroundColour(*wxWHITE);
m_scrolledWindow->SetMinSize(SELECT_MACHINE_LIST_SIZE);
m_scrolledWindow->SetScrollRate(0, 5);
auto m_sizxer_scrolledWindow = new wxBoxSizer(wxVERTICAL);
m_scrolledWindow->SetSizer(m_sizxer_scrolledWindow);
m_scrolledWindow->Layout();
m_sizxer_scrolledWindow->Fit(m_scrolledWindow);
#if !BBL_RELEASE_TO_PUBLIC && defined(__WINDOWS__)
m_sizer_search_bar = new wxBoxSizer(wxVERTICAL);
m_search_bar = new wxSearchCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
m_search_bar->SetDescriptiveText(_L("Search"));
m_search_bar->ShowSearchButton( true );
m_search_bar->ShowCancelButton( false );
m_sizer_search_bar->Add( m_search_bar, 1, wxALL| wxEXPAND, 1 );
m_sizer_main->Add(m_sizer_search_bar, 0, wxALL | wxEXPAND, FromDIP(2));
m_search_bar->Bind( wxEVT_COMMAND_TEXT_UPDATED, &SelectMachinePopup::update_machine_list, this );
#endif
auto own_title = create_title_panel(_L("My Device"));
m_sizer_my_devices = new wxBoxSizer(wxVERTICAL);
auto other_title = create_title_panel(_L("Other Device"));
m_sizer_other_devices = new wxBoxSizer(wxVERTICAL);
m_sizxer_scrolledWindow->Add(own_title, 0, wxEXPAND | wxLEFT, FromDIP(15));
m_sizxer_scrolledWindow->Add(m_sizer_my_devices, 0, wxEXPAND, 0);
m_sizxer_scrolledWindow->Add(other_title, 0, wxEXPAND | wxLEFT, FromDIP(15));
m_sizxer_scrolledWindow->Add(m_sizer_other_devices, 0, wxEXPAND, 0);
m_sizer_main->Add(m_scrolledWindow, 0, wxALL | wxEXPAND, FromDIP(2));
SetSizer(m_sizer_main);
Layout();
Thaw();
#ifdef __APPLE__
m_scrolledWindow->Bind(wxEVT_LEFT_UP, &SelectMachinePopup::OnLeftUp, this);
#endif // __APPLE__
m_refresh_timer = new wxTimer();
m_refresh_timer->SetOwner(this);
Bind(EVT_UPDATE_USER_MACHINE_LIST, &SelectMachinePopup::update_machine_list, this);
Bind(wxEVT_TIMER, &SelectMachinePopup::on_timer, this);
Bind(EVT_DISSMISS_MACHINE_LIST, &SelectMachinePopup::on_dissmiss_win, this);
}
SelectMachinePopup::~SelectMachinePopup() { delete m_refresh_timer;}
void SelectMachinePopup::Popup(wxWindow *WXUNUSED(focus))
{
BOOST_LOG_TRIVIAL(trace) << "get_print_info: start";
start_ssdp(true);
if (m_refresh_timer) {
m_refresh_timer->Stop();
m_refresh_timer->Start(MACHINE_LIST_REFRESH_INTERVAL);
}
if (wxGetApp().is_user_login()) {
if (!get_print_info_thread) {
get_print_info_thread = new boost::thread(Slic3r::create_thread([this, token = std::weak_ptr(m_token)] {
NetworkAgent* agent = wxGetApp().getAgent();
unsigned int http_code;
std::string body;
int result = agent->get_user_print_info(&http_code, &body);
CallAfter([token, this, result, body]() {
if (token.expired()) {return;}
if (result == 0) {
m_print_info = body;
}
else {
m_print_info = "";
}
wxCommandEvent event(EVT_UPDATE_USER_MACHINE_LIST);
event.SetEventObject(this);
wxPostEvent(this, event);
});
}));
}
}
wxPostEvent(this, wxTimerEvent());
PopupWindow::Popup();
}
void SelectMachinePopup::OnDismiss()
{
BOOST_LOG_TRIVIAL(trace) << "get_print_info: dismiss";
start_ssdp(false);
m_dismiss = true;
if (m_refresh_timer) {
m_refresh_timer->Stop();
}
if (get_print_info_thread) {
if (get_print_info_thread->joinable()) {
get_print_info_thread->join();
delete get_print_info_thread;
get_print_info_thread = nullptr;
}
}
wxCommandEvent event(EVT_FINISHED_UPDATE_MACHINE_LIST);
event.SetEventObject(this);
wxPostEvent(this, event);
}
bool SelectMachinePopup::ProcessLeftDown(wxMouseEvent &event) {
return PopupWindow::ProcessLeftDown(event);
}
bool SelectMachinePopup::Show(bool show) {
if (show) {
for (int i = 0; i < m_user_list_machine_panel.size(); i++) {
m_user_list_machine_panel[i]->mPanel->update_machine_info(nullptr);
m_user_list_machine_panel[i]->mPanel->Hide();
}
for (int j = 0; j < m_other_list_machine_panel.size(); j++) {
m_other_list_machine_panel[j]->mPanel->update_machine_info(nullptr);
m_other_list_machine_panel[j]->mPanel->Hide();
}
}
return PopupWindow::Show(show);
}
wxWindow *SelectMachinePopup::create_title_panel(wxString text)
{
auto m_panel_title_own = new wxWindow(m_scrolledWindow, wxID_ANY, wxDefaultPosition, SELECT_MACHINE_ITEM_SIZE, wxTAB_TRAVERSAL);
m_panel_title_own->SetBackgroundColour(*wxWHITE);
wxBoxSizer *m_sizer_title_own = new wxBoxSizer(wxHORIZONTAL);
auto m_title_own = new wxStaticText(m_panel_title_own, wxID_ANY, text, wxDefaultPosition, wxDefaultSize, 0);
m_title_own->Wrap(-1);
m_sizer_title_own->Add(m_title_own, 0, wxALIGN_CENTER, 0);
wxBoxSizer *m_sizer_line_own = new wxBoxSizer(wxHORIZONTAL);
auto m_panel_line_own = new wxPanel(m_panel_title_own, wxID_ANY, wxDefaultPosition, wxSize(SELECT_MACHINE_ITEM_SIZE.x, FromDIP(1)), wxTAB_TRAVERSAL);
m_panel_line_own->SetBackgroundColour(SELECT_MACHINE_GREY400);
m_sizer_line_own->Add(m_panel_line_own, 0, wxALIGN_CENTER, 0);
m_sizer_title_own->Add(0, 0, 0, wxLEFT, FromDIP(10));
m_sizer_title_own->Add(m_sizer_line_own, 1, wxEXPAND | wxRIGHT, FromDIP(10));
m_panel_title_own->SetSizer(m_sizer_title_own);
m_panel_title_own->Layout();
return m_panel_title_own;
}
void SelectMachinePopup::on_timer(wxTimerEvent &event)
{
BOOST_LOG_TRIVIAL(trace) << "SelectMachinePopup on_timer";
wxGetApp().reset_to_active();
wxCommandEvent user_event(EVT_UPDATE_USER_MACHINE_LIST);
user_event.SetEventObject(this);
wxPostEvent(this, user_event);
}
void SelectMachinePopup::update_other_devices()
{
DeviceManager* dev = wxGetApp().getDeviceManager();
if (!dev) return;
m_free_machine_list = dev->get_local_machine_list();
BOOST_LOG_TRIVIAL(trace) << "SelectMachinePopup update_other_devices start";
this->Freeze();
m_scrolledWindow->Freeze();
int i = 0;
for (auto &elem : m_free_machine_list) {
MachineObject * mobj = elem.second;
/* do not show printer bind state is empty */
if (!mobj->is_avaliable()) continue;
if (!wxGetApp().is_user_login() && !mobj->is_lan_mode_printer())
continue;
/* do not show printer in my list */
auto it = m_bind_machine_list.find(mobj->dev_id);
if (it != m_bind_machine_list.end())
continue;
MachineObjectPanel* op = nullptr;
if (i < m_other_list_machine_panel.size()) {
op = m_other_list_machine_panel[i]->mPanel;
} else {
op = new MachineObjectPanel(m_scrolledWindow, wxID_ANY);
MachinePanel* mpanel = new MachinePanel();
mpanel->mIndex = wxString::Format("%d", i);
mpanel->mPanel = op;
m_other_list_machine_panel.push_back(mpanel);
m_sizer_other_devices->Add(op, 0, wxEXPAND, 0);
}
#if !BBL_RELEASE_TO_PUBLIC && defined(__WINDOWS__)
if (!search_for_printer(mobj)) {
op->Hide();
}
else {
op->Show();
}
#else
op->Show();
#endif
i++;
op->update_machine_info(mobj);
if (mobj->is_lan_mode_printer()) {
if (mobj->has_access_right()) {
op->set_printer_state(PrinterState::IN_LAN);
} else {
op->set_printer_state(PrinterState::LOCK);
}
} else {
op->show_edit_printer_name(false);
op->show_printer_bind(true, PrinterBindState::ALLOW_BIND);
if (mobj->is_in_printing()) {
op->set_printer_state(PrinterState::BUSY);
} else {
op->SetToolTip(_L("Online"));
op->set_printer_state(IDLE);
}
}
op->Bind(EVT_CONNECT_LAN_PRINT, [this, mobj](wxCommandEvent &e) {
if (mobj) {
if (mobj->is_lan_mode_printer()) {
ConnectPrinterDialog dlg(wxGetApp().mainframe, wxID_ANY, _L("Input access code"));
dlg.set_machine_object(mobj);
if (dlg.ShowModal() == wxID_OK) {
wxGetApp().mainframe->jump_to_monitor(mobj->dev_id);
}
}
}
});
op->Bind(EVT_BIND_MACHINE, [this, mobj](wxCommandEvent &e) {
BindMachineDialog dlg;
dlg.update_machine_info(mobj);
int dlg_result = wxID_CANCEL;
dlg_result = dlg.ShowModal();
if (dlg_result == wxID_OK) { wxGetApp().mainframe->jump_to_monitor(mobj->dev_id); }
});
}
for (int j = i; j < m_other_list_machine_panel.size(); j++) {
m_other_list_machine_panel[j]->mPanel->update_machine_info(nullptr);
m_other_list_machine_panel[j]->mPanel->Hide();
}
if (m_placeholder_panel != nullptr) {
m_scrolledWindow->RemoveChild(m_placeholder_panel);
m_placeholder_panel->Destroy();
m_placeholder_panel = nullptr;
}
m_placeholder_panel = new wxWindow(m_scrolledWindow, wxID_ANY, wxDefaultPosition, wxSize(-1,FromDIP(26)));
wxBoxSizer* placeholder_sizer = new wxBoxSizer(wxVERTICAL);
m_hyperlink = new wxHyperlinkCtrl(m_placeholder_panel, wxID_ANY, _L("Can't find my devices?"), wxT("https://wiki.bambulab.com/en/software/bambu-studio/failed-to-connect-printer"), wxDefaultPosition, wxDefaultSize, wxHL_DEFAULT_STYLE);
placeholder_sizer->Add(m_hyperlink, 0, wxALIGN_CENTER | wxALL, 5);
m_placeholder_panel->SetSizer(placeholder_sizer);
m_placeholder_panel->Layout();
placeholder_sizer->Fit(m_placeholder_panel);
m_placeholder_panel->SetBackgroundColour(StateColor::darkModeColorFor(*wxWHITE));
m_sizer_other_devices->Add(m_placeholder_panel, 0, wxEXPAND, 0);
//m_sizer_other_devices->Layout();
if(m_other_devices_count != i) {
m_scrolledWindow->Fit();
}
m_scrolledWindow->Layout();
m_scrolledWindow->Thaw();
Layout();
Fit();
this->Thaw();
m_other_devices_count = i;
BOOST_LOG_TRIVIAL(trace) << "SelectMachinePopup update_other_devices end";
}
void SelectMachinePopup::update_user_devices()
{
Slic3r::DeviceManager* dev = Slic3r::GUI::wxGetApp().getDeviceManager();
if (!dev) return;
if (!m_print_info.empty()) {
dev->parse_user_print_info(m_print_info);
m_print_info = "";
}
m_bind_machine_list.clear();
m_bind_machine_list = dev->get_my_machine_list();
//sort list
std::vector<std::pair<std::string, MachineObject*>> user_machine_list;
for (auto& it: m_bind_machine_list) {
user_machine_list.push_back(it);
}
std::sort(user_machine_list.begin(), user_machine_list.end(), [&](auto& a, auto&b) {
if (a.second && b.second) {
return a.second->dev_name.compare(b.second->dev_name) < 0;
}
return false;
});
BOOST_LOG_TRIVIAL(trace) << "SelectMachinePopup update_machine_list start";
this->Freeze();
m_scrolledWindow->Freeze();
int i = 0;
for (auto& elem : user_machine_list) {
MachineObject* mobj = elem.second;
MachineObjectPanel* op = nullptr;
if (i < m_user_list_machine_panel.size()) {
op = m_user_list_machine_panel[i]->mPanel;
#if !BBL_RELEASE_TO_PUBLIC && defined(__WINDOWS__)
if (!search_for_printer(mobj)) {
op->Hide();
} else {
op->Show();
}
#else
op->Show();
#endif
} else {
op = new MachineObjectPanel(m_scrolledWindow, wxID_ANY);
MachinePanel* mpanel = new MachinePanel();
mpanel->mIndex = wxString::Format("%d", i);
mpanel->mPanel = op;
m_user_list_machine_panel.push_back(mpanel);
m_sizer_my_devices->Add(op, 0, wxEXPAND, 0);
}
i++;
op->update_machine_info(mobj, true);
//set in lan
if (mobj->is_lan_mode_printer()) {
if (!mobj->is_online()) {
continue;
}
else {
op->show_printer_bind(false, PrinterBindState::NONE);
op->show_edit_printer_name(false);
if (mobj->has_access_right() && mobj->is_avaliable()) {
op->set_printer_state(PrinterState::IN_LAN);
op->show_printer_bind(true, PrinterBindState::ALLOW_UNBIND);
op->SetToolTip(_L("Online"));
}
else {
op->set_printer_state(PrinterState::LOCK);
}
}
op->Bind(EVT_UNBIND_MACHINE, [this, dev, mobj](wxCommandEvent& e) {
dev->set_selected_machine("");
if (mobj) {
mobj->set_access_code("");
mobj->erase_user_access_code();
}
MessageDialog msg_wingow(nullptr, _L("Log out successful."), "", wxAPPLY | wxOK);
if (msg_wingow.ShowModal() == wxOK) { return; }
});
}
else {
op->show_printer_bind(true, PrinterBindState::ALLOW_UNBIND);
op->Bind(EVT_UNBIND_MACHINE, [this, mobj, dev](wxCommandEvent& e) {
// show_unbind_dialog
UnBindMachineDialog dlg;
dlg.update_machine_info(mobj);
if (dlg.ShowModal() == wxID_OK) {
dev->set_selected_machine("");
}
});
if (!mobj->is_online()) {
op->SetToolTip(_L("Offline"));
op->set_printer_state(PrinterState::OFFLINE);
}
else {
op->show_edit_printer_name(true);
op->show_printer_bind(true, PrinterBindState::ALLOW_UNBIND);
if (mobj->is_in_printing()) {
op->SetToolTip(_L("Busy"));
op->set_printer_state(PrinterState::BUSY);
}
else {
op->SetToolTip(_L("Online"));
op->set_printer_state(PrinterState::IDLE);
}
}
}
op->Bind(EVT_CONNECT_LAN_PRINT, [this, mobj](wxCommandEvent &e) {
if (mobj) {
if (mobj->is_lan_mode_printer()) {
ConnectPrinterDialog dlg(wxGetApp().mainframe, wxID_ANY, _L("Input access code"));
dlg.set_machine_object(mobj);
if (dlg.ShowModal() == wxID_OK) {
wxGetApp().mainframe->jump_to_monitor(mobj->dev_id);
}
}
}
});
op->Bind(EVT_EDIT_PRINT_NAME, [this, mobj](wxCommandEvent &e) {
EditDevNameDialog dlg;
dlg.set_machine_obj(mobj);
dlg.ShowModal();
});
}
for (int j = i; j < m_user_list_machine_panel.size(); j++) {
m_user_list_machine_panel[j]->mPanel->update_machine_info(nullptr);
m_user_list_machine_panel[j]->mPanel->Hide();
}
//m_sizer_my_devices->Layout();
if (m_my_devices_count != i) {
m_scrolledWindow->Fit();
}
m_scrolledWindow->Layout();
m_scrolledWindow->Thaw();
Layout();
Fit();
this->Thaw();
m_my_devices_count = i;
}
bool SelectMachinePopup::search_for_printer(MachineObject* obj)
{
std::string search_text = std::string((m_search_bar->GetValue()).mb_str());
if (search_text.empty()) {
return true;
}
auto name = obj->dev_name;
auto ip = obj->dev_ip;
auto name_it = name.find(search_text);
auto ip_it = ip.find(search_text);
if ((name_it != std::string::npos)||(ip_it != std::string::npos)) {
return true;
}
return false;
}
void SelectMachinePopup::on_dissmiss_win(wxCommandEvent &event)
{
Dismiss();
}
void SelectMachinePopup::update_machine_list(wxCommandEvent &event)
{
update_user_devices();
update_other_devices();
BOOST_LOG_TRIVIAL(trace) << "SelectMachinePopup update_machine_list end";
}
void SelectMachinePopup::start_ssdp(bool start)
{
return;
//if (wxGetApp().getAgent()) { wxGetApp().getAgent()->start_discovery(true, start); }
}
void SelectMachinePopup::OnLeftUp(wxMouseEvent &event)
{
auto mouse_pos = ClientToScreen(event.GetPosition());
auto wxscroll_win_pos = m_scrolledWindow->ClientToScreen(wxPoint(0, 0));
if (mouse_pos.x > wxscroll_win_pos.x && mouse_pos.y > wxscroll_win_pos.y && mouse_pos.x < (wxscroll_win_pos.x + m_scrolledWindow->GetSize().x) &&
mouse_pos.y < (wxscroll_win_pos.y + m_scrolledWindow->GetSize().y)) {
for (MachinePanel* p : m_user_list_machine_panel) {
auto p_rect = p->mPanel->ClientToScreen(wxPoint(0, 0));
if (mouse_pos.x > p_rect.x && mouse_pos.y > p_rect.y && mouse_pos.x < (p_rect.x + p->mPanel->GetSize().x) && mouse_pos.y < (p_rect.y + p->mPanel->GetSize().y)) {
wxMouseEvent event(wxEVT_LEFT_UP);
auto tag_pos = p->mPanel->ScreenToClient(mouse_pos);
event.SetPosition(tag_pos);
event.SetEventObject(p->mPanel);
wxPostEvent(p->mPanel, event);
}
}
for (MachinePanel* p : m_other_list_machine_panel) {
auto p_rect = p->mPanel->ClientToScreen(wxPoint(0, 0));
if (mouse_pos.x > p_rect.x && mouse_pos.y > p_rect.y && mouse_pos.x < (p_rect.x + p->mPanel->GetSize().x) && mouse_pos.y < (p_rect.y + p->mPanel->GetSize().y)) {
wxMouseEvent event(wxEVT_LEFT_UP);
auto tag_pos = p->mPanel->ScreenToClient(mouse_pos);
event.SetPosition(tag_pos);
event.SetEventObject(p->mPanel);
wxPostEvent(p->mPanel, event);
}
}
//hyper link
auto h_rect = m_hyperlink->ClientToScreen(wxPoint(0, 0));
if (mouse_pos.x > h_rect.x && mouse_pos.y > h_rect.y && mouse_pos.x < (h_rect.x + m_hyperlink->GetSize().x) && mouse_pos.y < (h_rect.y + m_hyperlink->GetSize().y)) {
wxLaunchDefaultBrowser(wxT("https://wiki.bambulab.com/en/software/bambu-studio/failed-to-connect-printer"));
}
}
}
static wxString MACHINE_BED_TYPE_STRING[BED_TYPE_COUNT] = {
//_L("Auto"),
_L("Bambu Cool Plate") + " / " + _L("PLA Plate"),
_L("Bambu Engineering Plate"),
_L("Bambu Smooth PEI Plate") + "/" + _L("High temperature Plate"),
_L("Bambu Textured PEI Plate")};
static std::string MachineBedTypeString[BED_TYPE_COUNT] = {
//"auto",
"pc",
"pe",
"pei",
"pte",
};
void SelectMachineDialog::stripWhiteSpace(std::string& str)
{
if (str == "") { return; }
string::iterator cur_it;
cur_it = str.begin();
while (cur_it != str.end()) {
if ((*cur_it) == '\n' || (*cur_it) == ' ') {
cur_it = str.erase(cur_it);
}
else {
cur_it++;
}
}
}
wxString SelectMachineDialog::format_text(wxString &m_msg)
{
if (wxGetApp().app_config->get("language") != "zh_CN") {return m_msg; }
wxString out_txt = m_msg;
wxString count_txt = "";
int new_line_pos = 0;
for (int i = 0; i < m_msg.length(); i++) {
auto text_size = m_statictext_ams_msg->GetTextExtent(count_txt);
if (text_size.x < (FromDIP(400))) {
count_txt += m_msg[i];
} else {
out_txt.insert(i - 1, '\n');
count_txt = "";
}
}
return out_txt;
}
SelectMachineDialog::SelectMachineDialog(Plater *plater)
: DPIDialog(static_cast<wxWindow *>(wxGetApp().mainframe), wxID_ANY, _L("Send print job to"), wxDefaultPosition, wxDefaultSize, wxCAPTION | wxCLOSE_BOX)
, m_plater(plater), m_export_3mf_cancel(false)
, m_mapping_popup(AmsMapingPopup(this))
, m_mapping_tip_popup(AmsMapingTipPopup(this))
, m_mapping_tutorial_popup(AmsTutorialPopup(this))
{
#ifdef __WINDOWS__
SetDoubleBuffered(true);
#endif //__WINDOWS__
// bind
Bind(wxEVT_CLOSE_WINDOW, &SelectMachineDialog::on_cancel, this);
for (int i = 0; i < BED_TYPE_COUNT; i++) { m_bedtype_list.push_back(MACHINE_BED_TYPE_STRING[i]); }
// font
SetFont(wxGetApp().normal_font());
// icon
std::string icon_path = (boost::format("%1%/images/OrcaSlicerTitle.ico") % resources_dir()).str();
SetIcon(wxIcon(encode_path(icon_path.c_str()), wxBITMAP_TYPE_ICO));
Freeze();
SetBackgroundColour(m_colour_def_color);
m_sizer_main = new wxBoxSizer(wxVERTICAL);
m_sizer_main->SetMinSize(wxSize(0, -1));
m_line_top = new wxPanel(this, wxID_ANY, wxDefaultPosition, wxSize(-1, 1), wxTAB_TRAVERSAL);
m_line_top->SetBackgroundColour(wxColour(166, 169, 170));
m_scrollable_view = new wxScrolledWindow(this, wxID_ANY, wxDefaultPosition, wxDefaultSize);
m_sizer_scrollable_view = new wxBoxSizer(wxVERTICAL);
m_scrollable_region = new wxPanel(m_scrollable_view, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL);
m_sizer_scrollable_region = new wxBoxSizer(wxVERTICAL);
//rename normal
m_rename_switch_panel = new wxSimplebook(m_scrollable_region);
m_rename_switch_panel->SetSize(wxSize(FromDIP(420), FromDIP(25)));
m_rename_switch_panel->SetMinSize(wxSize(FromDIP(420), FromDIP(25)));
m_rename_switch_panel->SetMaxSize(wxSize(FromDIP(420), FromDIP(25)));
m_rename_normal_panel = new wxPanel(m_rename_switch_panel, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL);
m_rename_normal_panel->SetBackgroundColour(*wxWHITE);
rename_sizer_v = new wxBoxSizer(wxVERTICAL);
rename_sizer_h = new wxBoxSizer(wxHORIZONTAL);
m_rename_text = new wxStaticText(m_rename_normal_panel, wxID_ANY, wxT("MyLabel"), wxDefaultPosition, wxDefaultSize, wxST_ELLIPSIZE_END);
m_rename_text->SetFont(::Label::Body_13);
m_rename_text->SetMaxSize(wxSize(FromDIP(390), -1));
m_rename_button = new ScalableButton(m_rename_normal_panel, wxID_ANY, "ams_editable");
ams_editable = new ScalableBitmap(this, "ams_editable", 13);
ams_editable_light = new ScalableBitmap(this, "ams_editable_light", 13);
m_rename_button->SetBackgroundColour(*wxWHITE);
rename_sizer_h->Add(m_rename_text, 0, wxALIGN_CENTER, 0);
rename_sizer_h->Add(m_rename_button, 0, wxALIGN_CENTER, 0);
rename_sizer_v->Add(rename_sizer_h, 1, wxALIGN_CENTER, 0);
m_rename_normal_panel->SetSizer(rename_sizer_v);
m_rename_normal_panel->Layout();
rename_sizer_v->Fit(m_rename_normal_panel);
//rename edit
auto m_rename_edit_panel = new wxPanel(m_rename_switch_panel, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL);
m_rename_edit_panel->SetBackgroundColour(*wxWHITE);
auto rename_edit_sizer_v = new wxBoxSizer(wxVERTICAL);
m_rename_input = new ::TextInput(m_rename_edit_panel, wxEmptyString, wxEmptyString, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER);
m_rename_input->GetTextCtrl()->SetFont(::Label::Body_13);
m_rename_input->SetSize(wxSize(FromDIP(380), FromDIP(24)));
m_rename_input->SetMinSize(wxSize(FromDIP(380), FromDIP(24)));
m_rename_input->SetMaxSize(wxSize(FromDIP(380), FromDIP(24)));
m_rename_input->Bind(wxEVT_TEXT_ENTER, [this](auto& e) {on_rename_enter();});
m_rename_input->Bind(wxEVT_KILL_FOCUS, [this](auto& e) {
if (!m_rename_input->HasFocus() && !m_rename_text->HasFocus())
on_rename_enter();
else
e.Skip(); });
rename_edit_sizer_v->Add(m_rename_input, 1, wxALIGN_CENTER, 0);
m_rename_edit_panel->SetSizer(rename_edit_sizer_v);
m_rename_edit_panel->Layout();
rename_edit_sizer_v->Fit(m_rename_edit_panel);
m_rename_button->Bind(wxEVT_BUTTON, &SelectMachineDialog::on_rename_click, this);
m_rename_switch_panel->AddPage(m_rename_normal_panel, wxEmptyString, true);
m_rename_switch_panel->AddPage(m_rename_edit_panel, wxEmptyString, false);
Bind(wxEVT_CHAR_HOOK, [this](wxKeyEvent& e) {
if (e.GetKeyCode() == WXK_ESCAPE) {
if (m_rename_switch_panel->GetSelection() == 0) {
e.Skip();
}
else {
m_rename_switch_panel->SetSelection(0);
m_rename_text->SetLabel(m_current_project_name);
m_rename_normal_panel->Layout();
}
}
else {
e.Skip();
}
});
auto m_sizer_thumbnail_area = new wxBoxSizer(wxHORIZONTAL);
auto last_plate_panel = new wxWindow(m_scrollable_region, wxID_ANY);
last_plate_panel->SetBackgroundColour(*wxWHITE);
auto last_plate_sizer = new wxBoxSizer(wxVERTICAL);
last_plate_panel->SetMinSize(wxSize(FromDIP(32), FromDIP(32)));
m_bitmap_last_plate = new wxStaticBitmap(last_plate_panel, wxID_ANY, create_scaled_bitmap("go_last_plate", this, 32), wxDefaultPosition, wxSize(FromDIP(32), FromDIP(32)), 0);
last_plate_sizer->Add(m_bitmap_last_plate, 0, wxALIGN_CENTER, 0);
last_plate_panel->SetSizer(last_plate_sizer);
m_panel_image = new wxPanel(m_scrollable_region, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL);
m_panel_image->SetBackgroundColour(m_colour_def_color);
m_sizer_thumbnail = new wxBoxSizer(wxHORIZONTAL);
m_thumbnailPanel = new ThumbnailPanel(m_panel_image);
m_thumbnailPanel->SetSize(wxSize(FromDIP(256), FromDIP(256)));
m_thumbnailPanel->SetMinSize(wxSize(FromDIP(256), FromDIP(256)));
m_thumbnailPanel->SetMaxSize(wxSize(FromDIP(256), FromDIP(256)));
m_thumbnailPanel->SetBackgroundColour(*wxRED);
m_sizer_thumbnail->Add(m_thumbnailPanel, 0, wxALIGN_CENTER, 0);
m_panel_image->SetSizer(m_sizer_thumbnail);
m_panel_image->Layout();
auto next_plate_panel = new wxWindow(m_scrollable_region, wxID_ANY);
next_plate_panel->SetBackgroundColour(*wxWHITE);
auto next_plate_sizer = new wxBoxSizer(wxVERTICAL);
next_plate_panel->SetMinSize(wxSize(FromDIP(32), FromDIP(32)));
m_bitmap_next_plate = new wxStaticBitmap(next_plate_panel, wxID_ANY, create_scaled_bitmap("go_next_plate", this, 32), wxDefaultPosition, wxSize(FromDIP(32), FromDIP(32)), 0);
next_plate_sizer->Add(m_bitmap_next_plate, 0, wxALIGN_CENTER, 0);
next_plate_panel->SetSizer(next_plate_sizer);
m_sizer_thumbnail_area->Add(last_plate_panel, 0, wxALIGN_CENTER, 0);
m_sizer_thumbnail_area->Add(m_panel_image, 0, wxALIGN_CENTER|wxLEFT|wxRIGHT, FromDIP(24));
m_sizer_thumbnail_area->Add(next_plate_panel, 0, wxALIGN_CENTER, 0);
wxBoxSizer *m_sizer_basic = new wxBoxSizer(wxHORIZONTAL);
wxBoxSizer *m_sizer_basic_weight = new wxBoxSizer(wxHORIZONTAL);
wxBoxSizer *m_sizer_basic_time = new wxBoxSizer(wxHORIZONTAL);
print_time = new ScalableBitmap(this, "print-time", 18);
timeimg = new wxStaticBitmap(m_scrollable_region, wxID_ANY, print_time->bmp(), wxDefaultPosition, wxSize(FromDIP(18), FromDIP(18)), 0);
m_sizer_basic_weight->Add(timeimg, 1, wxEXPAND | wxALL, FromDIP(5));
m_stext_time = new wxStaticText(m_scrollable_region, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT);
m_sizer_basic_weight->Add(m_stext_time, 0, wxALL, FromDIP(5));
m_sizer_basic->Add(m_sizer_basic_weight, 0, wxALIGN_CENTER, 0);
m_sizer_basic->Add(0, 0, 0, wxEXPAND | wxLEFT | wxRIGHT, FromDIP(30));
print_weight = new ScalableBitmap(this, "print-weight", 18);
weightimg = new wxStaticBitmap(m_scrollable_region, wxID_ANY, print_weight->bmp(), wxDefaultPosition, wxSize(FromDIP(18), FromDIP(18)), 0);
m_sizer_basic_time->Add(weightimg, 1, wxEXPAND | wxALL, FromDIP(5));
m_stext_weight = new wxStaticText(m_scrollable_region, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxALIGN_LEFT);
m_sizer_basic_time->Add(m_stext_weight, 0, wxALL, FromDIP(5));
m_sizer_basic->Add(m_sizer_basic_time, 0, wxALIGN_CENTER, 0);
wxBoxSizer* m_sizer_material_area = new wxBoxSizer(wxHORIZONTAL);
wxBoxSizer* m_sizer_material_tips = new wxBoxSizer(wxHORIZONTAL);
enable_ams_mapping = new ScalableBitmap(this, "enable_ams", 16);
img_amsmapping_tip = new wxStaticBitmap(m_scrollable_region, wxID_ANY, enable_ams_mapping->bmp(), wxDefaultPosition, wxSize(FromDIP(16), FromDIP(16)), 0);
m_sizer_material_tips->Add(img_amsmapping_tip, 0, wxALIGN_CENTER | wxLEFT, FromDIP(5));
img_amsmapping_tip->Bind(wxEVT_ENTER_WINDOW, [this](auto& e) {
wxPoint img_pos = img_amsmapping_tip->ClientToScreen(wxPoint(0, 0));
wxPoint popup_pos(img_pos.x, img_pos.y + img_amsmapping_tip->GetRect().height);
m_mapping_tutorial_popup.Position(popup_pos, wxSize(0, 0));
m_mapping_tutorial_popup.Popup();
if (m_mapping_tutorial_popup.ClientToScreen(wxPoint(0, 0)).y < img_pos.y) {
m_mapping_tutorial_popup.Dismiss();
popup_pos = wxPoint(img_pos.x, img_pos.y - m_mapping_tutorial_popup.GetRect().height);
m_mapping_tutorial_popup.Position(popup_pos, wxSize(0, 0));
m_mapping_tutorial_popup.Popup();
}
});
img_amsmapping_tip->Bind(wxEVT_LEAVE_WINDOW, [this](wxMouseEvent& e) {
m_mapping_tutorial_popup.Dismiss();
});
m_sizer_material = new wxGridSizer(0, 4, 0, FromDIP(5));
m_sizer_material_area->Add(m_sizer_material_tips, 0, wxALIGN_CENTER|wxLEFT, FromDIP(8));
m_sizer_material_area->Add(m_sizer_material, 0, wxLEFT, FromDIP(15));
m_sizer_backup = new wxBoxSizer(wxHORIZONTAL);
m_ams_backup_tip = new Label(this, _L("Auto Refill"));
m_ams_backup_tip->SetFont(::Label::Head_12);
m_ams_backup_tip->SetForegroundColour(wxColour(0x009688));
m_ams_backup_tip->SetBackgroundColour(*wxWHITE);
img_ams_backup = new wxStaticBitmap(this, wxID_ANY, create_scaled_bitmap("automatic_material_renewal", this, 16), wxDefaultPosition, wxSize(FromDIP(16), FromDIP(16)), 0);
img_ams_backup->SetBackgroundColour(*wxWHITE);
m_sizer_backup->Add(0, 0, 1, wxEXPAND, 0);
m_sizer_backup->Add(img_ams_backup, 0, wxALL, FromDIP(3));
m_sizer_backup->Add(m_ams_backup_tip, 0, wxTOP, FromDIP(5));
m_ams_backup_tip->Hide();
img_ams_backup->Hide();
m_ams_backup_tip->Bind(wxEVT_ENTER_WINDOW, [this](auto& e) {SetCursor(wxCURSOR_HAND); });
img_ams_backup->Bind(wxEVT_ENTER_WINDOW, [this](auto& e) {SetCursor(wxCURSOR_HAND); });
m_ams_backup_tip->Bind(wxEVT_LEAVE_WINDOW, [this](auto& e) {SetCursor(wxCURSOR_ARROW); });
img_ams_backup->Bind(wxEVT_LEAVE_WINDOW, [this](auto& e) {SetCursor(wxCURSOR_ARROW); });
m_ams_backup_tip->Bind(wxEVT_LEFT_DOWN, [this](auto& e) { if (!m_is_in_sending_mode) {popup_filament_backup(); on_rename_enter();} });
img_ams_backup->Bind(wxEVT_LEFT_DOWN, [this](auto& e) {if (!m_is_in_sending_mode) popup_filament_backup();on_rename_enter(); });
m_statictext_ams_msg = new wxStaticText(this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxALIGN_CENTER_HORIZONTAL);
m_statictext_ams_msg->SetFont(::Label::Body_13);
m_statictext_ams_msg->Hide();
m_line_materia = new wxPanel(this, wxID_ANY, wxDefaultPosition, wxSize(-1, 1), wxTAB_TRAVERSAL);
m_line_materia->SetForegroundColour(wxColour(238, 238, 238));
m_line_materia->SetBackgroundColour(wxColour(238, 238, 238));
wxBoxSizer *m_sizer_printer = new wxBoxSizer(wxHORIZONTAL);
m_stext_printer_title = new wxStaticText(this, wxID_ANY, _L("Printer"), wxDefaultPosition, wxSize(-1, -1), 0);
m_stext_printer_title->SetFont(::Label::Head_14);
m_stext_printer_title->Wrap(-1);
m_stext_printer_title->SetForegroundColour(m_colour_bold_color);
m_stext_printer_title->SetBackgroundColour(m_colour_def_color);
m_sizer_printer->Add(m_stext_printer_title, 0, wxALL | wxLEFT, FromDIP(5));
m_sizer_printer->Add(0, 0, 0, wxEXPAND | wxLEFT, FromDIP(12));
m_comboBox_printer = new ::ComboBox(this, wxID_ANY, "", wxDefaultPosition, wxSize(FromDIP(250), -1), 0, nullptr, wxCB_READONLY);
m_comboBox_printer->Bind(wxEVT_COMBOBOX, &SelectMachineDialog::on_selection_changed, this);
m_sizer_printer->Add(m_comboBox_printer, 1, wxEXPAND | wxRIGHT, FromDIP(5));
m_btn_bg_enable = StateColor(std::pair<wxColour, int>(wxColour(0, 137, 123), StateColor::Pressed), std::pair<wxColour, int>(wxColour(38, 166, 154), StateColor::Hovered),
std::pair<wxColour, int>(wxColour(0, 150, 136), StateColor::Normal));
m_button_refresh = new Button(this, _L("Refresh"));
m_button_refresh->SetBackgroundColor(m_btn_bg_enable);
m_button_refresh->SetBorderColor(m_btn_bg_enable);
m_button_refresh->SetTextColor(StateColor::darkModeColorFor("#FFFFFE"));
m_button_refresh->SetSize(SELECT_MACHINE_DIALOG_BUTTON_SIZE);
m_button_refresh->SetMinSize(SELECT_MACHINE_DIALOG_BUTTON_SIZE);
m_button_refresh->SetCornerRadius(FromDIP(10));
m_button_refresh->Bind(wxEVT_BUTTON, &SelectMachineDialog::on_refresh, this);
m_sizer_printer->Add(m_button_refresh, 0, wxALL | wxLEFT, FromDIP(5));
m_statictext_printer_msg = new wxStaticText(this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxALIGN_CENTER_HORIZONTAL);
m_statictext_printer_msg->SetFont(::Label::Body_13);
m_statictext_printer_msg->Hide();
//m_sizer_select = new wxGridSizer(0, 2, 0, 0);
m_sizer_select = new wxWrapSizer();
select_bed = create_item_checkbox(_L("Bed Leveling"), this, _L("Bed Leveling"), "bed_leveling");
select_flow = create_item_checkbox(_L("Flow Dynamics Calibration"), this, _L("Flow Dynamics Calibration"), "flow_cali");
select_timelapse = create_item_checkbox(_L("Timelapse"), this, _L("Timelapse"), "timelapse");
select_use_ams = create_ams_checkbox(_L("Enable AMS"), this, _L("Enable AMS"));
m_sizer_select->Add(select_bed, 0, wxLEFT | wxRIGHT, WRAP_GAP);
m_sizer_select->Add(select_flow, 0, wxLEFT | wxRIGHT, WRAP_GAP);
m_sizer_select->Add(select_timelapse, 0, wxLEFT | wxRIGHT, WRAP_GAP);
m_sizer_select->Add(select_use_ams, 0, wxLEFT | wxRIGHT, WRAP_GAP);
select_bed->Show(false);
select_flow->Show(false);
select_timelapse->Show(false);
select_use_ams->Show(false);
m_sizer_select->Layout();
// line schedule
m_line_schedule = new wxPanel(this, wxID_ANY, wxDefaultPosition, wxSize(-1, 1));
m_line_schedule->SetBackgroundColour(wxColour(238, 238, 238));
m_simplebook = new wxSimplebook(this, wxID_ANY, wxDefaultPosition, SELECT_MACHINE_DIALOG_SIMBOOK_SIZE, 0);
// perpare mode
m_panel_prepare = new wxPanel(m_simplebook, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL);
m_panel_prepare->SetBackgroundColour(m_colour_def_color);
wxBoxSizer *m_sizer_prepare = new wxBoxSizer(wxVERTICAL);
wxBoxSizer *m_sizer_pcont = new wxBoxSizer(wxHORIZONTAL);
m_sizer_prepare->Add(0, 0, 1, wxTOP, FromDIP(12));
auto hyperlink_sizer = new wxBoxSizer( wxHORIZONTAL );
m_hyperlink = new wxHyperlinkCtrl(m_panel_prepare, wxID_ANY, _L("Click here if you can't connect to the printer"), wxT("https://wiki.bambulab.com/en/software/bambu-studio/failed-to-connect-printer"), wxDefaultPosition, wxDefaultSize, wxHL_DEFAULT_STYLE);
hyperlink_sizer->Add(m_hyperlink, 0, wxALIGN_CENTER | wxALL, 5);
m_sizer_prepare->Add(hyperlink_sizer, 0, wxALIGN_CENTER | wxALL, 5);
m_button_ensure = new Button(m_panel_prepare, _L("Send"));
m_button_ensure->SetBackgroundColor(m_btn_bg_enable);
m_button_ensure->SetBorderColor(m_btn_bg_enable);
m_button_ensure->SetTextColor(StateColor::darkModeColorFor("#FFFFFE"));
m_button_ensure->SetSize(SELECT_MACHINE_DIALOG_BUTTON_SIZE);
m_button_ensure->SetMinSize(SELECT_MACHINE_DIALOG_BUTTON_SIZE);
m_button_ensure->SetMinSize(SELECT_MACHINE_DIALOG_BUTTON_SIZE);
m_button_ensure->SetCornerRadius(FromDIP(12));
m_button_ensure->Bind(wxEVT_BUTTON, &SelectMachineDialog::on_ok_btn, this);
m_sizer_pcont->Add(0, 0, 1, wxEXPAND, 0);
m_sizer_pcont->Add(m_button_ensure, 0,wxRIGHT, 0);
m_sizer_prepare->Add(m_sizer_pcont, 0, wxEXPAND, 0);
m_panel_prepare->SetSizer(m_sizer_prepare);
m_panel_prepare->Layout();
m_simplebook->AddPage(m_panel_prepare, wxEmptyString, true);
// sending mode
m_status_bar = std::make_shared<BBLStatusBarSend>(m_simplebook);
m_panel_sending = m_status_bar->get_panel();
m_simplebook->AddPage(m_panel_sending, wxEmptyString, false);
m_worker = std::make_unique<PlaterWorker<BoostThreadWorker>>(this, m_status_bar, "send_worker");
// finish mode
m_panel_finish = new wxPanel(m_simplebook, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL);
m_panel_finish->SetBackgroundColour(wxColour(135, 206, 250));
wxBoxSizer *m_sizer_finish = new wxBoxSizer(wxHORIZONTAL);
wxBoxSizer *m_sizer_finish_v = new wxBoxSizer(wxVERTICAL);
wxBoxSizer *m_sizer_finish_h = new wxBoxSizer(wxHORIZONTAL);
auto imgsize = FromDIP(25);
auto completedimg = new wxStaticBitmap(m_panel_finish, wxID_ANY, create_scaled_bitmap("completed", m_panel_finish, 25), wxDefaultPosition, wxSize(imgsize, imgsize), 0);
m_sizer_finish_h->Add(completedimg, 0, wxALIGN_CENTER | wxALL, FromDIP(5));
m_statictext_finish = new wxStaticText(m_panel_finish, wxID_ANY, L("send completed"), wxDefaultPosition, wxDefaultSize, 0);
m_statictext_finish->Wrap(-1);
m_statictext_finish->SetForegroundColour(wxColour(0, 150, 136));
m_sizer_finish_h->Add(m_statictext_finish, 0, wxALIGN_CENTER | wxALL, FromDIP(5));
m_sizer_finish_v->Add(m_sizer_finish_h, 1, wxALIGN_CENTER, 0);
m_sizer_finish->Add(m_sizer_finish_v, 1, wxALIGN_CENTER, 0);
m_panel_finish->SetSizer(m_sizer_finish);
m_panel_finish->Layout();
m_sizer_finish->Fit(m_panel_finish);
m_simplebook->AddPage(m_panel_finish, wxEmptyString, false);
//show bind failed info
m_sw_print_failed_info = new wxScrolledWindow(this, wxID_ANY, wxDefaultPosition, wxSize(FromDIP(380), FromDIP(125)), wxVSCROLL);
m_sw_print_failed_info->SetBackgroundColour(*wxWHITE);
m_sw_print_failed_info->SetScrollRate(0, 5);
m_sw_print_failed_info->SetMinSize(wxSize(FromDIP(380), FromDIP(125)));
m_sw_print_failed_info->SetMaxSize(wxSize(FromDIP(380), FromDIP(125)));
wxBoxSizer* sizer_print_failed_info = new wxBoxSizer(wxVERTICAL);
m_sw_print_failed_info->SetSizer(sizer_print_failed_info);
wxBoxSizer* sizer_error_code = new wxBoxSizer(wxHORIZONTAL);
wxBoxSizer* sizer_error_desc = new wxBoxSizer(wxHORIZONTAL);
wxBoxSizer* sizer_extra_info = new wxBoxSizer(wxHORIZONTAL);
auto st_title_error_code = new wxStaticText(m_sw_print_failed_info, wxID_ANY, _L("Error code"));
auto st_title_error_code_doc = new wxStaticText(m_sw_print_failed_info, wxID_ANY,": ");
m_st_txt_error_code = new Label(m_sw_print_failed_info, wxEmptyString);
st_title_error_code->SetForegroundColour(0x909090);
st_title_error_code_doc->SetForegroundColour(0x909090);
m_st_txt_error_code->SetForegroundColour(0x909090);
st_title_error_code->SetFont(::Label::Body_13);
st_title_error_code_doc->SetFont(::Label::Body_13);
m_st_txt_error_code->SetFont(::Label::Body_13);
st_title_error_code->SetMinSize(wxSize(FromDIP(74), -1));
st_title_error_code->SetMaxSize(wxSize(FromDIP(74), -1));
m_st_txt_error_code->SetMinSize(wxSize(FromDIP(260), -1));
m_st_txt_error_code->SetMaxSize(wxSize(FromDIP(260), -1));
sizer_error_code->Add(st_title_error_code, 0, wxALL, 0);
sizer_error_code->Add(st_title_error_code_doc, 0, wxALL, 0);
sizer_error_code->Add(m_st_txt_error_code, 0, wxALL, 0);
auto st_title_error_desc = new wxStaticText(m_sw_print_failed_info, wxID_ANY, wxT("Error desc"));
auto st_title_error_desc_doc = new wxStaticText(m_sw_print_failed_info, wxID_ANY,": ");
m_st_txt_error_desc = new Label(m_sw_print_failed_info, wxEmptyString);
st_title_error_desc->SetForegroundColour(0x909090);
st_title_error_desc_doc->SetForegroundColour(0x909090);
m_st_txt_error_desc->SetForegroundColour(0x909090);
st_title_error_desc->SetFont(::Label::Body_13);
st_title_error_desc_doc->SetFont(::Label::Body_13);
m_st_txt_error_desc->SetFont(::Label::Body_13);
st_title_error_desc->SetMinSize(wxSize(FromDIP(74), -1));
st_title_error_desc->SetMaxSize(wxSize(FromDIP(74), -1));
m_st_txt_error_desc->SetMinSize(wxSize(FromDIP(260), -1));
m_st_txt_error_desc->SetMaxSize(wxSize(FromDIP(260), -1));
sizer_error_desc->Add(st_title_error_desc, 0, wxALL, 0);
sizer_error_desc->Add(st_title_error_desc_doc, 0, wxALL, 0);
sizer_error_desc->Add(m_st_txt_error_desc, 0, wxALL, 0);
auto st_title_extra_info = new wxStaticText(m_sw_print_failed_info, wxID_ANY, wxT("Extra info"));
auto st_title_extra_info_doc = new wxStaticText(m_sw_print_failed_info, wxID_ANY, ": ");
m_st_txt_extra_info = new Label(m_sw_print_failed_info, wxEmptyString);
st_title_extra_info->SetForegroundColour(0x909090);
st_title_extra_info_doc->SetForegroundColour(0x909090);
m_st_txt_extra_info->SetForegroundColour(0x909090);
st_title_extra_info->SetFont(::Label::Body_13);
st_title_extra_info_doc->SetFont(::Label::Body_13);
m_st_txt_extra_info->SetFont(::Label::Body_13);
st_title_extra_info->SetMinSize(wxSize(FromDIP(74), -1));
st_title_extra_info->SetMaxSize(wxSize(FromDIP(74), -1));
m_st_txt_extra_info->SetMinSize(wxSize(FromDIP(260), -1));
m_st_txt_extra_info->SetMaxSize(wxSize(FromDIP(260), -1));
sizer_extra_info->Add(st_title_extra_info, 0, wxALL, 0);
sizer_extra_info->Add(st_title_extra_info_doc, 0, wxALL, 0);
sizer_extra_info->Add(m_st_txt_extra_info, 0, wxALL, 0);
m_link_network_state = new wxHyperlinkCtrl(m_sw_print_failed_info, wxID_ANY,_L("Check the status of current system services"),"");
m_link_network_state->SetFont(::Label::Body_12);
m_link_network_state->Bind(wxEVT_LEFT_DOWN, [this](auto& e) {wxGetApp().link_to_network_check();});
m_link_network_state->Bind(wxEVT_ENTER_WINDOW, [this](auto& e) {m_link_network_state->SetCursor(wxCURSOR_HAND);});
m_link_network_state->Bind(wxEVT_LEAVE_WINDOW, [this](auto& e) {m_link_network_state->SetCursor(wxCURSOR_ARROW);});
sizer_print_failed_info->Add(m_link_network_state, 0, wxLEFT, 5);
sizer_print_failed_info->Add(sizer_error_code, 0, wxLEFT, 5);
sizer_print_failed_info->Add(0, 0, 0, wxTOP, FromDIP(3));
sizer_print_failed_info->Add(sizer_error_desc, 0, wxLEFT, 5);
sizer_print_failed_info->Add(0, 0, 0, wxTOP, FromDIP(3));
sizer_print_failed_info->Add(sizer_extra_info, 0, wxLEFT, 5);
m_sizer_scrollable_region->Add(m_rename_switch_panel, 0, wxALIGN_CENTER_HORIZONTAL, 0);
m_sizer_scrollable_region->Add(0, 0, 0, wxTOP, FromDIP(8));
m_sizer_scrollable_region->Add(m_sizer_thumbnail_area, 0, wxALIGN_CENTER_HORIZONTAL, 0);
m_sizer_scrollable_region->Add(0, 0, 0, wxTOP, FromDIP(10));
m_sizer_scrollable_region->Add(m_sizer_basic, 0, wxALIGN_CENTER_HORIZONTAL, 0);
//m_sizer_scrollable_region->Add(m_sizer_material, 0, wxALIGN_CENTER_HORIZONTAL, 0);
m_sizer_scrollable_region->Add(m_sizer_material_area, 0, wxLEFT, FromDIP(10));
m_scrollable_region->SetSizer(m_sizer_scrollable_region);
m_scrollable_region->Layout();
m_scrollable_view->SetSizer(m_sizer_scrollable_view);
m_scrollable_view->Layout();
m_sizer_scrollable_view->Add(m_scrollable_region, 0, wxEXPAND, 0);
m_sizer_main->Add(m_line_top, 0, wxEXPAND, 0);
m_sizer_main->Add(0, 0, 0, wxTOP, FromDIP(13));
m_sizer_main->Add(m_scrollable_view, 0, wxALIGN_CENTER_HORIZONTAL|wxLEFT|wxRIGHT, FromDIP(25));
m_sizer_main->Add(m_sizer_backup, 0, wxALIGN_CENTER_HORIZONTAL, 0);
m_sizer_main->Add(0, 0, 0, wxEXPAND | wxTOP, FromDIP(6));
m_sizer_main->Add(m_statictext_ams_msg, 0, wxALIGN_CENTER_HORIZONTAL, 0);
m_sizer_main->Add(0, 0, 0, wxEXPAND | wxTOP, FromDIP(6));
m_sizer_main->Add(m_line_materia, 0, wxEXPAND | wxLEFT | wxRIGHT, FromDIP(30));
m_sizer_main->Add(0, 0, 0, wxEXPAND | wxTOP, FromDIP(12));
m_sizer_main->Add(m_sizer_printer, 0, wxEXPAND | wxLEFT | wxRIGHT, FromDIP(30));
m_sizer_main->Add(0, 0, 0, wxEXPAND | wxTOP, FromDIP(11));
m_sizer_main->Add(m_statictext_printer_msg, 0, wxALIGN_CENTER_HORIZONTAL, 0);
m_sizer_main->Add(0, 1, 0, wxTOP, FromDIP(16));
m_sizer_main->Add(m_sizer_select, 0, wxALIGN_CENTER_HORIZONTAL | wxLEFT | wxRIGHT, FromDIP(30));
m_sizer_main->Add(0, 1, 0, wxTOP, FromDIP(10));
m_sizer_main->Add(m_line_schedule, 0, wxEXPAND | wxLEFT | wxRIGHT, FromDIP(30));
m_sizer_main->Add(m_simplebook, 0, wxALIGN_CENTER_HORIZONTAL, 0);
m_sizer_main->Add(m_sw_print_failed_info, 0, wxALIGN_CENTER, 0);
m_sizer_main->Add(0, 0, 0, wxEXPAND | wxTOP, FromDIP(18));
show_print_failed_info(false);
SetSizer(m_sizer_main);
Layout();
Fit();
Thaw();
init_bind();
init_timer();
Centre(wxBOTH);
wxGetApp().UpdateDlgDarkUI(this);
}
void SelectMachineDialog::init_bind()
{
Bind(wxEVT_TIMER, &SelectMachineDialog::on_timer, this);
Bind(EVT_CLEAR_IPADDRESS, &SelectMachineDialog::clear_ip_address_config, this);
Bind(EVT_SHOW_ERROR_INFO, [this](auto& e) {show_print_failed_info(true);});
Bind(EVT_UPDATE_USER_MACHINE_LIST, &SelectMachineDialog::update_printer_combobox, this);
Bind(EVT_PRINT_JOB_CANCEL, &SelectMachineDialog::on_print_job_cancel, this);
Bind(EVT_SET_FINISH_MAPPING, &SelectMachineDialog::on_set_finish_mapping, this);
Bind(wxEVT_LEFT_DOWN, [this](auto& e) {check_fcous_state(this);e.Skip();});
m_panel_prepare->Bind(wxEVT_LEFT_DOWN, [this](auto& e) {check_fcous_state(this);e.Skip();});
m_scrollable_region->Bind(wxEVT_LEFT_DOWN, [this](auto& e) {check_fcous_state(this);e.Skip();});
m_bitmap_last_plate->Bind(wxEVT_ENTER_WINDOW, [this](auto& e) {SetCursor(wxCURSOR_HAND); });
m_bitmap_last_plate->Bind(wxEVT_LEAVE_WINDOW, [this](auto& e) {SetCursor(wxCURSOR_ARROW); });
m_bitmap_next_plate->Bind(wxEVT_ENTER_WINDOW, [this](auto& e) {SetCursor(wxCURSOR_HAND); });
m_bitmap_next_plate->Bind(wxEVT_LEAVE_WINDOW, [this](auto& e) {SetCursor(wxCURSOR_ARROW); });
Bind(EVT_CONNECT_LAN_MODE_PRINT, [this](wxCommandEvent& e) {
if (e.GetInt() == 0) {
DeviceManager* dev = Slic3r::GUI::wxGetApp().getDeviceManager();
if (!dev) return;
MachineObject* obj = dev->get_selected_machine();
if (!obj) return;
if (obj->dev_id == e.GetString()) {
m_comboBox_printer->SetValue(obj->dev_name + "(LAN)");
}
}else if(e.GetInt() == 1 && (m_print_type == PrintFromType::FROM_SDCARD_VIEW)){
on_send_print();
}
else if (e.GetInt() == -2 && (m_print_type == PrintFromType::FROM_SDCARD_VIEW)) {
show_status(PrintDialogStatus::PrintStatusInit);
prepare_mode();
MessageDialog msg_wingow(nullptr, _L("Printer local connection failed, please try again."), "", wxAPPLY | wxOK);
msg_wingow.ShowModal();
}
else if (e.GetInt() == 5 && (m_print_type == PrintFromType::FROM_SDCARD_VIEW)) {
show_status(PrintDialogStatus::PrintStatusInit);
prepare_mode();
DeviceManager* dev = Slic3r::GUI::wxGetApp().getDeviceManager();
if (!dev) return;
ConnectPrinterDialog dlg(wxGetApp().mainframe, wxID_ANY, _L("Input access code"));
dlg.go_connect_printer(false);
if (dev->get_selected_machine()) {
dlg.set_machine_object(dev->get_selected_machine());
if (dlg.ShowModal() == wxID_OK) {
this->connect_printer_mqtt();
}
}
}
});
m_bitmap_last_plate->Bind(wxEVT_LEFT_DOWN, [this](auto& e) {
if (m_print_plate_idx > 0) {
m_print_plate_idx--;
update_page_turn_state(true);
set_default_from_sdcard();
}
});
m_bitmap_next_plate->Bind(wxEVT_LEFT_DOWN, [this](auto& e) {
if (m_print_plate_idx < (m_print_plate_total - 1)) {
m_print_plate_idx++;
update_page_turn_state(true);
set_default_from_sdcard();
}
});
}
void SelectMachineDialog::check_focus(wxWindow* window)
{
if (window == m_rename_input || window == m_rename_input->GetTextCtrl()) {
on_rename_enter();
}
}
void SelectMachineDialog::show_print_failed_info(bool show, int code, wxString description, wxString extra)
{
if (show) {
if (!m_sw_print_failed_info->IsShown()) {
m_sw_print_failed_info->Show(true);
m_st_txt_error_code->SetLabelText(wxString::Format("%d", m_print_error_code));
m_st_txt_error_desc->SetLabelText( wxGetApp().filter_string(m_print_error_msg));
m_st_txt_extra_info->SetLabelText( wxGetApp().filter_string(m_print_error_extra));
m_st_txt_error_code->Wrap(FromDIP(260));
m_st_txt_error_desc->Wrap(FromDIP(260));
m_st_txt_extra_info->Wrap(FromDIP(260));
}
else {
m_sw_print_failed_info->Show(false);
}
Layout();
Fit();
}
else {
if (!m_sw_print_failed_info->IsShown()) {return;}
m_sw_print_failed_info->Show(false);
m_st_txt_error_code->SetLabelText(wxEmptyString);
m_st_txt_error_desc->SetLabelText(wxEmptyString);
m_st_txt_extra_info->SetLabelText(wxEmptyString);
Layout();
Fit();
}
}
void SelectMachineDialog::check_fcous_state(wxWindow* window)
{
check_focus(window);
auto children = window->GetChildren();
for (auto child : children) {
check_fcous_state(child);
}
}
void SelectMachineDialog::popup_filament_backup()
{
DeviceManager* dev = Slic3r::GUI::wxGetApp().getDeviceManager();
if (!dev) return;
if (dev->get_selected_machine()/* && dev->get_selected_machine()->filam_bak.size() > 0*/) {
AmsReplaceMaterialDialog* m_replace_material_popup = new AmsReplaceMaterialDialog(this);
m_replace_material_popup->update_mapping_result(m_ams_mapping_result);
m_replace_material_popup->update_machine_obj(dev->get_selected_machine());
m_replace_material_popup->ShowModal();
}
}
wxWindow *SelectMachineDialog::create_ams_checkbox(wxString title, wxWindow *parent, wxString tooltip)
{
auto checkbox = new wxWindow(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL);
checkbox->SetBackgroundColour(m_colour_def_color);
wxBoxSizer *sizer_checkbox = new wxBoxSizer(wxHORIZONTAL);
wxBoxSizer *sizer_check = new wxBoxSizer(wxVERTICAL);
auto check = new ::CheckBox(checkbox);
sizer_check->Add(check, 0, wxBOTTOM | wxEXPAND | wxTOP, FromDIP(5));
sizer_checkbox->Add(sizer_check, 0, wxEXPAND, FromDIP(5));
sizer_checkbox->Add(0, 0, 0, wxEXPAND | wxLEFT, FromDIP(11));
auto text = new wxStaticText(checkbox, wxID_ANY, title, wxDefaultPosition, wxDefaultSize, 0);
text->SetFont(::Label::Body_13);
text->SetForegroundColour(StateColor::darkModeColorFor(wxColour("#323A3C")));
text->Wrap(-1);
sizer_checkbox->Add(text, 0, wxALIGN_CENTER, 0);
enable_ams = new ScalableBitmap(this, "enable_ams", 16);
img_use_ams_tip = new wxStaticBitmap(checkbox, wxID_ANY, enable_ams->bmp(), wxDefaultPosition, wxSize(FromDIP(16), FromDIP(16)), 0);
sizer_checkbox->Add(img_use_ams_tip, 0, wxALIGN_CENTER | wxLEFT, FromDIP(5));
img_use_ams_tip->Bind(wxEVT_ENTER_WINDOW, [this](auto& e) {
wxPoint img_pos = img_use_ams_tip->ClientToScreen(wxPoint(0, 0));
wxPoint popup_pos(img_pos.x, img_pos.y + img_use_ams_tip->GetRect().height);
m_mapping_tip_popup.Position(popup_pos, wxSize(0, 0));
m_mapping_tip_popup.Popup();
if (m_mapping_tip_popup.ClientToScreen(wxPoint(0, 0)).y < img_pos.y) {
m_mapping_tip_popup.Dismiss();
popup_pos = wxPoint(img_pos.x, img_pos.y - m_mapping_tip_popup.GetRect().height);
m_mapping_tip_popup.Position(popup_pos, wxSize(0, 0));
m_mapping_tip_popup.Popup();
}
});
img_use_ams_tip->Bind(wxEVT_LEAVE_WINDOW, [this](wxMouseEvent& e) {
m_mapping_tip_popup.Dismiss();
});
checkbox->SetSizer(sizer_checkbox);
checkbox->Layout();
sizer_checkbox->Fit(checkbox);
checkbox->SetToolTip(tooltip);
text->SetToolTip(tooltip);
text->Bind(wxEVT_LEFT_DOWN, [this, check](wxMouseEvent& event) {
check->SetValue(check->GetValue() ? false : true);
});
checkbox->Bind(wxEVT_LEFT_DOWN, [this, check](wxMouseEvent& event) {
check->SetValue(check->GetValue() ? false : true);
});
m_checkbox_list["use_ams"] = check;
return checkbox;
}
wxWindow *SelectMachineDialog::create_item_checkbox(wxString title, wxWindow *parent, wxString tooltip, std::string param)
{
auto checkbox = new wxWindow(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL);
checkbox->SetBackgroundColour(m_colour_def_color);
wxBoxSizer *sizer_checkbox = new wxBoxSizer(wxHORIZONTAL);
wxBoxSizer *sizer_check = new wxBoxSizer(wxVERTICAL);
auto check = new ::CheckBox(checkbox);
sizer_check->Add(check, 0, wxBOTTOM | wxEXPAND | wxTOP, FromDIP(5));
auto text = new wxStaticText(checkbox, wxID_ANY, title, wxDefaultPosition, wxDefaultSize, wxST_ELLIPSIZE_END);
text->SetFont(::Label::Body_12);
text->SetForegroundColour(StateColor::darkModeColorFor(wxColour("#323A3C")));
text->Wrap(-1);
text->SetMinSize(wxSize(FromDIP(140), -1));
text->SetMaxSize(wxSize(FromDIP(140), -1));
sizer_checkbox->Add(sizer_check, 0, wxEXPAND, FromDIP(5));
sizer_checkbox->Add(0, 0, 0, wxEXPAND | wxLEFT, FromDIP(7));
sizer_checkbox->Add(text, 0, wxALIGN_CENTER, 0);
checkbox->SetSizer(sizer_checkbox);
checkbox->Layout();
sizer_checkbox->Fit(checkbox);
check->SetToolTip(tooltip);
text->SetToolTip(tooltip);
check->Bind(wxEVT_LEFT_DOWN, [this, check, param](wxMouseEvent &e) {
//if (!m_checkbox_state_list[param]) {return;}
AppConfig* config = wxGetApp().app_config;
if (config) {
if (check->GetValue())
config->set_str("print", param, "0");
else
config->set_str("print", param, "1");
}
e.Skip();
});
checkbox->Bind(wxEVT_LEFT_DOWN, [this, check, param](wxMouseEvent&) {
//if (!m_checkbox_state_list[param]) {return;}
check->SetValue(check->GetValue() ? false : true);
AppConfig* config = wxGetApp().app_config;
if (config) {
if (check->GetValue())
config->set_str("print", param, "1");
else
config->set_str("print", param, "0");
}
});
text->Bind(wxEVT_LEFT_DOWN, [this, check, param](wxMouseEvent &) {
//if (!m_checkbox_state_list[param]) {return;}
check->SetValue(check->GetValue() ? false : true);
AppConfig* config = wxGetApp().app_config;
if (config) {
if (check->GetValue())
config->set_str("print", param, "1");
else
config->set_str("print", param, "0");
}
});
//m_checkbox_state_list[param] = true;
m_checkbox_list[param] = check;
return checkbox;
}
void SelectMachineDialog::update_select_layout(MachineObject *obj)
{
if (obj && obj->is_support_flow_calibration) {
select_flow->Show();
} else {
select_flow->Hide();
}
if (obj && obj->is_support_auto_leveling) {
select_bed->Show();
} else {
select_bed->Hide();
}
if (obj && obj->is_support_timelapse && is_show_timelapse()) {
select_timelapse->Show();
update_timelapse_enable_status();
} else {
select_timelapse->Hide();
}
m_sizer_select->Layout();
Layout();
Fit();
}
void SelectMachineDialog::prepare_mode(bool refresh_button)
{
// disable combobox
m_comboBox_printer->Enable();
Enable_Auto_Refill(true);
show_print_failed_info(false);
m_is_in_sending_mode = false;
m_worker->wait_for_idle();
if (wxIsBusy())
wxEndBusyCursor();
if (refresh_button) {
Enable_Send_Button(true);
}
m_status_bar->reset();
if (m_simplebook->GetSelection() != 0) {
m_simplebook->SetSelection(0);
Layout();
Fit();
}
if (m_print_page_mode != PrintPageModePrepare) {
m_print_page_mode = PrintPageModePrepare;
for (auto it = m_materialList.begin(); it != m_materialList.end(); it++) {
it->second->item->enable();
}
}
}
void SelectMachineDialog::sending_mode()
{
// disable combobox
m_comboBox_printer->Disable();
Enable_Auto_Refill(false);
m_is_in_sending_mode = true;
if (m_simplebook->GetSelection() != 1){
m_simplebook->SetSelection(1);
Layout();
Fit();
}
if (m_print_page_mode != PrintPageModeSending) {
m_print_page_mode = PrintPageModeSending;
for (auto it = m_materialList.begin(); it != m_materialList.end(); it++) {
it->second->item->disable();
}
}
}
void SelectMachineDialog::finish_mode()
{
m_print_page_mode = PrintPageModeFinish;
m_is_in_sending_mode = false;
m_simplebook->SetSelection(2);
Layout();
Fit();
}
void SelectMachineDialog::sync_ams_mapping_result(std::vector<FilamentInfo> &result)
{
if (result.empty()) {
BOOST_LOG_TRIVIAL(trace) << "ams_mapping result is empty";
for (auto it = m_materialList.begin(); it != m_materialList.end(); it++) {
wxString ams_id = "-";
wxColour ams_col = wxColour(0xCE, 0xCE, 0xCE);
it->second->item->set_ams_info(ams_col, ams_id);
}
return;
}
for (auto f = result.begin(); f != result.end(); f++) {
BOOST_LOG_TRIVIAL(trace) << "ams_mapping f id = " << f->id << ", tray_id = " << f->tray_id << ", color = " << f->color << ", type = " << f->type;
MaterialHash::iterator iter = m_materialList.begin();
while (iter != m_materialList.end()) {
int id = iter->second->id;
Material * item = iter->second;
MaterialItem *m = item->item;
if (f->id == id) {
wxString ams_id;
wxColour ams_col;
if (f->tray_id >= 0) {
ams_id = wxGetApp().transition_tridid(f->tray_id);
//ams_id = wxString::Format("%02d", f->tray_id + 1);
} else {
ams_id = "-";
}
if (!f->color.empty()) {
ams_col = AmsTray::decode_color(f->color);
} else {
// default color
ams_col = wxColour(0xCE, 0xCE, 0xCE);
}
m->set_ams_info(ams_col, ams_id);
break;
}
iter++;
}
}
}
void print_ams_mapping_result(std::vector<FilamentInfo>& result)
{
if (result.empty()) {
BOOST_LOG_TRIVIAL(info) << "print_ams_mapping_result: empty";
}
char buffer[256];
for (int i = 0; i < result.size(); i++) {
::sprintf(buffer, "print_ams_mapping: F(%02d) -> A(%02d)", result[i].id+1, result[i].tray_id+1);
BOOST_LOG_TRIVIAL(info) << std::string(buffer);
}
}
bool SelectMachineDialog::do_ams_mapping(MachineObject *obj_)
{
if (!obj_) return false;
// try color and type mapping
int result = obj_->ams_filament_mapping(m_filaments, m_ams_mapping_result);
if (result == 0) {
print_ams_mapping_result(m_ams_mapping_result);
std::string ams_array;
std::string mapping_info;
get_ams_mapping_result(ams_array, mapping_info);
if (ams_array.empty()) {
reset_ams_material();
BOOST_LOG_TRIVIAL(info) << "ams_mapping_array=[]";
} else {
sync_ams_mapping_result(m_ams_mapping_result);
BOOST_LOG_TRIVIAL(info) << "ams_mapping_array=" << ams_array;
}
return obj_->is_valid_mapping_result(m_ams_mapping_result);
} else {
// do not support ams mapping try to use order mapping
bool is_valid = obj_->is_valid_mapping_result(m_ams_mapping_result);
if (result != 1 && !is_valid) {
//reset invalid result
for (int i = 0; i < m_ams_mapping_result.size(); i++) {
m_ams_mapping_result[i].tray_id = -1;
m_ams_mapping_result[i].distance = 99999;
}
}
sync_ams_mapping_result(m_ams_mapping_result);
return is_valid;
}
return true;
}
bool SelectMachineDialog::get_ams_mapping_result(std::string &mapping_array_str, std::string &ams_mapping_info)
{
if (m_ams_mapping_result.empty())
return false;
bool valid_mapping_result = true;
int invalid_count = 0;
for (int i = 0; i < m_ams_mapping_result.size(); i++) {
if (m_ams_mapping_result[i].tray_id == -1) {
valid_mapping_result = false;
invalid_count++;
}
}
if (invalid_count == m_ams_mapping_result.size()) {
return false;
} else {
json j = json::array();
json mapping_info_json = json::array();
for (int i = 0; i < wxGetApp().preset_bundle->filament_presets.size(); i++) {
int tray_id = -1;
json mapping_item;
mapping_item["ams"] = tray_id;
mapping_item["targetColor"] = "";
mapping_item["filamentId"] = "";
mapping_item["filamentType"] = "";
for (int k = 0; k < m_ams_mapping_result.size(); k++) {
if (m_ams_mapping_result[k].id == i) {
tray_id = m_ams_mapping_result[k].tray_id;
mapping_item["ams"] = tray_id;
mapping_item["filamentType"] = m_filaments[k].type;
auto it = wxGetApp().preset_bundle->filaments.find_preset(wxGetApp().preset_bundle->filament_presets[i]);
if (it != nullptr) {
mapping_item["filamentId"] = it->filament_id;
}
//convert #RRGGBB to RRGGBBAA
mapping_item["sourceColor"] = m_filaments[k].color;
mapping_item["targetColor"] = m_ams_mapping_result[k].color;
}
}
j.push_back(tray_id);
mapping_info_json.push_back(mapping_item);
}
mapping_array_str = j.dump();
ams_mapping_info = mapping_info_json.dump();
return valid_mapping_result;
}
return true;
}
void SelectMachineDialog::prepare(int print_plate_idx)
{
m_print_plate_idx = print_plate_idx;
}
void SelectMachineDialog::update_ams_status_msg(wxString msg, bool is_warning)
{
auto colour = is_warning ? wxColour(0xFF, 0x6F, 0x00):wxColour(0x6B, 0x6B, 0x6B);
m_statictext_ams_msg->SetForegroundColour(colour);
if (msg.empty()) {
if (!m_statictext_ams_msg->GetLabel().empty()) {
m_statictext_ams_msg->SetLabel(wxEmptyString);
m_statictext_ams_msg->Hide();
Layout();
Fit();
}
} else {
msg = format_text(msg);
auto str_new = msg.utf8_string();
stripWhiteSpace(str_new);
auto str_old = m_statictext_ams_msg->GetLabel().utf8_string();
stripWhiteSpace(str_old);
if (str_new != str_old) {
if (m_statictext_ams_msg->GetLabel() != msg) {
m_statictext_ams_msg->SetLabel(msg);
m_statictext_ams_msg->SetMinSize(wxSize(FromDIP(400), -1));
m_statictext_ams_msg->SetMaxSize(wxSize(FromDIP(400), -1));
m_statictext_ams_msg->Wrap(FromDIP(400));
m_statictext_ams_msg->Show();
Layout();
Fit();
}
}
}
}
void SelectMachineDialog::update_priner_status_msg(wxString msg, bool is_warning)
{
auto colour = is_warning ? wxColour(0xFF, 0x6F, 0x00) : wxColour(0x6B, 0x6B, 0x6B);
m_statictext_printer_msg->SetForegroundColour(colour);
if (msg.empty()) {
if (!m_statictext_printer_msg->GetLabel().empty()) {
m_statictext_printer_msg->SetLabel(wxEmptyString);
m_statictext_printer_msg->Hide();
Layout();
Fit();
}
} else {
msg = format_text(msg);
auto str_new = msg.utf8_string();
stripWhiteSpace(str_new);
auto str_old = m_statictext_printer_msg->GetLabel().utf8_string();
stripWhiteSpace(str_old);
if (str_new != str_old) {
if (m_statictext_printer_msg->GetLabel() != msg) {
m_statictext_printer_msg->SetLabel(msg);
m_statictext_printer_msg->SetMinSize(wxSize(FromDIP(400), -1));
m_statictext_printer_msg->SetMaxSize(wxSize(FromDIP(400), -1));
m_statictext_printer_msg->Wrap(FromDIP(400));
m_statictext_printer_msg->Show();
Layout();
Fit();
}
}
}
}
void SelectMachineDialog::update_print_status_msg(wxString msg, bool is_warning, bool is_printer_msg)
{
if (is_printer_msg) {
update_ams_status_msg(wxEmptyString, false);
update_priner_status_msg(msg, is_warning);
} else {
update_ams_status_msg(msg, is_warning);
update_priner_status_msg(wxEmptyString, false);
}
}
void SelectMachineDialog::update_print_error_info(int code, std::string msg, std::string extra)
{
m_print_error_code = code;
m_print_error_msg = msg;
m_print_error_extra = extra;
}
bool SelectMachineDialog::has_tips(MachineObject* obj)
{
if (!obj) return false;
// must set to a status if return true
if (select_timelapse->IsShown() &&
m_checkbox_list["timelapse"]->GetValue()) {
if (obj->get_sdcard_state() == MachineObject::SdcardState::NO_SDCARD) {
show_status(PrintDialogStatus::PrintStatusTimelapseNoSdcard);
return true;
}
}
return false;
}
void SelectMachineDialog::show_status(PrintDialogStatus status, std::vector<wxString> params)
{
if (m_print_status != status)
BOOST_LOG_TRIVIAL(info) << "select_machine_dialog: show_status = " << status << "(" << get_print_status_info(status) << ")";
m_print_status = status;
// m_comboBox_printer
if (status == PrintDialogStatus::PrintStatusRefreshingMachineList)
m_comboBox_printer->Disable();
else
m_comboBox_printer->Enable();
// other
if (status == PrintDialogStatus::PrintStatusInit) {
update_print_status_msg(wxEmptyString, false, false);
Enable_Send_Button(false);
Enable_Refresh_Button(true);
} else if (status == PrintDialogStatus::PrintStatusNoUserLogin) {
wxString msg_text = _L("No login account, only printers in LAN mode are displayed");
update_print_status_msg(msg_text, false, true);
Enable_Send_Button(false);
Enable_Refresh_Button(true);
}else if (status == PrintDialogStatus::PrintStatusInvalidPrinter) {
update_print_status_msg(wxEmptyString, true, true);
Enable_Send_Button(false);
Enable_Refresh_Button(true);
} else if (status == PrintDialogStatus::PrintStatusConnectingServer) {
wxString msg_text = _L("Connecting to server");
update_print_status_msg(msg_text, true, true);
Enable_Send_Button(false);
Enable_Refresh_Button(true);
} else if (status == PrintDialogStatus::PrintStatusReading) {
wxString msg_text = _L("Synchronizing device information");
update_print_status_msg(msg_text, false, true);
Enable_Send_Button(false);
Enable_Refresh_Button(true);
} else if (status == PrintDialogStatus::PrintStatusReadingFinished) {
update_print_status_msg(wxEmptyString, false, true);
Enable_Send_Button(true);
Enable_Refresh_Button(true);
} else if (status == PrintDialogStatus::PrintStatusReadingTimeout) {
wxString msg_text = _L("Synchronizing device information time out");
update_print_status_msg(msg_text, true, true);
Enable_Send_Button(true);
Enable_Refresh_Button(true);
} else if (status == PrintDialogStatus::PrintStatusInUpgrading) {
wxString msg_text = _L("Cannot send the print job when the printer is updating firmware");
update_print_status_msg(msg_text, true, true);
Enable_Send_Button(false);
Enable_Refresh_Button(true);
} else if (status == PrintDialogStatus::PrintStatusInSystemPrinting) {
wxString msg_text = _L("The printer is executing instructions. Please restart printing after it ends");
update_print_status_msg(msg_text, true, true);
Enable_Send_Button(false);
Enable_Refresh_Button(true);
} else if (status == PrintDialogStatus::PrintStatusInPrinting) {
wxString msg_text = _L("The printer is busy on other print job");
update_print_status_msg(msg_text, true, true);
Enable_Send_Button(false);
Enable_Refresh_Button(true);
} else if (status == PrintDialogStatus::PrintStatusDisableAms) {
update_print_status_msg(wxEmptyString, false, false);
Enable_Send_Button(true);
Enable_Refresh_Button(true);
} else if (status == PrintDialogStatus::PrintStatusNeedUpgradingAms) {
wxString msg_text;
if (params.size() > 0)
msg_text = wxString::Format(_L("Filament %s exceeds the number of AMS slots. Please update the printer firmware to support AMS slot assignment."), params[0]);
else
msg_text = _L("Filament exceeds the number of AMS slots. Please update the printer firmware to support AMS slot assignment.");
update_print_status_msg(msg_text, true, false);
Enable_Send_Button(false);
Enable_Refresh_Button(true);
} else if (status == PrintDialogStatus::PrintStatusAmsMappingSuccess){
wxString msg_text = _L("Filaments to AMS slots mappings have been established. You can click a filament above to change its mapping AMS slot");
update_print_status_msg(msg_text, false, false);
Enable_Send_Button(true);
Enable_Refresh_Button(true);
} else if (status == PrintDialogStatus::PrintStatusAmsMappingInvalid) {
wxString msg_text = _L("Please click each filament above to specify its mapping AMS slot before sending the print job");
update_print_status_msg(msg_text, true, false);
Enable_Send_Button(false);
Enable_Refresh_Button(true);
} else if (status == PrintDialogStatus::PrintStatusAmsMappingU0Invalid) {
wxString msg_text;
if (params.size() > 1)
msg_text = wxString::Format(_L("Filament %s does not match the filament in AMS slot %s. Please update the printer firmware to support AMS slot assignment."), params[0], params[1]);
else
msg_text = _L("Filament does not match the filament in AMS slot. Please update the printer firmware to support AMS slot assignment.");
update_print_status_msg(msg_text, true, false);
Enable_Send_Button(false);
Enable_Refresh_Button(true);
} else if (status == PrintDialogStatus::PrintStatusAmsMappingValid) {
wxString msg_text = _L("Filaments to AMS slots mappings have been established. You can click a filament above to change its mapping AMS slot");
update_print_status_msg(msg_text, false, false);
Enable_Send_Button(true);
Enable_Refresh_Button(true);
} else if (status == PrintDialogStatus::PrintStatusRefreshingMachineList) {
update_print_status_msg(wxEmptyString, false, true);
Enable_Send_Button(false);
Enable_Refresh_Button(false);
} else if (status == PrintDialogStatus::PrintStatusSending) {
Enable_Send_Button(false);
Enable_Refresh_Button(false);
} else if (status == PrintDialogStatus::PrintStatusSendingCanceled) {
Enable_Send_Button(true);
Enable_Refresh_Button(true);
} else if (status == PrintDialogStatus::PrintStatusLanModeNoSdcard) {
wxString msg_text = _L("An SD card needs to be inserted before printing via LAN.");
update_print_status_msg(msg_text, true, true);
Enable_Send_Button(true);
Enable_Refresh_Button(true);
} else if (status == PrintDialogStatus::PrintStatusAmsMappingByOrder) {
wxString msg_text = _L("The printer firmware only supports sequential mapping of filament => AMS slot.");
update_print_status_msg(msg_text, false, false);
Enable_Send_Button(true);
Enable_Refresh_Button(true);
} else if (status == PrintDialogStatus::PrintStatusNoSdcard) {
wxString msg_text = _L("An SD card needs to be inserted before printing.");
update_print_status_msg(msg_text, true, true);
Enable_Send_Button(false);
Enable_Refresh_Button(true);
} else if (status == PrintDialogStatus::PrintStatusUnsupportedPrinter) {
wxString msg_text = _L("The selected printer is incompatible with the chosen printer presets.");
update_print_status_msg(msg_text, true, true);
Enable_Send_Button(false);
Enable_Refresh_Button(true);
}else if (status == PrintDialogStatus::PrintStatusTimelapseNoSdcard) {
wxString msg_text = _L("An SD card needs to be inserted to record timelapse.");
update_print_status_msg(msg_text, true, true);
Enable_Send_Button(true);
Enable_Refresh_Button(true);
} else if (status == PrintDialogStatus::PrintStatusNeedForceUpgrading) {
wxString msg_text = _L("Cannot send the print job to a printer whose firmware is required to get updated.");
update_print_status_msg(msg_text, true, true);
Enable_Send_Button(false);
Enable_Refresh_Button(true);
} else if (status == PrintDialogStatus::PrintStatusNeedConsistencyUpgrading) {
wxString msg_text = _L("Cannot send the print job to a printer whose firmware is required to get updated.");
update_print_status_msg(msg_text, true, true);
Enable_Send_Button(false);
Enable_Refresh_Button(true);
} else if (status == PrintDialogStatus::PrintStatusBlankPlate) {
wxString msg_text = _L("Cannot send the print job for empty plate");
update_print_status_msg(msg_text, true, true);
Enable_Send_Button(false);
Enable_Refresh_Button(true);
} else if (status == PrintDialogStatus::PrintStatusNotSupportedPrintAll) {
wxString msg_text = _L("This printer does not support printing all plates");
update_print_status_msg(msg_text, true, true);
Enable_Send_Button(false);
Enable_Refresh_Button(true);
} else if (status == PrintDialogStatus::PrintStatusTimelapseWarning) {
wxString msg_text;
PartPlate *plate = m_plater->get_partplate_list().get_curr_plate();
for (auto warning : plate->get_slice_result()->warnings) {
if (warning.msg == NOT_GENERATE_TIMELAPSE) {
if (warning.error_code == "1001C001") {
msg_text = _L("When enable spiral vase mode, machines with I3 structure will not generate timelapse videos.");
}
else if (warning.error_code == "1001C002") {
msg_text = _L("Timelapse is not supported because Print sequence is set to \"By object\".");
}
}
}
update_print_status_msg(msg_text, true, true);
Enable_Send_Button(true);
Enable_Refresh_Button(true);
}
// m_panel_warn m_simplebook
if (status == PrintDialogStatus::PrintStatusSending) {
sending_mode();
}
else {
prepare_mode(false);
}
}
void SelectMachineDialog::init_timer()
{
m_refresh_timer = new wxTimer();
m_refresh_timer->SetOwner(this);
}
void SelectMachineDialog::on_cancel(wxCloseEvent &event)
{
if (m_mapping_popup.IsShown())
m_mapping_popup.Dismiss();
m_worker->cancel_all();
this->EndModal(wxID_CANCEL);
}
bool SelectMachineDialog::is_blocking_printing(MachineObject* obj_)
{
DeviceManager* dev = Slic3r::GUI::wxGetApp().getDeviceManager();
if (!dev) return true;
PresetBundle* preset_bundle = wxGetApp().preset_bundle;
auto source_model = preset_bundle->printers.get_edited_preset().get_printer_type(preset_bundle);
auto target_model = obj_->printer_type;
if (source_model != target_model) {
std::vector<std::string> compatible_machine = dev->get_compatible_machine(target_model);
vector<std::string>::iterator it = find(compatible_machine.begin(), compatible_machine.end(), source_model);
if (it == compatible_machine.end()) {
return true;
}
}
return false;
}
bool SelectMachineDialog::is_same_nozzle_diameters(std::string& tag_nozzle_type, std::string& nozzle_diameter)
{
bool is_same_nozzle_diameters = true;
float preset_nozzle_diameters;
std::string preset_nozzle_type;
DeviceManager* dev = Slic3r::GUI::wxGetApp().getDeviceManager();
if (!dev) return true;
MachineObject* obj_ = dev->get_selected_machine();
if (obj_ == nullptr) return true;
try
{
PresetBundle* preset_bundle = wxGetApp().preset_bundle;
auto opt_nozzle_diameters = preset_bundle->printers.get_edited_preset().config.option<ConfigOptionFloats>("nozzle_diameter");
const ConfigOptionEnum<NozzleType>* nozzle_type = preset_bundle->printers.get_edited_preset().config.option<ConfigOptionEnum<NozzleType>>("nozzle_type");
if (nozzle_type->value == NozzleType::ntHardenedSteel) {
preset_nozzle_type = "hardened_steel";
}
else if (nozzle_type->value == NozzleType::ntStainlessSteel) {
preset_nozzle_type = "stainless_steel";
}
tag_nozzle_type = obj_->nozzle_type;
auto extruders = wxGetApp().plater()->get_partplate_list().get_curr_plate()->get_used_extruders();
if (opt_nozzle_diameters != nullptr) {
for (auto i = 0; i < extruders.size(); i++) {
auto extruder = extruders[i] - 1;
preset_nozzle_diameters = float(opt_nozzle_diameters->get_at(extruder));
if (preset_nozzle_diameters != obj_->nozzle_diameter) {
is_same_nozzle_diameters = false;
}
}
}
}
catch (...)
{
}
//nozzle_type = preset_nozzle_type;
nozzle_diameter = wxString::Format("%.1f", preset_nozzle_diameters).ToStdString();
return is_same_nozzle_diameters;
}
bool SelectMachineDialog::is_same_nozzle_type(std::string& filament_type, std::string& tag_nozzle_type)
{
bool is_same_nozzle_type = true;
DeviceManager* dev = Slic3r::GUI::wxGetApp().getDeviceManager();
if (!dev) return true;
MachineObject* obj_ = dev->get_selected_machine();
if (obj_ == nullptr) return true;
NozzleType nozzle_type = NozzleType::ntUndefine;
if (obj_->nozzle_type == "stainless_steel") {
nozzle_type = NozzleType::ntStainlessSteel;
}
else if (obj_->nozzle_type == "hardened_steel") {
nozzle_type = NozzleType::ntHardenedSteel;
}
auto printer_nozzle_hrc = Print::get_hrc_by_nozzle_type(nozzle_type);
auto preset_bundle = wxGetApp().preset_bundle;
MaterialHash::iterator iter = m_materialList.begin();
while (iter != m_materialList.end()) {
Material* item = iter->second;
MaterialItem* m = item->item;
auto filament_nozzle_hrc = preset_bundle->get_required_hrc_by_filament_type(m->m_material_name.ToStdString());
if (abs(filament_nozzle_hrc) > abs(printer_nozzle_hrc)) {
filament_type = m->m_material_name.ToStdString();
BOOST_LOG_TRIVIAL(info) << "filaments hardness mismatch: filament = " << filament_type << " printer_nozzle_hrc = " << printer_nozzle_hrc;
is_same_nozzle_type = false;
tag_nozzle_type = "hardened_steel";
return is_same_nozzle_type;
}
else {
tag_nozzle_type = obj_->nozzle_type;
}
iter++;
}
return is_same_nozzle_type;
}
bool SelectMachineDialog::is_same_printer_model()
{
bool result = true;
DeviceManager* dev = Slic3r::GUI::wxGetApp().getDeviceManager();
if (!dev) return result;
MachineObject* obj_ = dev->get_selected_machine();
assert(obj_->dev_id == m_printer_last_select);
if (obj_ == nullptr) {
return result;
}
PresetBundle* preset_bundle = wxGetApp().preset_bundle;
if(preset_bundle == nullptr) return result;
const auto source_model = preset_bundle->printers.get_edited_preset().get_printer_type(preset_bundle);
const auto target_model = obj_->printer_type;
// Orca: ignore P1P -> P1S
if (source_model != target_model && !(preset_bundle->printers.get_edited_preset().get_printer_type(preset_bundle) == "C12") && !(target_model == "C11" && source_model == "C12")) {
BOOST_LOG_TRIVIAL(info) << "printer_model: source = " << source_model;
BOOST_LOG_TRIVIAL(info) << "printer_model: target = " << target_model;
return false;
}
if (obj_->is_support_p1s_plus) {
BOOST_LOG_TRIVIAL(info) << "printer_model: source = " << preset_bundle->printers.get_edited_preset().get_printer_type(preset_bundle);
BOOST_LOG_TRIVIAL(info) << "printer_model: target = " << obj_->printer_type << " (plus)";
return false;
}
return true;
}
void SelectMachineDialog::show_errors(wxString &info)
{
ConfirmBeforeSendDialog confirm_dlg(this, wxID_ANY, _L("Errors"));
confirm_dlg.update_text(info);
confirm_dlg.on_show();
}
void SelectMachineDialog::on_ok_btn(wxCommandEvent &event)
{
bool has_slice_warnings = false;
bool has_update_nozzle = false;
DeviceManager* dev = Slic3r::GUI::wxGetApp().getDeviceManager();
if (!dev) return;
MachineObject* obj_ = dev->get_selected_machine();
if (!obj_) return;
std::vector<wxString> confirm_text;
confirm_text.push_back(_L("Please check the following:") + "\n\n");
//Check Printer Model Id
bool is_same_printer_type = is_same_printer_model();
if (!is_same_printer_type && (m_print_type == PrintFromType::FROM_NORMAL)) {
confirm_text.push_back(_L("The printer type selected when generating G-Code is not consistent with the currently selected printer. It is recommended that you use the same printer type for slicing.") + "\n");
has_slice_warnings = true;
}
//check blacklist
for (auto i = 0; i < m_ams_mapping_result.size(); i++) {
auto tid = m_ams_mapping_result[i].tray_id;
std::string filament_type = boost::to_upper_copy(m_ams_mapping_result[i].type);
std::string filament_brand;
for (auto fs : m_filaments) {
if (fs.id == m_ams_mapping_result[i].id) {
filament_brand = m_filaments[i].brand;
}
}
bool in_blacklist = false;
std::string action;
std::string info;
DeviceManager::check_filaments_in_blacklist(filament_brand, filament_type, in_blacklist, action, info);
if (in_blacklist && action == "warning") {
wxString prohibited_error = wxString::FromUTF8(info);
confirm_text.push_back(prohibited_error + "\n");
has_slice_warnings = true;
}
}
PartPlate* plate = m_plater->get_partplate_list().get_curr_plate();
for (auto warning : plate->get_slice_result()->warnings) {
if (warning.msg == BED_TEMP_TOO_HIGH_THAN_FILAMENT) {
if ((obj_->get_printer_is_enclosed())){
// confirm_text.push_back(Plater::get_slice_warning_string(warning) + "\n");
// has_slice_warnings = true;
}
}
else if (warning.msg == NOT_SUPPORT_TRADITIONAL_TIMELAPSE) {
if (obj_->get_printer_arch() == PrinterArch::ARCH_I3 && m_checkbox_list["timelapse"]->GetValue()) {
confirm_text.push_back(Plater::get_slice_warning_string(warning) + "\n");
has_slice_warnings = true;
}
}
else if (warning.msg == NOT_GENERATE_TIMELAPSE) {
continue;
}
else {
wxString error_info = Plater::get_slice_warning_string(warning);
if (error_info.IsEmpty()) {
error_info = wxString::Format("%s\n", warning.msg);
confirm_text.push_back(error_info + "\n");
} else
confirm_text.push_back(error_info + "\n");
has_slice_warnings = true;
}
}
//check for unidentified material
auto mapping_result = m_mapping_popup.parse_ams_mapping(obj_->amsList);
auto has_unknown_filament = false;
// check if ams mapping is has errors, tpu
bool has_prohibited_filament = false;
wxString prohibited_error = wxEmptyString;
for (auto i = 0; i < m_ams_mapping_result.size(); i++) {
auto tid = m_ams_mapping_result[i].tray_id;
std::string filament_type = boost::to_upper_copy(m_ams_mapping_result[i].type);
std::string filament_brand;
for (auto fs : m_filaments) {
if (fs.id == m_ams_mapping_result[i].id) {
filament_brand = m_filaments[i].brand;
}
}
bool in_blacklist = false;
std::string action;
std::string info;
DeviceManager::check_filaments_in_blacklist(filament_brand, filament_type, in_blacklist, action, info);
if (in_blacklist && action == "prohibition") {
has_prohibited_filament = true;
prohibited_error = wxString::FromUTF8(info);
}
for (auto miter : mapping_result) {
//matching
if (miter.id == tid) {
if (miter.type == TrayType::THIRD || miter.type == TrayType::EMPTY) {
has_unknown_filament = true;
break;
}
}
}
}
if (has_prohibited_filament && obj_->has_ams() && m_checkbox_list["use_ams"]->GetValue()) {
wxString tpu_tips = prohibited_error;
show_errors(tpu_tips);
return;
}
if (has_unknown_filament) {
has_slice_warnings = true;
confirm_text.push_back(_L("There are some unknown filaments in the AMS mappings. Please check whether they are the required filaments. If they are okay, press \"Confirm\" to start printing.") + "\n");
}
std::string nozzle_diameter;
std::string filament_type;
std::string tag_nozzle_type;
if (!obj_->nozzle_type.empty() && (m_print_type == PrintFromType::FROM_NORMAL)) {
if (!is_same_nozzle_diameters(tag_nozzle_type, nozzle_diameter)) {
has_slice_warnings = true;
has_update_nozzle = true;
wxString nozzle_in_preset = wxString::Format(_L("nozzle in preset: %s %s"),nozzle_diameter, "");
wxString nozzle_in_printer = wxString::Format(_L("nozzle memorized: %.1f %s"), obj_->nozzle_diameter, "");
confirm_text.push_back(_L("Your nozzle diameter in preset is not consistent with memorized nozzle diameter. Did you change your nozzle lately?")
+ "\n " + nozzle_in_preset
+ "\n " + nozzle_in_printer
+ "\n");
}
else if (!is_same_nozzle_type(filament_type, tag_nozzle_type)){
has_slice_warnings = true;
has_update_nozzle = true;
nozzle_diameter = wxString::Format("%.1f", obj_->nozzle_diameter).ToStdString();
wxString nozzle_in_preset = wxString::Format(_L("*Printing %s material with %s may cause nozzle damage"), filament_type, format_steel_name(obj_->nozzle_type));
confirm_text.push_back(nozzle_in_preset + "\n");
}
}
if (has_slice_warnings) {
wxString confirm_title = _L("Warning");
ConfirmBeforeSendDialog confirm_dlg(this, wxID_ANY, confirm_title);
if(has_update_nozzle){confirm_dlg.show_update_nozzle_button();}
confirm_dlg.Bind(EVT_SECONDARY_CHECK_CONFIRM, [this, &confirm_dlg](wxCommandEvent& e) {
confirm_dlg.on_hide();
if (m_print_type == PrintFromType::FROM_SDCARD_VIEW) {
this->connect_printer_mqtt();
}
else {
this->on_send_print();
}
});
confirm_dlg.Bind(EVT_UPDATE_NOZZLE, [this, obj_, tag_nozzle_type, nozzle_diameter, &confirm_dlg](wxCommandEvent& e) {
if (obj_ && !tag_nozzle_type.empty() && !nozzle_diameter.empty()) {
try
{
float diameter = std::stof(nozzle_diameter);
diameter = round(diameter * 10) / 10;
obj_->command_set_printer_nozzle(tag_nozzle_type, diameter);
}
catch (...) {}
}
});
confirm_text.push_back(_L("Please click the confirm button if you still want to proceed with printing.") + "\n");
wxString info_msg = wxEmptyString;
for (auto i = 0; i < confirm_text.size(); i++) {
if (i == 0) {
info_msg += confirm_text[i];
}
else if (i == confirm_text.size() - 1) {
info_msg += confirm_text[i];
}
else {
info_msg += wxString::Format("%d. %s\n",i, confirm_text[i]);
}
}
confirm_dlg.update_text(info_msg);
confirm_dlg.on_show();
} else {
if (m_print_type == PrintFromType::FROM_SDCARD_VIEW) {
this->connect_printer_mqtt();
}
else {
this->on_send_print();
}
}
}
wxString SelectMachineDialog::format_steel_name(std::string name)
{
if (name == "hardened_steel") {
return _L("Hardened Steel");
}
else if (name == "stainless_steel") {
return _L("Stainless Steel");
}
return wxEmptyString;
}
void SelectMachineDialog::Enable_Auto_Refill(bool enable)
{
if (enable) {
m_ams_backup_tip->SetForegroundColour(wxColour(0x009688));
}
else {
m_ams_backup_tip->SetForegroundColour(wxColour(0x90, 0x90, 0x90));
}
m_ams_backup_tip->Refresh();
}
void SelectMachineDialog::connect_printer_mqtt()
{
DeviceManager* dev = Slic3r::GUI::wxGetApp().getDeviceManager();
if (!dev) return;
MachineObject* obj_ = dev->get_selected_machine();
if (obj_->connection_type() == "cloud") {
show_status(PrintDialogStatus::PrintStatusSending);
m_status_bar->disable_cancel_button();
m_status_bar->set_status_text(_L("Connecting to the printer. Unable to cancel during the connection process."));
#if !BBL_RELEASE_TO_PUBLIC
obj_->connect(false, wxGetApp().app_config->get("enable_ssl_for_mqtt") == "true" ? true : false);
#else
obj_->connect(false, obj_->local_use_ssl_for_mqtt);
#endif
}
else {
on_send_print();
}
}
void SelectMachineDialog::on_send_print()
{
BOOST_LOG_TRIVIAL(info) << "print_job: on_ok to send";
m_is_canceled = false;
Enable_Send_Button(false);
if (m_mapping_popup.IsShown())
m_mapping_popup.Dismiss();
if (m_print_type == PrintFromType::FROM_NORMAL && m_is_in_sending_mode)
return;
int result = 0;
if (m_printer_last_select.empty()) {
return;
}
DeviceManager* dev = Slic3r::GUI::wxGetApp().getDeviceManager();
if (!dev) return;
MachineObject* obj_ = dev->get_selected_machine();
assert(obj_->dev_id == m_printer_last_select);
if (obj_ == nullptr) {
return;
}
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ", print_job: for send task, current printer id = " << m_printer_last_select << std::endl;
show_status(PrintDialogStatus::PrintStatusSending);
m_status_bar->reset();
m_status_bar->set_prog_block();
m_status_bar->set_cancel_callback_fina([this]() {
BOOST_LOG_TRIVIAL(info) << "print_job: enter canceled";
m_worker->cancel_all();
m_is_canceled = true;
wxCommandEvent* event = new wxCommandEvent(EVT_PRINT_JOB_CANCEL);
wxQueueEvent(this, event);
});
if (m_is_canceled) {
BOOST_LOG_TRIVIAL(info) << "print_job: m_is_canceled";
m_status_bar->set_status_text(task_canceled_text);
return;
}
// enter sending mode
sending_mode();
m_status_bar->enable_cancel_button();
// get ams_mapping_result
std::string ams_mapping_array;
std::string ams_mapping_info;
if (m_checkbox_list["use_ams"]->GetValue())
get_ams_mapping_result(ams_mapping_array, ams_mapping_info);
else {
json mapping_info_json = json::array();
json item;
if (m_filaments.size() > 0) {
item["sourceColor"] = m_filaments[0].color.substr(1, 8);
item["filamentType"] = m_filaments[0].type;
mapping_info_json.push_back(item);
ams_mapping_info = mapping_info_json.dump();
}
}
if (m_print_type == PrintFromType::FROM_NORMAL) {
result = m_plater->send_gcode(m_print_plate_idx, [this](int export_stage, int current, int total, bool& cancel) {
if (this->m_is_canceled) return;
bool cancelled = false;
wxString msg = _L("Preparing print job");
m_status_bar->update_status(msg, cancelled, 10, true);
m_export_3mf_cancel = cancel = cancelled;
});
if (m_is_canceled || m_export_3mf_cancel) {
BOOST_LOG_TRIVIAL(info) << "print_job: m_export_3mf_cancel or m_is_canceled";
m_status_bar->set_status_text(task_canceled_text);
return;
}
if (result < 0) {
wxString msg = _L("Abnormal print file data. Please slice again");
m_status_bar->set_status_text(msg);
return;
}
// export config 3mf if needed
if (!obj_->is_lan_mode_printer()) {
result = m_plater->export_config_3mf(m_print_plate_idx);
if (result < 0) {
BOOST_LOG_TRIVIAL(trace) << "export_config_3mf failed, result = " << result;
return;
}
}
if (m_is_canceled || m_export_3mf_cancel) {
BOOST_LOG_TRIVIAL(info) << "print_job: m_export_3mf_cancel or m_is_canceled";
m_status_bar->set_status_text(task_canceled_text);
return;
}
}
auto m_print_job = std::make_unique<PrintJob>(m_printer_last_select);
m_print_job->m_dev_ip = obj_->dev_ip;
m_print_job->m_ftp_folder = obj_->get_ftp_folder();
m_print_job->m_access_code = obj_->get_access_code();
#if !BBL_RELEASE_TO_PUBLIC
m_print_job->m_local_use_ssl_for_ftp = wxGetApp().app_config->get("enable_ssl_for_ftp") == "true" ? true : false;
m_print_job->m_local_use_ssl_for_mqtt = wxGetApp().app_config->get("enable_ssl_for_mqtt") == "true" ? true : false;
#else
m_print_job->m_local_use_ssl_for_ftp = obj_->local_use_ssl_for_ftp;
m_print_job->m_local_use_ssl_for_mqtt = obj_->local_use_ssl_for_mqtt;
#endif
m_print_job->connection_type = obj_->connection_type();
m_print_job->cloud_print_only = obj_->is_support_cloud_print_only;
if (m_print_type == PrintFromType::FROM_NORMAL) {
BOOST_LOG_TRIVIAL(info) << "print_job: m_print_type = from_normal";
m_print_job->m_print_type = "from_normal";
m_print_job->set_project_name(m_current_project_name.utf8_string());
}
else if(m_print_type == PrintFromType::FROM_SDCARD_VIEW){
BOOST_LOG_TRIVIAL(info) << "print_job: m_print_type = from_sdcard_view";
m_print_job->m_print_type = "from_sdcard_view";
m_print_job->connection_type = "lan";
try {
m_print_job->m_print_from_sdc_plate_idx = m_required_data_plate_data_list[m_print_plate_idx]->plate_index + 1;
m_print_job->set_dst_name(m_required_data_file_path);
}
catch (...) {}
BOOST_LOG_TRIVIAL(info) << "print_job: m_print_plate_idx =" << m_print_job->m_print_from_sdc_plate_idx;
auto input_str_arr = wxGetApp().split_str(m_required_data_file_name, ".gcode.3mf");
if (input_str_arr.size() <= 1) {
input_str_arr = wxGetApp().split_str(m_required_data_file_name, ".3mf");
if (input_str_arr.size() > 1) {
m_print_job->set_project_name(input_str_arr[0]);
}
}
else {
m_print_job->set_project_name(input_str_arr[0]);
}
}
if (obj_->is_support_ams_mapping()) {
m_print_job->task_ams_mapping = ams_mapping_array;
m_print_job->task_ams_mapping_info = ams_mapping_info;
} else {
m_print_job->task_ams_mapping = "";
m_print_job->task_ams_mapping_info = "";
}
m_print_job->has_sdcard = obj_->has_sdcard();
bool timelapse_option = select_timelapse->IsShown() ? m_checkbox_list["timelapse"]->GetValue() : true;
m_print_job->set_print_config(
MachineBedTypeString[0],
m_checkbox_list["bed_leveling"]->GetValue(),
m_checkbox_list["flow_cali"]->GetValue(),
false,
timelapse_option,
true);
if (obj_->has_ams()) {
m_print_job->task_use_ams = m_checkbox_list["use_ams"]->GetValue();
} else {
m_print_job->task_use_ams = false;
}
BOOST_LOG_TRIVIAL(info) << "print_job: timelapse_option = " << timelapse_option;
BOOST_LOG_TRIVIAL(info) << "print_job: use_ams = " << m_print_job->task_use_ams;
m_print_job->on_success([this]() { finish_mode(); });
m_print_job->on_check_ip_address_fail([this]() {
wxCommandEvent* evt = new wxCommandEvent(EVT_CLEAR_IPADDRESS);
wxQueueEvent(this, evt);
wxGetApp().show_ip_address_enter_dialog();
});
// update ota version
NetworkAgent* agent = wxGetApp().getAgent();
if (agent)
agent->track_update_property("dev_ota_version", obj_->get_ota_version());
replace_job(*m_worker, std::move(m_print_job));
BOOST_LOG_TRIVIAL(info) << "print_job: start print job";
}
void SelectMachineDialog::clear_ip_address_config(wxCommandEvent& e)
{
prepare_mode();
}
void SelectMachineDialog::update_user_machine_list()
{
NetworkAgent* m_agent = wxGetApp().getAgent();
if (m_agent && m_agent->is_user_login()) {
boost::thread get_print_info_thread = Slic3r::create_thread([this, token = std::weak_ptr(m_token)] {
NetworkAgent* agent = wxGetApp().getAgent();
unsigned int http_code;
std::string body;
int result = agent->get_user_print_info(&http_code, &body);
CallAfter([token, this, result, body] {
if (token.expired()) {return;}
if (result == 0) {
m_print_info = body;
}
else {
m_print_info = "";
}
wxCommandEvent event(EVT_UPDATE_USER_MACHINE_LIST);
event.SetEventObject(this);
wxPostEvent(this, event);
});
});
} else {
wxCommandEvent event(EVT_UPDATE_USER_MACHINE_LIST);
event.SetEventObject(this);
wxPostEvent(this, event);
}
}
void SelectMachineDialog::on_refresh(wxCommandEvent &event)
{
BOOST_LOG_TRIVIAL(info) << "m_printer_last_select: on_refresh";
show_status(PrintDialogStatus::PrintStatusRefreshingMachineList);
update_user_machine_list();
}
void SelectMachineDialog::on_set_finish_mapping(wxCommandEvent &evt)
{
auto selection_data = evt.GetString();
auto selection_data_arr = wxSplit(selection_data.ToStdString(), '|');
BOOST_LOG_TRIVIAL(info) << "The ams mapping selection result: data is " << selection_data;
if (selection_data_arr.size() == 6) {
for (auto i = 0; i < m_ams_mapping_result.size(); i++) {
if (m_ams_mapping_result[i].id == wxAtoi(selection_data_arr[5])) {
m_ams_mapping_result[i].tray_id = evt.GetInt();
auto ams_colour = wxColour(wxAtoi(selection_data_arr[0]), wxAtoi(selection_data_arr[1]), wxAtoi(selection_data_arr[2]), wxAtoi(selection_data_arr[3]));
wxString color = wxString::Format("#%02X%02X%02X%02X", ams_colour.Red(), ams_colour.Green(), ams_colour.Blue(), ams_colour.Alpha());
m_ams_mapping_result[i].color = color.ToStdString();
}
BOOST_LOG_TRIVIAL(trace) << "The ams mapping result: id is " << m_ams_mapping_result[i].id << "tray_id is " << m_ams_mapping_result[i].tray_id;
}
MaterialHash::iterator iter = m_materialList.begin();
while (iter != m_materialList.end()) {
Material* item = iter->second;
MaterialItem *m = item->item;
if (item->id == m_current_filament_id) {
auto ams_colour = wxColour(wxAtoi(selection_data_arr[0]), wxAtoi(selection_data_arr[1]), wxAtoi(selection_data_arr[2]), wxAtoi(selection_data_arr[3]));
m->set_ams_info(ams_colour, selection_data_arr[4]);
}
iter++;
}
}
}
void SelectMachineDialog::on_print_job_cancel(wxCommandEvent &evt)
{
BOOST_LOG_TRIVIAL(info) << "print_job: canceled";
show_status(PrintDialogStatus::PrintStatusInit);
// enter prepare mode
prepare_mode();
}
std::vector<std::string> SelectMachineDialog::sort_string(std::vector<std::string> strArray)
{
std::vector<std::string> outputArray;
std::sort(strArray.begin(), strArray.end());
std::vector<std::string>::iterator st;
for (st = strArray.begin(); st != strArray.end(); st++) { outputArray.push_back(*st); }
return outputArray;
}
bool SelectMachineDialog::is_timeout()
{
if (m_timeout_count > 15 * 1000 / LIST_REFRESH_INTERVAL) {
return true;
}
return false;
}
int SelectMachineDialog::update_print_required_data(Slic3r::DynamicPrintConfig config, Slic3r::Model model, Slic3r::PlateDataPtrs plate_data_list, std::string file_name, std::string file_path)
{
m_required_data_plate_data_list.clear();
m_required_data_config = config;
m_required_data_model = model;
//m_required_data_plate_data_list = plate_data_list;
for (auto i = 0; i < plate_data_list.size(); i++) {
if (!plate_data_list[i]->gcode_file.empty()) {
m_required_data_plate_data_list.push_back(plate_data_list[i]);
}
}
m_required_data_file_name = file_name;
m_required_data_file_path = file_path;
return m_required_data_plate_data_list.size();
}
void SelectMachineDialog::reset_timeout()
{
m_timeout_count = 0;
}
void SelectMachineDialog::update_user_printer()
{
Slic3r::DeviceManager* dev = Slic3r::GUI::wxGetApp().getDeviceManager();
if (!dev) return;
// update user print info
if (!m_print_info.empty()) {
dev->parse_user_print_info(m_print_info);
m_print_info = "";
}
// clear machine list
m_list.clear();
m_comboBox_printer->Clear();
std::vector<std::string> machine_list;
wxArrayString machine_list_name;
std::map<std::string, MachineObject*> option_list;
//user machine list
option_list = dev->get_my_machine_list();
// same machine only appear once
for (auto it = option_list.begin(); it != option_list.end(); it++) {
if (it->second && (it->second->is_online() || it->second->is_connected())) {
machine_list.push_back(it->second->dev_name);
}
}
//lan machine list
auto lan_option_list = dev->get_local_machine_list();
for (auto elem : lan_option_list) {
MachineObject* mobj = elem.second;
/* do not show printer bind state is empty */
if (!mobj->is_avaliable()) continue;
if (!mobj->is_online()) continue;
if (!mobj->is_lan_mode_printer()) continue;
/*if (mobj->is_in_printing()) {op->set_printer_state(PrinterState::BUSY);}*/
if (!mobj->has_access_right()) {
option_list[mobj->dev_name] = mobj;
machine_list.push_back(mobj->dev_name);
}
}
machine_list = sort_string(machine_list);
for (auto tt = machine_list.begin(); tt != machine_list.end(); tt++) {
for (auto it = option_list.begin(); it != option_list.end(); it++) {
if (it->second->dev_name == *tt) {
m_list.push_back(it->second);
wxString dev_name_text = from_u8(it->second->dev_name);
if (it->second->is_lan_mode_printer()) {
dev_name_text += "(LAN)";
}
machine_list_name.Add(dev_name_text);
break;
}
}
}
m_comboBox_printer->Set(machine_list_name);
MachineObject* obj = dev->get_selected_machine();
if (obj) {
if (obj->is_lan_mode_printer() && !obj->has_access_right()) {
m_printer_last_select = "";
}
else {
m_printer_last_select = obj->dev_id;
}
} else {
m_printer_last_select = "";
}
if (m_list.size() > 0) {
// select a default machine
if (m_printer_last_select.empty()) {
int def_selection = -1;
for (int i = 0; i < m_list.size(); i++) {
if (m_list[i]->is_lan_mode_printer() && !m_list[i]->has_access_right()) {
continue;
}
else {
def_selection = i;
}
}
if (def_selection >= 0) {
m_printer_last_select = m_list[def_selection]->dev_id;
m_comboBox_printer->SetSelection(def_selection);
wxCommandEvent event(wxEVT_COMBOBOX);
event.SetEventObject(m_comboBox_printer);
wxPostEvent(m_comboBox_printer, event);
}
}
for (auto i = 0; i < m_list.size(); i++) {
if (m_list[i]->dev_id == m_printer_last_select) {
if (obj && !obj->get_lan_mode_connection_state()) {
m_comboBox_printer->SetSelection(i);
wxCommandEvent event(wxEVT_COMBOBOX);
event.SetEventObject(m_comboBox_printer);
wxPostEvent(m_comboBox_printer, event);
}
}
}
}
else {
m_printer_last_select = "";
update_select_layout(nullptr);
m_comboBox_printer->SetTextLabel("");
}
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << "for send task, current printer id = " << m_printer_last_select << std::endl;
}
void SelectMachineDialog::on_rename_click(wxCommandEvent& event)
{
m_is_rename_mode = true;
m_rename_input->GetTextCtrl()->SetValue(m_current_project_name);
m_rename_switch_panel->SetSelection(1);
m_rename_input->GetTextCtrl()->SetFocus();
m_rename_input->GetTextCtrl()->SetInsertionPointEnd();
}
void SelectMachineDialog::on_rename_enter()
{
if (m_is_rename_mode == false){
return;
}
else {
m_is_rename_mode = false;
}
auto new_file_name = m_rename_input->GetTextCtrl()->GetValue();
wxString temp;
int num = 0;
for (auto t : new_file_name) {
if (t == wxString::FromUTF8("\x20")) {
num++;
if (num == 1) temp += t;
} else {
num = 0;
temp += t;
}
}
new_file_name = temp;
auto m_valid_type = Valid;
wxString info_line;
const char* unusable_symbols = "<>[]:/\\|?*\"";
const std::string unusable_suffix = PresetCollection::get_suffix_modified(); //"(modified)";
for (size_t i = 0; i < std::strlen(unusable_symbols); i++) {
if (new_file_name.find_first_of(unusable_symbols[i]) != std::string::npos) {
info_line = _L("Name is invalid;") + "\n" + _L("illegal characters:") + " " + unusable_symbols;
m_valid_type = NoValid;
break;
}
}
if (m_valid_type == Valid && new_file_name.find(unusable_suffix) != std::string::npos) {
info_line = _L("Name is invalid;") + "\n" + _L("illegal suffix:") + "\n\t" + from_u8(PresetCollection::get_suffix_modified());
m_valid_type = NoValid;
}
if (m_valid_type == Valid && new_file_name.empty()) {
info_line = _L("The name is not allowed to be empty.");
m_valid_type = NoValid;
}
if (m_valid_type == Valid && new_file_name.find_first_of(' ') == 0) {
info_line = _L("The name is not allowed to start with space character.");
m_valid_type = NoValid;
}
if (m_valid_type == Valid && new_file_name.find_last_of(' ') == new_file_name.length() - 1) {
info_line = _L("The name is not allowed to end with space character.");
m_valid_type = NoValid;
}
if (m_valid_type == Valid && new_file_name.size() >= 100) {
info_line = _L("The name length exceeds the limit.");
m_valid_type = NoValid;
}
if (m_valid_type != Valid) {
MessageDialog msg_wingow(nullptr, info_line, "", wxICON_WARNING | wxOK);
if (msg_wingow.ShowModal() == wxID_OK) {
m_rename_switch_panel->SetSelection(0);
m_rename_text->SetLabel(m_current_project_name);
m_rename_normal_panel->Layout();
return;
}
}
m_current_project_name = new_file_name;
m_rename_switch_panel->SetSelection(0);
m_rename_text->SetLabel(m_current_project_name);
m_rename_normal_panel->Layout();
}
void SelectMachineDialog::update_printer_combobox(wxCommandEvent &event)
{
show_status(PrintDialogStatus::PrintStatusInit);
update_user_printer();
}
void SelectMachineDialog::on_timer(wxTimerEvent &event)
{
wxGetApp().reset_to_active();
update_show_status();
///show auto refill
DeviceManager* dev = Slic3r::GUI::wxGetApp().getDeviceManager();
if(!dev) return;
MachineObject* obj_ = dev->get_selected_machine();
if(!obj_) return;
update_ams_check(obj_);
update_select_layout(obj_);
if (!obj_
|| obj_->amsList.empty()
|| obj_->ams_exist_bits == 0
|| !obj_->is_support_filament_backup
|| !obj_->is_support_show_filament_backup
|| !obj_->ams_auto_switch_filament_flag
|| !m_checkbox_list["use_ams"]->GetValue() ) {
if (m_ams_backup_tip->IsShown()) {
m_ams_backup_tip->Hide();
img_ams_backup->Hide();
Layout();
Fit();
}
}
else {
if (!m_ams_backup_tip->IsShown()) {
m_ams_backup_tip->Show();
img_ams_backup->Show();
Layout();
Fit();
}
}
}
void SelectMachineDialog::on_selection_changed(wxCommandEvent &event)
{
/* reset timeout and reading printer info */
m_status_bar->reset();
m_timeout_count = 0;
m_ams_mapping_res = false;
m_ams_mapping_valid = false;
m_ams_mapping_result.clear();
auto selection = m_comboBox_printer->GetSelection();
DeviceManager* dev = Slic3r::GUI::wxGetApp().getDeviceManager();
if (!dev) return;
MachineObject* obj = nullptr;
for (int i = 0; i < m_list.size(); i++) {
if (i == selection) {
//check lan mode machine
if (m_list[i]->is_lan_mode_printer() && !m_list[i]->has_access_right()) {
ConnectPrinterDialog dlg(wxGetApp().mainframe, wxID_ANY, _L("Input access code"));
dlg.set_machine_object(m_list[i]);
auto res = dlg.ShowModal();
m_printer_last_select = "";
m_comboBox_printer->SetSelection(-1);
m_comboBox_printer->Refresh();
m_comboBox_printer->Update();
}
m_printer_last_select = m_list[i]->dev_id;
obj = m_list[i];
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << "for send task, current printer id = " << m_printer_last_select << std::endl;
break;
}
}
if (obj) {
obj->command_get_version();
obj->command_request_push_all();
if (!dev->get_selected_machine()) {
dev->set_selected_machine(m_printer_last_select, true);
}else if (dev->get_selected_machine()->dev_id != m_printer_last_select) {
dev->set_selected_machine(m_printer_last_select, true);
}
// reset the timelapse check status for I3 structure
if (obj->get_printer_arch() == PrinterArch::ARCH_I3) {
m_checkbox_list["timelapse"]->SetValue(false);
AppConfig *config = wxGetApp().app_config;
if (config) config->set_str("print", "timelapse", "0");
}
// Has changed machine unrecoverably
GUI::wxGetApp().sidebar().load_ams_list(obj->dev_id, obj);
update_select_layout(obj);
} else {
BOOST_LOG_TRIVIAL(error) << "on_selection_changed dev_id not found";
return;
}
//reset print status
update_flow_cali_check(obj);
show_status(PrintDialogStatus::PrintStatusInit);
reset_ams_material();
update_show_status();
}
void SelectMachineDialog::update_flow_cali_check(MachineObject* obj)
{
auto bed_type = m_plater->get_partplate_list().get_curr_plate()->get_bed_type(true);
auto show_cali_tips = true;
if (obj && obj->get_printer_arch() == PrinterArch::ARCH_I3) { show_cali_tips = false; }
if (bed_type == BedType::btPTE) {
set_flow_calibration_state(false, show_cali_tips);
}
else {
set_flow_calibration_state(true, show_cali_tips);
}
}
void SelectMachineDialog::update_ams_check(MachineObject* obj)
{
if (obj && obj->ams_support_use_ams && obj->has_ams()) {
select_use_ams->Show();
if (obj->get_printer_ams_type() == "generic") {
img_use_ams_tip->Show();
}
else {
img_use_ams_tip->Hide();
}
} else {
select_use_ams->Hide();
}
}
void SelectMachineDialog::update_show_status()
{
// refreshing return
if (get_status() == PrintDialogStatus::PrintStatusRefreshingMachineList)
return;
if (get_status() == PrintDialogStatus::PrintStatusSending)
return;
if (get_status() == PrintDialogStatus::PrintStatusSendingCanceled)
return;
NetworkAgent* agent = Slic3r::GUI::wxGetApp().getAgent();
DeviceManager* dev = Slic3r::GUI::wxGetApp().getDeviceManager();
if (!agent) {
update_ams_check(nullptr);
return;
}
if (!dev) return;
dev->check_pushing();
PartPlate* plate = m_plater->get_partplate_list().get_curr_plate();
// blank plate has no valid gcode file
if (m_print_type == PrintFromType::FROM_NORMAL) {
if (plate && !plate->is_valid_gcode_file()) {
show_status(PrintDialogStatus::PrintStatusBlankPlate);
return;
}
}
MachineObject* obj_ = dev->get_my_machine(m_printer_last_select);
if (!obj_) {
update_ams_check(nullptr);
if (agent) {
if (agent->is_user_login()) {
show_status(PrintDialogStatus::PrintStatusInvalidPrinter);
}
else {
show_status(PrintDialogStatus::PrintStatusNoUserLogin);
}
}
return;
}
/* check cloud machine connections */
if (!obj_->is_lan_mode_printer()) {
if (!agent->is_server_connected()) {
agent->refresh_connection();
show_status(PrintDialogStatus::PrintStatusConnectingServer);
reset_timeout();
return;
}
}
if (!obj_->is_info_ready()) {
if (is_timeout()) {
m_ams_mapping_result.clear();
sync_ams_mapping_result(m_ams_mapping_result);
show_status(PrintDialogStatus::PrintStatusReadingTimeout);
return;
}
else {
m_timeout_count++;
show_status(PrintDialogStatus::PrintStatusReading);
return;
}
return;
}
reset_timeout();
//update_ams_check(obj_);
if (!obj_->is_support_print_all && m_print_plate_idx == PLATE_ALL_IDX) {
show_status(PrintDialogStatus::PrintStatusNotSupportedPrintAll);
return;
}
// do ams mapping if no ams result
bool clean_ams_mapping = false;
if (obj_->has_ams() && m_ams_mapping_result.empty()) {
if (obj_->ams_support_use_ams) {
if (m_checkbox_list["use_ams"]->GetValue()) {
do_ams_mapping(obj_);
} else {
clean_ams_mapping = true;
}
}
}
if (!obj_->has_ams() || !m_checkbox_list["use_ams"]->GetValue()) {
clean_ams_mapping = true;
}
if (clean_ams_mapping) {
m_ams_mapping_result.clear();
sync_ams_mapping_result(m_ams_mapping_result);
}
// reading done
if (wxGetApp().app_config && wxGetApp().app_config->get("internal_debug").empty()) {
if (obj_->upgrade_force_upgrade) {
show_status(PrintDialogStatus::PrintStatusNeedForceUpgrading);
return;
}
if (obj_->upgrade_consistency_request) {
show_status(PrintStatusNeedConsistencyUpgrading);
return;
}
}
if (m_print_type == PrintFromType::FROM_NORMAL && is_blocking_printing(obj_)) {
show_status(PrintDialogStatus::PrintStatusUnsupportedPrinter);
return;
}
else if (obj_->is_in_upgrading()) {
show_status(PrintDialogStatus::PrintStatusInUpgrading);
return;
}
else if (obj_->is_system_printing()) {
show_status(PrintDialogStatus::PrintStatusInSystemPrinting);
return;
}
else if (obj_->is_in_printing() || obj_->ams_status_main == AMS_STATUS_MAIN_FILAMENT_CHANGE) {
show_status(PrintDialogStatus::PrintStatusInPrinting);
return;
}
else if (!obj_->is_support_print_without_sd && (obj_->get_sdcard_state() == MachineObject::SdcardState::NO_SDCARD)) {
show_status(PrintDialogStatus::PrintStatusNoSdcard);
return;
}
// check sdcard when if lan mode printer
if (obj_->is_lan_mode_printer()) {
if (obj_->get_sdcard_state() == MachineObject::SdcardState::NO_SDCARD) {
show_status(PrintDialogStatus::PrintStatusLanModeNoSdcard);
return;
}
}
if (has_timelapse_warning()) {
show_status(PrintDialogStatus::PrintStatusTimelapseWarning);
return;
}
// no ams
if (!obj_->has_ams() || !m_checkbox_list["use_ams"]->GetValue()) {
if (!has_tips(obj_))
show_status(PrintDialogStatus::PrintStatusReadingFinished);
return;
}
if (obj_->ams_support_use_ams) {
if (!m_checkbox_list["use_ams"]->GetValue()) {
m_ams_mapping_result.clear();
sync_ams_mapping_result(m_ams_mapping_result);
show_status(PrintDialogStatus::PrintStatusDisableAms);
return;
}
}
// do ams mapping if no ams result
if (m_ams_mapping_result.empty()) {
do_ams_mapping(obj_);
}
if (!obj_->is_support_ams_mapping()) {
int exceed_index = -1;
if (obj_->is_mapping_exceed_filament(m_ams_mapping_result, exceed_index)) {
std::vector<wxString> params;
params.push_back(wxString::Format("%02d", exceed_index+1));
show_status(PrintDialogStatus::PrintStatusNeedUpgradingAms, params);
} else {
if (obj_->is_valid_mapping_result(m_ams_mapping_result)) {
show_status(PrintDialogStatus::PrintStatusAmsMappingByOrder);
} else {
int mismatch_index = -1;
for (int i = 0; i < m_ams_mapping_result.size(); i++) {
if (m_ams_mapping_result[i].mapping_result == MappingResult::MAPPING_RESULT_TYPE_MISMATCH) {
mismatch_index = m_ams_mapping_result[i].id;
break;
}
}
std::vector<wxString> params;
if (mismatch_index >= 0) {
params.push_back(wxString::Format("%02d", mismatch_index+1));
params.push_back(wxString::Format("%02d", mismatch_index+1));
}
show_status(PrintDialogStatus::PrintStatusAmsMappingU0Invalid, params);
}
}
return;
}
if (m_ams_mapping_res) {
show_status(PrintDialogStatus::PrintStatusAmsMappingSuccess);
return;
}
else {
if (obj_->is_valid_mapping_result(m_ams_mapping_result)) {
if (!has_tips(obj_))
show_status(PrintDialogStatus::PrintStatusAmsMappingValid);
return;
}
else {
show_status(PrintDialogStatus::PrintStatusAmsMappingInvalid);
return;
}
}
}
bool SelectMachineDialog::has_timelapse_warning()
{
PartPlate *plate = m_plater->get_partplate_list().get_curr_plate();
for (auto warning : plate->get_slice_result()->warnings) {
if (warning.msg == NOT_GENERATE_TIMELAPSE) {
return true;
}
}
return false;
}
void SelectMachineDialog::update_timelapse_enable_status()
{
AppConfig *config = wxGetApp().app_config;
if (!has_timelapse_warning()) {
if (!config || config->get("print", "timelapse") == "0")
m_checkbox_list["timelapse"]->SetValue(false);
else
m_checkbox_list["timelapse"]->SetValue(true);
select_timelapse->Enable(true);
} else {
m_checkbox_list["timelapse"]->SetValue(false);
select_timelapse->Enable(false);
if (config) { config->set_str("print", "timelapse", "0"); }
}
}
bool SelectMachineDialog::is_show_timelapse()
{
auto compare_version = [](const std::string &version1, const std::string &version2) -> bool {
int i = 0, j = 0;
int max_size = std::max(version1.size(), version2.size());
while (i < max_size || j < max_size) {
int v1 = 0, v2 = 0;
while (i < version1.size() && version1[i] != '.') v1 = 10 * v1 + (version1[i++] - '0');
while (j < version2.size() && version2[j] != '.') v2 = 10 * v2 + (version2[j++] - '0');
if (v1 > v2) return true;
if (v1 < v2) return false;
++i;
++j;
}
return false;
};
std::string standard_version = "01.04.00.00";
PartPlate *plate = m_plater->get_partplate_list().get_curr_plate();
fs::path gcode_path = plate->get_tmp_gcode_path();
std::string line;
std::ifstream gcode_file;
gcode_file.open(gcode_path.string());
if (gcode_file.fail()) {
} else {
bool is_version = false;
while (gcode_file >> line) {
if (is_version) {
if (compare_version(standard_version, line)) {
gcode_file.close();
return false;
}
break;
}
if (line == "BambuStudio")
is_version = true;
}
}
gcode_file.close();
return true;
}
void SelectMachineDialog::reset_ams_material()
{
MaterialHash::iterator iter = m_materialList.begin();
while (iter != m_materialList.end()) {
int id = iter->first;
Material* item = iter->second;
MaterialItem* m = item->item;
wxString ams_id = "-";
wxColour ams_col = wxColour(0xEE, 0xEE, 0xEE);
m->set_ams_info(ams_col, ams_id);
iter++;
}
}
void SelectMachineDialog::Enable_Refresh_Button(bool en)
{
if (!en) {
if (m_button_refresh->IsEnabled()) {
m_button_refresh->Disable();
m_button_refresh->SetBackgroundColor(wxColour(0x90, 0x90, 0x90));
m_button_refresh->SetBorderColor(wxColour(0x90, 0x90, 0x90));
}
} else {
if (!m_button_refresh->IsEnabled()) {
m_button_refresh->Enable();
m_button_refresh->SetBackgroundColor(m_btn_bg_enable);
m_button_refresh->SetBorderColor(m_btn_bg_enable);
}
}
}
void SelectMachineDialog::Enable_Send_Button(bool en)
{
if (!en) {
if (m_button_ensure->IsEnabled()) {
m_button_ensure->Disable();
m_button_ensure->SetBackgroundColor(wxColour(0x90, 0x90, 0x90));
m_button_ensure->SetBorderColor(wxColour(0x90, 0x90, 0x90));
}
} else {
if (!m_button_ensure->IsEnabled()) {
m_button_ensure->Enable();
m_button_ensure->SetBackgroundColor(m_btn_bg_enable);
m_button_ensure->SetBorderColor(m_btn_bg_enable);
}
}
}
void SelectMachineDialog::on_dpi_changed(const wxRect &suggested_rect)
{
print_time->sys_color_changed();
timeimg->SetBitmap(print_time->bmp());
print_weight->sys_color_changed();
weightimg->SetBitmap(print_weight->bmp());
m_rename_button->sys_color_changed();
ams_editable->sys_color_changed();
ams_editable_light->sys_color_changed();
enable_ams_mapping->sys_color_changed();
img_amsmapping_tip->SetBitmap(enable_ams_mapping->bmp());
enable_ams->sys_color_changed();
img_use_ams_tip->SetBitmap(enable_ams->bmp());
m_button_refresh->SetMinSize(SELECT_MACHINE_DIALOG_BUTTON_SIZE);
m_button_refresh->SetCornerRadius(FromDIP(12));
m_button_ensure->SetMinSize(SELECT_MACHINE_DIALOG_BUTTON_SIZE);
m_button_ensure->SetCornerRadius(FromDIP(12));
m_status_bar->msw_rescale();
for (auto checkpire : m_checkbox_list) {
checkpire.second->Rescale();
}
for (auto material1 : m_materialList) {
material1.second->item->msw_rescale();
}
Fit();
Refresh();
}
wxImage *SelectMachineDialog::LoadImageFromBlob(const unsigned char *data, int size)
{
if (data != NULL) {
wxMemoryInputStream mi(data, size);
wxImage * img = new wxImage(mi, wxBITMAP_TYPE_ANY);
if (img != NULL && img->IsOk()) return img;
// wxLogDebug( wxT("DB::LoadImageFromBlob error: data=%p size=%d"), data, size);
// caller is responsible for deleting the pointer
delete img;
}
return NULL;
}
void SelectMachineDialog::set_flow_calibration_state(bool state, bool show_tips)
{
if (!state) {
m_checkbox_list["flow_cali"]->SetValue(state);
auto tool_tip = _L("Caution to use! Flow calibration on Textured PEI Plate may fail due to the scattered surface.");
m_checkbox_list["flow_cali"]->SetToolTip(tool_tip);
m_checkbox_list["flow_cali"]->Enable();
for (auto win : select_flow->GetWindowChildren()) {
win->SetToolTip(tool_tip);
}
//select_flow->SetToolTip(tool_tip);
}
else {
AppConfig* config = wxGetApp().app_config;
if (config && config->get("print", "flow_cali") == "0") {
m_checkbox_list["flow_cali"]->SetValue(false);
}
else {
m_checkbox_list["flow_cali"]->SetValue(true);
}
m_checkbox_list["flow_cali"]->Enable();
for (auto win : select_flow->GetWindowChildren()) {
win->SetToolTip( _L("Automatic flow calibration using Micro Lidar"));
}
}
if (!show_tips) {
for (auto win : select_flow->GetWindowChildren()) {
win->SetToolTip(wxEmptyString);
}
}
}
void SelectMachineDialog::set_default()
{
if (m_print_type == PrintFromType::FROM_NORMAL) {
m_stext_printer_title->Show(true);
m_comboBox_printer->Show(true);
m_button_refresh->Show(true);
m_rename_normal_panel->Show(true);
m_hyperlink->Show(true);
}
else if (m_print_type == PrintFromType::FROM_SDCARD_VIEW) {
m_stext_printer_title->Show(false);
m_comboBox_printer->Show(false);
m_button_refresh->Show(false);
m_rename_normal_panel->Show(false);
m_hyperlink->Show(false);
}
//project name
m_rename_switch_panel->SetSelection(0);
wxString filename = m_plater->get_export_gcode_filename("", true, m_print_plate_idx == PLATE_ALL_IDX ? true : false);
if (m_print_plate_idx == PLATE_ALL_IDX && filename.empty()) {
filename = _L("Untitled");
}
if (filename.empty()) {
filename = m_plater->get_export_gcode_filename("", true);
if (filename.empty()) filename = _L("Untitled");
}
fs::path filename_path(filename.c_str());
m_current_project_name = wxString::FromUTF8(filename_path.filename().string());
//unsupported character filter
m_current_project_name = from_u8(filter_characters(m_current_project_name.ToUTF8().data(), "<>[]:/\\|?*\""));
m_rename_text->SetLabelText(m_current_project_name);
m_rename_normal_panel->Layout();
//clear combobox
m_list.clear();
m_comboBox_printer->Clear();
m_printer_last_select = "";
m_print_info = "";
m_comboBox_printer->SetValue(wxEmptyString);
m_comboBox_printer->Enable();
// rset status bar
m_status_bar->reset();
NetworkAgent* agent = wxGetApp().getAgent();
if (agent) {
if (agent->is_user_login()) {
show_status(PrintDialogStatus::PrintStatusInit);
}
else {
show_status(PrintDialogStatus::PrintStatusNoUserLogin);
}
}
select_bed->Show();
select_flow->Show();
//reset checkbox
select_bed->Show(false);
select_flow->Show(false);
select_timelapse->Show(false);
select_use_ams->Show(false);
// load checkbox values from app config
AppConfig* config = wxGetApp().app_config;
if (config && config->get("print", "bed_leveling") == "0") {
m_checkbox_list["bed_leveling"]->SetValue(false);
}
else {
m_checkbox_list["bed_leveling"]->SetValue(true);
}
if (config && config->get("print", "flow_cali") == "0") {
m_checkbox_list["flow_cali"]->SetValue(false);
}
else {
m_checkbox_list["flow_cali"]->SetValue(true);
}
if (config && config->get("print", "timelapse") == "0") {
m_checkbox_list["timelapse"]->SetValue(false);
}
else {
m_checkbox_list["timelapse"]->SetValue(true);
}
m_checkbox_list["use_ams"]->SetValue(true);
if (m_print_type == PrintFromType::FROM_NORMAL) {
set_default_normal();
}
else if (m_print_type == PrintFromType::FROM_SDCARD_VIEW) {
set_default_from_sdcard();
}
Layout();
Fit();
}
void SelectMachineDialog::set_default_normal()
{
update_page_turn_state(false);
ThumbnailData& data = m_plater->get_partplate_list().get_curr_plate()->thumbnail_data;
if (data.is_valid()) {
wxImage image(data.width, data.height);
image.InitAlpha();
for (unsigned int r = 0; r < data.height; ++r) {
unsigned int rr = (data.height - 1 - r) * data.width;
for (unsigned int c = 0; c < data.width; ++c) {
unsigned char* px = (unsigned char*)data.pixels.data() + 4 * (rr + c);
image.SetRGB((int)c, (int)r, px[0], px[1], px[2]);
image.SetAlpha((int)c, (int)r, px[3]);
}
}
image = image.Rescale(FromDIP(256), FromDIP(256));
m_thumbnailPanel->set_thumbnail(image);
}
//for black list
std::vector<std::string> materials;
std::vector<std::string> brands;
std::vector<std::string> display_materials;
std::vector<std::string> m_filaments_id;
auto preset_bundle = wxGetApp().preset_bundle;
for (auto filament_name : preset_bundle->filament_presets) {
for (int f_index = 0; f_index < preset_bundle->filaments.size(); f_index++) {
PresetCollection* filament_presets = &wxGetApp().preset_bundle->filaments;
Preset* preset = &filament_presets->preset(f_index);
if (preset && filament_name.compare(preset->name) == 0) {
std::string display_filament_type;
std::string filament_type = preset->config.get_filament_type(display_filament_type);
std::string m_filament_id=preset->filament_id;
display_materials.push_back(display_filament_type);
materials.push_back(filament_type);
m_filaments_id.push_back(m_filament_id);
std::string m_vendor_name = "";
auto vendor = dynamic_cast<ConfigOptionStrings*> (preset->config.option("filament_vendor"));
if (vendor && (vendor->values.size() > 0)) {
std::string vendor_name = vendor->values[0];
m_vendor_name = vendor_name;
}
brands.push_back(m_vendor_name);
}
}
}
//init MaterialItem
auto extruders = wxGetApp().plater()->get_partplate_list().get_curr_plate()->get_used_extruders();
MaterialHash::iterator iter = m_materialList.begin();
while (iter != m_materialList.end()) {
int id = iter->first;
Material* item = iter->second;
item->item->Destroy();
delete item;
iter++;
}
m_sizer_material->Clear();
m_materialList.clear();
m_filaments.clear();
for (auto i = 0; i < extruders.size(); i++) {
auto extruder = extruders[i] - 1;
auto colour = wxGetApp().preset_bundle->project_config.opt_string("filament_colour", (unsigned int) extruder);
ColorRGBA rgb;
decode_color(colour, rgb);
auto colour_rgb = wxColour((int) rgb.r_uchar(), (int) rgb.g_uchar(), (int) rgb.b_uchar(), (int) rgb.a_uchar());
if (extruder >= materials.size() || extruder < 0 || extruder >= display_materials.size())
continue;
MaterialItem* item = new MaterialItem(m_scrollable_region, colour_rgb, _L(display_materials[extruder]));
m_sizer_material->Add(item, 0, wxALL, FromDIP(4));
item->Bind(wxEVT_LEFT_UP, [this, item, materials, extruder](wxMouseEvent& e) {});
item->Bind(wxEVT_LEFT_DOWN, [this, item, materials, extruder](wxMouseEvent& e) {
MaterialHash::iterator iter = m_materialList.begin();
while (iter != m_materialList.end()) {
int id = iter->first;
Material* item = iter->second;
MaterialItem* m = item->item;
m->on_normal();
iter++;
}
m_current_filament_id = extruder;
item->on_selected();
auto mouse_pos = ClientToScreen(e.GetPosition());
wxPoint rect = item->ClientToScreen(wxPoint(0, 0));
// update ams data
DeviceManager* dev_manager = Slic3r::GUI::wxGetApp().getDeviceManager();
if (!dev_manager) return;
MachineObject* obj_ = dev_manager->get_selected_machine();
if (obj_ && obj_->is_support_ams_mapping()) {
if (m_mapping_popup.IsShown()) return;
wxPoint pos = item->ClientToScreen(wxPoint(0, 0));
pos.y += item->GetRect().height;
m_mapping_popup.Move(pos);
if (obj_ &&
obj_->has_ams() &&
m_checkbox_list["use_ams"]->GetValue() &&
obj_->dev_id == m_printer_last_select)
{
m_mapping_popup.set_parent_item(item);
m_mapping_popup.set_current_filament_id(extruder);
m_mapping_popup.set_tag_texture(materials[extruder]);
m_mapping_popup.update_ams_data(obj_->amsList);
m_mapping_popup.Popup();
}
}
});
Material* material_item = new Material();
material_item->id = extruder;
material_item->item = item;
m_materialList[i] = material_item;
// build for ams mapping
if (extruder < materials.size() && extruder >= 0) {
FilamentInfo info;
info.id = extruder;
info.type = materials[extruder];
info.brand = brands[extruder];
info.filament_id=m_filaments_id[extruder];
info.color = wxString::Format("#%02X%02X%02X%02X", colour_rgb.Red(), colour_rgb.Green(), colour_rgb.Blue(), colour_rgb.Alpha()).ToStdString();
m_filaments.push_back(info);
}
}
if (extruders.size() <= 4) {
m_sizer_material->SetCols(extruders.size());
}
else {
m_sizer_material->SetCols(4);
}
m_scrollable_region->Layout();
m_scrollable_region->Fit();
m_scrollable_view->SetSize(m_scrollable_region->GetSize());
m_scrollable_view->SetMinSize(m_scrollable_region->GetSize());
m_scrollable_view->SetMaxSize(m_scrollable_region->GetSize());
//disable pei bed
DeviceManager* dev_manager = Slic3r::GUI::wxGetApp().getDeviceManager();
if (!dev_manager) return;
MachineObject* obj_ = dev_manager->get_selected_machine();
update_flow_cali_check(obj_);
wxSize screenSize = wxGetDisplaySize();
auto dialogSize = this->GetSize();
#ifdef __WINDOWS__
if (screenSize.GetHeight() < dialogSize.GetHeight()) {
m_need_adaptation_screen = true;
m_scrollable_view->SetScrollRate(0, 5);
m_scrollable_view->SetSize(wxSize(-1, FromDIP(220)));
m_scrollable_view->SetMinSize(wxSize(-1, FromDIP(220)));
m_scrollable_view->SetMaxSize(wxSize(-1, FromDIP(220)));
}
else {
m_scrollable_view->SetScrollRate(0, 0);
}
#endif // __WXOSX_MAC__
reset_ams_material();
// basic info
auto aprint_stats = m_plater->get_partplate_list().get_current_fff_print().print_statistics();
wxString time;
PartPlate* plate = m_plater->get_partplate_list().get_curr_plate();
if (plate) {
if (plate->get_slice_result()) { time = wxString::Format("%s", short_time(get_time_dhms(plate->get_slice_result()->print_statistics.modes[0].time))); }
}
char weight[64];
if (wxGetApp().app_config->get("use_inches") == "1") {
::sprintf(weight, " %.2f oz", aprint_stats.total_weight * 0.035274);
}
else {
::sprintf(weight, " %.2f g", aprint_stats.total_weight);
}
m_stext_time->SetLabel(time);
m_stext_weight->SetLabel(weight);
}
void SelectMachineDialog::set_default_from_sdcard()
{
m_print_plate_total = m_required_data_plate_data_list.size();
update_page_turn_state(true);
ThumbnailData& data = m_required_data_plate_data_list[m_print_plate_idx]->plate_thumbnail;
wxMemoryInputStream mis((unsigned char*)data.pixels.data(), data.pixels.size());
wxImage image = wxImage(mis);
image = image.Rescale(FromDIP(256), FromDIP(256));
m_thumbnailPanel->set_thumbnail(image);
//for black list
std::vector<std::string> materials;
std::vector<std::string> brands;
std::vector<std::string> display_materials;
for (auto i = 0; i < m_required_data_plate_data_list[m_print_plate_idx]->slice_filaments_info.size(); i++) {
FilamentInfo fo = m_required_data_plate_data_list[m_print_plate_idx]->slice_filaments_info[i];
display_materials.push_back(fo.type);
materials.push_back(fo.type);
brands.push_back(fo.brand);
}
//init MaterialItem
MaterialHash::iterator iter = m_materialList.begin();
while (iter != m_materialList.end()) {
int id = iter->first;
Material* item = iter->second;
item->item->Destroy();
delete item;
iter++;
}
m_ams_mapping_result.clear();
m_sizer_material->Clear();
m_materialList.clear();
m_filaments.clear();
for (auto i = 0; i < m_required_data_plate_data_list[m_print_plate_idx]->slice_filaments_info.size(); i++) {
FilamentInfo fo = m_required_data_plate_data_list[m_print_plate_idx]->slice_filaments_info[i];
MaterialItem* item = new MaterialItem(m_scrollable_region, wxColour(fo.color), fo.type);
m_sizer_material->Add(item, 0, wxALL, FromDIP(4));
item->Bind(wxEVT_LEFT_UP, [this, item, materials](wxMouseEvent& e) {});
item->Bind(wxEVT_LEFT_DOWN, [this, item, materials, fo](wxMouseEvent& e) {
MaterialHash::iterator iter = m_materialList.begin();
while (iter != m_materialList.end()) {
int id = iter->first;
Material* item = iter->second;
MaterialItem* m = item->item;
m->on_normal();
iter++;
}
try {
m_current_filament_id = fo.id;
}
catch (...) {}
item->on_selected();
auto mouse_pos = ClientToScreen(e.GetPosition());
wxPoint rect = item->ClientToScreen(wxPoint(0, 0));
// update ams data
DeviceManager* dev_manager = Slic3r::GUI::wxGetApp().getDeviceManager();
if (!dev_manager) return;
MachineObject* obj_ = dev_manager->get_selected_machine();
if (obj_ && obj_->is_support_ams_mapping()) {
if (m_mapping_popup.IsShown()) return;
wxPoint pos = item->ClientToScreen(wxPoint(0, 0));
pos.y += item->GetRect().height;
m_mapping_popup.Move(pos);
if (obj_ &&
obj_->has_ams() &&
m_checkbox_list["use_ams"]->GetValue() &&
obj_->dev_id == m_printer_last_select)
{
m_mapping_popup.set_parent_item(item);
m_mapping_popup.set_current_filament_id(fo.id);
m_mapping_popup.set_tag_texture(fo.type);
m_mapping_popup.update_ams_data(obj_->amsList);
m_mapping_popup.Popup();
}
}
});
Material* material_item = new Material();
material_item->id = fo.id;
material_item->item = item;
m_materialList[i] = material_item;
// build for ams mapping
m_filaments.push_back(fo);
}
if (m_required_data_plate_data_list[m_print_plate_idx]->slice_filaments_info.size() <= 4) {
m_sizer_material->SetCols(m_required_data_plate_data_list[m_print_plate_idx]->slice_filaments_info.size());
}
else {
m_sizer_material->SetCols(4);
}
m_scrollable_region->Layout();
m_scrollable_region->Fit();
m_scrollable_view->SetSize(m_scrollable_region->GetSize());
m_scrollable_view->SetMinSize(m_scrollable_region->GetSize());
m_scrollable_view->SetMaxSize(m_scrollable_region->GetSize());
//disable pei bed
auto bed_type = m_plater->get_partplate_list().get_curr_plate()->get_bed_type(true);
if (bed_type == BedType::btPTE) {
set_flow_calibration_state(false);
}
else {
set_flow_calibration_state(true);
}
wxSize screenSize = wxGetDisplaySize();
auto dialogSize = this->GetSize();
#ifdef __WINDOWS__
if (screenSize.GetHeight() < dialogSize.GetHeight()) {
m_need_adaptation_screen = true;
m_scrollable_view->SetScrollRate(0, 5);
m_scrollable_view->SetSize(wxSize(-1, FromDIP(220)));
m_scrollable_view->SetMinSize(wxSize(-1, FromDIP(220)));
m_scrollable_view->SetMaxSize(wxSize(-1, FromDIP(220)));
}
else {
m_scrollable_view->SetScrollRate(0, 0);
}
#endif // __WXOSX_MAC__
reset_ams_material();
// basic info
try {
float float_time = std::stof(m_required_data_plate_data_list[m_print_plate_idx]->get_gcode_prediction_str());
double float_weight = std::stof(m_required_data_plate_data_list[m_print_plate_idx]->get_gcode_weight_str());
wxString time;
time = wxString::Format("%s", short_time(get_time_dhms(float_time)));
char weight[64];
::sprintf(weight, " %.2f g", float_weight);
m_stext_time->SetLabel(time);
m_stext_weight->SetLabel(weight);
}
catch (...) {}
}
void SelectMachineDialog::update_page_turn_state(bool show)
{
m_bitmap_last_plate->Show(show);
m_bitmap_next_plate->Show(show);
if (show) {
if (m_print_plate_idx <= 0) { m_bitmap_last_plate->Hide(); }
else { m_bitmap_last_plate->Show(); }
if ((m_print_plate_idx + 1) >= m_print_plate_total) { m_bitmap_next_plate->Hide(); }
else { m_bitmap_next_plate->Show(); }
if (m_print_plate_total == 1) {
m_bitmap_last_plate->Show(false);
m_bitmap_next_plate->Show(false);
}
}
}
void SelectMachineDialog::sys_color_changed()
{
if (wxGetApp(). dark_mode()) {
//rename_button->SetIcon("ams_editable_light");
m_rename_button->SetBitmap(ams_editable_light->bmp());
}
else {
m_rename_button->SetBitmap(ams_editable->bmp());
}
m_rename_button->Refresh();
}
bool SelectMachineDialog::Show(bool show)
{
show_status(PrintDialogStatus::PrintStatusInit);
// set default value when show this dialog
if (show) {
wxGetApp().UpdateDlgDarkUI(this);
wxGetApp().reset_to_active();
set_default();
update_user_machine_list();
}
else {
DeviceManager* dev = Slic3r::GUI::wxGetApp().getDeviceManager();
if (dev) {
MachineObject* obj_ = dev->get_selected_machine();
if (obj_ && obj_->connection_type() == "cloud" && m_print_type == FROM_SDCARD_VIEW) {
if (obj_->is_connected()) {
obj_->disconnect();
}
}
}
}
if (show) {
m_refresh_timer->Start(LIST_REFRESH_INTERVAL);
} else {
m_refresh_timer->Stop();
}
Layout();
Fit();
if (show) { CenterOnParent(); }
return DPIDialog::Show(show);
}
SelectMachineDialog::~SelectMachineDialog()
{
delete m_refresh_timer;
}
void SelectMachineDialog::update_lan_machine_list()
{
DeviceManager* dev = wxGetApp().getDeviceManager();
if (!dev) return;
auto m_free_machine_list = dev->get_local_machine_list();
BOOST_LOG_TRIVIAL(trace) << "SelectMachinePopup update_other_devices start";
for (auto& elem : m_free_machine_list) {
MachineObject* mobj = elem.second;
/* do not show printer bind state is empty */
if (!mobj->is_avaliable()) continue;
if (!mobj->is_online()) continue;
if (!mobj->is_lan_mode_printer()) continue;
/*if (mobj->is_in_printing()) {op->set_printer_state(PrinterState::BUSY);}*/
if (mobj->has_access_right()) {
auto b = mobj->dev_name;
// clear machine list
//m_comboBox_printer->Clear();
std::vector<std::string> machine_list;
wxArrayString machine_list_name;
std::map<std::string, MachineObject*> option_list;
// same machine only appear once
/* machine_list = sort_string(machine_list);
for (auto tt = machine_list.begin(); tt != machine_list.end(); tt++) {
for (auto it = option_list.begin(); it != option_list.end(); it++) {
if (it->second->dev_name == *tt) {
m_list.push_back(it->second);
wxString dev_name_text = from_u8(it->second->dev_name);
if (it->second->is_lan_mode_printer()) {
dev_name_text += "(LAN)";
}
machine_list_name.Add(dev_name_text);
break;
}
}
}
m_comboBox_printer->Set(machine_list_name);
MachineObject* obj = dev->get_selected_machine();
if (obj) {
m_printer_last_select = obj->dev_id;
}
else {
m_printer_last_select = "";
}*/
//op->set_printer_state(PrinterState::LOCK);
}
}
BOOST_LOG_TRIVIAL(trace) << "SelectMachineDialog update_lan_devices end";
}
EditDevNameDialog::EditDevNameDialog(Plater *plater /*= nullptr*/)
: DPIDialog(static_cast<wxWindow *>(wxGetApp().mainframe), wxID_ANY, _L("Modifying the device name"), wxDefaultPosition, wxDefaultSize, wxCAPTION | wxCLOSE_BOX)
{
std::string icon_path = (boost::format("%1%/images/OrcaSlicerTitle.ico") % resources_dir()).str();
SetIcon(wxIcon(encode_path(icon_path.c_str()), wxBITMAP_TYPE_ICO));
SetBackgroundColour(*wxWHITE);
wxBoxSizer *m_sizer_main = new wxBoxSizer(wxVERTICAL);
auto m_line_top = new wxPanel(this, wxID_ANY, wxDefaultPosition, wxSize(-1, 1), wxTAB_TRAVERSAL);
m_line_top->SetBackgroundColour(wxColour(166, 169, 170));
m_sizer_main->Add(m_line_top, 0, wxEXPAND, 0);
m_sizer_main->Add(0, 0, 0, wxTOP, FromDIP(38));
m_textCtr = new ::TextInput(this, wxEmptyString, wxEmptyString, wxEmptyString, wxDefaultPosition, wxSize(FromDIP(260), FromDIP(40)), wxTE_PROCESS_ENTER);
m_textCtr->GetTextCtrl()->SetSize(wxSize(-1, FromDIP(22)));
m_textCtr->SetMinSize(wxSize(FromDIP(260), FromDIP(40)));
m_sizer_main->Add(m_textCtr, 0, wxALIGN_CENTER_HORIZONTAL | wxLEFT | wxRIGHT, FromDIP(40));
m_static_valid = new wxStaticText(this, wxID_ANY, wxT(""), wxDefaultPosition, wxDefaultSize, 0);
m_static_valid->Wrap(-1);
m_static_valid->SetFont(::Label::Body_13);
m_static_valid->SetForegroundColour(wxColour(255, 111, 0));
m_sizer_main->Add(m_static_valid, 0, wxALIGN_CENTER_HORIZONTAL | wxTOP | wxLEFT | wxRIGHT, FromDIP(10));
m_button_confirm = new Button(this, _L("Confirm"));
StateColor btn_bg_green(std::pair<wxColour, int>(wxColour(0, 137, 123), StateColor::Pressed), std::pair<wxColour, int>(wxColour(0, 150, 136), StateColor::Normal));
m_button_confirm->SetBackgroundColor(btn_bg_green);
m_button_confirm->SetBorderColor(wxColour(0, 150, 136));
m_button_confirm->SetTextColor(wxColour(255, 255, 255));
m_button_confirm->SetSize(wxSize(FromDIP(72), FromDIP(24)));
m_button_confirm->SetMinSize(wxSize(FromDIP(72), FromDIP(24)));
m_button_confirm->SetCornerRadius(FromDIP(12));
m_button_confirm->Bind(wxEVT_BUTTON, &EditDevNameDialog::on_edit_name, this);
m_sizer_main->Add(m_button_confirm, 0, wxALIGN_CENTER_HORIZONTAL | wxTOP, FromDIP(10));
m_sizer_main->Add(0, 0, 0, wxBOTTOM, FromDIP(38));
SetSizer(m_sizer_main);
Layout();
Fit();
Centre(wxBOTH);
wxGetApp().UpdateDlgDarkUI(this);
}
EditDevNameDialog::~EditDevNameDialog() {}
void EditDevNameDialog::set_machine_obj(MachineObject *obj)
{
m_info = obj;
if (m_info)
m_textCtr->GetTextCtrl()->SetValue(from_u8(m_info->dev_name));
}
void EditDevNameDialog::on_dpi_changed(const wxRect &suggested_rect)
{
m_button_confirm->SetSize(wxSize(FromDIP(72), FromDIP(24)));
m_button_confirm->SetMinSize(wxSize(FromDIP(72), FromDIP(24)));
}
void EditDevNameDialog::on_edit_name(wxCommandEvent &e)
{
m_static_valid->SetLabel(wxEmptyString);
auto m_valid_type = Valid;
wxString info_line;
auto new_dev_name = m_textCtr->GetTextCtrl()->GetValue();
const char * unusable_symbols = "<>[]:/\\|?*\"";
const std::string unusable_suffix = PresetCollection::get_suffix_modified();
for (size_t i = 0; i < std::strlen(unusable_symbols); i++) {
if (new_dev_name.find_first_of(unusable_symbols[i]) != std::string::npos) {
info_line = _L("Name is invalid;") + _L("illegal characters:") + " " + unusable_symbols;
m_valid_type = NoValid;
break;
}
}
if (m_valid_type == Valid && new_dev_name.find(unusable_suffix) != std::string::npos) {
info_line = _L("Name is invalid;") + _L("illegal suffix:") + "\n\t" + from_u8(PresetCollection::get_suffix_modified());
m_valid_type = NoValid;
}
if (m_valid_type == Valid && new_dev_name.empty()) {
info_line = _L("The name is not allowed to be empty.");
m_valid_type = NoValid;
}
if (m_valid_type == Valid && new_dev_name.find_first_of(' ') == 0) {
info_line = _L("The name is not allowed to start with space character.");
m_valid_type = NoValid;
}
if (m_valid_type == Valid && new_dev_name.find_last_of(' ') == new_dev_name.length() - 1) {
info_line = _L("The name is not allowed to end with space character.");
m_valid_type = NoValid;
}
if (m_valid_type == NoValid) {
m_static_valid->SetLabel(info_line);
Layout();
}
if (m_valid_type == Valid) {
m_static_valid->SetLabel(wxEmptyString);
DeviceManager *dev = Slic3r::GUI::wxGetApp().getDeviceManager();
if (dev) {
auto utf8_str = new_dev_name.ToUTF8();
auto name = std::string(utf8_str.data(), utf8_str.length());
if (m_info)
dev->modify_device_name(m_info->dev_id, name);
}
DPIDialog::EndModal(wxID_CLOSE);
}
}
ThumbnailPanel::ThumbnailPanel(wxWindow *parent, wxWindowID winid, const wxPoint &pos, const wxSize &size)
: wxPanel(parent, winid, pos, size)
{
#ifdef __WINDOWS__
SetDoubleBuffered(true);
#endif //__WINDOWS__
SetBackgroundStyle(wxBG_STYLE_CUSTOM);
wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
m_staticbitmap = new wxStaticBitmap(parent, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxDefaultSize);
m_background_bitmap = ScalableBitmap(this,"thumbnail_grid",256);
sizer->Add(m_staticbitmap, 1, wxEXPAND, 0);
Bind(wxEVT_PAINT, &ThumbnailPanel::OnPaint, this);
SetSizer(sizer);
Layout();
Fit();
}
void ThumbnailPanel::set_thumbnail(wxImage img)
{
m_bitmap = img;
//Paint the background bitmap to the thumbnail bitmap with wxMemoryDC
wxMemoryDC dc;
bitmap_with_background.Create(wxSize(m_bitmap.GetWidth(), m_bitmap.GetHeight()));
dc.SelectObject(bitmap_with_background);
dc.DrawBitmap(m_background_bitmap.get_bitmap(), 0, 0);
dc.DrawBitmap(m_bitmap, 0, 0);
dc.SelectObject(wxNullBitmap);
}
void ThumbnailPanel::OnPaint(wxPaintEvent& event) {
wxPaintDC dc(this);
render(dc);
}
void ThumbnailPanel::render(wxDC& dc) {
if (wxGetApp().dark_mode()) {
#ifdef __WXMSW__
wxMemoryDC memdc;
wxBitmap bmp(GetSize());
memdc.SelectObject(bmp);
memdc.DrawBitmap(bitmap_with_background, 0, 0);
dc.Blit(0, 0, GetSize().GetWidth(), GetSize().GetHeight(), &memdc, 0, 0);
#else
dc.DrawBitmap(bitmap_with_background, 0, 0);
#endif
}
else
dc.DrawBitmap(m_bitmap, 0, 0);
}
ThumbnailPanel::~ThumbnailPanel() {}
}} // namespace Slic3r::GUI