This commit is contained in:
enricoturri1966 2020-10-08 08:33:05 +02:00
commit e40593f2ef
12 changed files with 108 additions and 56 deletions

View file

@ -665,7 +665,7 @@ bool CLI::setup(int argc, char **argv)
#ifdef __APPLE__
// The application is packed in the .dmg archive as 'Slic3r.app/Contents/MacOS/Slic3r'
// The resources are packed to 'Slic3r.app/Contents/Resources'
boost::filesystem::path path_resources = path_to_binary.parent_path() / "../Resources";
boost::filesystem::path path_resources = boost::filesystem::canonical(path_to_binary).parent_path() / "../Resources";
#elif defined _WIN32
// The application is packed in the .zip archive in the root,
// The resources are packed to 'resources'
@ -679,7 +679,7 @@ bool CLI::setup(int argc, char **argv)
// The application is packed in the .tar.bz archive (or in AppImage) as 'bin/slic3r',
// The resources are packed to 'resources'
// Path from Slic3r binary to resources:
boost::filesystem::path path_resources = path_to_binary.parent_path() / "../resources";
boost::filesystem::path path_resources = boost::filesystem::canonical(path_to_binary).parent_path() / "../resources";
#endif
set_resources_dir(path_resources.string());

View file

@ -2,6 +2,9 @@
#define _libslic3r_h_
#include "libslic3r_version.h"
#define GCODEVIEWER_APP_NAME "PrusaSlicer G-code Viewer"
#define GCODEVIEWER_APP_KEY "PrusaSlicerGcodeViewer"
#define GCODEVIEWER_BUILD_ID std::string("PrusaSlicer G-code Viewer-") + std::string(SLIC3R_VERSION) + std::string("-UNKNOWN")
// this needs to be included early for MSVC (listing it in Build.PL is not enough)
#include <memory>

View file

@ -6,8 +6,4 @@
#define SLIC3R_VERSION "@SLIC3R_VERSION@"
#define SLIC3R_BUILD_ID "@SLIC3R_BUILD_ID@"
#define GCODEVIEWER_APP_NAME "@GCODEVIEWER_APP_NAME@"
#define GCODEVIEWER_APP_KEY "@GCODEVIEWER_APP_KEY@"
#define GCODEVIEWER_BUILD_ID "@GCODEVIEWER_BUILD_ID@"
#endif /* __SLIC3R_VERSION_H */

View file

