From 16562a2e77ad74c44e8b143ae3e45deafa0912ee Mon Sep 17 00:00:00 2001
From: Lukas Matena <lukasmatena@seznam.cz>
Date: Mon, 23 Aug 2021 15:51:06 +0200
Subject: [PATCH] Do not print brim when object has raft, it is not supported
 and makes no sense

---
 src/libslic3r/Brim.cpp        | 6 +++++-
 src/libslic3r/Print.hpp       | 8 ++++++--
 src/libslic3r/PrintConfig.cpp | 3 ++-
 3 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/src/libslic3r/Brim.cpp b/src/libslic3r/Brim.cpp
index e73bed2c9..f4455fdd5 100644
--- a/src/libslic3r/Brim.cpp
+++ b/src/libslic3r/Brim.cpp
@@ -71,12 +71,16 @@ static ConstPrintObjectPtrs get_top_level_objects_with_brim(const Print &print,
     Polygons             islands;
     ConstPrintObjectPtrs island_to_object;
     for(size_t print_object_idx = 0; print_object_idx < print.objects().size(); ++print_object_idx) {
+        const PrintObject *object = print.objects()[print_object_idx];
+
+        if (! object->has_brim())
+            continue;
+
         Polygons islands_object;
         islands_object.reserve(bottom_layers_expolygons[print_object_idx].size());
         for (const ExPolygon &ex_poly : bottom_layers_expolygons[print_object_idx])
             islands_object.emplace_back(ex_poly.contour);
 
-        const PrintObject *object = print.objects()[print_object_idx];
         islands.reserve(islands.size() + object->instances().size() * islands_object.size());
         for (const PrintInstance &instance : object->instances())
             for (Polygon &poly : islands_object) {
diff --git a/src/libslic3r/Print.hpp b/src/libslic3r/Print.hpp
index 491960705..0056aee33 100644
--- a/src/libslic3r/Print.hpp
+++ b/src/libslic3r/Print.hpp
@@ -271,7 +271,11 @@ public:
     // Centering offset of the sliced mesh from the scaled and rotated mesh of the model.
     const Point& 			     center_offset() const  { return m_center_offset; }
 
-    bool                         has_brim() const       { return this->config().brim_type != btNoBrim && this->config().brim_width.value > 0.; }
+    bool                         has_brim() const       {
+        return this->config().brim_type != btNoBrim
+            && this->config().brim_width.value > 0.
+            && ! this->has_raft();
+    }
 
     // This is the *total* layer count (including support layers)
     // this value is not supposed to be compared with Layer::id
@@ -321,7 +325,7 @@ public:
     bool                        has_raft()              const { return m_config.raft_layers > 0; }
     bool                        has_support_material()  const { return this->has_support() || this->has_raft(); }
     // Checks if the model object is painted using the multi-material painting gizmo.
-    bool                        is_mm_painted()         const { return this->model_object()->is_mm_painted(); };
+    bool                        is_mm_painted()         const { return this->model_object()->is_mm_painted(); }
 
     // returns 0-based indices of extruders used to print the object (without brim, support and other helper extrusions)
     std::vector<unsigned int>   object_extruders() const;
diff --git a/src/libslic3r/PrintConfig.cpp b/src/libslic3r/PrintConfig.cpp
index dffb8ac0c..c46ac04d6 100644
--- a/src/libslic3r/PrintConfig.cpp
+++ b/src/libslic3r/PrintConfig.cpp
@@ -471,7 +471,8 @@ void PrintConfigDef::init_fff_params()
     def = this->add("brim_width", coFloat);
     def->label = L("Brim width");
     def->category = L("Skirt and brim");
-    def->tooltip = L("Horizontal width of the brim that will be printed around each object on the first layer.");
+    def->tooltip = L("Horizontal width of the brim that will be printed around each object on the first layer."
+                     "When raft is used, no brim is generated (use raft_first_layer_expansion).");
     def->sidetext = L("mm");
     def->min = 0;
     def->max = 200;