GCode Preview - Travel moves colored by speed
This commit is contained in:
parent
d2d2a3fa8e
commit
c550ad2268
3 changed files with 130 additions and 44 deletions
|
@ -122,9 +122,10 @@ GCodeAnalyzer::PreviewData::Extrusion::Layer::Layer(float z, const ExtrusionPath
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
GCodeAnalyzer::PreviewData::Travel::Polyline::Polyline(EType type, EDirection direction, const Polyline3& polyline)
|
GCodeAnalyzer::PreviewData::Travel::Polyline::Polyline(EType type, EDirection direction, float feedrate, const Polyline3& polyline)
|
||||||
: type(type)
|
: type(type)
|
||||||
, direction(direction)
|
, direction(direction)
|
||||||
|
, feedrate(feedrate)
|
||||||
, polyline(polyline)
|
, polyline(polyline)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -1002,11 +1003,11 @@ void GCodeAnalyzer::_calc_gcode_preview_travel(Print& print)
|
||||||
{
|
{
|
||||||
struct Helper
|
struct Helper
|
||||||
{
|
{
|
||||||
static void store_polyline(const Polyline3& polyline, PreviewData::Travel::EType type, PreviewData::Travel::Polyline::EDirection direction, Print& print)
|
static void store_polyline(const Polyline3& polyline, PreviewData::Travel::EType type, PreviewData::Travel::Polyline::EDirection direction, float feedrate, Print& print)
|
||||||
{
|
{
|
||||||
// if the polyline is valid, store it
|
// if the polyline is valid, store it
|
||||||
if (polyline.is_valid())
|
if (polyline.is_valid())
|
||||||
print.gcode_preview.travel.polylines.emplace_back(type, direction, polyline);
|
print.gcode_preview.travel.polylines.emplace_back(type, direction, feedrate, polyline);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1018,6 +1019,7 @@ void GCodeAnalyzer::_calc_gcode_preview_travel(Print& print)
|
||||||
Pointf3 position(FLT_MAX, FLT_MAX, FLT_MAX);
|
Pointf3 position(FLT_MAX, FLT_MAX, FLT_MAX);
|
||||||
PreviewData::Travel::EType type = PreviewData::Travel::Num_Types;
|
PreviewData::Travel::EType type = PreviewData::Travel::Num_Types;
|
||||||
PreviewData::Travel::Polyline::EDirection direction = PreviewData::Travel::Polyline::Num_Directions;
|
PreviewData::Travel::Polyline::EDirection direction = PreviewData::Travel::Polyline::Num_Directions;
|
||||||
|
float feedrate = FLT_MAX;
|
||||||
|
|
||||||
// constructs the polylines while traversing the moves
|
// constructs the polylines while traversing the moves
|
||||||
for (const GCodeMove& move : travel_moves->second)
|
for (const GCodeMove& move : travel_moves->second)
|
||||||
|
@ -1025,11 +1027,11 @@ void GCodeAnalyzer::_calc_gcode_preview_travel(Print& print)
|
||||||
PreviewData::Travel::EType move_type = (move.delta_extruder < 0.0f) ? PreviewData::Travel::Retract : ((move.delta_extruder > 0.0f) ? PreviewData::Travel::Extrude : PreviewData::Travel::Move);
|
PreviewData::Travel::EType move_type = (move.delta_extruder < 0.0f) ? PreviewData::Travel::Retract : ((move.delta_extruder > 0.0f) ? PreviewData::Travel::Extrude : PreviewData::Travel::Move);
|
||||||
PreviewData::Travel::Polyline::EDirection move_direction = ((move.start_position.x != move.end_position.x) || (move.start_position.y != move.end_position.y)) ? PreviewData::Travel::Polyline::Generic : PreviewData::Travel::Polyline::Vertical;
|
PreviewData::Travel::Polyline::EDirection move_direction = ((move.start_position.x != move.end_position.x) || (move.start_position.y != move.end_position.y)) ? PreviewData::Travel::Polyline::Generic : PreviewData::Travel::Polyline::Vertical;
|
||||||
|
|
||||||
if ((type != move_type) || (direction != move_direction) || (position != move.start_position))
|
if ((type != move_type) || (direction != move_direction) || (feedrate != move.data.feedrate) || (position != move.start_position))
|
||||||
{
|
{
|
||||||
// store current polyline
|
// store current polyline
|
||||||
polyline.remove_duplicate_points();
|
polyline.remove_duplicate_points();
|
||||||
Helper::store_polyline(polyline, type, direction, print);
|
Helper::store_polyline(polyline, type, direction, feedrate, print);
|
||||||
|
|
||||||
// reset current polyline
|
// reset current polyline
|
||||||
polyline = Polyline3();
|
polyline = Polyline3();
|
||||||
|
@ -1045,11 +1047,12 @@ void GCodeAnalyzer::_calc_gcode_preview_travel(Print& print)
|
||||||
// update current values
|
// update current values
|
||||||
position = move.end_position;
|
position = move.end_position;
|
||||||
type = move_type;
|
type = move_type;
|
||||||
|
feedrate = move.data.feedrate;
|
||||||
}
|
}
|
||||||
|
|
||||||
// store last polyline
|
// store last polyline
|
||||||
polyline.remove_duplicate_points();
|
polyline.remove_duplicate_points();
|
||||||
Helper::store_polyline(polyline, type, direction, print);
|
Helper::store_polyline(polyline, type, direction, feedrate, print);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GCodeAnalyzer::_calc_gcode_preview_retractions(Print& print)
|
void GCodeAnalyzer::_calc_gcode_preview_retractions(Print& print)
|
||||||
|
|
|
@ -215,9 +215,10 @@ public:
|
||||||
|
|
||||||
EType type;
|
EType type;
|
||||||
EDirection direction;
|
EDirection direction;
|
||||||
|
float feedrate;
|
||||||
Polyline3 polyline;
|
Polyline3 polyline;
|
||||||
|
|
||||||
Polyline(EType type, EDirection direction, const Polyline3& polyline);
|
Polyline(EType type, EDirection direction, float feedrate, const Polyline3& polyline);
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef std::vector<Polyline> PolylinesList;
|
typedef std::vector<Polyline> PolylinesList;
|
||||||
|
|
|
@ -1863,59 +1863,141 @@ void _3DScene::_load_gcode_travel_paths(const Print& print, GLVolumeCollection&
|
||||||
|
|
||||||
typedef std::vector<Type> TypesList;
|
typedef std::vector<Type> TypesList;
|
||||||
|
|
||||||
|
// Helper structure for feedrate
|
||||||
|
struct Feedrate
|
||||||
|
{
|
||||||
|
float value;
|
||||||
|
GLVolume* volume;
|
||||||
|
|
||||||
|
explicit Feedrate(float value)
|
||||||
|
: value(value)
|
||||||
|
, volume(nullptr)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator == (const Feedrate& other) const
|
||||||
|
{
|
||||||
|
return value == other.value;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef std::vector<Feedrate> FeedratesList;
|
||||||
|
|
||||||
size_t initial_volumes_count = volumes.volumes.size();
|
size_t initial_volumes_count = volumes.volumes.size();
|
||||||
s_gcode_preview_data.first_volumes.emplace_back(GCodePreviewData::Travel, 0, (unsigned int)initial_volumes_count);
|
s_gcode_preview_data.first_volumes.emplace_back(GCodePreviewData::Travel, 0, (unsigned int)initial_volumes_count);
|
||||||
|
|
||||||
// detects types
|
if (print.gcode_preview.extrusion.view_type == GCodeAnalyzer::PreviewData::Extrusion::Feedrate)
|
||||||
TypesList types;
|
|
||||||
for (const GCodeAnalyzer::PreviewData::Travel::Polyline& polyline : print.gcode_preview.travel.polylines)
|
|
||||||
{
|
{
|
||||||
if (std::find(types.begin(), types.end(), Type(polyline.type)) == types.end())
|
// colors travels by feedrate
|
||||||
types.emplace_back(polyline.type);
|
|
||||||
}
|
|
||||||
|
|
||||||
// nothing to render, return
|
// detects feedrates
|
||||||
if (types.empty())
|
FeedratesList feedrates;
|
||||||
return;
|
for (const GCodeAnalyzer::PreviewData::Travel::Polyline& polyline : print.gcode_preview.travel.polylines)
|
||||||
|
|
||||||
// creates a new volume for each type
|
|
||||||
for (Type& type : types)
|
|
||||||
{
|
|
||||||
GLVolume* volume = new GLVolume(print.gcode_preview.travel.type_colors[type.value].rgba);
|
|
||||||
if (volume != nullptr)
|
|
||||||
{
|
{
|
||||||
type.volume = volume;
|
if (std::find(feedrates.begin(), feedrates.end(), Feedrate(polyline.feedrate)) == feedrates.end())
|
||||||
volumes.volumes.emplace_back(volume);
|
feedrates.emplace_back(polyline.feedrate);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
|
// nothing to render, return
|
||||||
|
if (feedrates.empty())
|
||||||
|
return;
|
||||||
|
|
||||||
|
// creates a new volume for each feedrate
|
||||||
|
for (Feedrate& feedrate : feedrates)
|
||||||
{
|
{
|
||||||
// an error occourred - restore to previous state and return
|
GLVolume* volume = new GLVolume(print.gcode_preview.get_extrusion_feedrate_color(feedrate.value).rgba);
|
||||||
if (initial_volumes_count != volumes.volumes.size())
|
if (volume != nullptr)
|
||||||
{
|
{
|
||||||
std::vector<GLVolume*>::iterator begin = volumes.volumes.begin() + initial_volumes_count;
|
feedrate.volume = volume;
|
||||||
std::vector<GLVolume*>::iterator end = volumes.volumes.end();
|
volumes.volumes.emplace_back(volume);
|
||||||
for (std::vector<GLVolume*>::iterator it = begin; it < end; ++it)
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// an error occourred - restore to previous state and return
|
||||||
|
if (initial_volumes_count != volumes.volumes.size())
|
||||||
{
|
{
|
||||||
GLVolume* volume = *it;
|
std::vector<GLVolume*>::iterator begin = volumes.volumes.begin() + initial_volumes_count;
|
||||||
delete volume;
|
std::vector<GLVolume*>::iterator end = volumes.volumes.end();
|
||||||
|
for (std::vector<GLVolume*>::iterator it = begin; it < end; ++it)
|
||||||
|
{
|
||||||
|
GLVolume* volume = *it;
|
||||||
|
delete volume;
|
||||||
|
}
|
||||||
|
volumes.volumes.erase(begin, end);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
volumes.volumes.erase(begin, end);
|
}
|
||||||
return;
|
}
|
||||||
|
|
||||||
|
// populates volumes
|
||||||
|
for (const GCodeAnalyzer::PreviewData::Travel::Polyline& polyline : print.gcode_preview.travel.polylines)
|
||||||
|
{
|
||||||
|
FeedratesList::iterator feedrate = std::find(feedrates.begin(), feedrates.end(), Feedrate(polyline.feedrate));
|
||||||
|
if (feedrate != feedrates.end())
|
||||||
|
{
|
||||||
|
feedrate->volume->print_zs.push_back(unscale(polyline.polyline.bounding_box().max.z));
|
||||||
|
feedrate->volume->offsets.push_back(feedrate->volume->indexed_vertex_array.quad_indices.size());
|
||||||
|
feedrate->volume->offsets.push_back(feedrate->volume->indexed_vertex_array.triangle_indices.size());
|
||||||
|
|
||||||
|
polyline3_to_verts(polyline.polyline, print.gcode_preview.travel.width, print.gcode_preview.travel.height, *feedrate->volume);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
// populates volumes
|
|
||||||
for (const GCodeAnalyzer::PreviewData::Travel::Polyline& polyline : print.gcode_preview.travel.polylines)
|
|
||||||
{
|
{
|
||||||
TypesList::iterator type = std::find(types.begin(), types.end(), Type(polyline.type));
|
// colors travels by travel type
|
||||||
if (type != types.end())
|
|
||||||
{
|
|
||||||
type->volume->print_zs.push_back(unscale(polyline.polyline.bounding_box().max.z));
|
|
||||||
type->volume->offsets.push_back(type->volume->indexed_vertex_array.quad_indices.size());
|
|
||||||
type->volume->offsets.push_back(type->volume->indexed_vertex_array.triangle_indices.size());
|
|
||||||
|
|
||||||
polyline3_to_verts(polyline.polyline, print.gcode_preview.travel.width, print.gcode_preview.travel.height, *type->volume);
|
// detects types
|
||||||
|
TypesList types;
|
||||||
|
for (const GCodeAnalyzer::PreviewData::Travel::Polyline& polyline : print.gcode_preview.travel.polylines)
|
||||||
|
{
|
||||||
|
if (std::find(types.begin(), types.end(), Type(polyline.type)) == types.end())
|
||||||
|
types.emplace_back(polyline.type);
|
||||||
|
}
|
||||||
|
|
||||||
|
// nothing to render, return
|
||||||
|
if (types.empty())
|
||||||
|
return;
|
||||||
|
|
||||||
|
// creates a new volume for each type
|
||||||
|
for (Type& type : types)
|
||||||
|
{
|
||||||
|
GLVolume* volume = new GLVolume(print.gcode_preview.travel.type_colors[type.value].rgba);
|
||||||
|
if (volume != nullptr)
|
||||||
|
{
|
||||||
|
type.volume = volume;
|
||||||
|
volumes.volumes.emplace_back(volume);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// an error occourred - restore to previous state and return
|
||||||
|
if (initial_volumes_count != volumes.volumes.size())
|
||||||
|
{
|
||||||
|
std::vector<GLVolume*>::iterator begin = volumes.volumes.begin() + initial_volumes_count;
|
||||||
|
std::vector<GLVolume*>::iterator end = volumes.volumes.end();
|
||||||
|
for (std::vector<GLVolume*>::iterator it = begin; it < end; ++it)
|
||||||
|
{
|
||||||
|
GLVolume* volume = *it;
|
||||||
|
delete volume;
|
||||||
|
}
|
||||||
|
volumes.volumes.erase(begin, end);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// populates volumes
|
||||||
|
for (const GCodeAnalyzer::PreviewData::Travel::Polyline& polyline : print.gcode_preview.travel.polylines)
|
||||||
|
{
|
||||||
|
TypesList::iterator type = std::find(types.begin(), types.end(), Type(polyline.type));
|
||||||
|
if (type != types.end())
|
||||||
|
{
|
||||||
|
type->volume->print_zs.push_back(unscale(polyline.polyline.bounding_box().max.z));
|
||||||
|
type->volume->offsets.push_back(type->volume->indexed_vertex_array.quad_indices.size());
|
||||||
|
type->volume->offsets.push_back(type->volume->indexed_vertex_array.triangle_indices.size());
|
||||||
|
|
||||||
|
polyline3_to_verts(polyline.polyline, print.gcode_preview.travel.width, print.gcode_preview.travel.height, *type->volume);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue