mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-10-18 22:31:13 -06:00
Edit Custom G-Codes Improvements
Orca: Added option to use CMake config option ORCA_CHECK_GCODE_PLACEHOLDERS to check custom gcode placeholders rather than using debug Original Commit: prusa3d/PrusaSlicer@b8bb7f2 Co-authored-by: YuSanka <yusanka@gmail.com>
This commit is contained in:
parent
6539dc4efa
commit
0e590083fa
16 changed files with 491 additions and 350 deletions
|
@ -13,6 +13,10 @@ include(PrecompiledHeader)
|
|||
string(TIMESTAMP COMPILE_TIME %Y%m%d-%H%M%S)
|
||||
set(SLIC3R_BUILD_TIME ${COMPILE_TIME})
|
||||
|
||||
if(NOT DEFINED ORCA_CHECK_GCODE_PLACEHOLDERS)
|
||||
set(ORCA_CHECK_GCODE_PLACEHOLDERS "0")
|
||||
endif()
|
||||
|
||||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libslic3r_version.h.in ${CMAKE_CURRENT_BINARY_DIR}/libslic3r_version.h @ONLY)
|
||||
|
||||
if (MINGW)
|
||||
|
|
|
@ -1786,6 +1786,8 @@ public:
|
|||
// Create a default option to be inserted into a DynamicConfig.
|
||||
ConfigOption* create_default_option() const;
|
||||
|
||||
bool is_scalar() const { return (int(this->type) & int(coVectorType)) == 0; }
|
||||
|
||||
template<class Archive> ConfigOption* load_option_from_archive(Archive &archive) const {
|
||||
if (this->nullable) {
|
||||
switch (this->type) {
|
||||
|
@ -1973,6 +1975,7 @@ public:
|
|||
out.push_back(kvp.first);
|
||||
return out;
|
||||
}
|
||||
bool empty() { return options.empty(); }
|
||||
|
||||
// Iterate through all of the CLI options and write them to a stream.
|
||||
std::ostream& print_cli_help(
|
||||
|
|
|
@ -2915,11 +2915,34 @@ 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;
|
||||
// Orca: Modified functionality from PS implementation since debug is rarely used in current workflow.
|
||||
// Allows generation to be toggled via a CMake config option.
|
||||
#if !defined(NDEBUG) || defined(ORCA_CHECK_GCODE_PLACEHOLDERS) // CHECK_CUSTOM_GCODE_PLACEHOLDERS
|
||||
if (config_override) {
|
||||
const auto& custom_gcode_placeholders = custom_gcode_specific_placeholders();
|
||||
|
||||
// 1-st check: custom G-code "name" have to be present in s_CustomGcodeSpecificOptions;
|
||||
//if (custom_gcode_placeholders.count(name) > 0) {
|
||||
// const auto& placeholders = custom_gcode_placeholders.at(name);
|
||||
if (auto it = custom_gcode_placeholders.find(name); it != custom_gcode_placeholders.end()) {
|
||||
const auto& placeholders = it->second;
|
||||
|
||||
for (const std::string& key : config_override->keys()) {
|
||||
// 2-nd check: "key" have to be present in s_CustomGcodeSpecificOptions for "name" custom G-code ;
|
||||
if (std::find(placeholders.begin(), placeholders.end(), key) == placeholders.end())
|
||||
throw Slic3r::PlaceholderParserError(format("\"%s\" placeholder for \"%s\" custom G-code \n"
|
||||
"needs to be added to s_CustomGcodeSpecificOptions", key.c_str(), name.c_str()));
|
||||
// 3-rd check: "key" have to be present in CustomGcodeSpecificConfigDef for "key" placeholder;
|
||||
if (!custom_gcode_specific_config_def.has(key))
|
||||
throw Slic3r::PlaceholderParserError(format("Definition of \"%s\" placeholder \n"
|
||||
"needs to be added to CustomGcodeSpecificConfigDef", key.c_str()));
|
||||
}
|
||||
}
|
||||
else
|
||||
throw Slic3r::PlaceholderParserError(format("\"%s\" custom G-code needs to be added to s_CustomGcodeSpecificOptions", name.c_str()));
|
||||
}
|
||||
#endif
|
||||
|
||||
PlaceholderParserIntegration &ppi = m_placeholder_parser_integration;
|
||||
try {
|
||||
ppi.update_from_gcodewriter(m_writer);
|
||||
|
|
|
@ -156,7 +156,6 @@ struct LayerResult {
|
|||
static LayerResult make_nop_layer_result() { return {"", std::numeric_limits<coord_t>::max(), false, false, true}; }
|
||||
};
|
||||
|
||||
#define GET_CUSTOM_GCODE_PLACEHOLDERS 1
|
||||
class GCode {
|
||||
|
||||
public:
|
||||
|
@ -187,13 +186,6 @@ 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);
|
||||
|
|
|
@ -2039,45 +2039,6 @@ std::string Print::export_gcode(const std::string& path_template, GCodeProcessor
|
|||
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();
|
||||
|
|
|
@ -6458,6 +6458,322 @@ void DynamicPrintAndCLIConfig::handle_legacy(t_config_option_key &opt_key, std::
|
|||
}
|
||||
}
|
||||
|
||||
// SlicingStatesConfigDefs
|
||||
|
||||
ReadOnlySlicingStatesConfigDef::ReadOnlySlicingStatesConfigDef()
|
||||
{
|
||||
ConfigOptionDef* def;
|
||||
|
||||
def = this->add("zhop", coFloat);
|
||||
def->label = L("");
|
||||
def->tooltip = L("");
|
||||
}
|
||||
|
||||
ReadWriteSlicingStatesConfigDef::ReadWriteSlicingStatesConfigDef()
|
||||
{
|
||||
ConfigOptionDef* def;
|
||||
|
||||
def = this->add("position", coFloats);
|
||||
def->label = L("Position");
|
||||
def->tooltip = L("");
|
||||
|
||||
def = this->add("e_retracted", coFloats);
|
||||
def->label = L("");
|
||||
def->tooltip = L("");
|
||||
|
||||
def = this->add("e_restart_extra", coFloats);
|
||||
def->label = L("");
|
||||
def->tooltip = L("");
|
||||
|
||||
def = this->add("e_position", coFloats);
|
||||
def->label = L("");
|
||||
def->tooltip = L("");
|
||||
}
|
||||
|
||||
OtherSlicingStatesConfigDef::OtherSlicingStatesConfigDef()
|
||||
{
|
||||
ConfigOptionDef* def;
|
||||
|
||||
def = this->add("current_extruder", coInt);
|
||||
def->label = L("Current extruder");
|
||||
def->tooltip = L("");
|
||||
|
||||
def = this->add("current_object_idx", coInt);
|
||||
def->label = L("Current object index");
|
||||
def->tooltip = L("");
|
||||
|
||||
def = this->add("has_single_extruder_multi_material_priming", coBool);
|
||||
def->label = L("Has single extruder MM priming");
|
||||
def->tooltip = L("");
|
||||
|
||||
def = this->add("has_wipe_tower", coBool);
|
||||
def->label = L("Has wipe tower");
|
||||
def->tooltip = L("");
|
||||
|
||||
def = this->add("initial_extruder", coInt);
|
||||
def->label = L("Initial extruder");
|
||||
def->tooltip = L("");
|
||||
|
||||
def = this->add("initial_filament_type", coStrings);
|
||||
def->label = L("");
|
||||
def->tooltip = L("");
|
||||
|
||||
def = this->add("initial_tool", coInt);
|
||||
def->label = L("Initial tool");
|
||||
def->tooltip = L("");
|
||||
|
||||
def = this->add("is_extruder_used", coBools);
|
||||
def->label = L("");
|
||||
def->tooltip = L("");
|
||||
}
|
||||
|
||||
PrintStatisticsConfigDef::PrintStatisticsConfigDef()
|
||||
{
|
||||
ConfigOptionDef* def;
|
||||
|
||||
def = this->add("extruded_volume", coFloats);
|
||||
def->label = L("");
|
||||
def->tooltip = L("");
|
||||
|
||||
def = this->add("normal_print_time", coString);
|
||||
def->label = L("");
|
||||
def->tooltip = L("");
|
||||
|
||||
def = this->add("num_printing_extruders", coInt);
|
||||
def->label = L("");
|
||||
def->tooltip = L("");
|
||||
|
||||
def = this->add("print_time", coString);
|
||||
def->label = L("");
|
||||
def->tooltip = L("");
|
||||
|
||||
def = this->add("printing_filament_types", coString);
|
||||
def->label = L("");
|
||||
def->tooltip = L("");
|
||||
|
||||
def = this->add("silent_print_time", coString);
|
||||
def->label = L("");
|
||||
def->tooltip = L("");
|
||||
|
||||
def = this->add("total_cost", coFloat);
|
||||
def->label = L("");
|
||||
def->tooltip = L("");
|
||||
|
||||
def = this->add("total_weight", coFloat);
|
||||
def->label = L("");
|
||||
def->tooltip = L("");
|
||||
|
||||
def = this->add("total_wipe_tower_cost", coFloat);
|
||||
def->label = L("");
|
||||
def->tooltip = L("");
|
||||
|
||||
def = this->add("total_wipe_tower_filament", coFloat);
|
||||
def->label = L("");
|
||||
def->tooltip = L("");
|
||||
|
||||
def = this->add("used_filament", coFloat);
|
||||
def->label = L("");
|
||||
def->tooltip = L("");
|
||||
|
||||
def = this->add("total_toolchanges", coInt);
|
||||
def->label = L("Total toolchanges");
|
||||
def->tooltip = L("");
|
||||
|
||||
def = this->add("extruded_volume_total", coFloat);
|
||||
def->label = L("");
|
||||
def->tooltip = L("");
|
||||
|
||||
def = this->add("extruded_weight", coFloats);
|
||||
def->label = L("");
|
||||
def->tooltip = L("");
|
||||
|
||||
def = this->add("extruded_weight_total", coFloat);
|
||||
def->label = L("");
|
||||
def->tooltip = L("");
|
||||
|
||||
def = this->add("total_layer_count", coInt);
|
||||
def->label = L("Total layer count");
|
||||
def->tooltip = L("");
|
||||
}
|
||||
|
||||
ObjectsInfoConfigDef::ObjectsInfoConfigDef()
|
||||
{
|
||||
ConfigOptionDef* def;
|
||||
|
||||
def = this->add("num_objects", coInt);
|
||||
def->label = L("");
|
||||
def->tooltip = L("");
|
||||
|
||||
def = this->add("num_instances", coInt);
|
||||
def->label = L("");
|
||||
def->tooltip = L("");
|
||||
|
||||
def = this->add("scale", coStrings);
|
||||
def->label = L("");
|
||||
def->tooltip = L("");
|
||||
|
||||
def = this->add("input_filename", coString);
|
||||
def->label = L("");
|
||||
def->tooltip = L("");
|
||||
|
||||
def = this->add("input_filename_base", coString);
|
||||
def->label = L("");
|
||||
def->tooltip = L("");
|
||||
}
|
||||
|
||||
DimensionsConfigDef::DimensionsConfigDef()
|
||||
{
|
||||
ConfigOptionDef* def;
|
||||
|
||||
def = this->add("first_layer_print_convex_hull", coPoints);
|
||||
def->label = L("");
|
||||
def->tooltip = L("");
|
||||
|
||||
def = this->add("first_layer_print_min", coFloats);
|
||||
def->label = L("");
|
||||
def->tooltip = L("");
|
||||
|
||||
def = this->add("first_layer_print_max", coFloats);
|
||||
def->label = L("");
|
||||
def->tooltip = L("");
|
||||
|
||||
def = this->add("first_layer_print_size", coFloats);
|
||||
def->label = L("");
|
||||
def->tooltip = L("");
|
||||
|
||||
def = this->add("print_bed_min", coFloats);
|
||||
def->label = L("");
|
||||
def->tooltip = L("");
|
||||
|
||||
def = this->add("print_bed_max", coFloats);
|
||||
def->label = L("");
|
||||
def->tooltip = L("");
|
||||
|
||||
def = this->add("print_bed_size", coFloats);
|
||||
def->label = L("");
|
||||
def->tooltip = L("");
|
||||
}
|
||||
|
||||
TimestampsConfigDef::TimestampsConfigDef()
|
||||
{
|
||||
ConfigOptionDef* def;
|
||||
|
||||
def = this->add("timestamp", coString);
|
||||
def->label = L("");
|
||||
def->tooltip = L("");
|
||||
|
||||
def = this->add("year", coInt);
|
||||
def->label = L("Year");
|
||||
def->tooltip = L("");
|
||||
|
||||
def = this->add("month", coInt);
|
||||
def->label = L("Month");
|
||||
def->tooltip = L("");
|
||||
|
||||
def = this->add("day", coInt);
|
||||
def->label = L("Day");
|
||||
def->tooltip = L("");
|
||||
|
||||
def = this->add("hour", coInt);
|
||||
def->label = L("Hour");
|
||||
def->tooltip = L("");
|
||||
|
||||
def = this->add("minute", coInt);
|
||||
def->label = L("Minute");
|
||||
def->tooltip = L("");
|
||||
|
||||
def = this->add("second", coInt);
|
||||
def->label = L("Second");
|
||||
def->tooltip = L("");
|
||||
}
|
||||
|
||||
OtherPresetsConfigDef::OtherPresetsConfigDef()
|
||||
{
|
||||
ConfigOptionDef* def;
|
||||
|
||||
def = this->add("num_extruders", coInt);
|
||||
def->label = L("");
|
||||
def->tooltip = L("");
|
||||
|
||||
def = this->add("print_preset", coString);
|
||||
def->label = L("");
|
||||
def->tooltip = L("");
|
||||
|
||||
def = this->add("filament_preset", coString);
|
||||
def->label = L("");
|
||||
def->tooltip = L("");
|
||||
|
||||
def = this->add("printer_preset", coString);
|
||||
def->label = L("");
|
||||
def->tooltip = L("");
|
||||
|
||||
def = this->add("physical_printer_preset", coString);
|
||||
def->label = L("");
|
||||
def->tooltip = L("");
|
||||
}
|
||||
|
||||
|
||||
static std::map<t_custom_gcode_key, t_config_option_keys> s_CustomGcodeSpecificPlaceholders{
|
||||
{"start_filament_gcode", {"layer_num", "layer_z", "max_layer_z", "filament_extruder_id"}},
|
||||
{"end_filament_gcode", {"layer_num", "layer_z", "max_layer_z", "filament_extruder_id"}},
|
||||
{"end_gcode", {"layer_num", "layer_z", "max_layer_z", "filament_extruder_id"}},
|
||||
{"before_layer_gcode", {"layer_num", "layer_z", "max_layer_z"}},
|
||||
{"layer_gcode", {"layer_num", "layer_z", "max_layer_z"}},
|
||||
{"toolchange_gcode", {"layer_num", "layer_z", "max_layer_z", "previous_extruder", "next_extruder", "toolchange_z"}},
|
||||
// some internal g_code ?
|
||||
{"tcr_rotated_gcode", {"toolchange_gcode", "deretraction_from_wipe_tower_generator"}},
|
||||
};
|
||||
|
||||
const std::map<t_custom_gcode_key, t_config_option_keys>& custom_gcode_specific_placeholders()
|
||||
{
|
||||
return s_CustomGcodeSpecificPlaceholders;
|
||||
}
|
||||
|
||||
CustomGcodeSpecificConfigDef::CustomGcodeSpecificConfigDef()
|
||||
{
|
||||
ConfigOptionDef* def;
|
||||
|
||||
def = this->add("layer_num", coInt);
|
||||
def->label = L("");
|
||||
def->tooltip = L("");
|
||||
|
||||
def = this->add("layer_z", coFloat);
|
||||
def->label = L("");
|
||||
def->tooltip = L("");
|
||||
|
||||
def = this->add("max_layer_z", coFloat);
|
||||
def->label = L("");
|
||||
def->tooltip = L("");
|
||||
|
||||
def = this->add("filament_extruder_id", coInt);
|
||||
def->label = L("");
|
||||
def->tooltip = L("");
|
||||
|
||||
def = this->add("previous_extruder", coInt);
|
||||
def->label = L("");
|
||||
def->tooltip = L("");
|
||||
|
||||
def = this->add("next_extruder", coInt);
|
||||
def->label = L("");
|
||||
def->tooltip = L("");
|
||||
|
||||
def = this->add("toolchange_z", coFloat);
|
||||
def->label = L("");
|
||||
def->tooltip = L("");
|
||||
|
||||
// I'm not sure if next options are really needed
|
||||
|
||||
def = this->add("toolchange_gcode", coString);
|
||||
def->label = L("");
|
||||
def->tooltip = L("");
|
||||
|
||||
def = this->add("deretraction_from_wipe_tower_generator", coString);
|
||||
def->label = L("");
|
||||
def->tooltip = L("");
|
||||
}
|
||||
|
||||
const CustomGcodeSpecificConfigDef custom_gcode_specific_config_def;
|
||||
|
||||
uint64_t ModelConfig::s_last_timestamp = 1;
|
||||
|
||||
static Points to_points(const std::vector<Vec2d> &dpts)
|
||||
|
|
|
@ -1432,6 +1432,68 @@ public:
|
|||
CLIMiscConfigDef();
|
||||
};
|
||||
|
||||
typedef std::string t_custom_gcode_key;
|
||||
// This map containes list of specific placeholders for each custom G-code, if any exist
|
||||
const std::map<t_custom_gcode_key, t_config_option_keys>& custom_gcode_specific_placeholders();
|
||||
|
||||
// Next classes define placeholders used by GUI::EditGCodeDialog.
|
||||
|
||||
class ReadOnlySlicingStatesConfigDef : public ConfigDef
|
||||
{
|
||||
public:
|
||||
ReadOnlySlicingStatesConfigDef();
|
||||
};
|
||||
|
||||
class ReadWriteSlicingStatesConfigDef : public ConfigDef
|
||||
{
|
||||
public:
|
||||
ReadWriteSlicingStatesConfigDef();
|
||||
};
|
||||
|
||||
class OtherSlicingStatesConfigDef : public ConfigDef
|
||||
{
|
||||
public:
|
||||
OtherSlicingStatesConfigDef();
|
||||
};
|
||||
|
||||
class PrintStatisticsConfigDef : public ConfigDef
|
||||
{
|
||||
public:
|
||||
PrintStatisticsConfigDef();
|
||||
};
|
||||
|
||||
class ObjectsInfoConfigDef : public ConfigDef
|
||||
{
|
||||
public:
|
||||
ObjectsInfoConfigDef();
|
||||
};
|
||||
|
||||
class DimensionsConfigDef : public ConfigDef
|
||||
{
|
||||
public:
|
||||
DimensionsConfigDef();
|
||||
};
|
||||
|
||||
class TimestampsConfigDef : public ConfigDef
|
||||
{
|
||||
public:
|
||||
TimestampsConfigDef();
|
||||
};
|
||||
|
||||
class OtherPresetsConfigDef : public ConfigDef
|
||||
{
|
||||
public:
|
||||
OtherPresetsConfigDef();
|
||||
};
|
||||
|
||||
// This classes defines all custom G-code specific placeholders.
|
||||
class CustomGcodeSpecificConfigDef : public ConfigDef
|
||||
{
|
||||
public:
|
||||
CustomGcodeSpecificConfigDef();
|
||||
};
|
||||
extern const CustomGcodeSpecificConfigDef custom_gcode_specific_config_def;
|
||||
|
||||
// This class defines the command line options representing actions.
|
||||
extern const CLIActionsConfigDef cli_actions_config_def;
|
||||
|
||||
|
|
|
@ -10,5 +10,6 @@
|
|||
//#define SLIC3R_RC_VERSION "@SLIC3R_VERSION@"
|
||||
#define BBL_RELEASE_TO_PUBLIC @BBL_RELEASE_TO_PUBLIC@
|
||||
#define BBL_INTERNAL_TESTING @BBL_INTERNAL_TESTING@
|
||||
#define ORCA_CHECK_GCODE_PLACEHOLDERS @ORCA_CHECK_GCODE_PLACEHOLDERS@
|
||||
|
||||
#endif /* __SLIC3R_VERSION_H */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue