mirror of
https://git.mirrors.martin98.com/https://github.com/slic3r/Slic3r.git
synced 2025-08-15 10:45:55 +08:00
Refactor some of the SL1 code out into SLAArchive, added "masked CWS" (tuned to Malyan S100 support).
This commit is contained in:
parent
dc4692e098
commit
eb402ea847
@ -447,7 +447,7 @@ int CLI::run(int argc, char **argv)
|
||||
std::string outfile = m_config.opt_string("output");
|
||||
Print fff_print;
|
||||
SLAPrint sla_print;
|
||||
std::shared_ptr<SL1Archive> sla_archive = Slic3r::get_output_format(m_print_config);
|
||||
std::shared_ptr<SLAArchive> sla_archive = Slic3r::get_output_format(m_print_config);
|
||||
|
||||
sla_print.set_printer(sla_archive);
|
||||
sla_print.set_status_callback(
|
||||
|
@ -88,6 +88,8 @@ add_library(libslic3r STATIC
|
||||
Format/STL.hpp
|
||||
Format/SL1.hpp
|
||||
Format/SL1.cpp
|
||||
Format/SLAArchive.hpp
|
||||
Format/SLAArchive.cpp
|
||||
Format/CWS.hpp
|
||||
Format/CWS.cpp
|
||||
GCode/ThumbnailData.cpp
|
||||
|
@ -15,8 +15,9 @@ std::string to_ini(const ConfMap &m)
|
||||
for (auto ¶m : m) ret += param.first + " = " + param.second + "\n";
|
||||
// this format, at least for the Malyan M100, seems to want this in the config.
|
||||
auto _t = m.find("layerHeight"s);
|
||||
if (_t != m.cend())
|
||||
ret += "<SliceHeight>" + _t->second + "< / SliceHeight>";
|
||||
if (_t != m.cend()) {
|
||||
ret += "<SliceHeight>" + _t->second + "</SliceHeight>\n";
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
@ -33,6 +34,7 @@ std::string get_cfg_value(const DynamicPrintConfig &cfg, const std::string &key)
|
||||
return ret;
|
||||
}
|
||||
|
||||
/// Set up list of configuration options in the default slicing.
|
||||
void fill_iniconf(ConfMap &m, const SLAPrint &print)
|
||||
{
|
||||
auto &cfg = print.full_print_config();
|
||||
@ -102,7 +104,6 @@ void MaskedCWSArchive::export_print(Zipper& zipper,
|
||||
prjname.empty() ?
|
||||
boost::filesystem::path(zipper.get_filename()).stem().string() :
|
||||
prjname;
|
||||
std::cerr << "Calling from MaskedCWSArchive\n" ;
|
||||
|
||||
ConfMap iniconf, slicerconf;
|
||||
fill_iniconf(iniconf, print);
|
||||
|
@ -6,9 +6,11 @@
|
||||
|
||||
namespace Slic3r {
|
||||
// "Masked" CWS as used by Malyan S100
|
||||
class MaskedCWSArchive : public SL1Archive {
|
||||
class MaskedCWSArchive : public SLAArchive {
|
||||
SLAPrinterConfig m_cfg;
|
||||
public:
|
||||
SLAPrinterConfig& config() override { return m_cfg; }
|
||||
const SLAPrinterConfig& config() const override { return m_cfg; }
|
||||
MaskedCWSArchive() = default;
|
||||
explicit MaskedCWSArchive(const SLAPrinterConfig &cfg): m_cfg(cfg) {}
|
||||
explicit MaskedCWSArchive(SLAPrinterConfig &&cfg): m_cfg(std::move(cfg)) {}
|
||||
|
20
src/libslic3r/Format/Format.cpp
Normal file
20
src/libslic3r/Format/Format.cpp
Normal file
@ -0,0 +1,20 @@
|
||||
#include "Format.hpp"
|
||||
#include "libslic3r/Exception.hpp"
|
||||
|
||||
namespace Slic3r {
|
||||
std::shared_ptr<SLAArchive> get_output_format(const ConfigBase& config)
|
||||
{
|
||||
OutputFormat output_format = Slic3r::output_format(config);
|
||||
if (output_format & ofSL1)
|
||||
return std::make_shared<SL1Archive>();
|
||||
else if (output_format & ofMaskedCWS) {
|
||||
return std::make_shared<MaskedCWSArchive>();
|
||||
}
|
||||
|
||||
// Default to the base class
|
||||
return std::make_shared<SL1Archive>();
|
||||
}
|
||||
|
||||
} // namespace Slic3r
|
||||
|
||||
|
14
src/libslic3r/Format/Format.hpp
Normal file
14
src/libslic3r/Format/Format.hpp
Normal file
@ -0,0 +1,14 @@
|
||||
#ifndef libslic3r_format_FORMAT_HPP
|
||||
#define libslic3r_format_FORMAT_HPP
|
||||
|
||||
#include "CWS.hpp"
|
||||
#include "SL1.hpp"
|
||||
|
||||
namespace Slic3r {
|
||||
|
||||
/// Select the correct subclass of
|
||||
/// Implementers of new SLA print archive formats should add to this list.
|
||||
std::shared_ptr<SLAArchive> get_output_format(const ConfigBase& config);
|
||||
} // namespace Slic3r
|
||||
|
||||
#endif // libslic3r_format_FORMAT_HPP
|
@ -403,44 +403,6 @@ void fill_slicerconf(ConfMap &m, const SLAPrint &print)
|
||||
|
||||
} // namespace
|
||||
|
||||
uqptr<sla::RasterBase> SL1Archive::create_raster() const
|
||||
{
|
||||
sla::RasterBase::Resolution res;
|
||||
sla::RasterBase::PixelDim pxdim;
|
||||
std::array<bool, 2> mirror;
|
||||
|
||||
double w = m_cfg.display_width.getFloat();
|
||||
double h = m_cfg.display_height.getFloat();
|
||||
auto pw = size_t(m_cfg.display_pixels_x.getInt());
|
||||
auto ph = size_t(m_cfg.display_pixels_y.getInt());
|
||||
|
||||
mirror[X] = m_cfg.display_mirror_x.getBool();
|
||||
mirror[Y] = m_cfg.display_mirror_y.getBool();
|
||||
|
||||
auto ro = m_cfg.display_orientation.getInt();
|
||||
sla::RasterBase::Orientation orientation =
|
||||
ro == sla::RasterBase::roPortrait ? sla::RasterBase::roPortrait :
|
||||
sla::RasterBase::roLandscape;
|
||||
|
||||
if (orientation == sla::RasterBase::roPortrait) {
|
||||
std::swap(w, h);
|
||||
std::swap(pw, ph);
|
||||
}
|
||||
|
||||
res = sla::RasterBase::Resolution{pw, ph};
|
||||
pxdim = sla::RasterBase::PixelDim{w / pw, h / ph};
|
||||
sla::RasterBase::Trafo tr{orientation, mirror};
|
||||
|
||||
double gamma = m_cfg.gamma_correction.getFloat();
|
||||
|
||||
return sla::create_raster_grayscale_aa(res, pxdim, gamma, tr);
|
||||
}
|
||||
|
||||
sla::RasterEncoder SL1Archive::get_encoder() const
|
||||
{
|
||||
return sla::PNGRasterEncoder{};
|
||||
}
|
||||
|
||||
void SL1Archive::export_print(Zipper& zipper,
|
||||
const SLAPrint &print,
|
||||
const std::string &prjname)
|
||||
|
@ -5,15 +5,16 @@
|
||||
|
||||
#include "libslic3r/Zipper.hpp"
|
||||
#include "libslic3r/SLAPrint.hpp"
|
||||
#include "libslic3r/Format/SLAArchive.hpp"
|
||||
|
||||
namespace Slic3r {
|
||||
|
||||
class SL1Archive: public SLAPrinter {
|
||||
class SL1Archive: public SLAArchive {
|
||||
SLAPrinterConfig m_cfg;
|
||||
|
||||
protected:
|
||||
uqptr<sla::RasterBase> create_raster() const override;
|
||||
sla::RasterEncoder get_encoder() const override;
|
||||
SLAPrinterConfig& config() override { return m_cfg; }
|
||||
const SLAPrinterConfig& config() const override { return m_cfg; }
|
||||
|
||||
public:
|
||||
|
||||
@ -21,21 +22,7 @@ public:
|
||||
explicit SL1Archive(const SLAPrinterConfig &cfg): m_cfg(cfg) {}
|
||||
explicit SL1Archive(SLAPrinterConfig &&cfg): m_cfg(std::move(cfg)) {}
|
||||
|
||||
void export_print(Zipper &zipper, const SLAPrint &print, const std::string &projectname = "");
|
||||
void export_print(const std::string &fname, const SLAPrint &print, const std::string &projectname = "")
|
||||
{
|
||||
Zipper zipper(fname);
|
||||
export_print(zipper, print, projectname);
|
||||
}
|
||||
|
||||
void apply(const SLAPrinterConfig &cfg) override
|
||||
{
|
||||
auto diff = m_cfg.diff(cfg);
|
||||
if (!diff.empty()) {
|
||||
m_cfg.apply_only(cfg, diff);
|
||||
m_layers = {};
|
||||
}
|
||||
}
|
||||
void export_print(Zipper &zipper, const SLAPrint &print, const std::string &projectname = "") override;
|
||||
};
|
||||
|
||||
void import_sla_archive(const std::string &zipfname, DynamicPrintConfig &out);
|
||||
|
59
src/libslic3r/Format/SLAArchive.cpp
Normal file
59
src/libslic3r/Format/SLAArchive.cpp
Normal file
@ -0,0 +1,59 @@
|
||||
#include "Format/SLAArchive.hpp"
|
||||
namespace Slic3r {
|
||||
|
||||
using ConfMap = std::map<std::string, std::string>;
|
||||
|
||||
namespace {
|
||||
|
||||
std::string get_cfg_value(const DynamicPrintConfig &cfg, const std::string &key)
|
||||
{
|
||||
std::string ret;
|
||||
|
||||
if (cfg.has(key)) {
|
||||
auto opt = cfg.option(key);
|
||||
if (opt) ret = opt->serialize();
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
uqptr<sla::RasterBase> SLAArchive::create_raster() const
|
||||
{
|
||||
sla::RasterBase::Resolution res;
|
||||
sla::RasterBase::PixelDim pxdim;
|
||||
std::array<bool, 2> mirror;
|
||||
|
||||
double w = this->config().display_width.getFloat();
|
||||
double h = this->config().display_height.getFloat();
|
||||
auto pw = size_t(this->config().display_pixels_x.getInt());
|
||||
auto ph = size_t(this->config().display_pixels_y.getInt());
|
||||
|
||||
mirror[X] = this->config().display_mirror_x.getBool();
|
||||
mirror[Y] = this->config().display_mirror_y.getBool();
|
||||
|
||||
auto ro = this->config().display_orientation.getInt();
|
||||
sla::RasterBase::Orientation orientation =
|
||||
ro == sla::RasterBase::roPortrait ? sla::RasterBase::roPortrait :
|
||||
sla::RasterBase::roLandscape;
|
||||
|
||||
if (orientation == sla::RasterBase::roPortrait) {
|
||||
std::swap(w, h);
|
||||
std::swap(pw, ph);
|
||||
}
|
||||
|
||||
res = sla::RasterBase::Resolution{pw, ph};
|
||||
pxdim = sla::RasterBase::PixelDim{w / pw, h / ph};
|
||||
sla::RasterBase::Trafo tr{orientation, mirror};
|
||||
|
||||
double gamma = this->config().gamma_correction.getFloat();
|
||||
|
||||
return sla::create_raster_grayscale_aa(res, pxdim, gamma, tr);
|
||||
}
|
||||
|
||||
sla::RasterEncoder SLAArchive::get_encoder() const
|
||||
{
|
||||
return sla::PNGRasterEncoder{};
|
||||
}
|
||||
|
||||
} // namespace Slic3r
|
46
src/libslic3r/Format/SLAArchive.hpp
Normal file
46
src/libslic3r/Format/SLAArchive.hpp
Normal file
@ -0,0 +1,46 @@
|
||||
#ifndef slic3r_FORMAT_SLACOMMON_HPP
|
||||
#define slic3r_FORMAT_SLACOMMON_HPP
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "libslic3r/Zipper.hpp"
|
||||
#include "libslic3r/SLAPrint.hpp"
|
||||
|
||||
namespace Slic3r {
|
||||
|
||||
/// Common abstract base class for SLA archive formats.
|
||||
/// Partial refactor from Slic3r::SL1Archive
|
||||
class SLAArchive: public SLAPrinter {
|
||||
protected:
|
||||
virtual SLAPrinterConfig& config() = 0;
|
||||
virtual const SLAPrinterConfig& config() const = 0;
|
||||
|
||||
uqptr<sla::RasterBase> create_raster() const override;
|
||||
sla::RasterEncoder get_encoder() const override;
|
||||
public:
|
||||
SLAArchive() = default;
|
||||
|
||||
/// Actually perform the export.
|
||||
virtual void export_print(Zipper &zipper, const SLAPrint &print, const std::string &projectname = "") = 0;
|
||||
|
||||
/// Export to a file. Virtual for overriding functions to change how the raster is assembled.
|
||||
virtual void export_print(const std::string &fname, const SLAPrint &print, const std::string &projectname = "")
|
||||
{
|
||||
Zipper zipper(fname);
|
||||
export_print(zipper, print, projectname);
|
||||
}
|
||||
|
||||
void apply(const SLAPrinterConfig &cfg) override
|
||||
{
|
||||
auto diff = this->config().diff(cfg);
|
||||
if (!diff.empty()) {
|
||||
this->config().apply_only(cfg, diff);
|
||||
m_layers = {};
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
} // namespace Slic3r
|
||||
|
||||
#endif // slic3r_FORMAT_SLACOMMON_HPP
|
Loading…
x
Reference in New Issue
Block a user