UndoState.cs 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /*
  2. * Copyright (c) Contributors, 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 OpenSimulator 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 OpenMetaverse;
  28. using OpenSim.Region.Framework.Interfaces;
  29. namespace OpenSim.Region.Framework.Scenes
  30. {
  31. public class UndoState
  32. {
  33. public Vector3 Position = Vector3.Zero;
  34. public Vector3 Scale = Vector3.Zero;
  35. public Quaternion Rotation = Quaternion.Identity;
  36. public UndoState(SceneObjectPart part)
  37. {
  38. if (part != null)
  39. {
  40. if (part.ParentID == 0)
  41. {
  42. Position = part.ParentGroup.AbsolutePosition;
  43. Rotation = part.RotationOffset;
  44. Scale = part.Shape.Scale;
  45. }
  46. else
  47. {
  48. Position = part.OffsetPosition;
  49. Rotation = part.RotationOffset;
  50. Scale = part.Shape.Scale;
  51. }
  52. }
  53. }
  54. public bool Compare(SceneObjectPart part)
  55. {
  56. if (part != null)
  57. {
  58. if (part.ParentID == 0)
  59. {
  60. if (Position == part.ParentGroup.AbsolutePosition && Rotation == part.ParentGroup.Rotation)
  61. return true;
  62. else
  63. return false;
  64. }
  65. else
  66. {
  67. if (Position == part.OffsetPosition && Rotation == part.RotationOffset && Scale == part.Shape.Scale)
  68. return true;
  69. else
  70. return false;
  71. }
  72. }
  73. return false;
  74. }
  75. public void PlaybackState(SceneObjectPart part)
  76. {
  77. if (part != null)
  78. {
  79. part.Undoing = true;
  80. if (part.ParentID == 0)
  81. {
  82. if (Position != Vector3.Zero)
  83. part.ParentGroup.AbsolutePosition = Position;
  84. part.RotationOffset = Rotation;
  85. if (Scale != Vector3.Zero)
  86. part.Resize(Scale);
  87. part.ParentGroup.ScheduleGroupForTerseUpdate();
  88. }
  89. else
  90. {
  91. if (Position != Vector3.Zero)
  92. part.OffsetPosition = Position;
  93. part.UpdateRotation(Rotation);
  94. if (Scale != Vector3.Zero)
  95. part.Resize(Scale); part.ScheduleTerseUpdate();
  96. }
  97. part.Undoing = false;
  98. }
  99. }
  100. public void PlayfwdState(SceneObjectPart part)
  101. {
  102. if (part != null)
  103. {
  104. part.Undoing = true;
  105. if (part.ParentID == 0)
  106. {
  107. if (Position != Vector3.Zero)
  108. part.ParentGroup.AbsolutePosition = Position;
  109. if (Rotation != Quaternion.Identity)
  110. part.UpdateRotation(Rotation);
  111. if (Scale != Vector3.Zero)
  112. part.Resize(Scale);
  113. part.ParentGroup.ScheduleGroupForTerseUpdate();
  114. }
  115. else
  116. {
  117. if (Position != Vector3.Zero)
  118. part.OffsetPosition = Position;
  119. if (Rotation != Quaternion.Identity)
  120. part.UpdateRotation(Rotation);
  121. if (Scale != Vector3.Zero)
  122. part.Resize(Scale);
  123. part.ScheduleTerseUpdate();
  124. }
  125. part.Undoing = false;
  126. }
  127. }
  128. }
  129. public class LandUndoState
  130. {
  131. public ITerrainModule m_terrainModule;
  132. public ITerrainChannel m_terrainChannel;
  133. public LandUndoState(ITerrainModule terrainModule, ITerrainChannel terrainChannel)
  134. {
  135. m_terrainModule = terrainModule;
  136. m_terrainChannel = terrainChannel;
  137. }
  138. public bool Compare(ITerrainChannel terrainChannel)
  139. {
  140. if (m_terrainChannel != terrainChannel)
  141. return false;
  142. else
  143. return false;
  144. }
  145. public void PlaybackState()
  146. {
  147. m_terrainModule.UndoTerrain(m_terrainChannel);
  148. }
  149. }
  150. }