From ab0bd11a373fc9fc71da66eba1de1f2a7f4f6f60 Mon Sep 17 00:00:00 2001
From: Walter Van Herck <w.van.herck@fz-juelich.de>
Date: Thu, 27 Sep 2018 17:11:56 +0200
Subject: [PATCH] Added factory method to create BCT lattice in a certain
 orientation

---
 Core/Lattice/LatticeUtils.cpp       |  10 +++
 Core/Lattice/LatticeUtils.h         |   2 +
 auto/Wrap/libBornAgainCore.py       |  24 +++++++
 auto/Wrap/libBornAgainCore_wrap.cpp | 108 ++++++++++++++++++++++++++++
 4 files changed, 144 insertions(+)

diff --git a/Core/Lattice/LatticeUtils.cpp b/Core/Lattice/LatticeUtils.cpp
index 18f388420eb..6c0965d7a19 100644
--- a/Core/Lattice/LatticeUtils.cpp
+++ b/Core/Lattice/LatticeUtils.cpp
@@ -35,3 +35,13 @@ Lattice LatticeUtils::CreateHCPLattice(double a, double c, const ILatticeOrienta
     Lattice hcp = Lattice::createHCPLattice(a, c);
     return hcp.createTransformedLattice(rotation);
 }
+
+Lattice LatticeUtils::CreateBCTLattice(double a, double c, const ILatticeOrientation &orientation)
+{
+    Lattice prim_tetragonal = Lattice::createTetragonalLattice(1.0, c/a);
+    std::unique_ptr<ILatticeOrientation> P_orientation(orientation.clone());
+    P_orientation->usePrimitiveLattice(prim_tetragonal);
+    auto rotation = P_orientation->transformationMatrix();
+    Lattice hcp = Lattice::createBCTLattice(a, c);
+    return hcp.createTransformedLattice(rotation);
+}
diff --git a/Core/Lattice/LatticeUtils.h b/Core/Lattice/LatticeUtils.h
index 74e48a57c9b..1c3eb7fe082 100644
--- a/Core/Lattice/LatticeUtils.h
+++ b/Core/Lattice/LatticeUtils.h
@@ -26,6 +26,8 @@ BA_CORE_API_ Lattice CreateFCCLattice(double lattice_constant,
                                       const ILatticeOrientation& orientation);
 BA_CORE_API_ Lattice CreateHCPLattice(double a, double c,
                                       const ILatticeOrientation& orientation);
+BA_CORE_API_ Lattice CreateBCTLattice(double a, double c,
+                                      const ILatticeOrientation& orientation);
 }  // namespace LatticeUtils
 
 #endif // LATTICEUTILS_H
diff --git a/auto/Wrap/libBornAgainCore.py b/auto/Wrap/libBornAgainCore.py
index 144f5323d88..56198b10522 100644
--- a/auto/Wrap/libBornAgainCore.py
+++ b/auto/Wrap/libBornAgainCore.py
@@ -24543,6 +24543,18 @@ class Lattice(INode):
 
     createHCPLattice = staticmethod(createHCPLattice)
 
+    def createTetragonalLattice(a, c):
+        """createTetragonalLattice(double a, double c) -> Lattice"""
+        return _libBornAgainCore.Lattice_createTetragonalLattice(a, c)
+
+    createTetragonalLattice = staticmethod(createTetragonalLattice)
+
+    def createBCTLattice(a, c):
+        """createBCTLattice(double a, double c) -> Lattice"""
+        return _libBornAgainCore.Lattice_createBCTLattice(a, c)
+
+    createBCTLattice = staticmethod(createBCTLattice)
+
     def onChange(self):
         """
         onChange(Lattice self)
@@ -24573,6 +24585,14 @@ def Lattice_createHCPLattice(a, c):
     """Lattice_createHCPLattice(double a, double c) -> Lattice"""
     return _libBornAgainCore.Lattice_createHCPLattice(a, c)
 
+def Lattice_createTetragonalLattice(a, c):
+    """Lattice_createTetragonalLattice(double a, double c) -> Lattice"""
+    return _libBornAgainCore.Lattice_createTetragonalLattice(a, c)
+
+def Lattice_createBCTLattice(a, c):
+    """Lattice_createBCTLattice(double a, double c) -> Lattice"""
+    return _libBornAgainCore.Lattice_createBCTLattice(a, c)
+
 
 def CreateFCCLattice(lattice_constant, orientation):
     """
@@ -24586,6 +24606,10 @@ def CreateFCCLattice(lattice_constant, orientation):
 def CreateHCPLattice(a, c, orientation):
     """CreateHCPLattice(double a, double c, ILatticeOrientation orientation) -> Lattice"""
     return _libBornAgainCore.CreateHCPLattice(a, c, orientation)
