diff --git a/lib/Slic3r.pm b/lib/Slic3r.pm index a4e1d07d8..0d7d350d6 100644 --- a/lib/Slic3r.pm +++ b/lib/Slic3r.pm @@ -18,6 +18,8 @@ sub debugf { printf @_ if $debug; } +our $loglevel = 0; + # load threads before Moo as required by it our $have_threads; BEGIN { @@ -104,6 +106,10 @@ my $pause_sema = Thread::Semaphore->new; my $parallel_sema; my $paused = 0; +# Set the logging level at the Slic3r XS module. +$Slic3r::loglevel = (defined($ENV{'SLIC3R_LOGLEVEL'}) && $ENV{'SLIC3R_LOGLEVEL'} =~ /^[1-9]/) ? $ENV{'SLIC3R_LOGLEVEL'} : 0; +set_logging_level($Slic3r::loglevel); + sub spawn_thread { my ($cb) = @_; diff --git a/xs/Build.PL b/xs/Build.PL index 98af40ead..e014ddbcf 100644 --- a/xs/Build.PL +++ b/xs/Build.PL @@ -117,7 +117,7 @@ if (defined $ENV{BOOST_LIBRARYDIR}) { # In order to generate the -l switches we need to know how Boost libraries are named my $have_boost = 0; -my @boost_libraries = qw(system thread); # we need these +my @boost_libraries = qw(system thread log); # we need these # check without explicit lib path (works on Linux) if (! $mswin) { diff --git a/xs/src/libslic3r/SupportMaterial.cpp b/xs/src/libslic3r/SupportMaterial.cpp index 02b2610e0..d9fe8084c 100644 --- a/xs/src/libslic3r/SupportMaterial.cpp +++ b/xs/src/libslic3r/SupportMaterial.cpp @@ -9,6 +9,7 @@ #include #include #include +#include // #define SLIC3R_DEBUG @@ -197,6 +198,8 @@ struct MyLayersPtrCompare void PrintObjectSupportMaterial::generate(PrintObject &object) { + BOOST_LOG_TRIVIAL(info) << "Support generator - Start"; + coordf_t max_object_layer_height = 0.; for (size_t i = 0; i < object.layer_count(); ++ i) max_object_layer_height = std::max(max_object_layer_height, object.get_layer(i)->height); @@ -210,6 +213,8 @@ void PrintObjectSupportMaterial::generate(PrintObject &object) // The layers will be referenced by various LayersPtr (of type std::vector) MyLayerStorage layer_storage; + BOOST_LOG_TRIVIAL(info) << "Support generator - Creating top contacts"; + // Determine the top contact surfaces of the support, defined as: // contact = overhangs - clearance + margin // This method is responsible for identifying what contact surfaces @@ -232,6 +237,8 @@ void PrintObjectSupportMaterial::generate(PrintObject &object) } #endif /* SLIC3R_DEBUG */ + BOOST_LOG_TRIVIAL(info) << "Support generator - Creating bottom contacts"; + // Determine the bottom contact surfaces of the supports over the top surfaces of the object. // Depending on whether the support is soluble or not, the contact layer thickness is decided. MyLayersPtr bottom_contacts = this->bottom_contact_layers(object, top_contacts, layer_storage); @@ -245,11 +252,15 @@ void PrintObjectSupportMaterial::generate(PrintObject &object) } #endif /* SLIC3R_DEBUG */ + BOOST_LOG_TRIVIAL(info) << "Support generator - Trimming top contacts by bottom contacts"; + // Because the top and bottom contacts are thick slabs, they may overlap causing over extrusion // and unwanted strong bonds to the object. // Rather trim the top contacts by their overlapping bottom contacts to leave a gap instead of over extruding. this->trim_top_contacts_by_bottom_contacts(object, bottom_contacts, top_contacts); + BOOST_LOG_TRIVIAL(info) << "Support generator - Creating intermediate layers - indices"; + // Generate empty intermediate layers between the top / bottom support contact layers, // The layers may or may not be synchronized with the object layers, depending on the configuration. // For example, a single nozzle multi material printing will need to generate a waste tower, which in turn @@ -257,6 +268,8 @@ void PrintObjectSupportMaterial::generate(PrintObject &object) MyLayersPtr intermediate_layers = this->raft_and_intermediate_support_layers( object, bottom_contacts, top_contacts, layer_storage, max_object_layer_height); + BOOST_LOG_TRIVIAL(info) << "Support generator - Creating base layers"; + // Fill in intermediate layers between the top / bottom support contact layers, trimmed by the object. this->generate_base_layers(object, bottom_contacts, top_contacts, intermediate_layers); @@ -269,6 +282,8 @@ void PrintObjectSupportMaterial::generate(PrintObject &object) } #endif /* SLIC3R_DEBUG */ + BOOST_LOG_TRIVIAL(info) << "Support generator - Creating raft"; + // If raft is to be generated, the 1st top_contact layer will contain the 1st object layer silhouette without holes. // Add the bottom contacts to the raft, inflate the support bases. // There is a contact layer below the 1st object layer in the bottom contacts. @@ -284,6 +299,8 @@ void PrintObjectSupportMaterial::generate(PrintObject &object) shape = this->generate_pillars_shape(contact, support_z); */ + BOOST_LOG_TRIVIAL(info) << "Support generator - Creating interfaces"; + // Propagate top / bottom contact layers to generate interface layers. MyLayersPtr interface_layers = this->generate_interface_layers( object, bottom_contacts, top_contacts, intermediate_layers, layer_storage); @@ -305,6 +322,8 @@ void PrintObjectSupportMaterial::generate(PrintObject &object) } */ + BOOST_LOG_TRIVIAL(info) << "Support generator - Creating layers"; + // Install support layers into the object. MyLayersPtr layers_sorted; layers_sorted.reserve(bottom_contacts.size() + top_contacts.size() + intermediate_layers.size() + interface_layers.size()); @@ -332,8 +351,12 @@ void PrintObjectSupportMaterial::generate(PrintObject &object) ++ layer_id; } + BOOST_LOG_TRIVIAL(info) << "Support generator - Generating tool paths"; + // Generate the actual toolpaths and save them into each layer. this->generate_toolpaths(object, raft, bottom_contacts, top_contacts, intermediate_layers, interface_layers); + + BOOST_LOG_TRIVIAL(info) << "Support generator - End"; } void collect_region_slices_by_type(const Layer &layer, SurfaceType surface_type, Polygons &out) diff --git a/xs/src/libslic3r/utils.cpp b/xs/src/libslic3r/utils.cpp index 3f340e04a..0f298e954 100644 --- a/xs/src/libslic3r/utils.cpp +++ b/xs/src/libslic3r/utils.cpp @@ -66,3 +66,30 @@ confess_at(const char *file, int line, const char *func, } #endif + +#include +#include +#include + +namespace Slic3r { + +static boost::log::trivial::severity_level logSeverity = boost::log::trivial::fatal; + +void set_logging_level(unsigned int level) +{ + switch (level) { + case 0: logSeverity = boost::log::trivial::fatal; break; + case 1: logSeverity = boost::log::trivial::error; break; + case 2: logSeverity = boost::log::trivial::warning; break; + case 3: logSeverity = boost::log::trivial::info; break; + case 4: logSeverity = boost::log::trivial::debug; break; + default: logSeverity = boost::log::trivial::trace; break; + } + + boost::log::core::get()->set_filter + ( + boost::log::trivial::severity >= logSeverity + ); +} + +} // namespace Slic3r diff --git a/xs/xsp/XS.xsp b/xs/xsp/XS.xsp index c324396b2..20c9d4154 100644 --- a/xs/xsp/XS.xsp +++ b/xs/xsp/XS.xsp @@ -2,6 +2,7 @@ %package{Slic3r::XS}; #include +#include "Utils.hpp" %{ @@ -28,6 +29,12 @@ FORK_NAME() RETVAL = newSVpv(SLIC3R_FORK_NAME, 0); OUTPUT: RETVAL +void +set_logging_level(level) + unsigned int level; + CODE: + Slic3r::set_logging_level(level); + void xspp_test_croak_hangs_on_strawberry() CODE: