Welcome to mirror list, hosted at ThFree Co, Russian Federation.

ProgressIndicator.hpp « GUI « slic3r « src - github.com/prusa3d/PrusaSlicer.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 0cf8b4a17cb9921bf82d37de2852a3955d4c63e1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#ifndef IPROGRESSINDICATOR_HPP
#define IPROGRESSINDICATOR_HPP

#include <string>
#include <functional>

namespace Slic3r {

/**
 * @brief Generic progress indication interface.
 */
class ProgressIndicator {
public:
    using CancelFn = std::function<void(void)>; // Cancel function signature.

private:
    float state_ = .0f, max_ = 1.f, step_;
    CancelFn cancelfunc_ = [](){};

public:

    inline virtual ~ProgressIndicator() {}

    /// Get the maximum of the progress range.
    float max() const { return max_; }

    /// Get the current progress state
    float state() const { return state_; }

    /// Set the maximum of the progress range
    virtual void max(float maxval) { max_ = maxval; }

    /// Set the current state of the progress.
    virtual void state(float val)  { state_ = val; }

    /**
     * @brief Number of states int the progress. Can be used instead of giving a
     * maximum value.
     */
    virtual void states(unsigned statenum) {
        step_ = max_ / statenum;
    }

    /// Message shown on the next status update.
    virtual void message(const std::string&) = 0;

    /// Title of the operation.
    virtual void title(const std::string&) = 0;

    /// Formatted message for the next status update. Works just like sprintf.
    virtual void message_fmt(const std::string& fmt, ...);

    /// Set up a cancel callback for the operation if feasible.
    virtual void on_cancel(CancelFn func = CancelFn()) { cancelfunc_ = func; }

    /**
     * Explicitly shut down the progress indicator and call the associated
     * callback.
     */
    virtual void cancel() { cancelfunc_(); }

    /// Convenience function to call message and status update in one function.
    void update(float st, const std::string& msg) {
        message(msg); state(st);
    }
};

}

#endif // IPROGRESSINDICATOR_HPP