ENH: add load_model_objects_and_custom_gcodes

Add cmd line option to pass layer change gcode.
This is useful for lithophane auto change colors.
Cmd: --custom-gcode custom_gcode_toolchange.json

Examples of the input json file can be found in the jira.

Jira: STUDIO-4070

Change-Id: I5beb5ff7d6d81028e95013e79f955e498cd3ba30
(cherry picked from commit bed6152b95c965ea87958d94ec069d8c883a8037)
This commit is contained in:
Arthur 2023-08-04 10:49:14 +08:00 committed by Lane.Wei
parent f250d6f5c7
commit ef2cc4b65c
4 changed files with 97 additions and 0 deletions

View file

@ -3,6 +3,7 @@
#include <string>
#include <vector>
#include <nlohmann/json.hpp>
namespace Slic3r {
@ -43,6 +44,24 @@ struct Item
std::string extra; // this field is used for the extra data like :
// - G-code text for the Type::Custom
// - message text for the Type::PausePrint
void from_json(const nlohmann::json& j) {
std::string type_str;
j.at("type").get_to(type_str);
std::map<std::string,Type> str2type = { {"ColorChange", ColorChange },
{"PausePrint",PausePrint},
{"ToolChange",ToolChange},
{"Template",Template},
{"Custom",Custom},
{"Unknown",Unknown} };
type = Unknown;
if (str2type.find(type_str) != str2type.end())
type = str2type[type_str];
j.at("print_z").get_to(print_z);
j.at("color").get_to(color);
j.at("extruder").get_to(extruder);
if(j.contains("extra"))
j.at("extra").get_to(extra);
}
};
enum Mode
@ -71,6 +90,24 @@ struct Info
(rhs.gcodes == this->gcodes );
}
bool operator!=(const Info& rhs) const { return !(*this == rhs); }
void from_json(const nlohmann::json& j) {
std::string mode_str;
if (j.contains("mode"))
j.at("mode").get_to(mode_str);
if (mode_str == "SingleExtruder") mode = SingleExtruder;
else if (mode_str == "MultiAsSingle") mode = MultiAsSingle;
else if (mode_str == "MultiExtruder") mode = MultiExtruder;
else mode = Undef;
auto j_gcodes = j.at("gcodes");
gcodes.reserve(j_gcodes.size());
for (auto& jj : j_gcodes) {
Item item;
item.from_json(jj);
gcodes.push_back(item);
}
}
};
// If loaded configuration has a "colorprint_heights" option (if it was imported from older Slicer),