Exemplo n.º 1
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);
            }
        }
Exemplo n.º 2
0
        List <CompInfoTemp> ScanTopo(string[] input)
        {
            List <Dictionary <string, string> > strDict = RegFunctions.GetTopoDict(input[0]);

            if (strDict.Count <= 0)
            {
                throw new Exception("首行不是拓补定义");
            }
            List <CompInfoTemp>              topoList       = new List <CompInfoTemp>();
            Dictionary <string, int>         compMaxNumDict = new Dictionary <string, int>();
            Dictionary <string, List <int> > checkNumDict   = new Dictionary <string, List <int> >();

            foreach (var kv in strDict)
            {
                List <int> compNumList = new List <int>();
                string     compName    = kv.First().Key;
                string     sv          = kv.First().Value;
                int        i;
                DictionaryFunctions.GetValueOrAddNewKey(checkNumDict, compName, new List <int>());
                if (sv.Contains('$'))
                {
                    List <int> li;
                    try
                    {
                        li = sv.Split('$')[1].Split(',').Select(s => int.Parse(s)).ToList();
                    }
                    catch
                    {
                        throw new Exception($"无效值{compName}:{sv}");
                    }
                    int num = int.TryParse(sv.Split('$')[0], out num) ? num : li.Count;
                    for (i = 1; i <= num; i++)
                    {
                        if (i <= li.Count)
                        {
                            compNumList.Add(li[i - 1]);
                        }
                        else
                        {
                            compNumList.Add(li.Last() + i - li.Count);
                        }
                    }
                }
                else
                {
                    int value = int.Parse(kv.First().Value);
                    i = DictionaryFunctions.GetValueOrAddNewKey(compMaxNumDict, compName, 0) + 1;
                    compMaxNumDict[compName] += value;
                    for (; i <= compMaxNumDict[compName]; i++)
                    {
                        compNumList.Add(i);
                    }
                }
                ;
                foreach (int j in compNumList)
                {
                    i = j;
                    if (checkNumDict[compName].Contains(i))
                    {
                        throw new Exception($"重复编号{compName}:{i}");
                    }
                    checkNumDict[compName].Add(i);
                    CompInfoTemp temp = new CompInfoTemp()
                    {
                        rname = compName + i.ToString(),
                        gname = compName,
                    };
                    topoList.Add(temp);
                }
            }
            return(topoList);
        }