diff --git a/src/imgui/imconfig.h b/src/imgui/imconfig.h index eb47459ea..d32f64aa4 100644 --- a/src/imgui/imconfig.h +++ b/src/imgui/imconfig.h @@ -107,7 +107,7 @@ namespace ImGui const char ColorMarkerStart = 0x2; // STX const char ColorMarkerEnd = 0x3; // ETX - // Special ASCII characters are used here as a ikons markers + // Special ASCII characters are used here as an ikons markers const char PrintIconMarker = 0x4; const char PrinterIconMarker = 0x5; const char PrinterSlaIconMarker = 0x6; diff --git a/src/libslic3r/Format/3mf.cpp b/src/libslic3r/Format/3mf.cpp index 0b02de1e7..657e9ec98 100644 --- a/src/libslic3r/Format/3mf.cpp +++ b/src/libslic3r/Format/3mf.cpp @@ -1197,14 +1197,32 @@ namespace Slic3r { } if (code.first != "code") continue; - pt::ptree tree = code.second; - double print_z = tree.get (".print_z" ); - CustomGCode::Type type = static_cast(tree.get (".type" )); -// std::string gcode = tree.get (".gcode" ); - int extruder = tree.get (".extruder" ); - std::string color = tree.get (".color" ); - m_model->custom_gcode_per_print_z.gcodes.push_back(CustomGCode::Item{print_z, type, /*gcode, */extruder, color}) ; + pt::ptree tree = code.second; + double print_z = tree.get (".print_z" ); + int extruder = tree.get (".extruder"); + std::string color = tree.get (".color" ); + + CustomGCode::Type type; + std::string extra; + if (tree.find("type") == tree.not_found()) + { + // It means that data was saved in old version (2.2.0 and older) of PrusaSlicer + // read old data ... + std::string gcode = tree.get (".gcode"); + // ... and interpret them to the new data + type = gcode == "M600" ? CustomGCode::ColorChange : + gcode == "M601" ? CustomGCode::PausePrint : + gcode == "tool_change" ? CustomGCode::ToolChange : CustomGCode::Custom; + extra = type == CustomGCode::PausePrint ? color : + type == CustomGCode::Custom ? gcode : ""; + } + else + { + type = static_cast(tree.get(".type")); + extra = tree.get(".extra"); + } + m_model->custom_gcode_per_print_z.gcodes.push_back(CustomGCode::Item{print_z, type, extruder, color, extra}) ; } } } @@ -1983,7 +2001,7 @@ namespace Slic3r { bool _add_sla_drain_holes_file_to_archive(mz_zip_archive& archive, Model& model); bool _add_print_config_file_to_archive(mz_zip_archive& archive, const DynamicPrintConfig &config); bool _add_model_config_file_to_archive(mz_zip_archive& archive, const Model& model, const IdToObjectDataMap &objects_data); - bool _add_custom_gcode_per_print_z_file_to_archive(mz_zip_archive& archive, Model& model); + bool _add_custom_gcode_per_print_z_file_to_archive(mz_zip_archive& archive, Model& model, const DynamicPrintConfig* config); }; bool _3MF_Exporter::save_model_to_file(const std::string& filename, Model& model, const DynamicPrintConfig* config, bool fullpath_sources, const ThumbnailData* thumbnail_data) @@ -2083,7 +2101,7 @@ namespace Slic3r { // Adds custom gcode per height file ("Metadata/Prusa_Slicer_custom_gcode_per_print_z.xml"). // All custom gcode per height of whole Model are stored here - if (!_add_custom_gcode_per_print_z_file_to_archive(archive, model)) + if (!_add_custom_gcode_per_print_z_file_to_archive(archive, model, config)) { close_zip_writer(&archive); boost::filesystem::remove(filename); @@ -2703,7 +2721,7 @@ namespace Slic3r { return true; } -bool _3MF_Exporter::_add_custom_gcode_per_print_z_file_to_archive( mz_zip_archive& archive, Model& model) +bool _3MF_Exporter::_add_custom_gcode_per_print_z_file_to_archive( mz_zip_archive& archive, Model& model, const DynamicPrintConfig* config) { std::string out = ""; @@ -2715,12 +2733,20 @@ bool _3MF_Exporter::_add_custom_gcode_per_print_z_file_to_archive( mz_zip_archiv for (const CustomGCode::Item& code : model.custom_gcode_per_print_z.gcodes) { pt::ptree& code_tree = main_tree.add("code", ""); - // store minX and maxZ + + // store data of custom_gcode_per_print_z code_tree.put(".print_z" , code.print_z ); - code_tree.put(".gcode" , static_cast(code.type)); -// code_tree.put(".gcode" , code.gcode ); + code_tree.put(".type" , static_cast(code.type)); code_tree.put(".extruder" , code.extruder ); code_tree.put(".color" , code.color ); + code_tree.put(".extra" , code.extra ); + + // add gcode field data for the old version of the PrusaSlicer + std::string gcode = code.type == CustomGCode::ColorChange ? config->opt_string("color_change_gcode") : + code.type == CustomGCode::PausePrint ? config->opt_string("pause_print_gcode") : + code.type == CustomGCode::Template ? config->opt_string("template_custom_gcode") : + code.type == CustomGCode::ToolChange ? "tool_change" : code.extra; + code_tree.put(".gcode" , gcode ); } pt::ptree& mode_tree = main_tree.add("mode", ""); diff --git a/src/libslic3r/Format/AMF.cpp b/src/libslic3r/Format/AMF.cpp index 4d2b1824c..41025f043 100644 --- a/src/libslic3r/Format/AMF.cpp +++ b/src/libslic3r/Format/AMF.cpp @@ -240,7 +240,7 @@ struct AMFParserContext // Current instance allocated for an amf/constellation/instance subtree. Instance *m_instance; // Generic string buffer for vertices, face indices, metadata etc. - std::string m_value[4]; + std::string m_value[5]; // Pointer to config to update if config data are stored inside the amf file DynamicPrintConfig *m_config; @@ -314,9 +314,26 @@ void AMFParserContext::startElement(const char *name, const char **atts) if (strcmp(name, "code") == 0) { node_type_new = NODE_TYPE_GCODE_PER_HEIGHT; m_value[0] = get_attribute(atts, "print_z"); - m_value[1] = get_attribute(atts, "gcode"); - m_value[2] = get_attribute(atts, "extruder"); - m_value[3] = get_attribute(atts, "color"); + m_value[1] = get_attribute(atts, "extruder"); + m_value[2] = get_attribute(atts, "color"); + if (get_attribute(atts, "type")) + { + m_value[3] = get_attribute(atts, "type"); + m_value[4] = get_attribute(atts, "extra"); + } + else + { + // It means that data was saved in old version (2.2.0 and older) of PrusaSlicer + // read old data ... + std::string gcode = get_attribute(atts, "gcode"); + // ... and interpret them to the new data + CustomGCode::Type type= gcode == "M600" ? CustomGCode::ColorChange : + gcode == "M601" ? CustomGCode::PausePrint : + gcode == "tool_change" ? CustomGCode::ToolChange : CustomGCode::Custom; + m_value[3] = std::to_string(static_cast(type)); + m_value[4] = type == CustomGCode::PausePrint ? m_value[2] : + type == CustomGCode::Custom ? gcode : ""; + } } else if (strcmp(name, "mode") == 0) { node_type_new = NODE_TYPE_CUSTOM_GCODE_MODE; @@ -640,13 +657,13 @@ void AMFParserContext::endElement(const char * /* name */) break; case NODE_TYPE_GCODE_PER_HEIGHT: { - double print_z = double(atof(m_value[0].c_str())); -// const std::string& gcode = m_value[1]; - CustomGCode::Type type = static_cast(atoi(m_value[1].c_str())); - int extruder = atoi(m_value[2].c_str()); - const std::string& color = m_value[3]; + double print_z = double(atof(m_value[0].c_str())); + int extruder = atoi(m_value[1].c_str()); + const std::string& color= m_value[2]; + CustomGCode::Type type = static_cast(atoi(m_value[3].c_str())); + const std::string& extra= m_value[4]; - m_model.custom_gcode_per_print_z.gcodes.push_back(CustomGCode::Item{print_z, type,/*gcode, */extruder, color}); + m_model.custom_gcode_per_print_z.gcodes.push_back(CustomGCode::Item{print_z, type, extruder, color, extra}); for (std::string& val: m_value) val.clear(); @@ -1254,10 +1271,17 @@ bool store_amf(const char* path, Model* model, const DynamicPrintConfig* config, pt::ptree& code_tree = main_tree.add("code", ""); // store custom_gcode_per_print_z gcodes information code_tree.put(".print_z" , code.print_z ); -// code_tree.put(".gcode" , code.gcode ); - code_tree.put(".type" , code.type ); + code_tree.put(".type" , static_cast(code.type)); code_tree.put(".extruder" , code.extruder ); code_tree.put(".color" , code.color ); + code_tree.put(".extra" , code.extra ); + + // add gcode field data for the old version of the PrusaSlicer + std::string gcode = code.type == CustomGCode::ColorChange ? config->opt_string("color_change_gcode") : + code.type == CustomGCode::PausePrint ? config->opt_string("pause_print_gcode") : + code.type == CustomGCode::Template ? config->opt_string("template_custom_gcode") : + code.type == CustomGCode::ToolChange ? "tool_change" : code.extra; + code_tree.put(".gcode" , gcode ); } pt::ptree& mode_tree = main_tree.add("mode", ""); diff --git a/src/slic3r/GUI/DoubleSlider.cpp b/src/slic3r/GUI/DoubleSlider.cpp index 3c682212a..7ada7733b 100644 --- a/src/slic3r/GUI/DoubleSlider.cpp +++ b/src/slic3r/GUI/DoubleSlider.cpp @@ -1506,8 +1506,9 @@ void Control::show_add_context_menu() append_menu_item(&menu, wxID_ANY, _L("Add pause print") + " (" + gcode(PausePrint) + ")", "", [this](wxCommandEvent&) { add_code_as_tick(PausePrint); }, "pause_print", &menu); - append_menu_item(&menu, wxID_ANY, _L("Add custom template") + " (" + gcode(Template) + ")", "", - [this](wxCommandEvent&) { add_code_as_tick(Template); }, "edit_gcode", &menu); + if (!gcode(Template).empty()) + append_menu_item(&menu, wxID_ANY, _L("Add custom template") + " (" + gcode(Template) + ")", "", + [this](wxCommandEvent&) { add_code_as_tick(Template); }, "edit_gcode", &menu); append_menu_item(&menu, wxID_ANY, _L("Add custom G-code"), "", [this](wxCommandEvent&) { add_code_as_tick(Custom); }, "edit_gcode", &menu); @@ -1898,7 +1899,7 @@ void Control::jump_to_print_z() void Control::post_ticks_changed_event(Type type /*= Custom*/) { - m_force_mode_apply = (type == Custom || type == ColorChange || type == ToolChange); + m_force_mode_apply = type != ToolChange; wxPostEvent(this->GetParent(), wxCommandEvent(wxCUSTOMEVT_TICKSCHANGED)); } diff --git a/src/slic3r/GUI/Search.cpp b/src/slic3r/GUI/Search.cpp index b8a7af339..613a39cce 100644 --- a/src/slic3r/GUI/Search.cpp +++ b/src/slic3r/GUI/Search.cpp @@ -34,20 +34,6 @@ namespace Search { #define SEARCH_SUPPORTS_MARKUP #endif -static const std::vector& NameByType() -{ - static std::vector data; - if (data.empty()) { - data.assign(Preset::TYPE_COUNT, std::wstring()); - data[Preset::TYPE_PRINT ] = _L("Print" ).ToStdWstring(); - data[Preset::TYPE_FILAMENT ] = _L("Filament" ).ToStdWstring(); - data[Preset::TYPE_SLA_MATERIAL ] = _L("Material" ).ToStdWstring(); - data[Preset::TYPE_SLA_PRINT ] = _L("Print" ).ToStdWstring(); - data[Preset::TYPE_PRINTER ] = _L("Printer" ).ToStdWstring(); - }; - return data; -} - static char marker_by_type(Preset::Type type, PrinterTechnology pt) { switch(type) {