Example #1
0
        private void btnBatchCreate_Click(object sender, EventArgs e)
        {
            var x = HoleOperate.XStart;
            var y = HoleOperate.YStart;
            var w = HoleOperate.WStart;
            var b = HoleOperate.BStart;
            var c = HoleOperate.CStart;

            for (int i = 0; i < HoleOperate.Repeat; i++)
            {
                var holeInfo = new HoleInfo()
                {
                    IsJiaGong = HoleOperate.IsJiagong,
                    X         = x + HoleOperate.XInterval,
                    Y         = y + HoleOperate.YInterval,
                    W         = w + HoleOperate.WInterval,
                    B         = b + HoleOperate.BInterval,
                    C         = c + HoleOperate.CInterval,
                    AxisType  = HoleOperate.AxisType,
                    Param     = HoleOperate.Param
                };
                x += HoleOperate.XInterval;
                y += HoleOperate.YInterval;
                w += HoleOperate.WInterval;
                b += HoleOperate.BInterval;
                c += HoleOperate.CInterval;
                HoleCollection.Insert(this.bindingSourceHole.Position + 1 + i, holeInfo);
            }
            bindingSourceHole.ResetBindings(false);
        }
Example #2
0
        public static HoleCollection LoadFromFile(string fileName)
        {
            BaseInfoCollection collection     = new BaseInfoCollection(fileName);
            HoleCollection     holeCollection = new HoleCollection();

            for (int i = 0; i < collection.Count; i++)
            {
                var baseInfo = collection[i];
                if (baseInfo is SingleMoveInfo)
                {
                    var singleMove = baseInfo as SingleMoveInfo;
                    var holeInfo   = new HoleInfo()
                    {
                        X     = singleMove.X,
                        Y     = singleMove.Y,
                        W     = singleMove.W,
                        B     = singleMove.B,
                        C     = singleMove.C,
                        Param = singleMove.Param
                    };
                    if (i < collection.Count - 1 && collection[i + 1] is M21Info)
                    {
                        holeInfo.IsJiaGong = true;
                    }
                    holeCollection.Add(holeInfo);
                }
            }
            return(holeCollection);
        }
Example #3
0
        public object Clone()
        {
            var newCollection = new HoleCollection();

            foreach (var item in this)
            {
                newCollection.Add(item.Clone() as HoleInfo);
            }
            return(newCollection);
        }
Example #4
0
 public FormHoleEdit(HoleCollection collection, ContraInfo contra, string axisType)
 {
     InitializeComponent();
     this.bindingSourceHole.DataSource = collection.Clone();
     this.bindingSource.DataSource     = new HoleOperateInfo()
     {
         AxisType = axisType
     };
     this.bindingSource2.DataSource = new HoleOperateInfo()
     {
         AxisType = axisType
     };
     this.contra   = contra;
     this.axisType = axisType;
 }
Example #5
0
        public void btnAddHole_Click(object sender, EventArgs e)
        {
            var holeInfo = new HoleInfo()
            {
                IsJiaGong = true,
                X         = contra.GetActPosX(axisType),
                Y         = contra.GetActPosY(axisType),
                W         = contra.GetActPosW(axisType),
                B         = contra.GetActPosB(axisType),
                C         = contra.GetActPosC(axisType),
                AxisType  = axisType,
                Param     = "E1"
            };

            HoleCollection.Insert(this.bindingSourceHole.Position + 1, holeInfo);
            bindingSourceHole.ResetBindings(false);
        }
Example #6
0
 public static void SaveCnc(HoleCollection holes, string fileName, string scriptMode)
 {
     if (File.Exists(fileName))
     {
         File.Delete(fileName);
     }
     using (FileStream fs = new FileStream(fileName, FileMode.Create, FileAccess.Write))
     {
         using (StreamWriter sw = new StreamWriter(fs))
         {
             sw.WriteLine("O1234");
             foreach (var item in holes)
             {
                 if (scriptMode == "2")
                 {
                     sw.Write(item.AxisType);
                     if (item.X.HasValue) sw.Write(string.Format("	{0:0.###}", item.X));
                     if (item.Y.HasValue) sw.Write(string.Format("	{0:0.###}", item.Y));
                     if (item.W.HasValue) sw.Write(string.Format("	{0:0.###}", item.W));
                     if (item.B.HasValue) sw.Write(string.Format("	{0:0.###}", item.B));
                     if (item.C.HasValue) sw.Write(string.Format("	{0:0.###}", item.C));
                     if (item.Param != null) sw.Write(string.Format("	{0}", item.Param));
                     if (item.IsJiaGong == true) sw.Write(string.Format("	{0}", "M21"));
                     sw.WriteLine();
                 }
                 else
                 {
                     sw.WriteLine(item.AxisType);
                     sw.Write("G0");
                     if (item.X.HasValue) sw.Write(string.Format(" X{0:0.###}", item.X));
                     if (item.Y.HasValue) sw.Write(string.Format(" Y{0:0.###}", item.Y));
                     if (item.W.HasValue) sw.Write(string.Format(" W{0:0.###}", item.W));
                     if (item.B.HasValue) sw.Write(string.Format(" B{0:0.###}", item.B));
                     if (item.C.HasValue) sw.Write(string.Format(" C{0:0.###}", item.C));
                     sw.WriteLine();
                     if (item.IsJiaGong)
                     {
                         sw.WriteLine("M21");
                     }
                 }
             }
             sw.WriteLine("M30");
         }
     }
 }
Example #7
0
        private void btnBatchCreate2_Click(object sender, EventArgs e)
        {
            var     operate = HoleOperate2;
            var     x       = operate.XStart;
            var     y       = operate.YStart;
            var     w       = operate.WStart;
            var     b       = operate.BStart;
            var     c       = operate.CStart;
            var     xe      = operate.XInterval;
            var     ye      = operate.YInterval;
            var     we      = operate.WInterval;
            var     be      = operate.BInterval;
            var     ce      = operate.CInterval;
            decimal?xs      = (xe - x) / (operate.Repeat + 1);
            decimal?ys      = (ye - y) / (operate.Repeat + 1);
            decimal?ws      = (we - w) / (operate.Repeat + 1);
            decimal?bs      = (be - b) / (operate.Repeat + 1);
            decimal?cs      = (ce - c) / (operate.Repeat + 1);

            for (int i = 0; i < operate.Repeat; i++)
            {
                var holeInfo = new HoleInfo()
                {
                    IsJiaGong = operate.IsJiagong,
                    X         = x + xs,
                    Y         = y + ys,
                    W         = w + ws,
                    B         = b + bs,
                    C         = c + cs,
                    AxisType  = operate.AxisType,
                    Param     = operate.Param
                };
                x += xs;
                y += ys;
                w += ws;
                b += bs;
                c += cs;
                HoleCollection.Insert(this.bindingSourceHole.Position + 1 + i, holeInfo);
            }
            bindingSourceHole.ResetBindings(false);
        }
Example #8
0
 public PNCInfo()
 {
     Holes    = new HoleCollection();
     Params   = new ParamCollection();
     ThrowSet = new ThrowSetInfo();
 }
Example #9
0
        public static HoleCollection LoadCnc(string fileName, string mode)
        {
            using (FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read))
            {
                using (StreamReader sr = new StreamReader(fs))
                {
                    var collection = new HoleCollection();
                    var axisType = "G54";
                    string line = sr.ReadLine().Replace(" ", "");
                    if (string.IsNullOrEmpty(line) || !line.StartsWith("O1234"))
                    {
                        throw new WarningException(L.R("PNCHelper.FileError1", "文件格式错误:缺少开始符!"));
                    }
                    HoleInfo holeInfo = null;
                    int index = 2;
                    Regex reg = new Regex(@"([X,Y,W,B,C])([-]?\d+(\.\d+)?)");
                    while (true)
                    {
                        line = sr.ReadLine().Replace(" ", "");
                        if (!string.IsNullOrEmpty(line))
                        {
                            if (mode == "2")
                            {
                                if (line.StartsWith("G"))
                                {
                                    holeInfo = new HoleInfo() { IsJiaGong = false, AxisType = axisType };
                                    string[] list = line.Split(new char[] { '	' }, StringSplitOptions.RemoveEmptyEntries);
                                    if (list.Length != 7 && list.Length != 8)
                                    {
                                        throw new WarningException("无效的脚本:" + line);
                                    }
                                    holeInfo.AxisType = list[0];
                                    holeInfo.X = Convert.ToDecimal(list[1]);
                                    holeInfo.Y = Convert.ToDecimal(list[2]);
                                    holeInfo.W = Convert.ToDecimal(list[3]);
                                    holeInfo.B = Convert.ToDecimal(list[4]);
                                    holeInfo.C = Convert.ToDecimal(list[5]);
                                    holeInfo.Param = list[6];
                                    if (list.Length == 8)
                                        holeInfo.IsJiaGong = list[7] == "M21";
                                    collection.Add(holeInfo);
                                }
                                else if ((line.StartsWith("M11") || line.StartsWith("M21")) && holeInfo != null)
                                {
                                    holeInfo.IsJiaGong = true;
                                }
                                else if (line.StartsWith("M30"))
                                {
                                    break;
                                }
                                else
                                {
                                    throw new WarningException(L.R("PNCHelper.FileError3", "文件格式错误:无法解析的行[{0}],行{0}"), line, index);
                                }
                            }
                            else
                            {
                                if (line.StartsWith("G0"))
                                {
                                    holeInfo = new HoleInfo() { IsJiaGong = false, AxisType = axisType };
                                    MatchCollection matchs = reg.Matches(line);
                                    foreach (Match match in matchs)
                                    {
                                        switch (match.Groups[1].Value)
                                        {
                                            case "X": holeInfo.X = Convert.ToDecimal(match.Groups[2].Value); break;
                                            case "Y": holeInfo.Y = Convert.ToDecimal(match.Groups[2].Value); break;
                                            case "W": holeInfo.W = Convert.ToDecimal(match.Groups[2].Value); break;
                                            case "B": holeInfo.B = Convert.ToDecimal(match.Groups[2].Value); break;
                                            case "C": holeInfo.C = Convert.ToDecimal(match.Groups[2].Value); break;
                                        }
                                    }
                                    collection.Add(holeInfo);
                                }
                                else if (line == "G54" || line == "G55" || line == "G56" || line == "G57" || line == "G58" || line == "G59")
                                {
                                    axisType = line;
                                }
                                else if ((line.StartsWith("M11") || line.StartsWith("M21")) && holeInfo != null)
                                {
                                    holeInfo.IsJiaGong = true;
                                }
                                else if (line.StartsWith("M30"))
                                {
                                    break;
                                }
                                else
                                {
                                    throw new WarningException(L.R("PNCHelper.FileError3", "文件格式错误:无法解析的行[{0}],行{0}"), line, index);
                                }
                            }

                            index++;
                        }
                    }
                    return collection;
                }
            }
        }