aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Framework/Scenes/Serialization/CoalescedSceneObjectsSerializer.cs
diff options
context:
space:
mode:
authorJustin Clark-Casey (justincc)2011-04-13 21:17:43 +0100
committerJustin Clark-Casey (justincc)2011-04-13 21:17:43 +0100
commit58efd761d13bd4f2617fcb3f94bbe265880589e3 (patch)
tree4900fbec5e577c48b42efeb10115fd64dc47681b /OpenSim/Region/Framework/Scenes/Serialization/CoalescedSceneObjectsSerializer.cs
parentfactor out some test code into the SetUp() (diff)
downloadopensim-SC_OLD-58efd761d13bd4f2617fcb3f94bbe265880589e3.zip
opensim-SC_OLD-58efd761d13bd4f2617fcb3f94bbe265880589e3.tar.gz
opensim-SC_OLD-58efd761d13bd4f2617fcb3f94bbe265880589e3.tar.bz2
opensim-SC_OLD-58efd761d13bd4f2617fcb3f94bbe265880589e3.tar.xz
Add coalesced scene objects class and serializer. This is currently only used by the TestRezCoalescedObject() regression test.
This structure matches the existing one for SceneObjects and will allow code to be reused by the uuid gatherer, other tests, etc. Test is not yet fully implemented due to a bug in rezzing coalesced objects where they all get the same name as the item. Only one object should get the same name as the item, which appears to be the one selected last when the the objects were coalesced in the first place. This bug will be addressed shortly.
Diffstat (limited to 'OpenSim/Region/Framework/Scenes/Serialization/CoalescedSceneObjectsSerializer.cs')
-rw-r--r--OpenSim/Region/Framework/Scenes/Serialization/CoalescedSceneObjectsSerializer.cs117
1 files changed, 117 insertions, 0 deletions
diff --git a/OpenSim/Region/Framework/Scenes/Serialization/CoalescedSceneObjectsSerializer.cs b/OpenSim/Region/Framework/Scenes/Serialization/CoalescedSceneObjectsSerializer.cs
new file mode 100644
index 0000000..3af2f76
--- /dev/null
+++ b/OpenSim/Region/Framework/Scenes/Serialization/CoalescedSceneObjectsSerializer.cs
@@ -0,0 +1,117 @@
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.Collections.Generic;
30using System.Drawing;
31using System.IO;
32using System.Reflection;
33using System.Xml;
34using log4net;
35using OpenMetaverse;
36using OpenSim.Framework;
37using OpenSim.Region.Framework.Interfaces;
38using OpenSim.Region.Framework.Scenes;
39
40namespace OpenSim.Region.Framework.Scenes.Serialization
41{
42 /// <summary>
43 /// Serialize and deserialize coalesced scene objects.
44 /// </summary>
45 public class CoalescedSceneObjectsSerializer
46 {
47 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
48
49 /// <summary>
50 /// Serialize coalesced objects to Xml
51 /// </summary>
52 /// <param name="coa"></param>
53 /// <returns></returns>
54 public static string ToXml(CoalescedSceneObjects coa)
55 {
56 // TODO: Should probably return an empty xml serialization rather than a blank string
57 if (!coa.HasObjects)
58 return "";
59
60 using (StringWriter sw = new StringWriter())
61 {
62 using (XmlTextWriter writer = new XmlTextWriter(sw))
63 {
64 List<SceneObjectGroup> coaObjects = coa.Objects;
65
66// m_log.DebugFormat(
67// "[COALESCED SCENE OBJECTS SERIALIZER]: Writing {0} objects for coalesced object",
68// coaObjects.Count);
69
70 float minX, minY, minZ;
71 float maxX, maxY, maxZ;
72
73 Vector3[] offsets = Scene.GetCombinedBoundingBox(coaObjects,
74 out minX, out maxX, out minY, out maxY,
75 out minZ, out maxZ);
76
77 writer.WriteStartElement("CoalescedObject");
78
79 float sizeX = maxX - minX;
80 float sizeY = maxY - minY;
81 float sizeZ = maxZ - minZ;
82
83 writer.WriteAttributeString("x", sizeX.ToString());
84 writer.WriteAttributeString("y", sizeY.ToString());
85 writer.WriteAttributeString("z", sizeZ.ToString());
86
87 // Embed the offsets into the group XML
88 for (int i = 0; i < coaObjects.Count; i++)
89 {
90 SceneObjectGroup obj = coaObjects[i];
91
92// m_log.DebugFormat(
93// "[COALESCED SCENE OBJECTS SERIALIZER]: Writing offset for object {0}, {1}",
94// i, obj.Name);
95
96 writer.WriteStartElement("SceneObjectGroup");
97 writer.WriteAttributeString("offsetx", offsets[i].X.ToString());
98 writer.WriteAttributeString("offsety", offsets[i].Y.ToString());
99 writer.WriteAttributeString("offsetz", offsets[i].Z.ToString());
100
101 SceneObjectSerializer.ToOriginalXmlFormat(obj, writer, true);
102
103 writer.WriteEndElement();
104 }
105
106 writer.WriteEndElement(); // CoalescedObject
107 }
108
109 string output = sw.ToString();
110
111// m_log.Debug(output);
112
113 return output;
114 }
115 }
116 }
117} \ No newline at end of file