Skip to content

Commit

Permalink
fix: create filament, and set the 'Snapmaker' to default
Browse files Browse the repository at this point in the history
  • Loading branch information
womendoushihaoyin committed Oct 22, 2024
1 parent 7f8685c commit 50213f9
Showing 1 changed file with 41 additions and 13 deletions.
54 changes: 41 additions & 13 deletions src/slic3r/GUI/CreatePresetsDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -542,17 +542,26 @@ static char* read_json_file(const std::string &preset_path)
}

static std::string get_printer_nozzle_diameter(std::string printer_name) {

size_t index = printer_name.find(" nozzle");
if (std::string::npos == index) {
return "";
}
std::string nozzle = printer_name.substr(0, index);
size_t last_space_index = nozzle.find_last_of(" ");
size_t index = printer_name.find(" nozzle)");
if (std::string::npos == index) {
return "";
size_t index = printer_name.find(" nozzle");
if (std::string::npos == index) {
return "";
}
std::string nozzle = printer_name.substr(0, index);
size_t last_space_index = nozzle.find_last_of(" ");
if (std::string::npos == index) {
return "";
}
return nozzle.substr(last_space_index + 1);
} else {
std::string nozzle = printer_name.substr(0, index);
size_t last_bracket_index = nozzle.find_last_of("(");
if (std::string::npos == index) {
return "";
}
return nozzle.substr(last_bracket_index + 1);
}
return nozzle.substr(last_space_index + 1);
}

static void adjust_dialog_in_screen(DPIDialog* dialog) {
Expand Down Expand Up @@ -711,10 +720,19 @@ wxBoxSizer *CreateFilamentPresetDialog::create_vendor_item()
std::sort(string_vendors.begin(), string_vendors.end(), caseInsensitiveCompare);

wxArrayString choices;
bool hasSnapmaker = false;
for (const std::string &vendor : string_vendors) {
if (vendor == "Snapmaker") {
hasSnapmaker = true;
continue;
}
choices.push_back(wxString(vendor)); // Convert std::string to wxString before adding
}

if (hasSnapmaker) {
choices.Insert(wxString("Snapmaker"), 0);
}

wxBoxSizer *vendor_sizer = new wxBoxSizer(wxHORIZONTAL);
m_filament_vendor_combobox = new ComboBox(this, wxID_ANY, wxEmptyString, wxDefaultPosition, NAME_OPTION_COMBOBOX_SIZE, 0, nullptr, wxCB_READONLY);
m_filament_vendor_combobox->SetLabel(_L("Select Vendor"));
Expand Down Expand Up @@ -1179,10 +1197,11 @@ wxArrayString CreateFilamentPresetDialog::get_filament_preset_choices()
std::string preset_name = filament_preset->name;
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " filament_id: " << filament_preset->filament_id << " preset name: " << filament_preset->name;
size_t index_at = preset_name.find(" @");
std::string cur_preset_name = preset_name;
if (std::string::npos != index_at) {
std::string cur_preset_name = preset_name.substr(0, index_at);
preset_name_set.insert(from_u8(cur_preset_name));
cur_preset_name = preset_name.substr(0, index_at);
}
preset_name_set.insert(from_u8(cur_preset_name));
}
assert(1 == preset_name_set.size());
if (preset_name_set.size() > 1) {
Expand All @@ -1192,11 +1211,20 @@ wxArrayString CreateFilamentPresetDialog::get_filament_preset_choices()
if (m_public_name_to_filament_id_map.find(public_name) != m_public_name_to_filament_id_map.end()) {
suffix++;
m_public_name_to_filament_id_map[public_name + "_" + std::to_string(suffix)] = preset.first;
choices.Add(public_name + "_" + std::to_string(suffix));
if (public_name.find("Snapmaker") != std::string::npos) {
choices.Insert(public_name + "_" + std::to_string(suffix), 0);
} else {
choices.Add(public_name + "_" + std::to_string(suffix));
}

BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " add filament choice: " << choices.back();
} else {
m_public_name_to_filament_id_map[public_name] = preset.first;
choices.Add(public_name);
if (public_name.find("Snapmaker") != std::string::npos) {
choices.Insert(public_name, 0);
} else {
choices.Add(public_name);
}
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " add filament choice: " << choices.back();
}
}
Expand Down

0 comments on commit 50213f9

Please sign in to comment.