mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-07-28 20:22:04 +08:00
Editing of Custom G-code: Partially automation to get a list of placeholders for custom gcodes
+ Added missed resources
This commit is contained in:
parent
59af551941
commit
55d5921d53
4
resources/custom_gcodes/before_layer_gcode
Normal file
4
resources/custom_gcodes/before_layer_gcode
Normal file
@ -0,0 +1,4 @@
|
||||
# generated by PrusaSlicer 2.6.0-rc1 on 2023-06-15 at 13:29:08 UTC
|
||||
layer_num = 2
|
||||
layer_z = 1
|
||||
max_layer_z = 1
|
5
resources/custom_gcodes/end_filament_gcode
Normal file
5
resources/custom_gcodes/end_filament_gcode
Normal file
@ -0,0 +1,5 @@
|
||||
# generated by PrusaSlicer 2.6.0-rc1 on 2023-06-15 at 13:29:09 UTC
|
||||
filament_extruder_id = 2
|
||||
layer_num = 2
|
||||
layer_z = 1
|
||||
max_layer_z = 1
|
5
resources/custom_gcodes/end_gcode
Normal file
5
resources/custom_gcodes/end_gcode
Normal file
@ -0,0 +1,5 @@
|
||||
# generated by PrusaSlicer 2.6.0-rc1 on 2023-06-15 at 13:29:09 UTC
|
||||
filament_extruder_id = 2
|
||||
layer_num = 2
|
||||
layer_z = 1
|
||||
max_layer_z = 1
|
4
resources/custom_gcodes/layer_gcode
Normal file
4
resources/custom_gcodes/layer_gcode
Normal file
@ -0,0 +1,4 @@
|
||||
# generated by PrusaSlicer 2.6.0-rc1 on 2023-06-15 at 13:29:09 UTC
|
||||
layer_num = 2
|
||||
layer_z = 1
|
||||
max_layer_z = 1
|
4
resources/custom_gcodes/rw_slicing_state
Normal file
4
resources/custom_gcodes/rw_slicing_state
Normal file
@ -0,0 +1,4 @@
|
||||
# generated by PrusaSlicer 2.6.0-rc1 on 2023-06-15 at 13:29:09 UTC
|
||||
e_restart_extra = 16385
|
||||
e_retracted = 16385
|
||||
position = 16385
|
5
resources/custom_gcodes/start_filament_gcode
Normal file
5
resources/custom_gcodes/start_filament_gcode
Normal file
@ -0,0 +1,5 @@
|
||||
# generated by PrusaSlicer 2.6.0-rc1 on 2023-06-15 at 13:29:09 UTC
|
||||
filament_extruder_id = 2
|
||||
layer_num = 2
|
||||
layer_z = 1
|
||||
max_layer_z = 1
|
3
resources/custom_gcodes/tcr_rotated_gcode
Normal file
3
resources/custom_gcodes/tcr_rotated_gcode
Normal file
@ -0,0 +1,3 @@
|
||||
# generated by PrusaSlicer 2.6.0-rc1 on 2023-06-14 at 11:40:58 UTC
|
||||
deretraction_from_wipe_tower_generator = 3
|
||||
toolchange_gcode = 3
|
7
resources/custom_gcodes/toolchange_gcode
Normal file
7
resources/custom_gcodes/toolchange_gcode
Normal file
@ -0,0 +1,7 @@
|
||||
# generated by PrusaSlicer 2.6.0-rc1 on 2023-06-14 at 11:40:58 UTC
|
||||
layer_num = 2
|
||||
layer_z = 1
|
||||
max_layer_z = 1
|
||||
next_extruder = 2
|
||||
previous_extruder = 2
|
||||
toolchange_z = 1
|
39
resources/custom_gcodes/universal
Normal file
39
resources/custom_gcodes/universal
Normal file
@ -0,0 +1,39 @@
|
||||
# generated by PrusaSlicer 2.6.0-rc1 on 2023-06-15 at 13:29:09 UTC
|
||||
current_extruder = 2
|
||||
current_object_idx = 2
|
||||
day = 2
|
||||
extruded_volume = 16385
|
||||
extruded_volume_total = 1
|
||||
extruded_weight = 16385
|
||||
extruded_weight_total = 1
|
||||
filament_preset = 16387
|
||||
first_layer_print_convex_hull = 16390
|
||||
first_layer_print_max = 16385
|
||||
first_layer_print_min = 16385
|
||||
first_layer_print_size = 16385
|
||||
has_single_extruder_multi_material_priming = 8
|
||||
has_wipe_tower = 8
|
||||
hour = 2
|
||||
initial_extruder = 2
|
||||
initial_tool = 2
|
||||
input_filename = 3
|
||||
input_filename_base = 3
|
||||
is_extruder_used = 16392
|
||||
minute = 2
|
||||
month = 2
|
||||
num_extruders = 2
|
||||
num_instances = 2
|
||||
num_objects = 2
|
||||
physical_printer_preset = 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
|
||||
zhop = 1
|
21
resources/icons/scalar_param.svg
Normal file
21
resources/icons/scalar_param.svg
Normal file
@ -0,0 +1,21 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Generator: Adobe Illustrator 23.0.3, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
|
||||
<svg version="1.0" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
|
||||
viewBox="0 0 16 16" enable-background="new 0 0 16 16" xml:space="preserve">
|
||||
<g id="number_x5F_of_x5F_copies">
|
||||
<g>
|
||||
<path fill="#808080" d="M13,2c0.55,0,1,0.45,1,1V13c0,0.55-0.45,1-1,1H3c-0.55,0-1-0.45-1-1V3c0-0.55,0.45-1,1-1H13 M13,1H3
|
||||
c-1.1,0-2,0.89-2,2V13c0,1.1,0.89,2,2,2H13c1.1,0,2-0.89,2-2V3C15,1.89,14.11,1,13,1L13,1z"/>
|
||||
</g>
|
||||
<g>
|
||||
<path fill="#ED6B21" d="M6,4.5H4C3.72,4.5,3.5,4.28,3.5,4S3.72,3.5,4,3.5h2c0.28,0,0.5,0.22,0.5,0.5S6.28,4.5,6,4.5z"/>
|
||||
</g>
|
||||
<g>
|
||||
<path fill="#ED6B21" d="M6,12.5H4c-0.28,0-0.5-0.22-0.5-0.5s0.22-0.5,0.5-0.5h2c0.28,0,0.5,0.22,0.5,0.5S6.28,12.5,6,12.5z"/>
|
||||
</g>
|
||||
<g>
|
||||
<path fill="#ED6B21" d="M5,12.5c-0.28,0-0.5-0.22-0.5-0.5V4c0-0.28,0.22-0.5,0.5-0.5S5.5,3.72,5.5,4v8C5.5,12.28,5.28,12.5,5,12.5
|
||||
z"/>
|
||||
</g>
|
||||
</g>
|
||||
</svg>
|
After Width: | Height: | Size: 1.0 KiB |
28
resources/icons/vector_filament_param.svg
Normal file
28
resources/icons/vector_filament_param.svg
Normal file
@ -0,0 +1,28 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Generator: Adobe Illustrator 23.0.3, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
|
||||
<svg version="1.0" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
|
||||
viewBox="0 0 16 16" enable-background="new 0 0 16 16" xml:space="preserve">
|
||||
<g id="number_x5F_of_x5F_copies">
|
||||
<g>
|
||||
<path fill="#808080" d="M13,2c0.55,0,1,0.45,1,1V13c0,0.55-0.45,1-1,1H3c-0.55,0-1-0.45-1-1V3c0-0.55,0.45-1,1-1H13 M13,1H3
|
||||
c-1.1,0-2,0.89-2,2V13c0,1.1,0.89,2,2,2H13c1.1,0,2-0.89,2-2V3C15,1.89,14.11,1,13,1L13,1z"/>
|
||||
</g>
|
||||
<g>
|
||||
<path fill="#ED6B21" d="M6,4.5H4C3.72,4.5,3.5,4.28,3.5,4S3.72,3.5,4,3.5h2c0.28,0,0.5,0.22,0.5,0.5S6.28,4.5,6,4.5z"/>
|
||||
</g>
|
||||
<g>
|
||||
<path fill="#808080" d="M12,8.5H8C7.72,8.5,7.5,8.28,7.5,8S7.72,7.5,8,7.5h4c0.28,0,0.5,0.22,0.5,0.5S12.28,8.5,12,8.5z"/>
|
||||
</g>
|
||||
<g>
|
||||
<path fill="#ED6B21" d="M6,12.5H4c-0.28,0-0.5-0.22-0.5-0.5s0.22-0.5,0.5-0.5h2c0.28,0,0.5,0.22,0.5,0.5S6.28,12.5,6,12.5z"/>
|
||||
</g>
|
||||
<g>
|
||||
<path fill="#ED6B21" d="M5,12.5c-0.28,0-0.5-0.22-0.5-0.5V4c0-0.28,0.22-0.5,0.5-0.5S5.5,3.72,5.5,4v8C5.5,12.28,5.28,12.5,5,12.5
|
||||
z"/>
|
||||
</g>
|
||||
<g>
|
||||
<path fill="#808080" d="M10,10.5c-0.28,0-0.5-0.22-0.5-0.5V6c0-0.28,0.22-0.5,0.5-0.5s0.5,0.22,0.5,0.5v4
|
||||
C10.5,10.28,10.28,10.5,10,10.5z"/>
|
||||
</g>
|
||||
</g>
|
||||
</svg>
|
After Width: | Height: | Size: 1.3 KiB |
28
resources/icons/vector_param.svg
Normal file
28
resources/icons/vector_param.svg
Normal file
@ -0,0 +1,28 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Generator: Adobe Illustrator 23.0.3, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
|
||||
<svg version="1.0" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
|
||||
viewBox="0 0 16 16" enable-background="new 0 0 16 16" xml:space="preserve">
|
||||
<g id="number_x5F_of_x5F_copies">
|
||||
<g>
|
||||
<path fill="#808080" d="M13,2c0.55,0,1,0.45,1,1V13c0,0.55-0.45,1-1,1H3c-0.55,0-1-0.45-1-1V3c0-0.55,0.45-1,1-1H13 M13,1H3
|
||||
c-1.1,0-2,0.89-2,2V13c0,1.1,0.89,2,2,2H13c1.1,0,2-0.89,2-2V3C15,1.89,14.11,1,13,1L13,1z"/>
|
||||
</g>
|
||||
<g>
|
||||
<path fill="#ED6B21" d="M6,4.5H4C3.72,4.5,3.5,4.28,3.5,4S3.72,3.5,4,3.5h2c0.28,0,0.5,0.22,0.5,0.5S6.28,4.5,6,4.5z"/>
|
||||
</g>
|
||||
<g>
|
||||
<path fill="#ED6B21" d="M12,8.5H8C7.72,8.5,7.5,8.28,7.5,8S7.72,7.5,8,7.5h4c0.28,0,0.5,0.22,0.5,0.5S12.28,8.5,12,8.5z"/>
|
||||
</g>
|
||||
<g>
|
||||
<path fill="#ED6B21" d="M6,12.5H4c-0.28,0-0.5-0.22-0.5-0.5s0.22-0.5,0.5-0.5h2c0.28,0,0.5,0.22,0.5,0.5S6.28,12.5,6,12.5z"/>
|
||||
</g>
|
||||
<g>
|
||||
<path fill="#ED6B21" d="M5,12.5c-0.28,0-0.5-0.22-0.5-0.5V4c0-0.28,0.22-0.5,0.5-0.5S5.5,3.72,5.5,4v8C5.5,12.28,5.28,12.5,5,12.5
|
||||
z"/>
|
||||
</g>
|
||||
<g>
|
||||
<path fill="#ED6B21" d="M10,10.5c-0.28,0-0.5-0.22-0.5-0.5V6c0-0.28,0.22-0.5,0.5-0.5s0.5,0.22,0.5,0.5v4
|
||||
C10.5,10.28,10.28,10.5,10,10.5z"/>
|
||||
</g>
|
||||
</g>
|
||||
</svg>
|
After Width: | Height: | Size: 1.3 KiB |
@ -763,6 +763,7 @@ bool CLI::setup(int argc, char **argv)
|
||||
set_var_dir((path_resources / "icons").string());
|
||||
set_local_dir((path_resources / "localization").string());
|
||||
set_sys_shapes_dir((path_resources / "shapes").string());
|
||||
set_custom_gcodes_dir((path_resources / "custom_gcodes").string());
|
||||
|
||||
// Parse all command line options into a DynamicConfig.
|
||||
// If any option is unsupported, print usage and abort immediately.
|
||||
|
@ -1504,6 +1504,12 @@ std::string GCodeGenerator::placeholder_parser_process(
|
||||
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);
|
||||
|
@ -72,6 +72,8 @@ struct LayerResult {
|
||||
};
|
||||
|
||||
class GCodeGenerator {
|
||||
#define GET_CUSTOM_GCODE_PLACEHOLDERS 1
|
||||
|
||||
public:
|
||||
GCodeGenerator() :
|
||||
m_origin(Vec2d::Zero()),
|
||||
@ -97,6 +99,13 @@ public:
|
||||
{}
|
||||
~GCodeGenerator() = 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);
|
||||
|
@ -1014,6 +1014,46 @@ std::string Print::export_gcode(const std::string& path_template, GCodeProcessor
|
||||
std::unique_ptr<GCodeGenerator> gcode(new GCodeGenerator);
|
||||
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
|
||||
|
||||
if (m_conflict_result.has_value())
|
||||
result->conflict_result = *m_conflict_result;
|
||||
|
||||
|
@ -53,6 +53,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.
|
||||
|
@ -193,6 +193,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;
|
||||
|
||||
|
@ -20,30 +20,104 @@
|
||||
#include "MsgDialog.hpp"
|
||||
#include "Plater.hpp"
|
||||
|
||||
#include "libslic3r/PlaceholderParser.hpp"
|
||||
#include "libslic3r/Preset.hpp"
|
||||
#include "libslic3r/Print.hpp"
|
||||
|
||||
namespace Slic3r {
|
||||
namespace GUI {
|
||||
|
||||
static std::vector<std::string> get_specific_params(const std::string& custom_gcode)
|
||||
|
||||
ConfigOption* get_new_option(const ConfigOptionType type)
|
||||
{
|
||||
if (custom_gcode == "start_filament_gcode" || custom_gcode == "end_filament_gcode")
|
||||
return{ "max_layer_z",
|
||||
"layer_num",
|
||||
"layer_z",
|
||||
"filament_extruder_id" };
|
||||
if (custom_gcode == "end_gcode" || custom_gcode == "before_layer_gcode" || custom_gcode == "layer_gcode")
|
||||
return{ "max_layer_z",
|
||||
"layer_num",
|
||||
"layer_z" };
|
||||
if (custom_gcode == "toolchange_gcode")
|
||||
return{ "next_extruder",
|
||||
"previous_extruder",
|
||||
"toolchange_z",
|
||||
"max_layer_z",
|
||||
"layer_num",
|
||||
"layer_z" };
|
||||
return {};
|
||||
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()));
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------
|
||||
@ -120,97 +194,106 @@ std::string EditGCodeDialog::get_edited_gcode() const
|
||||
|
||||
void EditGCodeDialog::init_params_list(const std::string& custom_gcode_name)
|
||||
{
|
||||
wxDataViewItem group = m_params_list->AppendGroup(_L("Slicing State"), "re_slice");
|
||||
const std::vector<std::string> universal_params = get_params_from_file("universal", m_universal_config);
|
||||
|
||||
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
|
||||
|
||||
std::vector<std::string> read_only_opts = { "zhop" };
|
||||
wxDataViewItem group = m_params_list->AppendGroup(_L("Slicing State"), "re_slice");
|
||||
{
|
||||
wxDataViewItem read_only = m_params_list->AppendSubGroup(group, _L("Read Only"), "lock_closed");
|
||||
m_params_list->AppendParam(read_only, ParamType::Scalar, "zhop");
|
||||
}
|
||||
{
|
||||
wxDataViewItem read_write = m_params_list->AppendSubGroup(group, _L("Read Write"), "lock_open");
|
||||
for (const auto& opt_name : { "position", "e_position"})
|
||||
m_params_list->AppendParam(read_write, ParamType::Vector, opt_name);
|
||||
for (const auto& opt_name : { "e_retracted", "e_restart_extra"})
|
||||
m_params_list->AppendParam(read_write, ParamType::FilamentVector, opt_name);
|
||||
wxDataViewItem read_only = m_params_list->AppendSubGroup(group, _L("Read Only"), "lock_closed");
|
||||
for (const auto& opt_key : read_only_opts)
|
||||
m_params_list->AppendParam(read_only, get_type(opt_key, m_universal_config), opt_key);
|
||||
}
|
||||
|
||||
group = m_params_list->AppendGroup(_L("Universal"), "equal");
|
||||
{
|
||||
wxDataViewItem time_stamp = m_params_list->AppendSubGroup(group, _L("Time Stamp"), "time");
|
||||
for (const auto& opt_name : { "day",
|
||||
"hour",
|
||||
"minute",
|
||||
"month",
|
||||
"second",
|
||||
"year",
|
||||
"timestamp" })
|
||||
m_params_list->AppendParam(time_stamp, ParamType::Scalar, opt_name);
|
||||
|
||||
for (const auto& opt_name : { "current_extruder",
|
||||
"current_object_idx",
|
||||
"filament_preset",
|
||||
"first_layer_print_convex_hull",
|
||||
"first_layer_print_max",
|
||||
"first_layer_print_min",
|
||||
"first_layer_print_size",
|
||||
"has_single_extruder_multi_material_priming",
|
||||
"has_wipe_tower",
|
||||
"initial_extruder",
|
||||
"initial_tool",
|
||||
"input_filename",
|
||||
"input_filename_base",
|
||||
"is_extruder_used",
|
||||
"num_instances",
|
||||
"num_objects",
|
||||
"physical_printer_preset",
|
||||
"print_bed_max",
|
||||
"print_bed_min",
|
||||
"print_bed_size",
|
||||
"print_preset",
|
||||
"printer_preset",
|
||||
"scale",
|
||||
"total_layer_count",
|
||||
"total_toolchanges" })
|
||||
m_params_list->AppendParam(group, ParamType::Scalar, opt_name);
|
||||
const std::vector<std::string> read_write_params = get_params_from_file("rw_slicing_state", m_read_write_config);
|
||||
if (!read_write_params.empty()) {
|
||||
wxDataViewItem read_write = m_params_list->AppendSubGroup(group, _L("Read Write"), "lock_open");
|
||||
for (const auto& opt_key : read_write_params)
|
||||
m_params_list->AppendParam(read_write, get_type(opt_key, m_read_write_config), opt_key);
|
||||
}
|
||||
|
||||
std::vector<std::string> specific_params = get_specific_params(custom_gcode_name);
|
||||
// Add universal placeholders
|
||||
|
||||
if (!universal_params.empty()) {
|
||||
group = m_params_list->AppendGroup(_L("Universal"), "equal");
|
||||
|
||||
// Add print statistics subgroup
|
||||
|
||||
m_print_statistics_config = PrintStatistics::placeholders();
|
||||
if (!m_print_statistics_config.empty()) {
|
||||
wxDataViewItem statistics = m_params_list->AppendSubGroup(group, _L("Print Statistics"), "info");
|
||||
const std::vector<std::string> statistics_params = m_print_statistics_config.keys();
|
||||
for (const auto& opt_key : statistics_params)
|
||||
m_params_list->AppendParam(statistics, get_type(opt_key, m_print_statistics_config), opt_key);
|
||||
}
|
||||
|
||||
// Add timestamp subgroup
|
||||
|
||||
PlaceholderParser parser;
|
||||
parser.update_timestamp();
|
||||
const DynamicConfig& ts_config = parser.config();
|
||||
wxDataViewItem time_stamp = ts_config.empty() ? group : m_params_list->AppendSubGroup(group, _L("Timestamps"), "time");
|
||||
|
||||
// Add un-grouped params
|
||||
|
||||
wxDataViewItem other = m_params_list->AppendSubGroup(group, _L("Other"), "add_gcode");
|
||||
for (const auto& opt_key : universal_params) {
|
||||
if (m_print_statistics_config.has(opt_key) || std::find(read_only_opts.begin(), read_only_opts.end(), opt_key) != read_only_opts.end())
|
||||
continue;
|
||||
m_params_list->AppendParam( ts_config.has(opt_key) ? time_stamp : other, get_type(opt_key, m_universal_config), opt_key);
|
||||
}
|
||||
}
|
||||
|
||||
// Add specific placeholders
|
||||
|
||||
const std::vector<std::string> specific_params = get_params_from_file(custom_gcode_name, m_specific_config);
|
||||
if (!specific_params.empty()) {
|
||||
group = m_params_list->AppendGroup(format_wxstr(_L("Specific for %1%"), custom_gcode_name), "not_equal");
|
||||
for (const auto& opt_name : specific_params)
|
||||
m_params_list->AppendParam(group, ParamType::Scalar, opt_name);
|
||||
for (const auto& opt_key : specific_params)
|
||||
m_params_list->AppendParam(group, get_type(opt_key, m_specific_config), opt_key);
|
||||
|
||||
m_params_list->Expand(group);
|
||||
}
|
||||
|
||||
auto get_set_from_vec = [](const std::vector<std::string>& vec) {
|
||||
// Add placeholders from presets
|
||||
|
||||
add_presets_placeholders();
|
||||
}
|
||||
|
||||
void EditGCodeDialog::add_presets_placeholders()
|
||||
{
|
||||
auto get_set_from_vec = [](const std::vector<std::string>&vec) {
|
||||
return std::set<std::string>(vec.begin(), vec.end());
|
||||
};
|
||||
const bool is_fff = wxGetApp().plater()->printer_technology() == ptFFF;
|
||||
|
||||
const bool is_fff = wxGetApp().plater()->printer_technology() == ptFFF;
|
||||
const std::set<std::string> print_options = get_set_from_vec(is_fff ? Preset::print_options() : Preset::sla_print_options());
|
||||
const std::set<std::string> material_options = get_set_from_vec(is_fff ? Preset::filament_options() : Preset::sla_material_options());
|
||||
const std::set<std::string> printer_options = get_set_from_vec(is_fff ? Preset::printer_options() : Preset::sla_printer_options());
|
||||
|
||||
const auto& full_config = wxGetApp().preset_bundle->full_config();
|
||||
const auto&full_config = wxGetApp().preset_bundle->full_config();
|
||||
|
||||
const auto& def = full_config.def()->get("")->label;
|
||||
wxDataViewItem group = m_params_list->AppendGroup(_L("Presets"), "cog");
|
||||
|
||||
wxDataViewItem print = m_params_list->AppendSubGroup(group, _L("Print settings"), "cog");
|
||||
for (const auto&opt : print_options)
|
||||
if (const ConfigOption *optptr = full_config.optptr(opt))
|
||||
m_params_list->AppendParam(print, optptr->is_scalar() ? ParamType::Scalar : ParamType::Vector, opt);
|
||||
|
||||
wxDataViewItem material = m_params_list->AppendSubGroup(group, _(is_fff ? L("Filament settings") : L("SLA Materials settings")), is_fff ? "spool" : "resin");
|
||||
for (const auto&opt : material_options)
|
||||
if (const ConfigOption *optptr = full_config.optptr(opt))
|
||||
m_params_list->AppendParam(material, optptr->is_scalar() ? ParamType::Scalar : ParamType::FilamentVector, opt);
|
||||
|
||||
group = m_params_list->AppendGroup(_L("Presets"), "cog");
|
||||
{
|
||||
wxDataViewItem print = m_params_list->AppendSubGroup(group, _L("Print settings"), "cog");
|
||||
for (const auto& opt : print_options)
|
||||
if (const ConfigOption *optptr = full_config.optptr(opt))
|
||||
m_params_list->AppendParam(print, optptr->is_scalar() ? ParamType::Scalar : ParamType::Vector, opt);
|
||||
|
||||
wxDataViewItem material = m_params_list->AppendSubGroup(group, _(is_fff ? L("Filament settings") : L("SLA Materials settings")), is_fff ? "spool" : "resin");
|
||||
for (const auto& opt : material_options)
|
||||
if (const ConfigOption *optptr = full_config.optptr(opt))
|
||||
m_params_list->AppendParam(material, optptr->is_scalar() ? ParamType::Scalar : ParamType::FilamentVector, opt);
|
||||
|
||||
wxDataViewItem printer = m_params_list->AppendSubGroup(group, _L("Printer settings"), is_fff ? "printer" : "sla_printer");
|
||||
for (const auto& opt : printer_options)
|
||||
if (const ConfigOption *optptr = full_config.optptr(opt))
|
||||
m_params_list->AppendParam(printer, optptr->is_scalar() ? ParamType::Scalar : ParamType::Vector, opt);
|
||||
|
||||
}
|
||||
wxDataViewItem printer = m_params_list->AppendSubGroup(group, _L("Printer settings"), is_fff ? "printer" : "sla_printer");
|
||||
for (const auto&opt : printer_options)
|
||||
if (const ConfigOption *optptr = full_config.optptr(opt))
|
||||
m_params_list->AppendParam(printer, optptr->is_scalar() ? ParamType::Scalar : ParamType::Vector, opt);
|
||||
}
|
||||
|
||||
void EditGCodeDialog::add_selected_value_to_gcode()
|
||||
@ -227,28 +310,43 @@ void EditGCodeDialog::bind_list_and_button()
|
||||
|
||||
const std::string opt_key = m_params_list->GetSelectedParamKey();
|
||||
if (!opt_key.empty()) {
|
||||
const ConfigOptionDef* cod { nullptr };
|
||||
const ConfigOption* optptr { nullptr };
|
||||
|
||||
const auto& full_config = wxGetApp().preset_bundle->full_config();
|
||||
if (const ConfigDef* def = full_config.def();
|
||||
def && def->has(opt_key)) {
|
||||
const ConfigOptionDef* cod = def->get(opt_key);
|
||||
const ConfigOption* optptr = full_config.optptr(opt_key);
|
||||
const ConfigOptionType type = optptr->type();
|
||||
if (const ConfigDef* def = full_config.def(); def && def->has(opt_key)) {
|
||||
cod = def->get(opt_key);
|
||||
optptr = full_config.optptr(opt_key);
|
||||
}
|
||||
else {
|
||||
for (const DynamicConfig* config: { &m_read_write_config, &m_universal_config, &m_specific_config, &m_print_statistics_config }) {
|
||||
optptr = config->optptr(opt_key);
|
||||
if (optptr)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
wxString type_str = type == coNone ? "none" :
|
||||
type == coFloat || type == coFloats ? "float" :
|
||||
type == coInt || type == coInts ? "integer" :
|
||||
type == coString || type == coStrings ? "string" :
|
||||
type == coPercent || type == coPercents ? "percent" :
|
||||
type == coFloatOrPercent || type == coFloatsOrPercents ? "float ar percent" :
|
||||
type == coPoint || type == coPoints || type == coPoint3 ? "point" :
|
||||
type == coBool || type == coBools ? "bool" :
|
||||
type == coEnum ? "enum" : "undef";
|
||||
if (optptr) {
|
||||
const ConfigOptionType scalar_type = optptr->is_scalar() ? optptr->type() : static_cast<ConfigOptionType>(optptr->type() - coVectorType);
|
||||
wxString type_str = scalar_type == coNone ? "none" :
|
||||
scalar_type == coFloat ? "float" :
|
||||
scalar_type == coInt ? "integer" :
|
||||
scalar_type == coString ? "string" :
|
||||
scalar_type == coPercent ? "percent" :
|
||||
scalar_type == coFloatOrPercent ? "float or percent" :
|
||||
scalar_type == coPoint ? "point" :
|
||||
scalar_type == coBool ? "bool" :
|
||||
scalar_type == coEnum ? "enum" : "undef";
|
||||
if (!optptr->is_scalar())
|
||||
type_str += "[]";
|
||||
|
||||
label = ( cod->full_label.empty() && cod->label.empty() ) ? format_wxstr("Undef Label\n(%1%)", type_str) :
|
||||
label = (!cod || (cod->full_label.empty() && cod->label.empty()) ) ? format_wxstr("%1%\n(%2%)", opt_key, type_str) :
|
||||
(!cod->full_label.empty() && !cod->label.empty() ) ?
|
||||
format_wxstr("%1% > %2%\n(%3%)", _(cod->full_label), _(cod->label), type_str) :
|
||||
format_wxstr("%1%\n(%2%)", cod->label.empty() ? _(cod->full_label) : _(cod->label), type_str);
|
||||
}
|
||||
else
|
||||
label = "Undef optptr";
|
||||
}
|
||||
|
||||
m_param_label->SetLabel(label);
|
||||
@ -461,7 +559,7 @@ void ParamsModel::GetValue(wxVariant& variant, const wxDataViewItem& item, unsig
|
||||
assert(item.IsOk());
|
||||
|
||||
ParamsNode* node = static_cast<ParamsNode*>(item.GetID());
|
||||
if (col == unsigned int(0))
|
||||
if (col == (unsigned int)0)
|
||||
#ifdef __linux__
|
||||
variant << wxDataViewIconText(node->text, get_bmp_bundle(node->icon_name)->GetIconFor(m_ctrl->GetParent()));
|
||||
#else
|
||||
@ -476,11 +574,11 @@ bool ParamsModel::SetValue(const wxVariant& variant, const wxDataViewItem& item,
|
||||
assert(item.IsOk());
|
||||
|
||||
ParamsNode* node = static_cast<ParamsNode*>(item.GetID());
|
||||
if (col == unsigned int(0)) {
|
||||
if (col == (unsigned int)0) {
|
||||
#ifdef __linux__
|
||||
wxDataViewIconText data;
|
||||
data << variant;
|
||||
node->m_icon = data.GetIcon();
|
||||
node->icon = data.GetIcon();
|
||||
#else
|
||||
DataViewBitmapText data;
|
||||
data << variant;
|
||||
@ -559,7 +657,7 @@ ParamsViewCtrl::ParamsViewCtrl(wxWindow *parent, wxSize size)
|
||||
#ifdef SUPPORTS_MARKUP
|
||||
rd->EnableMarkup(true);
|
||||
#endif
|
||||
wxDataViewColumn* column = new wxDataViewColumn("", rd, 0, width * m_em_unit, wxALIGN_TOP, wxDATAVIEW_COL_RESIZABLE | wxDATAVIEW_CELL_INERT);
|
||||
wxDataViewColumn* column = new wxDataViewColumn("", rd, 0, 20 * m_em_unit, wxALIGN_TOP, wxDATAVIEW_COL_RESIZABLE | wxDATAVIEW_CELL_INERT);
|
||||
#else
|
||||
wxDataViewColumn* column = new wxDataViewColumn("", new BitmapTextRenderer(true, wxDATAVIEW_CELL_INERT), 0, 20 * m_em_unit, wxALIGN_TOP, wxDATAVIEW_COL_RESIZABLE);
|
||||
#endif //__linux__
|
||||
|
@ -30,6 +30,11 @@ class EditGCodeDialog : public DPIDialog
|
||||
wxTextCtrl* m_gcode_editor {nullptr};
|
||||
wxStaticText* m_param_label {nullptr};
|
||||
|
||||
DynamicConfig m_read_write_config;
|
||||
DynamicConfig m_universal_config;
|
||||
DynamicConfig m_specific_config;
|
||||
DynamicConfig m_print_statistics_config;
|
||||
|
||||
public:
|
||||
EditGCodeDialog(wxWindow*parent, const std::string&key, const std::string&value);
|
||||
~EditGCodeDialog() {}
|
||||
@ -37,6 +42,8 @@ public:
|
||||
std::string get_edited_gcode() const;
|
||||
|
||||
void init_params_list(const std::string& custom_gcode_name);
|
||||
void add_presets_placeholders();
|
||||
|
||||
void add_selected_value_to_gcode();
|
||||
void bind_list_and_button();
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user