diff --git a/src/slic3r/CMakeLists.txt b/src/slic3r/CMakeLists.txt index cfa3193952..c55d867649 100644 --- a/src/slic3r/CMakeLists.txt +++ b/src/slic3r/CMakeLists.txt @@ -235,6 +235,8 @@ set(SLIC3R_GUI_SOURCES GUI/Monitor.hpp GUI/WebViewDialog.cpp GUI/WebViewDialog.hpp + GUI/PrinterWebView.cpp + GUI/PrinterWebView.hpp GUI/WebDownPluginDlg.hpp GUI/WebDownPluginDlg.cpp GUI/WebGuideDialog.hpp diff --git a/src/slic3r/GUI/MainFrame.cpp b/src/slic3r/GUI/MainFrame.cpp index c126ad771e..d61976afb8 100644 --- a/src/slic3r/GUI/MainFrame.cpp +++ b/src/slic3r/GUI/MainFrame.cpp @@ -73,6 +73,7 @@ wxDEFINE_EVENT(EVT_USER_LOGIN, wxCommandEvent); // BBS: backup wxDEFINE_EVENT(EVT_BACKUP_POST, wxCommandEvent); wxDEFINE_EVENT(EVT_LOAD_URL, wxCommandEvent); +wxDEFINE_EVENT(EVT_LOAD_PRINTER_URL, wxCommandEvent); enum class ERescaleTarget { @@ -934,6 +935,13 @@ void MainFrame::init_tabpanel() m_monitor = new MonitorPanel(m_tabpanel, wxID_ANY, wxDefaultPosition, wxDefaultSize); 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_auxiliary = new AuxiliaryPanel(m_tabpanel, wxID_ANY, wxDefaultPosition, wxDefaultSize); m_tabpanel->AddPage(m_auxiliary, _L("Project"), std::string("tab_auxiliary_avtice"), std::string("tab_auxiliary_avtice")); @@ -951,6 +959,33 @@ void MainFrame::init_tabpanel() } } + // SoftFever +void MainFrame::show_device(bool bBBLPrinter) { + if (m_tabpanel->GetPage(3) != m_monitor && + m_tabpanel->GetPage(3) != m_printer_view) { + BOOST_LOG_TRIVIAL(error) << "Failed to find device tab"; + return; + } + if (bBBLPrinter) { + if (m_tabpanel->GetPage(3) != m_monitor) { + m_tabpanel->RemovePage(3); + m_tabpanel->InsertPage(3, m_monitor, _L("Device"), + std::string("tab_monitor_active"), + std::string("tab_monitor_active")); + } + } else { + if (m_tabpanel->GetPage(3) != m_printer_view) { + m_tabpanel->RemovePage(3); + m_tabpanel->InsertPage(3, m_printer_view, _L("Device"), + std::string("tab_monitor_active"), + std::string("tab_monitor_active")); + } + } + + +} + + #ifdef WIN32 void MainFrame::register_win32_callbacks() { @@ -2859,6 +2894,13 @@ 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::refresh_plugin_tips() { if (m_webview != nullptr) diff --git a/src/slic3r/GUI/MainFrame.hpp b/src/slic3r/GUI/MainFrame.hpp index 416552743b..94841f09be 100644 --- a/src/slic3r/GUI/MainFrame.hpp +++ b/src/slic3r/GUI/MainFrame.hpp @@ -28,6 +28,8 @@ #include "BBLTopbar.hpp" +#include "PrinterWebView.hpp" + #define ENABEL_PRINT_ALL 0 class Notebook; @@ -307,9 +309,13 @@ public: //BBS void load_url(wxString url); + void load_printer_url(wxString url); void refresh_plugin_tips(); void RunScript(wxString js); + //SoftFever + void show_device(bool bBBLPrinter); + // BBS. Replace title bar and menu bar with top bar. BBLTopbar* m_topbar{ nullptr }; PrintHostQueueDialog* printhost_queue_dlg() { return m_printhost_queue_dlg; } @@ -318,6 +324,7 @@ public: MonitorPanel* m_monitor{ nullptr }; AuxiliaryPanel* m_auxiliary{ nullptr }; WebViewPanel* m_webview { nullptr }; + PrinterWebView* m_printer_view{nullptr}; wxLogWindow* m_log_window { nullptr }; // BBS //wxBookCtrlBase* m_tabpanel { nullptr }; diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index a7a3b14407..5b0bd4472b 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -911,30 +911,22 @@ 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); - MonitorPanel *curr_monitor = wxGetApp().mainframe->m_monitor; - if(wxGetApp().mainframe->m_tabpanel->GetPage(3) != - curr_monitor){ - wxGetApp().mainframe->m_tabpanel->InsertPage(3, - curr_monitor, _L("Device"), - std::string("tab_monitor_active"), - std::string("tab_monitor_active")); - } + p_mainframe->set_print_button_to_default(MainFrame::PrintSelectType::ePrintPlate); } else { connection_btn->Show(); ams_btn->Hide(); - wxGetApp().mainframe->set_print_button_to_default(MainFrame::PrintSelectType::eSendGcode); - MonitorPanel *curr_monitor = wxGetApp().mainframe->m_monitor; - if (wxGetApp().mainframe->m_tabpanel->GetPage(3) == curr_monitor) { - wxGetApp().mainframe->m_tabpanel->RemovePage(3); - } + p_mainframe->set_print_button_to_default(MainFrame::PrintSelectType::eSendGcode); + p_mainframe->load_printer_url(wxString::Format("http://%s",preset_bundle.printers.get_edited_preset().config.opt_string("print_host"))); } // Update the print choosers to only contain the compatible presets, update the dirty flags. diff --git a/src/slic3r/GUI/PrinterWebView.cpp b/src/slic3r/GUI/PrinterWebView.cpp new file mode 100644 index 0000000000..9635e8543f --- /dev/null +++ b/src/slic3r/GUI/PrinterWebView.cpp @@ -0,0 +1,125 @@ +#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 +#include +#include + +#include + +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 button + bSizer_toolbar = new wxBoxSizer(wxHORIZONTAL); + + //m_button_reload = new wxButton(this, wxID_ANY, wxT("Reload"), wxDefaultPosition, wxDefaultSize, 0); + //bSizer_toolbar->Add(m_button_reload, 0, wxALL, 5); + + m_url = new wxTextCtrl(this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER); + bSizer_toolbar->Add(m_url, 1, wxALL | wxEXPAND, 5); + + + // Create the webview + m_browser = WebView::CreateWebView(this, ""); + if (m_browser == nullptr) { + wxLogError("Could not init m_browser"); + return; + } + + 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 button events + //Bind(wxEVT_BUTTON, &PrinterWebView::OnReload, this, m_button_reload->GetId()); + Bind(wxEVT_TEXT_ENTER, &PrinterWebView::OnUrl, this, m_url->GetId()); + //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(); + m_url->SetLabelText(url); + + if (wxGetApp().get_mode() == comDevelop) + wxLogMessage(m_url->GetValue()); + 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()); + m_url->SetValue(m_browser->GetCurrentURL()); +} + +/** + * Callback invoked when user entered an URL and pressed enter + */ +void PrinterWebView::OnUrl(wxCommandEvent& WXUNUSED(evt)) +{ + if (wxGetApp().get_mode() == comDevelop) + wxLogMessage(m_url->GetValue()); + m_browser->LoadURL(m_url->GetValue()); + m_browser->SetFocus(); + UpdateState(); +} + +/** + * Callback invoked when user pressed the "reload" button + */ +void PrinterWebView::OnReload(wxCommandEvent& WXUNUSED(evt)) +{ + m_browser->Reload(); + UpdateState(); +} + +void PrinterWebView::OnClose(wxCloseEvent& evt) +{ + this->Hide(); +} + + + +} // GUI +} // Slic3r diff --git a/src/slic3r/GUI/PrinterWebView.hpp b/src/slic3r/GUI/PrinterWebView.hpp new file mode 100644 index 0000000000..4a02019153 --- /dev/null +++ b/src/slic3r/GUI/PrinterWebView.hpp @@ -0,0 +1,64 @@ +#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 +#include +#include "wx/textctrl.h" +#include + + +namespace Slic3r { +namespace GUI { + + +class PrinterWebView : public wxPanel { +public: + PrinterWebView(wxWindow *parent); + virtual ~PrinterWebView(); + + void load_url(wxString& url); + + void UpdateState(); + void OnUrl(wxCommandEvent& evt); + void OnReload(wxCommandEvent& evt); + void OnClose(wxCloseEvent& evt); + +private: + + wxWebView* m_browser; + wxBoxSizer *bSizer_toolbar; + wxButton * m_button_reload; + wxTextCtrl *m_url; + + long m_zoomFactor; + + // Last executed JavaScript snippet, for convenience. + // wxString m_javascript; + // wxString m_response_js; + + // DECLARE_EVENT_TABLE() +}; + +} // GUI +} // Slic3r + +#endif /* slic3r_Tab_hpp_ */