Files
OrcaSlicer/src/slic3r/GUI/Monitor.cpp
T
HanifKoh 4895bc03b4 Remove Unused Project Includes and Forward-Declare Where a Type Is Only Referenced (#16099)
* Remove Unused Project Includes and Forward-Declare Where a Type Is Only Referenced

Generated with include-what-you-use and applied conservatively. Only OrcaSlicer's own headers, the ones under src/ and tests/, are removed or forward-declared; standard-library and third-party includes are left alone. An include is removed only when both the Release and the Debug configuration leave it unused, never from inside a conditional block, and never from a file with platform-specific blocks, which only gain includes. Files whose only use of a header sits behind a feature or debug macro (libvgcode's OpenGL ES and marker code, the ARACHNE/TESTS_EXPORT_SVGS debug output) keep their includes.

clonable_ptr.hpp gains #pragma once; it had no include guard and was only safe while Config.hpp was its sole includer.

* Remove Unused Project Includes From Files With Platform-Specific Code

A Linux include-what-you-use run cannot see the code inside _WIN32, __APPLE__ or __linux__ blocks, so its verdict is only taken where nothing the removed header declares, directly or through what it includes, is named inside those blocks. Removals also have to hold in both the Release and Debug configuration and never touch a line inside a conditional block.

* Restore the libslic3r Precompiled Header and Direct Includes Lost in the Platform Pass

The platform-file pass treated pchheader.hpp as an ordinary header and
emptied it, and left GUI_Preview.hpp and 14 other files relying on
headers they no longer reached directly.

* Restore MainFrame.hpp in ParamsDialog.cpp for the Windows-Only Reparent Call

* Include Headers That Files Reached Through Ones the Cleanup Removed

* Drop Includes Duplicated by the Cleanup or by Main's Own Additions

* Leave PreciseSeam.cpp as Main Has It After the Precise Seam Rework
2026-10-05 16:47:17 +08:00

624 lines
20 KiB
C++

#include "Tab.hpp"
#include "libslic3r/Model.hpp"
#include "libslic3r/AppConfig.hpp"
#include "slic3r/Utils/bambu_networking.hpp"
#include "slic3r/Utils/NetworkAgent.hpp"
#include "slic3r/GUI/Monitor.hpp"
#include "slic3r/GUI/Widgets/StateColor.hpp"
#include <utility>
#include "slic3r/GUI/Field.hpp"
#include <cstddef>
#include "slic3r/GUI/SelectMachinePop.hpp"
#include "slic3r/GUI/HMSPanel.hpp"
#include "slic3r/GUI/Tabbook.hpp"
#include "slic3r/GUI/StatusPanel.hpp"
#include "slic3r/GUI/UpgradePanel.hpp"
#include "slic3r/GUI/Widgets/SideTools.hpp"
#include "slic3r/GUI/Printer/PrinterFileSystem.h"
#include <wx/app.h>
#include <wx/bookctrl.h>
#include <wx/button.h>
#include <wx/event.h>
#include <wx/gdicmn.h>
#include <wx/panel.h>
#include <wx/notebook.h>
#include <wx/scrolwin.h>
#include <wx/sizer.h>
#include <wx/bmpcbox.h>
#include <wx/bmpbuttn.h>
#include <wx/string.h>
#include <wx/timer.h>
#include <wx/treectrl.h>
#include <wx/imaglist.h>
#include <wx/settings.h>
#include <wx/filedlg.h>
#include <wx/wupdlock.h>
#include <wx/dataview.h>
#include <wx/tglbtn.h>
#include "wxExtensions.hpp"
#include "GUI_App.hpp"
#include "GUI_ObjectList.hpp"
#include "Plater.hpp"
#include "MainFrame.hpp"
#include "MediaPlayCtrl.h"
#include "MediaFilePanel.h"
#include "Plater.hpp"
#include "BindDialog.hpp"
#include "DeviceCore/DevManager.h"
#include <boost/log/trivial.hpp>
#include "slic3r/GUI/DeviceCore/DevHMS.h"
#include "slic3r/GUI/DeviceManager.hpp"
#include "slic3r/GUI/HMS.hpp"
#include "slic3r/GUI/I18N.hpp"
#include "slic3r/GUI/Widgets/Button.hpp"
namespace Slic3r {
namespace GUI {
#define REFRESH_INTERVAL 1000
AddMachinePanel::AddMachinePanel(wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style, const wxString& name)
: wxPanel(parent, id, pos, size, style)
{
this->SetBackgroundColour(0xEEEEEE);
wxBoxSizer* topsizer = new wxBoxSizer(wxVERTICAL);
topsizer->AddStretchSpacer();
m_bitmap_empty = new wxStaticBitmap(this, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxDefaultSize, 0);
m_bitmap_empty->SetBitmap(create_scaled_bitmap("monitor_status_empty", nullptr, 250));
topsizer->Add(m_bitmap_empty, 0, wxALL | wxALIGN_CENTER_HORIZONTAL, 0);
topsizer->AddSpacer(46);
wxBoxSizer* horiz_sizer = new wxBoxSizer(wxHORIZONTAL);
horiz_sizer->Add(0, 0, 538, 0, 0);
wxBoxSizer* btn_sizer = new wxBoxSizer(wxVERTICAL);
m_button_add_machine = new Button(this, "", "monitor_add_machine", FromDIP(24));
m_button_add_machine->SetCornerRadius(FromDIP(12));
StateColor button_bg(
std::pair<wxColour, int>(0xCECECE, StateColor::Pressed),
std::pair<wxColour, int>(0xCECECE, StateColor::Hovered),
std::pair<wxColour, int>(this->GetBackgroundColour(), StateColor::Normal)
);
m_button_add_machine->SetBackgroundColor(button_bg);
m_button_add_machine->SetBorderColor(0x909090);
m_button_add_machine->SetMinSize(wxSize(96, 39));
btn_sizer->Add(m_button_add_machine, 0, wxALL | wxALIGN_CENTER_HORIZONTAL, 5);
m_staticText_add_machine = new wxStaticText(this, wxID_ANY, _L("click to add machine"), wxDefaultPosition, wxDefaultSize, 0);
m_staticText_add_machine->Wrap(-1);
m_staticText_add_machine->SetForegroundColour(0x909090);
btn_sizer->Add(m_staticText_add_machine, 0, wxALL | wxALIGN_CENTER_HORIZONTAL, 5);
horiz_sizer->Add(btn_sizer);
horiz_sizer->Add(0, 0, 624, 0, 0);
topsizer->Add(horiz_sizer, 0, wxEXPAND, 0);
topsizer->AddStretchSpacer();
this->SetSizer(topsizer);
this->Layout();
// Connect Events
m_button_add_machine->Connect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(AddMachinePanel::on_add_machine), NULL, this);
}
void AddMachinePanel::msw_rescale() {
}
void AddMachinePanel::on_add_machine(wxCommandEvent& event) {
// load a url
}
AddMachinePanel::~AddMachinePanel() {
m_button_add_machine->Disconnect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(AddMachinePanel::on_add_machine), NULL, this);
}
MonitorPanel::MonitorPanel(wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style)
: wxPanel(parent, id, pos, size, style),
m_select_machine(SelectMachinePopup(this))
{
SetBackgroundColour(*wxWHITE);
#ifdef __WINDOWS__
SetDoubleBuffered(true);
#endif //__WINDOWS__
init_bitmap();
init_tabpanel();
m_main_sizer = new wxBoxSizer(wxHORIZONTAL);
m_main_sizer->Add(m_tabpanel, 1, wxEXPAND | wxLEFT, 0);
SetSizerAndFit(m_main_sizer);
init_timer();
m_side_tools->get_panel()->Connect(wxEVT_LEFT_DOWN, wxMouseEventHandler(MonitorPanel::on_printer_clicked), NULL, this);
Bind(wxEVT_TIMER, &MonitorPanel::on_timer, this);
Bind(wxEVT_SIZE, &MonitorPanel::on_size, this);
Bind(wxEVT_COMMAND_CHOICE_SELECTED, &MonitorPanel::on_select_printer, this);
m_select_machine.Bind(EVT_FINISHED_UPDATE_MACHINE_LIST, [this](wxCommandEvent& e) {
m_side_tools->start_interval();
});
Bind(EVT_ALREADY_READ_HMS, [this](wxCommandEvent& e) {
auto key = e.GetString().ToStdString();
auto iter = m_hms_panel->temp_hms_list.find(key);
if (iter != m_hms_panel->temp_hms_list.end()) {
m_hms_panel->temp_hms_list[key].set_read();
}
update_hms_tag();
e.Skip();
});
}
MonitorPanel::~MonitorPanel()
{
m_side_tools->get_panel()->Disconnect(wxEVT_LEFT_DOWN, wxMouseEventHandler(MonitorPanel::on_printer_clicked), NULL, this);
if (m_refresh_timer)
m_refresh_timer->Stop();
delete m_refresh_timer;
}
void MonitorPanel::init_bitmap()
{
m_signal_strong_img = create_scaled_bitmap("monitor_signal_strong", nullptr, 24);
m_signal_middle_img = create_scaled_bitmap("monitor_signal_middle", nullptr, 24);
m_signal_weak_img = create_scaled_bitmap("monitor_signal_weak", nullptr, 24);
m_signal_no_img = create_scaled_bitmap("monitor_signal_no", nullptr, 24);
m_printer_img = create_scaled_bitmap("monitor_printer", nullptr, 26);
m_arrow_img = create_scaled_bitmap("monitor_arrow",nullptr, 14);
}
void MonitorPanel::init_timer()
{
m_refresh_timer = new wxTimer();
m_refresh_timer->SetOwner(this);
m_refresh_timer->Start(REFRESH_INTERVAL);
if (update_flag) { update_all();}
}
void MonitorPanel::init_tabpanel()
{
m_side_tools = new SideTools(this, wxID_ANY);
wxBoxSizer* sizer_side_tools = new wxBoxSizer(wxVERTICAL);
sizer_side_tools->Add(m_side_tools, 1, wxEXPAND, 0);
m_tabpanel = new Tabbook(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, sizer_side_tools, wxNB_LEFT | wxTAB_TRAVERSAL | wxNB_NOPAGETHEME);
m_side_tools->set_table_panel(m_tabpanel);
m_tabpanel->SetBackgroundColour(wxColour("#FEFFFF"));
m_tabpanel->Bind(wxEVT_BOOKCTRL_PAGE_CHANGED, [this](wxBookCtrlEvent& e) {
auto page = m_tabpanel->GetCurrentPage();
if (page == m_media_file_panel) {
auto title = m_tabpanel->GetPageText(m_tabpanel->GetSelection());
m_media_file_panel->SwitchStorage(title == _L("Storage"));
}
// The first page is selected while the panel is built off screen.
if (page->IsShownOnScreen())
page->SetFocus();
update_all();
}, m_tabpanel->GetId());
m_status_info_panel = new StatusPanel(m_tabpanel);
// Queued before the page is added, since adding it selects it and runs the handler above,
// where built() must already be false.
add_build_steps_of(*m_status_info_panel);
m_tabpanel->AddPage(m_status_info_panel, _L("Status"), true);
add_build_step([this] {
m_media_file_panel = new MediaFilePanel(m_tabpanel);
m_tabpanel->AddPage(m_media_file_panel, _L("Storage"), false);
});
add_build_step([this] {
m_upgrade_panel = new UpgradePanel(m_tabpanel);
m_tabpanel->AddPage(m_upgrade_panel, _L_CONTEXT(L_CONTEXT("Update", "Firmware"), "Firmware"), false);
});
add_build_step([this] {
m_hms_panel = new HMSPanel(m_tabpanel);
m_tabpanel->AddPage(m_hms_panel, _L("Assistant(HMS)"), false);
std::string network_ver = Slic3r::NetworkAgent::get_version();
if (!network_ver.empty()) {
m_tabpanel->SetFooterText(wxString::Format(_L("Network plug-in v%s"), network_ver));
}
show_status((int)MonitorStatus::MONITOR_NO_PRINTER);
});
}
void MonitorPanel::set_default()
{
obj = nullptr;
last_conn_type = "undefined";
/* reset status panel*/
m_status_info_panel->set_default();
/* reset side tool*/
//m_bitmap_wifi_signal->SetBitmap(wxNullBitmap);
}
wxWindow* MonitorPanel::create_side_tools()
{
//TEST function
//m_bitmap_wifi_signal->Connect(wxEVT_LEFT_DCLICK, wxMouseEventHandler(MonitorPanel::on_update_all), NULL, this);
wxBoxSizer* sizer = new wxBoxSizer(wxVERTICAL);
auto panel = new wxPanel(this, wxID_ANY, wxDefaultPosition, wxSize(0, FromDIP(50)));
panel->SetBackgroundColour(wxColour(135,206,250));
panel->SetSizer(sizer);
sizer->Layout();
panel->Fit();
return panel;
}
void MonitorPanel::on_sys_color_changed()
{
m_status_info_panel->on_sys_color_changed();
m_upgrade_panel->on_sys_color_changed();
m_media_file_panel->Rescale();
}
void MonitorPanel::msw_rescale()
{
init_bitmap();
/* side_tool rescale */
m_side_tools->msw_rescale();
m_tabpanel->Rescale();
//m_status_add_machine_panel->msw_rescale();
m_status_info_panel->msw_rescale();
m_media_file_panel->Rescale();
m_upgrade_panel->msw_rescale();
m_hms_panel->msw_rescale();
Layout();
Refresh();
}
void MonitorPanel::select_machine(std::string machine_sn)
{
BOOST_LOG_TRIVIAL(trace) << "Orca diagnostic: MonitorPanel::select_machine queueing machine_sn=" << machine_sn;
wxCommandEvent *event = new wxCommandEvent(wxEVT_COMMAND_CHOICE_SELECTED);
event->SetString(machine_sn);
wxQueueEvent(this, event);
}
void MonitorPanel::on_timer(wxTimerEvent& event)
{
// MediaPlayCtrl may yield the event loop while it joins its camera worker
// during window teardown. Do not let a queued monitor refresh touch panels
// that are already being destroyed.
if (!wxGetApp().is_closing() && update_flag) {
update_all();
//Layout();
}
}
void MonitorPanel::on_select_printer(wxCommandEvent& event)
{
Slic3r::DeviceManager* dev = Slic3r::GUI::wxGetApp().getDeviceManager();
const std::string requested_dev_id = event.GetString().ToStdString();
BOOST_LOG_TRIVIAL(trace) << "Orca diagnostic: MonitorPanel::on_select_printer requested_dev_id="
<< requested_dev_id << " device_manager=" << (dev ? "set" : "null");
if (!dev) return;
if ( dev->get_selected_machine() && (dev->get_selected_machine()->get_dev_id() != event.GetString().ToStdString()) && m_hms_panel) {
m_hms_panel->clear_hms_tag();
}
const bool selected = dev->set_selected_machine(requested_dev_id);
BOOST_LOG_TRIVIAL(trace) << "Orca diagnostic: MonitorPanel::on_select_printer set_selected_machine result="
<< selected << " selected_dev_id="
<< (dev->get_selected_machine() ? dev->get_selected_machine()->get_dev_id() : "<null>");
if (!selected)
return;
set_default();
update_all();
on_machine_selected(dev->get_selected_machine());
Layout();
}
void MonitorPanel::on_machine_selected(MachineObject* obj)
{
if (obj == nullptr)
return;
obj->last_cali_version = -1;
obj->reset_pa_cali_history_result();
obj->reset_pa_cali_result();
Sidebar& sidebar = GUI::wxGetApp().sidebar();
sidebar.update_sync_status(obj);
sidebar.set_need_auto_sync_after_connect_printer(sidebar.need_auto_sync_extruder_list_after_connect_priner(obj));
}
void MonitorPanel::on_printer_clicked(wxMouseEvent &event)
{
auto mouse_pos = ClientToScreen(event.GetPosition());
wxPoint rect = m_side_tools->ClientToScreen(wxPoint(0, 0));
if (!m_side_tools->is_in_interval()) {
wxPoint pos = m_side_tools->ClientToScreen(wxPoint(0, 0));
pos.y += m_side_tools->GetRect().height;
//pos.x = pos.x < 0? 0:pos.x;
m_select_machine.Move(pos);
#ifdef __linux__
m_select_machine.SetSize(wxSize(m_side_tools->GetSize().x, -1));
m_select_machine.SetMaxSize(wxSize(m_side_tools->GetSize().x, -1));
m_select_machine.SetMinSize(wxSize(m_side_tools->GetSize().x, -1));
#endif
m_select_machine.Popup();
}
}
void MonitorPanel::on_size(wxSizeEvent &event)
{
Layout();
//event.Skip();
//Refresh();
}
void MonitorPanel::update_all()
{
// Every page exists once the last build step has run.
if (!built())
return;
NetworkAgent* m_agent = wxGetApp().getAgent();
Slic3r::DeviceManager* dev = Slic3r::GUI::wxGetApp().getDeviceManager();
if (!dev) return;
obj = dev->get_selected_machine();
if (!obj) {
show_status((int)MONITOR_NO_PRINTER);
m_hms_panel->clear_hms_tag();
m_tabpanel->GetBtnsListCtrl()->showNewTag(3, false);
if (m_status_info_panel->IsShown()) {
m_status_info_panel->m_media_play_ctrl->SetMachineObject(obj);
m_status_info_panel->update(obj);
}
return;
}
if (obj->connection_type() != last_conn_type) { last_conn_type = obj->connection_type(); }
m_side_tools->update_status(obj);
if (obj->is_connecting()) {
show_status(MONITOR_CONNECTING);
return;
} else if (!obj->is_connected()) {
int server_status = 0;
// only disconnected server in cloud mode
if (obj->connection_type() != "lan") {
if (m_agent) {
server_status = m_agent->is_server_connected(wxGetApp().get_printer_cloud_provider()) ? 0 : (int)MONITOR_DISCONNECTED_SERVER;
}
}
show_status((int) MONITOR_DISCONNECTED + server_status);
return;
}
show_status(MONITOR_NORMAL);
auto current_page = m_tabpanel->GetCurrentPage();
if (current_page == m_status_info_panel) {
if (m_status_info_panel->IsShown()) {
m_status_info_panel->obj = obj;
m_status_info_panel->m_media_play_ctrl->SetMachineObject(obj);
m_status_info_panel->update(obj);
}
} else if (current_page == m_upgrade_panel) {
m_upgrade_panel->update(obj);
} else if (current_page == m_media_file_panel) {
m_media_file_panel->UpdateByObj(obj);
}
if (current_page == m_hms_panel || (obj->GetHMS()->GetHMSItems().size() != m_hms_panel->temp_hms_list.size())) {
m_hms_panel->update(obj);
}
update_hms_tag();
}
void MonitorPanel::update_hms_tag()
{
for (auto hmsitem : m_hms_panel->temp_hms_list) {
if (!obj) { break;}
const wxString &msg = wxGetApp().get_hms_query()->query_hms_msg(obj->get_dev_id(), hmsitem.second.get_long_error_code());
if (msg.empty()){ continue;} /*STUDIO-10363 it's hidden message*/
if (!hmsitem.second.has_read()) {
//show HMS new tag
m_tabpanel->GetBtnsListCtrl()->showNewTag(3, true);
return;
}
}
m_tabpanel->GetBtnsListCtrl()->showNewTag(3, false);
}
bool MonitorPanel::Show(bool show)
{
NetworkAgent* m_agent = wxGetApp().getAgent();
DeviceManager* dev = Slic3r::GUI::wxGetApp().getDeviceManager();
if (show) {
#ifdef __APPLE__
wxGetApp().mainframe->SetMinSize(wxGetApp().plater()->GetMinSize());
#endif
start_update();
update_network_version_footer();
m_refresh_timer->Stop();
m_refresh_timer->SetOwner(this);
m_refresh_timer->Start(REFRESH_INTERVAL);
if (update_flag) { update_all(); }
if (dev) {
//set a default machine when obj is null
obj = dev->get_selected_machine();
if (obj == nullptr) {
dev->load_last_machine();
} else {
obj->reset_update_time();
}
}
} else {
stop_update();
m_refresh_timer->Stop();
}
return wxPanel::Show(show);
}
void MonitorPanel::show_status(int status)
{
if (!built()) return;
if (last_status == status)return;
if ((last_status & (int)MonitorStatus::MONITOR_CONNECTING) != 0) {
NetworkAgent* agent = wxGetApp().getAgent();
json j;
j["dev_id"] = obj ? obj->get_dev_id() : "obj_nullptr";
if ((status & (int)MonitorStatus::MONITOR_DISCONNECTED) != 0) {
j["result"] = "failed";
}
else if ((status & (int)MonitorStatus::MONITOR_NORMAL) != 0) {
j["result"] = "success";
}
}
last_status = status;
BOOST_LOG_TRIVIAL(info) << "monitor: show_status = " << status;
//Freeze();
// update panels
if (m_side_tools) { m_side_tools->show_status(status); };
m_status_info_panel->show_status(status);
m_hms_panel->show_status(status);
m_upgrade_panel->show_status(status);
if ((status & (int)MonitorStatus::MONITOR_NO_PRINTER) != 0) {
set_default();
m_tabpanel->Layout();
} else if (((status & (int)MonitorStatus::MONITOR_NORMAL) != 0)
|| ((status & (int)MonitorStatus::MONITOR_DISCONNECTED) != 0)
|| ((status & (int) MonitorStatus::MONITOR_DISCONNECTED_SERVER) != 0)
|| ((status & (int)MonitorStatus::MONITOR_CONNECTING) != 0) )
{
if (((status & (int) MonitorStatus::MONITOR_DISCONNECTED) != 0)
|| ((status & (int) MonitorStatus::MONITOR_DISCONNECTED_SERVER) != 0)
|| ((status & (int)MonitorStatus::MONITOR_CONNECTING) != 0))
{
set_default();
}
m_tabpanel->Layout();
}
Layout();
//Thaw();
}
std::string MonitorPanel::get_string_from_tab(PrinterTab tab)
{
switch (tab) {
case PT_STATUS :
return "status";
case PT_MEDIA:
return "sd_card";
case PT_UPDATE:
return "update";
case PT_HMS:
return "HMS";
case PT_DEBUG:
return "debug";
default:
return "";
}
return "";
}
void MonitorPanel::jump_to_HMS()
{
if (!this->IsShown())
return;
auto page = m_tabpanel->GetCurrentPage();
if (page && page != m_hms_panel)
m_tabpanel->SetSelection(PT_HMS);
}
void MonitorPanel::jump_to_Upgrade()
{
if (this->IsShown()) {
auto page = m_tabpanel->GetCurrentPage();
if (page && page != m_upgrade_panel) {
m_tabpanel->SetSelection(PT_UPDATE);
}
}
}
void MonitorPanel::jump_to_LiveView()
{
if (!this->IsShown()) { return; }
auto page = m_tabpanel->GetCurrentPage();
if (page && page != m_hms_panel)
{
m_tabpanel->SetSelection(PT_STATUS);
}
m_status_info_panel->get_media_play_ctrl()->jump_to_play();
}
void MonitorPanel::jump_to_Rack()
{
if (!this->IsShown()) {
return;
}
auto page = m_tabpanel->GetCurrentPage();
if (page && page != m_status_info_panel) {
m_tabpanel->SetSelection(PT_STATUS);
}
m_status_info_panel->jump_to_Rack();
}
void MonitorPanel::update_network_version_footer()
{
std::string binary_version = Slic3r::NetworkAgent::get_version();
if (binary_version.empty())
return;
std::string configured_version = wxGetApp().app_config->get_network_plugin_version();
std::string suffix = extract_suffix(configured_version);
std::string configured_base = extract_base_version(configured_version);
wxString footer_text;
if (!suffix.empty() && configured_base == binary_version) {
footer_text = wxString::Format(_L("Network plug-in v%s (%s)"), binary_version, suffix);
} else {
footer_text = wxString::Format(_L("Network plug-in v%s"), binary_version);
}
m_tabpanel->SetFooterText(footer_text);
}
} // GUI
} // Slic3r