OrcaSlicer/src/slic3r/GUI/Gizmos/GLGizmoAdvancedCut.cpp
SoftFever bba367cde8
Feature/merge 1.8.2 (#3193)
* FIX: user preset sync token

Change-Id: Id2aa865b778ee9ac4cfddb68ceef0374507b519b
Jira: none

* FIX: Bitmap cache not take effect

Change-Id: I972098fdbda0b4542c6c759a8f5e1f0f2a30852b
Jira: STUDIO-4991

* NEW: Open HotModel Link With GetParam-From bambustudio

JIRA: NO JIRA

Change-Id: I4ac49bac5ee0c50988c76a38b00b7ba7dc3201f5

* NEW:AmsMaterialsSetting Support for user-preset

JIRA: STUDIO-5135
Change-Id: If848047cd5dbd059d440de30989c505c361305a7

* FIX: upload custom root preset fail

Change-Id: I621c8d542dd604b07cc5df63d97d7a31558d3aba
Jira: none

* FIX: show custom filament in AMS filament list

Change-Id: I79b9f8f2f08db8c52bbed76f1ea133baff383c00
Jira: none

* FIX: dailytips window and gcodeviwer legend window size issue

reset to original logic of dailytips and legend window size

jira: new

Change-Id: Iacb016bb222ba3f87317cfbe1f2b003802d773a5

* ENH: add text translation

jira: new

Change-Id: I780cfb8a0a64d806b5e0a414b6598e3b7bdf52dc

* FIX: Delete and search object outside the plate

JIRA:
1. STUDIO-5132 Deleting object outside the plate will crash
2. STUDIO-5146 The search function cannot search for object outside the plate

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

* FIX: [5149 5142 5141 5140 5136] create printer and filament issue

Jira: 5149 5142 5141 5140 5136
5149 process preset name can not show all
5142 improt configs combobox not update
5141 disable modify filament_vendor
5140 disable input Bambu and Generic vendor
5136 preset list window adjust

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

* ci: update build version to 01.08.00.54

Change-Id: Ifd69c01a82f627a9c6cf4fe0d48a759563ee90e7

* FIX: print model from sdcard with p1p

Change-Id: If85383ba762022ead3dd754ae02a08817b891114
Jira: none

* FIX: dailytips text translation

jira: STUDIO-2556

Change-Id: If44e503615b09ee1692f42ba1f998918ec5bd691

* FIX: clone shortcut key conflict with quit in macos

jira: STUDIO-5166

Change-Id: I548f275bb68d3b0e6bb3cfad6fe93df09d507da3

* FIX:User preset material settings dependent on firmware

JIRA: 5167
Change-Id: I82cf26848594b01155883ad0aa2e9ee77d371fb2

* ENH:update the description of nozzle detection

Change-Id: Id27b25c69dc11fcf66fc82053af705906ae8c370

* FIX: [5159 5165 5171 5172] create printer and filament issue

Jira: 5159 5165 5171 5172
5159 create printer dialog no refresh
5165 create printer 2 step dialog no refersh
5171 change font
5172 edit filament dialog darkUI issue
input special character is prohibited
'/' in preset name translate to '-'
update printer combobox

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

* ci: update build version to 01.08.00.55

Change-Id: If1865d561cf274719204662314de163497759e89

* FIX:fix GLmodel deconstruction causing section not to be rendered

Jira: STUDIO-5156
Change-Id: Ibb2f459920989ee54f7b827352dc8893424b4de6

* FIX: missing unlock cause device or resource busy

Change-Id: I87563312ea9c6ce4e4e471da7ce7a02b53b64762

* FIX: some translation

Change-Id: I9758cbc758030b5a3945697a50ca4898af9fcb1b

* ci: update build version to 01.08.00.56

Change-Id: Id5ee53dd2ebb0b37b6927dc58b3cca94a1f66a83

* ENH: remove PLA GLOW in A1 mini

jira:[NEW]

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

* ci: update build version to 01.08.00.57

Change-Id: Ib4dfa60f097128b76b95bb14ca04978619021b56

* Allow line width of nozzle diameter * 2.5

As it were, 1 mm would be disallowed but 0.99 would be allowed for 0.4
nozzle.  1 mm is the sane maximum and 0.99 is unnecessary tedious to write.

* Russian translation update

Russian translation Bambu Studio_v1.8.0 Beta

* FIX: scale problem in needs_retraction

jira:[NEW]

Signed-off-by: xun.zhang <xun.zhang@bambulab.com>
Change-Id: Idfbe954b22fa6aa5769c55e46874fa6a80ecbf45
(cherry picked from commit 4e853f50b748e3af11e2d64862b6ee557fda361b)

* ENH: CLI: support load_assemble_list

JIRA: STUDIO-4848
Change-Id: Ife11533740988331ea71eac86c370e625970cb8b

* FIX: align to Y not working

This is a bug introduced in 7fbb650 when solving jira STUDIO-4695.
Now we use a more decent way to solve it.

Change-Id: I92deffcb9fe53e8a24c93fe973446ae37df07375
(cherry picked from commit bd98430dbd15eb6c9bb4b447990e0dcf8a50eef0)

* ENH: Add buried points for cut and meshboolean

JIRA: NONE

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

* FIX: 5092 edit filament add scrolled window

Jira: 5092

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

* FIX: can not select user preset when create filament

Jira: XXXX
github: 1936
and fix add preset for printer dialog can not show selected printer

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

* ENH: template filament don't be show in filament list and sort

Jira: 5160 5179

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

* FIX: [5174] export configs dialog issue

filament name too long to can not show all

Jira: 5174

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

* ENH: add filament Bambu TPU 95A HF

1.As title

jira:[NEW]

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

* ENH: modify some params with filaments

1.Modify the PEI bed temperature of PLA Basic, Matte, and Tough to 65 in
 A1 mini. Set the bed temperature for the first layer of Bambu PETG-CF
 to 65 and 70 for the other layers

jira:[NEW]

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

* ENH: add more status during printing

JIRA: STUDIO-5195

Change-Id: I85b3107839c6e2fdecbc10d90a876463e284468c
Signed-off-by: Stone Li <stone.li@bambulab.com>

* FIX:cut imgui has overlapping rendering on Apple

Jira: STUDIO-5150
Change-Id: I7969e19dc189cd617026a183067dad628208955c

* FIX:not TakeSnapshot for m_start_dragging_m

Jira: STUDIO-5176

Change-Id: Ia03e3e2c2664dbdcffa19ec8d0fa97dfd95e6d35

* FIX: rendered color changes

Jira: STUDIO-4956
during the drag processin connectors editing state

Change-Id: I3027176ea9f93a9ba9d6a2052f41aaa4adef79f1

* FIX: merge the patch from Prusa

Thanks for PrusaSlicer and YuSanka
Jira:STUDIO-5175
commit 510d59687b3b19c4a0f4e6540620d0694dd1b7ac
Author: YuSanka <yusanka@gmail.com>
Date:   Thu Oct 5 14:13:14 2023 +0200
    Follow-up 1b451cdf: Fixed #11415 - Connectors disappear when slicing => only when using multiple cut planes AND excluding parts

Change-Id: I9ccd5b85f482d723d21fccf5e104c9e0a9cc4849

* FIX:Press ESC directly to exit after entering the profile rendering

rendering is not normal,Code from PrusaSlicer,thanks for PrusaSlicer and enricoturri1966
commit a078627552f54497ed0518dc7bc349d243576d19
Author: enricoturri1966 <enricoturri@seznam.cz>
Date:   Mon Jan 30 14:00:02 2023 +0100

    Follow-up of 1218103fd620b319c56fd08116f81b581c537188 - Fixed gizmo missbehavior when closing a gizmo by resetting the selection clicking on the scene

Jira: STUDIO-5164
Change-Id: I261da9dba2a5ac37f3e263c175fbccd80d8045bd

* FIX: correct the strings and move create printer dialog center

Jira: 5221 5183

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

* ENH: CLI: skip layer height limit validate when slicing for existing models

JIRA: no jira
Change-Id: I1444a28b500ca7d08ed2606eecfa5cfaf261105e

* ENH:update the translation of auto refill

jira:[for translation]

Change-Id: Iaa7b4f3d7cd88c8b4f69a3db721ebd8ca8986eea

* FIX: icon issue for copying

Jira: STUDIO-4168

Icon issue when filling bed with copies

Change-Id: I61a03ecae02b75602c236ed2810e9c9cfe5a19f9
(cherry picked from commit b5079f8a2e79f19f65803f23ef4fd83aff17c84a)

* ENH: update some filament params

1. Modify texture bed temp to 65
2. Modify max-v-speed for ABS
3. Modify some params in Generic PA
4. Modify PLA,PVA params

jira:[NEW]

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

* FIX: 3770 printable checkbox incorrect display in darkUI

Jira: 3770

Change-Id: I97f67d7a0ffc41f6ee625abeecc52ee4e73cf318

* FIX:Display garbled code in AmsMaterialsSetting pop-up

Change-Id: I50531e939afa7715ae376bac47172ccf7b248114

* ENH:Modifying the Line Color of Transparent Materials

JIRA: STUDIO-4311,5088,4983
Change-Id: I9e63413dc9cd7d523f0f7f1a2e32c4537a84467a

* FIX: crash when async delete printer file

Change-Id: I92c5e812d04da263338fb0eea2fd7583cf9ecde0
Jira: STUDIO-5222

* FIX: 3733 backup time not effective

Jira: 3733

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

* FIX: enable edit and delete preset btn and fix issue

Jira: XXXX

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

* FIX:send print job,file name displays error

JIRA:3137
Change-Id: I1c113025d274a13fba1b845a58aada14058fadd4

* FIX: skip hold user preset from sync

Change-Id: I2252246e19bd80903ad82170782ea49535d30d05
Jira: STUDIO-5185

* FIX: 5115 translations

Jira: 5115

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

* FIX: add link for ironing parameter

Change-Id: I451f5549db3ac2205aa5703a2e5edc831e946af8

* FIX: scale problem in lift type decide

1. Scale the travel threshhold

jira:[NEW]

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

* ENH: add small perimeter speed and threshold

The original param is added by Prusa. Thanks orca for adding threshold.

1. Re add small perimeter speed and threhold.

github: #2221

Change-Id: I35b269b26f085d80f0edca28650bb21fc04898d7

* FIX: modify the picture of pa manual cali

Jira: STUDIO-5102
Change-Id: Id87898959ad4461b7bd2505b159271f2aa589c36

* FIX: Filament preset is the same with the first one

Jira: STUDIO-4519

Filament preset is the same wit the first one, it should align with the
last one.

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

* FIX: scoreDailog dark mode issue

Jira: 4570

Change-Id: I8be97b306a1494f73e3bba678ecc864e7ff88ca3

* FIX: CLI: fix the slicing issue while only one object with multicolor using seq-print

JIRA: no-jira
Change-Id: Iea2d23ff8e484bf2fd58aa2f596a8e4e4292fe39

* ENH: open support wall count for normal support

1. open support wall count for normal support
  Enabling this option makes normal support stronger and gives
  better overhang quality, but also more difficult to removal.
  Jira: STUDIO-5192
2. fix a bug where tree support (hybrid style) may get overlapped
  extrusions near the walls.
3. fix a bug where raft layers can't be 1 in tree support
  Jira: STUDIO-5261

Change-Id: Iadc0c67a9b50b5b221c8e83d5aa22ed282018cf8
(cherry picked from commit c0bb0084e386cb70ed6e16edf93190e4b38f5b90)

* FIX: compiling error on linux

jira: none
Change-Id: I1a4563503b5ddf74a1979cc0cee7a15b8aced904
(cherry picked from commit de52c6ca62c9f3a6314ddf5a856c1d8534329886)

* ENH: add translation for small perimeter

jira:[NEW]

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

* FIX: clone shortcut key issue on macos

jira: STUDIO-5166

Change-Id: I1967da1d443ed43bd750dad8e11560688d7bd533

* FIX: custom gcode window cannot paste/ navigate

jira: STUDIO-5208、STUDIO-5070

Change-Id: I4ecb9d06cf5db0ae53a4678181aae9298bac106b

* ENH: modify dailytips collapse & expand interaction

jira: STUDIO-5209、STUDIO-5210

Change-Id: Ifb0b998e5004d4b49390ba5a250eaf4743bf3471

* ENH:Add shortcut keys and lists for objects search

JIRA: STUDIO-5157 STUDIO-5158 STUDIO-5240

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

* FIX:Re-calculate button with White Box displayed in dark mode

JIRA: STUDIO-5098

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

* NEW: display plate index when printing a task

JIRA: STUDIO-2689

display on the thumbnail of the current task

Change-Id: I5f1f46c56e9d1e9120a66d491551908dfad099d6
Signed-off-by: Stone Li <stone.li@bambulab.com>

* ENH:fixed incorrect path prefix

jira:[for file path prefix]

Change-Id: Ie9e3999f02b78272e528ceceb479e746d46a7e6c

* FIX: thumbnail is not clear in dark mode

JIRA: STUDIO-5087

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

* FIX: translation

Jira: XXXX

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

* ENH: first nozzle change to 0.4 and nozzle change to mm

Jira: XXXX

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

* ENH:editing_window_width's value is small on the laptop

Jira: STUDIO-5238 STUDIO-5265
apply_selected_connectors should check_and_update_connectors_state

Change-Id: I8c2c1c920cc4d197d1908815a3e62f4962335451

* FIX: fix new_bed_shape's calculation process

Jira: STUDIO-5122
Change-Id: I5f3e6a301a297123af28692c90bef6759f425b06

* ENH:update some translations

jira:[STUDIO-5262]

Change-Id: Idb1d3586888043ac325f272bc7a2b788adb3e9e5

* FIX: edit text command resets object settings

Jira: STUDIO-4655

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

* ci: update build version to 01.08.00.58

Change-Id: Iacfec02aa50c617e4c9fe566319b07b30d47dce1

* FIX: remove GetUserAgent

Change-Id: I92886e1f0dcb091109231a10da8c19d51178e13b
Jira: STUDIO-5205

* FIX: nozzle_diameter_map data structure adjustment

Change-Id: Ifb724afc0fcf974e6d331e73ecac723107a102cf

* ENH:add _A and _B for perform_with_groove

Jira: STUDIO-5267
Change-Id: Iee3310dfa1cd8e6680310f0af0eff5c817490813

* ENH:is_equal for min_z and max_z

Jira: STUDIO-5267
Change-Id: I9493883d8be9d44e26ddc9afe62b7e9eb09c5052

* ci: update build version to 01.08.00.59

Change-Id: Ie8ed29ccf5d6c94594eb2ab8b717416fbeace3bd

* FIX:Image display unclear in light mode

JIRA:5161
Change-Id: I134cc64a2af0dfff60c47d0ff09d78d9c0f86b3f

* FIX:fix bugs of non manifold edge

Jira: STUDIO-5267

Change-Id: I8ac9a2cf96da0bc07ee00b309e65611b92fd174d

* ENH:nozzle type detection

jira:[STUDIO-5246]

Change-Id: Ic41a2161a0e41d23f56af93ad8ec34cc83ada0e3

* ENH: upadte P1S start gcode

1.turn on MC board fan by default on P1S

jira:[NEW]

Signed-off-by: xun.zhang <xun.zhang@bambulab.com>
Change-Id: I5b2f7868e350942fb8b7baf7d429e22a0987184a
(cherry picked from commit e866a575b6b7d9552f7412f84272f4b48dfc3961)

* ENH: improve support style's tooltip

jira: none
Change-Id: I8ee858d7052f04ce7ea6b226a500c7d1bf8a482f
(cherry picked from commit 665f31c4fcde22bd894cbb4a5fb160635947f2a4)

* ENH: set layer range error to warning

1. If layer range exceeds maximum/minimum layer range in printer
settings,pop up a window to warn

jira:[NEW]

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

* ENH: CLI: remove the warning of layer height

JIRA: no jira
Change-Id: Idaceee4f52611479fc3f4238d016d891b4dc8cd1

* FIX: the word search is not translated

Jira: STUDIO-5224

The world search in the device panel is not translated.

Signed-off-by: wenjie.guo <wenjie.guo@bambulab.com>
Change-Id: Ia3d651c2159a3aad94e10cd0a6da98848f53ee2a
(cherry picked from commit 4a46a0a4750d82d49c9523f4b668a1a00c41ed83)

* FIX: Bitmap will flash when sending printing task

Jira: STUDIO-5278

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

* ENH:display the euler angle of rotation plane

Jira: STUDIO-5268
Change-Id: I6b7b431931d60f1a9a832908400417781798c472

* ci: update build version to 01.08.00.60

Change-Id: I1c15b5c6437554c43327cd6b537f7a5860dba5a0

* ENH:cancel EnterReturnsTrue for imgui in cut

Jira: STUDIO-5269
Change-Id: I2832e1dccaf9755448debe7b2bd56426f90dfe0d

* ci: update build version to 01.08.00.61

Change-Id: Ib03e664a20990322c788686550c491d0139d8237

* FIX: some translation problems

jira:[NEW]

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

* add: Ukrainian lang support for 1.8

* FIX: calibration selected preset is null in some case

jira: STUDIO-5258

Change-Id: Iee63593c5f833c5a43e3b1d1c9ddb82f8c69569a

* FIX: create filament issue

Jira: 5296 5297 5295 5302 5311 5276

5296 create filament: list has same printer
5297 create filament: filament combobox has blank options
5298 edit filament: delete last preset prompt users
5302 create filament: filament combox has cili preset
5311 create filament: printer name too long to can not show all
5276 edit filament: PLA Aero filament type filter issue
add prusa vendor
Revised copy

Change-Id: I5dcc615ce0951b1a9953fa12283f6090f5069045

* FIX: some translation

Change-Id: Icb8614a0af18f96d15f3b97c17e0f6f708296847

* FIX:cancel is_equal for slicing function

Jira: STUDIO-5267
Change-Id: I66d759aa2c968f8a28a6a5d8378929754f2db689

* FIX:UI stuck due to pop-up window with wrong chamber temperature

JIRA: 5304
Change-Id: I1a49a7219b7a6f5700243704c348724e7930ce1a

* FIX: allow input '+' and hide edit preset btn

Change-Id: I97aec7c3ac4cc8b9d6c535f0126aaa1926553d86

* ENH: handle printer direct close and not retry

Change-Id: I5dd55f8085cf6383a8420ab41e614ea6ae210c78
Jira: STUDIO-5305

* ci: update build version to 01.08.00.62

Change-Id: I09716bf79354b503197c751272fd3171e0abc8fd

* add: new translation to ukr for AirFlow and Prusa

* add: Texture Plate name fix

* FIX:add slice_facet_for_cut_mesh api for cut tool

and modify section_vertices_map 's traverse
Jira: STUDIO-5267
Change-Id: Ifc4b183a4e4c4fdb4f47742f14f70a1ed93fa056

Change-Id: I52bfaef8926ef967b78a6cb712a1731a1b528a24

* FIX: Make the front smaller for Czech in device panel

Jira: STUDIO-5151

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

* FIX: there is no object can be jumped to in notification

jira: new

Change-Id: Ib81bf49236952ede24a2de126051572d63916e01

* FIX: add height range, modifier in Preview pane will crash

jira: STUDIO-5340

1. fix crash at add height range, modifiers in Preview from objectList
2. fix an assert hit when slicing
3. fix an assert hit when enter AssembleView
4. forbidden popup menu by right-click objectList in Preview

Change-Id: I444bc76b1a4307999b387e4f60386b2d272bd308

* FIX: Black spot in the sending printing task page

Jira: STUDIO-5307

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

* FIX: reset_cut_by_contours should update_buffer_data

Jira: STUDIO-5376
Change-Id: I5aacb1f7b65822031d7138abd61a45b09c743531

* ENH:editing_window_width's value is small on the laptop

Jira: STUDIO-5238 STUDIO-5265
Change-Id: Ia958772bcb081817da621115f99328bb62770cd5

* ENH: bumped version to 1.8.1

Change-Id: I9d25403daa5b7b8ca415c0b364670da9e0f932b0

* FIX: create filament dialog: create btn can not show all

Jira: 5310 5331

Change-Id: I185272c90d9ff1c3d6b47abbefbf488d0d965cca

* FIX:update custom_texture when new_shape=false

Jira: STUDIO-5287
Change-Id: I3add95f9f9345c14a48cc7467513d1b3ce95f4c9

* ENH:editing_window_width's value is small on the laptop

Jira: STUDIO-5238
Change-Id: I9044129f4e0c8ca7469db05b3e547fca4754342a

* FIX:add slash_to_back_slash for saving file path

Jira: STUDIO-5287
Change-Id: I9f3c176cd0831c793958f08601c63efac98176a4

* FIX: a button color didn't response to dark mode change

jira: STUDIO-5315

Change-Id: I95489f01ccd1f77b9e95b0d0f69e5398d2e88487

* FIX: height range layers displayed in wrong position

jira: STUDIO-5341

Change-Id: I83918b4624f367efa54321f1898e1176cdb04ea9

* FIX: auto arranging issues with locked plates

1. global auto arranging may put items overlap with wipe tower if some plates are locked
jira: STUDIO-5329
2. items outside bed may overlap with plate boundary if it's rotated
jira: STUDIO-5329
3. plate-wise auto arranging uses wrong min_obj_distance if the
plate is by-layer printing but global setting is by-object printing
jira: STUDIO-5330

Change-Id: I5dba2f1317e183c9aeec1cb2bd227fbddf4316e6
(cherry picked from commit db1eac41efff5f1e8d5ac0af74c6fc7ab59fc253)

* FIX:  a mistake in upward machine

jira:[NEW]

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

* FIX:a blank pop-up appears

JIRA:XXXX
Change-Id: Ice92b55204e4897fec024a6d99412eb810bddd4a

* FIX:fixed failure in updating nozzle type

jira:[STUDIO-5248]

Change-Id: Iad37b5d5b76d37cb1723ef21d7c39b1e3fcaf8d7

* FIX:fixed issue with AI monitoring settings

jira:[STUDIO-5082]

Change-Id: I967fe3c1e9da61a55bcbfaa2a8e067dd5af18f72

* FIX:fixed issue with lan mode

jira:[STUDIO-5189]

Change-Id: I1d0a05f19dcea154cf3ef2b61ed0546d3581905e

* FIX:update text for loading or unloading filaments

jira:[STUDIO-5231]

Change-Id: Ic7729c3ec012485b3d87e3d01f11e87502c67895

* FIX: Revert "ENH: do not leave a gap for top...

Revert "ENH: do not leave a gap for top interface if the top z distance is 0"

This reverts commit 79ea32c7cbbdb7e689637980af7c36caf42284c9.

Revert reason: the supports are impossible to remove in some cases.
jira: STUDIO-5385

Change-Id: I376a6f4dfd78da6dfea68b9ac3d552cddd0b4272
(cherry picked from commit 34e38b705fde7f5d7f9a3a89c96a3627ce0c998e)

* ENH: improve normal support's quality

1. Add a base_interface_layer when using Supp.W
2. Fix a bug where base_angle and interface_angle are wong

jira: STUDIO-5386
Change-Id: I52ab32c63b3cd1e6e2ba6463b01ae26699cf13d3
(cherry picked from commit 92ddd4a10b793572a1fa009da5b9e44fcdf81de2)

* NEW:tracking stl model files

jira:[STUDIO-5372]

Change-Id: Idb1275b07441f0cd06c24588d5f7c20f81f1556c

* FIX: edit filament dialog: preset name too long to del btn nan't show

Jira: 5336 5174
and verify string normalization

Change-Id: I380c3bed2bf43d01094b68979a8b67f4187c0b93

* FIX: some translation

Jira: 5232 5300 5334

Change-Id: Ie474ca823011e81aab82a9809af3d6e42980496b

* FIX: some translation

Change-Id: Iaabe6087bed3b7d47d911cf4fb51c770804e72fb

* ENH: change default tree_support_wall_count to 0

Now normal support also uses this option, so we can't default it to 1, otherwise normal supports will be too hard to remove.

jira: none
Change-Id: Ic5700af5c17e3a7b265c8915f28b0db35c6e06e6
(cherry picked from commit 6b84a9826da108b76569e686bd9def0b23ae29fd)

* FIX:The name of the material in the error prompt is empty

JIRA:STUDIO-4907
Change-Id: I3cf44f099256a51f21a44a89c89c000f734d1f36

* ci: update build version to 01.08.01.51

Change-Id: Ib20f5a12b65472102befec0a2adf82744fc29c46

* FIX: imgui textinput cannot paste on macos

jira: STUDIO-5070、STUDIO-5365

Change-Id: Iea8f41e12744ecda0fbb95c1a8f2e014a7cdc384

* FIX: not cache printer file list on error

Change-Id: I99843aedbf14d3d1d553ccac9b0bd26403274a82
Jira: none

* FIX: thread of close BBLUserPresetExceedLimit notify

Change-Id: I9698134ba1cc91fc83eac441f900d68c4c4b556a

* ENH: Resolve non manifold edges by fixing model interfaces

Jira: STUDIO-5124
Change-Id: I7ea86be44acb80b6c4762a76208b4a031acd0b27

* FIX:nozzle type sync

jira:[STUDIO-5248]

Change-Id: I63d48628832473d8d371ed643dc8528b00382531

* FIX: array bound happen in TriangleSelector::deserialize

Jira: STUDIO-5170
Change-Id: I92b72a887845b462fad208f13607293b44d3d333

* FIX:cropping rendering without considering assembly views

Jira: STUDIO-5260
Change-Id: Ia56cf80b305ae05f25f06ec277f85b3c5430a6df

* FIX: PA for custom filament not available in BL Studio

github: 2971
Change-Id: I6ccd36a183e7367d69557300f7242f5403f4bb33

* FIX: Bitmap is way too small on Mac

Jira: STUDIO-5393

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

* FIX: move shutdown wait to OnExit

Change-Id: I70d9a2bb686525ae5273aa9d63e25691da4ab65c
Jira: STUDIO-2884

* FIX: calibration manage result dialog issue on macos

jira: STUDIO-4949 STUDIO-5378

Change-Id: I00abefd45a0d274a4b68bb1ab18debe8f91d169e

* FIX: adjust bed shape dialog button UI style

fix that button text is hard to see in dark mode
jira: STUDIO-5247

Change-Id: I2cf5b3cdd2eff9b821bdf5525bec4f329fc58dd1

* FIX: 5331 rescale btn

Jira: STUDIO-5331

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

* FIX: support do not generate

jira:[NEW]

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

* FIX: remove not match printer config ota cache

Change-Id: Ib73fc2ea31fa2186061cfcb5a170bc59b9db84ca
Jira: none

* FIX:cancel the variable of "checkbox_size"  as a fixed value

Jira: STUDIO-5150
Change-Id: I30d876d141b8b35ab4a3fee4889993d87b7c1741

* ENH:add reset_cut_by_contours in on_load function

Jira:STUDIO-5269
m_connector_size_tolerance default value is 0.1f

Change-Id: I6c67fff3cb0c1190e9141ed6f68fbfa848679f35

* ENH:cancel EnterReturnsTrue for imgui in cut

Jira: STUDIO-5269
Change-Id: Ifc4b183a4e4c4fdb4f47742f14f70a1ed93fa056
Signed-off-by: zhou.xu <zhou.xu@bambulab.com>

* FIX: dailytips should not change content frequently when slicing all

jira: STUDIO-5234

Change-Id: Icb7e9c28404d9db8ebed58d937e13f89c5403b5c

* FIX: objectList clone shortcut key issue

jira: new

Change-Id: Ia75bf58a7d53f962e1af6c2fd97497270b7eea84

* ENH:handling cases without msgs

jira:[STUDIO-5401 STUDIO-5399]

Change-Id: Iae651d5a19a45b0138a6aa621326a8b4a9649824

* ENH: optimize param description

jira:[NEW]

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

* ENH: add translation

jira:[NEW]

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

* FIX: close edit preset paramsDialog, mac unresponsive

Jira: 5298

Change-Id: I021e00567354cfb1f2f5f1f2bf6ba1fc35b164c5

* ENH:disable AI monitoring on the p1p series

Change-Id: I514bb1fb1ced6c03dd619230a9adac3be63f2de2

* ci: update build version to 01.08.01.52

Change-Id: I9f5e30d3fc4b7ef9321c522d3c18fce98f03742f

* FIX: close edit preset paramsDialog, mac unresponsive

Change-Id: Ic816754a20b7f6a5cdb46475750eb301fec3ad3a

* FIX: organic support not work with raft only

There is no raft generated when only raft enabled but no support needed.
jira: none

Change-Id: Ic0c9269e2f98038d85c9bc54e4a85f892dc5d764

* FIX: CLI: add object config when assemble

JIRA: no jira
Change-Id: I945f820fb58f2f643170b4b0b66742f6bbbdfd29

* FIX: delete preset prompt

Jira: XXXX

Change-Id: I6511c806c56393d4f6bd72d1c506da59675d49ff

* FIX:Reorganize the assignment of variables of "m_editing_window_width"

Jira: STUDIO-5238
Change-Id: If369916f3f5c21510f5f297bfd05c1230bdda7a4

* ENH: CLI: re-compute flush_volumes_matrix when it is missed

Change-Id: Ie8f53c6bef003b1434de02ea14de5787b376484f

* FIX: some translation for delete filament

Change-Id: Ib46a8eba33f2e21016476aaab4a57a740e86b1b8

* FIX: scrolled window / del preset / edit filament issue

Jira: 5092
GitHub: 1936
edit filament: just one preset, the scroll bar obscures the preset name
edit filament: delete selected preset, click no, but preset be deleted
from UI
edit filament: serial sometimes displays incorrectly

Change-Id: Ibc91609e252179de0c05ca065099756da6631165

* ci: update build version to 01.08.01.53

Change-Id: I5563a2c0812ab9a0d7727df27e17e681066ffa08

* FIX: mistake in filament vendor

jira:[NEW]

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

* NEW:set customized materials for the A1 P1 series

Change-Id: I9c34f62867c074bf9ebb315013e5e40526e0eac7

* ci: update build version to 01.08.01.54

Change-Id: I579dcee428417ae7e7f7a96bd315a7066d72d974

* FIX: the flow rate ratio crashes after load model

for third party printer
Jira: 5244

Change-Id: Idd829c9d99eeba9d180653ac8de4e51b9a0d6370

* FIX: The maximum value is not printed in PA line mode

Jira: 5046  4951
Change-Id: Ic81f9a75ce7f088fe950fdde283ff5c942cd6e83

* ENH:add preset check for sending files

Change-Id: Ia3313d281b5ce91e277b380498014ffdac5debd3

* ci: update build version to 01.08.01.55

Change-Id: Ia839344d01a43f7159f376d4147337575c4edbe1

* FIX: locale loading user preset

Change-Id: I88521e4b10cb802d9253eb79a6b78b3286f15a33
Jira: STUDIO-5436

* FIX: sync user preset notify crash on exit

Change-Id: I88f5dbcbd487293ea847ea6092efb61744399541
Jira: STUDIO-5413

* ci: update build version to 01.08.01.56

Change-Id: Id7a9718d5f920da50d52fd2ef220acf5d3270d3c

* GUI/Field: Fix crash in color picker init (#2220)

wxButton->GetBitmap() may return an invalid wxBitmap.
Guard against this.

* FIX: custom filament preset display in cali history issue

jira: new

Change-Id: I4145450a231adff542ab1a7428b3479f4074e06a

* FIX: meshboolean transform result issue

jira: STUDIO-5425

Change-Id: If66fe909ce4458c1b3192e4fd8a3d758fe7c7eaa

* FIX: fix combobox and delete btn in filament setting enabled

Jira: XXXX

Change-Id: I8b659bd77ceb97c8cea9d3e5e931f4ea50822721

* ci: update build version to 01.08.01.57

Change-Id: I7a6f5439863ca81275ae8b80f1b5cf0bb36c4c0f

* unix: Use canonical mime-type for 3MF files

model/3mf is the canonical mime-type, but keep the
application/vnd.ms-3mfdocument alias.

See for details:
https://gitlab.freedesktop.org/xdg/shared-mime-info/-/merge_requests/179

* FIX: fix the compiling issue under windows

github: https://github.com/bambulab/BambuStudio/issues/3028
Change-Id: Iafde9d2086c0cd31aa12e39cef7ded1e19e9d3e7

* add: K1 and K1Max Support

* fix: Optimized STL and PNG for plates K1 & K1Max

* fix: simple version of models

* FIX: Close scan_first_layer when PA line cali

Jira: XXXX
Change-Id: Ide5c0038f4028b8f1d445a6b2d09b705d7872fb8

* FIX: CLI: fix the wipe tower disappear issue

JIRA: no jira
Change-Id: I547a8468b0bea06912d5d9ceee1c8deead85e28f

* FIX: the preset is the same with the first one when switching printers

Jira: STUDIO-5433

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

* FIX: [5504] Optimization description

Jira: 5540

Change-Id: I9379f2c69b6724ec1ef5294dd3c404b0e3189486

* FIX: [5451]Directly crash when memory is low

Jira: 5451

Change-Id: I5c75994e2bd556bec7ce8de6be44888e6924ff56

* ci: update build version to 01.08.01.58

Change-Id: I12b1e3ca6b07ed13f3ad42ab2f40b825cb84a8dc

* ENH: CLI: refine some logic

1. set wipe tower position to default when duplicate object
2. add cli_safe check logic when switch printers

JIRA: no jira
Change-Id: Iebe62f8be6acd6f44743abf3b0fe92ec04c94197

* ENH: CLI: allow height shrink when printer switch

to let the error generated at validate
JIRA: no jira

Change-Id: I94db90db858659a9254dfdc0a6eed04fd40d3768

* ENH: add support for A1

jira:[NEW]

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

* ENH: refine description of interface not for base

jira:[NEW]

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

* ENH: version: bumped to 1.8.2

Change-Id: Ic9acb5607ec94188112999afa41f2052281a08f1

* ENH: update some machine settings

1. Update A1 mini start  gcode
2. Update A1 load/unload filament time

jira:[NEW]

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

* ENH: support for head wrap detect

1.Add "in_head_wrap_detect_zone".Detect if the model projection enters
a specified area.

jira:[NEW]

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

* ENH: modify default head detect zone

1. Set default head detect to empty

jira:[NEW]

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

* ENH: change head wrap detect zone

Change to (156,156)-(180,180)

jira:[new]

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

* FIX:backup iterator location

Jira: STUDIO-5267
Change-Id: Id035c9225a858bb551aa4f09870fc4c6bb30b255

* NEW:compatible with p1p (plus)

jira:[p1p]

Change-Id: I7b30903dc0a728604c4f33c325aa79fd3bd08f68

* NEW:installed & supported p1p(plus)

jira:[pip plus]

Change-Id: I0a69f8629749e3076465b85f28aa39d5e7ae6277

* ENH: modify default head wrap detect zone

jira:[NEW]

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

* FIX: excpetion when plate center is negative

jira:[NEW]

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

* FIX: big window's scaling causes incomplete display

Jira: STUDIO-5530
Change-Id: I1d69e60658e49e43d4b3de718f2fd6739bab73ce

* ENH: update: remove the comment which is not used when updating preset

JIRA: no jira
Change-Id: Ic930eea50a7beb78aa6dc7c53fbb5c366857e825
(cherry picked from commit e0225fc147702cf73e6eda4830a2592c7598901c)

* FIX: wrong initial layer height in profile

jira:[NEW]

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

* NEW:add N2S picture and printers

JIRA: XXXX
Change-Id: Id8eddd9fafd07c967abfb1543c1b01ad8c0e1b0c

* ENH: rearrange machine pos on printer selection page

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

* ci: update build version to 01.08.02.51

Change-Id: I1985730c4ea29528a6f9b03f56c73131a07779b0

* ENH: some translations

Jira: STUDIO-5434

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

* ENH: do not cancel printing job when timeout

JIRA: STUDIO-5009

Change-Id: I067470173acc26d7ecd8ceb6f0e04ac7f03e3a4d
Signed-off-by: Stone Li <stone.li@bambulab.com>
(cherry picked from commit 7ab5817c7229c5179adca026ffacb97c2affd292)

* ENH: udpate A1 series gcode

1. Update A1 mini change layer gcode
2. Update A1 start gcode

jira:[NEW]

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

* ENH:After cutting,fix non manifold edges needed confirmed by user

Jira: STUDIO-5217
Change-Id: I52ba0db27ebe0b7b763c49311c7aa305bc4dcd5a

* ENH: linux: refine the d-bus name

github: #3075
Change-Id: Icf997f4f9203f4d429e3b6058d6d6e5f23bf29ac
(cherry picked from commit 5c766bff445cefee488ba9d057121b04c8e1445d)

* NEW:add "bed type to follow machine preset" function

Jira: STUDIO-5535
Change-Id: I2ef99a0a783a074d9379685adde11fddfd6f8cec

* NEW:add "default_bed_type"

Jira: STUDIO-5535
Change-Id: Ice1262937923b62854b0196229d5fb99392470af

* ENH:comment out two line code

Jira: STUDIO-5535
Change-Id: I5475e4f9ec6fb7e4abdb3d950da34fadead3b606

* ENH:translate three texts

Jira: STUDIO-5535
Change-Id: I00938567f0ae30bb354042769021451364bef308

* FIX: incorrect flag in A1 mini gcode

jira:[NEW]

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

* ci: update build version to 01.08.02.52

Change-Id: I2d8310b7321fefcb742d4cdbe5e4bc9a035ec45a

* FIX: Allow vendors that are not entirely numerical

github: #3082

Change-Id: I318f4df7f65c934ab6703e0970d775b754b24276

* ENH: update A1 series first layer speed

jira:[NEW]

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

* FIX: CLI: fix the wipe tower issue while mapping to one filament

JIRA: STUDIO-5550
Change-Id: I0b8d3af09d16bdfc45cdc5951d182f7e33dc9b93

* FIX: crash when support type and style are inconsistent

jira: STUDIO-5428
Change-Id: Ib1e79c71736810099e15282c30524e55e8f60f34
(cherry picked from commit aefb7fbaf25146c03bd2eb336f58ed2eb0e83ea6)

* NEW:display beta version

JIRA: XXXX
Change-Id: I78d748e53b266c3397b1c038c3425a52c573cc88

* FIX: slice error: WipeTowerIntegration::append_tcr

when print by object with multi-color
Jira: XXXX

Change-Id: Ic9ee2f6de45abb4a118fdb4cf89dea9ca7335094

* ci: update build version to 01.08.02.53

Change-Id: I980bff783b59fc6e9d6fd12a016c2daa2840991f

* FIX: remove duplicated profiles

jira:[NEW]

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

* FIX: translation: vendor can not be number

Jira: XXXX

Change-Id: I7bd45de944e8b25b30c88ab742b35d996c933966

* ci: update build version to 01.08.02.54

Change-Id: Ib83b131c533a03d6e48e9ded5e6f9ba574819756

* ENH: update A1 extruder clearance radius

jira:[NEW]

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

* ci: update build version to 01.08.02.55

Change-Id: I8d7016d27166b457e4cdc198b61e6aa36a72b8c1

* FIX: bed_type not follow machine preset

Jira: STUDIO-5578
when direct open project from https://makerworld.com/

Change-Id: I3281cf45e3057d766008487975b4585d2e277110

* ci: update build version to 01.08.02.56

Change-Id: I43cadeeb1a2fa150fa9396a63b9bc471da1500d5

* update strings

* autofix mesh after cut

---------

Signed-off-by: Kunlong Ma <kunlong.ma@bambulab.com>
Signed-off-by: maosheng.wei <maosheng.wei@bambulab.com>
Signed-off-by: xun.zhang <xun.zhang@bambulab.com>
Signed-off-by: Stone Li <stone.li@bambulab.com>
Signed-off-by: wenjie.guo <wenjie.guo@bambulab.com>
Signed-off-by: zhou.xu <zhou.xu@bambulab.com>
Signed-off-by: qing.zhang <qing.zhang@bambulab.com>
Signed-off-by: XunZhangBambu <xun.zhang@bambulab.com>
Co-authored-by: chunmao.guo <chunmao.guo@bambulab.com>
Co-authored-by: zorro.zhang <zorro.zhang@bambulab.com>
Co-authored-by: hu.wang <hu.wang@bambulab.com>
Co-authored-by: liz.li <liz.li@bambulab.com>
Co-authored-by: Kunlong Ma <kunlong.ma@bambulab.com>
Co-authored-by: maosheng.wei <maosheng.wei@bambulab.com>
Co-authored-by: gerrit <gerrit@bambulab.com>
Co-authored-by: tao wang <tao.wang@bambulab.com>
Co-authored-by: zhou.xu <zhou.xu@bambulab.com>
Co-authored-by: xun.zhang <xun.zhang@bambulab.com>
Co-authored-by: the Raz <rasmus@abc.se>
Co-authored-by: Andy <andylg@yandex.ru>
Co-authored-by: lane.wei <lane.wei@bambulab.com>
Co-authored-by: Arthur <arthur.tang@bambulab.com>
Co-authored-by: Stone Li <stone.li@bambulab.com>
Co-authored-by: enricoturri1966 <enricoturri@seznam.cz>
Co-authored-by: wenjie.guo <wenjie.guo@bambulab.com>
Co-authored-by: zhimin.zeng <zhimin.zeng@bambulab.com>
Co-authored-by: Dmytro Chystiakov <dlchistyakov@gmail.com>
Co-authored-by: mia <652892+mia-0@users.noreply.github.com>
Co-authored-by: Bastien Nocera <hadess@hadess.net>
Co-authored-by: qing.zhang <qing.zhang@bambulab.com>
2023-12-19 23:46:19 +08:00

1997 lines
76 KiB
C++

// Include GLGizmoBase.hpp before I18N.hpp as it includes some libigl code, which overrides our localization "L" macro.
#include "GLGizmoAdvancedCut.hpp"
#include "slic3r/GUI/GLCanvas3D.hpp"
#include <GL/glew.h>
#include <wx/button.h>
#include <wx/checkbox.h>
#include <wx/stattext.h>
#include <wx/sizer.h>
#include <algorithm>
#include "slic3r/GUI/GUI_App.hpp"
#include "slic3r/GUI/Plater.hpp"
#include "libslic3r/AppConfig.hpp"
#include "../GUI/MsgDialog.hpp"
#include <imgui/imgui_internal.h>
#include "slic3r/GUI/CameraUtils.hpp"
namespace Slic3r {
namespace GUI {
const double units_in_to_mm = 25.4;
const double units_mm_to_in = 1 / units_in_to_mm;
const int c_connectors_group_id = 4;
const float UndefFloat = -999.f;
// connector colors
static const ColorRGBA PLAG_COLOR = ColorRGBA::YELLOW();
static const ColorRGBA DOWEL_COLOR = ColorRGBA::DARK_YELLOW();
static const ColorRGBA HOVERED_PLAG_COLOR = ColorRGBA::CYAN();
static const ColorRGBA HOVERED_DOWEL_COLOR = {0.0f, 0.5f, 0.5f, 1.0f};
static const ColorRGBA SELECTED_PLAG_COLOR = ColorRGBA::GRAY();
static const ColorRGBA SELECTED_DOWEL_COLOR = ColorRGBA::GRAY(); // DARK_GRAY();
static const ColorRGBA CONNECTOR_DEF_COLOR = {1.0f, 1.0f, 1.0f, 0.5f};
static const ColorRGBA CONNECTOR_ERR_COLOR = {1.0f, 0.3f, 0.3f, 0.5f};
static const ColorRGBA HOVERED_ERR_COLOR = {1.0f, 0.3f, 0.3f, 1.0f};
static Vec3d rotate_vec3d_around_vec3d_with_rotate_matrix(
const Vec3d& rotate_point,
const Vec3d& origin_point,
const Transform3d& rotate_matrix)
{
Transform3d translate_to_point = Transform3d::Identity();
translate_to_point.translate(origin_point);
Transform3d translate_to_zero = Transform3d::Identity();
translate_to_zero.translate(-origin_point);
return (translate_to_point * rotate_matrix * translate_to_zero) * rotate_point;
}
static inline void rotate_point_2d(double& x, double& y, const double c, const double s)
{
double xold = x;
double yold = y;
x = c * xold - s * yold;
y = s * xold + c * yold;
}
static void rotate_x_3d(std::array<Vec3d, 4>& verts, float radian_angle)
{
double c = cos(radian_angle);
double s = sin(radian_angle);
for (uint32_t i = 0; i < verts.size(); ++i)
rotate_point_2d(verts[i](1), verts[i](2), c, s);
}
static void rotate_y_3d(std::array<Vec3d, 4>& verts, float radian_angle)
{
double c = cos(radian_angle);
double s = sin(radian_angle);
for (uint32_t i = 0; i < verts.size(); ++i)
rotate_point_2d(verts[i](2), verts[i](0), c, s);
}
static void rotate_z_3d(std::array<Vec3d, 4>& verts, float radian_angle)
{
double c = cos(radian_angle);
double s = sin(radian_angle);
for (uint32_t i = 0; i < verts.size(); ++i)
rotate_point_2d(verts[i](0), verts[i](1), c, s);
}
const double GLGizmoAdvancedCut::Offset = 10.0;
const double GLGizmoAdvancedCut::Margin = 20.0;
const ColorRGBA GLGizmoAdvancedCut::GrabberColor = { 1.0f, 1.0f, 0.0f, 1.0f };
const ColorRGBA GLGizmoAdvancedCut::GrabberHoverColor = { 0.7f, 0.7f, 0.0f, 1.0f };
GLGizmoAdvancedCut::GLGizmoAdvancedCut(GLCanvas3D& parent, const std::string& icon_filename, unsigned int sprite_id)
: GLGizmoRotate3D(parent, icon_filename, sprite_id, nullptr)
, m_movement(0.0)
, m_buffered_movement(0.0)
, m_last_active_id(0)
, m_keep_upper(true)
, m_keep_lower(true)
, m_cut_to_parts(false)
, m_do_segment(false)
, m_segment_smoothing_alpha(0.5)
, m_segment_number(5)
, m_connector_type(CutConnectorType::Plug)
, m_connector_style(size_t(CutConnectorStyle::Prizm))
, m_connector_shape_id(size_t(CutConnectorShape::Circle))
{
for (int i = 0; i < 4; i++)
m_cut_plane_points[i] = { 0., 0., 0. };
m_group_id = (m_gizmos.size());
m_rotation.setZero();
//m_current_base_rotation.setZero();
m_rotate_cmds.clear();
m_buffered_rotation.setZero();
}
void GLGizmoAdvancedCut::data_changed(bool is_serializing)
{
GLGizmoRotate3D::data_changed(is_serializing);
finish_rotation();
}
bool GLGizmoAdvancedCut::gizmo_event(SLAGizmoEventType action, const Vec2d &mouse_position, bool shift_down, bool alt_down, bool control_down)
{
CutConnectors &connectors = m_c->selection_info()->model_object()->cut_connectors;
if (shift_down && !m_connectors_editing &&
(action == SLAGizmoEventType::LeftDown || action == SLAGizmoEventType::LeftUp || action == SLAGizmoEventType::Dragging)) {
process_cut_line(action, mouse_position);
return true;
}
if (action == SLAGizmoEventType::LeftDown) {
if (!m_connectors_editing)
return false;
if (m_hover_id != -1) {
//start_dragging();
return true;
}
if (shift_down || alt_down) {
// left down with shift - show the selection rectangle:
//if (m_hover_id == -1)
// m_selection_rectangle.start_dragging(mouse_position, shift_down ? GLSelectionRectangle::EState::Select : GLSelectionRectangle::EState::Deselect);
} else {
// If there is no selection and no hovering, add new point
if (m_hover_id == -1 && !shift_down && !alt_down)
add_connector(connectors, mouse_position);
//m_ldown_mouse_position = mouse_position;
}
return true;
}
else if (action == SLAGizmoEventType::LeftUp) {
if (m_hover_id == -1 && !shift_down && !alt_down)
unselect_all_connectors();
is_selection_changed(alt_down, shift_down);
return true;
}
else if (action == SLAGizmoEventType::RightDown) {
if (m_hover_id < c_connectors_group_id)
return false;
unselect_all_connectors();
select_connector(m_hover_id - c_connectors_group_id, true);
return delete_selected_connectors();
}
else if (action == SLAGizmoEventType::RightUp) {
// catch right click event
return true;
}
return false;
}
bool GLGizmoAdvancedCut::on_key(wxKeyEvent &evt)
{
bool ctrl_down = evt.GetModifiers() & wxMOD_CONTROL;
if (evt.GetKeyCode() == WXK_DELETE) {
return delete_selected_connectors();
}
else if (ctrl_down
&& (evt.GetKeyCode() == 'A' || evt.GetKeyCode() == 'a'))
{
select_all_connectors();
return true;
}
return false;
}
std::string GLGizmoAdvancedCut::get_tooltip() const
{
return "";
}
BoundingBoxf3 GLGizmoAdvancedCut::bounding_box() const
{
BoundingBoxf3 ret;
const Selection & selection = m_parent.get_selection();
const Selection::IndicesList &idxs = selection.get_volume_idxs();
for (unsigned int i : idxs) {
const GLVolume *volume = selection.get_volume(i);
// respect just to the solid parts for FFF and ignore pad and supports for SLA
if (!volume->is_modifier && !volume->is_sla_pad() && !volume->is_sla_support()) ret.merge(volume->transformed_convex_hull_bounding_box());
}
return ret;
}
bool GLGizmoAdvancedCut::is_looking_forward() const
{
const Camera &camera = wxGetApp().plater()->get_camera();
const double dot = camera.get_dir_forward().dot(m_cut_plane_normal);
return dot < 0.05;
}
// Unprojects the mouse position on the mesh and saves hit point and normal of the facet into pos_and_normal
// Return false if no intersection was found, true otherwise.
bool GLGizmoAdvancedCut::unproject_on_cut_plane(const Vec2d &mouse_pos, Vec3d &pos, Vec3d &pos_world)
{
const float sla_shift = m_c->selection_info()->get_sla_shift();
const ModelObject * mo = m_c->selection_info()->model_object();
const ModelInstance *mi = mo->instances[m_c->selection_info()->get_active_instance()];
const Camera & camera = wxGetApp().plater()->get_camera();
// Calculate intersection with the clipping plane.
const ClippingPlane *cp = m_c->object_clipper()->get_clipping_plane();
Vec3d point;
Vec3d direction;
Vec3d hit;
CameraUtils::ray_from_screen_pos(camera, mouse_pos, point, direction);
Vec3d normal = -cp->get_normal().cast<double>();
double den = normal.dot(direction);
if (den != 0.) {
double t = (-cp->get_offset() - normal.dot(point)) / den;
hit = (point + t * direction);
} else
return false;
if (!m_c->object_clipper()->is_projection_inside_cut(hit))
return false;
// recalculate hit to object's local position
Vec3d hit_d = hit;
hit_d -= mi->get_offset();
hit_d[Z] -= sla_shift;
// Return both the point and the facet normal.
pos = hit_d;
pos_world = hit;
return true;
}
void GLGizmoAdvancedCut::update_plane_points()
{
Vec3d plane_center = get_plane_center();
std::array<Vec3d, 4> plane_points_rot;
for (int i = 0; i < plane_points_rot.size(); i++) {
plane_points_rot[i] = m_cut_plane_points[i] - plane_center;
}
if (m_rotation(0) > EPSILON) {
rotate_x_3d(plane_points_rot, m_rotation(0));
m_rotate_cmds.emplace(m_rotate_cmds.begin(), m_rotation(0), X);
}
if (m_rotation(1) > EPSILON) {
rotate_y_3d(plane_points_rot, m_rotation(1));
m_rotate_cmds.emplace(m_rotate_cmds.begin(), m_rotation(1), Y);
}
if (m_rotation(2) > EPSILON) {
rotate_z_3d(plane_points_rot, m_rotation(2));
m_rotate_cmds.emplace(m_rotate_cmds.begin(), m_rotation(2), Z);
}
Vec3d plane_normal = calc_plane_normal(plane_points_rot);
if (m_movement == 0 && m_height_delta != 0)
m_movement = plane_normal(2) * m_height_delta;// plane_normal.dot(Vec3d(0, 0, m_height_delta))
for (int i = 0; i < plane_points_rot.size(); i++) {
m_cut_plane_points[i] = plane_points_rot[i] + plane_center + plane_normal * m_movement;
}
//m_current_base_rotation += m_rotation;
m_rotation.setZero();
m_movement = 0.0;
m_height_delta = 0;
}
std::array<Vec3d, 4> GLGizmoAdvancedCut::get_plane_points() const
{
return m_cut_plane_points;
}
std::array<Vec3d, 4> GLGizmoAdvancedCut::get_plane_points_world_coord() const
{
std::array<Vec3d, 4> plane_world_coord = m_cut_plane_points;
const Selection& selection = m_parent.get_selection();
const BoundingBoxf3& box = selection.get_bounding_box();
Vec3d object_offset = box.center();
for (Vec3d& point : plane_world_coord) {
point += object_offset;
}
return plane_world_coord;
}
void GLGizmoAdvancedCut::reset_cut_plane()
{
const Selection& selection = m_parent.get_selection();
const BoundingBoxf3& box = selection.get_bounding_box();
const float max_x = box.size()(0) / 2.0 + Margin;
const float min_x = -max_x;
const float max_y = box.size()(1) / 2.0 + Margin;
const float min_y = -max_y;
m_cut_plane_points[0] = { min_x, min_y, 0 };
m_cut_plane_points[1] = { max_x, min_y, 0 };
m_cut_plane_points[2] = { max_x, max_y, 0 };
m_cut_plane_points[3] = { min_x, max_y, 0 };
m_movement = 0.0;
m_height = box.size()[2] / 2.0;
m_height_delta = 0;
m_rotation.setZero();
//m_current_base_rotation.setZero();
m_rotate_cmds.clear();
m_buffered_movement = 0.0;
m_buffered_height = m_height;
m_buffered_rotation.setZero();
}
void GLGizmoAdvancedCut::reset_all()
{
reset_cut_plane();
m_keep_upper = true;
m_keep_lower = true;
m_cut_to_parts = false;
m_place_on_cut_upper = true;
m_place_on_cut_lower = false;
m_rotate_upper = false;
m_rotate_lower = false;
}
bool GLGizmoAdvancedCut::on_init()
{
if (!GLGizmoRotate3D::on_init())
return false;
m_shortcut_key = WXK_CONTROL_C;
// initiate info shortcuts
const wxString ctrl = GUI::shortkey_ctrl_prefix();
const wxString alt = GUI::shortkey_alt_prefix();
const wxString shift = "Shift+";
m_shortcuts.push_back(std::make_pair(_L("Left click"), _L("Add connector")));
m_shortcuts.push_back(std::make_pair(_L("Right click"), _L("Remove connector")));
m_shortcuts.push_back(std::make_pair(_L("Drag"), _L("Move connector")));
m_shortcuts.push_back(std::make_pair(shift + _L("Left click"), _L("Add connector to selection")));
m_shortcuts.push_back(std::make_pair(alt + _L("Left click"), _L("Remove connector from selection")));
m_shortcuts.push_back(std::make_pair(ctrl + "A", _L("Select all connectors")));
init_connector_shapes();
return true;
}
std::string GLGizmoAdvancedCut::on_get_name() const
{
return (_(L("Cut"))).ToUTF8().data();
}
void GLGizmoAdvancedCut::on_load(cereal::BinaryInputArchive &ar)
{
ar(m_keep_upper, m_keep_lower, m_rotate_lower, m_rotate_upper, m_connectors_editing,
m_cut_plane_points[0], m_cut_plane_points[1], m_cut_plane_points[2], m_cut_plane_points[3]);
m_parent.request_extra_frame();
}
void GLGizmoAdvancedCut::on_save(cereal::BinaryOutputArchive &ar) const
{
ar(m_keep_upper, m_keep_lower, m_rotate_lower, m_rotate_upper, m_connectors_editing,
m_cut_plane_points[0], m_cut_plane_points[1], m_cut_plane_points[2], m_cut_plane_points[3]);
}
void GLGizmoAdvancedCut::on_set_state()
{
GLGizmoRotate3D::on_set_state();
// Reset m_cut_z on gizmo activation
if (get_state() == On) {
m_connectors_editing = false;
reset_cut_plane();
}
else if (get_state() == Off) {
clear_selection();
m_c->object_clipper()->release();
}
}
bool GLGizmoAdvancedCut::on_is_activable() const
{
const Selection& selection = m_parent.get_selection();
return selection.is_single_full_instance() && !selection.is_wipe_tower();
}
CommonGizmosDataID GLGizmoAdvancedCut::on_get_requirements() const
{
return CommonGizmosDataID(int(CommonGizmosDataID::SelectionInfo)
| int(CommonGizmosDataID::InstancesHider)
| int(CommonGizmosDataID::Raycaster)
| int(CommonGizmosDataID::ObjectClipper));
}
void GLGizmoAdvancedCut::on_start_dragging()
{
if (m_hover_id == X || m_hover_id == Y || m_hover_id == Z) {
m_gizmos[m_hover_id].start_dragging();
} else if (m_hover_id == c_connectors_group_id - 1) {
const Selection& selection = m_parent.get_selection();
const BoundingBoxf3& box = selection.get_bounding_box();
m_start_movement = m_movement;
m_start_height = m_height;
m_drag_pos = m_move_grabber.center;
}
}
void GLGizmoAdvancedCut::on_stop_dragging()
{
if (m_hover_id == X || m_hover_id == Y || m_hover_id == Z) {
m_gizmos[m_hover_id].stop_dragging();
Plater::TakeSnapshot snapshot(wxGetApp().plater(), "Rotate cut plane");
} else if (m_hover_id == c_connectors_group_id - 1) {
Plater::TakeSnapshot snapshot(wxGetApp().plater(), "Move cut plane");
} else if (m_hover_id >= c_connectors_group_id) {
Plater::TakeSnapshot snapshot(wxGetApp().plater(), "Move connector");
}
}
void GLGizmoAdvancedCut::on_dragging(const UpdateData &data)
{
GLGizmoRotate3D::on_dragging(data);
Vec3d rotation;
for (int i = 0; i < 3; i++)
{
rotation(i) = m_gizmos[i].get_angle();
if (rotation(i) < 0)
rotation(i) = 2*PI + rotation(i);
}
m_rotation = rotation;
//m_move_grabber.angles = m_current_base_rotation + m_rotation;
if (m_hover_id == m_group_id) {
double move = calc_projection(data.mouse_ray);
set_movement(m_start_movement + move);
Vec3d plane_normal = get_plane_normal();
m_height = m_start_height + plane_normal(2) * move;
}
// dragging connectors
if (m_connectors_editing && m_hover_id >= c_connectors_group_id) {
CutConnectors &connectors = m_c->selection_info()->model_object()->cut_connectors;
Vec3d pos;
Vec3d pos_world;
if (unproject_on_cut_plane(data.mouse_pos.cast<double>(), pos, pos_world)) {
connectors[m_hover_id - c_connectors_group_id].pos = pos;
}
}
}
void GLGizmoAdvancedCut::on_render()
{
update_clipper();
if (m_connectors_editing) {
render_connectors();
}
// render_clipper_cut for get the cut plane result
render_clipper_cut();
if(!m_connectors_editing) {
check_conflict_for_all_connectors();
render_cut_plane_and_grabbers();
}
render_cut_line();
}
/*
void GLGizmoAdvancedCut::on_render_for_picking()
{
GLGizmoRotate3D::on_render_for_picking();
glsafe(::glDisable(GL_DEPTH_TEST));
BoundingBoxf3 box = m_parent.get_selection().get_bounding_box();
#if ENABLE_FIXED_GRABBER
float mean_size = (float)(GLGizmoBase::Grabber::FixedGrabberSize);
#else
float mean_size = (float)((box.size().x() + box.size().y() + box.size().z()) / 3.0);
#endif
m_move_grabber.color = picking_color_component(0);
GLShaderProgram *shader = wxGetApp().get_shader("flat");
if (shader != nullptr) {
shader->start_using();
const Camera &camera = wxGetApp().plater()->get_camera();
shader->set_uniform("view_model_matrix", camera.get_view_matrix());
shader->set_uniform("projection_matrix", camera.get_projection_matrix());
m_move_grabber.render_for_picking(mean_size);
shader->stop_using();
}
glsafe(::glEnable(GL_DEPTH_TEST));
auto inst_id = m_c->selection_info()->get_active_instance();
if (inst_id < 0)
return;
const ModelObject *mo = m_c->selection_info()->model_object();
const ModelInstance *mi = mo->instances[inst_id];
const Vec3d & instance_offset = mi->get_offset();
const double sla_shift = double(m_c->selection_info()->get_sla_shift());
const CutConnectors &connectors = mo->cut_connectors;
for (int i = 0; i < connectors.size(); ++i) {
CutConnector connector = connectors[i];
Vec3d pos = connector.pos + instance_offset + sla_shift * Vec3d::UnitZ();
float height = connector.height;
if (connector.attribs.type == CutConnectorType::Dowel && connector.attribs.style == CutConnectorStyle::Prizm) {
pos -= height * m_cut_plane_normal;
height *= 2;
} else if (!is_looking_forward())
pos -= 0.05 * m_cut_plane_normal;
Transform3d translate_tf = Transform3d::Identity();
translate_tf.translate(pos);
Transform3d scale_tf = Transform3d::Identity();
scale_tf.scale(Vec3f(connector.radius, connector.radius, height).cast<double>());
const Transform3d model_matrix = translate_tf * m_rotate_matrix * scale_tf;
ColorRGBA color = picking_color_component(i+1);
render_connector_model(m_shapes[connectors[i].attribs], color, model_matrix, true);
}
}
*/
void GLGizmoAdvancedCut::on_render_input_window(float x, float y, float bottom_limit)
{
GizmoImguiSetNextWIndowPos(x, y, ImGuiCond_Always, 0.0f, 0.0f);
ImGuiWrapper::push_toolbar_style(m_parent.get_scale());
GizmoImguiBegin(on_get_name(),
ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoTitleBar);
if (m_connectors_editing) {
init_connectors_input_window_data();
render_connectors_input_window(x, y, bottom_limit);
}
else
render_cut_plane_input_window(x, y, bottom_limit);
render_input_window_warning();
GizmoImguiEnd();
ImGuiWrapper::pop_toolbar_style();
}
void GLGizmoAdvancedCut::show_tooltip_information(float x, float y)
{
float caption_max = 0.f;
for (const auto& short_cut : m_shortcuts) {
caption_max = std::max(caption_max, m_imgui->calc_text_size(short_cut.first).x);
}
ImTextureID normal_id = m_parent.get_gizmos_manager().get_icon_texture_id(GLGizmosManager::MENU_ICON_NAME::IC_TOOLBAR_TOOLTIP);
ImTextureID hover_id = m_parent.get_gizmos_manager().get_icon_texture_id(GLGizmosManager::MENU_ICON_NAME::IC_TOOLBAR_TOOLTIP_HOVER);
caption_max += m_imgui->calc_text_size(": ").x + 35.f;
float font_size = ImGui::GetFontSize();
ImVec2 button_size = ImVec2(font_size * 1.8, font_size * 1.3);
ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 0.0f);
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, {0, ImGui::GetStyle().FramePadding.y});
ImGui::ImageButton3(normal_id, hover_id, button_size);
if (ImGui::IsItemHovered()) {
ImGui::BeginTooltip2(ImVec2(x, y));
auto draw_text_with_caption = [this, &caption_max](const wxString &caption, const wxString &text) {
m_imgui->text_colored(ImGuiWrapper::COL_ACTIVE, caption);
ImGui::SameLine(caption_max);
m_imgui->text_colored(ImGuiWrapper::COL_WINDOW_BG, text);
};
for (const auto& short_cut : m_shortcuts)
draw_text_with_caption(short_cut.first + ": ", short_cut.second);
ImGui::EndTooltip();
}
ImGui::PopStyleVar(2);
}
void GLGizmoAdvancedCut::set_movement(double movement) const
{
m_movement = movement;
}
void GLGizmoAdvancedCut::perform_cut(const Selection& selection)
{
if (!can_perform_cut())
return;
const int instance_idx = selection.get_instance_idx();
const int object_idx = selection.get_object_idx();
wxCHECK_RET(instance_idx >= 0 && object_idx >= 0, "GLGizmoAdvancedCut: Invalid object selection");
// m_cut_z is the distance from the bed. Subtract possible SLA elevation.
const GLVolume* first_glvolume = selection.get_first_volume();
// perform cut
{
Plater::TakeSnapshot snapshot(wxGetApp().plater(), "Cut by Plane");
ModelObject *mo = wxGetApp().plater()->model().objects[object_idx];
const bool has_connectors = !mo->cut_connectors.empty();
bool create_dowels_as_separate_object = false;
// update connectors pos as offset of its center before cut performing
apply_connectors_in_model(mo, create_dowels_as_separate_object);
apply_connectors_in_model(cut_mo, dowels_count);
wxBusyCursor wait;
ModelObjectCutAttributes attributes = only_if(has_connectors ? true : m_keep_upper, ModelObjectCutAttribute::KeepUpper) |
only_if(has_connectors ? true : m_keep_lower, ModelObjectCutAttribute::KeepLower) |
only_if(has_connectors ? false : m_cut_to_parts, ModelObjectCutAttribute::CutToParts) |
only_if(m_place_on_cut_upper, ModelObjectCutAttribute::PlaceOnCutUpper) |
only_if(m_place_on_cut_lower, ModelObjectCutAttribute::PlaceOnCutLower) |
only_if(m_rotate_upper, ModelObjectCutAttribute::FlipUpper) | only_if(m_rotate_lower, ModelObjectCutAttribute::FlipLower) |
only_if(dowels_count > 0, ModelObjectCutAttribute::CreateDowels) |
only_if(!has_connectors && !cut_with_groove && cut_mo->cut_id.id().invalid(), ModelObjectCutAttribute::InvalidateCutInfo);
// update cut_id for the cut object in respect to the attributes
update_object_cut_id(cut_mo->cut_id, attributes, dowels_count);
Cut cut(cut_mo, instance_idx, get_cut_matrix(selection), attributes);
cut.set_offset_for_two_part = true;
const ModelObjectPtrs &new_objects = cut_by_contour ? cut.perform_by_contour(m_part_selection->get_cut_parts(), dowels_count) :
cut_with_groove ? cut.perform_with_groove(m_groove, m_rotate_matrix) :
cut.perform_with_plane();
// fix_non_manifold_edges
#ifdef HAS_WIN10SDK
if (is_windows10()) {
bool is_showed_dialog = false;
bool user_fix_model = false;
for (size_t i = 0; i < new_objects.size(); i++) {
for (size_t j = 0; j < new_objects[i]->volumes.size(); j++) {
if (its_num_open_edges(new_objects[i]->volumes[j]->mesh().its) > 0) {
if (!is_showed_dialog) {
is_showed_dialog = true;
MessageDialog dlg(nullptr, _L("non-mainifold edges be caused by cut tool, do you want to fix it now?"), "", wxYES | wxCANCEL);
int ret = dlg.ShowModal();
if (ret == wxID_YES) {
user_fix_model = true;
}
}
if (!user_fix_model) {
break;
}
// model_name
std::vector<std::string> succes_models;
// model_name failing reason
std::vector<std::pair<std::string, std::string>> failed_models;
auto plater = wxGetApp().plater();
auto fix_and_update_progress = [this, plater](ModelObject *model_object, const int vol_idx, const string &model_name, ProgressDialog &progress_dlg,
std::vector<std::string> &succes_models, std::vector<std::pair<std::string, std::string>> &failed_models) {
wxString msg = _L("Repairing model object");
msg += ": " + from_u8(model_name) + "\n";
std::string res;
if (!fix_model_by_win10_sdk_gui(*model_object, vol_idx, progress_dlg, msg, res)) return false;
return true;
};
ProgressDialog progress_dlg(_L("Repairing model object"), "", 100, find_toplevel_parent(plater), wxPD_AUTO_HIDE | wxPD_APP_MODAL | wxPD_CAN_ABORT, true);
auto model_name = new_objects[i]->name;
if (!fix_and_update_progress(new_objects[i], j, model_name, progress_dlg, succes_models, failed_models)) {
BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << "run fix_and_update_progress error";
};
};
}
}
}
#endif
// set offset for new_objects
// save cut_id to post update synchronization
const CutObjectBase cut_id = cut_mo->cut_id;
// update cut results on plater and in the model
plater->apply_cut_object_to_model(object_idx, new_objects);
}
}
}
bool GLGizmoAdvancedCut::can_perform_cut() const
{
if (m_has_invalid_connector || (!m_keep_upper && !m_keep_lower) || m_connectors_editing)
return false;
return true;
//const auto clipper = m_c->object_clipper();
//return clipper && clipper->has_valid_contour();
}
void GLGizmoAdvancedCut::apply_connectors_in_model(ModelObject *mo, bool &create_dowels_as_separate_object)
{
clear_selection();
for (CutConnector &connector : mo->cut_connectors) {
connector.rotation_m = m_rotate_matrix;
if (connector.attribs.type == CutConnectorType::Dowel) {
if (connector.attribs.style == CutConnectorStyle::Prizm) connector.height *= 2;
create_dowels_as_separate_object = true;
} else {
// culculate shift of the connector center regarding to the position on the cut plane
Vec3d shifted_center = m_cut_plane_center + Vec3d::UnitZ();
shifted_center = rotate_vec3d_around_vec3d_with_rotate_matrix(shifted_center, m_cut_plane_center, m_rotate_matrix);
Vec3d norm = (shifted_center - m_cut_plane_center).normalized();
connector.pos += norm * 0.5 * double(connector.height);
}
}
mo->apply_cut_connectors(_u8L("Connector"));
}
bool GLGizmoAdvancedCut::is_selection_changed(bool alt_down, bool shift_down)
{
if (m_hover_id >= c_connectors_group_id) {
if (alt_down)
select_connector(m_hover_id - c_connectors_group_id, false);
else {
if (!shift_down) unselect_all_connectors();
select_connector(m_hover_id - c_connectors_group_id, true);
}
return true;
}
return false;
}
void GLGizmoAdvancedCut::select_connector(int idx, bool select)
{
m_selected[idx] = select;
if (select)
++m_selected_count;
else
--m_selected_count;
}
Vec3d GLGizmoAdvancedCut::calc_plane_normal(const std::array<Vec3d, 4>& plane_points) const
{
Vec3d v01 = plane_points[1] - plane_points[0];
Vec3d v12 = plane_points[2] - plane_points[1];
Vec3d plane_normal = v01.cross(v12);
plane_normal.normalize();
return plane_normal;
}
Vec3d GLGizmoAdvancedCut::calc_plane_center(const std::array<Vec3d, 4>& plane_points) const
{
Vec3d plane_center;
plane_center.setZero();
for (const Vec3d& point : plane_points)
plane_center = plane_center + point;
return plane_center / (float)m_cut_plane_points.size();
}
double GLGizmoAdvancedCut::calc_projection(const Linef3& mouse_ray) const
{
Vec3d mouse_dir = mouse_ray.unit_vector();
Vec3d inters = mouse_ray.a + (m_drag_pos - mouse_ray.a).dot(mouse_dir) / mouse_dir.squaredNorm() * mouse_dir;
Vec3d inters_vec = inters - m_drag_pos;
Vec3d plane_normal = get_plane_normal();
return inters_vec.dot(plane_normal);
}
Vec3d GLGizmoAdvancedCut::get_plane_normal() const
{
return calc_plane_normal(m_cut_plane_points);
}
Vec3d GLGizmoAdvancedCut::get_plane_center() const
{
return calc_plane_center(m_cut_plane_points);
}
void GLGizmoAdvancedCut::finish_rotation()
{
for (int i = 0; i < 3; i++) {
m_gizmos[i].set_angle(0.);
}
update_plane_points();
}
void GLGizmoAdvancedCut::put_connectors_on_cut_plane(const Vec3d &cp_normal, double cp_offset)
{
ModelObject *mo = m_c->selection_info()->model_object();
if (CutConnectors &connectors = mo->cut_connectors; !connectors.empty()) {
const float sla_shift = m_c->selection_info()->get_sla_shift();
const Vec3d &instance_offset = mo->instances[m_c->selection_info()->get_active_instance()]->get_offset();
for (auto &connector : connectors) {
// convert connetor pos to the world coordinates
Vec3d pos = connector.pos + instance_offset;
pos[Z] += sla_shift;
// scalar distance from point to plane along the normal
double distance = -cp_normal.dot(pos) + cp_offset;
// move connector
connector.pos += distance * cp_normal;
}
}
}
void GLGizmoAdvancedCut::update_clipper()
{
BoundingBoxf3 box = bounding_box();
double radius = box.radius();
Vec3d plane_center = m_cut_plane_center;
Vec3d begin, end = begin = plane_center;
begin[Z] = box.center().z() - radius;
end[Z] = box.center().z() + radius;
double phi;
Vec3d rotation_axis;
Matrix3d rotation_matrix;
Geometry::rotation_from_two_vectors(Vec3d::UnitZ(), m_cut_plane_normal, rotation_axis, phi, &rotation_matrix);
m_rotate_matrix.setIdentity();
m_rotate_matrix = rotation_matrix * m_rotate_matrix;
begin = rotate_vec3d_around_vec3d_with_rotate_matrix(begin, plane_center, m_rotate_matrix);
end = rotate_vec3d_around_vec3d_with_rotate_matrix(end, plane_center, m_rotate_matrix);
Vec3d normal = end - begin;
if (!is_looking_forward()) {
end = begin = plane_center;
begin[Z] = box.center().z() + radius;
end[Z] = box.center().z() - radius;
begin = rotate_vec3d_around_vec3d_with_rotate_matrix(begin, plane_center, m_rotate_matrix);
end = rotate_vec3d_around_vec3d_with_rotate_matrix(end, plane_center, m_rotate_matrix);
// recalculate normal for clipping plane, if camera is looking downward to cut plane
normal = end - begin;
if (normal == Vec3d::Zero())
return;
}
// calculate normal and offset for clipping plane
double dist = (plane_center - begin).norm();
dist = std::clamp(dist, 0.0001, normal.norm());
normal.normalize();
const double offset = normal.dot(begin) + dist;
m_c->object_clipper()->set_range_and_pos(normal, offset, dist);
put_connectors_on_cut_plane(normal, offset);
}
void GLGizmoAdvancedCut::render_cut_plane_and_grabbers()
{
const Selection & selection = m_parent.get_selection();
const BoundingBoxf3 &box = selection.get_bounding_box();
// box center is the coord of object in the world coordinate
Vec3d object_offset = box.center();
// plane points is in object coordinate
Vec3d plane_center = get_plane_center();
m_cut_plane_center = object_offset + plane_center;
// rotate plane
std::array<Vec3d, 4> plane_points_rot;
{
for (int i = 0; i < plane_points_rot.size(); i++) {
plane_points_rot[i] = m_cut_plane_points[i] - plane_center;
}
if (m_rotation(0) > EPSILON)
rotate_x_3d(plane_points_rot, m_rotation(0));
if (m_rotation(1) > EPSILON)
rotate_y_3d(plane_points_rot, m_rotation(1));
if (m_rotation(2) > EPSILON)
rotate_z_3d(plane_points_rot, m_rotation(2));
for (int i = 0; i < plane_points_rot.size(); i++) {
plane_points_rot[i] += plane_center;
}
}
// move plane
Vec3d plane_normal_rot = calc_plane_normal(plane_points_rot);
m_cut_plane_normal = plane_normal_rot;
for (int i = 0; i < plane_points_rot.size(); i++) {
plane_points_rot[i] += plane_normal_rot * m_movement;
}
// transfer from object coordindate to the world coordinate
for (Vec3d& point : plane_points_rot) {
point += object_offset;
}
glsafe(::glEnable(GL_DEPTH_TEST));
glsafe(::glDisable(GL_CULL_FACE));
glsafe(::glEnable(GL_BLEND));
glsafe(::glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA));
GLShaderProgram *shader = wxGetApp().get_shader("flat");
if (shader != nullptr) {
shader->start_using();
// draw plane
{
m_plane.reset();
GLModel::Geometry init_data;
init_data.format = { GLModel::Geometry::EPrimitiveType::Triangles, GLModel::Geometry::EVertexLayout::P3 };
init_data.color = { 0.8f, 0.8f, 0.8f, 0.5f };
init_data.reserve_vertices(4);
init_data.reserve_vertices(6);
// vertices
for (const Vec3d &point : plane_points_rot) {
init_data.add_vertex((Vec3f)point.cast<float>());
}
// indices
init_data.add_triangle(0, 1, 2);
init_data.add_triangle(2, 3, 0);
m_plane.init_from(std::move(init_data));
}
const Camera &camera = wxGetApp().plater()->get_camera();
shader->set_uniform("view_model_matrix", camera.get_view_matrix());
shader->set_uniform("projection_matrix", camera.get_projection_matrix());
m_plane.render();
glsafe(::glEnable(GL_CULL_FACE));
glsafe(::glDisable(GL_BLEND));
// Draw the grabber and the connecting line
Vec3d plane_center_rot = calc_plane_center(plane_points_rot);
m_move_grabber.center = plane_center_rot + plane_normal_rot * Offset;
// m_move_grabber.angles = m_current_base_rotation + m_rotation;
{
m_grabber_connection.reset();
GLModel::Geometry init_data;
init_data.format = { GLModel::Geometry::EPrimitiveType::Lines, GLModel::Geometry::EVertexLayout::P3 };
init_data.color = ColorRGBA::YELLOW();
init_data.reserve_vertices(2);
init_data.reserve_vertices(2);
// vertices
init_data.add_vertex((Vec3f)plane_center_rot.cast<float>());
init_data.add_vertex((Vec3f)m_move_grabber.center.cast<float>());
// indices
init_data.add_line(0, 1);
m_grabber_connection.init_from(std::move(init_data));
}
glsafe(::glDisable(GL_DEPTH_TEST));
glsafe(::glLineWidth(m_hover_id != -1 ? 2.0f : 1.5f));
glLineStipple(1, 0x0FFF);
glEnable(GL_LINE_STIPPLE);
m_grabber_connection.render();
glDisable(GL_LINE_STIPPLE);
shader->stop_using();
}
{
GLShaderProgram *shader = wxGetApp().get_shader("gouraud_light");
if (shader == nullptr)
return;
shader->start_using();
shader->set_uniform("emission_factor", 0.1f);
// std::copy(std::begin(GrabberColor), std::end(GrabberColor), m_move_grabber.color);
// m_move_grabber.color = GrabberColor;
// m_move_grabber.hover_color = GrabberHoverColor;
// m_move_grabber.render(m_hover_id == get_group_id(), (float)((box.size()(0) + box.size()(1) + box.size()(2)) / 3.0));
bool hover = (m_hover_id == m_group_id);
ColorRGBA render_color;
if (hover) {
render_color = GrabberHoverColor;
}
else
render_color = GrabberColor;
PickingModel &cube = m_move_grabber.get_cube();
// BBS set to fixed size grabber
// float fullsize = 2 * (dragging ? get_dragging_half_size(size) : get_half_size(size));
float fullsize = 8.0f;
if (GLGizmoBase::INV_ZOOM > 0) {
fullsize = m_move_grabber.FixedGrabberSize * GLGizmoBase::INV_ZOOM;
}
cube.model.set_color(render_color);
const Transform3d trafo_matrix = Geometry::assemble_transform(m_move_grabber.center) * m_rotate_matrix *
Geometry::assemble_transform(Vec3d::Zero(), Vec3d::Zero(), fullsize * Vec3d::Ones());
const Camera& camera = wxGetApp().plater()->get_camera();
const Transform3d& view_matrix = camera.get_view_matrix();
shader->set_uniform("view_model_matrix", view_matrix * trafo_matrix);
shader->set_uniform("projection_matrix", camera.get_projection_matrix());
const Matrix3d view_normal_matrix = view_matrix.matrix().block(0, 0, 3, 3) * trafo_matrix.matrix().block(0, 0, 3, 3).inverse().transpose();
shader->set_uniform("view_normal_matrix", view_normal_matrix);
cube.model.render();
shader->stop_using();
}
// Should be placed at last, because GLGizmoRotate3D clears depth buffer
set_center(m_cut_plane_center);
GLGizmoRotate3D::on_render();
}
void GLGizmoAdvancedCut::render_connectors()
{
::glEnable(GL_DEPTH_TEST);
const ModelObject *mo = m_c->selection_info()->model_object();
auto inst_id = m_c->selection_info()->get_active_instance();
if (inst_id < 0)
return;
const CutConnectors &connectors = mo->cut_connectors;
if (connectors.size() != m_selected.size()) {
clear_selection();
m_selected.resize(connectors.size(), false);
}
const ModelInstance *mi = mo->instances[inst_id];
const Vec3d & instance_offset = mi->get_offset();
const double sla_shift = double(m_c->selection_info()->get_sla_shift());
m_has_invalid_connector = false;
m_info_stats.invalidate();
ColorRGBA render_color = CONNECTOR_DEF_COLOR;
for (size_t i = 0; i < connectors.size(); ++i) {
const CutConnector &connector = connectors[i];
float height = connector.height;
// recalculate connector position to world position
Vec3d pos = connector.pos + instance_offset + sla_shift * Vec3d::UnitZ();
// First decide about the color of the point.
const bool conflict_connector = is_conflict_for_connector(i, connectors, pos);
if (conflict_connector) {
m_has_invalid_connector = true;
render_color = CONNECTOR_ERR_COLOR;
} else // default connector color
render_color = connector.attribs.type == CutConnectorType::Dowel ? DOWEL_COLOR : PLAG_COLOR;
if (!m_connectors_editing)
render_color = CONNECTOR_ERR_COLOR;
else if (size_t(m_hover_id - 4) == i)
render_color = conflict_connector ? HOVERED_ERR_COLOR : connector.attribs.type == CutConnectorType::Dowel ? HOVERED_DOWEL_COLOR : HOVERED_PLAG_COLOR;
else if (m_selected[i])
render_color = connector.attribs.type == CutConnectorType::Dowel ? SELECTED_DOWEL_COLOR : SELECTED_PLAG_COLOR;
const Camera &camera = wxGetApp().plater()->get_camera();
if (connector.attribs.type == CutConnectorType::Dowel && connector.attribs.style == CutConnectorStyle::Prizm) {
pos -= height * m_cut_plane_normal;
height *= 2;
} else if (!is_looking_forward())
pos -= 0.05 * m_cut_plane_normal;
Transform3d translate_tf = Transform3d::Identity();
translate_tf.translate(pos);
Transform3d scale_tf = Transform3d::Identity();
scale_tf.scale(Vec3f(connector.radius, connector.radius, height).cast<double>());
const Transform3d model_matrix = translate_tf * m_rotate_matrix * scale_tf;
render_connector_model(m_shapes[connector.attribs], render_color, model_matrix);
}
}
void GLGizmoAdvancedCut::render_clipper_cut()
{
glsafe(::glEnable(GL_DEPTH_TEST));
m_c->object_clipper()->render_cut();
glsafe(::glDisable(GL_DEPTH_TEST));
}
void GLGizmoAdvancedCut::render_cut_line()
{
if (!cut_line_processing() || m_cut_line_end == Vec3d::Zero())
return;
glsafe(::glDisable(GL_DEPTH_TEST));
GLShaderProgram *shader = wxGetApp().get_shader("flat");
if (shader != nullptr) {
shader->start_using();
{
m_cut_line.reset();
GLModel::Geometry init_data;
init_data.format = {GLModel::Geometry::EPrimitiveType::Lines, GLModel::Geometry::EVertexLayout::P3};
init_data.color = ColorRGBA::GREEN();
init_data.reserve_vertices(2);
init_data.reserve_vertices(2);
// vertices
init_data.add_vertex((Vec3f) m_cut_line_begin.cast<float>());
init_data.add_vertex((Vec3f) m_cut_line_end.cast<float>());
// indices
init_data.add_line(0, 1);
m_cut_line.init_from(std::move(init_data));
}
const Camera &camera = wxGetApp().plater()->get_camera();
shader->set_uniform("view_model_matrix", camera.get_view_matrix());
shader->set_uniform("projection_matrix", camera.get_projection_matrix());
glEnable(GL_LINE_STIPPLE);
glLineStipple(1, 0x0FFF);
m_cut_line.render();
glDisable(GL_LINE_STIPPLE);
shader->stop_using();
}
}
void GLGizmoAdvancedCut::render_connector_model(GLModel &model, const ColorRGBA &color, Transform3d model_matrix, bool for_picking)
{
GLShaderProgram *shader = nullptr;
if (for_picking)
shader = wxGetApp().get_shader("flat");
else
shader = wxGetApp().get_shader("gouraud_light");
if (shader) {
shader->start_using();
const Camera& camera = wxGetApp().plater()->get_camera();
const Transform3d& view_matrix = camera.get_view_matrix();
shader->set_uniform("view_model_matrix", view_matrix * model_matrix);
shader->set_uniform("projection_matrix", camera.get_projection_matrix());
const Matrix3d view_normal_matrix = view_matrix.matrix().block(0, 0, 3, 3) * model_matrix.matrix().block(0, 0, 3, 3).inverse().transpose();
shader->set_uniform("view_normal_matrix", view_normal_matrix);
model.set_color(color);
model.render();
shader->stop_using();
}
}
void GLGizmoAdvancedCut::clear_selection()
{
m_selected.clear();
m_selected_count = 0;
}
void GLGizmoAdvancedCut::init_connector_shapes()
{
for (const CutConnectorType &type : {CutConnectorType::Dowel, CutConnectorType::Plug})
for (const CutConnectorStyle &style : {CutConnectorStyle::Frustum, CutConnectorStyle::Prizm})
for (const CutConnectorShape &shape : {CutConnectorShape::Circle, CutConnectorShape::Hexagon, CutConnectorShape::Square, CutConnectorShape::Triangle}) {
const CutConnectorAttributes attribs = {type, style, shape};
const indexed_triangle_set its = ModelObject::get_connector_mesh(attribs);
m_shapes[attribs].init_from(its);
}
}
void GLGizmoAdvancedCut::set_connectors_editing(bool connectors_editing)
{
m_connectors_editing = connectors_editing;
// todo: zhimin need a better method
// after change render mode, need update for scene
on_render();
}
void GLGizmoAdvancedCut::reset_connectors()
{
m_c->selection_info()->model_object()->cut_connectors.clear();
clear_selection();
}
void GLGizmoAdvancedCut::update_connector_shape()
{
CutConnectorAttributes attribs = {m_connector_type, CutConnectorStyle(m_connector_style), CutConnectorShape(m_connector_shape_id)};
const indexed_triangle_set its = ModelObject::get_connector_mesh(attribs);
m_connector_mesh.clear();
m_connector_mesh = TriangleMesh(its);
}
void GLGizmoAdvancedCut::apply_selected_connectors(std::function<void(size_t idx)> apply_fn)
{
for (size_t idx = 0; idx < m_selected.size(); idx++)
if (m_selected[idx])
apply_fn(idx);
}
void GLGizmoAdvancedCut::select_all_connectors()
{
std::fill(m_selected.begin(), m_selected.end(), true);
m_selected_count = int(m_selected.size());
}
void GLGizmoAdvancedCut::unselect_all_connectors()
{
std::fill(m_selected.begin(), m_selected.end(), false);
m_selected_count = 0;
validate_connector_settings();
}
void GLGizmoAdvancedCut::validate_connector_settings()
{
if (m_connector_depth_ratio < 0.f)
m_connector_depth_ratio = 3.f;
if (m_connector_depth_ratio_tolerance < 0.f)
m_connector_depth_ratio_tolerance = 0.1f;
if (m_connector_size < 0.f)
m_connector_size = 2.5f;
if (m_connector_size_tolerance < 0.f)
m_connector_size_tolerance = 0.f;
if (m_connector_type == CutConnectorType::Undef)
m_connector_type = CutConnectorType::Plug;
if (m_connector_style == size_t(CutConnectorStyle::Undef))
m_connector_style = size_t(CutConnectorStyle::Prizm);
if (m_connector_shape_id == size_t(CutConnectorShape::Undef))
m_connector_shape_id = size_t(CutConnectorShape::Circle);
}
bool GLGizmoAdvancedCut::add_connector(CutConnectors &connectors, const Vec2d &mouse_position)
{
if (!m_connectors_editing)
return false;
Vec3d pos;
Vec3d pos_world;
if (unproject_on_cut_plane(mouse_position.cast<double>(), pos, pos_world)) {
Plater::TakeSnapshot snapshot(wxGetApp().plater(), "Add connector");
unselect_all_connectors();
connectors.emplace_back(pos, m_rotate_matrix, m_connector_size * 0.5f, m_connector_depth_ratio, m_connector_size_tolerance, m_connector_depth_ratio_tolerance,
CutConnectorAttributes(CutConnectorType(m_connector_type), CutConnectorStyle(m_connector_style), CutConnectorShape(m_connector_shape_id)));
m_selected.push_back(true);
m_selected_count = 1;
assert(m_selected.size() == connectors.size());
m_parent.set_as_dirty();
return true;
}
return false;
}
bool GLGizmoAdvancedCut::delete_selected_connectors()
{
CutConnectors &connectors = m_c->selection_info()->model_object()->cut_connectors;
if (connectors.empty())
return false;
Plater::TakeSnapshot snapshot(wxGetApp().plater(), "Delete connector");
// remove connectors
for (int i = int(connectors.size()) - 1; i >= 0; i--)
if (m_selected[i]) connectors.erase(connectors.begin() + i);
// remove selections
m_selected.erase(std::remove_if(m_selected.begin(), m_selected.end(),
[](const auto &selected) {
return selected;}),
m_selected.end());
m_selected_count = 0;
assert(m_selected.size() == connectors.size());
m_parent.set_as_dirty();
return true;
}
bool GLGizmoAdvancedCut::is_outside_of_cut_contour(size_t idx, const CutConnectors &connectors, const Vec3d cur_pos)
{
// check if connector pos is out of clipping plane
if (m_c->object_clipper() && !m_c->object_clipper()->is_projection_inside_cut(cur_pos)) {
m_info_stats.outside_cut_contour++;
return true;
}
// check if connector bottom contour is out of clipping plane
const CutConnector & cur_connector = connectors[idx];
const CutConnectorShape shape = CutConnectorShape(cur_connector.attribs.shape);
const int sectorCount = shape == CutConnectorShape::Triangle ? 3 :
shape == CutConnectorShape::Square ? 4 :
shape == CutConnectorShape::Circle ? 60: // supposably, 60 points are enough for conflict detection
shape == CutConnectorShape::Hexagon ? 6 : 1 ;
indexed_triangle_set mesh;
auto & vertices = mesh.vertices;
vertices.reserve(sectorCount + 1);
float fa = 2 * PI / sectorCount;
auto vec = Eigen::Vector2f(0, cur_connector.radius);
for (float angle = 0; angle < 2.f * PI; angle += fa) {
Vec2f p = Eigen::Rotation2Df(angle) * vec;
vertices.emplace_back(Vec3f(p(0), p(1), 0.f));
}
Transform3d transform = Transform3d::Identity();
transform.translate(cur_pos);
its_transform(mesh, transform * m_rotate_matrix);
for (auto vertex : vertices) {
if (m_c->object_clipper() && !m_c->object_clipper()->is_projection_inside_cut(vertex.cast<double>())) {
m_info_stats.outside_cut_contour++;
return true;
}
}
return false;
}
bool GLGizmoAdvancedCut::is_conflict_for_connector(size_t idx, const CutConnectors &connectors, const Vec3d cur_pos)
{
if (is_outside_of_cut_contour(idx, connectors, cur_pos))
return true;
const CutConnector &cur_connector = connectors[idx];
Transform3d translate_tf = Transform3d::Identity();
translate_tf.translate(cur_pos);
Transform3d scale_tf = Transform3d::Identity();
scale_tf.scale(Vec3f(cur_connector.radius, cur_connector.radius, cur_connector.height).cast<double>());
const Transform3d matrix = translate_tf * m_rotate_matrix * scale_tf;
const BoundingBoxf3 cur_tbb = m_shapes[cur_connector.attribs].get_bounding_box().transformed(matrix);
// check if connector's bounding box is inside the object's bounding box
if (!bounding_box().contains(cur_tbb)) {
m_info_stats.outside_bb++;
return true;
}
// check if connectors are overlapping
for (size_t i = 0; i < connectors.size(); ++i) {
if (i == idx) continue;
const CutConnector &connector = connectors[i];
if ((connector.pos - cur_connector.pos).norm() < double(connector.radius + cur_connector.radius)) {
m_info_stats.is_overlap = true;
return true;
}
}
return false;
}
void GLGizmoAdvancedCut::check_conflict_for_all_connectors()
{
const ModelObject *mo = m_c->selection_info()->model_object();
auto inst_id = m_c->selection_info()->get_active_instance();
if (inst_id < 0)
return;
const CutConnectors &connectors = mo->cut_connectors;
const ModelInstance *mi = mo->instances[inst_id];
const Vec3d & instance_offset = mi->get_offset();
const double sla_shift = double(m_c->selection_info()->get_sla_shift());
m_has_invalid_connector = false;
m_info_stats.invalidate();
for (size_t i = 0; i < connectors.size(); ++i) {
const CutConnector &connector = connectors[i];
Vec3d pos = connector.pos + instance_offset + sla_shift * Vec3d::UnitZ();
// First decide about the color of the point.
const bool conflict_connector = is_conflict_for_connector(i, connectors, pos);
if (conflict_connector) {
m_has_invalid_connector = true;
}
}
}
void GLGizmoAdvancedCut::render_cut_plane_input_window(float x, float y, float bottom_limit)
{
// float unit_size = m_imgui->get_style_scaling() * 48.0f;
float space_size = m_imgui->get_style_scaling() * 8;
float movement_cap = m_imgui->calc_text_size(_L("Movement:")).x;
float rotate_cap = m_imgui->calc_text_size(_L("Rotate")).x;
float caption_size = std::max(movement_cap, rotate_cap) + 2 * space_size;
bool imperial_units = wxGetApp().app_config->get("use_inches") == "1";
unsigned int current_active_id = ImGui::GetActiveID();
Vec3d rotation = {Geometry::rad2deg(m_buffered_rotation(0)), Geometry::rad2deg(m_buffered_rotation(1)), Geometry::rad2deg(m_buffered_rotation(2))};
char buf[3][64];
float buf_size[3];
float vec_max = 0, unit_size = 0;
for (int i = 0; i < 3; i++) {
ImGui::DataTypeFormatString(buf[i], IM_ARRAYSIZE(buf[i]), ImGuiDataType_Double, (void *) &rotation[i], "%.2f");
buf_size[i] = ImGui::CalcTextSize(buf[i]).x;
vec_max = std::max(buf_size[i], vec_max);
}
float buf_size_max = ImGui::CalcTextSize("-100.00").x;
if (vec_max < buf_size_max) {
unit_size = buf_size_max + ImGui::GetStyle().FramePadding.x * 2.0f;
} else {
unit_size = vec_max + ImGui::GetStyle().FramePadding.x * 2.0f;
}
ImGui::PushItemWidth(caption_size);
ImGui::Dummy(ImVec2(caption_size, -1));
ImGui::SameLine(caption_size + 1 * space_size);
ImGui::PushItemWidth(unit_size);
ImGui::TextAlignCenter("X");
ImGui::SameLine(caption_size + 1 * unit_size + 2 * space_size);
ImGui::PushItemWidth(unit_size);
ImGui::TextAlignCenter("Y");
ImGui::SameLine(caption_size + 2 * unit_size + 3 * space_size);
ImGui::PushItemWidth(unit_size);
ImGui::TextAlignCenter("Z");
ImGui::AlignTextToFramePadding();
// Rotation input box
ImGui::PushItemWidth(caption_size);
m_imgui->text(_L("Rotation") + " ");
ImGui::SameLine(caption_size + 1 * space_size);
ImGui::PushItemWidth(unit_size);
ImGui::BBLInputDouble("##cut_rotation_x", &rotation[0], 0.0f, 0.0f, "%.2f");
ImGui::SameLine(caption_size + 1 * unit_size + 2 * space_size);
ImGui::PushItemWidth(unit_size);
ImGui::BBLInputDouble("##cut_rotation_y", &rotation[1], 0.0f, 0.0f, "%.2f");
ImGui::SameLine(caption_size + 2 * unit_size + 3 * space_size);
ImGui::PushItemWidth(unit_size);
ImGui::BBLInputDouble("##cut_rotation_z", &rotation[2], 0.0f, 0.0f, "%.2f");
if (current_active_id != m_last_active_id) {
if (std::abs(Geometry::rad2deg(m_rotation(0)) - m_buffered_rotation(0)) > EPSILON || std::abs(Geometry::rad2deg(m_rotation(1)) - m_buffered_rotation(1)) > EPSILON ||
std::abs(Geometry::rad2deg(m_rotation(2)) - m_buffered_rotation(2)) > EPSILON) {
m_rotation = m_buffered_rotation;
m_buffered_rotation.setZero();
update_plane_points();
m_parent.post_event(SimpleEvent(wxEVT_PAINT));
}
} else {
m_buffered_rotation(0) = Geometry::deg2rad(rotation(0));
m_buffered_rotation(1) = Geometry::deg2rad(rotation(1));
m_buffered_rotation(2) = Geometry::deg2rad(rotation(2));
}
ImGui::Separator();
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(4.0f, 10.0f));
// Movement input box
double movement = m_movement;
ImGui::PushItemWidth(caption_size);
ImGui::AlignTextToFramePadding();
m_imgui->text(_L("Movement") + " ");
ImGui::SameLine(caption_size + 1 * space_size);
ImGui::PushItemWidth(3 * unit_size + 2 * space_size);
ImGui::BBLInputDouble("##cut_movement", &movement, 0.0f, 0.0f, "%.2f");
if (current_active_id != m_last_active_id) {
if (std::abs(m_buffered_movement - m_movement) > EPSILON) {
m_movement = m_buffered_movement;
m_buffered_movement = 0.0;
// update absolute height
Vec3d plane_normal = get_plane_normal();
m_height_delta = plane_normal(2) * m_movement;
m_height += m_height_delta;
m_buffered_height = m_height;
update_plane_points();
m_parent.post_event(SimpleEvent(wxEVT_PAINT));
}
} else {
m_buffered_movement = movement;
}
// height input box
double height = m_height;
ImGui::PushItemWidth(caption_size);
ImGui::AlignTextToFramePadding();
// only allow setting height when cut plane is horizontal
Vec3d plane_normal = get_plane_normal();
m_imgui->disabled_begin(std::abs(plane_normal(0)) > EPSILON || std::abs(plane_normal(1)) > EPSILON);
m_imgui->text(_L("Height") + " ");
ImGui::SameLine(caption_size + 1 * space_size);
ImGui::PushItemWidth(3 * unit_size + 2 * space_size);
ImGui::BBLInputDouble("##cut_height", &height, 0.0f, 0.0f, "%.2f");
if (current_active_id != m_last_active_id) {
if (std::abs(m_buffered_height - m_height) > EPSILON) {
m_height_delta = m_buffered_height - m_height;
m_height = m_buffered_height;
update_plane_points();
m_parent.post_event(SimpleEvent(wxEVT_PAINT));
}
} else {
m_buffered_height = height;
}
ImGui::PopStyleVar(1);
m_imgui->disabled_end();
CutConnectors &connectors = m_c->selection_info()->model_object()->cut_connectors;
const bool has_connectors = !connectors.empty();
m_imgui->disabled_begin(!m_keep_upper || !m_keep_lower || m_cut_to_parts);
if (m_imgui->button(has_connectors ? _L("Edit connectors") : _L("Add connectors"))) set_connectors_editing(true);
m_imgui->disabled_end();
ImGui::Separator();
float label_width = 0;
for (const wxString& label : {_L("Upper part"), _L("Lower part")}) {
const float width = m_imgui->calc_text_size(label).x + m_imgui->scaled(1.5f);
if (label_width < width)
label_width = width;
}
auto render_part_action_line = [this, label_width, &connectors](const wxString &label, const wxString &suffix, bool &keep_part, bool &place_on_cut_part, bool &rotate_part) {
bool keep = true;
ImGui::AlignTextToFramePadding();
m_imgui->text(label);
ImGui::SameLine(label_width);
m_imgui->disabled_begin(!connectors.empty() || m_cut_to_parts);
m_imgui->bbl_checkbox(_L("Keep") + suffix, connectors.empty() ? keep_part : keep);
m_imgui->disabled_end();
ImGui::SameLine();
m_imgui->disabled_begin(!keep_part || m_cut_to_parts);
if (m_imgui->bbl_checkbox(_L("Place on cut") + suffix, place_on_cut_part))
rotate_part = false;
ImGui::SameLine();
if (m_imgui->bbl_checkbox(_L("Flip") + suffix, rotate_part))
place_on_cut_part = false;
m_imgui->disabled_end();
};
m_imgui->text(_L("After cut") + ": ");
render_part_action_line( _L("Upper part"), "##upper", m_keep_upper, m_place_on_cut_upper, m_rotate_upper);
render_part_action_line( _L("Lower part"), "##lower", m_keep_lower, m_place_on_cut_lower, m_rotate_lower);
m_imgui->disabled_begin(has_connectors);
m_imgui->bbl_checkbox(_L("Cut to parts"), m_cut_to_parts);
if (m_cut_to_parts) {
m_keep_upper = true;
m_keep_lower = true;
}
m_imgui->disabled_end();
#if 0
// Auto segment input
ImGui::PushItemWidth(m_imgui->get_style_scaling() * 150.0);
m_imgui->checkbox(_L("Auto Segment"), m_do_segment);
m_imgui->disabled_begin(!m_do_segment);
ImGui::InputDouble("smoothing_alpha", &m_segment_smoothing_alpha, 0.0f, 0.0f, "%.2f");
m_segment_smoothing_alpha = std::max(0.1, std::min(100.0, m_segment_smoothing_alpha));
ImGui::InputInt("segment number", &m_segment_number);
m_segment_number = std::max(1, m_segment_number);
m_imgui->disabled_end();
ImGui::Separator();
#endif
// Cut button
m_imgui->disabled_begin(!can_perform_cut());
if (m_imgui->button(_L("Perform cut")))
perform_cut(m_parent.get_selection());
m_imgui->disabled_end();
ImGui::SameLine();
const bool reset_clicked = m_imgui->button(_L("Reset"));
if (reset_clicked) { reset_all(); }
m_last_active_id = current_active_id;
}
void GLGizmoAdvancedCut::init_connectors_input_window_data()
{
CutConnectors &connectors = m_c->selection_info()->model_object()->cut_connectors;
float connectors_cap = m_imgui->calc_text_size(_L("Connectors")).x;
float type_cap = m_imgui->calc_text_size(_L("Type")).x;
float style_cap = m_imgui->calc_text_size(_L("Style")).x;
float shape_cap = m_imgui->calc_text_size(_L("Shape")).x;
float depth_ratio_cap = m_imgui->calc_text_size(_L("Depth ratio")).x;
float size_cap = m_imgui->calc_text_size(_L("Size")).x;
float max_lable_size = std::max(std::max(std::max(connectors_cap, type_cap), std::max(style_cap, shape_cap)), std::max(depth_ratio_cap, size_cap));
m_label_width = double(max_lable_size + 3 + ImGui::GetStyle().WindowPadding.x);
m_control_width = m_imgui->get_font_size() * 9.f;
m_editing_window_width = 1.45 * m_control_width + 11;
if (m_connectors_editing && m_selected_count > 0) {
float depth_ratio {UndefFloat};
float depth_ratio_tolerance {UndefFloat};
float radius {UndefFloat};
float radius_tolerance {UndefFloat};
CutConnectorType type{CutConnectorType::Undef};
CutConnectorStyle style{CutConnectorStyle::Undef};
CutConnectorShape shape{CutConnectorShape::Undef};
bool is_init = false;
for (size_t idx = 0; idx < m_selected.size(); idx++)
if (m_selected[idx]) {
const CutConnector &connector = connectors[idx];
if (!is_init) {
depth_ratio = connector.height;
depth_ratio_tolerance = connector.height_tolerance;
radius = connector.radius;
radius_tolerance = connector.radius_tolerance;
type = connector.attribs.type;
style = connector.attribs.style;
shape = connector.attribs.shape;
if (m_selected_count == 1) break;
is_init = true;
} else {
if (!is_approx(depth_ratio, connector.height))
depth_ratio = UndefFloat;
if (!is_approx(depth_ratio_tolerance, connector.height_tolerance))
depth_ratio_tolerance = UndefFloat;
if (!is_approx(radius, connector.radius))
radius = UndefFloat;
if (!is_approx(radius_tolerance, connector.radius_tolerance))
radius_tolerance = UndefFloat;
if (type != connector.attribs.type)
type = CutConnectorType::Undef;
if (style != connector.attribs.style)
style = CutConnectorStyle::Undef;
if (shape != connector.attribs.shape)
shape = CutConnectorShape::Undef;
}
}
m_connector_depth_ratio = depth_ratio;
m_connector_depth_ratio_tolerance = depth_ratio_tolerance;
m_connector_size = 2.f * radius;
m_connector_size_tolerance = radius_tolerance;
m_connector_type = type;
m_connector_style = size_t(style);
m_connector_shape_id = size_t(shape);
}
}
void GLGizmoAdvancedCut::render_connectors_input_window(float x, float y, float bottom_limit)
{
CutConnectors &connectors = m_c->selection_info()->model_object()->cut_connectors;
// update when change input window
m_imgui->set_requires_extra_frame();
ImGui::AlignTextToFramePadding();
m_imgui->text_colored(ImGuiWrapper::COL_ORANGE_LIGHT, _L("Connectors"));
m_imgui->disabled_begin(connectors.empty());
ImGui::SameLine(m_label_width);
if (render_reset_button("connectors", _u8L("Remove connectors")))
reset_connectors();
m_imgui->disabled_end();
m_imgui->text(_L("Type"));
ImGui::PushStyleColor(ImGuiCol_CheckMark, ImVec4(0.00f, 0.00f, 0.00f, 1.00f));
bool type_changed = render_connect_type_radio_button(CutConnectorType::Plug);
type_changed |= render_connect_type_radio_button(CutConnectorType::Dowel);
if (type_changed)
apply_selected_connectors([this, &connectors](size_t idx) { connectors[idx].attribs.type = CutConnectorType(m_connector_type); });
ImGui::PopStyleColor(1);
std::vector<std::string> connector_styles = {_u8L("Prizm"), _u8L("Frustum")};
std::vector<std::string> connector_shapes = { _u8L("Triangle"), _u8L("Square"), _u8L("Hexagon"), _u8L("Circle") };
m_imgui->disabled_begin(m_connector_type == CutConnectorType::Dowel);
if (type_changed && m_connector_type == CutConnectorType::Dowel) {
m_connector_style = size_t(CutConnectorStyle::Prizm);
apply_selected_connectors([this, &connectors](size_t idx) { connectors[idx].attribs.style = CutConnectorStyle(m_connector_style); });
}
ImGuiWrapper::push_combo_style(m_parent.get_scale());
if (render_combo(_u8L("Style"), connector_styles, m_connector_style))
apply_selected_connectors([this, &connectors](size_t idx) { connectors[idx].attribs.style = CutConnectorStyle(m_connector_style); });
m_imgui->disabled_end();
ImGuiWrapper::pop_combo_style();
ImGuiWrapper::push_combo_style(m_parent.get_scale());
if (render_combo(_u8L("Shape"), connector_shapes, m_connector_shape_id))
apply_selected_connectors([this, &connectors](size_t idx) { connectors[idx].attribs.shape = CutConnectorShape(m_connector_shape_id); });
ImGuiWrapper::pop_combo_style();
if (render_slider_double_input(_u8L("Depth ratio"), m_connector_depth_ratio, m_connector_depth_ratio_tolerance))
apply_selected_connectors([this, &connectors](size_t idx) {
if (m_connector_depth_ratio > 0)
connectors[idx].height = m_connector_depth_ratio;
if (m_connector_depth_ratio_tolerance >= 0)
connectors[idx].height_tolerance = m_connector_depth_ratio_tolerance;
});
if (render_slider_double_input(_u8L("Size"), m_connector_size, m_connector_size_tolerance))
apply_selected_connectors([this, &connectors](size_t idx) {
if (m_connector_size > 0)
connectors[idx].radius = 0.5f * m_connector_size;
if (m_connector_size_tolerance >= 0)
connectors[idx].radius_tolerance = m_connector_size_tolerance;
});
ImGui::Separator();
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(6.0f, 10.0f));
float get_cur_y = ImGui::GetContentRegionMax().y + ImGui::GetFrameHeight() + y;
show_tooltip_information(x, get_cur_y);
float f_scale = m_parent.get_gizmos_manager().get_layout_scale();
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(6.0f, 4.0f * f_scale));
ImGui::SameLine();
if (m_imgui->button(_L("Confirm connectors"))) {
unselect_all_connectors();
set_connectors_editing(false);
}
ImGui::SameLine(m_label_width + m_editing_window_width - m_imgui->calc_text_size(_L("Cancel")).x - m_imgui->get_style_scaling() * 8);
if (m_imgui->button(_L("Cancel"))) {
reset_connectors();
set_connectors_editing(false);
}
ImGui::PopStyleVar(2);
}
void GLGizmoAdvancedCut::render_input_window_warning() const
{
if (m_has_invalid_connector) {
wxString out = /*wxString(ImGui::WarningMarkerSmall)*/ _L("Warning") + ": " + _L("Invalid connectors detected") + ":";
if (m_info_stats.outside_cut_contour > size_t(0))
out += "\n - " + std::to_string(m_info_stats.outside_cut_contour) +
(m_info_stats.outside_cut_contour == 1 ? _L("connector is out of cut contour") : _L("connectors are out of cut contour"));
if (m_info_stats.outside_bb > size_t(0))
out += "\n - " + std::to_string(m_info_stats.outside_bb) +
(m_info_stats.outside_bb == 1 ? _L("connector is out of object") : _L("connectors is out of object"));
if (m_info_stats.is_overlap)
out += "\n - " + _L("Some connectors are overlapped");
m_imgui->text(out);
}
if (!m_keep_upper && !m_keep_lower) m_imgui->text(/*wxString(ImGui::WarningMarkerSmall)*/_L("Warning") + ": " + _L("Invalid state. \nNo one part is selected for keep after cut"));
}
bool GLGizmoAdvancedCut::render_reset_button(const std::string &label_id, const std::string &tooltip) const
{
const ImGuiStyle &style = ImGui::GetStyle();
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, {1, style.ItemSpacing.y});
ImGui::PushStyleColor(ImGuiCol_Button, {0.25f, 0.25f, 0.25f, 0.0f});
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, {0.4f, 0.4f, 0.4f, 1.0f});
ImGui::PushStyleColor(ImGuiCol_ButtonActive, {0.4f, 0.4f, 0.4f, 1.0f});
bool revert = m_imgui->button(wxString(ImGui::RevertBtn));
ImGui::PopStyleColor(3);
if (ImGui::IsItemHovered())
m_imgui->tooltip(tooltip.c_str(), ImGui::GetFontSize() * 20.0f);
ImGui::PopStyleVar();
return revert;
}
bool GLGizmoAdvancedCut::render_connect_type_radio_button(CutConnectorType type)
{
ImGui::SameLine(type == CutConnectorType::Plug ? m_label_width : 2 * m_label_width);
ImGui::PushItemWidth(m_control_width);
wxString radio_name;
switch (type) {
case CutConnectorType::Plug:
radio_name = _L("Plug");
break;
case CutConnectorType::Dowel:
radio_name = _L("Dowel");
break;
default:
break;
}
if (m_imgui->radio_button(radio_name, m_connector_type == type)) {
m_connector_type = type;
update_connector_shape();
return true;
}
return false;
}
bool GLGizmoAdvancedCut::render_combo(const std::string &label, const std::vector<std::string> &lines, size_t &selection_idx)
{
ImGui::AlignTextToFramePadding();
m_imgui->text(label);
ImGui::SameLine(m_label_width);
ImGui::PushItemWidth(m_editing_window_width);
size_t selection_out = selection_idx;
const char* selected_str = (selection_idx >= 0 && selection_idx < int(lines.size())) ? lines[selection_idx].c_str() : "";
if (ImGui::BBLBeginCombo(("##" + label).c_str(), selected_str, 0)) {
for (size_t line_idx = 0; line_idx < lines.size(); ++line_idx) {
ImGui::PushID(int(line_idx));
if (ImGui::Selectable("", line_idx == selection_idx))
selection_out = line_idx;
ImGui::SameLine();
ImGui::Text("%s", lines[line_idx].c_str());
ImGui::PopID();
}
ImGui::EndCombo();
}
bool is_changed = selection_idx != selection_out;
selection_idx = selection_out;
if (is_changed) update_connector_shape();
return is_changed;
}
bool GLGizmoAdvancedCut::render_slider_double_input(const std::string &label, float &value_in, float &tolerance_in)
{
// -------- [ ] -------- [ ]
// slider_with + item_in_gap + first_input_width + item_out_gap + slider_with + item_in_gap + second_input_width
double slider_with = 0.24 * m_editing_window_width; // m_control_width * 0.35;
double item_in_gap = 0.01 * m_editing_window_width;
double item_out_gap = 0.01 * m_editing_window_width;
double first_input_width = 0.29 * m_editing_window_width;
double second_input_width = 0.29 * m_editing_window_width;
ImGui::AlignTextToFramePadding();
m_imgui->text(label);
ImGui::SameLine(m_label_width);
ImGui::PushItemWidth(slider_with);
double left_width = m_label_width + slider_with + item_in_gap;
bool m_imperial_units = false;
float value = value_in;
if (m_imperial_units) value *= float(units_mm_to_in);
float old_val = value;
constexpr float UndefMinVal = -0.1f;
const BoundingBoxf3 bbox = bounding_box();
float mean_size = float((bbox.size().x() + bbox.size().y() + bbox.size().z()) / 9.0);
float min_size = value_in < 0.f ? UndefMinVal : 2.f;
if (m_imperial_units) {
mean_size *= float(units_mm_to_in);
min_size *= float(units_mm_to_in);
}
std::string format = value_in < 0.f ? " " : m_imperial_units ? "%.4f " + _u8L("in") : "%.2f " + _u8L("mm");
m_imgui->bbl_slider_float_style(("##" + label).c_str(), &value, min_size, mean_size, format.c_str());
ImGui::SameLine(left_width);
ImGui::PushItemWidth(first_input_width);
ImGui::BBLDragFloat(("##input_" + label).c_str(), &value, 0.05f, min_size, mean_size, format.c_str());
value_in = value * float(m_imperial_units ? units_in_to_mm : 1.0);
left_width += (first_input_width + item_out_gap);
ImGui::SameLine(left_width);
ImGui::PushItemWidth(slider_with);
float tolerance = tolerance_in;
if (m_imperial_units)
tolerance *= float(units_mm_to_in);
float old_tolerance = tolerance;
//std::string format_t = tolerance_in < 0.f ? " " : "%.f %%";
float min_tolerance = tolerance_in < 0.f ? UndefMinVal : 0.f;
m_imgui->bbl_slider_float_style(("##tolerance_" + label).c_str(), &tolerance, min_tolerance, 2.f, format.c_str(), 1.f, true, _L("Tolerance"));
left_width += (slider_with + item_in_gap);
ImGui::SameLine(left_width);
ImGui::PushItemWidth(second_input_width);
ImGui::BBLDragFloat(("##tolerance_input_" + label).c_str(), &tolerance, 0.05f, min_tolerance, 2.f, format.c_str());
tolerance_in = tolerance * float(m_imperial_units ? units_in_to_mm : 1.0);
return !is_approx(old_val, value) || !is_approx(old_tolerance, tolerance);
}
bool GLGizmoAdvancedCut::cut_line_processing() const
{
return m_cut_line_begin != Vec3d::Zero();
}
void GLGizmoAdvancedCut::discard_cut_line_processing()
{
m_cut_line_begin = m_cut_line_end = Vec3d::Zero();
}
bool GLGizmoAdvancedCut::process_cut_line(SLAGizmoEventType action, const Vec2d &mouse_position)
{
const Camera &camera = wxGetApp().plater()->get_camera();
Vec3d pt;
Vec3d dir;
CameraUtils::ray_from_screen_pos(camera, mouse_position, pt, dir);
dir.normalize();
pt += dir; // Move the pt along dir so it is not clipped.
if (action == SLAGizmoEventType::LeftDown && !cut_line_processing()) {
m_cut_line_begin = pt;
m_cut_line_end = pt;
return true;
}
if (cut_line_processing()) {
m_cut_line_end = pt;
if (action == SLAGizmoEventType::LeftDown || action == SLAGizmoEventType::LeftUp) {
Vec3d line_dir = m_cut_line_end - m_cut_line_begin;
if (line_dir.norm() < 3.0)
return true;
Plater::TakeSnapshot snapshot(wxGetApp().plater(), "Cut by line");
Vec3d cross_dir = line_dir.cross(dir).normalized();
Eigen::Quaterniond q;
Transform3d m = Transform3d::Identity();
m.matrix().block(0, 0, 3, 3) = q.setFromTwoVectors(m_cut_plane_normal, cross_dir).toRotationMatrix();
m_rotate_matrix = m;
const ModelObject * mo = m_c->selection_info()->model_object();
const ModelInstance *mi = mo->instances[m_c->selection_info()->get_active_instance()];
Vec3d plane_center = get_plane_center();
auto update_plane_after_line_cut = [this](const Vec3d &deta_plane_center, const Transform3d& rotate_matrix) {
Vec3d plane_center = get_plane_center();
std::array<Vec3d, 4> plane_points_rot;
for (int i = 0; i < plane_points_rot.size(); i++) {
plane_points_rot[i] = m_cut_plane_points[i] - plane_center;
}
for (uint32_t i = 0; i < plane_points_rot.size(); ++i) {
plane_points_rot[i] = rotate_matrix * plane_points_rot[i];
}
for (int i = 0; i < plane_points_rot.size(); i++) {
m_cut_plane_points[i] = plane_points_rot[i] + plane_center + deta_plane_center;
}
};
update_plane_after_line_cut(cross_dir * (cross_dir.dot(pt - m_cut_plane_center)), m_rotate_matrix);
discard_cut_line_processing();
} else if (action == SLAGizmoEventType::Dragging)
this->set_dirty();
return true;
}
return false;
}
} // namespace GUI
} // namespace Slic3r