Refactoring member variable names for my classes to match our coding style.
This commit is contained in:
parent
1a0b72de2c
commit
3f0968fb02
9 changed files with 236 additions and 250 deletions
|
@ -32,10 +32,10 @@ template<FilePrinterFormat format, class LayerFormat = void>
|
||||||
class FilePrinter {
|
class FilePrinter {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
void printConfig(const Print&);
|
void print_config(const Print&);
|
||||||
|
|
||||||
// Draw an ExPolygon which is a polygon inside a slice on the specified layer.
|
// Draw an ExPolygon which is a polygon inside a slice on the specified layer.
|
||||||
void drawPolygon(const ExPolygon& p, unsigned lyr);
|
void draw_polygon(const ExPolygon& p, unsigned lyr);
|
||||||
|
|
||||||
// Tell the printer how many layers should it consider.
|
// Tell the printer how many layers should it consider.
|
||||||
void layers(unsigned layernum);
|
void layers(unsigned layernum);
|
||||||
|
@ -47,26 +47,26 @@ public:
|
||||||
* specified layer number than an appropriate number of layers will be
|
* specified layer number than an appropriate number of layers will be
|
||||||
* allocated in the printer.
|
* allocated in the printer.
|
||||||
*/
|
*/
|
||||||
void beginLayer(unsigned layer);
|
void begin_layer(unsigned layer);
|
||||||
|
|
||||||
// Allocate a new layer on top of the last and switch to it.
|
// Allocate a new layer on top of the last and switch to it.
|
||||||
void beginLayer();
|
void begin_layer();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Finish the selected layer. It means that no drawing is allowed on that
|
* Finish the selected layer. It means that no drawing is allowed on that
|
||||||
* layer anymore. This fact can be used to prepare the file system output
|
* layer anymore. This fact can be used to prepare the file system output
|
||||||
* data like png comprimation and so on.
|
* data like png comprimation and so on.
|
||||||
*/
|
*/
|
||||||
void finishLayer(unsigned layer);
|
void finish_layer(unsigned layer);
|
||||||
|
|
||||||
// Finish the top layer.
|
// Finish the top layer.
|
||||||
void finishLayer();
|
void finish_layer();
|
||||||
|
|
||||||
// Save all the layers into the file (or dir) specified in the path argument
|
// Save all the layers into the file (or dir) specified in the path argument
|
||||||
void save(const std::string& path);
|
void save(const std::string& path);
|
||||||
|
|
||||||
// Save only the selected layer to the file specified in path argument.
|
// Save only the selected layer to the file specified in path argument.
|
||||||
void saveLayer(unsigned lyr, const std::string& path);
|
void save_layer(unsigned lyr, const std::string& path);
|
||||||
};
|
};
|
||||||
|
|
||||||
template<class T = void> struct VeryFalse { static const bool value = false; };
|
template<class T = void> struct VeryFalse { static const bool value = false; };
|
||||||
|
@ -112,22 +112,22 @@ template<class LyrFormat> class FilePrinter<FilePrinterFormat::PNG, LyrFormat> {
|
||||||
|
|
||||||
// We will save the compressed PNG data into stringstreams which can be done
|
// We will save the compressed PNG data into stringstreams which can be done
|
||||||
// in parallel. Later we can write every layer to the disk sequentially.
|
// in parallel. Later we can write every layer to the disk sequentially.
|
||||||
std::vector<Layer> layers_rst_;
|
std::vector<Layer> m_layers_rst;
|
||||||
Raster::Resolution res_;
|
Raster::Resolution m_res;
|
||||||
Raster::PixelDim pxdim_;
|
Raster::PixelDim m_pxdim;
|
||||||
const Print *print_ = nullptr;
|
const Print *m_print = nullptr;
|
||||||
double exp_time_s_ = .0, exp_time_first_s_ = .0;
|
double m_exp_time_s = .0, m_exp_time_first_s = .0;
|
||||||
|
|
||||||
std::string createIniContent(const std::string& projectname) {
|
std::string createIniContent(const std::string& projectname) {
|
||||||
double layer_height = print_?
|
double layer_height = m_print?
|
||||||
print_->default_object_config().layer_height.getFloat() :
|
m_print->default_object_config().layer_height.getFloat() :
|
||||||
0.05;
|
0.05;
|
||||||
|
|
||||||
using std::string;
|
using std::string;
|
||||||
using std::to_string;
|
using std::to_string;
|
||||||
|
|
||||||
auto expt_str = to_string(exp_time_s_);
|
auto expt_str = to_string(m_exp_time_s);
|
||||||
auto expt_first_str = to_string(exp_time_first_s_);
|
auto expt_first_str = to_string(m_exp_time_first_s);
|
||||||
auto stepnum_str = to_string(static_cast<unsigned>(800*layer_height));
|
auto stepnum_str = to_string(static_cast<unsigned>(800*layer_height));
|
||||||
auto layerh_str = to_string(layer_height);
|
auto layerh_str = to_string(layer_height);
|
||||||
|
|
||||||
|
@ -155,51 +155,51 @@ public:
|
||||||
inline FilePrinter(double width_mm, double height_mm,
|
inline FilePrinter(double width_mm, double height_mm,
|
||||||
unsigned width_px, unsigned height_px,
|
unsigned width_px, unsigned height_px,
|
||||||
double exp_time, double exp_time_first):
|
double exp_time, double exp_time_first):
|
||||||
res_(width_px, height_px),
|
m_res(width_px, height_px),
|
||||||
pxdim_(width_mm/width_px, height_mm/height_px),
|
m_pxdim(width_mm/width_px, height_mm/height_px),
|
||||||
exp_time_s_(exp_time),
|
m_exp_time_s(exp_time),
|
||||||
exp_time_first_s_(exp_time_first)
|
m_exp_time_first_s(exp_time_first)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
FilePrinter(const FilePrinter& ) = delete;
|
FilePrinter(const FilePrinter& ) = delete;
|
||||||
FilePrinter(FilePrinter&& m):
|
FilePrinter(FilePrinter&& m):
|
||||||
layers_rst_(std::move(m.layers_rst_)),
|
m_layers_rst(std::move(m.m_layers_rst)),
|
||||||
res_(m.res_),
|
m_res(m.m_res),
|
||||||
pxdim_(m.pxdim_) {}
|
m_pxdim(m.m_pxdim) {}
|
||||||
|
|
||||||
inline void layers(unsigned cnt) { if(cnt > 0) layers_rst_.resize(cnt); }
|
inline void layers(unsigned cnt) { if(cnt > 0) m_layers_rst.resize(cnt); }
|
||||||
inline unsigned layers() const { return unsigned(layers_rst_.size()); }
|
inline unsigned layers() const { return unsigned(m_layers_rst.size()); }
|
||||||
|
|
||||||
void printConfig(const Print& printconf) { print_ = &printconf; }
|
void print_config(const Print& printconf) { m_print = &printconf; }
|
||||||
|
|
||||||
inline void drawPolygon(const ExPolygon& p, unsigned lyr) {
|
inline void draw_polygon(const ExPolygon& p, unsigned lyr) {
|
||||||
assert(lyr < layers_rst_.size());
|
assert(lyr < m_layers_rst.size());
|
||||||
layers_rst_[lyr].first.draw(p);
|
m_layers_rst[lyr].first.draw(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void beginLayer(unsigned lyr) {
|
inline void begin_layer(unsigned lyr) {
|
||||||
if(layers_rst_.size() <= lyr) layers_rst_.resize(lyr+1);
|
if(m_layers_rst.size() <= lyr) m_layers_rst.resize(lyr+1);
|
||||||
layers_rst_[lyr].first.reset(res_, pxdim_, ORIGIN);
|
m_layers_rst[lyr].first.reset(m_res, m_pxdim, ORIGIN);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void beginLayer() {
|
inline void begin_layer() {
|
||||||
layers_rst_.emplace_back();
|
m_layers_rst.emplace_back();
|
||||||
layers_rst_.front().first.reset(res_, pxdim_, ORIGIN);
|
m_layers_rst.front().first.reset(m_res, m_pxdim, ORIGIN);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void finishLayer(unsigned lyr_id) {
|
inline void finish_layer(unsigned lyr_id) {
|
||||||
assert(lyr_id < layers_rst_.size());
|
assert(lyr_id < m_layers_rst.size());
|
||||||
layers_rst_[lyr_id].first.save(layers_rst_[lyr_id].second,
|
m_layers_rst[lyr_id].first.save(m_layers_rst[lyr_id].second,
|
||||||
Raster::Compression::PNG);
|
Raster::Compression::PNG);
|
||||||
layers_rst_[lyr_id].first.reset();
|
m_layers_rst[lyr_id].first.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void finishLayer() {
|
inline void finish_layer() {
|
||||||
if(!layers_rst_.empty()) {
|
if(!m_layers_rst.empty()) {
|
||||||
layers_rst_.back().first.save(layers_rst_.back().second,
|
m_layers_rst.back().first.save(m_layers_rst.back().second,
|
||||||
Raster::Compression::PNG);
|
Raster::Compression::PNG);
|
||||||
layers_rst_.back().first.reset();
|
m_layers_rst.back().first.reset();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -212,14 +212,14 @@ public:
|
||||||
writer.next_entry("config.ini");
|
writer.next_entry("config.ini");
|
||||||
writer << createIniContent(project);
|
writer << createIniContent(project);
|
||||||
|
|
||||||
for(unsigned i = 0; i < layers_rst_.size(); i++) {
|
for(unsigned i = 0; i < m_layers_rst.size(); i++) {
|
||||||
if(layers_rst_[i].second.rdbuf()->in_avail() > 0) {
|
if(m_layers_rst[i].second.rdbuf()->in_avail() > 0) {
|
||||||
char lyrnum[6];
|
char lyrnum[6];
|
||||||
std::sprintf(lyrnum, "%.5d", i);
|
std::sprintf(lyrnum, "%.5d", i);
|
||||||
auto zfilename = project + lyrnum + ".png";
|
auto zfilename = project + lyrnum + ".png";
|
||||||
writer.next_entry(zfilename);
|
writer.next_entry(zfilename);
|
||||||
writer << layers_rst_[i].second.rdbuf();
|
writer << m_layers_rst[i].second.rdbuf();
|
||||||
layers_rst_[i].second.str("");
|
m_layers_rst[i].second.str("");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -230,9 +230,9 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void saveLayer(unsigned lyr, const std::string& path) {
|
void save_layer(unsigned lyr, const std::string& path) {
|
||||||
unsigned i = lyr;
|
unsigned i = lyr;
|
||||||
assert(i < layers_rst_.size());
|
assert(i < m_layers_rst.size());
|
||||||
|
|
||||||
char lyrnum[6];
|
char lyrnum[6];
|
||||||
std::sprintf(lyrnum, "%.5d", lyr);
|
std::sprintf(lyrnum, "%.5d", lyr);
|
||||||
|
@ -240,19 +240,19 @@ public:
|
||||||
|
|
||||||
std::fstream out(loc, std::fstream::out | std::fstream::binary);
|
std::fstream out(loc, std::fstream::out | std::fstream::binary);
|
||||||
if(out.good()) {
|
if(out.good()) {
|
||||||
layers_rst_[i].first.save(out, Raster::Compression::PNG);
|
m_layers_rst[i].first.save(out, Raster::Compression::PNG);
|
||||||
} else {
|
} else {
|
||||||
BOOST_LOG_TRIVIAL(error) << "Can't create file for layer";
|
BOOST_LOG_TRIVIAL(error) << "Can't create file for layer";
|
||||||
}
|
}
|
||||||
|
|
||||||
out.close();
|
out.close();
|
||||||
layers_rst_[i].first.reset();
|
m_layers_rst[i].first.reset();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Let's shadow this eigen interface
|
// Let's shadow this eigen interface
|
||||||
inline coord_t px(const Point& p) { return p(0); }
|
inline coord_t px(const Point& p) { return p(0); }
|
||||||
inline coord_t py(const Point& p) { return p(1); }
|
inline coord_t py(const Point& p) { return p(1); }
|
||||||
inline coordf_t px(const Vec2d& p) { return p(0); }
|
inline coordf_t px(const Vec2d& p) { return p(0); }
|
||||||
inline coordf_t py(const Vec2d& p) { return p(1); }
|
inline coordf_t py(const Vec2d& p) { return p(1); }
|
||||||
|
|
||||||
|
@ -306,7 +306,7 @@ void print_to(Print& print,
|
||||||
FilePrinter<format, LayerFormat> printer(width_mm, height_mm,
|
FilePrinter<format, LayerFormat> printer(width_mm, height_mm,
|
||||||
std::forward<Args>(args)...);
|
std::forward<Args>(args)...);
|
||||||
|
|
||||||
printer.printConfig(print);
|
printer.print_config(print);
|
||||||
|
|
||||||
printer.layers(layers.size()); // Allocate space for all the layers
|
printer.layers(layers.size()); // Allocate space for all the layers
|
||||||
|
|
||||||
|
@ -327,7 +327,7 @@ void print_to(Print& print,
|
||||||
{
|
{
|
||||||
LayerPtrs lrange = layers[keys[layer_id]];
|
LayerPtrs lrange = layers[keys[layer_id]];
|
||||||
|
|
||||||
printer.beginLayer(layer_id); // Switch to the appropriate layer
|
printer.begin_layer(layer_id); // Switch to the appropriate layer
|
||||||
|
|
||||||
for(Layer *lp : lrange) {
|
for(Layer *lp : lrange) {
|
||||||
Layer& l = *lp;
|
Layer& l = *lp;
|
||||||
|
@ -348,7 +348,7 @@ void print_to(Print& print,
|
||||||
slice.translate(-px(print_bb.min) + cx,
|
slice.translate(-px(print_bb.min) + cx,
|
||||||
-py(print_bb.min) + cy);
|
-py(print_bb.min) + cy);
|
||||||
|
|
||||||
printer.drawPolygon(slice, layer_id);
|
printer.draw_polygon(slice, layer_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*if(print.has_support_material() && layer_id > 0) {
|
/*if(print.has_support_material() && layer_id > 0) {
|
||||||
|
@ -361,7 +361,7 @@ void print_to(Print& print,
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
printer.finishLayer(layer_id); // Finish the layer for later saving it.
|
printer.finish_layer(layer_id); // Finish the layer for later saving it.
|
||||||
|
|
||||||
auto st = static_cast<int>(layer_id*80.0/layers.size());
|
auto st = static_cast<int>(layer_id*80.0/layers.size());
|
||||||
m.lock();
|
m.lock();
|
||||||
|
|
|
@ -37,37 +37,37 @@ public:
|
||||||
using Origin = Raster::Origin;
|
using Origin = Raster::Origin;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Raster::Resolution resolution_;
|
Raster::Resolution m_resolution;
|
||||||
Raster::PixelDim pxdim_;
|
Raster::PixelDim m_pxdim;
|
||||||
TBuffer buf_;
|
TBuffer m_buf;
|
||||||
TRawBuffer rbuf_;
|
TRawBuffer m_rbuf;
|
||||||
TPixelRenderer pixfmt_;
|
TPixelRenderer m_pixfmt;
|
||||||
TRawRenderer raw_renderer_;
|
TRawRenderer m_raw_renderer;
|
||||||
TRendererAA renderer_;
|
TRendererAA m_renderer;
|
||||||
Origin o_;
|
Origin m_o;
|
||||||
std::function<void(agg::path_storage&)> flipy_ = [](agg::path_storage&) {};
|
std::function<void(agg::path_storage&)> m_flipy = [](agg::path_storage&) {};
|
||||||
public:
|
public:
|
||||||
inline Impl(const Raster::Resolution& res, const Raster::PixelDim &pd,
|
inline Impl(const Raster::Resolution& res, const Raster::PixelDim &pd,
|
||||||
Origin o):
|
Origin o):
|
||||||
resolution_(res), pxdim_(pd),
|
m_resolution(res), m_pxdim(pd),
|
||||||
buf_(res.pixels()),
|
m_buf(res.pixels()),
|
||||||
rbuf_(reinterpret_cast<TPixelRenderer::value_type*>(buf_.data()),
|
m_rbuf(reinterpret_cast<TPixelRenderer::value_type*>(m_buf.data()),
|
||||||
res.width_px, res.height_px,
|
res.width_px, res.height_px,
|
||||||
res.width_px*TPixelRenderer::num_components),
|
res.width_px*TPixelRenderer::num_components),
|
||||||
pixfmt_(rbuf_),
|
m_pixfmt(m_rbuf),
|
||||||
raw_renderer_(pixfmt_),
|
m_raw_renderer(m_pixfmt),
|
||||||
renderer_(raw_renderer_),
|
m_renderer(m_raw_renderer),
|
||||||
o_(o)
|
m_o(o)
|
||||||
{
|
{
|
||||||
renderer_.color(ColorWhite);
|
m_renderer.color(ColorWhite);
|
||||||
|
|
||||||
// If we would like to play around with gamma
|
// If we would like to play around with gamma
|
||||||
// ras.gamma(agg::gamma_power(1.0));
|
// ras.gamma(agg::gamma_power(1.0));
|
||||||
|
|
||||||
clear();
|
clear();
|
||||||
|
|
||||||
if(o_ == Origin::TOP_LEFT) flipy_ = [this](agg::path_storage& path) {
|
if(m_o == Origin::TOP_LEFT) m_flipy = [this](agg::path_storage& path) {
|
||||||
path.flip_y(0, resolution_.height_px);
|
path.flip_y(0, m_resolution.height_px);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -76,35 +76,35 @@ public:
|
||||||
agg::scanline_p8 scanlines;
|
agg::scanline_p8 scanlines;
|
||||||
|
|
||||||
auto&& path = to_path(poly.contour);
|
auto&& path = to_path(poly.contour);
|
||||||
flipy_(path);
|
m_flipy(path);
|
||||||
ras.add_path(path);
|
ras.add_path(path);
|
||||||
|
|
||||||
for(auto h : poly.holes) {
|
for(auto h : poly.holes) {
|
||||||
auto&& holepath = to_path(h);
|
auto&& holepath = to_path(h);
|
||||||
flipy_(holepath);
|
m_flipy(holepath);
|
||||||
ras.add_path(holepath);
|
ras.add_path(holepath);
|
||||||
}
|
}
|
||||||
|
|
||||||
agg::render_scanlines(ras, scanlines, renderer_);
|
agg::render_scanlines(ras, scanlines, m_renderer);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void clear() {
|
inline void clear() {
|
||||||
raw_renderer_.clear(ColorBlack);
|
m_raw_renderer.clear(ColorBlack);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline TBuffer& buffer() { return buf_; }
|
inline TBuffer& buffer() { return m_buf; }
|
||||||
|
|
||||||
inline const Raster::Resolution resolution() { return resolution_; }
|
inline const Raster::Resolution resolution() { return m_resolution; }
|
||||||
|
|
||||||
inline Origin origin() const /*noexcept*/ { return o_; }
|
inline Origin origin() const /*noexcept*/ { return m_o; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
double getPx(const Point& p) {
|
double getPx(const Point& p) {
|
||||||
return p(0) * SCALING_FACTOR/pxdim_.w_mm;
|
return p(0) * SCALING_FACTOR/m_pxdim.w_mm;
|
||||||
}
|
}
|
||||||
|
|
||||||
double getPy(const Point& p) {
|
double getPy(const Point& p) {
|
||||||
return p(1) * SCALING_FACTOR/pxdim_.h_mm;
|
return p(1) * SCALING_FACTOR/m_pxdim.h_mm;
|
||||||
}
|
}
|
||||||
|
|
||||||
agg::path_storage to_path(const Polygon& poly) {
|
agg::path_storage to_path(const Polygon& poly) {
|
||||||
|
@ -124,57 +124,57 @@ const Raster::Impl::TPixel Raster::Impl::ColorWhite = Raster::Impl::TPixel(255);
|
||||||
const Raster::Impl::TPixel Raster::Impl::ColorBlack = Raster::Impl::TPixel(0);
|
const Raster::Impl::TPixel Raster::Impl::ColorBlack = Raster::Impl::TPixel(0);
|
||||||
|
|
||||||
Raster::Raster(const Resolution &r, const PixelDim &pd, Origin o):
|
Raster::Raster(const Resolution &r, const PixelDim &pd, Origin o):
|
||||||
impl_(new Impl(r, pd, o)) {}
|
m_impl(new Impl(r, pd, o)) {}
|
||||||
|
|
||||||
Raster::Raster() {}
|
Raster::Raster() {}
|
||||||
|
|
||||||
Raster::~Raster() {}
|
Raster::~Raster() {}
|
||||||
|
|
||||||
Raster::Raster(Raster &&m):
|
Raster::Raster(Raster &&m):
|
||||||
impl_(std::move(m.impl_)) {}
|
m_impl(std::move(m.m_impl)) {}
|
||||||
|
|
||||||
void Raster::reset(const Raster::Resolution &r, const Raster::PixelDim &pd)
|
void Raster::reset(const Raster::Resolution &r, const Raster::PixelDim &pd)
|
||||||
{
|
{
|
||||||
// Free up the unnecessary memory and make sure it stays clear after
|
// Free up the unnecessary memory and make sure it stays clear after
|
||||||
// an exception
|
// an exception
|
||||||
auto o = impl_? impl_->origin() : Origin::TOP_LEFT;
|
auto o = m_impl? m_impl->origin() : Origin::TOP_LEFT;
|
||||||
reset(r, pd, o);
|
reset(r, pd, o);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Raster::reset(const Raster::Resolution &r, const Raster::PixelDim &pd,
|
void Raster::reset(const Raster::Resolution &r, const Raster::PixelDim &pd,
|
||||||
Raster::Origin o)
|
Raster::Origin o)
|
||||||
{
|
{
|
||||||
impl_.reset();
|
m_impl.reset();
|
||||||
impl_.reset(new Impl(r, pd, o));
|
m_impl.reset(new Impl(r, pd, o));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Raster::reset()
|
void Raster::reset()
|
||||||
{
|
{
|
||||||
impl_.reset();
|
m_impl.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
Raster::Resolution Raster::resolution() const
|
Raster::Resolution Raster::resolution() const
|
||||||
{
|
{
|
||||||
if(impl_) return impl_->resolution();
|
if(m_impl) return m_impl->resolution();
|
||||||
|
|
||||||
return Resolution(0, 0);
|
return Resolution(0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Raster::clear()
|
void Raster::clear()
|
||||||
{
|
{
|
||||||
assert(impl_);
|
assert(m_impl);
|
||||||
impl_->clear();
|
m_impl->clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Raster::draw(const ExPolygon &poly)
|
void Raster::draw(const ExPolygon &poly)
|
||||||
{
|
{
|
||||||
assert(impl_);
|
assert(m_impl);
|
||||||
impl_->draw(poly);
|
m_impl->draw(poly);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Raster::save(std::ostream& stream, Compression comp)
|
void Raster::save(std::ostream& stream, Compression comp)
|
||||||
{
|
{
|
||||||
assert(impl_);
|
assert(m_impl);
|
||||||
switch(comp) {
|
switch(comp) {
|
||||||
case Compression::PNG: {
|
case Compression::PNG: {
|
||||||
|
|
||||||
|
@ -188,7 +188,7 @@ void Raster::save(std::ostream& stream, Compression comp)
|
||||||
|
|
||||||
wr.write_info();
|
wr.write_info();
|
||||||
|
|
||||||
auto& b = impl_->buffer();
|
auto& b = m_impl->buffer();
|
||||||
auto ptr = reinterpret_cast<png::byte*>( b.data() );
|
auto ptr = reinterpret_cast<png::byte*>( b.data() );
|
||||||
unsigned stride =
|
unsigned stride =
|
||||||
sizeof(Impl::TBuffer::value_type) * resolution().width_px;
|
sizeof(Impl::TBuffer::value_type) * resolution().width_px;
|
||||||
|
@ -201,12 +201,12 @@ void Raster::save(std::ostream& stream, Compression comp)
|
||||||
}
|
}
|
||||||
case Compression::RAW: {
|
case Compression::RAW: {
|
||||||
stream << "P5 "
|
stream << "P5 "
|
||||||
<< impl_->resolution().width_px << " "
|
<< m_impl->resolution().width_px << " "
|
||||||
<< impl_->resolution().height_px << " "
|
<< m_impl->resolution().height_px << " "
|
||||||
<< "255 ";
|
<< "255 ";
|
||||||
|
|
||||||
stream.write(reinterpret_cast<const char*>(impl_->buffer().data()),
|
stream.write(reinterpret_cast<const char*>(m_impl->buffer().data()),
|
||||||
impl_->buffer().size()*sizeof(Impl::TBuffer::value_type));
|
m_impl->buffer().size()*sizeof(Impl::TBuffer::value_type));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,7 @@ class ExPolygon;
|
||||||
*/
|
*/
|
||||||
class Raster {
|
class Raster {
|
||||||
class Impl;
|
class Impl;
|
||||||
std::unique_ptr<Impl> impl_;
|
std::unique_ptr<Impl> m_impl;
|
||||||
public:
|
public:
|
||||||
|
|
||||||
/// Supported compression types
|
/// Supported compression types
|
||||||
|
@ -65,7 +65,7 @@ public:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Release the allocated resources. Drawing in this state ends in
|
* Release the allocated resources. Drawing in this state ends in
|
||||||
* unspecified behaviour.
|
* unspecified behavior.
|
||||||
*/
|
*/
|
||||||
void reset();
|
void reset();
|
||||||
|
|
||||||
|
|
|
@ -30,15 +30,15 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
AppControllerBoilerplate::AppControllerBoilerplate()
|
AppControllerBoilerplate::AppControllerBoilerplate()
|
||||||
:pri_data_(new PriData(std::this_thread::get_id())) {}
|
:m_pri_data(new PriData(std::this_thread::get_id())) {}
|
||||||
|
|
||||||
AppControllerBoilerplate::~AppControllerBoilerplate() {
|
AppControllerBoilerplate::~AppControllerBoilerplate() {
|
||||||
pri_data_.reset();
|
m_pri_data.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AppControllerBoilerplate::is_main_thread() const
|
bool AppControllerBoilerplate::is_main_thread() const
|
||||||
{
|
{
|
||||||
return pri_data_->ui_thread == std::this_thread::get_id();
|
return m_pri_data->ui_thread == std::this_thread::get_id();
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace GUI {
|
namespace GUI {
|
||||||
|
@ -58,9 +58,9 @@ AppControllerBoilerplate::ProgresIndicatorPtr
|
||||||
AppControllerBoilerplate::global_progress_indicator() {
|
AppControllerBoilerplate::global_progress_indicator() {
|
||||||
ProgresIndicatorPtr ret;
|
ProgresIndicatorPtr ret;
|
||||||
|
|
||||||
pri_data_->m.lock();
|
m_pri_data->m.lock();
|
||||||
ret = global_progressind_;
|
ret = m_global_progressind;
|
||||||
pri_data_->m.unlock();
|
m_pri_data->m.unlock();
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -68,9 +68,9 @@ AppControllerBoilerplate::global_progress_indicator() {
|
||||||
void AppControllerBoilerplate::global_progress_indicator(
|
void AppControllerBoilerplate::global_progress_indicator(
|
||||||
AppControllerBoilerplate::ProgresIndicatorPtr gpri)
|
AppControllerBoilerplate::ProgresIndicatorPtr gpri)
|
||||||
{
|
{
|
||||||
pri_data_->m.lock();
|
m_pri_data->m.lock();
|
||||||
global_progressind_ = gpri;
|
m_global_progressind = gpri;
|
||||||
pri_data_->m.unlock();
|
m_pri_data->m.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
PrintController::PngExportData
|
PrintController::PngExportData
|
||||||
|
@ -104,11 +104,11 @@ PrintController::query_png_export_data(const DynamicPrintConfig& conf)
|
||||||
|
|
||||||
void PrintController::slice(AppControllerBoilerplate::ProgresIndicatorPtr pri)
|
void PrintController::slice(AppControllerBoilerplate::ProgresIndicatorPtr pri)
|
||||||
{
|
{
|
||||||
print_->set_status_callback([pri](int st, const std::string& msg){
|
m_print->set_status_callback([pri](int st, const std::string& msg){
|
||||||
pri->update(unsigned(st), msg);
|
pri->update(unsigned(st), msg);
|
||||||
});
|
});
|
||||||
|
|
||||||
print_->process();
|
m_print->process();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PrintController::slice()
|
void PrintController::slice()
|
||||||
|
@ -156,7 +156,7 @@ void PrintController::slice_to_png()
|
||||||
auto exd = query_png_export_data(conf);
|
auto exd = query_png_export_data(conf);
|
||||||
if(exd.zippath.empty()) return;
|
if(exd.zippath.empty()) return;
|
||||||
|
|
||||||
Print *print = print_;
|
Print *print = m_print;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
print->apply_config(conf);
|
print->apply_config(conf);
|
||||||
|
@ -252,7 +252,7 @@ void PrintController::slice_to_png()
|
||||||
|
|
||||||
const PrintConfig &PrintController::config() const
|
const PrintConfig &PrintController::config() const
|
||||||
{
|
{
|
||||||
return print_->config();
|
return m_print->config();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProgressIndicator::message_fmt(
|
void ProgressIndicator::message_fmt(
|
||||||
|
@ -286,13 +286,13 @@ void AppController::arrange_model()
|
||||||
{
|
{
|
||||||
using Coord = libnest2d::TCoord<libnest2d::PointImpl>;
|
using Coord = libnest2d::TCoord<libnest2d::PointImpl>;
|
||||||
|
|
||||||
if(arranging_.load()) return;
|
if(m_arranging.load()) return;
|
||||||
|
|
||||||
// to prevent UI reentrancies
|
// to prevent UI reentrancies
|
||||||
arranging_.store(true);
|
m_arranging.store(true);
|
||||||
|
|
||||||
unsigned count = 0;
|
unsigned count = 0;
|
||||||
for(auto obj : model_->objects) count += obj->instances.size();
|
for(auto obj : m_model->objects) count += obj->instances.size();
|
||||||
|
|
||||||
auto pind = global_progress_indicator();
|
auto pind = global_progress_indicator();
|
||||||
|
|
||||||
|
@ -305,7 +305,7 @@ void AppController::arrange_model()
|
||||||
pind->max(count);
|
pind->max(count);
|
||||||
|
|
||||||
pind->on_cancel([this](){
|
pind->on_cancel([this](){
|
||||||
arranging_.store(false);
|
m_arranging.store(false);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -326,7 +326,7 @@ void AppController::arrange_model()
|
||||||
// TODO: from Sasha from GUI
|
// TODO: from Sasha from GUI
|
||||||
hint.type = arr::BedShapeType::WHO_KNOWS;
|
hint.type = arr::BedShapeType::WHO_KNOWS;
|
||||||
|
|
||||||
arr::arrange(*model_,
|
arr::arrange(*m_model,
|
||||||
min_obj_distance,
|
min_obj_distance,
|
||||||
bed,
|
bed,
|
||||||
hint,
|
hint,
|
||||||
|
@ -336,7 +336,7 @@ void AppController::arrange_model()
|
||||||
pind->update(count - rem, L("Arranging objects..."));
|
pind->update(count - rem, L("Arranging objects..."));
|
||||||
|
|
||||||
process_events();
|
process_events();
|
||||||
}, [this] () { return !arranging_.load(); });
|
}, [this] () { return !m_arranging.load(); });
|
||||||
} catch(std::exception& e) {
|
} catch(std::exception& e) {
|
||||||
std::cerr << e.what() << std::endl;
|
std::cerr << e.what() << std::endl;
|
||||||
report_issue(IssueType::ERR,
|
report_issue(IssueType::ERR,
|
||||||
|
@ -348,13 +348,13 @@ void AppController::arrange_model()
|
||||||
// Restore previous max value
|
// Restore previous max value
|
||||||
if(pind) {
|
if(pind) {
|
||||||
pind->max(pmax);
|
pind->max(pmax);
|
||||||
pind->update(0, arranging_.load() ? L("Arranging done.") :
|
pind->update(0, m_arranging.load() ? L("Arranging done.") :
|
||||||
L("Arranging canceled."));
|
L("Arranging canceled."));
|
||||||
|
|
||||||
pind->on_cancel(/*remove cancel function*/);
|
pind->on_cancel(/*remove cancel function*/);
|
||||||
}
|
}
|
||||||
|
|
||||||
arranging_.store(false);
|
m_arranging.store(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,7 +42,7 @@ private:
|
||||||
class PriData; // Some structure to store progress indication data
|
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<PriData> pri_data_;
|
std::unique_ptr<PriData> m_pri_data;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
@ -67,7 +67,7 @@ public:
|
||||||
* It should display a file chooser dialog in case of a UI application.
|
* It should display a file chooser dialog in case of a UI application.
|
||||||
* @param title Title of a possible query dialog.
|
* @param title Title of a possible query dialog.
|
||||||
* @param extensions Recognized file extensions.
|
* @param extensions Recognized file extensions.
|
||||||
* @return Returns a list of paths choosed by the user.
|
* @return Returns a list of paths chosen by the user.
|
||||||
*/
|
*/
|
||||||
PathList query_destination_paths(
|
PathList query_destination_paths(
|
||||||
const std::string& title,
|
const std::string& title,
|
||||||
|
@ -162,7 +162,7 @@ protected:
|
||||||
|
|
||||||
// This is a global progress indicator placeholder. In the Slic3r UI it can
|
// This is a global progress indicator placeholder. In the Slic3r UI it can
|
||||||
// contain the progress indicator on the statusbar.
|
// contain the progress indicator on the statusbar.
|
||||||
ProgresIndicatorPtr global_progressind_;
|
ProgresIndicatorPtr m_global_progressind;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Zipper {
|
class Zipper {
|
||||||
|
@ -186,18 +186,10 @@ public:
|
||||||
* @brief Implementation of the printing logic.
|
* @brief Implementation of the printing logic.
|
||||||
*/
|
*/
|
||||||
class PrintController: public AppControllerBoilerplate {
|
class PrintController: public AppControllerBoilerplate {
|
||||||
Print *print_ = nullptr;
|
Print *m_print = nullptr;
|
||||||
std::function<void()> rempools_;
|
std::function<void()> m_rempools;
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
void make_skirt() {}
|
|
||||||
void make_brim() {}
|
|
||||||
void make_wipe_tower() {}
|
|
||||||
|
|
||||||
void make_perimeters(PrintObject *pobj) {}
|
|
||||||
void infill(PrintObject *pobj) {}
|
|
||||||
void gen_support_material(PrintObject *pobj) {}
|
|
||||||
|
|
||||||
// Data structure with the png export input data
|
// Data structure with the png export input data
|
||||||
struct PngExportData {
|
struct PngExportData {
|
||||||
std::string zippath; // output zip file
|
std::string zippath; // output zip file
|
||||||
|
@ -215,20 +207,14 @@ protected:
|
||||||
PngExportData query_png_export_data(const DynamicPrintConfig&);
|
PngExportData query_png_export_data(const DynamicPrintConfig&);
|
||||||
|
|
||||||
// The previous export data, to pre-populate the dialog
|
// The previous export data, to pre-populate the dialog
|
||||||
PngExportData prev_expdata_;
|
PngExportData m_prev_expdata;
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Slice one pront object.
|
|
||||||
* @param pobj The print object.
|
|
||||||
*/
|
|
||||||
void slice(PrintObject *pobj);
|
|
||||||
|
|
||||||
void slice(ProgresIndicatorPtr pri);
|
void slice(ProgresIndicatorPtr pri);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
// Must be public for perl to use it
|
// Must be public for perl to use it
|
||||||
explicit inline PrintController(Print *print): print_(print) {}
|
explicit inline PrintController(Print *print): m_print(print) {}
|
||||||
|
|
||||||
PrintController(const PrintController&) = delete;
|
PrintController(const PrintController&) = delete;
|
||||||
PrintController(PrintController&&) = delete;
|
PrintController(PrintController&&) = delete;
|
||||||
|
@ -256,9 +242,9 @@ public:
|
||||||
* @brief Top level controller.
|
* @brief Top level controller.
|
||||||
*/
|
*/
|
||||||
class AppController: public AppControllerBoilerplate {
|
class AppController: public AppControllerBoilerplate {
|
||||||
Model *model_ = nullptr;
|
Model *m_model = nullptr;
|
||||||
PrintController::Ptr printctl;
|
PrintController::Ptr printctl;
|
||||||
std::atomic<bool> arranging_;
|
std::atomic<bool> m_arranging;
|
||||||
public:
|
public:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -275,7 +261,7 @@ public:
|
||||||
* @param model A raw pointer to the model object. This can be used from
|
* @param model A raw pointer to the model object. This can be used from
|
||||||
* perl.
|
* perl.
|
||||||
*/
|
*/
|
||||||
void set_model(Model *model) { model_ = model; }
|
void set_model(Model *model) { m_model = model; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Set the print object from perl.
|
* @brief Set the print object from perl.
|
||||||
|
|
|
@ -103,18 +103,18 @@ bool AppControllerBoilerplate::report_issue(
|
||||||
wxDEFINE_EVENT(PROGRESS_STATUS_UPDATE_EVENT, wxCommandEvent);
|
wxDEFINE_EVENT(PROGRESS_STATUS_UPDATE_EVENT, wxCommandEvent);
|
||||||
|
|
||||||
struct Zipper::Impl {
|
struct Zipper::Impl {
|
||||||
wxFileName m_fpath;
|
wxFileName fpath;
|
||||||
wxFFileOutputStream m_zipfile;
|
wxFFileOutputStream zipfile;
|
||||||
wxZipOutputStream m_zipstream;
|
wxZipOutputStream zipstream;
|
||||||
wxStdOutputStream m_pngstream;
|
wxStdOutputStream pngstream;
|
||||||
|
|
||||||
Impl(const std::string& zipfile_path):
|
Impl(const std::string& zipfile_path):
|
||||||
m_fpath(zipfile_path),
|
fpath(zipfile_path),
|
||||||
m_zipfile(zipfile_path),
|
zipfile(zipfile_path),
|
||||||
m_zipstream(m_zipfile),
|
zipstream(zipfile),
|
||||||
m_pngstream(m_zipstream)
|
pngstream(zipstream)
|
||||||
{
|
{
|
||||||
if(!m_zipfile.IsOk())
|
if(!zipfile.IsOk())
|
||||||
throw std::runtime_error(L("Cannot create zip file."));
|
throw std::runtime_error(L("Cannot create zip file."));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -128,23 +128,23 @@ Zipper::~Zipper() {}
|
||||||
|
|
||||||
void Zipper::next_entry(const std::string &fname)
|
void Zipper::next_entry(const std::string &fname)
|
||||||
{
|
{
|
||||||
m_impl->m_zipstream.PutNextEntry(fname);
|
m_impl->zipstream.PutNextEntry(fname);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string Zipper::get_name() const
|
std::string Zipper::get_name() const
|
||||||
{
|
{
|
||||||
return m_impl->m_fpath.GetName().ToStdString();
|
return m_impl->fpath.GetName().ToStdString();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::ostream &Zipper::stream()
|
std::ostream &Zipper::stream()
|
||||||
{
|
{
|
||||||
return m_impl->m_pngstream;
|
return m_impl->pngstream;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Zipper::close()
|
void Zipper::close()
|
||||||
{
|
{
|
||||||
m_impl->m_zipstream.Close();
|
m_impl->zipstream.Close();
|
||||||
m_impl->m_zipfile.Close();
|
m_impl->zipfile.Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
@ -156,26 +156,26 @@ namespace {
|
||||||
class GuiProgressIndicator:
|
class GuiProgressIndicator:
|
||||||
public ProgressIndicator, public wxEvtHandler {
|
public ProgressIndicator, public wxEvtHandler {
|
||||||
|
|
||||||
wxProgressDialog gauge_;
|
wxProgressDialog m_gauge;
|
||||||
using Base = ProgressIndicator;
|
using Base = ProgressIndicator;
|
||||||
wxString message_;
|
wxString m_message;
|
||||||
int range_; wxString title_;
|
int m_range; wxString m_title;
|
||||||
bool is_asynch_ = false;
|
bool m_is_asynch = false;
|
||||||
|
|
||||||
const int id_ = wxWindow::NewControlId();
|
const int m_id = wxWindow::NewControlId();
|
||||||
|
|
||||||
// status update handler
|
// status update handler
|
||||||
void _state( wxCommandEvent& evt) {
|
void _state( wxCommandEvent& evt) {
|
||||||
unsigned st = evt.GetInt();
|
unsigned st = evt.GetInt();
|
||||||
message_ = evt.GetString();
|
m_message = evt.GetString();
|
||||||
_state(st);
|
_state(st);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Status update implementation
|
// Status update implementation
|
||||||
void _state( unsigned st) {
|
void _state( unsigned st) {
|
||||||
if(!gauge_.IsShown()) gauge_.ShowModal();
|
if(!m_gauge.IsShown()) m_gauge.ShowModal();
|
||||||
Base::state(st);
|
Base::state(st);
|
||||||
if(!gauge_.Update(static_cast<int>(st), message_)) {
|
if(!m_gauge.Update(static_cast<int>(st), m_message)) {
|
||||||
cancel();
|
cancel();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -183,25 +183,25 @@ class GuiProgressIndicator:
|
||||||
public:
|
public:
|
||||||
|
|
||||||
/// Setting whether it will be used from the UI thread or some worker thread
|
/// Setting whether it will be used from the UI thread or some worker thread
|
||||||
inline void asynch(bool is) { is_asynch_ = is; }
|
inline void asynch(bool is) { m_is_asynch = is; }
|
||||||
|
|
||||||
/// Get the mode of parallel operation.
|
/// Get the mode of parallel operation.
|
||||||
inline bool asynch() const { return is_asynch_; }
|
inline bool asynch() const { return m_is_asynch; }
|
||||||
|
|
||||||
inline GuiProgressIndicator(int range, const wxString& title,
|
inline GuiProgressIndicator(int range, const wxString& title,
|
||||||
const wxString& firstmsg) :
|
const wxString& firstmsg) :
|
||||||
gauge_(title, firstmsg, range, wxTheApp->GetTopWindow(),
|
m_gauge(title, firstmsg, range, wxTheApp->GetTopWindow(),
|
||||||
wxPD_APP_MODAL | wxPD_AUTO_HIDE | wxPD_CAN_ABORT),
|
wxPD_APP_MODAL | wxPD_AUTO_HIDE | wxPD_CAN_ABORT),
|
||||||
|
|
||||||
message_(firstmsg),
|
m_message(firstmsg),
|
||||||
range_(range), title_(title)
|
m_range(range), m_title(title)
|
||||||
{
|
{
|
||||||
Base::max(static_cast<float>(range));
|
Base::max(static_cast<float>(range));
|
||||||
Base::states(static_cast<unsigned>(range));
|
Base::states(static_cast<unsigned>(range));
|
||||||
|
|
||||||
Bind(PROGRESS_STATUS_UPDATE_EVENT,
|
Bind(PROGRESS_STATUS_UPDATE_EVENT,
|
||||||
&GuiProgressIndicator::_state,
|
&GuiProgressIndicator::_state,
|
||||||
this, id_);
|
this, m_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void state(float val) override {
|
virtual void state(float val) override {
|
||||||
|
@ -210,27 +210,27 @@ public:
|
||||||
|
|
||||||
void state(unsigned st) {
|
void state(unsigned st) {
|
||||||
// send status update event
|
// send status update event
|
||||||
if(is_asynch_) {
|
if(m_is_asynch) {
|
||||||
auto evt = new wxCommandEvent(PROGRESS_STATUS_UPDATE_EVENT, id_);
|
auto evt = new wxCommandEvent(PROGRESS_STATUS_UPDATE_EVENT, m_id);
|
||||||
evt->SetInt(st);
|
evt->SetInt(st);
|
||||||
evt->SetString(message_);
|
evt->SetString(m_message);
|
||||||
wxQueueEvent(this, evt);
|
wxQueueEvent(this, evt);
|
||||||
} else _state(st);
|
} else _state(st);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void message(const std::string & msg) override {
|
virtual void message(const std::string & msg) override {
|
||||||
message_ = _(msg);
|
m_message = _(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void messageFmt(const std::string& fmt, ...) {
|
virtual void messageFmt(const std::string& fmt, ...) {
|
||||||
va_list arglist;
|
va_list arglist;
|
||||||
va_start(arglist, fmt);
|
va_start(arglist, fmt);
|
||||||
message_ = wxString::Format(_(fmt), arglist);
|
m_message = wxString::Format(_(fmt), arglist);
|
||||||
va_end(arglist);
|
va_end(arglist);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void title(const std::string & title) override {
|
virtual void title(const std::string & title) override {
|
||||||
title_ = _(title);
|
m_title = _(title);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -261,20 +261,20 @@ AppControllerBoilerplate::create_progress_indicator(
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
class Wrapper: public ProgressIndicator, public wxEvtHandler {
|
class Wrapper: public ProgressIndicator, public wxEvtHandler {
|
||||||
ProgressStatusBar *sbar_;
|
ProgressStatusBar *m_sbar;
|
||||||
using Base = ProgressIndicator;
|
using Base = ProgressIndicator;
|
||||||
wxString message_;
|
wxString m_message;
|
||||||
AppControllerBoilerplate& ctl_;
|
AppControllerBoilerplate& m_ctl;
|
||||||
|
|
||||||
void showProgress(bool show = true) {
|
void showProgress(bool show = true) {
|
||||||
sbar_->show_progress(show);
|
m_sbar->show_progress(show);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _state(unsigned st) {
|
void _state(unsigned st) {
|
||||||
if( st <= ProgressIndicator::max() ) {
|
if( st <= ProgressIndicator::max() ) {
|
||||||
Base::state(st);
|
Base::state(st);
|
||||||
sbar_->set_status_text(message_);
|
m_sbar->set_status_text(m_message);
|
||||||
sbar_->set_progress(st);
|
m_sbar->set_progress(st);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -289,10 +289,10 @@ public:
|
||||||
|
|
||||||
inline Wrapper(ProgressStatusBar *sbar,
|
inline Wrapper(ProgressStatusBar *sbar,
|
||||||
AppControllerBoilerplate& ctl):
|
AppControllerBoilerplate& ctl):
|
||||||
sbar_(sbar), ctl_(ctl)
|
m_sbar(sbar), m_ctl(ctl)
|
||||||
{
|
{
|
||||||
Base::max(static_cast<float>(sbar_->get_range()));
|
Base::max(static_cast<float>(m_sbar->get_range()));
|
||||||
Base::states(static_cast<unsigned>(sbar_->get_range()));
|
Base::states(static_cast<unsigned>(m_sbar->get_range()));
|
||||||
|
|
||||||
Bind(PROGRESS_STATUS_UPDATE_EVENT,
|
Bind(PROGRESS_STATUS_UPDATE_EVENT,
|
||||||
&Wrapper::_state,
|
&Wrapper::_state,
|
||||||
|
@ -305,13 +305,13 @@ public:
|
||||||
|
|
||||||
virtual void max(float val) override {
|
virtual void max(float val) override {
|
||||||
if(val > 1.0) {
|
if(val > 1.0) {
|
||||||
sbar_->set_range(static_cast<int>(val));
|
m_sbar->set_range(static_cast<int>(val));
|
||||||
ProgressIndicator::max(val);
|
ProgressIndicator::max(val);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void state(unsigned st) {
|
void state(unsigned st) {
|
||||||
if(!ctl_.is_main_thread()) {
|
if(!m_ctl.is_main_thread()) {
|
||||||
auto evt = new wxCommandEvent(PROGRESS_STATUS_UPDATE_EVENT, id_);
|
auto evt = new wxCommandEvent(PROGRESS_STATUS_UPDATE_EVENT, id_);
|
||||||
evt->SetInt(st);
|
evt->SetInt(st);
|
||||||
wxQueueEvent(this, evt);
|
wxQueueEvent(this, evt);
|
||||||
|
@ -321,20 +321,20 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void message(const std::string & msg) override {
|
virtual void message(const std::string & msg) override {
|
||||||
message_ = _(msg);
|
m_message = _(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void message_fmt(const std::string& fmt, ...) override {
|
virtual void message_fmt(const std::string& fmt, ...) override {
|
||||||
va_list arglist;
|
va_list arglist;
|
||||||
va_start(arglist, fmt);
|
va_start(arglist, fmt);
|
||||||
message_ = wxString::Format(_(fmt), arglist);
|
m_message = wxString::Format(_(fmt), arglist);
|
||||||
va_end(arglist);
|
va_end(arglist);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void title(const std::string & /*title*/) override {}
|
virtual void title(const std::string & /*title*/) override {}
|
||||||
|
|
||||||
virtual void on_cancel(CancelFn fn) override {
|
virtual void on_cancel(CancelFn fn) override {
|
||||||
sbar_->set_cancel_callback(fn);
|
m_sbar->set_cancel_callback(fn);
|
||||||
Base::on_cancel(fn);
|
Base::on_cancel(fn);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,31 +14,31 @@ public:
|
||||||
using CancelFn = std::function<void(void)>; // Cancel function signature.
|
using CancelFn = std::function<void(void)>; // Cancel function signature.
|
||||||
|
|
||||||
private:
|
private:
|
||||||
float state_ = .0f, max_ = 1.f, step_;
|
float m_state = .0f, m_max = 1.f, m_step;
|
||||||
CancelFn cancelfunc_ = [](){};
|
CancelFn m_cancelfunc = [](){};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
inline virtual ~ProgressIndicator() {}
|
inline virtual ~ProgressIndicator() {}
|
||||||
|
|
||||||
/// Get the maximum of the progress range.
|
/// Get the maximum of the progress range.
|
||||||
float max() const { return max_; }
|
float max() const { return m_max; }
|
||||||
|
|
||||||
/// Get the current progress state
|
/// Get the current progress state
|
||||||
float state() const { return state_; }
|
float state() const { return m_state; }
|
||||||
|
|
||||||
/// Set the maximum of the progress range
|
/// Set the maximum of the progress range
|
||||||
virtual void max(float maxval) { max_ = maxval; }
|
virtual void max(float maxval) { m_max = maxval; }
|
||||||
|
|
||||||
/// Set the current state of the progress.
|
/// Set the current state of the progress.
|
||||||
virtual void state(float val) { state_ = val; }
|
virtual void state(float val) { m_state = val; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Number of states int the progress. Can be used instead of giving a
|
* @brief Number of states int the progress. Can be used instead of giving a
|
||||||
* maximum value.
|
* maximum value.
|
||||||
*/
|
*/
|
||||||
virtual void states(unsigned statenum) {
|
virtual void states(unsigned statenum) {
|
||||||
step_ = max_ / statenum;
|
m_step = m_max / statenum;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Message shown on the next status update.
|
/// Message shown on the next status update.
|
||||||
|
@ -51,13 +51,13 @@ public:
|
||||||
virtual void message_fmt(const std::string& fmt, ...);
|
virtual void message_fmt(const std::string& fmt, ...);
|
||||||
|
|
||||||
/// Set up a cancel callback for the operation if feasible.
|
/// Set up a cancel callback for the operation if feasible.
|
||||||
virtual void on_cancel(CancelFn func = CancelFn()) { cancelfunc_ = func; }
|
virtual void on_cancel(CancelFn func = CancelFn()) { m_cancelfunc = func; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Explicitly shut down the progress indicator and call the associated
|
* Explicitly shut down the progress indicator and call the associated
|
||||||
* callback.
|
* callback.
|
||||||
*/
|
*/
|
||||||
virtual void cancel() { cancelfunc_(); }
|
virtual void cancel() { m_cancelfunc(); }
|
||||||
|
|
||||||
/// Convenience function to call message and status update in one function.
|
/// Convenience function to call message and status update in one function.
|
||||||
void update(float st, const std::string& msg) {
|
void update(float st, const std::string& msg) {
|
||||||
|
|
|
@ -14,117 +14,117 @@ namespace Slic3r {
|
||||||
ProgressStatusBar::ProgressStatusBar(wxWindow *parent, int id):
|
ProgressStatusBar::ProgressStatusBar(wxWindow *parent, int id):
|
||||||
self(new wxStatusBar(parent ? parent : GUI::get_main_frame(),
|
self(new wxStatusBar(parent ? parent : GUI::get_main_frame(),
|
||||||
id == -1? wxID_ANY : id)),
|
id == -1? wxID_ANY : id)),
|
||||||
timer_(new wxTimer(self)),
|
m_timer(new wxTimer(self)),
|
||||||
prog_ (new wxGauge(self,
|
m_prog (new wxGauge(self,
|
||||||
wxGA_HORIZONTAL,
|
wxGA_HORIZONTAL,
|
||||||
100,
|
100,
|
||||||
wxDefaultPosition,
|
wxDefaultPosition,
|
||||||
wxDefaultSize)),
|
wxDefaultSize)),
|
||||||
cancelbutton_(new wxButton(self,
|
m_cancelbutton(new wxButton(self,
|
||||||
-1,
|
-1,
|
||||||
"Cancel",
|
"Cancel",
|
||||||
wxDefaultPosition,
|
wxDefaultPosition,
|
||||||
wxDefaultSize))
|
wxDefaultSize))
|
||||||
{
|
{
|
||||||
prog_->Hide();
|
m_prog->Hide();
|
||||||
cancelbutton_->Hide();
|
m_cancelbutton->Hide();
|
||||||
|
|
||||||
self->SetFieldsCount(3);
|
self->SetFieldsCount(3);
|
||||||
int w[] = {-1, 150, 155};
|
int w[] = {-1, 150, 155};
|
||||||
self->SetStatusWidths(3, w);
|
self->SetStatusWidths(3, w);
|
||||||
|
|
||||||
self->Bind(wxEVT_TIMER, [this](const wxTimerEvent&) {
|
self->Bind(wxEVT_TIMER, [this](const wxTimerEvent&) {
|
||||||
if (prog_->IsShown()) timer_->Stop();
|
if (m_prog->IsShown()) m_timer->Stop();
|
||||||
if(is_busy()) prog_->Pulse();
|
if(is_busy()) m_prog->Pulse();
|
||||||
});
|
});
|
||||||
|
|
||||||
self->Bind(wxEVT_SIZE, [this](wxSizeEvent& event){
|
self->Bind(wxEVT_SIZE, [this](wxSizeEvent& event){
|
||||||
wxRect rect;
|
wxRect rect;
|
||||||
self->GetFieldRect(1, rect);
|
self->GetFieldRect(1, rect);
|
||||||
auto offset = 0;
|
auto offset = 0;
|
||||||
cancelbutton_->Move(rect.GetX() + offset, rect.GetY() + offset);
|
m_cancelbutton->Move(rect.GetX() + offset, rect.GetY() + offset);
|
||||||
cancelbutton_->SetSize(rect.GetWidth() - offset, rect.GetHeight());
|
m_cancelbutton->SetSize(rect.GetWidth() - offset, rect.GetHeight());
|
||||||
|
|
||||||
self->GetFieldRect(2, rect);
|
self->GetFieldRect(2, rect);
|
||||||
prog_->Move(rect.GetX() + offset, rect.GetY() + offset);
|
m_prog->Move(rect.GetX() + offset, rect.GetY() + offset);
|
||||||
prog_->SetSize(rect.GetWidth() - offset, rect.GetHeight());
|
m_prog->SetSize(rect.GetWidth() - offset, rect.GetHeight());
|
||||||
|
|
||||||
event.Skip();
|
event.Skip();
|
||||||
});
|
});
|
||||||
|
|
||||||
cancelbutton_->Bind(wxEVT_BUTTON, [this](const wxCommandEvent&) {
|
m_cancelbutton->Bind(wxEVT_BUTTON, [this](const wxCommandEvent&) {
|
||||||
if(cancel_cb_) cancel_cb_();
|
if(m_cancel_cb) m_cancel_cb();
|
||||||
m_perl_cancel_callback.call();
|
m_perl_cancel_callback.call();
|
||||||
cancelbutton_->Hide();
|
m_cancelbutton->Hide();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
ProgressStatusBar::~ProgressStatusBar() {
|
ProgressStatusBar::~ProgressStatusBar() {
|
||||||
if(timer_->IsRunning()) timer_->Stop();
|
if(m_timer->IsRunning()) m_timer->Stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
int ProgressStatusBar::get_progress() const
|
int ProgressStatusBar::get_progress() const
|
||||||
{
|
{
|
||||||
return prog_->GetValue();
|
return m_prog->GetValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProgressStatusBar::set_progress(int val)
|
void ProgressStatusBar::set_progress(int val)
|
||||||
{
|
{
|
||||||
if(!prog_->IsShown()) show_progress(true);
|
if(!m_prog->IsShown()) show_progress(true);
|
||||||
|
|
||||||
if(val == prog_->GetRange()) {
|
if(val == m_prog->GetRange()) {
|
||||||
prog_->SetValue(0);
|
m_prog->SetValue(0);
|
||||||
show_progress(false);
|
show_progress(false);
|
||||||
} else {
|
} else {
|
||||||
prog_->SetValue(val);
|
m_prog->SetValue(val);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int ProgressStatusBar::get_range() const
|
int ProgressStatusBar::get_range() const
|
||||||
{
|
{
|
||||||
return prog_->GetRange();
|
return m_prog->GetRange();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProgressStatusBar::set_range(int val)
|
void ProgressStatusBar::set_range(int val)
|
||||||
{
|
{
|
||||||
if(val != prog_->GetRange()) {
|
if(val != m_prog->GetRange()) {
|
||||||
prog_->SetRange(val);
|
m_prog->SetRange(val);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProgressStatusBar::show_progress(bool show)
|
void ProgressStatusBar::show_progress(bool show)
|
||||||
{
|
{
|
||||||
prog_->Show(show);
|
m_prog->Show(show);
|
||||||
prog_->Pulse();
|
m_prog->Pulse();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProgressStatusBar::start_busy(int rate)
|
void ProgressStatusBar::start_busy(int rate)
|
||||||
{
|
{
|
||||||
busy_ = true;
|
m_busy = true;
|
||||||
show_progress(true);
|
show_progress(true);
|
||||||
if (!timer_->IsRunning()) {
|
if (!m_timer->IsRunning()) {
|
||||||
timer_->Start(rate);
|
m_timer->Start(rate);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProgressStatusBar::stop_busy()
|
void ProgressStatusBar::stop_busy()
|
||||||
{
|
{
|
||||||
timer_->Stop();
|
m_timer->Stop();
|
||||||
show_progress(false);
|
show_progress(false);
|
||||||
prog_->SetValue(0);
|
m_prog->SetValue(0);
|
||||||
busy_ = false;
|
m_busy = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProgressStatusBar::set_cancel_callback(ProgressStatusBar::CancelFn ccb) {
|
void ProgressStatusBar::set_cancel_callback(ProgressStatusBar::CancelFn ccb) {
|
||||||
cancel_cb_ = ccb;
|
m_cancel_cb = ccb;
|
||||||
if(ccb) cancelbutton_->Show();
|
if(ccb) m_cancelbutton->Show();
|
||||||
else cancelbutton_->Hide();
|
else m_cancelbutton->Hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProgressStatusBar::run(int rate)
|
void ProgressStatusBar::run(int rate)
|
||||||
{
|
{
|
||||||
if(!timer_->IsRunning()) {
|
if(!m_timer->IsRunning()) {
|
||||||
timer_->Start(rate);
|
m_timer->Start(rate);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -141,12 +141,12 @@ void ProgressStatusBar::set_status_text(const wxString& txt)
|
||||||
|
|
||||||
void ProgressStatusBar::show_cancel_button()
|
void ProgressStatusBar::show_cancel_button()
|
||||||
{
|
{
|
||||||
cancelbutton_->Show();
|
m_cancelbutton->Show();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProgressStatusBar::hide_cancel_button()
|
void ProgressStatusBar::hide_cancel_button()
|
||||||
{
|
{
|
||||||
cancelbutton_->Hide();
|
m_cancelbutton->Hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,9 +24,9 @@ namespace Slic3r {
|
||||||
*/
|
*/
|
||||||
class ProgressStatusBar {
|
class ProgressStatusBar {
|
||||||
wxStatusBar *self; // we cheat! It should be the base class but: perl!
|
wxStatusBar *self; // we cheat! It should be the base class but: perl!
|
||||||
wxTimer *timer_;
|
wxTimer *m_timer;
|
||||||
wxGauge *prog_;
|
wxGauge *m_prog;
|
||||||
wxButton *cancelbutton_;
|
wxButton *m_cancelbutton;
|
||||||
public:
|
public:
|
||||||
|
|
||||||
/// Cancel callback function type
|
/// Cancel callback function type
|
||||||
|
@ -42,7 +42,7 @@ public:
|
||||||
void show_progress(bool);
|
void show_progress(bool);
|
||||||
void start_busy(int = 100);
|
void start_busy(int = 100);
|
||||||
void stop_busy();
|
void stop_busy();
|
||||||
inline bool is_busy() const { return busy_; }
|
inline bool is_busy() const { return m_busy; }
|
||||||
void set_cancel_callback(CancelFn = CancelFn());
|
void set_cancel_callback(CancelFn = CancelFn());
|
||||||
inline void remove_cancel_callback() { set_cancel_callback(); }
|
inline void remove_cancel_callback() { set_cancel_callback(); }
|
||||||
void run(int rate);
|
void run(int rate);
|
||||||
|
@ -55,8 +55,8 @@ public:
|
||||||
|
|
||||||
PerlCallback m_perl_cancel_callback;
|
PerlCallback m_perl_cancel_callback;
|
||||||
private:
|
private:
|
||||||
bool busy_ = false;
|
bool m_busy = false;
|
||||||
CancelFn cancel_cb_;
|
CancelFn m_cancel_cb;
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace GUI {
|
namespace GUI {
|
||||||
|
|
Loading…
Reference in a new issue