NEW: add Device view for third-party printers

cherry-picked from SoftFever

Change-Id: I36b2fa0227886e4fac494c8b83e12f4fc0b04e17
Signed-off-by: Stone Li <stone.li@bambulab.com>
This commit is contained in:
Stone Li 2023-06-14 14:29:36 +08:00 committed by Lane.Wei
parent 5f04066ac0
commit efd65561a2
27 changed files with 1797 additions and 60 deletions

View file

@ -83,6 +83,7 @@ wxDEFINE_EVENT(EVT_UPDATE_PRESET_CB, SimpleEvent);
// BBS: backup
wxDEFINE_EVENT(EVT_BACKUP_POST, wxCommandEvent);
wxDEFINE_EVENT(EVT_LOAD_URL, wxCommandEvent);
wxDEFINE_EVENT(EVT_LOAD_PRINTER_URL, wxCommandEvent);
enum class ERescaleTarget
{
@ -925,16 +926,35 @@ void MainFrame::init_tabpanel()
m_tabpanel->Bind(wxEVT_NOTEBOOK_PAGE_CHANGING, [this](wxBookCtrlEvent& e) {
int old_sel = e.GetOldSelection();
int new_sel = e.GetSelection();
if (new_sel == tpMonitor) {
if (wxGetApp().preset_bundle &&
wxGetApp().preset_bundle->printers.get_edited_preset().is_bbl_vendor_preset(wxGetApp().preset_bundle) &&
new_sel == tpMonitor) {
if (!wxGetApp().getAgent()) {
e.Veto();
BOOST_LOG_TRIVIAL(info) << boost::format("skipped tab switch from %1% to %2%, lack of network plugins")%old_sel %new_sel;
BOOST_LOG_TRIVIAL(info) << boost::format("skipped tab switch from %1% to %2%, lack of network plugins") %
old_sel % new_sel;
if (m_plater) {
wxCommandEvent *evt = new wxCommandEvent(EVT_INSTALL_PLUGIN_HINT);
wxCommandEvent* evt = new wxCommandEvent(EVT_INSTALL_PLUGIN_HINT);
wxQueueEvent(m_plater, evt);
}
}
}
else {
if (new_sel == tpMonitor && wxGetApp().preset_bundle != nullptr) {
auto cfg = wxGetApp().preset_bundle->printers.get_edited_preset().config;
wxString url;
if (cfg.has("print_host_webui") && !cfg.opt_string("print_host_webui").empty()) {
url = cfg.opt_string("print_host_webui");
}
else {
url = cfg.opt_string("print_host");
}
if (url.empty()) {
wxString url = wxString::Format("file://%s/web/device/missing_connection.html", from_u8(resources_dir()));
m_printer_view->load_url(url);
}
}
}
});
#ifdef __WXMSW__
@ -1017,6 +1037,14 @@ void MainFrame::init_tabpanel()
m_monitor->SetBackgroundColour(*wxWHITE);
m_tabpanel->AddPage(m_monitor, _L("Device"), std::string("tab_monitor_active"), std::string("tab_monitor_active"));
m_printer_view = new PrinterWebView(m_tabpanel);
Bind(EVT_LOAD_PRINTER_URL, [this](wxCommandEvent &evt) {
wxString url = evt.GetString();
//select_tab(MainFrame::tpMonitor);
m_printer_view->load_url(url);
});
m_printer_view->Hide();
m_project = new ProjectPanel(m_tabpanel, wxID_ANY, wxDefaultPosition, wxDefaultSize);
m_project->SetBackgroundColour(*wxWHITE);
m_tabpanel->AddPage(m_project, _L("Project"), std::string("tab_auxiliary_avtice"), std::string("tab_auxiliary_avtice"));
@ -1039,6 +1067,36 @@ void MainFrame::init_tabpanel()
}
}
// SoftFever
void MainFrame::show_device(bool bBBLPrinter) {
if (m_tabpanel->GetPage(tpMonitor) != m_monitor &&
m_tabpanel->GetPage(tpMonitor) != m_printer_view) {
BOOST_LOG_TRIVIAL(error) << "Failed to find device tab";
return;
}
if (bBBLPrinter) {
if (m_tabpanel->GetPage(tpMonitor) != m_monitor) {
m_printer_view->Hide();
m_tabpanel->RemovePage(tpMonitor);
m_tabpanel->InsertPage(tpMonitor, m_monitor, _L("Device"),
std::string("tab_monitor_active"),
std::string("tab_monitor_active"));
m_tabpanel->SetSelection(tp3DEditor);
}
} else {
if (m_tabpanel->GetPage(tpMonitor) != m_printer_view) {
m_printer_view->Show();
m_tabpanel->RemovePage(tpMonitor);
m_tabpanel->InsertPage(tpMonitor, m_printer_view, _L("Device"),
std::string("tab_monitor_active"),
std::string("tab_monitor_active"));
m_tabpanel->SetSelection(tp3DEditor);
}
}
}
bool MainFrame::preview_only_hint()
{
if (m_plater && (m_plater->only_gcode_mode() || (m_plater->using_exported_file()))) {
@ -3244,6 +3302,34 @@ void MainFrame::load_url(wxString url)
wxQueueEvent(this, evt);
}
void MainFrame::load_printer_url(wxString url)
{
BOOST_LOG_TRIVIAL(trace) << "load_printer_url:" << url;
auto evt = new wxCommandEvent(EVT_LOAD_PRINTER_URL, this->GetId());
evt->SetString(url);
wxQueueEvent(this, evt);
}
void MainFrame::load_printer_url()
{
PresetBundle &preset_bundle = *wxGetApp().preset_bundle;
if (preset_bundle.printers.get_edited_preset().is_bbl_vendor_preset(&preset_bundle))
return;
auto cfg = preset_bundle.printers.get_edited_preset().config;
wxString url =
cfg.opt_string("print_host_webui").empty() ? cfg.opt_string("print_host") : cfg.opt_string("print_host_webui");
if (!url.empty()) {
if (!url.Lower().starts_with("http"))
url = wxString::Format("http://%s", url);
load_printer_url(url);
}
}
bool MainFrame::is_printer_view() const { return m_tabpanel->GetSelection() == TabPosition::tpMonitor; }
void MainFrame::refresh_plugin_tips()
{
if (m_webview != nullptr)

View file

@ -28,6 +28,7 @@
// BBS
#include "BBLTopbar.hpp"
#include "PrinterWebView.hpp"
#define ENABEL_PRINT_ALL 0
@ -328,8 +329,12 @@ public:
//BBS
void load_url(wxString url);
void load_printer_url(wxString url);
void load_printer_url();
bool is_printer_view() const;
void refresh_plugin_tips();
void RunScript(wxString js);
void show_device(bool bBBLPrinter);
// BBS. Replace title bar and menu bar with top bar.
BBLTopbar* m_topbar{ nullptr };
@ -343,6 +348,7 @@ public:
CalibrationPanel* m_calibration{ nullptr };
WebViewPanel* m_webview { nullptr };
PrinterWebView* m_printer_view{nullptr};
wxLogWindow* m_log_window { nullptr };
// BBS
//wxBookCtrlBase* m_tabpanel { nullptr };

View file

@ -219,6 +219,10 @@ void PhysicalPrinterDialog::build_printhost_settings(ConfigOptionsGroup* m_optgr
host_line.append_widget(print_host_test);
m_optgroup->append_line(host_line);
option = m_optgroup->get_option("print_host_webui");
option.opt.width = Field::def_width_wider();
m_optgroup->append_single_option_line(option);
m_optgroup->append_single_option_line("printhost_authorization_type");
option = m_optgroup->get_option("printhost_apikey");
@ -233,7 +237,7 @@ void PhysicalPrinterDialog::build_printhost_settings(ConfigOptionsGroup* m_optgr
const auto ca_file_hint = _u8L("HTTPS CA file is optional. It is only needed if you use HTTPS with a self-signed certificate.");
/*if (Http::ca_file_supported()) {
if (Http::ca_file_supported()) {
option = m_optgroup->get_option("printhost_cafile");
option.opt.width = Field::def_width_wider();
Line cafile_line = m_optgroup->create_single_option_line(option);
@ -253,37 +257,37 @@ void PhysicalPrinterDialog::build_printhost_settings(ConfigOptionsGroup* m_optgr
};
cafile_line.append_widget(printhost_cafile_browse);
//m_optgroup->append_line(cafile_line);
m_optgroup->append_line(cafile_line);
//Line cafile_hint{ "", "" };
//cafile_hint.full_width = 1;
//cafile_hint.widget = [ca_file_hint](wxWindow* parent) {
// auto txt = new wxStaticText(parent, wxID_ANY, ca_file_hint);
// auto sizer = new wxBoxSizer(wxHORIZONTAL);
// sizer->Add(txt);
// return sizer;
//};
//m_optgroup->append_line(cafile_hint);
Line cafile_hint{ "", "" };
cafile_hint.full_width = 1;
cafile_hint.widget = [ca_file_hint](wxWindow* parent) {
auto txt = new wxStaticText(parent, wxID_ANY, ca_file_hint);
auto sizer = new wxBoxSizer(wxHORIZONTAL);
sizer->Add(txt);
return sizer;
};
m_optgroup->append_line(cafile_hint);
}
else {
//Line line{ "", "" };
//line.full_width = 1;
Line line{ "", "" };
line.full_width = 1;
//line.widget = [ca_file_hint](wxWindow* parent) {
// std::string info = _u8L("HTTPS CA File") + ":\n\t" +
// (boost::format(_u8L("On this system, %s uses HTTPS certificates from the system Certificate Store or Keychain.")) % SLIC3R_APP_NAME).str() +
// "\n\t" + _u8L("To use a custom CA file, please import your CA file into Certificate Store / Keychain.");
line.widget = [ca_file_hint](wxWindow* parent) {
std::string info = _u8L("HTTPS CA File") + ":\n\t" +
(boost::format(_u8L("On this system, %s uses HTTPS certificates from the system Certificate Store or Keychain.")) % SLIC3R_APP_NAME).str() +
"\n\t" + _u8L("To use a custom CA file, please import your CA file into Certificate Store / Keychain.");
// //auto txt = new wxStaticText(parent, wxID_ANY, from_u8((boost::format("%1%\n\n\t%2%") % info % ca_file_hint).str()));
// auto txt = new wxStaticText(parent, wxID_ANY, from_u8((boost::format("%1%\n\t%2%") % info % ca_file_hint).str()));
// txt->SetFont(wxGetApp().normal_font());
// auto sizer = new wxBoxSizer(wxHORIZONTAL);
// sizer->Add(txt, 1, wxEXPAND);
// return sizer;
//};
//m_optgroup->append_line(line);
}*/
//auto txt = new wxStaticText(parent, wxID_ANY, from_u8((boost::format("%1%\n\n\t%2%") % info % ca_file_hint).str()));
auto txt = new wxStaticText(parent, wxID_ANY, from_u8((boost::format("%1%\n\t%2%") % info % ca_file_hint).str()));
txt->SetFont(wxGetApp().normal_font());
auto sizer = new wxBoxSizer(wxHORIZONTAL);
sizer->Add(txt, 1, wxEXPAND|wxALIGN_LEFT);
return sizer;
};
m_optgroup->append_line(line);
}
for (const std::string& opt_key : std::vector<std::string>{ "printhost_user", "printhost_password" }) {
option = m_optgroup->get_option(opt_key);
@ -292,9 +296,9 @@ void PhysicalPrinterDialog::build_printhost_settings(ConfigOptionsGroup* m_optgr
}
#ifdef WIN32
//option = m_optgroup->get_option("printhost_ssl_ignore_revoke");
//option.opt.width = Field::def_width_wider();
//m_optgroup->append_single_option_line(option);
option = m_optgroup->get_option("printhost_ssl_ignore_revoke");
option.opt.width = Field::def_width_wider();
m_optgroup->append_single_option_line(option);
#endif
m_optgroup->activate();

View file

@ -1026,17 +1026,39 @@ void Sidebar::update_all_preset_comboboxes()
bool is_bbl_preset = preset_bundle.printers.get_edited_preset().is_bbl_vendor_preset(&preset_bundle);
auto p_mainframe = wxGetApp().mainframe;
p_mainframe->show_device(is_bbl_preset);
if (is_bbl_preset) {
//only show connection button for not-BBL printer
connection_btn->Hide();
//only show sync-ams button for BBL printer
ams_btn->Show();
//update print button default value for bbl or third-party printer
wxGetApp().mainframe->set_print_button_to_default(MainFrame::PrintSelectType::ePrintPlate);
p_mainframe->set_print_button_to_default(MainFrame::PrintSelectType::ePrintPlate);
m_bed_type_list->SelectAndNotify(btPC - 1);
m_bed_type_list->Enable();
} else {
connection_btn->Show();
ams_btn->Hide();
wxGetApp().mainframe->set_print_button_to_default(MainFrame::PrintSelectType::eSendGcode);
p_mainframe->set_print_button_to_default(MainFrame::PrintSelectType::eSendGcode);
auto cfg = preset_bundle.printers.get_edited_preset().config;
wxString url;
if (cfg.has("print_host_webui") && !cfg.opt_string("print_host_webui").empty()) {
url = cfg.opt_string("print_host_webui");
} else {
url = cfg.opt_string("print_host");
}
if(!url.empty())
{
if(!url.Lower().starts_with("http"))
url = wxString::Format("http://%s",url);
p_mainframe->load_printer_url(url);
}
m_bed_type_list->SelectAndNotify(btPEI - 1);
m_bed_type_list->Disable();
}
// Update the print choosers to only contain the compatible presets, update the dirty flags.

View file

@ -0,0 +1,123 @@
#include "PrinterWebView.hpp"
#include "I18N.hpp"
#include "slic3r/GUI/wxExtensions.hpp"
#include "slic3r/GUI/GUI_App.hpp"
#include "slic3r/GUI/MainFrame.hpp"
#include "libslic3r_version.h"
#include <wx/sizer.h>
#include <wx/toolbar.h>
#include <wx/textdlg.h>
#include <slic3r/GUI/Widgets/WebView.hpp>
namespace pt = boost::property_tree;
namespace Slic3r {
namespace GUI {
PrinterWebView::PrinterWebView(wxWindow *parent)
: wxPanel(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize)
{
wxBoxSizer* topsizer = new wxBoxSizer(wxVERTICAL);
// Create the webview
m_browser = WebView::CreateWebView(this, "");
if (m_browser == nullptr) {
wxLogError("Could not init m_browser");
return;
}
Bind(wxEVT_WEBVIEW_ERROR, &PrinterWebView::OnError, this);
SetSizer(topsizer);
topsizer->Add(m_browser, wxSizerFlags().Expand().Proportion(1));
// Log backend information
if (wxGetApp().get_mode() == comDevelop) {
wxLogMessage(wxWebView::GetBackendVersionInfo().ToString());
wxLogMessage("Backend: %s Version: %s", m_browser->GetClassInfo()->GetClassName(),
wxWebView::GetBackendVersionInfo().ToString());
wxLogMessage("User Agent: %s", m_browser->GetUserAgent());
}
//Zoom
m_zoomFactor = 100;
//Connect the idle events
Bind(wxEVT_CLOSE_WINDOW, &PrinterWebView::OnClose, this);
}
PrinterWebView::~PrinterWebView()
{
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " Start";
SetEvtHandlerEnabled(false);
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " End";
}
void PrinterWebView::load_url(wxString& url)
{
// this->Show();
// this->Raise();
if (m_browser == nullptr)
return;
m_browser->LoadURL(url);
//m_browser->SetFocus();
UpdateState();
}
/**
* Method that retrieves the current state from the web control and updates the
* GUI the reflect this current state.
*/
void PrinterWebView::UpdateState() {
// SetTitle(m_browser->GetCurrentTitle());
}
void PrinterWebView::OnClose(wxCloseEvent& evt)
{
this->Hide();
}
void PrinterWebView::OnError(wxWebViewEvent &evt)
{
auto e = "unknown error";
switch (evt.GetInt()) {
case wxWEBVIEW_NAV_ERR_CONNECTION:
e = "wxWEBVIEW_NAV_ERR_CONNECTION";
break;
case wxWEBVIEW_NAV_ERR_CERTIFICATE:
e = "wxWEBVIEW_NAV_ERR_CERTIFICATE";
break;
case wxWEBVIEW_NAV_ERR_AUTH:
e = "wxWEBVIEW_NAV_ERR_AUTH";
break;
case wxWEBVIEW_NAV_ERR_SECURITY:
e = "wxWEBVIEW_NAV_ERR_SECURITY";
break;
case wxWEBVIEW_NAV_ERR_NOT_FOUND:
e = "wxWEBVIEW_NAV_ERR_NOT_FOUND";
break;
case wxWEBVIEW_NAV_ERR_REQUEST:
e = "wxWEBVIEW_NAV_ERR_REQUEST";
break;
case wxWEBVIEW_NAV_ERR_USER_CANCELLED:
e = "wxWEBVIEW_NAV_ERR_USER_CANCELLED";
break;
case wxWEBVIEW_NAV_ERR_OTHER:
e = "wxWEBVIEW_NAV_ERR_OTHER";
break;
}
BOOST_LOG_TRIVIAL(info) << __FUNCTION__<< boost::format(": error loading page %1% %2% %3% %4%") %evt.GetURL() %evt.GetTarget() %e %evt.GetString();
}
} // GUI
} // Slic3r

View file

@ -0,0 +1,54 @@
#ifndef slic3r_PrinterWebView_hpp_
#define slic3r_PrinterWebView_hpp_
#include "wx/artprov.h"
#include "wx/cmdline.h"
#include "wx/notifmsg.h"
#include "wx/settings.h"
#include "wx/webview.h"
#if wxUSE_WEBVIEW_EDGE
#include "wx/msw/webview_edge.h"
#endif
#include "wx/webviewarchivehandler.h"
#include "wx/webviewfshandler.h"
#include "wx/numdlg.h"
#include "wx/infobar.h"
#include "wx/filesys.h"
#include "wx/fs_arc.h"
#include "wx/fs_mem.h"
#include "wx/stdpaths.h"
#include <wx/panel.h>
#include <wx/tbarbase.h>
#include "wx/textctrl.h"
#include <wx/timer.h>
namespace Slic3r {
namespace GUI {
class PrinterWebView : public wxPanel {
public:
PrinterWebView(wxWindow *parent);
virtual ~PrinterWebView();
void load_url(wxString& url);
void UpdateState();
void OnClose(wxCloseEvent& evt);
void OnError(wxWebViewEvent& evt);
private:
wxWebView* m_browser;
long m_zoomFactor;
// DECLARE_EVENT_TABLE()
};
} // GUI
} // Slic3r
#endif /* slic3r_Tab_hpp_ */

View file

@ -75,6 +75,10 @@ void ComboBox::SetSelection(int n)
if (drop.selection >= 0)
SetIcon(icons[drop.selection]);
}
void ComboBox::SelectAndNotify(int n) {
SetSelection(n);
sendComboBoxEvent();
}
void ComboBox::Rescale()
{

View file

@ -43,6 +43,8 @@ public:
void SetSelection(int n) override;
void SelectAndNotify(int n);
virtual void Rescale() override;
wxString GetValue() const;