2016-11-24 14:05:06 +01:00
|
|
|
#ifndef slic3r_Utils_hpp_
|
|
|
|
#define slic3r_Utils_hpp_
|
|
|
|
|
2017-10-26 17:17:39 +02:00
|
|
|
#include <locale>
|
|
|
|
|
2018-03-13 12:39:57 +01:00
|
|
|
#include "libslic3r.h"
|
|
|
|
|
2016-11-24 14:05:06 +01:00
|
|
|
namespace Slic3r {
|
|
|
|
|
|
|
|
extern void set_logging_level(unsigned int level);
|
2017-03-03 12:53:05 +01:00
|
|
|
extern void trace(unsigned int level, const char *message);
|
2016-11-24 14:05:06 +01:00
|
|
|
|
2017-10-17 20:00:15 +02:00
|
|
|
// Set a path with GUI resource files.
|
|
|
|
void set_var_dir(const std::string &path);
|
2017-10-25 12:53:31 +02:00
|
|
|
// Return a full path to the GUI resource files.
|
2017-10-17 20:00:15 +02:00
|
|
|
const std::string& var_dir();
|
2017-10-25 12:53:31 +02:00
|
|
|
// Return a full resource path for a file_name.
|
2017-10-17 20:00:15 +02:00
|
|
|
std::string var(const std::string &file_name);
|
|
|
|
|
2017-12-10 13:19:44 +01:00
|
|
|
// Set a path with various static definition data (for example the initial config bundles).
|
|
|
|
void set_resources_dir(const std::string &path);
|
|
|
|
// Return a full path to the resources directory.
|
|
|
|
const std::string& resources_dir();
|
2018-02-12 08:57:32 +01:00
|
|
|
|
|
|
|
// Set a path with GUI localization files.
|
|
|
|
void set_local_dir(const std::string &path);
|
2018-02-07 17:13:52 +01:00
|
|
|
// Return a full path to the localization directory.
|
2018-02-12 08:57:32 +01:00
|
|
|
const std::string& localization_dir();
|
2017-12-10 13:19:44 +01:00
|
|
|
|
2017-10-25 12:53:31 +02:00
|
|
|
// Set a path with preset files.
|
|
|
|
void set_data_dir(const std::string &path);
|
|
|
|
// Return a full path to the GUI resource files.
|
|
|
|
const std::string& data_dir();
|
|
|
|
|
2017-12-21 16:56:33 +01:00
|
|
|
// A special type for strings encoded in the local Windows 8-bit code page.
|
|
|
|
// This type is only needed for Perl bindings to relay to Perl that the string is raw, not UTF-8 encoded.
|
|
|
|
typedef std::string local_encoded_string;
|
|
|
|
|
|
|
|
// Convert an UTF-8 encoded string into local coding.
|
|
|
|
// On Windows, the UTF-8 string is converted to a local 8-bit code page.
|
|
|
|
// On OSX and Linux, this function does no conversion and returns a copy of the source string.
|
|
|
|
extern local_encoded_string encode_path(const char *src);
|
2017-08-03 17:31:31 +02:00
|
|
|
extern std::string decode_path(const char *src);
|
|
|
|
extern std::string normalize_utf8_nfc(const char *src);
|
|
|
|
|
2017-12-21 16:56:33 +01:00
|
|
|
// File path / name / extension splitting utilities, working with UTF-8,
|
|
|
|
// to be published to Perl.
|
|
|
|
namespace PerlUtils {
|
|
|
|
// Get a file name including the extension.
|
|
|
|
extern std::string path_to_filename(const char *src);
|
|
|
|
// Get a file name without the extension.
|
|
|
|
extern std::string path_to_stem(const char *src);
|
|
|
|
// Get just the extension.
|
|
|
|
extern std::string path_to_extension(const char *src);
|
|
|
|
// Get a directory without the trailing slash.
|
|
|
|
extern std::string path_to_parent_path(const char *src);
|
|
|
|
};
|
|
|
|
|
2017-10-30 18:15:41 +01:00
|
|
|
// Timestamp formatted for header_slic3r_generated().
|
|
|
|
extern std::string timestamp_str();
|
|
|
|
// Standard "generated by Slic3r version xxx timestamp xxx" header string,
|
|
|
|
// to be placed at the top of Slic3r generated files.
|
2017-11-01 19:30:05 +01:00
|
|
|
inline std::string header_slic3r_generated() { return std::string("generated by " SLIC3R_FORK_NAME " " SLIC3R_VERSION " " ) + timestamp_str(); }
|
2017-10-30 18:15:41 +01:00
|
|
|
|
2018-04-20 11:05:00 +02:00
|
|
|
// getpid platform wrapper
|
|
|
|
extern unsigned get_current_pid();
|
|
|
|
|
2017-03-28 17:09:57 +02:00
|
|
|
// Compute the next highest power of 2 of 32-bit v
|
|
|
|
// http://graphics.stanford.edu/~seander/bithacks.html
|
2017-03-28 18:02:26 +02:00
|
|
|
template<typename T>
|
|
|
|
inline T next_highest_power_of_2(T v)
|
2017-03-28 17:09:57 +02:00
|
|
|
{
|
|
|
|
if (v != 0)
|
|
|
|
-- v;
|
|
|
|
v |= v >> 1;
|
|
|
|
v |= v >> 2;
|
|
|
|
v |= v >> 4;
|
2017-03-28 18:02:26 +02:00
|
|
|
if (sizeof(T) >= sizeof(uint16_t))
|
|
|
|
v |= v >> 8;
|
|
|
|
if (sizeof(T) >= sizeof(uint32_t))
|
|
|
|
v |= v >> 16;
|
|
|
|
if (sizeof(T) >= sizeof(uint64_t))
|
|
|
|
v |= v >> 32;
|
2017-03-28 17:09:57 +02:00
|
|
|
return ++ v;
|
|
|
|
}
|
|
|
|
|
2018-07-23 14:39:50 +02:00
|
|
|
extern std::string xml_escape(std::string text);
|
|
|
|
|
2018-05-03 21:45:43 +02:00
|
|
|
class PerlCallback {
|
|
|
|
public:
|
|
|
|
PerlCallback(void *sv) : m_callback(nullptr) { this->register_callback(sv); }
|
|
|
|
PerlCallback() : m_callback(nullptr) {}
|
|
|
|
~PerlCallback() { this->deregister_callback(); }
|
|
|
|
void register_callback(void *sv);
|
|
|
|
void deregister_callback();
|
2018-05-29 13:54:34 +02:00
|
|
|
void call() const;
|
|
|
|
void call(int i) const;
|
|
|
|
void call(int i, int j) const;
|
2018-05-31 16:04:59 +02:00
|
|
|
void call(const std::vector<int>& ints) const;
|
2018-09-07 14:21:04 +02:00
|
|
|
void call(double a) const;
|
2018-06-22 11:19:38 +02:00
|
|
|
void call(double a, double b) const;
|
2018-09-07 14:21:04 +02:00
|
|
|
void call(double a, double b, double c) const;
|
2018-06-22 11:19:38 +02:00
|
|
|
void call(double a, double b, double c, double d) const;
|
2018-06-08 09:40:00 +02:00
|
|
|
void call(bool b) const;
|
2018-05-03 21:45:43 +02:00
|
|
|
private:
|
|
|
|
void *m_callback;
|
|
|
|
};
|
|
|
|
|
2016-11-24 14:05:06 +01:00
|
|
|
} // namespace Slic3r
|
|
|
|
|
|
|
|
#endif // slic3r_Utils_hpp_
|