ENH: Add Makerlab JS Command And MakerSupply
JIRA: none Change-Id: Idd2a471debd8d22d1e024956665cb8ff37d7c093
This commit is contained in:
parent
2093498516
commit
fda4aea3f9
|
@ -115,7 +115,8 @@ var LangText={
|
|||
"t121": "Search",
|
||||
"t122": "Search online models",
|
||||
"t123": "Plate",
|
||||
"t124": ""
|
||||
"t124": "",
|
||||
"t125": "Maker’s Supply"
|
||||
},
|
||||
"zh_CN": {
|
||||
"t1": "欢迎使用Bambu Studio",
|
||||
|
@ -233,7 +234,8 @@ var LangText={
|
|||
"t121": "搜索",
|
||||
"t122": "搜索在线模型",
|
||||
"t123": "第",
|
||||
"t124": " 盘",
|
||||
"t124": " 盘",
|
||||
"t125": "创客宝库",
|
||||
"wk1": "快速入门指南",
|
||||
"wk2": "本文介绍了Bambu Studio的最基本用法。它指导用户配置软件,创建项目,并逐步完成第一个打印任务。",
|
||||
"wk3": "基于项目的工作流",
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<g filter="url(#filter0_d_41282_63754)">
|
||||
<path d="M19.0832 7.5585H4.9165C4.28138 7.5585 3.7665 8.07337 3.7665 8.7085V11.9219C3.7665 12.557 4.28138 13.0719 4.9165 13.0719H19.0832C19.7183 13.0719 20.2332 12.557 20.2332 11.9219V8.7085C20.2332 8.07337 19.7183 7.5585 19.0832 7.5585Z" stroke="#6B6B6B" stroke-width="1.3"/>
|
||||
<path d="M5.5 13.0688H4.85V13.7188V18.5417C4.85 19.1768 5.36487 19.6917 6 19.6917H18C18.6351 19.6917 19.15 19.1768 19.15 18.5417V13.7188V13.0688H18.5H5.5Z" stroke="#6B6B6B" stroke-width="1.3"/>
|
||||
<path d="M16 7.50625H16.6V6.90625V5.5C16.6 4.89249 16.1075 4.4 15.5 4.4H8.5C7.89249 4.4 7.4 4.89249 7.4 5.5V6.90625V7.50625H8H16Z" stroke="#6B6B6B" stroke-width="1.2"/>
|
||||
<path fill-rule="evenodd" clip-rule="evenodd" d="M8.5875 11C8.94649 11 9.2375 11.291 9.2375 11.65L9.2376 14.4C9.2376 14.759 8.94658 15.05 8.5876 15.05C8.22861 15.05 7.9376 14.759 7.9376 14.4L7.9375 11.65C7.9375 11.291 8.22851 11 8.5875 11Z" fill="#6B6B6B"/>
|
||||
<path fill-rule="evenodd" clip-rule="evenodd" d="M15.41 11C15.769 11 16.06 11.291 16.06 11.65V14.3999C16.06 14.7589 15.769 15.0499 15.41 15.0499C15.051 15.0499 14.76 14.7589 14.76 14.3999V11.65C14.76 11.291 15.051 11 15.41 11Z" fill="#6B6B6B"/>
|
||||
</g>
|
||||
<defs>
|
||||
<filter id="filter0_d_41282_63754" x="-3" y="-1" width="28" height="28" filterUnits="userSpaceOnUse" color-interpolation-filters="sRGB">
|
||||
<feFlood flood-opacity="0" result="BackgroundImageFix"/>
|
||||
<feColorMatrix in="SourceAlpha" type="matrix" values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 127 0" result="hardAlpha"/>
|
||||
<feOffset dx="-1" dy="1"/>
|
||||
<feGaussianBlur stdDeviation="1"/>
|
||||
<feComposite in2="hardAlpha" operator="out"/>
|
||||
<feColorMatrix type="matrix" values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.08 0"/>
|
||||
<feBlend mode="normal" in2="BackgroundImageFix" result="effect1_dropShadow_41282_63754"/>
|
||||
<feBlend mode="normal" in="SourceGraphic" in2="effect1_dropShadow_41282_63754" result="shape"/>
|
||||
</filter>
|
||||
</defs>
|
||||
</svg>
|
After Width: | Height: | Size: 2.0 KiB |
|
@ -70,7 +70,7 @@ function GotoMenu( strMenu )
|
|||
{
|
||||
ShowMenuNewTag(strMenu,0);
|
||||
|
||||
if(NowMenu==strMenu && strMenu!='makerlab')
|
||||
if(NowMenu==strMenu && strMenu!='makersupply')
|
||||
return;
|
||||
|
||||
NowMenu=strMenu;
|
||||
|
@ -84,7 +84,7 @@ function GotoMenu( strMenu )
|
|||
|
||||
if( $(OneBtn).attr("menu")==strMenu )
|
||||
{
|
||||
//if(strMenu!=='makerlab')
|
||||
if(strMenu!=='makersupply')
|
||||
{
|
||||
$(".BtnItem").removeClass("BtnItemSelected");
|
||||
$(OneBtn).addClass("BtnItemSelected");
|
||||
|
|
|
@ -91,8 +91,8 @@ var Test_PrintTaskList={
|
|||
"weight": 0
|
||||
}
|
||||
],
|
||||
"mode": "cloud_slice",
|
||||
"isPublicProfile": true,
|
||||
"mode": "user_slice",
|
||||
"isPublicProfile": false,
|
||||
"isPrintable": true,
|
||||
"isDelete": false,
|
||||
"deviceModel": "X1E",
|
||||
|
|
|
@ -59,6 +59,10 @@
|
|||
<div class="BtnText trans" tid="">MakerLab</div>
|
||||
<div id="MakerlabNewTag" class="BtnNewIcon">New</div>
|
||||
</div>
|
||||
<div menu="makersupply" class="BtnItem" onClick="GotoMenu('makersupply')">
|
||||
<div class="BtnIcon "><img class="LeftIcon" src="img/left_ms.svg" /></div>
|
||||
<div class="BtnText trans" tid="t125">Maker’s Supply</div>
|
||||
</div>
|
||||
<div menu="printhistory" class="BtnItem" onClick="GotoMenu('printhistory')">
|
||||
<div class="BtnIcon "><img class="LeftIcon" src="img/left_ph.svg" /></div>
|
||||
<div class="BtnText trans" tid="t117">Print History</div>
|
||||
|
|
|
@ -4324,34 +4324,49 @@ std::string GUI_App::handle_web_request(std::string cmd)
|
|||
if (mainframe && mainframe->m_webview) {
|
||||
mainframe->m_webview->ShowUserPrintTask(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (command_str.compare("homepage_leftmenu_change_width") == 0) {
|
||||
int NewWidth = 214;
|
||||
if (root.get_child_optional("width") != boost::none) NewWidth = root.get<int>("width");
|
||||
|
||||
if (mainframe && mainframe->m_webview)
|
||||
{
|
||||
mainframe->m_webview->SetLeftMenuWidth(NewWidth);
|
||||
if (mainframe && mainframe->m_webview)
|
||||
{
|
||||
mainframe->m_webview->SetLeftMenuWidth(NewWidth);
|
||||
mainframe->m_webview->Layout();
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (command_str.compare("homepage_makerlab_open_3mf_binary") == 0) {
|
||||
if (root.get_child_optional("3mf") != boost::none) {
|
||||
std::string str3MFBase64 = root.get_optional<std::string>("3mf").value();
|
||||
|
||||
std::string str3MFName = "makerlab";
|
||||
if (root.get_child_optional("3mf_name") != boost::none)
|
||||
{
|
||||
if (root.get_child_optional("3mf_name") != boost::none)
|
||||
{
|
||||
std::string strTmp = from_u8(root.get_optional<std::string>("3mf_name").value()).ToStdString();
|
||||
if (strTmp != "") str3MFName = strTmp;
|
||||
}
|
||||
|
||||
if (mainframe && mainframe->m_webview)
|
||||
{
|
||||
if (mainframe && mainframe->m_webview)
|
||||
{
|
||||
mainframe->m_webview->OpenMakerlab3mf(str3MFBase64,str3MFName);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (command_str.compare("homepage_makerlab_stl_download")==0)
|
||||
{
|
||||
if (root.get_child_optional("file_data") != boost::none && root.get_child_optional("sequence_id") != boost::none) {
|
||||
int SeqID = root.get_optional<int>("sequence_id").value();
|
||||
std::string strSTLBase64 = root.get_optional<std::string>("file_data").value();
|
||||
|
||||
std::string strSTLName = "makerlab";
|
||||
if (root.get_child_optional("file_name") != boost::none) {
|
||||
std::string strTmp = from_u8(root.get_optional<std::string>("file_name").value()).ToStdString();
|
||||
if (strTmp != "") strSTLName = strTmp;
|
||||
}
|
||||
|
||||
if (mainframe && mainframe->m_webview) { mainframe->m_webview->SaveMakerlabStl(SeqID,strSTLBase64, strSTLName); }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (...) {
|
||||
|
|
|
@ -536,16 +536,15 @@ void WebViewPanel::OnFreshLoginStatus(wxTimerEvent &event)
|
|||
{
|
||||
m_loginstatus = 1;
|
||||
|
||||
if (m_onlinefirst)
|
||||
{
|
||||
if (m_onlinefirst)
|
||||
{
|
||||
UpdateMakerworldLoginStatus();
|
||||
}
|
||||
}
|
||||
|
||||
if (m_MakerLabFirst)
|
||||
{
|
||||
if (m_MakerLabFirst)
|
||||
{
|
||||
SetMakerlabUrl("");
|
||||
m_browserML->LoadURL(m_MakerLab_LastUrl);
|
||||
m_MakerLab_LastUrl = "";
|
||||
UpdateMakerlabStatus();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -563,8 +562,7 @@ void WebViewPanel::OnFreshLoginStatus(wxTimerEvent &event)
|
|||
|
||||
if (m_MakerLabFirst) {
|
||||
SetMakerlabUrl("");
|
||||
m_browserML->LoadURL(m_MakerLab_LastUrl);
|
||||
m_MakerLab_LastUrl = "";
|
||||
UpdateMakerlabStatus();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -818,19 +816,6 @@ void WebViewPanel::SetMakerlabUrl(std::string url) {
|
|||
LabUrl = (boost::format("%1%%2%?from=bambustudio") % host % url).str();
|
||||
|
||||
m_MakerLab_LastUrl = LabUrl;
|
||||
NetworkAgent *agent = GUI::wxGetApp().getAgent();
|
||||
if (!agent) return;
|
||||
|
||||
if (agent->is_user_login()) {
|
||||
std::string newticket;
|
||||
int ret = agent->request_bind_ticket(&newticket);
|
||||
if (ret == 0) {
|
||||
GetJumpUrl(true, newticket, m_MakerLab_LastUrl, m_MakerLab_LastUrl);
|
||||
} else
|
||||
return;
|
||||
} else {
|
||||
GetJumpUrl(false, "", m_MakerLab_LastUrl, m_MakerLab_LastUrl);
|
||||
}
|
||||
}
|
||||
|
||||
void WebViewPanel::OpenOneMakerlab(std::string url)
|
||||
|
@ -838,15 +823,13 @@ void WebViewPanel::OpenOneMakerlab(std::string url)
|
|||
NetworkAgent *agent = GUI::wxGetApp().getAgent();
|
||||
if (!agent) return;
|
||||
|
||||
if (!agent->is_user_login()) wxGetApp().ShowUserLogin(true);
|
||||
//if (!agent->is_user_login()) {
|
||||
// wxGetApp().CallAfter([this] { wxGetApp().handle_web_request("{\"sequence_id\":1,\"command\":\"homepage_login_or_register\"}"); });
|
||||
//}
|
||||
|
||||
if (agent->is_user_login()) {
|
||||
SetMakerlabUrl(url);
|
||||
SetMakerlabUrl(url);
|
||||
SwitchLeftMenu("makerlab");
|
||||
|
||||
SwitchLeftMenu("makerlab");
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
std::string GenerateRandomString(int length)
|
||||
|
@ -860,23 +843,28 @@ std::string GenerateRandomString(int length)
|
|||
return randomString;
|
||||
}
|
||||
|
||||
void WebViewPanel::OpenMakerlab3mf(std::string Base64Buf, std::string FileName)
|
||||
{
|
||||
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];
|
||||
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());
|
||||
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;
|
||||
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;
|
||||
|
@ -886,20 +874,20 @@ void WebViewPanel::OpenMakerlab3mf(std::string Base64Buf, std::string FileName)
|
|||
char separator = boost::filesystem::path::preferred_separator;
|
||||
std::string separatorStr(1, separator);
|
||||
|
||||
wxString download_path = wxString::FromUTF8(wxGetApp().app_config->get("download_path"));
|
||||
wxString download_file = download_path + separatorStr + FileName + "_" + ss.str() + "_" + GenerateRandomString(4) + ".3mf";
|
||||
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;
|
||||
return false;
|
||||
}
|
||||
outFile.write(DstBuf, nWrite);
|
||||
if (!outFile) {
|
||||
delete DstBuf;
|
||||
std::cerr << "Error writing to file." << std::endl;
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
delete DstBuf;
|
||||
|
@ -907,14 +895,91 @@ void WebViewPanel::OpenMakerlab3mf(std::string Base64Buf, std::string FileName)
|
|||
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
|
||||
download_file = download_file.utf8_string();
|
||||
wxGetApp().request_open_project(download_file.ToStdString());
|
||||
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)
|
||||
|
@ -1658,27 +1723,29 @@ void WebViewPanel::SwitchWebContent(std::string modelname, int refresh)
|
|||
|
||||
wxString strlang = wxGetApp().current_language_code_safe();
|
||||
|
||||
if (modelname.compare("makerlab") == 0)
|
||||
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";
|
||||
|
||||
wxLaunchDefaultBrowser(MakerSupplyUrl);
|
||||
}
|
||||
else if (modelname.compare("makerlab") == 0)
|
||||
{
|
||||
wxString FinalUrl;
|
||||
|
||||
if (!m_MakerLabFirst)
|
||||
{
|
||||
if (m_MakerLab_LastUrl != "")
|
||||
FinalUrl = m_MakerLab_LastUrl;
|
||||
else
|
||||
{
|
||||
SetMakerlabUrl("");
|
||||
|
||||
FinalUrl = m_MakerLab_LastUrl;
|
||||
}
|
||||
}
|
||||
if (!m_MakerLabFirst)
|
||||
{
|
||||
UpdateMakerlabStatus();
|
||||
}
|
||||
else {
|
||||
if (m_MakerLab_LastUrl != "")
|
||||
FinalUrl = m_MakerLab_LastUrl;
|
||||
if (m_MakerLab_LastUrl != "") m_browserML->LoadURL(m_MakerLab_LastUrl);
|
||||
}
|
||||
|
||||
m_browserML->LoadURL(FinalUrl);
|
||||
m_MakerLabFirst = true;
|
||||
m_MakerLab_LastUrl = "";
|
||||
|
||||
|
|
|
@ -143,6 +143,9 @@ public:
|
|||
void SetMakerlabUrl(std::string url);
|
||||
void OpenOneMakerlab(std::string url);
|
||||
void OpenMakerlab3mf(std::string Base64Buf, std::string FileName);
|
||||
bool SaveBase64ToLocal(std::string Base64Buf, std::string FileName,std::string FileTail, wxString &download_path, wxString &download_file);
|
||||
void SaveMakerlabStl(int SequenceID,std::string Base64Buf, std::string FileName);
|
||||
void UpdateMakerlabStatus();
|
||||
|
||||
//Common UI
|
||||
void SetWebviewShow(wxString name, bool show);
|
||||
|
|
Loading…
Reference in New Issue