From f0d106e5f016499214d60e3cdd600ed88a434d3e Mon Sep 17 00:00:00 2001
From: tamasmeszaros <meszaros.q@gmail.com>
Date: Thu, 4 Apr 2019 10:52:14 +0200
Subject: [PATCH] Added method for relative correction retrieval.

---
 src/libslic3r/SLAPrint.cpp | 39 ++++++++++++++++++++++----------------
 src/libslic3r/SLAPrint.hpp |  3 +++
 2 files changed, 26 insertions(+), 16 deletions(-)

diff --git a/src/libslic3r/SLAPrint.cpp b/src/libslic3r/SLAPrint.cpp
index c5c474521..b1bc7e015 100644
--- a/src/libslic3r/SLAPrint.cpp
+++ b/src/libslic3r/SLAPrint.cpp
@@ -85,22 +85,10 @@ void SLAPrint::clear()
 }
 
 // Transformation without rotation around Z and without a shift by X and Y.
-static Transform3d sla_trafo(const ModelObject &model_object, const SLAPrinterConfig& pconf, const SLAMaterialConfig& mconf)
+static Transform3d sla_trafo(const SLAPrint& p, const ModelObject &model_object)
 {
 
-    Vec3d corr(1., 1., 1.);
-
-    if(pconf.printer_correction.values.size() == 3) {
-        corr(X) = pconf.printer_correction.values[X];
-        corr(Y) = pconf.printer_correction.values[Y];
-        corr(Z) = pconf.printer_correction.values[Z];
-    }
-
-    if(mconf.material_correction.values.size() == 3) {
-        corr(X) *= mconf.material_correction.values[X];
-        corr(Y) *= mconf.material_correction.values[Y];
-        corr(Z) *= mconf.material_correction.values[Z];
-    }
+    Vec3d corr = p.relative_correction();
 
     ModelInstance &model_instance = *model_object.instances.front();
     Vec3d          offset         = model_instance.get_offset();
@@ -347,7 +335,7 @@ SLAPrint::ApplyStatus SLAPrint::apply(const Model &model, const DynamicPrintConf
             bool sla_trafo_differs  =
                 model_object.instances.empty() != model_object_new.instances.empty() ||
                 (! model_object.instances.empty() &&
-                  (! sla_trafo(model_object, m_printer_config, m_material_config).isApprox(sla_trafo(model_object_new, m_printer_config, m_material_config)) ||
+                  (! sla_trafo(*this, model_object_new).isApprox(sla_trafo(*this, model_object_new)) ||
                     model_object.instances.front()->is_left_handed() != model_object_new.instances.front()->is_left_handed()));
             if (model_parts_differ || sla_trafo_differs) {
                 // The very first step (the slicing step) is invalidated. One may freely remove all associated PrintObjects.
@@ -432,7 +420,7 @@ SLAPrint::ApplyStatus SLAPrint::apply(const Model &model, const DynamicPrintConf
 
             // FIXME: this invalidates the transformed mesh in SLAPrintObject
             // which is expensive to calculate (especially the raw_mesh() call)
-            print_object->set_trafo(sla_trafo(model_object, m_printer_config, m_material_config), model_object.instances.front()->is_left_handed());
+            print_object->set_trafo(sla_trafo(*this, model_object), model_object.instances.front()->is_left_handed());
 
             print_object->set_instances(std::move(new_instances));
             print_object->config_apply(config, true);
@@ -1643,6 +1631,25 @@ double SLAPrintObject::get_current_elevation() const
     return get_elevation();
 }
 
+Vec3d SLAPrint::relative_correction() const
+{
+    Vec3d corr(1., 1., 1.);
+
+    if(printer_config().printer_correction.values.size() == 3) {
+        corr(X) = printer_config().printer_correction.values[X];
+        corr(Y) = printer_config().printer_correction.values[Y];
+        corr(Z) = printer_config().printer_correction.values[Z];
+    }
+
+    if(material_config().material_correction.values.size() == 3) {
+        corr(X) *= material_config().material_correction.values[X];
+        corr(Y) *= material_config().material_correction.values[Y];
+        corr(Z) *= material_config().material_correction.values[Z];
+    }
+
+    return corr;
+}
+
 namespace { // dummy empty static containers for return values in some methods
 const std::vector<ExPolygons> EMPTY_SLICES;
 const TriangleMesh EMPTY_MESH;
diff --git a/src/libslic3r/SLAPrint.hpp b/src/libslic3r/SLAPrint.hpp
index a1e382acb..abea0b35b 100644
--- a/src/libslic3r/SLAPrint.hpp
+++ b/src/libslic3r/SLAPrint.hpp
@@ -401,6 +401,9 @@ public:
     const SLAMaterialConfig&    material_config() const { return m_material_config; }
     const SLAPrintObjectConfig& default_object_config() const { return m_default_object_config; }
 
+    // Extracted value from the configuration objects
+    Vec3d relative_correction() const;
+
 	std::string         output_filename() const override;
 
     const SLAPrintStatistics&      print_statistics() const { return m_print_statistics; }