Skip to content

Commit

Permalink
wip orca_reader: currently only for reading global config of generic 3mf
Browse files Browse the repository at this point in the history
  • Loading branch information
supermerill committed Jan 26, 2024
1 parent 9930173 commit 35ab0ce
Show file tree
Hide file tree
Showing 51 changed files with 27,592 additions and 67 deletions.
2 changes: 2 additions & 0 deletions src/libslic3r/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ add_library(libslic3r STATIC
Format/3mf.hpp
Format/AMF.cpp
Format/AMF.hpp
Format/BBConfig.cpp
Format/BBConfig.hpp
Format/OBJ.cpp
Format/OBJ.hpp
Format/objparser.cpp
Expand Down
6 changes: 3 additions & 3 deletions src/libslic3r/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ std::string escape_strings_cstyle(const std::vector<std::string> &strs)
bool should_quote = strs.size() == 1 && str.empty();
for (size_t i = 0; i < str.size(); ++ i) {
char c = str[i];
if (c == ' ' || c == ';' || c == '\t' || c == '\\' || c == '"' || c == '\r' || c == '\n') {
if (c == ' ' || c == ';' || c == ',' || c == '\t' || c == '\\' || c == '"' || c == '\r' || c == '\n') {
should_quote = true;
break;
}
Expand Down Expand Up @@ -212,7 +212,7 @@ bool unescape_strings_cstyle(const std::string &str, std::vector<std::string> &o
} else {
for (; i < str.size(); ++ i) {
c = str[i];
if (c == ';')
if (c == ';' || c == ',')
break;
buf.push_back(c);
}
Expand All @@ -229,7 +229,7 @@ bool unescape_strings_cstyle(const std::string &str, std::vector<std::string> &o
return true;
c = str[i];
}
if (c != ';')
if (c != ';' && c != ',')
return false;
if (++ i == str.size()) {
// Emit one additional empty string.
Expand Down
270 changes: 233 additions & 37 deletions src/libslic3r/Format/3mf.cpp

Large diffs are not rendered by default.

661 changes: 661 additions & 0 deletions src/libslic3r/Format/BBConfig.cpp

Large diffs are not rendered by default.

23 changes: 23 additions & 0 deletions src/libslic3r/Format/BBConfig.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#ifndef slic3r_Format_BBconfig_hpp_
#define slic3r_Format_BBconfig_hpp_


#include <filesystem>

namespace Slic3r {
class ModelConfigObject;
class DynamicPrintConfig;

bool read_project_file_bambu(const std::filesystem::path &temp_file,
DynamicPrintConfig & config,
ConfigSubstitutionContext & config_substitutions,
bool with_phony);

bool convert_settings_from_bambu(std::map<std::string, std::string> bambu_settings_serialized,
const DynamicPrintConfig & print_config,
ModelConfigObject & object_config,
ConfigSubstitutionContext & config_substitutions,
bool with_phony);
} // namespace Slic3r

#endif /* slic3r_Format_BBconfig_hpp_ */
2 changes: 1 addition & 1 deletion src/libslic3r/GCode/GCodeProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1414,7 +1414,7 @@ void GCodeProcessor::process_file(const std::string& filename, std::function<voi
// thus a probability of incorrect substitution is low and the G-code viewer is a consumer-only anyways.
config.load_from_gcode_file(filename, ForwardCompatibilitySubstitutionRule::EnableSilent);
if (m_producer == EProducer::PrusaSlicer || m_producer == EProducer::Slic3rPE)
config.convert_from_prusa();
config.convert_from_prusa(true);
apply_config(config);
} else if (m_producer == EProducer::Simplify3D)
apply_config_simplify3d(filename);
Expand Down
6 changes: 3 additions & 3 deletions src/libslic3r/PresetBundle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -802,7 +802,7 @@ ConfigSubstitutions PresetBundle::load_config_file(const std::string &path, Forw
ConfigSubstitutions config_substitutions = config.load_from_gcode_file(path, compatibility_rule);
Preset::normalize(config);
if(from_prusa)
config.convert_from_prusa();
config.convert_from_prusa(true);
load_config_file_config(path, true, std::move(config));
return config_substitutions;
}
Expand Down Expand Up @@ -838,7 +838,7 @@ ConfigSubstitutions PresetBundle::load_config_file(const std::string &path, Forw
config_substitutions = config.load(tree, compatibility_rule);
Preset::normalize(config);
if (from_prusa) {
config.convert_from_prusa();
config.convert_from_prusa(true);
}
load_config_file_config(path, true, std::move(config));
return config_substitutions;
Expand Down Expand Up @@ -1335,7 +1335,7 @@ std::pair<PresetsConfigSubstitutions, size_t> PresetBundle::load_configbundle(
config.set_deserialize(kvp.first, kvp.second.data(), substitution_context);
}
if (flags.has(LoadConfigBundleAttribute::ConvertFromPrusa))
config.convert_from_prusa();
config.convert_from_prusa(true);
};
if (presets == &this->printers) {
// Select the default config based on the printer_technology field extracted from kvp.
Expand Down
36 changes: 23 additions & 13 deletions src/libslic3r/PrintConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7793,7 +7793,7 @@ std::map<std::string,std::string> PrintConfigDef::from_prusa(t_config_option_key


template<typename CONFIG_CLASS>
void _convert_from_prusa(CONFIG_CLASS& conf, const DynamicPrintConfig& global_config) {
void _convert_from_prusa(CONFIG_CLASS& conf, const DynamicPrintConfig& global_config, bool with_phony) {
//void convert_from_prusa(DynamicPrintConfig& conf, const DynamicPrintConfig & global_config) {
//void convert_from_prusa(ModelConfigObject& conf, const DynamicPrintConfig& global_config) {
std::map<std::string, std::string> results;
Expand All @@ -7820,23 +7820,33 @@ void _convert_from_prusa(CONFIG_CLASS& conf, const DynamicPrintConfig& global_co
conf.set_key_value(entry.first, opt_new);
}
}

// set phony entries
for (const t_config_option_key &opt_key :
{"extrusion_spacing", "perimeter_extrusion_spacing", "external_perimeter_extrusion_spacing",
"first_layer_extrusion_spacing", "infill_extrusion_spacing", "solid_infill_extrusion_spacing",
"top_infill_extrusion_spacing"}) {
ConfigOption* opt_new = print_config_def.get(opt_key)->default_value.get()->clone();
opt_new->deserialize(""); // note: deserialize don't set phony, only the ConfigBase::set_deserialize*
opt_new->set_phony(true);
conf.set_key_value(opt_key, opt_new);
if (with_phony) {
for (auto &[opt_key_width, opt_key_spacing] :
{std::pair<char *, char *>{"extrusion_width", "extrusion_spacing"},
std::pair<char *, char *>{"perimeter_extrusion_width", "perimeter_extrusion_spacing"},
std::pair<char *, char *>{"external_perimeter_extrusion_width", "external_perimeter_extrusion_spacing"},
std::pair<char *, char *>{"first_layer_extrusion_width", "first_layer_extrusion_spacing"},
std::pair<char *, char *>{"infill_extrusion_width", "infill_extrusion_spacing"},
std::pair<char *, char *>{"solid_infill_extrusion_width", "solid_infill_extrusion_spacing"},
std::pair<char *, char *>{"top_infill_extrusion_width", "top_infill_extrusion_spacing"}}) {
// if prusa has defined a width, or if the conf has a default spacing that need to be overwritten
if (conf.option(opt_key_width) != nullptr || conf.option(opt_key_spacing) != nullptr) {
ConfigOption *opt_new = print_config_def.get(opt_key_spacing)->default_value.get()->clone();
opt_new->deserialize(""); // note: deserialize don't set phony, only the ConfigBase::set_deserialize*
opt_new->set_phony(true);
conf.set_key_value(opt_key_spacing, opt_new);
}
}
}
}

void DynamicPrintConfig::convert_from_prusa() {
_convert_from_prusa(*this, *this);
void DynamicPrintConfig::convert_from_prusa(bool with_phony) {
_convert_from_prusa(*this, *this, with_phony);
}
void ModelConfig::convert_from_prusa(const DynamicPrintConfig& global_config) {
_convert_from_prusa(*this, global_config);
void ModelConfig::convert_from_prusa(const DynamicPrintConfig& global_config, bool with_phony) {
_convert_from_prusa(*this, global_config, with_phony);
}

std::unordered_set<std::string> prusa_export_to_remove_keys = {
Expand Down
6 changes: 4 additions & 2 deletions src/libslic3r/PrintConfig.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,8 @@ class DynamicPrintConfig : public DynamicConfig
void to_prusa(t_config_option_key& opt_key, std::string& value) const override
{ PrintConfigDef::to_prusa(opt_key, value, *this); }
// utilities to help convert from prusa config.
void convert_from_prusa();
// if with_phony, then the phony settigns will be set to phony if needed.
void convert_from_prusa(bool with_phony);

/// <summary>
/// callback to changed other settings that are linked (like width & spacing)
Expand Down Expand Up @@ -1669,7 +1670,8 @@ class ModelConfig


// utilities to help convert from prusa config.
void convert_from_prusa(const DynamicPrintConfig& global_config);
// if with_phony, then the phony settigns will be set to phony if needed.
void convert_from_prusa(const DynamicPrintConfig& global_config, bool with_phony);

private:
friend class cereal::access;
Expand Down
13 changes: 5 additions & 8 deletions src/libslic3r/SupportMaterial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4122,10 +4122,6 @@ void PrintObjectSupportMaterial::generate_toolpaths(
LoopInterfaceProcessor loop_interface_processor(1.5 * m_support_params.support_material_interface_flow.scaled_width());
loop_interface_processor.n_contact_loops = this->has_contact_loops() ? 1 : 0;

//std::vector<float> angles { m_support_params.base_angle };
//if (m_object_config->support_material_pattern.value == smpRectilinearGrid)
// angles.push_back(m_support_params.interface_angle);

BoundingBox bbox_object(Point(-scale_(1.), -scale_(1.0)), Point(scale_(1.), scale_(1.)));

// const coordf_t link_max_length_factor = 3.;
Expand Down Expand Up @@ -4277,7 +4273,7 @@ void PrintObjectSupportMaterial::generate_toolpaths(
filler_first_layer_ptr->ratio_fill_inside = 0.2f;
tbb::parallel_for(tbb::blocked_range<size_t>(n_raft_layers, support_layers.size()),
[this, &support_layers, &bottom_contacts, &top_contacts, &intermediate_layers, &interface_layers, &base_interface_layers, &layer_caches, &loop_interface_processor,
&bbox_object, /*&angles,*/ link_max_length_factor, &filler_first_layer_ptr, &raft_top_interface_idx, &raft_angle_interface]
&bbox_object, link_max_length_factor, &filler_first_layer_ptr, &raft_top_interface_idx, &raft_angle_interface]
(const tbb::blocked_range<size_t>& range) {
// Indices of the 1st layer in their respective container at the support layer height.
size_t idx_layer_bottom_contact = size_t(-1);
Expand Down Expand Up @@ -4318,7 +4314,9 @@ void PrintObjectSupportMaterial::generate_toolpaths(

//compute if the support has to switch its angle
float suppport_angle = m_support_params.base_angle;
if (m_support_params.base_angle_height > 0 && (int(support_layer.print_z / m_support_params.base_angle_height)) % 2 == 1) {
if (m_object_config->support_material_pattern.value == smpRectilinearGrid && support_layer_id % 2 == 1) {
suppport_angle = m_support_params.interface_angle;
} else if (m_support_params.base_angle_height > 0 && (int(support_layer.print_z / m_support_params.base_angle_height)) % 2 == 1) {
suppport_angle += float(M_PI) / 2;
}

Expand Down Expand Up @@ -4419,7 +4417,7 @@ void PrintObjectSupportMaterial::generate_toolpaths(
} else {
filler->angle = interface_as_base ?
// If zero interface layers are configured, use the same angle as for the base layers.
suppport_angle : //angles[support_layer_id % angles.size()] :
suppport_angle :
// Use interface angle for the interface layers.
m_support_params.interface_angle + interface_angle_delta;
supp_density = interface_as_base ? m_support_params.support_density : m_support_params.interface_density;
Expand Down Expand Up @@ -4484,7 +4482,6 @@ void PrintObjectSupportMaterial::generate_toolpaths(
// its pattern to the other layers
filler_spacing = flow.spacing();
} else{
//filler->angle = angles[support_layer_id % angles.size()];
filler->angle = suppport_angle;
filler->link_max_length = coord_t(scale_(filler_spacing * link_max_length_factor / m_support_params.support_density));
}
Expand Down
73 changes: 73 additions & 0 deletions src/nlohmann/adl_serializer.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#pragma once

#include <type_traits>
#include <utility>

#include <nlohmann/detail/conversions/from_json.hpp>
#include <nlohmann/detail/conversions/to_json.hpp>
#include <nlohmann/detail/meta/identity_tag.hpp>
#include <nlohmann/detail/meta/type_traits.hpp>

namespace nlohmann
{

template<typename ValueType, typename>
struct adl_serializer
{
/*!
@brief convert a JSON value to any value type
This function is usually called by the `get()` function of the
@ref basic_json class (either explicit or via conversion operators).
@note This function is chosen for default-constructible value types.
@param[in] j JSON value to read from
@param[in,out] val value to write to
*/
template<typename BasicJsonType, typename TargetType = ValueType>
static auto from_json(BasicJsonType && j, TargetType& val) noexcept(
noexcept(::nlohmann::from_json(std::forward<BasicJsonType>(j), val)))
-> decltype(::nlohmann::from_json(std::forward<BasicJsonType>(j), val), void())
{
::nlohmann::from_json(std::forward<BasicJsonType>(j), val);
}

/*!
@brief convert a JSON value to any value type
This function is usually called by the `get()` function of the
@ref basic_json class (either explicit or via conversion operators).
@note This function is chosen for value types which are not default-constructible.
@param[in] j JSON value to read from
@return copy of the JSON value, converted to @a ValueType
*/
template<typename BasicJsonType, typename TargetType = ValueType>
static auto from_json(BasicJsonType && j) noexcept(
noexcept(::nlohmann::from_json(std::forward<BasicJsonType>(j), detail::identity_tag<TargetType> {})))
-> decltype(::nlohmann::from_json(std::forward<BasicJsonType>(j), detail::identity_tag<TargetType> {}))
{
return ::nlohmann::from_json(std::forward<BasicJsonType>(j), detail::identity_tag<TargetType> {});
}

/*!
@brief convert any value type to a JSON value
This function is usually called by the constructors of the @ref basic_json
class.
@param[in,out] j JSON value to write to
@param[in] val value to read from
*/
template<typename BasicJsonType, typename TargetType = ValueType>
static auto to_json(BasicJsonType& j, TargetType && val) noexcept(
noexcept(::nlohmann::to_json(j, std::forward<TargetType>(val))))
-> decltype(::nlohmann::to_json(j, std::forward<TargetType>(val)), void())
{
::nlohmann::to_json(j, std::forward<TargetType>(val));
}
};
} // namespace nlohmann
Loading

0 comments on commit 35ab0ce

Please sign in to comment.