public void CreateSVGDependencyGraph(DependencyGraph graph) { SVG svg = new SVG(this.Document, SVGNameSpace, "1.1"); this.BodyElement.AppendChild((svg as ISVGElement).Element); SVGDefinitions definitions = new SVGDefinitions(svg); System.Collections.Generic.Dictionary <DependencyNode, SVGGroup> nodeToSVGGroup = new System.Collections.Generic.Dictionary <DependencyNode, SVGGroup>(); int rankCount = graph.RankCount; int numVerticalSlots = 2 * rankCount + 1; float verticalStride = 100 / numVerticalSlots; int y = (int)verticalStride;; for (int i = rankCount - 1; i >= 0; --i) { DependencyNodeCollection rank = graph[i]; int nodeCount = rank.Count; int numHorizontalSlots = 2 * nodeCount + 1; float horizontalStride = 100 / numHorizontalSlots; int x = (int)horizontalStride; System.Text.StringBuilder rankIdName = new System.Text.StringBuilder(); rankIdName.AppendFormat("Rank{0}", rank.Rank); SVGGroup rankGroup = new SVGGroup(svg, rankIdName.ToString()); SVGAttributes.Fill(rankGroup, "red"); SVGText rankText = new SVGText(rankGroup, rankIdName.ToString(), 0, y, 100, (int)verticalStride, "%"); SVGAttributes.Fill(rankText, "black"); foreach (DependencyNode node in rank) { SVGGroup nodeGroup = new SVGGroup(rankGroup, node.UniqueModuleName); SVGRect nodeRect = new SVGRect(nodeGroup, x, y, (int)horizontalStride, (int)verticalStride, "%"); SVGText nodeText = new SVGText(nodeGroup, node.UniqueModuleName, x, y + (int)verticalStride / 2, (int)horizontalStride, (int)verticalStride, "%"); SVGAttributes.Fill(nodeText, "black"); nodeToSVGGroup.Add(node, nodeGroup); x += (int)(2 * horizontalStride); } y += (int)(verticalStride * 2); } SVGArrow arrow = new SVGArrow(svg, 0, 0, 100, 100, ""); SVGAttributes.Stroke(arrow, "black"); SVGAttributes.StrokeWidth(arrow, 5); #if false System.Xml.XmlElement circle = this.Document.CreateElement("circle"); System.Xml.XmlAttribute cx = this.Document.CreateAttribute("cx"); cx.Value = "100"; System.Xml.XmlAttribute cy = this.Document.CreateAttribute("cy"); cy.Value = "50"; System.Xml.XmlAttribute r = this.Document.CreateAttribute("r"); r.Value = "40"; circle.Attributes.Append(cx); circle.Attributes.Append(cy); circle.Attributes.Append(r); svgElement.AppendChild(circle); #endif }
public static List <List <Polygon> > LoadSVGToPolies(string Filename, double xoff, double yoff) { XmlReaderSettings settings = new XmlReaderSettings(); settings.DtdProcessing = DtdProcessing.Parse; XmlReader reader = XmlReader.Create(Filename, settings); reader.MoveToContent(); // Parse the file and display each of the nodes. SVGGroup RootGroup = new SVGGroup(); SVGGroup CurrentGroup = RootGroup; bool clippath = false; while (reader.Read()) { switch (reader.NodeType) { case XmlNodeType.Element: // Console.WriteLine("<{0}>", reader.Name); switch (reader.Name) { case "circle": { SVGCirc R = new SVGCirc(); var style = reader.GetAttribute("style"); if (style != null) { R.DecodeStyle(style); } R.Setup(reader.GetAttribute("cx"), reader.GetAttribute("cy"), reader.GetAttribute("r")); // < rect x = "336.794" y = "701.551" width = "1.889" height = "56.691" /> if (clippath) { Console.WriteLine("circle ignored for clippath"); } else { CurrentGroup.Children.Add(R); } } break; case "rect": { SVGRect R = new SVGRect(); var style = reader.GetAttribute("style"); if (style != null) { R.DecodeStyle(style); } R.Setup(reader.GetAttribute("x"), reader.GetAttribute("y"), reader.GetAttribute("width"), reader.GetAttribute("height")); // < rect x = "336.794" y = "701.551" width = "1.889" height = "56.691" /> if (clippath) { Console.WriteLine("rect ignored for clippath"); } else { CurrentGroup.Children.Add(R); } } break; case "clipPath": clippath = true; break; case "g": { SVGGroup ng = new SVGGroup(); var T = reader.GetAttribute("transform"); if (T != null) { ng.ParseTransform(T); } else { ng.mTransform.Reset(); } CurrentGroup.Children.Add(ng); ng.Parent = CurrentGroup; CurrentGroup = ng; } break; case "path": { SVGPathCollection R = new SVGPathCollection(); var P = reader.GetAttribute("d"); if (P != null) { R.ParseSVGPath(P); } var style = reader.GetAttribute("style"); if (style != null) { R.DecodeStyle(style); } if (clippath) { } else { CurrentGroup.Children.Add(R); } } break; } break; case XmlNodeType.Text: // Console.WriteLine(reader.Value); break; case XmlNodeType.CDATA: // Console.WriteLine("<![CDATA[{0}]]>", reader.Value); break; case XmlNodeType.ProcessingInstruction: // Console.WriteLine("<?{0} {1}?>", reader.Name, reader.Value); break; case XmlNodeType.Comment: // Console.WriteLine("<!--{0}-->", reader.Value); break; case XmlNodeType.XmlDeclaration: // Console.WriteLine("<?xml version='1.0'?>"); break; case XmlNodeType.Document: break; case XmlNodeType.DocumentType: // Console.WriteLine("<!DOCTYPE {0} [{1}]", reader.Name, reader.Value); break; case XmlNodeType.EntityReference: // Console.WriteLine(reader.Name); break; case XmlNodeType.EndElement: switch (reader.Name) { case "clipPath": clippath = false; break; case "g": if (CurrentGroup.Parent != null) { CurrentGroup = CurrentGroup.Parent; } break; } break; } } Matrix Trans = new Matrix(); Trans.Translate((float)xoff, (float)yoff); RootGroup.Transform(Trans); // RootGroup.Print(0); return(RootGroup.GetPolygons()); }
/// <summary> /// 根据读取的xml生成项目 /// </summary> /// <param name="svg"></param> public static void CreateProjectFromXML(SVGUnit svg, DrawObjectList list) { while (svg != null) { switch (svg.getElementType()) { case SVGUnit.SVGUnitType.def: //将所有symbol读取 SVGUnit defchild = svg.getChild(); while (defchild != null) { if (defchild.getElementType() == SVGUnit.SVGUnitType.symbol) { CreateSysmbolUnit(defchild as SVGSymbol); } defchild = defchild.getNext(); } break; case SVGUnit.SVGUnitType.typeGroup: if (svg.Id == SVGDefine.ConnectLineClass) { SVGGroup group = svg.getChild() as SVGGroup; DrawConnectObject drawConnectObject = DrawConnectObject.Create(group.getChild() as SVGPath); SVGCN_Ref svgcnRef = group.getChild().getNext().getChild() as SVGCN_Ref; var linkDnd = svgcnRef.LinkObjecttlDnd.Split('@'); drawConnectObject.SetConnectDeviceFromXml(linkDnd[0], 1, int.Parse(linkDnd[1]), list.GetDeviceList()); linkDnd = svgcnRef.LinkObjectIDznd.Split('@'); drawConnectObject.SetConnectDeviceFromXml(linkDnd[0], 2, int.Parse(linkDnd[1]), list.GetDeviceList()); drawConnectObject.Id = int.Parse(group.Id); list.Add(drawConnectObject); group = group.getNext() as SVGGroup; } else if (svg.Id == SVGDefine.AnimationClass) { } else { SVGGroup group = svg.getChild() as SVGGroup; while (group != null) { var gchild = group.getChild(); switch (gchild.getElementType()) { case SVGUnit.SVGUnitType.use: SVGUse use = gchild as SVGUse; var gDevice = CreateDeviceDrawObjectBase(use, group.Id); //TODO 后期添加到工作组中 list.Add(gDevice); break; default: //TODO 未编排为设备的图素集合,暂时用临时分组表示 var o = SVGDrawFactory.CreateDrawObject(svg); list.Add(o); //vBase = new DeviceDrawObjectBase(0f, 0f, 0f, 0f, group.Id, drawObjects, null, ""); break; } group = group.getNext() as SVGGroup; //获取下一个 } } break; default: break; } svg = svg.getNext(); } }