From 466cbd7d5dafd2831dd3369d953e2d3d47e9d248 Mon Sep 17 00:00:00 2001 From: Jannis Maier Date: Thu, 19 Dec 2024 09:41:15 +0100 Subject: [PATCH] --- Intern/rayx-core/src/Data/Importer.cpp | 57 +++++++++---------- Intern/rayx-core/src/Data/xml.cpp | 2 +- Intern/rayx-core/src/Design/DesignElement.cpp | 13 ++--- Intern/rayx-core/src/Element/Behaviour.cpp | 24 ++++---- Intern/rayx-core/src/Element/Surface.cpp | 39 +++++++------ 5 files changed, 64 insertions(+), 71 deletions(-) diff --git a/Intern/rayx-core/src/Data/Importer.cpp b/Intern/rayx-core/src/Data/Importer.cpp index 481c1583..94662a04 100644 --- a/Intern/rayx-core/src/Data/Importer.cpp +++ b/Intern/rayx-core/src/Data/Importer.cpp @@ -61,43 +61,42 @@ namespace RAYX { void addBeamlineObjectFromXML(rapidxml::xml_node<>* node, Beamline* beamline, const std::vector& group_context, std::filesystem::path filename) { - // the following three blocks of code are lambda expressions (see - // https://en.cppreference.com/w/cpp/language/lambda) They define functions - // to be used in the if-else-chain below to keep it structured and readable. - - // //addLightSource(s, node) is a function adding a light source to the - // beamline (if it's not nullptr) - RAYX::xml::Parser parser(node, group_context, filename); ElementType type = parser.type(); + DesignSource ds; ds.m_elementParameters = Map(); DesignElement de; de.m_elementParameters = Map(); - // Light sources have constructors that accept a const DesignObject& as argument. - // They use the param* functions declared in to retrieve the relevant information. - if (type == ElementType::PointSource) { - setPointSource(parser, &ds); - beamline->m_DesignSources.push_back(ds); - } else if (type == ElementType::MatrixSource) { - setMatrixSource(parser, &ds); - beamline->m_DesignSources.push_back(ds); - } else if (type == ElementType::DipoleSource) { - setDipoleSource(parser, &ds); - beamline->m_DesignSources.push_back(ds); - } else if (type == ElementType::DipoleSrc) { - setDipoleSource(parser, &ds); - beamline->m_DesignSources.push_back(ds); - } else if (type == ElementType::PixelSource) { - setPixelSource(parser, &ds); - beamline->m_DesignSources.push_back(ds); - } else if (type == ElementType::CircleSource) { - setCircleSource(parser, &ds); - beamline->m_DesignSources.push_back(ds); - } else if (type == ElementType::SimpleUndulatorSource) { - setSimpleUndulatorSource(parser, &ds); + bool isSource = true; + switch (type) { + case ElementType::PointSource: + setPointSource(parser, &ds); + break; + case ElementType::MatrixSource: + setMatrixSource(parser, &ds); + break; + case ElementType::DipoleSource: + case ElementType::DipoleSrc: + setDipoleSource(parser, &ds); + break; + case ElementType::PixelSource: + setPixelSource(parser, &ds); + break; + case ElementType::CircleSource: + setCircleSource(parser, &ds); + break; + case ElementType::SimpleUndulatorSource: + setSimpleUndulatorSource(parser, &ds); + break; + default: + isSource = false; + break; + } + + if (isSource) { beamline->m_DesignSources.push_back(ds); } else { parseElement(parser, &de); diff --git a/Intern/rayx-core/src/Data/xml.cpp b/Intern/rayx-core/src/Data/xml.cpp index b4b97950..ce605d3b 100644 --- a/Intern/rayx-core/src/Data/xml.cpp +++ b/Intern/rayx-core/src/Data/xml.cpp @@ -460,7 +460,7 @@ bool parseGroup(rapidxml::xml_node<>* node, xml::Group* out) { out->m_position = glm::vec4(0, 0, 0, 1); out->m_orientation = glm::dmat4x4(); - if (strcmp(node->name(), "group") != 0) { + if (std::strcmp(node->name(), "group") != 0) { return false; } diff --git a/Intern/rayx-core/src/Design/DesignElement.cpp b/Intern/rayx-core/src/Design/DesignElement.cpp index 44bcf7e0..f8bfa23e 100644 --- a/Intern/rayx-core/src/Design/DesignElement.cpp +++ b/Intern/rayx-core/src/Design/DesignElement.cpp @@ -8,20 +8,17 @@ namespace RAYX { Element DesignElement::compile() const { RAYX_PROFILE_FUNCTION_STDOUT(); - Surface surface; - Behaviour behav; - if (getType() == ElementType::ExpertsMirror) { return makeElement(*this, serializeMirror(), makeQuadric(*this)); } else { - surface = makeSurface(*this); - behav = makeBehaviour(*this); + Surface surface = makeSurface(*this); + Behaviour behavior = makeBehaviour(*this); if (getType() == ElementType::Slit) { - return makeElement(*this, behav, surface, {}, DesignPlane::XY); + return makeElement(*this, behavior, surface, {}, DesignPlane::XY); } else if (getType() == ElementType::ImagePlane) { - return makeElement(*this, behav, surface, serializeUnlimited(), DesignPlane::XY); + return makeElement(*this, behavior, surface, serializeUnlimited(), DesignPlane::XY); } else { - return makeElement(*this, behav, surface); + return makeElement(*this, behavior, surface); } } } diff --git a/Intern/rayx-core/src/Element/Behaviour.cpp b/Intern/rayx-core/src/Element/Behaviour.cpp index 158e8aec..1d9f3323 100644 --- a/Intern/rayx-core/src/Element/Behaviour.cpp +++ b/Intern/rayx-core/src/Element/Behaviour.cpp @@ -8,19 +8,17 @@ namespace RAYX { Behaviour makeBehaviour(const DesignElement& dele) { - BehaviourType behave = dele.getBehaviourType(); - if (behave == BehaviourType::Grating) { - return makeGrating(dele); - } else if (behave == BehaviourType::Mirror) { - return serializeMirror(); - } else if (behave == BehaviourType::Rzp) { - return makeRZPBehaviour(dele); - } else if (behave == BehaviourType::Slit) { - return makeSlit(dele); - } else if (behave == BehaviourType::Mirror) { - return serializeMirror(); - } else { - return serializeImagePlane(); + switch (dele.getBehaviourType()) { + case BehaviourType::Grating: + return makeGrating(dele); + case BehaviourType::Mirror: + return serializeMirror(); + case BehaviourType::Rzp: + return makeRZPBehaviour(dele); + case BehaviourType::Slit: + return makeSlit(dele); + default: + return serializeImagePlane(); } } diff --git a/Intern/rayx-core/src/Element/Surface.cpp b/Intern/rayx-core/src/Element/Surface.cpp index 881d0a3b..744396bb 100644 --- a/Intern/rayx-core/src/Element/Surface.cpp +++ b/Intern/rayx-core/src/Element/Surface.cpp @@ -6,25 +6,24 @@ namespace RAYX { Surface makeSurface(const DesignElement& dele) { - auto surface = dele.getCurvatureType(); - if (surface == CurvatureType::Plane) { - return makePlane(); - } else if (surface == CurvatureType::Toroidal) { - return makeToroid(dele); - } else if (surface == CurvatureType::Spherical) { - return makeSphere(dele.getRadius()); - } else if (surface == CurvatureType::RzpSphere) { - return makeSphere(dele.getLongRadius()); - } else if (surface == CurvatureType::Cone) { - return makeCone(dele); - } else if (surface == CurvatureType::Cylinder) { - return makeCylinder(dele); - } else if (surface == CurvatureType::Ellipsoid) { - return makeEllipsoid(dele); - } else if (surface == CurvatureType::Paraboloid) { - return makeParaboloid(dele); - } else { - return serializePlaneXZ(); + switch (dele.getCurvatureType()) { + case CurvatureType::Toroidal: + return makeToroid(dele); + case CurvatureType::Spherical: + return makeSphere(dele.getRadius()); + case CurvatureType::RzpSphere: + return makeSphere(dele.getLongRadius()); + case CurvatureType::Cone: + return makeCone(dele); + case CurvatureType::Cylinder: + return makeCylinder(dele); + case CurvatureType::Ellipsoid: + return makeEllipsoid(dele); + case CurvatureType::Paraboloid: + return makeParaboloid(dele); + case CurvatureType::Plane: + default: + return makePlane(); } } @@ -77,7 +76,7 @@ Surface makeCylinder(const DesignElement& dele) { } Surface makeCone(const DesignElement& dele) { - auto incidence = dele.getGrazingIncAngle(); + RAYX::Rad incidence = dele.getGrazingIncAngle(); double entranceArmLength = dele.getEntranceArmLength(); double exitArmLength = dele.getExitArmLength();