From 9313a28a0004316f978c0a2fa26dd9c239d2b3fa Mon Sep 17 00:00:00 2001 From: "Joachim Wuttke (h)" <j.wuttke@fz-juelich.de> Date: Sun, 15 Nov 2020 23:44:31 +0100 Subject: [PATCH] activate export of Lattice2D to Python --- Core/Export/OrderedMap.h | 19 +++++++------------ Core/Export/SampleLabelHandler.cpp | 24 ++++++++++++------------ Core/Export/SampleToPython.cpp | 5 ++++- 3 files changed, 23 insertions(+), 25 deletions(-) diff --git a/Core/Export/OrderedMap.h b/Core/Export/OrderedMap.h index 0fc22197462..c96b225103d 100644 --- a/Core/Export/OrderedMap.h +++ b/Core/Export/OrderedMap.h @@ -65,20 +65,16 @@ public: iterator find(const Key& key) { - iterator result = m_list.end(); - if (m_map.find(key) != m_map.end()) { - result = m_map[key]; - } - return result; + if (m_map.find(key) != m_map.end()) + return m_map[key]; + return m_list.end(); } const_iterator find(const Key& key) const { - const_iterator result = m_list.end(); - if (m_map.find(key) != m_map.end()) { - result = m_map[key]; - } - return result; + if (m_map.find(key) != m_map.end()) + return m_map[key]; + return m_list.end(); } size_t erase(const Key& key) @@ -95,9 +91,8 @@ public: const Object& value(const Key& key) const { typename map_t::const_iterator mit = m_map.find(key); - if (mit == m_map.end()) { + if (mit == m_map.end()) throw std::runtime_error("OrderedMap::value() -> No such key"); - } const_iterator it = mit->second; return (*it).second; } diff --git a/Core/Export/SampleLabelHandler.cpp b/Core/Export/SampleLabelHandler.cpp index f4c79391091..05a58d3d80e 100644 --- a/Core/Export/SampleLabelHandler.cpp +++ b/Core/Export/SampleLabelHandler.cpp @@ -112,6 +112,18 @@ void SampleLabelHandler::insertInterferenceFunction(const IInterferenceFunction* m_InterferenceFunctionLabel.insert(sample, label); } +void SampleLabelHandler::insertLattice2D(const Lattice2D* sample) +{ + std::string label = "lattice2D_" + std::to_string(m_Lattice2DLabel.size() + 1); + m_Lattice2DLabel.insert(sample, label); +} + +void SampleLabelHandler::insertLattice3D(const Lattice3D* sample) +{ + std::string label = "lattice3D_" + std::to_string(m_Lattice3DLabel.size() + 1); + m_Lattice3DLabel.insert(sample, label); +} + void SampleLabelHandler::insertLayer(const Layer* sample) { std::string label = "layer_" + std::to_string(m_LayerLabel.size() + 1); @@ -141,18 +153,6 @@ void SampleLabelHandler::insertMaterial(const Material* mat) m_MaterialLabel.insert(mat, label); } -void SampleLabelHandler::insertLattice2D(const Lattice2D* sample) -{ - std::string label = "lattice2D_" + std::to_string(m_Lattice2DLabel.size() + 1); - m_Lattice2DLabel.insert(sample, label); -} - -void SampleLabelHandler::insertLattice3D(const Lattice3D* sample) -{ - std::string label = "lattice3D_" + std::to_string(m_Lattice3DLabel.size() + 1); - m_Lattice3DLabel.insert(sample, label); -} - void SampleLabelHandler::insertMesoCrystal(const MesoCrystal* sample) { std::string label = "mesocrystal_" + std::to_string(m_MesoCrystalLabel.size() + 1); diff --git a/Core/Export/SampleToPython.cpp b/Core/Export/SampleToPython.cpp index d8d6b0264c5..11d9ef1d063 100644 --- a/Core/Export/SampleToPython.cpp +++ b/Core/Export/SampleToPython.cpp @@ -66,6 +66,8 @@ void SampleToPython::initLabels(const MultiLayer& multilayer) m_label->insertParticleComposition(x); for (auto x : INodeUtils::AllDescendantsOfType<ParticleDistribution>(multilayer)) m_label->insertParticleDistribution(x); + for (auto x : INodeUtils::AllDescendantsOfType<Lattice2D>(multilayer)) + m_label->insertLattice2D(x); for (auto x : INodeUtils::AllDescendantsOfType<Lattice3D>(multilayer)) m_label->insertLattice3D(x); for (auto x : INodeUtils::AllDescendantsOfType<Crystal>(multilayer)) @@ -301,7 +303,8 @@ std::string SampleToPython::defineLattices2D() const result << indent() << indent() << pyfmt::printNm(lattice->length1()) << ", " << pyfmt::printNm(lattice->length2()) << ", " - << pyfmt::printNm(lattice->latticeAngle()) << "),\n"; + << pyfmt::printDegrees(lattice->latticeAngle()) << ", " + << pyfmt::printDegrees(lattice->rotationAngle()) << "),\n"; } return result.str(); } -- GitLab