Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            List <string> paths = args.ToList();

            while (true)
            {
                foreach (string p in paths)
                {
                    MainHandler MH = new MainHandler();
                    if (p == "Q" || p == "q")
                    {
                        return;
                    }
                    string path = p.Trim('"');
                    try
                    {
                        string[] fileStrs = File.ReadAllLines(path);
                        string   prg      = MH.Handle(fileStrs);
                        string   name     = Path.GetDirectoryName(path) + '\\' + Path.GetFileNameWithoutExtension(path) + ".prg";
                        if (!File.Exists(name))
                        {
                            File.Create(name).Close();
                            File.WriteAllText(name, prg);
                            Console.WriteLine($"写入{name}成功");
                        }
                        else
                        {
                            while (true)
                            {
                                Console.Write($"文件{name}已存在,是否覆盖(y/n):");
                                string input = Console.ReadLine();
                                if (input == "y" || input == "Y")
                                {
                                    File.WriteAllText(name, prg);
                                    Console.WriteLine($"写入{name}成功");
                                    break;
                                }
                                else if (input == "N" || input == "n")
                                {
                                    break;
                                }
                                else
                                {
                                    Console.WriteLine("无效输入");
                                }
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.Message);
                    }
                }
                paths.Clear();
                Console.WriteLine("\r\n请将单个文件拖入");
                paths.Add(Console.ReadLine());
            }
        }
Ejemplo n.º 2
0
        protected override void WriteHome(CompInfoTemp c, List <int> homeBufferNo, ref string scripts)
        {
            string CHM = c.content[KeyWordDef.HM];

            if (CHM.Contains("D"))
            {
                return;
            }

            int HG      = GetHomeBufferNo(c, homeBufferNo);
            int HGIndex = GetHomeIndex(c, homeBufferNo, scripts);
            int count   = GetHomeCount(c, homeBufferNo, scripts);

            TextFunctions.ReplaceSingle(ref scripts, "BH", HG.ToString(), HGIndex, count);

            string HM = "";

            if (CHM.Contains("L"))
            {
                HM += "L";
            }
            else if (CHM.Contains("R"))
            {
                HM += "R";
            }
            else
            {
                throw new Exception("未定义回零方向");
            }

            if (CHM.Contains("I"))
            {
                HM += "I";
            }

            List <string> homeSpeedList = c.content[KeyWordDef.HS].Split(",".ToArray(),
                                                                         StringSplitOptions.RemoveEmptyEntries).ToList();
            List <Dictionary <string, string> > homeDictList = new List <Dictionary <string, string> >()
            {
                new Dictionary <string, string>()
                {
                    { "#AxisNo#", GetAxisNo(c).ToString() },
                    { "#NSpeed#", homeSpeedList[0] },
                    { "#HSpeed#", homeSpeedList.Count > 1 ? homeSpeedList[1] : (int.Parse(homeSpeedList[0]) / 2).ToString() },
                    { "@HP", c.content.ContainsKey(KeyWordDef.HP)? c.content[KeyWordDef.HP] : "0" },
                    { "@HF", c.content[KeyWordDef.HF] },
                    { "#HomingMethod#", HM },
                    { "#GoSafe#", c.content.ContainsKey(KeyWordDef.HP)? "" : "!" },
                    { "#NAME#", GetAxisName(c) },
                    { "#COMP#", int.Parse(c.content[KeyWordDef.CN]) > 0 ? "" : "!" },
                }
            };
            string repeatKeyWord = "HomeRepeat";

            TextFunctions.AppendMultiRepeat(ref scripts, repeatKeyWord, homeDictList, HGIndex, count);

            if (CHM.Contains("Z") || c.content.ContainsKey(KeyWordDef.SZ))
            {
                TextFunctions.ReplaceSingle(ref scripts, "ZLimitSafeLine__", "", HGIndex, count);
            }

            if (CHM.Contains("Z"))
            {
                homeDictList = new List <Dictionary <string, string> >()
                {
                    new Dictionary <string, string>()
                    {
                        { "#AxisNo#", GetAxisNo(c).ToString() },
                        { "@BH", HG.ToString() },
                    }
                };
                repeatKeyWord = "ZAxisSafeRepeat";
                TextFunctions.AppendMultiRepeat(ref scripts, repeatKeyWord, homeDictList, HGIndex, count);
                repeatKeyWord = "ZLimitSafeRepeat";
                TextFunctions.AppendMultiRepeat(ref scripts, repeatKeyWord, homeDictList, HGIndex, count);
            }

            if (c.content.ContainsKey(KeyWordDef.SZ))
            {
                List <int> li = MainHandler.GetAxisNoByCompName(c.content[KeyWordDef.SZ]);
                if (li.Count == 0)
                {
                    throw new Exception($"部件{c.rname}属性{KeyWordDef.SZ}错误:{c.content[KeyWordDef.SZ]}");
                }
                List <Dictionary <string, string> > SZDictList = new List <Dictionary <string, string> >();
                foreach (int i in li)
                {
                    if (!DictionaryFunctions.GetValueOrAddNewKey(homeSZDict, HG, new List <int>())
                        .Contains(i))
                    {
                        homeSZDict[HG].Add(i);
                        SZDictList.Add(new Dictionary <string, string>()
                        {
                            { "#AxisNo#", i.ToString() },
                            { "@BH", HG.ToString() },
                        });
                    }
                }
                repeatKeyWord = "ZLimitSafeRepeat";
                TextFunctions.AppendMultiRepeat(ref scripts, repeatKeyWord, SZDictList, HGIndex, count);
            }
        }