Skip to content
Snippets Groups Projects
Commit d1e56d64 authored by Wuttke, Joachim's avatar Wuttke, Joachim
Browse files

SampleLabelHandler: start new mechnism; leave single items unnumbered

parent 55a630a4
No related branches found
No related tags found
No related merge requests found
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include "Core/Export/SampleLabelHandler.h" #include "Core/Export/SampleLabelHandler.h"
#include "Sample/Aggregate/IInterferenceFunction.h" #include "Sample/Aggregate/IInterferenceFunction.h"
#include "Sample/Multilayer/MultiLayer.h" #include "Sample/Multilayer/MultiLayer.h"
#include "Sample/Multilayer/Layer.h"
#include "Sample/Particle/MesoCrystal.h" #include "Sample/Particle/MesoCrystal.h"
#include "Sample/Particle/Particle.h" #include "Sample/Particle/Particle.h"
#include "Sample/Particle/ParticleComposition.h" #include "Sample/Particle/ParticleComposition.h"
...@@ -36,7 +37,14 @@ std::string SampleLabelHandler::labelInterferenceFunction(const IInterferenceFun ...@@ -36,7 +37,14 @@ std::string SampleLabelHandler::labelInterferenceFunction(const IInterferenceFun
} }
std::string SampleLabelHandler::labelLayer(const Layer* layer) { std::string SampleLabelHandler::labelLayer(const Layer* layer) {
return m_LayerLabel[layer]; std::vector<const Layer*> v = objectsOfType<Layer>();
const auto vpos = std::find(v.begin(), v.end(), layer);
if (vpos == std::end(v))
throw std::runtime_error("BUG: object not found in SampleLabelHandler::labelLayer");
std::string ret = "layer";
if (v.size()>1)
ret += "_" + std::to_string(vpos-v.begin()+1);
return ret;
} }
std::string SampleLabelHandler::labelLayout(const ParticleLayout* layout) { std::string SampleLabelHandler::labelLayout(const ParticleLayout* layout) {
...@@ -109,6 +117,8 @@ void SampleLabelHandler::insertLattice3D(const Lattice3D* sample) { ...@@ -109,6 +117,8 @@ void SampleLabelHandler::insertLattice3D(const Lattice3D* sample) {
void SampleLabelHandler::insertLayer(const Layer* sample) { void SampleLabelHandler::insertLayer(const Layer* sample) {
std::string label = "layer_" + std::to_string(m_LayerLabel.size() + 1); std::string label = "layer_" + std::to_string(m_LayerLabel.size() + 1);
m_LayerLabel.insert(sample, label); m_LayerLabel.insert(sample, label);
m_objects.push_back((const ISample*)(sample));
} }
void SampleLabelHandler::insertLayout(const ParticleLayout* sample) { void SampleLabelHandler::insertLayout(const ParticleLayout* sample) {
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#define BORNAGAIN_CORE_EXPORT_SAMPLELABELHANDLER_H #define BORNAGAIN_CORE_EXPORT_SAMPLELABELHANDLER_H
#include "Core/Export/OrderedMap.h" #include "Core/Export/OrderedMap.h"
#include <vector>
class Crystal; class Crystal;
class IAbstractParticle; class IAbstractParticle;
...@@ -23,6 +24,7 @@ class IFormFactor; ...@@ -23,6 +24,7 @@ class IFormFactor;
class IInterferenceFunction; class IInterferenceFunction;
class ParticleLayout; class ParticleLayout;
class Material; class Material;
class ISample;
class IRotation; class IRotation;
class Lattice2D; class Lattice2D;
class Lattice3D; class Lattice3D;
...@@ -107,6 +109,9 @@ public: ...@@ -107,6 +109,9 @@ public:
void insertRotation(const IRotation* sample); void insertRotation(const IRotation* sample);
void insertRoughness(const LayerRoughness* sample); void insertRoughness(const LayerRoughness* sample);
template<class T>
std::vector<const T*> objectsOfType() const;
private: private:
crystals_t m_CrystalLabel; crystals_t m_CrystalLabel;
formfactors_t m_FormFactorLabel; formfactors_t m_FormFactorLabel;
...@@ -124,6 +129,17 @@ private: ...@@ -124,6 +129,17 @@ private:
particlescoreshell_t m_ParticleCoreShellLabel; particlescoreshell_t m_ParticleCoreShellLabel;
rotations_t m_RotationsLabel; rotations_t m_RotationsLabel;
roughnesses_t m_LayerRoughnessLabel; roughnesses_t m_LayerRoughnessLabel;
std::vector<const ISample*> m_objects;
}; };
template<class T>
std::vector<const T*> SampleLabelHandler::objectsOfType() const {
std::vector<const T*> ret;
for (const ISample* s: m_objects)
if (const auto* c = dynamic_cast<const T*>(s); c)
ret.push_back(c);
return ret;
}
#endif // BORNAGAIN_CORE_EXPORT_SAMPLELABELHANDLER_H #endif // BORNAGAIN_CORE_EXPORT_SAMPLELABELHANDLER_H
...@@ -188,29 +188,24 @@ std::string SampleToPython::defineMaterials() const { ...@@ -188,29 +188,24 @@ std::string SampleToPython::defineMaterials() const {
} }
std::string SampleToPython::defineLayers() const { std::string SampleToPython::defineLayers() const {
const auto* themap = m_label->layerMap(); std::vector<const Layer*> v = m_label->objectsOfType<Layer>();
if (themap->empty()) if (v.empty())
return "# No Layers.\n\n"; return "";
std::ostringstream result; std::ostringstream result;
result << std::setprecision(12);
result << "\n" << indent() << "# Define layers\n"; result << "\n" << indent() << "# Define layers\n";
for (auto it = themap->begin(); it != themap->end(); ++it) { result << std::setprecision(12);
const Layer* layer = it->first; for (const Layer* layer: v) {
result << indent() << it->second << " = ba.Layer(" const std::string& label = m_label->labelLayer(layer);
result << indent() << label << " = ba.Layer("
<< m_label->labelMaterial(layer->material()); << m_label->labelMaterial(layer->material());
if (layer->thickness() != 0) if (layer->thickness() != 0)
result << ", " << pyfmt::printNm(layer->thickness()); result << ", " << pyfmt::printNm(layer->thickness());
result << ")\n"; result << ")\n";
if (layer->numberOfSlices() != 1) if (layer->numberOfSlices() != 1)
result << indent() << it->second << ".setNumberOfSlices(" << layer->numberOfSlices() result << indent() << label << ".setNumberOfSlices(" << layer->numberOfSlices()
<< ")\n"; << ")\n";
}
result << std::setprecision(12);
const auto layermap = m_label->layerMap();
for (auto it = layermap->begin(); it != layermap->end(); ++it) {
const Layer* layer = it->first;
for (const auto* layout : layer->layouts()) for (const auto* layout : layer->layouts())
result << indent() << it->second << ".addLayout(" << m_label->labelLayout(layout) result << indent() << label << ".addLayout(" << m_label->labelLayout(layout)
<< ")\n"; << ")\n";
} }
return result.str(); return result.str();
...@@ -262,8 +257,7 @@ std::string SampleToPython::defineCoreShellParticles() const { ...@@ -262,8 +257,7 @@ std::string SampleToPython::defineCoreShellParticles() const {
result << "\n" << indent() << "# Define core shell particles\n"; result << "\n" << indent() << "# Define core shell particles\n";
for (auto it = themap->begin(); it != themap->end(); ++it) { for (auto it = themap->begin(); it != themap->end(); ++it) {
const ParticleCoreShell* coreshell = it->first; const ParticleCoreShell* coreshell = it->first;
result << "\n" result << indent() << it->second << " = ba.ParticleCoreShell("
<< indent() << it->second << " = ba.ParticleCoreShell("
<< m_label->labelParticle(coreshell->shellParticle()) << ", " << m_label->labelParticle(coreshell->shellParticle()) << ", "
<< m_label->labelParticle(coreshell->coreParticle()) << ")\n"; << m_label->labelParticle(coreshell->coreParticle()) << ")\n";
std::string core_shell_name = it->second; std::string core_shell_name = it->second;
......
...@@ -1889,6 +1889,9 @@ C++ includes: SampleLabelHandler.h ...@@ -1889,6 +1889,9 @@ C++ includes: SampleLabelHandler.h
%feature("docstring") SampleLabelHandler::insertRoughness "void SampleLabelHandler::insertRoughness(const LayerRoughness *sample) %feature("docstring") SampleLabelHandler::insertRoughness "void SampleLabelHandler::insertRoughness(const LayerRoughness *sample)
"; ";
%feature("docstring") SampleLabelHandler::objectsOfType "std::vector< const T * > SampleLabelHandler::objectsOfType() const
";
// File: classSampleToPython.xml // File: classSampleToPython.xml
%feature("docstring") SampleToPython " %feature("docstring") SampleToPython "
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment