Skip to content
Snippets Groups Projects
Commit 590e3d60 authored by Mikhail Svechnikov's avatar Mikhail Svechnikov
Browse files

[m.i888] Define child particles compositions first while exporting sample to...

[m.i888] Define child particles compositions first while exporting sample to Python script (Closes #888)

Merging branch 'm.i888'  into 'main'.

See merge request !2276
parents 873cbe6e 28c8ee8a
No related branches found
No related tags found
1 merge request!2276Define child particles compositions first while exporting sample to Python script
Pipeline #125576 passed
...@@ -48,10 +48,13 @@ template <typename T> std::vector<const T*> AllDescendantsOfType(const INode& no ...@@ -48,10 +48,13 @@ template <typename T> std::vector<const T*> AllDescendantsOfType(const INode& no
std::vector<const T*> result; std::vector<const T*> result;
for (const auto* child : node.nodeChildren()) { for (const auto* child : node.nodeChildren()) {
ASSERT(child); ASSERT(child);
if (const auto* t = dynamic_cast<const T*>(child)) // Since this function is used to define objects in the generated Python script, the order
result.push_back(t); // of the elements is important. The parent may call its children => the children must be
// defined before. So first add all children/descendants to the output vector.
for (const auto* t : AllDescendantsOfType<T>(*child)) for (const auto* t : AllDescendantsOfType<T>(*child))
result.push_back(t); result.push_back(t);
if (const auto* t = dynamic_cast<const T*>(child))
result.push_back(t);
} }
return result; return result;
} }
......
...@@ -524,11 +524,11 @@ std::string SampleToPython::sampleCode(const MultiLayer& sample) ...@@ -524,11 +524,11 @@ std::string SampleToPython::sampleCode(const MultiLayer& sample)
for (const auto* x : NodeUtil::AllDescendantsOfType<Particle>(sample)) for (const auto* x : NodeUtil::AllDescendantsOfType<Particle>(sample))
objHandler.insertModel("particle", x); objHandler.insertModel("particle", x);
for (const auto* x : NodeUtil::AllDescendantsOfType<Compound>(sample)) for (const auto* x : NodeUtil::AllDescendantsOfType<Compound>(sample))
objHandler.insertModel("particle", x); objHandler.insertModel("compound", x);
for (const auto* x : NodeUtil::AllDescendantsOfType<CoreAndShell>(sample)) for (const auto* x : NodeUtil::AllDescendantsOfType<CoreAndShell>(sample))
objHandler.insertModel("particle", x); objHandler.insertModel("coreshell", x);
for (const auto* x : NodeUtil::AllDescendantsOfType<Mesocrystal>(sample)) for (const auto* x : NodeUtil::AllDescendantsOfType<Mesocrystal>(sample))
objHandler.insertModel("particle", x); objHandler.insertModel("mesocrystal", x);
for (const auto* x : NodeUtil::AllDescendantsOfType<Lattice2D>(sample)) for (const auto* x : NodeUtil::AllDescendantsOfType<Lattice2D>(sample))
objHandler.insertModel("lattice", x); objHandler.insertModel("lattice", x);
for (const auto* x : NodeUtil::AllDescendantsOfType<Lattice3D>(sample)) for (const auto* x : NodeUtil::AllDescendantsOfType<Lattice3D>(sample))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment