private void Import(IList larlist) { try { bdzlist.Clear(); linelist.Clear(); string uid = ConfigurationManager.AppSettings["SvgID"];//����ͼ���ļ�ID fileid = uid; StringBuilder svgxml = new StringBuilder("<?xml version=\"1.0\" encoding=\"utf-8\"?><svg id=\"svg\" width=\"1500\" height=\"1000\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" xmlns:itop=\"http://www.Itop.com/itop\" >"); svgxml.AppendLine("<defs>"); svgxml.AppendLine("<layer id=\"layer0\" label=\"Ĭ�ϲ�\" />"); SVG_SYMBOL sym = new SVG_SYMBOL(); sym.svgID = uid; IList<SVG_SYMBOL> symlist = Services.BaseService.GetList<SVG_SYMBOL>("SelectSVG_SYMBOLBySvgID", sym); foreach (SVG_SYMBOL _sym in symlist) { svgxml.AppendLine(_sym.XML); } svgxml.AppendLine("</defs>"); foreach (SVG_LAYER _lar in larlist) { svgxml.AppendLine(_lar.XML); } svgxml.AppendLine("</svg>"); SvgDocument document = new SvgDocument(); document.LoadXml(svgxml.ToString()); string SVGUID = svgid; if (document.RootElement == null) { MessageBox.Show("����ʧ�ܣ�"); return; } document.FileName = tlVectorControl1.SVGDocument.FileName; tlVectorControl1.SVGDocument = document; tlVectorControl1.SVGDocument.SvgdataUid = SVGUID; tlVectorControl1.DocumentbgColor = Color.White; tlVectorControl1.BackColor = Color.White; SVG svg =document.RootElement as SVG; Layer layer = document.GetLayerByID("layer0"); document.CurrentLayer = layer; tlVectorControl1.DrawArea.RenderTo(tlVectorControl1.CreateGraphics()); bool flag1 = document.AcceptChanges; document.AcceptChanges = false; //������·�ͱ��վ foreach (SvgElement ele in svg.ChildList) { IGraph g = ele as IGraph; g.Layer = layer; if (ele.LocalName == "polyline") { if (ele.GetAttribute("IsLead") == "1") {//��· linelist.Add(ele.ID, ele); } } else if(ele is Use){// (ele.GetAttribute("xlink:href").Contains("Substation")) {//�ڵ� bdzlist.Add(ele.ID, ele); } } List<SvgElement> list1 = new List<SvgElement>(); #region ������·��β�ڵ� foreach (Polyline pl in linelist.Values) { PointF[] ps = new PointF[2]; getNode(pl); string s1 = pl.GetAttribute("FirstNode"); string s2 = pl.GetAttribute("LastNode"); bool b1 = pl.GetAttribute("ftj") == "true";//�ڵ�T�� bool b2 = pl.GetAttribute("ltj") == "true";//β�ڵ�T�� if (!((!string.IsNullOrEmpty(s1)||b1) && (!string.IsNullOrEmpty(s2)||b2))) { pl.ParentNode.RemoveChild(pl); continue; } Use use1 = bdzlist[s1] as Use; Use use2 = bdzlist[s2] as Use; ps[0] = pl.Points[0]; ps[1] = pl.Points[pl.Points.Length - 1]; pl.Points = ps; list1.Add(pl); //pl.Transform.Matrix.TransformPoints(ps); if (b1) { //createT(pl); } else if (use1 != null) { //ps[0] = use1.CenterPoint; list1.Add(use1); } if (b2) { //createT(pl); } else if (use2 != null) { //ps[1] = use2.CenterPoint; list1.Add(use2); } } #endregion #region �Ƴ�û��Graph for (int i=svg.ChildList.Count-1;i>=0;i--){ SvgElement graph = svg.ChildList[i] as SvgElement; if (!list1.Contains(graph) ) { graph.ParentNode.RemoveChild(graph); } } #endregion #region debug //StreamWriter sw = new StreamWriter("c:\\importjxt.txt"); //sw.Write(ItopVector.Core.Func.CodeFunc.FormatXmlDocumentString(document)); //sw.Flush(); //sw.Close(); #endregion Matrix mx = getMatrix(list1);//��ȡ���ž��� #region ���ű��վ�ڵ� foreach (IGraph graph in svg.ChildList) { if (graph is Use) { bool flag = graph.LimitSize; if (flag) graph.LimitSize = false; using (Matrix matrix1 = graph.Transform.Matrix.Clone()) { Use use = graph as Use; PointF p1 = graph.CenterPoint; PointF p2 = (use.RefElement as IGraph).CenterPoint; PointF[] pts = new PointF[1] { p1}; mx.TransformPoints(pts); p1 = pts[0]; use.X = 0; use.Y = 0; matrix1.Reset(); matrix1.Translate(p1.X - p2.X, p1.Y - p2.Y); graph.Transform = new ItopVector.Core.Types.Transf(matrix1); graph.GPath.Reset(); } graph.LimitSize = flag; //createName(document, graph); } } #endregion #region ������· foreach (IGraph graph in svg.ChildList) { if (graph is Polyline) { using (Matrix matrix1 = graph.Transform.Matrix.Clone()) { Polyline pl = graph as Polyline; PointF[] ps = pl.Points.Clone() as PointF[]; string s1 = pl.GetAttribute("FirstNode"); string s2 = pl.GetAttribute("LastNode"); bool b1 = pl.GetAttribute("ftj")=="true";//�ڵ�T�� bool b2 = pl.GetAttribute("ltj") == "true";//β�ڵ�T�� Use use1 = bdzlist[s1] as Use; Use use2 = bdzlist[s2] as Use; ps[0] = pl.Points[0]; ps[1] = pl.Points[pl.Points.Length - 1]; matrix1.Multiply(mx,MatrixOrder.Append); matrix1.TransformPoints(ps); if (use1 != null && !b1) { ps[0] = use1.CenterPoint; } if (use2 != null && !b2) { ps[1] = use2.CenterPoint; } pl.Points = ps; pl.RemoveAttribute("transform"); } } } #endregion #region ����T�� foreach (SvgElement e in list1) { if (e is Polyline) { Polyline pl = e as Polyline; bool b1 = pl.GetAttribute("ftj") == "true";//�ڵ�T�� bool b2 = pl.GetAttribute("ltj") == "true";//β�ڵ�T�� //����T��,����T�ڵ� if (b1) { SvgElement se = createT(pl, 0); if (se != null) { pl.SetAttribute("FirstNode", se.ID); //createsub(se); } } if (b2) { SvgElement se = createT(pl, 1); if (se != null) { pl.SetAttribute("LastNode", se.ID); //createsub(se); } } //PSPDEV dev = createline(e); } else { //createsub(e); createName(document, e as IGraph); } } #endregion document.AcceptChanges = flag1; #region debug //StreamWriter sw2 = new StreamWriter("c:\\importjxt2.txt"); //sw2.Write(ItopVector.Core.Func.CodeFunc.FormatXmlDocumentString(document)); //sw2.Flush(); //sw2.Close(); #endregion } catch (Exception e) { MessageBox.Show(e.Message); } }