mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-10-18 22:31:13 -06:00
Partial Automation of getting Gcode placeholders
Included pre-generated files specific to Orca rather than PS provided files Original Commit: prusa3d/PrusaSlicer@55d5921 Co-authored-by: YuSanka <yusanka@gmail.com>
This commit is contained in:
parent
05e159037f
commit
6d19d6207a
14 changed files with 362 additions and 109 deletions
|
@ -2915,6 +2915,11 @@ void GCode::process_layers(
|
|||
|
||||
std::string GCode::placeholder_parser_process(const std::string &name, const std::string &templ, unsigned int current_extruder_id, const DynamicConfig *config_override)
|
||||
{
|
||||
#if GET_CUSTOM_GCODE_PLACEHOLDERS
|
||||
if (config_override &&
|
||||
g_code_placeholders_map.find(name) == g_code_placeholders_map.end())
|
||||
g_code_placeholders_map[name] = *config_override;
|
||||
#endif
|
||||
PlaceholderParserIntegration &ppi = m_placeholder_parser_integration;
|
||||
try {
|
||||
ppi.update_from_gcodewriter(m_writer);
|
||||
|
|
|
@ -157,6 +157,8 @@ struct LayerResult {
|
|||
};
|
||||
|
||||
class GCode {
|
||||
#define GET_CUSTOM_GCODE_PLACEHOLDERS 1
|
||||
|
||||
public:
|
||||
GCode() :
|
||||
m_origin(Vec2d::Zero()),
|
||||
|
@ -185,6 +187,13 @@ public:
|
|||
{}
|
||||
~GCode() = default;
|
||||
|
||||
#if GET_CUSTOM_GCODE_PLACEHOLDERS
|
||||
std::map<std::string, DynamicConfig> g_code_placeholders_map;
|
||||
const std::map<std::string, DynamicConfig>& get_g_code_placeholders_map() { return g_code_placeholders_map; }
|
||||
const DynamicConfig& get_placeholder_parser_config() const { return m_placeholder_parser_integration.parser.config(); }
|
||||
const DynamicConfig& get_placeholder_output_config() const { return m_placeholder_parser_integration.output_config; }
|
||||
#endif
|
||||
|
||||
// throws std::runtime_exception on error,
|
||||
// throws CanceledException through print->throw_if_canceled().
|
||||
void do_export(Print* print, const char* path, GCodeProcessorResult* result = nullptr, ThumbnailsGeneratorCallback thumbnail_cb = nullptr);
|
||||
|
|
|
@ -2038,6 +2038,46 @@ std::string Print::export_gcode(const std::string& path_template, GCodeProcessor
|
|||
const Vec3d origin = this->get_plate_origin();
|
||||
gcode.set_gcode_offset(origin(0), origin(1));
|
||||
gcode.do_export(this, path.c_str(), result, thumbnail_cb);
|
||||
|
||||
#if GET_CUSTOM_GCODE_PLACEHOLDERS
|
||||
|
||||
const std::string dir = custom_gcodes_dir() +
|
||||
#ifdef _WIN32
|
||||
"\\";
|
||||
#else
|
||||
"/";
|
||||
#endif
|
||||
|
||||
auto save_placeholders = [dir](const std::string& file_name, const DynamicConfig& config) {
|
||||
try {
|
||||
boost::nowide::ofstream c;
|
||||
c.open(dir + file_name, std::ios::out | std::ios::trunc);
|
||||
c << "# " << header_slic3r_generated() << std::endl;
|
||||
auto keys = config.keys();
|
||||
for (const std::string& opt_key : keys) {
|
||||
const std::string type = std::to_string(int(config.optptr(opt_key)->type()));
|
||||
c << opt_key << " = " << type << std::endl;
|
||||
}
|
||||
c.close();
|
||||
}
|
||||
catch (const std::ofstream::failure& err) {
|
||||
throw RuntimeError(format("The %1% cannot be loaded:\n\tReason: %2%", file_name, err.what()));
|
||||
}
|
||||
};
|
||||
|
||||
// save specific placeholders
|
||||
const auto& gcode_placeholders = gcode.get_g_code_placeholders_map();
|
||||
for (const auto& [gcode_name, config] : gcode_placeholders)
|
||||
save_placeholders(gcode_name, config);
|
||||
|
||||
// save universal placeholders
|
||||
save_placeholders("universal", gcode.get_placeholder_parser_config());
|
||||
|
||||
// save placeholders for "rw_slicing_state" slicing state
|
||||
save_placeholders("rw_slicing_state", gcode.get_placeholder_output_config());
|
||||
|
||||
#endif
|
||||
|
||||
//BBS
|
||||
result->conflict_result = m_conflict_result;
|
||||
return path.c_str();
|
||||
|
|
|
@ -144,6 +144,11 @@ const std::string& sys_shapes_dir();
|
|||
// Return a full path to the custom shapes gallery directory.
|
||||
std::string custom_shapes_dir();
|
||||
|
||||
// Set a path with shapes gallery files.
|
||||
void set_custom_gcodes_dir(const std::string &path);
|
||||
// Return a full path to the system shapes gallery directory.
|
||||
const std::string& custom_gcodes_dir();
|
||||
|
||||
// Set a path with preset files.
|
||||
void set_data_dir(const std::string &path);
|
||||
// Return a full path to the GUI resource files.
|
||||
|
|
|
@ -265,6 +265,18 @@ const std::string& sys_shapes_dir()
|
|||
return g_sys_shapes_dir;
|
||||
}
|
||||
|
||||
static std::string g_custom_gcodes_dir;
|
||||
|
||||
void set_custom_gcodes_dir(const std::string &dir)
|
||||
{
|
||||
g_custom_gcodes_dir = dir;
|
||||
}
|
||||
|
||||
const std::string& custom_gcodes_dir()
|
||||
{
|
||||
return g_custom_gcodes_dir;
|
||||
}
|
||||
|
||||
// Translate function callback, to call wxWidgets translate function to convert non-localized UTF8 string to a localized one.
|
||||
Slic3r::I18N::translate_fn_type Slic3r::I18N::translate_fn = nullptr;
|
||||
static std::string g_data_dir;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue