OrcaSlicer/src/slic3r/GUI/CreatePresetsDialog.cpp
SoftFever d8dd8fa634
Feature/bs1.8beta (#2844)
* ENH: Show Recent File Image Keep Scale

Change-Id: Ib8a6cf916eaee8e353bf858bc4f2ea503705809e

* FIX: wipetower position problem

jira: STUDIO-4914

Change-Id: I7b05d3c53931ed8ce3d4603ff21ee6ef675611e5

* FIX: dailytips adapts screen scale

jira: STUDIO-5019 STUDIO-5026 STUDIO-5027 STUDIO-5028 STUDIO-5025

Change-Id: I63d3af1870218ba8e0f048a6ef03fb29fabe27cb

* FIX: generate process preset based on template

Jira: XXXX

Change-Id: I50adf0790dc239307d236a4cebece860ef6beb16
Signed-off-by: maosheng.wei <maosheng.wei@bambulab.com>

* FIX: object list plate name edit

Change-Id: I61d3dcd7d9598d759a3a0b44cc77d2af2adca25a
Jira: STUDIO-4937

* ENH:no longer checking nozzle type

jira:[for nozzle type check]

Change-Id: I0e88445a264f21b0c11519e9a22a165d05611d14

* ENH: improve first layer tree support

First layer support can't be top interface, and
min brim width of auto mode should be larger
than 0.

Jira: STUDIO-5010
Change-Id: I02f8b017b535f8a47965387e8679f692b1966e04
(cherry picked from commit 3e7d54abe352e8ab5f9d6492b5a86a96f9067f94)

* ENH: version: bumped to 1.8

JIRA: no jira
Change-Id: I50903098b59f1dd9a6b6cf7656cec7d388f3ff17

* ENH:try again after subscription failure

jira:[Try again after subscription failure]

Change-Id: Ibfb1e8e26eb166d786a372632a86ef98030db034

* ENH:display msg dialog once

jira:[for http error msg]

Change-Id: I12e9c155fdb567cac99c35b6feeef650269ba75d

* ENH:remove config.json file

Change-Id: Idfcf3a63fefe968e88153c26fb691fd05cd83dc4

* ENH:add protection in threads

jira:[for random crash]

Change-Id: I6286012dd77abccba461f7cd72a6fc531a84c95f

* FIX: add protection for get_model_task_thread thread

Jira: XXXX

Change-Id: I3cbc17d181a0e13c658f31eaeb6a4df878e6df41
Signed-off-by: maosheng.wei <maosheng.wei@bambulab.com>

* FIX: delete all compatible presets when delete third printer

Jira: XXXX

Change-Id: I1a294402627e7ab7a8c6701f20679b3d04aff059
Signed-off-by: maosheng.wei <maosheng.wei@bambulab.com>

* ci: update build version to 01.08.00.51

Change-Id: I20a01adacbdb5fe69c106b9efd029f7308136e10

* ENH: default open support_interface_not_for_body

jira:[NEW]

Signed-off-by: xun.zhang <xun.zhang@bambulab.com>
Change-Id: I48e084deb18633f9ec47a8ec4ec643163bf66318

* ENH:modified text with too low version

jira:[for low version]

Change-Id: I862a0defda976a35f326a8805e002330f2ed7fdf

* NEW:update printer config file version

Change-Id: I9a46b29b03beb67a3da0b8f76d8b5c4b3c482928

* FIX:The plane should rotate around the world coordinate system

Jira: STUDIO-5054
Change-Id: I16e484b38d79cabd9473acf1abf3c5c6b0adc4c6

* ENH:translate for limit file size and so on

Jira: STUDIO-5007
Change-Id: I2c279eb690841aa51cd8128f8028266cbc17e977

* ENH:use on_render_rotate_gizmos() replace GLGizmoRotate3D::on_render()

Jira: STUDIO-4227
Change-Id: If9b9ea5596e59472d5fa87ac56aeb7f6ecc65643

* FIX: some mistakes in filament profiles

jira:[NEW]

Signed-off-by: xun.zhang <xun.zhang@bambulab.com>
Change-Id: Ibe7f3650f2d9cf47561dd5f2ec591a5f6c553503

* FIX: fix shard_ptr is null

Change-Id: I0187cf64ffbb08a2265a11900b5c865e9ac9678f

* FIX:N1 printer image in dark mode

JIRA:STUDIO-4057
Change-Id: I22c001d96839daf213d5096f6ff6e3d6398fa8c4

* FIX: create printer issue

Jira: 5034 5059 5053
5034 create printer but filament is repeat
5039 create successful dialog remove to center
5053 create existing printer copywriting adjustments and preset updates
Delete printer secondary confirmation dialog

Change-Id: Ifb3822d1e168459d2af11e02b31ecaf3719d338a
Signed-off-by: maosheng.wei <maosheng.wei@bambulab.com>

* ENH:just don't check the nozzle diameter

jira:[for nozzle check]

Change-Id: I678e7d62832eaa14b9be47d6dce70f29ebd601f6

* NEW:p1 and x1 series added motor noise calibration

JIRA: 5085
Change-Id: Id73cc2d34b6130f215d81ffcdc39ba6b241445bf

* ci: update build version to 01.08.00.52

Change-Id: I93d800b413f2751d132fac53fbd9b191603d0352

* FIX: ObjectSetting changed when search plate

JIRA: STUDIO-5095

Signed-off-by: Kunlong Ma <kunlong.ma@bambulab.com>
Change-Id: I39b1ad997d51ac4224ff5ad2b3555f56da4bd911

* FIX: invalid support params in 3rd party profiles

Many params are not right.Just use default

jira:[NEW]

Signed-off-by: xun.zhang <xun.zhang@bambulab.com>
Change-Id: I5c4a1e8b046940e174f5681a79031b5f20fcafc5

* ENH: update A1 mini start gcode

Change x-axis freq sweep amp 5->10

jira:[NEW]

Signed-off-by: xun.zhang <xun.zhang@bambulab.com>
Change-Id: I2e731cc6392c0204d5e4467bf4b933ab233bc157

* FIX: [STUDIO-4946] use utf8 path to create sub process

Change-Id: I5873c114e8cd36978a7d50bf13c3aa7bf8b740ca
Jira: STUDIO-4946

* FIX: fix a plate state not correct issue

JIRA: no-jira
the object and instance states lost after undo

Change-Id: I527df9a7d426d994501a4ed5bbb198c7bbac810b

* FIX: some translation

Jira: 5096 5089 5036 5004

Change-Id: I4f1bd6e352b11451f5caf02cbc4eeb31dfa03eee
Signed-off-by: maosheng.wei <maosheng.wei@bambulab.com>

* FIX: [STUDIO-4935] plate name edit in object list

Change-Id: I271fa217281d0c7ceca61166497136628a66681e
Jira: STUDIO-4935

* FIX: take custom root as AMS sync candicate

Change-Id: I9c71babcd74238d1533b15d77a978b19997c70c0
Jira: none

* FIX: modify some default support params in code

1. Modify default values of some supports params, so 3rd party profiles are easier to setup.
3. Fix a bug that organic support may cause crash.

Jira: none

Change-Id: Icae348d8fe5985f4287404e96089198a499283f2
(cherry picked from commit 8889cfc703b72e142f288e525b89c87619f2213c)

* FIX: do not generate sheath for normal support

Jira: none
Change-Id: I8f3f3e39171055f8d18c06ceee8e245594273238
(cherry picked from commit 93bc7ecf4346f179f502bebc3cf47b0030b56e2c)

* FIX: push_notification on GUI thread

Change-Id: Iaec347f5684fe0f65d6418759518189b67033c42
Jira: STUDIO-5106

* ENH: CLI: add some params to support more functions

1. uptodate_filaments to support update the original filaments to newest config
2. allow_rotations/avoid_extrusion_cali_region for auto-arrange
3. skip_modified_gcodes to support skip modified gcodes

JIRA: STUDIO-5112
Change-Id: I95c09af1b5462cce3bf27aea32228d6d1d1d201d

* FIX: missed manually entered values for secondary processing

Jira: STUDIO-4964
Change-Id: I5cf0da1ae77cccd34de05b4a0318a751ac9f6753

* FIX: Z hop is still enabled when upper boundary is zero.

Jira: STUDIO-4893

Signed-off-by: wenjie.guo <wenjie.guo@bambulab.com>
Change-Id: I5f46a02e1fbb15ff43e253e3a184aa6cc38e7598

* ENH: update default filaments for Bambu printers

jira:[NEW]

Signed-off-by: xun.zhang <xun.zhang@bambulab.com>
Change-Id: Ic6380f39e546854ad0b7dc36929a8605c9ab3acc

* ENH: dailytips modification

1. modify closing behavior
2. dailytips can adjust self size according to the canvas size. And also adjust
   GodeViewer legend window size
3. fix a button text encoding bug
4. support vertical/horizontal layout(horizontal layout currently not used)

jira: new

Change-Id: I8e0b6e85c455d0608d7388fb441829c1991ad01f

* FIX: [4857 5097] export list and del preset two confirm issue

Jira: 4857 5097

Change-Id: If7cc4967a663f575527a227e9c4ac31e0491930c

* FIX: UUID conflict issue when referencing volume

Jira: XXXX
3mf file standard

Change-Id: I953a87294684ea85d03a95e7d2843c096904aeae
Signed-off-by: maosheng.wei <maosheng.wei@bambulab.com>

* FIX: [4483 5003 5109] create printer and edit filament issue

Jira: 4483 5003 5109
4483 dialog blink
5003 preset list too long
5109 encode

Change-Id: I190e12272ca09f36b841f2f85a6cf60f2c2614bd
Signed-off-by: maosheng.wei <maosheng.wei@bambulab.com>

* FIX: cloud use presets limit notify

Change-Id: I6cc7b4e560cb83db0fc30921633b10531957128e
Jira: STUDIO-5091, STUDIO-5104

* FIX: do user preset sync later on startup

Change-Id: I0653a0438477b1c803ce1cddc66ef47f95616dae
Jira: STUDIO-5106

* FIX: linux: pressing enter in height range will crash

jira: STUDIO-4391
Change-Id: I6bf990951d1456f5b2605b8d62a05bceb3cc4c10

* FIX: failed to limit the max width of DropDown

Jira: STUDIO-4503

Signed-off-by: wenjie.guo <wenjie.guo@bambulab.com>
Change-Id: Id9352d16f4bc016daade72a9c8d3d90164a1cb3d

* FIX: not jump to preview after first wizard

Change-Id: I8c94d66a91aa15a7874441a300b40438638bd33b
Jira: STUDIO-5018

* ENH: CLI: clear custom gcodes when skip_modified_gcodes

JIRA: STUDIO-5112
Change-Id: I2e7346d2ac57519029a4e80e5492c34d3d91ed77

* FIX: [4492 4851 4883 5121] create printer issue

Jira: 4492 4851 4883 5121

Change-Id: If252b5f30be0403f79410aa8c00fc14b066d5bbd
Signed-off-by: maosheng.wei <maosheng.wei@bambulab.com>

* ENH: add 'edit preset' and 'delete preset' btn for each preset

Jira: 5200 5113

Change-Id: I208ad63eb4b895306fa76db424da2e1df10a582e
Signed-off-by: maosheng.wei <maosheng.wei@bambulab.com>

* FIX: add skip label before tool change

Jira: 5074
github: 2776

Signed-off-by: qing.zhang <qing.zhang@bambulab.com>
Change-Id: Icaafd3b45da1e78c1a82e7d17d7505d9439b9100

* FIX:Network test dark mode adaptation

JIRA:STUDIO-2468
Change-Id: I20cb7f1fd8eca3ce852acb563c1cc87978e216dc

* FIX:n1 external feed prompt pop-up without retry button

JIRA: STUDIO-4696
Change-Id: I31069c72e29d3398469d71cdbc2a344a5430fc2c

* FIX: not show device page when switch printer preset

Change-Id: I00d8524625a4682b6a39876ddb66bf8bd928dbef
Jira: none

* ENH: Check the nozzle diameter when sending calibration

Jira: 4977
Change-Id: Iabbba44583bbd9fbaaa889ca546ee0ccbb2aa77f

* FIX: Generate UUID from objectID and volumeIndex

Jira: XXXX

Change-Id: I65147ef9b695f8af8de260d722e604b0e0bab563
Signed-off-by: maosheng.wei <maosheng.wei@bambulab.com>

* FIX: disable filament_typep

Jira: XXXX

Change-Id: Ib605b33e4474525fbe49e70596fc09aa356f478a
Signed-off-by: maosheng.wei <maosheng.wei@bambulab.com>

* ci: update build version to 01.08.00.53

Change-Id: I1d574fa2cf2a4d0eb63a38eb8ced7587d06a4272

* ENH: refine display logic of param

1. Refine the display logic of "support_interface_not_for_body".Only
toggle if support_filament is default and support_interface_filament
is specified

jira:[NEW]

Signed-off-by: xun.zhang <xun.zhang@bambulab.com>
Change-Id: Ia2af030c4531ad6b04a198bfe8a1677b3d20a800

* 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 linux

* fix some string and colors

* fix linux build error 2

* fix .gitignore

* 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

* add new feature to localization .de, fix .it (#2876)

* 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

---------

Signed-off-by: maosheng.wei <maosheng.wei@bambulab.com>
Signed-off-by: xun.zhang <xun.zhang@bambulab.com>
Signed-off-by: Kunlong Ma <kunlong.ma@bambulab.com>
Signed-off-by: wenjie.guo <wenjie.guo@bambulab.com>
Signed-off-by: qing.zhang <qing.zhang@bambulab.com>
Signed-off-by: Stone Li <stone.li@bambulab.com>
Signed-off-by: zhou.xu <zhou.xu@bambulab.com>
Co-authored-by: zorro.zhang <zorro.zhang@bambulab.com>
Co-authored-by: liz.li <liz.li@bambulab.com>
Co-authored-by: maosheng.wei <maosheng.wei@bambulab.com>
Co-authored-by: chunmao.guo <chunmao.guo@bambulab.com>
Co-authored-by: tao wang <tao.wang@bambulab.com>
Co-authored-by: Arthur <arthur.tang@bambulab.com>
Co-authored-by: lane.wei <lane.wei@bambulab.com>
Co-authored-by: gerrit <gerrit@bambulab.com>
Co-authored-by: xun.zhang <xun.zhang@bambulab.com>
Co-authored-by: zhou.xu <zhou.xu@bambulab.com>
Co-authored-by: hu.wang <hu.wang@bambulab.com>
Co-authored-by: Kunlong Ma <kunlong.ma@bambulab.com>
Co-authored-by: wenjie.guo <wenjie.guo@bambulab.com>
Co-authored-by: qing.zhang <qing.zhang@bambulab.com>
Co-authored-by: zhimin.zeng <zhimin.zeng@bambulab.com>
Co-authored-by: the Raz <rasmus@abc.se>
Co-authored-by: Andy <andylg@yandex.ru>
Co-authored-by: Stone Li <stone.li@bambulab.com>
Co-authored-by: enricoturri1966 <enricoturri@seznam.cz>
Co-authored-by: Dmytro Chystiakov <dlchistyakov@gmail.com>
Co-authored-by: Heiko Liebscher <hliebscher@idn.de>
2023-12-01 10:42:45 +00:00

4993 lines
258 KiB
C++

#include "CreatePresetsDialog.hpp"
#include <vector>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <openssl/md5.h>
#include <openssl/evp.h>
#include <wx/dcgraph.h>
#include "libslic3r/PresetBundle.hpp"
#include "I18N.hpp"
#include "GUI_App.hpp"
#include "MsgDialog.hpp"
#include "FileHelp.hpp"
#include "Tab.hpp"
#include "MainFrame.hpp"
#define NAME_OPTION_COMBOBOX_SIZE wxSize(FromDIP(200), FromDIP(24))
#define FILAMENT_PRESET_COMBOBOX_SIZE wxSize(FromDIP(300), FromDIP(24))
#define OPTION_SIZE wxSize(FromDIP(100), FromDIP(24))
#define PRINTER_LIST_SIZE wxSize(-1, FromDIP(100))
#define FILAMENT_LIST_SIZE wxSize(FromDIP(560), FromDIP(100))
#define FILAMENT_OPTION_SIZE wxSize(FromDIP(-1), FromDIP(30))
#define PRESET_TEMPLATE_SIZE wxSize(FromDIP(-1), FromDIP(100))
#define PRINTER_SPACE_SIZE wxSize(FromDIP(80), FromDIP(24))
#define ORIGIN_TEXT_SIZE wxSize(FromDIP(10), FromDIP(24))
#define PRINTER_PRESET_VENDOR_SIZE wxSize(FromDIP(150), FromDIP(24))
#define PRINTER_PRESET_MODEL_SIZE wxSize(FromDIP(280), FromDIP(24))
#define STATIC_TEXT_COLOUR wxColour("#363636")
#define PRINTER_LIST_COLOUR wxColour("#EEEEEE")
#define FILAMENT_OPTION_COLOUR wxColour("#D9D9D9")
#define SELECT_ALL_OPTION_COLOUR wxColour("#009688")
#define DEFAULT_PROMPT_TEXT_COLOUR wxColour("#ACACAC")
namespace Slic3r {
namespace GUI {
static const std::vector<std::string> filament_vendors = {"Polymaker", "OVERTURE", "Kexcelled", "HATCHBOX", "eSUN", "SUNLU", "Prusament", "Creality", "Protopasta",
"Anycubic", "Basf", "ELEGOO", "INLAND", "FLASHFORGE", "AMOLEN", "MIKA3D", "3DXTECH", "Duramic",
"Priline", "Eryone", "3Dgunius", "Novamaker", "Justmaker", "Giantarm", "iProspect"};
static const std::vector<std::string> filament_types = {"PLA", "PLA+", "PLA Tough", "PETG", "ABS", "ASA", "FLEX", "HIPS", "PA", "PACF",
"NYLON", "PVA", "PC", "PCABS", "PCTG", "PCCF", "PP", "PEI", "PET", "PETG",
"PETGCF", "PTBA", "PTBA90A", "PEEK", "TPU93A", "TPU75D", "TPU", "TPU92A", "TPU98A", "Misc",
"TPE", "GLAZE", "Nylon", "CPE", "METAL", "ABST", "Carbon Fiber"};
static const std::vector<std::string> system_filament_types = {"PLA", "ABS", "TPU", "PC", "ASA", "PA-CF", "PA6-CF", "PET-CF", "PETG", "PETG-CF",
"PLA Aero", "PLA-CF", "PPA-CF", "PPA-GF", "PA", "HIPS", "PPS", "PPS-CF", "PVA"};
static std::unordered_map<std::string, std::string> system_filament_types_map = {{"PLA", "PLA"}, {"ABS", "ABS"}, {"TPU", "TPU"},
{"PC", "PC"}, {"ASA", "ASA"}, {"PA-CF", "PA-CF"},
{"PA6-CF", "PA6-CF"}, {"PET-CF", "PET-CF"}, {"PETG", "PETG"},
{"PETG-CF", "PETG-CF"}, {"PLA Aero", "PLA-AERO"}, {"PLA-CF", "PLA-CF"},
{"PPA-CF", "PPA-CF"}, {"PPA-GF", "PPA-GF"}, {"PA", "PA"},
{"HIPS", "HIPS"}, {"PPS", "PPS"}, {"PPS-CF", "PPS-CF"},
{"PVA", "PVA"}};
static const std::vector<std::string> printer_vendors = {"Anycubic", "Artillery", "BIBO", "BIQU", "Creality ENDER", "Creality CR", "Creality SERMOON",
"FLSun", "gCreate", "Geeetech", "INAT", "Infinity3D", "Jubilee", "LNL3D",
"LulzBot", "MakerGear", "Original Prusa", "Papapiu", "Print4Taste", "RatRig", "Rigid3D",
"Snapmaker", "Sovol", "TriLAB", "Trimaker", "Ultimaker", "Voron", "Zonestar"};
static const std::unordered_map<std::string, std::vector<std::string>> printer_model_map =
{{"Anycubic", {"Kossel Linear Plus", "Kossel Pulley(Linear)", "Mega Zero", "i3 Mega", "Predator"}},
{"Artillery", {"sidewinder X1", "Genius", "Hornet"}},
{"BIBO", {"BIBO2 Touch"}},
{"BIQU", {"BX"}},
{"Creality ENDER", {"Ender-3", "Ender-3 BLTouch", "Ender-3 Pro", "Ender-3 Neo",
"Ender-3 V2 Neo", "Ender-3 S1 Plus", "Ender-3 Max", "Ender-3 Max Neo",
"Ender-4", "Ender-5 Pro", "Ender-5 Pro",
"Ender-7", "Ender-2", "Ender-2 Pro"}},
{"Creality CR", {"CR-5 Pro", "CR-5 Pro H", "CR-10 SMART", "CR-10 SMART Pro", "CR-10 Mini",
"CR-10", "CR-10 v3", "CR-10 S", "CR-10 v2", "CR-10 v2",
"CR-10 S Pro", "CR-10 S Pro v2", "CR-10 S4", "CR-10 S5", "CR-20", "CR-20 Pro", "CR-200B",
"CR-8"}},
{"Creality SERMOON",{"Sermoon-D1", "Sermoon-V1", "Sermoon-V1 Pro"}},
{"FLSun", {"FLSun QQs Pro", "FLSun Q5"}},
{"gCreate", {"gMax 1.5XT Plus", "gMax 2", "gMax 2 Pro", "gMax 2 Dual 2in1", "gMax 2 Dual Chimera"}},
{"Geeetech", {"Thunder", "Thunder Pro", "Mizar s", "Mizar Pro", "Mizar", "Mizar Max",
"Mizar M", "A10 Pro", "A10 M", "A10 T", "A20", "A20 M",
"A20T", "A30 Pro", "A30 M", "A30 T", "E180", "Me Ducer",
"Me creator", "Me Creator2", "GiantArmD200", "l3 ProB", "l3 Prow", "l3 ProC"}},
{"INAT", {"Proton X Rail", "Proton x Rod", "Proton XE-750"}},
{"Infinity3D", {"DEV-200", "DEV-350"}},
{"Jubilee", {"Jubilee"}},
{"LNL3D", {"D3 v2", "D3 Vulcan", "D5", "D6"}},
{"LulzBot", {"Mini Aero", "Taz6 Aero"}},
{"MakerGear", {"Micro", "M2(V4 Hotend)", "M2 Dual", "M3-single Extruder", "M3-Independent Dual Rev.0", "M3-Independent Dual Rev.0(Duplication Mode)",
"M3-Independent Dual Rev.1", "M3-Independent Dual Rev.1(Duplication Mode)", "ultra One", "Ultra One (DuplicationMode)"}},
{"Original Prusa", {"MK4", "SL1S SPEED", "MMU3"}},
{"Papapiu", {"N1s"}},
{"Print4Taste", {"mycusini 2.0"}},
{"RatRig", {"V-core-3 300mm", "V-Core-3 400mm", "V-Core-3 500mm", "V-Minion"}},
{"Rigid3D", {"Zero2", "Zero3"}},
{"Snapmaker", {"A250", "A350"}},
{"Sovol", {"SV06", "SV06 PLUS", "SV05", "SV04", "SV03 / SV03 BLTOUCH", "SVO2 / SV02 BLTOUCH", "SVO1 / SV01 BLToUCH", "SV01 PRO"}},
{"TriLAB", {"AzteQ Industrial","AzteQ Dynamic", "DeltiQ 2", "DeltiQ 2 Plus", "DeltiQ 2 + FlexPrint 2", "DeltiQ 2 Plus + FlexPrint 2", "DeltiQ 2 +FlexPrint",
"DeltiQ 2 Plus + FlexPrint", "DeltiQ M", "DeltiQ L", "DeltiQ XL"}},
{"Trimaker", {"Nebula cloud", "Nebula", "Cosmos ll"}},
{"Ultimaker", {"Ultimaker 2"}},
{"Voron", {"v2 250mm3", "v2 300mm3", "v2 350mm3", "v1 250mm3", "v1 300mm3", "v1 350mm3",
"Zero 120mm3", "Switchwire"}},
{"Zonestar", {"Z5", "Z6", "Z5x", "Z8", "Z9"}}};
static std::vector<std::string> nozzle_diameter_vec = {"0.4", "0.2", "0.25", "0.3", "0.35", "0.5", "0.6", "0.75", "0.8", "1.0", "1.2"};
static std::unordered_map<std::string, float> nozzle_diameter_map = {{"0.2", 0.2}, {"0.25", 0.25}, {"0.3", 0.3}, {"0.35", 0.35},
{"0.4", 0.4}, {"0.5", 0.5}, {"0.6", 0.6}, {"0.75", 0.75},
{"0.8", 0.8}, {"1.0", 1.0}, {"1.2", 1.2}};
static std::set<int> cannot_input_key = {9, 10, 13, 33, 35, 36, 37, 38, 40, 41, 42, 44, 46, 47, 59, 60, 62, 63, 64, 92, 94, 95, 124, 126};
static std::set<char> special_key = {'\n', '\t', '\r', '\v', '@', ';'};
static std::string remove_special_key(const std::string &str)
{
std::string res_str;
for (char c : str) {
if (special_key.find(c) == special_key.end()) {
res_str.push_back(c);
}
}
return res_str;
}
static bool delete_filament_preset_by_name(std::string delete_preset_name, std::string &selected_preset_name)
{
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format("select preset, name %1%") % delete_preset_name;
if (delete_preset_name.empty()) return false;
// Find an alternate preset to be selected after the current preset is deleted.
PresetCollection &m_presets = wxGetApp().preset_bundle->filaments;
if (delete_preset_name == selected_preset_name) {
const std::deque<Preset> &presets = m_presets.get_presets();
size_t idx_current = m_presets.get_idx_selected();
// Find the visible preset.
size_t idx_new = idx_current;
if (idx_current > presets.size()) idx_current = presets.size();
if (idx_current < 0) idx_current = 0;
if (idx_new < presets.size())
for (; idx_new < presets.size() && (presets[idx_new].name == delete_preset_name || !presets[idx_new].is_visible); ++idx_new)
;
if (idx_new == presets.size())
for (idx_new = idx_current - 1; idx_new > 0 && (presets[idx_new].name == delete_preset_name || !presets[idx_new].is_visible); --idx_new)
;
selected_preset_name = presets[idx_new].name;
BOOST_LOG_TRIVIAL(info) << boost::format("cause by delete current ,choose the next visible, idx %1%, name %2%") % idx_new % selected_preset_name;
}
try {
// BBS delete preset
Preset *need_delete_preset = m_presets.find_preset(delete_preset_name);
if (!need_delete_preset) BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(" can't find delete preset and name: %1%") % delete_preset_name;
if (!need_delete_preset->setting_id.empty()) {
BOOST_LOG_TRIVIAL(info) << "delete preset = " << need_delete_preset->name << ", setting_id = " << need_delete_preset->setting_id;
m_presets.set_sync_info_and_save(need_delete_preset->name, need_delete_preset->setting_id, "delete", 0);
wxGetApp().delete_preset_from_cloud(need_delete_preset->setting_id);
} else {
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(" can't preset setting id is empty and name: %1%") % delete_preset_name;
}
if (m_presets.get_edited_preset().name == delete_preset_name) {
m_presets.discard_current_changes();
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format("delete preset dirty and cancelled");
}
m_presets.delete_preset(need_delete_preset->name);
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " preset has been delete from filaments, and preset name is: " << delete_preset_name;
} catch (const std::exception &ex) {
// FIXME add some error reporting!
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format("found exception when delete: %1% and preset name: %%") % ex.what() % delete_preset_name;
return false;
}
return true;
}
static std::string get_curr_time()
{
std::chrono::system_clock::time_point now = std::chrono::system_clock::now();
std::time_t time = std::chrono::system_clock::to_time_t(now);
std::tm local_time = *std::localtime(&time);
std::ostringstream time_stream;
time_stream << std::put_time(&local_time, "%Y_%m_%d_%H_%M_%S");
std::string current_time = time_stream.str();
return current_time;
}
static std::string get_curr_timestmp()
{
std::time_t currentTime = std::time(nullptr);
std::ostringstream oss;
oss << currentTime;
std::string timestampString = oss.str();
return timestampString;
}
static void get_filament_compatible_printer(Preset* preset, vector<std::string>& printers)
{
auto compatible_printers = dynamic_cast<ConfigOptionStrings *>(preset->config.option("compatible_printers"));
if (compatible_printers == nullptr) return;
for (const std::string &printer_name : compatible_printers->values) {
printers.push_back(printer_name);
}
}
static wxBoxSizer* create_checkbox(wxWindow* parent, Preset* preset, wxString& preset_name, std::vector<std::pair<::CheckBox*, Preset*>>& preset_checkbox)
{
wxBoxSizer *sizer = new wxBoxSizer(wxHORIZONTAL);
::CheckBox * checkbox = new ::CheckBox(parent);
sizer->Add(checkbox, 0, 0, 0);
preset_checkbox.push_back(std::make_pair(checkbox, preset));
wxStaticText *preset_name_str = new wxStaticText(parent, wxID_ANY, preset_name);
wxToolTip * toolTip = new wxToolTip(preset_name);
preset_name_str->SetToolTip(toolTip);
sizer->Add(preset_name_str, 0, wxLEFT, 5);
return sizer;
}
static wxBoxSizer *create_checkbox(wxWindow *parent, std::string &compatible_printer, Preset* preset, std::unordered_map<::CheckBox *, std::pair<std::string, Preset *>> &ptinter_compatible_filament_preset)
{
wxBoxSizer *sizer = new wxBoxSizer(wxHORIZONTAL);
::CheckBox *checkbox = new ::CheckBox(parent);
sizer->Add(checkbox, 0, 0, 0);
ptinter_compatible_filament_preset[checkbox] = std::make_pair(compatible_printer, preset);
wxStaticText *preset_name_str = new wxStaticText(parent, wxID_ANY, wxString::FromUTF8(compatible_printer));
sizer->Add(preset_name_str, 0, wxLEFT, 5);
return sizer;
}
static wxBoxSizer *create_checkbox(wxWindow *parent, wxString &preset_name, std::vector<std::pair<::CheckBox *, std::string>> &preset_checkbox)
{
wxBoxSizer *sizer = new wxBoxSizer(wxHORIZONTAL);
::CheckBox *checkbox = new ::CheckBox(parent);
sizer->Add(checkbox, 0, 0, 0);
preset_checkbox.push_back(std::make_pair(checkbox, into_u8(preset_name)));
wxStaticText *preset_name_str = new wxStaticText(parent, wxID_ANY, preset_name);
sizer->Add(preset_name_str, 0, wxLEFT, 5);
return sizer;
}
static wxArrayString get_exist_vendor_choices(VendorMap& vendors)
{
wxArrayString choices;
PresetBundle temp_preset_bundle;
temp_preset_bundle.load_system_models_from_json(ForwardCompatibilitySubstitutionRule::EnableSystemSilent);
PresetBundle *preset_bundle = wxGetApp().preset_bundle;
VendorProfile users_models = preset_bundle->get_custom_vendor_models();
vendors = temp_preset_bundle.vendors;
if (!users_models.models.empty()) {
vendors[users_models.name] = users_models;
}
for (const pair<std::string, VendorProfile> &vendor : vendors) {
if (vendor.second.models.empty() || vendor.second.id.empty()) continue;
choices.Add(vendor.first);
}
return choices;
}
static std::string get_machine_name(const std::string &preset_name)
{
size_t index_at = preset_name.find_last_of("@");
if (std::string::npos == index_at) {
return "";
} else {
return preset_name.substr(index_at + 1);
}
}
static std::string get_filament_name(std::string &preset_name)
{
size_t index_at = preset_name.find_last_of("@");
if (std::string::npos == index_at) {
return preset_name;
} else {
return preset_name.substr(0, index_at - 1);
}
}
static wxBoxSizer *create_preset_tree(wxWindow *parent, std::pair<std::string, std::vector<std::shared_ptr<Preset>>> printer_and_preset)
{
wxTreeCtrl *treeCtrl = new wxTreeCtrl(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTR_DEFAULT_STYLE | wxNO_BORDER);
wxColour backgroundColor = parent->GetBackgroundColour();
treeCtrl->SetBackgroundColour(backgroundColor);
wxString printer_name = wxString::FromUTF8(printer_and_preset.first);
wxTreeItemId rootId = treeCtrl->AddRoot(printer_name);
int row = 1;
for (std::shared_ptr<Preset> preset : printer_and_preset.second) {
wxString preset_name = wxString::FromUTF8(preset->name);
wxTreeItemId childId1 = treeCtrl->AppendItem(rootId, preset_name);
row++;
}
treeCtrl->Expand(rootId);
wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
treeCtrl->SetMinSize(wxSize(-1, row * 22));
treeCtrl->SetMaxSize(wxSize(-1, row * 22));
sizer->Add(treeCtrl, 0, wxEXPAND | wxALL, 0);
return sizer;
}
static std::string get_vendor_name(std::string& preset_name)
{
if (preset_name.empty()) return "";
std::string vendor_name = preset_name.substr(preset_name.find_first_not_of(' ')); //remove the name prefix space
size_t index_at = vendor_name.find(" ");
if (std::string::npos == index_at) {
return vendor_name;
} else {
vendor_name = vendor_name.substr(0, index_at);
return vendor_name;
}
}
static wxBoxSizer *create_select_filament_preset_checkbox(wxWindow * parent,
std::string & compatible_printer,
std::vector<Preset *> presets,
std::unordered_map<::CheckBox *, std::pair<std::string, Preset *>> &machine_filament_preset)
{
wxBoxSizer *horizontal_sizer = new wxBoxSizer(wxHORIZONTAL);
wxBoxSizer *checkbox_sizer = new wxBoxSizer(wxVERTICAL);
::CheckBox *checkbox = new ::CheckBox(parent);
checkbox_sizer->Add(checkbox, 0, wxEXPAND | wxRIGHT, 5);
wxBoxSizer *combobox_sizer = new wxBoxSizer(wxVERTICAL);
wxStaticText *machine_name_str = new wxStaticText(parent, wxID_ANY, wxString::FromUTF8(compatible_printer));
ComboBox * combobox = new ComboBox(parent, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize(200, 24), 0, nullptr, wxCB_READONLY);
combobox->SetBackgroundColor(PRINTER_LIST_COLOUR);
combobox->SetBorderColor(*wxWHITE);
combobox->SetLabel(_L("Select filament preset"));
combobox->Bind(wxEVT_COMBOBOX, [combobox, checkbox, presets, &machine_filament_preset, compatible_printer](wxCommandEvent &e) {
combobox->SetLabelColor(*wxBLACK);
wxString preset_name = combobox->GetStringSelection();
checkbox->SetValue(true);
for (Preset *preset : presets) {
if (preset_name == wxString::FromUTF8(preset->name)) {
machine_filament_preset[checkbox] = std::make_pair(compatible_printer, preset);
}
}
e.Skip();
});
combobox_sizer->Add(machine_name_str, 0, wxEXPAND, 0);
combobox_sizer->Add(combobox, 0, wxEXPAND | wxTOP, 5);
wxArrayString choices;
for (Preset *preset : presets) {
choices.Add(wxString::FromUTF8(preset->name));
}
combobox->Set(choices);
horizontal_sizer->Add(checkbox_sizer);
horizontal_sizer->Add(combobox_sizer);
return horizontal_sizer;
}
static wxString get_curr_radio_type(std::vector<std::pair<RadioBox *, wxString>> &radio_btns)
{
for (std::pair<RadioBox *, wxString> radio_string : radio_btns) {
if (radio_string.first->GetValue()) {
return radio_string.second;
}
}
return "";
}
static std::string calculate_md5(const std::string &input)
{
unsigned char digest[MD5_DIGEST_LENGTH];
std::string md5;
EVP_MD_CTX *mdContext = EVP_MD_CTX_new();
EVP_DigestInit(mdContext, EVP_md5());
EVP_DigestUpdate(mdContext, input.c_str(), input.length());
EVP_DigestFinal(mdContext, digest, nullptr);
EVP_MD_CTX_free(mdContext);
char hexDigest[MD5_DIGEST_LENGTH * 2 + 1];
for (int i = 0; i < MD5_DIGEST_LENGTH; ++i) { sprintf(hexDigest + (i * 2), "%02x", digest[i]); }
hexDigest[MD5_DIGEST_LENGTH * 2] = '\0';
md5 = std::string(hexDigest);
return md5;
}
static std::string get_filament_id(std::string vendor_typr_serial)
{
std::unordered_map<std::string, std::set<std::string>> filament_id_to_filament_name;
// temp filament presets
PresetBundle temp_preset_bundle;
temp_preset_bundle.load_system_filaments_json(Slic3r::ForwardCompatibilitySubstitutionRule::EnableSilent);
std::string dir_user_presets = wxGetApp().app_config->get("preset_folder");
if (dir_user_presets.empty()) {
temp_preset_bundle.load_user_presets(DEFAULT_USER_FOLDER_NAME, ForwardCompatibilitySubstitutionRule::EnableSilent);
} else {
temp_preset_bundle.load_user_presets(dir_user_presets, ForwardCompatibilitySubstitutionRule::EnableSilent);
}
const std::deque<Preset> &filament_presets = temp_preset_bundle.filaments.get_presets();
for (const Preset &preset : filament_presets) {
std::string preset_name = preset.name;
size_t index_at = preset_name.find_first_of('@');
if (index_at == std::string::npos) {
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " filament preset name has no @ and name is: " << preset_name;
continue;
}
std::string filament_name = preset_name.substr(0, index_at - 1);
if (filament_name == vendor_typr_serial)
return preset.filament_id;
filament_id_to_filament_name[preset.filament_id].insert(filament_name);
}
// global filament presets
PresetBundle * preset_bundle = wxGetApp().preset_bundle;
std::map<std::string, std::vector<Preset const *>> temp_filament_id_to_presets = preset_bundle->filaments.get_filament_presets();
for (std::pair<std::string, std::vector<Preset const *>> filament_id_to_presets : temp_filament_id_to_presets) {
if (filament_id_to_presets.first.empty()) continue;
for (const Preset *preset : filament_id_to_presets.second) {
std::string preset_name = preset->name;
size_t index_at = preset_name.find_first_of('@');
if (index_at == std::string::npos) {
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " filament preset name has no @ and name is: " << preset_name;
continue;
}
std::string filament_name = preset_name.substr(0, index_at - 1);
if (filament_name == vendor_typr_serial)
return preset->filament_id;
filament_id_to_filament_name[preset->filament_id].insert(filament_name);
}
}
std::string user_filament_id = "P" + calculate_md5(vendor_typr_serial).substr(0, 7);
while (filament_id_to_filament_name.find(user_filament_id) != filament_id_to_filament_name.end()) {//find same filament id
bool have_same_filament_name = false;
for (const std::string &name : filament_id_to_filament_name.find(user_filament_id)->second) {
if (name == vendor_typr_serial) {
have_same_filament_name = true;
break;
}
}
if (have_same_filament_name) {
break;
}
else { //Different names correspond to the same filament id
user_filament_id = "P" + calculate_md5(vendor_typr_serial + get_curr_time()).substr(0, 7);
}
}
return user_filament_id;
}
static json get_config_json(const Preset* preset) {
json j;
// record the headers
j[BBL_JSON_KEY_VERSION] = preset->version.to_string();
j[BBL_JSON_KEY_NAME] = preset->name;
j[BBL_JSON_KEY_FROM] = "";
DynamicPrintConfig config = preset->config;
// record all the key-values
for (const std::string &opt_key : config.keys()) {
const ConfigOption *opt = config.option(opt_key);
if (opt->is_scalar()) {
if (opt->type() == coString)
// keep \n, \r, \t
j[opt_key] = (dynamic_cast<const ConfigOptionString *>(opt))->value;
else
j[opt_key] = opt->serialize();
} else {
const ConfigOptionVectorBase *vec = static_cast<const ConfigOptionVectorBase *>(opt);
std::vector<std::string> string_values = vec->vserialize();
json j_array(string_values);
j[opt_key] = j_array;
}
}
return j;
}
static char* read_json_file(const std::string &preset_path)
{
FILE *json_file = boost::nowide::fopen(boost::filesystem::path(preset_path).make_preferred().string().c_str(), "rb");
if (json_file == NULL) {
BOOST_LOG_TRIVIAL(info) << "Failed to open JSON file: " << preset_path;
return NULL;
}
fseek(json_file, 0, SEEK_END); // seek to end
long file_size = ftell(json_file); // get file size
fseek(json_file, 0, SEEK_SET); // seek to start
char * json_contents = (char *) malloc(file_size);
if (json_contents == NULL) {
BOOST_LOG_TRIVIAL(info) << "Failed to allocate memory for JSON file ";
fclose(json_file);
return NULL;
}
fread(json_contents, 1, file_size, json_file);
fclose(json_file);
return json_contents;
}
static void adjust_dialog_in_screen(DPIDialog* dialog) {
wxSize screen_size = wxGetDisplaySize();
int pos_x, pos_y, size_x, size_y, screen_width, screen_height, dialog_x, dialog_y;
pos_x = dialog->GetPosition().x;
pos_y = dialog->GetPosition().y;
size_x = dialog->GetSize().x;
size_y = dialog->GetSize().y;
screen_width = screen_size.GetWidth();
screen_height = screen_size.GetHeight();
dialog_x = pos_x;
dialog_y = pos_y;
if (pos_x + size_x > screen_width) {
int exceed_x = pos_x + size_x - screen_width;
dialog_x -= exceed_x;
}
if (pos_y + size_y > screen_height - 50) {
int exceed_y = pos_y + size_y - screen_height + 50;
dialog_y -= exceed_y;
}
if (pos_x != dialog_x || pos_y != dialog_y) { dialog->SetPosition(wxPoint(dialog_x, dialog_y)); }
}
CreateFilamentPresetDialog::CreateFilamentPresetDialog(wxWindow *parent)
: DPIDialog(parent ? parent : nullptr, wxID_ANY, _L("Create Filament"), wxDefaultPosition, wxDefaultSize, wxCAPTION | wxCLOSE_BOX | wxCENTRE)
{
m_create_type.base_filament = _L("Create Based on Current Filament");
m_create_type.base_filament_preset = _L("Copy Current Filament Preset ");
this->SetBackgroundColour(*wxWHITE);
this->SetSize(wxSize(FromDIP(600), FromDIP(480)));
std::string icon_path = (boost::format("%1%/images/OrcaSlicerTitle.ico") % resources_dir()).str();
SetIcon(wxIcon(encode_path(icon_path.c_str()), wxBITMAP_TYPE_ICO));
wxBoxSizer *m_main_sizer = new wxBoxSizer(wxVERTICAL);
// top line
auto m_line_top = new wxPanel(this, wxID_ANY, wxDefaultPosition, wxSize(-1, 1), wxTAB_TRAVERSAL);
m_line_top->SetBackgroundColour(wxColour(0xA6, 0xa9, 0xAA));
m_main_sizer->Add(m_line_top, 0, wxEXPAND, 0);
m_main_sizer->Add(0, 0, 0, wxTOP, FromDIP(5));
wxStaticText *basic_infomation = new wxStaticText(this, wxID_ANY, _L("Basic Information"));
basic_infomation->SetFont(Label::Head_16);
m_main_sizer->Add(basic_infomation, 0, wxLEFT, FromDIP(10));
m_main_sizer->Add(create_item(FilamentOptionType::VENDOR), 0, wxEXPAND | wxALL, FromDIP(5));
m_main_sizer->Add(create_item(FilamentOptionType::TYPE), 0, wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM, FromDIP(5));
m_main_sizer->Add(create_item(FilamentOptionType::SERIAL), 0, wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM, FromDIP(5));
// divider line
auto line_divider = new wxPanel(this, wxID_ANY, wxDefaultPosition, wxSize(-1, 1), wxTAB_TRAVERSAL);
line_divider->SetBackgroundColour(wxColour(0xA6, 0xa9, 0xAA));
m_main_sizer->Add(line_divider, 0, wxEXPAND | wxLEFT | wxRIGHT, FromDIP(10));
m_main_sizer->Add(0, 0, 0, wxTOP, FromDIP(5));
wxStaticText *presets_infomation = new wxStaticText(this, wxID_ANY, _L("Add Filament Preset under this filament"));
presets_infomation->SetFont(Label::Head_16);
m_main_sizer->Add(presets_infomation, 0, wxLEFT | wxRIGHT, FromDIP(15));
m_main_sizer->Add(create_item(FilamentOptionType::FILAMENT_PRESET), 0, wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM, FromDIP(5));
m_filament_preset_text = new wxStaticText(this, wxID_ANY, _L("We could create the filament presets for your following printer:"), wxDefaultPosition, wxDefaultSize);
m_main_sizer->Add(m_filament_preset_text, 0, wxEXPAND | wxLEFT | wxRIGHT, FromDIP(15));
m_scrolled_preset_panel = new wxScrolledWindow(this, wxID_ANY);
m_scrolled_preset_panel->SetMaxSize(wxSize(-1, FromDIP(350)));
m_scrolled_preset_panel->SetBackgroundColour(*wxWHITE);
m_scrolled_preset_panel->SetScrollRate(5, 5);
m_scrolled_sizer = new wxBoxSizer(wxVERTICAL);
m_scrolled_sizer->Add(create_item(FilamentOptionType::PRESET_FOR_PRINTER), 0, wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM, FromDIP(5));
m_scrolled_sizer->Add(0, 0, 0, wxTOP, FromDIP(5));
m_scrolled_preset_panel->SetSizerAndFit(m_scrolled_sizer);
m_main_sizer->Add(m_scrolled_preset_panel, 0, wxEXPAND | wxLEFT | wxRIGHT, FromDIP(10));
m_main_sizer->Add(create_button_item(), 0, wxEXPAND | wxALL, FromDIP(10));
get_all_filament_presets();
get_all_visible_printer_name();
select_curr_radiobox(m_create_type_btns, 0);
this->SetSizer(m_main_sizer);
Layout();
Fit();
wxGetApp().UpdateDlgDarkUI(this);
}
CreateFilamentPresetDialog::~CreateFilamentPresetDialog()
{
for (std::pair<std::string, Preset *> preset : m_all_presets_map) {
Preset *p = preset.second;
if (p) {
delete p;
p = nullptr;
}
}
}
void CreateFilamentPresetDialog::on_dpi_changed(const wxRect &suggested_rect) {
m_button_create->SetMinSize(wxSize(FromDIP(58), FromDIP(24)));
m_button_create->SetMaxSize(wxSize(FromDIP(58), FromDIP(24)));
m_button_create->SetCornerRadius(FromDIP(12));
m_button_cancel->SetMinSize(wxSize(FromDIP(58), FromDIP(24)));
m_button_cancel->SetMaxSize(wxSize(FromDIP(58), FromDIP(24)));
m_button_cancel->SetCornerRadius(FromDIP(12));
Layout();
}
bool CreateFilamentPresetDialog::is_check_box_selected()
{
for (const std::pair<::CheckBox *, std::pair<std::string, Preset *>> &checkbox_preset : m_filament_preset) {
if (checkbox_preset.first->GetValue()) { return true; }
}
for (const std::pair<::CheckBox *, std::pair<std::string, Preset *>> &checkbox_preset : m_machint_filament_preset) {
if (checkbox_preset.first->GetValue()) { return true; }
}
return false;
}
wxBoxSizer *CreateFilamentPresetDialog::create_item(FilamentOptionType option_type)
{
wxSizer *item = nullptr;
switch (option_type) {
case VENDOR: return create_vendor_item();
case TYPE: return create_type_item();
case SERIAL: return create_serial_item();
case FILAMENT_PRESET: return create_filament_preset_item();
case PRESET_FOR_PRINTER: return create_filament_preset_for_printer_item();
default: return nullptr;
}
}
wxBoxSizer *CreateFilamentPresetDialog::create_vendor_item()
{
wxBoxSizer *horizontal_sizer = new wxBoxSizer(wxHORIZONTAL);
wxBoxSizer * optionSizer = new wxBoxSizer(wxVERTICAL);
wxStaticText *static_vendor_text = new wxStaticText(this, wxID_ANY, _L("Vendor"), wxDefaultPosition, wxDefaultSize);
optionSizer->Add(static_vendor_text, 0, wxEXPAND | wxALL, 0);
optionSizer->SetMinSize(OPTION_SIZE);
horizontal_sizer->Add(optionSizer, 0, wxEXPAND | wxALL | wxALIGN_CENTER_VERTICAL, FromDIP(5));
wxArrayString choices;
for (const wxString &vendor : filament_vendors) {
choices.push_back(vendor);
}
wxBoxSizer *vendor_sizer = new wxBoxSizer(wxHORIZONTAL);
m_filament_vendor_combobox = new ComboBox(this, wxID_ANY, wxEmptyString, wxDefaultPosition, NAME_OPTION_COMBOBOX_SIZE, 0, nullptr, wxCB_READONLY);
m_filament_vendor_combobox->SetLabel(_L("Select Vendor"));
m_filament_vendor_combobox->SetLabelColor(DEFAULT_PROMPT_TEXT_COLOUR);
m_filament_vendor_combobox->Set(choices);
m_filament_vendor_combobox->Bind(wxEVT_COMBOBOX, [this](wxCommandEvent &e) {
m_filament_vendor_combobox->SetLabelColor(*wxBLACK);
e.Skip();
});
vendor_sizer->Add(m_filament_vendor_combobox, 0, wxEXPAND | wxALL, 0);
wxBoxSizer *textInputSizer = new wxBoxSizer(wxVERTICAL);
m_filament_custom_vendor_input = new TextInput(this, wxEmptyString, wxEmptyString, wxEmptyString, wxDefaultPosition, NAME_OPTION_COMBOBOX_SIZE, wxTE_PROCESS_ENTER);
m_filament_custom_vendor_input->GetTextCtrl()->SetMaxLength(50);
m_filament_custom_vendor_input->SetSize(NAME_OPTION_COMBOBOX_SIZE);
textInputSizer->Add(m_filament_custom_vendor_input, 0, wxEXPAND | wxALL, 0);
m_filament_custom_vendor_input->GetTextCtrl()->SetHint(_L("Input Custom Vendor"));
m_filament_custom_vendor_input->GetTextCtrl()->Bind(wxEVT_CHAR, [this](wxKeyEvent &event) {
int key = event.GetKeyCode();
if (cannot_input_key.find(key) != cannot_input_key.end()) {
event.Skip(false);
return;
}
event.Skip();
});
m_filament_custom_vendor_input->Hide();
vendor_sizer->Add(textInputSizer, 0, wxEXPAND | wxALIGN_CENTER_VERTICAL, FromDIP(10));
wxBoxSizer *comboBoxSizer = new wxBoxSizer(wxVERTICAL);
wxBoxSizer *checkbox_sizer = new wxBoxSizer(wxHORIZONTAL);
m_can_not_find_vendor_checkbox = new ::CheckBox(this);
checkbox_sizer->Add(m_can_not_find_vendor_checkbox, 0, wxALIGN_CENTER, 0);
checkbox_sizer->Add(0, 0, 0, wxEXPAND | wxRIGHT, FromDIP(5));
wxStaticText *m_can_not_find_vendor_text = new wxStaticText(this, wxID_ANY, _L("Can't find vendor I want"), wxDefaultPosition, wxDefaultSize, 0);
m_can_not_find_vendor_text->SetFont(::Label::Body_13);
wxSize size = m_can_not_find_vendor_text->GetTextExtent(_L("Can't find vendor I want"));
m_can_not_find_vendor_text->SetMinSize(wxSize(size.x + FromDIP(4), -1));
m_can_not_find_vendor_text->Wrap(-1);
checkbox_sizer->Add(m_can_not_find_vendor_text, 0, wxALIGN_CENTER, 0);
m_can_not_find_vendor_checkbox->Bind(wxEVT_TOGGLEBUTTON, [this](wxCommandEvent &e) {
bool value = m_can_not_find_vendor_checkbox->GetValue();
if (value) {
m_can_not_find_vendor_checkbox->SetValue(true);
m_filament_vendor_combobox->Hide();
m_filament_custom_vendor_input->Show();
} else {
m_can_not_find_vendor_checkbox->SetValue(false);
m_filament_vendor_combobox->Show();
m_filament_custom_vendor_input->Hide();
}
Refresh();
Layout();
Fit();
});
comboBoxSizer->Add(vendor_sizer, 0, wxEXPAND | wxTOP, FromDIP(5));
comboBoxSizer->Add(checkbox_sizer, 0, wxEXPAND | wxTOP, FromDIP(5));
horizontal_sizer->Add(comboBoxSizer, 0, wxEXPAND | wxALL | wxALIGN_CENTER_VERTICAL, FromDIP(5));
return horizontal_sizer;
}
wxBoxSizer *CreateFilamentPresetDialog::create_type_item()
{
wxBoxSizer *horizontal_sizer = new wxBoxSizer(wxHORIZONTAL);
wxBoxSizer * optionSizer = new wxBoxSizer(wxVERTICAL);
wxStaticText *static_type_text = new wxStaticText(this, wxID_ANY, _L("Type"), wxDefaultPosition, wxDefaultSize);
optionSizer->Add(static_type_text, 0, wxEXPAND | wxALL, 0);
optionSizer->SetMinSize(OPTION_SIZE);
horizontal_sizer->Add(optionSizer, 0, wxEXPAND | wxALL | wxALIGN_CENTER_VERTICAL, FromDIP(5));
wxArrayString filament_type;
for (const wxString &filament : system_filament_types) {
filament_type.Add(filament);
}
wxBoxSizer *comboBoxSizer = new wxBoxSizer(wxVERTICAL);
m_filament_type_combobox = new ComboBox(this, wxID_ANY, wxEmptyString, wxDefaultPosition, NAME_OPTION_COMBOBOX_SIZE, 0, nullptr, wxCB_READONLY);
m_filament_type_combobox->SetLabel(_L("Select Type"));
m_filament_type_combobox->SetLabelColor(DEFAULT_PROMPT_TEXT_COLOUR);
m_filament_type_combobox->Set(filament_type);
comboBoxSizer->Add(m_filament_type_combobox, 0, wxEXPAND | wxALL, 0);
horizontal_sizer->Add(comboBoxSizer, 0, wxEXPAND | wxALL | wxALIGN_CENTER_VERTICAL, FromDIP(5));
m_filament_type_combobox->Bind(wxEVT_COMBOBOX, [this](wxCommandEvent &e) {
m_filament_type_combobox->SetLabelColor(*wxBLACK);
const wxString &curr_create_type = curr_create_filament_type();
clear_filament_preset_map();
if (curr_create_type == m_create_type.base_filament) {
wxArrayString filament_preset_choice = get_filament_preset_choices();
m_filament_preset_combobox->Set(filament_preset_choice);
m_filament_preset_combobox->SetLabel(_L("Select Filament Preset"));
m_filament_preset_combobox->SetLabelColor(DEFAULT_PROMPT_TEXT_COLOUR);
} else if (curr_create_type == m_create_type.base_filament_preset) {
get_filament_presets_by_machine();
}
m_scrolled_preset_panel->SetSizerAndFit(m_scrolled_sizer);
update_dialog_size();
e.Skip();
});
return horizontal_sizer;
}
wxBoxSizer *CreateFilamentPresetDialog::create_serial_item()
{
wxBoxSizer *horizontal_sizer = new wxBoxSizer(wxHORIZONTAL);
wxBoxSizer * optionSizer = new wxBoxSizer(wxVERTICAL);
wxStaticText *static_serial_text = new wxStaticText(this, wxID_ANY, _L("Serial"), wxDefaultPosition, wxDefaultSize);
optionSizer->Add(static_serial_text, 0, wxEXPAND | wxALL, 0);
optionSizer->SetMinSize(OPTION_SIZE);
horizontal_sizer->Add(optionSizer, 0, wxEXPAND | wxALL | wxALIGN_CENTER_VERTICAL, FromDIP(5));
wxBoxSizer *comboBoxSizer = new wxBoxSizer(wxVERTICAL);
m_filament_serial_input = new TextInput(this, "", "", "", wxDefaultPosition, NAME_OPTION_COMBOBOX_SIZE, wxTE_PROCESS_ENTER);
m_filament_serial_input->GetTextCtrl()->SetMaxLength(50);
comboBoxSizer->Add(m_filament_serial_input, 0, wxEXPAND | wxALL, 0);
m_filament_serial_input->GetTextCtrl()->Bind(wxEVT_CHAR, [this](wxKeyEvent &event) {
int key = event.GetKeyCode();
if (cannot_input_key.find(key) != cannot_input_key.end()) {
event.Skip(false);
return;
}
event.Skip();
});
wxStaticText *static_eg_text = new wxStaticText(this, wxID_ANY, _L("e.g. Basic, Matte, Silk, Marble"), wxDefaultPosition, wxDefaultSize);
static_eg_text->SetForegroundColour(wxColour("#6B6B6B"));
static_eg_text->SetFont(::Label::Body_12);
comboBoxSizer->Add(static_eg_text, 0, wxEXPAND | wxTOP, FromDIP(5));
horizontal_sizer->Add(comboBoxSizer, 0, wxEXPAND | wxALL | wxALIGN_CENTER_VERTICAL, FromDIP(5));
return horizontal_sizer;
}
wxBoxSizer *CreateFilamentPresetDialog::create_filament_preset_item()
{
wxBoxSizer *horizontal_sizer = new wxBoxSizer(wxHORIZONTAL);
wxBoxSizer * optionSizer = new wxBoxSizer(wxVERTICAL);
wxStaticText *static_filament_preset_text = new wxStaticText(this, wxID_ANY, _L("Filament Preset"), wxDefaultPosition, wxDefaultSize);
optionSizer->Add(static_filament_preset_text, 0, wxEXPAND | wxALL, 0);
optionSizer->SetMinSize(OPTION_SIZE);
horizontal_sizer->Add(optionSizer, 0, wxEXPAND | wxALL | wxALIGN_CENTER_VERTICAL, FromDIP(10));
wxBoxSizer * comboBoxSizer = new wxBoxSizer(wxVERTICAL);
comboBoxSizer->Add(create_radio_item(m_create_type.base_filament, this, wxEmptyString, m_create_type_btns), 0, wxEXPAND | wxALL, 0);
m_filament_preset_combobox = new ComboBox(this, wxID_ANY, wxEmptyString, wxDefaultPosition, FILAMENT_PRESET_COMBOBOX_SIZE, 0, nullptr, wxCB_READONLY);
m_filament_preset_combobox->SetLabel(_L("Select Filament Preset"));
m_filament_preset_combobox->SetLabelColor(DEFAULT_PROMPT_TEXT_COLOUR);
m_filament_preset_combobox->Bind(wxEVT_COMBOBOX, [this](wxCommandEvent &e) {
m_filament_preset_combobox->SetLabelColor(*wxBLACK);
wxString filament_type = m_filament_preset_combobox->GetStringSelection();
std::unordered_map<std::string, std::vector<Preset *>>::iterator iter = m_filament_choice_map.find(m_public_name_to_filament_id_map[filament_type]);
m_scrolled_preset_panel->Freeze();
m_filament_presets_sizer->Clear(true);
m_filament_preset.clear();
std::vector<std::pair<std::string, Preset *>> printer_name_to_filament_preset;
if (iter != m_filament_choice_map.end()) {
std::unordered_map<std::string, float> nozzle_diameter = nozzle_diameter_map;
for (Preset* preset : iter->second) {
auto compatible_printers = preset->config.option<ConfigOptionStrings>("compatible_printers", true);
if (!compatible_printers || compatible_printers->values.empty()) {
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << "there is a preset has no compatible printers and the preset name is: " << preset->name;
continue;
}
for (std::string &compatible_printer_name : compatible_printers->values) {
if (m_visible_printers.find(compatible_printer_name) == m_visible_printers.end()) continue;
size_t index = compatible_printer_name.find("nozzle");
if (index < 4) {
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " compatible printer name encounter exception and name is: " << compatible_printer_name;
continue;
}
if (nozzle_diameter[compatible_printer_name.substr(index - 4, 3)] == 0) {
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " compatible printer nozzle encounter exception and name is: " << compatible_printer_name;
continue;
}
printer_name_to_filament_preset.push_back(std::make_pair(compatible_printer_name,preset));
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << "show compatible printer name: " << compatible_printer_name << "and preset name is: " << preset;
}
}
} else {
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " not find filament id corresponding to the type: and the type is" << filament_type;
}
sort_printer_by_nozzle(printer_name_to_filament_preset);
for (std::pair<std::string, Preset *> printer_to_preset : printer_name_to_filament_preset)
m_filament_presets_sizer->Add(create_checkbox(m_filament_preset_panel, printer_to_preset.first, printer_to_preset.second, m_filament_preset), 0,
wxEXPAND | wxTOP | wxLEFT, FromDIP(5));
m_scrolled_preset_panel->SetSizerAndFit(m_scrolled_sizer);
m_scrolled_preset_panel->Thaw();
update_dialog_size();
e.Skip();
});
comboBoxSizer->Add(m_filament_preset_combobox, 0, wxEXPAND | wxTOP, FromDIP(5));
comboBoxSizer->Add(create_radio_item(m_create_type.base_filament_preset, this, wxEmptyString, m_create_type_btns), 0, wxEXPAND | wxTOP, FromDIP(10));
horizontal_sizer->Add(comboBoxSizer, 0, wxEXPAND | wxALL | wxALIGN_CENTER_VERTICAL, FromDIP(10));
horizontal_sizer->Add(0, 0, 0, wxLEFT, FromDIP(30));
return horizontal_sizer;
}
wxBoxSizer *CreateFilamentPresetDialog::create_filament_preset_for_printer_item()
{
wxBoxSizer *vertical_sizer = new wxBoxSizer(wxVERTICAL);
m_filament_preset_panel = new wxPanel(m_scrolled_preset_panel, wxID_ANY);
m_filament_preset_panel->SetBackgroundColour(PRINTER_LIST_COLOUR);
m_filament_preset_panel->SetSize(PRINTER_LIST_SIZE);
m_filament_presets_sizer = new wxGridSizer(3, FromDIP(5), FromDIP(5));
m_filament_preset_panel->SetSizer(m_filament_presets_sizer);
vertical_sizer->Add(m_filament_preset_panel, 0, wxEXPAND | wxTOP | wxALIGN_CENTER_HORIZONTAL, FromDIP(5));
return vertical_sizer;
}
wxBoxSizer *CreateFilamentPresetDialog::create_button_item()
{
wxBoxSizer *bSizer_button = new wxBoxSizer(wxHORIZONTAL);
bSizer_button->Add(0, 0, 1, wxEXPAND, 0);
StateColor btn_bg_green(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_create = new Button(this, _L("Create"));
m_button_create->SetBackgroundColor(btn_bg_green);
m_button_create->SetBorderColor(*wxWHITE);
m_button_create->SetTextColor(wxColour(0xFFFFFE));
m_button_create->SetFont(Label::Body_12);
m_button_create->SetSize(wxSize(FromDIP(58), FromDIP(24)));
m_button_create->SetMinSize(wxSize(FromDIP(58), FromDIP(24)));
m_button_create->SetCornerRadius(FromDIP(12));
bSizer_button->Add(m_button_create, 0, wxRIGHT, FromDIP(10));
m_button_create->Bind(wxEVT_LEFT_DOWN, [this](wxMouseEvent &e) {
//get vendor name
wxString vendor_str = m_filament_vendor_combobox->GetLabel();
std::string vendor_name;
if (!m_can_not_find_vendor_checkbox->GetValue()) {
if (_L("Select Vendor") == vendor_str) {
MessageDialog dlg(this, _L("Vendor is not selected, please reselect vendor."), wxString(SLIC3R_APP_FULL_NAME) + " - " + _L("Info"),
wxYES | wxYES_DEFAULT | wxCENTRE);
dlg.ShowModal();
return;
} else {
vendor_name = into_u8(vendor_str);
}
} else {
if (m_filament_custom_vendor_input->GetTextCtrl()->GetValue().empty()) {
MessageDialog dlg(this, _L("Custom vendor is not input, please input custom vendor."), wxString(SLIC3R_APP_FULL_NAME) + " - " + _L("Info"),
wxYES | wxYES_DEFAULT | wxCENTRE);
dlg.ShowModal();
return;
} else {
vendor_name = into_u8(m_filament_custom_vendor_input->GetTextCtrl()->GetValue());
if (vendor_name == "Bambu" || vendor_name == "Generic") {
MessageDialog dlg(this, _L("\"Bambu\" or \"Generic\" can not be used as a Vendor for custom filaments."), wxString(SLIC3R_APP_FULL_NAME) + " - " + _L("Info"),
wxYES | wxYES_DEFAULT | wxCENTRE);
dlg.ShowModal();
return;
}
}
}
//get fialment type name
wxString type_str = m_filament_type_combobox->GetLabel();
std::string type_name;
if (_L("Select Type") == type_str) {
MessageDialog dlg(this, _L("Filament type is not selected, please reselect type."), wxString(SLIC3R_APP_FULL_NAME) + " - " + _L("Info"), wxYES | wxYES_DEFAULT | wxCENTRE);
dlg.ShowModal();
return;
} else {
type_name = into_u8(type_str);
}
//get filament serial
wxString serial_str = m_filament_serial_input->GetTextCtrl()->GetValue();
std::string serial_name;
if (serial_str.empty()) {
MessageDialog dlg(this, _L("Filament serial is not inputed, please input serial."), wxString(SLIC3R_APP_FULL_NAME) + " - " + _L("Info"),
wxYES | wxYES_DEFAULT | wxCENTRE);
dlg.ShowModal();
return;
} else {
serial_name = into_u8(serial_str);
}
vendor_name = remove_special_key(vendor_name);
serial_name = remove_special_key(serial_name);
if (vendor_name.empty() || serial_name.empty()) {
MessageDialog dlg(this, _L("There may be escape characters in the vendor or serial input of filament. Please delete and re-enter."), wxString(SLIC3R_APP_FULL_NAME) + " - " + _L("Info"),
wxYES | wxYES_DEFAULT | wxCENTRE);
dlg.ShowModal();
return;
}
boost::algorithm::trim(vendor_name);
boost::algorithm::trim(serial_name);
if (vendor_name.empty() || serial_name.empty()) {
MessageDialog dlg(this, _L("All inputs in the custom vendor or serial are spaces. Please re-enter."),
wxString(SLIC3R_APP_FULL_NAME) + " - " + _L("Info"), wxYES | wxYES_DEFAULT | wxCENTRE);
dlg.ShowModal();
return;
}
if (m_can_not_find_vendor_checkbox->GetValue() && vendor_name[0] >= '0' && vendor_name[0] <= '9') {
MessageDialog dlg(this, _L("The beginning of the vendor can not be a number. Please re-enter."), wxString(SLIC3R_APP_FULL_NAME) + " - " + _L("Info"),
wxYES | wxYES_DEFAULT | wxCENTRE);
dlg.ShowModal();
return;
}
if (!is_check_box_selected()) {
MessageDialog dlg(this, _L("You have not selected a printer or preset yet. Please select at least one."), wxString(SLIC3R_APP_FULL_NAME) + " - " + _L("Info"),
wxYES | wxYES_DEFAULT | wxCENTRE);
dlg.ShowModal();
return;
}
std::string filament_preset_name = vendor_name + " " + type_name + " " + serial_name;
std::string user_filament_id = get_filament_id(filament_preset_name);
const wxString &curr_create_type = curr_create_filament_type();
PresetBundle * preset_bundle = wxGetApp().preset_bundle;
if (curr_create_type == m_create_type.base_filament) {
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ":clone filament create type filament ";
for (const std::pair<::CheckBox *, std::pair<std::string, Preset *>> &checkbox_preset : m_filament_preset) {
if (checkbox_preset.first->GetValue()) {
std::string compatible_printer_name = checkbox_preset.second.first;
std::vector<std::string> failures;
Preset const *const checked_preset = checkbox_preset.second.second;
DynamicConfig dynamic_config;
dynamic_config.set_key_value("filament_vendor", new ConfigOptionStrings({vendor_name}));
dynamic_config.set_key_value("compatible_printers", new ConfigOptionStrings({compatible_printer_name}));
dynamic_config.set_key_value("filament_type", new ConfigOptionStrings({type_name}));
bool res = preset_bundle->filaments.clone_presets_for_filament(checked_preset, failures, filament_preset_name, user_filament_id, dynamic_config,
compatible_printer_name);
if (!res) {
std::string failure_names;
for (std::string &failure : failures) { failure_names += failure + "\n"; }
MessageDialog dlg(this, _L("Some existing presets have failed to be created, as follows:\n") + from_u8(failure_names) + _L("\nDo you want to rewrite it?"),
wxString(SLIC3R_APP_FULL_NAME) + " - " + _L("Info"), wxYES_NO | wxYES_DEFAULT | wxCENTRE);
if (dlg.ShowModal() == wxID_YES) {
res = preset_bundle->filaments.clone_presets_for_filament(checked_preset, failures, filament_preset_name, user_filament_id, dynamic_config,
compatible_printer_name, true);
BOOST_LOG_TRIVIAL(info) << "clone filament have failures rewritten is successful? " << res;
}
}
BOOST_LOG_TRIVIAL(info) << "clone filament no failures is successful? " << res;
}
}
} else if (curr_create_type == m_create_type.base_filament_preset) {
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ":clone filament presets create type filament preset";
for (const std::pair<::CheckBox *, std::pair<std::string, Preset *>> &checkbox_preset : m_machint_filament_preset) {
if (checkbox_preset.first->GetValue()) {
std::string compatible_printer_name = checkbox_preset.second.first;
std::vector<std::string> failures;
Preset const *const checked_preset = checkbox_preset.second.second;
DynamicConfig dynamic_config;
dynamic_config.set_key_value("filament_vendor", new ConfigOptionStrings({vendor_name}));
dynamic_config.set_key_value("compatible_printers", new ConfigOptionStrings({compatible_printer_name}));
dynamic_config.set_key_value("filament_type", new ConfigOptionStrings({type_name}));
bool res = preset_bundle->filaments.clone_presets_for_filament(checked_preset, failures, filament_preset_name, user_filament_id, dynamic_config,
compatible_printer_name);
if (!res) {
std::string failure_names;
for (std::string &failure : failures) { failure_names += failure + "\n"; }
MessageDialog dlg(this, _L("Some existing presets have failed to be created, as follows:\n") + from_u8(failure_names) + _L("\nDo you want to rewrite it?"),
wxString(SLIC3R_APP_FULL_NAME) + " - " + _L("Info"), wxYES_NO | wxYES_DEFAULT | wxCENTRE);
if (wxID_YES == dlg.ShowModal()) {
res = preset_bundle->filaments.clone_presets_for_filament(checked_preset, failures, filament_preset_name, user_filament_id, dynamic_config,
compatible_printer_name, true);
BOOST_LOG_TRIVIAL(info) << "clone filament presets have failures rewritten is successful? " << res;
}
}
BOOST_LOG_TRIVIAL(info) << "clone filament presets no failures is successful? " << res << " old preset is: " << checked_preset->name
<< " compatible_printer_name is: " << compatible_printer_name;
}
}
}
preset_bundle->update_compatible(PresetSelectCompatibleType::Always);
EndModal(wxID_OK);
});
StateColor btn_bg_white(std::pair<wxColour, int>(wxColour(206, 206, 206), StateColor::Pressed), std::pair<wxColour, int>(wxColour(238, 238, 238), StateColor::Hovered),
std::pair<wxColour, int>(*wxWHITE, StateColor::Normal));
m_button_cancel = new Button(this, _L("Cancel"));
m_button_cancel->SetBackgroundColor(btn_bg_white);
m_button_cancel->SetBorderColor(wxColour(38, 46, 48));
m_button_cancel->SetFont(Label::Body_12);
m_button_cancel->SetSize(wxSize(FromDIP(58), FromDIP(24)));
m_button_cancel->SetMinSize(wxSize(FromDIP(58), FromDIP(24)));
m_button_cancel->SetCornerRadius(FromDIP(12));
bSizer_button->Add(m_button_cancel, 0, wxRIGHT, FromDIP(10));
m_button_cancel->Bind(wxEVT_LEFT_DOWN, [this](wxMouseEvent &e) {
EndModal(wxID_CANCEL);
});
return bSizer_button;
}
wxArrayString CreateFilamentPresetDialog::get_filament_preset_choices()
{
wxArrayString choices;
// get fialment type name
wxString type_str = m_filament_type_combobox->GetLabel();
std::string type_name;
if (_L("Select Type") == type_str) {
/*MessageDialog dlg(this, _L("Filament type is not selected, please reselect type."), wxString(SLIC3R_APP_FULL_NAME) + " - " + _L("Info"), wxYES | wxYES_DEFAULT | wxCENTRE);
dlg.ShowModal();*/
return choices;
} else {
type_name = into_u8(type_str);
}
for (std::pair<std::string, Preset*> filament_presets : m_all_presets_map) {
Preset *preset = filament_presets.second;
auto inherit = preset->config.option<ConfigOptionString>("inherits");
if (inherit && !inherit->value.empty()) continue;
if (std::string::npos == filament_presets.first.find(type_name)) continue;
m_filament_choice_map[preset->filament_id].push_back(preset);
}
int suffix = 0;
for (const pair<std::string, std::vector<Preset *>> &preset : m_filament_choice_map) {
if (preset.second.empty()) continue;
std::set<wxString> preset_name_set;
for (Preset* filament_preset : preset.second) {
std::string preset_name = filament_preset->name;
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " filament id: " << filament_preset->filament_id << " preset name: " << filament_preset->name;
size_t index_at = preset_name.find("@");
if (std::string::npos != index_at) {
std::string cur_preset_name = preset_name.substr(0, index_at - 1);
preset_name_set.insert(wxString::FromUTF8(cur_preset_name));
}
}
assert(1 == preset_name_set.size());
if (preset_name_set.size() > 1) {
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " the same filament has different filament(vendor type serial)";
}
for (const wxString& public_name : preset_name_set) {
if (m_public_name_to_filament_id_map.find(public_name) != m_public_name_to_filament_id_map.end()) {
suffix++;
m_public_name_to_filament_id_map[public_name + "_" + std::to_string(suffix)] = preset.first;
choices.Add(public_name + "_" + std::to_string(suffix));
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " add filament choice: " << choices.back();
} else {
m_public_name_to_filament_id_map[public_name] = preset.first;
choices.Add(public_name);
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " add filament choice: " << choices.back();
}
}
}
return choices;
}
wxBoxSizer *CreateFilamentPresetDialog::create_radio_item(wxString title, wxWindow *parent, wxString tooltip, std::vector<std::pair<RadioBox *, wxString>> &radiobox_list)
{
wxBoxSizer *horizontal_sizer = new wxBoxSizer(wxHORIZONTAL);
RadioBox * radiobox = new RadioBox(parent);
horizontal_sizer->Add(radiobox, 0, wxEXPAND | wxALL, 0);
horizontal_sizer->Add(0, 0, 0, wxEXPAND | wxLEFT, FromDIP(5));
radiobox_list.push_back(std::make_pair(radiobox, title));
int btn_idx = radiobox_list.size() - 1;
radiobox->Bind(wxEVT_LEFT_DOWN, [this, &radiobox_list, btn_idx](wxMouseEvent &e) { select_curr_radiobox(radiobox_list, btn_idx); });
wxStaticText *text = new wxStaticText(parent, wxID_ANY, title, wxDefaultPosition, wxDefaultSize);
text->Bind(wxEVT_LEFT_DOWN, [this, &radiobox_list, btn_idx](wxMouseEvent &e) { select_curr_radiobox(radiobox_list, btn_idx); });
horizontal_sizer->Add(text, 0, wxEXPAND | wxLEFT, 0);
radiobox->SetToolTip(tooltip);
text->SetToolTip(tooltip);
return horizontal_sizer;
}
void CreateFilamentPresetDialog::select_curr_radiobox(std::vector<std::pair<RadioBox *, wxString>> &radiobox_list, int btn_idx)
{
int len = radiobox_list.size();
for (int i = 0; i < len; ++i) {
if (i == btn_idx) {
radiobox_list[i].first->SetValue(true);
const wxString &curr_selected_type = radiobox_list[i].second;
this->Freeze();
if (curr_selected_type == m_create_type.base_filament) {
m_filament_preset_text->SetLabel(_L("We could create the filament presets for your following printer:"));
m_filament_preset_combobox->Show();
if (_L("Select Type") != m_filament_type_combobox->GetLabel()) {
clear_filament_preset_map();
wxArrayString filament_preset_choice = get_filament_preset_choices();
m_filament_preset_combobox->Set(filament_preset_choice);
m_filament_preset_combobox->SetLabel(_L("Select Filament Preset"));
m_filament_preset_combobox->SetLabelColor(DEFAULT_PROMPT_TEXT_COLOUR);
}
} else if (curr_selected_type == m_create_type.base_filament_preset) {
m_filament_preset_text->SetLabel(_L("We would rename the presets as \"Vendor Type Serial @printer you selected\". \nTo add preset for more prinetrs, Please go to printer selection"));
m_filament_preset_combobox->Hide();
if (_L("Select Type") != m_filament_type_combobox->GetLabel()) {
clear_filament_preset_map();
get_filament_presets_by_machine();
}
}
m_scrolled_preset_panel->SetSizerAndFit(m_scrolled_sizer);
this->Thaw();
} else {
radiobox_list[i].first->SetValue(false);
}
}
update_dialog_size();
}
wxString CreateFilamentPresetDialog::curr_create_filament_type()
{
wxString curr_filament_type;
for (const std::pair<RadioBox *, wxString> &printer_radio : m_create_type_btns) {
if (printer_radio.first->GetValue()) {
curr_filament_type = printer_radio.second;
}
}
return curr_filament_type;
}
void CreateFilamentPresetDialog::get_filament_presets_by_machine()
{
wxArrayString choices;
// get fialment type name
wxString type_str = m_filament_type_combobox->GetLabel();
std::string type_name;
if (_L("Select Type") == type_str) {
/*MessageDialog dlg(this, _L("Filament type is not selected, please reselect type."), wxString(SLIC3R_APP_FULL_NAME) + " - " + _L("Info"), wxYES | wxYES_DEFAULT |
wxCENTRE); dlg.ShowModal();*/
return;
} else {
type_name = into_u8(type_str);
}
std::unordered_map<std::string, float> nozzle_diameter = nozzle_diameter_map;
std::unordered_map<std::string, std::vector<Preset *>> machine_name_to_presets;
PresetBundle * preset_bundle = wxGetApp().preset_bundle;
for (std::pair<std::string, Preset*> filament_preset : m_all_presets_map) {
Preset * preset = filament_preset.second;
auto compatible_printers = preset->config.option<ConfigOptionStrings>("compatible_printers", true);
if (!compatible_printers || compatible_printers->values.empty()) {
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << "there is a preset has no compatible printers and the preset name is: " << preset->name;
continue;
}
for (std::string &compatible_printer_name : compatible_printers->values) {
if (m_visible_printers.find(compatible_printer_name) == m_visible_printers.end()) {
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " compatable printer is not visible and preset name is: " << preset->name;
continue;
}
Preset * inherit_preset = nullptr;
auto inherit = dynamic_cast<ConfigOptionString*>(preset->config.option(BBL_JSON_KEY_INHERITS,false));
if (inherit && !inherit->value.empty()) {
std::string inherits_value = inherit->value;
inherit_preset = preset_bundle->filaments.find_preset(inherits_value, false, true);
}
ConfigOptionStrings *filament_types;
if (!inherit_preset) {
filament_types = dynamic_cast<ConfigOptionStrings *>(preset->config.option("filament_type"));
} else {
filament_types = dynamic_cast<ConfigOptionStrings *>(inherit_preset->config.option("filament_type"));
}
if (filament_types && filament_types->values.empty()) continue;
const std::string filament_type = filament_types->values[0];
if (filament_type != type_name) {
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " preset type is not selected type and preset name is: " << preset->name;
continue;
}
size_t index = compatible_printer_name.find("nozzle");
if (index < 4) {
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " compatible printer name encounter exception and name is: " << compatible_printer_name;
continue;
}
if (nozzle_diameter[compatible_printer_name.substr(index - 4, 3)] == 0) {
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " compatible printer nozzle encounter exception and name is: " << compatible_printer_name;
continue;
}
machine_name_to_presets[compatible_printer_name].push_back(preset);
}
}
std::vector<std::pair<std::string, std::vector<Preset *>>> printer_name_to_filament_presets;
for (std::pair<std::string, std::vector<Preset *>> machine_filament_presets : machine_name_to_presets) {
printer_name_to_filament_presets.push_back(machine_filament_presets);
}
sort_printer_by_nozzle(printer_name_to_filament_presets);
m_filament_preset_panel->Freeze();
for (std::pair<std::string, std::vector<Preset *>> machine_filament_presets : printer_name_to_filament_presets) {
std::string compatible_printer = machine_filament_presets.first;
std::vector<Preset *> &presets = machine_filament_presets.second;
m_filament_presets_sizer->Add(create_select_filament_preset_checkbox(m_filament_preset_panel, compatible_printer, presets, m_machint_filament_preset), 0, wxEXPAND | wxALL, FromDIP(5));
}
m_filament_preset_panel->Thaw();
}
void CreateFilamentPresetDialog::get_all_filament_presets()
{
// temp filament presets
PresetBundle temp_preset_bundle;
std::string dir_user_presets = wxGetApp().app_config->get("preset_folder");
if (dir_user_presets.empty()) {
temp_preset_bundle.load_user_presets(DEFAULT_USER_FOLDER_NAME, ForwardCompatibilitySubstitutionRule::EnableSilent);
} else {
temp_preset_bundle.load_user_presets(dir_user_presets, ForwardCompatibilitySubstitutionRule::EnableSilent);
}
const std::deque<Preset> &filament_presets = temp_preset_bundle.filaments.get_presets();
for (const Preset &preset : filament_presets) {
if (preset.filament_id.empty() || "null" == preset.filament_id) continue;
std::string filament_preset_name = preset.name;
Preset *filament_preset = new Preset(preset);
m_all_presets_map[filament_preset_name] = filament_preset;
}
// global filament presets
PresetBundle * preset_bundle = wxGetApp().preset_bundle;
const std::deque<Preset> &temp_filament_presets = preset_bundle->filaments.get_presets();
for (const Preset& preset : temp_filament_presets) {
if (preset.filament_id.empty() || "null" == preset.filament_id) continue;
std::string filament_preset_name = preset.name;
if (!preset.is_visible) continue;
Preset *filament_preset = new Preset(preset);
m_all_presets_map[filament_preset_name] = filament_preset;
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " loaded preset name is: " << filament_preset->name;
}
}
void CreateFilamentPresetDialog::get_all_visible_printer_name()
{
PresetBundle *preset_bundle = wxGetApp().preset_bundle;
for (const Preset &printer_preset : preset_bundle->printers.get_presets()) {
if (!printer_preset.is_visible) continue;
assert(m_visible_printers.find(printer_preset.name) == m_visible_printers.end());
m_visible_printers.insert(printer_preset.name);
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " entry, and visible printer is: " << printer_preset.name;
}
}
void CreateFilamentPresetDialog::update_dialog_size()
{
this->Freeze();
m_filament_preset_panel->SetSizerAndFit(m_filament_presets_sizer);
int width = m_filament_preset_panel->GetSize().GetWidth();
int height = m_filament_preset_panel->GetSize().GetHeight();
m_scrolled_preset_panel->SetMinSize(wxSize(std::min(1400, width + FromDIP(26)), std::min(600, height + FromDIP(18))));
m_scrolled_preset_panel->SetMaxSize(wxSize(std::min(1400, width + FromDIP(26)), std::min(600, height + FromDIP(18))));
m_scrolled_preset_panel->SetSize(wxSize(std::min(1500, width + FromDIP(26)), std::min(600, height + FromDIP(18))));
Layout();
Fit();
Refresh();
adjust_dialog_in_screen(this);
this->Thaw();
}
template<typename T>
void CreateFilamentPresetDialog::sort_printer_by_nozzle(std::vector<std::pair<std::string, T>> &printer_name_to_filament_preset)
{
std::unordered_map<std::string, float> nozzle_diameter = nozzle_diameter_map;
std::sort(printer_name_to_filament_preset.begin(), printer_name_to_filament_preset.end(),
[&nozzle_diameter](const std::pair<string, T> &a, const std::pair<string, T> &b) {
size_t nozzle_index_a = a.first.find("nozzle");
size_t nozzle_index_b = b.first.find("nozzle");
if (nozzle_index_a == std::string::npos || nozzle_index_b == std::string::npos) return a.first < b.first;
std::string nozzle_str_a;
std::string nozzle_str_b;
try {
nozzle_str_a = a.first.substr(nozzle_index_a - 4, 3);
nozzle_str_b = b.first.substr(nozzle_index_b - 4, 3);
} catch (...) {
BOOST_LOG_TRIVIAL(info) << "substr filed, and printer name is: " << a.first << " and " << b.first;
return a.first < b.first;
}
float nozzle_a, nozzle_b;
try {
nozzle_a = nozzle_diameter[nozzle_str_a];
nozzle_b = nozzle_diameter[nozzle_str_b];
assert(nozzle_a != 0 && nozzle_b != 0);
} catch (...) {
BOOST_LOG_TRIVIAL(info) << "find nozzle filed, and nozzle is: " << nozzle_str_a << "mm and " << nozzle_str_b << "mm";
return a.first < b.first;
}
float diff_nozzle_a = std::abs(nozzle_a - 0.4);
float diff_nozzle_b = std::abs(nozzle_b - 0.4);
if (nozzle_a == nozzle_b) return a.first < b.first;
if (diff_nozzle_a == diff_nozzle_b) return nozzle_a < nozzle_b;
return diff_nozzle_a < diff_nozzle_b;
});
}
void CreateFilamentPresetDialog::clear_filament_preset_map()
{
m_filament_choice_map.clear();
m_filament_preset.clear();
m_machint_filament_preset.clear();
m_public_name_to_filament_id_map.clear();
m_filament_preset_panel->Freeze();
m_filament_presets_sizer->Clear(true);
m_filament_preset_panel->Thaw();
}
CreatePrinterPresetDialog::CreatePrinterPresetDialog(wxWindow *parent)
: DPIDialog(parent ? parent : nullptr, wxID_ANY, _L("Create Printer/Nozzle"), wxDefaultPosition, wxDefaultSize, wxCAPTION | wxCLOSE_BOX | wxCENTER)
{
m_create_type.create_printer = _L("Create Printer");
m_create_type.create_nozzle = _L("Create Nozzle for Existing Printer");
m_create_type.base_template = _L("Create from Template");
m_create_type.base_curr_printer = _L("Create Based on Current Printer");
this->SetBackgroundColour(*wxWHITE);
SetSizeHints(wxDefaultSize, wxDefaultSize);
std::string icon_path = (boost::format("%1%/images/OrcaSlicerTitle.ico") % resources_dir()).str();
SetIcon(wxIcon(encode_path(icon_path.c_str()), wxBITMAP_TYPE_ICO));
wxBoxSizer *m_main_sizer = new wxBoxSizer(wxVERTICAL);
// top line
auto m_line_top = new wxPanel(this, wxID_ANY, wxDefaultPosition, wxSize(-1, 2), wxTAB_TRAVERSAL);
m_line_top->SetBackgroundColour(wxColour(0xA6, 0xa9, 0xAA));
m_main_sizer->Add(m_line_top, 0, wxEXPAND, 0);
m_main_sizer->Add(0, 0, 0, wxTOP, FromDIP(5));
m_main_sizer->Add(create_step_switch_item(), 0, wxEXPAND | wxALL, FromDIP(5));
wxBoxSizer *page_sizer = new wxBoxSizer(wxHORIZONTAL);
m_page1 = new wxScrolledWindow(this, wxID_ANY, wxDefaultPosition, wxDefaultSize);
m_page1->SetBackgroundColour(*wxWHITE);
m_page1->SetScrollRate(5, 5);
m_page2 = new wxPanel(this, wxID_ANY, wxDefaultPosition, wxDefaultSize);\
m_page2->SetBackgroundColour(*wxWHITE);
create_printer_page1(m_page1);
create_printer_page2(m_page2);
m_page2->Hide();
page_sizer->Add(m_page1, 1, wxEXPAND, 0);
page_sizer->Add(m_page2, 1, wxEXPAND, 0);
m_main_sizer->Add(page_sizer, 0, wxEXPAND | wxRIGHT, FromDIP(10));
select_curr_radiobox(m_create_type_btns, 0);
select_curr_radiobox(m_create_presets_btns, 0);
m_main_sizer->Add(0, 0, 0, wxTOP, FromDIP(10));
this->SetSizer(m_main_sizer);
Layout();
Fit();
wxSize screen_size = wxGetDisplaySize();
int dialogX = (screen_size.GetWidth() - GetSize().GetWidth()) / 2;
int dialogY = (screen_size.GetHeight() - GetSize().GetHeight()) / 2;
SetPosition(wxPoint(dialogX, dialogY));
wxGetApp().UpdateDlgDarkUI(this);
}
CreatePrinterPresetDialog::~CreatePrinterPresetDialog()
{
clear_preset_combobox();
if (m_printer_preset) {
delete m_printer_preset;
m_printer_preset = nullptr;
}
}
void CreatePrinterPresetDialog::on_dpi_changed(const wxRect &suggested_rect) {
m_button_OK->SetMinSize(wxSize(FromDIP(58), FromDIP(24)));
m_button_OK->SetMaxSize(wxSize(FromDIP(58), FromDIP(24)));
m_button_OK->SetCornerRadius(FromDIP(12));
m_button_create->SetMinSize(wxSize(FromDIP(58), FromDIP(24)));
m_button_create->SetMaxSize(wxSize(FromDIP(58), FromDIP(24)));
m_button_create->SetCornerRadius(FromDIP(12));
m_button_page1_cancel->SetMinSize(wxSize(FromDIP(58), FromDIP(24)));
m_button_page1_cancel->SetMaxSize(wxSize(FromDIP(58), FromDIP(24)));
m_button_page1_cancel->SetCornerRadius(FromDIP(12));
m_button_page2_cancel->SetMinSize(wxSize(FromDIP(58), FromDIP(24)));
m_button_page2_cancel->SetMaxSize(wxSize(FromDIP(58), FromDIP(24)));
m_button_page2_cancel->SetCornerRadius(FromDIP(12));
m_button_page2_back->SetMinSize(wxSize(FromDIP(58), FromDIP(24)));
m_button_page2_back->SetMaxSize(wxSize(FromDIP(58), FromDIP(24)));
m_button_page2_back->SetCornerRadius(FromDIP(12));
Layout();
}
wxBoxSizer *CreatePrinterPresetDialog::create_step_switch_item()
{
wxBoxSizer *step_switch_sizer = new wxBoxSizer(wxVERTICAL);
std::string wiki_url = "https://wiki.bambulab.com/en/software/bambu-studio/3rd-party-printer-profile";
wxHyperlinkCtrl *m_download_hyperlink = new wxHyperlinkCtrl(this, wxID_ANY, _L("wiki"), wiki_url, wxDefaultPosition, wxDefaultSize, wxHL_DEFAULT_STYLE);
step_switch_sizer->Add(m_download_hyperlink, 0, wxRIGHT | wxALIGN_RIGHT, FromDIP(5));
wxBoxSizer *horizontal_sizer = new wxBoxSizer(wxHORIZONTAL);
wxPanel * step_switch_panel = new wxPanel(this);
step_switch_panel->SetBackgroundColour(*wxWHITE);
horizontal_sizer->Add(0, 0, 1, wxEXPAND,0);
m_step_1 = new wxStaticBitmap(step_switch_panel, wxID_ANY, create_scaled_bitmap("step_1", nullptr, FromDIP(20)), wxDefaultPosition, wxDefaultSize);
horizontal_sizer->Add(m_step_1, 0, wxEXPAND | wxLEFT | wxRIGHT | wxALIGN_CENTER_VERTICAL, FromDIP(3));
wxStaticText *static_create_printer_text = new wxStaticText(step_switch_panel, wxID_ANY, m_create_type.create_printer, wxDefaultPosition, wxDefaultSize);
horizontal_sizer->Add(static_create_printer_text, 0, wxEXPAND | wxLEFT | wxRIGHT | wxALIGN_CENTER_VERTICAL, FromDIP(3));
auto divider_line = new wxPanel(step_switch_panel, wxID_ANY, wxDefaultPosition, wxSize(FromDIP(50), 1));
divider_line->SetBackgroundColour(PRINTER_LIST_COLOUR);
horizontal_sizer->Add(divider_line, 0, wxLEFT | wxRIGHT | wxALIGN_CENTER_VERTICAL, FromDIP(3));
m_step_2 = new wxStaticBitmap(step_switch_panel, wxID_ANY, create_scaled_bitmap("step_2_ready", nullptr, FromDIP(20)), wxDefaultPosition, wxDefaultSize);
horizontal_sizer->Add(m_step_2, 0, wxEXPAND | wxLEFT | wxRIGHT | wxALIGN_CENTER_VERTICAL, FromDIP(3));
wxStaticText *static_improt_presets_text = new wxStaticText(step_switch_panel, wxID_ANY, _L("Improt Preset"), wxDefaultPosition, wxDefaultSize);
horizontal_sizer->Add(static_improt_presets_text, 0, wxEXPAND | wxLEFT | wxRIGHT | wxALIGN_CENTER_VERTICAL, FromDIP(3));
horizontal_sizer->Add(0, 0, 1, wxEXPAND, 0);
step_switch_panel->SetSizer(horizontal_sizer);
step_switch_sizer->Add(step_switch_panel, 0, wxBOTTOM | wxALIGN_CENTER_HORIZONTAL, FromDIP(10));
auto line_top = new wxPanel(this, wxID_ANY, wxDefaultPosition, wxSize(-1, 1), wxTAB_TRAVERSAL);
line_top->SetBackgroundColour(PRINTER_LIST_COLOUR);
step_switch_sizer->Add(line_top, 0, wxEXPAND | wxALL, FromDIP(10));
return step_switch_sizer;
}
void CreatePrinterPresetDialog::create_printer_page1(wxWindow *parent)
{
this->SetBackgroundColour(*wxWHITE);
m_page1_sizer = new wxBoxSizer(wxVERTICAL);
m_page1_sizer->Add(create_type_item(parent), 0, wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM, FromDIP(5));
m_page1_sizer->Add(create_printer_item(parent), 0, wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM, FromDIP(5));
m_page1_sizer->Add(create_nozzle_diameter_item(parent), 0, wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM, FromDIP(5));
m_printer_info_panel = new wxPanel(parent);
m_printer_info_panel->SetBackgroundColour(*wxWHITE);
m_printer_info_sizer = new wxBoxSizer(wxVERTICAL);
m_printer_info_sizer->Add(create_bed_shape_item(m_printer_info_panel), 0, wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM, FromDIP(5));
m_printer_info_sizer->Add(create_bed_size_item(m_printer_info_panel), 0, wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM, FromDIP(5));
m_printer_info_sizer->Add(create_origin_item(m_printer_info_panel), 0, wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM, FromDIP(5));
m_printer_info_sizer->Add(create_hot_bed_stl_item(m_printer_info_panel), 0, wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM, FromDIP(5));
m_printer_info_sizer->Add(create_hot_bed_svg_item(m_printer_info_panel), 0, wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM, FromDIP(5));
m_printer_info_sizer->Add(create_max_print_height_item(m_printer_info_panel), 0, wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM, FromDIP(5));
m_printer_info_panel->SetSizer(m_printer_info_sizer);
m_page1_sizer->Add(m_printer_info_panel, 0, wxEXPAND, 0);
m_page1_sizer->Add(create_page1_btns_item(parent), 0, wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM, FromDIP(5));
parent->SetSizerAndFit(m_page1_sizer);
Layout();
wxGetApp().UpdateDlgDarkUI(this);
}
wxBoxSizer *CreatePrinterPresetDialog::create_type_item(wxWindow *parent)
{
wxBoxSizer *horizontal_sizer = new wxBoxSizer(wxHORIZONTAL);
wxBoxSizer * optionSizer = new wxBoxSizer(wxVERTICAL);
wxStaticText *static_serial_text = new wxStaticText(parent, wxID_ANY, _L("Create Type"), wxDefaultPosition, wxDefaultSize);
optionSizer->Add(static_serial_text, 0, wxEXPAND | wxALL, 0);
optionSizer->SetMinSize(OPTION_SIZE);
horizontal_sizer->Add(optionSizer, 0, wxEXPAND | wxALL | wxALIGN_CENTER_VERTICAL, FromDIP(10));
wxBoxSizer *radioBoxSizer = new wxBoxSizer(wxVERTICAL);
radioBoxSizer->Add(create_radio_item(m_create_type.create_printer, parent, wxEmptyString, m_create_type_btns), 0, wxEXPAND | wxALL, 0);
radioBoxSizer->Add(create_radio_item(m_create_type.create_nozzle, parent, wxEmptyString, m_create_type_btns), 0, wxEXPAND | wxTOP, FromDIP(10));
horizontal_sizer->Add(radioBoxSizer, 0, wxEXPAND | wxALL | wxALIGN_CENTER_VERTICAL, FromDIP(10));
return horizontal_sizer;
}
wxBoxSizer *CreatePrinterPresetDialog::create_printer_item(wxWindow *parent)
{
wxBoxSizer *horizontal_sizer = new wxBoxSizer(wxHORIZONTAL);
wxBoxSizer * optionSizer = new wxBoxSizer(wxVERTICAL);
wxStaticText *static_vendor_text = new wxStaticText(parent, wxID_ANY, _L("Printer"), wxDefaultPosition, wxDefaultSize);
optionSizer->Add(static_vendor_text, 0, wxEXPAND | wxALL, 0);
optionSizer->SetMinSize(OPTION_SIZE);
horizontal_sizer->Add(optionSizer, 0, wxEXPAND | wxALL | wxALIGN_CENTER_VERTICAL, FromDIP(10));
wxBoxSizer *vertical_sizer = new wxBoxSizer(wxVERTICAL);
wxBoxSizer *comboBoxSizer = new wxBoxSizer(wxHORIZONTAL);
m_select_vendor = new ComboBox(parent, wxID_ANY, wxEmptyString, wxDefaultPosition, NAME_OPTION_COMBOBOX_SIZE, 0, nullptr, wxCB_READONLY);
m_select_vendor->SetValue(_L("Select Vendor"));
m_select_vendor->SetLabelColor(DEFAULT_PROMPT_TEXT_COLOUR);
wxArrayString printer_vendor;
for (const std::string &vendor : printer_vendors) {
printer_vendor.Add(vendor);
}
m_select_vendor->Set(printer_vendor);
m_select_vendor->Bind(wxEVT_COMBOBOX, [this](wxCommandEvent e) {
m_select_vendor->SetLabelColor(*wxBLACK);
std::string curr_selected_vendor = into_u8(m_select_vendor->GetStringSelection());
std::unordered_map<std::string,std::vector<std::string>>::const_iterator iter = printer_model_map.find(curr_selected_vendor);
if (iter != printer_model_map.end())
{
std::vector<std::string> vendor_model = iter->second;
wxArrayString model_choice;
for (const std::string &model : vendor_model) {
model_choice.Add(model);
}
m_select_model->Set(model_choice);
if (!model_choice.empty()) {
m_select_model->SetSelection(0);
m_select_model->SetLabelColor(*wxBLACK);
}
} else {
MessageDialog dlg(this, _L("The model is not fond, place reselect vendor."), wxString(SLIC3R_APP_FULL_NAME) + " - " + _L("Info"), wxYES | wxYES_DEFAULT | wxCENTRE);
dlg.ShowModal();
}
e.Skip();
});
comboBoxSizer->Add(m_select_vendor, 0, wxEXPAND | wxALL, 0);
m_select_model = new ComboBox(parent, wxID_ANY, wxEmptyString, wxDefaultPosition, NAME_OPTION_COMBOBOX_SIZE, 0, nullptr, wxCB_READONLY);
comboBoxSizer->Add(m_select_model, 0, wxEXPAND | wxLEFT, FromDIP(5));
m_select_model->SetValue(_L("Select Model"));
m_select_model->SetLabelColor(DEFAULT_PROMPT_TEXT_COLOUR);
m_select_model->Bind(wxEVT_COMBOBOX, [this](wxCommandEvent e) {
m_select_model->SetLabelColor(*wxBLACK);
e.Skip();
});
m_select_printer = new ComboBox(parent, wxID_ANY, wxEmptyString, wxDefaultPosition, PRINTER_PRESET_MODEL_SIZE, 0, nullptr, wxCB_READONLY);
comboBoxSizer->Add(m_select_printer, 0, wxEXPAND | wxALL, 0);
m_select_printer->SetValue(_L("Select Printer"));
m_select_printer->SetLabelColor(DEFAULT_PROMPT_TEXT_COLOUR);
m_select_printer->Bind(wxEVT_COMBOBOX, [this](wxCommandEvent e) {
m_select_printer->SetLabelColor(*wxBLACK);
e.Skip();
});
m_select_printer->Hide();
m_custom_vendor_text_ctrl = new wxTextCtrl(parent, wxID_ANY, "", wxDefaultPosition, NAME_OPTION_COMBOBOX_SIZE);
m_custom_vendor_text_ctrl->SetHint(_L("Input Custom Vendor"));
m_custom_vendor_text_ctrl->Bind(wxEVT_CHAR, [this](wxKeyEvent &event) {
int key = event.GetKeyCode();
if (cannot_input_key.find(key) != cannot_input_key.end()) { // "@" can not be inputed
event.Skip(false);
return;
}
event.Skip();
});
comboBoxSizer->Add(m_custom_vendor_text_ctrl, 0, wxEXPAND | wxALL, 0);
m_custom_vendor_text_ctrl->Hide();
m_custom_model_text_ctrl = new wxTextCtrl(parent, wxID_ANY, "", wxDefaultPosition, NAME_OPTION_COMBOBOX_SIZE);
m_custom_model_text_ctrl->SetHint(_L("Input Custom Model"));
m_custom_model_text_ctrl->Bind(wxEVT_CHAR, [this](wxKeyEvent &event) {
int key = event.GetKeyCode();
if (cannot_input_key.find(key) != cannot_input_key.end()) { // "@" can not be inputed
event.Skip(false);
return;
}
event.Skip();
});
comboBoxSizer->Add(m_custom_model_text_ctrl, 0, wxEXPAND | wxLEFT, FromDIP(5));
m_custom_model_text_ctrl->Hide();
vertical_sizer->Add(comboBoxSizer, 0, wxEXPAND, 0);
wxBoxSizer *checkbox_sizer = new wxBoxSizer(wxHORIZONTAL);
m_can_not_find_vendor_combox = new ::CheckBox(parent);
checkbox_sizer->Add(m_can_not_find_vendor_combox, 0, wxALIGN_CENTER, 0);
checkbox_sizer->Add(0, 0, 0, wxEXPAND | wxRIGHT, FromDIP(5));
m_can_not_find_vendor_text = new wxStaticText(parent, wxID_ANY, _L("Can't find my printer model"), wxDefaultPosition, wxDefaultSize, 0);
m_can_not_find_vendor_text->SetFont(::Label::Body_13);
wxSize size = m_can_not_find_vendor_text->GetTextExtent(_L("Can't find my printer model"));
m_can_not_find_vendor_text->SetMinSize(wxSize(size.x + FromDIP(4), -1));
m_can_not_find_vendor_text->Wrap(-1);
checkbox_sizer->Add(m_can_not_find_vendor_text, 0, wxALIGN_CENTER, 0);
m_can_not_find_vendor_combox->Bind(wxEVT_TOGGLEBUTTON, [this](wxCommandEvent &e) {
bool value = m_can_not_find_vendor_combox->GetValue();
if (value) {
m_can_not_find_vendor_combox->SetValue(true);
m_custom_vendor_text_ctrl->Show();
m_custom_model_text_ctrl->Show();
m_select_vendor->Hide();
m_select_model->Hide();
} else {
m_can_not_find_vendor_combox->SetValue(false);
m_custom_vendor_text_ctrl->Hide();
m_custom_model_text_ctrl->Hide();
m_select_vendor->Show();
m_select_model->Show();
}
Refresh();
Layout();
m_page1->SetSizerAndFit(m_page1_sizer);
Fit();
});
vertical_sizer->Add(checkbox_sizer, 0, wxEXPAND | wxTOP, FromDIP(5));
horizontal_sizer->Add(vertical_sizer, 0, wxEXPAND | wxALL | wxALIGN_CENTER_VERTICAL, FromDIP(10));
return horizontal_sizer;
}
wxBoxSizer *CreatePrinterPresetDialog::create_nozzle_diameter_item(wxWindow *parent)
{
wxBoxSizer *horizontal_sizer = new wxBoxSizer(wxHORIZONTAL);
wxBoxSizer * optionSizer = new wxBoxSizer(wxVERTICAL);
wxStaticText *static_type_text = new wxStaticText(parent, wxID_ANY, _L("Nozzle Diameter"), wxDefaultPosition, wxDefaultSize);
optionSizer->Add(static_type_text, 0, wxEXPAND | wxALL, 0);
optionSizer->SetMinSize(OPTION_SIZE);
horizontal_sizer->Add(optionSizer, 0, wxEXPAND | wxALL | wxALIGN_CENTER_VERTICAL, FromDIP(10));
wxBoxSizer *comboBoxSizer = new wxBoxSizer(wxVERTICAL);
m_nozzle_diameter = new ComboBox(parent, wxID_ANY, wxEmptyString, wxDefaultPosition, OPTION_SIZE, 0, nullptr, wxCB_READONLY);
wxArrayString nozzle_diameters;
for (const std::string nozzle : nozzle_diameter_vec) {
nozzle_diameters.Add(nozzle + " mm");
}
m_nozzle_diameter->Set(nozzle_diameters);
m_nozzle_diameter->SetSelection(0);
comboBoxSizer->Add(m_nozzle_diameter, 0, wxEXPAND | wxALL, 0);
horizontal_sizer->Add(comboBoxSizer, 0, wxEXPAND | wxALL | wxALIGN_CENTER_VERTICAL, FromDIP(10));
horizontal_sizer->Add(0, 0, 0, wxEXPAND | wxLEFT, FromDIP(200));
return horizontal_sizer;
}
wxBoxSizer *CreatePrinterPresetDialog::create_bed_shape_item(wxWindow *parent)
{
wxBoxSizer *horizontal_sizer = new wxBoxSizer(wxHORIZONTAL);
wxBoxSizer * optionSizer = new wxBoxSizer(wxVERTICAL);
wxStaticText *static_type_text = new wxStaticText(parent, wxID_ANY, _L("Bed Shape"), wxDefaultPosition, wxDefaultSize);
optionSizer->Add(static_type_text, 0, wxEXPAND | wxALL, 0);
optionSizer->SetMinSize(OPTION_SIZE);
horizontal_sizer->Add(optionSizer, 0, wxEXPAND | wxALL | wxALIGN_CENTER_VERTICAL, FromDIP(10));
wxBoxSizer * bed_shape_sizer = new wxBoxSizer(wxVERTICAL);
wxStaticText *static_bed_shape_text = new wxStaticText(parent, wxID_ANY, _L("Rectangle"), wxDefaultPosition, wxDefaultSize);
bed_shape_sizer->Add(static_bed_shape_text, 0, wxEXPAND | wxALL, 0);
horizontal_sizer->Add(bed_shape_sizer, 0, wxEXPAND | wxALL | wxALIGN_CENTER_VERTICAL, FromDIP(10));
return horizontal_sizer;
}
wxBoxSizer *CreatePrinterPresetDialog::create_bed_size_item(wxWindow *parent)
{
wxBoxSizer *horizontal_sizer = new wxBoxSizer(wxHORIZONTAL);
wxBoxSizer * optionSizer = new wxBoxSizer(wxVERTICAL);
wxStaticText *static_type_text = new wxStaticText(parent, wxID_ANY, _L("Printable Space"), wxDefaultPosition, wxDefaultSize);
optionSizer->Add(static_type_text, 0, wxEXPAND | wxALL, 0);
optionSizer->SetMinSize(OPTION_SIZE);
horizontal_sizer->Add(optionSizer, 0, wxEXPAND | wxALL | wxALIGN_CENTER_VERTICAL, FromDIP(10));
wxBoxSizer * length_sizer = new wxBoxSizer(wxVERTICAL);
wxStaticText *static_length_text = new wxStaticText(parent, wxID_ANY, _L("X"), wxDefaultPosition, wxDefaultSize);
static_length_text->SetMinSize(ORIGIN_TEXT_SIZE);
static_length_text->SetSize(ORIGIN_TEXT_SIZE);
length_sizer->Add(static_length_text, 0, wxEXPAND | wxALL, 0);
horizontal_sizer->Add(length_sizer, 0, wxEXPAND | wxLEFT | wxTOP | wxALIGN_CENTER_VERTICAL, FromDIP(10));
wxBoxSizer *length_input_sizer = new wxBoxSizer(wxVERTICAL);
m_bed_size_x_input = new TextInput(parent, "200", "mm", wxEmptyString, wxDefaultPosition, PRINTER_SPACE_SIZE, wxTE_CENTRE | wxTE_PROCESS_ENTER);
wxTextValidator validator(wxFILTER_DIGITS);
m_bed_size_x_input->GetTextCtrl()->SetValidator(validator);
length_input_sizer->Add(m_bed_size_x_input, 0, wxEXPAND | wxALL, 0);
horizontal_sizer->Add(length_input_sizer, 0, wxEXPAND | wxALL | wxALIGN_CENTER_VERTICAL, FromDIP(5));
wxBoxSizer * width_sizer = new wxBoxSizer(wxVERTICAL);
wxStaticText *static_width_text = new wxStaticText(parent, wxID_ANY, _L("Y"), wxDefaultPosition, wxDefaultSize);
static_width_text->SetMinSize(ORIGIN_TEXT_SIZE);
static_width_text->SetSize(ORIGIN_TEXT_SIZE);
width_sizer->Add(static_width_text, 0, wxEXPAND | wxALL, 0);
horizontal_sizer->Add(width_sizer, 0, wxEXPAND | wxLEFT | wxTOP | wxALIGN_CENTER_VERTICAL, FromDIP(10));
wxBoxSizer *width_input_sizer = new wxBoxSizer(wxVERTICAL);
m_bed_size_y_input = new TextInput(parent, "200", "mm", wxEmptyString, wxDefaultPosition, PRINTER_SPACE_SIZE, wxTE_CENTRE | wxTE_PROCESS_ENTER);
m_bed_size_y_input->GetTextCtrl()->SetValidator(validator);
width_input_sizer->Add(m_bed_size_y_input, 0, wxEXPAND | wxALL, 0);
horizontal_sizer->Add(width_input_sizer, 0, wxEXPAND | wxALL | wxALIGN_CENTER_VERTICAL, FromDIP(5));
return horizontal_sizer;
}
wxBoxSizer *CreatePrinterPresetDialog::create_origin_item(wxWindow *parent)
{
wxBoxSizer *horizontal_sizer = new wxBoxSizer(wxHORIZONTAL);
wxBoxSizer * optionSizer = new wxBoxSizer(wxVERTICAL);
wxStaticText *static_type_text = new wxStaticText(parent, wxID_ANY, _L("Origin"), wxDefaultPosition, wxDefaultSize);
optionSizer->Add(static_type_text, 0, wxEXPAND | wxALL, 0);
optionSizer->SetMinSize(OPTION_SIZE);
horizontal_sizer->Add(optionSizer, 0, wxEXPAND | wxALL | wxALIGN_CENTER_VERTICAL, FromDIP(10));
wxBoxSizer * length_sizer = new wxBoxSizer(wxVERTICAL);
wxStaticText *static_origin_x_text = new wxStaticText(parent, wxID_ANY, _L("X"), wxDefaultPosition, wxDefaultSize);
static_origin_x_text->SetMinSize(ORIGIN_TEXT_SIZE);
static_origin_x_text->SetSize(ORIGIN_TEXT_SIZE);
length_sizer->Add(static_origin_x_text, 0, wxEXPAND | wxALL, 0);
horizontal_sizer->Add(length_sizer, 0, wxEXPAND | wxLEFT | wxTOP | wxALIGN_CENTER_VERTICAL, FromDIP(10));
wxBoxSizer *length_input_sizer = new wxBoxSizer(wxVERTICAL);
m_bed_origin_x_input = new TextInput(parent, "0", "mm", wxEmptyString, wxDefaultPosition, PRINTER_SPACE_SIZE, wxTE_CENTRE | wxTE_PROCESS_ENTER);
wxTextValidator validator(wxFILTER_DIGITS);
m_bed_origin_x_input->GetTextCtrl()->SetValidator(validator);
length_input_sizer->Add(m_bed_origin_x_input, 0, wxEXPAND | wxALL, 0);
horizontal_sizer->Add(length_input_sizer, 0, wxEXPAND | wxALL | wxALIGN_CENTER_VERTICAL, FromDIP(5));
wxBoxSizer * width_sizer = new wxBoxSizer(wxVERTICAL);
wxStaticText *static_origin_y_text = new wxStaticText(parent, wxID_ANY, _L("Y"), wxDefaultPosition, wxDefaultSize);
static_origin_y_text->SetMinSize(ORIGIN_TEXT_SIZE);
static_origin_y_text->SetSize(ORIGIN_TEXT_SIZE);
width_sizer->Add(static_origin_y_text, 0, wxEXPAND | wxALL, 0);
horizontal_sizer->Add(width_sizer, 0, wxEXPAND | wxLEFT | wxTOP | wxALIGN_CENTER_VERTICAL, FromDIP(10));
wxBoxSizer *width_input_sizer = new wxBoxSizer(wxVERTICAL);
m_bed_origin_y_input = new TextInput(parent, "0", "mm", wxEmptyString, wxDefaultPosition, PRINTER_SPACE_SIZE, wxTE_CENTRE | wxTE_PROCESS_ENTER);
m_bed_origin_y_input->GetTextCtrl()->SetValidator(validator);
width_input_sizer->Add(m_bed_origin_y_input, 0, wxEXPAND | wxALL, 0);
horizontal_sizer->Add(width_input_sizer, 0, wxEXPAND | wxALL | wxALIGN_CENTER_VERTICAL, FromDIP(5));
return horizontal_sizer;
}
wxBoxSizer *CreatePrinterPresetDialog::create_hot_bed_stl_item(wxWindow *parent)
{
wxBoxSizer *horizontal_sizer = new wxBoxSizer(wxHORIZONTAL);
wxBoxSizer * optionSizer = new wxBoxSizer(wxVERTICAL);
wxStaticText *static_type_text = new wxStaticText(parent, wxID_ANY, _L("Hot Bed STL"), wxDefaultPosition, wxDefaultSize);
optionSizer->Add(static_type_text, 0, wxEXPAND | wxALL, 0);
optionSizer->SetMinSize(OPTION_SIZE);
horizontal_sizer->Add(optionSizer, 0, wxEXPAND | wxALL | wxALIGN_CENTER_VERTICAL, FromDIP(10));
wxBoxSizer *hot_bed_stl_sizer = new wxBoxSizer(wxVERTICAL);
StateColor flush_bg_col(std::pair<wxColour, int>(wxColour(219, 253, 231), StateColor::Pressed), std::pair<wxColour, int>(wxColour(238, 238, 238), StateColor::Hovered),
std::pair<wxColour, int>(wxColour(238, 238, 238), StateColor::Normal));
StateColor flush_bd_col(std::pair<wxColour, int>(wxColour(0, 150, 136), StateColor::Pressed), std::pair<wxColour, int>(wxColour(0, 150, 136), StateColor::Hovered),
std::pair<wxColour, int>(wxColour(172, 172, 172), StateColor::Normal));
m_button_bed_stl = new Button(parent, _L("Load stl"));
m_button_bed_stl->Bind(wxEVT_BUTTON, ([this](wxCommandEvent &e) { load_model_stl(); }));
m_button_bed_stl->SetFont(Label::Body_10);
m_button_bed_stl->SetPaddingSize(wxSize(FromDIP(30), FromDIP(8)));
m_button_bed_stl->SetFont(Label::Body_13);
m_button_bed_stl->SetCornerRadius(FromDIP(8));
m_button_bed_stl->SetBackgroundColor(flush_bg_col);
m_button_bed_stl->SetBorderColor(flush_bd_col);
hot_bed_stl_sizer->Add(m_button_bed_stl, 0, wxEXPAND | wxALL, 0);
horizontal_sizer->Add(hot_bed_stl_sizer, 0, wxEXPAND | wxLEFT | wxALIGN_CENTER_VERTICAL, FromDIP(10));
m_upload_stl_tip_text = new wxStaticText(parent, wxID_ANY, "", wxDefaultPosition, wxDefaultSize);
m_upload_stl_tip_text->SetLabelText(_L("Empty"));
horizontal_sizer->Add(m_upload_stl_tip_text, 0, wxEXPAND | wxALL | wxALIGN_CENTER_VERTICAL, FromDIP(10));
return horizontal_sizer;
}
wxBoxSizer *CreatePrinterPresetDialog::create_hot_bed_svg_item(wxWindow *parent)
{
wxBoxSizer *horizontal_sizer = new wxBoxSizer(wxHORIZONTAL);
wxBoxSizer * optionSizer = new wxBoxSizer(wxVERTICAL);
wxStaticText *static_type_text = new wxStaticText(parent, wxID_ANY, _L("Hot Bed SVG"), wxDefaultPosition, wxDefaultSize);
optionSizer->Add(static_type_text, 0, wxEXPAND | wxALL, 0);
optionSizer->SetMinSize(OPTION_SIZE);
horizontal_sizer->Add(optionSizer, 0, wxEXPAND | wxALL | wxALIGN_CENTER_VERTICAL, FromDIP(10));
wxBoxSizer *hot_bed_stl_sizer = new wxBoxSizer(wxVERTICAL);
StateColor flush_bg_col(std::pair<wxColour, int>(wxColour(219, 253, 231), StateColor::Pressed), std::pair<wxColour, int>(wxColour(238, 238, 238), StateColor::Hovered),
std::pair<wxColour, int>(wxColour(238, 238, 238), StateColor::Normal));
StateColor flush_bd_col(std::pair<wxColour, int>(wxColour(0, 150, 136), StateColor::Pressed), std::pair<wxColour, int>(wxColour(0, 150, 136), StateColor::Hovered),
std::pair<wxColour, int>(wxColour(172, 172, 172), StateColor::Normal));
m_button_bed_svg = new Button(parent, _L("Load svg"));
m_button_bed_svg->Bind(wxEVT_BUTTON, ([this](wxCommandEvent &e) { load_texture(); }));
m_button_bed_svg->SetFont(Label::Body_10);
m_button_bed_svg->SetPaddingSize(wxSize(FromDIP(30), FromDIP(8)));
m_button_bed_svg->SetFont(Label::Body_13);
m_button_bed_svg->SetCornerRadius(FromDIP(8));
m_button_bed_svg->SetBackgroundColor(flush_bg_col);
m_button_bed_svg->SetBorderColor(flush_bd_col);
hot_bed_stl_sizer->Add(m_button_bed_svg, 0, wxEXPAND | wxALL, 0);
horizontal_sizer->Add(hot_bed_stl_sizer, 0, wxEXPAND | wxLEFT | wxALIGN_CENTER_VERTICAL, FromDIP(10));
m_upload_svg_tip_text = new wxStaticText(parent, wxID_ANY, "", wxDefaultPosition, wxDefaultSize);
m_upload_svg_tip_text->SetLabelText(_L("Empty"));
horizontal_sizer->Add(m_upload_svg_tip_text, 0, wxEXPAND | wxALL | wxALIGN_CENTER_VERTICAL, FromDIP(10));
return horizontal_sizer;
}
wxBoxSizer *CreatePrinterPresetDialog::create_max_print_height_item(wxWindow *parent)
{
wxBoxSizer * horizontal_sizer = new wxBoxSizer(wxHORIZONTAL);
wxBoxSizer * optionSizer = new wxBoxSizer(wxVERTICAL);
wxStaticText *static_type_text = new wxStaticText(parent, wxID_ANY, _L("Max Print Height"), wxDefaultPosition, wxDefaultSize);
optionSizer->Add(static_type_text, 0, wxEXPAND | wxALL, 0);
optionSizer->SetMinSize(OPTION_SIZE);
horizontal_sizer->Add(optionSizer, 0, wxEXPAND | wxALL | wxALIGN_CENTER_VERTICAL, FromDIP(10));
wxBoxSizer *hight_input_sizer = new wxBoxSizer(wxVERTICAL);
m_print_height_input = new TextInput(parent, "200", "mm", wxEmptyString, wxDefaultPosition, PRINTER_SPACE_SIZE, wxTE_CENTRE | wxTE_PROCESS_ENTER);
wxTextValidator validator(wxFILTER_DIGITS);
m_print_height_input->GetTextCtrl()->SetValidator(validator);
hight_input_sizer->Add(m_print_height_input, 0, wxEXPAND | wxLEFT, FromDIP(5));
horizontal_sizer->Add(hight_input_sizer, 0, wxEXPAND | wxALL | wxALIGN_CENTER_VERTICAL, FromDIP(5));
return horizontal_sizer;
}
wxBoxSizer *CreatePrinterPresetDialog::create_page1_btns_item(wxWindow *parent)
{
wxBoxSizer *bSizer_button = new wxBoxSizer(wxHORIZONTAL);
bSizer_button->Add(0, 0, 1, wxEXPAND, 0);
StateColor btn_bg_green(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_OK = new Button(parent, _L("OK"));
m_button_OK->SetBackgroundColor(btn_bg_green);
m_button_OK->SetBorderColor(*wxWHITE);
m_button_OK->SetTextColor(wxColour(0xFFFFFE));
m_button_OK->SetFont(Label::Body_12);
m_button_OK->SetSize(wxSize(FromDIP(58), FromDIP(24)));
m_button_OK->SetMinSize(wxSize(FromDIP(58), FromDIP(24)));
m_button_OK->SetCornerRadius(FromDIP(12));
bSizer_button->Add(m_button_OK, 0, wxRIGHT, FromDIP(10));
m_button_OK->Bind(wxEVT_LEFT_DOWN, [this](wxMouseEvent &e) {
if (!validate_input_valid()) return;
data_init();
show_page2();
});
StateColor btn_bg_white(std::pair<wxColour, int>(wxColour(206, 206, 206), StateColor::Pressed), std::pair<wxColour, int>(wxColour(238, 238, 238), StateColor::Hovered),
std::pair<wxColour, int>(*wxWHITE, StateColor::Normal));
m_button_page1_cancel = new Button(parent, _L("Cancel"));
m_button_page1_cancel->SetBackgroundColor(btn_bg_white);
m_button_page1_cancel->SetBorderColor(wxColour(38, 46, 48));
m_button_page1_cancel->SetFont(Label::Body_12);
m_button_page1_cancel->SetSize(wxSize(FromDIP(58), FromDIP(24)));
m_button_page1_cancel->SetMinSize(wxSize(FromDIP(58), FromDIP(24)));
m_button_page1_cancel->SetCornerRadius(FromDIP(12));
bSizer_button->Add(m_button_page1_cancel, 0, wxRIGHT, FromDIP(10));
m_button_page1_cancel->Bind(wxEVT_LEFT_DOWN, [this](wxMouseEvent &e) { EndModal(wxID_CANCEL); });
return bSizer_button;
}
static std::string last_directory = "";
void CreatePrinterPresetDialog::load_texture() {
wxFileDialog dialog(this, _L("Choose a file to import bed texture from (PNG/SVG):"), last_directory, "", file_wildcards(FT_TEX), wxFD_OPEN | wxFD_FILE_MUST_EXIST);
if (dialog.ShowModal() != wxID_OK)
return;
m_custom_texture = "";
m_upload_svg_tip_text->SetLabelText(_L("Empty"));
last_directory = dialog.GetDirectory().ToUTF8().data();
std::string file_name = dialog.GetPath().ToUTF8().data();
if (!boost::algorithm::iends_with(file_name, ".png") && !boost::algorithm::iends_with(file_name, ".svg")) {
show_error(this, _L("Invalid file format."));
return;
}
bool try_ok;
if (Utils::is_file_too_large(file_name, try_ok)) {
if (try_ok) {
m_upload_svg_tip_text->SetLabelText(wxString::Format(_L("The file exceeds %d MB, please import again."), STL_SVG_MAX_FILE_SIZE_MB));
} else {
m_upload_svg_tip_text->SetLabelText(_L("Exception in obtaining file size, please import again."));
}
return;
}
m_custom_texture = file_name;
wxGCDC dc;
auto text = wxControl::Ellipsize(_L(boost::filesystem::path(file_name).filename().string()), dc, wxELLIPSIZE_END, FromDIP(200));
m_upload_svg_tip_text->SetLabelText(text);
}
void CreatePrinterPresetDialog::load_model_stl()
{
wxFileDialog dialog(this, _L("Choose an STL file to import bed model from:"), last_directory, "", file_wildcards(FT_STL), wxFD_OPEN | wxFD_FILE_MUST_EXIST);
if (dialog.ShowModal() != wxID_OK)
return;
m_custom_model = "";
m_upload_stl_tip_text->SetLabelText(_L("Empty"));
last_directory = dialog.GetDirectory().ToUTF8().data();
std::string file_name = dialog.GetPath().ToUTF8().data();
if (!boost::algorithm::iends_with(file_name, ".stl")) {
show_error(this, _L("Invalid file format."));
return;
}
bool try_ok;
if (Utils::is_file_too_large(file_name, try_ok)) {
if (try_ok) {
m_upload_stl_tip_text->SetLabelText(wxString::Format(_L("The file exceeds %d MB, please import again."), STL_SVG_MAX_FILE_SIZE_MB));
}
else {
m_upload_stl_tip_text->SetLabelText(_L("Exception in obtaining file size, please import again."));
}
return;
}
m_custom_model = file_name;
wxGCDC dc;
auto text = wxControl::Ellipsize(_L(boost::filesystem::path(file_name).filename().string()), dc, wxELLIPSIZE_END, FromDIP(200));
m_upload_stl_tip_text->SetLabelText(text);
}
bool CreatePrinterPresetDialog::load_system_and_user_presets_with_curr_model(PresetBundle &temp_preset_bundle, bool just_template)
{
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " is load template: "<< just_template;
std::string selected_vendor_id;
std::string preset_path;
if (m_printer_preset) {
delete m_printer_preset;
m_printer_preset = nullptr;
}
std::string curr_selected_model = into_u8(m_printer_model->GetStringSelection());
int nozzle_index = curr_selected_model.find_first_of("@");
std::string select_model = curr_selected_model.substr(0, nozzle_index - 1);
for (const Slic3r::VendorProfile::PrinterModel &model : m_printer_preset_vendor_selected.models) {
if (model.name == select_model) {
m_printer_preset_model_selected = model;
break;
}
}
if (m_printer_preset_vendor_selected.id.empty() || m_printer_preset_model_selected.id.empty()) {
BOOST_LOG_TRIVIAL(info) << "selected id is not find";
MessageDialog dlg(this, _L("Preset path is not find, please reselect vendor."), wxString(SLIC3R_APP_FULL_NAME) + " - " + _L("Info"), wxYES_NO | wxYES_DEFAULT | wxCENTRE);
dlg.ShowModal();
return false;
}
bool is_custom_vendor = false;
if (PRESET_CUSTOM_VENDOR == m_printer_preset_vendor_selected.name || PRESET_CUSTOM_VENDOR == m_printer_preset_vendor_selected.id) {
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " select custom vendor ";
is_custom_vendor = true;
temp_preset_bundle = *(wxGetApp().preset_bundle);
} else {
selected_vendor_id = m_printer_preset_vendor_selected.id;
if (boost::filesystem::exists(boost::filesystem::path(Slic3r::data_dir()) / PRESET_SYSTEM_DIR / selected_vendor_id)) {
preset_path = (boost::filesystem::path(Slic3r::data_dir()) / PRESET_SYSTEM_DIR).string();
} else if (boost::filesystem::exists(boost::filesystem::path(Slic3r::resources_dir()) / "profiles" / selected_vendor_id)) {
preset_path = (boost::filesystem::path(Slic3r::resources_dir()) / "profiles").string();
}
if (preset_path.empty()) {
BOOST_LOG_TRIVIAL(info) << "Preset path is not find";
MessageDialog dlg(this, _L("Preset path is not find, please reselect vendor."), wxString(SLIC3R_APP_FULL_NAME) + " - " + _L("Info"),
wxYES_NO | wxYES_DEFAULT | wxCENTRE);
dlg.ShowModal();
return false;
}
try {
temp_preset_bundle.load_vendor_configs_from_json(preset_path, selected_vendor_id, PresetBundle::LoadConfigBundleAttribute::LoadSystem,
ForwardCompatibilitySubstitutionRule::EnableSilent);
} catch (...) {
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << "load vendor fonfigs form json failed";
MessageDialog dlg(this, _L("The printer model was not found, please reselect."), wxString(SLIC3R_APP_FULL_NAME) + " - " + _L("Info"),
wxYES_NO | wxYES_DEFAULT | wxCENTRE);
dlg.ShowModal();
return false;
}
if (!just_template) {
std::string dir_user_presets = wxGetApp().app_config->get("preset_folder");
if (dir_user_presets.empty()) {
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << "default user presets path";
temp_preset_bundle.load_user_presets(DEFAULT_USER_FOLDER_NAME, ForwardCompatibilitySubstitutionRule::EnableSilent);
} else {
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << "user presets path";
temp_preset_bundle.load_user_presets(dir_user_presets, ForwardCompatibilitySubstitutionRule::EnableSilent);
}
}
}
//get model varient
std::string model_varient = into_u8(m_printer_model->GetStringSelection());
size_t index_at = model_varient.find(" @ ");
size_t index_nozzle = model_varient.find("nozzle");
std::string varient;
if (index_at != std::string::npos && index_nozzle != std::string::npos) {
varient = model_varient.substr(index_at + 3, index_nozzle - index_at - 4);
} else {
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << "get nozzle failed";
MessageDialog dlg(this, _L("The nozzle diameter is not fond, place reselect."), wxString(SLIC3R_APP_FULL_NAME) + " - " + _L("Info"), wxYES_NO | wxYES_DEFAULT | wxCENTRE);
dlg.ShowModal();
return false;
}
const Preset *temp_printer_preset = is_custom_vendor ? temp_preset_bundle.printers.find_custom_preset_by_model_and_variant(m_printer_preset_model_selected.id, varient) :
temp_preset_bundle.printers.find_system_preset_by_model_and_variant(m_printer_preset_model_selected.id, varient);
if (temp_printer_preset) {
m_printer_preset = new Preset(*temp_printer_preset);
} else {
MessageDialog dlg(this, _L("The printer preset is not fond, place reselect."), wxString(SLIC3R_APP_FULL_NAME) + " - " + _L("Info"), wxYES_NO | wxYES_DEFAULT | wxCENTRE);
dlg.ShowModal();
return false;
}
if (!just_template) {
temp_preset_bundle.printers.select_preset_by_name(m_printer_preset->name, true);
temp_preset_bundle.update_compatible(PresetSelectCompatibleType::Always);
} else {
selected_vendor_id = PRESET_TEMPLATE_DIR;
preset_path.clear();
if (boost::filesystem::exists(boost::filesystem::path(Slic3r::resources_dir()) / PRESET_PROFILES_TEMOLATE_DIR / selected_vendor_id)) {
preset_path = (boost::filesystem::path(Slic3r::resources_dir()) / PRESET_PROFILES_TEMOLATE_DIR).string();
}
if (preset_path.empty()) {
BOOST_LOG_TRIVIAL(info) << "Preset path is not find";
MessageDialog dlg(this, _L("Preset path is not find, please reselect vendor."), wxString(SLIC3R_APP_FULL_NAME) + " - " + _L("Info"),
wxYES_NO | wxYES_DEFAULT | wxCENTRE);
dlg.ShowModal();
return false;
}
try {
temp_preset_bundle.load_vendor_configs_from_json(preset_path, selected_vendor_id, PresetBundle::LoadConfigBundleAttribute::LoadSystem,
ForwardCompatibilitySubstitutionRule::EnableSilent);
} catch (...) {
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << "load template vendor configs form json failed";
MessageDialog dlg(this, _L("The printer model was not found, please reselect."), wxString(SLIC3R_APP_FULL_NAME) + " - " + _L("Info"),
wxYES_NO | wxYES_DEFAULT | wxCENTRE);
dlg.ShowModal();
return false;
}
}
return true;
}
void CreatePrinterPresetDialog::generate_process_presets_data(std::vector<Preset const *> presets, std::string nozzle)
{
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " entry, and nozzle is: " << nozzle;
std::unordered_map<std::string, float> nozzle_diameter_map_ = nozzle_diameter_map;
for (const Preset *preset : presets) {
float nozzle_dia = nozzle_diameter_map_[nozzle];
assert(nozzle_dia != 0);
auto layer_height = dynamic_cast<ConfigOptionFloat *>(const_cast<Preset *>(preset)->config.option("layer_height", true));
if (layer_height)
layer_height->value = nozzle_dia / 2;
else
BOOST_LOG_TRIVIAL(info) << "process template has no layer_height";
auto initial_layer_print_height = dynamic_cast<ConfigOptionFloat *>(const_cast<Preset *>(preset)->config.option("initial_layer_print_height", true));
if (initial_layer_print_height)
initial_layer_print_height->value = nozzle_dia / 2;
else
BOOST_LOG_TRIVIAL(info) << "process template has no initial_layer_print_height";
auto line_width = dynamic_cast<ConfigOptionFloat *>(const_cast<Preset *>(preset)->config.option("line_width", true));
if (line_width)
line_width->value = nozzle_dia;
else
BOOST_LOG_TRIVIAL(info) << "process template has no line_width";
auto initial_layer_line_width = dynamic_cast<ConfigOptionFloat *>(const_cast<Preset *>(preset)->config.option("initial_layer_line_width", true));
if (initial_layer_line_width)
initial_layer_line_width->value = nozzle_dia;
else
BOOST_LOG_TRIVIAL(info) << "process template has no initial_layer_line_width";
auto outer_wall_line_width = dynamic_cast<ConfigOptionFloat *>(const_cast<Preset *>(preset)->config.option("outer_wall_line_width", true));
if (outer_wall_line_width)
outer_wall_line_width->value = nozzle_dia;
else
BOOST_LOG_TRIVIAL(info) << "process template has no outer_wall_line_width";
auto inner_wall_line_width = dynamic_cast<ConfigOptionFloat *>(const_cast<Preset *>(preset)->config.option("inner_wall_line_width", true));
if (inner_wall_line_width)
inner_wall_line_width->value = nozzle_dia;
else
BOOST_LOG_TRIVIAL(info) << "process template has no inner_wall_line_width";
auto top_surface_line_width = dynamic_cast<ConfigOptionFloat *>(const_cast<Preset *>(preset)->config.option("top_surface_line_width", true));
if (top_surface_line_width)
top_surface_line_width->value = nozzle_dia;
else
BOOST_LOG_TRIVIAL(info) << "process template has no top_surface_line_width";
auto sparse_infill_line_width = dynamic_cast<ConfigOptionFloat *>(const_cast<Preset *>(preset)->config.option("sparse_infill_line_width", true));
if (sparse_infill_line_width)
sparse_infill_line_width->value = nozzle_dia;
else
BOOST_LOG_TRIVIAL(info) << "process template has no sparse_infill_line_width";
auto internal_solid_infill_line_width = dynamic_cast<ConfigOptionFloat *>(const_cast<Preset *>(preset)->config.option("internal_solid_infill_line_width", true));
if (internal_solid_infill_line_width)
internal_solid_infill_line_width->value = nozzle_dia;
else
BOOST_LOG_TRIVIAL(info) << "process template has no internal_solid_infill_line_width";
auto support_line_width = dynamic_cast<ConfigOptionFloat *>(const_cast<Preset *>(preset)->config.option("support_line_width", true));
if (support_line_width)
support_line_width->value = nozzle_dia;
else
BOOST_LOG_TRIVIAL(info) << "process template has no support_line_width";
auto wall_loops = dynamic_cast<ConfigOptionInt *>(const_cast<Preset *>(preset)->config.option("wall_loops", true));
if (wall_loops)
wall_loops->value = std::max(2, (int) std::ceil(2 * 0.4 / nozzle_dia));
else
BOOST_LOG_TRIVIAL(info) << "process template has no wall_loops";
auto top_shell_layers = dynamic_cast<ConfigOptionInt *>(const_cast<Preset *>(preset)->config.option("top_shell_layers", true));
if (top_shell_layers)
top_shell_layers->value = std::max(5, (int) std::ceil(5 * 0.4 / nozzle_dia));
else
BOOST_LOG_TRIVIAL(info) << "process template has no top_shell_layers";
auto bottom_shell_layers = dynamic_cast<ConfigOptionInt *>(const_cast<Preset *>(preset)->config.option("bottom_shell_layers", true));
if (bottom_shell_layers)
bottom_shell_layers->value = std::max(3, (int) std::ceil(3 * 0.4 / nozzle_dia));
else
BOOST_LOG_TRIVIAL(info) << "process template has no bottom_shell_layers";
}
}
void CreatePrinterPresetDialog::update_preset_list_size()
{
m_scrolled_preset_window->Freeze();
m_preset_template_panel->SetSizerAndFit(m_filament_sizer);
m_preset_template_panel->SetMinSize(wxSize(FromDIP(660), -1));
m_preset_template_panel->SetSize(wxSize(FromDIP(660), -1));
int width = m_preset_template_panel->GetSize().GetWidth();
int height = m_preset_template_panel->GetSize().GetHeight();
m_scrolled_preset_window->SetMinSize(wxSize(std::min(1500, width + FromDIP(26)), std::min(600, height)));
m_scrolled_preset_window->SetMaxSize(wxSize(std::min(1500, width + FromDIP(26)), std::min(600, height)));
m_scrolled_preset_window->SetSize(wxSize(std::min(1500, width + FromDIP(26)), std::min(600, height)));
m_page2->SetSizerAndFit(m_page2_sizer);
Layout();
Fit();
Refresh();
adjust_dialog_in_screen(this);
m_scrolled_preset_window->Thaw();
}
wxBoxSizer *CreatePrinterPresetDialog::create_radio_item(wxString title, wxWindow *parent, wxString tooltip, std::vector<std::pair<RadioBox *, wxString>> &radiobox_list)
{
wxBoxSizer *horizontal_sizer = new wxBoxSizer(wxHORIZONTAL);
RadioBox * radiobox = new RadioBox(parent);
horizontal_sizer->Add(radiobox, 0, wxEXPAND | wxALL, 0);
horizontal_sizer->Add(0, 0, 0, wxEXPAND | wxLEFT, FromDIP(5));
radiobox_list.push_back(std::make_pair(radiobox,title));
int btn_idx = radiobox_list.size() - 1;
radiobox->Bind(wxEVT_LEFT_DOWN, [this, &radiobox_list, btn_idx](wxMouseEvent &e) {
select_curr_radiobox(radiobox_list, btn_idx);
});
wxStaticText *text = new wxStaticText(parent, wxID_ANY, title, wxDefaultPosition, wxDefaultSize);
text->Bind(wxEVT_LEFT_DOWN, [this, &radiobox_list, btn_idx](wxMouseEvent &e) {
select_curr_radiobox(radiobox_list, btn_idx);
});
horizontal_sizer->Add(text, 0, wxEXPAND | wxLEFT, 0);
radiobox->SetToolTip(tooltip);
text->SetToolTip(tooltip);
return horizontal_sizer;
}
void CreatePrinterPresetDialog::select_curr_radiobox(std::vector<std::pair<RadioBox *, wxString>> &radiobox_list, int btn_idx)
{
int len = radiobox_list.size();
for (int i = 0; i < len; ++i) {
if (i == btn_idx) {
radiobox_list[i].first->SetValue(true);
wxString curr_selected_type = radiobox_list[i].second;
this->Freeze();
if (curr_selected_type == m_create_type.base_template) {
if (m_printer_model->GetValue() == _L("Select Model")) {
m_filament_preset_template_sizer->Clear(true);
m_filament_preset.clear();
m_process_preset_template_sizer->Clear(true);
m_process_preset.clear();
} else {
update_presets_list(true);
}
m_page2->SetSizerAndFit(m_page2_sizer);
} else if (curr_selected_type == m_create_type.base_curr_printer) {
if (m_printer_model->GetValue() == _L("Select Model")) {
m_filament_preset_template_sizer->Clear(true);
m_filament_preset.clear();
m_process_preset_template_sizer->Clear(true);
m_process_preset.clear();
} else {
update_presets_list();
}
m_page2->SetSizerAndFit(m_page2_sizer);
} else if (curr_selected_type == m_create_type.create_printer) {
m_select_printer->Hide();
m_can_not_find_vendor_combox->Show();
m_can_not_find_vendor_text->Show();
m_printer_info_panel->Show();
if (m_can_not_find_vendor_combox->GetValue()) {
m_custom_vendor_text_ctrl->Show();
m_custom_model_text_ctrl->Show();
m_select_vendor->Hide();
m_select_model->Hide();
} else {
m_select_vendor->Show();
m_select_model->Show();
}
m_page1->SetSizerAndFit(m_page1_sizer);
} else if (curr_selected_type == m_create_type.create_nozzle) {
set_current_visible_printer();
m_select_vendor->Hide();
m_select_model->Hide();
m_can_not_find_vendor_combox->Hide();
m_can_not_find_vendor_text->Hide();
m_custom_vendor_text_ctrl->Hide();
m_custom_model_text_ctrl->Hide();
m_printer_info_panel->Hide();
m_select_printer->Show();
m_page1->SetSizerAndFit(m_page1_sizer);
}
this->Thaw();
} else {
radiobox_list[i].first->SetValue(false);
}
}
update_preset_list_size();
}
void CreatePrinterPresetDialog::create_printer_page2(wxWindow *parent)
{
this->SetBackgroundColour(*wxWHITE);
m_page2_sizer = new wxBoxSizer(wxVERTICAL);
m_page2_sizer->Add(create_printer_preset_item(parent), 0, wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM, FromDIP(5));
m_page2_sizer->Add(create_presets_item(parent), 0, wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM, FromDIP(5));
m_page2_sizer->Add(create_presets_template_item(parent), 0, wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM, FromDIP(5));
m_page2_sizer->Add(create_page2_btns_item(parent), 0, wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM, FromDIP(5));
parent->SetSizerAndFit(m_page2_sizer);
Layout();
Fit();
wxGetApp().UpdateDlgDarkUI(this);
}
wxBoxSizer *CreatePrinterPresetDialog::create_printer_preset_item(wxWindow *parent)
{
wxBoxSizer *horizontal_sizer = new wxBoxSizer(wxHORIZONTAL);
wxBoxSizer * optionSizer = new wxBoxSizer(wxVERTICAL);
wxStaticText *static_vendor_text = new wxStaticText(parent, wxID_ANY, _L("Printer Preset"), wxDefaultPosition, wxDefaultSize);
optionSizer->Add(static_vendor_text, 0, wxEXPAND | wxALL, 0);
optionSizer->SetMinSize(OPTION_SIZE);
horizontal_sizer->Add(optionSizer, 0, wxEXPAND | wxALL | wxALIGN_CENTER_VERTICAL, FromDIP(10));
wxBoxSizer * vertical_sizer = new wxBoxSizer(wxVERTICAL);
wxStaticText *combobox_title = new wxStaticText(parent, wxID_ANY, m_create_type.base_curr_printer, wxDefaultPosition, wxDefaultSize, 0);
combobox_title->SetFont(::Label::Body_13);
auto size = combobox_title->GetTextExtent(m_create_type.base_curr_printer);
combobox_title->SetMinSize(wxSize(size.x + FromDIP(4), -1));
combobox_title->Wrap(-1);
vertical_sizer->Add(combobox_title, 0, wxEXPAND | wxALL, 0);
wxBoxSizer *comboBox_sizer = new wxBoxSizer(wxHORIZONTAL);
m_printer_vendor = new ComboBox(parent, wxID_ANY, wxEmptyString, wxDefaultPosition, PRINTER_PRESET_VENDOR_SIZE, 0, nullptr, wxCB_READONLY);
m_printer_vendor->SetValue(_L("Select Vendor"));
m_printer_vendor->SetLabelColor(DEFAULT_PROMPT_TEXT_COLOUR);
comboBox_sizer->Add(m_printer_vendor, 0, wxEXPAND, 0);
m_printer_model = new ComboBox(parent, wxID_ANY, wxEmptyString, wxDefaultPosition, PRINTER_PRESET_MODEL_SIZE, 0, nullptr, wxCB_READONLY);
m_printer_model->SetLabelColor(DEFAULT_PROMPT_TEXT_COLOUR);
m_printer_model->SetValue(_L("Select Model"));
comboBox_sizer->Add(m_printer_model, 0, wxEXPAND | wxLEFT, FromDIP(10));
vertical_sizer->Add(comboBox_sizer, 0, wxEXPAND | wxTOP, FromDIP(5));
horizontal_sizer->Add(vertical_sizer, 0, wxEXPAND | wxALL | wxALIGN_CENTER_VERTICAL, FromDIP(10));
return horizontal_sizer;
}
wxBoxSizer *CreatePrinterPresetDialog::create_presets_item(wxWindow *parent)
{
wxBoxSizer *horizontal_sizer = new wxBoxSizer(wxHORIZONTAL);
wxBoxSizer * optionSizer = new wxBoxSizer(wxVERTICAL);
wxStaticText *static_serial_text = new wxStaticText(parent, wxID_ANY, _L("Presets"), wxDefaultPosition, wxDefaultSize);
optionSizer->Add(static_serial_text, 0, wxEXPAND | wxALL, 0);
optionSizer->SetMinSize(OPTION_SIZE);
horizontal_sizer->Add(optionSizer, 0, wxEXPAND | wxALL | wxALIGN_CENTER_VERTICAL, FromDIP(10));
wxBoxSizer *radioBoxSizer = new wxBoxSizer(wxVERTICAL);
radioBoxSizer->Add(create_radio_item(m_create_type.base_template, parent, wxEmptyString, m_create_presets_btns), 0, wxEXPAND | wxALL, 0);
radioBoxSizer->Add(create_radio_item(m_create_type.base_curr_printer, parent, wxEmptyString, m_create_presets_btns), 0, wxEXPAND | wxTOP, FromDIP(10));
horizontal_sizer->Add(radioBoxSizer, 0, wxEXPAND | wxALL | wxALIGN_CENTER_VERTICAL, FromDIP(10));
return horizontal_sizer;
}
wxBoxSizer *CreatePrinterPresetDialog::create_presets_template_item(wxWindow *parent)
{
wxBoxSizer *vertical_sizer = new wxBoxSizer(wxVERTICAL);
m_scrolled_preset_window = new wxScrolledWindow(parent);
m_scrolled_preset_window->SetScrollRate(5, 5);
m_scrolled_preset_window->SetBackgroundColour(*wxWHITE);
//m_scrolled_preset_window->SetMinSize(wxSize(FromDIP(1500), FromDIP(-1)));
m_scrolled_preset_window->SetMaxSize(wxSize(FromDIP(1500), FromDIP(-1)));
m_scrolled_preset_window->SetSize(wxSize(FromDIP(1500), FromDIP(-1)));
m_scrooled_preset_sizer = new wxBoxSizer(wxHORIZONTAL);
m_preset_template_panel = new wxPanel(m_scrolled_preset_window);
m_preset_template_panel->SetSize(wxSize(-1, -1));
m_preset_template_panel->SetBackgroundColour(PRINTER_LIST_COLOUR);
m_preset_template_panel->SetMinSize(wxSize(FromDIP(660), -1));
m_filament_sizer = new wxBoxSizer(wxVERTICAL);
wxStaticText *static_filament_preset_text = new wxStaticText(m_preset_template_panel, wxID_ANY, _L("Filament Preset Template"), wxDefaultPosition, wxDefaultSize);
m_filament_sizer->Add(static_filament_preset_text, 0, wxEXPAND | wxALL, FromDIP(5));
m_filament_preset_panel = new wxPanel(m_preset_template_panel);
m_filament_preset_template_sizer = new wxGridSizer(3, FromDIP(5), FromDIP(5));
m_filament_preset_panel->SetSize(PRESET_TEMPLATE_SIZE);
m_filament_preset_panel->SetSizer(m_filament_preset_template_sizer);
m_filament_sizer->Add(m_filament_preset_panel, 0, wxEXPAND | wxALL, FromDIP(5));
wxBoxSizer *hori_filament_btn_sizer = new wxBoxSizer(wxHORIZONTAL);
wxPanel * filament_btn_panel = new wxPanel(m_preset_template_panel);
filament_btn_panel->SetBackgroundColour(FILAMENT_OPTION_COLOUR);
wxStaticText *filament_sel_all_text = new wxStaticText(filament_btn_panel, wxID_ANY, _L("Select All"), wxDefaultPosition, wxDefaultSize);
filament_sel_all_text->SetForegroundColour(SELECT_ALL_OPTION_COLOUR);
filament_sel_all_text->Bind(wxEVT_LEFT_DOWN, [this](wxMouseEvent &e) {
select_all_preset_template(m_filament_preset);
e.Skip();
});
wxStaticText *filament_desel_all_text = new wxStaticText(filament_btn_panel, wxID_ANY, _L("Deselect All"), wxDefaultPosition, wxDefaultSize);
filament_desel_all_text->SetForegroundColour(SELECT_ALL_OPTION_COLOUR);
filament_desel_all_text->Bind(wxEVT_LEFT_DOWN, [this](wxMouseEvent &e) {
deselect_all_preset_template(m_filament_preset);
e.Skip();
});
hori_filament_btn_sizer->Add(filament_sel_all_text, 0, wxEXPAND | wxALL, FromDIP(5));
hori_filament_btn_sizer->Add(filament_desel_all_text, 0, wxEXPAND | wxALL, FromDIP(5));
filament_btn_panel->SetSizer(hori_filament_btn_sizer);
m_filament_sizer->Add(filament_btn_panel, 0, wxEXPAND, 0);
wxPanel *split_panel = new wxPanel(m_preset_template_panel, wxID_ANY, wxDefaultPosition, wxSize(-1, FromDIP(10)));
split_panel->SetBackgroundColour(wxColour(*wxWHITE));
m_filament_sizer->Add(split_panel, 0, wxEXPAND, 0);
wxStaticText *static_process_preset_text = new wxStaticText(m_preset_template_panel, wxID_ANY, _L("Process Preset Template"), wxDefaultPosition, wxDefaultSize);
m_filament_sizer->Add(static_process_preset_text, 0, wxEXPAND | wxALL, FromDIP(5));
m_process_preset_panel = new wxPanel(m_preset_template_panel);
m_process_preset_panel->SetSize(PRESET_TEMPLATE_SIZE);
m_process_preset_template_sizer = new wxGridSizer(3, FromDIP(5), FromDIP(5));
m_process_preset_panel->SetSizer(m_process_preset_template_sizer);
m_filament_sizer->Add(m_process_preset_panel, 0, wxEXPAND | wxALL, FromDIP(5));
wxBoxSizer *hori_process_btn_sizer = new wxBoxSizer(wxHORIZONTAL);
wxPanel * process_btn_panel = new wxPanel(m_preset_template_panel);
process_btn_panel->SetBackgroundColour(FILAMENT_OPTION_COLOUR);
wxStaticText *process_sel_all_text = new wxStaticText(process_btn_panel, wxID_ANY, _L("Select All"), wxDefaultPosition, wxDefaultSize);
process_sel_all_text->SetForegroundColour(SELECT_ALL_OPTION_COLOUR);
process_sel_all_text->Bind(wxEVT_LEFT_DOWN, [this](wxMouseEvent &e) {
select_all_preset_template(m_process_preset);
e.Skip();
});
wxStaticText *process_desel_all_text = new wxStaticText(process_btn_panel, wxID_ANY, _L("Deselect All"), wxDefaultPosition, wxDefaultSize);
process_desel_all_text->SetForegroundColour(SELECT_ALL_OPTION_COLOUR);
process_desel_all_text->Bind(wxEVT_LEFT_DOWN, [this](wxMouseEvent &e) {
deselect_all_preset_template(m_process_preset);
e.Skip();
});
hori_process_btn_sizer->Add(process_sel_all_text, 0, wxEXPAND | wxALL, FromDIP(5));
hori_process_btn_sizer->Add(process_desel_all_text, 0, wxEXPAND | wxALL, FromDIP(5));
process_btn_panel->SetSizer(hori_process_btn_sizer);
m_filament_sizer->Add(process_btn_panel, 0, wxEXPAND, 0);
m_preset_template_panel->SetSizer(m_filament_sizer);
m_scrooled_preset_sizer->Add(m_preset_template_panel, 0, wxEXPAND | wxALL, 0);
m_scrolled_preset_window->SetSizerAndFit(m_scrooled_preset_sizer);
vertical_sizer->Add(m_scrolled_preset_window, 0, wxEXPAND | wxLEFT | wxRIGHT | wxALIGN_CENTER_VERTICAL, FromDIP(10));
return vertical_sizer;
}
wxBoxSizer *CreatePrinterPresetDialog::create_page2_btns_item(wxWindow *parent)
{
wxBoxSizer *bSizer_button = new wxBoxSizer(wxHORIZONTAL);
bSizer_button->Add(0, 0, 1, wxEXPAND, 0);
StateColor btn_bg_green(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));
StateColor btn_bg_white(std::pair<wxColour, int>(wxColour(206, 206, 206), StateColor::Pressed), std::pair<wxColour, int>(wxColour(238, 238, 238), StateColor::Hovered),
std::pair<wxColour, int>(*wxWHITE, StateColor::Normal));
m_button_page2_back = new Button(parent, _L("Back Page 1"));
m_button_page2_back->SetBackgroundColor(btn_bg_white);
m_button_page2_back->SetBorderColor(wxColour(38, 46, 48));
m_button_page2_back->SetFont(Label::Body_12);
m_button_page2_back->SetSize(wxSize(FromDIP(58), FromDIP(24)));
m_button_page2_back->SetMinSize(wxSize(FromDIP(58), FromDIP(24)));
m_button_page2_back->SetCornerRadius(FromDIP(12));
bSizer_button->Add(m_button_page2_back, 0, wxRIGHT, FromDIP(10));
m_button_page2_back->Bind(wxEVT_LEFT_DOWN, [this](wxMouseEvent &e) { show_page1(); });
m_button_create = new Button(parent, _L("Create"));
m_button_create->SetBackgroundColor(btn_bg_green);
m_button_create->SetBorderColor(*wxWHITE);
m_button_create->SetTextColor(wxColour(0xFFFFFE));
m_button_create->SetFont(Label::Body_12);
m_button_create->SetSize(wxSize(FromDIP(58), FromDIP(24)));
m_button_create->SetMinSize(wxSize(FromDIP(58), FromDIP(24)));
m_button_create->SetCornerRadius(FromDIP(12));
bSizer_button->Add(m_button_create, 0, wxRIGHT, FromDIP(10));
m_button_create->Bind(wxEVT_LEFT_DOWN, [this](wxMouseEvent &e) {
PresetBundle *preset_bundle = wxGetApp().preset_bundle;
const wxString curr_selected_printer_type = curr_create_printer_type();
const wxString curr_selected_preset_type = curr_create_preset_type();
// Confirm if the printer preset exists
if (!m_printer_preset) {
MessageDialog dlg(this, _L("You have not yet chosen which printer preset to create based on. Please choose the vendor and model of the printer"),
wxString(SLIC3R_APP_FULL_NAME) + " - " + _L("Info"), wxYES | wxYES_DEFAULT | wxCENTRE);
dlg.ShowModal();
return;
}
if (!save_printable_area_config(m_printer_preset)) {
MessageDialog dlg(this, _L("You have entered an illegal input in the printable area section on the first page. Please check before creating it."),
wxString(SLIC3R_APP_FULL_NAME) + " - " + _L("Info"), wxYES | wxYES_DEFAULT | wxCENTRE);
dlg.ShowModal();
show_page1();
return;
}
// create preset name
std::string printer_preset_name;
std::string printer_model_name;
std::string printer_nozzle_name;
std::string nozzle_diameter = into_u8(m_nozzle_diameter->GetStringSelection());
size_t index_mm = nozzle_diameter.find("mm");
if (std::string::npos != index_mm) {
nozzle_diameter.replace(index_mm, 2, "nozzle");
}
if (curr_selected_printer_type == m_create_type.create_printer) {
if (m_can_not_find_vendor_combox->GetValue()) {
std::string custom_vendor = into_u8(m_custom_vendor_text_ctrl->GetValue());
std::string custom_model = into_u8(m_custom_model_text_ctrl->GetValue());
if (custom_vendor.empty() || custom_model.empty()) {
MessageDialog dlg(this, _L("The custom printer or model is not inputed, place input."), wxString(SLIC3R_APP_FULL_NAME) + " - " + _L("Info"),
wxYES | wxYES_DEFAULT | wxCENTRE);
dlg.ShowModal();
show_page1();
return;
}
custom_vendor = remove_special_key(custom_vendor);
custom_model = remove_special_key(custom_model);
boost::algorithm::trim(custom_vendor);
boost::algorithm::trim(custom_model);
printer_preset_name = custom_vendor + " " + custom_model + " " + nozzle_diameter;
printer_model_name = custom_vendor + " " + custom_model;
} else {
std::string vender_name = into_u8(m_select_vendor->GetStringSelection());
std::string model_name = into_u8(m_select_model->GetStringSelection());
printer_preset_name = vender_name + " " + model_name + " " + nozzle_diameter;
printer_model_name = vender_name + " " + model_name;
}
} else if (curr_selected_printer_type == m_create_type.create_nozzle) {
std::string selected_printer_preset_name = into_u8(m_select_printer->GetStringSelection());
std::unordered_map<std::string, std::shared_ptr<Preset>>::iterator itor = m_printer_name_to_preset.find(selected_printer_preset_name);
assert(m_printer_name_to_preset.end() != itor);
if (m_printer_name_to_preset.end() != itor) {
std::shared_ptr<Preset> printer_preset = itor->second;
try{
printer_model_name = printer_preset->config.opt_string("printer_model", true);
printer_preset_name = printer_model_name + " " + nozzle_diameter;
}
catch (...) {
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " get config printer_model or , and the name is: " << selected_printer_preset_name;
}
} else {
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " don't get printer preset, and the name is: " << selected_printer_preset_name;
}
}
printer_nozzle_name = nozzle_diameter.substr(0, nozzle_diameter.find(" nozzle"));
// Confirm if the printer preset has a duplicate name
if (!rewritten && preset_bundle->printers.find_preset(printer_preset_name)) {
MessageDialog dlg(this,
_L("The printer preset you created already has a preset with the same name. Do you want to overwrite it?\n\tYes: Overwrite the printer preset with the "
"same name, and filament and process presets with the same preset name will be recreated \nand filament and process presets without the same preset name will be reserve.\n\tCancel: Do not create a preset, return to the "
"creation interface."),
wxString(SLIC3R_APP_FULL_NAME) + " - " + _L("Info"), wxYES | wxCANCEL | wxYES_DEFAULT | wxCENTRE);
int res = dlg.ShowModal();
if (res == wxID_YES) {
rewritten = true;
} else {
return;
}
}
// Confirm if the filament preset is exist
bool filament_preset_is_exist = false;
std::vector<Preset const *> selected_filament_presets;
for (std::pair<::CheckBox *, Preset const *> filament_preset : m_filament_preset) {
if (filament_preset.first->GetValue()) { selected_filament_presets.push_back(filament_preset.second); }
if (!filament_preset_is_exist && preset_bundle->filaments.find_preset(filament_preset.second->alias + " @ " + printer_preset_name) != nullptr) {
filament_preset_is_exist = true;
}
}
if (selected_filament_presets.empty() && !filament_preset_is_exist) {
MessageDialog dlg(this, _L("You need to select at least one filament preset."), wxString(SLIC3R_APP_FULL_NAME) + " - " + _L("Info"), wxYES | wxYES_DEFAULT | wxCENTRE);
dlg.ShowModal();
return;
}
// Confirm if the process preset is exist
bool process_preset_is_exist = false;
std::vector<Preset const *> selected_process_presets;
for (std::pair<::CheckBox *, Preset const *> process_preset : m_process_preset) {
if (process_preset.first->GetValue()) { selected_process_presets.push_back(process_preset.second); }
if (!process_preset_is_exist && preset_bundle->prints.find_preset(process_preset.second->alias + " @" + printer_preset_name) != nullptr) {
process_preset_is_exist = true;
}
}
if (selected_process_presets.empty() && !process_preset_is_exist) {
MessageDialog dlg(this, _L("You need to select at least one process preset."), wxString(SLIC3R_APP_FULL_NAME) + " - " + _L("Info"), wxYES | wxYES_DEFAULT | wxCENTRE);
dlg.ShowModal();
return;
}
std::vector<std::string> successful_preset_names;
if (curr_selected_preset_type == m_create_type.base_template) {
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " base template";
/****************************** clone filament preset ********************************/
std::vector<std::string> failures;
if (!selected_filament_presets.empty()) {
bool create_preset_result = preset_bundle->filaments.create_presets_from_template_for_printer(selected_filament_presets, failures, printer_preset_name, get_filament_id, rewritten);
if (!create_preset_result) {
std::string message;
for (const std::string &failure : failures) { message += "\t" + failure + "\n"; }
MessageDialog dlg(this, _L("Create filament presets failed. As follows:\n") + from_u8(message) + _L("\nDo you want to rewrite it?"),
wxString(SLIC3R_APP_FULL_NAME) + " - " + _L("Info"),
wxYES | wxYES_DEFAULT | wxCENTRE);
int res = dlg.ShowModal();
if (wxID_YES == res) {
create_preset_result = preset_bundle->filaments.create_presets_from_template_for_printer(selected_filament_presets, failures, printer_preset_name,
get_filament_id, true);
} else {
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " printer preset no same preset but filament has same preset, user cancel create the printer preset";
return;
}
}
// save created successfully preset name
for (Preset const *sucessful_preset : selected_filament_presets)
successful_preset_names.push_back(sucessful_preset->name.substr(0, sucessful_preset->name.find(" @")) + " @" + printer_preset_name);
}
/****************************** clone process preset ********************************/
failures.clear();
if (!selected_process_presets.empty()) {
generate_process_presets_data(selected_process_presets, printer_nozzle_name);
bool create_preset_result = preset_bundle->prints.create_presets_from_template_for_printer(selected_process_presets, failures, printer_preset_name,
get_filament_id, rewritten);
if (!create_preset_result) {
std::string message;
for (const std::string &failure : failures) { message += "\t" + failure + "\n"; }
MessageDialog dlg(this, _L("Create process presets failed. As follows:\n") + from_u8(message) + _L("\nDo you want to rewrite it?"),
wxString(SLIC3R_APP_FULL_NAME) + " - " + _L("Info"),
wxYES | wxYES_DEFAULT | wxCENTRE);
int res = dlg.ShowModal();
if (wxID_YES == res) {
create_preset_result = preset_bundle->prints.create_presets_from_template_for_printer(selected_process_presets, failures, printer_preset_name, get_filament_id, true);
} else {
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " printer preset no same preset but process has same preset, user cancel create the printer preset";
return;
}
}
}
} else if (curr_selected_preset_type == m_create_type.base_curr_printer) { // create printer and based on printer
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " base curr printer";
/****************************** clone filament preset ********************************/
std::vector<std::string> failures;
if (!selected_filament_presets.empty()) {
bool create_preset_result = preset_bundle->filaments.clone_presets_for_printer(selected_filament_presets, failures, printer_preset_name, rewritten);
if (!create_preset_result) {
std::string message;
for (const std::string& failure : failures) {
message += "\t" + failure + "\n";
}
MessageDialog dlg(this, _L("Create filament presets failed. As follows:\n") + from_u8(message) + _L("\nDo you want to rewrite it?"),
wxString(SLIC3R_APP_FULL_NAME) + " - " + _L("Info"),
wxYES | wxYES_DEFAULT | wxCENTRE);
int res = dlg.ShowModal();
if (wxID_YES == res) {
create_preset_result = preset_bundle->filaments.clone_presets_for_printer(selected_filament_presets, failures, printer_preset_name, true);
} else {
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " printer preset no same preset but filament has same preset, user cancel create the printer preset";
return;
}
}
}
/****************************** clone process preset ********************************/
failures.clear();
if (!selected_process_presets.empty()) {
bool create_preset_result = preset_bundle->prints.clone_presets_for_printer(selected_process_presets, failures, printer_preset_name, rewritten);
if (!create_preset_result) {
std::string message;
for (const std::string& failure : failures) {
message += "\t" + failure + "\n";
}
MessageDialog dlg(this, _L("Create process presets failed. As follows:\n") + from_u8(message) + _L("\nDo you want to rewrite it?"), wxString(SLIC3R_APP_FULL_NAME) + " - " + _L("Info"), wxYES | wxYES_DEFAULT | wxCENTRE);
int res = dlg.ShowModal();
if (wxID_YES == res) {
create_preset_result = preset_bundle->prints.clone_presets_for_printer(selected_process_presets, failures, printer_preset_name, true);
} else {
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " printer preset no same preset but filament has same preset, user cancel create the printer preset";
return;
}
}
// save created successfully preset name
for (Preset const *sucessful_preset : selected_filament_presets)
successful_preset_names.push_back(sucessful_preset->name.substr(0, sucessful_preset->name.find(" @")) + " @" + printer_preset_name);
}
}
/****************************** clone printer preset ********************************/
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ":creater printer ";
try {
auto printer_model = dynamic_cast<ConfigOptionString *>(m_printer_preset->config.option("printer_model", true));
if (printer_model)
printer_model->value = printer_model_name;
auto printer_variant = dynamic_cast<ConfigOptionString *>(m_printer_preset->config.option("printer_variant", true));
if (printer_variant)
printer_variant->value = printer_nozzle_name;
auto nozzle_diameter = dynamic_cast<ConfigOptionFloats *>(m_printer_preset->config.option("nozzle_diameter", true));
if (nozzle_diameter) {
std::unordered_map<std::string, float>::const_iterator iter = nozzle_diameter_map.find(printer_nozzle_name);
if (nozzle_diameter_map.end() != iter) {
nozzle_diameter->values = {iter->second};
}
}
}
catch (...) {
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " bisic info is not rewritten, may be printer_model, printer_variant, or nozzle_diameter";
}
preset_bundle->printers.save_current_preset(printer_preset_name, true, false, m_printer_preset);
preset_bundle->update_compatible(PresetSelectCompatibleType::Always);
EndModal(wxID_OK);
});
m_button_page2_cancel = new Button(parent, _L("Cancel"));
m_button_page2_cancel->SetBackgroundColor(btn_bg_white);
m_button_page2_cancel->SetBorderColor(wxColour(38, 46, 48));
m_button_page2_cancel->SetFont(Label::Body_12);
m_button_page2_cancel->SetSize(wxSize(FromDIP(58), FromDIP(24)));
m_button_page2_cancel->SetMinSize(wxSize(FromDIP(58), FromDIP(24)));
m_button_page2_cancel->SetCornerRadius(FromDIP(12));
bSizer_button->Add(m_button_page2_cancel, 0, wxRIGHT, FromDIP(10));
m_button_page2_cancel->Bind(wxEVT_LEFT_DOWN, [this](wxMouseEvent &e) { EndModal(wxID_CANCEL); });
return bSizer_button;
}
void CreatePrinterPresetDialog::show_page1()
{
m_step_1->SetBitmap(create_scaled_bitmap("step_1", nullptr, FromDIP(20)));
m_step_2->SetBitmap(create_scaled_bitmap("step_2_ready", nullptr, FromDIP(20)));
m_page1->Show();
m_page2->Hide();
Refresh();
Layout();
Fit();
}
void CreatePrinterPresetDialog::show_page2()
{
m_step_1->SetBitmap(create_scaled_bitmap("step_is_ok", nullptr, FromDIP(20)));
m_step_2->SetBitmap(create_scaled_bitmap("step_2", nullptr, FromDIP(20)));
m_page2->Show();
m_page1->Hide();
Refresh();
Layout();
Fit();
}
bool CreatePrinterPresetDialog::data_init()
{
std::string nozzle_type = into_u8(m_nozzle_diameter->GetStringSelection());
size_t index_mm = nozzle_type.find(" mm");
if (std::string::npos != index_mm) {
nozzle_type = nozzle_type.substr(0, index_mm);
}
float nozzle = nozzle_diameter_map[nozzle_type];
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " entry and nozzle type is: " << nozzle_type << " and nozzle is: " << nozzle;
VendorMap vendors;
wxArrayString exist_vendor_choice = get_exist_vendor_choices(vendors);
m_printer_vendor->Set(exist_vendor_choice);
m_printer_model->Bind(wxEVT_COMBOBOX, &CreatePrinterPresetDialog::on_preset_model_value_change, this);
m_printer_vendor->Bind(wxEVT_COMBOBOX, [this, vendors, nozzle](wxCommandEvent e) {
m_printer_vendor->SetLabelColor(*wxBLACK);
std::string curr_selected_vendor = into_u8(m_printer_vendor->GetStringSelection());
auto iterator = vendors.find(curr_selected_vendor);
if (iterator != vendors.end()) {
m_printer_preset_vendor_selected = iterator->second;
} else {
MessageDialog dlg(this, _L("Vendor is not find, please reselect."), wxString(SLIC3R_APP_FULL_NAME) + " - " + _L("Info"), wxYES_NO | wxYES_DEFAULT | wxCENTRE);
dlg.ShowModal();
return;
}
wxArrayString printer_preset_model = printer_preset_sort_with_nozzle_diameter(m_printer_preset_vendor_selected, nozzle);
if (printer_preset_model.size() == 0) {
MessageDialog dlg(this, _L("Current vendor has no models, please reselect."), wxString(SLIC3R_APP_FULL_NAME) + " - " + _L("Info"), wxYES | wxYES_DEFAULT | wxCENTRE);
dlg.ShowModal();
return;
}
m_printer_model->Set(printer_preset_model);
if (!printer_preset_model.empty()) {
m_printer_model->SetSelection(0);
wxCommandEvent e;
on_preset_model_value_change(e);
update_preset_list_size();
}
rewritten = false;
e.Skip();
});
return true;
}
void CreatePrinterPresetDialog::set_current_visible_printer()
{
PresetBundle *preset_bundle = wxGetApp().preset_bundle;
const std::deque<Preset> &printer_presets = preset_bundle->printers.get_presets();
wxArrayString printer_choice;
m_printer_name_to_preset.clear();
for (const Preset &printer_preset : printer_presets) {
if (printer_preset.is_system || !printer_preset.is_visible) continue;
if (preset_bundle->printers.get_preset_base(printer_preset)->name != printer_preset.name) continue;
printer_choice.push_back(wxString::FromUTF8(printer_preset.name));
m_printer_name_to_preset[printer_preset.name] = std::make_shared<Preset>(printer_preset);
}
m_select_printer->Set(printer_choice);
}
wxArrayString CreatePrinterPresetDialog::printer_preset_sort_with_nozzle_diameter(const VendorProfile &vendor_profile, float nozzle_diameter)
{
std::vector<pair<float, std::string>> preset_sort;
for (const Slic3r::VendorProfile::PrinterModel &model : vendor_profile.models) {
std::string model_name = model.name;
for (const Slic3r::VendorProfile::PrinterVariant &variant : model.variants) {
try {
float variant_diameter = std::stof(variant.name);
preset_sort.push_back(std::make_pair(variant_diameter, model_name + " @ " + variant.name + " nozzle"));
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << "nozzle: " << variant_diameter << "model: " << preset_sort.back().second;
}
catch (...) {
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " prase varient fialed and the model_name is: " << model_name;
continue;
}
}
}
std::sort(preset_sort.begin(), preset_sort.end(), [](const std::pair<float, std::string> &a, const std::pair<float, std::string> &b) { return a.first < b.first; });
int index_nearest_nozzle = -1;
float nozzle_diameter_diff = 1;
for (int i = 0; i < preset_sort.size(); ++i) {
float curr_nozzle_diameter_diff = std::abs(nozzle_diameter - preset_sort[i].first);
if (curr_nozzle_diameter_diff < nozzle_diameter_diff) {
index_nearest_nozzle = i;
nozzle_diameter_diff = curr_nozzle_diameter_diff;
if (curr_nozzle_diameter_diff == 0) break;
}
}
wxArrayString printer_preset_model_selection;
int right_index = index_nearest_nozzle + 1;
while (index_nearest_nozzle >= 0 || right_index < preset_sort.size()) {
if (index_nearest_nozzle >= 0 && right_index < preset_sort.size()) {
float left_nozzle_diff = std::abs(nozzle_diameter - preset_sort[index_nearest_nozzle].first);
float right_nozzle_diff = std::abs(nozzle_diameter - preset_sort[right_index].first);
bool left_is_little = left_nozzle_diff < right_nozzle_diff;
if (left_is_little) {
printer_preset_model_selection.Add(from_u8(preset_sort[index_nearest_nozzle].second));
index_nearest_nozzle--;
} else {
printer_preset_model_selection.Add(from_u8(preset_sort[right_index].second));
right_index++;
}
} else if (index_nearest_nozzle >= 0) {
printer_preset_model_selection.Add(from_u8(preset_sort[index_nearest_nozzle].second));
index_nearest_nozzle--;
} else if (right_index < preset_sort.size()) {
printer_preset_model_selection.Add(from_u8(preset_sort[right_index].second));
right_index++;
}
}
return printer_preset_model_selection;
}
void CreatePrinterPresetDialog::select_all_preset_template(std::vector<std::pair<::CheckBox *, Preset *>> &preset_templates)
{
for (std::pair<::CheckBox *, Preset const *> filament_preset : preset_templates) {
filament_preset.first->SetValue(true);
}
}
void CreatePrinterPresetDialog::deselect_all_preset_template(std::vector<std::pair<::CheckBox *, Preset *>> &preset_templates)
{
for (std::pair<::CheckBox *, Preset const *> filament_preset : preset_templates) {
filament_preset.first->SetValue(false);
}
}
void CreatePrinterPresetDialog::update_presets_list(bool just_template)
{
PresetBundle temp_preset_bundle;
if (!load_system_and_user_presets_with_curr_model(temp_preset_bundle, just_template)) return;
const std::deque<Preset> &filament_presets = temp_preset_bundle.filaments.get_presets();
const std::deque<Preset> &process_presets = temp_preset_bundle.prints.get_presets();
// clear filament preset window sizer
m_preset_template_panel->Freeze();
clear_preset_combobox();
// update filament preset window sizer
for (const Preset &filament_preset : filament_presets) {
if (filament_preset.is_compatible) {
if (filament_preset.is_default) continue;
Preset *temp_filament = new Preset(filament_preset);
wxString filament_name = wxString::FromUTF8(temp_filament->name);
m_filament_preset_template_sizer->Add(create_checkbox(m_filament_preset_panel, temp_filament, filament_name, m_filament_preset), 0,
wxEXPAND, FromDIP(5));
}
}
for (const Preset &process_preset : process_presets) {
if (process_preset.is_compatible) {
if (process_preset.is_default) continue;
Preset *temp_process = new Preset(process_preset);
wxString process_name = wxString::FromUTF8(temp_process->name);
m_process_preset_template_sizer->Add(create_checkbox(m_process_preset_panel, temp_process, process_name, m_process_preset), 0, wxEXPAND,
FromDIP(5));
}
}
m_preset_template_panel->Thaw();
}
void CreatePrinterPresetDialog::clear_preset_combobox()
{
for (std::pair<::CheckBox *, Preset *> preset : m_filament_preset) {
if (preset.second) {
delete preset.second;
preset.second = nullptr;
}
}
m_filament_preset.clear();
m_filament_preset_template_sizer->Clear(true);
for (std::pair<::CheckBox *, Preset *> preset : m_process_preset) {
if (preset.second) {
delete preset.second;
preset.second = nullptr;
}
}
m_process_preset.clear();
m_process_preset_template_sizer->Clear(true);
}
bool CreatePrinterPresetDialog::save_printable_area_config(Preset *preset)
{
const wxString curr_selected_printer_type = curr_create_printer_type();
DynamicPrintConfig &config = preset->config;
if (curr_selected_printer_type == m_create_type.create_printer) {
double x = 0;
m_bed_size_x_input->GetTextCtrl()->GetValue().ToDouble(&x);
double y = 0;
m_bed_size_y_input->GetTextCtrl()->GetValue().ToDouble(&y);
double dx = 0;
m_bed_origin_x_input->GetTextCtrl()->GetValue().ToDouble(&dx);
double dy = 0;
m_bed_origin_y_input->GetTextCtrl()->GetValue().ToDouble(&dy);
// range check begin
if (x == 0 || y == 0) { return false; }
double x0 = 0.0;
double y0 = 0.0;
double x1 = x;
double y1 = y;
if (dx >= x || dy >= y) { return false; }
x0 -= dx;
x1 -= dx;
y0 -= dy;
y1 -= dy;
// range check end
std::vector<Vec2d> points = {Vec2d(x0, y0), Vec2d(x1, y0), Vec2d(x1, y1), Vec2d(x0, y1)};
config.set_key_value("printable_area", new ConfigOptionPoints(points));
double max_print_height = 0;
m_print_height_input->GetTextCtrl()->GetValue().ToDouble(&max_print_height);
config.set("printable_height", max_print_height);
Utils::slash_to_back_slash(m_custom_texture);
Utils::slash_to_back_slash(m_custom_model);
config.set("bed_custom_model", m_custom_model);
config.set("bed_custom_texture", m_custom_texture);
} else if(m_create_type.create_nozzle){
std::string selected_printer_preset_name = into_u8(m_select_printer->GetStringSelection());
std::unordered_map<std::string, std::shared_ptr<Preset>>::iterator itor = m_printer_name_to_preset.find(selected_printer_preset_name);
assert(m_printer_name_to_preset.end() != itor);
if (m_printer_name_to_preset.end() != itor) {
std::shared_ptr<Preset> printer_preset = itor->second;
std::vector<std::string> keys = {"printable_area", "printable_height", "bed_custom_model", "bed_custom_texture"};
config.apply_only(printer_preset->config, keys, true);
}
}
return true;
}
bool CreatePrinterPresetDialog::check_printable_area() {
double x = 0;
m_bed_size_x_input->GetTextCtrl()->GetValue().ToDouble(&x);
double y = 0;
m_bed_size_y_input->GetTextCtrl()->GetValue().ToDouble(&y);
double dx = 0;
m_bed_origin_x_input->GetTextCtrl()->GetValue().ToDouble(&dx);
double dy = 0;
m_bed_origin_y_input->GetTextCtrl()->GetValue().ToDouble(&dy);
// range check begin
if (x == 0 || y == 0) {
return false;
}
double x0 = 0.0;
double y0 = 0.0;
double x1 = x;
double y1 = y;
if (dx >= x || dy >= y) {
return false;
}
return true;
}
bool CreatePrinterPresetDialog::validate_input_valid()
{
const wxString curr_selected_printer_type = curr_create_printer_type();
if (curr_selected_printer_type == m_create_type.create_printer) {
std::string vendor_name, model_name;
if (m_can_not_find_vendor_combox->GetValue()) {
vendor_name = into_u8(m_custom_vendor_text_ctrl->GetValue());
model_name = into_u8(m_custom_model_text_ctrl->GetValue());
} else {
vendor_name = into_u8(m_select_vendor->GetStringSelection());
model_name = into_u8(m_select_model->GetStringSelection());
}
if ((vendor_name.empty() || model_name.empty())) {
MessageDialog dlg(this, _L("You have not selected the vendor and model or inputed the custom vendor and model."), wxString(SLIC3R_APP_FULL_NAME) + " - " + _L("Info"),
wxYES | wxYES_DEFAULT | wxCENTRE);
dlg.ShowModal();
return false;
}
vendor_name = remove_special_key(vendor_name);
model_name = remove_special_key(model_name);
if (vendor_name.empty() || model_name.empty()) {
MessageDialog dlg(this, _L("There may be escape characters in the custom printer vendor or model. Please delete and re-enter."),
wxString(SLIC3R_APP_FULL_NAME) + " - " + _L("Info"), wxYES | wxYES_DEFAULT | wxCENTRE);
dlg.ShowModal();
return false;
}
boost::algorithm::trim(vendor_name);
boost::algorithm::trim(model_name);
if (vendor_name.empty() || model_name.empty()) {
MessageDialog dlg(this, _L("All inputs in the custom printer vendor or model are spaces. Please re-enter."), wxString(SLIC3R_APP_FULL_NAME) + " - " + _L("Info"),
wxYES | wxYES_DEFAULT | wxCENTRE);
dlg.ShowModal();
return false;
}
if (check_printable_area() == false) {
MessageDialog dlg(this, _L("Please check bed printable shape and origin input."), wxString(SLIC3R_APP_FULL_NAME) + " - " + _L("Info"), wxYES | wxYES_DEFAULT | wxCENTRE);
dlg.ShowModal();
return false;
}
} else if (curr_selected_printer_type == m_create_type.create_nozzle) {
wxString printer_name = m_select_printer->GetStringSelection();
if (printer_name.empty()) {
MessageDialog dlg(this, _L("You have not yet selected the printer to replace the nozzle, please choose."), wxString(SLIC3R_APP_FULL_NAME) + " - " + _L("Info"),
wxYES | wxYES_DEFAULT | wxCENTRE);
dlg.ShowModal();
return false;
}
}
return true;
}
void CreatePrinterPresetDialog::on_preset_model_value_change(wxCommandEvent &e)
{
m_printer_model->SetLabelColor(*wxBLACK);
if (m_printer_preset_vendor_selected.models.empty()) {
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " selected vendor has no models, and the vendor is: " << m_printer_preset_vendor_selected.id;
return;
}
wxString curr_selected_preset_type = curr_create_preset_type();
if (curr_selected_preset_type == m_create_type.base_curr_printer) {
update_presets_list();
} else if (curr_selected_preset_type == m_create_type.base_template) {
update_presets_list(true);
}
rewritten = false;
update_preset_list_size();
e.Skip();
}
wxString CreatePrinterPresetDialog::curr_create_preset_type()
{
wxString curr_selected_preset_type;
for (const std::pair<RadioBox *, wxString> &presets_radio : m_create_presets_btns) {
if (presets_radio.first->GetValue()) {
curr_selected_preset_type = presets_radio.second;
}
}
return curr_selected_preset_type;
}
wxString CreatePrinterPresetDialog::curr_create_printer_type()
{
wxString curr_selected_printer_type;
for (const std::pair<RadioBox *, wxString> &printer_radio : m_create_type_btns) {
if (printer_radio.first->GetValue()) { curr_selected_printer_type = printer_radio.second; }
}
return curr_selected_printer_type;
}
CreatePresetSuccessfulDialog::CreatePresetSuccessfulDialog(wxWindow *parent, const SuccessType &create_success_type)
: DPIDialog(parent ? parent : nullptr, wxID_ANY, PRINTER == create_success_type ? _L("Create Printer Successful") : _L("Create Filament Successful"), wxDefaultPosition, wxDefaultSize, wxCAPTION | wxCLOSE_BOX)
{
this->SetBackgroundColour(*wxWHITE);
this->SetSize(wxSize(FromDIP(450), FromDIP(200)));
std::string icon_path = (boost::format("%1%/images/OrcaSlicerTitle.ico") % resources_dir()).str();
SetIcon(wxIcon(encode_path(icon_path.c_str()), wxBITMAP_TYPE_ICO));
wxBoxSizer *m_main_sizer = new wxBoxSizer(wxVERTICAL);
// top line
auto m_line_top = new wxPanel(this, wxID_ANY, wxDefaultPosition, wxSize(-1, 1), wxTAB_TRAVERSAL);
m_line_top->SetBackgroundColour(wxColour(0xA6, 0xa9, 0xAA));
m_main_sizer->Add(m_line_top, 0, wxEXPAND, 0);
m_main_sizer->Add(0, 0, 0, wxTOP, FromDIP(5));
wxBoxSizer *horizontal_sizer = new wxBoxSizer(wxHORIZONTAL);
horizontal_sizer->Add(0, 0, 0, wxLEFT, FromDIP(30));
wxBoxSizer *success_bitmap_sizer = new wxBoxSizer(wxVERTICAL);
wxStaticBitmap *success_bitmap = new wxStaticBitmap(this,wxID_ANY, create_scaled_bitmap("create_success", nullptr, FromDIP(24)));
success_bitmap_sizer->Add(success_bitmap, 0, wxEXPAND, 0);
horizontal_sizer->Add(success_bitmap_sizer, 0, wxEXPAND | wxALL, FromDIP(5));
wxBoxSizer *success_text_sizer = new wxBoxSizer(wxVERTICAL);
wxStaticText *success_text;
wxStaticText *next_step_text;
switch (create_success_type) {
case PRINTER:
success_text = new wxStaticText(this, wxID_ANY, _L("Printer Created"));
next_step_text = new wxStaticText(this, wxID_ANY, _L("Please go to printer settings to edit your presets"));
break;
case FILAMENT:
success_text = new wxStaticText(this, wxID_ANY, _L("Filament Created"));
next_step_text = new wxStaticText(this, wxID_ANY, _L("Please go to filament setting to edit your presets if you need.\nPlease note that nozzle temperature, hot bed temperature, and maximum volumetric speed have a significant impact on printing quality. Please set them carefully."));
break;
}
success_text->SetFont(Label::Head_18);
//next_step_text->SetFont(Label::Body_14);
success_text_sizer->Add(success_text, 0, wxEXPAND, 0);
success_text_sizer->Add(next_step_text, 0, wxEXPAND | wxTOP, FromDIP(5));
horizontal_sizer->Add(success_text_sizer, 0, wxEXPAND | wxALL, FromDIP(5));
horizontal_sizer->Add(0, 0, 0, wxLEFT, FromDIP(60));
m_main_sizer->Add(horizontal_sizer, 0, wxALL, FromDIP(5));
wxBoxSizer *btn_sizer = new wxBoxSizer(wxHORIZONTAL);
btn_sizer->Add(0, 0, 1, wxEXPAND, 0);
switch (create_success_type) {
case PRINTER:
m_button_ok = new Button(this, _L("Printer Setting"));
break;
case FILAMENT:
m_button_ok = new Button(this, _L("OK"));
break;
}
StateColor btn_bg_green(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));
StateColor btn_bg_white(std::pair<wxColour, int>(wxColour(206, 206, 206), StateColor::Pressed), std::pair<wxColour, int>(wxColour(238, 238, 238), StateColor::Hovered),
std::pair<wxColour, int>(*wxWHITE, StateColor::Normal));
m_button_ok->SetBackgroundColor(btn_bg_green);
m_button_ok->SetBorderColor(wxColour(*wxWHITE));
m_button_ok->SetTextColor(wxColour(*wxWHITE));
m_button_ok->SetFont(Label::Body_12);
m_button_ok->SetSize(wxSize(FromDIP(58), FromDIP(24)));
m_button_ok->SetMinSize(wxSize(FromDIP(58), FromDIP(24)));
m_button_ok->SetCornerRadius(FromDIP(12));
btn_sizer->Add(m_button_ok, 0, wxRIGHT, FromDIP(10));
m_button_ok->Bind(wxEVT_LEFT_DOWN, [this](wxMouseEvent &e) { EndModal(wxID_OK); });
if (PRINTER == create_success_type) {
m_button_cancel = new Button(this, _L("Cancel"));
m_button_cancel->SetBackgroundColor(btn_bg_white);
m_button_cancel->SetBorderColor(wxColour(38, 46, 48));
m_button_cancel->SetTextColor(wxColour(38, 46, 48));
m_button_cancel->SetFont(Label::Body_12);
m_button_cancel->SetSize(wxSize(FromDIP(58), FromDIP(24)));
m_button_cancel->SetMinSize(wxSize(FromDIP(58), FromDIP(24)));
m_button_cancel->SetCornerRadius(FromDIP(12));
btn_sizer->Add(m_button_cancel, 0, wxRIGHT, FromDIP(10));
m_button_cancel->Bind(wxEVT_LEFT_DOWN, [this](wxMouseEvent &e) { EndModal(wxID_CANCEL); });
}
m_main_sizer->Add(btn_sizer, 0, wxEXPAND | wxALL, FromDIP(15));
m_main_sizer->Add(0, 0, 0, wxTOP, FromDIP(10));
SetSizer(m_main_sizer);
Layout();
Fit();
wxGetApp().UpdateDlgDarkUI(this);
}
CreatePresetSuccessfulDialog::~CreatePresetSuccessfulDialog() {}
void CreatePresetSuccessfulDialog::on_dpi_changed(const wxRect &suggested_rect) {
m_button_ok->SetMinSize(wxSize(FromDIP(58), FromDIP(24)));
m_button_ok->SetMaxSize(wxSize(FromDIP(58), FromDIP(24)));
m_button_ok->SetCornerRadius(FromDIP(12));
m_button_cancel->SetMinSize(wxSize(FromDIP(58), FromDIP(24)));
m_button_cancel->SetMaxSize(wxSize(FromDIP(58), FromDIP(24)));
m_button_cancel->SetCornerRadius(FromDIP(12));
Layout();
}
ExportConfigsDialog::ExportConfigsDialog(wxWindow *parent)
: DPIDialog(parent ? parent : nullptr, wxID_ANY, _L("Export Configs"), wxDefaultPosition, wxDefaultSize, wxCAPTION | wxCLOSE_BOX)
{
m_exprot_type.preset_bundle = _L("Printer config bundle(.bbscfg)");
m_exprot_type.filament_bundle = _L("Filament bundle(.bbsflmt)");
m_exprot_type.printer_preset = _L("Printer presets(.zip)");
m_exprot_type.filament_preset = _L("Filament presets(.zip)");
m_exprot_type.process_preset = _L("Process presets(.zip)");
this->SetBackgroundColour(*wxWHITE);
this->SetSize(wxSize(FromDIP(600), FromDIP(600)));
std::string icon_path = (boost::format("%1%/images/OrcaSlicerTitle.ico") % resources_dir()).str();
SetIcon(wxIcon(encode_path(icon_path.c_str()), wxBITMAP_TYPE_ICO));
m_main_sizer = new wxBoxSizer(wxVERTICAL);
// top line
auto m_line_top = new wxPanel(this, wxID_ANY, wxDefaultPosition, wxSize(-1, 1), wxTAB_TRAVERSAL);
m_line_top->SetBackgroundColour(wxColour(0xA6, 0xa9, 0xAA));
m_main_sizer->Add(m_line_top, 0, wxEXPAND, 0);
m_main_sizer->Add(0, 0, 0, wxTOP, FromDIP(5));
m_main_sizer->Add(create_export_config_item(this), 0, wxEXPAND | wxALL, FromDIP(5));
m_main_sizer->Add(create_select_printer(this), 0, wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM, FromDIP(5));
m_main_sizer->Add(create_button_item(this), 0, wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM, FromDIP(5));
data_init();
this->SetSizer(m_main_sizer);
this->Layout();
this->Fit();
wxGetApp().UpdateDlgDarkUI(this);
}
ExportConfigsDialog::~ExportConfigsDialog()
{
for (std::pair<std::string, Preset *> printer_preset : m_printer_presets) {
Preset *preset = printer_preset.second;
if (preset) {
delete preset;
preset = nullptr;
}
}
for (std::pair<std::string, std::vector<Preset *>> filament_presets : m_filament_presets) {
for (Preset* preset : filament_presets.second) {
if (preset) {
delete preset;
preset = nullptr;
}
}
}
for (std::pair<std::string, std::vector<Preset *>> filament_presets : m_process_presets) {
for (Preset *preset : filament_presets.second) {
if (preset) {
delete preset;
preset = nullptr;
}
}
}
for (std::pair<std::string, std::vector<std::pair<std::string, Preset *>>> filament_preset : m_filament_name_to_presets) {
for (std::pair<std::string, Preset*> printer_name_preset : filament_preset.second) {
Preset *preset = printer_name_preset.second;
if (preset) {
delete preset;
preset = nullptr;
}
}
}
}
void ExportConfigsDialog::on_dpi_changed(const wxRect &suggested_rect) {
m_button_ok->SetMinSize(wxSize(FromDIP(58), FromDIP(24)));
m_button_ok->SetMaxSize(wxSize(FromDIP(58), FromDIP(24)));
m_button_ok->SetCornerRadius(FromDIP(12));
m_button_cancel->SetMinSize(wxSize(FromDIP(58), FromDIP(24)));
m_button_cancel->SetMaxSize(wxSize(FromDIP(58), FromDIP(24)));
m_button_cancel->SetCornerRadius(FromDIP(12));
Layout();
}
void ExportConfigsDialog::show_export_result(const ExportCase &export_case)
{
MessageDialog *msg_dlg = nullptr;
switch (export_case) {
case ExportCase::INITIALIZE_FAIL:
msg_dlg = new MessageDialog(this, _L("initialize fail"), wxString(SLIC3R_APP_FULL_NAME) + " - " + _L("Info"), wxYES | wxYES_DEFAULT | wxCENTRE);
break;
case ExportCase::ADD_FILE_FAIL:
msg_dlg = new MessageDialog(this, _L("add file fail"), wxString(SLIC3R_APP_FULL_NAME) + " - " + _L("Info"), wxYES | wxYES_DEFAULT | wxCENTRE);
break;
case ExportCase::ADD_BUNDLE_STRUCTURE_FAIL:
msg_dlg = new MessageDialog(this, _L("add bundle structure file fail"), wxString(SLIC3R_APP_FULL_NAME) + " - " + _L("Info"), wxYES | wxYES_DEFAULT | wxCENTRE);
break;
case ExportCase::FINALIZE_FAIL:
msg_dlg = new MessageDialog(this, _L("finalize fail"), wxString(SLIC3R_APP_FULL_NAME) + " - " + _L("Info"), wxYES | wxYES_DEFAULT | wxCENTRE);
break;
case ExportCase::OPEN_ZIP_WRITTEN_FILE:
msg_dlg = new MessageDialog(this, _L("open zip written fail"), wxString(SLIC3R_APP_FULL_NAME) + " - " + _L("Info"), wxYES | wxYES_DEFAULT | wxCENTRE);
break;
case ExportCase::EXPORT_SUCCESS:
msg_dlg = new MessageDialog(this, _L("Export successful"), wxString(SLIC3R_APP_FULL_NAME) + " - " + _L("Info"), wxYES | wxYES_DEFAULT | wxCENTRE);
break;
}
if (msg_dlg) {
msg_dlg->ShowModal();
delete msg_dlg;
msg_dlg = nullptr;
}
}
bool ExportConfigsDialog::has_check_box_selected()
{
for (std::pair<::CheckBox *, Preset *> checkbox_preset : m_preset) {
if (checkbox_preset.first->GetValue()) return true;
}
for (std::pair<::CheckBox *, std::string> checkbox_filament_name : m_printer_name) {
if (checkbox_filament_name.first->GetValue()) return true;
}
return false;
}
bool ExportConfigsDialog::preset_is_not_compatible_bbl_printer(Preset *preset)
{
if (preset->type != Preset::Type::TYPE_PRINT && preset->type != Preset::Type::TYPE_FILAMENT) return true;
PresetBundle * preset_bundle = wxGetApp().preset_bundle;
vector<std::string> printers;
get_filament_compatible_printer(preset, printers);
if (printers.empty()) return true;
Preset *printer_preset = preset_bundle->printers.find_preset(printers[0], false);
if (!printer_preset) return true;
if (!preset_bundle->is_bbl_vendor()) return true;
return false;
}
std::string ExportConfigsDialog::initial_file_path(const wxString &path, const std::string &sub_file_path)
{
std::string export_path = into_u8(path);
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << "initial file path and path is:" << export_path << " and sub path is: " << sub_file_path;
boost::filesystem::path printer_export_path = (boost::filesystem::path(export_path) / sub_file_path).make_preferred();
if (boost::filesystem::exists(printer_export_path)) {
MessageDialog dlg(this, wxString::Format(_L("The '%s' folder already exists in the current directory. Do you want to clear it and rebuild it.\nIf not, a time suffix will be "
"added, and you can modify the name after creation."), sub_file_path), wxString(SLIC3R_APP_FULL_NAME) + " - " + _L("Info"), wxYES_NO | wxYES_DEFAULT | wxCENTRE);
int res = dlg.ShowModal();
if (wxID_YES == res) {
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << "Same path exists, delete and need to rebuild, and path is: " << printer_export_path.string();
try {
boost::filesystem::remove_all(printer_export_path);
} catch (...) {
MessageDialog dlg(this, _L(wxString::Format("The file: %s \nin the directory may have been opened by another program. \nPlease close it and try again.",
encode_path(printer_export_path.string().c_str()))),
wxString(SLIC3R_APP_FULL_NAME) + " - " + _L("Info"),
wxYES | wxYES_DEFAULT | wxCENTRE);
dlg.ShowModal();
return "initial_failed";
}
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << "delete path";
boost::filesystem::create_directories(printer_export_path);
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << "create path";
export_path = printer_export_path.string();
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << "Same path exists, delete and rebuild, and path is: " << export_path;
} else if (wxID_NO == res) {
export_path = printer_export_path.string();
std::string export_path_with_time;
boost::filesystem::path *printer_export_path_with_time = nullptr;
do {
if (printer_export_path_with_time) {
delete printer_export_path_with_time;
printer_export_path_with_time = nullptr;
}
export_path_with_time = export_path + " " + get_curr_time();
printer_export_path_with_time = new boost::filesystem::path(export_path_with_time);
} while (boost::filesystem::exists(*printer_export_path_with_time));
export_path = export_path_with_time;
boost::filesystem::create_directories(*printer_export_path_with_time);
if (printer_export_path_with_time) {
delete printer_export_path_with_time;
printer_export_path_with_time = nullptr;
}
} else {
return "";
}
} else {
boost::filesystem::create_directories(printer_export_path);
export_path = printer_export_path.string();
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << "Same path exists, delete and rebuild, and path is: " << export_path;
}
return export_path;
}
std::string ExportConfigsDialog::initial_file_name(const wxString &path, const std::string file_name)
{
std::string export_path = into_u8(path);
boost::filesystem::path printer_export_path = (boost::filesystem::path(export_path) / file_name).make_preferred();
if (boost::filesystem::exists(printer_export_path)) {
MessageDialog dlg(this, wxString::Format(_L("The '%s' folder already exists in the current directory. Do you want to clear it and rebuild it.\nIf not, a time suffix will be "
"added, and you can modify the name after creation."), file_name), wxString(SLIC3R_APP_FULL_NAME) + " - " + _L("Info"), wxYES_NO | wxYES_DEFAULT | wxCENTRE);
int res = dlg.ShowModal();
if (wxID_YES == res) {
try {
boost::filesystem::remove_all(printer_export_path);
}
catch(...) {
MessageDialog dlg(this,
_L(wxString::Format("The file: %s \nmay have been opened by another program. \nPlease close it and try again.",
encode_path(printer_export_path.string().c_str()))),
wxString(SLIC3R_APP_FULL_NAME) + " - " + _L("Info"), wxYES | wxYES_DEFAULT | wxCENTRE);
dlg.ShowModal();
return "initial_failed";
}
export_path = printer_export_path.string();
} else if (wxID_NO == res) {
export_path = printer_export_path.string();
export_path = export_path.substr(0, export_path.find(".zip"));
std::string export_path_with_time;
boost::filesystem::path *printer_export_path_with_time = nullptr;
do {
if (printer_export_path_with_time) {
delete printer_export_path_with_time;
printer_export_path_with_time = nullptr;
}
export_path_with_time = export_path + " " + get_curr_time() + ".zip";
printer_export_path_with_time = new boost::filesystem::path(export_path_with_time);
} while (boost::filesystem::exists(*printer_export_path_with_time));
export_path = export_path_with_time;
if (printer_export_path_with_time) {
delete printer_export_path_with_time;
printer_export_path_with_time = nullptr;
}
} else {
return "";
}
} else {
export_path = printer_export_path.string();
}
return export_path;
}
wxBoxSizer *ExportConfigsDialog::create_export_config_item(wxWindow *parent)
{
wxBoxSizer *horizontal_sizer = new wxBoxSizer(wxHORIZONTAL);
wxBoxSizer * optionSizer = new wxBoxSizer(wxVERTICAL);
wxStaticText *static_serial_text = new wxStaticText(parent, wxID_ANY, _L("Presets"), wxDefaultPosition, wxDefaultSize);
optionSizer->Add(static_serial_text, 0, wxEXPAND | wxALL, 0);
optionSizer->SetMinSize(OPTION_SIZE);
horizontal_sizer->Add(optionSizer, 0, wxEXPAND | wxALL | wxALIGN_CENTER_VERTICAL, FromDIP(10));
wxBoxSizer *radioBoxSizer = new wxBoxSizer(wxVERTICAL);
radioBoxSizer->Add(create_radio_item(m_exprot_type.preset_bundle, parent, wxEmptyString, m_export_type_btns), 0, wxEXPAND | wxALL, 0);
radioBoxSizer->Add(0, 0, 0, wxTOP, FromDIP(6));
wxStaticText *static_export_printer_preset_bundle_text = new wxStaticText(parent, wxID_ANY, _L("Printer and all the filament&process presets that belongs to the printer. \nCan be shared with others."), wxDefaultPosition, wxDefaultSize);
static_export_printer_preset_bundle_text->SetFont(Label::Body_12);
static_export_printer_preset_bundle_text->SetForegroundColour(wxColour("#6B6B6B"));
radioBoxSizer->Add(static_export_printer_preset_bundle_text, 0, wxEXPAND | wxLEFT, FromDIP(22));
radioBoxSizer->Add(create_radio_item(m_exprot_type.filament_bundle, parent, wxEmptyString, m_export_type_btns), 0, wxEXPAND | wxTOP, FromDIP(10));
wxStaticText *static_export_filament_preset_bundle_text = new wxStaticText(parent, wxID_ANY, _L("User's fillment preset set. \nCan be shared with others."), wxDefaultPosition, wxDefaultSize);
static_export_filament_preset_bundle_text->SetFont(Label::Body_12);
static_export_filament_preset_bundle_text->SetForegroundColour(wxColour("#6B6B6B"));
radioBoxSizer->Add(static_export_filament_preset_bundle_text, 0, wxEXPAND | wxLEFT, FromDIP(22));
radioBoxSizer->Add(create_radio_item(m_exprot_type.printer_preset, parent, wxEmptyString, m_export_type_btns), 0, wxEXPAND | wxTOP, FromDIP(10));
radioBoxSizer->Add(create_radio_item(m_exprot_type.filament_preset, parent, wxEmptyString, m_export_type_btns), 0, wxEXPAND | wxTOP, FromDIP(10));
radioBoxSizer->Add(create_radio_item(m_exprot_type.process_preset, parent, wxEmptyString, m_export_type_btns), 0, wxEXPAND | wxTOP, FromDIP(10));
horizontal_sizer->Add(radioBoxSizer, 0, wxEXPAND | wxALL | wxALIGN_CENTER_VERTICAL, FromDIP(10));
return horizontal_sizer;
}
wxBoxSizer *ExportConfigsDialog::create_radio_item(wxString title, wxWindow *parent, wxString tooltip, std::vector<std::pair<RadioBox *, wxString>> &radiobox_list)
{
wxBoxSizer *horizontal_sizer = new wxBoxSizer(wxHORIZONTAL);
RadioBox * radiobox = new RadioBox(parent);
horizontal_sizer->Add(radiobox, 0, wxEXPAND | wxALL, 0);
horizontal_sizer->Add(0, 0, 0, wxEXPAND | wxLEFT, FromDIP(5));
radiobox_list.push_back(std::make_pair(radiobox, title));
int btn_idx = radiobox_list.size() - 1;
radiobox->Bind(wxEVT_LEFT_DOWN, [this, &radiobox_list, btn_idx](wxMouseEvent &e) {
select_curr_radiobox(radiobox_list, btn_idx);
});
wxStaticText *text = new wxStaticText(parent, wxID_ANY, title, wxDefaultPosition, wxDefaultSize);
text->Bind(wxEVT_LEFT_DOWN, [this, &radiobox_list, btn_idx](wxMouseEvent &e) {
select_curr_radiobox(radiobox_list, btn_idx);
});
horizontal_sizer->Add(text, 0, wxEXPAND | wxLEFT, 0);
radiobox->SetToolTip(tooltip);
text->SetToolTip(tooltip);
return horizontal_sizer;
}
mz_bool ExportConfigsDialog::initial_zip_archive(mz_zip_archive &zip_archive, const std::string &file_path)
{
mz_zip_zero_struct(&zip_archive);
mz_bool status;
// Initialize the ZIP file to write to the structure, using memory storage
std::string export_dir = encode_path(file_path.c_str());
status = mz_zip_writer_init_file(&zip_archive, export_dir.c_str(), 0);
return status;
}
ExportConfigsDialog::ExportCase ExportConfigsDialog::save_zip_archive_to_file(mz_zip_archive &zip_archive)
{
// Complete writing of ZIP file
mz_bool status = mz_zip_writer_finalize_archive(&zip_archive);
if (MZ_FALSE == status) {
BOOST_LOG_TRIVIAL(info) << "Failed to finalize ZIP archive";
mz_zip_writer_end(&zip_archive);
return ExportCase::FINALIZE_FAIL;
}
// Release ZIP file to write structure and related resources
mz_zip_writer_end(&zip_archive);
return ExportCase::CASE_COUNT;
}
ExportConfigsDialog::ExportCase ExportConfigsDialog::save_presets_to_zip(const std::string &export_file, const std::vector<std::pair<std::string, std::string>> &config_paths)
{
mz_zip_archive zip_archive;
mz_bool status = initial_zip_archive(zip_archive, export_file);
if (MZ_FALSE == status) {
BOOST_LOG_TRIVIAL(info) << "Failed to initialize ZIP archive";
return ExportCase::INITIALIZE_FAIL;
}
for (std::pair<std::string, std::string> config_path : config_paths) {
std::string preset_name = config_path.first;
// Add a file to the ZIP file
status = mz_zip_writer_add_file(&zip_archive, (preset_name).c_str(), encode_path(config_path.second.c_str()).c_str(), NULL, 0, MZ_DEFAULT_COMPRESSION);
// status = mz_zip_writer_add_mem(&zip_archive, ("printer/" + printer_preset->name + ".json").c_str(), json_contents, strlen(json_contents), MZ_DEFAULT_COMPRESSION);
if (MZ_FALSE == status) {
BOOST_LOG_TRIVIAL(info) << preset_name << " Filament preset failed to add file to ZIP archive";
mz_zip_writer_end(&zip_archive);
return ExportCase::ADD_FILE_FAIL;
}
BOOST_LOG_TRIVIAL(info) << "Printer preset json add successful: " << preset_name;
}
return save_zip_archive_to_file(zip_archive);
}
void ExportConfigsDialog::select_curr_radiobox(std::vector<std::pair<RadioBox *, wxString>> &radiobox_list, int btn_idx)
{
int len = radiobox_list.size();
for (int i = 0; i < len; ++i) {
if (i == btn_idx) {
radiobox_list[i].first->SetValue(true);
const wxString &export_type = radiobox_list[i].second;
m_preset_sizer->Clear(true);
m_printer_name.clear();
m_preset.clear();
PresetBundle *preset_bundle = wxGetApp().preset_bundle;
this->Freeze();
if (export_type == m_exprot_type.preset_bundle) {
for (std::pair<std::string, Preset *> preset : m_printer_presets) {
std::string preset_name = preset.first;
//printer preset mast have user's filament or process preset or printer preset is user preset
if (m_filament_presets.find(preset_name) == m_filament_presets.end() && m_process_presets.find(preset_name) == m_process_presets.end() && preset.second->is_system) continue;
wxString printer_name = wxString::FromUTF8(preset_name);
m_preset_sizer->Add(create_checkbox(m_presets_window, preset.second, printer_name, m_preset), 0, wxEXPAND | wxTOP | wxLEFT | wxRIGHT, FromDIP(5));
}
m_serial_text->SetLabel(_L("Only display printer names with changes to printer, filament, and process presets."));
}else if (export_type == m_exprot_type.filament_bundle) {
for (std::pair<std::string, std::vector<std::pair<std::string, Preset*>>> filament_name_to_preset : m_filament_name_to_presets) {
if (filament_name_to_preset.second.empty()) continue;
bool all_preset_is_compatible_third_printer = true;
for (std::pair<std::string, Preset *> filament_preset : filament_name_to_preset.second) {
if (!preset_is_not_compatible_bbl_printer(filament_preset.second))
all_preset_is_compatible_third_printer = false;
}
if (all_preset_is_compatible_third_printer) continue;
wxString filament_name = wxString::FromUTF8(filament_name_to_preset.first);
m_preset_sizer->Add(create_checkbox(m_presets_window, filament_name, m_printer_name), 0, wxEXPAND | wxTOP | wxLEFT | wxRIGHT, FromDIP(5));
}
m_serial_text->SetLabel(_L("Only display the filament names with changes to filament presets."));
} else if (export_type == m_exprot_type.printer_preset) {
for (std::pair<std::string, Preset *> preset : m_printer_presets) {
if (preset.second->is_system) continue;
wxString printer_name = wxString::FromUTF8(preset.first);
m_preset_sizer->Add(create_checkbox(m_presets_window, preset.second, printer_name, m_preset), 0, wxEXPAND | wxTOP | wxLEFT | wxRIGHT,
FromDIP(5));
}
m_serial_text->SetLabel(_L("Only printer names with user printer presets will be displayed, and each preset you choose will be exported as a zip."));
} else if (export_type == m_exprot_type.filament_preset) {
for (std::pair<std::string, std::vector<std::pair<std::string, Preset *>>> filament_name_to_preset : m_filament_name_to_presets) {
if (filament_name_to_preset.second.empty()) continue;
bool all_preset_is_compatible_third_printer = true;
for (std::pair<std::string, Preset*> filament_preset : filament_name_to_preset.second) {
if (!preset_is_not_compatible_bbl_printer(filament_preset.second))
all_preset_is_compatible_third_printer = false;
}
if (all_preset_is_compatible_third_printer) continue;
wxString filament_name = wxString::FromUTF8(filament_name_to_preset.first);
m_preset_sizer->Add(create_checkbox(m_presets_window, filament_name, m_printer_name), 0, wxEXPAND | wxTOP | wxLEFT | wxRIGHT, FromDIP(5));
}
m_serial_text->SetLabel(_L("Only the filament names with user filament presets will be displayed, \nand all user filament presets in each filament name you select will be exported as a zip."));
} else if (export_type == m_exprot_type.process_preset) {
for (std::pair<std::string, std::vector<Preset *>> presets : m_process_presets) {
Preset * printer_preset = preset_bundle->printers.find_preset(presets.first, false);
if (!printer_preset) continue;
if (!printer_preset->is_system) continue;
if (preset_bundle->printers.get_preset_base(*printer_preset) != printer_preset) continue;
for (Preset *preset : presets.second) {
if (!preset->is_system) {
wxString printer_name = wxString::FromUTF8(presets.first);
m_preset_sizer->Add(create_checkbox(m_presets_window, printer_name, m_printer_name), 0, wxEXPAND | wxTOP | wxLEFT | wxRIGHT, FromDIP(5));
break;
}
}
}
m_serial_text->SetLabel(_L("Only printer names with changed process presets will be displayed, \nand all user process presets in each printer name you select will be exported as a zip."));
}
//m_presets_window->SetSizerAndFit(m_preset_sizer);
m_presets_window->Layout();
m_presets_window->Fit();
int width = m_presets_window->GetSize().GetWidth();
int height = m_presets_window->GetSize().GetHeight();
m_scrolled_preset_window->SetMinSize(wxSize(std::min(1200, width), std::min(600, height)));
m_scrolled_preset_window->SetMaxSize(wxSize(std::min(1200, width), std::min(600, height)));
m_scrolled_preset_window->SetSize(wxSize(std::min(1200, width), std::min(600, height)));
this->SetSizerAndFit(m_main_sizer);
Layout();
Fit();
Refresh();
adjust_dialog_in_screen(this);
this->Thaw();
} else {
radiobox_list[i].first->SetValue(false);
}
}
}
ExportConfigsDialog::ExportCase ExportConfigsDialog::archive_preset_bundle_to_file(const wxString &path)
{
std::string export_path = initial_file_path(path, "Printer config bundle");
if (export_path.empty() || "initial_failed" == export_path) return ExportCase::EXPORT_CANCEL;
BOOST_LOG_TRIVIAL(info) << "Export printer preset bundle";
for (std::pair<::CheckBox *, Preset *> checkbox_preset : m_preset) {
if (checkbox_preset.first->GetValue()) {
Preset *printer_preset = checkbox_preset.second;
std::string printer_preset_name_ = printer_preset->name;
json bundle_structure;
NetworkAgent *agent = wxGetApp().getAgent();
std::string clock = get_curr_timestmp();
if (agent) {
bundle_structure["user_name"] = agent->get_user_name();
bundle_structure["user_id"] = agent->get_user_id();
bundle_structure["version"] = agent->get_version();
bundle_structure["bundle_id"] = agent->get_user_id() + "_" + printer_preset_name_ + "_" + clock;
} else {
bundle_structure["user_name"] = "";
bundle_structure["user_id"] = "";
bundle_structure["version"] = "";
bundle_structure["bundle_id"] = "offline_" + printer_preset_name_ + "_" + clock;
}
bundle_structure["bundle_type"] = "printer config bundle";
bundle_structure["printer_preset_name"] = printer_preset_name_;
json printer_config = json::array();
json filament_configs = json::array();
json process_configs = json::array();
mz_zip_archive zip_archive;
mz_bool status = initial_zip_archive(zip_archive, export_path + "/" + printer_preset->name + ".bbscfg");
if (MZ_FALSE == status) {
BOOST_LOG_TRIVIAL(info) << "Failed to initialize ZIP archive";
return ExportCase::INITIALIZE_FAIL;
}
boost::filesystem::path pronter_file_path = boost::filesystem::path(printer_preset->file);
std::string preset_path = pronter_file_path.make_preferred().string();
if (preset_path.empty()) {
BOOST_LOG_TRIVIAL(info) << "Export printer preset: " << printer_preset->name << " skip because of the preset file path is empty.";
continue;
}
// Add a file to the ZIP file
std::string printer_config_file_name = "printer/" + pronter_file_path.filename().string();
status = mz_zip_writer_add_file(&zip_archive, printer_config_file_name.c_str(), encode_path(preset_path.c_str()).c_str(), NULL, 0, MZ_DEFAULT_COMPRESSION);
//status = mz_zip_writer_add_mem(&zip_archive, ("printer/" + printer_preset->name + ".json").c_str(), json_contents, strlen(json_contents), MZ_DEFAULT_COMPRESSION);
if (MZ_FALSE == status) {
BOOST_LOG_TRIVIAL(info) << printer_preset->name << " Failed to add file to ZIP archive";
mz_zip_writer_end(&zip_archive);
return ExportCase::ADD_FILE_FAIL;
}
printer_config.push_back(printer_config_file_name);
BOOST_LOG_TRIVIAL(info) << "Printer preset json add successful: " << printer_preset->name;
const std::string printer_preset_name = printer_preset->name;
std::unordered_map<std::string, std::vector<Preset *>>::iterator iter = m_filament_presets.find(printer_preset_name);
if (m_filament_presets.end() != iter) {
for (Preset *preset : iter->second) {
boost::filesystem::path filament_file_path = boost::filesystem::path(preset->file);
std::string filament_preset_path = filament_file_path.make_preferred().string();
if (filament_preset_path.empty()) {
BOOST_LOG_TRIVIAL(info) << "Export filament preset: " << preset->name << " skip because of the preset file path is empty.";
continue;
}
std::string filament_config_file_name = "filament/" + filament_file_path.filename().string();
status = mz_zip_writer_add_file(&zip_archive, filament_config_file_name.c_str(), encode_path(filament_preset_path.c_str()).c_str(), NULL, 0, MZ_DEFAULT_COMPRESSION);
if (MZ_FALSE == status) {
BOOST_LOG_TRIVIAL(info) << preset->name << " Failed to add file to ZIP archive";
mz_zip_writer_end(&zip_archive);
return ExportCase::ADD_FILE_FAIL;
}
filament_configs.push_back(filament_config_file_name);
BOOST_LOG_TRIVIAL(info) << "Filament preset json add successful.";
}
}
iter = m_process_presets.find(printer_preset_name);
if (m_process_presets.end() != iter) {
for (Preset *preset : iter->second) {
boost::filesystem::path process_file_path = boost::filesystem::path(preset->file);
std::string process_preset_path = process_file_path.make_preferred().string();
if (process_preset_path.empty()) {
BOOST_LOG_TRIVIAL(info) << "Export process preset: " << preset->name << " skip because of the preset file path is empty.";
continue;
}
std::string process_config_file_name = "process/" + process_file_path.filename().string();
status = mz_zip_writer_add_file(&zip_archive, process_config_file_name.c_str(), encode_path(process_preset_path.c_str()).c_str(), NULL, 0, MZ_DEFAULT_COMPRESSION);
if (MZ_FALSE == status) {
BOOST_LOG_TRIVIAL(info) << preset->name << " Failed to add file to ZIP archive";
mz_zip_writer_end(&zip_archive);
return ExportCase::ADD_FILE_FAIL;
}
process_configs.push_back(process_config_file_name);
BOOST_LOG_TRIVIAL(info) << "Process preset json add successful: ";
}
}
bundle_structure["printer_config"] = printer_config;
bundle_structure["filament_config"] = filament_configs;
bundle_structure["process_config"] = process_configs;
std::string bundle_structure_str = bundle_structure.dump();
status = mz_zip_writer_add_mem(&zip_archive, BUNDLE_STRUCTURE_JSON_NAME, bundle_structure_str.data(), bundle_structure_str.size(), MZ_DEFAULT_COMPRESSION);
if (MZ_FALSE == status) {
BOOST_LOG_TRIVIAL(info) << " Failed to add file: " << BUNDLE_STRUCTURE_JSON_NAME;
mz_zip_writer_end(&zip_archive);
return ExportCase::ADD_BUNDLE_STRUCTURE_FAIL;
}
BOOST_LOG_TRIVIAL(info) << " Success to add file: " << BUNDLE_STRUCTURE_JSON_NAME;
ExportCase save_result = save_zip_archive_to_file(zip_archive);
if (ExportCase::CASE_COUNT != save_result) return save_result;
}
}
BOOST_LOG_TRIVIAL(info) << "ZIP archive created successfully";
return ExportCase::EXPORT_SUCCESS;
}
ExportConfigsDialog::ExportCase ExportConfigsDialog::archive_filament_bundle_to_file(const wxString &path)
{
std::string export_path = initial_file_path(path, "Filament bundle");
if (export_path.empty() || "initial_failed" == export_path) return ExportCase::EXPORT_CANCEL;
BOOST_LOG_TRIVIAL(info) << "Export filament preset bundle";
for (std::pair<::CheckBox *, std::string> checkbox_filament_name : m_printer_name) {
if (checkbox_filament_name.first->GetValue()) {
std::string filament_name = checkbox_filament_name.second;
json bundle_structure;
NetworkAgent *agent = wxGetApp().getAgent();
std::string clock = get_curr_timestmp();
if (agent) {
bundle_structure["user_name"] = agent->get_user_name();
bundle_structure["user_id"] = agent->get_user_id();
bundle_structure["version"] = agent->get_version();
bundle_structure["bundle_id"] = agent->get_user_id() + "_" + filament_name + "_" + clock;
} else {
bundle_structure["user_name"] = "";
bundle_structure["user_id"] = "";
bundle_structure["version"] = "";
bundle_structure["bundle_id"] = "offline_" + filament_name + "_" + clock;
}
bundle_structure["bundle_type"] = "filament config bundle";
bundle_structure["filament_name"] = filament_name;
std::unordered_map<std::string, json> vendor_structure;
mz_zip_archive zip_archive;
mz_bool status = initial_zip_archive(zip_archive, export_path + "/" + filament_name + ".bbsflmt");
if (MZ_FALSE == status) {
BOOST_LOG_TRIVIAL(info) << "Failed to initialize ZIP archive";
return ExportCase::INITIALIZE_FAIL;
}
std::unordered_map<std::string, std::vector<std::pair<std::string, Preset *>>>::iterator iter = m_filament_name_to_presets.find(filament_name);
if (m_filament_name_to_presets.end() == iter) {
BOOST_LOG_TRIVIAL(info) << "Filament name do not find, filament name:" << filament_name;
continue;
}
std::set<std::pair<std::string, std::string>> vendor_to_filament_name;
for (std::pair<std::string, Preset *> printer_name_to_preset : iter->second) {
std::string printer_vendor = printer_name_to_preset.first;
if (printer_vendor.empty()) continue;
Preset * filament_preset = printer_name_to_preset.second;
if (preset_is_not_compatible_bbl_printer(filament_preset)) continue;
if (vendor_to_filament_name.find(std::make_pair(printer_vendor, filament_preset->name)) != vendor_to_filament_name.end()) continue;
vendor_to_filament_name.insert(std::make_pair(printer_vendor, filament_preset->name));
std::string preset_path = boost::filesystem::path(filament_preset->file).make_preferred().string();
if (preset_path.empty()) {
BOOST_LOG_TRIVIAL(info) << "Export printer preset: " << filament_preset->name << " skip because of the preset file path is empty.";
continue;
}
// Add a file to the ZIP file
std::string file_name = printer_vendor + "/" + filament_preset->name + ".json";
status = mz_zip_writer_add_file(&zip_archive, file_name.c_str(), encode_path(preset_path.c_str()).c_str(), NULL, 0, MZ_DEFAULT_COMPRESSION);
// status = mz_zip_writer_add_mem(&zip_archive, ("printer/" + printer_preset->name + ".json").c_str(), json_contents, strlen(json_contents), MZ_DEFAULT_COMPRESSION);
if (MZ_FALSE == status) {
BOOST_LOG_TRIVIAL(info) << filament_preset->name << " Failed to add file to ZIP archive";
mz_zip_writer_end(&zip_archive);
return ExportCase::ADD_FILE_FAIL;
}
std::unordered_map<std::string, json>::iterator iter = vendor_structure.find(printer_vendor);
if (vendor_structure.end() == iter) {
json j = json::array();
j.push_back(file_name);
vendor_structure[printer_vendor] = j;
} else {
iter->second.push_back(file_name);
}
BOOST_LOG_TRIVIAL(info) << "Filament preset json add successful: " << filament_preset->name;
}
for (const std::pair<std::string, json>& vendor_name_to_json : vendor_structure) {
json j;
std::string printer_vendor = vendor_name_to_json.first;
j["vendor"] = printer_vendor;
j["filament_path"] = vendor_name_to_json.second;
bundle_structure["printer_vendor"].push_back(j);
}
std::string bundle_structure_str = bundle_structure.dump();
status = mz_zip_writer_add_mem(&zip_archive, BUNDLE_STRUCTURE_JSON_NAME, bundle_structure_str.data(), bundle_structure_str.size(), MZ_DEFAULT_COMPRESSION);
if (MZ_FALSE == status) {
BOOST_LOG_TRIVIAL(info) << " Failed to add file: " << BUNDLE_STRUCTURE_JSON_NAME;
mz_zip_writer_end(&zip_archive);
return ExportCase::ADD_BUNDLE_STRUCTURE_FAIL;
}
BOOST_LOG_TRIVIAL(info) << " Success to add file: " << BUNDLE_STRUCTURE_JSON_NAME;
// Complete writing of ZIP file
ExportCase save_result = save_zip_archive_to_file(zip_archive);
if (ExportCase::CASE_COUNT != save_result) return save_result;
}
}
BOOST_LOG_TRIVIAL(info) << "ZIP archive created successfully";
return ExportCase::EXPORT_SUCCESS;
}
ExportConfigsDialog::ExportCase ExportConfigsDialog::archive_printer_preset_to_file(const wxString &path)
{
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << "start exprot printer presets";
std::string export_file = "Printer presets.zip";
export_file = initial_file_name(path, export_file);
if (export_file.empty() || "initial_failed" == export_file) return ExportCase::EXPORT_CANCEL;
std::vector<std::pair<std::string, std::string>> config_paths;
for (std::pair<::CheckBox *, Preset *> checkbox_preset : m_preset) {
if (checkbox_preset.first->GetValue()) {
Preset * printer_preset = checkbox_preset.second;
std::string preset_path = boost::filesystem::path(printer_preset->file).make_preferred().string();
if (preset_path.empty()) {
BOOST_LOG_TRIVIAL(info) << "Export printer preset: " << printer_preset->name << " skip because of the preset file path is empty.";
continue;
}
std::string preset_name = printer_preset->name + ".json";
config_paths.push_back(std::make_pair(preset_name, preset_path));
}
}
ExportCase save_result = save_presets_to_zip(export_file, config_paths);
if (ExportCase::CASE_COUNT != save_result) return save_result;
BOOST_LOG_TRIVIAL(info) << "ZIP archive created successfully";
return ExportCase::EXPORT_SUCCESS;
}
ExportConfigsDialog::ExportCase ExportConfigsDialog::archive_filament_preset_to_file(const wxString &path)
{
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << "start exprot filament presets";
std::string export_file = "Filament presets.zip";
export_file = initial_file_name(path, export_file);
if (export_file.empty() || "initial_failed" == export_file) return ExportCase::EXPORT_CANCEL;
std::vector<std::pair<std::string, std::string>> config_paths;
std::set<std::string> filament_presets;
for (std::pair<::CheckBox *, std::string> checkbox_preset : m_printer_name) {
if (checkbox_preset.first->GetValue()) {
std::string filament_name = checkbox_preset.second;
std::unordered_map<std::string, std::vector<std::pair<std::string, Preset *>>>::iterator iter = m_filament_name_to_presets.find(filament_name);
if (m_filament_name_to_presets.end() == iter) {
BOOST_LOG_TRIVIAL(info) << "Filament name do not find, filament name:" << filament_name;
continue;
}
for (std::pair<std::string, Preset*> printer_name_preset : iter->second) {
Preset * filament_preset = printer_name_preset.second;
if (preset_is_not_compatible_bbl_printer(filament_preset)) continue;
if (filament_presets.find(filament_preset->name) != filament_presets.end()) continue;
filament_presets.insert(filament_preset->name);
std::string preset_path = boost::filesystem::path(filament_preset->file).make_preferred().string();
if (preset_path.empty()) {
BOOST_LOG_TRIVIAL(info) << "Export filament preset: " << filament_preset->name << " skip because of the filament file path is empty.";
continue;
}
std::string preset_name = filament_preset->name + ".json";
config_paths.push_back(std::make_pair(preset_name, preset_path));
}
}
}
ExportCase save_result = save_presets_to_zip(export_file, config_paths);
if (ExportCase::CASE_COUNT != save_result) return save_result;
BOOST_LOG_TRIVIAL(info) << "ZIP archive created successfully";
return ExportCase::EXPORT_SUCCESS;
}
ExportConfigsDialog::ExportCase ExportConfigsDialog::archive_process_preset_to_file(const wxString &path)
{
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << "start exprot process presets";
std::string export_file = "Process presets.zip";
export_file = initial_file_name(path, export_file);
if (export_file.empty() || "initial_failed" == export_file) return ExportCase::EXPORT_CANCEL;
std::vector<std::pair<std::string, std::string>> config_paths;
std::set<std::string> process_presets;
for (std::pair<::CheckBox *, std::string> checkbox_preset : m_printer_name) {
if (checkbox_preset.first->GetValue()) {
std::string printer_name = checkbox_preset.second;
std::unordered_map<std::string, std::vector<Preset *>>::iterator iter = m_process_presets.find(printer_name);
if (m_process_presets.end() != iter) {
for (Preset *process_preset : iter->second) {
if (preset_is_not_compatible_bbl_printer(process_preset)) continue;
if (process_presets.find(process_preset->name) != process_presets.end()) continue;
process_presets.insert(process_preset->name);
std::string preset_path = boost::filesystem::path(process_preset->file).make_preferred().string();
if (preset_path.empty()) {
BOOST_LOG_TRIVIAL(info) << "Export process preset: " << process_preset->name << " skip because of the preset file path is empty.";
continue;
}
std::string preset_name = process_preset->name + ".json";
config_paths.push_back(std::make_pair(preset_name, preset_path));
}
}
}
}
ExportCase save_result = save_presets_to_zip(export_file, config_paths);
if (ExportCase::CASE_COUNT != save_result) return save_result;
BOOST_LOG_TRIVIAL(info) << "ZIP archive created successfully";
return ExportCase::EXPORT_SUCCESS;
}
wxBoxSizer *ExportConfigsDialog::create_button_item(wxWindow* parent)
{
wxBoxSizer *bSizer_button = new wxBoxSizer(wxHORIZONTAL);
bSizer_button->Add(0, 0, 1, wxEXPAND, 0);
StateColor btn_bg_green(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_ok = new Button(this, _L("OK"));
m_button_ok->SetBackgroundColor(btn_bg_green);
m_button_ok->SetBorderColor(*wxWHITE);
m_button_ok->SetTextColor(wxColour(0xFFFFFE));
m_button_ok->SetFont(Label::Body_12);
m_button_ok->SetSize(wxSize(FromDIP(58), FromDIP(24)));
m_button_ok->SetMinSize(wxSize(FromDIP(58), FromDIP(24)));
m_button_ok->SetCornerRadius(FromDIP(12));
bSizer_button->Add(m_button_ok, 0, wxRIGHT, FromDIP(10));
m_button_ok->Bind(wxEVT_LEFT_DOWN, [this](wxMouseEvent &e) {
if (!has_check_box_selected()) {
MessageDialog dlg(this, _L("Please select at least one printer or filament."), wxString(SLIC3R_APP_FULL_NAME) + " - " + _L("Info"),
wxYES | wxYES_DEFAULT | wxCENTRE);
dlg.ShowModal();
return;
}
wxDirDialog dlg(this, _L("Choose a directory"), from_u8(wxGetApp().app_config->get_last_dir()), wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST);
wxString path;
if (dlg.ShowModal() == wxID_OK) path = dlg.GetPath();
ExportCase export_case = ExportCase::EXPORT_CANCEL;
if (!path.IsEmpty()) {
wxGetApp().app_config->update_config_dir(into_u8(path));
wxGetApp().app_config->save();
const wxString curr_radio_type = get_curr_radio_type(m_export_type_btns);
if (curr_radio_type == m_exprot_type.preset_bundle) {
export_case = archive_preset_bundle_to_file(path);
} else if (curr_radio_type == m_exprot_type.filament_bundle) {
export_case = archive_filament_bundle_to_file(path);
} else if (curr_radio_type == m_exprot_type.printer_preset) {
export_case = archive_printer_preset_to_file(path);
} else if (curr_radio_type == m_exprot_type.filament_preset) {
export_case = archive_filament_preset_to_file(path);
} else if (curr_radio_type == m_exprot_type.process_preset) {
export_case = archive_process_preset_to_file(path);
}
} else {
return;
}
show_export_result(export_case);
if (ExportCase::EXPORT_SUCCESS != export_case) return;
EndModal(wxID_OK);
});
StateColor btn_bg_white(std::pair<wxColour, int>(wxColour(206, 206, 206), StateColor::Pressed), std::pair<wxColour, int>(wxColour(238, 238, 238), StateColor::Hovered),
std::pair<wxColour, int>(*wxWHITE, StateColor::Normal));
m_button_cancel = new Button(this, _L("Cancel"));
m_button_cancel->SetBackgroundColor(btn_bg_white);
m_button_cancel->SetBorderColor(wxColour(38, 46, 48));
m_button_cancel->SetFont(Label::Body_12);
m_button_cancel->SetSize(wxSize(FromDIP(58), FromDIP(24)));
m_button_cancel->SetMinSize(wxSize(FromDIP(58), FromDIP(24)));
m_button_cancel->SetCornerRadius(FromDIP(12));
bSizer_button->Add(m_button_cancel, 0, wxRIGHT, FromDIP(10));
m_button_cancel->Bind(wxEVT_LEFT_DOWN, [this](wxMouseEvent &e) { EndModal(wxID_CANCEL); });
return bSizer_button;
}
wxBoxSizer *ExportConfigsDialog::create_select_printer(wxWindow *parent)
{
wxBoxSizer *horizontal_sizer = new wxBoxSizer(wxVERTICAL);
wxBoxSizer * optionSizer = new wxBoxSizer(wxVERTICAL);
m_serial_text = new wxStaticText(parent, wxID_ANY, _L("Please select a type you want to export"), wxDefaultPosition, wxDefaultSize);
optionSizer->Add(m_serial_text, 0, wxEXPAND | wxALL, 0);
optionSizer->SetMinSize(OPTION_SIZE);
horizontal_sizer->Add(optionSizer, 0, wxEXPAND | wxALL | wxALIGN_CENTER_VERTICAL, FromDIP(10));
m_scrolled_preset_window = new wxScrolledWindow(parent);
m_scrolled_preset_window->SetScrollRate(5, 5);
m_scrolled_preset_window->SetBackgroundColour(PRINTER_LIST_COLOUR);
m_scrolled_preset_window->SetMaxSize(wxSize(FromDIP(660), FromDIP(400)));
m_scrolled_preset_window->SetSize(wxSize(FromDIP(660), FromDIP(400)));
wxBoxSizer *scrolled_window = new wxBoxSizer(wxHORIZONTAL);
m_presets_window = new wxPanel(m_scrolled_preset_window, wxID_ANY);
m_presets_window->SetBackgroundColour(PRINTER_LIST_COLOUR);
wxBoxSizer *select_printer_sizer = new wxBoxSizer(wxVERTICAL);
m_preset_sizer = new wxGridSizer(3, FromDIP(5), FromDIP(5));
select_printer_sizer->Add(m_preset_sizer, 0, wxEXPAND, FromDIP(5));
m_presets_window->SetSizer(select_printer_sizer);
scrolled_window->Add(m_presets_window, 0, wxEXPAND, 0);
m_scrolled_preset_window->SetSizerAndFit(scrolled_window);
horizontal_sizer->Add(m_scrolled_preset_window, 0, wxEXPAND | wxLEFT | wxRIGHT, FromDIP(10));
return horizontal_sizer;
}
void ExportConfigsDialog::data_init()
{
PresetBundle preset_bundle(*wxGetApp().preset_bundle);
const std::deque<Preset> & printer_presets = preset_bundle.printers.get_presets();
for (const Preset &printer_preset : printer_presets) {
std::string preset_name = printer_preset.name;
if (!printer_preset.is_visible || "Default Printer" == preset_name) continue;
if (preset_bundle.printers.select_preset_by_name(preset_name, false)) {
preset_bundle.update_compatible(PresetSelectCompatibleType::Always);
const std::deque<Preset> &filament_presets = preset_bundle.filaments.get_presets();
for (const Preset &filament_preset : filament_presets) {
if (filament_preset.is_system || filament_preset.is_default) continue;
if (filament_preset.is_compatible) {
Preset *new_filament_preset = new Preset(filament_preset);
m_filament_presets[preset_name].push_back(new_filament_preset);
}
}
const std::deque<Preset> &process_presets = preset_bundle.prints.get_presets();
for (const Preset &process_preset : process_presets) {
if (process_preset.is_system || process_preset.is_default) continue;
if (process_preset.is_compatible) {
Preset *new_prpcess_preset = new Preset(process_preset);
m_process_presets[preset_name].push_back(new_prpcess_preset);
}
}
Preset *new_printer_preset = new Preset(printer_preset);
m_printer_presets[preset_name] = new_printer_preset;
}
}
const std::deque<Preset> &filament_presets = preset_bundle.filaments.get_presets();
for (const Preset &filament_preset : filament_presets) {
if (filament_preset.is_system || filament_preset.is_default) continue;
Preset *new_filament_preset = new Preset(filament_preset);
const Preset *base_filament_preset = preset_bundle.filaments.get_preset_base(*new_filament_preset);
std::string filament_preset_name = base_filament_preset->name;
std::string machine_name = get_machine_name(filament_preset_name);
m_filament_name_to_presets[get_filament_name(filament_preset_name)].push_back(std::make_pair(get_vendor_name(machine_name), new_filament_preset));
}
}
EditFilamentPresetDialog::EditFilamentPresetDialog(wxWindow *parent, FilamentInfomation *filament_info)
: DPIDialog(parent ? parent : nullptr, wxID_ANY, _L("Edit Filament"), wxDefaultPosition, wxDefaultSize, wxCAPTION | wxCLOSE_BOX)
, m_filament_id("")
, m_filament_name("")
, m_vendor_name("")
, m_filament_type("")
, m_filament_serial("")
{
m_preset_tree_creater = new PresetTree(this);
this->SetBackgroundColour(*wxWHITE);
this->SetMinSize(wxSize(FromDIP(600), -1));
std::string icon_path = (boost::format("%1%/images/OrcaSlicerTitle.ico") % resources_dir()).str();
SetIcon(wxIcon(encode_path(icon_path.c_str()), wxBITMAP_TYPE_ICO));
m_main_sizer = new wxBoxSizer(wxVERTICAL);
// top line
auto m_line_top = new wxPanel(this, wxID_ANY, wxDefaultPosition, wxSize(-1, 1), wxTAB_TRAVERSAL);
m_line_top->SetBackgroundColour(wxColour(0xA6, 0xa9, 0xAA));
m_main_sizer->Add(m_line_top, 0, wxEXPAND, 0);
m_main_sizer->Add(0, 0, 0, wxTOP, FromDIP(5));
wxStaticText* basic_infomation = new wxStaticText(this, wxID_ANY, _L("Basic Information"));
basic_infomation->SetFont(Label::Head_16);
m_main_sizer->Add(basic_infomation, 0, wxALL, FromDIP(10));
m_filament_id = filament_info->filament_id;
//std::string filament_name = filament_info->filament_name;
bool get_filament_presets = get_same_filament_id_presets(m_filament_id);
// get filament vendor, type, serial, and name
if (get_filament_presets && !m_printer_compatible_presets.empty()) {
std::shared_ptr<Preset> preset;
for (std::pair<std::string, std::vector<std::shared_ptr<Preset>>> pair : m_printer_compatible_presets) {
for (std::shared_ptr<Preset> fialment_preset : pair.second) {
if (fialment_preset->inherits().empty()) {
preset = fialment_preset;
break;
}
}
}
if (!preset.get()) preset = m_printer_compatible_presets.begin()->second[0];
m_filament_name = get_filament_name(preset->name);
auto vendor_names = dynamic_cast<ConfigOptionStrings *>(preset->config.option("filament_vendor"));
if (vendor_names && !vendor_names->values.empty()) m_vendor_name = vendor_names->values[0];
auto filament_types = dynamic_cast<ConfigOptionStrings *>(preset->config.option("filament_type"));
if (filament_types && !filament_types->values.empty()) m_filament_type = filament_types->values[0];
size_t index = m_filament_name.find(m_filament_type);
if (std::string::npos != index && index + m_filament_type.size() < m_filament_name.size()) {
m_filament_serial = m_filament_name.substr(index + m_filament_type.size());
if (m_filament_serial.size() > 2 && m_filament_serial[0] == ' ') {
m_filament_serial = m_filament_serial.substr(1);
}
}
}
m_main_sizer->Add(create_filament_basic_info(), 0, wxEXPAND | wxALL, 0);
// divider line
auto line_divider = new wxPanel(this, wxID_ANY, wxDefaultPosition, wxSize(-1, 1), wxTAB_TRAVERSAL);
line_divider->SetBackgroundColour(wxColour(0xA6, 0xa9, 0xAA));
m_main_sizer->Add(line_divider, 0, wxEXPAND | wxLEFT | wxRIGHT, FromDIP(10));
m_main_sizer->Add(0, 0, 0, wxTOP, FromDIP(5));
wxStaticText *presets_infomation = new wxStaticText(this, wxID_ANY, _L("Filament presets under this filament"));
presets_infomation->SetFont(Label::Head_16);
m_main_sizer->Add(presets_infomation, 0, wxLEFT | wxRIGHT, FromDIP(10));
m_main_sizer->Add(create_add_filament_btn(), 0, wxEXPAND | wxALL, 0);
m_main_sizer->Add(create_preset_tree_sizer(), 0, wxEXPAND | wxALL, 0);
m_note_text = new wxStaticText(this, wxID_ANY, _L("Note: If the only preset under this filament is deleted, the filament will be deleted after exiting the dialog."));
m_main_sizer->Add(m_note_text, 0, wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM | wxALIGN_CENTER_VERTICAL, FromDIP(10));
m_note_text->Hide();
m_main_sizer->Add(create_button_sizer(), 0, wxEXPAND | wxALL, 0);
update_preset_tree();
this->SetSizer(m_main_sizer);
this->Layout();
this->Fit();
wxGetApp().UpdateDlgDarkUI(this);
}
EditFilamentPresetDialog::~EditFilamentPresetDialog() {}
void EditFilamentPresetDialog::on_dpi_changed(const wxRect &suggested_rect) {
/*m_add_filament_btn->Rescale();
m_del_filament_btn->SetMinSize(wxSize(FromDIP(58), FromDIP(24)));
m_del_filament_btn->SetMaxSize(wxSize(FromDIP(58), FromDIP(24)));
m_del_filament_btn->SetCornerRadius(FromDIP(12));
m_ok_btn->SetMinSize(wxSize(FromDIP(58), FromDIP(24)));
m_ok_btn->SetMaxSize(wxSize(FromDIP(58), FromDIP(24)));
m_ok_btn->SetCornerRadius(FromDIP(12));*/
Layout();
}
bool EditFilamentPresetDialog::get_same_filament_id_presets(std::string filament_id)
{
PresetBundle *preset_bundle = wxGetApp().preset_bundle;
const std::deque<Preset> &filament_presets = preset_bundle->filaments.get_presets();
m_printer_compatible_presets.clear();
for (Preset const &preset : filament_presets) {
if (preset.is_system || preset.filament_id != filament_id) continue;
std::shared_ptr<Preset> new_preset = std::make_shared<Preset>(preset);
std::vector<std::string> printers;
get_filament_compatible_printer(new_preset.get(), printers);
for (const std::string &printer_name : printers) {
m_printer_compatible_presets[printer_name].push_back(new_preset);
}
}
if (m_printer_compatible_presets.empty()) {
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " no filament presets ";
return false;
}
return true;
}
void EditFilamentPresetDialog::update_preset_tree()
{
this->Freeze();
m_preset_tree_sizer->Clear(true);
for (std::pair<std::string, std::vector<std::shared_ptr<Preset>>> printer_and_presets : m_printer_compatible_presets) {
m_preset_tree_sizer->Add(m_preset_tree_creater->get_preset_tree(printer_and_presets), 0, wxEXPAND | wxLEFT | wxTOP | wxRIGHT, 5);
}
if (m_printer_compatible_presets.size() == 1 && m_printer_compatible_presets.begin()->second.size() == 1) {
m_note_text->Show();
} else {
m_note_text->Hide();
}
m_preset_tree_panel->SetSizerAndFit(m_preset_tree_sizer);
int width = m_preset_tree_panel->GetSize().GetWidth();
int height = m_preset_tree_panel->GetSize().GetHeight();
if (width < m_note_text->GetSize().GetWidth()) {
width = m_note_text->GetSize().GetWidth();
m_preset_tree_panel->SetMinSize(wxSize(width, -1));
}
int width_extend = 0;
int height_extend = 0;
if (width > 1000) height_extend = 22;
if (height > 400) width_extend = 22;
m_preset_tree_window->SetMinSize(wxSize(std::min(1000, width + width_extend), std::min(400, height + height_extend)));
m_preset_tree_window->SetMaxSize(wxSize(std::min(1000, width + width_extend), std::min(400, height + height_extend)));
m_preset_tree_window->SetSize(wxSize(std::min(1000, width + width_extend), std::min(400, height + height_extend)));
this->SetSizerAndFit(m_main_sizer);
this->Layout();
this->Fit();
this->Refresh();
wxGetApp().UpdateDlgDarkUI(this);
adjust_dialog_in_screen(this);
this->Thaw();
}
void EditFilamentPresetDialog::delete_preset()
{
if (m_selected_printer.empty()) return;
if (m_need_delete_preset_index < 0) return;
std::unordered_map<std::string, std::vector<std::shared_ptr<Preset>>>::iterator iter = m_printer_compatible_presets.find(m_selected_printer);
if (m_printer_compatible_presets.end() == iter) {
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " can not find printer and printer name is: " << m_selected_printer;
return;
}
std::vector<std::shared_ptr<Preset>>& filament_presets = iter->second;
if (m_need_delete_preset_index >= filament_presets.size()) {
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " index error and selected printer is: " << m_selected_printer << " and index: " << m_need_delete_preset_index;
return;
}
std::shared_ptr<Preset> need_delete_preset = filament_presets[m_need_delete_preset_index];
// is selecetd filament preset
if (need_delete_preset->name == wxGetApp().preset_bundle->filaments.get_selected_preset_name()) {
wxGetApp().get_tab(need_delete_preset->type)->delete_preset();
// is preset exist? exist: not delete
Preset *delete_preset = wxGetApp().preset_bundle->filaments.find_preset(need_delete_preset->name, false);
if (delete_preset) {
m_selected_printer.clear();
m_need_delete_preset_index = -1;
return;
}
} else {
Preset *filament_preset = wxGetApp().preset_bundle->filaments.find_preset(need_delete_preset->name);
// is root preset ?
bool is_base_preset = false;
if (filament_preset && wxGetApp().preset_bundle->filaments.get_preset_base(*filament_preset) == filament_preset) {
is_base_preset = true;
int count = 0;
wxString presets;
for (auto &preset2 : wxGetApp().preset_bundle->filaments)
if (preset2.inherits() == filament_preset->name) {
++count;
presets += "\n - " + from_u8(preset2.name);
}
wxString msg;
if (count > 0) {
msg = _L("Presets inherited by other presets can not be deleted");
msg += "\n";
msg += _L_PLURAL("The following presets inherits this preset.", "The following preset inherits this preset.", count);
wxString title = _L("Delete Preset");
MessageDialog(this, msg + presets, title, wxOK | wxICON_ERROR).ShowModal();
m_selected_printer.clear();
m_need_delete_preset_index = -1;
return;
}
}
wxString msg;
if (is_base_preset) {
msg = _L("Are you sure to delete the selected preset? \nIf the preset corresponds to a filament currently in use on your printer, please reset the filament information for that slot.");
} else {
msg = _L("Are you sure to delete the selected preset?");
}
if (wxID_YES != MessageDialog(this, msg, _L("Delete preset"), wxYES_NO | wxNO_DEFAULT | wxICON_QUESTION).ShowModal()) {
m_selected_printer.clear();
m_need_delete_preset_index = -1;
return;
}
// delete preset
std::string next_selected_preset_name = wxGetApp().preset_bundle->filaments.get_selected_preset().name;
bool delete_result = delete_filament_preset_by_name(need_delete_preset->name, next_selected_preset_name);
BOOST_LOG_TRIVIAL(info) << __LINE__ << " filament preset name: " << need_delete_preset->name << (delete_result ? " delete successful" : " delete failed");
wxGetApp().preset_bundle->filaments.select_preset_by_name(next_selected_preset_name, true);
for (size_t i = 0; i < wxGetApp().preset_bundle->filament_presets.size(); ++i) {
auto preset = wxGetApp().preset_bundle->filaments.find_preset(wxGetApp().preset_bundle->filament_presets[i]);
if (preset == nullptr) wxGetApp().preset_bundle->filament_presets[i] = wxGetApp().preset_bundle->filaments.get_selected_preset_name();
}
}
// remove preset shared_ptr from m_printer_compatible_presets
int last_index = filament_presets.size() - 1;
if (m_need_delete_preset_index != last_index) {
std::swap(filament_presets[m_need_delete_preset_index], filament_presets[last_index]);
}
filament_presets.pop_back();
if (filament_presets.empty()) m_printer_compatible_presets.erase(iter);
update_preset_tree();
m_selected_printer.clear();
m_need_delete_preset_index = -1;
}
void EditFilamentPresetDialog::edit_preset()
{
if (m_selected_printer.empty()) return;
if (m_need_edit_preset_index < 0) return;
std::unordered_map<std::string, std::vector<std::shared_ptr<Preset>>>::iterator iter = m_printer_compatible_presets.find(m_selected_printer);
if (m_printer_compatible_presets.end() == iter) {
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " can not find printer and printer name is: " << m_selected_printer;
return;
}
std::vector<std::shared_ptr<Preset>> &filament_presets = iter->second;
if (m_need_edit_preset_index >= filament_presets.size()) {
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " index error and selected printer is: " << m_selected_printer << " and index: " << m_need_edit_preset_index;
return;
}
// edit preset
std::shared_ptr<Preset> need_edit_preset = filament_presets[m_need_edit_preset_index];
std::string need_edit_preset_name = need_edit_preset->name;
Tab * tab = wxGetApp().get_tab(need_edit_preset->type);
if (tab == nullptr) {
m_selected_printer.clear();
m_need_edit_preset_index = -1;
return;
}
tab->restore_last_select_item();
wxGetApp().get_tab(need_edit_preset->type)->select_preset(need_edit_preset_name);
// when some preset have modified, if the printer is not need_edit_preset_name compatible printer, the preset will jump to other preset, need select again
if (!need_edit_preset->is_compatible) wxGetApp().get_tab(need_edit_preset->type)->select_preset(need_edit_preset_name);
m_selected_printer.clear();
m_need_edit_preset_index = -1;
wxGetApp().params_dialog()->set_editing_filament_id(m_filament_id);
EndModal(wxID_EDIT);
}
wxBoxSizer *EditFilamentPresetDialog::create_filament_basic_info()
{
wxBoxSizer *basic_info_sizer = new wxBoxSizer(wxVERTICAL);
wxBoxSizer *vendor_sizer = new wxBoxSizer(wxHORIZONTAL);
wxBoxSizer *type_sizer = new wxBoxSizer(wxHORIZONTAL);
wxBoxSizer *serial_sizer = new wxBoxSizer(wxHORIZONTAL);
//vendor
wxBoxSizer * vendor_key_sizer = new wxBoxSizer(wxVERTICAL);
wxStaticText *static_vendor_text = new wxStaticText(this, wxID_ANY, _L("Vendor"), wxDefaultPosition, wxDefaultSize);
vendor_key_sizer->Add(static_vendor_text, 0, wxEXPAND | wxALL, 0);
vendor_key_sizer->SetMinSize(OPTION_SIZE);
vendor_sizer->Add(vendor_key_sizer, 0, wxEXPAND | wxLEFT | wxBOTTOM | wxALIGN_CENTER_VERTICAL, FromDIP(10));
wxBoxSizer *vendor_value_sizer = new wxBoxSizer(wxVERTICAL);
wxStaticText *vendor_text = new wxStaticText(this, wxID_ANY, from_u8(m_vendor_name), wxDefaultPosition, wxDefaultSize);
vendor_value_sizer->Add(vendor_text, 0, wxEXPAND | wxALL, 0);
vendor_sizer->Add(vendor_value_sizer, 0, wxEXPAND | wxLEFT | wxBOTTOM | wxALIGN_CENTER_VERTICAL, FromDIP(10));
//type
wxBoxSizer * type_key_sizer = new wxBoxSizer(wxVERTICAL);
wxStaticText *static_type_text = new wxStaticText(this, wxID_ANY, _L("Type"), wxDefaultPosition, wxDefaultSize);
type_key_sizer->Add(static_type_text, 0, wxEXPAND | wxALL, 0);
type_key_sizer->SetMinSize(OPTION_SIZE);
type_sizer->Add(type_key_sizer, 0, wxEXPAND | wxLEFT | wxBOTTOM | wxALIGN_CENTER_VERTICAL, FromDIP(10));
wxBoxSizer * type_value_sizer = new wxBoxSizer(wxVERTICAL);
wxStaticText *type_text = new wxStaticText(this, wxID_ANY, from_u8(m_filament_type), wxDefaultPosition, wxDefaultSize);
type_value_sizer->Add(type_text, 0, wxEXPAND | wxALL, 0);
type_sizer->Add(type_value_sizer, 0, wxEXPAND | wxLEFT | wxBOTTOM | wxALIGN_CENTER_VERTICAL, FromDIP(10));
//serial
wxBoxSizer * serial_key_sizer = new wxBoxSizer(wxVERTICAL);
wxStaticText *static_serial_text = new wxStaticText(this, wxID_ANY, _L("Serial"), wxDefaultPosition, wxDefaultSize);
serial_key_sizer->Add(static_serial_text, 0, wxEXPAND | wxALL, 0);
serial_key_sizer->SetMinSize(OPTION_SIZE);
serial_sizer->Add(serial_key_sizer, 0, wxEXPAND | wxLEFT | wxBOTTOM | wxALIGN_CENTER_VERTICAL, FromDIP(10));
wxBoxSizer * serial_value_sizer = new wxBoxSizer(wxVERTICAL);
wxString full_filamnet_serial = from_u8(m_filament_serial);
wxString show_filament_serial = full_filamnet_serial;
if (m_filament_serial.size() > 40) {
show_filament_serial = from_u8(m_filament_serial.substr(0, 20)) + "...";
}
wxStaticText *serial_text = new wxStaticText(this, wxID_ANY, show_filament_serial, wxDefaultPosition, wxDefaultSize);
wxToolTip * toolTip = new wxToolTip(full_filamnet_serial);
serial_text->SetToolTip(toolTip);
serial_value_sizer->Add(serial_text, 0, wxEXPAND | wxALL, 0);
serial_sizer->Add(serial_value_sizer, 0, wxEXPAND | wxLEFT | wxBOTTOM | wxALIGN_CENTER_VERTICAL, FromDIP(10));
basic_info_sizer->Add(vendor_sizer, 0, wxEXPAND | wxALL, 0);
basic_info_sizer->Add(type_sizer, 0, wxEXPAND | wxALL, 0);
basic_info_sizer->Add(serial_sizer, 0, wxEXPAND | wxALL, 0);
return basic_info_sizer;
}
wxBoxSizer *EditFilamentPresetDialog::create_add_filament_btn()
{
wxBoxSizer *add_filament_btn_sizer = new wxBoxSizer(wxHORIZONTAL);
m_add_filament_btn = new Button(this, _L("+ Add Preset"));
m_add_filament_btn->SetFont(Label::Body_10);
m_add_filament_btn->SetPaddingSize(wxSize(FromDIP(8), FromDIP(3)));
m_add_filament_btn->SetCornerRadius(FromDIP(8));
StateColor flush_bg_col(std::pair<wxColour, int>(wxColour(219, 253, 231), StateColor::Pressed), std::pair<wxColour, int>(wxColour(238, 238, 238), StateColor::Hovered),
std::pair<wxColour, int>(wxColour(238, 238, 238), StateColor::Normal));
StateColor flush_fg_col(std::pair<wxColour, int>(wxColour(107, 107, 106), StateColor::Pressed), std::pair<wxColour, int>(wxColour(107, 107, 106), StateColor::Hovered),
std::pair<wxColour, int>(wxColour(107, 107, 106), StateColor::Normal));
StateColor flush_bd_col(std::pair<wxColour, int>(wxColour(0, 150, 136), StateColor::Pressed), std::pair<wxColour, int>(wxColour(0, 150, 136), StateColor::Hovered),
std::pair<wxColour, int>(wxColour(172, 172, 172), StateColor::Normal));
m_add_filament_btn->SetBackgroundColor(flush_bg_col);
m_add_filament_btn->SetBorderColor(flush_bd_col);
m_add_filament_btn->SetTextColor(flush_fg_col);
add_filament_btn_sizer->Add(m_add_filament_btn, 0, wxEXPAND | wxALL, FromDIP(10));
m_add_filament_btn->Bind(wxEVT_BUTTON, [this](wxCommandEvent &e) {
CreatePresetForPrinterDialog dlg(nullptr, m_filament_type, m_filament_id, m_vendor_name, m_filament_name);
int res = dlg.ShowModal();
if (res == wxID_OK) {
if (get_same_filament_id_presets(m_filament_id)) {
update_preset_tree();
}
}
});
return add_filament_btn_sizer;
}
wxBoxSizer *EditFilamentPresetDialog::create_preset_tree_sizer()
{
wxBoxSizer *filament_preset_tree_sizer = new wxBoxSizer(wxHORIZONTAL);
m_preset_tree_window = new wxScrolledWindow(this);
m_preset_tree_window->SetScrollRate(5, 5);
m_preset_tree_window->SetBackgroundColour(PRINTER_LIST_COLOUR);
m_preset_tree_window->SetMinSize(wxSize(-1, FromDIP(400)));
m_preset_tree_window->SetMaxSize(wxSize(-1, FromDIP(300)));
m_preset_tree_window->SetSize(wxSize(-1, FromDIP(300)));
m_preset_tree_panel = new wxPanel(m_preset_tree_window);
m_preset_tree_sizer = new wxBoxSizer(wxVERTICAL);
m_preset_tree_panel->SetSizer(m_preset_tree_sizer);
m_preset_tree_panel->SetMinSize(wxSize(580, -1));
m_preset_tree_panel->SetBackgroundColour(PRINTER_LIST_COLOUR);
wxBoxSizer* m_preset_tree_window_sizer = new wxBoxSizer(wxVERTICAL);
m_preset_tree_window_sizer->Add(m_preset_tree_panel, wxEXPAND | wxLEFT | wxRIGHT, FromDIP(10));
m_preset_tree_window->SetSizerAndFit(m_preset_tree_window_sizer);
filament_preset_tree_sizer->Add(m_preset_tree_window, 0, wxEXPAND | wxALL | wxALIGN_CENTER_VERTICAL, FromDIP(10));
return filament_preset_tree_sizer;
}
wxBoxSizer *EditFilamentPresetDialog::create_button_sizer()
{
wxBoxSizer *bSizer_button = new wxBoxSizer(wxHORIZONTAL);
m_del_filament_btn = new Button(this, _L("Delete Filament"));
m_del_filament_btn->SetBackgroundColor(*wxRED);
m_del_filament_btn->SetBorderColor(*wxWHITE);
m_del_filament_btn->SetTextColor(wxColour(0xFFFFFE));
m_del_filament_btn->SetFont(Label::Body_12);
m_del_filament_btn->SetSize(wxSize(FromDIP(58), FromDIP(24)));
m_del_filament_btn->SetMinSize(wxSize(FromDIP(58), FromDIP(24)));
m_del_filament_btn->SetCornerRadius(FromDIP(12));
bSizer_button->Add(m_del_filament_btn, 0, wxLEFT | wxBOTTOM, FromDIP(10));
bSizer_button->Add(0, 0, 1, wxEXPAND, 0);
StateColor btn_bg_green(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_ok_btn = new Button(this, _L("OK"));
m_ok_btn->SetBackgroundColor(btn_bg_green);
m_ok_btn->SetBorderColor(*wxWHITE);
m_ok_btn->SetTextColor(wxColour(0xFFFFFE));
m_ok_btn->SetFont(Label::Body_12);
m_ok_btn->SetSize(wxSize(FromDIP(58), FromDIP(24)));
m_ok_btn->SetMinSize(wxSize(FromDIP(58), FromDIP(24)));
m_ok_btn->SetCornerRadius(FromDIP(12));
bSizer_button->Add(m_ok_btn, 0, wxRIGHT | wxBOTTOM, FromDIP(10));
StateColor btn_bg_white(std::pair<wxColour, int>(wxColour(206, 206, 206), StateColor::Pressed), std::pair<wxColour, int>(wxColour(238, 238, 238), StateColor::Hovered),
std::pair<wxColour, int>(*wxWHITE, StateColor::Normal));
m_del_filament_btn->Bind(wxEVT_BUTTON, ([this](wxCommandEvent &e) {
WarningDialog dlg(this, _L("All the filament presets belong to this filament would be deleted. \nIf you are using this filament on your printer, please reset the filament information for that slot."), _L("Delete filament"), wxYES | wxCANCEL | wxCANCEL_DEFAULT | wxCENTRE);
int res = dlg.ShowModal();
if (wxID_YES == res) {
PresetBundle *preset_bundle = wxGetApp().preset_bundle;
std::set<std::shared_ptr<Preset>> inherit_preset_names;
std::set<std::shared_ptr<Preset>> root_preset_names;
for (std::pair<std::string, std::vector<std::shared_ptr<Preset>>> printer_and_preset : m_printer_compatible_presets) {
for (std::shared_ptr<Preset> preset : printer_and_preset.second) {
if (preset->inherits().empty()) {
root_preset_names.insert(preset);
} else {
inherit_preset_names.insert(preset);
}
}
}
// delete inherit preset first
std::string next_selected_preset_name = wxGetApp().preset_bundle->filaments.get_selected_preset().name;
for (std::shared_ptr<Preset> preset : inherit_preset_names) {
bool delete_result = delete_filament_preset_by_name(preset->name, next_selected_preset_name);
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " inherit filament name: " << preset->name << (delete_result ? " delete successful" : " delete failed");
}
for (std::shared_ptr<Preset> preset : root_preset_names) {
bool delete_result = delete_filament_preset_by_name(preset->name, next_selected_preset_name);
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " root filament name: " << preset->name << (delete_result ? " delete successful" : " delete failed");
}
m_printer_compatible_presets.clear();
wxGetApp().preset_bundle->filaments.select_preset_by_name(next_selected_preset_name,true);
for (size_t i = 0; i < wxGetApp().preset_bundle->filament_presets.size(); ++i) {
auto preset = wxGetApp().preset_bundle->filaments.find_preset(wxGetApp().preset_bundle->filament_presets[i]);
if (preset == nullptr) wxGetApp().preset_bundle->filament_presets[i] = wxGetApp().preset_bundle->filaments.get_selected_preset_name();
}
EndModal(wxID_OK);
}
e.Skip();
}));
m_ok_btn->Bind(wxEVT_LEFT_DOWN, [this](wxMouseEvent &e) { EndModal(wxID_OK); });
return bSizer_button;
}
CreatePresetForPrinterDialog::CreatePresetForPrinterDialog(wxWindow *parent, std::string filament_type, std::string filament_id, std::string filament_vendor, std::string filament_name)
: DPIDialog(parent ? parent : nullptr, wxID_ANY, _L("Add Preset"), wxDefaultPosition, wxDefaultSize, wxCAPTION | wxCLOSE_BOX)
, m_filament_id(filament_id)
, m_filament_name(filament_name)
, m_filament_vendor(filament_vendor)
, m_filament_type(filament_type)
{
m_preset_bundle = std::make_shared<PresetBundle>(*(wxGetApp().preset_bundle));
get_visible_printer_and_compatible_filament_presets();
this->SetBackgroundColour(*wxWHITE);
std::string icon_path = (boost::format("%1%/images/OrcaSlicerTitle.ico") % resources_dir()).str();
SetIcon(wxIcon(encode_path(icon_path.c_str()), wxBITMAP_TYPE_ICO));
wxBoxSizer *main_sizer = new wxBoxSizer(wxVERTICAL);
// top line
auto m_line_top = new wxPanel(this, wxID_ANY, wxDefaultPosition, wxSize(-1, 1), wxTAB_TRAVERSAL);
m_line_top->SetBackgroundColour(wxColour(0xA6, 0xa9, 0xAA));
main_sizer->Add(m_line_top, 0, wxEXPAND, 0);
main_sizer->Add(0, 0, 0, wxTOP, FromDIP(5));
wxStaticText *basic_infomation = new wxStaticText(this, wxID_ANY, _L("Add preset for new printer"));
basic_infomation->SetFont(Label::Head_16);
main_sizer->Add(basic_infomation, 0, wxALL, FromDIP(10));
main_sizer->Add(create_selected_printer_preset_sizer(), 0, wxALL, FromDIP(10));
main_sizer->Add(create_selected_filament_preset_sizer(), 0, wxALL, FromDIP(10));
main_sizer->Add(create_button_sizer(), 0, wxEXPAND | wxALL, FromDIP(10));
this->SetSizer(main_sizer);
this->Layout();
this->Fit();
wxGetApp().UpdateDlgDarkUI(this);
}
CreatePresetForPrinterDialog::~CreatePresetForPrinterDialog() {}
void CreatePresetForPrinterDialog::on_dpi_changed(const wxRect &suggested_rect) {
m_ok_btn->SetMinSize(wxSize(FromDIP(58), FromDIP(24)));
m_ok_btn->SetMaxSize(wxSize(FromDIP(58), FromDIP(24)));
m_ok_btn->SetCornerRadius(FromDIP(12));
m_cancel_btn->SetMinSize(wxSize(FromDIP(58), FromDIP(24)));
m_cancel_btn->SetMaxSize(wxSize(FromDIP(58), FromDIP(24)));
m_cancel_btn->SetCornerRadius(FromDIP(12));
Layout();
}
void CreatePresetForPrinterDialog::get_visible_printer_and_compatible_filament_presets()
{
const std::deque<Preset> &printer_presets = m_preset_bundle->printers.get_presets();
m_printer_compatible_filament_presets.clear();
for (const Preset &printer_preset : printer_presets) {
if (printer_preset.is_visible) {
if (m_preset_bundle->printers.get_preset_base(printer_preset) != &printer_preset) continue;
if (m_preset_bundle->printers.select_preset_by_name(printer_preset.name, true)) {
m_preset_bundle->update_compatible(PresetSelectCompatibleType::Always);
const std::deque<Preset> &filament_presets = m_preset_bundle->filaments.get_presets();
for (const Preset &filament_preset : filament_presets) {
if (filament_preset.is_default || !filament_preset.is_compatible) continue;
ConfigOptionStrings *filament_types;
const Preset * filament_preset_base = m_preset_bundle->filaments.get_preset_base(filament_preset);
if (filament_preset_base == &filament_preset) {
filament_types = dynamic_cast<ConfigOptionStrings *>(const_cast<Preset *>(&filament_preset)->config.option("filament_type"));
} else {
filament_types = dynamic_cast<ConfigOptionStrings *>(const_cast<Preset *>(filament_preset_base)->config.option("filament_type"));
}
if (filament_types && filament_types->values.empty()) continue;
const std::string filament_type = filament_types->values[0];
std::string filament_type_ = system_filament_types_map[m_filament_type];
if (filament_type_.empty()) filament_type_ = m_filament_type;
if (filament_type == filament_type_) {
m_printer_compatible_filament_presets[printer_preset.name].push_back(std::make_shared<Preset>(filament_preset));
}
}
}
}
}
}
wxBoxSizer *CreatePresetForPrinterDialog::create_selected_printer_preset_sizer()
{
wxBoxSizer *select_preseter_preset_sizer = new wxBoxSizer(wxVERTICAL);
wxStaticText *printer_text = new wxStaticText(this, wxID_ANY, _L("Printer"), wxDefaultPosition, wxDefaultSize);
select_preseter_preset_sizer->Add(printer_text, 0, wxEXPAND | wxALL, 0);
m_selected_printer = new ComboBox(this, wxID_ANY, wxEmptyString, wxDefaultPosition, PRINTER_PRESET_MODEL_SIZE, 0, nullptr, wxCB_READONLY);
select_preseter_preset_sizer->Add(m_selected_printer, 0, wxEXPAND | wxTOP, FromDIP(5));
wxArrayString printer_choices;
for (std::pair<std::string, std::vector<std::shared_ptr<Preset>>> printer_to_filament_presets : m_printer_compatible_filament_presets) {
auto compatible_printer_name = printer_to_filament_presets.first;
if (compatible_printer_name.empty()) {
BOOST_LOG_TRIVIAL(info)<<__FUNCTION__ << " a printer has no name";
continue;
}
wxString printer_name = from_u8(compatible_printer_name);
printer_choices.push_back(printer_name);
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " entry, and visible printer is: " << compatible_printer_name;
}
m_selected_printer->Set(printer_choices);
return select_preseter_preset_sizer;
}
wxBoxSizer *CreatePresetForPrinterDialog::create_selected_filament_preset_sizer()
{
wxBoxSizer * select_filament_preset_sizer = new wxBoxSizer(wxVERTICAL);
wxStaticText *printer_text = new wxStaticText(this, wxID_ANY, _L("Copy preset from filament"), wxDefaultPosition, wxDefaultSize);
select_filament_preset_sizer->Add(printer_text, 0, wxEXPAND | wxALL, 0);
m_selected_filament = new ComboBox(this, wxID_ANY, wxEmptyString, wxDefaultPosition, PRINTER_PRESET_MODEL_SIZE, 0, nullptr, wxCB_READONLY);
select_filament_preset_sizer->Add(m_selected_filament, 0, wxEXPAND | wxTOP, FromDIP(5));
m_selected_printer->Bind(wxEVT_COMBOBOX, [this](wxCommandEvent &e) {
wxString printer_name = m_selected_printer->GetStringSelection();
std::unordered_map<string, std::vector<std::shared_ptr<Preset>>>::iterator filament_iter = m_printer_compatible_filament_presets.find(into_u8(printer_name));
if (m_printer_compatible_filament_presets.end() != filament_iter) {
filament_choice_to_filament_preset.clear();
wxArrayString filament_choices;
for (std::shared_ptr<Preset> filament_preset : filament_iter->second) {
wxString filament_name = wxString::FromUTF8(filament_preset->name);
filament_choice_to_filament_preset[filament_name] = filament_preset;
filament_choices.push_back(filament_name);
}
m_selected_filament->Set(filament_choices);
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " count of compatible filament presets :" << filament_choices.size();
if (filament_choices.size()) { m_selected_filament->SetSelection(0); }
} else {
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << "printer preset not find compatible filament presets";
}
});
return select_filament_preset_sizer;
}
wxBoxSizer *CreatePresetForPrinterDialog::create_button_sizer()
{
wxBoxSizer *bSizer_button = new wxBoxSizer(wxHORIZONTAL);
bSizer_button->Add(0, 0, 1, wxEXPAND, 0);
StateColor btn_bg_green(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_ok_btn = new Button(this, _L("OK"));
m_ok_btn->SetBackgroundColor(btn_bg_green);
m_ok_btn->SetBorderColor(*wxWHITE);
m_ok_btn->SetTextColor(wxColour(0xFFFFFE));
m_ok_btn->SetFont(Label::Body_12);
m_ok_btn->SetSize(wxSize(FromDIP(58), FromDIP(24)));
m_ok_btn->SetMinSize(wxSize(FromDIP(58), FromDIP(24)));
m_ok_btn->SetCornerRadius(FromDIP(12));
bSizer_button->Add(m_ok_btn, 0, wxRIGHT | wxBOTTOM, FromDIP(10));
StateColor btn_bg_white(std::pair<wxColour, int>(wxColour(206, 206, 206), StateColor::Pressed), std::pair<wxColour, int>(wxColour(238, 238, 238), StateColor::Hovered),
std::pair<wxColour, int>(*wxWHITE, StateColor::Normal));
m_cancel_btn = new Button(this, _L("Cancel"));
m_cancel_btn->SetBackgroundColor(btn_bg_white);
m_cancel_btn->SetBorderColor(wxColour(38, 46, 48));
m_cancel_btn->SetFont(Label::Body_12);
m_cancel_btn->SetSize(wxSize(FromDIP(58), FromDIP(24)));
m_cancel_btn->SetMinSize(wxSize(FromDIP(58), FromDIP(24)));
m_cancel_btn->SetCornerRadius(FromDIP(12));
bSizer_button->Add(m_cancel_btn, 0, wxRIGHT | wxBOTTOM, FromDIP(10));
m_ok_btn->Bind(wxEVT_BUTTON, [this](wxCommandEvent &e) {
wxString selected_printer_name = m_selected_printer->GetStringSelection();
std::string printer_name = into_u8(selected_printer_name);
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " add preset: get compatible printer name:";
wxString filament_preset_name = m_selected_filament->GetStringSelection();
std::unordered_map<wxString, std::shared_ptr<Preset>>::iterator iter = filament_choice_to_filament_preset.find(filament_preset_name);
if (filament_choice_to_filament_preset.end() != iter) {
std::shared_ptr<Preset> filament_preset = iter->second;
PresetBundle * preset_bundle = wxGetApp().preset_bundle;
std::vector<std::string> failures;
DynamicConfig dynamic_config;
dynamic_config.set_key_value("filament_vendor", new ConfigOptionStrings({m_filament_vendor}));
dynamic_config.set_key_value("compatible_printers", new ConfigOptionStrings({printer_name}));
dynamic_config.set_key_value("filament_type", new ConfigOptionStrings({m_filament_type}));
bool res = preset_bundle->filaments.clone_presets_for_filament(filament_preset.get(), failures, m_filament_name, m_filament_id, dynamic_config, printer_name);
if (!res) {
std::string failure_names;
for (std::string &failure : failures) { failure_names += failure + "\n"; }
MessageDialog dlg(this, _L("Some existing presets have failed to be created, as follows:\n") + from_u8(failure_names) + _L("\nDo you want to rewrite it?"),
wxString(SLIC3R_APP_FULL_NAME) + " - " + _L("Info"), wxYES_NO | wxYES_DEFAULT | wxCENTRE);
if (dlg.ShowModal() == wxID_YES) {
res = preset_bundle->filaments.clone_presets_for_filament(filament_preset.get(), failures, m_filament_name, m_filament_id, dynamic_config, printer_name, true);
BOOST_LOG_TRIVIAL(info) << "clone filament have failures rewritten is successful? " << res;
} else {
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << "have same name preset and not rewritten";
return;
}
} else {
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << "create filament preset successful and name is:" << m_filament_name + " @" + printer_name;
}
} else {
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << "filament choice not find filament preset and choice is:" << filament_preset_name;
MessageDialog dlg(this, _L("The filament choice not find filament preset, please reselect it"), wxString(SLIC3R_APP_FULL_NAME) + " - " + _L("Info"),
wxYES | wxYES_DEFAULT | wxCENTRE);
dlg.ShowModal();
return;
}
EndModal(wxID_OK);
});
m_cancel_btn->Bind(wxEVT_BUTTON, [this](wxCommandEvent &e) { EndModal(wxID_CANCEL); });
return bSizer_button;
}
PresetTree::PresetTree(EditFilamentPresetDialog * dialog)
: m_parent_dialog(dialog)
{}
wxPanel *PresetTree::get_preset_tree(std::pair<std::string, std::vector<std::shared_ptr<Preset>>> printer_and_presets)
{
wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
wxPanel * parent = m_parent_dialog->get_preset_tree_panel();
wxPanel * panel = new wxPanel(parent);
wxColour backgroundColor = parent->GetBackgroundColour();
panel->SetBackgroundColour(backgroundColor);
const std::string &printer_name = printer_and_presets.first;
sizer->Add(get_root_item(panel, printer_name), 0, wxEXPAND, 0);
int child_count = printer_and_presets.second.size();
for (int i = 0; i < child_count; i++) {
if (i == child_count - 1) {
sizer->Add(get_child_item(panel, printer_and_presets.second[i], printer_name, i, true), 0, wxEXPAND, 0);
} else {
sizer->Add(get_child_item(panel, printer_and_presets.second[i], printer_name, i, false), 0, wxEXPAND, 0);
}
}
panel->SetSizerAndFit(sizer);
return panel;
}
wxPanel *PresetTree::get_root_item(wxPanel *parent, const std::string &printer_name)
{
wxBoxSizer *sizer = new wxBoxSizer(wxHORIZONTAL);
wxPanel * panel = new wxPanel(parent);
wxColour backgroundColor = parent->GetBackgroundColour();
panel->SetBackgroundColour(backgroundColor);
wxStaticText *preset_name = new wxStaticText(panel, wxID_ANY, from_u8(printer_name));
preset_name->SetFont(Label::Body_11);
preset_name->SetForegroundColour(*wxBLACK);
sizer->Add(preset_name, 0, wxEXPAND | wxALL, 5);
panel->SetSizer(sizer);
return panel;
}
wxPanel *PresetTree::get_child_item(wxPanel *parent, std::shared_ptr<Preset> preset, std::string printer_name, int preset_index, bool is_last)
{
wxBoxSizer *sizer = new wxBoxSizer(wxHORIZONTAL);
wxPanel * panel = new wxPanel(parent);
wxColour backgroundColor = parent->GetBackgroundColour();
panel->SetBackgroundColour(backgroundColor);
sizer->Add(0, 0, 0, wxLEFT, 10);
wxPanel *line_left = new wxPanel(panel, wxID_ANY, wxDefaultPosition, is_last ? wxSize(1, 12) : wxSize(1, -1));
line_left->SetBackgroundColour(*wxBLACK);
sizer->Add(line_left, 0, is_last ? wxALL : wxEXPAND | wxALL, 0);
wxPanel *line_right = new wxPanel(panel, wxID_ANY, wxDefaultPosition, wxSize(10, 1));
line_right->SetBackgroundColour(*wxBLACK);
sizer->Add(line_right, 0, wxALL | wxALIGN_CENTER_VERTICAL, 0);
sizer->Add(0, 0, 0, wxLEFT, 5);
wxStaticText *preset_name = new wxStaticText(panel, wxID_ANY, from_u8(preset->name));
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " create child item: " << preset->name;
preset_name->SetFont(Label::Body_10);
preset_name->SetForegroundColour(*wxBLACK);
sizer->Add(preset_name, 0, wxEXPAND | wxALL, 5);
sizer->Add(0, 0, 1, wxEXPAND, 0);
StateColor flush_bg_col(std::pair<wxColour, int>(wxColour(219, 253, 231), StateColor::Pressed), std::pair<wxColour, int>(wxColour(238, 238, 238), StateColor::Hovered),
std::pair<wxColour, int>(wxColour(238, 238, 238), StateColor::Normal));
StateColor flush_fg_col(std::pair<wxColour, int>(wxColour(107, 107, 106), StateColor::Pressed), std::pair<wxColour, int>(wxColour(107, 107, 106), StateColor::Hovered),
std::pair<wxColour, int>(wxColour(107, 107, 106), StateColor::Normal));
StateColor flush_bd_col(std::pair<wxColour, int>(wxColour(0, 150, 136), StateColor::Pressed), std::pair<wxColour, int>(wxColour(0, 150, 136), StateColor::Hovered),
std::pair<wxColour, int>(wxColour(172, 172, 172), StateColor::Normal));
Button *edit_preset_btn = new Button(panel, _L("Edit Preset"));
edit_preset_btn->SetFont(Label::Body_10);
edit_preset_btn->SetPaddingSize(wxSize(8, 3));
edit_preset_btn->SetCornerRadius(8);
edit_preset_btn->SetBackgroundColor(flush_bg_col);
edit_preset_btn->SetBorderColor(flush_bd_col);
edit_preset_btn->SetTextColor(flush_fg_col);
//edit_preset_btn->Hide();
sizer->Add(edit_preset_btn, 0, wxALL | wxALIGN_CENTER_VERTICAL, 0);
sizer->Add(0, 0, 0, wxLEFT, 5);
Button *del_preset_btn = new Button(panel, _L("Delete Preset"));
del_preset_btn->SetFont(Label::Body_10);
del_preset_btn->SetPaddingSize(wxSize(8, 3));
del_preset_btn->SetCornerRadius(8);
del_preset_btn->SetBackgroundColor(flush_bg_col);
del_preset_btn->SetBorderColor(flush_bd_col);
del_preset_btn->SetTextColor(flush_fg_col);
//del_preset_btn->Hide();
sizer->Add(del_preset_btn, 0, wxALL | wxALIGN_CENTER_VERTICAL, 0);
edit_preset_btn->Bind(wxEVT_BUTTON, [this, printer_name, preset_index](wxCommandEvent &e) {
wxGetApp().CallAfter([this, printer_name, preset_index]() { edit_preset(printer_name, preset_index); });
});
del_preset_btn->Bind(wxEVT_BUTTON, [this, printer_name, preset_index](wxCommandEvent &e) {
wxGetApp().CallAfter([this, printer_name, preset_index]() { delete_preset(printer_name, preset_index); });
});
panel->SetSizer(sizer);
return panel;
}
void PresetTree::delete_preset(std::string printer_name, int need_delete_preset_index)
{
m_parent_dialog->set_printer_name(printer_name);
m_parent_dialog->set_need_delete_preset_index(need_delete_preset_index);
m_parent_dialog->delete_preset();
}
void PresetTree::edit_preset(std::string printer_name, int need_edit_preset_index)
{
m_parent_dialog->set_printer_name(printer_name);
m_parent_dialog->set_need_edit_preset_index(need_edit_preset_index);
m_parent_dialog->edit_preset();
}
} // namespace GUI
} // namespace Slic3r