+
+def CreateBCTLattice(a, c, orientation):
+    """CreateBCTLattice(double a, double c, ILatticeOrientation orientation) -> Lattice"""
+    return _libBornAgainCore.CreateBCTLattice(a, c, orientation)
 class Lattice1DParameters(_object):
     """
 
diff --git a/auto/Wrap/libBornAgainCore_wrap.cpp b/auto/Wrap/libBornAgainCore_wrap.cpp
index 89fce75173d..1f9c17cbd2c 100644
--- a/auto/Wrap/libBornAgainCore_wrap.cpp
+++ b/auto/Wrap/libBornAgainCore_wrap.cpp
@@ -104899,6 +104899,68 @@ fail:
 }
 
 
+SWIGINTERN PyObject *_wrap_Lattice_createTetragonalLattice(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
+  PyObject *resultobj = 0;
+  double arg1 ;
+  double arg2 ;
+  double val1 ;
+  int ecode1 = 0 ;
+  double val2 ;
+  int ecode2 = 0 ;
+  PyObject * obj0 = 0 ;
+  PyObject * obj1 = 0 ;
+  SwigValueWrapper< Lattice > result;
+  
+  if (!PyArg_ParseTuple(args,(char *)"OO:Lattice_createTetragonalLattice",&obj0,&obj1)) SWIG_fail;
+  ecode1 = SWIG_AsVal_double(obj0, &val1);
+  if (!SWIG_IsOK(ecode1)) {
+    SWIG_exception_fail(SWIG_ArgError(ecode1), "in method '" "Lattice_createTetragonalLattice" "', argument " "1"" of type '" "double""'");
+  } 
+  arg1 = static_cast< double >(val1);
+  ecode2 = SWIG_AsVal_double(obj1, &val2);
+  if (!SWIG_IsOK(ecode2)) {
+    SWIG_exception_fail(SWIG_ArgError(ecode2), "in method '" "Lattice_createTetragonalLattice" "', argument " "2"" of type '" "double""'");
+  } 
+  arg2 = static_cast< double >(val2);
+  result = Lattice::createTetragonalLattice(arg1,arg2);
+  resultobj = SWIG_NewPointerObj((new Lattice(static_cast< const Lattice& >(result))), SWIGTYPE_p_Lattice, SWIG_POINTER_OWN |  0 );
+  return resultobj;
+fail:
+  return NULL;
+}
+
+
+SWIGINTERN PyObject *_wrap_Lattice_createBCTLattice(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
+  PyObject *resultobj = 0;
+  double arg1 ;
+  double arg2 ;
+  double val1 ;
+  int ecode1 = 0 ;
+  double val2 ;
+  int ecode2 = 0 ;
+  PyObject * obj0 = 0 ;
+  PyObject * obj1 = 0 ;
+  SwigValueWrapper< Lattice > result;
+  
+  if (!PyArg_ParseTuple(args,(char *)"OO:Lattice_createBCTLattice",&obj0,&obj1)) SWIG_fail;
+  ecode1 = SWIG_AsVal_double(obj0, &val1);
+  if (!SWIG_IsOK(ecode1)) {
+    SWIG_exception_fail(SWIG_ArgError(ecode1), "in method '" "Lattice_createBCTLattice" "', argument " "1"" of type '" "double""'");
+  } 
+  arg1 = static_cast< double >(val1);
+  ecode2 = SWIG_AsVal_double(obj1, &val2);
+  if (!SWIG_IsOK(ecode2)) {
+    SWIG_exception_fail(SWIG_ArgError(ecode2), "in method '" "Lattice_createBCTLattice" "', argument " "2"" of type '" "double""'");
+  } 
+  arg2 = static_cast< double >(val2);
+  result = Lattice::createBCTLattice(arg1,arg2);
+  resultobj = SWIG_NewPointerObj((new Lattice(static_cast< const Lattice& >(result))), SWIGTYPE_p_Lattice, SWIG_POINTER_OWN |  0 );
+  return resultobj;
+fail:
+  return NULL;
+}
+
+
 SWIGINTERN PyObject *_wrap_Lattice_onChange(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
   PyObject *resultobj = 0;
   Lattice *arg1 = (Lattice *) 0 ;
@@ -105004,6 +105066,49 @@ fail:
 }
 
 
+SWIGINTERN PyObject *_wrap_CreateBCTLattice(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
+  PyObject *resultobj = 0;
+  double arg1 ;
+  double arg2 ;
+  ILatticeOrientation *arg3 = 0 ;
+  double val1 ;
+  int ecode1 = 0 ;
+  double val2 ;
+  int ecode2 = 0 ;
+  void *argp3 = 0 ;
+  int res3 = 0 ;
+  PyObject * obj0 = 0 ;
+  PyObject * obj1 = 0 ;
+  PyObject * obj2 = 0 ;
+  SwigValueWrapper< Lattice > result;
+  
+  if (!PyArg_ParseTuple(args,(char *)"OOO:CreateBCTLattice",&obj0,&obj1,&obj2)) SWIG_fail;
+  ecode1 = SWIG_AsVal_double(obj0, &val1);
+  if (!SWIG_IsOK(ecode1)) {
+    SWIG_exception_fail(SWIG_ArgError(ecode1), "in method '" "CreateBCTLattice" "', argument " "1"" of type '" "double""'");
+  } 
+  arg1 = static_cast< double >(val1);
+  ecode2 = SWIG_AsVal_double(obj1, &val2);
+  if (!SWIG_IsOK(ecode2)) {
+    SWIG_exception_fail(SWIG_ArgError(ecode2), "in method '" "CreateBCTLattice" "', argument " "2"" of type '" "double""'");
+  } 
+  arg2 = static_cast< double >(val2);
+  res3 = SWIG_ConvertPtr(obj2, &argp3, SWIGTYPE_p_ILatticeOrientation,  0  | 0);
+  if (!SWIG_IsOK(res3)) {
+    SWIG_exception_fail(SWIG_ArgError(res3), "in method '" "CreateBCTLattice" "', argument " "3"" of type '" "ILatticeOrientation const &""'"); 
+  }
+  if (!argp3) {
+    SWIG_exception_fail(SWIG_ValueError, "invalid null reference " "in method '" "CreateBCTLattice" "', argument " "3"" of type '" "ILatticeOrientation const &""'"); 
+  }
+  arg3 = reinterpret_cast< ILatticeOrientation * >(argp3);
+  result = LatticeUtils::CreateBCTLattice(arg1,arg2,(ILatticeOrientation const &)*arg3);
+  resultobj = SWIG_NewPointerObj((new Lattice(static_cast< const Lattice& >(result))), SWIGTYPE_p_Lattice, SWIG_POINTER_OWN |  0 );
+  return resultobj;
+fail:
+  return NULL;
+}
+
+
 SWIGINTERN PyObject *_wrap_new_Lattice1DParameters__SWIG_0(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
   PyObject *resultobj = 0;
   Lattice1DParameters *result = 0 ;
@@ -136913,6 +137018,8 @@ static PyMethodDef SwigMethods[] = {
 	 { (char *)"Lattice_createFCCLattice", _wrap_Lattice_createFCCLattice, METH_VARARGS, (char *)"Lattice_createFCCLattice(double a) -> Lattice"},
 	 { (char *)"Lattice_createHexagonalLattice", _wrap_Lattice_createHexagonalLattice, METH_VARARGS, (char *)"Lattice_createHexagonalLattice(double a, double c) -> Lattice"},
 	 { (char *)"Lattice_createHCPLattice", _wrap_Lattice_createHCPLattice, METH_VARARGS, (char *)"Lattice_createHCPLattice(double a, double c) -> Lattice"},
+	 { (char *)"Lattice_createTetragonalLattice", _wrap_Lattice_createTetragonalLattice, METH_VARARGS, (char *)"Lattice_createTetragonalLattice(double a, double c) -> Lattice"},
+	 { (char *)"Lattice_createBCTLattice", _wrap_Lattice_createBCTLattice, METH_VARARGS, (char *)"Lattice_createBCTLattice(double a, double c) -> Lattice"},
 	 { (char *)"Lattice_onChange", _wrap_Lattice_onChange, METH_VARARGS, (char *)"\n"
 		"Lattice_onChange(Lattice self)\n"
 		"\n"
@@ -136929,6 +137036,7 @@ static PyMethodDef SwigMethods[] = {
 		"\n"
 		""},
 	 { (char *)"CreateHCPLattice", _wrap_CreateHCPLattice, METH_VARARGS, (char *)"CreateHCPLattice(double a, double c, ILatticeOrientation orientation) -> Lattice"},
+	 { (char *)"CreateBCTLattice", _wrap_CreateBCTLattice, METH_VARARGS, (char *)"CreateBCTLattice(double a, double c, ILatticeOrientation orientation) -> Lattice"},
 	 { (char *)"new_Lattice1DParameters", _wrap_new_Lattice1DParameters, METH_VARARGS, (char *)"\n"
 		"Lattice1DParameters()\n"
 		"new_Lattice1DParameters(double length, double xi) -> Lattice1DParameters\n"
-- 
GitLab