gen_geometry_object.h 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  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_GEOMETRY_OBJECT_H
  12. #define API_GEN_GEOMETRY_OBJECT_H
  13. #include "api/api_common.h"
  14. #include "api/region.h"
  15. namespace MCell {
  16. namespace API {
  17. class GeometryObject;
  18. class Color;
  19. class InitialSurfaceRelease;
  20. class Region;
  21. class SurfaceClass;
  22. class SurfaceRegion;
  23. class PythonExportContext;
  24. #define GEOMETRY_OBJECT_CTOR() \
  25. GeometryObject( \
  26. const std::string& name_, \
  27. const std::vector<std::vector<double>> vertex_list_, \
  28. const std::vector<std::vector<int>> wall_list_, \
  29. const bool is_bngl_compartment_ = false, \
  30. const std::string& surface_compartment_name_ = STR_UNSET, \
  31. const std::vector<std::shared_ptr<SurfaceRegion>> surface_regions_ = std::vector<std::shared_ptr<SurfaceRegion>>(), \
  32. std::shared_ptr<SurfaceClass> surface_class_ = nullptr, \
  33. const std::vector<std::shared_ptr<InitialSurfaceRelease>> initial_surface_releases_ = std::vector<std::shared_ptr<InitialSurfaceRelease>>(), \
  34. std::shared_ptr<Color> initial_color_ = nullptr, \
  35. const RegionNodeType node_type_ = RegionNodeType::UNSET, \
  36. std::shared_ptr<Region> left_node_ = nullptr, \
  37. std::shared_ptr<Region> right_node_ = nullptr \
  38. ) : GenGeometryObject(node_type_,left_node_,right_node_) { \
  39. class_name = "GeometryObject"; \
  40. name = name_; \
  41. vertex_list = vertex_list_; \
  42. wall_list = wall_list_; \
  43. is_bngl_compartment = is_bngl_compartment_; \
  44. surface_compartment_name = surface_compartment_name_; \
  45. surface_regions = surface_regions_; \
  46. surface_class = surface_class_; \
  47. initial_surface_releases = initial_surface_releases_; \
  48. initial_color = initial_color_; \
  49. node_type = node_type_; \
  50. left_node = left_node_; \
  51. right_node = right_node_; \
  52. postprocess_in_ctor(); \
  53. check_semantics(); \
  54. } \
  55. GeometryObject(DefaultCtorArgType) : \
  56. GenGeometryObject(DefaultCtorArgType()) { \
  57. set_all_attributes_as_default_or_unset(); \
  58. set_all_custom_attributes_to_default(); \
  59. }
  60. class GenGeometryObject: public Region {
  61. public:
  62. GenGeometryObject(
  63. const RegionNodeType node_type_ = RegionNodeType::UNSET,
  64. std::shared_ptr<Region> left_node_ = nullptr,
  65. std::shared_ptr<Region> right_node_ = nullptr
  66. ) : Region(node_type_,left_node_,right_node_) {
  67. }
  68. GenGeometryObject(DefaultCtorArgType) {
  69. }
  70. void postprocess_in_ctor() override {}
  71. void check_semantics() const override;
  72. void set_initialized() override;
  73. void set_all_attributes_as_default_or_unset() override;
  74. std::shared_ptr<GeometryObject> copy_geometry_object() const;
  75. std::shared_ptr<GeometryObject> deepcopy_geometry_object(py::dict = py::dict()) const;
  76. virtual bool __eq__(const GeometryObject& other) const;
  77. virtual bool eq_nonarray_attributes(const GeometryObject& other, const bool ignore_name = false) const;
  78. bool operator == (const GeometryObject& other) const { return __eq__(other);}
  79. bool operator != (const GeometryObject& other) const { return !__eq__(other);}
  80. std::string to_str(const bool all_details=false, const std::string ind="") const override;
  81. virtual std::string export_to_python(std::ostream& out, PythonExportContext& ctx);
  82. virtual std::string export_vec_vertex_list(std::ostream& out, PythonExportContext& ctx, const std::string& parent_name);
  83. virtual std::string export_vec_wall_list(std::ostream& out, PythonExportContext& ctx, const std::string& parent_name);
  84. virtual std::string export_vec_surface_regions(std::ostream& out, PythonExportContext& ctx, const std::string& parent_name);
  85. virtual std::string export_vec_initial_surface_releases(std::ostream& out, PythonExportContext& ctx, const std::string& parent_name);
  86. // --- attributes ---
  87. std::vector<std::vector<double>> vertex_list;
  88. virtual void set_vertex_list(const std::vector<std::vector<double>> new_vertex_list_) {
  89. if (initialized) {
  90. throw RuntimeError("Value 'vertex_list' of object with name " + name + " (class " + class_name + ") "
  91. "cannot be set after model was initialized.");
  92. }
  93. cached_data_are_uptodate = false;
  94. vertex_list = new_vertex_list_;
  95. }
  96. virtual std::vector<std::vector<double>>& get_vertex_list() {
  97. cached_data_are_uptodate = false; // arrays and other data can be modified through getters
  98. return vertex_list;
  99. }
  100. std::vector<std::vector<int>> wall_list;
  101. virtual void set_wall_list(const std::vector<std::vector<int>> new_wall_list_) {
  102. if (initialized) {
  103. throw RuntimeError("Value 'wall_list' of object with name " + name + " (class " + class_name + ") "
  104. "cannot be set after model was initialized.");
  105. }
  106. cached_data_are_uptodate = false;
  107. wall_list = new_wall_list_;
  108. }
  109. virtual std::vector<std::vector<int>>& get_wall_list() {
  110. cached_data_are_uptodate = false; // arrays and other data can be modified through getters
  111. return wall_list;
  112. }
  113. bool is_bngl_compartment;
  114. virtual void set_is_bngl_compartment(const bool new_is_bngl_compartment_) {
  115. if (initialized) {
  116. throw RuntimeError("Value 'is_bngl_compartment' of object with name " + name + " (class " + class_name + ") "
  117. "cannot be set after model was initialized.");
  118. }
  119. cached_data_are_uptodate = false;
  120. is_bngl_compartment = new_is_bngl_compartment_;
  121. }
  122. virtual bool get_is_bngl_compartment() const {
  123. cached_data_are_uptodate = false; // arrays and other data can be modified through getters
  124. return is_bngl_compartment;
  125. }
  126. std::string surface_compartment_name;
  127. virtual void set_surface_compartment_name(const std::string& new_surface_compartment_name_) {
  128. if (initialized) {
  129. throw RuntimeError("Value 'surface_compartment_name' of object with name " + name + " (class " + class_name + ") "
  130. "cannot be set after model was initialized.");
  131. }
  132. cached_data_are_uptodate = false;
  133. surface_compartment_name = new_surface_compartment_name_;
  134. }
  135. virtual const std::string& get_surface_compartment_name() const {
  136. cached_data_are_uptodate = false; // arrays and other data can be modified through getters
  137. return surface_compartment_name;
  138. }
  139. std::vector<std::shared_ptr<SurfaceRegion>> surface_regions;
  140. virtual void set_surface_regions(const std::vector<std::shared_ptr<SurfaceRegion>> new_surface_regions_) {
  141. if (initialized) {
  142. throw RuntimeError("Value 'surface_regions' of object with name " + name + " (class " + class_name + ") "
  143. "cannot be set after model was initialized.");
  144. }
  145. cached_data_are_uptodate = false;
  146. surface_regions = new_surface_regions_;
  147. }
  148. virtual std::vector<std::shared_ptr<SurfaceRegion>>& get_surface_regions() {
  149. cached_data_are_uptodate = false; // arrays and other data can be modified through getters
  150. return surface_regions;
  151. }
  152. std::shared_ptr<SurfaceClass> surface_class;
  153. virtual void set_surface_class(std::shared_ptr<SurfaceClass> new_surface_class_) {
  154. if (initialized) {
  155. throw RuntimeError("Value 'surface_class' of object with name " + name + " (class " + class_name + ") "
  156. "cannot be set after model was initialized.");
  157. }
  158. cached_data_are_uptodate = false;
  159. surface_class = new_surface_class_;
  160. }
  161. virtual std::shared_ptr<SurfaceClass> get_surface_class() const {
  162. cached_data_are_uptodate = false; // arrays and other data can be modified through getters
  163. return surface_class;
  164. }
  165. std::vector<std::shared_ptr<InitialSurfaceRelease>> initial_surface_releases;
  166. virtual void set_initial_surface_releases(const std::vector<std::shared_ptr<InitialSurfaceRelease>> new_initial_surface_releases_) {
  167. if (initialized) {
  168. throw RuntimeError("Value 'initial_surface_releases' of object with name " + name + " (class " + class_name + ") "
  169. "cannot be set after model was initialized.");
  170. }
  171. cached_data_are_uptodate = false;
  172. initial_surface_releases = new_initial_surface_releases_;
  173. }
  174. virtual std::vector<std::shared_ptr<InitialSurfaceRelease>>& get_initial_surface_releases() {
  175. cached_data_are_uptodate = false; // arrays and other data can be modified through getters
  176. return initial_surface_releases;
  177. }
  178. std::shared_ptr<Color> initial_color;
  179. virtual void set_initial_color(std::shared_ptr<Color> new_initial_color_) {
  180. if (initialized) {
  181. throw RuntimeError("Value 'initial_color' of object with name " + name + " (class " + class_name + ") "
  182. "cannot be set after model was initialized.");
  183. }
  184. cached_data_are_uptodate = false;
  185. initial_color = new_initial_color_;
  186. }
  187. virtual std::shared_ptr<Color> get_initial_color() const {
  188. cached_data_are_uptodate = false; // arrays and other data can be modified through getters
  189. return initial_color;
  190. }
  191. // --- methods ---
  192. virtual void translate(const std::vector<double> move) = 0;
  193. }; // GenGeometryObject
  194. class GeometryObject;
  195. py::class_<GeometryObject> define_pybinding_GeometryObject(py::module& m);
  196. } // namespace API
  197. } // namespace MCell
  198. #endif // API_GEN_GEOMETRY_OBJECT_H