/// <summary> /// Main constructor for edge /// </summary> /// <param name="pStart">starting point of the edge</param> /// <param name="pEnd">ending point of the edge</param> /// <param name="connectionType">connection type of the edge</param> public AGraphMLEdge(AGraphMLNode pStart, AGraphMLNode pEnd, string connectionType) { // init values this.PStart = pStart; this.PEnd = pEnd; this.ConnectionType = connectionType; }
/// <summary> /// This method returns a list with all nodes from the file /// </summary> /// <param name="doc">Representant of the xml document to be read</param> /// <returns>a list with nodes</returns> private IEnumerable<AGraphMLNode> getPointsFromFile(XmlDocument doc) { // return value List<AGraphMLNode> points = new List<AGraphMLNode>(); // temporary attributes string id; double x; double y; string roomType; string corners; // set root element XmlElement root = doc.DocumentElement; // add the namespace XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable); nsmgr.AddNamespace("x", "http://graphml.graphdrawing.org/xmlns"); // get all xml-tags with nodes XmlNodeList nodeList = root.SelectNodes(attributeXPathNode, nsmgr); foreach (XmlNode node in nodeList) { // init values id = ""; x = 0.0; y = 0.0; roomType = ""; corners = ""; // get id as attribute from the child foreach (XmlAttribute attr in node.Attributes) { if (attr.Name == attributeNameId) id = attr.InnerText; } // get data from children foreach (XmlNode child in node.ChildNodes) { // search in attributes foreach (XmlAttribute attr in child.Attributes) { // center coordinate if (attr.InnerText.Equals(attributeNameCenter)) { // center has format "POINT (0.25 0.75)" string center = child.InnerText; // cut string int firstIndex = center.IndexOf('(') + 1; int lastIndex = center.LastIndexOf(')'); center = center.Substring(firstIndex, lastIndex - firstIndex); // cut string by space symbol x = double.Parse(center.Split(' ')[0], System.Globalization.CultureInfo.InvariantCulture); y = double.Parse(center.Split(' ')[1], System.Globalization.CultureInfo.InvariantCulture); } // room type if (attr.InnerText.Equals(attributeNameRoomType)) { roomType = child.InnerText; } // corners if (attr.InnerText.Equals(attributeNameCorners)) { // corners has format "POLYGON ((0 0, 1 0, 1 1, 0 0))" corners = child.InnerText; // cut string int first = corners.IndexOf('(') + 2; int last = corners.LastIndexOf(')') - 1; corners = corners.Substring(first, last - first); } } } // create point AGraphMLNode p = new AGraphMLNode(id, x, y, roomType); // add corners string[] corner = corners.Split(','); // process each corner for (int i = 0; i < corner.Length; i++) { string temp = corner[i]; // delete leading space if there if (temp[0] == ' ') temp = temp.Substring(1); // add corner to list p.addCorner(new AGraphMLCorner(double.Parse(temp.Split(' ')[0], System.Globalization.CultureInfo.InvariantCulture), double.Parse(temp.Split(' ')[1], System.Globalization.CultureInfo.InvariantCulture))); } // add point points.Add(p); } // return list return points; }
/// <summary> /// This method returns a list with all nodes from the file /// </summary> /// <param name="doc">Representant of the xml document to be read</param> /// <returns>a list with nodes</returns> private IEnumerable <AGraphMLNode> getPointsFromFile(XmlDocument doc) { // return value List <AGraphMLNode> points = new List <AGraphMLNode>(); // temporary attributes string id; double x; double y; string roomType; string corners; // set root element XmlElement root = doc.DocumentElement; // add the namespace XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable); nsmgr.AddNamespace("x", "http://graphml.graphdrawing.org/xmlns"); // get all xml-tags with nodes XmlNodeList nodeList = root.SelectNodes(attributeXPathNode, nsmgr); foreach (XmlNode node in nodeList) { // init values id = ""; x = 0.0; y = 0.0; roomType = ""; corners = ""; // get id as attribute from the child foreach (XmlAttribute attr in node.Attributes) { if (attr.Name == attributeNameId) { id = attr.InnerText; } } // get data from children foreach (XmlNode child in node.ChildNodes) { // search in attributes foreach (XmlAttribute attr in child.Attributes) { // center coordinate if (attr.InnerText.Equals(attributeNameCenter)) { // center has format "POINT (0.25 0.75)" string center = child.InnerText; // cut string int firstIndex = center.IndexOf('(') + 1; int lastIndex = center.LastIndexOf(')'); center = center.Substring(firstIndex, lastIndex - firstIndex); // cut string by space symbol x = double.Parse(center.Split(' ')[0], System.Globalization.CultureInfo.InvariantCulture); y = double.Parse(center.Split(' ')[1], System.Globalization.CultureInfo.InvariantCulture); } // room type if (attr.InnerText.Equals(attributeNameRoomType)) { roomType = child.InnerText; } // corners if (attr.InnerText.Equals(attributeNameCorners)) { // corners has format "POLYGON ((0 0, 1 0, 1 1, 0 0))" corners = child.InnerText; // cut string int first = corners.IndexOf('(') + 2; int last = corners.LastIndexOf(')') - 1; corners = corners.Substring(first, last - first); } } } // create point AGraphMLNode p = new AGraphMLNode(id, x, y, roomType); // add corners string[] corner = corners.Split(','); // process each corner for (int i = 0; i < corner.Length; i++) { string temp = corner[i]; // delete leading space if there if (temp[0] == ' ') { temp = temp.Substring(1); } // add corner to list p.addCorner(new AGraphMLCorner(double.Parse(temp.Split(' ')[0], System.Globalization.CultureInfo.InvariantCulture), double.Parse(temp.Split(' ')[1], System.Globalization.CultureInfo.InvariantCulture))); } // add point points.Add(p); } // return list return(points); }