Esempio n. 1
0
 void ScanForCompInfo(string[] input)
 {
     for (int i = 1; i < input.Length; i++)
     {
         if (RegFunctions.IsCompBaseInfo(input[i]))
         {
             string s = input[i].Split('@')[0];
             Dictionary <string, string> d  = ScanFile(s);
             Dictionary <string, string> d2 = RegFunctions.GetDefLineDict(input[i]);
             defaultDict.Add(s, new Dictionary <string, string>());
             if (d != null)
             {
                 foreach (var kv in d2)
                 {
                     DictionaryFunctions.AddOrUpdatePair(kv, d);
                 }
                 defaultDict[s] = d;
             }
             else
             {
                 defaultDict[s] = d2;
             }
         }
     }
 }
Esempio n. 2
0
        public static Dictionary <string, List <string> > GetMacroDictAndRemove(string input, out string output)
        {
            MatchCollection mc = Regex.Matches(input, macroReg);

            output = Regex.Replace(input, macroReg, "");
            Dictionary <string, List <string> > dl = new Dictionary <string, List <string> >();

            foreach (Match m in mc)
            {
                string key   = m.Groups[1].Value;
                string value = m.Groups[2].Value;
                try
                {
                    DictionaryFunctions.GetValueOrThrowException("", dl, m.Groups[1].Value);
                    dl[key].Add(value);
                }
                catch
                {
                    dl.Add(key, new List <string>()
                    {
                        value
                    });
                }
            }

            return(dl);
        }
Esempio n. 3
0
 protected virtual void FillContent(Dictionary <string, string> source, ref CompInfoTemp output)
 {
     foreach (var kv in source)
     {
         DictionaryFunctions.UpdatePair(kv, output.content);
     }
 }
Esempio n. 4
0
        public virtual void FillContentFromDefLine(CompInfoTemp t, string defLine)
        {
            Dictionary <string, string> dt = RegFunctions.GetDefLineDict(defLine);

            foreach (var kv in dt)
            {
                DictionaryFunctions.AddOrUpdatePair(kv, t.content);
            }
        }
Esempio n. 5
0
 void FillTopoFromGeneralCompInfo(List <CompInfoTemp> topolist, string[] input)
 {
     for (int i = 0; i < topolist.Count; i++)
     {
         CompInfoTemp c = topolist[i];
         if (!defaultDict.ContainsKey(c.gname))
         {
             Dictionary <string, string> d = ScanFile(c.gname);
             if (!DictionaryFunctions.NotNullOrEmpty(d))
             {
                 throw new Exception($"未定义的部件{c.gname}");
             }
             defaultDict.Add(c.gname, d);
         }
     }
 }
Esempio n. 6
0
        protected override void FillContent(Dictionary <string, string> source, ref CompInfoTemp output)
        {
            string v;
            string name = output.rname;

            if (output.contents.Count == 0)
            {
                output.contents.Add(source);
            }
            output.contents = (from dict in output.contents
                               let t = dict.TryGetValue(KeyWordDef.AN, out v) ? v :
                                       DictionaryFunctions.GetValueOrThrowException(name, source, KeyWordDef.AN)
                                       from n in t.Split(',').Select(i => int.Parse(i))
                                       let ndict = new Dictionary <string, string>(dict)
                                                   group ndict by n into gdict orderby gdict.Key
                                                   let rdict = AggregateDicts(gdict).Concat(source)
                                                               .GroupBy(d => d.Key)
                                                               .ToDictionary(d => d.Key, d => d.First().Value)
                                                               select rdict).ToList();
            output.content = output.contents[0];
        }
Esempio n. 7
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);
            }
        }
Esempio n. 8
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);
        }