gen_wall_wall_hit_info.cpp 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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_wall_hit_info.h"
  15. #include "api/wall_wall_hit_info.h"
  16. #include "api/wall.h"
  17. namespace MCell {
  18. namespace API {
  19. void GenWallWallHitInfo::check_semantics() const {
  20. if (!is_set(wall1)) {
  21. throw ValueError("Parameter 'wall1' must be set.");
  22. }
  23. if (!is_set(wall2)) {
  24. throw ValueError("Parameter 'wall2' must be set.");
  25. }
  26. }
  27. void GenWallWallHitInfo::set_initialized() {
  28. if (is_set(wall1)) {
  29. wall1->set_initialized();
  30. }
  31. if (is_set(wall2)) {
  32. wall2->set_initialized();
  33. }
  34. initialized = true;
  35. }
  36. void GenWallWallHitInfo::set_all_attributes_as_default_or_unset() {
  37. class_name = "WallWallHitInfo";
  38. wall1 = nullptr;
  39. wall2 = nullptr;
  40. }
  41. std::shared_ptr<WallWallHitInfo> GenWallWallHitInfo::copy_wall_wall_hit_info() const {
  42. std::shared_ptr<WallWallHitInfo> res = std::make_shared<WallWallHitInfo>(DefaultCtorArgType());
  43. res->class_name = class_name;
  44. res->wall1 = wall1;
  45. res->wall2 = wall2;
  46. return res;
  47. }
  48. std::shared_ptr<WallWallHitInfo> GenWallWallHitInfo::deepcopy_wall_wall_hit_info(py::dict) const {
  49. std::shared_ptr<WallWallHitInfo> res = std::make_shared<WallWallHitInfo>(DefaultCtorArgType());
  50. res->class_name = class_name;
  51. res->wall1 = is_set(wall1) ? wall1->deepcopy_wall() : nullptr;
  52. res->wall2 = is_set(wall2) ? wall2->deepcopy_wall() : nullptr;
  53. return res;
  54. }
  55. bool GenWallWallHitInfo::__eq__(const WallWallHitInfo& other) const {
  56. return
  57. (
  58. (is_set(wall1)) ?
  59. (is_set(other.wall1) ?
  60. (wall1->__eq__(*other.wall1)) :
  61. false
  62. ) :
  63. (is_set(other.wall1) ?
  64. false :
  65. true
  66. )
  67. ) &&
  68. (
  69. (is_set(wall2)) ?
  70. (is_set(other.wall2) ?
  71. (wall2->__eq__(*other.wall2)) :
  72. false
  73. ) :
  74. (is_set(other.wall2) ?
  75. false :
  76. true
  77. )
  78. ) ;
  79. }
  80. bool GenWallWallHitInfo::eq_nonarray_attributes(const WallWallHitInfo& other, const bool ignore_name) const {
  81. return
  82. (
  83. (is_set(wall1)) ?
  84. (is_set(other.wall1) ?
  85. (wall1->__eq__(*other.wall1)) :
  86. false
  87. ) :
  88. (is_set(other.wall1) ?
  89. false :
  90. true
  91. )
  92. ) &&
  93. (
  94. (is_set(wall2)) ?
  95. (is_set(other.wall2) ?
  96. (wall2->__eq__(*other.wall2)) :
  97. false
  98. ) :
  99. (is_set(other.wall2) ?
  100. false :
  101. true
  102. )
  103. ) ;
  104. }
  105. std::string GenWallWallHitInfo::to_str(const bool all_details, const std::string ind) const {
  106. std::stringstream ss;
  107. ss << get_object_name() << ": " <<
  108. "\n" << ind + " " << "wall1=" << "(" << ((wall1 != nullptr) ? wall1->to_str(all_details, ind + " ") : "null" ) << ")" << ", " << "\n" << ind + " " <<
  109. "wall2=" << "(" << ((wall2 != nullptr) ? wall2->to_str(all_details, ind + " ") : "null" ) << ")";
  110. return ss.str();
  111. }
  112. py::class_<WallWallHitInfo> define_pybinding_WallWallHitInfo(py::module& m) {
  113. return py::class_<WallWallHitInfo, std::shared_ptr<WallWallHitInfo>>(m, "WallWallHitInfo", "This class is used in the return type of Model.apply_vertex_moves.\nContains pair of walls that collided.\n")
  114. .def(
  115. py::init<
  116. >()
  117. )
  118. .def("check_semantics", &WallWallHitInfo::check_semantics)
  119. .def("__copy__", &WallWallHitInfo::copy_wall_wall_hit_info)
  120. .def("__deepcopy__", &WallWallHitInfo::deepcopy_wall_wall_hit_info, py::arg("memo"))
  121. .def("__str__", &WallWallHitInfo::to_str, py::arg("all_details") = false, py::arg("ind") = std::string(""))
  122. .def("__eq__", &WallWallHitInfo::__eq__, py::arg("other"))
  123. .def("dump", &WallWallHitInfo::dump)
  124. .def_property("wall1", &WallWallHitInfo::get_wall1, &WallWallHitInfo::set_wall1, "First colliding wall.")
  125. .def_property("wall2", &WallWallHitInfo::get_wall2, &WallWallHitInfo::set_wall2, "Second colliding wall.")
  126. ;
  127. }
  128. } // namespace API
  129. } // namespace MCell