From: Bruno Turcksin Date: Fri, 3 Jun 2016 15:16:50 +0000 (-0400) Subject: Move PointWrapper to its own files. X-Git-Tag: v8.5.0-rc1~809^2~18 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=af2bc21844f07e2b2451ab2d13f068256aad9ba5;p=dealii.git Move PointWrapper to its own files. --- diff --git a/include/deal.II/python/point_wrapper.h b/include/deal.II/python/point_wrapper.h new file mode 100644 index 0000000000..b3f081a786 --- /dev/null +++ b/include/deal.II/python/point_wrapper.h @@ -0,0 +1,39 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2016 by the deal.II authors +// +// This file is part of the deal.II library. +// +// The deal.II library is free software; you can use it, redistribute +// it, and/or modify it under the terms of the GNU Lesser General +// Public License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// The full text of the license can be found in the file LICENSE at +// the top level of the deal.II distribution. +// +// --------------------------------------------------------------------- + +#ifndef dealii__point_wrapper_h +#define dealii__point_wrapper_h +#include + +namespace PyDealII +{ + class PointWrapper + { + public: + PointWrapper(boost::python::list list); + double get_x(); + void set_x(double x); + double get_y(); + void set_y(double y); + double get_z(); + void set_z(double z); + + private: + int dim; + std::shared_ptr point; + }; +} + +#endif diff --git a/source/python/CMakeLists.txt b/source/python/CMakeLists.txt index 886dce057e..7607ad8bec 100644 --- a/source/python/CMakeLists.txt +++ b/source/python/CMakeLists.txt @@ -23,6 +23,7 @@ SET(_src wrappers.cc export_point.cc export_triangulation.cc + point_wrapper.cc ) FILE(GLOB _header diff --git a/source/python/export_point.cc b/source/python/export_point.cc index 95b42740b3..b2f9d42cde 100644 --- a/source/python/export_point.cc +++ b/source/python/export_point.cc @@ -14,108 +14,12 @@ // --------------------------------------------------------------------- #include +#include #include #include namespace PyDealII { - class PointWrapper - { - public: - PointWrapper(boost::python::list list); - double get_x(); - void set_x(double x); - double get_y(); - void set_y(double y); - double get_z(); - void set_z(double z); - - private: - int dim; - std::shared_ptr point; - }; - - - - PointWrapper::PointWrapper(boost::python::list coord) - { - dim = boost::python::len(coord); - if (dim == 2) - point.reset(new dealii::Point<2> (boost::python::extract(coord[0]), - boost::python::extract(coord[1]))); - else if (dim == 3) - point.reset(new dealii::Point<3> (boost::python::extract(coord[0]), - boost::python::extract(coord[1]), - boost::python::extract(coord[2]))); - else - AssertThrow(false, - dealii::ExcMessage("The list of coordinates must contain two or three elements.")); - } - - - - double PointWrapper::get_x() - { - if (dim == 2) - return (*std::static_pointer_cast>(point))(0); - else - return (*std::static_pointer_cast>(point))(0); - } - - - - void PointWrapper::set_x(double x) - { - if (dim == 2) - (*std::static_pointer_cast>(point))(0) = x; - else - (*std::static_pointer_cast>(point))(0) = x; - } - - - - double PointWrapper::get_y() - { - if (dim == 2) - return (*std::static_pointer_cast>(point))(1); - else - return (*std::static_pointer_cast>(point))(1); - } - - - - void PointWrapper::set_y(double y) - { - if (dim == 2) - (*std::static_pointer_cast>(point))(1) = y; - else - (*std::static_pointer_cast>(point))(1) = y; - } - - - - double PointWrapper::get_z() - { - if (dim == 3) - return (*std::static_pointer_cast>(point))(2); - else - AssertThrow(false, - dealii::ExcMessage("The z coordinate is only available for three-dimensional points")); - } - - - - void PointWrapper::set_z(double z) - { - if (dim == 3) - (*std::static_pointer_cast>(point))(2) = z; - else - AssertThrow(false, - dealii::ExcMessage("The z coordinate is only available for three-dimensional points")); - } - - - void export_point() { boost::python::class_ ("Point",boost::python::init()) @@ -123,5 +27,4 @@ namespace PyDealII .add_property("y", &PointWrapper::get_y, &PointWrapper::set_y, "Get the y component of the point.") .add_property("z", &PointWrapper::get_z, &PointWrapper::set_z, "Get the z component of the point."); } - } diff --git a/source/python/point_wrapper.cc b/source/python/point_wrapper.cc new file mode 100644 index 0000000000..07529ac726 --- /dev/null +++ b/source/python/point_wrapper.cc @@ -0,0 +1,97 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2016 by the deal.II authors +// +// This file is part of the deal.II library. +// +// The deal.II library is free software; you can use it, redistribute +// it, and/or modify it under the terms of the GNU Lesser General +// Public License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// The full text of the license can be found in the file LICENSE at +// the top level of the deal.II distribution. +// +// --------------------------------------------------------------------- + +#include +#include + +namespace PyDealII +{ + PointWrapper::PointWrapper(boost::python::list coord) + { + dim = boost::python::len(coord); + if (dim == 2) + point.reset(new dealii::Point<2> (boost::python::extract(coord[0]), + boost::python::extract(coord[1]))); + else if (dim == 3) + point.reset(new dealii::Point<3> (boost::python::extract(coord[0]), + boost::python::extract(coord[1]), + boost::python::extract(coord[2]))); + else + AssertThrow(false, + dealii::ExcMessage("The list of coordinates must contain two or three elements.")); + } + + + + double PointWrapper::get_x() + { + if (dim == 2) + return (*std::static_pointer_cast>(point))(0); + else + return (*std::static_pointer_cast>(point))(0); + } + + + + void PointWrapper::set_x(double x) + { + if (dim == 2) + (*std::static_pointer_cast>(point))(0) = x; + else + (*std::static_pointer_cast>(point))(0) = x; + } + + + + double PointWrapper::get_y() + { + if (dim == 2) + return (*std::static_pointer_cast>(point))(1); + else + return (*std::static_pointer_cast>(point))(1); + } + + + + void PointWrapper::set_y(double y) + { + if (dim == 2) + (*std::static_pointer_cast>(point))(1) = y; + else + (*std::static_pointer_cast>(point))(1) = y; + } + + + + double PointWrapper::get_z() + { + if (dim == 3) + return (*std::static_pointer_cast>(point))(2); + else + AssertThrow(false, + dealii::ExcMessage("The z coordinate is only available for three-dimensional points")); + } + + + + void PointWrapper::set_z(double z) + { + if (dim == 3) + (*std::static_pointer_cast>(point))(2) = z; + else + AssertThrow(false, + dealii::ExcMessage("The z coordinate is only available for three-dimensional points")); + } +}