mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-07-19 22:44:28 +08:00
Add 3mf Config by cereal
This commit is contained in:
parent
b0ed881bd4
commit
b975fe84ed
@ -208,6 +208,8 @@ add_library(libslic3r STATIC
|
|||||||
Tesselate.cpp
|
Tesselate.cpp
|
||||||
Tesselate.hpp
|
Tesselate.hpp
|
||||||
TextConfiguration.hpp
|
TextConfiguration.hpp
|
||||||
|
TextConfigurationSerialization.cpp
|
||||||
|
TextConfigurationSerialization.hpp
|
||||||
TriangleMesh.cpp
|
TriangleMesh.cpp
|
||||||
TriangleMesh.hpp
|
TriangleMesh.hpp
|
||||||
TriangleMeshSlicer.cpp
|
TriangleMeshSlicer.cpp
|
||||||
|
@ -32,6 +32,8 @@ namespace pt = boost::property_tree;
|
|||||||
#include <Eigen/Dense>
|
#include <Eigen/Dense>
|
||||||
#include "miniz_extension.hpp"
|
#include "miniz_extension.hpp"
|
||||||
|
|
||||||
|
#include "TextConfigurationSerialization.hpp"
|
||||||
|
|
||||||
// Slightly faster than sprintf("%.9g"), but there is an issue with the karma floating point formatter,
|
// Slightly faster than sprintf("%.9g"), but there is an issue with the karma floating point formatter,
|
||||||
// https://github.com/boostorg/spirit/pull/586
|
// https://github.com/boostorg/spirit/pull/586
|
||||||
// where the exported string is one digit shorter than it should be to guarantee lossless round trip.
|
// where the exported string is one digit shorter than it should be to guarantee lossless round trip.
|
||||||
@ -2941,6 +2943,10 @@ namespace Slic3r {
|
|||||||
stream << " <" << METADATA_TAG << " " << TYPE_ATTR << "=\"" << VOLUME_TYPE << "\" " << KEY_ATTR << "=\"" << VOLUME_TYPE_KEY << "\" " <<
|
stream << " <" << METADATA_TAG << " " << TYPE_ATTR << "=\"" << VOLUME_TYPE << "\" " << KEY_ATTR << "=\"" << VOLUME_TYPE_KEY << "\" " <<
|
||||||
VALUE_ATTR << "=\"" << ModelVolume::type_to_string(volume->type()) << "\"/>\n";
|
VALUE_ATTR << "=\"" << ModelVolume::type_to_string(volume->type()) << "\"/>\n";
|
||||||
|
|
||||||
|
// stores volume's text data
|
||||||
|
if (volume->text_configuration.has_value())
|
||||||
|
stream << " " << TextConfigurationSerialization::to_string(*volume->text_configuration) << "\n";
|
||||||
|
|
||||||
// stores volume's local matrix
|
// stores volume's local matrix
|
||||||
stream << " <" << METADATA_TAG << " " << TYPE_ATTR << "=\"" << VOLUME_TYPE << "\" " << KEY_ATTR << "=\"" << MATRIX_KEY << "\" " << VALUE_ATTR << "=\"";
|
stream << " <" << METADATA_TAG << " " << TYPE_ATTR << "=\"" << VOLUME_TYPE << "\" " << KEY_ATTR << "=\"" << MATRIX_KEY << "\" " << VALUE_ATTR << "=\"";
|
||||||
Transform3d matrix = volume->get_matrix() * volume->source.transform.get_matrix();
|
Transform3d matrix = volume->get_matrix() * volume->source.transform.get_matrix();
|
||||||
|
68
src/libslic3r/TextConfigurationSerialization.cpp
Normal file
68
src/libslic3r/TextConfigurationSerialization.cpp
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
#include "TextConfigurationSerialization.hpp"
|
||||||
|
|
||||||
|
#include <cereal/archives/xml.hpp>
|
||||||
|
#include <strstream>
|
||||||
|
|
||||||
|
using namespace Slic3r;
|
||||||
|
|
||||||
|
const std::string TextConfigurationSerialization::font_item = "FontItem";
|
||||||
|
const std::string TextConfigurationSerialization::font_prop = "FontProp";
|
||||||
|
const std::string TextConfigurationSerialization::text = "Text";
|
||||||
|
|
||||||
|
namespace cereal {
|
||||||
|
template<class Archive>
|
||||||
|
void serialize(Archive &archive, FontItem &font_item)
|
||||||
|
{
|
||||||
|
archive(
|
||||||
|
CEREAL_NVP(font_item.name),
|
||||||
|
CEREAL_NVP(font_item.path)
|
||||||
|
//,CEREAL_NVP(font_item.type)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class Archive>
|
||||||
|
void serialize(Archive &archive, FontProp &font_prop)
|
||||||
|
{
|
||||||
|
archive(
|
||||||
|
CEREAL_NVP(font_prop.char_gap),
|
||||||
|
CEREAL_NVP(font_prop.line_gap),
|
||||||
|
CEREAL_NVP(font_prop.flatness),
|
||||||
|
CEREAL_NVP(font_prop.size_in_mm),
|
||||||
|
CEREAL_NVP(font_prop.emboss)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class Archive>
|
||||||
|
void serialize(Archive &archive, TextConfiguration &text_configuration)
|
||||||
|
{
|
||||||
|
archive(CEREAL_NVP(text_configuration.font_item),
|
||||||
|
CEREAL_NVP(text_configuration.font_prop),
|
||||||
|
CEREAL_NVP(text_configuration.text));
|
||||||
|
}
|
||||||
|
} // namespace cereal
|
||||||
|
|
||||||
|
std::string TextConfigurationSerialization::to_string(
|
||||||
|
const TextConfiguration &text_configuration)
|
||||||
|
{
|
||||||
|
std::strstream ss;
|
||||||
|
{
|
||||||
|
cereal::XMLOutputArchive archive(ss);
|
||||||
|
// CEREAL_NVP - Names the output the same as the variable name
|
||||||
|
archive(CEREAL_NVP(text_configuration));
|
||||||
|
}
|
||||||
|
std::string result = ss.str();
|
||||||
|
static size_t start = std::string("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<cereal>\n\t").size();
|
||||||
|
size_t end = result.find("\n</cereal>", start);
|
||||||
|
result = result.substr(start, end - start);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::optional<TextConfiguration> TextConfigurationSerialization::from_string(const std::string &data)
|
||||||
|
{
|
||||||
|
std::strstream ss;
|
||||||
|
ss << data;
|
||||||
|
cereal::XMLInputArchive archive(ss);
|
||||||
|
TextConfiguration tc;
|
||||||
|
archive(tc);
|
||||||
|
return tc;
|
||||||
|
}
|
24
src/libslic3r/TextConfigurationSerialization.hpp
Normal file
24
src/libslic3r/TextConfigurationSerialization.hpp
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
#ifndef slic3r_TextConfigurationSerialization_hpp_
|
||||||
|
#define slic3r_TextConfigurationSerialization_hpp_
|
||||||
|
|
||||||
|
#include "TextConfiguration.hpp"
|
||||||
|
#include <optional>
|
||||||
|
|
||||||
|
namespace Slic3r {
|
||||||
|
|
||||||
|
// utility for convert TextConfiguration into string and vice versa
|
||||||
|
class TextConfigurationSerialization
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
TextConfigurationSerialization() = delete; // only static functions
|
||||||
|
static std::string to_string(const TextConfiguration &text_configuration);
|
||||||
|
static std::optional<TextConfiguration> from_string(const std::string &data);
|
||||||
|
|
||||||
|
private:
|
||||||
|
static const std::string font_item;
|
||||||
|
static const std::string font_prop;
|
||||||
|
static const std::string text;
|
||||||
|
};
|
||||||
|
} // namespace Slic3r
|
||||||
|
|
||||||
|
#endif // slic3r_TextConfigurationSerialization_hpp_
|
Loading…
x
Reference in New Issue
Block a user