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:
Ocraftyone 2023-12-26 07:43:49 -05:00
parent 6539dc4efa
commit 0e590083fa
No known key found for this signature in database
GPG key ID: 85836ED21AD4D125
16 changed files with 491 additions and 350 deletions

View file

@ -1,4 +0,0 @@
# OrcaSlicer 1.9.0-dev
layer_num = 2
layer_z = 1
max_layer_z = 1

View file

@ -1,5 +0,0 @@
# OrcaSlicer 1.9.0-dev
filament_extruder_id = 2
layer_num = 2
layer_z = 1
max_layer_z = 1

View file

@ -1,3 +0,0 @@
# OrcaSlicer 1.9.0-dev
layer_num = 2
layer_z = 1

View file

@ -1,5 +0,0 @@
# OrcaSlicer 1.9.0-dev
filament_extruder_id = 2
layer_num = 2
layer_z = 1
max_layer_z = 1

View file

@ -1,4 +0,0 @@
# OrcaSlicer 1.9.0-dev
e_restart_extra = 16385
e_retracted = 16385
position = 16385

View file

@ -1,55 +0,0 @@
# OrcaSlicer 1.9.0-dev
bbl_bed_temperature_gcode = 8
bed_temperature = 16386
bed_temperature_initial_layer = 16386
bed_temperature_initial_layer_single = 2
bed_temperature_initial_layer_vector = 3
chamber_temperature = 16386
current_extruder = 2
current_object_idx = 2
day = 2
during_print_exhaust_fan_speed_num = 16386
extruded_volume = 16385
extruded_volume_total = 1
extruded_weight = 16385
extruded_weight_total = 1
filament_preset = 16387
first_layer_bed_temperature = 16386
first_layer_center_no_wipe_tower = 16385
first_layer_height = 1
first_layer_print_convex_hull = 16390
first_layer_print_max = 16385
first_layer_print_min = 16385
first_layer_print_size = 16385
first_layer_temperature = 16386
has_wipe_tower = 8
hour = 2
in_head_wrap_detect_zone = 8
initial_extruder = 2
initial_no_support_extruder = 2
initial_no_support_tool = 2
initial_tool = 2
input_filename = 3
input_filename_base = 3
is_extruder_used = 16392
max_print_height = 2
minute = 2
month = 2
num_instances = 2
num_objects = 2
outer_wall_volumetric_speed = 1
overall_chamber_temperature = 2
plate_name = 3
print_bed_max = 16385
print_bed_min = 16385
print_bed_size = 16385
print_preset = 3
printer_preset = 3
scale = 16387
second = 2
timestamp = 3
total_layer_count = 2
total_toolchanges = 2
year = 2
z_offset = 1
zhop = 1

View file

@ -13,6 +13,10 @@ include(PrecompiledHeader)
string(TIMESTAMP COMPILE_TIME %Y%m%d-%H%M%S) string(TIMESTAMP COMPILE_TIME %Y%m%d-%H%M%S)
set(SLIC3R_BUILD_TIME ${COMPILE_TIME}) 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) configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libslic3r_version.h.in ${CMAKE_CURRENT_BINARY_DIR}/libslic3r_version.h @ONLY)
if (MINGW) if (MINGW)

View file

