This commit is contained in:
bubnikv 2019-04-04 16:24:44 +02:00
commit a71f05cdc0
12 changed files with 221 additions and 100 deletions

View file

@ -556,19 +556,9 @@ std::string Model::propose_export_file_name_and_path() const
for (const ModelObject *model_object : this->objects)
for (ModelInstance *model_instance : model_object->instances)
if (model_instance->is_printable()) {
input_file = model_object->input_file;
if (! model_object->name.empty()) {
if (input_file.empty())
// model_object->input_file was empty, just use model_object->name
input_file = model_object->name;
else {
// Replace file name in input_file with model_object->name, but keep the path and file extension.
input_file = (boost::filesystem::path(model_object->name).parent_path().empty()) ?
(boost::filesystem::path(input_file).parent_path() / model_object->name).make_preferred().string() :
model_object->name;
}
}
if (! input_file.empty())
input_file = model_object->get_export_filename();
if (!input_file.empty())
goto end;
// Other instances will produce the same name, skip them.
break;
@ -1433,6 +1423,26 @@ void ModelObject::print_info() const
cout << "volume = " << mesh.volume() << endl;
}
std::string ModelObject::get_export_filename() const
{
std::string ret = input_file;
if (!name.empty())
{
if (ret.empty())
// input_file was empty, just use name
ret = name;
else
{
// Replace file name in input_file with name, but keep the path and file extension.
ret = (boost::filesystem::path(name).parent_path().empty()) ?
(boost::filesystem::path(ret).parent_path() / name).make_preferred().string() : name;
}
}
return ret;
}
void ModelVolume::set_material_id(t_model_material_id material_id)
{
m_material_id = material_id;

View file

@ -275,6 +275,8 @@ public:
// Print object statistics to console.
void print_info() const;
std::string get_export_filename() const;
protected:
friend class Print;
friend class SLAPrint;

View file

@ -10,7 +10,7 @@
#include "GCode/WipeTowerPrusaMM.hpp"
#include "Utils.hpp"
#include "PrintExport.hpp"
//#include "PrintExport.hpp"
#include <algorithm>
#include <limits>

View file

@ -7,6 +7,7 @@
#include <vector>
#include <boost/log/trivial.hpp>
#include <boost/filesystem/path.hpp>
#include "Rasterizer/Rasterizer.hpp"
//#include <tbb/parallel_for.h>
@ -72,7 +73,8 @@ public:
void finish_layer();
// Save all the layers into the file (or dir) specified in the path argument
void save(const std::string& path);
// An optional project name can be added to be used for the layer file names
void save(const std::string& path, const std::string& projectname = "");
// Save only the selected layer to the file specified in path argument.
void save_layer(unsigned lyr, const std::string& path);
@ -86,7 +88,8 @@ template<class T = void> struct VeryFalse { static const bool value = false; };
template<class Fmt> class LayerWriter {
public:
LayerWriter(const std::string& /*zipfile_path*/) {
LayerWriter(const std::string& /*zipfile_path*/)
{
static_assert(VeryFalse<Fmt>::value,
"No layer writer implementation provided!");
}
@ -99,10 +102,6 @@ public:
void binary_entry(const std::string& /*fname*/,
const std::uint8_t* buf, size_t len);
// Get the name of the archive but only the name part without the path or
// the extension.
std::string get_name() { return ""; }
// Test whether the object can still be used for writing.
bool is_ok() { return false; }
@ -253,12 +252,14 @@ public:
}
template<class LyrFmt>
inline void save(const std::string& path) {
inline void save(const std::string& fpath, const std::string& prjname = "")
{
try {
LayerWriter<LyrFmt> writer(path);
LayerWriter<LyrFmt> writer(fpath);
if(!writer.is_ok()) return;
std::string project = writer.get_name();
std::string project = prjname.empty()?
boost::filesystem::path(fpath).stem().string() : prjname;
writer.next_entry("config.ini");
if(!writer.is_ok()) return;

View file

@ -320,10 +320,8 @@ struct SLAPrintStatistics
}
};
struct SLAminzZipper {};
// The implementation of creating zipped archives with wxWidgets
template<> class LayerWriter<SLAminzZipper> {
template<> class LayerWriter<Zipper> {
Zipper m_zip;
public:
@ -332,16 +330,12 @@ public:
void next_entry(const std::string& fname) { m_zip.add_entry(fname); }
void binary_entry(const std::string& fname,
const std::uint8_t* buf,
size_t l)
const std::uint8_t* buf,
size_t l)
{
m_zip.add_entry(fname, buf, l);
}
std::string get_name() const {
return m_zip.get_name();
}
template<class T> inline LayerWriter& operator<<(T&& arg) {
m_zip << std::forward<T>(arg); return *this;
}
@ -389,9 +383,11 @@ public:
// Returns true if the last step was finished with success.
bool finished() const override { return this->is_step_done(slaposSliceSupports) && this->Inherited::is_step_done(slapsRasterize); }
template<class Fmt = SLAminzZipper>
void export_raster(const std::string& fname) {
if(m_printer) m_printer->save<Fmt>(fname);
template<class Fmt = Zipper>
inline void export_raster(const std::string& fpath,
const std::string& projectname = "")
{
if(m_printer) m_printer->save<Fmt>(fpath, projectname);
}
const PrintObjects& objects() const { return m_objects; }

View file

@ -4,7 +4,6 @@
#include "Zipper.hpp"
#include "miniz/miniz_zip.h"
#include <boost/filesystem/path.hpp>
#include <boost/log/trivial.hpp>
#include "I18N.hpp"
@ -213,10 +212,6 @@ void Zipper::finish_entry()
m_entry.clear();
}
std::string Zipper::get_name() const {
return boost::filesystem::path(m_impl->m_zipname).stem().string();
}
void Zipper::finalize()
{
finish_entry();

View file

@ -81,9 +81,6 @@ public:
/// file is up to minz after the erroneous write.
void finish_entry();
/// Gets the name of the archive without the path or extension.
std::string get_name() const;
void finalize();
};