-
Notifications
You must be signed in to change notification settings - Fork 885
Expand file tree
/
Copy pathStatusPanel.cpp
More file actions
6595 lines (5669 loc) · 283 KB
/
Copy pathStatusPanel.cpp
File metadata and controls
6595 lines (5669 loc) · 283 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "StatusPanel.hpp"
#include "I18N.hpp"
#include "Widgets/Label.hpp"
#include "Widgets/Button.hpp"
#include "Widgets/StepCtrl.hpp"
#include "Widgets/SideTools.hpp"
#include "BitmapCache.hpp"
#include "GUI_App.hpp"
#include "MainFrame.hpp"
#include <wx/weakref.h>
#ifdef __APPLE__
#include "CameraFullscreenMac.hpp"
#endif
#include "MsgDialog.hpp"
#include "slic3r/Utils/Http.hpp"
#include "libslic3r/Thread.hpp"
#include "DeviceErrorDialog.hpp"
#include "RecenterDialog.hpp"
#include "CalibUtils.hpp"
#include "BBLUtil.hpp"
#include <slic3r/GUI/Widgets/ProgressDialog.hpp>
#include <wx/accel.h>
#include <wx/display.h>
#include <wx/dcbuffer.h>
#include <wx/dcgraph.h>
#include <wx/frame.h>
#include <wx/mstream.h>
#include <wx/sstream.h>
#include <wx/zstream.h>
#include "DeviceCore/DevAxis.h"
#include "DeviceCore/DevBed.h"
#include "DeviceCore/DevChamber.h"
#include "DeviceCore/DevCtrl.h"
#include "DeviceCore/DevFan.h"
#include "DeviceCore/DevFilaSystem.h"
#include "DeviceCore/DevFilaSwitch.h"
#include "DeviceCore/DevLamp.h"
#include "DeviceCore/DevNozzleSystem.h"
#include "DeviceCore/DevStorage.h"
#include "DeviceCore/DevStatus.h"
#include "DeviceCore/DevConfig.h"
#include "DeviceCore/DevConfigUtil.h"
#include "DeviceCore/DevInfo.h"
#include "DeviceCore/DevManager.h"
#include "DeviceCore/DevPrintTaskInfo.h"
#include "DeviceCore/DevPrintOptions.h"
#include "DeviceTab/wgtDeviceNozzleRack.h"
#include "PrintOptionsDialog.hpp"
#include "SafetyOptionsDialog.hpp"
#include "ThermalPreconditioningDialog.hpp"
#include <algorithm>
#include <functional>
namespace Slic3r { namespace GUI {
#define TEMP_THRESHOLD_VAL 2
#define TEMP_THRESHOLD_ALLOW_E_CTRL 170.0f
/* const strings */
static const wxString NA_STR = _L("N/A");
static const wxString TEMP_BLANK_STR = wxString("_");
static const wxFont SWITCH_FONT = Label::Body_10;
/* const values */
static const int bed_temp_range[2] = {20, 120};
static const int default_champer_temp_min = 20;
static const int default_champer_temp_max = 60;
/* colors */
static const wxColour STATUS_PANEL_BG = wxColour(238, 238, 238);
static const wxColour STATUS_TITLE_BG = wxColour(248, 248, 248);
static const wxColour STATIC_BOX_LINE_COL = wxColour(238, 238, 238);
static const wxColour BUTTON_NORMAL1_COL = wxColour(238, 238, 238);
static const wxColour BUTTON_NORMAL2_COL = wxColour(206, 206, 206);
static const wxColour BUTTON_PRESS_COL = wxColour(172, 172, 172);
static const wxColour BUTTON_HOVER_COL = wxColour(0, 174, 66);
static const wxColour DISCONNECT_TEXT_COL = wxColour(171, 172, 172);
static const wxColour NORMAL_TEXT_COL = wxColour(48, 58, 60);
class CameraFullscreenCloseButton : public wxPopupWindow
{
public:
CameraFullscreenCloseButton(wxWindow *parent, std::function<void()> close_cb, std::function<void(bool)> hover_cb)
: wxPopupWindow(parent, wxBORDER_NONE)
, m_close_cb(std::move(close_cb))
, m_hover_cb(std::move(hover_cb))
{
SetBackgroundStyle(wxBG_STYLE_PAINT);
SetCursor(wxCursor(wxCURSOR_HAND));
Bind(wxEVT_PAINT, &CameraFullscreenCloseButton::on_paint, this);
Bind(wxEVT_ENTER_WINDOW, &CameraFullscreenCloseButton::on_enter, this);
Bind(wxEVT_LEAVE_WINDOW, &CameraFullscreenCloseButton::on_leave, this);
Bind(wxEVT_LEFT_UP, &CameraFullscreenCloseButton::on_left_up, this);
}
void set_alpha(int alpha)
{
m_alpha = std::clamp(alpha, 0, 255);
Refresh();
}
private:
void on_paint(wxPaintEvent &)
{
wxAutoBufferedPaintDC paint_dc(this);
paint_dc.SetBackground(wxBrush(wxColour(0, 0, 0, 0)));
paint_dc.Clear();
if (m_alpha <= 0) return;
wxGCDC dc(paint_dc);
const wxSize size = GetClientSize();
const int inset = FromDIP(1);
const int x_pad = FromDIP(14);
const int line_width = FromDIP(2);
const int bg_alpha = m_hover ? std::min(255, m_alpha + 35) : m_alpha;
dc.SetPen(*wxTRANSPARENT_PEN);
dc.SetBrush(wxBrush(wxColour(18, 18, 18, bg_alpha)));
dc.DrawEllipse(inset, inset, size.x - 2 * inset, size.y - 2 * inset);
dc.SetPen(wxPen(wxColour(255, 255, 255, std::min(255, bg_alpha + 20)), line_width, wxPENSTYLE_SOLID));
dc.DrawLine(x_pad, x_pad, size.x - x_pad, size.y - x_pad);
dc.DrawLine(size.x - x_pad, x_pad, x_pad, size.y - x_pad);
}
void on_enter(wxMouseEvent &event)
{
m_hover = true;
if (m_hover_cb) m_hover_cb(true);
Refresh();
event.Skip();
}
void on_leave(wxMouseEvent &event)
{
m_hover = false;
if (m_hover_cb) m_hover_cb(false);
Refresh();
event.Skip();
}
void on_left_up(wxMouseEvent &)
{
if (m_close_cb) m_close_cb();
}
std::function<void()> m_close_cb;
std::function<void(bool)> m_hover_cb;
int m_alpha{0};
bool m_hover{false};
};
class CameraFullscreenFrame : public wxFrame
{
public:
explicit CameraFullscreenFrame(StatusBasePanel *owner)
: wxFrame(owner, wxID_ANY, _L("Camera Full Screen"), wxDefaultPosition, wxDefaultSize, wxBORDER_NONE | wxFRAME_NO_TASKBAR | wxSTAY_ON_TOP)
, m_owner(owner)
{
SetBackgroundColour(*wxBLACK);
EnableFullScreenView(true);
m_hide_timer.SetOwner(this, wxWindow::NewControlId());
m_fade_timer.SetOwner(this, wxWindow::NewControlId());
auto *root_sizer = new wxBoxSizer(wxVERTICAL);
m_video_host = new wxPanel(this, wxID_ANY);
m_video_host->SetBackgroundColour(*wxBLACK);
m_video_sizer = new wxBoxSizer(wxVERTICAL);
m_video_host->SetSizer(m_video_sizer);
root_sizer->Add(m_video_host, 1, wxEXPAND);
SetSizer(root_sizer);
m_close_button = new CameraFullscreenCloseButton(
this,
[this] { request_close(); },
[this](bool hover) { on_close_hover_changed(hover); });
m_close_button->Hide();
Bind(wxEVT_CLOSE_WINDOW, &CameraFullscreenFrame::on_close, this);
Bind(wxEVT_ACTIVATE, &CameraFullscreenFrame::on_activate, this);
m_escape_accel_id = wxWindow::NewControlId();
Bind(wxEVT_MENU, &CameraFullscreenFrame::on_escape_accelerator, this, m_escape_accel_id);
Bind(wxEVT_CHAR_HOOK, &CameraFullscreenFrame::on_char_hook, this);
Bind(wxEVT_KEY_DOWN, &CameraFullscreenFrame::on_char_hook, this);
Bind(wxEVT_SIZE, &CameraFullscreenFrame::on_size, this);
Bind(wxEVT_MOTION, &CameraFullscreenFrame::on_mouse_motion, this);
Bind(wxEVT_TIMER, &CameraFullscreenFrame::on_hide_timer, this, m_hide_timer.GetId());
Bind(wxEVT_TIMER, &CameraFullscreenFrame::on_fade_timer, this, m_fade_timer.GetId());
wxAcceleratorEntry entries[1];
entries[0].Set(wxACCEL_NORMAL, WXK_ESCAPE, m_escape_accel_id);
SetAcceleratorTable(wxAcceleratorTable(1, entries));
#ifdef __APPLE__
m_escape_monitor = install_camera_fullscreen_escape_monitor(
[](void *context) {
auto *frame = static_cast<CameraFullscreenFrame *>(context);
frame->CallAfter([frame] { frame->request_close(); });
},
this);
#endif
m_video_host->Bind(wxEVT_KEY_DOWN, &CameraFullscreenFrame::on_char_hook, this);
m_video_host->Bind(wxEVT_MOTION, &CameraFullscreenFrame::on_mouse_motion, this);
m_close_button->Bind(wxEVT_CHAR_HOOK, &CameraFullscreenFrame::on_char_hook, this);
m_close_button->Bind(wxEVT_KEY_DOWN, &CameraFullscreenFrame::on_char_hook, this);
m_top_level = wxGetTopLevelParent(owner);
if (wxWindow *top = m_top_level.get())
top->Bind(wxEVT_CLOSE_WINDOW, &CameraFullscreenFrame::on_top_level_close, this);
wxDisplay display(wxDisplay::GetFromWindow(owner));
if (display.IsOk()) SetSize(display.GetGeometry());
}
~CameraFullscreenFrame() override
{
if (wxWindow *top = m_top_level.get())
top->Unbind(wxEVT_CLOSE_WINDOW, &CameraFullscreenFrame::on_top_level_close, this);
#ifdef __APPLE__
restore_camera_fullscreen_presentation(m_presentation_state);
uninstall_camera_fullscreen_escape_monitor(m_escape_monitor);
#endif
}
wxWindow *video_parent() const { return m_video_host; }
void show_camera_view(bool active_monitor_only)
{
m_native_fullscreen = false;
if (active_monitor_only) {
#ifdef __APPLE__
m_presentation_state = enter_camera_fullscreen_presentation(this);
#endif
SetSize(display_geometry_for(m_owner ? static_cast<wxWindow *>(m_owner) : this));
Show();
#ifdef __APPLE__
apply_camera_fullscreen_frame(this);
#else
ShowFullScreen(true, wxFULLSCREEN_ALL);
m_native_fullscreen = true;
#endif
} else {
#ifdef __APPLE__
Show();
ShowFullScreen(true, wxFULLSCREEN_ALL);
m_native_fullscreen = true;
#else
SetSize(all_display_geometry());
Show();
#endif
}
Raise();
SetFocus();
}
void exit_camera_view()
{
if (m_native_fullscreen) ShowFullScreen(false);
#ifdef __APPLE__
if (m_close_button)
detach_camera_fullscreen_overlay(this, m_close_button);
restore_camera_fullscreen_presentation(m_presentation_state);
m_presentation_state = nullptr;
#endif
if (wxWindow *top = m_top_level.get(); top && !top->IsBeingDeleted()) {
if (auto *tlw = dynamic_cast<wxTopLevelWindow *>(top); tlw && tlw->IsIconized())
tlw->Iconize(false);
#ifdef __APPLE__
raise_main_window_after_camera_fullscreen(top);
#else
top->Raise();
#endif
}
}
void attach_media(wxMediaCtrl3 *media_ctrl)
{
m_media_ctrl = media_ctrl;
m_saved_max_size = m_media_ctrl->GetMaxSize();
m_media_ctrl->SetConstrainByAspectRatio(false);
m_media_ctrl->SetMaxSize(wxDefaultSize);
m_video_sizer->Add(m_media_ctrl, 1, wxEXPAND);
m_media_ctrl->Bind(wxEVT_CHAR_HOOK, &CameraFullscreenFrame::on_char_hook, this);
m_media_ctrl->Bind(wxEVT_KEY_DOWN, &CameraFullscreenFrame::on_char_hook, this);
m_media_ctrl->Bind(wxEVT_MOTION, &CameraFullscreenFrame::on_mouse_motion, this);
Layout();
position_close_button();
CallAfter([this] {
show_close_button();
// Reclaim focus so ESC works immediately without clicking
SetFocus();
});
}
void detach_media()
{
if (!m_media_ctrl) return;
m_media_ctrl->Unbind(wxEVT_CHAR_HOOK, &CameraFullscreenFrame::on_char_hook, this);
m_media_ctrl->Unbind(wxEVT_KEY_DOWN, &CameraFullscreenFrame::on_char_hook, this);
m_media_ctrl->Unbind(wxEVT_MOTION, &CameraFullscreenFrame::on_mouse_motion, this);
m_video_sizer->Detach(m_media_ctrl);
m_media_ctrl->SetConstrainByAspectRatio(true);
m_media_ctrl->SetMaxSize(m_saved_max_size);
m_media_ctrl = nullptr;
}
void clear_owner() { m_owner = nullptr; }
private:
void on_close(wxCloseEvent &event)
{
if (m_owner) {
m_owner->close_camera_fullscreen();
return;
}
event.Skip();
}
void on_activate(wxActivateEvent &event)
{
event.Skip();
if (!event.GetActive()) {
#ifdef __WXMSW__
::SetWindowPos(GetHWND(), HWND_NOTOPMOST, 0, 0, 0, 0,
SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
#elif defined(__APPLE__)
if (!m_native_fullscreen)
suspend_camera_fullscreen_topmost(this);
#endif
} else {
#ifdef __WXMSW__
::SetWindowPos(GetHWND(), HWND_TOPMOST, 0, 0, 0, 0,
SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
#elif defined(__APPLE__)
if (!m_native_fullscreen)
resume_camera_fullscreen_topmost(this);
#endif
}
}
void on_escape_accelerator(wxCommandEvent &)
{
request_close();
}
void on_top_level_close(wxCloseEvent &event)
{
event.Skip();
if (m_owner) {
m_owner->close_camera_fullscreen();
} else {
Destroy();
}
}
void on_char_hook(wxKeyEvent &event)
{
if (event.GetKeyCode() == WXK_ESCAPE) {
request_close();
return;
}
event.Skip();
}
void on_size(wxSizeEvent &event)
{
event.Skip();
position_close_button();
}
void on_mouse_motion(wxMouseEvent &event)
{
show_close_button();
event.Skip();
}
void on_hide_timer(wxTimerEvent &)
{
if (m_close_hover) return;
m_fade_elapsed_ms = 0;
m_fade_start_alpha = m_close_alpha;
m_fade_timer.Start(30);
}
void on_fade_timer(wxTimerEvent &)
{
if (m_close_hover) {
m_fade_timer.Stop();
return;
}
m_fade_elapsed_ms += 30;
if (m_fade_elapsed_ms >= 300) {
m_fade_timer.Stop();
m_close_alpha = 0;
m_close_button->set_alpha(m_close_alpha);
m_close_button->Hide();
return;
}
m_close_alpha = m_fade_start_alpha * (300 - m_fade_elapsed_ms) / 300;
m_close_button->set_alpha(m_close_alpha);
}
void on_close_hover_changed(bool hover)
{
m_close_hover = hover;
if (hover) {
show_close_button(false);
} else {
start_hide_timer();
}
}
void request_close()
{
m_hide_timer.Stop();
m_fade_timer.Stop();
if (m_close_button) m_close_button->Hide();
if (m_owner) {
m_owner->close_camera_fullscreen();
} else {
Close();
}
}
static wxRect display_geometry_for(wxWindow *window)
{
const int display_index = window ? wxDisplay::GetFromWindow(window) : wxNOT_FOUND;
if (display_index != wxNOT_FOUND) {
wxDisplay display(static_cast<unsigned int>(display_index));
if (display.IsOk()) return display.GetGeometry();
}
wxDisplay primary_display(static_cast<unsigned int>(0));
return primary_display.IsOk() ? primary_display.GetGeometry() : wxGetClientDisplayRect();
}
static wxRect all_display_geometry()
{
wxRect geometry;
bool has_geometry = false;
const unsigned int display_count = wxDisplay::GetCount();
for (unsigned int i = 0; i < display_count; ++i) {
wxDisplay display(i);
if (!display.IsOk()) continue;
if (!has_geometry) {
geometry = display.GetGeometry();
has_geometry = true;
} else {
geometry.Union(display.GetGeometry());
}
}
return has_geometry ? geometry : wxGetClientDisplayRect();
}
void show_close_button(bool reset_idle_timer = true)
{
if (!m_close_button) return;
m_fade_timer.Stop();
m_close_alpha = m_close_hover ? 225 : 185;
m_close_button->set_alpha(m_close_alpha);
if (!m_close_button->IsShown()) m_close_button->Show();
position_close_button();
m_close_button->Raise();
#ifdef __APPLE__
attach_camera_fullscreen_overlay(this, m_close_button);
#endif
if (reset_idle_timer && !m_close_hover) start_hide_timer();
}
void start_hide_timer()
{
m_hide_timer.Stop();
m_hide_timer.StartOnce(3000);
}
void position_close_button()
{
if (!m_close_button) return;
const int button_size = FromDIP(44);
const int margin = FromDIP(24);
wxRect target_rect;
wxPoint mouse_screen = wxGetMousePosition();
int display_idx = wxDisplay::GetFromPoint(mouse_screen);
if (display_idx != wxNOT_FOUND) {
wxDisplay display(static_cast<unsigned int>(display_idx));
target_rect = display.GetGeometry();
} else {
target_rect = wxRect(wxPoint(0, 0), GetClientSize());
target_rect.SetPosition(ClientToScreen(wxPoint(0, 0)));
}
int screen_x = target_rect.GetRight() - button_size - margin;
int screen_y = target_rect.GetTop() + margin;
m_close_button->SetSize(wxSize(button_size, button_size));
m_close_button->Move(wxPoint(screen_x, screen_y));
}
StatusBasePanel *m_owner{nullptr};
wxWeakRef<wxWindow> m_top_level;
wxPanel *m_video_host{nullptr};
wxBoxSizer *m_video_sizer{nullptr};
wxMediaCtrl3 *m_media_ctrl{nullptr};
wxSize m_saved_max_size{wxDefaultSize};
CameraFullscreenCloseButton *m_close_button{nullptr};
wxTimer m_hide_timer;
wxTimer m_fade_timer;
#ifdef __APPLE__
void *m_escape_monitor{nullptr};
void *m_presentation_state{nullptr};
#endif
wxWindowID m_escape_accel_id{ wxID_ANY };
int m_close_alpha{ 0 };
int m_fade_start_alpha{ 0 };
int m_fade_elapsed_ms{ 0 };
bool m_close_hover{ false };
bool m_native_fullscreen{ false };
};
static const wxColour NORMAL_FAN_TEXT_COL = wxColour(107, 107, 107);
static const wxColour WARNING_INFO_BG_COL = wxColour(255, 111, 0);
static const wxColour STAGE_TEXT_COL = wxColour(107, 107, 107);
static const wxColour GROUP_STATIC_LINE_COL = wxColour(206, 206, 206);
/* font and foreground colors */
static const wxFont PAGE_TITLE_FONT = Label::Body_14;
// static const wxFont GROUP_TITLE_FONT = Label::sysFont(17);
static wxColour PAGE_TITLE_FONT_COL = wxColour(107, 107, 107);
static wxColour GROUP_TITLE_FONT_COL = wxColour(172, 172, 172);
static wxColour TEXT_LIGHT_FONT_COL = wxColour(107, 107, 107);
static wxImage fail_image;
/* size */
#define PAGE_TITLE_HEIGHT FromDIP(36)
#define PAGE_TITLE_TEXT_WIDTH FromDIP(200)
#define PAGE_TITLE_LEFT_MARGIN FromDIP(17)
#define GROUP_TITLE_LEFT_MARGIN FromDIP(15)
#define GROUP_TITLE_LINE_MARGIN FromDIP(11)
#define GROUP_TITLE_RIGHT_MARGIN FromDIP(15)
#define NORMAL_SPACING FromDIP(5)
#define PAGE_SPACING FromDIP(10)
#define PAGE_MIN_WIDTH FromDIP(574)
#define PROGRESSBAR_HEIGHT FromDIP(8)
#define SWITCH_BUTTON_SIZE (wxSize(FromDIP(40), -1))
#define TASK_THUMBNAIL_SIZE (wxSize(FromDIP(120), FromDIP(120)))
#define TASK_BUTTON_SIZE (wxSize(FromDIP(48), FromDIP(24)))
#define TASK_BUTTON_SIZE2 (wxSize(-1, FromDIP(24)))
#define Z_BUTTON_SIZE (wxSize(FromDIP(44), FromDIP(40)))
#define MISC_BUTTON_PANEL_SIZE (wxSize(FromDIP(136), FromDIP(55)))
#define MISC_BUTTON_1FAN_SIZE (wxSize(FromDIP(132), FromDIP(51)))
#define MISC_BUTTON_2FAN_SIZE (wxSize(FromDIP(66), FromDIP(51)))
#define MISC_BUTTON_3FAN_SIZE (wxSize(FromDIP(44), FromDIP(51)))
#define TEMP_CTRL_MIN_SIZE_ALIGN_ONE_ICON (wxSize(FromDIP(125), FromDIP(52)))
#define TEMP_CTRL_MIN_SIZE_ALIGN_TWO_ICON (wxSize(FromDIP(145), FromDIP(48)))
#define AXIS_MIN_SIZE (wxSize(FromDIP(258), FromDIP(258)))
#define EXTRUDER_IMAGE_SIZE (wxSize(FromDIP(48), FromDIP(76)))
static void market_model_scoring_page(int design_id)
{
std::string url;
std::string country_code = GUI::wxGetApp().app_config->get_country_code();
url = GUI::wxGetApp().get_model_http_url(country_code);
if (GUI::wxGetApp().getAgent()->get_model_mall_detail_url(&url, std::to_string(design_id)) == 0) {
std::string user_id = GUI::wxGetApp().getAgent()->get_user_id();
boost::algorithm::replace_first(url, "models", "u/" + user_id + "/rating");
// Prevent user_id from containing design_id
size_t sign_in = url.find("/rating");
std::string sub_url = url.substr(0, sign_in + 7);
url.erase(0, sign_in + 7);
boost::algorithm::replace_first(url, std::to_string(design_id), "");
url = sub_url + url;
try {
if (!url.empty()) { wxLaunchDefaultBrowser(url); }
} catch (...) {
return;
}
}
}
/*************************************************
Description:Extruder
**************************************************/
ExtruderImage::ExtruderImage(wxWindow *parent, wxWindowID id, int nozzle_num, const wxPoint &pos, const wxSize &size)
{
wxWindow::Create(parent, id, pos, wxSize(FromDIP(45), FromDIP(112)));
SetBackgroundColour(*wxWHITE);
m_nozzle_num = nozzle_num;
SetSize(wxSize(FromDIP(45), FromDIP(112)));
SetMinSize(wxSize(FromDIP(45), FromDIP(112)));
SetMaxSize(wxSize(FromDIP(45), FromDIP(112)));
m_pipe_filled_load = new ScalableBitmap(this, "pipe_of_loading_selected", 50);
m_pipe_filled_unload = new ScalableBitmap(this, "pipe_of_unloading_selected", 50);
m_pipe_empty_load = new ScalableBitmap(this, "pipe_of_empty", 50);
m_pipe_empty_unload = new ScalableBitmap(this, "pipe_of_empty", 50);
m_pipe_filled_load_unselected = new ScalableBitmap(this, "pipe_of_loading_unselected", 50);
m_pipe_filled_unload_unselected = new ScalableBitmap(this, "pipe_of_unloading_unselected", 50);
m_pipe_empty_load_unselected = new ScalableBitmap(this, "pipe_of_empty", 50);
m_pipe_empty_unload_unselected = new ScalableBitmap(this, "pipe_of_empty", 50);
m_left_extruder_active_filled = new ScalableBitmap(this, "left_extruder_active_filled", 62);
m_left_extruder_active_empty = new ScalableBitmap(this, "left_extruder_active_empty", 62);
m_left_extruder_unactive_filled = new ScalableBitmap(this, "left_extruder_unactive_filled", 62);
m_left_extruder_unactive_empty = new ScalableBitmap(this, "left_extruder_unactive_empty", 62);
m_right_extruder_active_filled = new ScalableBitmap(this, "right_extruder_active_filled", 62);
m_right_extruder_active_empty = new ScalableBitmap(this, "right_extruder_active_empty", 62);
m_right_extruder_unactive_filled = new ScalableBitmap(this, "right_extruder_unactive_filled", 62);
m_right_extruder_unactive_empty = new ScalableBitmap(this, "right_extruder_unactive_empty", 62);
m_extruder_single_nozzle_empty_load = new ScalableBitmap(this, "monitor_extruder_empty_load", 106);
m_extruder_single_nozzle_empty_unload = new ScalableBitmap(this, "monitor_extruder_empty_unload", 106);
m_extruder_single_nozzle_filled_load = new ScalableBitmap(this, "monitor_extruder_filled_load", 106);
m_extruder_single_nozzle_filled_unload = new ScalableBitmap(this, "monitor_extruder_filled_unload", 106);
Bind(wxEVT_PAINT, &ExtruderImage::paintEvent, this);
}
ExtruderImage::~ExtruderImage() {}
void ExtruderImage::msw_rescale()
{
// m_ams_extruder.SetSize(AMS_EXTRUDER_BITMAP_SIZE);
// auto image = m_ams_extruder.ConvertToImage();
// m_extruder_pipe = ScalableBitmap(this, "pipe_of_extruder_control", 50);
m_pipe_filled_load->msw_rescale();
m_pipe_filled_unload->msw_rescale();
m_pipe_empty_load->msw_rescale();
m_pipe_empty_unload->msw_rescale();
m_pipe_filled_load_unselected->msw_rescale();
m_pipe_filled_unload_unselected->msw_rescale();
m_pipe_empty_load_unselected->msw_rescale();
m_pipe_empty_unload_unselected->msw_rescale();
m_left_extruder_active_filled->msw_rescale();
m_left_extruder_active_empty->msw_rescale();
m_left_extruder_unactive_filled->msw_rescale();
m_left_extruder_unactive_empty->msw_rescale();
m_right_extruder_active_filled->msw_rescale();
m_right_extruder_active_empty->msw_rescale();
m_right_extruder_unactive_filled->msw_rescale();
m_right_extruder_unactive_empty->msw_rescale();
m_extruder_single_nozzle_empty_load->msw_rescale();
m_extruder_single_nozzle_empty_unload->msw_rescale();
m_extruder_single_nozzle_filled_load->msw_rescale();
m_extruder_single_nozzle_filled_unload->msw_rescale();
Layout();
Refresh();
}
void ExtruderImage::setExtruderCount(int nozzle_num) { m_nozzle_num = nozzle_num; }
void ExtruderImage::setExtruderUsed(std::string loc)
{
// current_nozzle_idx = nozzle_id;
if (current_nozzle_loc == loc) { return; }
current_nozzle_loc = loc;
Refresh();
}
void ExtruderImage::update(ExtruderState single_state) { m_single_ext_state = single_state; }
void ExtruderImage::update(ExtruderState right_state, ExtruderState left_state)
{
m_left_ext_state = left_state;
m_right_ext_state = right_state;
}
void ExtruderImage::paintEvent(wxPaintEvent &evt)
{
wxPaintDC dc(this);
render(dc);
}
void ExtruderImage::render(wxDC &dc)
{
#ifdef __WXMSW__
wxSize size = GetSize();
wxMemoryDC memdc;
wxBitmap bmp(size.x, size.y);
memdc.SelectObject(bmp);
memdc.Blit({0, 0}, size, &dc, {0, 0});
{
wxGCDC dc2(memdc);
doRender(dc2);
}
memdc.SelectObject(wxNullBitmap);
dc.DrawBitmap(bmp, 0, 0);
#else
doRender(dc);
#endif
}
void ExtruderImage::doRender(wxDC &dc)
{
auto size = GetSize();
// dc.DrawRectangle(0, FromDIP(5), size.x, size.y - FromDIP(5) - FromDIP(2));
auto pot = wxPoint(size.x / 2, (size.y - m_pipe_filled_load->GetBmpSize().y - m_left_extruder_active_filled->GetBmpSize().y) / 2);
if (m_nozzle_num >= 2) {
ScalableBitmap *left_nozzle_bmp;
ScalableBitmap *right_nozzle_bmp;
ScalableBitmap *left_pipe_bmp;
ScalableBitmap *right_pipe_bmp;
switch (m_right_ext_state) {
case Slic3r::GUI::FILLED_LOAD:
right_pipe_bmp = current_nozzle_loc == "right" ? m_pipe_filled_load : m_pipe_filled_load_unselected;
right_nozzle_bmp = current_nozzle_loc == "right" ? m_right_extruder_active_filled : m_right_extruder_unactive_filled;
break;
case Slic3r::GUI::FILLED_UNLOAD:
right_pipe_bmp = current_nozzle_loc == "right" ? m_pipe_filled_unload : m_pipe_filled_unload_unselected;
right_nozzle_bmp = current_nozzle_loc == "right" ? m_right_extruder_active_filled : m_right_extruder_unactive_filled;
break;
case Slic3r::GUI::EMPTY_LOAD:
right_pipe_bmp = current_nozzle_loc == "right" ? m_pipe_empty_load : m_pipe_empty_load_unselected;
right_nozzle_bmp = current_nozzle_loc == "right" ? m_right_extruder_active_empty : m_right_extruder_unactive_empty;
break;
case Slic3r::GUI::EMPTY_UNLOAD:
right_pipe_bmp = current_nozzle_loc == "right" ? m_pipe_empty_unload : m_pipe_empty_unload_unselected;
right_nozzle_bmp = current_nozzle_loc == "right" ? m_right_extruder_active_empty : m_right_extruder_unactive_empty;
break;
default: break;
}
switch (m_left_ext_state) {
case Slic3r::GUI::FILLED_LOAD:
left_pipe_bmp = current_nozzle_loc == "left" ? m_pipe_filled_load : m_pipe_filled_load_unselected;
left_nozzle_bmp = current_nozzle_loc == "left" ? m_left_extruder_active_filled : m_left_extruder_unactive_filled;
break;
case Slic3r::GUI::FILLED_UNLOAD:
left_pipe_bmp = current_nozzle_loc == "left" ? m_pipe_filled_unload : m_pipe_filled_unload_unselected;
left_nozzle_bmp = current_nozzle_loc == "left" ? m_left_extruder_active_filled : m_left_extruder_unactive_filled;
break;
case Slic3r::GUI::EMPTY_LOAD:
left_pipe_bmp = current_nozzle_loc == "left" ? m_pipe_empty_load : m_pipe_empty_load_unselected;
left_nozzle_bmp = current_nozzle_loc == "left" ? m_left_extruder_active_empty : m_left_extruder_unactive_empty;
break;
case Slic3r::GUI::EMPTY_UNLOAD:
left_pipe_bmp = current_nozzle_loc == "left" ? m_pipe_empty_unload : m_pipe_empty_unload_unselected;
left_nozzle_bmp = current_nozzle_loc == "left" ? m_left_extruder_active_empty : m_left_extruder_unactive_empty;
break;
default: break;
}
left_pipe_bmp = m_pipe_filled_load;
right_pipe_bmp = m_pipe_filled_load;
dc.DrawBitmap(left_pipe_bmp->bmp(), pot.x - left_nozzle_bmp->GetBmpWidth() / 2 - left_pipe_bmp->GetBmpWidth() / 2 + left_pipe_bmp->GetBmpWidth() / 5, pot.y);
dc.DrawBitmap(left_nozzle_bmp->bmp(), pot.x - left_nozzle_bmp->GetBmpWidth(), pot.y + left_pipe_bmp->GetBmpSize().y);
dc.DrawBitmap(right_pipe_bmp->bmp(), pot.x + right_nozzle_bmp->GetBmpWidth() / 2 - right_pipe_bmp->GetBmpWidth() / 2 - right_pipe_bmp->GetBmpWidth() / 5, pot.y);
dc.DrawBitmap(right_nozzle_bmp->bmp(), pot.x, pot.y + right_pipe_bmp->GetBmpSize().y);
} else {
ScalableBitmap *nozzle_bmp = nullptr;
switch (m_single_ext_state) {
case Slic3r::GUI::FILLED_LOAD: nozzle_bmp = m_extruder_single_nozzle_filled_load; break;
case Slic3r::GUI::FILLED_UNLOAD: nozzle_bmp = m_extruder_single_nozzle_filled_unload; break;
case Slic3r::GUI::EMPTY_LOAD: nozzle_bmp = m_extruder_single_nozzle_empty_load; break;
case Slic3r::GUI::EMPTY_UNLOAD: nozzle_bmp = m_extruder_single_nozzle_empty_unload; break;
default: break;
}
if (nozzle_bmp) { dc.DrawBitmap(nozzle_bmp->bmp(), pot.x - nozzle_bmp->GetBmpWidth() / 2, (size.y - nozzle_bmp->GetBmpHeight()) / 2); }
}
}
#define SWITCHING_STATUS_BTN_SIZE wxSize(FromDIP(25), FromDIP(26))
ExtruderSwithingStatus::ExtruderSwithingStatus(wxWindow *parent) : wxPanel(parent)
{
m_switching_status_label = new Label(this);
m_switching_status_label->SetFont(::Label::Body_13);
if (parent) { m_switching_status_label->SetBackgroundColour(parent->GetBackgroundColour()); }
StateColor e_ctrl_bg(std::pair<wxColour, int>(BUTTON_PRESS_COL, StateColor::Pressed), std::pair<wxColour, int>(BUTTON_NORMAL1_COL, StateColor::Normal));
StateColor e_ctrl_bd(std::pair<wxColour, int>(BUTTON_HOVER_COL, StateColor::Hovered), std::pair<wxColour, int>(BUTTON_NORMAL1_COL, StateColor::Normal));
m_button_quit = new Button(this, _CTX(L_CONTEXT("Quit", "Quit_Switching"), "Quit_Switching"), "", 0, FromDIP(22));
m_button_quit->SetFont(::Label::Body_13);
m_button_quit->Bind(wxEVT_BUTTON, &ExtruderSwithingStatus::on_quit, this);
m_button_quit->SetMinSize(SWITCHING_STATUS_BTN_SIZE);
m_button_quit->SetMaxSize(SWITCHING_STATUS_BTN_SIZE);
m_button_quit->SetBackgroundColor(e_ctrl_bg);
m_button_quit->SetBorderColor(e_ctrl_bd);
m_button_quit->SetBorderWidth(2);
if (parent) { m_button_quit->SetBackgroundColour(parent->GetBackgroundColour()); }
m_button_retry = new Button(this, _L("Retry"), "", 0, FromDIP(22));
m_button_retry->SetFont(::Label::Body_13);
m_button_retry->Bind(wxEVT_BUTTON, &ExtruderSwithingStatus::on_retry, this);
m_button_retry->SetMinSize(SWITCHING_STATUS_BTN_SIZE);
m_button_retry->SetMaxSize(SWITCHING_STATUS_BTN_SIZE);
m_button_retry->SetBackgroundColor(e_ctrl_bg);
m_button_retry->SetBorderColor(e_ctrl_bd);
m_button_retry->SetBorderWidth(2);
if (parent) { m_button_retry->SetBackgroundColour(parent->GetBackgroundColour()); }
wxBoxSizer *btn_sizer = new wxBoxSizer(wxHORIZONTAL);
btn_sizer->Add(m_button_quit, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT, FromDIP(10));
btn_sizer->Add(m_button_retry, 0, wxALIGN_CENTER_VERTICAL, 0);
wxBoxSizer *main_sizer = new wxBoxSizer(wxVERTICAL);
main_sizer->Add(m_switching_status_label, 0, wxALIGN_CENTER_HORIZONTAL | wxTOP, FromDIP(10));
main_sizer->Add(btn_sizer, 0, wxALIGN_CENTER_HORIZONTAL | wxTOP, FromDIP(10));
SetSizer(main_sizer);
Layout();
}
void ExtruderSwithingStatus::updateBy(MachineObject *obj)
{
m_obj = obj;
if (!m_obj) {
Show(false);
} else {
/*do not display while command sended in a mean while*/
if ((time(nullptr) - m_last_ctrl_time) > HOLD_TIME_6SEC) { updateBy(obj->GetExtderSystem()); }
}
}
void ExtruderSwithingStatus::updateBy(const DevExtderSystem *ext_system)
{
Show(ext_system->GetTotalExtderCount() > 1);
if (!IsShown()) { return; }
auto state = ext_system->GetSwitchState();
{
if (state == DevExtderSwitchState::ES_SWITCHING) {
m_switching_status_label->SetLabel(_L("Switching..."));
m_switching_status_label->SetForegroundColour(StateColor::darkModeColorFor("#262E30"));
m_switching_status_label->Show(true);
} else if (state == DevExtderSwitchState::ES_SWITCHING_FAILED) {
m_switching_status_label->SetLabel(_L("Switching failed"));
m_switching_status_label->SetForegroundColour(StateColor::darkModeColorFor(*wxRED));
m_switching_status_label->Show(true);
} else {
m_switching_status_label->Show(false);
}
}
if (state != DevExtderSwitchState::ES_SWITCHING_FAILED) {
showQuitBtn(false);
showRetryBtn(false);
return;
}
/*can not quit if it's printing*/
if (m_obj && !m_obj->is_in_printing() && !m_obj->is_in_printing_pause()) { showQuitBtn(true); }
showRetryBtn(true);
}
void ExtruderSwithingStatus::showQuitBtn(bool show)
{
if (m_button_quit->IsShown() != show) {
m_button_quit->Show(show);
Layout();
}
}
void ExtruderSwithingStatus::showRetryBtn(bool show)
{
if (m_button_retry->IsShown() != show) {
m_button_retry->Show(show);
Layout();
}
}
bool ExtruderSwithingStatus::has_content_shown() const
{
if (!IsShown()) { return false; }
if (!m_switching_status_label->IsShown() && !m_button_quit->IsShown() && !m_button_retry->IsShown()) { return false; }
return true;
}
void ExtruderSwithingStatus::msw_rescale()
{
m_button_quit->SetMinSize(SWITCHING_STATUS_BTN_SIZE);
m_button_quit->SetMaxSize(SWITCHING_STATUS_BTN_SIZE);
m_button_retry->SetMinSize(SWITCHING_STATUS_BTN_SIZE);
m_button_retry->SetMaxSize(SWITCHING_STATUS_BTN_SIZE);
Layout();
}
void ExtruderSwithingStatus::on_quit(wxCommandEvent &event)
{
Show(false);
if (m_obj) {
m_obj->command_ams_control("abort");
m_last_ctrl_time = time(nullptr);
}
}
void ExtruderSwithingStatus::on_retry(wxCommandEvent &event)
{
Show(false);
if (m_obj) {
m_obj->command_ams_control("resume");
m_last_ctrl_time = time(nullptr);
}
}
PrintingTaskPanel::PrintingTaskPanel(wxWindow *parent, PrintingTaskType type) : wxPanel(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL)
{
m_type = type;
m_question_button = nullptr;
create_panel(this);
SetBackgroundColour(*wxWHITE);
m_bitmap_background = ScalableBitmap(this, "thumbnail_grid", m_bitmap_thumbnail->GetSize().y);
m_bitmap_thumbnail->Bind(wxEVT_PAINT, &PrintingTaskPanel::paint, this);
}
PrintingTaskPanel::~PrintingTaskPanel()
{
if (m_question_button) {
delete m_question_button;
m_question_button = nullptr;
}
}
void PrintingTaskPanel::create_panel(wxWindow *parent)
{
wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
wxBoxSizer *bSizer_printing_title = new wxBoxSizer(wxHORIZONTAL);
m_panel_printing_title = new wxPanel(parent, wxID_ANY, wxDefaultPosition, wxSize(-1, PAGE_TITLE_HEIGHT), wxTAB_TRAVERSAL);
m_panel_printing_title->SetBackgroundColour(STATUS_TITLE_BG);
m_staticText_printing = new wxStaticText(m_panel_printing_title, wxID_ANY, _L("Printing Progress"));
m_staticText_printing->Wrap(-1);
// m_staticText_printing->SetFont(PAGE_TITLE_FONT);
m_staticText_printing->SetForegroundColour(PAGE_TITLE_FONT_COL);
bSizer_printing_title->Add(m_staticText_printing, 0, wxALIGN_CENTER_VERTICAL | wxLEFT, PAGE_TITLE_LEFT_MARGIN);
bSizer_printing_title->Add(0, 0, 1, wxEXPAND, 0);
m_panel_printing_title->SetSizer(bSizer_printing_title);
m_panel_printing_title->Layout();
bSizer_printing_title->Fit(m_panel_printing_title);
m_bitmap_thumbnail = new wxStaticBitmap(parent, wxID_ANY, m_thumbnail_placeholder.bmp(), wxDefaultPosition, TASK_THUMBNAIL_SIZE, 0);
m_bitmap_thumbnail->SetMaxSize(TASK_THUMBNAIL_SIZE);
m_bitmap_thumbnail->SetMinSize(TASK_THUMBNAIL_SIZE);
wxBoxSizer *bSizer_subtask_info = new wxBoxSizer(wxVERTICAL);
wxBoxSizer *bSizer_task_name = new wxBoxSizer(wxVERTICAL);
wxBoxSizer *bSizer_task_name_hor = new wxBoxSizer(wxHORIZONTAL);
wxPanel *task_name_panel = new wxPanel(parent);
m_staticText_subtask_value = new wxStaticText(task_name_panel, wxID_ANY, _L("N/A"), wxDefaultPosition, wxDefaultSize, wxALIGN_LEFT | wxST_ELLIPSIZE_END);
m_staticText_subtask_value->SetMaxSize(wxSize(FromDIP(600), -1));
m_staticText_subtask_value->Wrap(-1);
#ifdef __WXOSX_MAC__
m_staticText_subtask_value->SetFont(::Label::Body_13);
#else
m_staticText_subtask_value->SetFont(wxFont(13, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL, false, wxT("HarmonyOS Sans SC")));
#endif
m_staticText_subtask_value->SetForegroundColour(wxColour(44, 44, 46));
m_bitmap_static_use_time = new wxStaticBitmap(task_name_panel, wxID_ANY, m_bitmap_use_time.bmp(), wxDefaultPosition, wxSize(FromDIP(16), FromDIP(16)));
m_staticText_consumption_of_time = new wxStaticText(task_name_panel, wxID_ANY, "0m", wxDefaultPosition, wxDefaultSize, 0);
m_staticText_consumption_of_time->SetFont(::Label::Body_12);
m_staticText_consumption_of_time->SetForegroundColour(wxColour(0x68, 0x68, 0x68));
m_staticText_consumption_of_time->Wrap(-1);
m_bitmap_static_use_weight = new wxStaticBitmap(task_name_panel, wxID_ANY, m_bitmap_use_weight.bmp(), wxDefaultPosition, wxSize(FromDIP(16), FromDIP(16)));
m_staticText_consumption_of_weight = new wxStaticText(task_name_panel, wxID_ANY, "0g", wxDefaultPosition, wxDefaultSize, 0);
m_staticText_consumption_of_weight->SetFont(::Label::Body_12);