GCode Preview - Fixed values in range labels of legend texture

This commit is contained in:
Enrico Turri 2018-03-06 12:12:00 +01:00
parent 6dd241921f
commit d91f59379b
3 changed files with 60 additions and 15 deletions

View file

@ -717,6 +717,10 @@ void GCodeAnalyzer::_calc_gcode_preview_travel(GCodePreviewData& preview_data)
float feedrate = FLT_MAX;
unsigned int extruder_id = -1;
GCodePreviewData::Range height_range;
GCodePreviewData::Range width_range;
GCodePreviewData::Range feedrate_range;
// constructs the polylines while traversing the moves
for (const GCodeMove& move : travel_moves->second)
{
@ -745,11 +749,19 @@ void GCodeAnalyzer::_calc_gcode_preview_travel(GCodePreviewData& preview_data)
type = move_type;
feedrate = move.data.feedrate;
extruder_id = move.data.extruder_id;
height_range.update_from(move.data.height);
width_range.update_from(move.data.width);
feedrate_range.update_from(move.data.feedrate);
}
// store last polyline
polyline.remove_duplicate_points();
Helper::store_polyline(polyline, type, direction, feedrate, extruder_id, preview_data);
// updates preview ranges data
preview_data.travel.ranges.height.set_from(height_range);
preview_data.travel.ranges.width.set_from(width_range);
preview_data.travel.ranges.feedrate.set_from(feedrate_range);
}
void GCodeAnalyzer::_calc_gcode_preview_retractions(GCodePreviewData& preview_data)

View file

@ -85,6 +85,12 @@ void GCodePreviewData::Range::update_from(float value)
max = std::max(max, value);
}
void GCodePreviewData::Range::update_from(const Range& other)
{
min = std::min(min, other.min);
max = std::max(max, other.max);
}
void GCodePreviewData::Range::set_from(const Range& other)
{
min = other.min;
@ -198,6 +204,11 @@ void GCodePreviewData::Travel::set_default()
width = Default_Width;
height = Default_Height;
::memcpy((void*)type_colors, (const void*)Default_Type_Colors, Num_Types * sizeof(Color));
::memcpy((void*)ranges.height.colors, (const void*)Range::Default_Colors, Range::Colors_Count * sizeof(Color));
::memcpy((void*)ranges.width.colors, (const void*)Range::Default_Colors, Range::Colors_Count * sizeof(Color));
::memcpy((void*)ranges.feedrate.colors, (const void*)Range::Default_Colors, Range::Colors_Count * sizeof(Color));
is_visible = false;
}
@ -345,15 +356,26 @@ GCodePreviewData::LegendItemsList GCodePreviewData::get_legend_items(const std::
{
struct Helper
{
static void FillListFromRange(LegendItemsList& list, const Range& range, unsigned int decimals, float scale_factor)
static void FillListFromRange(LegendItemsList& list, const std::vector<const Range*>& ranges, unsigned int decimals, float scale_factor)
{
if (ranges.empty())
return;
list.reserve(Range::Colors_Count);
float step = range.step_size();
Range total_range;
for (const Range* range : ranges)
{
if (range != nullptr)
total_range.update_from(*range);
}
float step = total_range.step_size();
for (unsigned int i = 0; i < Range::Colors_Count; ++i)
{
char buf[32];
sprintf(buf, "%.*f/%.*f", decimals, scale_factor * (range.min + (float)i * step), decimals, scale_factor * (range.min + (float)(i + 1) * step));
list.emplace_back(buf, range.colors[i]);
char buf[1024];
sprintf(buf, "%.*f/%.*f", decimals, scale_factor * (total_range.min + (float)i * step), decimals, scale_factor * (total_range.min + (float)(i + 1) * step));
list.emplace_back(buf, ranges[0]->colors[i]);
}
}
};
@ -377,17 +399,26 @@ GCodePreviewData::LegendItemsList GCodePreviewData::get_legend_items(const std::
}
case Extrusion::Height:
{
Helper::FillListFromRange(items, extrusion.ranges.height, 3, 1.0f);
std::vector<const Range*> ranges;
ranges.push_back(&extrusion.ranges.height);
ranges.push_back(&travel.ranges.height);
Helper::FillListFromRange(items, ranges, 3, 1.0f);
break;
}
case Extrusion::Width:
{
Helper::FillListFromRange(items, extrusion.ranges.width, 3, 1.0f);
std::vector<const Range*> ranges;
ranges.push_back(&extrusion.ranges.width);
ranges.push_back(&travel.ranges.width);
Helper::FillListFromRange(items, ranges, 3, 1.0f);
break;
}
case Extrusion::Feedrate:
{
Helper::FillListFromRange(items, extrusion.ranges.feedrate, 0, 1.0f);
std::vector<const Range*> ranges;
ranges.push_back(&extrusion.ranges.feedrate);
ranges.push_back(&travel.ranges.feedrate);
Helper::FillListFromRange(items, ranges, 0, 1.0f);
break;
}
case Extrusion::Tool:

View file

@ -37,6 +37,7 @@ public:
void reset();
bool empty() const;
void update_from(float value);
void update_from(const Range& other);
void set_from(const Range& other);
float step_size() const;
@ -44,6 +45,13 @@ public:
const Color& get_color_at_max() const;
};
struct Ranges
{
Range height;
Range width;
Range feedrate;
};
struct LegendItem
{
std::string text;
@ -71,13 +79,6 @@ public:
static const std::string Default_Extrusion_Role_Names[Num_Extrusion_Roles];
static const EViewType Default_View_Type;
struct Ranges
{
Range height;
Range width;
Range feedrate;
};
struct Layer
{
float z;
@ -140,6 +141,7 @@ public:
float height;
Color type_colors[Num_Types];
bool is_visible;
Ranges ranges;
void set_default();
};