mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-10-22 16:21:24 -06:00
Removed the GCodePreviewData from the Print class, it does not belong here,
as the GCode is generated outside of the Print class. Exported the GCodePreviewData as GCode::PreviewData to Perl. When exporting the G-code with a command line Slic3r, the GCodeAnalyzer is now supressed for performance reasons. Removed obsolete Perl module Slic3r::GUI::Plater::3DToolpaths.
This commit is contained in:
parent
3a6436f6f0
commit
b1f5e7e8fa
20 changed files with 166 additions and 401 deletions
|
@ -348,7 +348,7 @@ std::vector<std::pair<coordf_t, std::vector<GCode::LayerToPrint>>> GCode::collec
|
|||
return layers_to_print;
|
||||
}
|
||||
|
||||
void GCode::do_export(Print *print, const char *path)
|
||||
void GCode::do_export(Print *print, const char *path, GCodePreviewData *preview_data)
|
||||
{
|
||||
PROFILE_CLEAR();
|
||||
|
||||
|
@ -363,7 +363,7 @@ void GCode::do_export(Print *print, const char *path)
|
|||
throw std::runtime_error(std::string("G-code export to ") + path + " failed.\nCannot open the file for writing.\n");
|
||||
|
||||
this->m_placeholder_parser_failed_templates.clear();
|
||||
this->_do_export(*print, file);
|
||||
this->_do_export(*print, file, preview_data);
|
||||
fflush(file);
|
||||
if (ferror(file)) {
|
||||
fclose(file);
|
||||
|
@ -394,7 +394,7 @@ void GCode::do_export(Print *print, const char *path)
|
|||
PROFILE_OUTPUT(debug_out_path("gcode-export-profile.txt").c_str());
|
||||
}
|
||||
|
||||
void GCode::_do_export(Print &print, FILE *file)
|
||||
void GCode::_do_export(Print &print, FILE *file, GCodePreviewData *preview_data)
|
||||
{
|
||||
PROFILE_FUNC();
|
||||
|
||||
|
@ -404,6 +404,7 @@ void GCode::_do_export(Print &print, FILE *file)
|
|||
|
||||
// resets analyzer
|
||||
m_analyzer.reset();
|
||||
m_enable_analyzer = preview_data != nullptr;
|
||||
|
||||
// resets analyzer's tracking data
|
||||
m_last_mm3_per_mm = GCodeAnalyzer::Default_mm3_per_mm;
|
||||
|
@ -820,7 +821,8 @@ void GCode::_do_export(Print &print, FILE *file)
|
|||
}
|
||||
|
||||
// starts analizer calculations
|
||||
m_analyzer.calc_gcode_preview_data(print);
|
||||
if (preview_data != nullptr)
|
||||
m_analyzer.calc_gcode_preview_data(*preview_data);
|
||||
}
|
||||
|
||||
std::string GCode::placeholder_parser_process(const std::string &name, const std::string &templ, unsigned int current_extruder_id, const DynamicConfig *config_override)
|
||||
|
|
|
@ -26,6 +26,7 @@ namespace Slic3r {
|
|||
|
||||
// Forward declarations.
|
||||
class GCode;
|
||||
class GCodePreviewData;
|
||||
|
||||
class AvoidCrossingPerimeters {
|
||||
public:
|
||||
|
@ -119,7 +120,7 @@ public:
|
|||
m_enable_loop_clipping(true),
|
||||
m_enable_cooling_markers(false),
|
||||
m_enable_extrusion_role_markers(false),
|
||||
m_enable_analyzer(true),
|
||||
m_enable_analyzer(false),
|
||||
m_layer_count(0),
|
||||
m_layer_index(-1),
|
||||
m_layer(nullptr),
|
||||
|
@ -136,7 +137,7 @@ public:
|
|||
~GCode() {}
|
||||
|
||||
// throws std::runtime_exception
|
||||
void do_export(Print *print, const char *path);
|
||||
void do_export(Print *print, const char *path, GCodePreviewData *preview_data = nullptr);
|
||||
|
||||
// Exported for the helper classes (OozePrevention, Wipe) and for the Perl binding for unit tests.
|
||||
const Pointf& origin() const { return m_origin; }
|
||||
|
@ -153,8 +154,6 @@ public:
|
|||
// inside the generated string and after the G-code export finishes.
|
||||
std::string placeholder_parser_process(const std::string &name, const std::string &templ, unsigned int current_extruder_id, const DynamicConfig *config_override = nullptr);
|
||||
bool enable_cooling_markers() const { return m_enable_cooling_markers; }
|
||||
bool enable_analyzer() const { return m_enable_analyzer; }
|
||||
void enable_analyzer(bool enable) { m_enable_analyzer = enable; }
|
||||
|
||||
// For Perl bindings, to be used exclusively by unit tests.
|
||||
unsigned int layer_count() const { return m_layer_count; }
|
||||
|
@ -162,7 +161,7 @@ public:
|
|||
void apply_print_config(const PrintConfig &print_config);
|
||||
|
||||
protected:
|
||||
void _do_export(Print &print, FILE *file);
|
||||
void _do_export(Print &print, FILE *file, GCodePreviewData *preview_data);
|
||||
|
||||
// Object and support extrusions of the same PrintObject at the same print_z.
|
||||
struct LayerToPrint
|
||||
|
|
|
@ -123,22 +123,22 @@ const std::string& GCodeAnalyzer::process_gcode(const std::string& gcode)
|
|||
return m_process_output;
|
||||
}
|
||||
|
||||
void GCodeAnalyzer::calc_gcode_preview_data(Print& print)
|
||||
void GCodeAnalyzer::calc_gcode_preview_data(GCodePreviewData& preview_data)
|
||||
{
|
||||
// resets preview data
|
||||
print.gcode_preview.reset();
|
||||
preview_data.reset();
|
||||
|
||||
// calculates extrusion layers
|
||||
_calc_gcode_preview_extrusion_layers(print);
|
||||
_calc_gcode_preview_extrusion_layers(preview_data);
|
||||
|
||||
// calculates travel
|
||||
_calc_gcode_preview_travel(print);
|
||||
_calc_gcode_preview_travel(preview_data);
|
||||
|
||||
// calculates retractions
|
||||
_calc_gcode_preview_retractions(print);
|
||||
_calc_gcode_preview_retractions(preview_data);
|
||||
|
||||
// calculates unretractions
|
||||
_calc_gcode_preview_unretractions(print);
|
||||
_calc_gcode_preview_unretractions(preview_data);
|
||||
}
|
||||
|
||||
bool GCodeAnalyzer::is_valid_extrusion_role(ExtrusionRole role)
|
||||
|
@ -601,7 +601,7 @@ bool GCodeAnalyzer::_is_valid_extrusion_role(int value) const
|
|||
return ((int)erNone <= value) && (value <= (int)erMixed);
|
||||
}
|
||||
|
||||
void GCodeAnalyzer::_calc_gcode_preview_extrusion_layers(Print& print)
|
||||
void GCodeAnalyzer::_calc_gcode_preview_extrusion_layers(GCodePreviewData& preview_data)
|
||||
{
|
||||
struct Helper
|
||||
{
|
||||
|
@ -619,7 +619,7 @@ void GCodeAnalyzer::_calc_gcode_preview_extrusion_layers(Print& print)
|
|||
return layers.back();
|
||||
}
|
||||
|
||||
static void store_polyline(const Polyline& polyline, const Metadata& data, float z, Print& print)
|
||||
static void store_polyline(const Polyline& polyline, const Metadata& data, float z, GCodePreviewData& preview_data)
|
||||
{
|
||||
// if the polyline is valid, create the extrusion path from it and store it
|
||||
if (polyline.is_valid())
|
||||
|
@ -629,7 +629,7 @@ void GCodeAnalyzer::_calc_gcode_preview_extrusion_layers(Print& print)
|
|||
path.feedrate = data.feedrate;
|
||||
path.extruder_id = data.extruder_id;
|
||||
|
||||
get_layer_at_z(print.gcode_preview.extrusion.layers, z).paths.push_back(path);
|
||||
get_layer_at_z(preview_data.extrusion.layers, z).paths.push_back(path);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -653,7 +653,7 @@ void GCodeAnalyzer::_calc_gcode_preview_extrusion_layers(Print& print)
|
|||
{
|
||||
// store current polyline
|
||||
polyline.remove_duplicate_points();
|
||||
Helper::store_polyline(polyline, data, z, print);
|
||||
Helper::store_polyline(polyline, data, z, preview_data);
|
||||
|
||||
// reset current polyline
|
||||
polyline = Polyline();
|
||||
|
@ -679,23 +679,24 @@ void GCodeAnalyzer::_calc_gcode_preview_extrusion_layers(Print& print)
|
|||
|
||||
// store last polyline
|
||||
polyline.remove_duplicate_points();
|
||||
Helper::store_polyline(polyline, data, z, print);
|
||||
Helper::store_polyline(polyline, data, z, preview_data);
|
||||
|
||||
// updates preview ranges data
|
||||
print.gcode_preview.extrusion.ranges.height.set_from(height_range);
|
||||
print.gcode_preview.extrusion.ranges.width.set_from(width_range);
|
||||
print.gcode_preview.extrusion.ranges.feedrate.set_from(feedrate_range);
|
||||
preview_data.extrusion.ranges.height.set_from(height_range);
|
||||
preview_data.extrusion.ranges.width.set_from(width_range);
|
||||
preview_data.extrusion.ranges.feedrate.set_from(feedrate_range);
|
||||
}
|
||||
|
||||
void GCodeAnalyzer::_calc_gcode_preview_travel(Print& print)
|
||||
void GCodeAnalyzer::_calc_gcode_preview_travel(GCodePreviewData& preview_data)
|
||||
{
|
||||
struct Helper
|
||||
{
|
||||
static void store_polyline(const Polyline3& polyline, GCodePreviewData::Travel::EType type, GCodePreviewData::Travel::Polyline::EDirection direction, float feedrate, unsigned int extruder_id, Print& print)
|
||||
static void store_polyline(const Polyline3& polyline, GCodePreviewData::Travel::EType type, GCodePreviewData::Travel::Polyline::EDirection direction,
|
||||
float feedrate, unsigned int extruder_id, GCodePreviewData& preview_data)
|
||||
{
|
||||
// if the polyline is valid, store it
|
||||
if (polyline.is_valid())
|
||||
print.gcode_preview.travel.polylines.emplace_back(type, direction, feedrate, extruder_id, polyline);
|
||||
preview_data.travel.polylines.emplace_back(type, direction, feedrate, extruder_id, polyline);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -720,7 +721,7 @@ void GCodeAnalyzer::_calc_gcode_preview_travel(Print& print)
|
|||
{
|
||||
// store current polyline
|
||||
polyline.remove_duplicate_points();
|
||||
Helper::store_polyline(polyline, type, direction, feedrate, extruder_id, print);
|
||||
Helper::store_polyline(polyline, type, direction, feedrate, extruder_id, preview_data);
|
||||
|
||||
// reset current polyline
|
||||
polyline = Polyline3();
|
||||
|
@ -742,10 +743,10 @@ void GCodeAnalyzer::_calc_gcode_preview_travel(Print& print)
|
|||
|
||||
// store last polyline
|
||||
polyline.remove_duplicate_points();
|
||||
Helper::store_polyline(polyline, type, direction, feedrate, extruder_id, print);
|
||||
Helper::store_polyline(polyline, type, direction, feedrate, extruder_id, preview_data);
|
||||
}
|
||||
|
||||
void GCodeAnalyzer::_calc_gcode_preview_retractions(Print& print)
|
||||
void GCodeAnalyzer::_calc_gcode_preview_retractions(GCodePreviewData& preview_data)
|
||||
{
|
||||
TypeToMovesMap::iterator retraction_moves = m_moves_map.find(GCodeMove::Retract);
|
||||
if (retraction_moves == m_moves_map.end())
|
||||
|
@ -755,11 +756,11 @@ void GCodeAnalyzer::_calc_gcode_preview_retractions(Print& print)
|
|||
{
|
||||
// store position
|
||||
Point3 position(scale_(move.start_position.x), scale_(move.start_position.y), scale_(move.start_position.z));
|
||||
print.gcode_preview.retraction.positions.emplace_back(position, move.data.width, move.data.height);
|
||||
preview_data.retraction.positions.emplace_back(position, move.data.width, move.data.height);
|
||||
}
|
||||
}
|
||||
|
||||
void GCodeAnalyzer::_calc_gcode_preview_unretractions(Print& print)
|
||||
void GCodeAnalyzer::_calc_gcode_preview_unretractions(GCodePreviewData& preview_data)
|
||||
{
|
||||
TypeToMovesMap::iterator unretraction_moves = m_moves_map.find(GCodeMove::Unretract);
|
||||
if (unretraction_moves == m_moves_map.end())
|
||||
|
@ -769,7 +770,7 @@ void GCodeAnalyzer::_calc_gcode_preview_unretractions(Print& print)
|
|||
{
|
||||
// store position
|
||||
Point3 position(scale_(move.start_position.x), scale_(move.start_position.y), scale_(move.start_position.z));
|
||||
print.gcode_preview.unretraction.positions.emplace_back(position, move.data.width, move.data.height);
|
||||
preview_data.unretraction.positions.emplace_back(position, move.data.width, move.data.height);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
namespace Slic3r {
|
||||
|
||||
class Print;
|
||||
class GCodePreviewData;
|
||||
|
||||
class GCodeAnalyzer
|
||||
{
|
||||
|
@ -116,7 +116,7 @@ public:
|
|||
const std::string& process_gcode(const std::string& gcode);
|
||||
|
||||
// Calculates all data needed for gcode visualization
|
||||
void calc_gcode_preview_data(Print& print);
|
||||
void calc_gcode_preview_data(GCodePreviewData& preview_data);
|
||||
|
||||
static bool is_valid_extrusion_role(ExtrusionRole role);
|
||||
|
||||
|
@ -216,10 +216,10 @@ private:
|
|||
// Checks if the given int is a valid extrusion role (contained into enum ExtrusionRole)
|
||||
bool _is_valid_extrusion_role(int value) const;
|
||||
|
||||
void _calc_gcode_preview_extrusion_layers(Print& print);
|
||||
void _calc_gcode_preview_travel(Print& print);
|
||||
void _calc_gcode_preview_retractions(Print& print);
|
||||
void _calc_gcode_preview_unretractions(Print& print);
|
||||
void _calc_gcode_preview_extrusion_layers(GCodePreviewData& preview_data);
|
||||
void _calc_gcode_preview_travel(GCodePreviewData& preview_data);
|
||||
void _calc_gcode_preview_retractions(GCodePreviewData& preview_data);
|
||||
void _calc_gcode_preview_unretractions(GCodePreviewData& preview_data);
|
||||
};
|
||||
|
||||
} // namespace Slic3r
|
||||
|
|
|
@ -66,89 +66,6 @@ bool Print::reload_model_instances()
|
|||
return invalidated;
|
||||
}
|
||||
|
||||
void Print::clear_gcode_preview_data()
|
||||
{
|
||||
gcode_preview.reset();
|
||||
}
|
||||
|
||||
void Print::set_gcode_preview_type(unsigned char type)
|
||||
{
|
||||
if ((0 <= type) && (type < GCodePreviewData::Extrusion::Num_View_Types))
|
||||
gcode_preview.extrusion.view_type = (GCodePreviewData::Extrusion::EViewType)type;
|
||||
}
|
||||
|
||||
void Print::set_gcode_preview_extrusion_flags(unsigned int flags)
|
||||
{
|
||||
gcode_preview.extrusion.role_flags = flags;
|
||||
}
|
||||
|
||||
bool Print::is_gcode_preview_extrusion_role_enabled(ExtrusionRole role)
|
||||
{
|
||||
return gcode_preview.extrusion.is_role_flag_set(role);
|
||||
}
|
||||
|
||||
void Print::set_gcode_preview_travel_visible(bool visible)
|
||||
{
|
||||
gcode_preview.travel.is_visible = visible;
|
||||
}
|
||||
|
||||
void Print::set_gcode_preview_retractions_visible(bool visible)
|
||||
{
|
||||
gcode_preview.retraction.is_visible = visible;
|
||||
}
|
||||
|
||||
void Print::set_gcode_preview_unretractions_visible(bool visible)
|
||||
{
|
||||
gcode_preview.unretraction.is_visible = visible;
|
||||
}
|
||||
|
||||
void Print::set_gcode_preview_shells_visible(bool visible)
|
||||
{
|
||||
gcode_preview.shell.is_visible = visible;
|
||||
}
|
||||
|
||||
void Print::set_gcode_extrusion_paths_colors(const std::vector<std::string>& colors)
|
||||
{
|
||||
unsigned int size = (unsigned int)colors.size();
|
||||
|
||||
if (size % 2 != 0)
|
||||
return;
|
||||
|
||||
for (unsigned int i = 0; i < size; i += 2)
|
||||
{
|
||||
const std::string& color_str = colors[i + 1];
|
||||
|
||||
if (color_str.size() == 6)
|
||||
{
|
||||
bool valid = true;
|
||||
for (int c = 0; c < 6; ++c)
|
||||
{
|
||||
if (::isxdigit(color_str[c]) == 0)
|
||||
{
|
||||
valid = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (valid)
|
||||
{
|
||||
unsigned int color;
|
||||
std::stringstream ss;
|
||||
ss << std::hex << color_str;
|
||||
ss >> color;
|
||||
|
||||
float den = 1.0f / 255.0f;
|
||||
|
||||
float r = (float)((color & 0xFF0000) >> 16) * den;
|
||||
float g = (float)((color & 0x00FF00) >> 8) * den;
|
||||
float b = (float)(color & 0x0000FF) * den;
|
||||
|
||||
gcode_preview.set_extrusion_role_color(colors[i], r, g, b, 1.0f);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
PrintRegion* Print::add_region()
|
||||
{
|
||||
regions.push_back(new PrintRegion(this));
|
||||
|
|
|
@ -15,7 +15,6 @@
|
|||
#include "Slicing.hpp"
|
||||
#include "GCode/ToolOrdering.hpp"
|
||||
#include "GCode/WipeTower.hpp"
|
||||
#include "GCode/PreviewData.hpp"
|
||||
|
||||
#include "tbb/atomic.h"
|
||||
|
||||
|
@ -241,7 +240,6 @@ public:
|
|||
|
||||
// ordered collections of extrusion paths to build skirt loops and brim
|
||||
ExtrusionEntityCollection skirt, brim;
|
||||
GCodePreviewData gcode_preview;
|
||||
|
||||
Print() : total_used_filament(0), total_extruded_volume(0) { restart(); }
|
||||
~Print() { clear_objects(); }
|
||||
|
@ -255,27 +253,6 @@ public:
|
|||
void reload_object(size_t idx);
|
||||
bool reload_model_instances();
|
||||
|
||||
void clear_gcode_preview_data();
|
||||
void set_gcode_preview_type(unsigned char type);
|
||||
void set_gcode_preview_extrusion_flags(unsigned int flags);
|
||||
bool is_gcode_preview_extrusion_role_enabled(ExtrusionRole role);
|
||||
void set_gcode_preview_travel_visible(bool visible);
|
||||
void set_gcode_preview_retractions_visible(bool visible);
|
||||
void set_gcode_preview_unretractions_visible(bool visible);
|
||||
void set_gcode_preview_shells_visible(bool visible);
|
||||
|
||||
// Sets the extrusion path colors from the given strings vector.
|
||||
// Data in the vector should be formatted as follows:
|
||||
// std::vector<std::string> role_colors =
|
||||
// { <role_1>, <color_1>,
|
||||
// <role_2>, <color_2>,
|
||||
// <role_3>, <color_3>,
|
||||
// ...
|
||||
// <role_N>, <color_N> };
|
||||
// where <role_X> should be a string from GCodePreviewData::Extrusion::Default_Extrusion_Role_Names[]
|
||||
// and <color_X> an RGB color in hex format (i.e. red = FF0000)
|
||||
void set_gcode_extrusion_paths_colors(const std::vector<std::string>& colors);
|
||||
|
||||
// methods for handling regions
|
||||
PrintRegion* get_region(size_t idx) { return regions.at(idx); }
|
||||
const PrintRegion* get_region(size_t idx) const { return regions.at(idx); }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue