/Aurora/Framework/SceneInfo/UndoState.cs

https://bitbucket.org/VirtualReality/software-testing · C# · 223 lines · 181 code · 16 blank · 26 comment · 50 complexity · a92df85b5274d0f5d981ef41801ca974 MD5 · raw file

  1. /*
  2. * Copyright (c) Contributors, http://aurora-sim.org/, http://opensimulator.org/
  3. * See CONTRIBUTORS.TXT for a full list of copyright holders.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * * Neither the name of the Aurora-Sim Project nor the
  13. * names of its contributors may be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
  17. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  18. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19. * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
  20. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  21. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  22. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  23. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  25. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. using System.Linq;
  28. using Aurora.Framework.Modules;
  29. using Aurora.Framework.PresenceInfo;
  30. using OpenMetaverse;
  31. namespace Aurora.Framework.SceneInfo
  32. {
  33. public class UndoState
  34. {
  35. public Vector3 Position = Vector3.Zero;
  36. public Quaternion Rotation = Quaternion.Identity;
  37. public Vector3 Scale = Vector3.Zero;
  38. public UndoState(ISceneChildEntity part)
  39. {
  40. if (part != null)
  41. {
  42. if (part.UUID == part.ParentEntity.UUID)
  43. {
  44. Position = part.ParentEntity.AbsolutePosition;
  45. Rotation = part.GetRotationOffset();
  46. Scale = part.Shape.Scale;
  47. }
  48. else
  49. {
  50. Position = part.OffsetPosition;
  51. Rotation = part.GetRotationOffset();
  52. Scale = part.Shape.Scale;
  53. }
  54. }
  55. }
  56. public bool Compare(ISceneChildEntity part)
  57. {
  58. if (part != null)
  59. {
  60. if (part.UUID == part.ParentEntity.UUID)
  61. {
  62. if (Position == part.AbsolutePosition && Rotation == part.GetRotationOffset() &&
  63. Scale == part.Shape.Scale)
  64. return true;
  65. else
  66. return false;
  67. }
  68. else
  69. {
  70. if (Position == part.OffsetPosition && Rotation == part.GetRotationOffset() &&
  71. Scale == part.Shape.Scale)
  72. return true;
  73. else
  74. return false;
  75. }
  76. }
  77. return false;
  78. }
  79. public void PlaybackState(ISceneChildEntity part)
  80. {
  81. if (part != null)
  82. {
  83. part.Undoing = true;
  84. bool ChangedScale = false;
  85. bool ChangedRot = false;
  86. bool ChangedPos = false;
  87. if (part.UUID == part.ParentEntity.UUID)
  88. {
  89. if (Position != Vector3.Zero)
  90. {
  91. ChangedPos = true;
  92. part.ParentEntity.AbsolutePosition = Position;
  93. }
  94. ChangedRot = true;
  95. part.SetRotationOffset(true, Rotation, true);
  96. if (Scale != Vector3.Zero)
  97. {
  98. ChangedScale = true;
  99. part.Scale = Scale;
  100. }
  101. foreach (
  102. ISceneChildEntity child in
  103. part.ParentEntity.ChildrenEntities().Where(child => child.UUID != part.UUID))
  104. {
  105. child.Undo(); //No updates here, child undo will do it on their own
  106. }
  107. }
  108. else
  109. {
  110. if (Position != Vector3.Zero)
  111. {
  112. ChangedPos = true;
  113. part.FixOffsetPosition(Position, false);
  114. }
  115. ChangedRot = true;
  116. part.UpdateRotation(Rotation);
  117. if (Scale != Vector3.Zero)
  118. {
  119. ChangedScale = true;
  120. part.Resize(Scale);
  121. }
  122. }
  123. part.Undoing = false;
  124. part.ScheduleUpdate((ChangedScale ? PrimUpdateFlags.Shape : PrimUpdateFlags.None) |
  125. (ChangedPos ? PrimUpdateFlags.Position : PrimUpdateFlags.None) |
  126. (ChangedRot ? PrimUpdateFlags.Rotation : PrimUpdateFlags.None));
  127. }
  128. }
  129. public void PlayfwdState(ISceneChildEntity part)
  130. {
  131. if (part != null)
  132. {
  133. bool ChangedScale = false;
  134. bool ChangedRot = false;
  135. bool ChangedPos = false;
  136. part.Undoing = true;
  137. if (part.UUID == part.ParentEntity.UUID)
  138. {
  139. if (Position != Vector3.Zero)
  140. {
  141. ChangedPos = true;
  142. part.ParentEntity.AbsolutePosition = Position;
  143. }
  144. if (Rotation != Quaternion.Identity)
  145. {
  146. ChangedRot = true;
  147. part.UpdateRotation(Rotation);
  148. }
  149. if (Scale != Vector3.Zero)
  150. {
  151. ChangedScale = true;
  152. part.Resize(Scale);
  153. }
  154. foreach (
  155. ISceneChildEntity child in
  156. part.ParentEntity.ChildrenEntities().Where(child => child.UUID != part.UUID))
  157. {
  158. child.Redo(); //No updates here, child redo will do it on their own
  159. }
  160. }
  161. else
  162. {
  163. if (Position != Vector3.Zero)
  164. {
  165. ChangedPos = true;
  166. part.FixOffsetPosition(Position, false);
  167. }
  168. if (Rotation != Quaternion.Identity)
  169. {
  170. ChangedRot = true;
  171. part.ParentEntity.Rotation = (Rotation);
  172. }
  173. if (Scale != Vector3.Zero)
  174. {
  175. ChangedScale = true;
  176. part.Resize(Scale);
  177. }
  178. }
  179. part.ScheduleUpdate((ChangedScale ? PrimUpdateFlags.Shape : PrimUpdateFlags.None) |
  180. (ChangedPos ? PrimUpdateFlags.Position : PrimUpdateFlags.None) |
  181. (ChangedRot ? PrimUpdateFlags.Rotation : PrimUpdateFlags.None));
  182. part.Undoing = false;
  183. }
  184. }
  185. }
  186. public class LandUndoState
  187. {
  188. public ITerrainChannel m_terrainChannel;
  189. public ITerrainModule m_terrainModule;
  190. public LandUndoState(ITerrainModule terrainModule, ITerrainChannel terrainChannel)
  191. {
  192. m_terrainModule = terrainModule;
  193. m_terrainChannel = terrainChannel;
  194. }
  195. public bool Compare(ITerrainChannel terrainChannel)
  196. {
  197. if (m_terrainChannel != terrainChannel)
  198. return false;
  199. else
  200. return false;
  201. }
  202. public void PlaybackState()
  203. {
  204. m_terrainModule.UndoTerrain(m_terrainChannel);
  205. }
  206. }
  207. }