gen_viz_output.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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_VIZ_OUTPUT_H
  12. #define API_GEN_VIZ_OUTPUT_H
  13. #include "api/api_common.h"
  14. #include "api/base_data_class.h"
  15. namespace MCell {
  16. namespace API {
  17. class VizOutput;
  18. class Species;
  19. class PythonExportContext;
  20. #define VIZ_OUTPUT_CTOR() \
  21. VizOutput( \
  22. const std::string& output_files_prefix_ = STR_UNSET, \
  23. const std::vector<std::shared_ptr<Species>> species_list_ = std::vector<std::shared_ptr<Species>>(), \
  24. const VizMode mode_ = VizMode::ASCII, \
  25. const double every_n_timesteps_ = 1 \
  26. ) { \
  27. class_name = "VizOutput"; \
  28. output_files_prefix = output_files_prefix_; \
  29. species_list = species_list_; \
  30. mode = mode_; \
  31. every_n_timesteps = every_n_timesteps_; \
  32. postprocess_in_ctor(); \
  33. check_semantics(); \
  34. } \
  35. VizOutput(DefaultCtorArgType) : \
  36. GenVizOutput(DefaultCtorArgType()) { \
  37. set_all_attributes_as_default_or_unset(); \
  38. set_all_custom_attributes_to_default(); \
  39. }
  40. class GenVizOutput: public BaseDataClass {
  41. public:
  42. GenVizOutput() {
  43. }
  44. GenVizOutput(DefaultCtorArgType) {
  45. }
  46. void postprocess_in_ctor() override {}
  47. void check_semantics() const override;
  48. void set_initialized() override;
  49. void set_all_attributes_as_default_or_unset() override;
  50. std::shared_ptr<VizOutput> copy_viz_output() const;
  51. std::shared_ptr<VizOutput> deepcopy_viz_output(py::dict = py::dict()) const;
  52. virtual bool __eq__(const VizOutput& other) const;
  53. virtual bool eq_nonarray_attributes(const VizOutput& other, const bool ignore_name = false) const;
  54. bool operator == (const VizOutput& other) const { return __eq__(other);}
  55. bool operator != (const VizOutput& other) const { return !__eq__(other);}
  56. std::string to_str(const bool all_details=false, const std::string ind="") const override;
  57. std::string export_to_python(std::ostream& out, PythonExportContext& ctx) override;
  58. virtual std::string export_vec_species_list(std::ostream& out, PythonExportContext& ctx, const std::string& parent_name);
  59. // --- attributes ---
  60. std::string output_files_prefix;
  61. virtual void set_output_files_prefix(const std::string& new_output_files_prefix_) {
  62. if (initialized) {
  63. throw RuntimeError("Value 'output_files_prefix' of object with name " + name + " (class " + class_name + ") "
  64. "cannot be set after model was initialized.");
  65. }
  66. cached_data_are_uptodate = false;
  67. output_files_prefix = new_output_files_prefix_;
  68. }
  69. virtual const std::string& get_output_files_prefix() const {
  70. cached_data_are_uptodate = false; // arrays and other data can be modified through getters
  71. return output_files_prefix;
  72. }
  73. std::vector<std::shared_ptr<Species>> species_list;
  74. virtual void set_species_list(const std::vector<std::shared_ptr<Species>> new_species_list_) {
  75. if (initialized) {
  76. throw RuntimeError("Value 'species_list' of object with name " + name + " (class " + class_name + ") "
  77. "cannot be set after model was initialized.");
  78. }
  79. cached_data_are_uptodate = false;
  80. species_list = new_species_list_;
  81. }
  82. virtual std::vector<std::shared_ptr<Species>>& get_species_list() {
  83. cached_data_are_uptodate = false; // arrays and other data can be modified through getters
  84. return species_list;
  85. }
  86. VizMode mode;
  87. virtual void set_mode(const VizMode new_mode_) {
  88. if (initialized) {
  89. throw RuntimeError("Value 'mode' of object with name " + name + " (class " + class_name + ") "
  90. "cannot be set after model was initialized.");
  91. }
  92. cached_data_are_uptodate = false;
  93. mode = new_mode_;
  94. }
  95. virtual VizMode get_mode() const {
  96. cached_data_are_uptodate = false; // arrays and other data can be modified through getters
  97. return mode;
  98. }
  99. double every_n_timesteps;
  100. virtual void set_every_n_timesteps(const double new_every_n_timesteps_) {
  101. if (initialized) {
  102. throw RuntimeError("Value 'every_n_timesteps' of object with name " + name + " (class " + class_name + ") "
  103. "cannot be set after model was initialized.");
  104. }
  105. cached_data_are_uptodate = false;
  106. every_n_timesteps = new_every_n_timesteps_;
  107. }
  108. virtual double get_every_n_timesteps() const {
  109. cached_data_are_uptodate = false; // arrays and other data can be modified through getters
  110. return every_n_timesteps;
  111. }
  112. // --- methods ---
  113. }; // GenVizOutput
  114. class VizOutput;
  115. py::class_<VizOutput> define_pybinding_VizOutput(py::module& m);
  116. } // namespace API
  117. } // namespace MCell
  118. #endif // API_GEN_VIZ_OUTPUT_H