mirror of
https://github.com/QIDITECH/QIDIStudio.git
synced 2026-02-03 18:38:42 +03:00
update slic3r
This commit is contained in:
@@ -12,6 +12,7 @@
|
||||
#include <boost/property_tree/ptree.hpp>
|
||||
#include <boost/property_tree/json_parser.hpp>
|
||||
#include <boost/chrono.hpp>
|
||||
#include <boost/beast/core/detail/base64.hpp>
|
||||
|
||||
#include <wx/sizer.h>
|
||||
#include <wx/toolbar.h>
|
||||
@@ -145,10 +146,21 @@ WebViewPanel::WebViewPanel(wxWindow *parent)
|
||||
SetPrintHistoryTaskID(0);
|
||||
m_printhistoryfirst = false;
|
||||
|
||||
// MakerLab webview
|
||||
m_browserML = WebView::CreateWebView(this, "about:blank");
|
||||
if (m_browserML == nullptr) {
|
||||
wxLogError("Could not init m_browserML");
|
||||
return;
|
||||
}
|
||||
m_browserML->Hide();
|
||||
SetMakerlabUrl("");
|
||||
m_MakerLabFirst = false;
|
||||
|
||||
m_home_web->Add(m_browserLeft, 0, wxEXPAND | wxALL, 0);
|
||||
m_home_web->Add(m_browser, 1, wxEXPAND | wxALL, 0);
|
||||
m_home_web->Add(m_browserMW, 1, wxEXPAND | wxALL, 0);
|
||||
m_home_web->Add(m_browserPH, 1, wxEXPAND | wxALL, 0);
|
||||
m_home_web->Add(m_browserML, 1, wxEXPAND | wxALL, 0);
|
||||
|
||||
topsizer->Add(m_home_web,1, wxEXPAND | wxALL, 0);
|
||||
|
||||
@@ -312,6 +324,10 @@ void WebViewPanel::ResetWholePage()
|
||||
//PrintHistory
|
||||
SetPrintHistoryTaskID(0);
|
||||
m_printhistoryfirst = false;
|
||||
|
||||
//MakerLab
|
||||
m_MakerLabFirst = false;
|
||||
SetMakerlabUrl("");
|
||||
}
|
||||
|
||||
wxString WebViewPanel::MakeDisconnectUrl(std::string MenuName)
|
||||
@@ -521,7 +537,15 @@ void WebViewPanel::OnFreshLoginStatus(wxTimerEvent &event)
|
||||
m_loginstatus = 1;
|
||||
|
||||
if (m_onlinefirst)
|
||||
{
|
||||
UpdateMakerworldLoginStatus();
|
||||
}
|
||||
|
||||
if (m_MakerLabFirst)
|
||||
{
|
||||
SetMakerlabUrl("");
|
||||
UpdateMakerlabStatus();
|
||||
}
|
||||
}
|
||||
|
||||
if (m_TaskInfo == "" && m_browser && phShow != "false")
|
||||
@@ -535,6 +559,11 @@ void WebViewPanel::OnFreshLoginStatus(wxTimerEvent &event)
|
||||
|
||||
if (m_onlinefirst)
|
||||
SetMakerworldPageLoginStatus(false);
|
||||
|
||||
if (m_MakerLabFirst) {
|
||||
SetMakerlabUrl("");
|
||||
UpdateMakerlabStatus();
|
||||
}
|
||||
}
|
||||
|
||||
if (m_TaskInfo != "" && m_browser) ShowUserPrintTask(false);
|
||||
@@ -779,6 +808,179 @@ void WebViewPanel::get_makerlab_list(std::function<void(std::string)> callback)
|
||||
.perform();
|
||||
}
|
||||
|
||||
void WebViewPanel::SetMakerlabUrl(std::string url) {
|
||||
auto host = wxGetApp().get_model_http_url(wxGetApp().app_config->get_country_code());
|
||||
std::string LabUrl;
|
||||
if (url == "")
|
||||
LabUrl = (boost::format("%1%makerlab?from=bambustudio") % host).str();
|
||||
else
|
||||
LabUrl = (boost::format("%1%%2%?from=bambustudio") % host % url).str();
|
||||
|
||||
m_MakerLab_LastUrl = LabUrl;
|
||||
}
|
||||
|
||||
void WebViewPanel::OpenOneMakerlab(std::string url)
|
||||
{
|
||||
NetworkAgent *agent = GUI::wxGetApp().getAgent();
|
||||
if (!agent) return;
|
||||
|
||||
//if (!agent->is_user_login()) {
|
||||
// wxGetApp().CallAfter([this] { wxGetApp().handle_web_request("{\"sequence_id\":1,\"command\":\"homepage_login_or_register\"}"); });
|
||||
//}
|
||||
|
||||
SetMakerlabUrl(url);
|
||||
SwitchLeftMenu("makerlab");
|
||||
|
||||
}
|
||||
|
||||
std::string GenerateRandomString(int length)
|
||||
{
|
||||
std::string randomString;
|
||||
srand(static_cast<unsigned int>(time(nullptr)));
|
||||
for (int i = 0; i < length; ++i) {
|
||||
int randomAscii = rand() % 26 + 65;
|
||||
randomString += static_cast<char>(randomAscii);
|
||||
}
|
||||
return randomString;
|
||||
}
|
||||
|
||||
bool WebViewPanel::SaveBase64ToLocal(std::string Base64Buf, std::string FileName, std::string FileTail, wxString &download_path, wxString &download_file)
|
||||
{
|
||||
int nSize = wxBase64DecodedSize(Base64Buf.length());
|
||||
char *DstBuf = new char[nSize + 1];
|
||||
if (!DstBuf)
|
||||
{
|
||||
BOOST_LOG_TRIVIAL(trace) << __FUNCTION__ << ": New Failed. Memory Not Enough";
|
||||
return false;
|
||||
}
|
||||
memset(DstBuf, 0, nSize + 1);
|
||||
|
||||
int nWrite = wxBase64Decode(DstBuf, nSize + 1, Base64Buf.c_str(), Base64Buf.length());
|
||||
|
||||
// Format Time String
|
||||
std::time_t currentTime = std::time(nullptr);
|
||||
std::tm *timeInfo = std::localtime(¤tTime);
|
||||
int year = timeInfo->tm_year % 100;
|
||||
int month = timeInfo->tm_mon + 1;
|
||||
int day = timeInfo->tm_mday;
|
||||
int hour = timeInfo->tm_hour;
|
||||
int minute = timeInfo->tm_min;
|
||||
int second = timeInfo->tm_sec;
|
||||
|
||||
std::stringstream ss;
|
||||
ss << std::setfill('0') << std::setw(2) << year << std::setw(2) << month << std::setw(2) << day << std::setw(2) << hour << std::setw(2) << minute << std::setw(2) << second;
|
||||
std::string dateTimeString = ss.str();
|
||||
|
||||
// Write 3MF to Disk
|
||||
char separator = boost::filesystem::path::preferred_separator;
|
||||
std::string separatorStr(1, separator);
|
||||
|
||||
download_path = wxString::FromUTF8(wxGetApp().app_config->get("download_path"));
|
||||
download_file = download_path + separatorStr + FileName + "_" + ss.str() + "_" + GenerateRandomString(4) + "."+ FileTail;
|
||||
|
||||
std::ofstream outFile(download_file.ToStdString(), std::ios::binary);
|
||||
if (!outFile) {
|
||||
delete DstBuf;
|
||||
std::cerr << "Error opening file for writing." << std::endl;
|
||||
return false;
|
||||
}
|
||||
outFile.write(DstBuf, nWrite);
|
||||
if (!outFile) {
|
||||
delete DstBuf;
|
||||
std::cerr << "Error writing to file." << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
delete DstBuf;
|
||||
outFile.close();
|
||||
std::cout << "Data written to file successfully." << std::endl;
|
||||
wxLogMessage("Makerlab Binary Write to %s", download_file.ToStdString());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void WebViewPanel::OpenMakerlab3mf(std::string Base64Buf, std::string FileName)
|
||||
{
|
||||
//Save
|
||||
wxString SavePath, SaveFile;
|
||||
bool bRet = SaveBase64ToLocal(Base64Buf, FileName, "3mf", SavePath, SaveFile);
|
||||
if (!bRet) return;
|
||||
|
||||
//Open File
|
||||
SaveFile = SaveFile.utf8_string();
|
||||
wxGetApp().request_open_project(SaveFile.ToStdString());
|
||||
|
||||
//Remove File
|
||||
//boost::filesystem::remove(download_file.ToStdString());
|
||||
}
|
||||
|
||||
void WebViewPanel::SaveMakerlabStl(int SequenceID, std::string Base64Buf, std::string FileName)
|
||||
{
|
||||
// Save
|
||||
wxString SavePath, SaveFile;
|
||||
bool bRet = SaveBase64ToLocal(Base64Buf, FileName, "stl", SavePath, SaveFile);
|
||||
|
||||
// Response
|
||||
json JFile;
|
||||
JFile["sequence_id"] = SequenceID;
|
||||
JFile["command"] = "homepage_makerlab_stl_download";
|
||||
JFile["file_name"] = FileName;
|
||||
JFile["result"] = bRet ? "success" : "fail";
|
||||
|
||||
std::string strJS = JFile.dump(-1, ' ', false, json::error_handler_t::ignore);
|
||||
|
||||
wxGetApp().CallAfter([this, strJS] {
|
||||
if (!m_browserML) return;
|
||||
|
||||
WebView::RunScript(m_browserML, strJS);
|
||||
});
|
||||
}
|
||||
|
||||
void WebViewPanel::UpdateMakerlabStatus( )
|
||||
{
|
||||
if (m_browserML == nullptr) return;
|
||||
|
||||
wxString ml_currenturl;
|
||||
if (m_MakerLab_LastUrl != "") {
|
||||
ml_currenturl = m_MakerLab_LastUrl;
|
||||
} else {
|
||||
ml_currenturl = m_browserML->GetCurrentURL();
|
||||
if (ml_currenturl == "about:blank") {
|
||||
SetMakerlabUrl("");
|
||||
ml_currenturl = m_MakerLab_LastUrl;
|
||||
}
|
||||
}
|
||||
|
||||
if (wxGetApp().is_user_login())
|
||||
{
|
||||
NetworkAgent *agent = GUI::wxGetApp().getAgent();
|
||||
if (agent == nullptr) {
|
||||
wxString UrlDisconnect = MakeDisconnectUrl("makerlab");
|
||||
m_browserML->LoadURL(UrlDisconnect);
|
||||
return;
|
||||
}
|
||||
|
||||
std::string newticket;
|
||||
int ret = agent->request_bind_ticket(&newticket);
|
||||
if (ret == 0)
|
||||
{
|
||||
GetJumpUrl(login, newticket, ml_currenturl, ml_currenturl);
|
||||
m_browserML->LoadURL(ml_currenturl);
|
||||
m_MakerLab_LastUrl = "";
|
||||
}
|
||||
else {
|
||||
wxString UrlDisconnect = MakeDisconnectUrl("makerlab");
|
||||
m_browserML->LoadURL(UrlDisconnect);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
GetJumpUrl(false, "", ml_currenturl, ml_currenturl);
|
||||
m_browserML->LoadURL(ml_currenturl);
|
||||
m_MakerLab_LastUrl = "";
|
||||
}
|
||||
}
|
||||
|
||||
unsigned char ToHex(unsigned char x) { return x > 9 ? x + 55 : x + 48; }
|
||||
|
||||
unsigned char FromHex(unsigned char x)
|
||||
@@ -1092,6 +1294,13 @@ void WebViewPanel::OnNavigationComplete(wxWebViewEvent& evt)
|
||||
}
|
||||
}
|
||||
|
||||
if (m_browser != nullptr && evt.GetId() == m_browser->GetId())
|
||||
{
|
||||
SwitchWebContent("home");
|
||||
SendDesignStaffpick(true);
|
||||
SendMakerlabList();
|
||||
}
|
||||
|
||||
//m_browser->Show();
|
||||
Layout();
|
||||
BOOST_LOG_TRIVIAL(trace) << __FUNCTION__ << ": " << evt.GetTarget().ToUTF8().data();
|
||||
@@ -1435,6 +1644,7 @@ void WebViewPanel::OnError(wxWebViewEvent& evt)
|
||||
wxString UrlDisconnect = MakeDisconnectUrl("online");
|
||||
m_browserMW->LoadURL(UrlDisconnect);
|
||||
|
||||
SetWebviewShow("makerlab", false);
|
||||
SetWebviewShow("online", true);
|
||||
SetWebviewShow("right", false);
|
||||
SetWebviewShow("printhistory", false);
|
||||
@@ -1450,12 +1660,29 @@ void WebViewPanel::OnError(wxWebViewEvent& evt)
|
||||
wxString UrlDisconnect = MakeDisconnectUrl("printhistory");
|
||||
m_browserPH->LoadURL(UrlDisconnect);
|
||||
|
||||
SetWebviewShow("makerlab", false);
|
||||
SetWebviewShow("printhistory", true);
|
||||
SetWebviewShow("online", false);
|
||||
SetWebviewShow("right", false);
|
||||
}
|
||||
}
|
||||
|
||||
if (evt.GetInt() == wxWEBVIEW_NAV_ERR_CONNECTION && evt.GetId() == m_browserML->GetId()) {
|
||||
m_MakerLab_LastUrl = m_browserML->GetCurrentURL();
|
||||
|
||||
if (m_contentname == "makerlab") {
|
||||
wxString errurl = evt.GetURL();
|
||||
|
||||
wxString UrlDisconnect = MakeDisconnectUrl("makerlab");
|
||||
m_browserML->LoadURL(UrlDisconnect);
|
||||
|
||||
SetWebviewShow("makerlab", true);
|
||||
SetWebviewShow("printhistory", false);
|
||||
SetWebviewShow("online", false);
|
||||
SetWebviewShow("right", false);
|
||||
}
|
||||
}
|
||||
|
||||
UpdateState();
|
||||
}
|
||||
|
||||
@@ -1508,21 +1735,36 @@ void WebViewPanel::SwitchWebContent(std::string modelname, int refresh)
|
||||
|
||||
wxString strlang = wxGetApp().current_language_code_safe();
|
||||
|
||||
if (modelname.compare("makerlab") == 0) {
|
||||
auto host = wxGetApp().get_model_http_url(wxGetApp().app_config->get_country_code());
|
||||
std::string LabUrl = (boost::format("%1%makerlab?from=qidistudio") % host).str();
|
||||
if (modelname.compare("makersupply") == 0)
|
||||
{
|
||||
std::string strRegion = wxGetApp().app_config->get_country_code();
|
||||
wxString MakerSupplyUrl;
|
||||
if (strRegion == "CN")
|
||||
MakerSupplyUrl = "https://bambulab.tmall.com/category-1761686934.htm?from=bambustudio";
|
||||
else
|
||||
MakerSupplyUrl = "https://store.bambulab.com/collections/makers-supply?from=bambustudio";
|
||||
|
||||
wxString FinalUrl = LabUrl;
|
||||
NetworkAgent *agent = GUI::wxGetApp().getAgent();
|
||||
if (agent && agent->is_user_login()) {
|
||||
std::string QIDIHost=agent->get_qiditech_host();
|
||||
|
||||
std::string newticket;
|
||||
int ret = agent->request_bind_ticket(&newticket);
|
||||
if (ret == 0) GetJumpUrl(true, newticket, FinalUrl, FinalUrl);
|
||||
wxLaunchDefaultBrowser(MakerSupplyUrl);
|
||||
}
|
||||
else if (modelname.compare("makerlab") == 0)
|
||||
{
|
||||
wxString FinalUrl;
|
||||
|
||||
wxLaunchDefaultBrowser(FinalUrl);
|
||||
if (!m_MakerLabFirst)
|
||||
{
|
||||
UpdateMakerlabStatus();
|
||||
}
|
||||
else {
|
||||
if (m_MakerLab_LastUrl != "") m_browserML->LoadURL(m_MakerLab_LastUrl);
|
||||
}
|
||||
|
||||
m_MakerLabFirst = true;
|
||||
m_MakerLab_LastUrl = "";
|
||||
|
||||
SetWebviewShow("makerlab", true);
|
||||
SetWebviewShow("online", false);
|
||||
SetWebviewShow("right", false);
|
||||
SetWebviewShow("printhistory", false);
|
||||
|
||||
// conf save
|
||||
wxGetApp().app_config->set_str("homepage", "makerlab_clicked", "1");
|
||||
@@ -1549,11 +1791,10 @@ void WebViewPanel::SwitchWebContent(std::string modelname, int refresh)
|
||||
}
|
||||
|
||||
SetWebviewShow("online", true);
|
||||
SetWebviewShow("makerlab", false);
|
||||
SetWebviewShow("right", false);
|
||||
SetWebviewShow("printhistory", false);
|
||||
|
||||
GetSizer()->Layout();
|
||||
|
||||
// conf save
|
||||
wxGetApp().app_config->set_str("homepage", "online_clicked", "1");
|
||||
wxGetApp().app_config->save();
|
||||
@@ -1594,8 +1835,7 @@ void WebViewPanel::SwitchWebContent(std::string modelname, int refresh)
|
||||
SetWebviewShow("online", false);
|
||||
SetWebviewShow("right", false);
|
||||
SetWebviewShow("printhistory", true);
|
||||
|
||||
GetSizer()->Layout();
|
||||
SetWebviewShow("makerlab", false);
|
||||
|
||||
} else if (modelname.compare("home") == 0 || modelname.compare("recent") == 0 || modelname.compare("manual") == 0) {
|
||||
if (!m_browser) return;
|
||||
@@ -1613,9 +1853,10 @@ void WebViewPanel::SwitchWebContent(std::string modelname, int refresh)
|
||||
SetWebviewShow("online", false);
|
||||
SetWebviewShow("printhistory", false);
|
||||
SetWebviewShow("right", true);
|
||||
|
||||
GetSizer()->Layout();
|
||||
SetWebviewShow("makerlab", false);
|
||||
}
|
||||
|
||||
GetSizer()->Layout();
|
||||
}
|
||||
|
||||
void WebViewPanel::SwitchLeftMenu(std::string strMenu)
|
||||
@@ -1633,22 +1874,6 @@ void WebViewPanel::SwitchLeftMenu(std::string strMenu)
|
||||
WebView::RunScript(m_browserLeft, strJS);
|
||||
}
|
||||
|
||||
void WebViewPanel::OpenOneMakerlab(std::string url) {
|
||||
auto host = wxGetApp().get_model_http_url(wxGetApp().app_config->get_country_code());
|
||||
std::string LabUrl = (boost::format("%1%%2%?from=qidistudio") % host % url).str();
|
||||
|
||||
wxString FinalUrl = LabUrl;
|
||||
NetworkAgent *agent = GUI::wxGetApp().getAgent();
|
||||
if (agent && agent->is_user_login()) {
|
||||
std::string newticket;
|
||||
int ret = agent->request_bind_ticket(&newticket);
|
||||
if (ret == 0) GetJumpUrl(true, newticket, FinalUrl, FinalUrl);
|
||||
}
|
||||
|
||||
wxLaunchDefaultBrowser(FinalUrl);
|
||||
}
|
||||
|
||||
|
||||
void WebViewPanel::CheckMenuNewTag() {
|
||||
std::string sClick = wxGetApp().app_config->get("homepage", "online_clicked");
|
||||
if (sClick.compare("1")==0)
|
||||
@@ -1700,6 +1925,12 @@ void WebViewPanel::SetLeftMenuShow(std::string menuname, int show)
|
||||
WebView::RunScript(m_browser, strJS);
|
||||
}
|
||||
|
||||
void WebViewPanel::SetLeftMenuWidth(int nWidth) {
|
||||
m_browserLeft->SetSize(wxSize(FromDIP(nWidth), -1));
|
||||
m_browserLeft->SetMinSize(wxSize(FromDIP(nWidth), -1));
|
||||
m_browserLeft->SetMaxSize(wxSize(FromDIP(nWidth), -1));
|
||||
}
|
||||
|
||||
void WebViewPanel::SetWebviewShow(wxString name, bool show)
|
||||
{
|
||||
wxWebView *TmpWeb = nullptr;
|
||||
@@ -1711,7 +1942,9 @@ void WebViewPanel::SetWebviewShow(wxString name, bool show)
|
||||
TmpWeb = m_browserMW;
|
||||
else if (name == "printhistory")
|
||||
TmpWeb = m_browserPH;
|
||||
|
||||
else if (name == "makerlab")
|
||||
TmpWeb = m_browserML;
|
||||
|
||||
if (TmpWeb != nullptr)
|
||||
{
|
||||
if (show)
|
||||
|
||||
Reference in New Issue
Block a user