Skip to content

Commit

Permalink
Fix refresh gcode preview if already on it when gcode is computed.
Browse files Browse the repository at this point in the history
  • Loading branch information
supermerill committed Feb 15, 2022
1 parent ed3676f commit b8ef7ee
Show file tree
Hide file tree
Showing 10 changed files with 29 additions and 13 deletions.
12 changes: 8 additions & 4 deletions src/libslic3r/PrintApply.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -994,15 +994,12 @@ Print::ApplyStatus Print::apply(const Model &model, DynamicPrintConfig new_full_
update_apply_status(false);

// Grab the lock for the Print / PrintObject milestones.
std::scoped_lock<std::mutex> lock(this->state_mutex());
{ std::scoped_lock<std::mutex> lock(this->state_mutex());

// The following call may stop the background processing.
if (! print_diff.empty())
update_apply_status(this->invalidate_state_by_config_options(new_full_config, print_diff));

// we change everything, reset the modify time
this->m_timestamp_last_change = std::time(0);

// Apply variables to placeholder parser. The placeholder parser is used by G-code export,
// which should be stopped if print_diff is not empty.
size_t num_extruders = m_config.nozzle_diameter.size();
Expand Down Expand Up @@ -1454,6 +1451,13 @@ Print::ApplyStatus Print::apply(const Model &model, DynamicPrintConfig new_full_
check_model_ids_equal(m_model, model);
#endif /* _DEBUG */

} // exit the mutex before re-using it via is_step_done
if(!is_step_done(PrintObjectStep::posSlice))
this->m_timestamp_last_change = std::time(0);
else if(!is_step_done(PrintStep::psSkirtBrim))
// reset the modify time if not all step done
this->m_timestamp_last_change = std::time(0);

return static_cast<ApplyStatus>(apply_status);
}

Expand Down
2 changes: 1 addition & 1 deletion src/libslic3r/PrintBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ class PrintBase : public ObjectBase
std::string main_text;
std::vector<std::string> args;
// Bitmap of flags.
enum FlagBits {
enum FlagBits : uint16_t {
DEFAULT = 0,
RELOAD_SCENE = 1 << 1,
RELOAD_SLA_SUPPORT_POINTS = 1 << 2,
Expand Down
2 changes: 1 addition & 1 deletion src/libslic3r/SLAPrint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1263,7 +1263,7 @@ std::string SLAPrintStatistics::finalize_output_path(const std::string &path_in)
void SLAPrint::StatusReporter::operator()(SLAPrint & p,
double st,
const std::string &msg,
unsigned flags,
uint16_t flags,
const std::string &logmsg)
{
m_st = st;
Expand Down
2 changes: 1 addition & 1 deletion src/libslic3r/SLAPrint.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,7 @@ class SLAPrint : public PrintBaseWithState<SLAPrintStep, slapsCount>
void operator()(SLAPrint & p,
double st,
const std::string &msg,
unsigned flags = SlicingStatus::DEFAULT,
uint16_t flags = SlicingStatus::DEFAULT,
const std::string &logmsg = "");

double status() const { return m_st; }
Expand Down
2 changes: 1 addition & 1 deletion src/libslic3r/SLAPrintSteps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,7 @@ void SLAPrint::Steps::support_tree(SLAPrintObject &po)
throw_if_canceled();

// Create the unified mesh
auto rc = SlicingStatus::RELOAD_SCENE;
SlicingStatus::FlagBits rc = SlicingStatus::RELOAD_SCENE;

// This is to prevent "Done." being displayed during merged_mesh()
report_status(-1, L("Visualizing supports"));
Expand Down
4 changes: 4 additions & 0 deletions src/slic3r/GUI/GLCanvas3D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2175,6 +2175,10 @@ static void reserve_new_volume_finalize_old_volume(GLVolume& vol_new, GLVolume&
vol_old.finalize_geometry(gl_initialized);
}

bool GLCanvas3D::is_gcode_preview_dirty(const GCodeProcessorResult& gcode_result) {
return last_showned_gcode != gcode_result.computed_timestamp;
}

void GLCanvas3D::load_gcode_preview(const GCodeProcessorResult& gcode_result, const std::vector<std::string>& str_tool_colors)
{
if (last_showned_gcode != gcode_result.computed_timestamp) {
Expand Down
1 change: 1 addition & 0 deletions src/slic3r/GUI/GLCanvas3D.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,7 @@ class GLCanvas3D

void set_as_dirty();
bool is_preview_dirty();
bool is_gcode_preview_dirty(const GCodeProcessorResult& gcode_result);
void set_items_show(bool show_objects, bool show_gcode);

void requires_check_outside_state() { m_requires_check_outside_state = true; }
Expand Down
6 changes: 5 additions & 1 deletion src/slic3r/GUI/GUI_Preview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,11 @@ void Preview::reload_print(bool keep_volumes)
#endif /* __linux__ */
}

load_print();
//test if gcode is up-to-date
if (m_gcode_result && m_canvas->is_gcode_preview_dirty(*m_gcode_result))
refresh_print();
else
load_print();
}

void Preview::refresh_print()
Expand Down
7 changes: 7 additions & 0 deletions src/slic3r/GUI/Notebook.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ class ButtonsListCtrl : public wxControl
ModeSizer* m_mode_sizer {nullptr};
};

// A tabpane but with custom buttons.
// The top buttons are stored in ButtonsListCtrl.
// The panes are stored here, in the wxBookCtrlBase.
// It's possible to add "fake" button that link to an existing pane.
// This notebook selection and tab count include the fake buttons.
// So it's possible to return the same pane for two different index.
// It's possible to set icons for the buttons, but they have no index as it's managed in the ButtonsListCtrl
class Notebook: public wxBookCtrlBase
{
public:
Expand Down
4 changes: 0 additions & 4 deletions src/slic3r/GUI/Plater.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4207,8 +4207,6 @@ void Plater::priv::on_slicing_began()
notification_manager->close_notification_of_type(NotificationType::SignDetected);
notification_manager->close_notification_of_type(NotificationType::ExportFinished);
notification_manager->set_slicing_progress_began();
//preview->get_canvas3d()->set_gcode_viewer_dirty();
//preview->get_canvas3d()->set_preview_dirty();
}
void Plater::priv::add_warning(const Slic3r::PrintStateBase::Warning& warning, size_t oid)
{
Expand Down Expand Up @@ -5421,8 +5419,6 @@ void Plater::load_gcode(const wxString& filename)
p->gcode_result = std::move(processor.extract_result());

// show results
//p->preview->get_canvas3d()->set_preview_dirty();
//p->preview->get_canvas3d()->set_gcode_viewer_dirty();
p->preview->reload_print(false);
p->preview->get_canvas3d()->zoom_to_gcode();

Expand Down

0 comments on commit b8ef7ee

Please sign in to comment.