diff --git a/Core/Multilayer/Layer.cpp b/Core/Multilayer/Layer.cpp index 0737cd996944c50b209b51d72f18bbc83b7548c0..7446356c3f4ae5d8cdc0fa05acfc7f424195e9db 100644 --- a/Core/Multilayer/Layer.cpp +++ b/Core/Multilayer/Layer.cpp @@ -36,16 +36,20 @@ Layer::Layer(HomogeneousMaterial material, double thickness) Layer::~Layer() {} -Layer*Layer::clone() const +Layer* Layer::clone() const { - return new Layer(*this); + Layer* p_result = shallowClone(); + p_result->m_n_slices = m_n_slices; + for (auto p_layout : layouts()) + p_result->addLayout(*p_layout); + return p_result; } Layer* Layer::cloneInvertB() const { - Layer* p_clone = new Layer(m_material.inverted(), m_thickness); - p_clone->m_B_field = - m_B_field; - return p_clone; + Layer* p_result = shallowClone(); + p_result->m_B_field = -m_B_field; + return p_result; } SafePointerVector<Layer> Layer::cloneSliced(ZLimits limits, Layer::ELayerType layer_type) const @@ -160,18 +164,6 @@ void Layer::initBField(kvector_t h_field, double b_z) m_B_field.setZ(b_z); } -Layer::Layer(const Layer& other) - : m_material(other.m_material) -{ - setName(other.getName()); - m_thickness = other.m_thickness; - m_n_slices = other.m_n_slices; - m_B_field = other.m_B_field; - for (auto p_layout : other.layouts()) - addLayout(*p_layout); - registerThickness(); -} - Layer* Layer::shallowClone() const { Layer* p_result = new Layer(m_material, m_thickness); diff --git a/Core/Multilayer/Layer.h b/Core/Multilayer/Layer.h index 62e5d270d0c157d3ae64bd115991ac9f14f55285..ca777912ed375f725c7da458043fb2dc93ddb671 100644 --- a/Core/Multilayer/Layer.h +++ b/Core/Multilayer/Layer.h @@ -81,7 +81,6 @@ public: static constexpr double Magnetic_Permeability = 4e-7 * M_PI; private: - Layer(const Layer& other); //! Clone the layer without its layouts Layer* shallowClone() const; //! Clone and offsets the particles in the z-direction