protected override void _SetAttributes(Dictionary <string, string> _attrs) { Dictionary <string, string> attrs = new Dictionary <string, string>(); foreach (var item in _attrs) { attrs[item.Key] = item.Value; } if (attrs.ContainsKey("centerpoint")) { CenterPoint = Utility.ParsePoint3d(attrs["centerpoint"]); } if (attrs.ContainsKey("connectedpipes")) { string[] strs = attrs["connectedpipes"].Split(','); List <PipeLine> lines = new List <PipeLine>(); for (int i = 0; i < strs.Count() - 1; i++) { int modelId = ModelIdManager.Parse(strs[i]); lines.Add((PipeLine)BaseModel.GetModelById(modelId)); } this.SetPipeLines(lines); } if (attrs.ContainsKey("solution")) { this.OwnSolution = (Solution)BaseModel.GetModelById(Utils.ModelIdManager.Parse(attrs["solution"])); if (this.OwnSolution != null) { this.OwnSolution.SimplePipeJoints.Add(this.BaseObjectId, this); } } if (attrs.ContainsKey("style")) { this.Style = (Solution.PipeLineStyle) int.Parse(attrs["style"]); } }
public SimplePipeJoint(Point3d p1, Point3d p2, Point3d p3, double pipeWidth, Solution sol, bool needId) : base(sol, needId) { this.Style = sol.CurrentLineStyle; this.SplitLines = new List <ObjectId>(); this.p1 = p1; this.p2 = p2; this.p3 = p3; CenterPoint = p2; Vector3d d1 = (p2 - p1).GetNormal(); Vector3d d2 = (p3 - p2).GetNormal(); Vector3d d3 = (d2 - d1).GetNormal(); //角平分线 double cos1 = d3.DotProduct(-d1); double sin1 = Math.Sqrt(1 - cos1 * cos1); double R1 = jointRadius / sin1; Point3d center = p2 + R1 * d3; Point3d arcStartPoint = p2 - R1 * cos1 * d1; Point3d arcEndPoint = p2 + R1 * cos1 * d2; Point3d arcCenterPoint = center - d3 * jointRadius; CircularArc3d c = new CircularArc3d(arcStartPoint, arcCenterPoint, arcEndPoint); double angle1 = c.ReferenceVector.AngleOnPlane(new Plane(c.Center, c.Normal)); arc = new Arc(); arc.Center = c.Center; arc.Radius = c.Radius; arc.Normal = c.Normal; arc.StartAngle = c.StartAngle + angle1; arc.EndAngle = c.EndAngle + angle1; double angle = d2.GetAngleTo(d1); if (d1.CrossProduct(d2).Z < 0) { angle = -angle; } int seg = 3; if (Math.Abs(angle) < Math.PI / 2) { seg = 3; } else if (Math.Abs(angle) < Math.PI / 4 * 3) { seg = 4; } else { seg = 5; } polyline = new Polyline(); double ShortR = jointRadius - pipeWidth; double WideR = jointRadius + pipeWidth; Vector3d d4 = (arcStartPoint - center).GetNormal(); Point3d p4 = center + d4 * ShortR; Point3d p5 = center + d4 * WideR; lines = new List <Line>(); for (int i = 0; i < seg - 1; i++) { Point3d p6; Point3d p7; if (i == 0) { d4 = d4.RotateBy(angle / (seg - 1) / 2, Vector3d.ZAxis); } else { d4 = d4.RotateBy(angle / (seg - 1), Vector3d.ZAxis); } p6 = center + d4 * ShortR; p7 = center + d4 * WideR; Line l = new Line(p6, p7); lines.Add(l); } Vector3d d5 = (arcEndPoint - center).GetNormal(); Point3d p8 = center + d5 * ShortR; Point3d p9 = center + d5 * WideR; polyline.AddVertexAt(0, new Point2d(p4.X, p4.Y), 0, 0, 0); for (int i = 0; i < lines.Count; i++) { Point3d p = lines[i].StartPoint; polyline.AddVertexAt(i + 1, new Point2d(p.X, p.Y), 0, 0, 0); } polyline.AddVertexAt(lines.Count + 1, new Point2d(p8.X, p8.Y), 0, 0, 0); polyline.AddVertexAt(lines.Count + 2, new Point2d(p9.X, p9.Y), 0, 0, 0); for (int i = lines.Count - 1; i >= 0; i--) { Point3d p = lines[i].EndPoint; polyline.AddVertexAt(lines.Count + 2 + lines.Count - i, new Point2d(p.X, p.Y), 0, 0, 0); } polyline.AddVertexAt(2 * lines.Count + 3, new Point2d(p5.X, p5.Y), 0, 0, 0); polyline.AddVertexAt(2 * lines.Count + 4, new Point2d(p4.X, p4.Y), 0, 0, 0); //save all objects this.SaveEntities(); }