mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-11 16:57:53 -06:00
gcode preview - first installment - wip
This commit is contained in:
parent
696d420dc8
commit
0f4bec8af0
25 changed files with 2552 additions and 27 deletions
|
@ -401,6 +401,18 @@ void GCode::_do_export(Print &print, FILE *file)
|
|||
// resets time estimator
|
||||
m_time_estimator.reset();
|
||||
|
||||
//############################################################################################################
|
||||
#if ENRICO_GCODE_PREVIEW
|
||||
// resets analyzer
|
||||
m_analyzer.reset();
|
||||
|
||||
// resets analyzer's tracking data
|
||||
m_last_mm3_per_mm = GCodeAnalyzer::Default_mm3_per_mm;
|
||||
m_last_width = GCodeAnalyzer::Default_Width;
|
||||
m_last_height = GCodeAnalyzer::Default_Height;
|
||||
#endif // ENRICO_GCODE_PREVIEW
|
||||
//############################################################################################################
|
||||
|
||||
// How many times will be change_layer() called?
|
||||
// change_layer() in turn increments the progress bar status.
|
||||
m_layer_count = 0;
|
||||
|
@ -809,6 +821,13 @@ void GCode::_do_export(Print &print, FILE *file)
|
|||
_write_format(file, "; %s = %s\n", key.c_str(), cfg->serialize(key).c_str());
|
||||
}
|
||||
}
|
||||
|
||||
//############################################################################################################
|
||||
#if ENRICO_GCODE_PREVIEW
|
||||
// starts analizer calculations
|
||||
m_analyzer.calc_gcode_preview_data(print);
|
||||
#endif // ENRICO_GCODE_PREVIEW
|
||||
//############################################################################################################
|
||||
}
|
||||
|
||||
std::string GCode::placeholder_parser_process(const std::string &name, const std::string &templ, unsigned int current_extruder_id, const DynamicConfig *config_override)
|
||||
|
@ -1300,12 +1319,18 @@ void GCode::process_layer(
|
|||
if (print_object == nullptr)
|
||||
// This layer is empty for this particular object, it has neither object extrusions nor support extrusions at this print_z.
|
||||
continue;
|
||||
//############################################################################################################
|
||||
#if !ENRICO_GCODE_PREVIEW
|
||||
//############################################################################################################
|
||||
if (m_enable_analyzer_markers) {
|
||||
// Store the binary pointer to the layer object directly into the G-code to be accessed by the GCodeAnalyzer.
|
||||
char buf[64];
|
||||
sprintf(buf, ";_LAYEROBJ:%p\n", m_layer);
|
||||
gcode += buf;
|
||||
}
|
||||
//############################################################################################################
|
||||
#endif // !ENRICO_GCODE_PREVIEW
|
||||
//############################################################################################################
|
||||
m_config.apply(print_object->config, true);
|
||||
m_layer = layers[layer_id].layer();
|
||||
if (m_config.avoid_crossing_perimeters)
|
||||
|
@ -1997,13 +2022,36 @@ std::string GCode::extrude_support(const ExtrusionEntityCollection &support_fill
|
|||
return gcode;
|
||||
}
|
||||
|
||||
//############################################################################################################
|
||||
#if ENRICO_GCODE_PREVIEW
|
||||
void GCode::_write(FILE* file, const char *what)
|
||||
#else
|
||||
//############################################################################################################
|
||||
void GCode::_write(FILE* file, const char *what, size_t size)
|
||||
//############################################################################################################
|
||||
#endif // ENRICO_GCODE_PREVIEW
|
||||
//############################################################################################################
|
||||
{
|
||||
//############################################################################################################
|
||||
#if ENRICO_GCODE_PREVIEW
|
||||
if (what != nullptr) {
|
||||
// apply analyzer, if enabled
|
||||
const char* gcode = m_enable_analyzer ? m_analyzer.process_gcode(what).c_str() : what;
|
||||
|
||||
// writes string to file
|
||||
fwrite(gcode, 1, ::strlen(gcode), file);
|
||||
// updates time estimator and gcode lines vector
|
||||
m_time_estimator.add_gcode_block(gcode);
|
||||
#else
|
||||
//############################################################################################################
|
||||
if (size > 0) {
|
||||
// writes string to file
|
||||
fwrite(what, 1, size, file);
|
||||
// updates time estimator and gcode lines vector
|
||||
m_time_estimator.add_gcode_block(what);
|
||||
//############################################################################################################
|
||||
#endif // ENRICO_GCODE_PREVIEW
|
||||
//############################################################################################################
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2037,7 +2085,15 @@ void GCode::_write_format(FILE* file, const char* format, ...)
|
|||
char *bufptr = buffer_dynamic ? (char*)malloc(buflen) : buffer;
|
||||
int res = ::vsnprintf(bufptr, buflen, format, args);
|
||||
if (res > 0)
|
||||
//############################################################################################################
|
||||
#if ENRICO_GCODE_PREVIEW
|
||||
_write(file, bufptr);
|
||||
#else
|
||||
//############################################################################################################
|
||||
_write(file, bufptr, res);
|
||||
//############################################################################################################
|
||||
#endif // ENRICO_GCODE_PREVIEW
|
||||
//############################################################################################################
|
||||
if (buffer_dynamic)
|
||||
free(bufptr);
|
||||
|
||||
|
@ -2122,6 +2178,60 @@ std::string GCode::_extrude(const ExtrusionPath &path, std::string description,
|
|||
double F = speed * 60; // convert mm/sec to mm/min
|
||||
|
||||
// extrude arc or line
|
||||
//############################################################################################################
|
||||
#if ENRICO_GCODE_PREVIEW
|
||||
if (m_enable_extrusion_role_markers || m_enable_analyzer)
|
||||
{
|
||||
if (path.role() != m_last_extrusion_role)
|
||||
{
|
||||
m_last_extrusion_role = path.role();
|
||||
if (m_enable_extrusion_role_markers)
|
||||
{
|
||||
char buf[32];
|
||||
sprintf(buf, ";_EXTRUSION_ROLE:%d\n", int(m_last_extrusion_role));
|
||||
gcode += buf;
|
||||
}
|
||||
if (m_enable_analyzer)
|
||||
{
|
||||
char buf[32];
|
||||
sprintf(buf, ";%s%d\n", GCodeAnalyzer::Extrusion_Role_Tag.c_str(), int(m_last_extrusion_role));
|
||||
gcode += buf;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// adds analyzer tags and updates analyzer's tracking data
|
||||
if (m_enable_analyzer)
|
||||
{
|
||||
if (m_last_mm3_per_mm != path.mm3_per_mm)
|
||||
{
|
||||
m_last_mm3_per_mm = path.mm3_per_mm;
|
||||
|
||||
char buf[32];
|
||||
sprintf(buf, ";%s%f\n", GCodeAnalyzer::Mm3_Per_Mm_Tag.c_str(), m_last_mm3_per_mm);
|
||||
gcode += buf;
|
||||
}
|
||||
|
||||
if (m_last_width != path.width)
|
||||
{
|
||||
m_last_width = path.width;
|
||||
|
||||
char buf[32];
|
||||
sprintf(buf, ";%s%f\n", GCodeAnalyzer::Width_Tag.c_str(), m_last_width);
|
||||
gcode += buf;
|
||||
}
|
||||
|
||||
if (m_last_height != path.height)
|
||||
{
|
||||
m_last_height = path.height;
|
||||
|
||||
char buf[32];
|
||||
sprintf(buf, ";%s%f\n", GCodeAnalyzer::Height_Tag.c_str(), m_last_height);
|
||||
gcode += buf;
|
||||
}
|
||||
}
|
||||
#else
|
||||
//############################################################################################################
|
||||
if (m_enable_extrusion_role_markers || m_enable_analyzer_markers) {
|
||||
if (path.role() != m_last_extrusion_role) {
|
||||
m_last_extrusion_role = path.role();
|
||||
|
@ -2130,6 +2240,10 @@ std::string GCode::_extrude(const ExtrusionPath &path, std::string description,
|
|||
gcode += buf;
|
||||
}
|
||||
}
|
||||
//############################################################################################################
|
||||
#endif // ENRICO_GCODE_PREVIEW
|
||||
//############################################################################################################
|
||||
|
||||
std::string comment;
|
||||
if (m_enable_cooling_markers) {
|
||||
if (is_bridge(path.role()))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue