resource.cc 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
  2. /*
  3. * resource.cc
  4. * Copyright (C) 2016 Fran??ois Gautrais <francois@gautrais.eu>
  5. *
  6. * histodex is free software: you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License as published by the
  8. * Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * histodex is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  14. * See the GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along
  17. * with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #include "resource.h"
  20. #include <cassert>
  21. Resource::Resource() : Data()
  22. {
  23. m_data_type=DATA_TYPE_RESOURCE;
  24. m_scale = Number3d(1,1,1);
  25. m_stage=0;
  26. m_type="3D";
  27. }
  28. Resource::Resource(Json::Value v) : Data(v)
  29. {
  30. m_data_type=DATA_TYPE_RESOURCE;
  31. set(v);
  32. }
  33. Resource::~Resource()
  34. {
  35. }
  36. const std::string& Resource::getName()
  37. {
  38. return m_name;
  39. }
  40. const std::string& Resource::getComments()
  41. {
  42. return m_comments;
  43. }
  44. const std::string& Resource::getType()
  45. {
  46. return m_type;
  47. }
  48. Number3d Resource::getPosition()
  49. {
  50. return m_position;
  51. }
  52. Number3d Resource::getRotation()
  53. {
  54. return m_rotation;
  55. }
  56. Number3d Resource::getScale()
  57. {
  58. return m_scale;
  59. }
  60. int Resource::getStage()
  61. {
  62. return m_stage;
  63. }
  64. void Resource::setName(const std::string& n)
  65. {
  66. m_name=n;
  67. }
  68. void Resource::setComments(const std::string& n)
  69. {
  70. m_comments=n;
  71. }
  72. void Resource::setType(const std::string& n)
  73. {
  74. m_type=n;
  75. }
  76. void Resource::setPosition(const Number3d& n)
  77. {
  78. m_position=n;
  79. }
  80. void Resource::setRotation(const Number3d& n)
  81. {
  82. m_rotation=n;
  83. }
  84. void Resource::setScale(const Number3d& n)
  85. {
  86. m_scale=n;
  87. }
  88. void Resource::setStage(int n)
  89. {
  90. m_stage=n;
  91. }
  92. const Resource& Resource::operator=(const Resource& a)
  93. {
  94. m_name=a.m_name;
  95. m_title=a.m_title;
  96. m_comments=a.m_comments;
  97. m_position=a.m_position;
  98. m_rotation=a.m_rotation;
  99. m_scale=a.m_scale;
  100. m_type=a.m_type;
  101. m_file=a.m_file;
  102. m_stage=a.m_stage;
  103. return a;
  104. }
  105. Json::Value Resource::getJson(bool genFinal)
  106. {
  107. Json::Value v(Json::objectValue);
  108. v["name"] = m_name;
  109. v["stage"] = m_stage;
  110. v["title"] = m_title;
  111. v["comment"]= m_comments;
  112. v["position"]= m_position.getJson();
  113. v["rotation"]= m_rotation.getJson();
  114. v["scale"]= m_scale.getJson();
  115. v["type"] = m_type;
  116. if(!genFinal) v["file"] = m_file;
  117. return v;
  118. }
  119. Resource& Resource::cast(Data& d)
  120. {
  121. if(d.getDataType ()!=DATA_TYPE_RESOURCE)
  122. assert(0);
  123. return (Resource&)d;
  124. }
  125. void Resource::set(Json::Value& v)
  126. {
  127. m_name = v["name"].asString();
  128. m_stage = v["stage"].asInt();
  129. m_title = v["title"].asString();
  130. m_comments = v["comment"].asString();
  131. m_position = Number3d(v["position"]);
  132. m_rotation = Number3d(v["rotation"]);
  133. m_scale = Number3d(v["scale"]);
  134. m_type = v["type"].asString();
  135. m_file = v["file"].asString();
  136. }