Browse Source

Ported a couple more methods to XS

Alessandro Ranellucci 9 years ago
parent
commit
3a9cf91f83

+ 0 - 9
lib/Slic3r/Config.pm

@@ -340,15 +340,6 @@ sub validate {
     return 1;
 }
 
-# min object distance is max(duplicate_distance, clearance_radius)
-sub min_object_distance {
-    my $self = shift;
-    
-    return ($self->complete_objects && $self->extruder_clearance_radius > $self->duplicate_distance)
-        ? $self->extruder_clearance_radius
-        : $self->duplicate_distance;
-}
-
 # CLASS METHODS:
 
 sub write_ini {

+ 0 - 18
lib/Slic3r/Print.pm

@@ -444,22 +444,4 @@ sub expanded_output_filepath {
     return $self->placeholder_parser->process($path);
 }
 
-# This method assigns extruders to the volumes having a material
-# but not having extruders set in the volume config.
-sub auto_assign_extruders {
-    my ($self, $model_object) = @_;
-    
-    # only assign extruders if object has more than one volume
-    return if @{$model_object->volumes} == 1;
-    
-    my $extruders = scalar @{ $self->config->nozzle_diameter };
-    foreach my $i (0..$#{$model_object->volumes}) {
-        my $volume = $model_object->volumes->[$i];
-        if ($volume->material_id ne '') {
-            my $extruder_id = $i + 1;
-            $volume->config->set_ifndef('extruder', $extruder_id);
-        }
-    }
-}
-
 1;

+ 18 - 0
xs/src/libslic3r/Print.cpp

@@ -824,6 +824,24 @@ Print::has_support_material() const
     return false;
 }
 
+/*  This method assigns extruders to the volumes having a material
+    but not having extruders set in the volume config. */
+void
+Print::auto_assign_extruders(ModelObject* model_object) const
+{
+    // only assign extruders if object has more than one volume
+    if (model_object->volumes.size() < 2) return;
+    
+    size_t extruders = this->config.nozzle_diameter.values.size();
+    for (ModelVolumePtrs::const_iterator v = model_object->volumes.begin(); v != model_object->volumes.end(); ++v) {
+        if (!(*v)->material_id().empty()) {
+            size_t extruder_id = (v - model_object->volumes.begin()) + 1;
+            if (!(*v)->config.has("extruder"))
+                (*v)->config.opt<ConfigOptionInt>("extruder", true)->value = extruder_id;
+        }
+    }
+}
+
 
 #ifdef SLIC3RXS
 REGISTER_CLASS(Print, "Print");

+ 1 - 0
xs/src/libslic3r/Print.hpp

@@ -206,6 +206,7 @@ class Print
     void _simplify_slices(double distance);
     double max_allowed_layer_height() const;
     bool has_support_material() const;
+    void auto_assign_extruders(ModelObject* model_object) const;
     
     private:
     void clear_regions();

+ 9 - 0
xs/src/libslic3r/PrintConfig.cpp

@@ -1095,6 +1095,15 @@ DynamicPrintConfig::normalize() {
     }
 }
 
+double
+PrintConfig::min_object_distance() const
+{
+    // min object distance is max(duplicate_distance, clearance_radius)
+    return (this->complete_objects.value && this->extruder_clearance_radius.value > this->duplicate_distance.value)
+        ? this->extruder_clearance_radius.value
+        : this->duplicate_distance.value;
+}
+
 #ifdef SLIC3RXS
 REGISTER_CLASS(DynamicPrintConfig, "Config");
 REGISTER_CLASS(PrintObjectConfig, "Config::PrintObject");

+ 2 - 0
xs/src/libslic3r/PrintConfig.hpp

@@ -576,6 +576,8 @@ class PrintConfig : public GCodeConfig
         
         return NULL;
     };
+    
+    double min_object_distance() const;
 };
 
 class HostConfig : public virtual StaticPrintConfig

+ 2 - 0
xs/xsp/Config.xsp

@@ -75,6 +75,7 @@
     %name{get_keys} std::vector<std::string> keys();
     std::string get_extrusion_axis();
     %name{setenv} void setenv_();
+    double min_object_distance();
 };
 
 %name{Slic3r::Config::PrintRegion} class PrintRegionConfig {
@@ -146,6 +147,7 @@
     %name{get_keys} std::vector<std::string> keys();
     std::string get_extrusion_axis();
     %name{setenv} void setenv_();
+    double min_object_distance();
 };
 
 %package{Slic3r::Config};

+ 1 - 0
xs/xsp/Print.xsp

@@ -211,6 +211,7 @@ _constant()
     void _simplify_slices(double distance);
     double max_allowed_layer_height() const;
     bool has_support_material() const;
+    void auto_assign_extruders(ModelObject* model_object);
     
     void add_model_object(ModelObject* model_object, int idx = -1);
     bool apply_config(DynamicPrintConfig* config)