From: Richard Alimi <ralimi@us.ibm.com>

The following patch makes some enhancements to loading/saving the Xml2
format.

- Add streamed version of functionality for saving prims to Xml2
  format. The streamed version (optionally) allows for saving the
  prims whose positions appear within a particular bounding box.

- Expose stream versions of LoadPrimsFromXml2 and SavePrimsToXml2 in
  the Scene class

- Extend loading from Xml2 (the streamed version) to optionally start
  scripts for the loaded scene objects)
0.6.0-stable
Dr Scofield 2008-08-15 07:20:38 +00:00
parent 8606a86d5c
commit 8d479fe5af
4 changed files with 106 additions and 12 deletions

View File

@ -64,7 +64,8 @@ namespace OpenSim.Region.Environment.Modules.World.Serialiser
/// </summary>
/// <param name="scene"></param>
/// <param name="reader"></param>
void LoadPrimsFromXml2(Scene scene, TextReader reader);
/// <param name="startScripts"></param>
void LoadPrimsFromXml2(Scene scene, TextReader reader, bool startScripts);
/// <summary>
/// Save prims in the xml2 format
@ -73,6 +74,17 @@ namespace OpenSim.Region.Environment.Modules.World.Serialiser
/// <param name="fileName"></param>
void SavePrimsToXml2(Scene scene, string fileName);
/// <summary>
/// Save prims in the xml2 format, optionally specifying a bounding box for which
/// prims should be saved. If both min and max vectors are LLVector3.Zero, then all prims
/// are exported.
/// </summary>
/// <param name="scene"></param>
/// <param name="stream"></param>
/// <param name="min"></param>
/// <param name="max"></param>
void SavePrimsToXml2(Scene scene, TextWriter stream, LLVector3 min, LLVector3 max);
/// <summary>
/// Save a set of prims in the xml2 format
/// </summary>
@ -80,6 +92,17 @@ namespace OpenSim.Region.Environment.Modules.World.Serialiser
/// <param name="fileName"></param>
void SavePrimListToXml2(List<EntityBase> entityList, string fileName);
/// <summary>
/// Save a set of prims in the xml2 format, optionally specifying a bounding box for which
/// prims should be saved. If both min and max vectors are LLVector3.Zero, then all prims
/// are exported.
/// </summary>
/// <param name="entityList"></param>
/// <param name="stream"></param>
/// <param name="min"></param>
/// <param name="max"></param>
void SavePrimListToXml2(List<EntityBase> entityList, TextWriter stream, LLVector3 min, LLVector3 max);
/// <summary>
/// Deserializes a scene object from its xml2 representation. This does not load the object into the scene.
/// </summary>

View File

@ -143,7 +143,7 @@ namespace OpenSim.Region.Environment.Scenes
/// <param name="fileName"></param>
public static void LoadPrimsFromXml2(Scene scene, string fileName)
{
LoadPrimsFromXml2(scene, new XmlTextReader(fileName));
LoadPrimsFromXml2(scene, new XmlTextReader(fileName), false);
}
/// <summary>
@ -151,9 +151,10 @@ namespace OpenSim.Region.Environment.Scenes
/// </summary>
/// <param name="scene"></param>
/// <param name="reader"></param>
public static void LoadPrimsFromXml2(Scene scene, TextReader reader)
/// <param name="startScripts"></param>
public static void LoadPrimsFromXml2(Scene scene, TextReader reader, bool startScripts)
{
LoadPrimsFromXml2(scene, new XmlTextReader(reader));
LoadPrimsFromXml2(scene, new XmlTextReader(reader), startScripts);
}
/// <summary>
@ -161,7 +162,8 @@ namespace OpenSim.Region.Environment.Scenes
/// </summary>
/// <param name="scene"></param>
/// <param name="reader"></param>
protected static void LoadPrimsFromXml2(Scene scene, XmlTextReader reader)
/// <param name="startScripts"></param>
protected static void LoadPrimsFromXml2(Scene scene, XmlTextReader reader, bool startScripts)
{
XmlDocument doc = new XmlDocument();
reader.WhitespaceHandling = WhitespaceHandling.None;
@ -169,9 +171,17 @@ namespace OpenSim.Region.Environment.Scenes
reader.Close();
XmlNode rootNode = doc.FirstChild;
ICollection<SceneObjectGroup> sceneObjects = new List<SceneObjectGroup>();
foreach (XmlNode aPrimNode in rootNode.ChildNodes)
{
CreatePrimFromXml2(scene, aPrimNode.OuterXml);
SceneObjectGroup obj = CreatePrimFromXml2(scene, aPrimNode.OuterXml);
if (obj != null && startScripts)
sceneObjects.Add(obj);
}
foreach (SceneObjectGroup sceneObject in sceneObjects)
{
sceneObject.CreateScriptInstances(0, true);
}
}
@ -198,10 +208,36 @@ namespace OpenSim.Region.Environment.Scenes
SavePrimListToXml2(EntityList, fileName);
}
public static void SavePrimsToXml2(Scene scene, TextWriter stream, LLVector3 min, LLVector3 max)
{
List<EntityBase> EntityList = scene.GetEntities();
SavePrimListToXml2(EntityList, stream, min, max);
}
public static void SavePrimListToXml2(List<EntityBase> entityList, string fileName)
{
FileStream file = new FileStream(fileName, FileMode.Create);
StreamWriter stream = new StreamWriter(file);
try
{
StreamWriter stream = new StreamWriter(file);
try
{
SavePrimListToXml2(entityList, stream, LLVector3.Zero, LLVector3.Zero);
}
finally
{
stream.Close();
}
}
finally
{
file.Close();
}
}
public static void SavePrimListToXml2(List<EntityBase> entityList, TextWriter stream, LLVector3 min, LLVector3 max)
{
int primCount = 0;
stream.WriteLine("<scene>\n");
@ -209,13 +245,23 @@ namespace OpenSim.Region.Environment.Scenes
{
if (ent is SceneObjectGroup)
{
stream.WriteLine(((SceneObjectGroup)ent).ToXmlString2());
SceneObjectGroup g = (SceneObjectGroup)ent;
if (!min.Equals(LLVector3.Zero) || !max.Equals(LLVector3.Zero))
{
LLVector3 pos = g.RootPart.GetWorldPosition();
if (min.X > pos.X || min.Y > pos.Y || min.Z > pos.Z)
continue;
if (max.X < pos.X || max.Y < pos.Y || max.Z < pos.Z)
continue;
}
stream.WriteLine(g.ToXmlString2());
primCount++;
}
}
stream.WriteLine("</scene>\n");
stream.Close();
file.Close();
stream.Flush();
}
}
}

