From 9f175a237fd8d95b7bdc6925871dade0f74f544d Mon Sep 17 00:00:00 2001
From: pospelov <pospelov@fz-juelich.de>
Date: Sun, 21 Jul 2013 17:35:37 +0200
Subject: [PATCH] PythonAPI is restored

---
 Core/PythonAPI/src/Beam.pypp.cpp              | 39 ++++++++++++++
 .../src/HomogeneousMaterial.pypp.cpp          | 53 +++++++++++++++++--
 Core/PythonAPI/src/IMaterial.pypp.cpp         | 44 ++++++++++++++-
 Core/PythonAPI/src/MaterialManager.pypp.cpp   |  2 +-
 .../PythonInterface_global_variables.pypp.cpp |  4 ++
 Core/Samples/inc/IMaterial.h                  |  5 --
 .../FunctionalTests/TestPyCore/isgisaxs02.py  |  2 +-
 dev-tools/python-bindings/MakePyCore.py       |  5 +-
 dev-tools/python-bindings/MakePyFit.py        |  6 +--
 shared.pri                                    |  3 +-
 10 files changed, 144 insertions(+), 19 deletions(-)

diff --git a/Core/PythonAPI/src/Beam.pypp.cpp b/Core/PythonAPI/src/Beam.pypp.cpp
index 7be8b71bcf0..b9a6fb9a58e 100644
--- a/Core/PythonAPI/src/Beam.pypp.cpp
+++ b/Core/PythonAPI/src/Beam.pypp.cpp
@@ -132,6 +132,26 @@ void register_Beam_class(){
         Beam_exposer_t Beam_exposer = Beam_exposer_t( "Beam", bp::init< >() );
         bp::scope Beam_scope( Beam_exposer );
         Beam_exposer.def( bp::init< Beam const & >(( bp::arg("other") )) );
+        { //::Beam::SetSpinUpFraction
+        
+            typedef void ( ::Beam::*SetSpinUpFraction_function_type )( double ) ;
+            
+            Beam_exposer.def( 
+                "SetSpinUpFraction"
+                , SetSpinUpFraction_function_type( &::Beam::SetSpinUpFraction )
+                , ( bp::arg("up_fraction") ) );
+        
+        }
+        { //::Beam::checkPolarization
+        
+            typedef bool ( ::Beam::*checkPolarization_function_type )( ::Eigen::Matrix2cd const & ) const;
+            
+            Beam_exposer.def( 
+                "checkPolarization"
+                , checkPolarization_function_type( &::Beam::checkPolarization )
+                , ( bp::arg("polarization") ) );
+        
+        }
         { //::Beam::getCentralK
         
             typedef ::cvector_t ( ::Beam::*getCentralK_function_type )(  ) const;
@@ -149,6 +169,15 @@ void register_Beam_class(){
                 "getIntensity"
                 , getIntensity_function_type( &::Beam::getIntensity ) );
         
+        }
+        { //::Beam::getPolarization
+        
+            typedef ::Eigen::Matrix2cd ( ::Beam::*getPolarization_function_type )(  ) const;
+            
+            Beam_exposer.def( 
+                "getPolarization"
+                , getPolarization_function_type( &::Beam::getPolarization ) );
+        
         }
         { //::Beam::operator=
         
@@ -190,6 +219,16 @@ void register_Beam_class(){
                 , setIntensity_function_type( &::Beam::setIntensity )
                 , ( bp::arg("intensity") ) );
         
+        }
+        { //::Beam::setPolarization
+        
+            typedef void ( ::Beam::*setPolarization_function_type )( ::Eigen::Matrix2cd const & ) ;
+            
+            Beam_exposer.def( 
+                "setPolarization"
+                , setPolarization_function_type( &::Beam::setPolarization )
+                , ( bp::arg("polarization") ) );
+        
         }
         { //::IParameterized::areParametersChanged
         
diff --git a/Core/PythonAPI/src/HomogeneousMaterial.pypp.cpp b/Core/PythonAPI/src/HomogeneousMaterial.pypp.cpp
index 1e01a3ee1dc..ae553a96174 100644
--- a/Core/PythonAPI/src/HomogeneousMaterial.pypp.cpp
+++ b/Core/PythonAPI/src/HomogeneousMaterial.pypp.cpp
@@ -14,14 +14,50 @@ GCC_DIAG_ON(missing-field-initializers);
 
 namespace bp = boost::python;
 
+struct HomogeneousMaterial_wrapper : HomogeneousMaterial, bp::wrapper< HomogeneousMaterial > {
+
+    HomogeneousMaterial_wrapper(HomogeneousMaterial const & arg )
+    : HomogeneousMaterial( arg )
+      , bp::wrapper< HomogeneousMaterial >(){
+        // copy constructor
+        
+    }
+
+    HomogeneousMaterial_wrapper(::std::string const & name, ::complex_t const & refractive_index )
+    : HomogeneousMaterial( name, boost::ref(refractive_index) )
+      , bp::wrapper< HomogeneousMaterial >(){
+        // constructor
+    
+    }
+
+    HomogeneousMaterial_wrapper(::std::string const & name, double refractive_index_delta, double refractive_index_beta )
+    : HomogeneousMaterial( name, refractive_index_delta, refractive_index_beta )
+      , bp::wrapper< HomogeneousMaterial >(){
+        // constructor
+    
+    }
+
+    virtual bool isScalarMaterial(  ) {
+        if( bp::override func_isScalarMaterial = this->get_override( "isScalarMaterial" ) )
+            return func_isScalarMaterial(  );
+        else{
+            return this->IMaterial::isScalarMaterial(  );
+        }
+    }
+    
+    bool default_isScalarMaterial(  ) {
+        return IMaterial::isScalarMaterial( );
+    }
+
+};
+
 void register_HomogeneousMaterial_class(){
 
     { //::HomogeneousMaterial
-        typedef bp::class_< HomogeneousMaterial, bp::bases< IMaterial > > HomogeneousMaterial_exposer_t;
+        typedef bp::class_< HomogeneousMaterial_wrapper, bp::bases< IMaterial > > HomogeneousMaterial_exposer_t;
         HomogeneousMaterial_exposer_t HomogeneousMaterial_exposer = HomogeneousMaterial_exposer_t( "HomogeneousMaterial", bp::init< std::string const &, complex_t const & >(( bp::arg("name"), bp::arg("refractive_index") )) );
         bp::scope HomogeneousMaterial_scope( HomogeneousMaterial_exposer );
-        HomogeneousMaterial_exposer.def( bp::init< std::string const &, double, double >(( bp::arg("name"), bp::arg("refractive_index_real"), bp::arg("refractive_index_imag") )) );
-        HomogeneousMaterial_exposer.def( bp::init< complex_t const & >(( bp::arg("refractive_index") )) );
+        HomogeneousMaterial_exposer.def( bp::init< std::string const &, double, double >(( bp::arg("name"), bp::arg("refractive_index_delta"), bp::arg("refractive_index_beta") )) );
         { //::HomogeneousMaterial::getRefractiveIndex
         
             typedef ::complex_t ( ::HomogeneousMaterial::*getRefractiveIndex_function_type )(  ) const;
@@ -41,6 +77,17 @@ void register_HomogeneousMaterial_class(){
                 , ( bp::arg("refractive_index") ) );
         
         }
+        { //::IMaterial::isScalarMaterial
+        
+            typedef bool ( ::IMaterial::*isScalarMaterial_function_type )(  ) ;
+            typedef bool ( HomogeneousMaterial_wrapper::*default_isScalarMaterial_function_type )(  ) ;
+            
+            HomogeneousMaterial_exposer.def( 
+                "isScalarMaterial"
+                , isScalarMaterial_function_type(&::IMaterial::isScalarMaterial)
+                , default_isScalarMaterial_function_type(&HomogeneousMaterial_wrapper::default_isScalarMaterial) );
+        
+        }
     }
 
 }
diff --git a/Core/PythonAPI/src/IMaterial.pypp.cpp b/Core/PythonAPI/src/IMaterial.pypp.cpp
index 1a1997a5f36..87c26478ab3 100644
--- a/Core/PythonAPI/src/IMaterial.pypp.cpp
+++ b/Core/PythonAPI/src/IMaterial.pypp.cpp
@@ -14,13 +14,53 @@ GCC_DIAG_ON(missing-field-initializers);
 
 namespace bp = boost::python;
 
+struct IMaterial_wrapper : IMaterial, bp::wrapper< IMaterial > {
+
+    IMaterial_wrapper(IMaterial const & arg )
+    : IMaterial( arg )
+      , bp::wrapper< IMaterial >(){
+        // copy constructor
+        
+    }
+
+    IMaterial_wrapper(::std::string const & name )
+    : IMaterial( name )
+      , bp::wrapper< IMaterial >(){
+        // constructor
+    
+    }
+
+    virtual bool isScalarMaterial(  ) {
+        if( bp::override func_isScalarMaterial = this->get_override( "isScalarMaterial" ) )
+            return func_isScalarMaterial(  );
+        else{
+            return this->IMaterial::isScalarMaterial(  );
+        }
+    }
+    
+    bool default_isScalarMaterial(  ) {
+        return IMaterial::isScalarMaterial( );
+    }
+
+};
+
 void register_IMaterial_class(){
 
     { //::IMaterial
-        typedef bp::class_< IMaterial > IMaterial_exposer_t;
+        typedef bp::class_< IMaterial_wrapper > IMaterial_exposer_t;
         IMaterial_exposer_t IMaterial_exposer = IMaterial_exposer_t( "IMaterial", bp::init< std::string const & >(( bp::arg("name") )) );
         bp::scope IMaterial_scope( IMaterial_exposer );
-        IMaterial_exposer.def( bp::init< IMaterial const & >(( bp::arg("other") )) );
+        { //::IMaterial::isScalarMaterial
+        
+            typedef bool ( ::IMaterial::*isScalarMaterial_function_type )(  ) ;
+            typedef bool ( IMaterial_wrapper::*default_isScalarMaterial_function_type )(  ) ;
+            
+            IMaterial_exposer.def( 
+                "isScalarMaterial"
+                , isScalarMaterial_function_type(&::IMaterial::isScalarMaterial)
+                , default_isScalarMaterial_function_type(&IMaterial_wrapper::default_isScalarMaterial) );
+        
+        }
     }
 
 }
diff --git a/Core/PythonAPI/src/MaterialManager.pypp.cpp b/Core/PythonAPI/src/MaterialManager.pypp.cpp
index 6fb93d93363..945dc8ba821 100644
--- a/Core/PythonAPI/src/MaterialManager.pypp.cpp
+++ b/Core/PythonAPI/src/MaterialManager.pypp.cpp
@@ -48,7 +48,7 @@ void register_MaterialManager_class(){
             MaterialManager_exposer.def( 
                 "getHomogeneousMaterial"
                 , getHomogeneousMaterial_function_type( &::MaterialManager::getHomogeneousMaterial )
-                , ( bp::arg("name"), bp::arg("refractive_index_real"), bp::arg("refractive_index_imag") )
+                , ( bp::arg("name"), bp::arg("refractive_index_delta"), bp::arg("refractive_index_beta") )
                 , bp::return_value_policy< bp::reference_existing_object >() );
         
         }
diff --git a/Core/PythonAPI/src/PythonInterface_global_variables.pypp.cpp b/Core/PythonAPI/src/PythonInterface_global_variables.pypp.cpp
index 5d1add1c371..8342a29e628 100644
--- a/Core/PythonAPI/src/PythonInterface_global_variables.pypp.cpp
+++ b/Core/PythonAPI/src/PythonInterface_global_variables.pypp.cpp
@@ -30,6 +30,8 @@ void register_global_variables(){
 
     bp::scope().attr("degree") = Units::degree;
 
+    bp::scope().attr("gauss") = Units::gauss;
+
     bp::scope().attr("meter") = Units::meter;
 
     bp::scope().attr("micrometer") = Units::micrometer;
@@ -52,4 +54,6 @@ void register_global_variables(){
 
     bp::scope().attr("steradian") = Units::steradian;
 
+    bp::scope().attr("tesla") = Units::tesla;
+
 }
diff --git a/Core/Samples/inc/IMaterial.h b/Core/Samples/inc/IMaterial.h
index 883c734a2d6..88a1e84eb83 100644
--- a/Core/Samples/inc/IMaterial.h
+++ b/Core/Samples/inc/IMaterial.h
@@ -18,7 +18,6 @@
 
 #include <string>
 #include <iostream>
-//#include <typeinfo>
 #include "INamed.h"
 
 //! Interface to a named material.
@@ -29,9 +28,6 @@ class IMaterial : public INamed
     //! Constructor that sets _name_.
     explicit IMaterial(const std::string& name) : INamed(name) {}
 
-    //! Copy constructor. TODO: test whether needed
-    IMaterial(const IMaterial& other) : INamed(other) {}
-
     //! Destructor.
     virtual ~IMaterial() {}
 
@@ -46,7 +42,6 @@ class IMaterial : public INamed
  protected:
     virtual void print(std::ostream& ostr) const
     { ostr << "IMat:" << getName() << "<" << this << ">"; }
-        // TODO: try ostr << typeid(*this).name() << " " << this;
 };
 
 #endif // IMATERIAL_H
diff --git a/Tests/FunctionalTests/TestPyCore/isgisaxs02.py b/Tests/FunctionalTests/TestPyCore/isgisaxs02.py
index a12939931ac..a6db44bb9e4 100644
--- a/Tests/FunctionalTests/TestPyCore/isgisaxs02.py
+++ b/Tests/FunctionalTests/TestPyCore/isgisaxs02.py
@@ -19,7 +19,7 @@ def RunSimulation():
     # defining materials
     mAmbience = MaterialManager.getHomogeneousMaterial("Air", 0.0, 0.0 )
     # collection of particles
-    n_particle = complex(6e-4, 2e-8)
+    n_particle = complex(1.0 - 6e-4, 2e-8)
     radius1 = 5.0*nanometer
     radius2 = 10.0*nanometer
     height1 = radius1
diff --git a/dev-tools/python-bindings/MakePyCore.py b/dev-tools/python-bindings/MakePyCore.py
index 29095b0af1a..a1f51c606f4 100644
--- a/dev-tools/python-bindings/MakePyCore.py
+++ b/dev-tools/python-bindings/MakePyCore.py
@@ -26,7 +26,8 @@ include_dirs = [
     '../../Core/Algorithms/inc',
     '../../Core/Tools/inc',
     '../../Core/PythonAPI/inc',
-    '../../Core/Geometry/inc'
+    '../../Core/Geometry/inc',
+    '../../ThirdParty/eigen3'
 ]
 
 include_classes = [
@@ -250,7 +251,7 @@ def MakePythonAPI(OutputTempDir):
     print "NOTE: If you update the source library code you need to manually delete the cache_core.xml file, or run 'python codegenerator.py clean'"
     xml_cached_fc = parser.create_cached_source_fc( "PythonCoreList.h", "cache_core.xml" )
     #xml_cached_fc = parser.create_cached_source_fc( ["PythonCoreList.h","PythonCoreExposer.h"], "cache_core.xml" )
-    mb = module_builder.module_builder_t( [xml_cached_fc], include_paths=include_dirs, gccxml_path=mygccxml, cflags="-m64")
+    mb = module_builder.module_builder_t( [xml_cached_fc], include_paths=include_dirs, gccxml_path=mygccxml, cflags="-m64 -msse -msse2 -fno-strict-aliasing -msse3")
 
     # -----------------
     # general rules
diff --git a/dev-tools/python-bindings/MakePyFit.py b/dev-tools/python-bindings/MakePyFit.py
index 3329d9da217..b765bb90253 100644
--- a/dev-tools/python-bindings/MakePyFit.py
+++ b/dev-tools/python-bindings/MakePyFit.py
@@ -25,9 +25,9 @@ include_dirs = [
 '../../Core/Algorithms/inc',
 '../../Core/Tools/inc',
 '../../Core/Geometry/inc',
-'../../Core/Fitting/inc',
 '../../Fit/Factory/inc',
-'../../Fit/PythonAPI/inc'
+'../../Fit/PythonAPI/inc',
+'../../ThirdParty/eigen3',
 ]
 
 include_classes = [
@@ -100,7 +100,7 @@ def MakePythonAPI(OutputTempDir):
     #If the cache file cache_core.xml doesn't exist it gets created, otherwise it just gets loaded
     print "NOTE: If you update the source library code you need to manually delete the cache_fit.xml file, or run 'python codegenerator.py clean'"
     xml_cached_fc = parser.create_cached_source_fc( "PythonFitList.h", "cache_fit.xml" )
-    mb = module_builder.module_builder_t( [xml_cached_fc], include_paths=include_dirs, gccxml_path=mygccxml, cflags="-m64")
+    mb = module_builder.module_builder_t( [xml_cached_fc], include_paths=include_dirs, gccxml_path=mygccxml, cflags="-m64 -msse3")
 
     # -----------------
     # general rules
diff --git a/shared.pri b/shared.pri
index 472e551b2d7..4df3f5c229d 100644
--- a/shared.pri
+++ b/shared.pri
@@ -2,8 +2,7 @@
 # Common settings for all BornAgain compilations
 # -----------------------------------------------------------------------------
 
-#CONFIG  += BORNAGAIN_PYTHON # provide python bindings compilation
-
+CONFIG  += BORNAGAIN_PYTHON # provide python bindings compilation
 
 win32 {
     MAKE_COMMAND = mingw32-make
-- 
GitLab