This commit is contained in:
enricoturri1966 2020-06-11 16:09:22 +02:00
commit 9566a05d8f
28 changed files with 514 additions and 365 deletions

View File

@ -107,7 +107,7 @@ namespace ImGui
const char ColorMarkerStart = 0x2; // STX
const char ColorMarkerEnd = 0x3; // ETX
// Special ASCII characters are used here as a ikons markers
// Special ASCII characters are used here as an ikons markers
const char PrintIconMarker = 0x4;
const char PrinterIconMarker = 0x5;
const char PrinterSlaIconMarker = 0x6;

View File

@ -23,7 +23,7 @@ extern void update_custom_gcode_per_print_z_from_config(Info& info, DynamicPrint
info.gcodes.reserve(colorprint_values.size());
int i = 0;
for (auto val : colorprint_values)
info.gcodes.emplace_back(Item{ val, ColorChangeCode, 1, colors[(++i)%7] });
info.gcodes.emplace_back(Item{ val, ColorChange, 1, colors[(++i)%7] });
info.mode = SingleExtruder;
}
@ -43,11 +43,11 @@ extern void check_mode_for_custom_gcode_per_print_z(Info& info)
bool is_single_extruder = true;
for (auto item : info.gcodes)
{
if (item.gcode == ToolChangeCode) {
if (item.type == ToolChange) {
info.mode = MultiAsSingle;
return;
}
if (item.gcode == ColorChangeCode && item.extruder > 1)
if (item.type == ColorChange && item.extruder > 1)
is_single_extruder = false;
}
@ -60,7 +60,7 @@ std::vector<std::pair<double, unsigned int>> custom_tool_changes(const Info& cus
{
std::vector<std::pair<double, unsigned int>> custom_tool_changes;
for (const Item& custom_gcode : custom_gcode_per_print_z.gcodes)
if (custom_gcode.gcode == ToolChangeCode) {
if (custom_gcode.type == ToolChange) {
// If extruder count in PrinterSettings was changed, use default (0) extruder for extruders, more than num_extruders
assert(custom_gcode.extruder >= 0);
custom_tool_changes.emplace_back(custom_gcode.print_z, static_cast<unsigned int>(size_t(custom_gcode.extruder) > num_extruders ? 1 : custom_gcode.extruder));

View File

@ -8,38 +8,40 @@ namespace Slic3r {
class DynamicPrintConfig;
// Additional Codes which can be set by user using DoubleSlider
static constexpr char ColorChangeCode[] = "M600";
static constexpr char PausePrintCode[] = "M601";
static constexpr char ToolChangeCode[] = "tool_change";
enum CustomGcodeType
{
cgtColorChange,
cgtPausePrint,
};
namespace CustomGCode {
enum Type
{
ColorChange,
PausePrint,
ToolChange,
Template,
Custom
};
struct Item
{
bool operator<(const Item& rhs) const { return this->print_z < rhs.print_z; }
bool operator==(const Item& rhs) const
{
return (rhs.print_z == this->print_z ) &&
(rhs.gcode == this->gcode ) &&
(rhs.type == this->type ) &&
(rhs.extruder == this->extruder ) &&
(rhs.color == this->color );
(rhs.color == this->color ) &&
(rhs.extra == this->extra );
}
bool operator!=(const Item& rhs) const { return ! (*this == rhs); }
double print_z;
std::string gcode;
Type type;
int extruder; // Informative value for ColorChangeCode and ToolChangeCode
// "gcode" == ColorChangeCode => M600 will be applied for "extruder" extruder
// "gcode" == ToolChangeCode => for whole print tool will be switched to "extruder" extruder
std::string color; // if gcode is equal to PausePrintCode,
// this field is used for save a short message shown on Printer display
std::string extra; // this field is used for the extra data like :
// - G-code text for the Type::Custom
// - message text for the Type::PausePrint
};
enum Mode

View File

@ -1197,13 +1197,32 @@ namespace Slic3r {
}
if (code.first != "code")
continue;
pt::ptree tree = code.second;
double print_z = tree.get<double> ("<xmlattr>.print_z" );
std::string gcode = tree.get<std::string> ("<xmlattr>.gcode" );
int extruder = tree.get<int> ("<xmlattr>.extruder" );
std::string color = tree.get<std::string> ("<xmlattr>.color" );
m_model->custom_gcode_per_print_z.gcodes.push_back(CustomGCode::Item{print_z, gcode, extruder, color}) ;
pt::ptree tree = code.second;
double print_z = tree.get<double> ("<xmlattr>.print_z" );
int extruder = tree.get<int> ("<xmlattr>.extruder");
std::string color = tree.get<std::string> ("<xmlattr>.color" );
CustomGCode::Type type;
std::string extra;
if (tree.find("type") == tree.not_found())
{
// It means that data was saved in old version (2.2.0 and older) of PrusaSlicer
// read old data ...
std::string gcode = tree.get<std::string> ("<xmlattr>.gcode");
// ... and interpret them to the new data
type = gcode == "M600" ? CustomGCode::ColorChange :
gcode == "M601" ? CustomGCode::PausePrint :
gcode == "tool_change" ? CustomGCode::ToolChange : CustomGCode::Custom;
extra = type == CustomGCode::PausePrint ? color :
type == CustomGCode::Custom ? gcode : "";
}
else
{
type = static_cast<CustomGCode::Type>(tree.get<int>("<xmlattr>.type"));
extra = tree.get<std::string>("<xmlattr>.extra");
}
m_model->custom_gcode_per_print_z.gcodes.push_back(CustomGCode::Item{print_z, type, extruder, color, extra}) ;
}
}
}
@ -1982,7 +2001,7 @@ namespace Slic3r {
bool _add_sla_drain_holes_file_to_archive(mz_zip_archive& archive, Model& model);
bool _add_print_config_file_to_archive(mz_zip_archive& archive, const DynamicPrintConfig &config);
bool _add_model_config_file_to_archive(mz_zip_archive& archive, const Model& model, const IdToObjectDataMap &objects_data);
bool _add_custom_gcode_per_print_z_file_to_archive(mz_zip_archive& archive, Model& model);
bool _add_custom_gcode_per_print_z_file_to_archive(mz_zip_archive& archive, Model& model, const DynamicPrintConfig* config);
};
bool _3MF_Exporter::save_model_to_file(const std::string& filename, Model& model, const DynamicPrintConfig* config, bool fullpath_sources, const ThumbnailData* thumbnail_data)
@ -2082,7 +2101,7 @@ namespace Slic3r {
// Adds custom gcode per height file ("Metadata/Prusa_Slicer_custom_gcode_per_print_z.xml").
// All custom gcode per height of whole Model are stored here
if (!_add_custom_gcode_per_print_z_file_to_archive(archive, model))
if (!_add_custom_gcode_per_print_z_file_to_archive(archive, model, config))
{
close_zip_writer(&archive);
boost::filesystem::remove(filename);
@ -2702,7 +2721,7 @@ namespace Slic3r {
return true;
}
bool _3MF_Exporter::_add_custom_gcode_per_print_z_file_to_archive( mz_zip_archive& archive, Model& model)
bool _3MF_Exporter::_add_custom_gcode_per_print_z_file_to_archive( mz_zip_archive& archive, Model& model, const DynamicPrintConfig* config)
{
std::string out = "";
@ -2714,11 +2733,20 @@ bool _3MF_Exporter::_add_custom_gcode_per_print_z_file_to_archive( mz_zip_archiv
for (const CustomGCode::Item& code : model.custom_gcode_per_print_z.gcodes)
{
pt::ptree& code_tree = main_tree.add("code", "");
// store minX and maxZ
// store data of custom_gcode_per_print_z
code_tree.put("<xmlattr>.print_z" , code.print_z );
code_tree.put("<xmlattr>.gcode" , code.gcode );
code_tree.put("<xmlattr>.type" , static_cast<int>(code.type));
code_tree.put("<xmlattr>.extruder" , code.extruder );
code_tree.put("<xmlattr>.color" , code.color );
code_tree.put("<xmlattr>.extra" , code.extra );
// add gcode field data for the old version of the PrusaSlicer
std::string gcode = code.type == CustomGCode::ColorChange ? config->opt_string("color_change_gcode") :
code.type == CustomGCode::PausePrint ? config->opt_string("pause_print_gcode") :
code.type == CustomGCode::Template ? config->opt_string("template_custom_gcode") :
code.type == CustomGCode::ToolChange ? "tool_change" : code.extra;
code_tree.put("<xmlattr>.gcode" , gcode );
}
pt::ptree& mode_tree = main_tree.add("mode", "");

View File

@ -240,7 +240,7 @@ struct AMFParserContext
// Current instance allocated for an amf/constellation/instance subtree.
Instance *m_instance;
// Generic string buffer for vertices, face indices, metadata etc.
std::string m_value[4];
std::string m_value[5];
// Pointer to config to update if config data are stored inside the amf file
DynamicPrintConfig *m_config;
@ -314,9 +314,26 @@ void AMFParserContext::startElement(const char *name, const char **atts)
if (strcmp(name, "code") == 0) {
node_type_new = NODE_TYPE_GCODE_PER_HEIGHT;
m_value[0] = get_attribute(atts, "print_z");
m_value[1] = get_attribute(atts, "gcode");
m_value[2] = get_attribute(atts, "extruder");
m_value[3] = get_attribute(atts, "color");
m_value[1] = get_attribute(atts, "extruder");
m_value[2] = get_attribute(atts, "color");
if (get_attribute(atts, "type"))
{
m_value[3] = get_attribute(atts, "type");
m_value[4] = get_attribute(atts, "extra");
}
else
{
// It means that data was saved in old version (2.2.0 and older) of PrusaSlicer
// read old data ...
std::string gcode = get_attribute(atts, "gcode");
// ... and interpret them to the new data
CustomGCode::Type type= gcode == "M600" ? CustomGCode::ColorChange :
gcode == "M601" ? CustomGCode::PausePrint :
gcode == "tool_change" ? CustomGCode::ToolChange : CustomGCode::Custom;
m_value[3] = std::to_string(static_cast<int>(type));
m_value[4] = type == CustomGCode::PausePrint ? m_value[2] :
type == CustomGCode::Custom ? gcode : "";
}
}
else if (strcmp(name, "mode") == 0) {
node_type_new = NODE_TYPE_CUSTOM_GCODE_MODE;
@ -640,12 +657,13 @@ void AMFParserContext::endElement(const char * /* name */)
break;
case NODE_TYPE_GCODE_PER_HEIGHT: {
double print_z = double(atof(m_value[0].c_str()));
const std::string& gcode = m_value[1];
int extruder = atoi(m_value[2].c_str());
const std::string& color = m_value[3];
double print_z = double(atof(m_value[0].c_str()));
int extruder = atoi(m_value[1].c_str());
const std::string& color= m_value[2];
CustomGCode::Type type = static_cast<CustomGCode::Type>(atoi(m_value[3].c_str()));
const std::string& extra= m_value[4];
m_model.custom_gcode_per_print_z.gcodes.push_back(CustomGCode::Item{print_z, gcode, extruder, color});
m_model.custom_gcode_per_print_z.gcodes.push_back(CustomGCode::Item{print_z, type, extruder, color, extra});
for (std::string& val: m_value)
val.clear();
@ -1253,9 +1271,17 @@ bool store_amf(const char* path, Model* model, const DynamicPrintConfig* config,
pt::ptree& code_tree = main_tree.add("code", "");
// store custom_gcode_per_print_z gcodes information
code_tree.put("<xmlattr>.print_z" , code.print_z );
code_tree.put("<xmlattr>.gcode" , code.gcode );
code_tree.put("<xmlattr>.type" , static_cast<int>(code.type));
code_tree.put("<xmlattr>.extruder" , code.extruder );
code_tree.put("<xmlattr>.color" , code.color );
code_tree.put("<xmlattr>.extra" , code.extra );
// add gcode field data for the old version of the PrusaSlicer
std::string gcode = code.type == CustomGCode::ColorChange ? config->opt_string("color_change_gcode") :
code.type == CustomGCode::PausePrint ? config->opt_string("pause_print_gcode") :
code.type == CustomGCode::Template ? config->opt_string("template_custom_gcode") :
code.type == CustomGCode::ToolChange ? "tool_change" : code.extra;
code_tree.put("<xmlattr>.gcode" , gcode );
}
pt::ptree& mode_tree = main_tree.add("mode", "");

View File

@ -1778,17 +1778,18 @@ namespace ProcessLayer
const CustomGCode::Item *custom_gcode,
// ID of the first extruder printing this layer.
unsigned int first_extruder_id,
bool single_extruder_printer)
const PrintConfig &config)
{
std::string gcode;
bool single_extruder_printer = config.nozzle_diameter.size() == 1;
if (custom_gcode != nullptr) {
// Extruder switches are processed by LayerTools, they should be filtered out.
assert(custom_gcode->gcode != ToolChangeCode);
assert(custom_gcode->type != CustomGCode::ToolChange);
const std::string &custom_code = custom_gcode->gcode;
bool color_change = custom_code == ColorChangeCode;
bool tool_change = custom_code == ToolChangeCode;
CustomGCode::Type gcode_type = custom_gcode->type;
bool color_change = gcode_type == CustomGCode::ColorChange;
bool tool_change = gcode_type == CustomGCode::ToolChange;
// Tool Change is applied as Color Change for a single extruder printer only.
assert(! tool_change || single_extruder_printer);
@ -1796,8 +1797,8 @@ namespace ProcessLayer
int m600_extruder_before_layer = -1;
if (color_change && custom_gcode->extruder > 0)
m600_extruder_before_layer = custom_gcode->extruder - 1;
else if (custom_code == PausePrintCode)
pause_print_msg = custom_gcode->color;
else if (gcode_type == CustomGCode::PausePrint)
pause_print_msg = custom_gcode->extra;
// we should add or not colorprint_change in respect to nozzle_diameter count instead of really used extruders count
if (color_change || tool_change)
@ -1813,17 +1814,18 @@ namespace ProcessLayer
// && !MMU1
) {
//! FIXME_in_fw show message during print pause
gcode += "M601\n"; // pause print
gcode += config.pause_print_gcode;// pause print
gcode += "\n";
gcode += "M117 Change filament for Extruder " + std::to_string(m600_extruder_before_layer) + "\n";
}
else {
gcode += ColorChangeCode;
gcode += config.color_change_gcode;//ColorChangeCode;
gcode += "\n";
}
}
else
{
if (custom_code == PausePrintCode) // Pause print
if (gcode_type == CustomGCode::PausePrint) // Pause print
{
// add tag for analyzer
gcode += "; " + GCodeAnalyzer::Pause_Print_Tag + "\n";
@ -1832,15 +1834,21 @@ namespace ProcessLayer
gcode += "M117 " + pause_print_msg + "\n";
// add tag for time estimator
gcode += "; " + GCodeTimeEstimator::Pause_Print_Tag + "\n";
gcode += config.pause_print_gcode;
}
else // custom Gcode
else
{
// add tag for analyzer
gcode += "; " + GCodeAnalyzer::Custom_Code_Tag + "\n";
// add tag for time estimator
//gcode += "; " + GCodeTimeEstimator::Custom_Code_Tag + "\n";
if (gcode_type == CustomGCode::Template) // Template Cistom Gcode
gcode += config.template_custom_gcode;
else // custom Gcode
gcode += custom_gcode->extra;
}
gcode += custom_code + "\n";
gcode += "\n";
}
}
@ -2017,7 +2025,7 @@ void GCode::process_layer(
if (single_object_instance_idx == size_t(-1)) {
// Normal (non-sequential) print.
gcode += ProcessLayer::emit_custom_gcode_per_print_z(layer_tools.custom_gcode, first_extruder_id, print.config().nozzle_diameter.size() == 1);
gcode += ProcessLayer::emit_custom_gcode_per_print_z(layer_tools.custom_gcode, first_extruder_id, print.config());
}
// Extrude skirt at the print_z of the raft layers and normal object layers
// not at the print_z of the interlaced support material layers.

View File

@ -492,7 +492,7 @@ void ToolOrdering::assign_custom_gcodes(const Print &print)
for (unsigned int i : lt.extruders)
extruder_printing_above[i] = true;
// Skip all custom G-codes above this layer and skip all extruder switches.
for (; custom_gcode_it != custom_gcode_per_print_z.gcodes.rend() && (custom_gcode_it->print_z > lt.print_z + EPSILON || custom_gcode_it->gcode == ToolChangeCode); ++ custom_gcode_it);
for (; custom_gcode_it != custom_gcode_per_print_z.gcodes.rend() && (custom_gcode_it->print_z > lt.print_z + EPSILON || custom_gcode_it->type == CustomGCode::ToolChange); ++ custom_gcode_it);
if (custom_gcode_it == custom_gcode_per_print_z.gcodes.rend())
// Custom G-codes were processed.
break;
@ -504,8 +504,8 @@ void ToolOrdering::assign_custom_gcodes(const Print &print)
print_z_below = it_lt_below->print_z;
if (custom_gcode.print_z > print_z_below + 0.5 * EPSILON) {
// The custom G-code applies to the current layer.
bool color_change = custom_gcode.gcode == ColorChangeCode;
bool tool_change = custom_gcode.gcode == ToolChangeCode;
bool color_change = custom_gcode.type == CustomGCode::ColorChange;
bool tool_change = custom_gcode.type == CustomGCode::ToolChange;
bool pause_or_custom_gcode = ! color_change && ! tool_change;
bool apply_color_change = ! ignore_tool_and_color_changes &&
// If it is color change, it will actually be useful as the exturder above will print.

View File

@ -188,7 +188,7 @@ namespace Slic3r {
_calculate_time(0);
if (m_needs_custom_gcode_times && (m_custom_gcode_time_cache != 0.0f))
m_custom_gcode_times.push_back({ cgtColorChange, m_custom_gcode_time_cache });
m_custom_gcode_times.push_back({CustomGCode::ColorChange, m_custom_gcode_time_cache });
#if ENABLE_MOVE_STATS
_log_moves_stats();
@ -678,7 +678,7 @@ namespace Slic3r {
return _get_time_minutes(get_time());
}
std::vector<std::pair<CustomGcodeType, float>> GCodeTimeEstimator::get_custom_gcode_times() const
std::vector<std::pair<CustomGCode::Type, float>> GCodeTimeEstimator::get_custom_gcode_times() const
{
return m_custom_gcode_times;
}
@ -722,9 +722,9 @@ namespace Slic3r {
return ret;
}
std::vector<std::pair<CustomGcodeType, std::string>> GCodeTimeEstimator::get_custom_gcode_times_dhm(bool include_remaining) const
std::vector<std::pair<CustomGCode::Type, std::string>> GCodeTimeEstimator::get_custom_gcode_times_dhm(bool include_remaining) const
{
std::vector<std::pair<CustomGcodeType, std::string>> ret;
std::vector<std::pair<CustomGCode::Type, std::string>> ret;
float total_time = 0.0f;
for (auto t : m_custom_gcode_times)
@ -1470,7 +1470,7 @@ namespace Slic3r {
size_t pos = comment.find(Color_Change_Tag);
if (pos != comment.npos)
{
_process_custom_gcode_tag(cgtColorChange);
_process_custom_gcode_tag(CustomGCode::ColorChange);
return true;
}
@ -1478,14 +1478,14 @@ namespace Slic3r {
pos = comment.find(Pause_Print_Tag);
if (pos != comment.npos)
{
_process_custom_gcode_tag(cgtPausePrint);
_process_custom_gcode_tag(CustomGCode::PausePrint);
return true;
}
return false;
}
void GCodeTimeEstimator::_process_custom_gcode_tag(CustomGcodeType code)
void GCodeTimeEstimator::_process_custom_gcode_tag(CustomGCode::Type code)
{
PROFILE_FUNC();
m_needs_custom_gcode_times = true;

View File

@ -234,7 +234,7 @@ namespace Slic3r {
// data to calculate custom code times
bool m_needs_custom_gcode_times;
std::vector<std::pair<CustomGcodeType, float>> m_custom_gcode_times;
std::vector<std::pair<CustomGCode::Type, float>> m_custom_gcode_times;
float m_custom_gcode_time_cache;
#if ENABLE_MOVE_STATS
@ -358,7 +358,7 @@ namespace Slic3r {
std::string get_time_minutes() const;
// Returns the estimated time, in seconds, for each custom gcode
std::vector<std::pair<CustomGcodeType, float>> get_custom_gcode_times() const;
std::vector<std::pair<CustomGCode::Type, float>> get_custom_gcode_times() const;
// Returns the estimated time, in format DDd HHh MMm SSs, for each color
// If include_remaining==true the strings will be formatted as: "time for color (remaining time at color start)"
@ -370,7 +370,7 @@ namespace Slic3r {
// Returns the estimated time, in format DDd HHh MMm, for each custom_gcode
// If include_remaining==true the strings will be formatted as: "time for custom_gcode (remaining time at color start)"
std::vector<std::pair<CustomGcodeType, std::string>> get_custom_gcode_times_dhm(bool include_remaining) const;
std::vector<std::pair<CustomGCode::Type, std::string>> get_custom_gcode_times_dhm(bool include_remaining) const;
// Return an estimate of the memory consumed by the time estimator.
size_t memory_used() const;
@ -453,7 +453,7 @@ namespace Slic3r {
bool _process_tags(const GCodeReader::GCodeLine& line);
// Processes ColorChangeTag and PausePrintTag
void _process_custom_gcode_tag(CustomGcodeType code);
void _process_custom_gcode_tag(CustomGCode::Type code);
// Simulates firmware st_synchronize() call
void _simulate_st_synchronize(float additional_time);

View File

@ -499,12 +499,12 @@ static bool custom_per_printz_gcodes_tool_changes_differ(const std::vector<Custo
auto it_a = va.begin();
auto it_b = vb.begin();
while (it_a != va.end() || it_b != vb.end()) {
if (it_a != va.end() && it_a->gcode != ToolChangeCode) {
if (it_a != va.end() && it_a->type != CustomGCode::ToolChange) {
// Skip any CustomGCode items, which are not tool changes.
++ it_a;
continue;
}
if (it_b != vb.end() && it_b->gcode != ToolChangeCode) {
if (it_b != vb.end() && it_b->type != CustomGCode::ToolChange) {
// Skip any CustomGCode items, which are not tool changes.
++ it_b;
continue;
@ -512,8 +512,8 @@ static bool custom_per_printz_gcodes_tool_changes_differ(const std::vector<Custo
if (it_a == va.end() || it_b == vb.end())
// va or vb contains more Tool Changes than the other.
return true;
assert(it_a->gcode == ToolChangeCode);
assert(it_b->gcode == ToolChangeCode);
assert(it_a->type == CustomGCode::ToolChange);
assert(it_b->type == CustomGCode::ToolChange);
if (*it_a != *it_b)
// The two Tool Changes differ.
return true;

View File

@ -300,8 +300,8 @@ struct PrintStatistics
PrintStatistics() { clear(); }
std::string estimated_normal_print_time;
std::string estimated_silent_print_time;
std::vector<std::pair<CustomGcodeType, std::string>> estimated_normal_custom_gcode_print_times;
std::vector<std::pair<CustomGcodeType, std::string>> estimated_silent_custom_gcode_print_times;
std::vector<std::pair<CustomGCode::Type, std::string>> estimated_normal_custom_gcode_print_times;
std::vector<std::pair<CustomGCode::Type, std::string>> estimated_silent_custom_gcode_print_times;
double total_used_filament;
double total_extruded_volume;
double total_cost;

View File

@ -1909,6 +1909,33 @@ void PrintConfigDef::init_fff_params()
def->mode = comExpert;
def->set_default_value(new ConfigOptionStrings { "; Filament gcode\n" });
def = this->add("color_change_gcode", coString);
def->label = L("Color change G-code");
def->tooltip = L("This G-code will be used as a code for the color change");
def->multiline = true;
def->full_width = true;
def->height = 12;
def->mode = comExpert;
def->set_default_value(new ConfigOptionString("M600"));
def = this->add("pause_print_gcode", coString);
def->label = L("Pause Print G-code");
def->tooltip = L("This G-code will be used as a code for the pause print");
def->multiline = true;
def->full_width = true;
def->height = 12;
def->mode = comExpert;
def->set_default_value(new ConfigOptionString("M601"));
def = this->add("template_custom_gcode", coString);
def->label = L("Custom G-code");
def->tooltip = L("This G-code will be used as a custom code");
def->multiline = true;
def->full_width = true;
def->height = 12;
def->mode = comExpert;
def->set_default_value(new ConfigOptionString(""));
def = this->add("single_extruder_multi_material", coBool);
def->label = L("Single Extruder Multi Material");
def->tooltip = L("The printer multiplexes filaments into a single hot end.");

View File

@ -699,6 +699,9 @@ public:
ConfigOptionBool remaining_times;
ConfigOptionBool silent_mode;
ConfigOptionFloat extra_loading_move;
ConfigOptionString color_change_gcode;
ConfigOptionString pause_print_gcode;
ConfigOptionString template_custom_gcode;
std::string get_extrusion_axis() const
{
@ -772,6 +775,9 @@ protected:
OPT_PTR(remaining_times);
OPT_PTR(silent_mode);
OPT_PTR(extra_loading_move);
OPT_PTR(color_change_gcode);
OPT_PTR(pause_print_gcode);
OPT_PTR(template_custom_gcode);
}
};

View File

@ -97,7 +97,7 @@ std::unique_ptr<TriangleMesh> generate_interior(const TriangleMesh & mesh,
_generate_interior(mesh, ctl, hc.min_thickness, voxel_scale,
hc.closing_distance));
if (meshptr) {
if (meshptr && !meshptr->empty()) {
// This flips the normals to be outward facing...
meshptr->require_shared_vertices();

View File

@ -28,17 +28,25 @@ void reproject_support_points(const EigenMesh3D &mesh, std::vector<PointType> &p
inline void reproject_points_and_holes(ModelObject *object)
{
bool has_sppoints = !object->sla_support_points.empty();
bool has_holes = !object->sla_drain_holes.empty();
if (!object || (!has_holes && !has_sppoints)) return;
// Disabling reprojection of holes as they have a significant offset away
// from the model body which tolerates minor geometrical changes.
//
// TODO: uncomment and ensure the right offset of the hole points if
// reprojection would still be necessary.
// bool has_holes = !object->sla_drain_holes.empty();
EigenMesh3D emesh{object->raw_mesh()};
if (!object || (/*!has_holes &&*/ !has_sppoints)) return;
TriangleMesh rmsh = object->raw_mesh();
rmsh.require_shared_vertices();
EigenMesh3D emesh{rmsh};
if (has_sppoints)
reproject_support_points(emesh, object->sla_support_points);
if (has_holes)
reproject_support_points(emesh, object->sla_drain_holes);
// if (has_holes)
// reproject_support_points(emesh, object->sla_drain_holes);
}
}}

View File

@ -98,6 +98,9 @@ void AppConfig::set_defaults()
set("use_environment_map", "0");
#endif // ENABLE_ENVIRONMENT_MAP
if (get("use_inches").empty())
set("use_inches", "0");
// Remove legacy window positions/sizes
erase("", "main_frame_maximized");
erase("", "main_frame_pos");

View File

@ -29,6 +29,7 @@
#include "GUI.hpp"
#include "GUI_App.hpp"
#include "GUI_Utils.hpp"
#include "GUI_ObjectManipulation.hpp"
#include "slic3r/Config/Snapshot.hpp"
#include "slic3r/Utils/PresetUpdater.hpp"
@ -840,6 +841,10 @@ PageMode::PageMode(ConfigWizard *parent)
append(radio_simple);
append(radio_advanced);
append(radio_expert);
append_text("\n" + _L("The size of the object can be specified in inches"));
check_inch = new wxCheckBox(this, wxID_ANY, _L("Use inches"));
append(check_inch);
}
void PageMode::on_activate()
@ -850,6 +855,8 @@ void PageMode::on_activate()
if (mode == "advanced") { radio_advanced->SetValue(true); }
else if (mode == "expert") { radio_expert->SetValue(true); }
else { radio_simple->SetValue(true); }
check_inch->SetValue(wxGetApp().app_config->get("use_inches") == "1");
}
void PageMode::serialize_mode(AppConfig *app_config) const
@ -866,6 +873,7 @@ void PageMode::serialize_mode(AppConfig *app_config) const
return;
app_config->set("view_mode", mode);
app_config->set("use_inches", check_inch->GetValue() ? "1" : "0");
}
PageVendors::PageVendors(ConfigWizard *parent)
@ -2179,6 +2187,7 @@ bool ConfigWizard::run(RunReason reason, StartPage start_page)
p->apply_config(app.app_config, app.preset_bundle, app.preset_updater);
app.app_config->set_legacy_datadir(false);
app.update_mode();
app.obj_manipul()->update_ui_from_settings();
BOOST_LOG_TRIVIAL(info) << "ConfigWizard applied";
return true;
} else {

View File

@ -316,6 +316,8 @@ struct PageMode: ConfigWizardPage
wxRadioButton *radio_advanced;
wxRadioButton *radio_expert;
wxCheckBox *check_inch;
PageMode(ConfigWizard *parent);
void serialize_mode(AppConfig *app_config) const;

View File

@ -33,6 +33,21 @@ namespace DoubleSlider {
wxDEFINE_EVENT(wxCUSTOMEVT_TICKSCHANGED, wxEvent);
static std::string gcode(Type type)
{
const PrintConfig& config = GUI::wxGetApp().plater()->fff_print().config();
switch (type) {
case ColorChange:
return config.color_change_gcode;
case PausePrint:
return config.pause_print_gcode;
case Template:
return config.template_custom_gcode;
default:
return "";
}
}
Control::Control( wxWindow *parent,
wxWindowID id,
int lowerValue,
@ -284,18 +299,17 @@ double Control::get_double_value(const SelectedSlider& selection)
return m_values[selection == ssLower ? m_lower_value : m_higher_value];
}
using t_custom_code = CustomGCode::Item;
CustomGCode::Info Control::GetTicksValues() const
Info Control::GetTicksValues() const
{
CustomGCode::Info custom_gcode_per_print_z;
std::vector<t_custom_code>& values = custom_gcode_per_print_z.gcodes;
Info custom_gcode_per_print_z;
std::vector<Item>& values = custom_gcode_per_print_z.gcodes;
const int val_size = m_values.size();
if (!m_values.empty())
for (const TickCode& tick : m_ticks.ticks) {
if (tick.tick > val_size)
break;
values.emplace_back(t_custom_code{m_values[tick.tick], tick.gcode, tick.extruder, tick.color});
values.emplace_back(Item{m_values[tick.tick], tick.type, tick.extruder, tick.color, tick.extra});
}
if (m_force_mode_apply)
@ -304,7 +318,7 @@ CustomGCode::Info Control::GetTicksValues() const
return custom_gcode_per_print_z;
}
void Control::SetTicksValues(const CustomGCode::Info& custom_gcode_per_print_z)
void Control::SetTicksValues(const Info& custom_gcode_per_print_z)
{
if (m_values.empty())
{
@ -315,14 +329,14 @@ void Control::SetTicksValues(const CustomGCode::Info& custom_gcode_per_print_z)
const bool was_empty = m_ticks.empty();
m_ticks.ticks.clear();
const std::vector<t_custom_code>& heights = custom_gcode_per_print_z.gcodes;
const std::vector<Item>& heights = custom_gcode_per_print_z.gcodes;
for (auto h : heights) {
auto it = std::lower_bound(m_values.begin(), m_values.end(), h.print_z - epsilon());
if (it == m_values.end())
continue;
m_ticks.ticks.emplace(TickCode{int(it-m_values.begin()), h.gcode, h.extruder, h.color});
m_ticks.ticks.emplace(TickCode{int(it-m_values.begin()), h.type, h.extruder, h.color, h.extra});
}
if (!was_empty && m_ticks.empty())
@ -345,14 +359,14 @@ void Control::SetDrawMode(bool is_sla_print, bool is_sequential_print)
void Control::SetModeAndOnlyExtruder(const bool is_one_extruder_printed_model, const int only_extruder)
{
m_mode = !is_one_extruder_printed_model ? t_mode::MultiExtruder :
only_extruder < 0 ? t_mode::SingleExtruder :
t_mode::MultiAsSingle;
m_mode = !is_one_extruder_printed_model ? MultiExtruder :
only_extruder < 0 ? SingleExtruder :
MultiAsSingle;
if (!m_ticks.mode)
m_ticks.mode = m_mode;
m_only_extruder = only_extruder;
UseDefaultColors(m_mode == t_mode::SingleExtruder);
UseDefaultColors(m_mode == SingleExtruder);
}
void Control::SetExtruderColors( const std::vector<std::string>& extruder_colors)
@ -653,11 +667,11 @@ void Control::draw_ticks(wxDC& dc)
// if we have non-regular draw mode, all ticks should be marked with error icon
if (m_draw_mode != dmRegular)
icon_name = focused_tick ? "error_tick_f" : "error_tick";
else if (tick.gcode == ColorChangeCode || tick.gcode == ToolChangeCode) {
else if (tick.type == ColorChange || tick.type == ToolChange) {
if (m_ticks.is_conflict_tick(tick, m_mode, m_only_extruder, m_values[tick.tick]))
icon_name = focused_tick ? "error_tick_f" : "error_tick";
}
else if (tick.gcode == PausePrintCode)
else if (tick.type == PausePrint)
icon_name = focused_tick ? "pause_print_f" : "pause_print";
else
icon_name = focused_tick ? "edit_gcode_f" : "edit_gcode";
@ -682,7 +696,7 @@ std::string Control::get_color_for_tool_change_tick(std::set<TickCode>::const_it
auto it_n = it;
while (it_n != m_ticks.ticks.begin()) {
--it_n;
if (it_n->gcode == ColorChangeCode && it_n->extruder == current_extruder)
if (it_n->type == ColorChange && it_n->extruder == current_extruder)
return it_n->color;
}
@ -696,13 +710,13 @@ std::string Control::get_color_for_color_change_tick(std::set<TickCode>::const_i
bool is_tool_change = false;
while (it_n != m_ticks.ticks.begin()) {
--it_n;
if (it_n->gcode == ToolChangeCode) {
if (it_n->type == ToolChange) {
is_tool_change = true;
if (it_n->extruder == it->extruder)
return it->color;
break;
}
if (it_n->gcode == ColorChangeCode && it_n->extruder == it->extruder)
if (it_n->type == ColorChange && it_n->extruder == it->extruder)
return it->color;
}
if (!is_tool_change && it->extruder == def_extruder)
@ -740,28 +754,28 @@ void Control::draw_colored_band(wxDC& dc)
wxRect main_band = get_colored_band_rect();
// don't color a band for MultiExtruder mode
if (m_ticks.empty() || m_mode == t_mode::MultiExtruder)
if (m_ticks.empty() || m_mode == MultiExtruder)
{
draw_band(dc, GetParent()->GetBackgroundColour(), main_band);
return;
}
const int default_color_idx = m_mode==t_mode::MultiAsSingle ? std::max<int>(m_only_extruder - 1, 0) : 0;
const int default_color_idx = m_mode==MultiAsSingle ? std::max<int>(m_only_extruder - 1, 0) : 0;
draw_band(dc, wxColour(m_extruder_colors[default_color_idx]), main_band);
std::set<TickCode>::const_iterator tick_it = m_ticks.ticks.begin();
while (tick_it != m_ticks.ticks.end())
{
if ( (m_mode == t_mode::SingleExtruder && tick_it->gcode == ColorChangeCode ) ||
(m_mode == t_mode::MultiAsSingle && (tick_it->gcode == ToolChangeCode || tick_it->gcode == ColorChangeCode)) )
if ( (m_mode == SingleExtruder && tick_it->type == ColorChange ) ||
(m_mode == MultiAsSingle && (tick_it->type == ToolChange || tick_it->type == ColorChange)) )
{
const wxCoord pos = get_position_from_value(tick_it->tick);
is_horizontal() ? main_band.SetLeft(SLIDER_MARGIN + pos) :
main_band.SetBottom(pos - 1);
const std::string clr_str = m_mode == t_mode::SingleExtruder ? tick_it->color :
tick_it->gcode == ToolChangeCode ?
const std::string clr_str = m_mode == SingleExtruder ? tick_it->color :
tick_it->type == ToolChange ?
get_color_for_tool_change_tick(tick_it) :
get_color_for_color_change_tick(tick_it);
@ -950,17 +964,17 @@ wxString Control::get_tooltip(int tick/*=-1*/)
if (m_focus == fiNone)
return "";
if (m_focus == fiOneLayerIcon)
return _(L("One layer mode"));
return _L("One layer mode");
if (m_focus == fiRevertIcon)
return _(L("Discard all custom changes"));
return _L("Discard all custom changes");
if (m_focus == fiCogIcon)
return m_mode == t_mode::MultiAsSingle ?
GUI::from_u8((boost::format(_utf8(L("Jump to height %s or "
"Set extruder sequence for the entire print"))) % " (Shift + G)\n").str()) :
_(L("Jump to height")) + " (Shift + G)";
return m_mode == MultiAsSingle ?
GUI::from_u8((boost::format(_u8L("Jump to height %s or "
"Set extruder sequence for the entire print")) % " (Shift + G)\n").str()) :
_L("Jump to height") + " (Shift + G)";
if (m_focus == fiColorBand)
return m_mode != t_mode::SingleExtruder ? "" :
_(L("Edit current color - Right click the colored slider segment"));
return m_mode != SingleExtruder ? "" :
_L("Edit current color - Right click the colored slider segment");
if (m_draw_mode == dmSlaPrint)
return ""; // no drawn ticks and no tooltips for them in SlaPrinting mode
@ -970,10 +984,10 @@ wxString Control::get_tooltip(int tick/*=-1*/)
if (tick_code_it == m_ticks.ticks.end() && m_focus == fiActionIcon) // tick doesn't exist
{
// Show mode as a first string of tooltop
tooltip = " " + _(L("Print mode")) + ": ";
tooltip += (m_mode == t_mode::SingleExtruder ? CustomGCode::SingleExtruderMode :
m_mode == t_mode::MultiAsSingle ? CustomGCode::MultiAsSingleMode :
CustomGCode::MultiExtruderMode );
tooltip = " " + _L("Print mode") + ": ";
tooltip += (m_mode == SingleExtruder ? SingleExtruderMode :
m_mode == MultiAsSingle ? MultiAsSingleMode :
MultiExtruderMode );
tooltip += "\n\n";
/* Note: just on OSX!!!
@ -983,68 +997,70 @@ wxString Control::get_tooltip(int tick/*=-1*/)
* */
// Show list of actions with new tick
tooltip += ( m_mode == t_mode::MultiAsSingle ?
_(L("Add extruder change - Left click")) :
m_mode == t_mode::SingleExtruder ?
_(L("Add color change - Left click for predefined color or "
"Shift + Left click for custom color selection")) :
_(L("Add color change - Left click")) ) + " " +
_(L("or press \"+\" key")) + "\n" + (
is_osx ?
_(L("Add another code - Ctrl + Left click")) :
_(L("Add another code - Right click")) );
tooltip += ( m_mode == MultiAsSingle ?
_L("Add extruder change - Left click") :
m_mode == SingleExtruder ?
_L("Add color change - Left click for predefined color or "
"Shift + Left click for custom color selection") :
_L("Add color change - Left click") ) + " " +
_L("or press \"+\" key") + "\n" + (
is_osx ?
_L("Add another code - Ctrl + Left click") :
_L("Add another code - Right click") );
}
if (tick_code_it != m_ticks.ticks.end()) // tick exists
{
if (m_draw_mode == dmSequentialFffPrint)
return _(L("The sequential print is on.\n"
return _L("The sequential print is on.\n"
"It's impossible to apply any custom G-code for objects printing sequentually.\n"
"This code won't be processed during G-code generation."));
"This code won't be processed during G-code generation.");
// Show custom Gcode as a first string of tooltop
tooltip = " ";
tooltip +=
tick_code_it->gcode == ColorChangeCode ?
(m_mode == t_mode::SingleExtruder ?
format_wxstr(_L("Color change (\"%1%\")"), tick_code_it->gcode) :
format_wxstr(_L("Color change (\"%1%\") for Extruder %2%"), tick_code_it->gcode, tick_code_it->extruder)) :
tick_code_it->gcode == PausePrintCode ?
format_wxstr(_L("Pause print (\"%1%\")"), tick_code_it->gcode) :
tick_code_it->gcode == ToolChangeCode ?
format_wxstr(_L("Extruder (tool) is changed to Extruder \"%1%\""), tick_code_it->extruder) :
from_u8(tick_code_it->gcode);
tick_code_it->type == ColorChange ?
(m_mode == SingleExtruder ?
format_wxstr(_L("Color change (\"%1%\")"), gcode(ColorChange)) :
format_wxstr(_L("Color change (\"%1%\") for Extruder %2%"), gcode(ColorChange), tick_code_it->extruder)) :
tick_code_it->type == PausePrint ?
format_wxstr(_L("Pause print (\"%1%\")"), gcode(PausePrint)) :
tick_code_it->type == Template ?
format_wxstr(_L("Custom template (\"%1%\")"), gcode(Template)) :
tick_code_it->type == ToolChange ?
format_wxstr(_L("Extruder (tool) is changed to Extruder \"%1%\""), tick_code_it->extruder) :
from_u8(tick_code_it->extra);// tick_code_it->type == Custom
// If tick is marked as a conflict (exclamation icon),
// we should to explain why
ConflictType conflict = m_ticks.is_conflict_tick(*tick_code_it, m_mode, m_only_extruder, m_values[tick]);
if (conflict != ctNone)
tooltip += "\n\n" + _(L("Note")) + "! ";
tooltip += "\n\n" + _L("Note") + "! ";
if (conflict == ctModeConflict)
tooltip += _(L("G-code associated to this tick mark is in a conflict with print mode.\n"
"Editing it will cause changes of Slider data."));
tooltip += _L("G-code associated to this tick mark is in a conflict with print mode.\n"
"Editing it will cause changes of Slider data.");
else if (conflict == ctMeaninglessColorChange)
tooltip += _(L("There is a color change for extruder that won't be used till the end of print job.\n"
"This code won't be processed during G-code generation."));
tooltip += _L("There is a color change for extruder that won't be used till the end of print job.\n"
"This code won't be processed during G-code generation.");
else if (conflict == ctMeaninglessToolChange)
tooltip += _(L("There is an extruder change set to the same extruder.\n"
"This code won't be processed during G-code generation."));
tooltip += _L("There is an extruder change set to the same extruder.\n"
"This code won't be processed during G-code generation.");
else if (conflict == ctRedundant)
tooltip += _(L("There is a color change for extruder that has not been used before.\n"
"Check your settings to avoid redundant color changes."));
tooltip += _L("There is a color change for extruder that has not been used before.\n"
"Check your settings to avoid redundant color changes.");
// Show list of actions with existing tick
if (m_focus == fiActionIcon)
tooltip += "\n\n" + _(L("Delete tick mark - Left click or press \"-\" key")) + "\n" + (
tooltip += "\n\n" + _L("Delete tick mark - Left click or press \"-\" key") + "\n" + (
is_osx ?
_(L("Edit tick mark - Ctrl + Left click")) :
_(L("Edit tick mark - Right click")) );
_L("Edit tick mark - Ctrl + Left click") :
_L("Edit tick mark - Right click") );
}
return tooltip;
}
int Control::get_edited_tick_for_position(const wxPoint pos, const std::string& gcode /*= ColorChangeCode*/)
int Control::get_edited_tick_for_position(const wxPoint pos, Type type /*= ColorChange*/)
{
if (m_ticks.empty())
return -1;
@ -1054,7 +1070,7 @@ int Control::get_edited_tick_for_position(const wxPoint pos, const std::string&
while (it != m_ticks.ticks.begin()) {
--it;
if (it->gcode == gcode)
if (it->type == type)
return it->tick;
}
@ -1080,7 +1096,7 @@ void Control::OnMotion(wxMouseEvent& event)
m_focus = fiRevertIcon;
else if (is_point_in_rect(pos, m_rect_cog_icon))
m_focus = fiCogIcon;
else if (m_mode == t_mode::SingleExtruder && is_point_in_rect(pos, get_colored_band_rect()) &&
else if (m_mode == SingleExtruder && is_point_in_rect(pos, get_colored_band_rect()) &&
get_edited_tick_for_position(pos) >= 0 )
m_focus = fiColorBand;
else {
@ -1137,21 +1153,21 @@ void Control::append_change_extruder_menu_item(wxMenu* menu, bool switch_current
const wxString item_name = wxString::Format(_(L("Extruder %d")), i) +
(is_active_extruder ? " (" + _(L("active")) + ")" : "");
if (m_mode == t_mode::MultiAsSingle)
if (m_mode == MultiAsSingle)
append_menu_item(change_extruder_menu, wxID_ANY, item_name, "",
[this, i](wxCommandEvent&) { add_code_as_tick(ToolChangeCode, i); }, *icons[i-1], menu,
[this, i](wxCommandEvent&) { add_code_as_tick(ToolChange, i); }, *icons[i-1], menu,
[is_active_extruder]() { return !is_active_extruder; }, GUI::wxGetApp().plater());
}
const wxString change_extruder_menu_name = m_mode == t_mode::MultiAsSingle ?
(switch_current_code ? _(L("Switch code to Change extruder")) : _(L("Change extruder")) ) :
_(L("Change extruder (N/A)"));
const wxString change_extruder_menu_name = m_mode == MultiAsSingle ?
(switch_current_code ? _L("Switch code to Change extruder") : _L("Change extruder") ) :
_L("Change extruder (N/A)");
wxMenuItem* change_extruder_menu_item = menu->AppendSubMenu(change_extruder_menu, change_extruder_menu_name, _(L("Use another extruder")));
change_extruder_menu_item->SetBitmap(create_scaled_bitmap(active_extruders[1] > 0 ? "edit_uni" : "change_extruder"));
GUI::wxGetApp().plater()->Bind(wxEVT_UPDATE_UI, [this, change_extruder_menu_item](wxUpdateUIEvent& evt) {
enable_menu_item(evt, [this]() {return m_mode == t_mode::MultiAsSingle; }, change_extruder_menu_item, this); },
enable_menu_item(evt, [this]() {return m_mode == MultiAsSingle; }, change_extruder_menu_item, this); },
change_extruder_menu_item->GetId());
}
}
@ -1174,13 +1190,13 @@ void Control::append_add_color_change_menu_item(wxMenu* menu, bool switch_curren
(is_used_extruder ? " (" + _(L("used")) + ")" : "");
append_menu_item(add_color_change_menu, wxID_ANY, item_name, "",
[this, i](wxCommandEvent&) { add_code_as_tick(ColorChangeCode, i); }, "", menu,
[this, i](wxCommandEvent&) { add_code_as_tick(ColorChange, i); }, "", menu,
[]() { return true; }, GUI::wxGetApp().plater());
}
const wxString menu_name = switch_current_code ?
format_wxstr(_L("Switch code to Color change (%1%) for:"), ColorChangeCode) :
format_wxstr(_L("Add color change (%1%) for:"), ColorChangeCode);
format_wxstr(_L("Switch code to Color change (%1%) for:"), gcode(ColorChange)) :
format_wxstr(_L("Add color change (%1%) for:"), gcode(ColorChange));
wxMenuItem* add_color_change_menu_item = menu->AppendSubMenu(add_color_change_menu, menu_name, "");
add_color_change_menu_item->SetBitmap(create_scaled_bitmap("colorchange_add_m"));
}
@ -1204,7 +1220,7 @@ void Control::OnLeftUp(wxMouseEvent& event)
add_current_tick();
break;
case maCogIconClick :
if (m_mode == t_mode::MultiAsSingle && m_draw_mode == dmRegular)
if (m_mode == MultiAsSingle && m_draw_mode == dmRegular)
show_cog_icon_context_menu();
else
jump_to_print_z();
@ -1362,9 +1378,9 @@ void Control::OnRightDown(wxMouseEvent& event)
m_mouse = m_ticks.ticks.find(TickCode{ tick }) == m_ticks.ticks.end() ?
maAddMenu : maEditMenu;
}
else if (m_mode == t_mode::SingleExtruder && !detect_selected_slider(pos) && is_point_in_rect(pos, get_colored_band_rect()))
else if (m_mode == SingleExtruder && !detect_selected_slider(pos) && is_point_in_rect(pos, get_colored_band_rect()))
m_mouse = maForceColorEdit;
else if (m_mode == t_mode::MultiAsSingle && is_point_in_rect(pos, m_rect_cog_icon))
else if (m_mode == MultiAsSingle && is_point_in_rect(pos, m_rect_cog_icon))
m_mouse = maCogIconMenu;
}
if (m_mouse != maNone || !detect_selected_slider(pos))
@ -1385,11 +1401,11 @@ void Control::OnRightDown(wxMouseEvent& event)
// Get active extruders for tick.
// Means one current extruder for not existing tick OR
// 2 extruders - for existing tick (extruder before ToolChangeCode and extruder of current existing tick)
// 2 extruders - for existing tick (extruder before ToolChange and extruder of current existing tick)
// Use those values to disable selection of active extruders
std::array<int, 2> Control::get_active_extruders_for_tick(int tick) const
{
int default_initial_extruder = m_mode == t_mode::MultiAsSingle ? std::max<int>(1, m_only_extruder) : 1;
int default_initial_extruder = m_mode == MultiAsSingle ? std::max<int>(1, m_only_extruder) : 1;
std::array<int, 2> extruders = { default_initial_extruder, -1 };
if (m_ticks.empty())
return extruders;
@ -1401,7 +1417,7 @@ std::array<int, 2> Control::get_active_extruders_for_tick(int tick) const
while (it != m_ticks.ticks.begin()) {
--it;
if(it->gcode == ToolChangeCode) {
if(it->type == ToolChange) {
extruders[0] = it->extruder;
break;
}
@ -1412,11 +1428,11 @@ std::array<int, 2> Control::get_active_extruders_for_tick(int tick) const
// Get used extruders for tick.
// Means all extruders(tools) which will be used during printing from current tick to the end
std::set<int> TickCodeInfo::get_used_extruders_for_tick(int tick, int only_extruder, double print_z, t_mode force_mode/* = t_mode::Undef*/) const
std::set<int> TickCodeInfo::get_used_extruders_for_tick(int tick, int only_extruder, double print_z, Mode force_mode/* = Undef*/) const
{
t_mode e_mode = !force_mode ? mode : force_mode;
Mode e_mode = !force_mode ? mode : force_mode;
if (e_mode == t_mode::MultiExtruder)
if (e_mode == MultiExtruder)
{
// #ys_FIXME: get tool ordering from _correct_ place
const ToolOrdering& tool_ordering = GUI::wxGetApp().plater()->fff_print().get_tool_ordering();
@ -1437,15 +1453,15 @@ std::set<int> TickCodeInfo::get_used_extruders_for_tick(int tick, int only_extru
return used_extruders;
}
const int default_initial_extruder = e_mode == t_mode::MultiAsSingle ? std::max(only_extruder, 1) : 1;
if (ticks.empty() || e_mode == t_mode::SingleExtruder)
const int default_initial_extruder = e_mode == MultiAsSingle ? std::max(only_extruder, 1) : 1;
if (ticks.empty() || e_mode == SingleExtruder)
return {default_initial_extruder};
std::set<int> used_extruders;
auto it_start = ticks.lower_bound(TickCode{tick});
auto it = it_start;
if (it == ticks.begin() && it->gcode == ToolChangeCode &&
if (it == ticks.begin() && it->type == ToolChange &&
tick != it->tick ) // In case of switch of ToolChange to ColorChange, when tick exists,
// we shouldn't change color for extruder, which will be deleted
{
@ -1456,7 +1472,7 @@ std::set<int> TickCodeInfo::get_used_extruders_for_tick(int tick, int only_extru
while (it != ticks.begin()) {
--it;
if (it->gcode == ToolChangeCode && tick != it->tick) {
if (it->type == ToolChange && tick != it->tick) {
used_extruders.emplace(it->extruder);
break;
}
@ -1466,7 +1482,7 @@ std::set<int> TickCodeInfo::get_used_extruders_for_tick(int tick, int only_extru
used_extruders.emplace(default_initial_extruder);
for (it = it_start; it != ticks.end(); ++it)
if (it->gcode == ToolChangeCode && tick != it->tick)
if (it->type == ToolChange && tick != it->tick)
used_extruders.emplace(it->extruder);
return used_extruders;
@ -1476,9 +1492,9 @@ void Control::show_add_context_menu()
{
wxMenu menu;
if (m_mode == t_mode::SingleExtruder) {
append_menu_item(&menu, wxID_ANY, _(L("Add color change")) + " (M600)", "",
[this](wxCommandEvent&) { add_code_as_tick(ColorChangeCode); }, "colorchange_add_m", &menu);
if (m_mode == SingleExtruder) {
append_menu_item(&menu, wxID_ANY, _L("Add color change") + " (" + gcode(ColorChange) + ")", "",
[this](wxCommandEvent&) { add_code_as_tick(ColorChange); }, "colorchange_add_m", &menu);
UseDefaultColors(false);
}
@ -1487,11 +1503,15 @@ void Control::show_add_context_menu()
append_add_color_change_menu_item(&menu);
}
append_menu_item(&menu, wxID_ANY, _(L("Add pause print")) + " (M601)", "",
[this](wxCommandEvent&) { add_code_as_tick(PausePrintCode); }, "pause_print", &menu);
append_menu_item(&menu, wxID_ANY, _L("Add pause print") + " (" + gcode(PausePrint) + ")", "",
[this](wxCommandEvent&) { add_code_as_tick(PausePrint); }, "pause_print", &menu);
append_menu_item(&menu, wxID_ANY, _(L("Add custom G-code")), "",
[this](wxCommandEvent&) { add_code_as_tick(""); }, "edit_gcode", &menu);
if (!gcode(Template).empty())
append_menu_item(&menu, wxID_ANY, _L("Add custom template") + " (" + gcode(Template) + ")", "",
[this](wxCommandEvent&) { add_code_as_tick(Template); }, "edit_gcode", &menu);
append_menu_item(&menu, wxID_ANY, _L("Add custom G-code"), "",
[this](wxCommandEvent&) { add_code_as_tick(Custom); }, "edit_gcode", &menu);
GUI::wxGetApp().plater()->PopupMenu(&menu);
}
@ -1502,23 +1522,23 @@ void Control::show_edit_context_menu()
std::set<TickCode>::iterator it = m_ticks.ticks.find(TickCode{ m_selection == ssLower ? m_lower_value : m_higher_value });
if (it->gcode == ToolChangeCode) {
if (m_mode == t_mode::MultiAsSingle)
if (it->type == ToolChange) {
if (m_mode == MultiAsSingle)
append_change_extruder_menu_item(&menu);
append_add_color_change_menu_item(&menu, true);
}
else
append_menu_item(&menu, wxID_ANY, it->gcode == ColorChangeCode ? _(L("Edit color")) :
it->gcode == PausePrintCode ? _(L("Edit pause print message")) :
append_menu_item(&menu, wxID_ANY, it->type == ColorChange ? _(L("Edit color")) :
it->type == PausePrint ? _(L("Edit pause print message")) :
_(L("Edit custom G-code")), "",
[this](wxCommandEvent&) { edit_tick(); }, "edit_uni", &menu);
if (it->gcode == ColorChangeCode && m_mode == t_mode::MultiAsSingle)
if (it->type == ColorChange && m_mode == MultiAsSingle)
append_change_extruder_menu_item(&menu, true);
append_menu_item(&menu, wxID_ANY, it->gcode == ColorChangeCode ? _(L("Delete color change")) :
it->gcode == ToolChangeCode ? _(L("Delete tool change")) :
it->gcode == PausePrintCode ? _(L("Delete pause print")) :
append_menu_item(&menu, wxID_ANY, it->type == ColorChange ? _(L("Delete color change")) :
it->type == ToolChange ? _(L("Delete tool change")) :
it->type == PausePrint ? _(L("Delete pause print")) :
_(L("Delete custom G-code")), "",
[this](wxCommandEvent&) { delete_current_tick();}, "colorchange_del_f", &menu);
@ -1599,6 +1619,8 @@ static void upgrade_text_entry_dialog(wxTextEntryDialog* dlg, double min = -1.0,
if (!textctrl)
return;
textctrl->SetInsertionPointEnd();
wxButton* btn_OK = static_cast<wxButton*>(dlg->FindWindowById(wxID_OK));
btn_OK->Bind(wxEVT_UPDATE_UI, [textctrl, min, max](wxUpdateUIEvent& evt)
{
@ -1665,13 +1687,13 @@ static double get_print_z_to_jump(double active_print_z, double min_z, double ma
return dlg.GetValue().ToCDouble(&value) ? value : -1.0;
}
void Control::add_code_as_tick(std::string code, int selected_extruder/* = -1*/)
void Control::add_code_as_tick(Type type, int selected_extruder/* = -1*/)
{
if (m_selection == ssUndef)
return;
const int tick = m_selection == ssLower ? m_lower_value : m_higher_value;
if ( !check_ticks_changed_event(code) )
if ( !check_ticks_changed_event(type) )
return;
const int extruder = selected_extruder > 0 ? selected_extruder : std::max<int>(1, m_only_extruder);
@ -1679,18 +1701,18 @@ void Control::add_code_as_tick(std::string code, int selected_extruder/* = -1*/)
if ( it == m_ticks.ticks.end() ) {
// try to add tick
if (!m_ticks.add_tick(tick, code, extruder, m_values[tick]))
if (!m_ticks.add_tick(tick, type, extruder, m_values[tick]))
return;
}
else if (code == ToolChangeCode || code == ColorChangeCode) {
// try to switch tick code to ToolChangeCode or ColorChangeCode accordingly
if (!m_ticks.switch_code_for_tick(it, code, extruder))
else if (type == ToolChange || type == ColorChange) {
// try to switch tick code to ToolChange or ColorChange accordingly
if (!m_ticks.switch_code_for_tick(it, type, extruder))
return;
}
else
return;
post_ticks_changed_event(code);
post_ticks_changed_event(type);
}
void Control::add_current_tick(bool call_from_keyboard /*= false*/)
@ -1701,16 +1723,16 @@ void Control::add_current_tick(bool call_from_keyboard /*= false*/)
auto it = m_ticks.ticks.find(TickCode{ tick });
if (it != m_ticks.ticks.end() || // this tick is already exist
!check_ticks_changed_event(m_mode == t_mode::MultiAsSingle ? ToolChangeCode : ColorChangeCode))
!check_ticks_changed_event(m_mode == MultiAsSingle ? ToolChange : ColorChange))
return;
if (m_mode == t_mode::SingleExtruder)
add_code_as_tick(ColorChangeCode);
if (m_mode == SingleExtruder)
add_code_as_tick(ColorChange);
else
{
wxMenu menu;
if (m_mode == t_mode::MultiAsSingle)
if (m_mode == MultiAsSingle)
append_change_extruder_menu_item(&menu);
else
append_add_color_change_menu_item(&menu);
@ -1743,12 +1765,12 @@ void Control::delete_current_tick()
auto it = m_ticks.ticks.find(TickCode{ m_selection == ssLower ? m_lower_value : m_higher_value });
if (it == m_ticks.ticks.end() ||
!check_ticks_changed_event(it->gcode))
!check_ticks_changed_event(it->type))
return;
const std::string code = it->gcode;
Type type = it->type;
m_ticks.ticks.erase(it);
post_ticks_changed_event(code);
post_ticks_changed_event(type);
}
void Control::edit_tick(int tick/* = -1*/)
@ -1758,12 +1780,12 @@ void Control::edit_tick(int tick/* = -1*/)
const std::set<TickCode>::iterator it = m_ticks.ticks.find(TickCode{ tick });
if (it == m_ticks.ticks.end() ||
!check_ticks_changed_event(it->gcode))
!check_ticks_changed_event(it->type))
return;
const std::string code = it->gcode;
Type type = it->type;
if (m_ticks.edit_tick(it, m_values[it->tick]))
post_ticks_changed_event(code);
post_ticks_changed_event(type);
}
// switch on/off one layer mode
@ -1818,7 +1840,7 @@ void Control::move_current_thumb_to_pos(wxPoint pos)
void Control::edit_extruder_sequence()
{
if (!check_ticks_changed_event(ToolChangeCode))
if (!check_ticks_changed_event(ToolChange))
return;
GUI::ExtruderSequenceDialog dlg(m_extruders_sequence);
@ -1826,7 +1848,7 @@ void Control::edit_extruder_sequence()
return;
m_extruders_sequence = dlg.GetValue();
m_ticks.erase_all_ticks_with_code(ToolChangeCode);
m_ticks.erase_all_ticks_with_code(ToolChange);
int tick = 0;
double value = 0.0;
@ -1839,7 +1861,7 @@ void Control::edit_extruder_sequence()
bool meaningless_tick = tick == 0.0 && cur_extruder == extruder;
if (!meaningless_tick)
m_ticks.ticks.emplace(TickCode{tick, ToolChangeCode, cur_extruder + 1, m_extruder_colors[cur_extruder]});
m_ticks.ticks.emplace(TickCode{tick, ToolChange,cur_extruder + 1, m_extruder_colors[cur_extruder]});
extruder++;
if (extruder == extr_cnt)
@ -1858,7 +1880,7 @@ void Control::edit_extruder_sequence()
tick += m_extruders_sequence.interval_by_layers;
}
post_ticks_changed_event(ToolChangeCode);
post_ticks_changed_event(ToolChange);
}
void Control::jump_to_print_z()
@ -1877,64 +1899,64 @@ void Control::jump_to_print_z()
SetHigherValue(tick_value);
}
void Control::post_ticks_changed_event(const std::string& gcode /*= ""*/)
void Control::post_ticks_changed_event(Type type /*= Custom*/)
{
m_force_mode_apply = (gcode.empty() || gcode == ColorChangeCode || gcode == ToolChangeCode);
m_force_mode_apply = type != ToolChange;
wxPostEvent(this->GetParent(), wxCommandEvent(wxCUSTOMEVT_TICKSCHANGED));
}
bool Control::check_ticks_changed_event(const std::string& gcode)
bool Control::check_ticks_changed_event(Type type)
{
if ( m_ticks.mode == m_mode ||
(gcode != ColorChangeCode && gcode != ToolChangeCode) ||
(m_ticks.mode == t_mode::SingleExtruder && m_mode == t_mode::MultiAsSingle) || // All ColorChanges will be applied for 1st extruder
(m_ticks.mode == t_mode::MultiExtruder && m_mode == t_mode::MultiAsSingle) ) // Just mark ColorChanges for all unused extruders
(type != ColorChange && type != ToolChange) ||
(m_ticks.mode == SingleExtruder && m_mode == MultiAsSingle) || // All ColorChanges will be applied for 1st extruder
(m_ticks.mode == MultiExtruder && m_mode == MultiAsSingle) ) // Just mark ColorChanges for all unused extruders
return true;
if ((m_ticks.mode == t_mode::SingleExtruder && m_mode == t_mode::MultiExtruder ) ||
(m_ticks.mode == t_mode::MultiExtruder && m_mode == t_mode::SingleExtruder) )
if ((m_ticks.mode == SingleExtruder && m_mode == MultiExtruder ) ||
(m_ticks.mode == MultiExtruder && m_mode == SingleExtruder) )
{
if (!m_ticks.has_tick_with_code(ColorChangeCode))
if (!m_ticks.has_tick_with_code(ColorChange))
return true;
wxString message = (m_ticks.mode == t_mode::SingleExtruder ?
_(L("The last color change data was saved for a single extruder printing.")) :
_(L("The last color change data was saved for a multi extruder printing."))
wxString message = (m_ticks.mode == SingleExtruder ?
_L("The last color change data was saved for a single extruder printing.") :
_L("The last color change data was saved for a multi extruder printing.")
) + "\n" +
_(L("Your current changes will delete all saved color changes.")) + "\n\n\t" +
_(L("Are you sure you want to continue?"));
_L("Your current changes will delete all saved color changes.") + "\n\n\t" +
_L("Are you sure you want to continue?");
wxMessageDialog msg(this, message, _(L("Notice")), wxYES_NO);
wxMessageDialog msg(this, message, _L("Notice"), wxYES_NO);
if (msg.ShowModal() == wxID_YES) {
m_ticks.erase_all_ticks_with_code(ColorChangeCode);
post_ticks_changed_event(ColorChangeCode);
m_ticks.erase_all_ticks_with_code(ColorChange);
post_ticks_changed_event(ColorChange);
}
return false;
}
// m_ticks_mode == t_mode::MultiAsSingle
if( m_ticks.has_tick_with_code(ToolChangeCode) )
// m_ticks_mode == MultiAsSingle
if( m_ticks.has_tick_with_code(ToolChange) )
{
wxString message = m_mode == t_mode::SingleExtruder ? (
_(L("The last color change data was saved for a multi extruder printing.")) + "\n\n" +
_(L("Select YES if you want to delete all saved tool changes, \n"
"NO if you want all tool changes switch to color changes, \n"
"or CANCEL to leave it unchanged.")) + "\n\n\t" +
_(L("Do you want to delete all saved tool changes?"))
) : ( // t_mode::MultiExtruder
_(L("The last color change data was saved for a multi extruder printing with tool changes for whole print.")) + "\n\n" +
_(L("Your current changes will delete all saved extruder (tool) changes.")) + "\n\n\t" +
_(L("Are you sure you want to continue?")) ) ;
wxString message = m_mode == SingleExtruder ? (
_L("The last color change data was saved for a multi extruder printing.") + "\n\n" +
_L("Select YES if you want to delete all saved tool changes, \n"
"NO if you want all tool changes switch to color changes, \n"
"or CANCEL to leave it unchanged.") + "\n\n\t" +
_L("Do you want to delete all saved tool changes?")
): ( // MultiExtruder
_L("The last color change data was saved for a multi extruder printing with tool changes for whole print.") + "\n\n" +
_L("Your current changes will delete all saved extruder (tool) changes.") + "\n\n\t" +
_L("Are you sure you want to continue?") ) ;
wxMessageDialog msg(this, message, _(L("Notice")), wxYES_NO | (m_mode == t_mode::SingleExtruder ? wxCANCEL : 0));
wxMessageDialog msg(this, message, _L("Notice"), wxYES_NO | (m_mode == SingleExtruder ? wxCANCEL : 0));
const int answer = msg.ShowModal();
if (answer == wxID_YES) {
m_ticks.erase_all_ticks_with_code(ToolChangeCode);
post_ticks_changed_event(ToolChangeCode);
m_ticks.erase_all_ticks_with_code(ToolChange);
post_ticks_changed_event(ToolChange);
}
else if (m_mode == t_mode::SingleExtruder && answer == wxID_NO) {
m_ticks.switch_code(ToolChangeCode, ColorChangeCode);
post_ticks_changed_event(ColorChangeCode);
else if (m_mode == SingleExtruder && answer == wxID_NO) {
m_ticks.switch_code(ToolChange, ColorChange);
post_ticks_changed_event(ColorChange);
}
return false;
}
@ -1942,9 +1964,9 @@ bool Control::check_ticks_changed_event(const std::string& gcode)
return true;
}
std::string TickCodeInfo::get_color_for_tick(TickCode tick, const std::string& code, const int extruder)
std::string TickCodeInfo::get_color_for_tick(TickCode tick, Type type, const int extruder)
{
if (mode == t_mode::SingleExtruder && code == ColorChangeCode && m_use_default_colors)
if (mode == SingleExtruder && type == ColorChange && m_use_default_colors)
{
const std::vector<std::string>& colors = GCodePreviewData::ColorPrintColors();
if (ticks.empty())
@ -1956,14 +1978,14 @@ std::string TickCodeInfo::get_color_for_tick(TickCode tick, const std::string& c
std::string color = (*m_colors)[extruder - 1];
if (code == ColorChangeCode)
if (type == ColorChange)
{
if (!ticks.empty())
{
auto before_tick_it = std::lower_bound(ticks.begin(), ticks.end(), tick );
while (before_tick_it != ticks.begin()) {
--before_tick_it;
if (before_tick_it->gcode == ColorChangeCode && before_tick_it->extruder == extruder) {
if (before_tick_it->type == ColorChange && before_tick_it->extruder == extruder) {
color = before_tick_it->color;
break;
}
@ -1975,63 +1997,67 @@ std::string TickCodeInfo::get_color_for_tick(TickCode tick, const std::string& c
return color;
}
bool TickCodeInfo::add_tick(const int tick, std::string& code, const int extruder, double print_z)
bool TickCodeInfo::add_tick(const int tick, Type type, const int extruder, double print_z)
{
std::string color;
if (code.empty()) // custom Gcode
std::string extra;
if (type == Custom) // custom Gcode
{
code = get_custom_code(custom_gcode, print_z);
if (code.empty())
extra = get_custom_code(custom_gcode, print_z);
if (extra.empty())
return false;
custom_gcode = code;
custom_gcode = extra;
}
else if (code == PausePrintCode)
else if (type == PausePrint)
{
/* PausePrintCode doesn't need a color, so
* this field is used for save a short message shown on Printer display
* */
color = get_pause_print_msg(pause_print_msg, print_z);
if (color.empty())
extra = get_pause_print_msg(pause_print_msg, print_z);
if (extra.empty())
return false;
pause_print_msg = color;
pause_print_msg = extra;
}
else
{
color = get_color_for_tick(TickCode{ tick }, code, extruder);
color = get_color_for_tick(TickCode{ tick }, type, extruder);
if (color.empty())
return false;
}
if (mode == t_mode::SingleExtruder)
if (mode == SingleExtruder)
m_use_default_colors = true;
ticks.emplace(TickCode{ tick, code, extruder, color });
ticks.emplace(TickCode{ tick, type, extruder, color, extra });
return true;
}
bool TickCodeInfo::edit_tick(std::set<TickCode>::iterator it, double print_z)
{
std::string edited_value;
if (it->gcode == ColorChangeCode)
if (it->type == ColorChange)
edited_value = get_new_color(it->color);
else if (it->gcode == PausePrintCode)
edited_value = get_pause_print_msg(it->color, print_z);
else if (it->type == PausePrint)
edited_value = get_pause_print_msg(it->extra, print_z);
else
edited_value = get_custom_code(it->gcode, print_z);
edited_value = get_custom_code(it->type == Template ? gcode(Template) : it->extra, print_z);
if (edited_value.empty())
return false;
TickCode changed_tick = *it;
if (it->gcode == ColorChangeCode || it->gcode == PausePrintCode) {
if (it->type == ColorChange) {
if (it->color == edited_value)
return false;
changed_tick.color = edited_value;
}
else {
if (it->gcode == edited_value)
else if (it->type == Template) {
if (gcode(Template) == edited_value)
return false;
changed_tick.gcode = edited_value;
changed_tick.extra = edited_value;
changed_tick.type = Custom;
}
else if (it->type == Custom || it->type == PausePrint) {
if (it->extra == edited_value)
return false;
changed_tick.extra = edited_value;
}
ticks.erase(it);
@ -2040,13 +2066,13 @@ bool TickCodeInfo::edit_tick(std::set<TickCode>::iterator it, double print_z)
return true;
}
void TickCodeInfo::switch_code(const std::string& code_from, const std::string& code_to)
void TickCodeInfo::switch_code(Type type_from, Type type_to)
{
for (auto it{ ticks.begin() }, end{ ticks.end() }; it != end; )
if (it->gcode == code_from)
if (it->type == type_from)
{
TickCode tick = *it;
tick.gcode = code_to;
tick.type = type_to;
tick.extruder = 1;
ticks.erase(it);
it = ticks.emplace(tick).first;
@ -2055,14 +2081,14 @@ void TickCodeInfo::switch_code(const std::string& code_from, const std::string&
++it;
}
bool TickCodeInfo::switch_code_for_tick(std::set<TickCode>::iterator it, const std::string& code_to, const int extruder)
bool TickCodeInfo::switch_code_for_tick(std::set<TickCode>::iterator it, Type type_to, const int extruder)
{
const std::string color = get_color_for_tick(*it, code_to, extruder);
const std::string color = get_color_for_tick(*it, type_to, extruder);
if (color.empty())
return false;
TickCode changed_tick = *it;
changed_tick.gcode = code_to;
TickCode changed_tick = *it;
changed_tick.type = type_to;
changed_tick.extruder = extruder;
changed_tick.color = color;
@ -2072,36 +2098,36 @@ bool TickCodeInfo::switch_code_for_tick(std::set<TickCode>::iterator it, const s
return true;
}
void TickCodeInfo::erase_all_ticks_with_code(const std::string& gcode)
void TickCodeInfo::erase_all_ticks_with_code(Type type)
{
for (auto it{ ticks.begin() }, end{ ticks.end() }; it != end; ) {
if (it->gcode == gcode)
if (it->type == type)
it = ticks.erase(it);
else
++it;
}
}
bool TickCodeInfo::has_tick_with_code(const std::string& gcode)
bool TickCodeInfo::has_tick_with_code(Type type)
{
for (const TickCode& tick : ticks)
if (tick.gcode == gcode)
if (tick.type == type)
return true;
return false;
}
ConflictType TickCodeInfo::is_conflict_tick(const TickCode& tick, t_mode out_mode, int only_extruder, double print_z)
ConflictType TickCodeInfo::is_conflict_tick(const TickCode& tick, Mode out_mode, int only_extruder, double print_z)
{
if ((tick.gcode == ColorChangeCode && (
(mode == t_mode::SingleExtruder && out_mode == t_mode::MultiExtruder ) ||
(mode == t_mode::MultiExtruder && out_mode == t_mode::SingleExtruder) )) ||
(tick.gcode == ToolChangeCode &&
(mode == t_mode::MultiAsSingle && out_mode != t_mode::MultiAsSingle)) )
if ((tick.type == ColorChange && (
(mode == SingleExtruder && out_mode == MultiExtruder ) ||
(mode == MultiExtruder && out_mode == SingleExtruder) )) ||
(tick.type == ToolChange &&
(mode == MultiAsSingle && out_mode != MultiAsSingle)) )
return ctModeConflict;
// check ColorChange tick
if (tick.gcode == ColorChangeCode)
if (tick.type == ColorChange)
{
// We should mark a tick as a "MeaninglessColorChange",
// if it has a ColorChange for unused extruder from current print to end of the print
@ -2112,15 +2138,15 @@ ConflictType TickCodeInfo::is_conflict_tick(const TickCode& tick, t_mode out_mod
// We should mark a tick as a "Redundant",
// if it has a ColorChange for extruder that has not been used before
if (mode == t_mode::MultiAsSingle && tick.extruder != std::max<int>(only_extruder, 1) )
if (mode == MultiAsSingle && tick.extruder != std::max<int>(only_extruder, 1) )
{
auto it = ticks.lower_bound( tick );
if (it == ticks.begin() && it->gcode == ToolChangeCode && tick.extruder == it->extruder)
if (it == ticks.begin() && it->type == ToolChange && tick.extruder == it->extruder)
return ctNone;
while (it != ticks.begin()) {
--it;
if (it->gcode == ToolChangeCode && tick.extruder == it->extruder)
if (it->type == ToolChange && tick.extruder == it->extruder)
return ctNone;
}
@ -2129,7 +2155,7 @@ ConflictType TickCodeInfo::is_conflict_tick(const TickCode& tick, t_mode out_mod
}
// check ToolChange tick
if (mode == t_mode::MultiAsSingle && tick.gcode == ToolChangeCode)
if (mode == MultiAsSingle && tick.type == ToolChange)
{
// We should mark a tick as a "MeaninglessToolChange",
// if it has a ToolChange to the same extruder
@ -2139,7 +2165,7 @@ ConflictType TickCodeInfo::is_conflict_tick(const TickCode& tick, t_mode out_mod
while (it != ticks.begin()) {
--it;
if (it->gcode == ToolChangeCode)
if (it->type == ToolChange)
return tick.extruder == it->extruder ? ctMeaninglessToolChange : ctNone;
}
}

View File

@ -17,6 +17,8 @@ class wxMenu;
namespace Slic3r {
using namespace CustomGCode;
namespace DoubleSlider {
/* For exporting GCode in GCodeWriter is used XYZF_NUM(val) = PRECISION(val, 3) for XYZ values.
@ -73,17 +75,16 @@ enum DrawMode
dmSequentialFffPrint,
};
using t_mode = CustomGCode::Mode;
struct TickCode
{
bool operator<(const TickCode& other) const { return other.tick > this->tick; }
bool operator>(const TickCode& other) const { return other.tick < this->tick; }
int tick = 0;
std::string gcode = ColorChangeCode;
Type type = ColorChange;
int extruder = 0;
std::string color;
std::string extra;
};
class TickCodeInfo
@ -97,27 +98,27 @@ class TickCodeInfo
std::vector<std::string>* m_colors {nullptr};
std::string get_color_for_tick(TickCode tick, const std::string& code, const int extruder);
std::string get_color_for_tick(TickCode tick, Type type, const int extruder);
public:
std::set<TickCode> ticks {};
t_mode mode = t_mode::Undef;
Mode mode = Undef;
bool empty() const { return ticks.empty(); }
void set_pause_print_msg(const std::string& message) { pause_print_msg = message; }
bool add_tick(const int tick, std::string& code, int extruder, double print_z);
bool add_tick(const int tick, Type type, int extruder, double print_z);
bool edit_tick(std::set<TickCode>::iterator it, double print_z);
void switch_code(const std::string& code_from, const std::string& code_to);
bool switch_code_for_tick(std::set<TickCode>::iterator it, const std::string& code_to, const int extruder);
void erase_all_ticks_with_code(const std::string& gcode);
void switch_code(Type type_from, Type type_to);
bool switch_code_for_tick(std::set<TickCode>::iterator it, Type type_to, const int extruder);
void erase_all_ticks_with_code(Type type);
bool has_tick_with_code(const std::string& gcode);
ConflictType is_conflict_tick(const TickCode& tick, t_mode out_mode, int only_extruder, double print_z);
bool has_tick_with_code(Type type);
ConflictType is_conflict_tick(const TickCode& tick, Mode out_mode, int only_extruder, double print_z);
// Get used extruders for tick.
// Means all extruders(tools) which will be used during printing from current tick to the end
std::set<int> get_used_extruders_for_tick(int tick, int only_extruder, double print_z, t_mode force_mode = t_mode::Undef) const;
std::set<int> get_used_extruders_for_tick(int tick, int only_extruder, double print_z, Mode force_mode = Undef) const;
void suppress_plus (bool suppress) { m_suppress_plus = suppress; }
void suppress_minus(bool suppress) { m_suppress_minus = suppress; }
@ -205,13 +206,13 @@ public:
void SetSliderValues(const std::vector<double>& values) { m_values = values; }
void ChangeOneLayerLock();
CustomGCode::Info GetTicksValues() const;
void SetTicksValues(const Slic3r::CustomGCode::Info &custom_gcode_per_print_z);
Info GetTicksValues() const;
void SetTicksValues(const Info &custom_gcode_per_print_z);
void SetDrawMode(bool is_sla_print, bool is_sequential_print);
void SetManipulationMode(t_mode mode) { m_mode = mode; }
t_mode GetManipulationMode() const { return m_mode; }
void SetManipulationMode(Mode mode) { m_mode = mode; }
Mode GetManipulationMode() const { return m_mode; }
void SetModeAndOnlyExtruder(const bool is_one_extruder_printed_model, const int only_extruder);
void SetExtruderColors(const std::vector<std::string>& extruder_colors);
@ -235,7 +236,7 @@ public:
void OnRightDown(wxMouseEvent& event);
void OnRightUp(wxMouseEvent& event);
void add_code_as_tick(std::string code, int selected_extruder = -1);
void add_code_as_tick(Type type, int selected_extruder = -1);
// add default action for tick, when press "+"
void add_current_tick(bool call_from_keyboard = false);
// delete current tick, when press "-"
@ -293,7 +294,7 @@ private:
void get_size(int *w, int *h);
double get_double_value(const SelectedSlider& selection);
wxString get_tooltip(int tick = -1);
int get_edited_tick_for_position(wxPoint pos, const std::string& gcode = ColorChangeCode);
int get_edited_tick_for_position(wxPoint pos, Type type = ColorChange);
std::string get_color_for_tool_change_tick(std::set<TickCode>::const_iterator it) const;
std::string get_color_for_color_change_tick(std::set<TickCode>::const_iterator it) const;
@ -305,8 +306,8 @@ private:
// Use those values to disable selection of active extruders
std::array<int, 2> get_active_extruders_for_tick(int tick) const;
void post_ticks_changed_event(const std::string& gcode = "");
bool check_ticks_changed_event(const std::string& gcode);
void post_ticks_changed_event(Type type = Custom);
bool check_ticks_changed_event(Type type);
void append_change_extruder_menu_item (wxMenu*, bool switch_current_code = false);
void append_add_color_change_menu_item(wxMenu*, bool switch_current_code = false);
@ -338,7 +339,7 @@ private:
DrawMode m_draw_mode = dmRegular;
t_mode m_mode = t_mode::SingleExtruder;
Mode m_mode = SingleExtruder;
int m_only_extruder = -1;
MouseAction m_mouse = maNone;

View File

@ -916,7 +916,7 @@ void GLCanvas3D::LegendTexture::fill_color_print_legend_items( const GLCanvas3D
std::vector<double> print_zs = canvas.get_current_print_zs(true);
for (auto custom_code : custom_gcode_per_print_z)
{
if (custom_code.gcode != ColorChangeCode)
if (custom_code.type != CustomGCode::ColorChange)
continue;
auto lower_b = std::lower_bound(print_zs.begin(), print_zs.end(), custom_code.print_z - Slic3r::DoubleSlider::epsilon());
@ -989,7 +989,7 @@ void GLCanvas3D::LegendTexture::fill_color_print_legend_items( const GLCanvas3D
int cnt = custom_gcode_per_print_z.size();
int color_change_idx = color_cnt - extruders_cnt;
for (int i = cnt-1; i >= 0; --i)
if (custom_gcode_per_print_z[i].gcode == ColorChangeCode) {
if (custom_gcode_per_print_z[i].type == CustomGCode::ColorChange) {
::memcpy((void*)(colors.data() + color_pos), (const void*)(colors_in.data() + color_in_pos), 4 * sizeof(float));
color_pos += 4;
color_in_pos -= 4;
@ -6003,7 +6003,7 @@ void GLCanvas3D::_load_print_object_toolpaths(const PrintObject& print_object, c
// For coloring by a color_print(M600), return a parsed color.
bool color_by_color_print() const { return color_print_values!=nullptr; }
const size_t color_print_color_idx_by_layer_idx(const size_t layer_idx) const {
const CustomGCode::Item value{layers[layer_idx]->print_z + EPSILON, "", 0, ""};
const CustomGCode::Item value{layers[layer_idx]->print_z + EPSILON, CustomGCode::Custom, 0, ""};
auto it = std::lower_bound(color_print_values->begin(), color_print_values->end(), value);
return (it - color_print_values->begin()) % number_tools();
}
@ -6017,36 +6017,36 @@ void GLCanvas3D::_load_print_object_toolpaths(const PrintObject& print_object, c
{ return fabs(code.print_z - print_z) < EPSILON; });
if (it != color_print_values->end())
{
const std::string& code = it->gcode;
CustomGCode::Type type = it->type;
// pause print or custom Gcode
if (code == PausePrintCode ||
(code != ColorChangeCode && code != ToolChangeCode))
if (type == CustomGCode::PausePrint ||
(type != CustomGCode::ColorChange && type != CustomGCode::ToolChange))
return number_tools()-1; // last color item is a gray color for pause print or custom G-code
// change tool (extruder)
if (code == ToolChangeCode)
if (type == CustomGCode::ToolChange)
return get_color_idx_for_tool_change(it, extruder);
// change color for current extruder
if (code == ColorChangeCode) {
if (type == CustomGCode::ColorChange) {
int color_idx = get_color_idx_for_color_change(it, extruder);
if (color_idx >= 0)
return color_idx;
}
}
const CustomGCode::Item value{print_z + EPSILON, "", 0, ""};
const CustomGCode::Item value{print_z + EPSILON, CustomGCode::Custom, 0, ""};
it = std::lower_bound(color_print_values->begin(), color_print_values->end(), value);
while (it != color_print_values->begin())
{
--it;
// change color for current extruder
if (it->gcode == ColorChangeCode) {
if (it->type == CustomGCode::ColorChange) {
int color_idx = get_color_idx_for_color_change(it, extruder);
if (color_idx >= 0)
return color_idx;
}
// change tool (extruder)
if (it->gcode == ToolChangeCode)
if (it->type == CustomGCode::ToolChange)
return get_color_idx_for_tool_change(it, extruder);
}
@ -6059,7 +6059,7 @@ void GLCanvas3D::_load_print_object_toolpaths(const PrintObject& print_object, c
int shift = 0;
while (it != color_print_values->begin()) {
--it;
if (it->gcode == ColorChangeCode)
if (it->type == CustomGCode::ColorChange)
shift++;
}
return extruders_cnt + shift;
@ -6074,7 +6074,7 @@ void GLCanvas3D::_load_print_object_toolpaths(const PrintObject& print_object, c
auto it_n = it;
while (it_n != color_print_values->begin()) {
--it_n;
if (it_n->gcode == ColorChangeCode && it_n->extruder == current_extruder)
if (it_n->type == CustomGCode::ColorChange && it_n->extruder == current_extruder)
return get_m600_color_idx(it_n);
}
@ -6090,7 +6090,7 @@ void GLCanvas3D::_load_print_object_toolpaths(const PrintObject& print_object, c
bool is_tool_change = false;
while (it_n != color_print_values->begin()) {
--it_n;
if (it_n->gcode == ToolChangeCode) {
if (it_n->type == CustomGCode::ToolChange) {
is_tool_change = true;
if (it_n->extruder == it->extruder || (it_n->extruder == 0 && it->extruder == extruder))
return get_m600_color_idx(it);

View File

@ -715,24 +715,16 @@ void GUI_App::update_ui_from_settings()
void GUI_App::persist_window_geometry(wxTopLevelWindow *window, bool default_maximized)
{
const std::string name = into_u8(window->GetName());
wxTopLevelWindow* settings_dlg = dynamic_cast<MainFrame*>(window)->m_settings_dialog;
const std::string settings_dlg_name = "settings_dialog";
window->Bind(wxEVT_CLOSE_WINDOW, [=](wxCloseEvent &event) {
window_pos_save(window, name);
if (settings_dlg)
window_pos_save(settings_dlg, settings_dlg_name);
event.Skip();
});
window_pos_restore(window, name, default_maximized);
if (settings_dlg)
window_pos_restore(settings_dlg, settings_dlg_name, default_maximized);
on_window_geometry(window, [=]() {
window_pos_sanitize(window);
if (settings_dlg)
window_pos_sanitize(settings_dlg);
});
}

View File

@ -578,10 +578,10 @@ void Preview::update_view_type(bool slice_completed)
const wxString& choice = !wxGetApp().plater()->model().custom_gcode_per_print_z.gcodes.empty() /*&&
(wxGetApp().extruders_edited_cnt()==1 || !slice_completed) */?
_(L("Color Print")) :
_L("Color Print") :
config.option<ConfigOptionFloats>("wiping_volumes_matrix")->values.size() > 1 ?
_(L("Tool")) :
_(L("Feature type"));
_L("Tool") :
_L("Feature type");
int type = m_choice_view_type->FindString(choice);
if (m_choice_view_type->GetSelection() != type) {
@ -590,6 +590,8 @@ void Preview::update_view_type(bool slice_completed)
m_gcode_preview_data->extrusion.view_type = (GCodePreviewData::Extrusion::EViewType)type;
m_preferred_color_mode = "feature";
}
reload_print();
}
void Preview::create_double_slider()
@ -618,8 +620,6 @@ void Preview::create_double_slider()
m_schedule_background_process();
update_view_type(false);
reload_print();
});
}

View File

@ -205,6 +205,8 @@ DPIFrame(NULL, wxID_ANY, "", wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_S
});
wxGetApp().persist_window_geometry(this, true);
if (m_settings_dialog != nullptr)
wxGetApp().persist_window_geometry(m_settings_dialog, true);
update_ui_from_settings(); // FIXME (?)
@ -244,8 +246,14 @@ void MainFrame::shutdown()
// In addition, there were some crashes due to the Paint events sent to already destructed windows.
this->Show(false);
if (m_settings_dialog)
if (m_settings_dialog != nullptr)
{
if (m_settings_dialog->IsShown())
// call Close() to trigger call to lambda defined into GUI_App::persist_window_geometry()
m_settings_dialog->Close();
m_settings_dialog->Destroy();
}
// Stop the background thread (Windows and Linux).
// Disconnect from a 3DConnextion driver (OSX).
@ -1444,7 +1452,8 @@ std::string MainFrame::get_dir_name(const wxString &full_name) const
// ----------------------------------------------------------------------------
SettingsDialog::SettingsDialog(MainFrame* mainframe)
: DPIDialog(nullptr, wxID_ANY, wxString(SLIC3R_APP_NAME) + " - " + _L("Settings")),
: DPIDialog(nullptr, wxID_ANY, wxString(SLIC3R_APP_NAME) + " - " + _L("Settings"), wxDefaultPosition, wxDefaultSize,
wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER | wxMINIMIZE_BOX | wxMAXIMIZE_BOX | wxDIALOG_NO_PARENT, "settings_dialog"),
m_main_frame(mainframe)
{
this->SetFont(wxGetApp().normal_font());

View File

@ -1324,22 +1324,22 @@ void Sidebar::update_sliced_info_sizer()
wxString str_color = _L("Color");
wxString str_pause = _L("Pause");
auto fill_labels = [str_color, str_pause](const std::vector<std::pair<CustomGcodeType, std::string>>& times,
auto fill_labels = [str_color, str_pause](const std::vector<std::pair<CustomGCode::Type, std::string>>& times,
wxString& new_label, wxString& info_text)
{
int color_change_count = 0;
for (auto time : times)
if (time.first == cgtColorChange)
if (time.first == CustomGCode::ColorChange)
color_change_count++;
for (int i = (int)times.size() - 1; i >= 0; --i)
{
if (i == 0 || times[i - 1].first == cgtPausePrint)
if (i == 0 || times[i - 1].first == CustomGCode::PausePrint)
new_label += format_wxstr("\n - %1%%2%", str_color + " ", color_change_count);
else if (times[i - 1].first == cgtColorChange)
else if (times[i - 1].first == CustomGCode::ColorChange)
new_label += format_wxstr("\n - %1%%2%", str_color + " ", color_change_count--);
if (i != (int)times.size() - 1 && times[i].first == cgtPausePrint)
if (i != (int)times.size() - 1 && times[i].first == CustomGCode::PausePrint)
new_label += format_wxstr(" -> %1%", str_pause);
info_text += format_wxstr("\n%1%", times[i].second);
@ -5336,7 +5336,7 @@ std::vector<std::string> Plater::get_colors_for_color_print() const
colors.reserve(colors.size() + p->model.custom_gcode_per_print_z.gcodes.size());
for (const CustomGCode::Item& code : p->model.custom_gcode_per_print_z.gcodes)
if (code.gcode == ColorChangeCode)
if (code.type == CustomGCode::ColorChange)
colors.emplace_back(code.color);
return colors;

View File

@ -461,6 +461,7 @@ const std::vector<std::string>& Preset::printer_options()
"use_firmware_retraction", "use_volumetric_e", "variable_layer_height",
"host_type", "print_host", "printhost_apikey", "printhost_cafile",
"single_extruder_multi_material", "start_gcode", "end_gcode", "before_layer_gcode", "layer_gcode", "toolchange_gcode",
"color_change_gcode", "pause_print_gcode", "template_custom_gcode",
"between_objects_gcode", "printer_vendor", "printer_model", "printer_variant", "printer_notes", "cooling_tube_retraction",
"cooling_tube_length", "high_current_on_filament_swap", "parking_pos_retraction", "extra_loading_move", "max_print_height",
"default_print_profile", "inherits",

View File

@ -34,20 +34,6 @@ namespace Search {
#define SEARCH_SUPPORTS_MARKUP
#endif
static const std::vector<std::wstring>& NameByType()
{
static std::vector<std::wstring> data;
if (data.empty()) {
data.assign(Preset::TYPE_COUNT, std::wstring());
data[Preset::TYPE_PRINT ] = _L("Print" ).ToStdWstring();
data[Preset::TYPE_FILAMENT ] = _L("Filament" ).ToStdWstring();
data[Preset::TYPE_SLA_MATERIAL ] = _L("Material" ).ToStdWstring();
data[Preset::TYPE_SLA_PRINT ] = _L("Print" ).ToStdWstring();
data[Preset::TYPE_PRINTER ] = _L("Printer" ).ToStdWstring();
};
return data;
}
static char marker_by_type(Preset::Type type, PrinterTechnology pt)
{
switch(type) {

View File

@ -2218,6 +2218,21 @@ void TabPrinter::build_fff()
option.opt.height = gcode_field_height;//150;
optgroup->append_single_option_line(option);
optgroup = page->new_optgroup(L("Color Change G-code"), 0);
option = optgroup->get_option("color_change_gcode");
option.opt.height = gcode_field_height;//150;
optgroup->append_single_option_line(option);
optgroup = page->new_optgroup(L("Pause Print G-code"), 0);
option = optgroup->get_option("pause_print_gcode");
option.opt.height = gcode_field_height;//150;
optgroup->append_single_option_line(option);
optgroup = page->new_optgroup(L("Template Custom G-code"), 0);
option = optgroup->get_option("template_custom_gcode");
option.opt.height = gcode_field_height;//150;
optgroup->append_single_option_line(option);
page = add_options_page(L("Notes"), "note.png");
optgroup = page->new_optgroup(L("Notes"), 0);
option = optgroup->get_option("printer_notes");