OrcaSlicer latest
OrcaSlicer
Loading...
Searching...
No Matches
Slic3r::PrintState< StepType, COUNT > Class Template Reference

#include </home/runner/work/OrcaSlicer/OrcaSlicer/src/libslic3r/PrintBase.hpp>

Inheritance diagram for Slic3r::PrintState< StepType, COUNT >:
Collaboration diagram for Slic3r::PrintState< StepType, COUNT >:

Public Types

enum  State { INVALID , STARTED , DONE }
enum class  WarningLevel { NON_CRITICAL , CRITICAL }
enum  SlicingNotificationType {
  SlicingDefaultNotification = 0 , SlicingReplaceInitEmptyLayers , SlicingNeedSupportOn , SlicingEmptyGcodeLayers ,
  SlicingGcodeOverlap , SlicingExclusionVolumeToolpath , SlicingPreciseSeamWarning
}
typedef size_t TimeStamp

Public Member Functions

 PrintState ()
StateWithTimeStamp state_with_timestamp (StepType step, std::mutex &mtx) const
StateWithWarnings state_with_warnings (StepType step, std::mutex &mtx) const
bool is_started (StepType step, std::mutex &mtx) const
bool is_done (StepType step, std::mutex &mtx) const
StateWithTimeStamp state_with_timestamp_unguarded (StepType step) const
bool is_started_unguarded (StepType step) const
bool is_done_unguarded (StepType step) const
template<typename ThrowIfCanceled>
bool set_started (StepType step, std::mutex &mtx, ThrowIfCanceled throw_if_canceled)
template<typename ThrowIfCanceled>
std::pair< TimeStamp, bool > set_done (StepType step, std::mutex &mtx, ThrowIfCanceled throw_if_canceled)
template<typename CancelationCallback>
bool invalidate (StepType step, CancelationCallback cancel)
template<typename CancelationCallback, typename StepTypeIterator>
bool invalidate_multiple (StepTypeIterator step_begin, StepTypeIterator step_end, CancelationCallback cancel)
template<typename CancelationCallback>
bool invalidate_all (CancelationCallback cancel)
std::pair< StepType, bool > active_step_add_warning (PrintStateBase::WarningLevel warning_level, const std::string &message, int message_id, std::mutex &mtx)

Static Protected Attributes

static size_t g_last_timestamp = 0

Private Attributes

StateWithWarnings m_state [COUNT]
int m_step_active = -1

Detailed Description

template<class StepType, size_t COUNT>
class Slic3r::PrintState< StepType, COUNT >

Member Typedef Documentation

◆ TimeStamp

typedef size_t Slic3r::PrintStateBase::TimeStamp
inherited

Member Enumeration Documentation

◆ SlicingNotificationType

Enumerator
SlicingDefaultNotification 
SlicingReplaceInitEmptyLayers 
SlicingNeedSupportOn 
SlicingEmptyGcodeLayers 
SlicingGcodeOverlap 
SlicingExclusionVolumeToolpath 
SlicingPreciseSeamWarning 
67 {
68 SlicingDefaultNotification = 0, //normal status update, called by set_status
75 };
@ SlicingPreciseSeamWarning
Definition PrintBase.hpp:74
@ SlicingGcodeOverlap
Definition PrintBase.hpp:72
@ SlicingNeedSupportOn
Definition PrintBase.hpp:70
@ SlicingEmptyGcodeLayers
Definition PrintBase.hpp:71
@ SlicingDefaultNotification
Definition PrintBase.hpp:68
@ SlicingReplaceInitEmptyLayers
Definition PrintBase.hpp:69
@ SlicingExclusionVolumeToolpath
Definition PrintBase.hpp:73

◆ State

Enumerator
INVALID 
STARTED 
DONE 
55 {
56 INVALID,
57 STARTED,
58 DONE,
59 };
@ DONE
Definition PrintBase.hpp:58
@ INVALID
Definition PrintBase.hpp:56
@ STARTED
Definition PrintBase.hpp:57

◆ WarningLevel

enum class Slic3r::PrintStateBase::WarningLevel
stronginherited
Enumerator
NON_CRITICAL 
CRITICAL 
61 {
62 NON_CRITICAL,
63 CRITICAL
64 };

Constructor & Destructor Documentation

◆ PrintState()

template<class StepType, size_t COUNT>
Slic3r::PrintState< StepType, COUNT >::PrintState ( )
inline
121{}

Member Function Documentation

◆ active_step_add_warning()

template<class StepType, size_t COUNT>
std::pair< StepType, bool > Slic3r::PrintState< StepType, COUNT >::active_step_add_warning ( PrintStateBase::WarningLevel warning_level,
const std::string & message,
int message_id,
std::mutex & mtx )
inline
306 {
308 assert(m_step_active != -1);
310 assert(state.state == STARTED);
312 // Does a warning of the same level and message or message_id exist already?
313 auto it = (message_id == 0) ?
314 std::find_if(state.warnings.begin(), state.warnings.end(), [&message](const auto &w) { return w.message_id == 0 && w.message == message; }) :
315 std::find_if(state.warnings.begin(), state.warnings.end(), [message_id](const auto& w) { return w.message_id == message_id; });
316 if (it == state.warnings.end())
317 // No, create a new warning and update UI.
318 state.warnings.emplace_back(PrintStateBase::Warning{ warning_level, true, message, message_id });
319 else if (it->message != message || it->level != warning_level) {
320 // Yes, however it needs an update.
321 it->message = message;
322 it->level = warning_level;
323 it->current = true;
324 } else if (it->current)
325 // Yes, and it is current. Don't update UI.
326 retval.second = false;
327 else
328 // Yes, but it is not current. Mark it as current.
329 it->current = true;
330 return retval;
331 }
Definition PrintBase.hpp:119
int m_step_active
Definition PrintBase.hpp:338
StateWithWarnings m_state[COUNT]
Definition PrintBase.hpp:334
Definition PrintBase.hpp:104

◆ invalidate()

template<class StepType, size_t COUNT>
template<typename CancelationCallback>
bool Slic3r::PrintState< StepType, COUNT >::invalidate ( StepType step,
CancelationCallback cancel )
inline
218 {
219 bool invalidated = m_state[step].state != INVALID;
220 if (invalidated) {
221#if 0
222 if (mtx.state != mtx.HELD) {
223 printf("Not held!\n");
224 }
225#endif
227 state.state = INVALID;
228 state.timestamp = ++ g_last_timestamp;
229 // Raise the mutex, so that the following cancel() callback could cancel
230 // the background processing.
231 // Internally the cancel() callback shall unlock the PrintBase::m_status_mutex to let
232 // the working thread proceed.
233 cancel();
234 // Now the worker thread should be stopped, therefore it cannot write into the warnings field.
235 // It is safe to modify it.
236 state.mark_warnings_non_current();
237 m_step_active = -1;
238 }
239 return invalidated;
240 }
static size_t g_last_timestamp
Definition PrintBase.hpp:113

◆ invalidate_all()

template<class StepType, size_t COUNT>
template<typename CancelationCallback>
bool Slic3r::PrintState< StepType, COUNT >::invalidate_all ( CancelationCallback cancel)
inline
278 {
279 bool invalidated = false;
280 for (size_t i = 0; i < COUNT; ++ i) {
282 if (state.state != INVALID) {
283 invalidated = true;
284 state.state = INVALID;
285 state.timestamp = ++ g_last_timestamp;
286 }
287 }
288 if (invalidated) {
289 cancel();
290 // Now the worker thread should be stopped, therefore it cannot write into the warnings field.
291 // It is safe to modify the warnings.
292 for (size_t i = 0; i < COUNT; ++ i)
294 m_step_active = -1;
295 }
296 return invalidated;
297 }

◆ invalidate_multiple()

template<class StepType, size_t COUNT>
template<typename CancelationCallback, typename StepTypeIterator>
bool Slic3r::PrintState< StepType, COUNT >::invalidate_multiple ( StepTypeIterator step_begin,
StepTypeIterator step_end,
CancelationCallback cancel )
inline
243 {
244 bool invalidated = false;
245 for (StepTypeIterator it = step_begin; it != step_end; ++ it) {
247 if (state.state != INVALID) {
248 invalidated = true;
249 state.state = INVALID;
250 state.timestamp = ++ g_last_timestamp;
251 }
252 }
253 if (invalidated) {
254#if 0
255 if (mtx.state != mtx.HELD) {
256 printf("Not held!\n");
257 }
258#endif
259 // Raise the mutex, so that the following cancel() callback could cancel
260 // the background processing.
261 // Internally the cancel() callback shall unlock the PrintBase::m_status_mutex to let
262 // the working thread to proceed.
263 cancel();
264 // Now the worker thread should be stopped, therefore it cannot write into the warnings field.
265 // It is safe to modify the warnings.
268 m_step_active = -1;
269 }
270 return invalidated;
271 }

◆ is_done()

template<class StepType, size_t COUNT>
bool Slic3r::PrintState< StepType, COUNT >::is_done ( StepType step,
std::mutex & mtx ) const
inline
139 {
140 return this->state_with_timestamp(step, mtx).state == DONE;
141 }
StateWithTimeStamp state_with_timestamp(StepType step, std::mutex &mtx) const
Definition PrintBase.hpp:123
State state
Definition PrintBase.hpp:83

◆ is_done_unguarded()

template<class StepType, size_t COUNT>
bool Slic3r::PrintState< StepType, COUNT >::is_done_unguarded ( StepType step) const
inline
151 {
153 }
StateWithTimeStamp state_with_timestamp_unguarded(StepType step) const
Definition PrintBase.hpp:143

◆ is_started()

template<class StepType, size_t COUNT>
bool Slic3r::PrintState< StepType, COUNT >::is_started ( StepType step,
std::mutex & mtx ) const
inline
135 {
136 return this->state_with_timestamp(step, mtx).state == STARTED;
137 }

◆ is_started_unguarded()

template<class StepType, size_t COUNT>
bool Slic3r::PrintState< StepType, COUNT >::is_started_unguarded ( StepType step) const
inline
147 {
149 }

◆ set_done()

template<class StepType, size_t COUNT>
template<typename ThrowIfCanceled>
std::pair< TimeStamp, bool > Slic3r::PrintState< StepType, COUNT >::set_done ( StepType step,
std::mutex & mtx,
ThrowIfCanceled throw_if_canceled )
inline
193 {
195 // If canceled, throw before changing the step state.
198 assert(m_step_active == static_cast<int>(step));
200 state.state = DONE;
201 state.timestamp = ++ g_last_timestamp;
202 m_step_active = -1;
203 // Remove all non-current warnings.
204 auto it = std::remove_if(state.warnings.begin(), state.warnings.end(), [](const auto &w) { return ! w.current; });
205 bool update_warning_ui = false;
206 if (it != state.warnings.end()) {
207 state.warnings.erase(it, state.warnings.end());
208 update_warning_ui = true;
209 }
210 return std::make_pair(state.timestamp, update_warning_ui);
211 }

◆ set_started()

template<class StepType, size_t COUNT>
template<typename ThrowIfCanceled>
bool Slic3r::PrintState< StepType, COUNT >::set_started ( StepType step,
std::mutex & mtx,
ThrowIfCanceled throw_if_canceled )
inline
160 {
162 // If canceled, throw before changing the step state.
164#ifndef NDEBUG
165// The following test is not necessarily valid after the background processing thread
166// is stopped with throw_if_canceled(), as the CanceledException is not being catched
167// by the Print or PrintObject to update m_step_active or m_state[...].state.
168// This should not be a problem as long as the caller calls set_started() / set_done() /
169// active_step_add_warning() consistently. From the robustness point of view it would be
170// be better to catch CanceledException and do the updates. From the performance point of view,
171// the current implementation is optimal.
172//
173// assert(m_step_active == -1);
174// for (int i = 0; i < int(COUNT); ++ i)
175// assert(m_state[i].state != STARTED);
176#endif // NDEBUG
177 if (m_state[step].state == DONE)
178 return false;
180 state.state = STARTED;
181 state.timestamp = ++ g_last_timestamp;
182 state.mark_warnings_non_current();
183 m_step_active = static_cast<int>(step);
184 return true;
185 }

◆ state_with_timestamp()

template<class StepType, size_t COUNT>
StateWithTimeStamp Slic3r::PrintState< StepType, COUNT >::state_with_timestamp ( StepType step,
std::mutex & mtx ) const
inline

Referenced by Slic3r::PrintState< PrintObjectStepEnum, COUNT >::is_done(), and Slic3r::PrintState< PrintObjectStepEnum, COUNT >::is_started().

Here is the caller graph for this function:

◆ state_with_timestamp_unguarded()

template<class StepType, size_t COUNT>
StateWithTimeStamp Slic3r::PrintState< StepType, COUNT >::state_with_timestamp_unguarded ( StepType step) const
inline
143 {
144 return m_state[step];
145 }

Referenced by Slic3r::PrintState< PrintObjectStepEnum, COUNT >::is_done_unguarded(), and Slic3r::PrintState< PrintObjectStepEnum, COUNT >::is_started_unguarded().

Here is the caller graph for this function:

◆ state_with_warnings()

template<class StepType, size_t COUNT>
StateWithWarnings Slic3r::PrintState< StepType, COUNT >::state_with_warnings ( StepType step,
std::mutex & mtx ) const
inline

Member Data Documentation

◆ g_last_timestamp

size_t Slic3r::PrintStateBase::g_last_timestamp = 0
staticprotectedinherited

◆ m_state

template<class StepType, size_t COUNT>
StateWithWarnings Slic3r::PrintState< StepType, COUNT >::m_state[COUNT]
private

◆ m_step_active

template<class StepType, size_t COUNT>
int Slic3r::PrintState< StepType, COUNT >::m_step_active = -1
private

The documentation for this class was generated from the following file:
  • /home/runner/work/OrcaSlicer/OrcaSlicer/src/libslic3r/PrintBase.hpp