PageRenderTime 32ms CodeModel.GetById 24ms app.highlight 6ms RepoModel.GetById 0ms app.codeStats 0ms

/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
 28using System.Linq;
 29using Aurora.Framework.Modules;
 30using Aurora.Framework.PresenceInfo;
 31using OpenMetaverse;
 32
 33namespace Aurora.Framework.SceneInfo
 34{
 35    public class UndoState
 36    {
 37        public Vector3 Position = Vector3.Zero;
 38        public Quaternion Rotation = Quaternion.Identity;
 39        public Vector3 Scale = Vector3.Zero;
 40
 41        public UndoState(ISceneChildEntity part)
 42        {
 43            if (part != null)
 44            {
 45                if (part.UUID == part.ParentEntity.UUID)
 46                {
 47                    Position = part.ParentEntity.AbsolutePosition;
 48                    Rotation = part.GetRotationOffset();
 49                    Scale = part.Shape.Scale;
 50                }
 51                else
 52                {
 53                    Position = part.OffsetPosition;
 54                    Rotation = part.GetRotationOffset();
 55                    Scale = part.Shape.Scale;
 56                }
 57            }
 58        }
 59
 60        public bool Compare(ISceneChildEntity part)
 61        {
 62            if (part != null)
 63            {
 64                if (part.UUID == part.ParentEntity.UUID)
 65                {
 66                    if (Position == part.AbsolutePosition && Rotation == part.GetRotationOffset() &&
 67                        Scale == part.Shape.Scale)
 68                        return true;
 69                    else
 70                        return false;
 71                }
 72                else
 73                {
 74                    if (Position == part.OffsetPosition && Rotation == part.GetRotationOffset() &&
 75                        Scale == part.Shape.Scale)
 76                        return true;
 77                    else
 78                        return false;
 79                }
 80            }
 81            return false;
 82        }
 83
 84        public void PlaybackState(ISceneChildEntity part)
 85        {
 86            if (part != null)
 87            {
 88                part.Undoing = true;
 89
 90                bool ChangedScale = false;
 91                bool ChangedRot = false;
 92                bool ChangedPos = false;
 93
 94                if (part.UUID == part.ParentEntity.UUID)
 95                {
 96                    if (Position != Vector3.Zero)
 97                    {
 98                        ChangedPos = true;
 99                        part.ParentEntity.AbsolutePosition = Position;
100                    }
101                    ChangedRot = true;
102                    part.SetRotationOffset(true, Rotation, true);
103                    if (Scale != Vector3.Zero)
104                    {
105                        ChangedScale = true;
106                        part.Scale = Scale;
107                    }
108
109                    foreach (
110                        ISceneChildEntity child in
111                            part.ParentEntity.ChildrenEntities().Where(child => child.UUID != part.UUID))
112                    {
113                        child.Undo(); //No updates here, child undo will do it on their own
114                    }
115                }
116                else
117                {
118                    if (Position != Vector3.Zero)
119                    {
120                        ChangedPos = true;
121                        part.FixOffsetPosition(Position, false);
122                    }
123                    ChangedRot = true;
124                    part.UpdateRotation(Rotation);
125                    if (Scale != Vector3.Zero)
126                    {
127                        ChangedScale = true;
128                        part.Resize(Scale);
129                    }
130                }
131                part.Undoing = false;
132                part.ScheduleUpdate((ChangedScale ? PrimUpdateFlags.Shape : PrimUpdateFlags.None) |
133                                    (ChangedPos ? PrimUpdateFlags.Position : PrimUpdateFlags.None) |
134                                    (ChangedRot ? PrimUpdateFlags.Rotation : PrimUpdateFlags.None));
135            }
136        }
137
138        public void PlayfwdState(ISceneChildEntity part)
139        {
140            if (part != null)
141            {
142                bool ChangedScale = false;
143                bool ChangedRot = false;
144                bool ChangedPos = false;
145                part.Undoing = true;
146
147                if (part.UUID == part.ParentEntity.UUID)
148                {
149                    if (Position != Vector3.Zero)
150                    {
151                        ChangedPos = true;
152                        part.ParentEntity.AbsolutePosition = Position;
153                    }
154                    if (Rotation != Quaternion.Identity)
155                    {
156                        ChangedRot = true;
157                        part.UpdateRotation(Rotation);
158                    }
159                    if (Scale != Vector3.Zero)
160                    {
161                        ChangedScale = true;
162                        part.Resize(Scale);
163                    }
164
165                    foreach (
166                        ISceneChildEntity child in
167                            part.ParentEntity.ChildrenEntities().Where(child => child.UUID != part.UUID))
168                    {
169                        child.Redo(); //No updates here, child redo will do it on their own
170                    }
171                }
172                else
173                {
174                    if (Position != Vector3.Zero)
175                    {
176                        ChangedPos = true;
177                        part.FixOffsetPosition(Position, false);
178                    }
179                    if (Rotation != Quaternion.Identity)
180                    {
181                        ChangedRot = true;
182                        part.ParentEntity.Rotation = (Rotation);
183                    }
184                    if (Scale != Vector3.Zero)
185                    {
186                        ChangedScale = true;
187                        part.Resize(Scale);
188                    }
189                }
190
191                part.ScheduleUpdate((ChangedScale ? PrimUpdateFlags.Shape : PrimUpdateFlags.None) |
192                                    (ChangedPos ? PrimUpdateFlags.Position : PrimUpdateFlags.None) |
193                                    (ChangedRot ? PrimUpdateFlags.Rotation : PrimUpdateFlags.None));
194                part.Undoing = false;
195            }
196        }
197    }
198
199    public class LandUndoState
200    {
201        public ITerrainChannel m_terrainChannel;
202        public ITerrainModule m_terrainModule;
203
204        public LandUndoState(ITerrainModule terrainModule, ITerrainChannel terrainChannel)
205        {
206            m_terrainModule = terrainModule;
207            m_terrainChannel = terrainChannel;
208        }
209
210        public bool Compare(ITerrainChannel terrainChannel)
211        {
212            if (m_terrainChannel != terrainChannel)
213                return false;
214            else
215                return false;
216        }
217
218        public void PlaybackState()
219        {
220            m_terrainModule.UndoTerrain(m_terrainChannel);
221        }
222    }
223}