mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-05-21 20:18:17 +08:00
GCode Preview - Fixed values in range labels of legend texture
This commit is contained in:
parent
6dd241921f
commit
d91f59379b
@ -717,6 +717,10 @@ void GCodeAnalyzer::_calc_gcode_preview_travel(GCodePreviewData& preview_data)
|
|||||||
float feedrate = FLT_MAX;
|
float feedrate = FLT_MAX;
|
||||||
unsigned int extruder_id = -1;
|
unsigned int extruder_id = -1;
|
||||||
|
|
||||||
|
GCodePreviewData::Range height_range;
|
||||||
|
GCodePreviewData::Range width_range;
|
||||||
|
GCodePreviewData::Range feedrate_range;
|
||||||
|
|
||||||
// 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)
|
||||||
{
|
{
|
||||||
@ -745,11 +749,19 @@ void GCodeAnalyzer::_calc_gcode_preview_travel(GCodePreviewData& preview_data)
|
|||||||
type = move_type;
|
type = move_type;
|
||||||
feedrate = move.data.feedrate;
|
feedrate = move.data.feedrate;
|
||||||
extruder_id = move.data.extruder_id;
|
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
|
// store last polyline
|
||||||
polyline.remove_duplicate_points();
|
polyline.remove_duplicate_points();
|
||||||
Helper::store_polyline(polyline, type, direction, feedrate, extruder_id, preview_data);
|
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)
|
void GCodeAnalyzer::_calc_gcode_preview_retractions(GCodePreviewData& preview_data)
|
||||||
|
@ -85,6 +85,12 @@ void GCodePreviewData::Range::update_from(float value)
|
|||||||
max = std::max(max, 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)
|
void GCodePreviewData::Range::set_from(const Range& other)
|
||||||
{
|
{
|
||||||
min = other.min;
|
min = other.min;
|
||||||
@ -198,6 +204,11 @@ void GCodePreviewData::Travel::set_default()
|
|||||||
width = Default_Width;
|
width = Default_Width;
|
||||||
height = Default_Height;
|
height = Default_Height;
|
||||||
::memcpy((void*)type_colors, (const void*)Default_Type_Colors, Num_Types * sizeof(Color));
|
::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;
|
is_visible = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -345,15 +356,26 @@ GCodePreviewData::LegendItemsList GCodePreviewData::get_legend_items(const std::
|
|||||||
{
|
{
|
||||||
struct Helper
|
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);
|
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)
|
for (unsigned int i = 0; i < Range::Colors_Count; ++i)
|
||||||
{
|
{
|
||||||
char buf[32];
|
char buf[1024];
|
||||||
sprintf(buf, "%.*f/%.*f", decimals, scale_factor * (range.min + (float)i * step), decimals, scale_factor * (range.min + (float)(i + 1) * step));
|
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, range.colors[i]);
|
list.emplace_back(buf, ranges[0]->colors[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -377,17 +399,26 @@ GCodePreviewData::LegendItemsList GCodePreviewData::get_legend_items(const std::
|
|||||||
}
|
}
|
||||||
case Extrusion::Height:
|
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;
|
break;
|
||||||
}
|
}
|
||||||
case Extrusion::Width:
|
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;
|
break;
|
||||||
}
|
}
|
||||||
case Extrusion::Feedrate:
|
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;
|
break;
|
||||||
}
|
}
|
||||||
case Extrusion::Tool:
|
case Extrusion::Tool:
|
||||||
|
@ -37,6 +37,7 @@ public:
|
|||||||
void reset();
|
void reset();
|
||||||
bool empty() const;
|
bool empty() const;
|
||||||
void update_from(float value);
|
void update_from(float value);
|
||||||
|
void update_from(const Range& other);
|
||||||
void set_from(const Range& other);
|
void set_from(const Range& other);
|
||||||
float step_size() const;
|
float step_size() const;
|
||||||
|
|
||||||
@ -44,6 +45,13 @@ public:
|
|||||||
const Color& get_color_at_max() const;
|
const Color& get_color_at_max() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct Ranges
|
||||||
|
{
|
||||||
|
Range height;
|
||||||
|
Range width;
|
||||||
|
Range feedrate;
|
||||||
|
};
|
||||||
|
|
||||||
struct LegendItem
|
struct LegendItem
|
||||||
{
|
{
|
||||||
std::string text;
|
std::string text;
|
||||||
@ -71,13 +79,6 @@ public:
|
|||||||
static const std::string Default_Extrusion_Role_Names[Num_Extrusion_Roles];
|
static const std::string Default_Extrusion_Role_Names[Num_Extrusion_Roles];
|
||||||
static const EViewType Default_View_Type;
|
static const EViewType Default_View_Type;
|
||||||
|
|
||||||
struct Ranges
|
|
||||||
{
|
|
||||||
Range height;
|
|
||||||
Range width;
|
|
||||||
Range feedrate;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct Layer
|
struct Layer
|
||||||
{
|
{
|
||||||
float z;
|
float z;
|
||||||
@ -140,6 +141,7 @@ public:
|
|||||||
float height;
|
float height;
|
||||||
Color type_colors[Num_Types];
|
Color type_colors[Num_Types];
|
||||||
bool is_visible;
|
bool is_visible;
|
||||||
|
Ranges ranges;
|
||||||
|
|
||||||
void set_default();
|
void set_default();
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user