SceneEditOp.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. //
  2. // Copyright (c) 2014-2016 THUNDERBEAST GAMES LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to deal
  6. // in the Software without restriction, including without limitation the rights
  7. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. // copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. // THE SOFTWARE.
  21. //
  22. #pragma once
  23. #include <Atomic/Core/Object.h>
  24. #include <Atomic/IO/VectorBuffer.h>
  25. namespace Atomic
  26. {
  27. class Node;
  28. class Component;
  29. }
  30. using namespace Atomic;
  31. namespace AtomicEditor
  32. {
  33. enum SceneEditType
  34. {
  35. SCENEEDIT_UNKNOWN = 0,
  36. SCENEEDIT_SELECTION
  37. };
  38. class SceneEditOp
  39. {
  40. public:
  41. SceneEditOp(Scene* scene, SceneEditType type) { type_ = type; scene_ = scene;}
  42. virtual ~SceneEditOp() { }
  43. virtual bool Undo() = 0;
  44. virtual bool Redo() = 0;
  45. /// Returns true if the states are identical
  46. bool CompareStates(const VectorBuffer& stateOne, const VectorBuffer& stateTwo) const
  47. {
  48. if (stateOne.GetSize() != stateTwo.GetSize())
  49. return false;
  50. if (memcmp(stateOne.GetData(), stateTwo.GetData(), stateOne.GetSize()))
  51. return false;
  52. return true;
  53. }
  54. SharedPtr<Scene> scene_;
  55. SceneEditType type_;
  56. };
  57. class SelectionEditOp : public SceneEditOp
  58. {
  59. public:
  60. SelectionEditOp(Scene* scene);
  61. ~SelectionEditOp();
  62. bool Undo();
  63. bool Redo();
  64. void RegisterEdit();
  65. void SetNodes(Vector<SharedPtr<Node>>& nodes);
  66. void AddNode(Node* node);
  67. void NodeAdded(Node* node, Node* parent);
  68. void NodeRemoved(Node* node, Node* parent);
  69. // Erases a node from the edit op, return true if no other nodes in the operation
  70. bool EraseNode(Node *node);
  71. bool Commit();
  72. private:
  73. struct EditComponent
  74. {
  75. SharedPtr<Component> component_;
  76. SharedPtr<Node> nodeBegin_;
  77. SharedPtr<Node> nodeEnd_;
  78. VectorBuffer stateBegin_;
  79. VectorBuffer stateEnd_;
  80. };
  81. struct EditNode
  82. {
  83. SharedPtr<Node> node_;
  84. SharedPtr<Node> parentBegin_;
  85. SharedPtr<Node> parentEnd_;
  86. VectorBuffer stateBegin_;
  87. VectorBuffer stateEnd_;
  88. PODVector<EditComponent*> components_;
  89. };
  90. PODVector<EditNode*> editNodes_;
  91. };
  92. }