OrcaSlicer latest
OrcaSlicer
Loading...
Searching...
No Matches
Slic3r::BackgroundSlicingProcess Class Reference

#include </home/runner/work/OrcaSlicer/OrcaSlicer/src/slic3r/GUI/BackgroundSlicingProcess.hpp>

Collaboration diagram for Slic3r::BackgroundSlicingProcess:

Classes

struct  UITask

Public Types

enum  State {
  STATE_INITIAL = 0 , STATE_IDLE , STATE_STARTED , STATE_RUNNING ,
  STATE_FINISHED , STATE_CANCELED , STATE_EXIT , STATE_EXITED
}

Public Member Functions

 BackgroundSlicingProcess ()
 ~BackgroundSlicingProcess ()
void set_fff_print (Print *print)
void set_sla_print (SLAPrint *print)
void set_thumbnail_cb (ThumbnailsGeneratorCallback cb)
void set_gcode_result (GCodeProcessorResult *result)
bool switch_print_preprocess ()
bool can_switch_print ()
void set_current_plate (GUI::PartPlate *plate)
GUI::PartPlate * get_current_plate ()
GCodeProcessorResult * get_current_gcode_result ()
void set_slicing_completed_event (int event_id)
void set_finished_event (int event_id)
void set_export_began_event (int event_id)
void set_export_finished_event (int event_id)
bool select_technology (PrinterTechnology tech)
PrinterTechnology current_printer_technology () const
const PrintBase * current_print () const
const Print * fff_print () const
Print * fff_print ()
const SLAPrint * sla_print () const
std::string output_filepath_for_project (const boost::filesystem::path &project_path)
bool start ()
bool stop ()
bool reset ()
PrintBase::ApplyStatus apply (const Model &model, const DynamicPrintConfig &config)
void set_task (const PrintBase::TaskParams &params)
bool empty () const
StringObjectException validate (std::vector< StringObjectException > *warnings=nullptr, Polygons *collison_polygons=nullptr, std::vector< std::pair< Polygon, float > > *height_polygons=nullptr)
void schedule_export (const std::string &path, bool export_path_on_removable_media)
void schedule_upload (Slic3r::PrintHostJob upload_job)
void reset_export ()
bool is_export_scheduled () const
bool is_upload_scheduled () const
State state () const
bool idle () const
bool running () const
bool finished () const
bool is_internal_cancelled ()

Private Member Functions

void thread_proc ()
void thread_proc_safe () throw ()
void join_background_thread ()
void stop_internal ()
void process_fff ()
void process_sla ()
void call_process (std::exception_ptr &ex) throw ()
bool set_step_started (BackgroundSlicingProcessStep step)
void set_step_done (BackgroundSlicingProcessStep step)
bool is_step_done (BackgroundSlicingProcessStep step) const
bool invalidate_step (BackgroundSlicingProcessStep step)
bool invalidate_all_steps ()
void throw_if_canceled () const
void finalize_gcode ()
void export_gcode ()
void prepare_upload ()
ThumbnailsList render_thumbnails (const ThumbnailsParams &params)
bool execute_ui_task (std::function< void()> task)

Static Private Member Functions

static void cancel_ui_task (std::shared_ptr< BackgroundSlicingProcess::UITask > task)

Private Attributes

PrintBase * m_print = nullptr
Print * m_fff_print = nullptr
SLAPrint * m_sla_print = nullptr
GCodeProcessorResult * m_gcode_result = nullptr
ThumbnailsGeneratorCallback m_thumbnail_cb = nullptr
SL1Archive m_sla_archive
std::string m_temp_output_path
std::string m_export_path
bool m_export_path_on_removable_media = false
bool m_export_statistics = false
PrintHostJob m_upload_job
boost::thread m_thread
std::mutex m_mutex
std::condition_variable m_condition
State m_state = STATE_INITIAL
std::shared_ptr< UITask > m_ui_task
GUI::PartPlate * m_current_plate
PrinterTechnology m_printer_tech = ptUnknown
bool m_internal_cancelled = false
PrintState< BackgroundSlicingProcessStep, bspsCount > m_step_state
int m_event_slicing_completed_id = 0
int m_event_finished_id = 0
int m_event_export_began_id = 0
int m_event_export_finished_id = 0

Friends

class GUI::Plater

Detailed Description

Member Enumeration Documentation

◆ State

Enumerator
STATE_INITIAL 
STATE_IDLE 
STATE_STARTED 
STATE_RUNNING 
STATE_FINISHED 
STATE_CANCELED 
STATE_EXIT 
STATE_EXITED 
175 {
176 // m_thread is not running yet, or it did not reach the STATE_IDLE yet (it does not wait on the condition yet).
177 STATE_INITIAL = 0,
178 // m_thread is waiting for the task to execute.
181 // m_thread is executing a task.
183 // m_thread finished executing a task, and it is waiting until the UI thread picks up the results.
185 // m_thread finished executing a task, the task has been canceled by the UI thread, therefore the UI thread will not be notified.
187 // m_thread exited the loop and it is going to finish. The UI thread should join on m_thread.
190 };
@ STATE_EXITED
Definition BackgroundSlicingProcess.hpp:189
@ STATE_INITIAL
Definition BackgroundSlicingProcess.hpp:177
@ STATE_RUNNING
Definition BackgroundSlicingProcess.hpp:182
@ STATE_CANCELED
Definition BackgroundSlicingProcess.hpp:186
@ STATE_FINISHED
Definition BackgroundSlicingProcess.hpp:184
@ STATE_EXIT
Definition BackgroundSlicingProcess.hpp:188
@ STATE_IDLE
Definition BackgroundSlicingProcess.hpp:179
@ STATE_STARTED
Definition BackgroundSlicingProcess.hpp:180

Constructor & Destructor Documentation

◆ BackgroundSlicingProcess()

Slic3r::BackgroundSlicingProcess::BackgroundSlicingProcess ( )
133{
134 // BBS: move this logic to part plate
135#if 0
136 boost::filesystem::path temp_path(wxStandardPaths::Get().GetTempDir().utf8_str().data());
137 temp_path /= (boost::format(".%1%.gcode") % get_current_pid()).str();
138 m_temp_output_path = temp_path.string();
139#endif
140}
std::string m_temp_output_path
Definition BackgroundSlicingProcess.hpp:256
unsigned get_current_pid()
Definition utils.cpp:1480

References Slic3r::get_current_pid(), and m_temp_output_path.

Here is the call graph for this function:

◆ ~BackgroundSlicingProcess()

Slic3r::BackgroundSlicingProcess::~BackgroundSlicingProcess ( )
143{
144 this->stop();
146 // BBS: move this logic to part plate
147 // boost::nowide::remove(m_temp_output_path.c_str());
148}
void join_background_thread()
Definition BackgroundSlicingProcess.cpp:540
bool stop()
Definition BackgroundSlicingProcess.cpp:594

References join_background_thread(), and stop().

Here is the call graph for this function:

Member Function Documentation

◆ apply()

Print::ApplyStatus Slic3r::BackgroundSlicingProcess::apply ( const Model & model,
const DynamicPrintConfig & config )
740{
741 assert(m_print != nullptr);
742 assert(config.opt_enum<PrinterTechnology>("printer_technology") == m_print->technology());
743 // TODO: add partplate config
744 DynamicPrintConfig new_config = config;
745 new_config.apply(*m_current_plate->config());
746 Print::ApplyStatus invalidated = m_print->apply(model, new_config);
747
748 // Orca: prevent resetting under gcode viewer mode
749 if (invalidated != PrintBase::APPLY_STATUS_UNCHANGED) {
750 // Use the app’s plater accessor instead of going through mainframe, otherwise anything during startup that reaches apply()
751 // (loading presets, config or input files, e.g. from the CLI) therefore dereferences a null `mainframe` and crashes.
752 const auto plater = GUI::wxGetApp().plater();
753 if (plater && plater->only_gcode_mode()) {
755 }
756 }
757
758 if ((invalidated & PrintBase::APPLY_STATUS_INVALIDATED) != 0 && m_print->technology() == ptFFF &&
759 !m_fff_print->is_step_done(psGCodeExport)) {
760 // Some FFF status was invalidated, and the G-code was not exported yet.
761 // Let the G-code preview UI know that the final G-code preview is not valid.
762 // In addition, this early memory deallocation reduces memory footprint.
763 BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": invalide gcode result %1%, will reset soon") % m_gcode_result;
764 if (m_gcode_result != nullptr)
765 m_gcode_result->reset();
766 }
767 return invalidated;
768}
PrintBase * m_print
Definition BackgroundSlicingProcess.hpp:246
GCodeProcessorResult * m_gcode_result
Definition BackgroundSlicingProcess.hpp:251
Print * m_fff_print
Definition BackgroundSlicingProcess.hpp:248
GUI::PartPlate * m_current_plate
Definition BackgroundSlicingProcess.hpp:292
ApplyStatus
Definition PrintBase.hpp:410
@ APPLY_STATUS_UNCHANGED
Definition PrintBase.hpp:412
@ APPLY_STATUS_INVALIDATED
Definition PrintBase.hpp:417
PrinterTechnology
Definition Config.hpp:229
@ ptFFF
Definition Config.hpp:231
@ psGCodeExport
Definition Print.hpp:118

