mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-08 23:46:24 -06:00
ENH: support recover after close Studio
fix flow_ratio not change according preset Change-Id: I048d1183ffcfc2d4470725528aa62f12b32c6216
This commit is contained in:
parent
d4e7cc926f
commit
e5e66cb3dd
5 changed files with 154 additions and 101 deletions
|
@ -513,21 +513,20 @@ std::string AppConfig::load()
|
||||||
PrinterCaliInfo cali_info;
|
PrinterCaliInfo cali_info;
|
||||||
if (calis_j.contains("dev_id"))
|
if (calis_j.contains("dev_id"))
|
||||||
cali_info.dev_id = calis_j["dev_id"].get<std::string>();
|
cali_info.dev_id = calis_j["dev_id"].get<std::string>();
|
||||||
if (calis_j.contains("cali_mode"))
|
if (calis_j.contains("flow_ratio"))
|
||||||
cali_info.mode = CalibMode(calis_j["cali_mode"].get<int>());
|
cali_info.cache_flow_ratio = calis_j["flow_ratio"].get<float>();
|
||||||
if (calis_j.contains("cali_state"))
|
if (calis_j.contains("presets")) {
|
||||||
cali_info.state = CalibState(calis_j["cali_state"].get<int>());
|
cali_info.selected_presets.clear();
|
||||||
if (calis_j.contains("preset")) {
|
for (auto cali_it = calis_j["presets"].begin(); cali_it != calis_j["presets"].end(); cali_it++) {
|
||||||
for (auto cali_it = calis_j["preset"].begin(); cali_it != calis_j["preset"].end(); cali_it++) {
|
CaliPresetInfo preset_info;
|
||||||
int tray_id = cali_it.value()["tray_id"].get<int>();
|
preset_info.tray_id = cali_it.value()["tray_id"].get<int>();
|
||||||
std::string name = cali_it.value()["preset_name"].get<std::string>();
|
preset_info.nozzle_diameter = cali_it.value()["nozzle_diameter"].get<float>();
|
||||||
cali_info.filament_presets[tray_id] = name;
|
preset_info.filament_id = cali_it.value()["filament_id"].get<std::string>();
|
||||||
|
preset_info.setting_id = cali_it.value()["setting_id"].get<std::string>();
|
||||||
|
preset_info.name = cali_it.value()["name"].get<std::string>();
|
||||||
|
cali_info.selected_presets.push_back(preset_info);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//if (j.contains("nozzle"))
|
|
||||||
//cali_info.nozzle_dia = j["nozzle"].get<float>();
|
|
||||||
//if (j.contains("bed_type"))
|
|
||||||
//cali_info.bed_type = j["bed_type"].get<int>();
|
|
||||||
m_printer_cali_infos.emplace_back(cali_info);
|
m_printer_cali_infos.emplace_back(cali_info);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -638,16 +637,16 @@ void AppConfig::save()
|
||||||
for (const auto &cali_info : m_printer_cali_infos) {
|
for (const auto &cali_info : m_printer_cali_infos) {
|
||||||
json cali_json;
|
json cali_json;
|
||||||
cali_json["dev_id"] = cali_info.dev_id;
|
cali_json["dev_id"] = cali_info.dev_id;
|
||||||
cali_json["cali_mode"] = int(cali_info.mode);
|
cali_json["flow_ratio"] = cali_info.cache_flow_ratio;
|
||||||
cali_json["cali_state"] = int(cali_info.state);
|
for (auto filament_preset : cali_info.selected_presets) {
|
||||||
for (auto filament_preset : cali_info.filament_presets) {
|
|
||||||
json preset_json;
|
json preset_json;
|
||||||
preset_json["tray_id"] = filament_preset.first;
|
preset_json["tray_id"] = filament_preset.tray_id;
|
||||||
preset_json["preset_name"] = filament_preset.second;
|
preset_json["nozzle_diameter"] = filament_preset.nozzle_diameter;
|
||||||
cali_json["preset"].push_back(preset_json);
|
preset_json["filament_id"] = filament_preset.filament_id;
|
||||||
|
preset_json["setting_id"] = filament_preset.setting_id;
|
||||||
|
preset_json["name"] = filament_preset.name;
|
||||||
|
cali_json["presets"].push_back(preset_json);
|
||||||
}
|
}
|
||||||
//json["nozzle"] = cali_info.nozzle_dia;
|
|
||||||
//json["bed_type"] = cali_info.bed_type;
|
|
||||||
j["calis"].push_back(cali_json);
|
j["calis"].push_back(cali_json);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -986,11 +985,8 @@ void AppConfig::save_printer_cali_infos(const PrinterCaliInfo &cali_info)
|
||||||
if (iter == m_printer_cali_infos.end()) {
|
if (iter == m_printer_cali_infos.end()) {
|
||||||
m_printer_cali_infos.emplace_back(cali_info);
|
m_printer_cali_infos.emplace_back(cali_info);
|
||||||
} else {
|
} else {
|
||||||
(*iter).filament_presets = cali_info.filament_presets;
|
(*iter).cache_flow_ratio = cali_info.cache_flow_ratio;
|
||||||
(*iter).mode = cali_info.mode;
|
(*iter).selected_presets = cali_info.selected_presets;
|
||||||
(*iter).state = cali_info.state;
|
|
||||||
//(*iter).nozzle_dia = cali_info.nozzle_dia;
|
|
||||||
//(*iter).bed_type = cali_info.bed_type;
|
|
||||||
}
|
}
|
||||||
m_dirty = true;
|
m_dirty = true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,15 +27,6 @@ enum class CalibState {
|
||||||
Finish
|
Finish
|
||||||
};
|
};
|
||||||
|
|
||||||
struct PrinterCaliInfo
|
|
||||||
{
|
|
||||||
std::string dev_id;
|
|
||||||
CalibMode mode;
|
|
||||||
CalibState state;
|
|
||||||
/* tray index -> filament preset name */
|
|
||||||
std::map<int, std::string> filament_presets;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct Calib_Params
|
struct Calib_Params
|
||||||
{
|
{
|
||||||
Calib_Params() : mode(CalibMode::Calib_None){}
|
Calib_Params() : mode(CalibMode::Calib_None){}
|
||||||
|
@ -44,6 +35,89 @@ struct Calib_Params
|
||||||
CalibMode mode;
|
CalibMode mode;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class X1CCalibInfos
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
struct X1CCalibInfo
|
||||||
|
{
|
||||||
|
int tray_id;
|
||||||
|
int bed_temp;
|
||||||
|
int nozzle_temp;
|
||||||
|
float nozzle_diameter;
|
||||||
|
std::string filament_id;
|
||||||
|
std::string setting_id;
|
||||||
|
float max_volumetric_speed;
|
||||||
|
float flow_rate = 0.98f; // for flow ratio
|
||||||
|
};
|
||||||
|
|
||||||
|
std::vector<X1CCalibInfo> calib_datas;
|
||||||
|
};
|
||||||
|
|
||||||
|
class CaliPresetInfo
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
int tray_id;
|
||||||
|
float nozzle_diameter;
|
||||||
|
std::string filament_id;
|
||||||
|
std::string setting_id;
|
||||||
|
std::string name;
|
||||||
|
|
||||||
|
CaliPresetInfo &operator=(const CaliPresetInfo &other)
|
||||||
|
{
|
||||||
|
this->tray_id = other.tray_id;
|
||||||
|
this->nozzle_diameter = other.nozzle_diameter;
|
||||||
|
this->filament_id = other.filament_id;
|
||||||
|
this->setting_id = other.setting_id;
|
||||||
|
this->name = other.name;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
struct PrinterCaliInfo
|
||||||
|
{
|
||||||
|
std::string dev_id;
|
||||||
|
float cache_flow_ratio;
|
||||||
|
std::vector<CaliPresetInfo> selected_presets;
|
||||||
|
};
|
||||||
|
|
||||||
|
class PACalibResult
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
enum CalibResult {
|
||||||
|
CALI_RESULT_SUCCESS = 0,
|
||||||
|
CALI_RESULT_PROBLEM = 1,
|
||||||
|
CALI_RESULT_FAILED = 2,
|
||||||
|
};
|
||||||
|
int tray_id;
|
||||||
|
int cali_idx = -1;
|
||||||
|
float nozzle_diameter;
|
||||||
|
std::string filament_id;
|
||||||
|
std::string setting_id;
|
||||||
|
std::string name;
|
||||||
|
float k_value;
|
||||||
|
float n_coef;
|
||||||
|
int confidence = -1; // 0: success 1: uncertain 2: failed
|
||||||
|
};
|
||||||
|
|
||||||
|
struct PACalibIndexInfo
|
||||||
|
{
|
||||||
|
int tray_id;
|
||||||
|
int cali_idx;
|
||||||
|
float nozzle_diameter;
|
||||||
|
std::string filament_id;
|
||||||
|
};
|
||||||
|
|
||||||
|
class FlowRatioCalibResult
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
int tray_id;
|
||||||
|
float nozzle_diameter;
|
||||||
|
std::string filament_id;
|
||||||
|
std::string setting_id;
|
||||||
|
float flow_ratio;
|
||||||
|
int confidence; // 0: success 1: uncertain 2: failed
|
||||||
|
};
|
||||||
|
|
||||||
class calib_pressure_advance
|
class calib_pressure_advance
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -101,6 +101,8 @@ void CalibrationWizard::on_device_connected(MachineObject* obj)
|
||||||
if (!m_page_steps.empty())
|
if (!m_page_steps.empty())
|
||||||
show_step(m_page_steps.front());
|
show_step(m_page_steps.front());
|
||||||
|
|
||||||
|
recover_preset_info(obj);
|
||||||
|
|
||||||
for (int i = 0; i < m_page_steps.size(); i++) {
|
for (int i = 0; i < m_page_steps.size(); i++) {
|
||||||
if (m_page_steps[i]->page)
|
if (m_page_steps[i]->page)
|
||||||
m_page_steps[i]->page->on_device_connected(obj);
|
m_page_steps[i]->page->on_device_connected(obj);
|
||||||
|
@ -213,6 +215,22 @@ void CalibrationWizard::cache_preset_info(MachineObject* obj, float nozzle_dia)
|
||||||
|
|
||||||
CaliPresetStage stage;
|
CaliPresetStage stage;
|
||||||
preset_page->get_cali_stage(stage, obj->cache_flow_ratio);
|
preset_page->get_cali_stage(stage, obj->cache_flow_ratio);
|
||||||
|
|
||||||
|
PrinterCaliInfo printer_cali_info;
|
||||||
|
printer_cali_info.dev_id = obj->dev_id;
|
||||||
|
printer_cali_info.cache_flow_ratio = obj->cache_flow_ratio;
|
||||||
|
printer_cali_info.selected_presets = obj->selected_cali_preset;
|
||||||
|
wxGetApp().app_config->save_printer_cali_infos(printer_cali_info);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CalibrationWizard::recover_preset_info(MachineObject *obj)
|
||||||
|
{
|
||||||
|
std::vector<PrinterCaliInfo> back_infos = wxGetApp().app_config->get_printer_cali_infos();
|
||||||
|
for (const auto& back_info : back_infos) {
|
||||||
|
obj->dev_id = back_info.dev_id;
|
||||||
|
obj->cache_flow_ratio = back_info.cache_flow_ratio;
|
||||||
|
obj->selected_cali_preset = back_info.selected_presets;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CalibrationWizard::on_cali_go_home()
|
void CalibrationWizard::on_cali_go_home()
|
||||||
|
@ -365,6 +383,17 @@ static bool get_preset_info(const DynamicConfig& config, const BedType plate_typ
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool get_flow_ratio(const DynamicConfig& config, float& flow_ratio)
|
||||||
|
{
|
||||||
|
const ConfigOptionFloats *flow_ratio_opt = config.option<ConfigOptionFloats>("filament_flow_ratio");
|
||||||
|
if (flow_ratio_opt) {
|
||||||
|
flow_ratio = flow_ratio_opt->get_at(0);
|
||||||
|
if (flow_ratio > 0)
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
void PressureAdvanceWizard::on_cali_start()
|
void PressureAdvanceWizard::on_cali_start()
|
||||||
{
|
{
|
||||||
if (!curr_obj) {
|
if (!curr_obj) {
|
||||||
|
@ -705,6 +734,9 @@ void FlowRateWizard::on_cali_start(CaliPresetStage stage, float cali_value, Flow
|
||||||
calib_info.bed_temp = bed_temp;
|
calib_info.bed_temp = bed_temp;
|
||||||
calib_info.nozzle_temp = nozzle_temp;
|
calib_info.nozzle_temp = nozzle_temp;
|
||||||
calib_info.max_volumetric_speed = max_volumetric_speed;
|
calib_info.max_volumetric_speed = max_volumetric_speed;
|
||||||
|
float flow_ratio = 0.98;
|
||||||
|
if (get_flow_ratio(item.second->config, flow_ratio))
|
||||||
|
calib_info.flow_rate = flow_ratio;
|
||||||
calib_infos.calib_datas.push_back(calib_info);
|
calib_infos.calib_datas.push_back(calib_info);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -724,6 +756,21 @@ void FlowRateWizard::on_cali_start(CaliPresetStage stage, float cali_value, Flow
|
||||||
int cali_stage = -1;
|
int cali_stage = -1;
|
||||||
wxString wx_err_string;
|
wxString wx_err_string;
|
||||||
|
|
||||||
|
// Recover to coarse and start fine print, should recover the selected_filaments
|
||||||
|
CalibrationMethod temp_method;
|
||||||
|
int temp_cali_tage = 0;
|
||||||
|
CalibMode obj_cali_mode = get_obj_calibration_mode(curr_obj, temp_method, temp_cali_tage);
|
||||||
|
if (selected_filaments.empty() && stage == CaliPresetStage::CALI_MANUAL_STAGE_2 && obj_cali_mode == CalibMode::Calib_Flow_Rate) {
|
||||||
|
if (!curr_obj->selected_cali_preset.empty()) {
|
||||||
|
int selected_tray_id = curr_obj->selected_cali_preset.front().tray_id;
|
||||||
|
PresetCollection *filament_presets = &wxGetApp().preset_bundle->filaments;
|
||||||
|
Preset* preset = filament_presets->find_preset(curr_obj->selected_cali_preset.front().name);
|
||||||
|
if (preset) {
|
||||||
|
selected_filaments.insert(std::make_pair(selected_tray_id, preset));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!selected_filaments.empty()) {
|
if (!selected_filaments.empty()) {
|
||||||
calib_info.select_ams = "[" + std::to_string(selected_filaments.begin()->first) + "]";
|
calib_info.select_ams = "[" + std::to_string(selected_filaments.begin()->first) + "]";
|
||||||
Preset* preset = selected_filaments.begin()->second;
|
Preset* preset = selected_filaments.begin()->second;
|
||||||
|
|
|
@ -63,6 +63,7 @@ public:
|
||||||
bool save_preset(const std::string &old_preset_name, const std::string &new_preset_name, const std::map<std::string, ConfigOption *> &key_values, std::string& message);
|
bool save_preset(const std::string &old_preset_name, const std::string &new_preset_name, const std::map<std::string, ConfigOption *> &key_values, std::string& message);
|
||||||
|
|
||||||
virtual void cache_preset_info(MachineObject* obj, float nozzle_dia);
|
virtual void cache_preset_info(MachineObject* obj, float nozzle_dia);
|
||||||
|
virtual void recover_preset_info(MachineObject *obj);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void on_cali_go_home();
|
void on_cali_go_home();
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
#include "slic3r/Utils/json_diff.hpp"
|
#include "slic3r/Utils/json_diff.hpp"
|
||||||
#include "slic3r/Utils/NetworkAgent.hpp"
|
#include "slic3r/Utils/NetworkAgent.hpp"
|
||||||
#include "CameraPopup.hpp"
|
#include "CameraPopup.hpp"
|
||||||
|
#include "libslic3r/Calib.hpp"
|
||||||
|
|
||||||
#define USE_LOCAL_SOCKET_BIND 0
|
#define USE_LOCAL_SOCKET_BIND 0
|
||||||
|
|
||||||
|
@ -309,72 +310,6 @@ public:
|
||||||
static wxString get_hms_msg_level_str(HMSMessageLevel level);
|
static wxString get_hms_msg_level_str(HMSMessageLevel level);
|
||||||
};
|
};
|
||||||
|
|
||||||
class X1CCalibInfos
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
struct X1CCalibInfo
|
|
||||||
{
|
|
||||||
int tray_id;
|
|
||||||
int bed_temp;
|
|
||||||
int nozzle_temp;
|
|
||||||
float nozzle_diameter;
|
|
||||||
std::string filament_id;
|
|
||||||
std::string setting_id;
|
|
||||||
float max_volumetric_speed;
|
|
||||||
float flow_rate = 0.98f; // for flow ratio
|
|
||||||
};
|
|
||||||
|
|
||||||
std::vector<X1CCalibInfo> calib_datas;
|
|
||||||
};
|
|
||||||
|
|
||||||
class CaliPresetInfo
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
int tray_id;
|
|
||||||
float nozzle_diameter;
|
|
||||||
std::string filament_id;
|
|
||||||
std::string setting_id;
|
|
||||||
std::string name;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
class PACalibResult
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
enum CalibResult {
|
|
||||||
CALI_RESULT_SUCCESS = 0,
|
|
||||||
CALI_RESULT_PROBLEM = 1,
|
|
||||||
CALI_RESULT_FAILED = 2,
|
|
||||||
};
|
|
||||||
int tray_id;
|
|
||||||
int cali_idx = -1;
|
|
||||||
float nozzle_diameter;
|
|
||||||
std::string filament_id;
|
|
||||||
std::string setting_id;
|
|
||||||
std::string name;
|
|
||||||
float k_value;
|
|
||||||
float n_coef;
|
|
||||||
int confidence = -1; // 0: success 1: uncertain 2: failed
|
|
||||||
};
|
|
||||||
|
|
||||||
struct PACalibIndexInfo
|
|
||||||
{
|
|
||||||
int tray_id;
|
|
||||||
int cali_idx;
|
|
||||||
float nozzle_diameter;
|
|
||||||
std::string filament_id;
|
|
||||||
};
|
|
||||||
|
|
||||||
class FlowRatioCalibResult
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
int tray_id;
|
|
||||||
float nozzle_diameter;
|
|
||||||
std::string filament_id;
|
|
||||||
std::string setting_id;
|
|
||||||
float flow_ratio;
|
|
||||||
int confidence; // 0: success 1: uncertain 2: failed
|
|
||||||
};
|
|
||||||
|
|
||||||
#define UpgradeNoError 0
|
#define UpgradeNoError 0
|
||||||
#define UpgradeDownloadFailed -1
|
#define UpgradeDownloadFailed -1
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue