gen_color.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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_COLOR_H
  12. #define API_GEN_COLOR_H
  13. #include "api/api_common.h"
  14. #include "api/base_data_class.h"
  15. namespace MCell {
  16. namespace API {
  17. class Color;
  18. class PythonExportContext;
  19. #define COLOR_CTOR() \
  20. Color( \
  21. const double red_ = FLT_UNSET, \
  22. const double green_ = FLT_UNSET, \
  23. const double blue_ = FLT_UNSET, \
  24. const double alpha_ = 1, \
  25. const uint rgba_ = 0 \
  26. ) { \
  27. class_name = "Color"; \
  28. red = red_; \
  29. green = green_; \
  30. blue = blue_; \
  31. alpha = alpha_; \
  32. rgba = rgba_; \
  33. postprocess_in_ctor(); \
  34. check_semantics(); \
  35. } \
  36. Color(DefaultCtorArgType) : \
  37. GenColor(DefaultCtorArgType()) { \
  38. set_all_attributes_as_default_or_unset(); \
  39. set_all_custom_attributes_to_default(); \
  40. }
  41. class GenColor: public BaseDataClass {
  42. public:
  43. GenColor() {
  44. }
  45. GenColor(DefaultCtorArgType) {
  46. }
  47. void postprocess_in_ctor() override {}
  48. void check_semantics() const override;
  49. void set_initialized() override;
  50. void set_all_attributes_as_default_or_unset() override;
  51. std::shared_ptr<Color> copy_color() const;
  52. std::shared_ptr<Color> deepcopy_color(py::dict = py::dict()) const;
  53. virtual bool __eq__(const Color& other) const;
  54. virtual bool eq_nonarray_attributes(const Color& other, const bool ignore_name = false) const;
  55. bool operator == (const Color& other) const { return __eq__(other);}
  56. bool operator != (const Color& other) const { return !__eq__(other);}
  57. std::string to_str(const bool all_details=false, const std::string ind="") const override;
  58. std::string export_to_python(std::ostream& out, PythonExportContext& ctx) override;
  59. // --- attributes ---
  60. double red;
  61. virtual void set_red(const double new_red_) {
  62. if (initialized) {
  63. throw RuntimeError("Value 'red' of object with name " + name + " (class " + class_name + ") "
  64. "cannot be set after model was initialized.");
  65. }
  66. cached_data_are_uptodate = false;
  67. red = new_red_;
  68. }
  69. virtual double get_red() const {
  70. cached_data_are_uptodate = false; // arrays and other data can be modified through getters
  71. return red;
  72. }
  73. double green;
  74. virtual void set_green(const double new_green_) {
  75. if (initialized) {
  76. throw RuntimeError("Value 'green' of object with name " + name + " (class " + class_name + ") "
  77. "cannot be set after model was initialized.");
  78. }
  79. cached_data_are_uptodate = false;
  80. green = new_green_;
  81. }
  82. virtual double get_green() const {
  83. cached_data_are_uptodate = false; // arrays and other data can be modified through getters
  84. return green;
  85. }
  86. double blue;
  87. virtual void set_blue(const double new_blue_) {
  88. if (initialized) {
  89. throw RuntimeError("Value 'blue' of object with name " + name + " (class " + class_name + ") "
  90. "cannot be set after model was initialized.");
  91. }
  92. cached_data_are_uptodate = false;
  93. blue = new_blue_;
  94. }
  95. virtual double get_blue() const {
  96. cached_data_are_uptodate = false; // arrays and other data can be modified through getters
  97. return blue;
  98. }
  99. double alpha;
  100. virtual void set_alpha(const double new_alpha_) {
  101. if (initialized) {
  102. throw RuntimeError("Value 'alpha' of object with name " + name + " (class " + class_name + ") "
  103. "cannot be set after model was initialized.");
  104. }
  105. cached_data_are_uptodate = false;
  106. alpha = new_alpha_;
  107. }
  108. virtual double get_alpha() const {
  109. cached_data_are_uptodate = false; // arrays and other data can be modified through getters
  110. return alpha;
  111. }
  112. uint rgba;
  113. virtual void set_rgba(const uint new_rgba_) {
  114. if (initialized) {
  115. throw RuntimeError("Value 'rgba' of object with name " + name + " (class " + class_name + ") "
  116. "cannot be set after model was initialized.");
  117. }
  118. cached_data_are_uptodate = false;
  119. rgba = new_rgba_;
  120. }
  121. virtual uint get_rgba() const {
  122. cached_data_are_uptodate = false; // arrays and other data can be modified through getters
  123. return rgba;
  124. }
  125. // --- methods ---
  126. }; // GenColor
  127. class Color;
  128. py::class_<Color> define_pybinding_Color(py::module& m);
  129. } // namespace API
  130. } // namespace MCell
  131. #endif // API_GEN_COLOR_H