References Slic3r::ConfigBase::apply(), Slic3r::PrintBase::APPLY_STATUS_INVALIDATED, Slic3r::PrintBase::APPLY_STATUS_UNCHANGED, m_current_plate, m_fff_print, m_gcode_result, m_print, Slic3r::DynamicConfig::opt_enum(), Slic3r::psGCodeExport, and Slic3r::ptFFF.

Here is the call graph for this function:

◆ call_process()

void Slic3r::BackgroundSlicingProcess::call_process ( std::exception_ptr & ex)
throw ( )
private
487{
488 try {
489 assert(m_print != nullptr);
490 switch (m_print->technology()) {
491 case ptFFF: this->process_fff(); break;
492 case ptSLA: this->process_sla(); break;
493 default: m_print->process(); break;
494 }
495 } catch (CanceledException& /* ex */) {
496 // Canceled, this is all right.
497 assert(m_print->canceled());
498 ex = std::current_exception();
499 BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << ":got cancelled exception" << std::endl;
500 } catch (...) {
501 ex = std::current_exception();
502 BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << ":got other exception" << std::endl;
503 }
504}
void process_fff()
Definition BackgroundSlicingProcess.cpp:220
void process_sla()
Definition BackgroundSlicingProcess.cpp:327
@ ptSLA
Definition Config.hpp:233

References m_print, process_fff(), process_sla(), Slic3r::ptFFF, and Slic3r::ptSLA.

Referenced by thread_proc().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ can_switch_print()

bool Slic3r::BackgroundSlicingProcess::can_switch_print ( )
165{
166 bool result = true;
167
168 if (m_state == STATE_RUNNING) {
169 // currently it is on slicing, judge whether the slice result is valid or not
170 // if (m_current_plate->is_slice_result_valid())
171 {
172 result = false;
173 BOOST_LOG_TRIVIAL(info) << __FUNCTION__
174 << boost::format(": slicing plate's plate_id %1%, on slicing, can not switch print") %
175 m_current_plate->get_index();
176 }
177 }
178
179 return result;
180}
State m_state
Definition BackgroundSlicingProcess.hpp:272

References m_current_plate, m_state, and STATE_RUNNING.

◆ cancel_ui_task()

void Slic3r::BackgroundSlicingProcess::cancel_ui_task ( std::shared_ptr< BackgroundSlicingProcess::UITask > task)
staticprivate
711{
712 if (task) {
713 std::unique_lock<std::mutex> lck(task->mutex);
714 task->state = UITask::Canceled;
715 lck.unlock();
716 task->condition.notify_all();
717 }
718}
@ Canceled
Definition BackgroundSlicingProcess.hpp:281

References Slic3r::BackgroundSlicingProcess::UITask::Canceled.

Referenced by stop(), and stop_internal().

Here is the caller graph for this function:

◆ current_print()

const PrintBase * Slic3r::BackgroundSlicingProcess::current_print ( ) const
inline
134{ return m_print; }

References m_print.

Referenced by Slic3r::GUI::Plater::priv::on_process_completed(), prepare_upload(), process_sla(), and Slic3r::GUI::Plater::priv::update_background_process().

Here is the caller graph for this function:

◆ current_printer_technology()

PrinterTechnology Slic3r::BackgroundSlicingProcess::current_printer_technology ( ) const
204{
205 // BBS: as the m_printer is changed frequently when switch plates, use m_printer_tech directly
206 return m_printer_tech;
207 // return m_print->technology();
208}
PrinterTechnology m_printer_tech
Definition BackgroundSlicingProcess.hpp:293

References m_printer_tech.

◆ empty()

bool Slic3r::BackgroundSlicingProcess::empty ( ) const
721{
722 assert(m_print != nullptr);
723 return m_print->empty();
724}

References m_print.

Referenced by Slic3r::GUI::Plater::priv::on_process_completed(), and Slic3r::GUI::Plater::priv::restart_background_process().

Here is the caller graph for this function:

◆ execute_ui_task()

bool Slic3r::BackgroundSlicingProcess::execute_ui_task ( std::function< void()> task)
private
668{
669 bool running = false;
670 if (m_mutex.try_lock()) {
671 // Cancellation is either not in process, or already canceled and waiting for us to finish.
672 // There must be no UI task planned.
673 assert(!m_ui_task);
674 if (!m_print->canceled()) {
675 running = true;
676 m_ui_task = std::make_shared<UITask>();
677 }
678 m_mutex.unlock();
679 } else {
680 // Cancellation is in process.
681 }
682
683 bool result = false;
684 if (running) {
685 std::shared_ptr<UITask> ctx = m_ui_task;
686 GUI::wxGetApp().mainframe->m_plater->CallAfter([task, ctx]() {
687 // Running on the UI thread, thus ctx->state does not need to be guarded with mutex against ::cancel_ui_task().
688 assert(ctx->state == UITask::Planned || ctx->state == UITask::Canceled);
689 if (ctx->state == UITask::Planned) {
690 task();
691 std::unique_lock<std::mutex> lck(ctx->mutex);
692 ctx->state = UITask::Finished;
693 }
694 // Wake up the worker thread from the UI thread.
695 ctx->condition.notify_all();
696 });
697
698 {
699 std::unique_lock<std::mutex> lock(ctx->mutex);
700 ctx->condition.wait(lock, [&ctx] { return ctx->state == UITask::Finished || ctx->state == UITask::Canceled; });
701 }
702 result = ctx->state == UITask::Finished;
703 m_ui_task.reset();
704 }
705
706 return result;
707}
std::shared_ptr< UITask > m_ui_task
Definition BackgroundSlicingProcess.hpp:289
std::mutex m_mutex
Definition BackgroundSlicingProcess.hpp:270
bool running() const
Definition BackgroundSlicingProcess.hpp:193
@ lock
Definition GLGizmoEmboss.cpp:209
@ Finished
Definition BackgroundSlicingProcess.hpp:280
@ Planned
Definition BackgroundSlicingProcess.hpp:279

References Slic3r::BackgroundSlicingProcess::UITask::Canceled, Slic3r::BackgroundSlicingProcess::UITask::Finished, m_mutex, m_print, m_ui_task, Slic3r::BackgroundSlicingProcess::UITask::Planned, and running().

Referenced by render_thumbnails().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ export_gcode()

void Slic3r::BackgroundSlicingProcess::export_gcode ( )
private
924{
925 // Perform the final post-processing of the export path by applying the print statistics over the file name.
926 std::string export_path = m_fff_print->print_statistics().finalize_output_path(m_export_path);
927 std::string output_path = m_temp_output_path;
928
929 // FIXME localize the messages
930 std::string error_message;
931 int copy_ret_val = CopyFileResult::SUCCESS;
932 try {
933 copy_ret_val = copy_file(output_path, export_path, error_message, m_export_path_on_removable_media);
934 } catch (...) {
935 throw Slic3r::ExportError(_utf8(L("Unknown error with G-code export")));
936 }
937 switch (copy_ret_val) {
938 case CopyFileResult::SUCCESS: break; // no error
940 // throw Slic3r::ExportError((boost::format(_utf8(L("Copying of the temporary G-code to the output G-code failed. Maybe the SD card
941 // is write locked?\nError message: %1%"))) % error_message).str()); break;
943 // throw Slic3r::ExportError((boost::format(_utf8(L("Copying of the temporary G-code to the output G-code failed. There might be
944 // problem with target device, please try exporting again or using different device. The corrupted output G-code is at %1%.tmp.")))
945 // % export_path).str()); break;
947 // throw Slic3r::ExportError((boost::format(_utf8(L("Renaming of the G-code after copying to the selected destination folder has
948 // failed. Current path is %1%.tmp. Please try exporting again."))) % export_path).str()); break;
950 // throw Slic3r::ExportError((boost::format(_utf8(L("Copying of the temporary G-code has finished but the original code at %1%
951 // couldn't be opened during copy check. The output G-code is at %2%.tmp."))) % output_path % export_path).str()); break;
953 // throw Slic3r::ExportError((boost::format(_utf8(L("Copying of the temporary G-code has finished but the exported code couldn't be
954 // opened during copy check. The output G-code is at %1%.tmp."))) % export_path).str()); break;
955 default:
956 BOOST_LOG_TRIVIAL(error) << "Fail code(" << (int) copy_ret_val << ") when copy " << output_path << " to " << export_path << ".";
957 throw Slic3r::ExportError(
958 (boost::format(_utf8(L("Failed to save G-code file.\nError message: %1%.\nSource file %2%."))) % error_message % output_path)
959 .str());
960 // throw Slic3r::ExportError(_utf8(L("Unknown error when exporting G-code.")));
961 break;
962 }
965
966 // BBS
967 auto evt = new wxCommandEvent(m_event_export_finished_id, GUI::wxGetApp().mainframe->m_plater->GetId());
968 wxString output_gcode_str = wxString::FromUTF8(export_path.c_str(), export_path.length());
969 evt->SetString(output_gcode_str);
970 wxQueueEvent(GUI::wxGetApp().mainframe->m_plater, evt);
971
972 // BBS: to be checked. Whether use export_path or output_path.
973 gcode_add_line_number(export_path, m_fff_print->full_print_config());
974}
#define L(s)
Definition ExtrusionEntity.cpp:25
std::string m_export_path
Definition BackgroundSlicingProcess.hpp:259
int m_event_export_finished_id
Definition BackgroundSlicingProcess.hpp:321
bool m_export_statistics
Definition BackgroundSlicingProcess.hpp:262
bool m_export_path_on_removable_media
Definition BackgroundSlicingProcess.hpp:260
CopyFileResult copy_file(const std::string &from, const std::string &to, std::string &error_message, const bool with_check)
Definition utils.cpp:1071
@ FAIL_RENAMING
Definition Utils.hpp:263
@ FAIL_COPY_FILE
Definition Utils.hpp:261
@ FAIL_CHECK_ORIGIN_NOT_OPENED
Definition Utils.hpp:264
@ FAIL_FILES_DIFFERENT
Definition Utils.hpp:262
@ SUCCESS
Definition Utils.hpp:260
@ FAIL_CHECK_TARGET_NOT_OPENED
Definition Utils.hpp:265
void export_gcode_statistics(const GCodeProcessorResult &result, const std::string &path)
Definition GCodeStatistics.cpp:190
void gcode_add_line_number(const std::string &path, const DynamicPrintConfig &config)
Definition PostProcessor.cpp:234
std::string gcode_statistics_path(const std::string &gcode_path)
Definition GCodeStatistics.cpp:185
#define _utf8(s)
Definition I18N.hpp:10

References _utf8, Slic3r::copy_file(), Slic3r::export_gcode_statistics(), Slic3r::FAIL_CHECK_ORIGIN_NOT_OPENED, Slic3r::FAIL_CHECK_TARGET_NOT_OPENED, Slic3r::FAIL_COPY_FILE, Slic3r::FAIL_FILES_DIFFERENT, Slic3r::FAIL_RENAMING, Slic3r::gcode_add_line_number(), Slic3r::gcode_statistics_path(), L, m_event_export_finished_id, m_export_path, m_export_path_on_removable_media, m_export_statistics, m_fff_print, m_gcode_result, m_temp_output_path, and Slic3r::SUCCESS.

Referenced by process_fff().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fff_print() [1/2]

Print * Slic3r::BackgroundSlicingProcess::fff_print ( )
inline
136{ return m_fff_print; }

References m_fff_print.

◆ fff_print() [2/2]

const Print * Slic3r::BackgroundSlicingProcess::fff_print ( ) const
inline
135{ return m_fff_print; }

References m_fff_print.

Referenced by Slic3r::GUI::Plater::priv::update_fff_scene_only_shells().

Here is the caller graph for this function:

◆ finalize_gcode()

void Slic3r::BackgroundSlicingProcess::finalize_gcode ( )
private
844{
845 m_print->set_status(95, _u8L("Running post-processing scripts"));
846
847 // Perform the final post-processing of the export path by applying the print statistics over the file name.
848 std::string export_path = m_fff_print->print_statistics().finalize_output_path(m_export_path);
849 std::string output_path = m_temp_output_path;
850 // Both output_path and export_path ar in-out parameters.
851 // If post processed, output_path will differ from m_temp_output_path as run_post_process_scripts() will make a copy of the G-code to not
852 // collide with the G-code viewer memory mapping of the unprocessed G-code. G-code viewer maps unprocessed G-code, because m_gcode_result
853 // is calculated for the unprocessed G-code and it references lines in the memory mapped G-code file by line numbers.
854 // export_path may be changed by the post-processing script as well if the post processing script decides so, see GH #6042.
855 // Runs both post-processing scripts and plugins on a single .pp copy of the G-code (make_copy = true),
856 // so neither touches the original file the G-code viewer keeps memory-mapped.
857 bool post_processed = run_post_process_scripts(output_path, true, "File", export_path, m_fff_print->full_print_config());
858
859 auto remove_post_processed_temp_file = [post_processed, &output_path]() {
860 if (post_processed)
861 try {
862 boost::filesystem::remove(output_path);
863 } catch (const std::exception& ex) {
864 BOOST_LOG_TRIVIAL(error) << "Failed to remove temp file " << output_path << ": " << ex.what();
865 }
866 };
867 m_print->set_status(99, _utf8(L("Successfully executed post-processing script")));
868
869 // FIXME localize the messages
870 std::string error_message;
871 int copy_ret_val = CopyFileResult::SUCCESS;
872 try {
873 copy_ret_val = copy_file(output_path, export_path, error_message, m_export_path_on_removable_media);
874 remove_post_processed_temp_file();
875 } catch (...) {
876 remove_post_processed_temp_file();
877 throw Slic3r::ExportError(_u8L("Unknown error occurred during exporting G-code."));
878 }
879 switch (copy_ret_val) {
880 case CopyFileResult::SUCCESS: break; // no error
882 throw Slic3r::ExportError(GUI::format(
884 _L("Copying of the temporary G-code to the output G-code failed. Maybe the SD card is write locked?\nError message: %1%") :
885 _L("Copying of the temporary G-code to the output G-code failed.\nError message: %1%"),
886 error_message));
887 break;
889 throw Slic3r::ExportError(
890 GUI::format(_L("Copying of the temporary G-code to the output G-code failed. There might be problem with target device, please "
891 "try exporting again or using different device. The corrupted output G-code is at %1%.tmp."),
892 export_path));
893 break;
895 throw Slic3r::ExportError(GUI::format(_L("Renaming of the G-code after copying to the selected destination folder has failed. "
896 "Current path is %1%.tmp. Please try exporting again."),
897 export_path));
898 break;
900 throw Slic3r::ExportError(GUI::format(_L("Copying of the temporary G-code has finished but the original code at %1% couldn't be "
901 "opened during copy check. The output G-code is at %2%.tmp."),
902 output_path, export_path));
903 break;
905 throw Slic3r::ExportError(GUI::format(_L("Copying of the temporary G-code has finished but the exported code couldn't be opened "
906 "during copy check. The output G-code is at %1%.tmp."),
907 export_path));
908 break;
909 default:
910 throw Slic3r::ExportError(_u8L("Unknown error occurred during exporting G-code."));
911 BOOST_LOG_TRIVIAL(error) << "Unexpected fail code(" << (int) copy_ret_val << ") durring copy_file() to " << export_path << ".";
912 break;
913 }
916
917 m_print->set_status(100, GUI::format(_L("G-code file exported to %1%"), export_path));
918}
#define _L(s)
Definition OBJ.cpp:34
std::string format(const char *fmt, TArgs &&... args)
Definition format.hpp:36
bool run_post_process_scripts(std::string &src_path, bool make_copy, const std::string &host, std::string &output_name, const DynamicPrintConfig &config)
Definition PostProcessor.cpp:346
#define _u8L(s)
Definition I18N.hpp:11

References _L, _u8L, _utf8, Slic3r::copy_file(), Slic3r::export_gcode_statistics(), Slic3r::FAIL_CHECK_ORIGIN_NOT_OPENED, Slic3r::FAIL_CHECK_TARGET_NOT_OPENED, Slic3r::FAIL_COPY_FILE, Slic3r::FAIL_FILES_DIFFERENT, Slic3r::FAIL_RENAMING, Slic3r::GUI::format(), Slic3r::gcode_statistics_path(), L, m_export_path, m_export_path_on_removable_media, m_export_statistics, m_fff_print, m_gcode_result, m_print, m_temp_output_path, Slic3r::run_post_process_scripts(), and Slic3r::SUCCESS.

Referenced by process_fff().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ finished()

bool Slic3r::BackgroundSlicingProcess::finished ( ) const
inline
200{ return m_print->finished() && !m_gcode_result->moves.empty(); }

References m_gcode_result, and m_print.

◆ get_current_gcode_result()

GCodeProcessorResult * Slic3r::BackgroundSlicingProcess::get_current_gcode_result ( )
inline
110{ return m_gcode_result;}

References m_gcode_result.

Referenced by Slic3r::DevNozzleMappingCtrl::CtrlGetAutoNozzleMappingV0(), and Slic3r::DevUtilBackend::GetNozzleGroupResult().

Here is the caller graph for this function:

◆ get_current_plate()

GUI::PartPlate * Slic3r::BackgroundSlicingProcess::get_current_plate ( )
inline
109{ return m_current_plate; }

References m_current_plate.

Referenced by Slic3r::GUI::Plater::priv::on_process_completed(), process_fff(), Slic3r::GUI::Plater::priv::set_current_panel(), and Slic3r::GUI::Plater::priv::update_background_process().

Here is the caller graph for this function:

◆ idle()

bool Slic3r::BackgroundSlicingProcess::idle ( ) const
inline
192{ return m_state == STATE_IDLE; }

References m_state, and STATE_IDLE.

Referenced by Slic3r::GUI::Plater::priv::init_notification_manager(), and start().

Here is the caller graph for this function:

◆ invalidate_all_steps()

bool Slic3r::BackgroundSlicingProcess::invalidate_all_steps ( )
private
836{
837 return m_step_state.invalidate_all([this]() { this->stop_internal(); });
838}
PrintState< BackgroundSlicingProcessStep, bspsCount > m_step_state
Definition BackgroundSlicingProcess.hpp:296
void stop_internal()
Definition BackgroundSlicingProcess.cpp:637

References m_step_state, and stop_internal().

Referenced by reset().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ invalidate_step()

bool Slic3r::BackgroundSlicingProcess::invalidate_step ( BackgroundSlicingProcessStep step)
private
830{
831 bool invalidated = m_step_state.invalidate(step, [this]() { this->stop_internal(); });
832 return invalidated;
833}

References m_step_state, and stop_internal().

Referenced by reset_export(), schedule_export(), and schedule_upload().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ is_export_scheduled()

bool Slic3r::BackgroundSlicingProcess::is_export_scheduled ( ) const
inline
172{ return ! m_export_path.empty(); }

References m_export_path.

Referenced by Slic3r::GUI::Plater::priv::object_list_changed(), and Slic3r::GUI::Plater::priv::set_current_panel().

Here is the caller graph for this function:

◆ is_internal_cancelled()

bool Slic3r::BackgroundSlicingProcess::is_internal_cancelled ( )
inline
201{ return m_internal_cancelled; }
bool m_internal_cancelled
Definition BackgroundSlicingProcess.hpp:294

References m_internal_cancelled.

Referenced by Slic3r::GUI::Plater::priv::update_background_process().

Here is the caller graph for this function:

◆ is_step_done()

bool Slic3r::BackgroundSlicingProcess::is_step_done ( BackgroundSlicingProcessStep step) const
private
827{ return m_step_state.is_done(step, m_print->state_mutex()); }

References m_print, and m_step_state.

◆ is_upload_scheduled()

bool Slic3r::BackgroundSlicingProcess::is_upload_scheduled ( ) const
inline
173{ return ! m_upload_job.empty(); }
PrintHostJob m_upload_job
Definition BackgroundSlicingProcess.hpp:265

References m_upload_job.

◆ join_background_thread()

void Slic3r::BackgroundSlicingProcess::join_background_thread ( )
private
541{
542 std::unique_lock<std::mutex> lck(m_mutex);
543 if (m_state == STATE_INITIAL) {
544 // Worker thread has not been started yet.
545 assert(!m_thread.joinable());
546 } else {
547 assert(m_state == STATE_IDLE);
548 assert(m_thread.joinable());
549 // Notify the worker thread to exit.
551 lck.unlock();
552 m_condition.notify_one();
553 // Wait until the worker thread exits.
554 m_thread.join();
555 }
556}
std::condition_variable m_condition
Definition BackgroundSlicingProcess.hpp:271
boost::thread m_thread
Definition BackgroundSlicingProcess.hpp:268

References m_condition, m_mutex, m_state, m_thread, STATE_EXIT, STATE_IDLE, and STATE_INITIAL.

Referenced by ~BackgroundSlicingProcess().

Here is the caller graph for this function:

◆ output_filepath_for_project()

std::string Slic3r::BackgroundSlicingProcess::output_filepath_for_project ( const boost::filesystem::path & project_path)
211{
212 assert(m_print != nullptr);
213 if (project_path.empty())
214 return m_print->output_filepath("");
215 return m_print->output_filepath(project_path.parent_path().string(), project_path.stem().string());
216}

References m_print.

◆ prepare_upload()

void Slic3r::BackgroundSlicingProcess::prepare_upload ( )
private
978{
979 // Generate a unique temp path to which the gcode/zip file is copied/exported
980 boost::filesystem::path source_path = boost::filesystem::temp_directory_path() /
981 boost::filesystem::unique_path("." SLIC3R_APP_KEY ".upload.%%%%-%%%%-%%%%-%%%%");
982
983 if (m_print == m_fff_print) {
984 if (m_upload_job.upload_data.use_3mf) {
985 source_path = m_upload_job.upload_data.source_path;
986 } else {
987 m_print->set_status(95, _utf8(L("Running post-processing scripts")));
988 std::string error_message;
989 if (copy_file(m_temp_output_path, source_path.string(), error_message) != SUCCESS)
990 throw Slic3r::RuntimeError(_utf8(L("Copying of the temporary G-code to the output G-code failed.")));
991 m_upload_job.upload_data.upload_path = m_fff_print->print_statistics().finalize_output_path(
992 m_upload_job.upload_data.upload_path.string());
993 // Orca: skip post-processing scripts for BBL printers as we have run them already in finalize_gcode()
994 // todo: do we need to copy the file?
995
996 // Make a copy of the source path, as run_post_process_scripts() is allowed to change it when making a copy of the source file
997 // (not here, but when the final target is a file).
998 if (!m_fff_print->is_BBL_printer()) {
999 std::string source_path_str = source_path.string();
1000 std::string output_name_str = m_upload_job.upload_data.upload_path.string();
1001 // source_path_str is already a dedicated copy of the temp G-code (see copy_file above), not the
1002 // memory-mapped original, so scripts and plugins can modify it in place (make_copy = false).
1003 bool post_process = run_post_process_scripts(source_path_str, false, m_upload_job.printhost->get_name(), output_name_str,
1004 m_fff_print->full_print_config());
1005 if (post_process)
1006 m_upload_job.upload_data.upload_path = output_name_str;
1007 }
1008 }
1009 } else {
1010 m_upload_job.upload_data.upload_path = m_sla_print->print_statistics().finalize_output_path(
1011 m_upload_job.upload_data.upload_path.string());
1012
1013 ThumbnailsList thumbnails = this->render_thumbnails(
1014 ThumbnailsParams{current_print()->full_print_config().option<ConfigOptionPoints>("thumbnails")->values, true, true, true, true});
1015 // true, false, true, true); // renders also supports and pad
1016 Zipper zipper{source_path.string()};
1017 m_sla_archive.export_print(zipper, *m_sla_print, m_upload_job.upload_data.upload_path.string());
1018 for (const ThumbnailData& data : thumbnails)
1019 if (data.is_valid())
1020 write_thumbnail(zipper, data);
1021 zipper.finalize();
1022 }
1023
1024 m_print->set_status(100, (boost::format(_utf8(L("Scheduling upload to `%1%`. See Window -> Print Host Upload Queue"))) %
1025 m_upload_job.printhost->get_host())
1026 .str());
1027
1028 m_upload_job.upload_data.source_path = std::move(source_path);
1029
1030 GUI::wxGetApp().printhost_job_queue().enqueue(std::move(m_upload_job));
1031}
const PrintBase * current_print() const
Definition BackgroundSlicingProcess.hpp:134
ThumbnailsList render_thumbnails(const ThumbnailsParams &params)
Definition BackgroundSlicingProcess.cpp:1033
SL1Archive m_sla_archive
Definition BackgroundSlicingProcess.hpp:254
SLAPrint * m_sla_print
Definition BackgroundSlicingProcess.hpp:249
ConfigOption * option(const t_config_option_key &opt_key, bool create=false)
Definition Config.hpp:2768
const DynamicPrintConfig & full_print_config() const
Definition PrintBase.hpp:518
static void write_thumbnail(Zipper &zipper, const ThumbnailData &data)
Definition BackgroundSlicingProcess.cpp:315
zaa_minimize_perimeter_height post_process((ConfigOptionStrings, slicing_pipeline_plugin))((ConfigOptionString
std::vector< ThumbnailData > ThumbnailsList
Definition ThumbnailData.hpp:34

References _utf8, Slic3r::copy_file(), current_print(), Slic3r::PrintBase::full_print_config(), L, m_fff_print, m_print, m_sla_archive, m_sla_print, m_temp_output_path, m_upload_job, Slic3r::ConfigBase::option(), Slic3r::post_process(), render_thumbnails(), Slic3r::run_post_process_scripts(), Slic3r::SUCCESS, and Slic3r::write_thumbnail().

Referenced by process_fff().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ process_fff()

void Slic3r::BackgroundSlicingProcess::process_fff ( )
private
221{
222 assert(m_print == m_fff_print);
223 PresetBundle& preset_bundle = *GUI::wxGetApp().preset_bundle;
224 m_fff_print->is_BBL_printer() = preset_bundle.is_bbl_vendor();
225 // BBS: add the logic to process from an existed gcode file
226 if (m_print->finished()) {
227 BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(" %1%: skip slicing, to process previous gcode file") % __LINE__;
228 m_fff_print->set_status(80, _utf8(L("Processing G-code from previous file\u2026" /* \u2026 -> ... */)));
229 wxCommandEvent evt(m_event_slicing_completed_id);
230 // Post the Slicing Finished message for the G-code viewer to update.
231 // Passing the timestamp
232 evt.SetInt((int) (m_fff_print->step_state_with_timestamp(PrintStep::psSlicingFinished).timestamp));
233 wxQueueEvent(GUI::wxGetApp().mainframe->m_plater, evt.Clone());
234
236 if (!m_export_path.empty()) {
237 BOOST_LOG_TRIVIAL(info) << __FUNCTION__
238 << boost::format(" %1%: export gcode from %2% directly to %3%") % __LINE__ % m_temp_output_path %
240 } else {
241 if (m_upload_job.empty()) {
242 m_fff_print->export_gcode_from_previous_file(m_temp_output_path, m_gcode_result, [this](const ThumbnailsParams& params) {
243 return this->render_thumbnails(params);
244 });
245 }
246 BOOST_LOG_TRIVIAL(info) << __FUNCTION__
247 << boost::format(" %1%: export_gcode_from_previous_file from %2% finished") % __LINE__ %
249 }
250 } else {
251 // BBS: reset the gcode before reload_print in slicing_completed event processing
252 // FIX the gcode rename failed issue
253 BOOST_LOG_TRIVIAL(info) << __FUNCTION__
254 << boost::format(" %1%: will start slicing, reset gcode_result %2% firstly") % __LINE__ % m_gcode_result;
255 m_gcode_result->reset();
256
257 BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(" %1%: gcode_result reseted, will start print::process") % __LINE__;
258 m_print->process();
259 BOOST_LOG_TRIVIAL(info) << __FUNCTION__
260 << boost::format(" %1%: after print::process, send slicing complete event to gui...") % __LINE__;
261 if (m_current_plate->get_real_filament_map_mode(preset_bundle.project_config) < FilamentMapMode::fmmManual) {
262 std::vector<int> f_maps = m_fff_print->get_filament_maps();
263 m_current_plate->set_filament_maps(f_maps);
264 // The engine's concrete per-filament volume assignment is merged into the print
265 // config by the ToolOrdering write-back; reading it back keeps the plate config the
266 // next apply overlays equal to the written-back state (no diff, no re-invalidation)
267 // and persists the auto result (always concrete Std/HF, never the Hybrid seed).
268 std::vector<int> f_volume_maps = m_fff_print->get_filament_volume_maps();
269 m_current_plate->set_filament_volume_maps(f_volume_maps);
270 }
271 if (m_current_plate->get_real_filament_map_mode(preset_bundle.project_config) != FilamentMapMode::fmmNozzleManual) {
272 // The engine-resolved nozzle map is read back for every non-nozzle-manual mode so the
273 // plate config the next apply overlays matches the engine's written-back state
274 // (otherwise the full-config diff would invalidate the g-code on every apply).
275 std::vector<int> f_nozzle_maps = m_fff_print->get_filament_nozzle_maps();
276 m_current_plate->set_filament_nozzle_maps(f_nozzle_maps);
277 }
278 wxCommandEvent evt(m_event_slicing_completed_id);
279 // Post the Slicing Finished message for the G-code viewer to update.
280 // Passing the timestamp
281 evt.SetInt((int) (m_fff_print->step_state_with_timestamp(PrintStep::psSlicingFinished).timestamp));
282 wxQueueEvent(GUI::wxGetApp().mainframe->m_plater, evt.Clone());
283
284 // BBS: add plate index into render params
287 [this](const ThumbnailsParams& params) { return this->render_thumbnails(params); });
288 // Orca: BBL printers post-process the g-code in place here, in the file the G-code viewer maps, so
289 // the preview re-reads its moves and line offsets from the edited file. The rest of m_gcode_result,
290 // including nozzle_group_result (consumed by the H2C print-dispatch nozzle mapping), is kept.
291 if (m_fff_print->is_BBL_printer()) {
292 if (run_post_process_scripts(m_temp_output_path, false, "File", m_temp_output_path, m_fff_print->full_print_config()))
293 m_fff_print->reload_gcode_moves(m_gcode_result);
294 }
295
296 BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": export gcode finished");
297 }
299 if (!m_export_path.empty()) {
300 wxQueueEvent(GUI::wxGetApp().mainframe->m_plater, new wxCommandEvent(m_event_export_began_id));
301 if (!m_fff_print->is_BBL_printer())
303 else
304 export_gcode();
305 } else if (!m_upload_job.empty()) {
306 wxQueueEvent(GUI::wxGetApp().mainframe->m_plater, new wxCommandEvent(m_event_export_began_id));
308 } else {
309 m_print->set_status(100, _utf8(L("Slicing complete")));
310 }
312 }
313}
void finalize_gcode()
Definition BackgroundSlicingProcess.cpp:843
GUI::PartPlate * get_current_plate()
Definition BackgroundSlicingProcess.hpp:109
void export_gcode()
Definition BackgroundSlicingProcess.cpp:923
void prepare_upload()
Definition BackgroundSlicingProcess.cpp:977
void set_step_done(BackgroundSlicingProcessStep step)
Definition BackgroundSlicingProcess.cpp:821
int m_event_slicing_completed_id
Definition BackgroundSlicingProcess.hpp:315
int m_event_export_began_id
Definition BackgroundSlicingProcess.hpp:319
bool set_step_started(BackgroundSlicingProcessStep step)
Definition BackgroundSlicingProcess.cpp:816
std::string get_tmp_gcode_path()
Definition PartPlate.cpp:5465
@ psSlicingFinished
Definition Print.hpp:117
@ bspsGCodeFinalize
Definition BackgroundSlicingProcess.hpp:88
@ fmmNozzleManual
Definition PrintConfig.hpp:636
@ fmmManual
Definition PrintConfig.hpp:635

References _utf8, Slic3r::bspsGCodeFinalize, export_gcode(), finalize_gcode(), Slic3r::fmmManual, Slic3r::fmmNozzleManual, get_current_plate(), Slic3r::GUI::PartPlate::get_tmp_gcode_path(), Slic3r::PresetBundle::is_bbl_vendor(), L, m_current_plate, m_event_export_began_id, m_event_slicing_completed_id, m_export_path, m_fff_print, m_gcode_result, m_print, m_temp_output_path, m_upload_job, prepare_upload(), Slic3r::PresetBundle::project_config, Slic3r::psSlicingFinished, render_thumbnails(), Slic3r::run_post_process_scripts(), set_step_done(), and set_step_started().

Referenced by call_process().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ process_sla()

void Slic3r::BackgroundSlicingProcess::process_sla ( )
private
328{
329 assert(m_print == m_sla_print);
330 m_print->process();
332 if (!m_export_path.empty()) {
333 wxQueueEvent(GUI::wxGetApp().mainframe->m_plater, new wxCommandEvent(m_event_export_began_id));
334
335 const std::string export_path = m_sla_print->print_statistics().finalize_output_path(m_export_path);
336
337 // BBS: add plate id for thumbnail generation
338 ThumbnailsList thumbnails = this->render_thumbnails(
339 ThumbnailsParams{current_print()->full_print_config().option<ConfigOptionPoints>("thumbnails")->values, true, true, true,
340 true, 0});
341
342 Zipper zipper(export_path);
343 m_sla_archive.export_print(zipper, *m_sla_print); // true, false, true, true); // renders also supports and pad
344 for (const ThumbnailData& data : thumbnails)
345 if (data.is_valid())
346 write_thumbnail(zipper, data);
347 zipper.finalize();
348
349 // m_print->set_status(100, (boost::format(_utf8(L("Masked SLA file exported to %1%"))) % export_path).str());
350 m_print->set_status(100, (boost::format(_utf8("Masked SLA file exported to %1%")) % export_path).str());
351 } else {
352 // m_print->set_status(100, _utf8(L("Slicing complete")));
353 m_print->set_status(100, _utf8("Slicing complete"));
354 }
356 }
357}

References _utf8, Slic3r::bspsGCodeFinalize, current_print(), Slic3r::PrintBase::full_print_config(), m_event_export_began_id, m_export_path, m_print, m_sla_archive, m_sla_print, Slic3r::ConfigBase::option(), render_thumbnails(), set_step_done(), set_step_started(), and Slic3r::write_thumbnail().

Referenced by call_process().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ render_thumbnails()

ThumbnailsList Slic3r::BackgroundSlicingProcess::render_thumbnails ( const ThumbnailsParams & params)
private
1034{
1035 ThumbnailsList thumbnails;
1036 if (m_thumbnail_cb)
1037 this->execute_ui_task([this, &params, &thumbnails]() { thumbnails = m_thumbnail_cb(params); });
1038 return thumbnails;
1039}
bool execute_ui_task(std::function< void()> task)
Definition BackgroundSlicingProcess.cpp:667
ThumbnailsGeneratorCallback m_thumbnail_cb
Definition BackgroundSlicingProcess.hpp:253

References execute_ui_task(), and m_thumbnail_cb.

Referenced by prepare_upload(), process_fff(), and process_sla().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ reset()

bool Slic3r::BackgroundSlicingProcess::reset ( )
624{
625 bool stopped = this->stop();
626 this->reset_export();
627 // BBS: don't clear print for print is not owned by background slicing process anymore
628 // do it in the part_plate
629 // m_print->clear();
630 this->invalidate_all_steps();
631 return stopped;
632}
bool invalidate_all_steps()
Definition BackgroundSlicingProcess.cpp:835
void reset_export()
Definition BackgroundSlicingProcess.cpp:804

References invalidate_all_steps(), reset_export(), and stop().

Referenced by Slic3r::GUI::Plater::priv::reset(), and select_technology().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ reset_export()

void Slic3r::BackgroundSlicingProcess::reset_export ( )
805{
806 assert(!this->running());
807 if (!this->running()) {
808 m_export_path.clear();
810 // invalidate_step expects the mutex to be locked.
811 std::scoped_lock<std::mutex> lock(m_print->state_mutex());
813 }
814}
bool invalidate_step(BackgroundSlicingProcessStep step)
Definition BackgroundSlicingProcess.cpp:829

References Slic3r::bspsGCodeFinalize, invalidate_step(), m_export_path, m_export_path_on_removable_media, m_print, and running().

Referenced by Slic3r::GUI::Plater::priv::on_process_completed(), and reset().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ running()

bool Slic3r::BackgroundSlicingProcess::running ( ) const
inline

References m_state, STATE_CANCELED, STATE_FINISHED, STATE_RUNNING, and STATE_STARTED.

Referenced by execute_ui_task(), reset_export(), Slic3r::GUI::Plater::priv::set_current_panel(), start(), Slic3r::GUI::Plater::priv::trigger_auto_reslice_now(), and Slic3r::GUI::Plater::priv::update_background_process().

Here is the caller graph for this function:

◆ schedule_export()

void Slic3r::BackgroundSlicingProcess::schedule_export ( const std::string & path,
bool export_path_on_removable_media )
778{
779 assert(m_export_path.empty());
780 if (!m_export_path.empty())
781 return;
782
783 // Guard against entering the export step before changing the export path.
784 std::scoped_lock<std::mutex> lock(m_print->state_mutex());
786 m_export_path = path;
787 m_export_path_on_removable_media = export_path_on_removable_media;
788 m_export_statistics = GUI::wxGetApp().app_config->get_bool("export_statistics");
789}

References Slic3r::bspsGCodeFinalize, invalidate_step(), m_export_path, m_export_path_on_removable_media, m_export_statistics, and m_print.

Here is the call graph for this function:

◆ schedule_upload()

void Slic3r::BackgroundSlicingProcess::schedule_upload ( Slic3r::PrintHostJob upload_job)
792{
793 assert(m_export_path.empty());
794 if (!m_export_path.empty())
795 return;
796
797 // Guard against entering the export step before changing the export path.
798 std::scoped_lock<std::mutex> lock(m_print->state_mutex());
800 m_export_path.clear();
801 m_upload_job = std::move(upload_job);
802}

References Slic3r::bspsGCodeFinalize, invalidate_step(), m_export_path, m_print, and m_upload_job.

Here is the call graph for this function:

◆ select_technology()

bool Slic3r::BackgroundSlicingProcess::select_technology ( PrinterTechnology tech)
184{
185 bool changed = false;
186 if (m_printer_tech != tech) {
187 BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": change the printer technology from %1% to %2%") % m_printer_tech % tech;
188 m_printer_tech = tech;
189 if (m_print != nullptr)
190 this->reset();
191 changed = true;
192 }
193
194 switch (tech) {
195 case ptFFF: m_print = m_fff_print; break;
196 case ptSLA: m_print = m_sla_print; break;
197 default: assert(false); break;
198 }
199 assert(m_print != nullptr);
200 return changed;
201}
bool reset()
Definition BackgroundSlicingProcess.cpp:623

References m_fff_print, m_print, m_printer_tech, m_sla_print, Slic3r::ptFFF, Slic3r::ptSLA, and reset().

Here is the call graph for this function:

◆ set_current_plate()

void Slic3r::BackgroundSlicingProcess::set_current_plate ( GUI::PartPlate * plate)
inline
108{ m_current_plate = plate; }

References m_current_plate.

◆ set_export_began_event()

void Slic3r::BackgroundSlicingProcess::set_export_began_event ( int event_id)
inline
122{ m_event_export_began_id = event_id; }

References m_event_export_began_id.

◆ set_export_finished_event()

void Slic3r::BackgroundSlicingProcess::set_export_finished_event ( int event_id)
inline

◆ set_fff_print()

void Slic3r::BackgroundSlicingProcess::set_fff_print ( Print * print)
inline
100{ m_fff_print = print; }

References m_fff_print.

◆ set_finished_event()

void Slic3r::BackgroundSlicingProcess::set_finished_event ( int event_id)
inline
118{ m_event_finished_id = event_id; }
int m_event_finished_id
Definition BackgroundSlicingProcess.hpp:317

References m_event_finished_id.

◆ set_gcode_result()

void Slic3r::BackgroundSlicingProcess::set_gcode_result ( GCodeProcessorResult * result)
inline
103{ m_gcode_result = result; }

References m_gcode_result.

◆ set_sla_print()

void Slic3r::BackgroundSlicingProcess::set_sla_print ( SLAPrint * print)
inline
101{ m_sla_print = print; m_sla_print->set_printer(&m_sla_archive); }

References m_sla_archive, and m_sla_print.

◆ set_slicing_completed_event()

void Slic3r::BackgroundSlicingProcess::set_slicing_completed_event ( int event_id)
inline

◆ set_step_done()

void Slic3r::BackgroundSlicingProcess::set_step_done ( BackgroundSlicingProcessStep step)
private
822{
823 m_step_state.set_done(step, m_print->state_mutex(), [this]() { this->throw_if_canceled(); });
824}

References m_print, and m_step_state.

Referenced by process_fff(), and process_sla().

Here is the caller graph for this function:

◆ set_step_started()

bool Slic3r::BackgroundSlicingProcess::set_step_started ( BackgroundSlicingProcessStep step)
private
817{
818 return m_step_state.set_started(step, m_print->state_mutex(), [this]() { this->throw_if_canceled(); });
819}

References m_print, and m_step_state.

Referenced by process_fff(), and process_sla().

Here is the caller graph for this function:

◆ set_task()

void Slic3r::BackgroundSlicingProcess::set_task ( const PrintBase::TaskParams & params)
771{
772 assert(m_print != nullptr);
773 m_print->set_task(params);
774}

References m_print.

Referenced by Slic3r::GUI::Plater::priv::export_gcode(), and Slic3r::GUI::Plater::priv::export_gcode().

Here is the caller graph for this function:

◆ set_thumbnail_cb()

void Slic3r::BackgroundSlicingProcess::set_thumbnail_cb ( ThumbnailsGeneratorCallback cb)
inline
102{ m_thumbnail_cb = cb; }

References m_thumbnail_cb.

◆ sla_print()

const SLAPrint * Slic3r::BackgroundSlicingProcess::sla_print ( ) const
inline
137{ return m_sla_print; }

References m_sla_print.

◆ start()

bool Slic3r::BackgroundSlicingProcess::start ( )
559{
560 if (m_print->empty()) {
561 if (!m_current_plate || !m_current_plate->is_slice_result_valid())
562 // The print is empty (no object in Model, or all objects are out of the print bed).
563 return false;
564 }
565
566 std::unique_lock<std::mutex> lck(m_mutex);
567 if (m_state == STATE_INITIAL) {
568 // The worker thread is not running yet. Start it.
569 assert(!m_thread.joinable());
570 m_thread = create_thread([this] {
571#ifdef _WIN32
572 this->thread_proc_safe_seh_throw();
573#else // _WIN32
574 this->thread_proc_safe();
575#endif // _WIN32
576 });
577 // Wait until the worker thread is ready to execute the background processing task.
578 m_condition.wait(lck, [this]() { return m_state == STATE_IDLE; });
579 }
580 assert(m_state == STATE_IDLE || this->running());
581 if (this->running())
582 // The background processing thread is already running.
583 return false;
584 if (!this->idle())
585 throw Slic3r::RuntimeError("Cannot start a background task, the worker thread is not idle.");
587 m_print->set_cancel_callback([this]() { this->stop_internal(); });
588 lck.unlock();
589 m_condition.notify_one();
590 return true;
591}
bool idle() const
Definition BackgroundSlicingProcess.hpp:192
void thread_proc_safe()
Definition BackgroundSlicingProcess.cpp:531
boost::thread create_thread(boost::thread::attributes &attrs, Fn &&fn)
Definition Thread.hpp:48

References Slic3r::create_thread(), idle(), m_condition, m_current_plate, m_mutex, m_print, m_state, m_thread, running(), STATE_IDLE, STATE_INITIAL, STATE_STARTED, stop_internal(), and thread_proc_safe().

Referenced by Slic3r::GUI::Plater::priv::restart_background_process().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ state()

State Slic3r::BackgroundSlicingProcess::state ( ) const
inline
191{ return m_state; }

References m_state.

◆ stop()

bool Slic3r::BackgroundSlicingProcess::stop ( )
595{
596 BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ", enter" << std::endl;
597 // m_print->state_mutex() shall NOT be held. Unfortunately there is no interface to test for it.
598 std::unique_lock<std::mutex> lck(m_mutex);
599 if (m_state == STATE_INITIAL) {
600 // m_export_path.clear();
601 return false;
602 }
603 // assert(this->running());
605 // Cancel any task planned by the background thread on UI thread.
607 m_print->cancel();
608 // Wait until the background processing stops by being canceled.
609 m_condition.wait(lck, [this]() { return m_state == STATE_CANCELED; });
610 // In the "Canceled" state. Reset the state to "Idle".
612 m_print->set_cancel_callback([]() {});
613 } else if (m_state == STATE_FINISHED || m_state == STATE_CANCELED) {
614 // In the "Finished" or "Canceled" state. Reset the state to "Idle".
616 m_print->set_cancel_callback([]() {});
617 }
618 BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ", exit" << std::endl;
619 // m_export_path.clear();
620 return true;
621}
static void cancel_ui_task(std::shared_ptr< BackgroundSlicingProcess::UITask > task)
Definition BackgroundSlicingProcess.cpp:710

References cancel_ui_task(), m_condition, m_mutex, m_print, m_state, m_ui_task, STATE_CANCELED, STATE_FINISHED, STATE_IDLE, STATE_INITIAL, STATE_RUNNING, and STATE_STARTED.

Referenced by ~BackgroundSlicingProcess(), Slic3r::GUI::Plater::priv::init_notification_manager(), Slic3r::GUI::Plater::priv::on_process_completed(), reset(), and Slic3r::GUI::Plater::priv::reset().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ stop_internal()

void Slic3r::BackgroundSlicingProcess::stop_internal ( )
private
638{
639 BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ", enter" << std::endl;
640 // m_print->state_mutex() shall be held. Unfortunately there is no interface to test for it.
641 if (m_state == STATE_IDLE)
642 // The worker thread is waiting on m_mutex/m_condition for wake up. The following lock of the mutex would block.
643 return;
644 std::unique_lock<std::mutex> lck(m_mutex);
647 // Cancel any task planned by the background thread on UI thread.
649 // At this point of time the worker thread may be blocking on m_print->state_mutex().
650 // Set the print state to canceled before unlocking the state_mutex(), so when the worker thread wakes up,
651 // it throws the CanceledException().
652 m_print->cancel_internal();
653 // Allow the worker thread to wake up if blocking on a milestone.
654 m_print->state_mutex().unlock();
655 // Wait until the background processing stops by being canceled.
656 m_condition.wait(lck, [this]() { return m_state == STATE_CANCELED; });
657 // Lock it back to be in a consistent state.
658 m_print->state_mutex().lock();
659 }
660 // In the "Canceled" state. Reset the state to "Idle".
662 m_print->set_cancel_callback([]() {});
663 BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ", exit" << std::endl;
664}

References cancel_ui_task(), m_condition, m_mutex, m_print, m_state, m_ui_task, STATE_CANCELED, STATE_FINISHED, STATE_IDLE, STATE_RUNNING, and STATE_STARTED.

Referenced by invalidate_all_steps(), invalidate_step(), and start().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ switch_print_preprocess()

