gen_wall.cpp 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /******************************************************************************
  2. *
  3. * Copyright (C) 2021 by
  4. * The Salk Institute for Biological Studies
  5. *
  6. * Use of this source code is governed by an MIT-style
  7. * license that can be found in the LICENSE file or at
  8. * https://opensource.org/licenses/MIT.
  9. *
  10. ******************************************************************************/
  11. #include <sstream>
  12. #include "api/pybind11_stl_include.h"
  13. #include "api/python_export_utils.h"
  14. #include "gen_wall.h"
  15. #include "api/wall.h"
  16. #include "api/geometry_object.h"
  17. namespace MCell {
  18. namespace API {
  19. void GenWall::check_semantics() const {
  20. if (!is_set(geometry_object)) {
  21. throw ValueError("Parameter 'geometry_object' must be set.");
  22. }
  23. if (!is_set(wall_index)) {
  24. throw ValueError("Parameter 'wall_index' must be set.");
  25. }
  26. if (!is_set(vertices)) {
  27. throw ValueError("Parameter 'vertices' must be set and the value must not be an empty list.");
  28. }
  29. if (!is_set(area)) {
  30. throw ValueError("Parameter 'area' must be set.");
  31. }
  32. if (!is_set(unit_normal)) {
  33. throw ValueError("Parameter 'unit_normal' must be set and the value must not be an empty list.");
  34. }
  35. }
  36. void GenWall::set_initialized() {
  37. if (is_set(geometry_object)) {
  38. geometry_object->set_initialized();
  39. }
  40. initialized = true;
  41. }
  42. void GenWall::set_all_attributes_as_default_or_unset() {
  43. class_name = "Wall";
  44. geometry_object = nullptr;
  45. wall_index = INT_UNSET;
  46. vertices = std::vector<std::vector<double>>();
  47. area = FLT_UNSET;
  48. unit_normal = std::vector<double>();
  49. is_movable = true;
  50. }
  51. std::shared_ptr<Wall> GenWall::copy_wall() const {
  52. std::shared_ptr<Wall> res = std::make_shared<Wall>(DefaultCtorArgType());
  53. res->class_name = class_name;
  54. res->geometry_object = geometry_object;
  55. res->wall_index = wall_index;
  56. res->vertices = vertices;
  57. res->area = area;
  58. res->unit_normal = unit_normal;
  59. res->is_movable = is_movable;
  60. return res;
  61. }
  62. std::shared_ptr<Wall> GenWall::deepcopy_wall(py::dict) const {
  63. std::shared_ptr<Wall> res = std::make_shared<Wall>(DefaultCtorArgType());
  64. res->class_name = class_name;
  65. res->geometry_object = is_set(geometry_object) ? geometry_object->deepcopy_geometry_object() : nullptr;
  66. res->wall_index = wall_index;
  67. res->vertices = vertices;
  68. res->area = area;
  69. res->unit_normal = unit_normal;
  70. res->is_movable = is_movable;
  71. return res;
  72. }
  73. bool GenWall::__eq__(const Wall& other) const {
  74. return
  75. (
  76. (is_set(geometry_object)) ?
  77. (is_set(other.geometry_object) ?
  78. (geometry_object->__eq__(*other.geometry_object)) :
  79. false
  80. ) :
  81. (is_set(other.geometry_object) ?
  82. false :
  83. true
  84. )
  85. ) &&
  86. wall_index == other.wall_index &&
  87. vertices == other.vertices &&
  88. area == other.area &&
  89. unit_normal == other.unit_normal &&
  90. is_movable == other.is_movable;
  91. }
  92. bool GenWall::eq_nonarray_attributes(const Wall& other, const bool ignore_name) const {
  93. return
  94. (
  95. (is_set(geometry_object)) ?
  96. (is_set(other.geometry_object) ?
  97. (geometry_object->__eq__(*other.geometry_object)) :
  98. false
  99. ) :
  100. (is_set(other.geometry_object) ?
  101. false :
  102. true
  103. )
  104. ) &&
  105. wall_index == other.wall_index &&
  106. true /*vertices*/ &&
  107. area == other.area &&
  108. true /*unit_normal*/ &&
  109. is_movable == other.is_movable;
  110. }
  111. std::string GenWall::to_str(const bool all_details, const std::string ind) const {
  112. std::stringstream ss;
  113. ss << get_object_name() << ": " <<
  114. "\n" << ind + " " << "geometry_object=" << "(" << ((geometry_object != nullptr) ? geometry_object->to_str(all_details, ind + " ") : "null" ) << ")" << ", " << "\n" << ind + " " <<
  115. "wall_index=" << wall_index << ", " <<
  116. "vertices=" << vec_nonptr_to_str(vertices, all_details, ind + " ") << ", " <<
  117. "area=" << area << ", " <<
  118. "unit_normal=" << vec_nonptr_to_str(unit_normal, all_details, ind + " ") << ", " <<
  119. "is_movable=" << is_movable;
  120. return ss.str();
  121. }
  122. py::class_<Wall> define_pybinding_Wall(py::module& m) {
  123. return py::class_<Wall, std::shared_ptr<Wall>>(m, "Wall", "Constant representation of wall of a geometry object.\nChanges through changing attributes of this object are not allowed\nexcept for the attribute is_movable.\n")
  124. .def(
  125. py::init<
  126. >()
  127. )
  128. .def("check_semantics", &Wall::check_semantics)
  129. .def("__copy__", &Wall::copy_wall)
  130. .def("__deepcopy__", &Wall::deepcopy_wall, py::arg("memo"))
  131. .def("__str__", &Wall::to_str, py::arg("all_details") = false, py::arg("ind") = std::string(""))
  132. .def("__eq__", &Wall::__eq__, py::arg("other"))
  133. .def("dump", &Wall::dump)
  134. .def_property("geometry_object", &Wall::get_geometry_object, &Wall::set_geometry_object, "Object to which this wall belongs.")
  135. .def_property("wall_index", &Wall::get_wall_index, &Wall::set_wall_index, "Index of this wall in the object to which this wall belongs.")
  136. .def_property("vertices", &Wall::get_vertices, &Wall::set_vertices, py::return_value_policy::reference, "Vertices of the triangle that represents this wall.")
  137. .def_property("area", &Wall::get_area, &Wall::set_area, "Area of the wall in um^2.")
  138. .def_property("unit_normal", &Wall::get_unit_normal, &Wall::set_unit_normal, py::return_value_policy::reference, "Normal of this wall with unit length of 1 um.\nThere is also a method Model.get_wall_unit_normal that allows to \nretrieve just the normal value without the need to prepare this \nwhole Wall object. \n")
  139. .def_property("is_movable", &Wall::get_is_movable, &Wall::set_is_movable, "If True, whis wall can be moved through Model.apply_vertex_moves,\nif False, wall moves are ignored. \nCan be set during simulation.\n")
  140. ;
  141. }
  142. } // namespace API
  143. } // namespace MCell