diff options
Diffstat (limited to 'OpenSim/Region/Framework/Scenes/UndoState.cs')
-rw-r--r-- | OpenSim/Region/Framework/Scenes/UndoState.cs | 219 |
1 files changed, 154 insertions, 65 deletions
diff --git a/OpenSim/Region/Framework/Scenes/UndoState.cs b/OpenSim/Region/Framework/Scenes/UndoState.cs index 55e407e..393f42d 100644 --- a/OpenSim/Region/Framework/Scenes/UndoState.cs +++ b/OpenSim/Region/Framework/Scenes/UndoState.cs | |||
@@ -25,6 +25,9 @@ | |||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | */ | 26 | */ |
27 | 27 | ||
28 | using System; | ||
29 | using System.Reflection; | ||
30 | using log4net; | ||
28 | using OpenMetaverse; | 31 | using OpenMetaverse; |
29 | using OpenSim.Region.Framework.Interfaces; | 32 | using OpenSim.Region.Framework.Interfaces; |
30 | 33 | ||
@@ -32,110 +35,199 @@ namespace OpenSim.Region.Framework.Scenes | |||
32 | { | 35 | { |
33 | public class UndoState | 36 | public class UndoState |
34 | { | 37 | { |
38 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
39 | |||
35 | public Vector3 Position = Vector3.Zero; | 40 | public Vector3 Position = Vector3.Zero; |
36 | public Vector3 Scale = Vector3.Zero; | 41 | public Vector3 Scale = Vector3.Zero; |
37 | public Quaternion Rotation = Quaternion.Identity; | 42 | public Quaternion Rotation = Quaternion.Identity; |
38 | 43 | ||
39 | public UndoState(SceneObjectPart part) | 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) | ||
40 | { | 55 | { |
41 | if (part != null) | 56 | if (part.ParentID == 0) |
42 | { | 57 | { |
43 | if (part.ParentID == 0) | 58 | ForGroup = forGroup; |
44 | { | 59 | |
60 | // if (ForGroup) | ||
45 | Position = part.ParentGroup.AbsolutePosition; | 61 | Position = part.ParentGroup.AbsolutePosition; |
46 | Rotation = part.RotationOffset; | 62 | // else |
47 | Scale = part.Shape.Scale; | 63 | // Position = part.OffsetPosition; |
48 | } | 64 | |
49 | else | 65 | // m_log.DebugFormat( |
50 | { | 66 | // "[UNDO STATE]: Storing undo position {0} for root part", Position); |
51 | Position = part.OffsetPosition; | 67 | |
52 | Rotation = part.RotationOffset; | 68 | Rotation = part.RotationOffset; |
53 | Scale = part.Shape.Scale; | 69 | |
54 | } | 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); | ||
55 | } | 91 | } |
56 | } | 92 | } |
57 | 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> | ||
58 | public bool Compare(SceneObjectPart part) | 99 | public bool Compare(SceneObjectPart part) |
59 | { | 100 | { |
60 | if (part != null) | 101 | if (part != null) |
61 | { | 102 | { |
62 | if (part.ParentID == 0) | 103 | if (part.ParentID == 0) |
63 | { | 104 | return |
64 | if (Position == part.ParentGroup.AbsolutePosition && Rotation == part.ParentGroup.Rotation) | 105 | Position == part.ParentGroup.AbsolutePosition |
65 | return true; | 106 | && Rotation == part.RotationOffset |
66 | else | 107 | && Scale == part.Shape.Scale; |
67 | return false; | ||
68 | } | ||
69 | else | 108 | else |
70 | { | 109 | return |
71 | if (Position == part.OffsetPosition && Rotation == part.RotationOffset && Scale == part.Shape.Scale) | 110 | Position == part.OffsetPosition |
72 | return true; | 111 | && Rotation == part.RotationOffset |
73 | else | 112 | && Scale == part.Shape.Scale; |
74 | return false; | ||
75 | |||
76 | } | ||
77 | } | 113 | } |
114 | |||
78 | return false; | 115 | return false; |
79 | } | 116 | } |
80 | 117 | ||
81 | public void PlaybackState(SceneObjectPart part) | 118 | public void PlaybackState(SceneObjectPart part) |
82 | { | 119 | { |
83 | if (part != null) | 120 | part.Undoing = true; |
121 | |||
122 | if (part.ParentID == 0) | ||
84 | { | 123 | { |
85 | part.Undoing = true; | 124 | // m_log.DebugFormat( |
125 | // "[UNDO STATE]: Undoing position to {0} for root part {1} {2}", | ||
126 | // Position, part.Name, part.LocalId); | ||
86 | 127 | ||
87 | if (part.ParentID == 0) | 128 | if (Position != Vector3.Zero) |
88 | { | 129 | { |
89 | if (Position != Vector3.Zero) | 130 | if (ForGroup) |
90 | part.ParentGroup.AbsolutePosition = Position; | 131 | part.ParentGroup.AbsolutePosition = Position; |
91 | part.RotationOffset = Rotation; | 132 | else |
92 | if (Scale != Vector3.Zero) | 133 | part.ParentGroup.UpdateRootPosition(Position); |
93 | part.Resize(Scale); | ||
94 | part.ParentGroup.ScheduleGroupForTerseUpdate(); | ||
95 | } | 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); | ||
96 | else | 142 | else |
143 | part.ParentGroup.UpdateRootRotation(Rotation); | ||
144 | |||
145 | if (Scale != Vector3.Zero) | ||
97 | { | 146 | { |
98 | if (Position != Vector3.Zero) | 147 | // m_log.DebugFormat( |
99 | part.OffsetPosition = Position; | 148 | // "[UNDO STATE]: Undoing scale {0} to {1} for root part {2} {3}", |
100 | part.UpdateRotation(Rotation); | 149 | // part.Shape.Scale, Scale, part.Name, part.LocalId); |
101 | if (Scale != Vector3.Zero) | 150 | |
102 | part.Resize(Scale); part.ScheduleTerseUpdate(); | 151 | if (ForGroup) |
152 | part.ParentGroup.GroupResize(Scale); | ||
153 | else | ||
154 | part.Resize(Scale); | ||
103 | } | 155 | } |
104 | part.Undoing = false; | ||
105 | 156 | ||
157 | part.ParentGroup.ScheduleGroupForTerseUpdate(); | ||
106 | } | 158 | } |
159 | else | ||
160 | { | ||
161 | if (Position != Vector3.Zero) | ||
162 | { | ||
163 | // m_log.DebugFormat( | ||
164 | // "[UNDO STATE]: Undoing position {0} to {1} for child part {2} {3}", | ||
165 | // part.OffsetPosition, Position, part.Name, part.LocalId); | ||
166 | |||
167 | part.OffsetPosition = Position; | ||
168 | } | ||
169 | |||
170 | // m_log.DebugFormat( | ||
171 | // "[UNDO STATE]: Undoing rotation {0} to {1} for child part {2} {3}", | ||
172 | // part.RotationOffset, Rotation, part.Name, part.LocalId); | ||
173 | |||
174 | part.UpdateRotation(Rotation); | ||
175 | |||
176 | if (Scale != Vector3.Zero) | ||
177 | { | ||
178 | // m_log.DebugFormat( | ||
179 | // "[UNDO STATE]: Undoing scale {0} to {1} for child part {2} {3}", | ||
180 | // part.Shape.Scale, Scale, part.Name, part.LocalId); | ||
181 | |||
182 | part.Resize(Scale); | ||
183 | } | ||
184 | |||
185 | part.ScheduleTerseUpdate(); | ||
186 | } | ||
187 | |||
188 | part.Undoing = false; | ||
107 | } | 189 | } |
190 | |||
108 | public void PlayfwdState(SceneObjectPart part) | 191 | public void PlayfwdState(SceneObjectPart part) |
109 | { | 192 | { |
110 | if (part != null) | 193 | part.Undoing = true; |
194 | |||
195 | if (part.ParentID == 0) | ||
111 | { | 196 | { |
112 | part.Undoing = true; | 197 | if (Position != Vector3.Zero) |
198 | part.ParentGroup.AbsolutePosition = Position; | ||
113 | 199 | ||
114 | if (part.ParentID == 0) | 200 | if (Rotation != Quaternion.Identity) |
115 | { | 201 | part.UpdateRotation(Rotation); |
116 | if (Position != Vector3.Zero) | 202 | |
117 | part.ParentGroup.AbsolutePosition = Position; | 203 | if (Scale != Vector3.Zero) |
118 | if (Rotation != Quaternion.Identity) | ||
119 | part.UpdateRotation(Rotation); | ||
120 | if (Scale != Vector3.Zero) | ||
121 | part.Resize(Scale); | ||
122 | part.ParentGroup.ScheduleGroupForTerseUpdate(); | ||
123 | } | ||
124 | else | ||
125 | { | 204 | { |
126 | if (Position != Vector3.Zero) | 205 | if (ForGroup) |
127 | part.OffsetPosition = Position; | 206 | part.ParentGroup.GroupResize(Scale); |
128 | if (Rotation != Quaternion.Identity) | 207 | else |
129 | part.UpdateRotation(Rotation); | ||
130 | if (Scale != Vector3.Zero) | ||
131 | part.Resize(Scale); | 208 | part.Resize(Scale); |
132 | part.ScheduleTerseUpdate(); | ||
133 | } | 209 | } |
134 | part.Undoing = false; | ||
135 | 210 | ||
211 | part.ParentGroup.ScheduleGroupForTerseUpdate(); | ||
136 | } | 212 | } |
213 | else | ||
214 | { | ||
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 | part.ScheduleTerseUpdate(); | ||
225 | } | ||
226 | |||
227 | part.Undoing = false; | ||
137 | } | 228 | } |
138 | } | 229 | } |
230 | |||
139 | public class LandUndoState | 231 | public class LandUndoState |
140 | { | 232 | { |
141 | public ITerrainModule m_terrainModule; | 233 | public ITerrainModule m_terrainModule; |
@@ -149,10 +241,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
149 | 241 | ||
150 | public bool Compare(ITerrainChannel terrainChannel) | 242 | public bool Compare(ITerrainChannel terrainChannel) |
151 | { | 243 | { |
152 | if (m_terrainChannel != terrainChannel) | 244 | return m_terrainChannel == terrainChannel; |
153 | return false; | ||
154 | else | ||
155 | return false; | ||
156 | } | 245 | } |
157 | 246 | ||
158 | public void PlaybackState() | 247 | public void PlaybackState() |
@@ -160,4 +249,4 @@ namespace OpenSim.Region.Framework.Scenes | |||
160 | m_terrainModule.UndoTerrain(m_terrainChannel); | 249 | m_terrainModule.UndoTerrain(m_terrainChannel); |
161 | } | 250 | } |
162 | } | 251 | } |
163 | } | 252 | } \ No newline at end of file |