View File

@ -102,9 +102,9 @@ namespace OpenSim.Region.Environment.Modules.World.Serialiser
SceneXmlLoader.LoadPrimsFromXml2(scene, fileName);
}
public void LoadPrimsFromXml2(Scene scene, TextReader reader)
public void LoadPrimsFromXml2(Scene scene, TextReader reader, bool startScripts)
{
SceneXmlLoader.LoadPrimsFromXml2(scene, reader);
SceneXmlLoader.LoadPrimsFromXml2(scene, reader, startScripts);
}
public void SavePrimsToXml2(Scene scene, string fileName)
@ -112,6 +112,11 @@ namespace OpenSim.Region.Environment.Modules.World.Serialiser
SceneXmlLoader.SavePrimsToXml2(scene, fileName);
}
public void SavePrimsToXml2(Scene scene, TextWriter stream, LLVector3 min, LLVector3 max)
{
SceneXmlLoader.SavePrimsToXml2(scene, stream, min, max);
}
public SceneObjectGroup DeserializeGroupFromXml2(string xmlString)
{
return SceneXmlLoader.DeserializeGroupFromXml2(xmlString);
@ -127,6 +132,11 @@ namespace OpenSim.Region.Environment.Modules.World.Serialiser
SceneXmlLoader.SavePrimListToXml2(entityList, fileName);
}
public void SavePrimListToXml2(List<EntityBase> entityList, TextWriter stream, LLVector3 min, LLVector3 max)
{
SceneXmlLoader.SavePrimListToXml2(entityList, stream, min, max);
}
public List<string> SerialiseRegion(Scene scene, string saveDir)
{
List<string> results = new List<string>();

View File

@ -29,6 +29,7 @@ using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Threading;
using System.Timers;
using Axiom.Math;
@ -1760,6 +1761,13 @@ namespace OpenSim.Region.Environment.Scenes
m_serialiser.LoadPrimsFromXml2(this, fileName);
}
public void LoadPrimsFromXml2(TextReader reader, bool startScripts)
{
m_log.InfoFormat("[SCENE]: Loading prims in xml2 format to region {0} from stream", RegionInfo.RegionName);
m_serialiser.LoadPrimsFromXml2(this, reader, startScripts);
}
public void SavePrimsToXml2(string fileName)
{
m_log.InfoFormat("[SCENE]: Saving prims in xml2 format for region {0} to {1}", RegionInfo.RegionName, fileName);
@ -1767,6 +1775,13 @@ namespace OpenSim.Region.Environment.Scenes
m_serialiser.SavePrimsToXml2(this, fileName);
}
public void SavePrimsToXml2(TextWriter stream, LLVector3 min, LLVector3 max)
{
m_log.InfoFormat("[SCENE]: Saving prims in xml2 format for region {0} to stream", RegionInfo.RegionName);
m_serialiser.SavePrimsToXml2(this, stream, min, max);
}
public void SaveNamedPrimsToXml2(string primName, string fileName)
{
m_log.InfoFormat(