bool Slic3r::BackgroundSlicingProcess::switch_print_preprocess ( )
152{
153 bool result = true;
154
155 /*switch (m_printer_tech) {
156 case ptFFF: m_print = m_fff_print; break;
157 case ptSLA: m_print = m_sla_print; break;
158 default: assert(false); break;
159 }*/
160 return result;
161}

◆ thread_proc()

void Slic3r::BackgroundSlicingProcess::thread_proc ( )
private
360{
361 // BBS: thread name
362 set_current_thread_name("bbl_BgSlcPcs");
364
365 assert(m_print != nullptr);
366 assert(m_print == m_fff_print || m_print == m_sla_print);
367 std::unique_lock<std::mutex> lck(m_mutex);
368 // Let the caller know we are ready to run the background processing task.
370 lck.unlock();
371 m_condition.notify_one();
372 for (;;) {
373 // BBS: sometimes the state has already been set in the start function
374 // assert(m_state == STATE_IDLE || m_state == STATE_CANCELED || m_state == STATE_FINISHED || m_state == STATE_STARTED);
375 // Wait until a new task is ready to be executed, or this thread should be finished.
376 lck.lock();
377 m_condition.wait(lck, [this]() { return m_state == STATE_STARTED || m_state == STATE_EXIT; });
378 if (m_state == STATE_EXIT)
379 // Exiting this thread.
380 break;
381 // Process the background slicing task.
383 // BBS: internal cancel
384 m_internal_cancelled = false;
385 lck.unlock();
386 std::exception_ptr exception;
387#ifdef _WIN32
388 this->call_process_seh_throw(exception);
389#else
390 this->call_process(exception);
391#endif
392 m_print->finalize();
393 lck.lock();
395 BOOST_LOG_TRIVIAL(debug) << __FUNCTION__
396 << boost::format(": process finished, state %1%, print cancel_status %2%") % m_state %
397 m_print->cancel_status();
398 if (m_print->cancel_status() != Print::CANCELED_INTERNAL) {
399 // Only post the canceled event, if canceled by user.
400 // Don't post the canceled event, if canceled from Print::apply().
401 SlicingProcessCompletedEvent evt(m_event_finished_id, 0,
405 exception);
406 BOOST_LOG_TRIVIAL(info) << __FUNCTION__
407 << boost::format(": send SlicingProcessCompletedEvent to main, status %1%") % evt.status();
408 wxQueueEvent(GUI::wxGetApp().mainframe->m_plater, evt.Clone());
409 } else {
410 // BBS: internal cancel
412 }
413 m_print->restart();
414 lck.unlock();
415 // Let the UI thread wake up if it is waiting for the background task to finish.
416 m_condition.notify_one();
417 // Let the UI thread see the result.
418 }
420 lck.unlock();
421 // End of the background processing thread. The UI thread should join m_thread now.
422}
void call_process(std::exception_ptr &ex)
Definition BackgroundSlicingProcess.cpp:486
@ CANCELED_INTERNAL
Definition PrintBase.hpp:504
@ Cancelled
Definition BackgroundSlicingProcess.hpp:55
@ Finished
Definition BackgroundSlicingProcess.hpp:54
@ Error
Definition BackgroundSlicingProcess.hpp:56
bool set_current_thread_name(const char *thread_name)
Definition Thread.cpp:187
void name_tbb_thread_pool_threads_set_locale()
Definition Thread.cpp:225

References call_process(), Slic3r::PrintBase::CANCELED_INTERNAL, Slic3r::SlicingProcessCompletedEvent::Cancelled, Slic3r::SlicingProcessCompletedEvent::Clone(), Slic3r::SlicingProcessCompletedEvent::Error, Slic3r::SlicingProcessCompletedEvent::Finished, m_condition, m_event_finished_id, m_fff_print, m_internal_cancelled, m_mutex, m_print, m_sla_print, m_state, Slic3r::name_tbb_thread_pool_threads_set_locale(), Slic3r::set_current_thread_name(), STATE_CANCELED, STATE_EXIT, STATE_EXITED, STATE_FINISHED, STATE_IDLE, STATE_RUNNING, STATE_STARTED, and Slic3r::SlicingProcessCompletedEvent::status().

Referenced by thread_proc_safe().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ thread_proc_safe()

void Slic3r::BackgroundSlicingProcess::thread_proc_safe ( )
throw ( )
private
532{
533 try {
534 this->thread_proc();
535 } catch (...) {
536 wxTheApp->OnUnhandledException();
537 }
538}
void thread_proc()
Definition BackgroundSlicingProcess.cpp:359

References thread_proc().

Referenced by start().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ throw_if_canceled()

void Slic3r::BackgroundSlicingProcess::throw_if_canceled ( ) const
inlineprivate
303{ if (m_print->canceled()) throw CanceledException(); }

References m_print.

◆ validate()

StringObjectException Slic3r::BackgroundSlicingProcess::validate ( std::vector< StringObjectException > * warnings = nullptr,
Polygons * collison_polygons = nullptr,
std::vector< std::pair< Polygon, float > > * height_polygons = nullptr )
729{
730 assert(m_print != nullptr);
731 assert(m_print == m_fff_print);
732
733 m_fff_print->is_BBL_printer() = GUI::wxGetApp().preset_bundle->is_bbl_vendor();
734 return m_print->validate(warnings, collison_polygons, height_polygons);
735}

References m_fff_print, and m_print.

◆ GUI::Plater

friend class GUI::Plater
friend

Member Data Documentation

◆ m_condition

std::condition_variable Slic3r::BackgroundSlicingProcess::m_condition
private

◆ m_current_plate

GUI::PartPlate* Slic3r::BackgroundSlicingProcess::m_current_plate
private

◆ m_event_export_began_id

int Slic3r::BackgroundSlicingProcess::m_event_export_began_id = 0
private

◆ m_event_export_finished_id

int Slic3r::BackgroundSlicingProcess::m_event_export_finished_id = 0
private

◆ m_event_finished_id

int Slic3r::BackgroundSlicingProcess::m_event_finished_id = 0
private

Referenced by set_finished_event(), and thread_proc().

◆ m_event_slicing_completed_id

int Slic3r::BackgroundSlicingProcess::m_event_slicing_completed_id = 0
private

◆ m_export_path

std::string Slic3r::BackgroundSlicingProcess::m_export_path
private

◆ m_export_path_on_removable_media

bool Slic3r::BackgroundSlicingProcess::m_export_path_on_removable_media = false
private

◆ m_export_statistics

bool Slic3r::BackgroundSlicingProcess::m_export_statistics = false
private

◆ m_fff_print

◆ m_gcode_result

GCodeProcessorResult* Slic3r::BackgroundSlicingProcess::m_gcode_result = nullptr
private

◆ m_internal_cancelled

bool Slic3r::BackgroundSlicingProcess::m_internal_cancelled = false
private

◆ m_mutex

std::mutex Slic3r::BackgroundSlicingProcess::m_mutex
private

◆ m_print

◆ m_printer_tech

PrinterTechnology Slic3r::BackgroundSlicingProcess::m_printer_tech = ptUnknown
private

◆ m_sla_archive

SL1Archive Slic3r::BackgroundSlicingProcess::m_sla_archive
private

◆ m_sla_print

◆ m_state

State Slic3r::BackgroundSlicingProcess::m_state = STATE_INITIAL
private

◆ m_step_state

PrintState<BackgroundSlicingProcessStep, bspsCount> Slic3r::BackgroundSlicingProcess::m_step_state
private

◆ m_temp_output_path

std::string Slic3r::BackgroundSlicingProcess::m_temp_output_path
private

◆ m_thread

boost::thread Slic3r::BackgroundSlicingProcess::m_thread
private

Referenced by join_background_thread(), and start().

◆ m_thumbnail_cb

ThumbnailsGeneratorCallback Slic3r::BackgroundSlicingProcess::m_thumbnail_cb = nullptr
private

◆ m_ui_task

std::shared_ptr<UITask> Slic3r::BackgroundSlicingProcess::m_ui_task
private

◆ m_upload_job

PrintHostJob Slic3r::BackgroundSlicingProcess::m_upload_job
private

The documentation for this class was generated from the following files: