Prusa Slicer 2.6.0
Loading...
Searching...
No Matches
Slic3r::PrintState< StepType, COUNT > Class Template Reference

#include <src/libslic3r/PrintBase.hpp>

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

Public Types

enum class  State {
  Fresh , Started , Canceled , Done ,
  Invalidated
}
 
enum class  WarningLevel { NON_CRITICAL , CRITICAL }
 
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
 
void enable_unguarded (StepType step, bool enable)
 
void enable_all_unguarded (bool enable)
 
bool is_enabled_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)
 
bool query_reset_dirty_unguarded (StepType step)
 
void mark_canceled_unguarded ()
 
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

◆ State

enum class Slic3r::PrintStateBase::State
stronginherited
Enumerator
Fresh 
Started 
Canceled 
Done 
Invalidated 
26 {
27 // Fresh state, either the object is new or the data of that particular milestone was cleaned up.
28 // Fresh state may transit to Started.
29 Fresh,
30 // Milestone was started and now it is being executed.
31 // Started state may transit to Canceled with invalid data or Done with valid data.
32 Started,
33 // Milestone was being executed, but now it is canceled and not yet cleaned up.
34 // Canceled state may transit to Fresh state if its invalid data is cleaned up
35 // or to Started state.
36 // Canceled and Invalidated states are of similar nature: Canceled step was Started but canceled,
37 // while Invalidated state was Done but invalidated.
39 // Milestone was finished successfully, it's data is now valid.
40 // Done state may transit to Invalidated state if its data is no more valid
41 // or to a Started state.
42 Done,
43 // Milestone was finished successfully (done), but now it is invalidated and it's data is no more valid.
44 // Invalidated state may transit to Fresh if its invalid data is cleaned up,
45 // or to state Started.
46 // Canceled and Invalidated states are of similar nature: Canceled step was Started but canceled,
47 // while Invalidated state was Done but invalidated.
49 };

◆ WarningLevel

enum class Slic3r::PrintStateBase::WarningLevel
stronginherited
Enumerator
NON_CRITICAL 
CRITICAL 

Constructor & Destructor Documentation

◆ PrintState()

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

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
322 {
323 std::scoped_lock<std::mutex> lock(mtx);
324 assert(m_step_active != -1);
325 StateWithWarnings &state = m_state[m_step_active];
326 assert(state.state == State::Started);
327 std::pair<StepType, bool> retval(static_cast<StepType>(m_step_active), true);
328 // Does a warning of the same level and message or message_id exist already?
329 auto it = (message_id == 0) ?
330 std::find_if(state.warnings.begin(), state.warnings.end(), [&message](const auto &w) { return w.message_id == 0 && w.message == message; }) :
331 std::find_if(state.warnings.begin(), state.warnings.end(), [message_id](const auto& w) { return w.message_id == message_id; });
332 if (it == state.warnings.end())
333 // No, create a new warning and update UI.
334 state.warnings.emplace_back(PrintStateBase::Warning{ warning_level, true, message, message_id });
335 else if (it->message != message || it->level != warning_level) {
336 // Yes, however it needs an update.
337 it->message = message;
338 it->level = warning_level;
339 it->current = true;
340 } else if (it->current)
341 // Yes, and it is current. Don't update UI.
342 retval.second = false;
343 else
344 // Yes, but it is not current. Mark it as current.
345 it->current = true;
346 return retval;
347 }
int m_step_active
Definition PrintBase.hpp:354
StateWithWarnings m_state[COUNT]
Definition PrintBase.hpp:350
#define const
Definition getopt.c:38
S::iterator begin(S &sh, const PathTag &)
Definition geometry_traits.hpp:614
S::iterator end(S &sh, const PathTag &)
Definition geometry_traits.hpp:620
STL namespace.

References Slic3r::PrintState< StepType, COUNT >::m_state, Slic3r::PrintState< StepType, COUNT >::m_step_active, Slic3r::PrintStateBase::Started, Slic3r::PrintStateBase::StateWithTimeStamp::state, and Slic3r::PrintStateBase::StateWithWarnings::warnings.

Referenced by Slic3r::PrintBaseWithState< PrintStepEnumType, COUNT >::active_step_add_warning(), and Slic3r::PrintObjectBaseWithState< PrintType, PrintObjectStepEnumType, COUNT >::active_step_add_warning().

+ Here is the caller graph for this function:

◆ enable_all_unguarded()

template<class StepType , size_t COUNT>
void Slic3r::PrintState< StepType, COUNT >::enable_all_unguarded ( bool  enable)
inline
154 {
155 for (size_t istep = 0; istep < COUNT; ++ istep)
156 m_state[istep].enabled = enable;
157 }

References Slic3r::PrintState< StepType, COUNT >::m_state.

Referenced by Slic3r::PrintObjectBaseWithState< PrintType, PrintObjectStepEnumType, COUNT >::enable_all_steps_unguarded(), Slic3r::PrintObjectBaseWithState< PrintType, PrintObjectStepEnumType, COUNT >::finalize_impl(), and Slic3r::PrintBaseWithState< PrintStepEnumType, COUNT >::finalize_impl().

+ Here is the caller graph for this function:

◆ enable_unguarded()

template<class StepType , size_t COUNT>
void Slic3r::PrintState< StepType, COUNT >::enable_unguarded ( StepType  step,
bool  enable 
)
inline
150 {
151 m_state[step].enabled = enable;
152 }
Coord step(const Coord &crd, Dir d)
Definition MarchingSquares.hpp:137
bool enabled
Definition PrintBase.hpp:63

References Slic3r::PrintStateBase::StateWithTimeStamp::enabled, and Slic3r::PrintState< StepType, COUNT >::m_state.

Referenced by Slic3r::PrintObjectBaseWithState< PrintType, PrintObjectStepEnumType, COUNT >::enable_step_unguarded(), and Slic3r::PrintBaseWithState< PrintStepEnumType, COUNT >::set_task_impl().

+ Here is the caller graph for this function:

◆ invalidate()

template<class StepType , size_t COUNT>
template<typename CancelationCallback >
bool Slic3r::PrintState< StepType, COUNT >::invalidate ( StepType  step,
CancelationCallback  cancel 
)
inline
227 {
228 if (PrintStateBase::StateWithWarnings &state = m_state[step]; state.try_invalidate()) {
229#if 0
230 if (mtx.state != mtx.HELD) {
231 printf("Not held!\n");
232 }
233#endif
234 // Raise the mutex, so that the following cancel() callback could cancel
235 // the background processing.
236 // Internally the cancel() callback shall unlock the PrintBase::m_status_mutex to let
237 // the working thread proceed.
238 cancel();
239 // Now the worker thread should be stopped, therefore it cannot write into the warnings field.
240 // It is safe to modify it.
241 state.mark_warnings_non_current();
242 m_step_active = -1;
243 return true;
244 } else
245 return false;
246 }
bool try_invalidate()
Definition PrintBase.hpp:72

References Slic3r::PrintState< StepType, COUNT >::m_state, Slic3r::PrintState< StepType, COUNT >::m_step_active, and Slic3r::PrintStateBase::StateWithTimeStamp::try_invalidate().

Referenced by Slic3r::BackgroundSlicingProcess::invalidate_step(), Slic3r::PrintObjectBaseWithState< PrintType, PrintObjectStepEnumType, COUNT >::invalidate_step(), and Slic3r::PrintBaseWithState< PrintStepEnumType, COUNT >::invalidate_step().

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

◆ invalidate_all()

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

References Slic3r::PrintState< StepType, COUNT >::m_state, and Slic3r::PrintState< StepType, COUNT >::m_step_active.

Referenced by Slic3r::PrintBaseWithState< PrintStepEnumType, COUNT >::invalidate_all_steps(), Slic3r::PrintObjectBaseWithState< PrintType, PrintObjectStepEnumType, COUNT >::invalidate_all_steps(), and Slic3r::BackgroundSlicingProcess::invalidate_all_steps().

