1 /*****************************************************************************
2  *   Copyright (C) 2004-2018 The pykep development team,                     *
3  *   Advanced Concepts Team (ACT), European Space Agency (ESA)               *
4  *                                                                           *
5  *   https://gitter.im/esa/pykep                                             *
6  *   https://github.com/esa/pykep                                            *
7  *                                                                           *
8  *   act@esa.int                                                             *
9  *                                                                           *
10  *   This program is free software; you can redistribute it and/or modify    *
11  *   it under the terms of the GNU General Public License as published by    *
12  *   the Free Software Foundation; either version 2 of the License, or       *
13  *   (at your option) any later version.                                     *
14  *                                                                           *
15  *   This program is distributed in the hope that it will be useful,         *
16  *   but WITHOUT ANY WARRANTY; without even the implied warranty of          *
17  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           *
18  *   GNU General Public License for more details.                            *
19  *                                                                           *
20  *   You should have received a copy of the GNU General Public License       *
21  *   along with this program; if not, write to the                           *
22  *   Free Software Foundation, Inc.,                                         *
23  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.               *
24  *****************************************************************************/
25 
26 #ifndef KEP_TOOLBOX_PYTHON_PLANET_BASE_H
27 #define KEP_TOOLBOX_PYTHON_PLANET_BASE_H
28 
29 #include <boost/python/wrapper.hpp>
30 #include <string>
31 
32 #include <keplerian_toolbox/detail/visibility.hpp>
33 #include <keplerian_toolbox/exceptions.hpp>
34 #include <keplerian_toolbox/planet/base.hpp>
35 #include <keplerian_toolbox/serialization.hpp>
36 
37 // The fact we have multiple libarries core.pyd, planet.pyd etc. makes it
38 // necessary to have this visibility rule.
39 #if defined(_WIN32) || defined(__CYGWIN__)
40 
41 #define PYKEP_DLL_PUBLIC __declspec(dllexport)
42 
43 #elif defined(__clang__) || defined(__GNUC__) || defined(__INTEL_COMPILER)
44 
45 #define PYKEP_DLL_PUBLIC __attribute__((visibility("default")))
46 
47 #endif
48 
49 namespace kep_toolbox
50 {
51 namespace planet
52 {
53 
54 // Wrapper for exporting the planet::base into python
55 class PYKEP_DLL_PUBLIC python_base : public base, public boost::python::wrapper<base>
56 {
57 public:
58     /// Same constructor as plates::base
59     python_base(double mu_central_body = 0.1, double mu_self = 0.1, double radius = 0.1, double safe_radius = 0.1,
60                 const std::string &name = "Unknown")
base(mu_central_body,mu_self,radius,safe_radius,name)61         : base(mu_central_body, mu_self, radius, safe_radius, name), boost::python::wrapper<base>()
62     {
63     }
64 
65     /// Clone pure virtual
clone()66     planet_ptr clone() const
67     {
68         planet_ptr retval = this->get_override("__get_deepcopy__")();
69         if (!retval) {
70             throw_value_error(
71                 "algorithms's __get_deepcopy__() method returns a NULL pointer, please check the implementation");
72         }
73         return retval;
74     }
75 
76     /// Human readable virtual
human_readable_extra()77     std::string human_readable_extra() const
78     {
79         if (boost::python::override f = this->get_override("human_readable_extra")) {
80 #if BOOST_WORKAROUND(BOOST_MSVC, <= 1700)
81             return boost::python::call<std::string>(this->get_override("human_readable_extra").ptr());
82 #else
83             return f();
84 #endif
85         }
86         return base::human_readable_extra();
87     }
default_human_readable_extra()88     std::string default_human_readable_extra() const
89     {
90         return this->base::human_readable_extra();
91     }
92 
93 protected:
94     /// Pure virtual ephemerides
eph_impl(double mjd2000,array3D & r,array3D & v)95     void eph_impl(double mjd2000, array3D &r, array3D &v) const
96     {
97         if (boost::python::override f = this->get_override("eph_impl")) {
98 #if BOOST_WORKAROUND(BOOST_MSVC, <= 1700)
99             boost::python::call<void>(f.ptr());
100 #else
101             f(mjd2000, r, v);
102             return;
103 #endif
104         }
105         throw_value_error("ephemerides have not been implemented!!");
106     }
107 
108 private:
109     friend class boost::serialization::access;
110     template <class Archive>
serialize(Archive & ar,const unsigned int)111     void serialize(Archive &ar, const unsigned int)
112     {
113         ar &boost::serialization::base_object<base>(*this);
114         ar &boost::serialization::base_object<boost::python::wrapper<base>>(*this);
115     }
116 };
117 }
118 } // namespaces
119 
120 BOOST_CLASS_EXPORT(kep_toolbox::planet::python_base)
121 
122 #endif
123