@ -1786,6 +1786,8 @@ public:
// Create a default option to be inserted into a DynamicConfig. // Create a default option to be inserted into a DynamicConfig.
ConfigOption* create_default_option() const; 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 { template<class Archive> ConfigOption* load_option_from_archive(Archive &archive) const {
if (this->nullable) { if (this->nullable) {
switch (this->type) { switch (this->type) {
@ -1973,6 +1975,7 @@ public:
out.push_back(kvp.first); out.push_back(kvp.first);
return out; return out;
} }
bool empty() { return options.empty(); }
// Iterate through all of the CLI options and write them to a stream. // Iterate through all of the CLI options and write them to a stream.
std::ostream& print_cli_help( std::ostream& print_cli_help(

View file

@ -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) 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 // Orca: Modified functionality from PS implementation since debug is rarely used in current workflow.
if (config_override && // Allows generation to be toggled via a CMake config option.
g_code_placeholders_map.find(name) == g_code_placeholders_map.end()) #if !defined(NDEBUG) || defined(ORCA_CHECK_GCODE_PLACEHOLDERS) // CHECK_CUSTOM_GCODE_PLACEHOLDERS
g_code_placeholders_map[name] = *config_override; 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 #endif
PlaceholderParserIntegration &ppi = m_placeholder_parser_integration; PlaceholderParserIntegration &ppi = m_placeholder_parser_integration;
try { try {
ppi.update_from_gcodewriter(m_writer); ppi.update_from_gcodewriter(m_writer);

View file

@ -156,7 +156,6 @@ struct LayerResult {
static LayerResult make_nop_layer_result() { return {"", std::numeric_limits<coord_t>::max(), false, false, true}; } static LayerResult make_nop_layer_result() { return {"", std::numeric_limits<coord_t>::max(), false, false, true}; }
}; };
#define GET_CUSTOM_GCODE_PLACEHOLDERS 1
class GCode { class GCode {
public: public:
@ -187,13 +186,6 @@ public:
{} {}
~GCode() = default; ~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 std::runtime_exception on error,
// throws CanceledException through print->throw_if_canceled(). // throws CanceledException through print->throw_if_canceled().
void do_export(Print* print, const char* path, GCodeProcessorResult* result = nullptr, ThumbnailsGeneratorCallback thumbnail_cb = nullptr); void do_export(Print* print, const char* path, GCodeProcessorResult* result = nullptr, ThumbnailsGeneratorCallback thumbnail_cb = nullptr);

View file

@ -2039,45 +2039,6 @@ std::string Print::export_gcode(const std::string& path_template, GCodeProcessor
gcode.set_gcode_offset(origin(0), origin(1)); gcode.set_gcode_offset(origin(0), origin(1));
gcode.do_export(this, path.c_str(), result, thumbnail_cb); 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 //BBS
result->conflict_result = m_conflict_result; result->conflict_result = m_conflict_result;
return path.c_str(); return path.c_str();

View file

@ -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; uint64_t ModelConfig::s_last_timestamp = 1;
static Points to_points(const std::vector<Vec2d> &dpts) static Points to_points(const std::vector<Vec2d> &dpts)

View file

@ -1432,6 +1432,68 @@ public:
CLIMiscConfigDef(); 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. // This class defines the command line options representing actions.
extern const CLIActionsConfigDef cli_actions_config_def; extern const CLIActionsConfigDef cli_actions_config_def;

View file

@ -10,5 +10,6 @@
//#define SLIC3R_RC_VERSION "@SLIC3R_VERSION@" //#define SLIC3R_RC_VERSION "@SLIC3R_VERSION@"
#define BBL_RELEASE_TO_PUBLIC @BBL_RELEASE_TO_PUBLIC@ #define BBL_RELEASE_TO_PUBLIC @BBL_RELEASE_TO_PUBLIC@
#define BBL_INTERNAL_TESTING @BBL_INTERNAL_TESTING@ #define BBL_INTERNAL_TESTING @BBL_INTERNAL_TESTING@
#define ORCA_CHECK_GCODE_PLACEHOLDERS @ORCA_CHECK_GCODE_PLACEHOLDERS@
#endif /* __SLIC3R_VERSION_H */ #endif /* __SLIC3R_VERSION_H */

View file

@ -30,99 +30,6 @@
namespace Slic3r { namespace Slic3r {
namespace GUI { namespace GUI {
ConfigOption* get_new_option(const ConfigOptionType type)
{
switch (type) {
case coFloat:
return new ConfigOptionFloat(0.);
case coFloats:
return new ConfigOptionFloats({ 0. });
case coInt:
return new ConfigOptionInt(0);
case coInts:
return new ConfigOptionInts({ 0 });
case coString:
return new ConfigOptionString("");
case coStrings:
return new ConfigOptionStrings({ ""});
case coPercent:
return new ConfigOptionPercent(0);
case coPercents:
return new ConfigOptionPercents({ 0});
case coFloatOrPercent:
return new ConfigOptionFloatOrPercent();
case coFloatsOrPercents:
return new ConfigOptionFloatsOrPercents();
case coPoint:
return new ConfigOptionPoint(Vec2d(100, 100));
case coPoints:
return new ConfigOptionPoints({ Vec2d(100,100) });
case coPoint3:
return new ConfigOptionPoint3();
case coBool:
return new ConfigOptionBool(true);
case coBools:
return new ConfigOptionBools({ true });
case coEnum:
return new ConfigOptionEnum<InfillPattern>();
default:
return nullptr;
}
}
namespace fs = boost::filesystem;
namespace pt = boost::property_tree;
static std::vector<std::string> get_params_from_file(const std::string& file_name, DynamicConfig& out_config)
{
const fs::path file_path = fs::path(custom_gcodes_dir() +
#ifdef _WIN32
"\\"
#else
"/"
#endif
+ file_name);
if (!fs::exists(file_path))
return {};
const std::string file = file_path.string();
// Load the preset file, apply preset values on top of defaults.
try {
DynamicConfig config;
try {
pt::ptree tree;
boost::nowide::ifstream ifs(file);
pt::read_ini(ifs, tree);
for (const pt::ptree::value_type& v : tree) {
try {
t_config_option_key opt_key = v.first;
const std::string type_str = v.second.get_value<std::string>();
const ConfigOptionType type = ConfigOptionType(std::atoi(type_str.c_str()));
if (ConfigOption* opt = get_new_option(type))
config.set_key_value(opt_key, std::move(opt));
}
catch (UnknownOptionException& err) {
throw RuntimeError(format("Some option from %1% cannot be loaded:\n\tReason: %2%", file, err.what()));
}
}
}
catch (const ConfigurationError& e) {
throw ConfigurationError(format("Failed loading configuration file \"%1%\": \n\t%2%", file, e.what()));
}
out_config += config;
return config.keys();
}
catch (const std::ifstream::failure& err) {
throw RuntimeError(format("The %1% cannot be loaded:\n\tReason: %2%", file, err.what()));
}
catch (const std::runtime_error& err) {
throw RuntimeError(format("Failed loading the custom_gcode_placeholders file: \"%1%\"\n\tReason: %2%", file , err.what()));
}
}
//------------------------------------------ //------------------------------------------
// EditGCodeDialog // EditGCodeDialog
//------------------------------------------ //------------------------------------------
@ -201,150 +108,84 @@ std::string EditGCodeDialog::get_edited_gcode() const
return into_u8(m_gcode_editor->GetValue()); return into_u8(m_gcode_editor->GetValue());
} }
static ParamType get_type(const std::string& opt_key, const ConfigOptionDef& opt_def)
{
return opt_def.is_scalar() ? ParamType::Scalar : ParamType::Vector;
}
void EditGCodeDialog::init_params_list(const std::string& custom_gcode_name) void EditGCodeDialog::init_params_list(const std::string& custom_gcode_name)
{ {
const std::vector<std::string> read_write_params = get_params_from_file("rw_slicing_state", m_read_write_config); const auto& custom_gcode_placeholders = custom_gcode_specific_placeholders();
const std::vector<std::string> universal_params = get_params_from_file("universal", m_universal_config); const auto& specific_params = custom_gcode_placeholders.count(custom_gcode_name) > 0 ?
const std::vector<std::string> specific_params = get_params_from_file(custom_gcode_name, m_specific_config); custom_gcode_placeholders.at(custom_gcode_name) : t_config_option_keys({});
m_print_statistics_config = PrintStatistics::placeholders();
auto get_type = [](const std::string& opt_key, const DynamicConfig& config) {
return config.optptr(opt_key)->is_scalar() ? ParamType::Scalar : ParamType::Vector;
};
// Add slicing states placeholders // Add slicing states placeholders
std::set<std::string> read_only_slicing_state_opts = { "zhop" };
wxDataViewItem slicing_state = m_params_list->AppendGroup(_L("[Global] Slicing State"), "re_slice"); wxDataViewItem slicing_state = m_params_list->AppendGroup(_L("[Global] Slicing State"), "re_slice");
if (!universal_params.empty()) { if (!cgp_ro_slicing_states_config_def.empty()) {
wxDataViewItem read_only = m_params_list->AppendSubGroup(slicing_state, _L("Read Only"), "lock_closed"); wxDataViewItem read_only = m_params_list->AppendSubGroup(slicing_state, _L("Read Only"), "lock_closed");
for (const auto& opt_key : read_only_slicing_state_opts) for (const auto& [opt_key, def]: cgp_ro_slicing_states_config_def.options)
m_params_list->AppendParam(read_only, get_type(opt_key, m_universal_config), opt_key); m_params_list->AppendParam(read_only, get_type(opt_key, def), opt_key);
} }
if (!read_write_params.empty()) { if (!cgp_rw_slicing_states_config_def.empty()) {
wxDataViewItem read_write = m_params_list->AppendSubGroup(slicing_state, _L("Read Write"), "lock_open"); wxDataViewItem read_write = m_params_list->AppendSubGroup(slicing_state, _L("Read Write"), "lock_open");
for (const auto& opt_key : read_write_params) for (const auto& [opt_key, def] : cgp_rw_slicing_states_config_def.options)
m_params_list->AppendParam(read_write, get_type(opt_key, m_read_write_config), opt_key); m_params_list->AppendParam(read_write, get_type(opt_key, def), opt_key);
} }
//TODO: Orca: add other params which are related to slicing state that are specific to Orca
// add other universal params, which are related to slicing state // add other universal params, which are related to slicing state
const std::set<std::string> other_slicing_state_opts = { "initial_extruder" if (!cgp_other_slicing_states_config_def.empty()) {
// , "initial_filament_type"
, "initial_tool"
, "current_extruder"
, "is_extruder_used"
, "current_object_idx"
// , "has_single_extruder_multi_material_priming"
, "has_wipe_tower" };
slicing_state = m_params_list->AppendGroup(_L("Slicing State"), "re_slice"); slicing_state = m_params_list->AppendGroup(_L("Slicing State"), "re_slice");
for (const auto& opt_key : other_slicing_state_opts) { for (const auto& [opt_key, def] : cgp_other_slicing_states_config_def.options)
if (m_print_statistics_config.has(opt_key)) m_params_list->AppendParam(slicing_state, get_type(opt_key, def), opt_key);
m_params_list->AppendParam(slicing_state, get_type(opt_key, m_print_statistics_config), opt_key);
else if(!universal_params.empty())
m_params_list->AppendParam(slicing_state, get_type(opt_key, m_universal_config), opt_key);
} }
const std::set<std::string> other_print_statistics_opts = { "extruded_volume_total"
, "extruded_weight"
, "extruded_weight_total"
, "total_layer_count" };
const std::set<std::string> other_presets_opts = { "filament_preset"
// , "physical_printer_preset"
, "printer_preset"
, "print_preset"
/*, "num_extruders"*/ };
const std::set<std::string> objects_info_opts = { "num_instances"
, "num_objects"
, "scale"
, "input_filename"
, "input_filename_base" };
const std::set<std::string> dimensions_opts = { "first_layer_print_convex_hull"
, "first_layer_print_max"
, "first_layer_print_min"
, "first_layer_print_size"
, "print_bed_max"
, "print_bed_min"
, "print_bed_size" };
// Add universal placeholders // Add universal placeholders
if (!universal_params.empty()) { {
// wxDataViewItem group = m_params_list->AppendGroup(_L("Universal"), "equal");
// Add print statistics subgroup // Add print statistics subgroup
if (!m_print_statistics_config.empty()) { if (!cgp_print_statistics_config_def.empty()) {
// wxDataViewItem statistics = m_params_list->AppendSubGroup(group, _L("Print Statistics"), "info");
wxDataViewItem statistics = m_params_list->AppendGroup(_L("Print Statistics"), "info"); wxDataViewItem statistics = m_params_list->AppendGroup(_L("Print Statistics"), "info");
const std::vector<std::string> statistics_params = m_print_statistics_config.keys(); for (const auto& [opt_key, def] : cgp_print_statistics_config_def.options)
for (const auto& opt_key : statistics_params) m_params_list->AppendParam(statistics, get_type(opt_key, def), opt_key);
if (std::find(other_slicing_state_opts.begin(), other_slicing_state_opts.end(), opt_key) == other_slicing_state_opts.end())
m_params_list->AppendParam(statistics, get_type(opt_key, m_print_statistics_config), opt_key);
// add other universal params, which are related to print statistics
if (!universal_params.empty())
for (const auto& opt_key : other_print_statistics_opts)
m_params_list->AppendParam(statistics, get_type(opt_key, m_universal_config), opt_key);
} }
// Add objects info subgroup // Add objects info subgroup
if (!universal_params.empty()) { if (!cgp_objects_info_config_def.empty()) {
// wxDataViewItem objects_info = m_params_list->AppendSubGroup(group, _L("Objects Info"), "advanced_plus");
wxDataViewItem objects_info = m_params_list->AppendGroup(_L("Objects Info"), "advanced_plus"); wxDataViewItem objects_info = m_params_list->AppendGroup(_L("Objects Info"), "advanced_plus");
for (const auto& opt_key : objects_info_opts) for (const auto& [opt_key, def] : cgp_objects_info_config_def.options)
m_params_list->AppendParam(objects_info, get_type(opt_key, m_universal_config), opt_key); m_params_list->AppendParam(objects_info, get_type(opt_key, def), opt_key);
} }
// Add objects info subgroup // Add dimensions subgroup
if (!universal_params.empty()) { if (!cgp_dimensions_config_def.empty()) {
// wxDataViewItem dimensions = m_params_list->AppendSubGroup(group, _L("Dimensions"), "measure");
wxDataViewItem dimensions = m_params_list->AppendGroup(_L("Dimensions"), "measure"); wxDataViewItem dimensions = m_params_list->AppendGroup(_L("Dimensions"), "measure");
for (const auto& opt_key : dimensions_opts) for (const auto& [opt_key, def] : cgp_dimensions_config_def.options)
m_params_list->AppendParam(dimensions, get_type(opt_key, m_universal_config), opt_key); m_params_list->AppendParam(dimensions, get_type(opt_key, def), opt_key);
} }
// Add timestamp subgroup // Add timestamp subgroup
PlaceholderParser parser; if (!cgp_timestamps_config_def.empty()) {
parser.update_timestamp(); wxDataViewItem dimensions = m_params_list->AppendGroup(_L("Timestamps"), "time");
const DynamicConfig& ts_config = parser.config(); for (const auto& [opt_key, def] : cgp_timestamps_config_def.options)
// wxDataViewItem time_stamp = ts_config.empty() ? group : m_params_list->AppendSubGroup(group, _L("Timestamps"), "time"); m_params_list->AppendParam(dimensions, get_type(opt_key, def), opt_key);
wxDataViewItem time_stamp = m_params_list->AppendGroup(_L("Timestamps"), "time");
// Add un-grouped params
// wxDataViewItem other = m_params_list->AppendSubGroup(group, _L("Other"), "add_gcode");
wxDataViewItem other = m_params_list->AppendGroup(_L("Other"), "add_gcode");
for (const auto& opt_key : universal_params)
if (std::find(read_only_slicing_state_opts.begin(), read_only_slicing_state_opts.end(), opt_key)== read_only_slicing_state_opts.end() &&
std::find(other_slicing_state_opts.begin(), other_slicing_state_opts.end(), opt_key) == other_slicing_state_opts.end() &&
std::find(other_print_statistics_opts.begin(), other_print_statistics_opts.end(), opt_key) == other_print_statistics_opts.end() &&
std::find(other_presets_opts.begin(), other_presets_opts.end(), opt_key) == other_presets_opts.end() &&
std::find(objects_info_opts.begin(), objects_info_opts.end(), opt_key) == objects_info_opts.end() &&
std::find(dimensions_opts.begin(), dimensions_opts.end(), opt_key) == dimensions_opts.end() &&
!m_print_statistics_config.has(opt_key)) {
m_params_list->AppendParam(ts_config.has(opt_key) ? time_stamp : other, get_type(opt_key, m_universal_config), opt_key);
} }
m_params_list->CheckAndDeleteIfEmpty(other);
} }
// Add specific placeholders // Add specific placeholders
if (!specific_params.empty()) { if (!specific_params.empty()) {
wxDataViewItem group = m_params_list->AppendGroup(format_wxstr(_L("Specific for %1%"), custom_gcode_name), /*"not_equal"*/"add_gcode"); wxDataViewItem group = m_params_list->AppendGroup(format_wxstr(_L("Specific for %1%"), custom_gcode_name), "add_gcode");
for (const auto& opt_key : specific_params) for (const auto& opt_key : specific_params)
m_params_list->AppendParam(group, get_type(opt_key, m_specific_config), opt_key); if (custom_gcode_specific_config_def.has(opt_key)) {
auto def = custom_gcode_specific_config_def.get(opt_key);
m_params_list->AppendParam(group, get_type(opt_key, *def), opt_key);
}
m_params_list->Expand(group); m_params_list->Expand(group);
} }
@ -352,9 +193,9 @@ void EditGCodeDialog::init_params_list(const std::string& custom_gcode_name)
wxDataViewItem presets = add_presets_placeholders(); wxDataViewItem presets = add_presets_placeholders();
// add other params which are related to presets // add other params which are related to presets
if (!universal_params.empty()) if (!cgp_other_presets_config_def.empty())
for (const auto& opt_key : other_presets_opts) for (const auto& [opt_key, def] : cgp_other_presets_config_def.options)
m_params_list->AppendParam(presets, get_type(opt_key, m_universal_config), opt_key); m_params_list->AppendParam(presets, get_type(opt_key, def), opt_key);
} }
wxDataViewItem EditGCodeDialog::add_presets_placeholders() wxDataViewItem EditGCodeDialog::add_presets_placeholders()
@ -405,24 +246,33 @@ void EditGCodeDialog::bind_list_and_button()
const std::string opt_key = m_params_list->GetSelectedParamKey(); const std::string opt_key = m_params_list->GetSelectedParamKey();
if (!opt_key.empty()) { if (!opt_key.empty()) {
const ConfigOptionDef* cod { nullptr }; const ConfigOptionDef* def { nullptr };
const ConfigOption* optptr { nullptr };
const auto& full_config = wxGetApp().preset_bundle->full_config(); const auto& full_config = wxGetApp().preset_bundle->full_config();
if (const ConfigDef* def = full_config.def(); def && def->has(opt_key)) { if (const ConfigDef* config_def = full_config.def(); config_def && config_def->has(opt_key)) {
cod = def->get(opt_key); def = config_def->get(opt_key);
optptr = full_config.optptr(opt_key);
} }
else { else {
for (const DynamicConfig* config: { &m_read_write_config, &m_universal_config, &m_specific_config, &m_print_statistics_config }) { for (const ConfigDef* config: std::initializer_list<const ConfigDef*> {
optptr = config->optptr(opt_key); &custom_gcode_specific_config_def,
if (optptr) &cgp_ro_slicing_states_config_def,
&cgp_rw_slicing_states_config_def,
&cgp_other_slicing_states_config_def,
&cgp_print_statistics_config_def,
&cgp_objects_info_config_def,
&cgp_dimensions_config_def,
&cgp_timestamps_config_def,
&cgp_other_presets_config_def
}) {
if (config->has(opt_key)) {
def = config->get(opt_key);
break; break;
} }
} }
}
if (optptr) { if (def) {
const ConfigOptionType scalar_type = optptr->is_scalar() ? optptr->type() : static_cast<ConfigOptionType>(optptr->type() - coVectorType); const ConfigOptionType scalar_type = def->is_scalar() ? def->type : static_cast<ConfigOptionType>(def->type - coVectorType);
wxString type_str = scalar_type == coNone ? "none" : wxString type_str = scalar_type == coNone ? "none" :
scalar_type == coFloat ? "float" : scalar_type == coFloat ? "float" :
scalar_type == coInt ? "integer" : scalar_type == coInt ? "integer" :
@ -432,16 +282,16 @@ void EditGCodeDialog::bind_list_and_button()
scalar_type == coPoint ? "point" : scalar_type == coPoint ? "point" :
scalar_type == coBool ? "bool" : scalar_type == coBool ? "bool" :
scalar_type == coEnum ? "enum" : "undef"; scalar_type == coEnum ? "enum" : "undef";
if (!optptr->is_scalar()) if (!def->is_scalar())
type_str += "[]"; type_str += "[]";
label = (!cod || (cod->full_label.empty() && cod->label.empty()) ) ? format_wxstr("%1%\n(%2%)", opt_key, type_str) : label = (!def || (def->full_label.empty() && def->label.empty()) ) ? format_wxstr("%1%\n(%2%)", opt_key, type_str) :
(!cod->full_label.empty() && !cod->label.empty() ) ? (!def->full_label.empty() && !def->label.empty() ) ?
format_wxstr("%1% > %2%\n(%3%)", _(cod->full_label), _(cod->label), type_str) : format_wxstr("%1% > %2%\n(%3%)", _(def->full_label), _(def->label), type_str) :
format_wxstr("%1%\n(%2%)", cod->label.empty() ? _(cod->full_label) : _(cod->label), type_str); format_wxstr("%1%\n(%2%)", def->label.empty() ? _(def->full_label) : _(def->label), type_str);
if (cod) if (def)
description = _(cod->tooltip); description = _(def->tooltip);
} }
else else
label = "Undef optptr"; label = "Undef optptr";

View file

@ -9,6 +9,7 @@
#include "GUI_Utils.hpp" #include "GUI_Utils.hpp"
#include "wxExtensions.hpp" #include "wxExtensions.hpp"
#include "libslic3r/Preset.hpp" #include "libslic3r/Preset.hpp"
#include "libslic3r/PrintConfig.hpp"
class wxListBox; class wxListBox;
class wxTextCtrl; class wxTextCtrl;
@ -32,10 +33,14 @@ class EditGCodeDialog : public DPIDialog
wxStaticText* m_param_label {nullptr}; wxStaticText* m_param_label {nullptr};
wxStaticText* m_param_description {nullptr}; wxStaticText* m_param_description {nullptr};
DynamicConfig m_read_write_config; ReadOnlySlicingStatesConfigDef cgp_ro_slicing_states_config_def;
DynamicConfig m_universal_config; ReadWriteSlicingStatesConfigDef cgp_rw_slicing_states_config_def;
DynamicConfig m_specific_config; OtherSlicingStatesConfigDef cgp_other_slicing_states_config_def;
DynamicConfig m_print_statistics_config; PrintStatisticsConfigDef cgp_print_statistics_config_def;
ObjectsInfoConfigDef cgp_objects_info_config_def;
DimensionsConfigDef cgp_dimensions_config_def;
TimestampsConfigDef cgp_timestamps_config_def;
OtherPresetsConfigDef cgp_other_presets_config_def;
public: public:
EditGCodeDialog(wxWindow*parent, const std::string&key, const std::string&value); EditGCodeDialog(wxWindow*parent, const std::string&key, const std::string&value);