gen_surface_region.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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. #ifndef API_GEN_SURFACE_REGION_H
  12. #define API_GEN_SURFACE_REGION_H
  13. #include "api/api_common.h"
  14. #include "api/region.h"
  15. namespace MCell {
  16. namespace API {
  17. class SurfaceRegion;
  18. class Color;
  19. class InitialSurfaceRelease;
  20. class Region;
  21. class SurfaceClass;
  22. class PythonExportContext;
  23. #define SURFACE_REGION_CTOR() \
  24. SurfaceRegion( \
  25. const std::string& name_, \
  26. const std::vector<int> wall_indices_, \
  27. std::shared_ptr<SurfaceClass> surface_class_ = nullptr, \
  28. const std::vector<std::shared_ptr<InitialSurfaceRelease>> initial_surface_releases_ = std::vector<std::shared_ptr<InitialSurfaceRelease>>(), \
  29. std::shared_ptr<Color> initial_color_ = nullptr, \
  30. const RegionNodeType node_type_ = RegionNodeType::UNSET, \
  31. std::shared_ptr<Region> left_node_ = nullptr, \
  32. std::shared_ptr<Region> right_node_ = nullptr \
  33. ) : GenSurfaceRegion(node_type_,left_node_,right_node_) { \
  34. class_name = "SurfaceRegion"; \
  35. name = name_; \
  36. wall_indices = wall_indices_; \
  37. surface_class = surface_class_; \
  38. initial_surface_releases = initial_surface_releases_; \
  39. initial_color = initial_color_; \
  40. node_type = node_type_; \
  41. left_node = left_node_; \
  42. right_node = right_node_; \
  43. postprocess_in_ctor(); \
  44. check_semantics(); \
  45. } \
  46. SurfaceRegion(DefaultCtorArgType) : \
  47. GenSurfaceRegion(DefaultCtorArgType()) { \
  48. set_all_attributes_as_default_or_unset(); \
  49. set_all_custom_attributes_to_default(); \
  50. }
  51. class GenSurfaceRegion: public Region {
  52. public:
  53. GenSurfaceRegion(
  54. const RegionNodeType node_type_ = RegionNodeType::UNSET,
  55. std::shared_ptr<Region> left_node_ = nullptr,
  56. std::shared_ptr<Region> right_node_ = nullptr
  57. ) : Region(node_type_,left_node_,right_node_) {
  58. }
  59. GenSurfaceRegion(DefaultCtorArgType) {
  60. }
  61. void postprocess_in_ctor() override {}
  62. void check_semantics() const override;
  63. void set_initialized() override;
  64. void set_all_attributes_as_default_or_unset() override;
  65. std::shared_ptr<SurfaceRegion> copy_surface_region() const;
  66. std::shared_ptr<SurfaceRegion> deepcopy_surface_region(py::dict = py::dict()) const;
  67. virtual bool __eq__(const SurfaceRegion& other) const;
  68. virtual bool eq_nonarray_attributes(const SurfaceRegion& other, const bool ignore_name = false) const;
  69. bool operator == (const SurfaceRegion& other) const { return __eq__(other);}
  70. bool operator != (const SurfaceRegion& other) const { return !__eq__(other);}
  71. std::string to_str(const bool all_details=false, const std::string ind="") const override;
  72. virtual std::string export_to_python(std::ostream& out, PythonExportContext& ctx);
  73. virtual std::string export_vec_wall_indices(std::ostream& out, PythonExportContext& ctx, const std::string& parent_name);
  74. virtual std::string export_vec_initial_surface_releases(std::ostream& out, PythonExportContext& ctx, const std::string& parent_name);
  75. // --- attributes ---
  76. std::vector<int> wall_indices;
  77. virtual void set_wall_indices(const std::vector<int> new_wall_indices_) {
  78. if (initialized) {
  79. throw RuntimeError("Value 'wall_indices' of object with name " + name + " (class " + class_name + ") "
  80. "cannot be set after model was initialized.");
  81. }
  82. cached_data_are_uptodate = false;
  83. wall_indices = new_wall_indices_;
  84. }
  85. virtual std::vector<int>& get_wall_indices() {
  86. cached_data_are_uptodate = false; // arrays and other data can be modified through getters
  87. return wall_indices;
  88. }
  89. std::shared_ptr<SurfaceClass> surface_class;
  90. virtual void set_surface_class(std::shared_ptr<SurfaceClass> new_surface_class_) {
  91. if (initialized) {
  92. throw RuntimeError("Value 'surface_class' of object with name " + name + " (class " + class_name + ") "
  93. "cannot be set after model was initialized.");
  94. }
  95. cached_data_are_uptodate = false;
  96. surface_class = new_surface_class_;
  97. }
  98. virtual std::shared_ptr<SurfaceClass> get_surface_class() const {
  99. cached_data_are_uptodate = false; // arrays and other data can be modified through getters
  100. return surface_class;
  101. }
  102. std::vector<std::shared_ptr<InitialSurfaceRelease>> initial_surface_releases;
  103. virtual void set_initial_surface_releases(const std::vector<std::shared_ptr<InitialSurfaceRelease>> new_initial_surface_releases_) {
  104. if (initialized) {
  105. throw RuntimeError("Value 'initial_surface_releases' of object with name " + name + " (class " + class_name + ") "
  106. "cannot be set after model was initialized.");
  107. }
  108. cached_data_are_uptodate = false;
  109. initial_surface_releases = new_initial_surface_releases_;
  110. }
  111. virtual std::vector<std::shared_ptr<InitialSurfaceRelease>>& get_initial_surface_releases() {
  112. cached_data_are_uptodate = false; // arrays and other data can be modified through getters
  113. return initial_surface_releases;
  114. }
  115. std::shared_ptr<Color> initial_color;
  116. virtual void set_initial_color(std::shared_ptr<Color> new_initial_color_) {
  117. if (initialized) {
  118. throw RuntimeError("Value 'initial_color' of object with name " + name + " (class " + class_name + ") "
  119. "cannot be set after model was initialized.");
  120. }
  121. cached_data_are_uptodate = false;
  122. initial_color = new_initial_color_;
  123. }
  124. virtual std::shared_ptr<Color> get_initial_color() const {
  125. cached_data_are_uptodate = false; // arrays and other data can be modified through getters
  126. return initial_color;
  127. }
  128. // --- methods ---
  129. }; // GenSurfaceRegion
  130. class SurfaceRegion;
  131. py::class_<SurfaceRegion> define_pybinding_SurfaceRegion(py::module& m);
  132. } // namespace API
  133. } // namespace MCell
  134. #endif // API_GEN_SURFACE_REGION_H