Remove progress indicators for individual threads.
This commit is contained in:
parent
9beb767830
commit
99f2d40b53
2 changed files with 28 additions and 75 deletions
|
@ -18,26 +18,24 @@
|
||||||
|
|
||||||
namespace Slic3r {
|
namespace Slic3r {
|
||||||
|
|
||||||
class AppControllerBoilerplate::PriMap {
|
class AppControllerBoilerplate::PriData {
|
||||||
public:
|
public:
|
||||||
using M = std::unordered_map<std::thread::id, ProgresIndicatorPtr>;
|
|
||||||
std::mutex m;
|
std::mutex m;
|
||||||
M store;
|
|
||||||
std::thread::id ui_thread;
|
std::thread::id ui_thread;
|
||||||
|
|
||||||
inline explicit PriMap(std::thread::id uit): ui_thread(uit) {}
|
inline explicit PriData(std::thread::id uit): ui_thread(uit) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
AppControllerBoilerplate::AppControllerBoilerplate()
|
AppControllerBoilerplate::AppControllerBoilerplate()
|
||||||
:progressind_(new PriMap(std::this_thread::get_id())) {}
|
:pri_data_(new PriData(std::this_thread::get_id())) {}
|
||||||
|
|
||||||
AppControllerBoilerplate::~AppControllerBoilerplate() {
|
AppControllerBoilerplate::~AppControllerBoilerplate() {
|
||||||
progressind_.reset();
|
pri_data_.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AppControllerBoilerplate::is_main_thread() const
|
bool AppControllerBoilerplate::is_main_thread() const
|
||||||
{
|
{
|
||||||
return progressind_->ui_thread == std::this_thread::get_id();
|
return pri_data_->ui_thread == std::this_thread::get_id();
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace GUI {
|
namespace GUI {
|
||||||
|
@ -53,50 +51,25 @@ static const PrintStep STEP_SKIRT = psSkirt;
|
||||||
static const PrintStep STEP_BRIM = psBrim;
|
static const PrintStep STEP_BRIM = psBrim;
|
||||||
static const PrintStep STEP_WIPE_TOWER = psWipeTower;
|
static const PrintStep STEP_WIPE_TOWER = psWipeTower;
|
||||||
|
|
||||||
void AppControllerBoilerplate::progress_indicator(
|
|
||||||
AppControllerBoilerplate::ProgresIndicatorPtr progrind) {
|
|
||||||
progressind_->m.lock();
|
|
||||||
progressind_->store[std::this_thread::get_id()] = progrind;
|
|
||||||
progressind_->m.unlock();
|
|
||||||
}
|
|
||||||
|
|
||||||
void AppControllerBoilerplate::progress_indicator(unsigned statenum,
|
|
||||||
const string &title,
|
|
||||||
const string &firstmsg)
|
|
||||||
{
|
|
||||||
progressind_->m.lock();
|
|
||||||
progressind_->store[std::this_thread::get_id()] =
|
|
||||||
create_progress_indicator(statenum, title, firstmsg);
|
|
||||||
progressind_->m.unlock();
|
|
||||||
}
|
|
||||||
|
|
||||||
void AppControllerBoilerplate::progress_indicator(unsigned statenum,
|
|
||||||
const string &title)
|
|
||||||
{
|
|
||||||
progressind_->m.lock();
|
|
||||||
progressind_->store[std::this_thread::get_id()] =
|
|
||||||
create_progress_indicator(statenum, title);
|
|
||||||
progressind_->m.unlock();
|
|
||||||
}
|
|
||||||
|
|
||||||
AppControllerBoilerplate::ProgresIndicatorPtr
|
AppControllerBoilerplate::ProgresIndicatorPtr
|
||||||
AppControllerBoilerplate::progress_indicator() {
|
AppControllerBoilerplate::global_progress_indicator() {
|
||||||
|
|
||||||
PriMap::M::iterator pret;
|
|
||||||
ProgresIndicatorPtr ret;
|
ProgresIndicatorPtr ret;
|
||||||
|
|
||||||
progressind_->m.lock();
|
pri_data_->m.lock();
|
||||||
if( (pret = progressind_->store.find(std::this_thread::get_id()))
|
ret = global_progressind_;
|
||||||
== progressind_->store.end())
|
pri_data_->m.unlock();
|
||||||
{
|
|
||||||
progressind_->store[std::this_thread::get_id()] = ret =
|
|
||||||
global_progressind_;
|
|
||||||
} else ret = pret->second;
|
|
||||||
progressind_->m.unlock();
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AppControllerBoilerplate::global_progress_indicator(
|
||||||
|
AppControllerBoilerplate::ProgresIndicatorPtr gpri)
|
||||||
|
{
|
||||||
|
pri_data_->m.lock();
|
||||||
|
global_progressind_ = gpri;
|
||||||
|
pri_data_->m.unlock();
|
||||||
|
}
|
||||||
|
|
||||||
void PrintController::make_skirt()
|
void PrintController::make_skirt()
|
||||||
{
|
{
|
||||||
assert(print_ != nullptr);
|
assert(print_ != nullptr);
|
||||||
|
@ -195,8 +168,6 @@ void PrintController::make_perimeters(PrintObject *pobj)
|
||||||
|
|
||||||
slice(pobj);
|
slice(pobj);
|
||||||
|
|
||||||
auto&& prgind = progress_indicator();
|
|
||||||
|
|
||||||
if (!pobj->state.is_done(STEP_PERIMETERS)) {
|
if (!pobj->state.is_done(STEP_PERIMETERS)) {
|
||||||
pobj->_make_perimeters();
|
pobj->_make_perimeters();
|
||||||
}
|
}
|
||||||
|
@ -279,7 +250,8 @@ void PrintController::slice(AppControllerBoilerplate::ProgresIndicatorPtr pri)
|
||||||
|
|
||||||
void PrintController::slice()
|
void PrintController::slice()
|
||||||
{
|
{
|
||||||
auto pri = progress_indicator();
|
auto pri = global_progress_indicator();
|
||||||
|
if(!pri) pri = create_progress_indicator(100, L("Slicing"));
|
||||||
slice(pri);
|
slice(pri);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -324,7 +296,7 @@ void AppController::arrange_model()
|
||||||
unsigned count = 0;
|
unsigned count = 0;
|
||||||
for(auto obj : model_->objects) count += obj->instances.size();
|
for(auto obj : model_->objects) count += obj->instances.size();
|
||||||
|
|
||||||
auto pind = progress_indicator();
|
auto pind = global_progress_indicator();
|
||||||
|
|
||||||
float pmax = 1.0;
|
float pmax = 1.0;
|
||||||
|
|
||||||
|
|
|
@ -30,16 +30,16 @@ class PrintConfig;
|
||||||
* a cli client.
|
* a cli client.
|
||||||
*/
|
*/
|
||||||
class AppControllerBoilerplate {
|
class AppControllerBoilerplate {
|
||||||
class PriMap; // Some structure to store progress indication data
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
/// A Progress indicator object smart pointer
|
/// A Progress indicator object smart pointer
|
||||||
using ProgresIndicatorPtr = std::shared_ptr<IProgressIndicator>;
|
using ProgresIndicatorPtr = std::shared_ptr<IProgressIndicator>;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
class PriData; // Some structure to store progress indication data
|
||||||
|
|
||||||
// Pimpl data for thread safe progress indication features
|
// Pimpl data for thread safe progress indication features
|
||||||
std::unique_ptr<PriMap> progressind_;
|
std::unique_ptr<PriData> pri_data_;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
@ -102,32 +102,14 @@ public:
|
||||||
const string& description);
|
const string& description);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Set up a progress indicator for the current thread.
|
* @brief Return the global progress indicator for the current controller.
|
||||||
* @param progrind An already created progress indicator object.
|
* Can be empty as well.
|
||||||
|
*
|
||||||
|
* Only one thread should use the global indicator at a time.
|
||||||
*/
|
*/
|
||||||
void progress_indicator(ProgresIndicatorPtr progrind);
|
ProgresIndicatorPtr global_progress_indicator();
|
||||||
|
|
||||||
/**
|
void global_progress_indicator(ProgresIndicatorPtr gpri);
|
||||||
* @brief Create and set up a new progress indicator for the current thread.
|
|
||||||
* @param statenum The number of states for the given procedure.
|
|
||||||
* @param title The title of the procedure.
|
|
||||||
* @param firstmsg The message for the first subtask to be displayed.
|
|
||||||
*/
|
|
||||||
void progress_indicator(unsigned statenum,
|
|
||||||
const string& title,
|
|
||||||
const string& firstmsg);
|
|
||||||
|
|
||||||
void progress_indicator(unsigned statenum,
|
|
||||||
const string& title);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Return the progress indicator set up for the current thread. This
|
|
||||||
* can be empty as well.
|
|
||||||
* @return A progress indicator object implementing IProgressIndicator. If
|
|
||||||
* a global progress indicator is available for the current implementation
|
|
||||||
* than this will be set up for the current thread and returned.
|
|
||||||
*/
|
|
||||||
ProgresIndicatorPtr progress_indicator();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief A predicate telling the caller whether it is the thread that
|
* @brief A predicate telling the caller whether it is the thread that
|
||||||
|
@ -258,7 +240,6 @@ public:
|
||||||
*/
|
*/
|
||||||
void set_print(Print *print) {
|
void set_print(Print *print) {
|
||||||
printctl = PrintController::create(print);
|
printctl = PrintController::create(print);
|
||||||
printctl->progress_indicator(progress_indicator());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue