mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-08-03 05:50:35 +08:00
Merge remote-tracking branch 'private/dk_web'
This commit is contained in:
commit
eada1893e6
77
resources/web/connect_loading.html
Normal file
77
resources/web/connect_loading.html
Normal file
@ -0,0 +1,77 @@
|
||||
<!doctype html>
|
||||
<html lang='en'>
|
||||
<head>
|
||||
<meta charset='UTF-8' />
|
||||
<meta content='width=device-width, initial-scale=1.0' name='viewport' />
|
||||
<title>Connect-Slicer integration</title>
|
||||
</head>
|
||||
<body>
|
||||
<!-- This page is not served anywhere, only to be copy 'n' pasted into Slicer as a fallback loading screen. -->
|
||||
<div id='loading-screen' style='width: 100%; height: 100%'>
|
||||
<div style='position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); text-align: center'>
|
||||
<p>
|
||||
<svg height='100%' style='width: 250px; fill-rule:evenodd;clip-rule:evenodd;stroke-linejoin:round;stroke-miterlimit:2;'
|
||||
version='1.1' viewBox='0 0 10584 1835' width='100%'
|
||||
xml:space='preserve' xmlns='http://www.w3.org/2000/svg'
|
||||
>
|
||||
<path d='M 10485.267,532.67639 4431.78,535.92 v 1298.52 h 6058.92 l -5.433,-1301.76361 z M 0,535.92 H 4257.14 V 1834.44 H 0 Z m 427.69,409.16 h 142.58 c 65.02,0 114.07,29.65 114.07,107.22 0,74.14 -46.76,101.52 -114.07,101.52 H 427.69 Z m -212.17,644.48 h 212.17 v -271.48 h 174.52 c 179.09,0 294.3,-78.71 294.3,-280.61 0,-192.77 -142.59,-262.36 -294.3,-262.36 H 215.52 Z m 957.61,-644.48 h 168.82 c 59.32,0 107.22,27.37 107.22,87.83 0,62.74 -34.22,95.82 -98.09,95.82 h -177.95 z m -212.17,644.48 h 212.17 v -296.58 h 160.84 c 100.38,0 112.92,84.41 118.63,166.54 3.42,23.96 5.7,101.52 23.95,130.04 h 209.89 c -28.52,-31.94 -30.8,-148.29 -34.22,-183.65 -5.71,-77.57 -33.08,-173.38 -118.64,-195.06 v -2.28 c 86.7,-33.08 127.76,-116.35 127.76,-204.18 0,-164.26 -142.58,-229.28 -285.17,-229.28 H 960.96 Z M 2452.4,775.11 h -212.16 v 490.5 c 0,104.94 -37.65,158.55 -142.59,158.55 -104.94,0 -142.58,-53.61 -142.58,-158.55 V 775.11 H 1742.9 v 477.95 c 0,236.12 108.36,353.61 354.75,353.61 246.39,0 354.75,-117.49 354.75,-353.61 z m 58.75,540.69 c 0,208.74 167.68,290.87 353.61,290.87 179.08,0 354.75,-66.16 354.75,-272.62 0,-147.15 -118.63,-201.9 -236.12,-234.98 -118.63,-33.08 -236.12,-43.35 -236.12,-107.23 0,-53.61 57.03,-69.58 102.66,-69.58 63.88,0 134.6,25.1 131.18,98.1 h 212.16 c 0,-182.51 -165.4,-262.36 -326.23,-262.36 -152.85,0 -331.94,69.59 -331.94,247.53 0,150.57 123.19,201.9 238.4,234.98 117.49,33.08 233.84,45.63 233.84,118.63 0,60.46 -66.16,83.27 -130.04,83.27 -91.25,0 -149.43,-30.8 -153.99,-126.61 z m 688.39,273.76 h 217.87 l 51.33,-146.01 h 284.03 l 50.19,146.01 h 221.3 L 3719.69,775.11 h -215.58 z m 410.65,-588.59 h 2.28 l 90.11,285.17 h -184.79 z m 1840.23,65.02 C 5444.72,869.79 5255.37,758 5078.56,758 c -247.53,0 -406.08,188.22 -406.08,424.34 0,236.12 158.55,424.33 406.08,424.33 206.46,0 359.31,-122.05 371.86,-333.08 h -212.16 c -7.99,94.68 -63.88,150.57 -164.26,150.57 -136.88,0 -189.35,-119.77 -189.35,-241.82 0,-122.06 52.47,-241.83 189.35,-241.83 90.11,0 151.71,43.35 164.26,125.48 z m 258.37,116.35 c 0,-122.06 52.47,-241.83 189.35,-241.83 136.89,0 189.36,119.77 189.36,241.83 0,122.05 -52.47,241.82 -189.36,241.82 -136.88,0 -189.35,-119.77 -189.35,-241.82 z m -212.16,0 c 0,236.12 146,424.33 401.51,424.33 255.52,0 401.52,-188.21 401.52,-424.33 0,-236.12 -146,-424.34 -401.52,-424.34 -255.51,0 -401.51,188.22 -401.51,424.34 z m 880.03,407.22 h 199.62 v -507.6 h 2.28 l 282.89,507.6 h 217.87 V 775.11 H 6879.7 v 501.9 h -2.28 l -282.89,-501.9 h -217.87 z m 809.31,0 h 199.62 v -507.6 h 2.28 l 282.89,507.6 h 217.87 V 775.11 h -199.62 v 501.9 h -2.28 l -282.89,-501.9 h -217.87 z m 811.59,0 h 660.46 v -182.51 h -448.29 v -155.13 h 399.24 V 1087.66 H 8209.73 V 945.08 h 436.88 V 775.11 H 7997.56 Z M 9495.85,1065.99 C 9490.15,869.79 9300.8,758 9123.99,758 c -247.53,0 -406.08,188.22 -406.08,424.34 0,236.12 158.55,424.33 406.08,424.33 206.46,0 359.31,-122.05 371.86,-333.08 h -212.16 c -7.99,94.68 -63.88,150.57 -164.26,150.57 -136.88,0 -189.35,-119.77 -189.35,-241.82 0,-122.06 52.47,-241.83 189.35,-241.83 90.11,0 151.71,43.35 164.26,125.48 z m 722.65,-290.88 h -698.12 v 182.51 h 242.97 v 631.94 h 212.16 V 957.62 h 242.99 z'
|
||||
fill='var(--color-text)' />
|
||||
</svg>
|
||||
</p>
|
||||
<p>
|
||||
<svg style='width: 80px'
|
||||
viewBox='-250 -250 500 500' xmlns='http://www.w3.org/2000/svg'>
|
||||
<style type='text/css'>
|
||||
.filament {
|
||||
stroke: #FA6831;
|
||||
}
|
||||
|
||||
.spool {
|
||||
stroke: #231F20;
|
||||
fill: none;
|
||||
}
|
||||
|
||||
.filament line {
|
||||
stroke-linecap: round;
|
||||
}
|
||||
</style>
|
||||
<defs>
|
||||
<pattern class='spool' height='100' id='hexagon' patternTransform='scale(0.875)' patternUnits='userSpaceOnUse'
|
||||
viewBox='-0.866025 -1.5 1.73205 3'
|
||||
width='57.735'
|
||||
>
|
||||
<polygon fill='none' points='0,1 0.866025,0.5 0.866025,-0.5 0,-1 -0.866025,-0.5 -0.866025,0.5'
|
||||
stroke-width='0.34' />
|
||||
<line stroke-width='0.34' x1='0' x2='0' y1='1' y2='1.5'></line>
|
||||
<line stroke-width='0.34' x1='0' x2='0' y1='-1' y2='-1.5'></line>
|
||||
</pattern>
|
||||
</defs>
|
||||
<g class='filament'>
|
||||
<circle fill='none' r='145' stroke-width='130'>
|
||||
<animate attributeName='r' dur='6s' repeatCount='indefinite' values='145;80;145' />
|
||||
<animate attributeName='stroke-width' dur='6s' repeatCount='indefinite' values='130;0;130' />
|
||||
</circle>
|
||||
<line stroke-width='12' x1='204' x2='204' y1='0' y2='245'>
|
||||
<animate attributeName='x1' dur='6s' repeatCount='indefinite' values='204;74;204' />
|
||||
<animate attributeName='x2' dur='6s' repeatCount='indefinite' values='204;74;204' />
|
||||
</line>
|
||||
</g>
|
||||
<g class='spool'>
|
||||
<circle fill='none' r='157' stroke='url(#hexagon)' stroke-width='171' />
|
||||
<circle r='244' stroke-width='12' />
|
||||
<circle r='71' stroke-width='18' />
|
||||
<animateTransform
|
||||
attributeName='transform' begin='0s'
|
||||
dur='6s'
|
||||
fill='freeze'
|
||||
repeatCount='indefinite'
|
||||
type='rotate'
|
||||
values='0;540;0'
|
||||
/>
|
||||
</g>
|
||||
</svg>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
68
resources/web/loading.html
Normal file
68
resources/web/loading.html
Normal file
@ -0,0 +1,68 @@
|
||||
<!doctype html>
|
||||
<html lang='en'>
|
||||
<head>
|
||||
<meta charset='UTF-8' />
|
||||
<meta content='width=device-width, initial-scale=1.0' name='viewport' />
|
||||
<title>Connect-Slicer integration</title>
|
||||
</head>
|
||||
<body>
|
||||
<!-- This page is not served anywhere, only to be copy 'n' pasted into Slicer as a fallback loading screen. -->
|
||||
<div id='loading-screen' style='width: 100%; height: 100%'>
|
||||
<div style='position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); text-align: center'>
|
||||
<p>
|
||||
<svg style='width: 80px'
|
||||
viewBox='-250 -250 500 500' xmlns='http://www.w3.org/2000/svg'>
|
||||
<style type='text/css'>
|
||||
.filament {
|
||||
stroke: #FA6831;
|
||||
}
|
||||
|
||||
.spool {
|
||||
stroke: #231F20;
|
||||
fill: none;
|
||||
}
|
||||
|
||||
.filament line {
|
||||
stroke-linecap: round;
|
||||
}
|
||||
</style>
|
||||
<defs>
|
||||
<pattern class='spool' height='100' id='hexagon' patternTransform='scale(0.875)' patternUnits='userSpaceOnUse'
|
||||
viewBox='-0.866025 -1.5 1.73205 3'
|
||||
width='57.735'
|
||||
>
|
||||
<polygon fill='none' points='0,1 0.866025,0.5 0.866025,-0.5 0,-1 -0.866025,-0.5 -0.866025,0.5'
|
||||
stroke-width='0.34' />
|
||||
<line stroke-width='0.34' x1='0' x2='0' y1='1' y2='1.5'></line>
|
||||
<line stroke-width='0.34' x1='0' x2='0' y1='-1' y2='-1.5'></line>
|
||||
</pattern>
|
||||
</defs>
|
||||
<g class='filament'>
|
||||
<circle fill='none' r='145' stroke-width='130'>
|
||||
<animate attributeName='r' dur='6s' repeatCount='indefinite' values='145;80;145' />
|
||||
<animate attributeName='stroke-width' dur='6s' repeatCount='indefinite' values='130;0;130' />
|
||||
</circle>
|
||||
<line stroke-width='12' x1='204' x2='204' y1='0' y2='245'>
|
||||
<animate attributeName='x1' dur='6s' repeatCount='indefinite' values='204;74;204' />
|
||||
<animate attributeName='x2' dur='6s' repeatCount='indefinite' values='204;74;204' />
|
||||
</line>
|
||||
</g>
|
||||
<g class='spool'>
|
||||
<circle fill='none' r='157' stroke='url(#hexagon)' stroke-width='171' />
|
||||
<circle r='244' stroke-width='12' />
|
||||
<circle r='71' stroke-width='18' />
|
||||
<animateTransform
|
||||
attributeName='transform' begin='0s'
|
||||
dur='6s'
|
||||
fill='freeze'
|
||||
repeatCount='indefinite'
|
||||
type='rotate'
|
||||
values='0;540;0'
|
||||
/>
|
||||
</g>
|
||||
</svg>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
@ -3132,7 +3132,7 @@ bool GUI_App::may_switch_to_SLA_preset(const wxString& caption)
|
||||
bool GUI_App::run_wizard(ConfigWizard::RunReason reason, ConfigWizard::StartPage start_page)
|
||||
{
|
||||
wxCHECK_MSG(mainframe != nullptr, false, "Internal error: Main frame not created / null");
|
||||
|
||||
#if 0
|
||||
if (!plater()->get_user_account()->is_logged()) {
|
||||
m_login_dialog = std::make_unique<LoginDialog>(mainframe, plater()->get_user_account());
|
||||
m_login_dialog->ShowModal();
|
||||
@ -3141,7 +3141,7 @@ bool GUI_App::run_wizard(ConfigWizard::RunReason reason, ConfigWizard::StartPage
|
||||
// Destructor does not call Destroy
|
||||
m_login_dialog.reset();
|
||||
}
|
||||
|
||||
#endif // 0
|
||||
if (reason == ConfigWizard::RR_USER) {
|
||||
// Cancel sync before starting wizard to prevent two downloads at same time
|
||||
preset_updater->cancel_sync();
|
||||
@ -3171,6 +3171,7 @@ bool GUI_App::run_wizard(ConfigWizard::RunReason reason, ConfigWizard::StartPage
|
||||
return res;
|
||||
}
|
||||
|
||||
#if 0
|
||||
void GUI_App::update_login_dialog()
|
||||
{
|
||||
if (!m_login_dialog) {
|
||||
@ -3178,6 +3179,7 @@ void GUI_App::update_login_dialog()
|
||||
}
|
||||
m_login_dialog->update_account();
|
||||
}
|
||||
#endif // 0
|
||||
|
||||
void GUI_App::show_desktop_integration_dialog()
|
||||
{
|
||||
@ -3650,8 +3652,8 @@ void GUI_App::open_wifi_config_dialog(bool forced, const wxString& drive_path/*
|
||||
}
|
||||
m_wifi_config_dialog_shown = false;
|
||||
}
|
||||
|
||||
bool GUI_App::select_printer_from_connect(const Preset* preset)
|
||||
// Returns true if preset had to be installed.
|
||||
bool GUI_App::select_printer_preset(const Preset* preset)
|
||||
{
|
||||
assert(preset);
|
||||
|
||||
@ -3675,36 +3677,142 @@ bool GUI_App::select_printer_from_connect(const Preset* preset)
|
||||
return is_installed;
|
||||
}
|
||||
|
||||
void GUI_App::handle_connect_request_printer_pick(std::string msg)
|
||||
bool GUI_App::select_printer_from_connect(const std::string& msg)
|
||||
{
|
||||
BOOST_LOG_TRIVIAL(error) << "Handling web request: " << msg;
|
||||
// return to plater
|
||||
this->mainframe->select_tab(size_t(0));
|
||||
// parse message
|
||||
std::vector<std::string> compatible_printers;
|
||||
plater()->get_user_account()->fill_compatible_printers_from_json(msg, compatible_printers);
|
||||
std::string model_name;
|
||||
if (compatible_printers.empty()) {
|
||||
// TODO: This should go away when compatible printers gives right information.
|
||||
model_name = plater()->get_user_account()->get_model_from_json(msg);
|
||||
} else {
|
||||
model_name = compatible_printers.front();
|
||||
std::string model_name = plater()->get_user_account()->get_keyword_from_json(msg, "printer_model");
|
||||
if (model_name.empty()) {
|
||||
std::vector<std::string> compatible_printers;
|
||||
plater()->get_user_account()->fill_supported_printer_models_from_json(msg, compatible_printers);
|
||||
if (!compatible_printers.empty()) {
|
||||
model_name = compatible_printers.front();
|
||||
}
|
||||
}
|
||||
if (model_name.empty()) {
|
||||
BOOST_LOG_TRIVIAL(error) << "Failed to select printer from Connect. Printer_model is empty.";
|
||||
return false;
|
||||
}
|
||||
std::string nozzle = plater()->get_user_account()->get_nozzle_from_json(msg);
|
||||
assert(!model_name.empty());
|
||||
if (model_name.empty())
|
||||
return;
|
||||
|
||||
BOOST_LOG_TRIVIAL(info) << "Select printer from Connect. Model: " << model_name << "nozzle: " << nozzle;
|
||||
// select printer
|
||||
const Preset* preset = preset_bundle->printers.find_system_preset_by_model_and_variant(model_name, nozzle);
|
||||
bool is_installed = preset && select_printer_from_connect(preset);
|
||||
const Preset* printer_preset = preset_bundle->printers.find_system_preset_by_model_and_variant(model_name, nozzle);
|
||||
bool is_installed = printer_preset && select_printer_preset(printer_preset);
|
||||
// notification
|
||||
std::string out = preset ?
|
||||
(is_installed ? GUI::format(_L("Installed and Select Printer:\n%1%"), preset->name) :
|
||||
GUI::format(_L("Select Printer:\n%1%"), preset->name) ):
|
||||
GUI::format(_L("Printer not found:\n%1%"), model_name);
|
||||
this->plater()->get_notification_manager()->close_notification_of_type(NotificationType::UserAccountID);
|
||||
this->plater()->get_notification_manager()->push_notification(NotificationType::UserAccountID, NotificationManager::NotificationLevel::ImportantNotificationLevel, out);
|
||||
std::string out = printer_preset ?
|
||||
(is_installed ? GUI::format(_L("Installed and Selected Printer:\n%1%"), printer_preset->name) :
|
||||
GUI::format(_L("Selected Printer:\n%1%"), printer_preset->name)) :
|
||||
GUI::format(_L("Printer not found:\n%1%"), model_name);
|
||||
this->plater()->get_notification_manager()->close_notification_of_type(NotificationType::SelectPrinterFromConnect);
|
||||
this->plater()->get_notification_manager()->push_notification(
|
||||
NotificationType::SelectPrinterFromConnect
|
||||
, printer_preset ? NotificationManager::NotificationLevel::ImportantNotificationLevel : NotificationManager::NotificationLevel::WarningNotificationLevel
|
||||
, out);
|
||||
return printer_preset;
|
||||
}
|
||||
|
||||
bool GUI_App::select_filament_preset(const Preset* preset, size_t extruder_index)
|
||||
{
|
||||
assert(preset && preset->is_compatible);
|
||||
|
||||
if (!preset->is_visible) {
|
||||
// To correct update of presets visibility call select_preset for preset_bundle->filaments()
|
||||
size_t preset_id = preset_bundle->filaments.get_preset_idx_by_name(preset->name);
|
||||
assert(preset_id != size_t(-1));
|
||||
preset_bundle->filaments.select_preset(preset_id);
|
||||
}
|
||||
assert(preset->is_visible);
|
||||
return preset_bundle->extruders_filaments[extruder_index].select_filament(preset->name);
|
||||
}
|
||||
void GUI_App::search_and_select_filaments(const std::string& material, size_t extruder_index, std::string& out_message)
|
||||
{
|
||||
const DynamicPrintConfig& config = preset_bundle->extruders_filaments[extruder_index].get_selected_preset()->config;
|
||||
// selected is ok
|
||||
if (config.has("filament_type") && config.option("filament_type")->serialize() == material) {
|
||||
return;
|
||||
}
|
||||
// find first installed compatible filament with suitable type and select it
|
||||
for (const auto& filament : preset_bundle->extruders_filaments[extruder_index]) {
|
||||
if (filament.is_compatible
|
||||
&& !filament.preset->is_default
|
||||
&& filament.preset->is_visible
|
||||
&& !filament.preset->vendor->templates_profile
|
||||
&& filament.preset->config.has("filament_type")
|
||||
&& filament.preset->config.option("filament_type")->serialize() == material
|
||||
&& select_filament_preset(filament.preset, extruder_index)
|
||||
)
|
||||
{
|
||||
out_message += /*(extruder_count == 1)
|
||||
? GUI::format(_L("Selected Filament:\n%1%"), filament_preset.preset->name)
|
||||
: */GUI::format(_L("Extruder %1%: Selected Filament %2%\n"), extruder_index + 1, filament.preset->name);
|
||||
return;
|
||||
}
|
||||
}
|
||||
// find profile to install
|
||||
// try finding Prusament
|
||||
for (const auto& filament : preset_bundle->extruders_filaments[extruder_index]) {
|
||||
if (filament.is_compatible
|
||||
&& !filament.preset->is_default
|
||||
&& !filament.preset->vendor->templates_profile
|
||||
&& filament.preset->config.has("filament_type")
|
||||
&& filament.preset->config.option("filament_type")->serialize() == material
|
||||
&& filament.preset->name.compare(0, 9, "Prusament") == 0
|
||||
&& select_filament_preset(filament.preset, extruder_index))
|
||||
{
|
||||
out_message += GUI::format(_L("Extruder %1%: Selected and Installed Filament %2%\n"), extruder_index + 1, filament.preset->name);
|
||||
return;
|
||||
}
|
||||
}
|
||||
out_message += GUI::format(_L("Extruder %2%: Failed to Find and Select Filament type: %1%\n"), material, extruder_index + 1);
|
||||
}
|
||||
|
||||
void GUI_App::select_filament_from_connect(const std::string& msg)
|
||||
{
|
||||
// parse message
|
||||
std::vector<std::string> materials;
|
||||
plater()->get_user_account()->fill_material_from_json(msg, materials);
|
||||
if (materials.empty()) {
|
||||
BOOST_LOG_TRIVIAL(error) << "Failed to select filament from Connect. No material data.";
|
||||
return;
|
||||
}
|
||||
// test if currently selected is same type
|
||||
size_t extruder_count = preset_bundle->extruders_filaments.size();
|
||||
if (extruder_count != materials.size()) {
|
||||
BOOST_LOG_TRIVIAL(error) << format("Failed to select filament from Connect. Selected printer has %1% extruders while data from Connect contains %2% materials.", extruder_count, materials.size());
|
||||
return;
|
||||
}
|
||||
std::string notification_text;
|
||||
for (size_t i = 0; i < extruder_count; i++) {
|
||||
search_and_select_filaments(materials[i], i, notification_text);
|
||||
}
|
||||
|
||||
// When all filaments are selected/intalled,
|
||||
// then update preset comboboxes on sidebar
|
||||
sidebar().update_presets(Preset::TYPE_FILAMENT);
|
||||
// and filaments tab
|
||||
TabFilament* tab = dynamic_cast<TabFilament*>(get_tab(Preset::TYPE_FILAMENT));
|
||||
tab->select_preset(preset_bundle->extruders_filaments[tab->get_active_extruder()].get_selected_preset_name());
|
||||
|
||||
if (!notification_text.empty()) {
|
||||
plater()->get_notification_manager()->close_notification_of_type(NotificationType::SelectFilamentFromConnect);
|
||||
plater()->get_notification_manager()->push_notification(NotificationType::SelectFilamentFromConnect, NotificationManager::NotificationLevel::ImportantNotificationLevel, notification_text);
|
||||
}
|
||||
}
|
||||
|
||||
void GUI_App::handle_connect_request_printer_pick(const std::string& msg)
|
||||
{
|
||||
BOOST_LOG_TRIVIAL(debug) << "Handling web request: " << msg;
|
||||
// return to plater
|
||||
this->mainframe->select_tab(size_t(0));
|
||||
|
||||
if (!select_printer_from_connect(msg)) {
|
||||
// If printer was not selected, do not select filament.
|
||||
return;
|
||||
}
|
||||
// TODO: Selecting SLA material
|
||||
if (Preset::printer_technology(preset_bundle->printers.get_selected_preset().config) != ptFFF) {
|
||||
return;
|
||||
}
|
||||
select_filament_from_connect(msg);
|
||||
}
|
||||
|
||||
void GUI_App::show_printer_webview_tab()
|
||||
|
@ -371,7 +371,9 @@ public:
|
||||
void open_web_page_localized(const std::string &http_address);
|
||||
bool may_switch_to_SLA_preset(const wxString& caption);
|
||||
bool run_wizard(ConfigWizard::RunReason reason, ConfigWizard::StartPage start_page = ConfigWizard::SP_WELCOME);
|
||||
#if 0
|
||||
void update_login_dialog();
|
||||
#endif // 0
|
||||
void show_desktop_integration_dialog();
|
||||
void show_downloader_registration_dialog();
|
||||
|
||||
@ -409,10 +411,14 @@ public:
|
||||
void request_user_login(int online_login) {}
|
||||
void request_user_logout() {}
|
||||
int request_user_unbind(std::string dev_id) { return 0; }
|
||||
void handle_connect_request_printer_pick(std::string cmd);
|
||||
bool select_printer_from_connect(const std::string& cmd);
|
||||
void select_filament_from_connect(const std::string& cmd);
|
||||
void handle_connect_request_printer_pick(const std::string& cmd);
|
||||
void show_printer_webview_tab();
|
||||
// return true if preset vas invisible and we have to installed it to make it selectable
|
||||
bool select_printer_from_connect(const Preset* printer_preset);
|
||||
bool select_printer_preset(const Preset* printer_preset);
|
||||
bool select_filament_preset(const Preset* filament_preset, size_t extruder_index);
|
||||
void search_and_select_filaments(const std::string& material, size_t extruder_index, std::string& out_message);
|
||||
void handle_script_message(std::string msg) {}
|
||||
void request_model_download(std::string import_json) {}
|
||||
void download_project(std::string project_id) {}
|
||||
@ -446,8 +452,9 @@ private:
|
||||
// change to vector of items when adding more items that require update
|
||||
//wxMenuItem* m_login_config_menu_item { nullptr };
|
||||
std::map< ConfigMenuIDs, wxMenuItem*> m_config_menu_updatable_items;
|
||||
|
||||
#if 0
|
||||
std::unique_ptr<LoginDialog> m_login_dialog;
|
||||
#endif // 0
|
||||
};
|
||||
|
||||
DECLARE_APP(GUI_App)
|
||||
|
@ -777,7 +777,7 @@ void MainFrame::remove_connect_webview_tab()
|
||||
void MainFrame::show_printer_webview_tab(DynamicPrintConfig* dpc)
|
||||
{
|
||||
// if physical printer is selected
|
||||
if (dpc) {
|
||||
if (dpc && dpc->option<ConfigOptionEnum<PrintHostType>>("host_type")->value != htPrusaConnect) {
|
||||
std::string url = dpc->opt_string("print_host");
|
||||
|
||||
if (url.find("http://") != 0 && url.find("https://") != 0) {
|
||||
|
@ -131,6 +131,9 @@ enum class NotificationType
|
||||
WifiConfigFileDetected,
|
||||
// Info abouty successful login or logout
|
||||
UserAccountID,
|
||||
// When in Connect tab "set as current" is selected and selected presets in plater changes
|
||||
SelectPrinterFromConnect,
|
||||
SelectFilamentFromConnect,
|
||||
// Debug notification for connect communication
|
||||
PrusaConnectPrinters,
|
||||
};
|
||||
|
@ -837,7 +837,7 @@ Plater::priv::priv(Plater *q, MainFrame *main_frame)
|
||||
// Reset the "dirty project" flag.
|
||||
m_undo_redo_stack_main.mark_current_as_saved();
|
||||
dirty_state.update_from_undo_redo_stack(false);
|
||||
|
||||
|
||||
this->q->Bind(EVT_LOAD_MODEL_OTHER_INSTANCE, [this](LoadFromOtherInstanceEvent& evt) {
|
||||
BOOST_LOG_TRIVIAL(trace) << "Received load from other instance event.";
|
||||
wxArrayString input_files;
|
||||
@ -847,67 +847,83 @@ Plater::priv::priv(Plater *q, MainFrame *main_frame)
|
||||
wxGetApp().mainframe->Raise();
|
||||
this->q->load_files(input_files);
|
||||
});
|
||||
|
||||
this->q->Bind(EVT_START_DOWNLOAD_OTHER_INSTANCE, [](StartDownloadOtherInstanceEvent& evt) {
|
||||
BOOST_LOG_TRIVIAL(trace) << "Received url from other instance event.";
|
||||
wxGetApp().mainframe->Raise();
|
||||
for (size_t i = 0; i < evt.data.size(); ++i) {
|
||||
wxGetApp().start_download(evt.data[i]);
|
||||
}
|
||||
|
||||
});
|
||||
this->q->Bind(EVT_LOGIN_OTHER_INSTANCE, [this](LoginOtherInstanceEvent& evt) {
|
||||
BOOST_LOG_TRIVIAL(trace) << "Received login from other instance event.";
|
||||
user_account->on_login_code_recieved(evt.data);
|
||||
});
|
||||
|
||||
this->q->Bind(EVT_INSTANCE_GO_TO_FRONT, [this](InstanceGoToFrontEvent &) {
|
||||
this->q->Bind(EVT_INSTANCE_GO_TO_FRONT, [this](InstanceGoToFrontEvent&) {
|
||||
bring_instance_forward();
|
||||
});
|
||||
|
||||
this->q->Bind(EVT_OPEN_PRUSAAUTH, [](OpenPrusaAuthEvent& evt) {
|
||||
BOOST_LOG_TRIVIAL(info) << "open browser: " << evt.data;
|
||||
// first register url to be sure to get the code back
|
||||
//auto downloader_worker = new DownloaderUtils::Worker(nullptr);
|
||||
DownloaderUtils::Worker::perform_register(wxGetApp().app_config->get("url_downloader_dest"));
|
||||
#ifdef __linux__
|
||||
if (DownloaderUtils::Worker::perform_registration_linux)
|
||||
DesktopIntegrationDialog::perform_downloader_desktop_integration();
|
||||
#endif // __linux__
|
||||
// than open url
|
||||
wxGetApp().open_login_browser_with_dialog(evt.data);
|
||||
});
|
||||
// Downloader and USerAccount Events doesnt need to be binded in viewer.
|
||||
// Not binding Account events prevents it from loging in.
|
||||
if (wxGetApp().is_editor()) {
|
||||
this->q->Bind(EVT_START_DOWNLOAD_OTHER_INSTANCE, [](StartDownloadOtherInstanceEvent& evt) {
|
||||
BOOST_LOG_TRIVIAL(trace) << "Received url from other instance event.";
|
||||
wxGetApp().mainframe->Raise();
|
||||
for (size_t i = 0; i < evt.data.size(); ++i) {
|
||||
wxGetApp().start_download(evt.data[i]);
|
||||
}
|
||||
});
|
||||
this->q->Bind(EVT_LOGIN_OTHER_INSTANCE, [this](LoginOtherInstanceEvent& evt) {
|
||||
BOOST_LOG_TRIVIAL(trace) << "Received login from other instance event.";
|
||||
user_account->on_login_code_recieved(evt.data);
|
||||
});
|
||||
this->q->Bind(EVT_OPEN_PRUSAAUTH, [](OpenPrusaAuthEvent& evt) {
|
||||
BOOST_LOG_TRIVIAL(info) << "open browser: " << evt.data;
|
||||
// first register url to be sure to get the code back
|
||||
//auto downloader_worker = new DownloaderUtils::Worker(nullptr);
|
||||
DownloaderUtils::Worker::perform_register(wxGetApp().app_config->get("url_downloader_dest"));
|
||||
#ifdef __linux__
|
||||
if (DownloaderUtils::Worker::perform_registration_linux)
|
||||
DesktopIntegrationDialog::perform_downloader_desktop_integration();
|
||||
#endif // __linux__
|
||||
// than open url
|
||||
wxGetApp().open_login_browser_with_dialog(evt.data);
|
||||
});
|
||||
|
||||
this->q->Bind(EVT_UA_LOGGEDOUT, [this](UserAccountSuccessEvent& evt) {
|
||||
user_account->clear();
|
||||
std::string text = _u8L("Logged out from Prusa Account.");
|
||||
this->notification_manager->close_notification_of_type(NotificationType::UserAccountID);
|
||||
this->notification_manager->push_notification(NotificationType::UserAccountID, NotificationManager::NotificationLevel::ImportantNotificationLevel, text);
|
||||
this->main_frame->remove_connect_webview_tab();
|
||||
this->main_frame->refresh_account_menu(true);
|
||||
// Update sidebar printer status
|
||||
sidebar->update_printer_presets_combobox();
|
||||
wxGetApp().update_login_dialog();
|
||||
this->show_action_buttons(this->ready_to_slice);
|
||||
});
|
||||
|
||||
this->q->Bind(EVT_UA_ID_USER_SUCCESS, [this](UserAccountSuccessEvent& evt) {
|
||||
std::string username;
|
||||
if (user_account->on_user_id_success(evt.data, username)) {
|
||||
// login notification
|
||||
std::string text = format(_u8L("Logged to Prusa Account as %1%."), username);
|
||||
this->q->Bind(EVT_UA_LOGGEDOUT, [this](UserAccountSuccessEvent& evt) {
|
||||
user_account->clear();
|
||||
std::string text = _u8L("Logged out from Prusa Account.");
|
||||
this->notification_manager->close_notification_of_type(NotificationType::UserAccountID);
|
||||
this->notification_manager->push_notification(NotificationType::UserAccountID, NotificationManager::NotificationLevel::ImportantNotificationLevel, text);
|
||||
// show connect tab
|
||||
this->main_frame->add_connect_webview_tab();
|
||||
// Update User name in TopBar
|
||||
this->main_frame->refresh_account_menu();
|
||||
this->main_frame->remove_connect_webview_tab();
|
||||
this->main_frame->refresh_account_menu(true);
|
||||
// Update sidebar printer status
|
||||
sidebar->update_printer_presets_combobox();
|
||||
#if 0
|
||||
wxGetApp().update_login_dialog();
|
||||
#endif // 0
|
||||
this->show_action_buttons(this->ready_to_slice);
|
||||
} else {
|
||||
// data were corrupt and username was not retrieved
|
||||
// procced as if EVT_UA_RESET was recieved
|
||||
BOOST_LOG_TRIVIAL(error) << "Reseting Prusa Account communication. Recieved data were corrupt.";
|
||||
});
|
||||
|
||||
this->q->Bind(EVT_UA_ID_USER_SUCCESS, [this](UserAccountSuccessEvent& evt) {
|
||||
std::string username;
|
||||
if (user_account->on_user_id_success(evt.data, username)) {
|
||||
// login notification
|
||||
std::string text = format(_u8L("Logged to Prusa Account as %1%."), username);
|
||||
this->notification_manager->close_notification_of_type(NotificationType::UserAccountID);
|
||||
this->notification_manager->push_notification(NotificationType::UserAccountID, NotificationManager::NotificationLevel::ImportantNotificationLevel, text);
|
||||
// show connect tab
|
||||
this->main_frame->add_connect_webview_tab();
|
||||
// Update User name in TopBar
|
||||
this->main_frame->refresh_account_menu();
|
||||
#if 0
|
||||
wxGetApp().update_login_dialog();
|
||||
#endif // 0
|
||||
this->show_action_buttons(this->ready_to_slice);
|
||||
} else {
|
||||
// data were corrupt and username was not retrieved
|
||||
// procced as if EVT_UA_RESET was recieved
|
||||
BOOST_LOG_TRIVIAL(error) << "Reseting Prusa Account communication. Recieved data were corrupt.";
|
||||
user_account->clear();
|
||||
this->notification_manager->close_notification_of_type(NotificationType::UserAccountID);
|
||||
this->notification_manager->push_notification(NotificationType::UserAccountID, NotificationManager::NotificationLevel::WarningNotificationLevel, _u8L("Failed to connect to Prusa Account."));
|
||||
this->main_frame->remove_connect_webview_tab();
|
||||
// Update User name in TopBar
|
||||
this->main_frame->refresh_account_menu(true);
|
||||
// Update sidebar printer status
|
||||
sidebar->update_printer_presets_combobox();
|
||||
}
|
||||
|
||||
});
|
||||
this->q->Bind(EVT_UA_RESET, [this](UserAccountFailEvent& evt) {
|
||||
BOOST_LOG_TRIVIAL(error) << "Reseting Prusa Account communication. Error message: " << evt.data;
|
||||
user_account->clear();
|
||||
this->notification_manager->close_notification_of_type(NotificationType::UserAccountID);
|
||||
this->notification_manager->push_notification(NotificationType::UserAccountID, NotificationManager::NotificationLevel::WarningNotificationLevel, _u8L("Failed to connect to Prusa Account."));
|
||||
@ -916,45 +932,48 @@ Plater::priv::priv(Plater *q, MainFrame *main_frame)
|
||||
this->main_frame->refresh_account_menu(true);
|
||||
// Update sidebar printer status
|
||||
sidebar->update_printer_presets_combobox();
|
||||
}
|
||||
|
||||
});
|
||||
this->q->Bind(EVT_UA_RESET, [this](UserAccountFailEvent& evt) {
|
||||
BOOST_LOG_TRIVIAL(error) << "Reseting Prusa Account communication. Error message: " << evt.data;
|
||||
user_account->clear();
|
||||
this->notification_manager->close_notification_of_type(NotificationType::UserAccountID);
|
||||
this->notification_manager->push_notification(NotificationType::UserAccountID, NotificationManager::NotificationLevel::WarningNotificationLevel, _u8L("Failed to connect to Prusa Account."));
|
||||
this->main_frame->remove_connect_webview_tab();
|
||||
// Update User name in TopBar
|
||||
this->main_frame->refresh_account_menu(true);
|
||||
// Update sidebar printer status
|
||||
sidebar->update_printer_presets_combobox();
|
||||
});
|
||||
this->q->Bind(EVT_UA_FAIL, [this](UserAccountFailEvent& evt) {
|
||||
BOOST_LOG_TRIVIAL(error) << "Failed communication with Prusa Account: " << evt.data;
|
||||
user_account->on_communication_fail();
|
||||
});
|
||||
this->q->Bind(EVT_UA_PRUSACONNECT_PRINTERS_SUCCESS, [this](UserAccountSuccessEvent& evt) {
|
||||
std::string text;
|
||||
bool printers_changed = false;
|
||||
if (user_account->on_connect_printers_success(evt.data, wxGetApp().app_config, printers_changed)) {
|
||||
if (printers_changed) {
|
||||
sidebar->update_printer_presets_combobox();
|
||||
}
|
||||
} else {
|
||||
// message was corrupt, procceed like EVT_UA_FAIL
|
||||
});
|
||||
this->q->Bind(EVT_UA_FAIL, [this](UserAccountFailEvent& evt) {
|
||||
BOOST_LOG_TRIVIAL(error) << "Failed communication with Prusa Account: " << evt.data;
|
||||
user_account->on_communication_fail();
|
||||
}
|
||||
});
|
||||
this->q->Bind(EVT_UA_AVATAR_SUCCESS, [this](UserAccountSuccessEvent& evt) {
|
||||
boost::filesystem::path path = user_account->get_avatar_path(true);
|
||||
FILE* file;
|
||||
file = fopen(path.string().c_str(), "wb");
|
||||
fwrite(evt.data.c_str(), 1, evt.data.size(), file);
|
||||
fclose(file);
|
||||
this->main_frame->refresh_account_menu(true);
|
||||
wxGetApp().update_login_dialog();
|
||||
});
|
||||
});
|
||||
this->q->Bind(EVT_UA_PRUSACONNECT_STATUS_SUCCESS, [this](UserAccountSuccessEvent& evt) {
|
||||
std::string text;
|
||||
bool printers_changed = false;
|
||||
if (user_account->on_connect_printers_success(evt.data, wxGetApp().app_config, printers_changed)) {
|
||||
if (printers_changed) {
|
||||
sidebar->update_printer_presets_combobox();
|
||||
}
|
||||
} else {
|
||||
// message was corrupt, procceed like EVT_UA_FAIL
|
||||
user_account->on_communication_fail();
|
||||
}
|
||||
});
|
||||
this->q->Bind(EVT_UA_PRUSACONNECT_PRINTER_MODELS_SUCCESS, [this](UserAccountSuccessEvent& evt) {
|
||||
std::string text;
|
||||
bool printers_changed = false;
|
||||
if (user_account->on_connect_uiid_map_success(evt.data, wxGetApp().app_config, printers_changed)) {
|
||||
if (printers_changed) {
|
||||
sidebar->update_printer_presets_combobox();
|
||||
}
|
||||
}
|
||||
else {
|
||||
// message was corrupt, procceed like EVT_UA_FAIL
|
||||
user_account->on_communication_fail();
|
||||
}
|
||||
});
|
||||
this->q->Bind(EVT_UA_AVATAR_SUCCESS, [this](UserAccountSuccessEvent& evt) {
|
||||
boost::filesystem::path path = user_account->get_avatar_path(true);
|
||||
FILE* file;
|
||||
file = fopen(path.string().c_str(), "wb");
|
||||
fwrite(evt.data.c_str(), 1, evt.data.size(), file);
|
||||
fclose(file);
|
||||
this->main_frame->refresh_account_menu(true);
|
||||
#if 0
|
||||
wxGetApp().update_login_dialog();
|
||||
#endif // 0
|
||||
});
|
||||
}
|
||||
|
||||
wxGetApp().other_instance_message_handler()->init(this->q);
|
||||
|
||||
@ -5855,20 +5874,46 @@ void Plater::connect_gcode()
|
||||
PresetBundle* preset_bundle = wxGetApp().preset_bundle;
|
||||
// Connect data
|
||||
std::vector<std::string> compatible_printers;
|
||||
p->user_account->fill_compatible_printers_from_json(dialog_msg, compatible_printers);
|
||||
p->user_account->fill_supported_printer_models_from_json(dialog_msg, compatible_printers);
|
||||
std::string connect_nozzle = p->user_account->get_nozzle_from_json(dialog_msg);
|
||||
std::string connect_filament = p->user_account->get_keyword_from_json(dialog_msg, "filament_type");
|
||||
|
||||
std::vector<std::string> connect_materials;
|
||||
p->user_account->fill_material_from_json(dialog_msg, connect_materials);
|
||||
|
||||
std::vector<const Preset*> compatible_printer_presets;
|
||||
for (const std::string& cp : compatible_printers) {
|
||||
compatible_printer_presets.emplace_back(preset_bundle->printers.find_system_preset_by_model_and_variant(cp, connect_nozzle));
|
||||
const Preset* found_preset = preset_bundle->printers.find_system_preset_by_model_and_variant(cp, connect_nozzle);
|
||||
if (found_preset) {
|
||||
compatible_printer_presets.emplace_back(found_preset);
|
||||
}
|
||||
}
|
||||
if (compatible_printer_presets.empty()) {
|
||||
show_error(this, _L("No compatible printer presets found."));
|
||||
return;
|
||||
}
|
||||
// Selected profiles
|
||||
const Preset* selected_printer_preset = &preset_bundle->printers.get_selected_preset();
|
||||
const Preset* selected_filament_preset = &preset_bundle->filaments.get_selected_preset();
|
||||
const std::string selected_nozzle_serialized = dynamic_cast<const ConfigOptionFloats*>(selected_printer_preset->config.option("nozzle_diameter"))->serialize();
|
||||
const std::string selected_filament_serialized = selected_filament_preset->config.option("filament_type")->serialize();
|
||||
const std::string selected_printer_model_serialized = selected_printer_preset->config.option("printer_model")->serialize();
|
||||
|
||||
|
||||
bool selected_filament_ok = true;
|
||||
if (Preset::printer_technology(selected_printer_preset->config) == ptFFF) {
|
||||
size_t extruder_count = preset_bundle->extruders_filaments.size();
|
||||
for (size_t i = 0; i < extruder_count; i++) {
|
||||
if (connect_materials.size() <= i) {
|
||||
selected_filament_ok = false;
|
||||
break;
|
||||
}
|
||||
const Preset* selected_filament_preset = preset_bundle->extruders_filaments[i].get_selected_preset();
|
||||
if (selected_filament_preset && selected_filament_preset->config.has("filament_type")
|
||||
&& selected_filament_preset->config.option("filament_type")->serialize() != connect_materials[i])
|
||||
{
|
||||
selected_filament_ok = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool is_first = compatible_printer_presets.front()->name == selected_printer_preset->name;
|
||||
bool found = false;
|
||||
for (const Preset* connect_preset : compatible_printer_presets) {
|
||||
@ -5880,9 +5925,9 @@ void Plater::connect_gcode()
|
||||
break;
|
||||
}
|
||||
}
|
||||
//
|
||||
// Dialog to select action
|
||||
if (!found) {
|
||||
wxString line1 = _L("The printer profile you've selected for upload is not compatible with profiles selected for slicing.");
|
||||
wxString line1 = _L("The printer you've selected for upload is not compatible with profiles selected for slicing.");
|
||||
wxString line2 = GUI::format_wxstr(_L("PrusaSlicer Profile:\n%1%"), selected_printer_preset->name);
|
||||
wxString line3 = _L("Known profiles compatible with printer selected for upload:");
|
||||
wxString printers_line;
|
||||
@ -5900,7 +5945,7 @@ void Plater::connect_gcode()
|
||||
return;
|
||||
}
|
||||
} else if (!is_first) {
|
||||
wxString line1 = _L("The printer profile you've selected for upload might not be compatible with profiles selected for slicing.");
|
||||
wxString line1 = _L("The printer you've selected for upload might not be compatible with profiles selected for slicing.");
|
||||
wxString line2 = GUI::format_wxstr(_L("PrusaSlicer Profile:\n%1%"), selected_printer_preset->name);
|
||||
wxString line3 = _L("Known profiles compatible with printer selected for upload:");
|
||||
wxString printers_line;
|
||||
@ -5918,29 +5963,33 @@ void Plater::connect_gcode()
|
||||
return;
|
||||
}
|
||||
}
|
||||
// Commented code with selecting printers in plater
|
||||
/*
|
||||
// if selected (in connect) preset is not visible, make it visible and selected
|
||||
if (!connect_printer_preset->is_visible) {
|
||||
size_t preset_id = preset_bundle->printers.get_preset_idx_by_name(connect_printer_preset->name);
|
||||
assert(preset_id != size_t(-1));
|
||||
preset_bundle->printers.select_preset(preset_id);
|
||||
wxGetApp().get_tab(Preset::Type::TYPE_PRINTER)->select_preset(connect_printer_preset->name);
|
||||
p->notification_manager->close_notification_of_type(NotificationType::PrusaConnectPrinters);
|
||||
p->notification_manager->push_notification(NotificationType::PrusaConnectPrinters, NotificationManager::NotificationLevel::ImportantNotificationLevel, format(_u8L("Changed Printer to %1%."), connect_printer_preset->name));
|
||||
select_view_3D("3D");
|
||||
|
||||
if (!connect_materials.empty() && !selected_filament_ok) {
|
||||
wxString line1 = _L("The printer you've selected has different filament type than filament profile selected for slicing.");
|
||||
wxString connect_filament_types = "\n";
|
||||
for (size_t i = 0; i < connect_materials.size(); i++) {
|
||||
connect_filament_types += GUI::format_wxstr(_L("Extruder %1%: %2%\n"), i + 1, connect_materials[i]);
|
||||
}
|
||||
wxString line2 = GUI::format_wxstr(_L("PrusaConnect Filament Type: %1%"), connect_filament_types);
|
||||
|
||||
wxString selected_filament_types = "\n";
|
||||
for (size_t i = 0; i < preset_bundle->extruders_filaments.size(); i++) {
|
||||
const Preset* selected_filament_preset = preset_bundle->extruders_filaments[i].get_selected_preset();
|
||||
std::string filament_serialized;
|
||||
if (selected_filament_preset && selected_filament_preset->config.has("filament_type")) {
|
||||
filament_serialized = selected_filament_preset->config.option("filament_type")->serialize();
|
||||
}
|
||||
// if selected (in connect) preset is not selected in slicer, select it
|
||||
if (preset_bundle->printers.get_selected_preset_name() != connect_printer_preset->name) {
|
||||
size_t preset_id = preset_bundle->printers.get_preset_idx_by_name(connect_printer_preset->name);
|
||||
assert(preset_id != size_t(-1));
|
||||
preset_bundle->printers.select_preset(preset_id);
|
||||
wxGetApp().get_tab(Preset::Type::TYPE_PRINTER)->select_preset(connect_printer_preset->name);
|
||||
p->notification_manager->close_notification_of_type(NotificationType::PrusaConnectPrinters);
|
||||
p->notification_manager->push_notification(NotificationType::PrusaConnectPrinters, NotificationManager::NotificationLevel::ImportantNotificationLevel, format(_u8L("Changed Printer to %1%."), connect_printer_preset->name));
|
||||
select_view_3D("3D");
|
||||
}
|
||||
*/
|
||||
selected_filament_types += GUI::format_wxstr(_L("Extruder %1%: %2%\n"), i + 1, filament_serialized);
|
||||
}
|
||||
wxString line3 = GUI::format_wxstr(_L("PrusaSlicer Filament Type: %1%"), selected_filament_types);
|
||||
wxString line4 = _L("Do you still wish to upload?");
|
||||
wxString message = GUI::format_wxstr("%1%\n\n%2%\n%3%\n\n%4%", line1, line2, line3, line4);
|
||||
MessageDialog msg_dialog(this, message, _L("Do you wish to upload?"), wxYES_NO);
|
||||
auto modal_res = msg_dialog.ShowModal();
|
||||
if (modal_res != wxID_YES) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
const std::string connect_state = p->user_account->get_keyword_from_json(dialog_msg, "connect_state");
|
||||
const std::string printer_state = p->user_account->get_keyword_from_json(dialog_msg, "printer_state");
|
||||
@ -5959,7 +6008,7 @@ void Plater::connect_gcode()
|
||||
show_error(this, _L("Failed to select a printer. Missing data (uuid and team id) for chosen printer."));
|
||||
return;
|
||||
}
|
||||
PhysicalPrinter ph_printer("connect_temp_printer", wxGetApp().preset_bundle->physical_printers.default_config(), /**connect_printer_preset*/*selected_printer_preset);
|
||||
PhysicalPrinter ph_printer("connect_temp_printer", wxGetApp().preset_bundle->physical_printers.default_config(), *selected_printer_preset);
|
||||
ph_printer.config.set_key_value("host_type", new ConfigOptionEnum<PrintHostType>(htPrusaConnectNew));
|
||||
// use existing structures to pass data
|
||||
ph_printer.config.opt_string("printhost_apikey") = team_id;
|
||||
|
@ -374,8 +374,10 @@ void PresetComboBox::edit_physical_printer()
|
||||
return;
|
||||
|
||||
PhysicalPrinterDialog dlg(this->GetParent(),this->GetString(this->GetSelection()));
|
||||
if (dlg.ShowModal() == wxID_OK)
|
||||
if (dlg.ShowModal() == wxID_OK) {
|
||||
update();
|
||||
wxGetApp().show_printer_webview_tab();
|
||||
}
|
||||
}
|
||||
|
||||
void PresetComboBox::add_physical_printer()
|
||||
@ -610,6 +612,9 @@ bool PresetComboBox::selection_is_changed_according_to_physical_printers()
|
||||
else if (dynamic_cast<TabPresetComboBox*>(this)!=nullptr)
|
||||
wxGetApp().sidebar().update_presets(m_type);
|
||||
|
||||
// Check and show "Physical printer" page if needed
|
||||
wxGetApp().show_printer_webview_tab();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -885,9 +890,11 @@ static std::string get_connect_state_suffix_for_printer(const Preset& printer_pr
|
||||
if (auto printer_state_map = wxGetApp().plater()->get_user_account()->get_printer_state_map();
|
||||
!printer_state_map.empty()) {
|
||||
|
||||
for (const auto& [printer_model_id, states] : printer_state_map) {
|
||||
if (printer_model_id == printer_preset.config.opt_string("printer_model")) {
|
||||
|
||||
for (const auto& [printer_model_nozzle_pair, states] : printer_state_map) {
|
||||
if (printer_model_nozzle_pair.first == printer_preset.config.opt_string("printer_model")
|
||||
&& (printer_model_nozzle_pair.second.empty()
|
||||
|| printer_model_nozzle_pair.second == printer_preset.config.opt_string("nozzle_diamenter"))
|
||||
) {
|
||||
PrinterStatesCount states_cnt = get_printe_states_count(states);
|
||||
|
||||
if (states_cnt.available_cnt > 0)
|
||||
@ -907,9 +914,11 @@ static wxString get_connect_info_line(const Preset& printer_preset)
|
||||
if (auto printer_state_map = wxGetApp().plater()->get_user_account()->get_printer_state_map();
|
||||
!printer_state_map.empty()) {
|
||||
|
||||
for (const auto& [printer_model_id, states] : printer_state_map) {
|
||||
if (printer_model_id == printer_preset.config.opt_string("printer_model")) {
|
||||
|
||||
for (const auto& [printer_model_nozzle_pair, states] : printer_state_map) {
|
||||
if (printer_model_nozzle_pair.first == printer_preset.config.opt_string("printer_model")
|
||||
&& (printer_model_nozzle_pair.second.empty()
|
||||
|| printer_model_nozzle_pair.second == printer_preset.config.opt_string("nozzle_diamenter"))
|
||||
) {
|
||||
PrinterStatesCount states_cnt = get_printe_states_count(states);
|
||||
|
||||
return format_wxstr(_L("Available: %1%, Offline: %2%, Busy: %3%. Total: %4% printers"),
|
||||
|
@ -84,10 +84,13 @@ boost::filesystem::path UserAccount::get_avatar_path(bool logged) const
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void UserAccount::enqueue_connect_printers_action()
|
||||
void UserAccount::enqueue_connect_printer_models_action()
|
||||
{
|
||||
m_communication->enqueue_connect_printers_action();
|
||||
m_communication->enqueue_connect_printer_models_action();
|
||||
}
|
||||
void UserAccount::enqueue_connect_status_action()
|
||||
{
|
||||
m_communication->enqueue_connect_status_action();
|
||||
}
|
||||
void UserAccount::enqueue_avatar_action()
|
||||
{
|
||||
@ -137,7 +140,7 @@ bool UserAccount::on_user_id_success(const std::string data, std::string& out_us
|
||||
BOOST_LOG_TRIVIAL(error) << "User ID message from PrusaAuth did not contain avatar.";
|
||||
}
|
||||
// update printers list
|
||||
enqueue_connect_printers_action();
|
||||
enqueue_connect_printer_models_action();
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -157,15 +160,25 @@ namespace {
|
||||
for (const auto& section : tree) {
|
||||
if (section.first == param) {
|
||||
return section.second.data();
|
||||
} else {
|
||||
if (std::string res = parse_tree_for_param(section.second, param); !res.empty())
|
||||
return res;
|
||||
}
|
||||
|
||||
if (std::string res = parse_tree_for_param(section.second, param); !res.empty()) {
|
||||
return res;
|
||||
}
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
void parse_tree_for_param_vector(const pt::ptree& tree, const std::string& param, std::vector<std::string>& results)
|
||||
{
|
||||
for (const auto& section : tree) {
|
||||
if (section.first == param) {
|
||||
results.emplace_back(section.second.data());
|
||||
} else {
|
||||
parse_tree_for_param_vector(section.second, param, results);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pt::ptree parse_tree_for_subtree(const pt::ptree& tree, const std::string& param)
|
||||
{
|
||||
for (const auto& section : tree) {
|
||||
@ -194,51 +207,46 @@ bool UserAccount::on_connect_printers_success(const std::string& data, AppConfig
|
||||
BOOST_LOG_TRIVIAL(error) << "Could not parse prusaconnect message. " << e.what();
|
||||
return false;
|
||||
}
|
||||
// fill m_printer_map with data from ptree
|
||||
// tree string is in format {"result": [{"printer_type": "1.2.3", "states": [{"printer_state": "OFFLINE", "count": 1}, ...]}, {..}]}
|
||||
|
||||
// tree format:
|
||||
/*
|
||||
[{
|
||||
"printer_uuid": "972d2ce7-0967-4555-bff2-330c7fa0a4e1",
|
||||
"printer_state" : "IDLE"
|
||||
}, {
|
||||
"printer_uuid": "15d160fd-c7e4-4b5a-9748-f0e531c7e0f5",
|
||||
"printer_state" : "OFFLINE"
|
||||
}]
|
||||
*/
|
||||
ConnectPrinterStateMap new_printer_map;
|
||||
|
||||
assert(ptree.front().first == "result");
|
||||
for (const auto& printer_tree : ptree.front().second) {
|
||||
// printer_tree is {"printer_type": "1.2.3", "states": [..]}
|
||||
std::string name;
|
||||
ConnectPrinterState state;
|
||||
|
||||
const auto type_opt = printer_tree.second.get_optional<std::string>("printer_model");
|
||||
if (!type_opt) {
|
||||
for (const auto& printer_tree : ptree) {
|
||||
const auto printer_uuid = printer_tree.second.get_optional<std::string>("printer_uuid");
|
||||
if (!printer_uuid) {
|
||||
continue;
|
||||
}
|
||||
// printer_type is actually printer_name for now
|
||||
name = *type_opt;
|
||||
// printer should not appear twice
|
||||
assert(new_printer_map.find(name) == new_printer_map.end());
|
||||
// prepare all states on 0
|
||||
new_printer_map[name].reserve(static_cast<size_t>(ConnectPrinterState::CONNECT_PRINTER_STATE_COUNT));
|
||||
for (size_t i = 0; i < static_cast<size_t>(ConnectPrinterState::CONNECT_PRINTER_STATE_COUNT); i++) {
|
||||
new_printer_map[name].push_back(0);
|
||||
const auto printer_state = printer_tree.second.get_optional<std::string>("printer_state");
|
||||
if (!printer_state) {
|
||||
continue;
|
||||
}
|
||||
ConnectPrinterState state;
|
||||
if (auto pair = printer_state_table.find(*printer_state); pair != printer_state_table.end()) {
|
||||
state = pair->second;
|
||||
} else {
|
||||
assert(true); // On this assert, printer_state_table needs to be updated with *state_opt and correct ConnectPrinterState
|
||||
continue;
|
||||
}
|
||||
if (m_printer_uuid_map.find(*printer_uuid) == m_printer_uuid_map.end()) {
|
||||
BOOST_LOG_TRIVIAL(error) << "Missing printer model for printer uuid: " << *printer_uuid;
|
||||
continue;
|
||||
}
|
||||
std::pair<std::string, std::string> model_nozzle_pair = m_printer_uuid_map[*printer_uuid];
|
||||
|
||||
for (const auto& section : printer_tree.second) {
|
||||
// section is "printer_type": "1.2.3" OR "states": [..]}
|
||||
if (section.first == "states") {
|
||||
for (const auto& subsection : section.second) {
|
||||
// subsection is {"printer_state": "OFFLINE", "count": 1}
|
||||
const auto state_opt = subsection.second.get_optional<std::string>("printer_state");
|
||||
const auto count_opt = subsection.second.get_optional<int>("count");
|
||||
if (!state_opt || ! count_opt) {
|
||||
continue;
|
||||
}
|
||||
if (auto pair = printer_state_table.find(*state_opt); pair != printer_state_table.end()) {
|
||||
state = pair->second;
|
||||
} else {
|
||||
assert(true); // On this assert, printer_state_table needs to be updated with *state_opt and correct ConnectPrinterState
|
||||
continue;
|
||||
}
|
||||
new_printer_map[name][static_cast<size_t>(state)] = *count_opt;
|
||||
}
|
||||
if (new_printer_map.find(model_nozzle_pair) == new_printer_map.end()) {
|
||||
new_printer_map[model_nozzle_pair].reserve(static_cast<size_t>(ConnectPrinterState::CONNECT_PRINTER_STATE_COUNT));
|
||||
for (size_t i = 0; i < static_cast<size_t>(ConnectPrinterState::CONNECT_PRINTER_STATE_COUNT); i++) {
|
||||
new_printer_map[model_nozzle_pair].push_back(0);
|
||||
}
|
||||
}
|
||||
new_printer_map[model_nozzle_pair][static_cast<size_t>(state)] += 1;
|
||||
}
|
||||
|
||||
// compare new and old printer map and update old map into new
|
||||
@ -264,24 +272,35 @@ bool UserAccount::on_connect_printers_success(const std::string& data, AppConfig
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string UserAccount::get_model_from_json(const std::string& message) const
|
||||
bool UserAccount::on_connect_uiid_map_success(const std::string& data, AppConfig* app_config, bool& out_printers_changed)
|
||||
{
|
||||
std::string out;
|
||||
m_printer_uuid_map.clear();
|
||||
pt::ptree ptree;
|
||||
try {
|
||||
std::stringstream ss(message);
|
||||
pt::ptree ptree;
|
||||
std::stringstream ss(data);
|
||||
pt::read_json(ss, ptree);
|
||||
|
||||
std::string printer_type = parse_tree_for_param(ptree, "printer_type");
|
||||
if (auto pair = printer_type_and_name_table.find(printer_type); pair != printer_type_and_name_table.end()) {
|
||||
out = pair->second;
|
||||
}
|
||||
//assert(!out.empty());
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
BOOST_LOG_TRIVIAL(error) << "Could not parse prusaconnect message. " << e.what();
|
||||
return false;
|
||||
}
|
||||
return out;
|
||||
|
||||
for (const auto& printer_tree : ptree) {
|
||||
const auto printer_uuid = printer_tree.second.get_optional<std::string>("printer_uuid");
|
||||
if (!printer_uuid) {
|
||||
continue;
|
||||
}
|
||||
const auto printer_model = printer_tree.second.get_optional<std::string>("printer_model");
|
||||
if (!printer_model) {
|
||||
continue;
|
||||
}
|
||||
const auto nozzle_diameter_opt = printer_tree.second.get_optional<std::string>("nozzle_diameter");
|
||||
const std::string nozzle_diameter = nozzle_diameter_opt ? *nozzle_diameter_opt : std::string();
|
||||
std::pair<std::string, std::string> model_nozzle_pair = { *printer_model, nozzle_diameter };
|
||||
m_printer_uuid_map[*printer_uuid] = model_nozzle_pair;
|
||||
}
|
||||
m_communication->on_uuid_map_success();
|
||||
return on_connect_printers_success(data, app_config, out_printers_changed);
|
||||
}
|
||||
|
||||
std::string UserAccount::get_nozzle_from_json(const std::string& message) const
|
||||
@ -298,6 +317,15 @@ std::string UserAccount::get_nozzle_from_json(const std::string& message) const
|
||||
catch (const std::exception& e) {
|
||||
BOOST_LOG_TRIVIAL(error) << "Could not parse prusaconnect message. " << e.what();
|
||||
}
|
||||
|
||||
// Get rid of trailing zeros.
|
||||
// This is because somtimes we get "nozzle_diameter":0.40000000000000002
|
||||
// This will return wrong result for f.e. 0.05. But we dont have such profiles right now.
|
||||
if (size_t fist_dot = out.find('.'); fist_dot != std::string::npos) {
|
||||
if (size_t first_zero = out.find('0', fist_dot); first_zero != std::string::npos) {
|
||||
return out.substr(0, first_zero);
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
@ -318,20 +346,27 @@ std::string UserAccount::get_keyword_from_json(const std::string& json, const st
|
||||
return out;
|
||||
}
|
||||
|
||||
void UserAccount::fill_compatible_printers_from_json(const std::string& json, std::vector<std::string>& result) const
|
||||
void UserAccount::fill_supported_printer_models_from_json(const std::string& json, std::vector<std::string>& result) const
|
||||
{
|
||||
try {
|
||||
std::stringstream ss(json);
|
||||
pt::ptree ptree;
|
||||
pt::read_json(ss, ptree);
|
||||
|
||||
pt::ptree out = parse_tree_for_subtree(ptree, "printer_type_compatible");
|
||||
std::string printer_model = parse_tree_for_param(ptree, "printer_model");
|
||||
if (!printer_model.empty()) {
|
||||
result.emplace_back(printer_model);
|
||||
}
|
||||
pt::ptree out = parse_tree_for_subtree(ptree, "supported_printer_models");
|
||||
if (out.empty()) {
|
||||
BOOST_LOG_TRIVIAL(error) << "Failed to find compatible_printer_type in printer detail.";
|
||||
BOOST_LOG_TRIVIAL(error) << "Failed to find supported_printer_models in printer detail.";
|
||||
return;
|
||||
}
|
||||
for (const auto& sub : out) {
|
||||
result.emplace_back(sub.second.data());
|
||||
if (printer_model != sub.second.data()) {
|
||||
result.emplace_back(sub.second.data());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
@ -339,18 +374,78 @@ void UserAccount::fill_compatible_printers_from_json(const std::string& json, st
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
std::string UserAccount::get_printer_type_from_name(const std::string& printer_name) const
|
||||
void UserAccount::fill_material_from_json(const std::string& json, std::vector<std::string>& result) const
|
||||
{
|
||||
|
||||
for (const auto& pair : printer_type_and_name_table) {
|
||||
if (pair.second == printer_name) {
|
||||
return pair.first;
|
||||
|
||||
/* option 1:
|
||||
"slot": {
|
||||
"active": 2,
|
||||
"slots": {
|
||||
"1": {
|
||||
"material": "PLA",
|
||||
"temp": 170,
|
||||
"fan_hotend": 7689,
|
||||
"fan_print": 0
|
||||
},
|
||||
"2": {
|
||||
"material": "PLA",
|
||||
"temp": 225,
|
||||
"fan_hotend": 7798,
|
||||
"fan_print": 6503
|
||||
},
|
||||
"3": {
|
||||
"material": "PLA",
|
||||
"temp": 36,
|
||||
"fan_hotend": 6636,
|
||||
"fan_print": 0
|
||||
},
|
||||
"4": {
|
||||
"material": "PLA",
|
||||
"temp": 35,
|
||||
"fan_hotend": 0,
|
||||
"fan_print": 0
|
||||
},
|
||||
"5": {
|
||||
"material": "PETG",
|
||||
"temp": 136,
|
||||
"fan_hotend": 8132,
|
||||
"fan_print": 0
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
/* option 2
|
||||
"filament": {
|
||||
"material": "PLA",
|
||||
"bed_temperature": 60,
|
||||
"nozzle_temperature": 210
|
||||
}
|
||||
*/
|
||||
// try finding "slot" subtree a use it to
|
||||
// if not found, find "filament" subtree
|
||||
try {
|
||||
std::stringstream ss(json);
|
||||
pt::ptree ptree;
|
||||
pt::read_json(ss, ptree);
|
||||
// find "slot" subtree
|
||||
pt::ptree slot_subtree = parse_tree_for_subtree(ptree, "slot");
|
||||
if (slot_subtree.empty()) {
|
||||
// if not found, find "filament" subtree
|
||||
pt::ptree filament_subtree = parse_tree_for_subtree(ptree, "filament");
|
||||
if (!filament_subtree.empty()) {
|
||||
std::string material = parse_tree_for_param(filament_subtree, "material");
|
||||
if (!material.empty()) {
|
||||
result.emplace_back(std::move(material));
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
// search "slot" subtree for all "material"s
|
||||
parse_tree_for_param_vector(slot_subtree, "material", result);
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
BOOST_LOG_TRIVIAL(error) << "Could not parse prusaconnect message. " << e.what();
|
||||
}
|
||||
assert(true); // This assert means printer_type_and_name_table needs a update
|
||||
return {};
|
||||
}
|
||||
|
||||
|
||||
}} // namespace slic3r::GUI
|
@ -24,8 +24,9 @@ enum class ConnectPrinterState {
|
||||
CONNECT_PRINTER_ERROR,
|
||||
CONNECT_PRINTER_STATE_COUNT
|
||||
};
|
||||
|
||||
typedef std::map<std::string, std::vector<size_t>> ConnectPrinterStateMap;
|
||||
// <std::pair<std::string, std::string> is pair of printer_model and nozzle_diameter. std::vector<size_t> is vector of ConnectPrinterState counters
|
||||
typedef std::map<std::pair<std::string, std::string>, std::vector<size_t>> ConnectPrinterStateMap;
|
||||
typedef std::map< std::string, std::pair<std::string, std::string>> ConnectUUIDToModelNozzleMap;
|
||||
// Class UserAccount should handle every request for entities outside PrusaSlicer like PrusaAuth or PrusaConnect.
|
||||
// Outside communication is implemented in class UserAccountCommunication that runs separate thread. Results come back in events to Plater.
|
||||
// All incoming data shoud be stored in UserAccount.
|
||||
@ -41,7 +42,8 @@ public:
|
||||
void set_remember_session(bool remember);
|
||||
void toggle_remember_session();
|
||||
bool get_remember_session();
|
||||
void enqueue_connect_printers_action();
|
||||
void enqueue_connect_status_action();
|
||||
void enqueue_connect_printer_models_action();
|
||||
void enqueue_avatar_action();
|
||||
|
||||
// Clears all data and connections, called on logout or EVT_UA_RESET
|
||||
@ -54,6 +56,7 @@ public:
|
||||
// Called on EVT_UA_FAIL, triggers test after several calls
|
||||
void on_communication_fail();
|
||||
bool on_connect_printers_success(const std::string& data, AppConfig* app_config, bool& out_printers_changed);
|
||||
bool on_connect_uiid_map_success(const std::string& data, AppConfig* app_config, bool& out_printers_changed);
|
||||
|
||||
std::string get_username() const { return m_username; }
|
||||
std::string get_access_token();
|
||||
@ -62,15 +65,13 @@ public:
|
||||
boost::filesystem::path get_avatar_path(bool logged) const;
|
||||
|
||||
// standalone utility methods
|
||||
std::string get_model_from_json(const std::string& message) const;
|
||||
std::string get_nozzle_from_json(const std::string& message) const;
|
||||
//std::string get_apikey_from_json(const std::string& message) const;
|
||||
std::string get_keyword_from_json(const std::string& json, const std::string& keyword) const;
|
||||
void fill_compatible_printers_from_json(const std::string& json, std::vector<std::string>& result) const;
|
||||
void fill_supported_printer_models_from_json(const std::string& json, std::vector<std::string>& result) const;
|
||||
void fill_material_from_json(const std::string& json, std::vector<std::string>& result) const;
|
||||
|
||||
const std::map<std::string, ConnectPrinterState>& get_printer_state_table() const { return printer_state_table; }
|
||||
|
||||
std::string get_printer_type_from_name(const std::string& printer_name) const;
|
||||
private:
|
||||
void set_username(const std::string& username);
|
||||
|
||||
@ -79,41 +80,11 @@ private:
|
||||
std::unique_ptr<Slic3r::GUI::UserAccountCommunication> m_communication;
|
||||
|
||||
ConnectPrinterStateMap m_printer_map;
|
||||
ConnectUUIDToModelNozzleMap m_printer_uuid_map;
|
||||
std::map<std::string, std::string> m_account_user_data;
|
||||
std::string m_username;
|
||||
size_t m_fail_counter { 0 };
|
||||
std::string m_avatar_extension;
|
||||
|
||||
// first string is "printer_type" code from Connect edpoints
|
||||
const std::map<std::string, std::string> printer_type_and_name_table = {
|
||||
{"1.2.5", "MK2.5" },
|
||||
{"1.2.6", "MK2.5S" },
|
||||
{"1.3.0", "MK3" },
|
||||
{"1.3.1", "MK3S" },
|
||||
{"1.3.5", "MK3.5" },
|
||||
{"1.3.9", "MK3.9" },
|
||||
{"1.4.0", "MK4" },
|
||||
{"2.1.0", "MINI" },
|
||||
{"3.1.0", "XL" },
|
||||
{"5.1.0", "SL1" },
|
||||
// ysFIXME : needs to add Connect ids for next printers
|
||||
/*{"0.0.0", "MK4IS" },
|
||||
{"0.0.0", "MK3SMMU2S" },
|
||||
{"0.0.0", "MK3MMU2" },
|
||||
{"0.0.0", "MK2.5SMMU2S" },
|
||||
{"0.0.0", "MK2.5MMU2" },
|
||||
{"0.0.0", "MK2S" },
|
||||
{"0.0.0", "MK2SMM" },
|
||||
{"0.0.0", "SL1S" },*/
|
||||
};
|
||||
/* TODO:
|
||||
4 1 0 iXL
|
||||
6 2 0 Trilab DeltiQ 2
|
||||
6 2 1 Trilab DelriQ 2 Plus
|
||||
7 1 0 Trilab AzteQ
|
||||
7 2 0 Trilab AzteQ Industrial
|
||||
7 2 1 Trilab AzteQ Industrial Plus
|
||||
*/
|
||||
std::string m_avatar_extension;
|
||||
|
||||
const std::map<std::string, ConnectPrinterState> printer_state_table = {
|
||||
{"OFFLINE" , ConnectPrinterState::CONNECT_PRINTER_OFFLINE},
|
||||
|
@ -214,7 +214,15 @@ void UserAccountCommunication::set_polling_enabled(bool enabled)
|
||||
{
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_session_mutex);
|
||||
return m_session->set_polling_enabled(enabled);
|
||||
return m_session->set_polling_action(enabled ? UserAccountActionID::USER_ACCOUNT_ACTION_CONNECT_PRINTER_MODELS : UserAccountActionID::USER_ACCOUNT_ACTION_DUMMY);
|
||||
}
|
||||
}
|
||||
|
||||
void UserAccountCommunication::on_uuid_map_success()
|
||||
{
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_session_mutex);
|
||||
return m_session->set_polling_action(UserAccountActionID::USER_ACCOUNT_ACTION_CONNECT_STATUS);
|
||||
}
|
||||
}
|
||||
|
||||
@ -228,7 +236,8 @@ void UserAccountCommunication::login_redirect()
|
||||
std::string code_challenge = ccg.generate_chalenge(m_code_verifier);
|
||||
BOOST_LOG_TRIVIAL(info) << "code verifier: " << m_code_verifier;
|
||||
BOOST_LOG_TRIVIAL(info) << "code challenge: " << code_challenge;
|
||||
wxString url = GUI::format_wxstr(L"%1%/o/authorize/?client_id=%2%&response_type=code&code_challenge=%3%&code_challenge_method=S256&scope=basic_info&redirect_uri=%4%", AUTH_HOST, CLIENT_ID, code_challenge, REDIRECT_URI);
|
||||
|
||||
wxString url = GUI::format_wxstr(L"%1%/o/authorize/?client_id=%2%&response_type=code&code_challenge=%3%&code_challenge_method=S256&scope=basic_info&redirect_uri=%4%&choose_account=1", AUTH_HOST, CLIENT_ID, code_challenge, REDIRECT_URI);
|
||||
|
||||
wxQueueEvent(m_evt_handler,new OpenPrusaAuthEvent(GUI::EVT_OPEN_PRUSAAUTH, std::move(url)));
|
||||
}
|
||||
@ -274,14 +283,25 @@ void UserAccountCommunication::on_login_code_recieved(const std::string& url_mes
|
||||
wakeup_session_thread();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void UserAccountCommunication::enqueue_connect_printers_action()
|
||||
void UserAccountCommunication::enqueue_connect_printer_models_action()
|
||||
{
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_session_mutex);
|
||||
if (!m_session->is_initialized()) {
|
||||
BOOST_LOG_TRIVIAL(error) << "Connect Printers endpoint connection failed - Not Logged in.";
|
||||
BOOST_LOG_TRIVIAL(error) << "Connect Printer Models connection failed - Not Logged in.";
|
||||
return;
|
||||
}
|
||||
m_session->enqueue_action(UserAccountActionID::USER_ACCOUNT_ACTION_CONNECT_PRINTER_MODELS, nullptr, nullptr, {});
|
||||
}
|
||||
wakeup_session_thread();
|
||||
}
|
||||
|
||||
void UserAccountCommunication::enqueue_connect_status_action()
|
||||
{
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_session_mutex);
|
||||
if (!m_session->is_initialized()) {
|
||||
BOOST_LOG_TRIVIAL(error) << "Connect Status endpoint connection failed - Not Logged in.";
|
||||
return;
|
||||
}
|
||||
m_session->enqueue_action(UserAccountActionID::USER_ACCOUNT_ACTION_CONNECT_STATUS, nullptr, nullptr, {});
|
||||
@ -296,7 +316,7 @@ void UserAccountCommunication::enqueue_test_connection()
|
||||
BOOST_LOG_TRIVIAL(error) << "Connect Printers endpoint connection failed - Not Logged in.";
|
||||
return;
|
||||
}
|
||||
m_session->enqueue_action(UserAccountActionID::USER_ACCOUNT_ACTION_TEST_CONNECTION, nullptr, nullptr, {});
|
||||
m_session->enqueue_test_with_refresh();
|
||||
}
|
||||
wakeup_session_thread();
|
||||
}
|
||||
|
@ -39,7 +39,8 @@ public:
|
||||
void do_logout();
|
||||
void do_clear();
|
||||
// Trigger function starts various remote operations
|
||||
void enqueue_connect_printers_action();
|
||||
void enqueue_connect_status_action();
|
||||
void enqueue_connect_printer_models_action();
|
||||
void enqueue_avatar_action(const std::string& url);
|
||||
void enqueue_test_connection();
|
||||
|
||||
@ -59,7 +60,8 @@ public:
|
||||
std::string get_shared_session_key();
|
||||
|
||||
void set_polling_enabled(bool enabled);
|
||||
|
||||
// we have map of uuids and printer_models - set polling action to lightweight STATUS action
|
||||
void on_uuid_map_success();
|
||||
private:
|
||||
std::unique_ptr<UserAccountSession> m_session;
|
||||
std::thread m_thread;
|
||||
|
@ -22,7 +22,8 @@ wxDEFINE_EVENT(EVT_OPEN_PRUSAAUTH, OpenPrusaAuthEvent);
|
||||
wxDEFINE_EVENT(EVT_UA_LOGGEDOUT, UserAccountSuccessEvent);
|
||||
wxDEFINE_EVENT(EVT_UA_ID_USER_SUCCESS, UserAccountSuccessEvent);
|
||||
wxDEFINE_EVENT(EVT_UA_SUCCESS, UserAccountSuccessEvent);
|
||||
wxDEFINE_EVENT(EVT_UA_PRUSACONNECT_PRINTERS_SUCCESS, UserAccountSuccessEvent);
|
||||
wxDEFINE_EVENT(EVT_UA_PRUSACONNECT_STATUS_SUCCESS, UserAccountSuccessEvent);
|
||||
wxDEFINE_EVENT(EVT_UA_PRUSACONNECT_PRINTER_MODELS_SUCCESS, UserAccountSuccessEvent);
|
||||
wxDEFINE_EVENT(EVT_UA_AVATAR_SUCCESS, UserAccountSuccessEvent);
|
||||
wxDEFINE_EVENT(EVT_UA_FAIL, UserAccountFailEvent);
|
||||
wxDEFINE_EVENT(EVT_UA_RESET, UserAccountFailEvent);
|
||||
@ -74,11 +75,7 @@ void UserAccountSession::process_action_queue()
|
||||
return;
|
||||
if (m_priority_action_queue.empty() && m_action_queue.empty()) {
|
||||
// update printers periodically
|
||||
if (m_polling_enabled) {
|
||||
enqueue_action(UserAccountActionID::USER_ACCOUNT_ACTION_CONNECT_STATUS, nullptr, nullptr, {});
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
enqueue_action(m_polling_action, nullptr, nullptr, {});
|
||||
}
|
||||
// priority queue works even when tokens are empty or broken
|
||||
while (!m_priority_action_queue.empty()) {
|
||||
|
@ -20,7 +20,8 @@ wxDECLARE_EVENT(EVT_OPEN_PRUSAAUTH, OpenPrusaAuthEvent);
|
||||
wxDECLARE_EVENT(EVT_UA_LOGGEDOUT, UserAccountSuccessEvent);
|
||||
wxDECLARE_EVENT(EVT_UA_ID_USER_SUCCESS, UserAccountSuccessEvent);
|
||||
wxDECLARE_EVENT(EVT_UA_SUCCESS, UserAccountSuccessEvent);
|
||||
wxDECLARE_EVENT(EVT_UA_PRUSACONNECT_PRINTERS_SUCCESS, UserAccountSuccessEvent);
|
||||
wxDECLARE_EVENT(EVT_UA_PRUSACONNECT_STATUS_SUCCESS, UserAccountSuccessEvent);
|
||||
wxDECLARE_EVENT(EVT_UA_PRUSACONNECT_PRINTER_MODELS_SUCCESS, UserAccountSuccessEvent);
|
||||
wxDECLARE_EVENT(EVT_UA_AVATAR_SUCCESS, UserAccountSuccessEvent);
|
||||
wxDECLARE_EVENT(EVT_UA_FAIL, UserAccountFailEvent); // Soft fail - clears only after some number of fails
|
||||
wxDECLARE_EVENT(EVT_UA_RESET, UserAccountFailEvent); // Hard fail - clears all
|
||||
@ -37,7 +38,8 @@ enum class UserAccountActionID {
|
||||
USER_ACCOUNT_ACTION_USER_ID,
|
||||
USER_ACCOUNT_ACTION_TEST_ACCESS_TOKEN,
|
||||
USER_ACCOUNT_ACTION_TEST_CONNECTION,
|
||||
USER_ACCOUNT_ACTION_CONNECT_STATUS, // status of all printers
|
||||
USER_ACCOUNT_ACTION_CONNECT_STATUS, // status of all printers by UUID
|
||||
USER_ACCOUNT_ACTION_CONNECT_PRINTER_MODELS, // status of all printers by UUID with printer_model. Should be called once to save printer models.
|
||||
USER_ACCOUNT_ACTION_AVATAR,
|
||||
};
|
||||
class UserAction
|
||||
@ -99,7 +101,7 @@ public:
|
||||
, m_access_token(access_token)
|
||||
, m_refresh_token(refresh_token)
|
||||
, m_shared_session_key(shared_session_key)
|
||||
, m_polling_enabled(polling_enabled)
|
||||
, m_polling_action(polling_enabled ? UserAccountActionID::USER_ACCOUNT_ACTION_CONNECT_PRINTER_MODELS : UserAccountActionID::USER_ACCOUNT_ACTION_DUMMY)
|
||||
|
||||
{
|
||||
|
||||
@ -110,7 +112,8 @@ public:
|
||||
m_actions[UserAccountActionID::USER_ACCOUNT_ACTION_USER_ID] = std::make_unique<UserActionGetWithEvent>("USER_ID", "https://account.prusa3d.com/api/v1/me/", EVT_UA_ID_USER_SUCCESS, EVT_UA_RESET);
|
||||
m_actions[UserAccountActionID::USER_ACCOUNT_ACTION_TEST_ACCESS_TOKEN] = std::make_unique<UserActionGetWithEvent>("TEST_ACCESS_TOKEN", "https://account.prusa3d.com/api/v1/me/", EVT_UA_ID_USER_SUCCESS, EVT_UA_FAIL);
|
||||
m_actions[UserAccountActionID::USER_ACCOUNT_ACTION_TEST_CONNECTION] = std::make_unique<UserActionGetWithEvent>("TEST_CONNECTION", "https://account.prusa3d.com/api/v1/me/", wxEVT_NULL, EVT_UA_RESET);
|
||||
m_actions[UserAccountActionID::USER_ACCOUNT_ACTION_CONNECT_STATUS] = std::make_unique<UserActionGetWithEvent>("CONNECT_STATUS", "https://connect.prusa3d.com/slicer/status", EVT_UA_PRUSACONNECT_PRINTERS_SUCCESS, EVT_UA_FAIL);
|
||||
m_actions[UserAccountActionID::USER_ACCOUNT_ACTION_CONNECT_STATUS] = std::make_unique<UserActionGetWithEvent>("CONNECT_STATUS", "https://connect.prusa3d.com/slicer/status", EVT_UA_PRUSACONNECT_STATUS_SUCCESS, EVT_UA_FAIL);
|
||||
m_actions[UserAccountActionID::USER_ACCOUNT_ACTION_CONNECT_PRINTER_MODELS] = std::make_unique<UserActionGetWithEvent>("CONNECT_PRINTER_MODELS", "https://connect.prusa3d.com/slicer/printer_list", EVT_UA_PRUSACONNECT_PRINTER_MODELS_SUCCESS, EVT_UA_FAIL);
|
||||
m_actions[UserAccountActionID::USER_ACCOUNT_ACTION_AVATAR] = std::make_unique<UserActionGetWithEvent>("AVATAR", "https://media.printables.com/media/", EVT_UA_AVATAR_SUCCESS, EVT_UA_FAIL);
|
||||
}
|
||||
~UserAccountSession()
|
||||
@ -143,7 +146,8 @@ public:
|
||||
std::string get_refresh_token() const { return m_refresh_token; }
|
||||
std::string get_shared_session_key() const { return m_shared_session_key; }
|
||||
|
||||
void set_polling_enabled(bool enabled) {m_polling_enabled = enabled; }
|
||||
//void set_polling_enabled(bool enabled) {m_polling_action = enabled ? UserAccountActionID::USER_ACCOUNT_ACTION_CONNECT_PRINTER_MODELS : UserAccountActionID::USER_ACCOUNT_ACTION_DUMMY; }
|
||||
void set_polling_action(UserAccountActionID action) { m_polling_action = action; }
|
||||
private:
|
||||
|
||||
void enqueue_refresh(const std::string& body);
|
||||
@ -156,8 +160,9 @@ private:
|
||||
// false prevents action queu to be processed - no communication is done
|
||||
// sets to true by init_with_code or enqueue_action call
|
||||
bool m_proccessing_enabled {false};
|
||||
// triggers CONNECT_PRINTERS action when woken up on idle
|
||||
bool m_polling_enabled;
|
||||
// action when woken up on idle - switches between USER_ACCOUNT_ACTION_CONNECT_PRINTER_MODELS and USER_ACCOUNT_ACTION_CONNECT_STATUS
|
||||
// set to USER_ACCOUNT_ACTION_DUMMY to switch off polling
|
||||
UserAccountActionID m_polling_action;
|
||||
|
||||
std::string m_access_token;
|
||||
std::string m_refresh_token;
|
||||
|
@ -6,43 +6,6 @@
|
||||
|
||||
#include <boost/log/trivial.hpp>
|
||||
|
||||
|
||||
class FakeWebView : public wxWebView
|
||||
{
|
||||
virtual bool Create(wxWindow* parent, wxWindowID id, const wxString& url, const wxPoint& pos, const wxSize& size, long style, const wxString& name) override { return false; }
|
||||
virtual wxString GetCurrentTitle() const override { return wxString(); }
|
||||
virtual wxString GetCurrentURL() const override { return wxString(); }
|
||||
virtual bool IsBusy() const override { return false; }
|
||||
virtual bool IsEditable() const override { return false; }
|
||||
virtual void LoadURL(const wxString& url) override { }
|
||||
virtual void Print() override { }
|
||||
virtual void RegisterHandler(wxSharedPtr<wxWebViewHandler> handler) override { }
|
||||
virtual void Reload(wxWebViewReloadFlags flags = wxWEBVIEW_RELOAD_DEFAULT) override { }
|
||||
virtual bool RunScript(const wxString& javascript, wxString* output = NULL) const override { return false; }
|
||||
virtual void SetEditable(bool enable = true) override { }
|
||||
virtual void Stop() override { }
|
||||
virtual bool CanGoBack() const override { return false; }
|
||||
virtual bool CanGoForward() const override { return false; }
|
||||
virtual void GoBack() override { }
|
||||
virtual void GoForward() override { }
|
||||
virtual void ClearHistory() override { }
|
||||
virtual void EnableHistory(bool enable = true) override { }
|
||||
virtual wxVector<wxSharedPtr<wxWebViewHistoryItem>> GetBackwardHistory() override { return {}; }
|
||||
virtual wxVector<wxSharedPtr<wxWebViewHistoryItem>> GetForwardHistory() override { return {}; }
|
||||
virtual void LoadHistoryItem(wxSharedPtr<wxWebViewHistoryItem> item) override { }
|
||||
virtual bool CanSetZoomType(wxWebViewZoomType type) const override { return false; }
|
||||
virtual float GetZoomFactor() const override { return 0.0f; }
|
||||
virtual wxWebViewZoomType GetZoomType() const override { return wxWebViewZoomType(); }
|
||||
virtual void SetZoomFactor(float zoom) override { }
|
||||
virtual void SetZoomType(wxWebViewZoomType zoomType) override { }
|
||||
virtual bool CanUndo() const override { return false; }
|
||||
virtual bool CanRedo() const override { return false; }
|
||||
virtual void Undo() override { }
|
||||
virtual void Redo() override { }
|
||||
virtual void* GetNativeBackend() const override { return nullptr; }
|
||||
virtual void DoSetPage(const wxString& html, const wxString& baseUrl) override { }
|
||||
};
|
||||
|
||||
wxWebView* WebView::CreateWebView(wxWindow * parent, const wxString& url)
|
||||
{
|
||||
#if wxUSE_WEBVIEW_EDGE
|
||||
@ -87,16 +50,9 @@ wxWebView* WebView::CreateWebView(wxWindow * parent, const wxString& url)
|
||||
webView->EnableContextMenu(false);
|
||||
} else {
|
||||
// TODO: dialog to user !!!
|
||||
BOOST_LOG_TRIVIAL(error) << "Failed to create wxWebView object. Using Dummy object instead. Webview won't be working.";
|
||||
webView = new FakeWebView;
|
||||
BOOST_LOG_TRIVIAL(error) << "Failed to create wxWebView object.";
|
||||
}
|
||||
return webView;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool WebView::run_script(wxWebView *webView, wxString const &javascript)
|
||||
{
|
||||
webView->RunScriptAsync(javascript);
|
||||
return true;
|
||||
}
|
||||
|
@ -8,7 +8,6 @@ class wxString;
|
||||
namespace WebView
|
||||
{
|
||||
wxWebView *CreateWebView(wxWindow *parent, const wxString& url);
|
||||
bool run_script(wxWebView * webView, const wxString& msg);
|
||||
};
|
||||
|
||||
#endif // !slic3r_GUI_WebView_hpp_
|
||||
|
@ -22,9 +22,10 @@ namespace Slic3r {
|
||||
namespace GUI {
|
||||
|
||||
|
||||
WebViewPanel::WebViewPanel(wxWindow *parent, const wxString& default_url)
|
||||
WebViewPanel::WebViewPanel(wxWindow *parent, const wxString& default_url, const std::string& loading_html/* = "loading"*/)
|
||||
: wxPanel(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize)
|
||||
, m_default_url (default_url)
|
||||
, m_loading_html(loading_html)
|
||||
{
|
||||
wxBoxSizer* topsizer = new wxBoxSizer(wxVERTICAL);
|
||||
#ifdef DEBUG_URL_PANEL
|
||||
@ -66,17 +67,16 @@ WebViewPanel::WebViewPanel(wxWindow *parent, const wxString& default_url)
|
||||
topsizer->Add(m_info, wxSizerFlags().Expand());
|
||||
#endif
|
||||
|
||||
// Create the webview
|
||||
m_browser = WebView::CreateWebView(this, /*m_default_url*/ GUI::format_wxstr("file://%1%/web/connection_failed.html", boost::filesystem::path(resources_dir()).generic_string()));
|
||||
if (m_browser == nullptr) {
|
||||
wxLogError("Could not init m_browser");
|
||||
return;
|
||||
}
|
||||
|
||||
SetSizer(topsizer);
|
||||
|
||||
// Create the webview
|
||||
m_browser = WebView::CreateWebView(this, /*m_default_url*/ GUI::format_wxstr("file://%1%/web/%2%.html", boost::filesystem::path(resources_dir()).generic_string(), m_loading_html));
|
||||
if (!m_browser) {
|
||||
wxStaticText* text = new wxStaticText(this, wxID_ANY, _L("Failed to load a web browser."));
|
||||
topsizer->Add(text, 0, wxALIGN_LEFT | wxBOTTOM, 10);
|
||||
return;
|
||||
}
|
||||
topsizer->Add(m_browser, wxSizerFlags().Expand().Proportion(1));
|
||||
|
||||
#ifdef DEBUG_URL_PANEL
|
||||
// Create the Tools menu
|
||||
m_tools_menu = new wxMenu();
|
||||
@ -98,7 +98,6 @@ WebViewPanel::WebViewPanel(wxWindow *parent, const wxString& default_url)
|
||||
//Zoom
|
||||
m_zoomFactor = 100;
|
||||
|
||||
|
||||
Bind(wxEVT_SHOW, &WebViewPanel::on_show, this);
|
||||
|
||||
// Connect the webview events
|
||||
@ -127,7 +126,6 @@ WebViewPanel::WebViewPanel(wxWindow *parent, const wxString& default_url)
|
||||
Bind(wxEVT_IDLE, &WebViewPanel::on_idle, this);
|
||||
Bind(wxEVT_CLOSE_WINDOW, &WebViewPanel::on_close, this);
|
||||
|
||||
m_LoginUpdateTimer = nullptr;
|
||||
}
|
||||
|
||||
WebViewPanel::~WebViewPanel()
|
||||
@ -135,18 +133,15 @@ WebViewPanel::~WebViewPanel()
|
||||
SetEvtHandlerEnabled(false);
|
||||
#ifdef DEBUG_URL_PANEL
|
||||
delete m_tools_menu;
|
||||
|
||||
if (m_LoginUpdateTimer != nullptr) {
|
||||
m_LoginUpdateTimer->Stop();
|
||||
delete m_LoginUpdateTimer;
|
||||
m_LoginUpdateTimer = NULL;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void WebViewPanel::load_url(const wxString& url)
|
||||
{
|
||||
if (!m_browser)
|
||||
return;
|
||||
|
||||
this->Show();
|
||||
this->Raise();
|
||||
#ifdef DEBUG_URL_PANEL
|
||||
@ -164,26 +159,36 @@ void WebViewPanel::load_default_url_delayed()
|
||||
|
||||
void WebViewPanel::load_error_page()
|
||||
{
|
||||
load_url(GUI::format_wxstr("file://%1%/web/connection_failed.html", boost::filesystem::path(resources_dir()).generic_string()));
|
||||
if (!m_browser)
|
||||
return;
|
||||
|
||||
m_browser->Stop();
|
||||
m_load_error_page = true;
|
||||
}
|
||||
|
||||
void WebViewPanel::on_show(wxShowEvent& evt)
|
||||
{
|
||||
if (evt.IsShown() && m_load_default_url)
|
||||
{
|
||||
m_shown = evt.IsShown();
|
||||
if (evt.IsShown() && m_load_default_url) {
|
||||
m_load_default_url = false;
|
||||
load_url(m_default_url);
|
||||
}
|
||||
// TODO: add check that any url was loaded
|
||||
}
|
||||
|
||||
void WebViewPanel::on_idle(wxIdleEvent& WXUNUSED(evt))
|
||||
{
|
||||
if (m_browser->IsBusy())
|
||||
if (!m_browser)
|
||||
return;
|
||||
if (m_browser->IsBusy()) {
|
||||
wxSetCursor(wxCURSOR_ARROWWAIT);
|
||||
else
|
||||
} else {
|
||||
wxSetCursor(wxNullCursor);
|
||||
|
||||
if (m_shown && m_load_error_page) {
|
||||
m_load_error_page = false;
|
||||
load_url(GUI::format_wxstr("file://%1%/web/connection_failed.html", boost::filesystem::path(resources_dir()).generic_string()));
|
||||
}
|
||||
}
|
||||
#ifdef DEBUG_URL_PANEL
|
||||
m_button_stop->Enable(m_browser->IsBusy());
|
||||
#endif
|
||||
@ -194,6 +199,8 @@ void WebViewPanel::on_idle(wxIdleEvent& WXUNUSED(evt))
|
||||
*/
|
||||
void WebViewPanel::on_url(wxCommandEvent& WXUNUSED(evt))
|
||||
{
|
||||
if (!m_browser)
|
||||
return;
|
||||
#ifdef DEBUG_URL_PANEL
|
||||
m_browser->LoadURL(m_url->GetValue());
|
||||
m_browser->SetFocus();
|
||||
@ -205,6 +212,8 @@ void WebViewPanel::on_url(wxCommandEvent& WXUNUSED(evt))
|
||||
*/
|
||||
void WebViewPanel::on_back_button(wxCommandEvent& WXUNUSED(evt))
|
||||
{
|
||||
if (!m_browser)
|
||||
return;
|
||||
m_browser->GoBack();
|
||||
}
|
||||
|
||||
@ -213,6 +222,8 @@ void WebViewPanel::on_back_button(wxCommandEvent& WXUNUSED(evt))
|
||||
*/
|
||||
void WebViewPanel::on_forward_button(wxCommandEvent& WXUNUSED(evt))
|
||||
{
|
||||
if (!m_browser)
|
||||
return;
|
||||
m_browser->GoForward();
|
||||
}
|
||||
|
||||
@ -221,6 +232,8 @@ void WebViewPanel::on_forward_button(wxCommandEvent& WXUNUSED(evt))
|
||||
*/
|
||||
void WebViewPanel::on_stop_button(wxCommandEvent& WXUNUSED(evt))
|
||||
{
|
||||
if (!m_browser)
|
||||
return;
|
||||
m_browser->Stop();
|
||||
}
|
||||
|
||||
@ -229,28 +242,28 @@ void WebViewPanel::on_stop_button(wxCommandEvent& WXUNUSED(evt))
|
||||
*/
|
||||
void WebViewPanel::on_reload_button(wxCommandEvent& WXUNUSED(evt))
|
||||
{
|
||||
if (!m_browser)
|
||||
return;
|
||||
m_browser->Reload();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void WebViewPanel::on_close(wxCloseEvent& evt)
|
||||
{
|
||||
this->Hide();
|
||||
}
|
||||
|
||||
|
||||
void WebViewPanel::on_script_message(wxWebViewEvent& evt)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Invoked when user selects the "View Source" menu item
|
||||
*/
|
||||
void WebViewPanel::on_view_source_request(wxCommandEvent& WXUNUSED(evt))
|
||||
{
|
||||
if (!m_browser)
|
||||
return;
|
||||
|
||||
SourceViewDialog dlg(this, m_browser->GetPageSource());
|
||||
dlg.ShowModal();
|
||||
}
|
||||
@ -260,6 +273,9 @@ void WebViewPanel::on_view_source_request(wxCommandEvent& WXUNUSED(evt))
|
||||
*/
|
||||
void WebViewPanel::on_view_text_request(wxCommandEvent& WXUNUSED(evt))
|
||||
{
|
||||
if (!m_browser)
|
||||
return;
|
||||
|
||||
wxDialog textViewDialog(this, wxID_ANY, "Page Text",
|
||||
wxDefaultPosition, wxSize(700, 500),
|
||||
wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER);
|
||||
@ -281,6 +297,9 @@ void WebViewPanel::on_view_text_request(wxCommandEvent& WXUNUSED(evt))
|
||||
*/
|
||||
void WebViewPanel::on_tools_clicked(wxCommandEvent& WXUNUSED(evt))
|
||||
{
|
||||
if (!m_browser)
|
||||
return;
|
||||
|
||||
#ifdef DEBUG_URL_PANEL
|
||||
m_context_menu->Check(m_browser->IsContextMenuEnabled());
|
||||
m_dev_tools->Check(m_browser->IsAccessToDevToolsEnabled());
|
||||
@ -292,14 +311,13 @@ void WebViewPanel::on_tools_clicked(wxCommandEvent& WXUNUSED(evt))
|
||||
|
||||
void WebViewPanel::run_script(const wxString& javascript)
|
||||
{
|
||||
if (!m_browser || !m_shown)
|
||||
return;
|
||||
// Remember the script we run in any case, so the next time the user opens
|
||||
// the "Run Script" dialog box, it is shown there for convenient updating.
|
||||
m_javascript = javascript;
|
||||
|
||||
if (!m_browser) return;
|
||||
|
||||
bool res = WebView::run_script(m_browser, javascript);
|
||||
BOOST_LOG_TRIVIAL(debug) << "RunScript " << javascript << " " << res;
|
||||
BOOST_LOG_TRIVIAL(debug) << "RunScript " << javascript;
|
||||
m_browser->RunScriptAsync(javascript);
|
||||
}
|
||||
|
||||
|
||||
@ -339,6 +357,9 @@ void WebViewPanel::on_add_user_script(wxCommandEvent& WXUNUSED(evt))
|
||||
|
||||
void WebViewPanel::on_set_custom_user_agent(wxCommandEvent& WXUNUSED(evt))
|
||||
{
|
||||
if (!m_browser)
|
||||
return;
|
||||
|
||||
wxString customUserAgent = "Mozilla/5.0 (iPhone; CPU iPhone OS 13_1_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.1 Mobile/15E148 Safari/604.1";
|
||||
wxTextEntryDialog dialog
|
||||
(
|
||||
@ -357,25 +378,40 @@ void WebViewPanel::on_set_custom_user_agent(wxCommandEvent& WXUNUSED(evt))
|
||||
|
||||
void WebViewPanel::on_clear_selection(wxCommandEvent& WXUNUSED(evt))
|
||||
{
|
||||
if (!m_browser)
|
||||
return;
|
||||
|
||||
m_browser->ClearSelection();
|
||||
}
|
||||
|
||||
void WebViewPanel::on_delete_selection(wxCommandEvent& WXUNUSED(evt))
|
||||
{
|
||||
if (!m_browser)
|
||||
return;
|
||||
|
||||
m_browser->DeleteSelection();
|
||||
}
|
||||
|
||||
void WebViewPanel::on_select_all(wxCommandEvent& WXUNUSED(evt))
|
||||
{
|
||||
if (!m_browser)
|
||||
return;
|
||||
|
||||
m_browser->SelectAll();
|
||||
}
|
||||
|
||||
void WebViewPanel::On_enable_context_menu(wxCommandEvent& evt)
|
||||
{
|
||||
if (!m_browser)
|
||||
return;
|
||||
|
||||
m_browser->EnableContextMenu(evt.IsChecked());
|
||||
}
|
||||
void WebViewPanel::On_enable_dev_tools(wxCommandEvent& evt)
|
||||
{
|
||||
if (!m_browser)
|
||||
return;
|
||||
|
||||
m_browser->EnableAccessToDevTools(evt.IsChecked());
|
||||
}
|
||||
|
||||
@ -446,12 +482,12 @@ ConnectRequestHandler::~ConnectRequestHandler()
|
||||
void ConnectRequestHandler::handle_message(const std::string& message)
|
||||
{
|
||||
// read msg and choose action
|
||||
/*
|
||||
v0:
|
||||
{"type":"request","detail":{"action":"requestAccessToken"}}
|
||||
v1:
|
||||
{"action":"REQUEST_ACCESS_TOKEN"}
|
||||
*/
|
||||
/*
|
||||
v0:
|
||||
{"type":"request","detail":{"action":"requestAccessToken"}}
|
||||
v1:
|
||||
{"action":"REQUEST_ACCESS_TOKEN"}
|
||||
*/
|
||||
std::string action_string;
|
||||
m_message_data = message;
|
||||
try {
|
||||
@ -503,7 +539,8 @@ void ConnectRequestHandler::on_request_config()
|
||||
const std::string token = wxGetApp().plater()->get_user_account()->get_access_token();
|
||||
//const std::string sesh = wxGetApp().plater()->get_user_account()->get_shared_session_key();
|
||||
const std::string dark_mode = wxGetApp().dark_mode() ? "DARK" : "LIGHT";
|
||||
const wxString language = GUI::wxGetApp().current_language_code();
|
||||
wxString language = GUI::wxGetApp().current_language_code();
|
||||
language = language.SubString(0, 1);
|
||||
const std::string init_options = GUI::format("{\"accessToken\": \"%1%\" , \"clientVersion\": \"%2%\", \"colorMode\": \"%3%\", \"language\": \"%4%\"}", token, SLIC3R_VERSION, dark_mode, language);
|
||||
wxString script = GUI::format_wxstr("window._prusaConnect_v1.init(%1%)", init_options);
|
||||
run_script_bridge(script);
|
||||
@ -511,13 +548,13 @@ void ConnectRequestHandler::on_request_config()
|
||||
}
|
||||
|
||||
ConnectWebViewPanel::ConnectWebViewPanel(wxWindow* parent)
|
||||
: WebViewPanel(parent, L"https://connect.prusa3d.com/connect-slicer-app/")
|
||||
: WebViewPanel(parent, L"https://connect.prusa3d.com/connect-slicer-app/", "connect_loading")
|
||||
{
|
||||
}
|
||||
|
||||
void ConnectWebViewPanel::on_script_message(wxWebViewEvent& evt)
|
||||
{
|
||||
BOOST_LOG_TRIVIAL(error) << "recieved message from PrusaConnect FE: " << evt.GetString();
|
||||
BOOST_LOG_TRIVIAL(debug) << "recieved message from PrusaConnect FE: " << evt.GetString();
|
||||
handle_message(into_u8(evt.GetString()));
|
||||
}
|
||||
|
||||
@ -542,6 +579,9 @@ void ConnectWebViewPanel::on_request_update_selected_printer_action()
|
||||
PrinterWebViewPanel::PrinterWebViewPanel(wxWindow* parent, const wxString& default_url)
|
||||
: WebViewPanel(parent, default_url)
|
||||
{
|
||||
if (!m_browser)
|
||||
return;
|
||||
|
||||
m_browser->Bind(wxEVT_WEBVIEW_LOADED, &PrinterWebViewPanel::on_loaded, this);
|
||||
}
|
||||
|
||||
@ -558,7 +598,7 @@ void PrinterWebViewPanel::on_loaded(wxWebViewEvent& evt)
|
||||
|
||||
void PrinterWebViewPanel::send_api_key()
|
||||
{
|
||||
if (m_api_key_sent)
|
||||
if (!m_browser || m_api_key_sent)
|
||||
return;
|
||||
m_api_key_sent = true;
|
||||
wxString key = from_u8(m_api_key);
|
||||
@ -583,7 +623,7 @@ void PrinterWebViewPanel::send_api_key()
|
||||
|
||||
void PrinterWebViewPanel::send_credentials()
|
||||
{
|
||||
if (m_api_key_sent)
|
||||
if (!m_browser || m_api_key_sent)
|
||||
return;
|
||||
m_api_key_sent = true;
|
||||
wxString usr = from_u8(m_usr);
|
||||
@ -610,24 +650,28 @@ void PrinterWebViewPanel::sys_color_changed()
|
||||
{
|
||||
}
|
||||
|
||||
WebViewDialog::WebViewDialog(wxWindow* parent, const wxString& url, const wxString& dialog_name, const wxSize& size)
|
||||
WebViewDialog::WebViewDialog(wxWindow* parent, const wxString& url, const wxString& dialog_name, const wxSize& size, const std::string& loading_html/* = "loading"*/)
|
||||
: wxDialog(parent, wxID_ANY, dialog_name, wxDefaultPosition, size, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER)
|
||||
, m_loading_html(loading_html)
|
||||
{
|
||||
wxBoxSizer* topsizer = new wxBoxSizer(wxVERTICAL);
|
||||
topsizer->SetMinSize(size);
|
||||
SetSizerAndFit(topsizer);
|
||||
|
||||
// Create the webview
|
||||
m_browser = WebView::CreateWebView(this, url);
|
||||
if (m_browser == nullptr) {
|
||||
wxLogError("Could not init m_browser");
|
||||
m_browser = WebView::CreateWebView(this, GUI::format_wxstr("file://%1%/web/%2%.html", boost::filesystem::path(resources_dir()).generic_string(), m_loading_html));
|
||||
if (!m_browser) {
|
||||
wxStaticText* text = new wxStaticText(this, wxID_ANY, _L("Failed to load a web browser."));
|
||||
topsizer->Add(text, 0, wxALIGN_LEFT | wxBOTTOM, 10);
|
||||
return;
|
||||
}
|
||||
|
||||
SetSizer(topsizer);
|
||||
|
||||
topsizer->Add(m_browser, wxSizerFlags().Expand().Proportion(1));
|
||||
|
||||
Bind(wxEVT_SHOW, &WebViewDialog::on_show, this);
|
||||
Bind(wxEVT_WEBVIEW_SCRIPT_MESSAGE_RECEIVED, &WebViewDialog::on_script_message, this, m_browser->GetId());
|
||||
|
||||
m_browser->LoadURL(url);
|
||||
}
|
||||
WebViewDialog::~WebViewDialog()
|
||||
{
|
||||
@ -637,12 +681,15 @@ void WebViewDialog::run_script(const wxString& javascript)
|
||||
{
|
||||
if (!m_browser)
|
||||
return;
|
||||
// dk_FIXME: Is it ok to discard the return value?
|
||||
/*bool res = */ WebView::run_script(m_browser, javascript);
|
||||
m_browser->RunScriptAsync(javascript);
|
||||
}
|
||||
|
||||
PrinterPickWebViewDialog::PrinterPickWebViewDialog(wxWindow* parent, std::string& ret_val)
|
||||
: WebViewDialog(parent, L"https://connect.prusa3d.com/connect-slicer-app/printer-list", _L("Choose a printer"), wxSize(std::max(parent->GetClientSize().x / 2, 100 * wxGetApp().em_unit()), std::max(parent->GetClientSize().y / 2, 50 * wxGetApp().em_unit())))
|
||||
: WebViewDialog(parent
|
||||
, L"https://connect.prusa3d.com/connect-slicer-app/printer-list"
|
||||
, _L("Choose a printer")
|
||||
, wxSize(std::max(parent->GetClientSize().x / 2, 100 * wxGetApp().em_unit()), std::max(parent->GetClientSize().y / 2, 50 * wxGetApp().em_unit()))
|
||||
, "connect_loading")
|
||||
, m_ret_val(ret_val)
|
||||
{
|
||||
Centre();
|
||||
@ -670,6 +717,16 @@ void PrinterPickWebViewDialog::on_request_update_selected_printer_action()
|
||||
}
|
||||
|
||||
void PrinterPickWebViewDialog::request_compatible_printers()
|
||||
{
|
||||
|
||||
if (Preset::printer_technology(wxGetApp().preset_bundle->printers.get_selected_preset().config) == ptFFF) {
|
||||
request_compatible_printers_FFF();
|
||||
} else {
|
||||
request_compatible_printers_SLA();
|
||||
}
|
||||
}
|
||||
|
||||
void PrinterPickWebViewDialog::request_compatible_printers_FFF()
|
||||
{
|
||||
//PrinterParams: {
|
||||
//material: Material;
|
||||
@ -678,19 +735,37 @@ void PrinterPickWebViewDialog::request_compatible_printers()
|
||||
//}
|
||||
const Preset& selected_printer = wxGetApp().preset_bundle->printers.get_selected_preset();
|
||||
const Preset& selected_filament = wxGetApp().preset_bundle->filaments.get_selected_preset();
|
||||
const std::string nozzle_diameter_serialized = dynamic_cast<const ConfigOptionFloats*>(selected_printer.config.option("nozzle_diameter"))->serialize();
|
||||
std::string nozzle_diameter_serialized = dynamic_cast<const ConfigOptionFloats*>(selected_printer.config.option("nozzle_diameter"))->serialize();
|
||||
// Sending only first nozzle diamenter for now.
|
||||
if (size_t comma = nozzle_diameter_serialized.find(','); comma != std::string::npos)
|
||||
nozzle_diameter_serialized = nozzle_diameter_serialized.substr(0, comma);
|
||||
// Sending only first filament type for now. This should change to array of values
|
||||
const std::string filament_type_serialized = selected_filament.config.option("filament_type")->serialize();
|
||||
const std::string printer_model_serialized = selected_printer.config.option("printer_model")->serialize();
|
||||
const std::string printer_type = wxGetApp().plater()->get_user_account()->get_printer_type_from_name(printer_model_serialized);
|
||||
|
||||
|
||||
// assert(!filament_type_serialized.empty() && !nozzle_diameter_serialized.empty() && !printer_type.empty());
|
||||
const std::string request = GUI::format(
|
||||
"{"
|
||||
"\"printerModel\": \"%3%\", "
|
||||
"\"nozzleDiameter\": %2%, "
|
||||
"\"material\": \"%1%\" "
|
||||
"}", filament_type_serialized, nozzle_diameter_serialized, printer_model_serialized);
|
||||
|
||||
wxString script = GUI::format_wxstr("window._prusaConnect_v1.requestCompatiblePrinter(%1%)", request);
|
||||
run_script(script);
|
||||
}
|
||||
void PrinterPickWebViewDialog::request_compatible_printers_SLA()
|
||||
{
|
||||
const Preset& selected_printer = wxGetApp().preset_bundle->printers.get_selected_preset();
|
||||
const std::string printer_model_serialized = selected_printer.config.option("printer_model")->serialize();
|
||||
const Preset& selected_material = wxGetApp().preset_bundle->sla_materials.get_selected_preset();
|
||||
const std::string material_type_serialized = selected_material.config.option("material_type")->serialize();
|
||||
const std::string request = GUI::format(
|
||||
"{"
|
||||
"\"material\": \"%1%\", "
|
||||
"\"nozzleDiameter\": %2%, "
|
||||
"\"printerType\": \"%3%\" "
|
||||
"}", filament_type_serialized, nozzle_diameter_serialized, printer_type);
|
||||
|
||||
"\"printerModel\": \"%2%\" "
|
||||
"}", material_type_serialized, printer_model_serialized);
|
||||
|
||||
wxString script = GUI::format_wxstr("window._prusaConnect_v1.requestCompatiblePrinter(%1%)", request);
|
||||
run_script(script);
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ namespace GUI {
|
||||
class WebViewPanel : public wxPanel
|
||||
{
|
||||
public:
|
||||
WebViewPanel(wxWindow *parent, const wxString& default_url);
|
||||
WebViewPanel(wxWindow *parent, const wxString& default_url, const std::string& loading_html = "loading");
|
||||
virtual ~WebViewPanel();
|
||||
|
||||
void load_url(const wxString& url);
|
||||
@ -49,8 +49,6 @@ public:
|
||||
void On_enable_dev_tools(wxCommandEvent& evt);
|
||||
void on_close(wxCloseEvent& evt);
|
||||
|
||||
wxTimer * m_LoginUpdateTimer{nullptr};
|
||||
|
||||
wxString get_default_url() const { return m_default_url; }
|
||||
void set_default_url(const wxString& url) { m_default_url = url; }
|
||||
|
||||
@ -85,8 +83,12 @@ protected:
|
||||
wxString m_response_js;
|
||||
wxString m_default_url;
|
||||
|
||||
std::string m_loading_html;
|
||||
//DECLARE_EVENT_TABLE()
|
||||
};
|
||||
|
||||
bool m_load_error_page { false };
|
||||
bool m_shown { false };
|
||||
};
|
||||
|
||||
class ConnectRequestHandler
|
||||
{
|
||||
@ -146,7 +148,7 @@ private:
|
||||
class WebViewDialog : public wxDialog
|
||||
{
|
||||
public:
|
||||
WebViewDialog(wxWindow* parent, const wxString& url, const wxString& dialog_name, const wxSize& size);
|
||||
WebViewDialog(wxWindow* parent, const wxString& url, const wxString& dialog_name, const wxSize& size, const std::string& loading_html = "loading");
|
||||
virtual ~WebViewDialog();
|
||||
|
||||
virtual void on_show(wxShowEvent& evt) = 0;
|
||||
@ -156,6 +158,7 @@ public:
|
||||
|
||||
protected:
|
||||
wxWebView* m_browser;
|
||||
std::string m_loading_html;
|
||||
};
|
||||
|
||||
class PrinterPickWebViewDialog : public WebViewDialog, public ConnectRequestHandler
|
||||
@ -167,6 +170,8 @@ public:
|
||||
protected:
|
||||
void on_request_update_selected_printer_action() override;
|
||||
void request_compatible_printers() override;
|
||||
void request_compatible_printers_FFF();
|
||||
void request_compatible_printers_SLA();
|
||||
void run_script_bridge(const wxString& script) override { run_script(script); }
|
||||
private:
|
||||
std::string& m_ret_val;
|
||||
|
@ -70,6 +70,10 @@ PrintHost* PrintHost::get_print_host(DynamicPrintConfig *config)
|
||||
default: return nullptr;
|
||||
}
|
||||
} else {
|
||||
const auto opt = config->option<ConfigOptionEnum<PrintHostType>>("host_type");
|
||||
if (opt != nullptr && opt->value == htPrusaConnectNew) {
|
||||
return new PrusaConnectNew(config);
|
||||
}
|
||||
return new SL1Host(config);
|
||||
}
|
||||
}
|
||||
|
@ -60,7 +60,7 @@ bool PrusaConnectNew::test(wxString& curl_msg) const
|
||||
{
|
||||
// Test is not used by upload and gets list of files on a device.
|
||||
const std::string name = get_name();
|
||||
std::string url = GUI::format("https://dev.connect.prusa3d.com/app/teams/%1%/files?printer_uuid=%2%", m_team_id, m_uuid);
|
||||
std::string url = GUI::format("https://connect.prusa3d.com/app/teams/%1%/files?printer_uuid=%2%", m_team_id, m_uuid);
|
||||
const std::string access_token = GUI::wxGetApp().plater()->get_user_account()->get_access_token();
|
||||
BOOST_LOG_TRIVIAL(info) << GUI::format("%1%: Get files/raw at: %2%", name, url);
|
||||
bool res = true;
|
||||
|
@ -32,7 +32,7 @@ public:
|
||||
bool has_auto_discovery() const override { return true; }
|
||||
bool can_test() const override { return true; }
|
||||
PrintHostPostUploadActions get_post_upload_actions() const override { return PrintHostPostUploadAction::StartPrint | PrintHostPostUploadAction::QueuePrint; }
|
||||
std::string get_host() const override { return "https://dev.connect.prusa3d.com"; }
|
||||
std::string get_host() const override { return "https://connect.prusa3d.com"; }
|
||||
bool get_storage(wxArrayString& storage_path, wxArrayString& storage_name) const override;
|
||||
//const std::string& get_apikey() const { return m_apikey; }
|
||||
//const std::string& get_cafile() const { return m_cafile; }
|
||||
|
Loading…
x
Reference in New Issue
Block a user