mirror of
				https://github.com/SoftFever/OrcaSlicer.git
				synced 2025-11-02 20:51:23 -07:00 
			
		
		
		
	Removed explicit dependency of wxWidgets from PrintExport.hpp
This commit is contained in:
		
							parent
							
								
									5fa99fd903
								
							
						
					
					
						commit
						4d6fb52047
					
				
					 2 changed files with 87 additions and 36 deletions
				
			
		| 
						 | 
				
			
			@ -1341,22 +1341,22 @@ std::string Print::output_filepath(const std::string &path) const
 | 
			
		|||
 | 
			
		||||
void Print::export_png(const std::string &dirpath)
 | 
			
		||||
{
 | 
			
		||||
    size_t idx = 0;
 | 
			
		||||
    for (PrintObject *obj : m_objects) {
 | 
			
		||||
        obj->slice();
 | 
			
		||||
        this->set_status(int(floor(idx * 100. / m_objects.size() + 0.5)), "Slicing...");
 | 
			
		||||
        ++ idx;
 | 
			
		||||
    }
 | 
			
		||||
    this->set_status(90, "Exporting zipped archive...");
 | 
			
		||||
    print_to<FilePrinterFormat::PNG>(*this,
 | 
			
		||||
        dirpath,
 | 
			
		||||
        float(m_config.bed_size_x.value),
 | 
			
		||||
        float(m_config.bed_size_y.value),
 | 
			
		||||
        int(m_config.pixel_width.value),
 | 
			
		||||
        int(m_config.pixel_height.value),
 | 
			
		||||
        float(m_config.exp_time.value),
 | 
			
		||||
        float(m_config.exp_time_first.value));
 | 
			
		||||
    this->set_status(100, "Done.");
 | 
			
		||||
//    size_t idx = 0;
 | 
			
		||||
//    for (PrintObject *obj : m_objects) {
 | 
			
		||||
//        obj->slice();
 | 
			
		||||
//        this->set_status(int(floor(idx * 100. / m_objects.size() + 0.5)), "Slicing...");
 | 
			
		||||
//        ++ idx;
 | 
			
		||||
//    }
 | 
			
		||||
//    this->set_status(90, "Exporting zipped archive...");
 | 
			
		||||
//    print_to<FilePrinterFormat::PNG>(*this,
 | 
			
		||||
//        dirpath,
 | 
			
		||||
//        float(m_config.bed_size_x.value),
 | 
			
		||||
//        float(m_config.bed_size_y.value),
 | 
			
		||||
//        int(m_config.pixel_width.value),
 | 
			
		||||
//        int(m_config.pixel_height.value),
 | 
			
		||||
//        float(m_config.exp_time.value),
 | 
			
		||||
//        float(m_config.exp_time_first.value));
 | 
			
		||||
//    this->set_status(100, "Done.");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Returns extruder this eec should be printed with, according to PrintRegion config
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -7,9 +7,9 @@
 | 
			
		|||
#include <fstream>
 | 
			
		||||
#include <sstream>
 | 
			
		||||
 | 
			
		||||
#include <wx/stdstream.h>
 | 
			
		||||
#include <wx/wfstream.h>
 | 
			
		||||
#include <wx/zipstrm.h>
 | 
			
		||||
//#include <wx/stdstream.h>
 | 
			
		||||
//#include <wx/wfstream.h>
 | 
			
		||||
//#include <wx/zipstrm.h>
 | 
			
		||||
 | 
			
		||||
#include <boost/log/trivial.hpp>
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -32,7 +32,7 @@ enum class FilePrinterFormat {
 | 
			
		|||
 * different implementations of this class template for each supported format.
 | 
			
		||||
 *
 | 
			
		||||
 */
 | 
			
		||||
template<FilePrinterFormat format>
 | 
			
		||||
template<FilePrinterFormat format, class LayerFormat = void>
 | 
			
		||||
class FilePrinter {
 | 
			
		||||
public:
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -73,10 +73,35 @@ public:
 | 
			
		|||
    void saveLayer(unsigned lyr, const std::string& path);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
template<class T = void> struct VeryFalse { static const bool value = false; };
 | 
			
		||||
 | 
			
		||||
// This has to be explicitly implemented in the gui layer or a default zlib
 | 
			
		||||
// based implementation is needed.
 | 
			
		||||
template<class Backend> class Zipper {
 | 
			
		||||
public:
 | 
			
		||||
 | 
			
		||||
    Zipper(const std::string& /*zipfile_path*/) {
 | 
			
		||||
        static_assert(Backend>::value,
 | 
			
		||||
                      "No zipper implementation provided!");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    void next_entry(const std::string& /*fname*/) {}
 | 
			
		||||
 | 
			
		||||
    bool is_ok() { return false; }
 | 
			
		||||
 | 
			
		||||
    std::string get_name() { return ""; }
 | 
			
		||||
 | 
			
		||||
    template<class T> Zipper& operator<<(const T& /*arg*/) {
 | 
			
		||||
        return *this;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    void close() {}
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
// Implementation for PNG raster output
 | 
			
		||||
// Be aware that if a large number of layers are allocated, it can very well
 | 
			
		||||
// exhaust the available memory especially on 32 bit platform.
 | 
			
		||||
template<> class FilePrinter<FilePrinterFormat::PNG> {
 | 
			
		||||
template<class LyrFormat> class FilePrinter<FilePrinterFormat::PNG, LyrFormat> {
 | 
			
		||||
 | 
			
		||||
    struct Layer {
 | 
			
		||||
        Raster first;
 | 
			
		||||
| 
						 | 
				
			
			@ -148,7 +173,7 @@ public:
 | 
			
		|||
        pxdim_(m.pxdim_) {}
 | 
			
		||||
 | 
			
		||||
    inline void layers(unsigned cnt) { if(cnt > 0) layers_rst_.resize(cnt); }
 | 
			
		||||
    inline unsigned layers() const { return layers_rst_.size(); }
 | 
			
		||||
    inline unsigned layers() const { return unsigned(layers_rst_.size()); }
 | 
			
		||||
 | 
			
		||||
    void printConfig(const Print& printconf) { print_ = &printconf; }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -184,37 +209,63 @@ public:
 | 
			
		|||
 | 
			
		||||
    inline void save(const std::string& path) {
 | 
			
		||||
 | 
			
		||||
        wxFileName filepath(path);
 | 
			
		||||
        Zipper<LyrFormat> zipper(path);
 | 
			
		||||
 | 
			
		||||
        wxFFileOutputStream zipfile(path);
 | 
			
		||||
        std::string project = zipper.get_name();
 | 
			
		||||
 | 
			
		||||
        std::string project = filepath.GetName().ToStdString();
 | 
			
		||||
 | 
			
		||||
        if(!zipfile.IsOk()) {
 | 
			
		||||
        if(!zipper.is_ok()) {
 | 
			
		||||
            BOOST_LOG_TRIVIAL(error) << "Can't create zip file for layers! "
 | 
			
		||||
                                     << path;
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        wxZipOutputStream zipstream(zipfile);
 | 
			
		||||
        wxStdOutputStream pngstream(zipstream);
 | 
			
		||||
 | 
			
		||||
        zipstream.PutNextEntry("config.ini");
 | 
			
		||||
        pngstream << createIniContent(project);
 | 
			
		||||
        zipper.next_entry(project);
 | 
			
		||||
        zipper << createIniContent(project);
 | 
			
		||||
 | 
			
		||||
        for(unsigned i = 0; i < layers_rst_.size(); i++) {
 | 
			
		||||
            if(layers_rst_[i].second.rdbuf()->in_avail() > 0) {
 | 
			
		||||
                char lyrnum[6];
 | 
			
		||||
                std::sprintf(lyrnum, "%.5d", i);
 | 
			
		||||
                auto zfilename = project + lyrnum + ".png";
 | 
			
		||||
                zipstream.PutNextEntry(zfilename);
 | 
			
		||||
                pngstream << layers_rst_[i].second.rdbuf();
 | 
			
		||||
                zipper.next_entry(zfilename);
 | 
			
		||||
                zipper << layers_rst_[i].second.rdbuf();
 | 
			
		||||
                layers_rst_[i].second.str("");
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        zipstream.Close();
 | 
			
		||||
        zipfile.Close();
 | 
			
		||||
        zipper.close();
 | 
			
		||||
 | 
			
		||||
//        wxFileName filepath(path);
 | 
			
		||||
 | 
			
		||||
//        wxFFileOutputStream zipfile(path);
 | 
			
		||||
 | 
			
		||||
//        std::string project = filepath.GetName().ToStdString();
 | 
			
		||||
 | 
			
		||||
//        if(!zipfile.IsOk()) {
 | 
			
		||||
//            BOOST_LOG_TRIVIAL(error) << "Can't create zip file for layers! "
 | 
			
		||||
//                                     << path;
 | 
			
		||||
//            return;
 | 
			
		||||
//        }
 | 
			
		||||
 | 
			
		||||
//        wxZipOutputStream zipstream(zipfile);
 | 
			
		||||
//        wxStdOutputStream pngstream(zipstream);
 | 
			
		||||
 | 
			
		||||
//        zipstream.PutNextEntry("config.ini");
 | 
			
		||||
//        pngstream << createIniContent(project);
 | 
			
		||||
 | 
			
		||||
//        for(unsigned i = 0; i < layers_rst_.size(); i++) {
 | 
			
		||||
//            if(layers_rst_[i].second.rdbuf()->in_avail() > 0) {
 | 
			
		||||
//                char lyrnum[6];
 | 
			
		||||
//                std::sprintf(lyrnum, "%.5d", i);
 | 
			
		||||
//                auto zfilename = project + lyrnum + ".png";
 | 
			
		||||
//                zipstream.PutNextEntry(zfilename);
 | 
			
		||||
//                pngstream << layers_rst_[i].second.rdbuf();
 | 
			
		||||
//                layers_rst_[i].second.str("");
 | 
			
		||||
//            }
 | 
			
		||||
//        }
 | 
			
		||||
 | 
			
		||||
//        zipstream.Close();
 | 
			
		||||
//        zipfile.Close();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    void saveLayer(unsigned lyr, const std::string& path) {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue