Esempio n. 1
0
        protected override void WriteComp(CompInfoTemp c, int compBufferNo, List <int> homeBufferNo, ref string scripts)
        {
            string CHM = c.content[KeyWordDef.HM];

            if (!CHM.Contains("D"))
            {
                TextFunctions.AppendMultiRepeat(
                    ref scripts,
                    "SingleAxisHome",
                    new List <Dictionary <string, string> >()
                {
                    new Dictionary <string, string>()
                    {
                        { "#AxisNo#", GetAxisNo(c).ToString() },
                        { "#NAME#", GetAxisName(c, false) },
                        { "@HG", GetHomeBufferNo(c, homeBufferNo).ToString() },
                    }
                },
                    CompManager.GetBufferIndex(compBufferNo, scripts),
                    CompManager.GetBufferCount(compBufferNo, scripts)
                    );
            }
            bool CN = int.Parse(c.content[KeyWordDef.CN]) > 0 ? true : false;

            if (!CN)
            {
                return;
            }
            int index = GetHomeIndex(c, homeBufferNo, scripts);
            int count = GetHomeCount(c, homeBufferNo, scripts);

            List <Dictionary <string, string> > compDictList = new List <Dictionary <string, string> >()
            {
                new Dictionary <string, string>()
                {
                    { "#AxisNo#", GetAxisNo(c).ToString() },
                    { "#BCNo#", compBufferNo.ToString() },
                    { "@CS", c.content[KeyWordDef.CS] },
                    { "@CT", c.content[KeyWordDef.CT] },
                    { "@CND", c.content[KeyWordDef.CND] },
                    { "#NAME#", GetAxisName(c, false) },
                    { "@HG", GetHomeBufferNo(c, homeBufferNo).ToString() },
                }
            };
            string repeatKeyWord = "CompRepeat";

            TextFunctions.AppendMultiRepeat(ref scripts, repeatKeyWord, compDictList, index, count);
            index = CompManager.GetBufferIndex(compBufferNo, scripts);
            count = CompManager.GetBufferCount(compBufferNo, scripts);
            TextFunctions.AppendMultiRepeat(ref scripts, repeatKeyWord, compDictList, index, count);
            index = CompManager.GetBufferIndex(ST.DEF, scripts);
            TextFunctions.AppendMultiRepeat(ref scripts, repeatKeyWord, compDictList, index);
        }
Esempio n. 2
0
        protected override void WriteLaser(CompInfoTemp c, int laserBufferNo, ref string scripts)
        {
            int index = CompManager.GetBufferIndex(laserBufferNo, scripts);
            int count = CompManager.GetBufferCount(laserBufferNo, scripts);

            List <Dictionary <string, string> > LCMDictList = new List <Dictionary <string, string> >()
            {
                new Dictionary <string, string>()
                {
                    { "#AxisNo#", (c.axisStart + 3).ToString() },
                }
            };
            string repeatKeyWord = "LaserRepeat_LCM_" + c.content[KeyWordDef.LM];

            TextFunctions.AppendMultiRepeat(ref scripts, repeatKeyWord, LCMDictList, index, count);
        }
Esempio n. 3
0
        protected override void WriteAuto(CompInfoTemp c, int autoBufferNo, ref string scripts)
        {
            int index = CompManager.GetBufferIndex(autoBufferNo, scripts);
            int count = CompManager.GetBufferIndex(autoBufferNo, scripts);
            List <Dictionary <string, string> > autoDictList;

            autoDictList = new List <Dictionary <string, string> >()
            {
                c.content.ToDictionary(k => '@' + k.Key, v => v.Value)
            };
            autoDictList.First().Add("#AxisNo#", c.axisStart.ToString());
            string repeatKeyWord = "CANRepeat";

            TextFunctions.AppendMultiRepeat(ref scripts, repeatKeyWord, autoDictList, index, count);

            base.WriteAuto(c, autoBufferNo, ref scripts);
        }
Esempio n. 4
0
        protected override void WriteAuto(CompInfoTemp c, int autoBufferNo, ref string scripts)
        {
            ParseTopo(c.content[KeyWordDef.TOP]);
            //Write IO Config
            string KeyWord    = "IORepeat";
            int    startIndex = CompManager.GetBufferIndex(ST.AUTO, scripts);
            List <Dictionary <string, string> > IODictList = GenerateDictList(c, out int IIndex, out int OIndex);

            IODictList = IODictList.OrderByDescending(d => d["#IOType#"]).Select((d, i) =>
            {
                if (i != 0)
                {
                    d.Remove("#StartIndex#");
                }
                return(d);
            }).ToList();
            CheckIndexes(IODictList);
            TextFunctions.AppendMultiRepeat(ref scripts, KeyWord, IODictList, startIndex);

            Dictionary <string, string> OADict = new Dictionary <string, string>
            {
                { "OA1", "BeforeUnstopRepeat" },
                { "OA2", "DuringEMGRepeat" },
                { "OA3", "EscapeEMGRepeat" },
            };

            foreach (var kv in OADict)
            {
                if (c.content.ContainsKey(kv.Key))
                {
                    KeyWord    = kv.Value;
                    IODictList = GetOADictList(c, kv.Key);
                    TextFunctions.AppendMultiRepeat(ref scripts, KeyWord, IODictList, startIndex);
                }
            }

            if (!c.content.ContainsKey("EMG"))
            {
                c.content.Add("EMG", "EMG");
            }
            TextFunctions.ReplaceSingle(ref scripts, c.content, startIndex);
            TextFunctions.AppendMultiNoRepeat(ref scripts, c.content, startIndex);
        }
Esempio n. 5
0
        protected virtual void WriteAutoSingle(CompInfoTemp c, int autoBufferNo, ref string scripts)
        {
            bool MU    = int.Parse(c.content[KeyWordDef.MU]) > 0 ? true : false;
            int  index = CompManager.GetBufferIndex(autoBufferNo, scripts);
            int  count = CompManager.GetBufferIndex(autoBufferNo, scripts);
            List <Dictionary <string, string> > autoDictList;

            if (MU)
            {
                autoDictList = new List <Dictionary <string, string> >()
                {
                    new Dictionary <string, string>()
                    {
                        { "#AxisNo#", GetAxisNo(c).ToString() },
                    }
                };
                string repeatKeyWord = "CommutRepeat";
                TextFunctions.AppendMultiRepeat(ref scripts, repeatKeyWord, autoDictList, index, count);
            }

            base.WriteAuto(c, autoBufferNo, ref scripts);
        }
Esempio n. 6
0
        public string Handle(string[] input)
        {
            input = ScanMacro(input);
            List <string> inputs = input.ToList();

            for (int m = 0; m < inputs.Count; m++)
            {
                inputs[m] = Regex.Replace(inputs[m], RegFunctions.defLineCommentReg, "");
                if (Regex.IsMatch(inputs[m], RegFunctions.defLineCommentReg) || string.IsNullOrEmpty(inputs[m]))
                {
                    inputs.RemoveAt(m);
                    m--;
                }
            }
            input = inputs.ToArray();
            List <CompInfoTemp> topolist = new List <CompInfoTemp>();

            topolist = ScanTopo(input);
            ScanForCompInfo(input);
            FillTopoFromGeneralCompInfo(topolist, input);
            FillTopoFromUserCompInfo(topolist, input);
            Dictionary <ST, string> STContent = (from kv in STFileName
                                                 select new { kv.Key, b = File.ReadAllText(defaultPRGPath + kv.Value) })
                                                .ToDictionary(a => a.Key, a => a.b);

            gTopoList = topolist.Concat(gTopoList).ToList();
            string script = CManager.GenerateScript(STContent, gTopoList);

            script = TextFunctions.RemoveInvalidLine(script, DeleteOptions.ALL);
            script = TextFunctions.TrimStrInList(script);
            script = TextFunctions.SubSpecial(script);
            string date = DateTime.Now.ToString("MM/dd/yyyy hh:mm tt", new CultureInfo("en-US"));
            string head = $"#/ Controller version = 2.70\r\n#/ Date = {date}\r\n#/ " +
                          $"User remarks = Automatically generated by ScriptGen\r\n";

            script = script.Insert(0, head);
            return(script);
        }
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
 public override void WriteScript(CompInfoTemp c, Dictionary <ST, List <int> > scriptNo, ref string scripts)
 {
     TextFunctions.AppendMultiRepeat(ref scripts, c.rname, c.contents);
 }