/** * Добавляет координаты к элементам * @param packagedElement */ private void FindCoordinates(XmlNode packagedElement, Diagram diagram) { if (diagram.Image == null) { return; } int xMin = int.MaxValue, yMin = int.MaxValue; (int, int)coordMin = (0, 0); coordMin = MinCoordinates.Compute(diagram.Image); foreach (XmlNode nodeCh in packagedElement.ChildNodes) { var attr = nodeCh.Attributes["xsi:type"]; if (attr == null) { continue; // если эл-т не имеет атрибут type, он нас не интересует } string id = nodeCh.Attributes["modelElement"]?.Value; string xStr = nodeCh.Attributes["x"]?.Value; string yStr = nodeCh.Attributes["y"]?.Value; string widthStr = nodeCh.Attributes["width"]?.Value; string heightStr = nodeCh.Attributes["height"]?.Value; int x = 0, y = 0, width = 0, height = 0; bool noCoord = true; if (xStr != null) { x = int.Parse(xStr); noCoord = false; } if (yStr != null) { y = int.Parse(yStr); noCoord = false; } if (widthStr != null) { width = int.Parse(widthStr); noCoord = false; } if (heightStr != null) { height = int.Parse(heightStr); noCoord = false; } if (noCoord) { x = y = width = height = -1; } // ищем эл-т по ид BaseNode node = adNodesList.get(id); if (node == default) { node = unknownNodes.Find(n => n.getId().Equals(id)); if (node == default && attr.Value != "com.genmymodel.graphic.uml:GroupWidget") { continue; } } if (node != null) { node.X = x; node.Y = y; node.Width = width; node.Height = height; } // ищем минимальный if (x != -1) { xMin = Math.Min(x, xMin); yMin = Math.Min(y, yMin); } } // нормализация координат if (xMin == int.MaxValue) { return; } for (int i = 0; i < adNodesList.size(); i++) { adNodesList.get(i).X -= xMin; adNodesList.get(i).X += coordMin.Item1; adNodesList.get(i).Y -= yMin; adNodesList.get(i).Y += coordMin.Item2; } }
private bool ReadCoordinates(XmlElement root) { XmlNode coordRoot; try { coordRoot = root.GetElementsByTagName("plane")[0]; if (coordRoot == null) { throw new NullReferenceException(); } } catch (Exception) { return(false); } int minX = int.MaxValue, minY = int.MaxValue; foreach (XmlNode node in coordRoot.ChildNodes) { string id = node.Attributes["modelElement"]?.Value, x = node.Attributes["x"]?.Value, y = node.Attributes["y"]?.Value, w = node.Attributes["width"]?.Value, h = node.Attributes["height"]?.Value, type = node.Attributes["xsi:type"]?.Value; if (type == null || type.Contains("Association")) { continue; } int intX = ConvertCoordinates(x); int intY = ConvertCoordinates(y); int intW = ConvertCoordinates(w); int intH = ConvertCoordinates(h); minX = minX > intX ? intX : minX; minY = minY > intY ? intY : minY; if (id == null || !elements.ContainsKey(id)) { continue; } var element = elements[id]; if (element.Type == ElementTypes.Actor && minX == intX) { var words = element.Name.Split(' ').ToList(); words.Sort(); words.Reverse(); if (words[0].Count() > 5) { minX += (int)((words[0].Count() - 5) * 1.5); } } element.X = element.X == int.MaxValue ? intX : element.X; element.Y = element.Y == int.MaxValue ? intY : element.Y; if (intW != int.MaxValue && element.W == -1) { element.W = intW; } if (intH != int.MaxValue && element.H == -1) { element.H = intH; } } var(realMinX, realMinY) = MinCoordinates.Compute(diagram.Image); var diffX = realMinX - minX; var diffY = realMinY - minY; foreach (var element in elements) { element.Value.X += diffX; element.Value.Y += diffY; } return(true); }