@ -1021,8 +1021,7 @@ void Control::OnLeftDown(wxMouseEvent& event)
m_mouse = maOneLayerIconClick;
else if (is_point_in_rect(pos, m_rect_cog_icon))
m_mouse = maCogIconClick;
else if (m_draw_mode == dmRegular)
{
else if (m_draw_mode == dmRegular) {
if (is_point_in_rect(pos, m_rect_tick_action)) {
auto it = m_ticks.ticks.find(TickCode{ m_selection == ssLower ? m_lower_value : m_higher_value });
m_mouse = it == m_ticks.ticks.end() ? maAddTick : maDeleteTick;
@ -1267,8 +1266,8 @@ void Control::append_change_extruder_menu_item(wxMenu* menu, bool switch_current
for (int i = 1; i <= extruders_cnt; i++)
{
const bool is_active_extruder = i == active_extruders[0] || i == active_extruders[1];
const wxString item_name = wxString::Format(_(L("Extruder %d")), i) +
(is_active_extruder ? " (" + _(L("active")) + ")" : "");
const wxString item_name = wxString::Format(_L("Extruder %d"), i) +
(is_active_extruder ? " (" + _L("active") + ")" : "");
if (m_mode == MultiAsSingle)
append_menu_item(change_extruder_menu, wxID_ANY, item_name, "",
@ -1280,7 +1279,7 @@ void Control::append_change_extruder_menu_item(wxMenu* menu, bool switch_current
(switch_current_code ? _L("Switch code to Change extruder") : _L("Change extruder") ) :
_L("Change extruder (N/A)");
wxMenuItem* change_extruder_menu_item = menu->AppendSubMenu(change_extruder_menu, change_extruder_menu_name, _(L("Use another extruder")));
wxMenuItem* change_extruder_menu_item = menu->AppendSubMenu(change_extruder_menu, change_extruder_menu_name, _L("Use another extruder"));
change_extruder_menu_item->SetBitmap(create_scaled_bitmap(active_extruders[1] > 0 ? "edit_uni" : "change_extruder"));
GUI::wxGetApp().plater()->Bind(wxEVT_UPDATE_UI, [this, change_extruder_menu_item](wxUpdateUIEvent& evt) {
@ -1303,8 +1302,8 @@ void Control::append_add_color_change_menu_item(wxMenu* menu, bool switch_curren
{
const bool is_used_extruder = used_extruders_for_tick.empty() ? true : // #ys_FIXME till used_extruders_for_tick doesn't filled correct for mmMultiExtruder
used_extruders_for_tick.find(i) != used_extruders_for_tick.end();
const wxString item_name = wxString::Format(_(L("Extruder %d")), i) +
(is_used_extruder ? " (" + _(L("used")) + ")" : "");
const wxString item_name = wxString::Format(_L("Extruder %d"), i) +
(is_used_extruder ? " (" + _L("used") + ")" : "");
append_menu_item(add_color_change_menu, wxID_ANY, item_name, "",
[this, i](wxCommandEvent&) { add_code_as_tick(ColorChange, i); }, "", menu,
@ -1466,11 +1465,9 @@ void Control::OnKeyDown(wxKeyEvent &event)
else if (event.GetKeyCode() == WXK_SHIFT)
UseDefaultColors(false);
#endif // ENABLE_GCODE_VIEWER
else if (is_horizontal())
{
else if (is_horizontal()) {
#if ENABLE_GCODE_VIEWER
if (m_is_focused)
{
if (m_is_focused) {
#endif // ENABLE_GCODE_VIEWER
if (key == WXK_LEFT || key == WXK_RIGHT)
move_current_thumb(key == WXK_LEFT);
@ -1484,8 +1481,7 @@ void Control::OnKeyDown(wxKeyEvent &event)
}
else {
#if ENABLE_GCODE_VIEWER
if (m_is_focused)
{
if (m_is_focused) {
#endif // ENABLE_GCODE_VIEWER
if (key == WXK_LEFT || key == WXK_RIGHT) {
m_selection = key == WXK_LEFT ? ssHigher : ssLower;
@ -1704,18 +1700,18 @@ void Control::show_edit_context_menu()
append_add_color_change_menu_item(&menu, true);
}
else
append_menu_item(&menu, wxID_ANY, it->type == ColorChange ? _(L("Edit color")) :
it->type == PausePrint ? _(L("Edit pause print message")) :
_(L("Edit custom G-code")), "",
append_menu_item(&menu, wxID_ANY, it->type == ColorChange ? _L("Edit color") :
it->type == PausePrint ? _L("Edit pause print message") :
_L("Edit custom G-code"), "",
[this](wxCommandEvent&) { edit_tick(); }, "edit_uni", &menu);
if (it->type == ColorChange && m_mode == MultiAsSingle)
append_change_extruder_menu_item(&menu, true);
append_menu_item(&menu, wxID_ANY, it->type == ColorChange ? _(L("Delete color change")) :
it->type == ToolChange ? _(L("Delete tool change")) :
it->type == PausePrint ? _(L("Delete pause print")) :
_(L("Delete custom G-code")), "",
append_menu_item(&menu, wxID_ANY, it->type == ColorChange ? _L("Delete color change") :
it->type == ToolChange ? _L("Delete tool change") :
it->type == PausePrint ? _L("Delete pause print") :
_L("Delete custom G-code"), "",
[this](wxCommandEvent&) { delete_current_tick();}, "colorchange_del_f", &menu);
GUI::wxGetApp().plater()->PopupMenu(&menu);
@ -1725,14 +1721,14 @@ void Control::show_cog_icon_context_menu()
{
wxMenu menu;
append_menu_item(&menu, wxID_ANY, _(L("Jump to height")) + " (Shift+G)", "",
append_menu_item(&menu, wxID_ANY, _L("Jump to height") + " (Shift+G)", "",
#if ENABLE_GCODE_VIEWER
[this](wxCommandEvent&) { jump_to_value(); }, "", & menu);
#else
[this](wxCommandEvent&) { jump_to_print_z(); }, "", &menu);
#endif // ENABLE_GCODE_VIEWER
append_menu_item(&menu, wxID_ANY, _(L("Set extruder sequence for the entire print")), "",
append_menu_item(&menu, wxID_ANY, _L("Set extruder sequence for the entire print"), "",
[this](wxCommandEvent&) { edit_extruder_sequence(); }, "", &menu);
GUI::wxGetApp().plater()->PopupMenu(&menu);
@ -1861,8 +1857,8 @@ static double get_print_z_to_jump(double active_print_z, double min_z, double ma
wxString msg_header = (mode == dmSequentialGCodeView) ? _L("Jump to move") : _L("Jump to height");
wxString msg_in = GUI::double_to_string(active_value);
#else
wxString msg_text = _(L("Enter the height you want to jump to")) + ":";
wxString msg_header = _(L("Jump to height"));
wxString msg_text = _L("Enter the height you want to jump to") + ":";
wxString msg_header = _L("Jump to height");
wxString msg_in = GUI::double_to_string(active_print_z);
#endif // ENABLE_GCODE_VIEWER

View file

@ -495,6 +495,50 @@ void GCodeViewer::render() const
#endif // ENABLE_GCODE_VIEWER_STATISTICS
}
void GCodeViewer::update_sequential_view_current(unsigned int first, unsigned int last)
{
auto is_visible = [this](unsigned int id) {
for (const TBuffer& buffer : m_buffers) {
if (buffer.visible) {
for (const Path& path : buffer.paths) {
if (path.first.s_id <= id && id <= path.last.s_id)
return true;
}
}
}
return false;
};
int first_diff = static_cast<int>(first) - static_cast<int>(m_sequential_view.last_current.first);
int last_diff = static_cast<int>(last) - static_cast<int>(m_sequential_view.last_current.last);
unsigned int new_first = first;
unsigned int new_last = last;
while (!is_visible(new_first)) {
if (first_diff > 0)
++new_first;
else
--new_first;
}
while (!is_visible(new_last)) {
if (last_diff > 0)
++new_last;
else
--new_last;
}
m_sequential_view.current.first = new_first;
m_sequential_view.current.last = new_last;
m_sequential_view.last_current = m_sequential_view.current;
refresh_render_paths(true, true);
if (new_first != first || new_last != last)
wxGetApp().plater()->update_preview_moves_slider();
}
bool GCodeViewer::is_toolpath_move_type_visible(EMoveType type) const
{
size_t id = static_cast<size_t>(buffer_id(type));
@ -1645,6 +1689,8 @@ void GCodeViewer::refresh_render_paths(bool keep_sequential_current_first, bool
break;
}
unsigned int render_paths_count = 0;
// second pass: filter paths by sequential data and collect them by color
for (const auto& [buffer, index_buffer_id, path_id] : paths) {
const Path& path = buffer->paths[path_id];
@ -1667,6 +1713,7 @@ void GCodeViewer::refresh_render_paths(bool keep_sequential_current_first, bool
it->color = color;
it->path_id = path_id;
it->index_buffer_id = index_buffer_id;
++render_paths_count;
}
unsigned int segments_count = std::min(m_sequential_view.current.last, path.last.s_id) - std::max(m_sequential_view.current.first, path.first.s_id) + 1;
@ -1689,6 +1736,8 @@ void GCodeViewer::refresh_render_paths(bool keep_sequential_current_first, bool
it->offsets.push_back(static_cast<size_t>((path.first.i_id + delta_1st) * sizeof(unsigned int)));
}
wxGetApp().plater()->enable_preview_moves_slider(render_paths_count > 0);
#if ENABLE_GCODE_VIEWER_STATISTICS
for (const TBuffer& buffer : m_buffers) {
m_statistics.render_paths_size += SLIC3R_STDVEC_MEMSIZE(buffer.render_paths, RenderPath);

View file

@ -367,6 +367,7 @@ public:
Endpoints endpoints;
Endpoints current;
Endpoints last_current;
Vec3f current_position{ Vec3f::Zero() };
Marker marker;
};
@ -430,12 +431,7 @@ public:
const std::vector<double>& get_layers_zs() const { return m_layers_zs; };
const SequentialView& get_sequential_view() const { return m_sequential_view; }
void update_sequential_view_current(unsigned int first, unsigned int last)
{
m_sequential_view.current.first = first;
m_sequential_view.current.last = last;
refresh_render_paths(true, true);
}
void update_sequential_view_current(unsigned int first, unsigned int last);
EViewType get_view_type() const { return m_view_type; }
void set_view_type(EViewType type) {

View file

@ -1162,8 +1162,7 @@ void Preview::update_moves_slider()
std::vector<double> values(view.endpoints.last - view.endpoints.first + 1);
unsigned int count = 0;
for (unsigned int i = view.endpoints.first; i <= view.endpoints.last; ++i)
{
for (unsigned int i = view.endpoints.first; i <= view.endpoints.last; ++i) {
values[count++] = static_cast<double>(i + 1);
}
@ -1171,6 +1170,12 @@ void Preview::update_moves_slider()
m_moves_slider->SetMaxValue(view.endpoints.last - view.endpoints.first);
m_moves_slider->SetSelectionSpan(view.current.first - view.endpoints.first, view.current.last - view.endpoints.first);
}
void Preview::enable_moves_slider(bool enable)
{
if (m_moves_slider != nullptr)
m_moves_slider->Enable(enable);
}
#else
void Preview::update_double_slider_from_canvas(wxKeyEvent & event)
{

View file

@ -194,6 +194,7 @@ Preview(wxWindow* parent, Model* model, DynamicPrintConfig* config,
#if ENABLE_GCODE_VIEWER
void update_bottom_toolbar();
void update_moves_slider();
void enable_moves_slider(bool enable);
void hide_layers_slider();
#endif // ENABLE_GCODE_VIEWER

View file

@ -1612,9 +1612,8 @@ struct Plater::priv
#if ENABLE_GCODE_VIEWER
void update_preview_bottom_toolbar();
void update_preview_moves_slider();
#endif // ENABLE_GCODE_VIEWER
void enable_preview_moves_slider(bool enable);
#if ENABLE_GCODE_VIEWER
void reset_gcode_toolpaths();
#endif // ENABLE_GCODE_VIEWER
@ -4105,9 +4104,12 @@ void Plater::priv::update_preview_moves_slider()
{
preview->update_moves_slider();
}
#endif // ENABLE_GCODE_VIEWER
#if ENABLE_GCODE_VIEWER
void Plater::priv::enable_preview_moves_slider(bool enable)
{
preview->enable_moves_slider(enable);
}
void Plater::priv::reset_gcode_toolpaths()
{
preview->get_canvas3d()->reset_gcode_toolpaths();
@ -5898,6 +5900,11 @@ void Plater::update_preview_moves_slider()
p->update_preview_moves_slider();
}
void Plater::enable_preview_moves_slider(bool enable)
{
p->enable_preview_moves_slider(enable);
}
void Plater::reset_gcode_toolpaths()
{
p->reset_gcode_toolpaths();

View file

@ -316,6 +316,7 @@ public:
#if ENABLE_GCODE_VIEWER
void update_preview_bottom_toolbar();
void update_preview_moves_slider();
void enable_preview_moves_slider(bool enable);
void reset_gcode_toolpaths();
void reset_last_loaded_gcode() { m_last_loaded_gcode = ""; }

View file

@ -303,7 +303,6 @@ void Tab::create_preset_tab()
// so that the cursor jumps to the last item.
m_treectrl->Bind(wxEVT_TREE_SEL_CHANGED, [this](wxTreeEvent&) {
if (!m_disable_tree_sel_changed_event && !m_pages.empty()) {
#ifdef WIN32
if (m_page_switch_running)
m_page_switch_planned = true;
else {
@ -314,10 +313,6 @@ void Tab::create_preset_tab()
} while (this->tree_sel_change_delayed());
m_page_switch_running = false;
}
#else
// Crashes on Linux on start-up without CallAfter.
this->CallAfter([this]() { this->tree_sel_change_delayed(); });
#endif
}
});
@ -357,6 +352,13 @@ void Tab::create_preset_tab()
// Initialize the DynamicPrintConfig by default keys/values.
build();
// ys_FIXME: Following should not be needed, the function will be called later
// (update_mode->update_visibility->rebuild_page_tree). This does not work, during the
// second call of rebuild_page_tree m_treectrl->GetFirstVisibleItem(); returns zero
// for some unknown reason (and the page is not refreshed until user does a selection).
rebuild_page_tree();
m_completed = true;
}

View file

@ -7,7 +7,3 @@ set(SLIC3R_VERSION "2.3.0-alpha0")
set(SLIC3R_BUILD_ID "PrusaSlicer-${SLIC3R_VERSION}+UNKNOWN")
set(SLIC3R_RC_VERSION "2,3,0,0")
set(SLIC3R_RC_VERSION_DOTS "2.3.0.0")
set(GCODEVIEWER_APP_NAME "Prusa GCode Viewer")
set(GCODEVIEWER_APP_KEY "PrusaGCodeViewer")
set(GCODEVIEWER_BUILD_ID "Prusa GCode Viewer-${SLIC3R_VERSION}+UNKNOWN")