public void SerializeTilesTest() { TileInSpace.ResetCounter(); FloatingObjectInSpace.ResetCounter(); //Set test Floating objects set FloatingObjectInSpace testFloatingObjectInSpace = new FloatingObjectInSpace(v_TestFloatingObject, new Point3D(0, 0, 0)); FloatingObjectsSet testFloatingObjectsSet = new FloatingObjectsSet { testFloatingObjectInSpace }; //Set test Tile set List <Point3D> testPointList = new List <Point3D>() { new Point3D(1, 1, 1), new Point3D(2, 2, 2) }; Tile baseObject = new Tile("testName", testPointList, null, null, null, Color.Black); List <TileInSpace> testTilesList = new List <TileInSpace> { new TileInSpace(baseObject, Point3D.Origin, Quaternion.One) }; SerializeSnapshot testSnapshot = new SerializeSnapshot(c_TestMSystemDescription, new List <Tile> { baseObject }); testSnapshot.Serialize(0, testFloatingObjectsSet, testTilesList); string serializedSnapShot = testSnapshot.GetXmlDocAsAString(); XDocument expecteDocument = XDocument.Load("../../Classes/Xml/TestXML/serializedSnapShotTest.xml"); //TODO Due to TileInSpace static counter this test fails if you use "run all tests". Assert.AreEqual(expecteDocument.ToString(), serializedSnapShot); //Compare both documents. }
/// <summary> /// Adds a new snapshot to the snapshots XML document /// </summary> /// <param name="snapshotXmlDoc">Target snapshots XML document</param> /// <param name="stepID">Snapshot number.</param> /// <param name="floatingObjects">Floating objects to be serialized.</param> /// <param name="tilesWorld">Tiles to be serialized.</param> public static void AddSnapshot(ulong stepID, FloatingObjectsSet floatingObjects, TilesWorld tilesWorld, SerializeSnapshot snapshotXmlDoc) { if (floatingObjects == null) { throw new ArgumentNullException("Parameter 'floatingObjects' may not be null."); } if (tilesWorld == null) { throw new ArgumentNullException("Parameter 'tilesWorld' may not be null."); } if (snapshotXmlDoc == null) { throw new ArgumentNullException("Parameter 'snapshotXmlDoc' may not be null."); } snapshotXmlDoc.Serialize(stepID, floatingObjects, tilesWorld); }
/// <summary> /// Serializes one snapshot. /// </summary> /// <param name="stepID">Snapshot number.</param> /// <param name="floatingObjects">Floating objects to be serialized.</param> /// <param name="tiles">Tiles to be serialized.</param> public void Serialize(ulong stepID, FloatingObjectsSet floatingObjects, IEnumerable <TileInSpace> tiles) { // Child snapshot declaration. XElement snapshot = new XElement("snapshot", new XAttribute("stepID", stepID.ToString())); v_RootXmlElement.GetElement("snapshots").Add(snapshot); // Child floatingObjects. XElement floatingObjectsNode = new XElement("floatingObjects"); snapshot.Add(floatingObjectsNode); // Child tiles. XElement tilesNode = new XElement("tiles"); snapshot.Add(tilesNode); SerializeFloatingObjects(floatingObjectsNode, floatingObjects); SerializeTiles(tilesNode, tiles); }
/// <summary> /// Serializes floating objects. /// </summary> /// <param name="floatingObjectsNode">Xml node where the floating objects belong.</param> /// <param name="floatingObjects">Floating objects to serialize.</param> private void SerializeFloatingObjects(XElement floatingObjectsNode, FloatingObjectsSet floatingObjects) { foreach (FloatingObjectInSpace floatingObject in floatingObjects) { /* <floatingObject name="a" objectID="1"> * <position> * <posX value="0"/> * <posY value="0"/> * <posZ value="0"/> * </position> * </floatingObject> */ XElement floatingObjectElement = new XElement("floatingObject", new XAttribute("name", floatingObject.Name), new XAttribute("objectID", floatingObject.ID.ToString())); SerializePosition(floatingObjectElement, floatingObject.Position); floatingObjectsNode.Add(floatingObjectElement); } }
public void CreateComplexSnapshotFileTest() // Petr: Actually not a test - only temporary debugging method. Please do not remove. // Produces a test snapshot file for Honza - testing the visualization package in Unity. { //Set test Floating objects set var testFloatingObjectInSpace = new FloatingObjectInSpace(v_TestFloatingObject, new Point3D(0, 1, 2)); // Add more var testFloatingObjectsSet = new FloatingObjectsSet { testFloatingObjectInSpace }; Tile baseTile = CreateTile("q2"); Tile baseTubule = CreateSegment("s1"); var v_baseTilesList = new List <Tile> { baseTile, baseTubule }; var testTilesList = new List <TileInSpace> { new TileInSpace(baseTile, Point3D.Origin, Quaternion.One) }; SerializeSnapshot testSnapshot = new SerializeSnapshot(c_TestMSystemDescription, v_baseTilesList); testSnapshot.Serialize(0, testFloatingObjectsSet, testTilesList); TileInSpace bottomTile = testTilesList.First(); bottomTile.State = TileInSpace.FState.Unchanged; var level1Tiles = new List <TileInSpace>(); for (int i = 0; i < 5; i++) { level1Tiles.Add(bottomTile.Connectors[i].ConnectObject(baseTile.Connectors[0])); } testTilesList.AddRange(level1Tiles); var tubule1 = bottomTile.Connectors.Last().ConnectObject(baseTubule.Connectors[0]); testTilesList.Add(tubule1); testSnapshot.Serialize(1, testFloatingObjectsSet, testTilesList); // Adding the second level of tiles of dodecahedron and tubules tubule1.State = TileInSpace.FState.Unchanged; var level2Tiles = new List <TileInSpace>(); var level2Tubules = new List <TileInSpace>(); foreach (var tile in level1Tiles) { tile.State = TileInSpace.FState.Unchanged; level2Tiles.Add(tile.Connectors[2].ConnectObject(baseTile.Connectors[0])); } for (int i = 1; i < 3; i++) { level2Tubules.Add(tubule1.Connectors[i].ConnectObject(baseTubule.Connectors[0])); } testTilesList.AddRange(level2Tiles); testTilesList.AddRange(level2Tubules); testSnapshot.Serialize(2, testFloatingObjectsSet, testTilesList); foreach (var tile in level2Tiles) { tile.State = TileInSpace.FState.Unchanged; } // Adding the last top tile of dodecahedron TileInSpace topTile = level2Tiles.Last().Connectors[3].ConnectObject(baseTile.Connectors[0]); testTilesList.Add(topTile); var level3Tubules = new List <TileInSpace>(); foreach (var tubule in level2Tubules) { tubule.State = TileInSpace.FState.Unchanged; for (int i = 1; i < 3; i++) { level3Tubules.Add(tubule.Connectors[i].ConnectObject(baseTubule.Connectors[0])); } } // Dodecahedron complete, three levels of tubule tree complete testTilesList.AddRange(level3Tubules); testSnapshot.Serialize(3, testFloatingObjectsSet, testTilesList); topTile.State = TileInSpace.FState.Unchanged; foreach (var tubule in level3Tubules) { tubule.State = TileInSpace.FState.Unchanged; } foreach (var tile in level2Tiles) { tile.State = TileInSpace.FState.Destroy; } // Level 2 tiles destructed testSnapshot.Serialize(4, testFloatingObjectsSet, testTilesList); testTilesList.RemoveAll(obj => level2Tiles.Contains(obj)); topTile.Move(new Vector3D(0, 0, -5)); // Top tile moved 5 units down testSnapshot.Serialize(5, testFloatingObjectsSet, testTilesList); topTile.State = TileInSpace.FState.Unchanged; var Tile = CreateSquareTile("TestSquare"); TileInSpace baseSquare = new TileInSpace(Tile, new Point3D(30, 0, 0), Quaternion.One); TileInSpace eastSquare = baseSquare.Connectors[0].ConnectObject(Tile.Connectors[1]); TileInSpace southSquare = eastSquare.Connectors[0].ConnectObject(Tile.Connectors[0]); TileInSpace topSquare = southSquare.Connectors[1].ConnectObject(Tile.Connectors[0]); // Four squares added, forming an incomplete cube testTilesList.AddRange(new List <TileInSpace>() { baseSquare, eastSquare, southSquare, topSquare }); testSnapshot.Serialize(6, testFloatingObjectsSet, testTilesList); testSnapshot.SaveXmlFile(@"..\..\..\Cytos_v2\Examples\TestSnapshotFile.xml"); }