private Solid.Straight BuildStraight(Node sn, Node en) { double length = sn.Position.DistanceTo(en.Position); AcadGeo.Vector3d vec = AcadFuncs.GetVec(sn.Position, en.Position); Solid.Straight straight = new Solid.Straight(); if (ELBOW_CONNS == sn.Connections.Count) { double angle = AngleElbow(sn); if (Math.Abs(Math.Sin(angle * 0.5)) < 0.001 || Math.Abs(Math.Cos(angle * 0.5)) < 0.001) { straight.StartPosition = sn.Position - vec * width; length -= width; } else { straight.StartPosition = sn.Position - vec * (width / Math.Tan(angle * 0.5)); length -= width / Math.Tan(angle * 0.5); } } else if (sn.Connections.Count > 1) { straight.StartPosition = sn.Position - vec * width; length -= width; } else { straight.StartPosition = sn.Position; } if (ELBOW_CONNS == en.Connections.Count) { double angle = AngleElbow(en); if (Math.Abs(Math.Sin(angle * 0.5)) < 0.001 || Math.Abs(Math.Cos(angle * 0.5)) < 0.001) { straight.EndPosition = en.Position + vec * width; length -= width; } else { straight.EndPosition = en.Position + vec * (width / Math.Tan(angle * 0.5)); length -= width / Math.Tan(angle * 0.5); } } else if (en.Connections.Count > 1) { straight.EndPosition = en.Position + vec * width; } else { straight.EndPosition = en.Position; } if (length > 0.0) { return(straight); } else { return(null); } }
public void BuildRoutingSolid() { List <Node> nodes = routers.Vertices.ToList(); foreach (var n in nodes.ToList()) { nodes.Remove(n); if (n.Connections.Count > 4) { continue; } foreach (var conn in n.Connections) { Node sn = n.GetConnection(conn); if (null != nodes.Find(x => x == sn)) { Solid.Straight solid = BuildStraight(n, sn); if (null != solid) { Solid.Profile cal_prol = CalculateProfile(n.Position); cal_prol.Rotate(AcadFuncs.GetVec(sn.Position, n.Position)); solid.Profile = cal_prol; solids.Add(solid); } } } if (ELBOW_CONNS == n.Connections.Count) { Solid.Elbow elbow = new Solid.Elbow(); elbow.Position = n.Position; AcadGeo.Point3d[] bps = new AcadGeo.Point3d[2]; bps[0] = n.Connections[0].Source.Position == n.Position ? n.Connections[0].Target.Position : n.Connections[0].Source.Position; bps[1] = n.Connections[1].Source.Position == n.Position ? n.Connections[1].Target.Position : n.Connections[1].Source.Position; elbow.BranchPos = bps; elbow.Profile = CalculateProfile(n.Position); elbow.Radius = width; elbow.CalculateAngle(); solids.Add(elbow); } else if (TEE_CONNS == n.Connections.Count) { Solid.Tee tee = new Solid.Tee(); tee.Position = n.Position; tee.MainBranchPosition = GetMainTeePos(n.Position, n.Connections[0].ConnectedPos(n.Position), n.Connections[1].ConnectedPos(n.Position), n.Connections[2].ConnectedPos(n.Position)); tee.BranchPosition = GetBranchTeePos(n.Position, n.Connections[0].ConnectedPos(n.Position), n.Connections[1].ConnectedPos(n.Position), n.Connections[2].ConnectedPos(n.Position)); tee.Profile = CalculateProfile(n.Position); tee.Radius = width; solids.Add(tee); } else if (CROSSING_CONNS == n.Connections.Count) { Solid.Crossing crossing = new Solid.Crossing(); crossing.Position = n.Position; crossing.MainBranchPosition = GetMainTeePos(n.Position, n.Connections[0].ConnectedPos(n.Position), n.Connections[1].ConnectedPos(n.Position), n.Connections[2].ConnectedPos(n.Position)); crossing.BranchPosition = GetBranchTeePos(n.Position, n.Connections[0].ConnectedPos(n.Position), n.Connections[1].ConnectedPos(n.Position), n.Connections[2].ConnectedPos(n.Position)); crossing.Profile = CalculateProfile(n.Position); crossing.Radius = width; solids.Add(crossing); } } }