mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2026-03-11 05:47:03 -06:00
ENH:multiple printers mgr support the new protocol version
jira:[none] Change-Id: Iee89fcf3e945e3507ec773b7ae70a61968fbe9ef (cherry picked from commit 7395bbb4577a59e9b874750b3faec77f9e9a3756)
This commit is contained in:
parent
bb74ca8b63
commit
bdc9e421cc
4 changed files with 208 additions and 92 deletions
|
|
@ -505,9 +505,11 @@ BBL::PrintParams SendMultiMachinePage::request_params(MachineObject* obj)
|
|||
|
||||
if (use_ams) {
|
||||
std::string ams_array;
|
||||
std::string ams_array2;
|
||||
std::string mapping_info;
|
||||
get_ams_mapping_result(ams_array, mapping_info);
|
||||
get_ams_mapping_result(ams_array, ams_array2, mapping_info);
|
||||
params.ams_mapping = ams_array;
|
||||
params.ams_mapping2 = ams_array2;
|
||||
params.ams_mapping_info = mapping_info;
|
||||
}
|
||||
else {
|
||||
|
|
@ -577,13 +579,12 @@ BBL::PrintParams SendMultiMachinePage::request_params(MachineObject* obj)
|
|||
return params;
|
||||
}
|
||||
|
||||
bool SendMultiMachinePage::get_ams_mapping_result(std::string& mapping_array_str, std::string& ams_mapping_info)
|
||||
bool SendMultiMachinePage::get_ams_mapping_result(std::string &mapping_array_str, std::string &mapping_array_str2, std::string &ams_mapping_info)
|
||||
{
|
||||
if (m_ams_mapping_result.empty())
|
||||
return false;
|
||||
if (m_ams_mapping_result.empty()) return false;
|
||||
|
||||
bool valid_mapping_result = true;
|
||||
int invalid_count = 0;
|
||||
int invalid_count = 0;
|
||||
for (int i = 0; i < m_ams_mapping_result.size(); i++) {
|
||||
if (m_ams_mapping_result[i].tray_id == -1) {
|
||||
valid_mapping_result = false;
|
||||
|
|
@ -593,38 +594,72 @@ bool SendMultiMachinePage::get_ams_mapping_result(std::string& mapping_array_str
|
|||
|
||||
if (invalid_count == m_ams_mapping_result.size()) {
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
json j = json::array();
|
||||
} else {
|
||||
json mapping_v0_json = json::array();
|
||||
json mapping_v1_json = json::array();
|
||||
json mapping_info_json = json::array();
|
||||
|
||||
for (int i = 0; i < wxGetApp().preset_bundle->filament_presets.size(); i++) {
|
||||
int tray_id = -1;
|
||||
json mapping_item;
|
||||
mapping_item["ams"] = tray_id;
|
||||
mapping_item["targetColor"] = "";
|
||||
mapping_item["filamentId"] = "";
|
||||
mapping_item["filamentType"] = "";
|
||||
/* get filament maps */
|
||||
std::vector<int> filament_maps;
|
||||
Plater * plater = wxGetApp().plater();
|
||||
if (plater) {
|
||||
PartPlate *curr_plate = plater->get_partplate_list().get_curr_plate();
|
||||
if (curr_plate) {
|
||||
filament_maps = curr_plate->get_filament_maps();
|
||||
} else {
|
||||
BOOST_LOG_TRIVIAL(error) << "get_ams_mapping_result, curr_plate is nullptr";
|
||||
}
|
||||
} else {
|
||||
BOOST_LOG_TRIVIAL(error) << "get_ams_mapping_result, plater is nullptr";
|
||||
}
|
||||
|
||||
for (int i = 0; i < wxGetApp().preset_bundle->filament_presets.size(); i++) {
|
||||
int tray_id = -1;
|
||||
json mapping_item_v1;
|
||||
mapping_item_v1["ams_id"] = 0xff;
|
||||
mapping_item_v1["slot_id"] = 0xff;
|
||||
json mapping_item;
|
||||
mapping_item["ams"] = tray_id;
|
||||
mapping_item["targetColor"] = "";
|
||||
mapping_item["filamentId"] = "";
|
||||
mapping_item["filamentType"] = "";
|
||||
for (int k = 0; k < m_ams_mapping_result.size(); k++) {
|
||||
if (m_ams_mapping_result[k].id == i) {
|
||||
tray_id = m_ams_mapping_result[k].tray_id;
|
||||
mapping_item["ams"] = tray_id;
|
||||
tray_id = m_ams_mapping_result[k].tray_id;
|
||||
mapping_item["ams"] = tray_id;
|
||||
mapping_item["filamentType"] = m_filaments[k].type;
|
||||
auto it = wxGetApp().preset_bundle->filaments.find_preset(wxGetApp().preset_bundle->filament_presets[i]);
|
||||
if (it != nullptr) {
|
||||
mapping_item["filamentId"] = it->filament_id;
|
||||
if (i >= 0 && i < wxGetApp().preset_bundle->filament_presets.size()) {
|
||||
auto it = wxGetApp().preset_bundle->filaments.find_preset(wxGetApp().preset_bundle->filament_presets[i]);
|
||||
if (it != nullptr) { mapping_item["filamentId"] = it->filament_id; }
|
||||
}
|
||||
//convert #RRGGBB to RRGGBBAA
|
||||
/* nozzle id */
|
||||
mapping_item["nozzleId"] = 0;
|
||||
|
||||
// convert #RRGGBB to RRGGBBAA
|
||||
mapping_item["sourceColor"] = m_filaments[k].color;
|
||||
mapping_item["targetColor"] = m_ams_mapping_result[k].color;
|
||||
if (tray_id == VIRTUAL_TRAY_MAIN_ID || tray_id == VIRTUAL_TRAY_DEPUTY_ID) { tray_id = -1; }
|
||||
|
||||
/*new ams mapping data*/
|
||||
try {
|
||||
if (m_ams_mapping_result[k].ams_id.empty() || m_ams_mapping_result[k].slot_id.empty()) { // invalid case
|
||||
mapping_item_v1["ams_id"] = VIRTUAL_TRAY_MAIN_ID;
|
||||
mapping_item_v1["slot_id"] = VIRTUAL_TRAY_MAIN_ID;
|
||||
} else {
|
||||
mapping_item_v1["ams_id"] = std::stoi(m_ams_mapping_result[k].ams_id);
|
||||
mapping_item_v1["slot_id"] = std::stoi(m_ams_mapping_result[k].slot_id);
|
||||
}
|
||||
} catch (...) {}
|
||||
}
|
||||
}
|
||||
j.push_back(tray_id);
|
||||
mapping_v0_json.push_back(tray_id);
|
||||
mapping_v1_json.push_back(mapping_item_v1);
|
||||
mapping_info_json.push_back(mapping_item);
|
||||
}
|
||||
mapping_array_str = j.dump();
|
||||
ams_mapping_info = mapping_info_json.dump();
|
||||
|
||||
mapping_array_str = mapping_v0_json.dump();
|
||||
mapping_array_str2 = mapping_v1_json.dump();
|
||||
ams_mapping_info = mapping_info_json.dump();
|
||||
return valid_mapping_result;
|
||||
}
|
||||
return true;
|
||||
|
|
@ -876,16 +911,33 @@ void SendMultiMachinePage::OnSelectRadio(wxMouseEvent& event)
|
|||
AmsRadioSelectorList::Node* node = m_radio_group.GetFirst();
|
||||
auto groupid = 0;
|
||||
|
||||
while (node) {
|
||||
AmsRadioSelector* rs = node->GetData();
|
||||
if (rs->m_radiobox->GetId() == event.GetId()) groupid = rs->m_groupid;
|
||||
node = node->GetNext();
|
||||
}
|
||||
//while (node) {
|
||||
// AmsRadioSelector* rs = node->GetData();
|
||||
// if (rs->m_radiobox->GetId() == event.GetId()) groupid = rs->m_groupid;
|
||||
// node = node->GetNext();
|
||||
//}
|
||||
|
||||
node = m_radio_group.GetFirst();
|
||||
while (node) {
|
||||
AmsRadioSelector* rs = node->GetData();
|
||||
if (rs->m_groupid == groupid && rs->m_radiobox->GetId() == event.GetId()) rs->m_radiobox->SetValue(true);
|
||||
AmsRadioSelector *rs = node->GetData();
|
||||
if (rs->m_groupid == groupid && rs->m_radiobox->GetId() == event.GetId()) {
|
||||
rs->m_radiobox->SetValue(true);
|
||||
if (rs->m_param_name == "use_external") {
|
||||
MaterialHash::iterator iter = m_material_list.begin();
|
||||
while (iter != m_material_list.end()) {
|
||||
Material * item = iter->second;
|
||||
MaterialItem *m = item->item;
|
||||
if (item->id == m_current_filament_id) { m->set_ams_info(wxColour("#CECECE"), "Ext", 0, std::vector<wxColour>()); }
|
||||
iter++;
|
||||
}
|
||||
} else if (rs->m_param_name == "use_ams") {
|
||||
m_current_filament_id = 1;
|
||||
wxCommandEvent event(EVT_SET_FINISH_MAPPING);
|
||||
event.SetInt(0);
|
||||
event.SetString("206|206|206|255|A1|1|0|0");
|
||||
wxPostEvent(this, event);
|
||||
}
|
||||
}
|
||||
if (rs->m_groupid == groupid && rs->m_radiobox->GetId() != event.GetId()) rs->m_radiobox->SetValue(false);
|
||||
node = node->GetNext();
|
||||
}
|
||||
|
|
@ -931,7 +983,7 @@ void SendMultiMachinePage::on_set_finish_mapping(wxCommandEvent& evt)
|
|||
|
||||
BOOST_LOG_TRIVIAL(info) << "The ams mapping selection result: data is " << selection_data;
|
||||
|
||||
if (selection_data_arr.size() == 6) {
|
||||
if (selection_data_arr.size() == 8) {
|
||||
auto ams_colour = wxColour(wxAtoi(selection_data_arr[0]), wxAtoi(selection_data_arr[1]), wxAtoi(selection_data_arr[2]), wxAtoi(selection_data_arr[3]));
|
||||
int old_filament_id = (int)wxAtoi(selection_data_arr[5]);
|
||||
|
||||
|
|
@ -953,11 +1005,14 @@ void SendMultiMachinePage::on_set_finish_mapping(wxCommandEvent& evt)
|
|||
for (auto i = 0; i < m_ams_mapping_result.size(); i++) {
|
||||
if (m_ams_mapping_result[i].id == wxAtoi(selection_data_arr[5])) {
|
||||
m_ams_mapping_result[i].tray_id = evt.GetInt();
|
||||
auto ams_colour = wxColour(wxAtoi(selection_data_arr[0]), wxAtoi(selection_data_arr[1]), wxAtoi(selection_data_arr[2]), wxAtoi(selection_data_arr[3]));
|
||||
wxString color = wxString::Format("#%02X%02X%02X%02X", ams_colour.Red(), ams_colour.Green(), ams_colour.Blue(), ams_colour.Alpha());
|
||||
m_ams_mapping_result[i].color = color.ToStdString();
|
||||
m_ams_mapping_result[i].ctype = ctype;
|
||||
auto ams_colour = wxColour(wxAtoi(selection_data_arr[0]), wxAtoi(selection_data_arr[1]), wxAtoi(selection_data_arr[2]), wxAtoi(selection_data_arr[3]));
|
||||
wxString color = wxString::Format("#%02X%02X%02X%02X", ams_colour.Red(), ams_colour.Green(), ams_colour.Blue(), ams_colour.Alpha());
|
||||
m_ams_mapping_result[i].color = color.ToStdString();
|
||||
m_ams_mapping_result[i].ctype = ctype;
|
||||
m_ams_mapping_result[i].colors = tray_cols;
|
||||
|
||||
m_ams_mapping_result[i].ams_id = selection_data_arr[6].ToStdString();
|
||||
m_ams_mapping_result[i].slot_id = selection_data_arr[7].ToStdString();
|
||||
}
|
||||
BOOST_LOG_TRIVIAL(trace) << "The ams mapping result: id is " << m_ams_mapping_result[i].id << "tray_id is " << m_ams_mapping_result[i].tray_id;
|
||||
}
|
||||
|
|
@ -1094,9 +1149,9 @@ wxPanel* SendMultiMachinePage::create_page()
|
|||
wxBoxSizer* title_filament = create_item_title(_L("Filament"), main_page, "");
|
||||
wxBoxSizer* radio_sizer = new wxBoxSizer(wxHORIZONTAL);
|
||||
wxBoxSizer* use_external_sizer = create_item_radiobox(_L("Use External Spool"), main_page, "", 0, "use_external");
|
||||
//wxBoxSizer* use_ams_sizer = create_item_radiobox(_L("Use AMS"), main_page, "", 0, "use_ams");
|
||||
wxBoxSizer* use_ams_sizer = create_item_radiobox(_L("Use AMS"), main_page, "", 0, "use_ams");
|
||||
radio_sizer->Add(use_external_sizer, 0, wxLeft, FromDIP(20));
|
||||
//radio_sizer->Add(use_ams_sizer, 0, wxLeft, FromDIP(5));
|
||||
radio_sizer->Add(use_ams_sizer, 0, wxLeft, FromDIP(5));
|
||||
sizer->Add(title_filament, 0, wxEXPAND, 0);
|
||||
sizer->Add(radio_sizer, 0, wxLEFT, FromDIP(20));
|
||||
sizer->AddSpacer(FromDIP(5));
|
||||
|
|
@ -1104,7 +1159,7 @@ wxPanel* SendMultiMachinePage::create_page()
|
|||
|
||||
// add ams item
|
||||
m_ams_list_sizer = new wxGridSizer(0, 4, 0, FromDIP(5));
|
||||
//sync_ams_list();
|
||||
sync_ams_list();
|
||||
sizer->Add(m_ams_list_sizer, 0, wxLEFT, FromDIP(25));
|
||||
sizer->AddSpacer(FromDIP(10));
|
||||
|
||||
|
|
@ -1432,6 +1487,7 @@ void SendMultiMachinePage::sync_ams_list()
|
|||
wxPoint pos = item->ClientToScreen(wxPoint(0, 0));
|
||||
pos.y += item->GetRect().height;
|
||||
m_mapping_popup->Move(pos);
|
||||
m_mapping_popup->set_send_win(this);
|
||||
m_mapping_popup->set_parent_item(item);
|
||||
m_mapping_popup->set_current_filament_id(extruder);
|
||||
m_mapping_popup->set_tag_texture(materials[extruder]);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue