From b9c2f47b4ee8db7f6ac560a330ad17eb9455c705 Mon Sep 17 00:00:00 2001
From: Mikhail Svechnikov <svechnikovmv@gmail.com>
Date: Mon, 16 Oct 2023 23:51:15 +0200
Subject: [PATCH] allow magnetization for particles in fronting media

---
 GUI/View/SampleDesigner/LayerEditorUtil.cpp     | 17 +++++++++--------
 GUI/View/SampleDesigner/LayerEditorUtil.h       |  6 +++---
 GUI/View/SampleDesigner/MaterialInplaceForm.cpp |  9 +++++----
 3 files changed, 17 insertions(+), 15 deletions(-)

diff --git a/GUI/View/SampleDesigner/LayerEditorUtil.cpp b/GUI/View/SampleDesigner/LayerEditorUtil.cpp
index 37cf6a069fe..288782a1935 100644
--- a/GUI/View/SampleDesigner/LayerEditorUtil.cpp
+++ b/GUI/View/SampleDesigner/LayerEditorUtil.cpp
@@ -135,16 +135,17 @@ void LayerEditorUtil::addVectorToGrid(QGridLayout* m_gridLayout, int firstCol, V
                            vertically, addSpacer);
 }
 
-void LayerEditorUtil::addMagnetizationNoZToGrid(
+void LayerEditorUtil::addMagnetizationToGrid(
     QGridLayout* m_gridLayout, int firstCol, VectorProperty& v,
-    std::function<void(double, DoubleProperty&)> setNewValue, bool vertically, bool addSpacer)
+    std::function<void(double, DoubleProperty&)> setNewValue, bool vertically, bool addSpacer,
+    bool with_z)
 {
-    // Setting z-component is temporary disabled (see issue #654)
-    // When interaction with magnetic field in fronting medium is implemented,
-    // delete this method and use 'addVectorToGrid' instead
-
-    addMultiPropertyToGrid(m_gridLayout, firstCol, {&v.x(), &v.y()}, setNewValue, vertically,
-                           addSpacer);
+    if (with_z)
+        addMultiPropertyToGrid(m_gridLayout, firstCol, {&v.x(), &v.y(), &v.z()}, setNewValue,
+                               vertically, addSpacer);
+    else
+        addMultiPropertyToGrid(m_gridLayout, firstCol, {&v.x(), &v.y()}, setNewValue, vertically,
+                               addSpacer);
 }
 
 QLabel* LayerEditorUtil::createBoldLabel(const QString& text)
diff --git a/GUI/View/SampleDesigner/LayerEditorUtil.h b/GUI/View/SampleDesigner/LayerEditorUtil.h
index 9af6be1d749..efbf80c821b 100644
--- a/GUI/View/SampleDesigner/LayerEditorUtil.h
+++ b/GUI/View/SampleDesigner/LayerEditorUtil.h
@@ -64,9 +64,9 @@ void addVectorToGrid(QGridLayout* m_gridLayout, int firstCol, VectorProperty& v,
 void addVectorToGrid(QGridLayout* m_gridLayout, int firstCol, VectorProperty& v,
                      std::function<void(double, DoubleProperty&)> setNewValue, bool vertically,
                      bool addSpacer);
-void addMagnetizationNoZToGrid(QGridLayout* m_gridLayout, int firstCol, VectorProperty& v,
-                               std::function<void(double, DoubleProperty&)> setNewValue,
-                               bool vertically, bool addSpacer);
+void addMagnetizationToGrid(QGridLayout* m_gridLayout, int firstCol, VectorProperty& v,
+                            std::function<void(double, DoubleProperty&)> setNewValue,
+                            bool vertically, bool addSpacer, bool with_z);
 
 QLabel* createBoldLabel(const QString& text);
 
diff --git a/GUI/View/SampleDesigner/MaterialInplaceForm.cpp b/GUI/View/SampleDesigner/MaterialInplaceForm.cpp
index 934696c62eb..e8eeb5e9248 100644
--- a/GUI/View/SampleDesigner/MaterialInplaceForm.cpp
+++ b/GUI/View/SampleDesigner/MaterialInplaceForm.cpp
@@ -120,12 +120,13 @@ void MaterialInplaceForm::createWidgets()
     };
 
     // Processing z-magnetization is not implemented yet (see issue #654)
-    // LayerEditorUtil::addVectorToGrid(m_layout, col, material->magnetization(), setNewValue, true,
-    // false); When implemented, rm following lines and use 'addVectorToGrid'
     const LayerItem* layer_item = dynamic_cast<LayerItem*>(m_item);
     if (layer_item && !layer_item->isTopLayer())
-        LayerEditorUtil::addMagnetizationNoZToGrid(m_layout, col, material->magnetization(),
-                                                   setNewValue, true, false);
+        LayerEditorUtil::addMagnetizationToGrid(m_layout, col, material->magnetization(),
+                                                setNewValue, true, false, false);
+    if (!layer_item)
+        LayerEditorUtil::addMagnetizationToGrid(m_layout, col, material->magnetization(),
+                                                setNewValue, true, false, true);
 
     // -- Create UI for material selection button
     auto* btn = new QPushButton("...", this);
-- 
GitLab