/// <summary> /// 布局线路 /// </summary> /// <param name="pshape"></param> void layeroutmx(BaseShape pshape) { ShapeCollection childshapes = pshape.GetChildShapes(); if (pshape is MX1Shape) { MX1Shape mx1 = pshape as MX1Shape; mx1.Width = Math.Max(mx1.Width, 40 * childshapes.Count); mx1.ConnectorNumber = childshapes.Count; } foreach (Connector cr in pshape.Connectors) { if (cr.ConnectorLocation == ConnectorLocation.South) { foreach (Connection cn in cr.Connections) { Connector crto = cn.From; if (cn.From == cr) { crto = cn.To; } if (!movedshapes.Contains(crto.BelongsTo)) { movedshapes.Add(crto.BelongsTo); PointF pf1 = crto.BelongsTo.ConnectionPoint(crto); PointF pf2 = cr.BelongsTo.ConnectionPoint(cr); float offx = pf2.X - pf1.X; float offy = 50; crto.BelongsTo.X += offx; crto.BelongsTo.Y += offy; } } } } float xlright = 0; //线路右边范围 int xlnum = -1; //有设备的线路 foreach (BaseShape sp1 in childshapes) { if (!layershapes.Contains(sp1)) { layershapes.Add(sp1); { if (sp1.GetChildShapes().Count > 1) { if (xlright > sp1.X) { sp1.X = xlright + 30; } if (sp1.DeviceType != "01") { sp1.Y -= xlnum * 3; xlnum++; } layeroutsb(sp1, ref xlright); } } } } curWidth = Math.Max(xlright, pshape.X + pshape.Width); }
/// <summary> /// 布局子设备 /// </summary> /// <param name="pshape"></param> /// <param name="xlright"></param> void layeroutsb(BaseShape pshape, ref float xlright) { ShapeCollection childshapes = pshape.GetChildShapes(); float offx = pshape.X; int wnum = 0; int hnum = 0; for (int i = 0; i < childshapes.Count; i++) { BaseShape sp1 = childshapes[i] as BaseShape; if (!layershapes.Contains(sp1)) { layershapes.Add(sp1); if (sp1.DeviceType == "01") { layeroutmx(sp1); } else { if (IsEven(sp1.Grade)) { sp1.X = pshape.X + sp1.Width + 50; sp1.Y = pshape.Y + (pshape.Height - sp1.Height) / 2; sp1.Y += 30 * wnum; wnum++; xlright = Math.Max(sp1.X + sp1.Width, xlright); layeroutsb(sp1, ref xlright); } else { sp1.X = pshape.X + (pshape.Width - sp1.Width) / 2; sp1.X += 30 * hnum; hnum++; xlright = Math.Max(sp1.X + sp1.Width, xlright); sp1.Y = pshape.Y + pshape.Height + 30; layeroutsb(sp1, ref xlright); } } } } }