+ Here is the caller graph for this function:

◆ 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
249 {
250 bool invalidated = false;
251 for (StepTypeIterator it = step_begin; it != step_end; ++ it)
252 if (m_state[*it].try_invalidate())
253 invalidated = true;
254 if (invalidated) {
255#if 0
256 if (mtx.state != mtx.HELD) {
257 printf("Not held!\n");
258 }
259#endif
260 // Raise the mutex, so that the following cancel() callback could cancel
261 // the background processing.
262 // Internally the cancel() callback shall unlock the PrintBase::m_status_mutex to let
263 // the working thread to proceed.
264 cancel();
265 // Now the worker thread should be stopped, therefore it cannot write into the warnings field.
266 // It is safe to modify the warnings.
267 for (StepTypeIterator it = step_begin; it != step_end; ++ it)
268 m_state[*it].mark_warnings_non_current();
269 m_step_active = -1;
270 }
271 return invalidated;
272 }

References Slic3r::PrintState< StepType, COUNT >::m_state, and Slic3r::PrintState< StepType, COUNT >::m_step_active.

Referenced by Slic3r::PrintObjectBaseWithState< PrintType, PrintObjectStepEnumType, COUNT >::invalidate_steps(), Slic3r::PrintBaseWithState< PrintStepEnumType, COUNT >::invalidate_steps(), Slic3r::PrintBaseWithState< PrintStepEnumType, COUNT >::invalidate_steps(), and Slic3r::PrintObjectBaseWithState< PrintType, PrintObjectStepEnumType, COUNT >::invalidate_steps().

+ Here is the caller graph for this function:

◆ is_done()

template<class StepType , size_t COUNT>
bool Slic3r::PrintState< StepType, COUNT >::is_done ( StepType  step,
std::mutex &  mtx 
) const
inline
134 {
135 return this->state_with_timestamp(step, mtx).state == State::Done;
136 }
StateWithTimeStamp state_with_timestamp(StepType step, std::mutex &mtx) const
Definition PrintBase.hpp:118
State state
Definition PrintBase.hpp:61

References Slic3r::PrintStateBase::Done, Slic3r::PrintStateBase::StateWithTimeStamp::state, and Slic3r::PrintState< StepType, COUNT >::state_with_timestamp().

Referenced by Slic3r::BackgroundSlicingProcess::is_step_done(), Slic3r::PrintObjectBaseWithState< PrintType, PrintObjectStepEnumType, COUNT >::is_step_done(), and Slic3r::PrintBaseWithState< PrintStepEnumType, COUNT >::is_step_done().

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

◆ is_done_unguarded()

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

References Slic3r::PrintStateBase::Done, Slic3r::PrintStateBase::StateWithTimeStamp::state, and Slic3r::PrintState< StepType, COUNT >::state_with_timestamp_unguarded().

Referenced by Slic3r::PrintObjectBaseWithState< PrintType, PrintObjectStepEnumType, COUNT >::is_step_done_unguarded(), and Slic3r::PrintBaseWithState< PrintStepEnumType, COUNT >::is_step_done_unguarded().

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

◆ is_enabled_unguarded()

template<class StepType , size_t COUNT>
bool Slic3r::PrintState< StepType, COUNT >::is_enabled_unguarded ( StepType  step) const
inline
159 {
160 return this->state_with_timestamp_unguarded(step).enabled;
161 }

References Slic3r::PrintStateBase::StateWithTimeStamp::enabled, and Slic3r::PrintState< StepType, COUNT >::state_with_timestamp_unguarded().

Referenced by Slic3r::PrintObjectBaseWithState< PrintType, PrintObjectStepEnumType, COUNT >::is_step_enabled_unguarded().

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

◆ is_started()

template<class StepType , size_t COUNT>
bool Slic3r::PrintState< StepType, COUNT >::is_started ( StepType  step,
std::mutex &  mtx 
) const
inline
130 {
131 return this->state_with_timestamp(step, mtx).state == State::Started;
132 }

