diff options
Diffstat (limited to 'src/libslic3r/Utils.hpp')
-rw-r--r-- | src/libslic3r/Utils.hpp | 49 |
1 files changed, 33 insertions, 16 deletions
diff --git a/src/libslic3r/Utils.hpp b/src/libslic3r/Utils.hpp index 5cdf75037..0979d7f76 100644 --- a/src/libslic3r/Utils.hpp +++ b/src/libslic3r/Utils.hpp @@ -7,6 +7,8 @@ #include <type_traits> #include <system_error> +#include <boost/system/error_code.hpp> + #include "libslic3r.h" namespace boost { namespace filesystem { class directory_entry; }} @@ -73,11 +75,12 @@ enum CopyFileResult { FAIL_CHECK_TARGET_NOT_OPENED }; // Copy a file, adjust the access attributes, so that the target is writable. -CopyFileResult copy_file_inner(const std::string &from, const std::string &to); +CopyFileResult copy_file_inner(const std::string &from, const std::string &to, std::string& error_message); // Copy file to a temp file first, then rename it to the final file name. // If with_check is true, then the content of the copied file is compared to the content // of the source file before renaming. -extern CopyFileResult copy_file(const std::string &from, const std::string &to, const bool with_check = false); +// Additional error info is passed in error message. +extern CopyFileResult copy_file(const std::string &from, const std::string &to, std::string& error_message, const bool with_check = false); // Compares two files if identical. extern CopyFileResult check_copy(const std::string& origin, const std::string& copy); @@ -87,6 +90,7 @@ extern CopyFileResult check_copy(const std::string& origin, const std::string& c extern bool is_plain_file(const boost::filesystem::directory_entry &path); extern bool is_ini_file(const boost::filesystem::directory_entry &path); extern bool is_idx_file(const boost::filesystem::directory_entry &path); +extern bool is_gcode_file(const std::string &path); // File path / name / extension splitting utilities, working with UTF-8, // to be published to Perl. @@ -107,23 +111,13 @@ std::string string_printf(const char *format, ...); // to be placed at the top of Slic3r generated files. std::string header_slic3r_generated(); +// Standard "generated by PrusaGCodeViewer version xxx timestamp xxx" header string, +// to be placed at the top of Slic3r generated files. +std::string header_gcodeviewer_generated(); + // getpid platform wrapper extern unsigned get_current_pid(); -template <typename Real> -Real round_nearest(Real value, unsigned int decimals) -{ - Real res = (Real)0; - if (decimals == 0) - res = ::round(value); - else - { - Real power = ::pow((Real)10, (int)decimals); - res = ::round(value * power + (Real)0.5) / power; - } - return res; -} - // Compute the next highest power of 2 of 32-bit v // http://graphics.stanford.edu/~seander/bithacks.html inline uint16_t next_highest_power_of_2(uint16_t v) @@ -337,12 +331,35 @@ inline std::string get_time_dhms(float time_in_secs) return buffer; } +inline std::string get_time_dhm(float time_in_secs) +{ + int days = (int)(time_in_secs / 86400.0f); + time_in_secs -= (float)days * 86400.0f; + int hours = (int)(time_in_secs / 3600.0f); + time_in_secs -= (float)hours * 3600.0f; + int minutes = (int)(time_in_secs / 60.0f); + + char buffer[64]; + if (days > 0) + ::sprintf(buffer, "%dd %dh %dm", days, hours, minutes); + else if (hours > 0) + ::sprintf(buffer, "%dh %dm", hours, minutes); + else if (minutes > 0) + ::sprintf(buffer, "%dm", minutes); + + return buffer; +} + } // namespace Slic3r #if WIN32 #define SLIC3R_STDVEC_MEMSIZE(NAME, TYPE) NAME.capacity() * ((sizeof(TYPE) + __alignof(TYPE) - 1) / __alignof(TYPE)) * __alignof(TYPE) + //FIXME this is an inprecise hack. Add the hash table size and possibly some estimate of the linked list at each of the used bin. + #define SLIC3R_STDUNORDEREDSET_MEMSIZE(NAME, TYPE) NAME.size() * ((sizeof(TYPE) + __alignof(TYPE) - 1) / __alignof(TYPE)) * __alignof(TYPE) #else #define SLIC3R_STDVEC_MEMSIZE(NAME, TYPE) NAME.capacity() * ((sizeof(TYPE) + alignof(TYPE) - 1) / alignof(TYPE)) * alignof(TYPE) + //FIXME this is an inprecise hack. Add the hash table size and possibly some estimate of the linked list at each of the used bin. + #define SLIC3R_STDUNORDEREDSET_MEMSIZE(NAME, TYPE) NAME.size() * ((sizeof(TYPE) + alignof(TYPE) - 1) / alignof(TYPE)) * alignof(TYPE) #endif #endif // slic3r_Utils_hpp_ |