aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Framework/Scenes/UndoState.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/Framework/Scenes/UndoState.cs')
-rw-r--r--OpenSim/Region/Framework/Scenes/UndoState.cs250
1 files changed, 250 insertions, 0 deletions
diff --git a/OpenSim/Region/Framework/Scenes/UndoState.cs b/OpenSim/Region/Framework/Scenes/UndoState.cs
new file mode 100644
index 0000000..860172c
--- /dev/null
+++ b/OpenSim/Region/Framework/Scenes/UndoState.cs
@@ -0,0 +1,250 @@
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
28using System;
29using System.Reflection;
30using log4net;
31using OpenMetaverse;
32using OpenSim.Region.Framework.Interfaces;
33
34namespace OpenSim.Region.Framework.Scenes
35{
36 public class UndoState
37 {
38// private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
39
40 public Vector3 Position = Vector3.Zero;
41 public Vector3 Scale = Vector3.Zero;
42 public Quaternion Rotation = Quaternion.Identity;
43
44 /// <summary>
45 /// Is this undo state for an entire group?
46 /// </summary>
47 public bool ForGroup;
48
49 /// <summary>
50 /// Constructor.
51 /// </summary>
52 /// <param name="part"></param>
53 /// <param name="forGroup">True if the undo is for an entire group</param>
54 public UndoState(SceneObjectPart part, bool forGroup)
55 {
56 if (part.ParentID == 0)
57 {
58 ForGroup = forGroup;
59
60// if (ForGroup)
61 Position = part.ParentGroup.AbsolutePosition;
62// else
63// Position = part.OffsetPosition;
64
65// m_log.DebugFormat(
66// "[UNDO STATE]: Storing undo position {0} for root part", Position);
67
68 Rotation = part.RotationOffset;
69
70// m_log.DebugFormat(
71// "[UNDO STATE]: Storing undo rotation {0} for root part", Rotation);
72
73 Scale = part.Shape.Scale;
74
75// m_log.DebugFormat(
76// "[UNDO STATE]: Storing undo scale {0} for root part", Scale);
77 }
78 else
79 {
80 Position = part.OffsetPosition;
81// m_log.DebugFormat(
82// "[UNDO STATE]: Storing undo position {0} for child part", Position);
83
84 Rotation = part.RotationOffset;
85// m_log.DebugFormat(
86// "[UNDO STATE]: Storing undo rotation {0} for child part", Rotation);
87
88 Scale = part.Shape.Scale;
89// m_log.DebugFormat(
90// "[UNDO STATE]: Storing undo scale {0} for child part", Scale);
91 }
92 }
93
94 /// <summary>
95 /// Compare the relevant state in the given part to this state.
96 /// </summary>
97 /// <param name="part"></param>
98 /// <returns>true if both the part's position, rotation and scale match those in this undo state. False otherwise.</returns>
99 public bool Compare(SceneObjectPart part)
100 {
101 if (part != null)
102 {
103 if (part.ParentID == 0)
104 return
105 Position == part.ParentGroup.AbsolutePosition
106 && Rotation == part.RotationOffset
107 && Scale == part.Shape.Scale;
108 else
109 return
110 Position == part.OffsetPosition
111 && Rotation == part.RotationOffset
112 && Scale == part.Shape.Scale;
113 }
114
115 return false;
116 }
117
118 public void PlaybackState(SceneObjectPart part)
119 {
120 part.Undoing = true;
121
122 if (part.ParentID == 0)
123 {
124// m_log.DebugFormat(
125// "[UNDO STATE]: Undoing position to {0} for root part {1} {2}",
126// Position, part.Name, part.LocalId);
127
128 if (Position != Vector3.Zero)
129 {
130 if (ForGroup)
131 part.ParentGroup.AbsolutePosition = Position;
132 else
133 part.ParentGroup.UpdateRootPosition(Position);
134 }
135
136// m_log.DebugFormat(
137// "[UNDO STATE]: Undoing rotation {0} to {1} for root part {2} {3}",
138// part.RotationOffset, Rotation, part.Name, part.LocalId);
139
140 if (ForGroup)
141 part.UpdateRotation(Rotation);
142 else
143 part.ParentGroup.UpdateRootRotation(Rotation);
144
145 if (Scale != Vector3.Zero)
146 {
147// m_log.DebugFormat(
148// "[UNDO STATE]: Undoing scale {0} to {1} for root part {2} {3}",
149// part.Shape.Scale, Scale, part.Name, part.LocalId);
150
151 if (ForGroup)
152 part.ParentGroup.GroupResize(Scale);
153 else
154 part.Resize(Scale);
155 }
156
157 part.ParentGroup.ScheduleGroupForTerseUpdate();
158 }
159 else
160 {
161 // Note: Updating these properties on sop automatically schedules an update if needed
162 if (Position != Vector3.Zero)
163 {
164// m_log.DebugFormat(
165// "[UNDO STATE]: Undoing position {0} to {1} for child part {2} {3}",
166// part.OffsetPosition, Position, part.Name, part.LocalId);
167
168 part.OffsetPosition = Position;
169 }
170
171// m_log.DebugFormat(
172// "[UNDO STATE]: Undoing rotation {0} to {1} for child part {2} {3}",
173// part.RotationOffset, Rotation, part.Name, part.LocalId);
174
175 part.UpdateRotation(Rotation);
176
177 if (Scale != Vector3.Zero)
178 {
179// m_log.DebugFormat(
180// "[UNDO STATE]: Undoing scale {0} to {1} for child part {2} {3}",
181// part.Shape.Scale, Scale, part.Name, part.LocalId);
182
183 part.Resize(Scale);
184 }
185 }
186
187 part.Undoing = false;
188 }
189
190 public void PlayfwdState(SceneObjectPart part)
191 {
192 part.Undoing = true;
193
194 if (part.ParentID == 0)
195 {
196 if (Position != Vector3.Zero)
197 part.ParentGroup.AbsolutePosition = Position;
198
199 if (Rotation != Quaternion.Identity)
200 part.UpdateRotation(Rotation);
201
202 if (Scale != Vector3.Zero)
203 {
204 if (ForGroup)
205 part.ParentGroup.GroupResize(Scale);
206 else
207 part.Resize(Scale);
208 }
209
210 part.ParentGroup.ScheduleGroupForTerseUpdate();
211 }
212 else
213 {
214 // Note: Updating these properties on sop automatically schedules an update if needed
215 if (Position != Vector3.Zero)
216 part.OffsetPosition = Position;
217
218 if (Rotation != Quaternion.Identity)
219 part.UpdateRotation(Rotation);
220
221 if (Scale != Vector3.Zero)
222 part.Resize(Scale);
223 }
224
225 part.Undoing = false;
226 }
227 }
228
229 public class LandUndoState
230 {
231 public ITerrainModule m_terrainModule;
232 public ITerrainChannel m_terrainChannel;
233
234 public LandUndoState(ITerrainModule terrainModule, ITerrainChannel terrainChannel)
235 {
236 m_terrainModule = terrainModule;
237 m_terrainChannel = terrainChannel;
238 }
239
240 public bool Compare(ITerrainChannel terrainChannel)
241 {
242 return m_terrainChannel == terrainChannel;
243 }
244
245 public void PlaybackState()
246 {
247 m_terrainModule.UndoTerrain(m_terrainChannel);
248 }
249 }
250} \ No newline at end of file