References Slic3r::PrintStateBase::Started, Slic3r::PrintStateBase::StateWithTimeStamp::state, and Slic3r::PrintState< StepType, COUNT >::state_with_timestamp().

+ Here is the call graph for this function:

◆ is_started_unguarded()

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

References Slic3r::PrintStateBase::Started, Slic3r::PrintStateBase::StateWithTimeStamp::state, and Slic3r::PrintState< StepType, COUNT >::state_with_timestamp_unguarded().

Referenced by Slic3r::PrintObjectBaseWithState< PrintType, PrintObjectStepEnumType, COUNT >::is_step_started_unguarded(), and Slic3r::PrintBaseWithState< PrintStepEnumType, COUNT >::is_step_started_unguarded().

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

◆ mark_canceled_unguarded()

template<class StepType , size_t COUNT>
void Slic3r::PrintState< StepType, COUNT >::mark_canceled_unguarded ( )
inline
308 {
309 for (size_t i = 0; i < COUNT; ++ i) {
310 if (State &state = m_state[i].state; state == State::Started)
311 state = State::Canceled;
312 }
313 }
State
Definition PrintBase.hpp:26

References Slic3r::PrintStateBase::Canceled, Slic3r::PrintState< StepType, COUNT >::m_state, and Slic3r::PrintStateBase::Started.

Referenced by Slic3r::PrintObjectBaseWithState< PrintType, PrintObjectStepEnumType, COUNT >::finalize_impl(), and Slic3r::PrintBaseWithState< PrintStepEnumType, COUNT >::finalize_impl().

+ Here is the caller graph for this function:

◆ query_reset_dirty_unguarded()

template<class StepType , size_t COUNT>
bool Slic3r::PrintState< StepType, COUNT >::query_reset_dirty_unguarded ( StepType  step)
inline
297 {
298 if (PrintStateBase::StateWithWarnings &state = m_state[step]; state.is_dirty()) {
299 state.state = State::Fresh;
300 return true;
301 } else
302 return false;
303 }
bool is_dirty() const
Definition PrintBase.hpp:67

References Slic3r::PrintStateBase::Fresh, Slic3r::PrintStateBase::StateWithTimeStamp::is_dirty(), and Slic3r::PrintState< StepType, COUNT >::m_state.

Referenced by Slic3r::PrintObjectBaseWithState< PrintType, PrintObjectStepEnumType, COUNT >::query_reset_dirty_step_unguarded().

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

◆ 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
202 {
203 std::scoped_lock<std::mutex> lock(mtx);
204 // If canceled, throw before changing the step state.
205 throw_if_canceled();
206 assert(m_state[step].state == State::Started);
207 assert(m_step_active == static_cast<int>(step));
208 PrintStateBase::StateWithWarnings &state = m_state[step];
209 state.state = State::Done;
210 state.timestamp = ++ g_last_timestamp;
211 m_step_active = -1;
212 // Remove all non-current warnings.
213 auto it = std::remove_if(state.warnings.begin(), state.warnings.end(), [](const auto &w) { return ! w.current; });
214 bool update_warning_ui = false;
215 if (it != state.warnings.end()) {
216 state.warnings.erase(it, state.warnings.end());
217 update_warning_ui = true;
218 }
219 return std::make_pair(state.timestamp, update_warning_ui);
220 }
static size_t g_last_timestamp
Definition PrintBase.hpp:108

References Slic3r::PrintStateBase::Done, Slic3r::PrintStateBase::g_last_timestamp, Slic3r::PrintState< StepType, COUNT >::m_state, Slic3r::PrintState< StepType, COUNT >::m_step_active, Slic3r::PrintStateBase::Started, Slic3r::PrintStateBase::StateWithTimeStamp::state, Slic3r::PrintStateBase::StateWithTimeStamp::timestamp, and Slic3r::PrintStateBase::StateWithWarnings::warnings.

Referenced by Slic3r::PrintObjectBaseWithState< PrintType, PrintObjectStepEnumType, COUNT >::set_done(), Slic3r::PrintBaseWithState< PrintStepEnumType, COUNT >::set_done(), and Slic3r::BackgroundSlicingProcess::set_step_done().

