Exemplo n.º 1
0
        private static void readSeq(string line, StreamReader sr, Part part)
        {
            if (line.StartsWith("BorderSequence"))
            {
                part.Border = BorderSeq.LoadSeq(line);
            }
            else if (line.StartsWith("VdrillSequence"))
            {
                part.Vdrillings.Add(VdrillSeq.LoadSeq(line));
            }
            else if (line.StartsWith("HDrillSequence"))
            {
                part.Hdrillings.Add(HdrillSeq.LoadSeq(line));
            }
            else if (line.StartsWith("RouteSetMillSequence"))
            {
                RouteSeq rs = new RouteSeq(line);
                while (((line = sr.ReadLine()) != null) &&
                       (line.StartsWith("RouteSequence")))
                {
                    rs.AddRoute(line);
                }
                part.Routes.Add(rs);

                if (line != null)
                {
                    readSeq(line, sr, part);
                }
            }
            else if (line.StartsWith("EndSequence"))
            {
                return;
            }
        }
Exemplo n.º 2
0
        private void drawRoute(RouteSeq r)
        {
            if (r.RouteSeqs.Count == 0)
            {
                throw new Exception("铣型分段数必须大于等于1");
            }

            var list = new List <RouteOneSeq>(r.RouteSeqs);

            list.Insert(0, r.SetMillSeq);

            if (!isMirrorPart)
            {
                for (int i = 1; i < list.Count; i++)
                {
                    float x1, y1;
                    x1 = (i == 1) ? list[0].RouteSetMillX : list[i - 1].RouteX; //铣型的起点X
                    y1 = (i == 1) ? list[0].RouteSetMillY : list[i - 1].RouteY; //铣型的起点Y
                    if (i == 1)                                                 //如果是圆弧部份就不画刀具轨迹  在20180320的时候取消掉原先的判断拱高比的条件  && list[i].RouteBulge == 0
                    {
                        this.g.DrawEllipse(this.routePen,
                                           this.gap + list[0].RouteStartOffsetX * this.ratio - list[0].RouteDiameter / 2 * this.ratio,
                                           this.gap + list[0].RouteStartOffsetY * this.ratio - list[0].RouteDiameter / 2 * this.ratio,
                                           list[0].RouteDiameter * this.ratio,
                                           list[0].RouteDiameter * this.ratio);
                    }

                    if (list[i].RouteBulge == 0)
                    {
                        g.DrawLine(borderPen,
                                   gap + x1 * ratio,
                                   gap + y1 * ratio,
                                   gap + list[i].RouteX * ratio,
                                   gap + list[i].RouteY * ratio);
                    }
                    else
                    {
                        float angle1 = GetAngle(x1, y1, list[i].RouteCenterX, list[i].RouteCenterY);
                        float angle2 = GetAngle(list[i].RouteX, list[i].RouteY, list[i].RouteCenterX, list[i].RouteCenterY);

                        float sweepAngle;
                        if (list[i].RouteBulge > 0)
                        {
                            sweepAngle = angle1 > angle2 ?
                                         angle2 - angle1 :
                                         angle2 - angle1 - 360;
                        }
                        else
                        {
                            sweepAngle = angle1 < angle2 ?
                                         angle2 - angle1 :
                                         360 - angle1 + angle2;
                        }


                        if (list[i].RouteRadius < 0)
                        {
                            angle1 = angle1 - 270;

                            sweepAngle = 360 - sweepAngle;
                        }


                        //MessageBox.Show(string.Format("2x:{0},y:{1},w:{2},h:{3},sa:{4},wa:{5}",
                        //    gap + (list[i].RouteCenterX - list[i].RouteRadius) * ratio,
                        //    gap + (list[i].RouteCenterY - list[i].RouteRadius) * ratio,
                        //    list[i].RouteRadius * ratio * 2,
                        //    list[i].RouteRadius * ratio * 2,
                        //    angle1,
                        //    sweepAngle)
                        //    );

                        float x2 = list[i].RouteX;
                        float y2 = list[i].RouteY;
                        float x  = 0;
                        float y  = 0;

                        if (list[i].RouteRadius < 0)
                        {
                            if ((x1 - x2) > 0 && (y1 - y2) < 0)
                            {
                                x = list[i].RouteCenterX - Math.Abs(list[i].RouteRadius) * 2;
                                y = list[i].RouteCenterY - Math.Abs(list[i].RouteRadius) * 2;
                            }
                            else if ((x1 - x2) > 0 && (y1 - y2) > 0)
                            {
                                x = list[i].RouteCenterX;
                                y = list[i].RouteCenterY - Math.Abs(list[i].RouteRadius) * 2;
                            }
                            else if ((x1 - x2) < 0 && (y1 - y2) > 0)  //20180725  已验证  再次验证 20180801
                            {
                                x = list[i].RouteCenterX;
                                y = list[i].RouteCenterY;
                            }
                            else if ((x1 - x2) < 0 && (y1 - y2) < 0)
                            {
                                x = list[i].RouteCenterX - Math.Abs(list[i].RouteRadius) * 2;
                                y = list[i].RouteCenterY;
                            }
                            else if ((x1 - x2) < 0 && (y1 - y2) == 0)
                            {
                                x = list[i].RouteCenterX + list[i].RouteRadius;  // 20180717 两段圆弧的整圆
                                y = list[i].RouteCenterY + list[i].RouteRadius;
                            }
                            else if ((x1 - x2) > 0 && (y1 - y2) == 0)
                            {
                                x = list[i].RouteCenterX + list[i].RouteRadius;  // 20180725 两段圆弧的整圆
                                y = list[i].RouteCenterY + list[i].RouteRadius;
                            }
                            else if ((x1 - x2) == 0 && (y1 - y2) > 0)
                            {
                                x = list[i].RouteCenterX + list[i].RouteRadius;  // 20180717 两段圆弧的整圆
                                y = list[i].RouteCenterY + list[i].RouteRadius;
                            }
                            else if ((x1 - x2) == 0 && (y1 - y2) < 0)
                            {
                                x = list[i].RouteCenterX + list[i].RouteRadius;  // 20180717 两段圆弧的整圆
                                y = list[i].RouteCenterY + list[i].RouteRadius;
                            }
                        }
                        else
                        {
                            x = list[i].RouteCenterX - list[i].RouteRadius;
                            y = list[i].RouteCenterY - list[i].RouteRadius;
                        }


                        g.DrawArc(borderPen,
                                  gap + x * ratio,
                                  gap + y * ratio,
                                  Math.Abs(list[i].RouteRadius * ratio * 2),
                                  Math.Abs(list[i].RouteRadius * ratio * 2),
                                  angle1,
                                  sweepAngle);
                    }
                }
            }
            else
            {
                for (int i = 1; i < list.Count; i++)
                {
                    float x1, y1;
                    x1 = (i == 1) ? list[0].RouteSetMillX : list[i - 1].RouteX;
                    y1 = (i == 1) ? list[0].RouteSetMillY : list[i - 1].RouteY;

                    if (i == 1)
                    {
                        this.g.DrawEllipse(this.routePen,
                                           this.gap + (this.part.Border.PanelLength - list[0].RouteStartOffsetX) * this.ratio - list[0].RouteDiameter / 2 * this.ratio,
                                           this.gap + (list[0].RouteStartOffsetY) * this.ratio - list[0].RouteDiameter / 2 * this.ratio,
                                           list[0].RouteDiameter * this.ratio,
                                           list[0].RouteDiameter * this.ratio);
                    }

                    if (list[i].RouteBulge == 0)
                    {
                        g.DrawLine(borderPen,
                                   gap + (part.Border.PanelLength - x1) * ratio,
                                   gap + y1 * ratio,
                                   gap + (part.Border.PanelLength - list[i].RouteX) * ratio,
                                   gap + list[i].RouteY * ratio);
                    }
                    else
                    {
                        float angle1 = GetAngle(x1, y1, list[i].RouteCenterX, list[i].RouteCenterY);
                        float angle2 = GetAngle(list[i].RouteX, list[i].RouteY, list[i].RouteCenterX, list[i].RouteCenterY);

                        float sweepAngle;
                        if (list[i].RouteBulge > 0)
                        {
                            sweepAngle = angle1 > angle2 ?
                                         angle2 - angle1 :
                                         angle2 - angle1 - 360;
                        }
                        else
                        {
                            sweepAngle = angle1 < angle2 ?
                                         angle2 - angle1 :
                                         360 - angle1 + angle2;
                        }

                        if (list[i].RouteRadius < 0)
                        {
                            angle1 = angle1 - 270;

                            sweepAngle = 360 - sweepAngle;
                        }

                        //MessageBox.Show(string.Format("1x:{0},y:{1},w:{2},h:{3},sa:{4},wa:{5},radius:{6}:{7}",
                        //    gap + (part.Border.PanelLength - list[i].RouteCenterX - list[i].RouteRadius) * ratio,
                        //    gap + (list[i].RouteCenterY - list[i].RouteRadius) * ratio,
                        //    list[i].RouteRadius * ratio * 2,
                        //    list[i].RouteRadius * ratio * 2,
                        //    180 - angle1,
                        //    -sweepAngle,
                        //    list[i].RouteRadius,i)
                        //    );

                        float x2 = list[i].RouteX;
                        float y2 = list[i].RouteY;
                        float x  = 0;
                        float y  = 0;

                        if (list[i].RouteRadius < 0)
                        {
                            if ((x1 - x2) > 0 && (y1 - y2) < 0)//已验证
                            {
                                x = list[i].RouteCenterX;
                                y = list[i].RouteCenterY - Math.Abs(list[i].RouteRadius) * 2;
                            }
                            else if ((x1 - x2) > 0 && (y1 - y2) > 0) //已验证 20180331
                            {
                                x = list[i].RouteCenterX + Math.Abs(list[i].RouteRadius) * 2;
                                y = list[i].RouteCenterY - Math.Abs(list[i].RouteRadius) * 2;
                            }
                            else if ((x1 - x2) < 0 && (y1 - y2) > 0) //已验证 20180331
                            {
                                x = list[i].RouteCenterX + Math.Abs(list[i].RouteRadius) * 2;
                                y = list[i].RouteCenterY;
                            }
                            else if ((x1 - x2) < 0 && (y1 - y2) < 0)//已验证
                            {
                                x = list[i].RouteCenterX;;
                                y = list[i].RouteCenterY;
                            }
                            else if ((x1 - x2) < 0 && (y1 - y2) == 0)
                            {
                                x = list[i].RouteCenterX - list[i].RouteRadius;  // 20180713 两段圆弧的整圆
                                y = list[i].RouteCenterY + list[i].RouteRadius;
                            }
                            else if ((x1 - x2) > 0 && (y1 - y2) == 0)
                            {
                                x = list[i].RouteCenterX - list[i].RouteRadius;  // 20180713 两段圆弧的整圆
                                y = list[i].RouteCenterY + list[i].RouteRadius;
                            }
                            else if ((x1 - x2) == 0 && (y1 - y2) > 0)
                            {
                                x = list[i].RouteCenterX - list[i].RouteRadius;  // 20180713 两段圆弧的整圆
                                y = list[i].RouteCenterY + list[i].RouteRadius;
                            }
                            else if ((x1 - x2) == 0 && (y1 - y2) < 0)
                            {
                                x = list[i].RouteCenterX - list[i].RouteRadius;  // 20180713 两段圆弧的整圆
                                y = list[i].RouteCenterY + list[i].RouteRadius;
                            }
                        }
                        else
                        {
                            x = list[i].RouteCenterX + list[i].RouteRadius;  // 20180401 have check by sxg036
                            y = list[i].RouteCenterY - list[i].RouteRadius;
                        }

                        g.DrawArc(borderPen,
                                  gap + (part.Border.PanelLength - x) * ratio,
                                  gap + y * ratio,
                                  Math.Abs(list[i].RouteRadius * ratio * 2),
                                  Math.Abs(list[i].RouteRadius * ratio * 2),
                                  180 - angle1,
                                  //5);
                                  -sweepAngle);
                    }
                }
            }
        }