mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-08-14 10:15:55 +08:00
Information about extruders count is added for each of printer profiles
+ Added JsonUtils to post-process written json.
This commit is contained in:
parent
fbe63ba1ab
commit
f4f1eb5f9b
@ -512,6 +512,8 @@ set(SLIC3R_SOURCES
|
||||
ProfilesSharingUtils.cpp
|
||||
Utils/DirectoriesUtils.hpp
|
||||
Utils/DirectoriesUtils.cpp
|
||||
Utils/JsonUtils.hpp
|
||||
Utils/JsonUtils.cpp
|
||||
)
|
||||
|
||||
if (APPLE)
|
||||
|
@ -8,8 +8,8 @@
|
||||
#include "PrintConfig.hpp"
|
||||
#include "PresetBundle.hpp"
|
||||
#include "Utils/DirectoriesUtils.hpp"
|
||||
#include "Utils/JsonUtils.hpp"
|
||||
|
||||
#include <boost/property_tree/json_parser.hpp>
|
||||
#include <boost/log/trivial.hpp>
|
||||
|
||||
namespace Slic3r {
|
||||
@ -116,9 +116,7 @@ static std::string get_printer_profiles(const VendorProfile* vendor_profile,
|
||||
data_node.add_child("printer_profiles", printer_profiles_node);
|
||||
|
||||
// Serialize the tree into JSON and return it.
|
||||
std::stringstream ss;
|
||||
pt::write_json(ss, data_node);
|
||||
return ss.str();
|
||||
return write_json_with_post_process(data_node);
|
||||
}
|
||||
}
|
||||
|
||||
@ -161,10 +159,14 @@ static bool is_compatible_preset(const Preset& printer_preset, const PrinterAttr
|
||||
printer_preset.config.opt_string("printer_variant") == attr.variant_name;
|
||||
}
|
||||
|
||||
static void add_profile_node(pt::ptree& printer_profiles_node, const std::string& preset_name)
|
||||
static void add_profile_node(pt::ptree& printer_profiles_node, const std::string& preset_name, const int extruders_cnt)
|
||||
{
|
||||
pt::ptree profile_node;
|
||||
profile_node.put("", preset_name);
|
||||
|
||||
profile_node.put("name", preset_name);
|
||||
if (extruders_cnt > 0)
|
||||
profile_node.put("extruders_cnt", extruders_cnt);
|
||||
|
||||
printer_profiles_node.push_back(std::make_pair("", profile_node));
|
||||
}
|
||||
|
||||
@ -178,13 +180,16 @@ static void get_printer_profiles_node(pt::ptree& printer_profiles_node,
|
||||
|
||||
for (const Preset& printer_preset : printer_presets) {
|
||||
|
||||
int extruders_cnt = printer_preset.printer_technology() == ptSLA ? 0 :
|
||||
printer_preset.config.option<ConfigOptionFloats>("nozzle_diameter")->values.size();
|
||||
|
||||
if (printer_preset.is_user()) {
|
||||
const Preset* parent_preset = printer_presets.get_preset_parent(printer_preset);
|
||||
if (parent_preset && printer_preset.is_visible && is_compatible_preset(*parent_preset, attr))
|
||||
add_profile_node(user_printer_profiles_node, printer_preset.name);
|
||||
add_profile_node(user_printer_profiles_node, printer_preset.name, extruders_cnt);
|
||||
}
|
||||
else if (printer_preset.is_visible && is_compatible_preset(printer_preset, attr))
|
||||
add_profile_node(printer_profiles_node, printer_preset.name);
|
||||
add_profile_node(printer_profiles_node, printer_preset.name, extruders_cnt);
|
||||
}
|
||||
}
|
||||
|
||||
@ -266,9 +271,7 @@ std::string get_json_printer_models(PrinterTechnology printer_technology)
|
||||
root.add_child("printer_models", vendor_node);
|
||||
|
||||
// Serialize the tree into JSON and return it.
|
||||
std::stringstream ss;
|
||||
pt::write_json(ss, root);
|
||||
return ss.str();
|
||||
return write_json_with_post_process(root);
|
||||
}
|
||||
|
||||
static std::string get_installed_print_and_filament_profiles(const PresetBundle* preset_bundle, const Preset* printer_preset)
|
||||
@ -335,9 +338,7 @@ static std::string get_installed_print_and_filament_profiles(const PresetBundle*
|
||||
tree.add_child("user_print_profiles", user_print_profiles);
|
||||
|
||||
// Serialize the tree into JSON and return it.
|
||||
std::stringstream ss;
|
||||
pt::write_json(ss, tree);
|
||||
return ss.str();
|
||||
return write_json_with_post_process(tree);
|
||||
}
|
||||
|
||||
std::string get_json_print_filament_profiles(const std::string& printer_profile)
|
||||
|
22
src/libslic3r/Utils/JsonUtils.cpp
Normal file
22
src/libslic3r/Utils/JsonUtils.cpp
Normal file
@ -0,0 +1,22 @@
|
||||
#include "JsonUtils.hpp"
|
||||
|
||||
namespace Slic3r {
|
||||
|
||||
namespace pt = boost::property_tree;
|
||||
|
||||
std::string write_json_with_post_process(const pt::ptree& ptree)
|
||||
{
|
||||
std::stringstream oss;
|
||||
pt::write_json(oss, ptree);
|
||||
|
||||
// fix json-out to show node values as a string just for string nodes
|
||||
std::regex reg("\\\"([0-9]+\\.{0,1}[0-9]*)\\\""); // code is borrowed from https://stackoverflow.com/questions/2855741/why-does-boost-property-tree-write-json-save-everything-as-string-is-it-possibl
|
||||
std::string result = std::regex_replace(oss.str(), reg, "$1");
|
||||
|
||||
boost::replace_all(result, "\"true\"", "true");
|
||||
boost::replace_all(result, "\"false\"", "false");
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
} // namespace Slic3r
|
12
src/libslic3r/Utils/JsonUtils.hpp
Normal file
12
src/libslic3r/Utils/JsonUtils.hpp
Normal file
@ -0,0 +1,12 @@
|
||||
#ifndef slic3r_JsonUtils_hpp_
|
||||
#define slic3r_JsonUtils_hpp_
|
||||
|
||||
#include <boost/property_tree/json_parser.hpp>
|
||||
|
||||
namespace Slic3r {
|
||||
|
||||
std::string write_json_with_post_process(const boost::property_tree::ptree& ptree);
|
||||
|
||||
} // namespace Slic3r
|
||||
|
||||
#endif // slic3r_jsonUtils_hpp_
|
Loading…
x
Reference in New Issue
Block a user