+ Here is the caller graph for this function:

◆ 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
169 {
170 std::scoped_lock<std::mutex> lock(mtx);
171 // If canceled, throw before changing the step state.
172 throw_if_canceled();
173#ifndef NDEBUG
174// The following test is not necessarily valid after the background processing thread
175// is stopped with throw_if_canceled(), as the CanceledException is not being catched
176// by the Print or PrintObject to update m_step_active or m_state[...].state.
177// This should not be a problem as long as the caller calls set_started() / set_done() /
178// active_step_add_warning() consistently. From the robustness point of view it would be
179// be better to catch CanceledException and do the updates. From the performance point of view,
180// the current implementation is optimal.
181//
182// assert(m_step_active == -1);
183// for (int i = 0; i < int(COUNT); ++ i)
184// assert(m_state[i].state != State::Started);
185#endif // NDEBUG
186 PrintStateBase::StateWithWarnings &state = m_state[step];
187 if (! state.enabled || state.state == State::Done)
188 return false;
189 state.state = State::Started;
190 state.timestamp = ++ g_last_timestamp;
191 state.mark_warnings_non_current();
192 m_step_active = static_cast<int>(step);
193 return true;
194 }

References Slic3r::PrintStateBase::Done, Slic3r::PrintStateBase::StateWithTimeStamp::enabled, Slic3r::PrintStateBase::g_last_timestamp, Slic3r::PrintState< StepType, COUNT >::m_state, Slic3r::PrintState< StepType, COUNT >::m_step_active, Slic3r::PrintStateBase::StateWithWarnings::mark_warnings_non_current(), Slic3r::PrintStateBase::Started, Slic3r::PrintStateBase::StateWithTimeStamp::state, and Slic3r::PrintStateBase::StateWithTimeStamp::timestamp.

Referenced by Slic3r::PrintObjectBaseWithState< PrintType, PrintObjectStepEnumType, COUNT >::set_started(), Slic3r::PrintBaseWithState< PrintStepEnumType, COUNT >::set_started(), and Slic3r::BackgroundSlicingProcess::set_step_started().

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

◆ state_with_timestamp()

template<class StepType , size_t COUNT>
StateWithTimeStamp Slic3r::PrintState< StepType, COUNT >::state_with_timestamp ( StepType  step,
std::mutex &  mtx 
) const
inline
118 {
119 std::scoped_lock<std::mutex> lock(mtx);
120 StateWithTimeStamp state = m_state[step];
121 return state;
122 }

References Slic3r::PrintState< StepType, COUNT >::m_state.

Referenced by Slic3r::PrintState< StepType, COUNT >::is_done(), Slic3r::PrintState< StepType, COUNT >::is_started(), Slic3r::PrintObjectBaseWithState< PrintType, PrintObjectStepEnumType, COUNT >::step_state_with_timestamp(), and Slic3r::PrintBaseWithState< PrintStepEnumType, COUNT >::step_state_with_timestamp().

+ 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
138 {
139 return m_state[step];
140 }

References Slic3r::PrintState< StepType, COUNT >::m_state.

Referenced by Slic3r::PrintState< StepType, COUNT >::is_done_unguarded(), Slic3r::PrintState< StepType, COUNT >::is_enabled_unguarded(), and Slic3r::PrintState< StepType, 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
124 {
125 std::scoped_lock<std::mutex> lock(mtx);
126 StateWithWarnings state = m_state[step];
127 return state;
128 }

References Slic3r::PrintState< StepType, COUNT >::m_state.

Referenced by Slic3r::PrintObjectBaseWithState< PrintType, PrintObjectStepEnumType, COUNT >::step_state_with_warnings(), and Slic3r::PrintBaseWithState< PrintStepEnumType, COUNT >::step_state_with_warnings().

+ Here is the caller graph for this function:

Member Data Documentation

◆ g_last_timestamp

◆ m_state

◆ m_step_active


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