From 895e02a89cd6c5a465e2e32429a1380391c58d13 Mon Sep 17 00:00:00 2001
From: Christof Kraus <christof.j.kraus@gmail.com>
Date: Sun, 19 Jul 2020 20:32:03 +0200
Subject: [PATCH] cleaning up OpalRBend and OpalSBend

---
 src/Elements/OpalRBend.cpp | 11 +++++------
 src/Elements/OpalSBend.cpp |  9 ++++++---
 2 files changed, 11 insertions(+), 9 deletions(-)

diff --git a/src/Elements/OpalRBend.cpp b/src/Elements/OpalRBend.cpp
index 90fecb7d5..97f10fe22 100644
--- a/src/Elements/OpalRBend.cpp
+++ b/src/Elements/OpalRBend.cpp
@@ -181,18 +181,17 @@ void OpalRBend::update() {
                             "RBend requires non-zero DESIGNENERGY");
     }
 
-    bend->setFullGap(Attributes::getReal(itsAttr[GAP]));
+    double gap = Attributes::getReal(itsAttr[GAP]);
+    bend->setFullGap(gap);
 
-    // if(itsAttr[APERT])
-    //     throw OpalException("OpalRBend::fillRegisteredAttributes",
-    //                         "APERTURE in RBEND not supported; use GAP and HAPERT instead");
+    if(itsAttr[APERT])
+        throw OpalException("OpalRBend::update",
+                            "APERTURE in RBEND not supported; use GAP and HAPERT instead");
 
     if(itsAttr[HAPERT]) {
         double hapert = Attributes::getReal(itsAttr[HAPERT]);
-        double gap = Attributes::getReal(itsAttr[GAP]);
         bend->setAperture(ElementBase::RECTANGULAR, std::vector<double>({hapert, gap, 1.0}));
     } else {
-        double gap = Attributes::getReal(itsAttr[GAP]);
         bend->setAperture(ElementBase::RECTANGULAR, std::vector<double>({0.5, gap, 1.0}));
     }
 
diff --git a/src/Elements/OpalSBend.cpp b/src/Elements/OpalSBend.cpp
index 2ec776a80..ffa9518ba 100644
--- a/src/Elements/OpalSBend.cpp
+++ b/src/Elements/OpalSBend.cpp
@@ -187,7 +187,8 @@ void OpalSBend::update() {
                             "SBend requires non-zero DESIGNENERGY");
     }
 
-    bend->setFullGap(Attributes::getReal(itsAttr[GAP]));
+    double gap = Attributes::getReal(itsAttr[GAP]);
+    bend->setFullGap(gap);
 
     if(itsAttr[APERT])
         throw OpalException("OpalSBend::update",
@@ -195,7 +196,9 @@ void OpalSBend::update() {
 
     if(itsAttr[HAPERT]) {
         double hapert = Attributes::getReal(itsAttr[HAPERT]);
-        bend->setAperture(ElementBase::RECTANGULAR, std::vector<double>({hapert, hapert, 1.0}));
+        bend->setAperture(ElementBase::RECTANGULAR, std::vector<double>({hapert, gap, 1.0}));
+    } else {
+        bend->setAperture(ElementBase::RECTANGULAR, std::vector<double>({0.5, gap, 1.0}));
     }
 
     if(itsAttr[LENGTH])
@@ -222,4 +225,4 @@ void OpalSBend::update() {
 
     // Transmit "unknown" attributes.
     OpalElement::updateUnknown(bend);
-}
+}
\ No newline at end of file
-- 
GitLab