Ejemplo n.º 1
0
        private static CCOLElemListData CollectAllCounters(ControllerModel controller, List <ICCOLCodePieceGenerator> pgens)
        {
            var data = new CCOLElemListData
            {
                CCOLCode    = "C_code",
                CCOLSetting = "C_max",
                CCOLTType   = "C_type"
            };

            // Collect everything
            foreach (var pgen in pgens)
            {
                if (pgen.HasCCOLElements())
                {
                    foreach (var i in pgen.GetCCOLElements(CCOLElementTypeEnum.Counter))
                    {
                        data.Elements.Add(i);
                    }
                }
            }

            if (data.Elements.Count == 0)
            {
                var ct = CCOL.Settings.CCOLGeneratorSettingsProvider.Default.GetPrefix(Settings.CCOLGeneratorSettingTypeEnum.Counter);
                data.Elements.Add(new CCOLElement {
                    Define = $"{ct}dummy", Naam = "dummy"
                });
            }

            return(data);
        }
Ejemplo n.º 2
0
        private static CCOLElemListData CollectAllHulpElementen(ControllerModel controller, List <ICCOLCodePieceGenerator> pgens)
        {
            var data = new CCOLElemListData {
                CCOLCode = "H_code"
            };

            // Collect everything

            foreach (var pgen in pgens)
            {
                if (!pgen.HasCCOLElements())
                {
                    continue;
                }
                foreach (var i in pgen.GetCCOLElements(CCOLElementTypeEnum.HulpElement))
                {
                    data.Elements.Add(i);
                }
            }

            if (data.Elements.Count == 0)
            {
                var he = Settings.CCOLGeneratorSettingsProvider.Default.GetPrefix(Settings.CCOLGeneratorSettingTypeEnum.Parameter);
                data.Elements.Add(new CCOLElement()
                {
                    Define = $"{he}dummy", Naam = "dummy"
                });
            }

            return(data);
        }
Ejemplo n.º 3
0
        public static CCOLElemListData[] CollectAllCCOLElements(ControllerModel controller, List <ICCOLCodePieceGenerator> pgens)
        {
            AlleDetectoren = new List <DetectorModel>();
            foreach (var fcm in controller.Fasen)
            {
                foreach (var dm in fcm.Detectoren)
                {
                    AlleDetectoren.Add(dm);
                }
            }
            foreach (var dm in controller.Detectoren)
            {
                AlleDetectoren.Add(dm);
            }

            var lists = new CCOLElemListData[8];

            lists[0] = CollectAllUitgangen(controller, pgens);
            lists[1] = CollectAllIngangen(controller, pgens);
            lists[2] = CollectAllHulpElementen(controller, pgens);
            lists[3] = CollectAllGeheugenElementen(controller, pgens);
            lists[4] = CollectAllTimers(controller, pgens);
            lists[5] = CollectAllCounters(controller, pgens);
            lists[6] = CollectAllSchakelaars(controller, pgens);
            lists[7] = CollectAllParameters(controller, pgens);

            return(lists);
        }
Ejemplo n.º 4
0
        private static CCOLElemListData CollectAllUitgangen(ControllerModel controller, List <ICCOLCodePieceGenerator> pgens)
        {
            var data = new CCOLElemListData {
                CCOLCode = "US_code"
            };

            // Segment display elements
            foreach (var item in controller.Data.SegmentenDisplayBitmapData)
            {
                var _item = item.BitmapData as IOElementModel;
                data.Elements.Add(new CCOLElement()
                {
                    Define = _item.GetBitmapCoordinaatOutputDefine(), Naam = item.Naam
                });
            }

            foreach (var pgen in pgens)
            {
                if (pgen.HasCCOLElements())
                {
                    foreach (var i in pgen.GetCCOLElements(CCOLElementTypeEnum.Uitgang))
                    {
                        data.Elements.Add(i);
                    }
                }
            }

            return(data);
        }
Ejemplo n.º 5
0
        private static CCOLElemListData CollectAllParameters(ControllerModel controller, List <ICCOLCodePieceGenerator> pgens)
        {
            var data = new CCOLElemListData
            {
                CCOLCode    = "PRM_code",
                CCOLSetting = "PRM",
                CCOLTType   = "PRM_type"
            };

            // Collect everything
            data.Elements.Add(new CCOLElement()
            {
                Define = "prmfb", Naam = "FB", Instelling = controller.Data.Fasebewaking, TType = CCOLElementTimeTypeEnum.TS_type
            });

            foreach (var pgen in pgens)
            {
                if (pgen.HasCCOLElements())
                {
                    foreach (var i in pgen.GetCCOLElements(CCOLElementTypeEnum.Parameter))
                    {
                        data.Elements.Add(i);
                    }
                }
            }

            return(data);
        }
Ejemplo n.º 6
0
        private static CCOLElemListData CollectAllTimers(ControllerModel controller, List <ICCOLCodePieceGenerator> pgens)
        {
            var data = new CCOLElemListData
            {
                CCOLCode    = "T_code",
                CCOLSetting = "T_max",
                CCOLTType   = "T_type"
            };

            foreach (var pgen in pgens)
            {
                if (pgen.HasCCOLElements())
                {
                    foreach (var i in pgen.GetCCOLElements(CCOLElementTypeEnum.Timer))
                    {
                        data.Elements.Add(i);
                    }
                }
            }

            if (data.Elements.Count == 0)
            {
                data.Elements.Add(new CCOLElement {
                    Define = "tdummy", Naam = "dummy"
                });
            }

            return(data);
        }
Ejemplo n.º 7
0
        private static CCOLElemListData CollectAllGeheugenElementen(ControllerModel controller, List <ICCOLCodePieceGenerator> pgens)
        {
            var data = new CCOLElemListData {
                CCOLCode = "MM_code"
            };

            data.Elements.Add(new CCOLElement()
            {
                Define = "mperiod", Naam = "PERIOD"
            });

            // Collect everything
            foreach (var pgen in pgens)
            {
                if (pgen.HasCCOLElements())
                {
                    foreach (var i in pgen.GetCCOLElements(CCOLElementTypeEnum.GeheugenElement))
                    {
                        data.Elements.Add(i);
                    }
                }
            }

            return(data);
        }
Ejemplo n.º 8
0
        private static CCOLElemListData CollectAllHulpElementen(ControllerModel controller, List <ICCOLCodePieceGenerator> pgens)
        {
            var data = new CCOLElemListData {
                CCOLCode = "H_code"
            };

            // Collect everything

            foreach (var pgen in pgens)
            {
                if (pgen.HasCCOLElements())
                {
                    foreach (var i in pgen.GetCCOLElements(CCOLElementTypeEnum.HulpElement))
                    {
                        data.Elements.Add(i);
                    }
                }
            }

            if (data.Elements.Count == 0)
            {
                data.Elements.Add(new CCOLElement()
                {
                    Define = "hedummy", Naam = "dummy"
                });
            }

            return(data);
        }
Ejemplo n.º 9
0
        public static CCOLElemListData[] CollectAllCCOLElements(ControllerModel controller, List <ICCOLCodePieceGenerator> pgens)
        {
            var lists = new CCOLElemListData[8];

            lists[0] = CollectAllUitgangen(controller, pgens);
            lists[1] = CollectAllIngangen(controller, pgens);
            lists[2] = CollectAllHulpElementen(controller, pgens);
            lists[3] = CollectAllGeheugenElementen(controller, pgens);
            lists[4] = CollectAllTimers(controller, pgens);
            lists[5] = CollectAllCounters(controller, pgens);
            lists[6] = CollectAllSchakelaars(controller, pgens);
            lists[7] = CollectAllParameters(controller, pgens);

            return(lists);
        }
Ejemplo n.º 10
0
        private static CCOLElemListData CollectAllIngangen(ControllerModel controller, List <ICCOLCodePieceGenerator> pgens)
        {
            var data = new CCOLElemListData {
                CCOLCode = "IS_code"
            };

            foreach (var pgen in pgens)
            {
                if (pgen.HasCCOLElements())
                {
                    foreach (var i in pgen.GetCCOLElements(CCOLElementTypeEnum.Ingang))
                    {
                        data.Elements.Add(i);
                    }
                }
            }

            return(data);
        }
Ejemplo n.º 11
0
        private static CCOLElemListData CollectAllSchakelaars(ControllerModel controller, List <ICCOLCodePieceGenerator> pgens)
        {
            var data = new CCOLElemListData
            {
                CCOLCode    = "SCH_code",
                CCOLSetting = "SCH"
            };

            foreach (var pgen in pgens)
            {
                if (pgen.HasCCOLElements())
                {
                    foreach (var i in pgen.GetCCOLElements(CCOLElementTypeEnum.Schakelaar))
                    {
                        data.Elements.Add(i);
                    }
                }
            }

            return(data);
        }
Ejemplo n.º 12
0
        private static CCOLElemListData CollectAllParameters(ControllerModel controller, List <ICCOLCodePieceGenerator> pgens)
        {
            var data = new CCOLElemListData
            {
                CCOLCode    = "PRM_code",
                CCOLSetting = "PRM",
                CCOLTType   = "PRM_type"
            };

            // Collect everything
            foreach (var pgen in pgens)
            {
                if (pgen.HasCCOLElements())
                {
                    foreach (var i in pgen.GetCCOLElements(CCOLElementTypeEnum.Parameter))
                    {
                        data.Elements.Add(i);
                    }
                }
            }

            return(data);
        }
Ejemplo n.º 13
0
        public string GenerateSourceFiles(ControllerModel c, string sourcefilepath)
        {
            if (Directory.Exists(sourcefilepath))
            {
                CCOLGeneratorSettingsProvider.Default.Reset();
                CCOLElementCollector.Reset();

                _uspf  = CCOLGeneratorSettingsProvider.Default.GetPrefix("us");
                _ispf  = CCOLGeneratorSettingsProvider.Default.GetPrefix("is");
                _fcpf  = CCOLGeneratorSettingsProvider.Default.GetPrefix("fc");
                _dpf   = CCOLGeneratorSettingsProvider.Default.GetPrefix("d");
                _tpf   = CCOLGeneratorSettingsProvider.Default.GetPrefix("t");
                _schpf = CCOLGeneratorSettingsProvider.Default.GetPrefix("sch");
                _hpf   = CCOLGeneratorSettingsProvider.Default.GetPrefix("h");
                _cpf   = CCOLGeneratorSettingsProvider.Default.GetPrefix("c");
                _prmpf = CCOLGeneratorSettingsProvider.Default.GetPrefix("prm");

                foreach (var pgen in PieceGenerators)
                {
                    pgen.CollectCCOLElements(c);
                }

                _alleDetectoren = new List <DetectorModel>();
                foreach (var fcm in c.Fasen)
                {
                    foreach (var dm in fcm.Detectoren)
                    {
                        _alleDetectoren.Add(dm);
                    }
                }
                foreach (var dm in c.Detectoren)
                {
                    _alleDetectoren.Add(dm);
                }
                foreach (var dm in c.SelectieveDetectoren)
                {
                    _alleDetectoren.Add(dm);
                }

                var CCOLElementLists = CCOLElementCollector.CollectAllCCOLElements(c, PieceGenerators);

                if (CCOLElementLists == null || CCOLElementLists.Length != 8)
                {
                    throw new IndexOutOfRangeException("Error collecting CCOL elements from controller.");
                }

                foreach (var pl in TLCGenPluginManager.Default.ApplicationPlugins)
                {
                    if ((pl.Item1 & TLCGenPluginElems.IOElementProvider) != TLCGenPluginElems.IOElementProvider)
                    {
                        continue;
                    }

                    var elemprov = pl.Item2 as ITLCGenElementProvider;
                    var elems    = elemprov?.GetAllItems();
                    if (elems == null)
                    {
                        continue;
                    }
                    foreach (var elem in elems)
                    {
                        var ccolElement = elem as CCOLElement;
                        if (ccolElement == null)
                        {
                            continue;
                        }
                        switch (ccolElement.Type)
                        {
                        case CCOLElementTypeEnum.Uitgang: CCOLElementLists[0].Elements.Add(ccolElement); break;

                        case CCOLElementTypeEnum.Ingang: CCOLElementLists[1].Elements.Add(ccolElement); break;

                        case CCOLElementTypeEnum.HulpElement: CCOLElementLists[2].Elements.Add(ccolElement); break;

                        case CCOLElementTypeEnum.GeheugenElement: CCOLElementLists[3].Elements.Add(ccolElement); break;

                        case CCOLElementTypeEnum.Timer: CCOLElementLists[4].Elements.Add(ccolElement); break;

                        case CCOLElementTypeEnum.Counter: CCOLElementLists[5].Elements.Add(ccolElement); break;

                        case CCOLElementTypeEnum.Schakelaar: CCOLElementLists[6].Elements.Add(ccolElement); break;

                        case CCOLElementTypeEnum.Parameter: CCOLElementLists[7].Elements.Add(ccolElement); break;
                        }
                    }
                }

                _uitgangen         = CCOLElementLists[0];
                _ingangen          = CCOLElementLists[1];
                _hulpElementen     = CCOLElementLists[2];
                _geheugenElementen = CCOLElementLists[3];
                _timers            = CCOLElementLists[4];
                _counters          = CCOLElementLists[5];
                _schakelaars       = CCOLElementLists[6];
                _parameters        = CCOLElementLists[7];

                foreach (var l in CCOLElementLists)
                {
                    l.SetMax();
                }

                CCOLElementCollector.AddAllMaxElements(CCOLElementLists);

                File.WriteAllText(Path.Combine(sourcefilepath, $"{c.Data.Naam}reg.c"), GenerateRegC(c), Encoding.Default);
                if (!c.Data.NietGebruikenBitmap)
                {
                    File.WriteAllText(Path.Combine(sourcefilepath, $"{c.Data.Naam}dpl.c"), GenerateDplC(c), Encoding.Default);
                }
                File.WriteAllText(Path.Combine(sourcefilepath, $"{c.Data.Naam}tab.c"), GenerateTabC(c), Encoding.Default);
                File.WriteAllText(Path.Combine(sourcefilepath, $"{c.Data.Naam}sim.c"), GenerateSimC(c), Encoding.Default);
                File.WriteAllText(Path.Combine(sourcefilepath, $"{c.Data.Naam}sys.h"), GenerateSysH(c), Encoding.Default);
                if (c.RoBuGrover.ConflictGroepen?.Count > 0)
                {
                    File.WriteAllText(Path.Combine(sourcefilepath, $"{c.Data.Naam}rgv.c"), GenerateRgvC(c), Encoding.Default);
                }
                if (c.PTPData.PTPKoppelingen?.Count > 0)
                {
                    File.WriteAllText(Path.Combine(sourcefilepath, $"{c.Data.Naam}ptp.c"), GeneratePtpC(c), Encoding.Default);
                }
                if (c.OVData.OVIngrepen.Any() ||
                    c.OVData.HDIngrepen.Any())
                {
                    File.WriteAllText(Path.Combine(sourcefilepath, $"{c.Data.Naam}ov.c"), GenerateOvC(c), Encoding.Default);
                }
                if (c.HalfstarData.IsHalfstar)
                {
                    File.WriteAllText(Path.Combine(sourcefilepath, $"{c.Data.Naam}hst.c"), GenerateHstC(c), Encoding.Default);
                }
                if (c.Data.PracticeOmgeving)
                {
                    File.WriteAllText(Path.Combine(sourcefilepath, "ccolreg.txt"), GeneratePraticeCcolReg(c), Encoding.Default);
                    File.WriteAllText(Path.Combine(sourcefilepath, "ccolreg2.txt"), GeneratePraticeCcolReg2(c), Encoding.Default);
                }

                WriteAndReviseAdd(Path.Combine(sourcefilepath, $"{c.Data.Naam}reg.add"), c, GenerateRegAdd, GenerateRegAddHeader, Encoding.Default);
                WriteAndReviseAdd(Path.Combine(sourcefilepath, $"{c.Data.Naam}tab.add"), c, GenerateTabAdd, GenerateTabAddHeader, Encoding.Default);
                if (!c.Data.NietGebruikenBitmap)
                {
                    WriteAndReviseAdd(Path.Combine(sourcefilepath, $"{c.Data.Naam}dpl.add"), c, GenerateDplAdd, GenerateDplAddHeader, Encoding.Default);
                }
                WriteAndReviseAdd(Path.Combine(sourcefilepath, $"{c.Data.Naam}sim.add"), c, GenerateSimAdd, GenerateSimAddHeader, Encoding.Default);
                WriteAndReviseAdd(Path.Combine(sourcefilepath, $"{c.Data.Naam}sys.add"), c, GenerateSysAdd, GenerateSysAddHeader, Encoding.Default);
                if (c.OVData.OVIngrepen.Count > 0 || c.OVData.HDIngrepen.Count > 0)
                {
                    WriteAndReviseAdd(Path.Combine(sourcefilepath, $"{c.Data.Naam}ov.add"), c, GenerateOvAdd, GenerateOvAddHeader, Encoding.Default);
                }
                if (c.HalfstarData.IsHalfstar)
                {
                    WriteAndReviseAdd(Path.Combine(sourcefilepath, $"{c.Data.Naam}hst.add"), c, GenerateHstAdd, GenerateHstAddHeader, Encoding.Default);
                }

                CopySourceIfNeeded("extra_func.c", sourcefilepath);
                CopySourceIfNeeded("extra_func.h", sourcefilepath);
                CopySourceIfNeeded("ccolfunc.c", sourcefilepath);
                CopySourceIfNeeded("ccolfunc.h", sourcefilepath);
                CopySourceIfNeeded("detectie.c", sourcefilepath);
                CopySourceIfNeeded("uitstuur.c", sourcefilepath);
                CopySourceIfNeeded("uitstuur.h", sourcefilepath);

                if (c.Data.FixatieData.FixatieMogelijk)
                {
                    CopySourceIfNeeded("fixatie.c", sourcefilepath);
                    CopySourceIfNeeded("fixatie.h", sourcefilepath);
                }

                if (c.OVData.OVIngrepen.Count > 0 || c.OVData.HDIngrepen.Count > 0)
                {
                    CopySourceIfNeeded("extra_func_ov.c", sourcefilepath);
                    CopySourceIfNeeded("extra_func_ov.h", sourcefilepath);
                }

                if (c.InterSignaalGroep.Nalopen.Any())
                {
                    CopySourceIfNeeded("gkvar.c", sourcefilepath);
                    CopySourceIfNeeded("gkvar.h", sourcefilepath);
                    CopySourceIfNeeded("nlvar.c", sourcefilepath);
                    CopySourceIfNeeded("nlvar.h", sourcefilepath);
                    CopySourceIfNeeded("nalopen.c", sourcefilepath);
                    CopySourceIfNeeded("nalopen.h", sourcefilepath);
                }

                if (c.InterSignaalGroep.Voorstarten.Any() || c.InterSignaalGroep.Gelijkstarten.Any())
                {
                    CopySourceIfNeeded("syncfunc.c", sourcefilepath);
                    CopySourceIfNeeded("syncvar.c", sourcefilepath);
                    CopySourceIfNeeded("syncvar.h", sourcefilepath);
                }

                if (c.OVData.OVIngrepen.Any() || c.OVData.HDIngrepen.Any())
                {
                    CopySourceIfNeeded("ov.c", sourcefilepath);
                    CopySourceIfNeeded("ov.h", sourcefilepath);
                }

                if (c.RoBuGrover.ConflictGroepen.Any())
                {
                    CopySourceIfNeeded("rgv_overslag.c", sourcefilepath);
                    CopySourceIfNeeded("rgvfunc.c", sourcefilepath);
                    CopySourceIfNeeded("rgvvar.c", sourcefilepath);
                    CopySourceIfNeeded("winmg.c", sourcefilepath);
                    CopySourceIfNeeded("winmg.h", sourcefilepath);
                }

                if (c.HalfstarData.IsHalfstar)
                {
                    CopySourceIfNeeded("halfstar.c", sourcefilepath);
                    CopySourceIfNeeded("halfstar.h", sourcefilepath);
                    CopySourceIfNeeded("halfstar_ov.c", sourcefilepath);
                    CopySourceIfNeeded("halfstar_ov.h", sourcefilepath);
                    CopySourceIfNeeded("halfstar_help.c", sourcefilepath);
                    CopySourceIfNeeded("halfstar_help.h", sourcefilepath);
                }

                if (c.Fasen.Any(x => x.WachttijdVoorspeller))
                {
                    CopySourceIfNeeded("wtv_testwin.c", sourcefilepath);
                }

                foreach (var pl in PieceGenerators)
                {
                    var fs = pl.GetSourcesToCopy();
                    if (fs != null)
                    {
                        foreach (var f in fs)
                        {
                            CopySourceIfNeeded(f, sourcefilepath);
                        }
                    }
                }

                if (Directory.Exists(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "SourceFilesToCopy\\")))
                {
                    try
                    {
                        foreach (var f in Directory.EnumerateFiles(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "SourceFilesToCopy\\")))
                        {
                            try
                            {
                                var lines = File.ReadAllLines(f);
                                if (lines != null && lines.Length > 0 && lines[0].StartsWith("CONDITION="))
                                {
                                    var copy = false;
                                    var cond = lines[0].Replace("CONDITION=", "");
                                    switch (cond)
                                    {
                                    case "ALWAYS":
                                        copy = true;
                                        break;

                                    case "OV":
                                        copy = (c.OVData.OVIngrepen.Count > 0 || c.OVData.HDIngrepen.Count > 0);
                                        break;

                                    case "SYNC":
                                        copy = (c.InterSignaalGroep.Gelijkstarten.Count > 0 ||
                                                c.InterSignaalGroep.Voorstarten.Count > 0);
                                        break;

                                    case "FIXATIE":
                                        copy = (c.Data.FixatieData.FixatieMogelijk);
                                        break;

                                    case "NALOPEN":
                                        copy = (c.InterSignaalGroep.Nalopen.Count > 0);
                                        break;

                                    case "RGV":
                                        copy = (c.RoBuGrover.SignaalGroepInstellingen.Count > 0);
                                        break;
                                    }

                                    if (!copy || File.Exists(Path.Combine(sourcefilepath, Path.GetFileName(f))))
                                    {
                                        continue;
                                    }

                                    var fileLines = new string[lines.Length - 1];
                                    Array.Copy(lines, 1, fileLines, 0, lines.Length - 1);
                                    File.WriteAllLines(Path.Combine(sourcefilepath, Path.GetFileName(f)), fileLines, Encoding.Default);
                                }
                            }
                            catch
                            {
                                // ignored
                            }
                        }
                    }
                    catch
                    {
                        // ignored
                    }
                }

                return("CCOL source code gegenereerd");
            }
            return($"Map {sourcefilepath} niet gevonden. Niets gegenereerd.");
        }
Ejemplo n.º 14
0
        private string GetAllElementsTabCLines(CCOLElemListData data)
        {
            StringBuilder sb = new StringBuilder();

            int pad1 = ts.Length + data.CCOLCodeWidth + 2 + data.DefineMaxWidth; // 3: [ ]
            int pad2 = data.NameMaxWidth + 6;                                    // 6: space = space " " ;
            int pad3 = data.CCOLSettingWidth + 3 + data.DefineMaxWidth;          // 3: space [ ]
            int pad4 = data.SettingMaxWidth + 4;                                 // 4: space = space ;
            int pad5 = data.CCOLTTypeWidth + 3 + data.DefineMaxWidth;            // 3: space [ ]
            int pad6 = data.CommentsMaxWidth;
            int pad7 = data.TTypeMaxWidth + 4;                                   // 4: ' = ;'

            foreach (CCOLElement elem in data.Elements)
            {
                if (elem.Dummy)
                {
                    continue;
                }

                if (!string.IsNullOrWhiteSpace(elem.Naam))
                {
                    sb.Append($"{ts}{data.CCOLCode}[{elem.Define}]".PadRight(pad1));
                    sb.Append($" = \"{elem.Naam}\";".PadRight(pad2));
                    if (!string.IsNullOrEmpty(data.CCOLSetting) && elem.Instelling.HasValue)
                    {
                        sb.Append($" {data.CCOLSetting}[{elem.Define}]".PadRight(pad3));
                        sb.Append($" = {elem.Instelling};".PadRight(pad4));
                    }
                    if (!string.IsNullOrEmpty(data.CCOLTType) && elem.TType != CCOLElementTimeTypeEnum.None)
                    {
                        sb.Append($" {data.CCOLTType}[{elem.Define}]".PadRight(pad5));
                        sb.Append($" = {elem.TType};");
                    }
                    else
                    {
                        sb.Append("".PadRight(pad5 + pad7));
                    }
                    if (!string.IsNullOrWhiteSpace(elem.Commentaar))
                    {
                        sb.Append($" /* ");
                        sb.Append($"{ elem.Commentaar}".PadRight(pad6));
                        sb.Append($" */");
                    }
                    sb.AppendLine();
                }
            }

            if (data.Elements.Count > 0 && data.Elements.Any(x => x.Dummy))
            {
                sb.AppendLine("#if (!defined AUTOMAAT && !defined AUTOMAAT_TEST)");
                foreach (CCOLElement delem in data.Elements)
                {
                    if (!delem.Dummy)
                    {
                        continue;
                    }
                    sb.Append($"{ts}{data.CCOLCode}[{delem.Define}]".PadRight(pad1));
                    sb.Append($" = \"{delem.Naam}\";".PadRight(pad2));
                    if (!string.IsNullOrEmpty(data.CCOLSetting) && delem.Instelling.HasValue)
                    {
                        sb.Append($" {data.CCOLSetting}[{delem.Define}]".PadRight(pad3));
                        sb.Append($" = {delem.Instelling};".PadRight(pad4));
                    }
                    if (!string.IsNullOrEmpty(data.CCOLTType) && delem.TType != CCOLElementTimeTypeEnum.None)
                    {
                        sb.Append($" {data.CCOLTType}[{delem.Define}]".PadRight(pad5));
                        sb.Append($" = {delem.TType};");
                    }
                    else
                    {
                        sb.Append("".PadRight(pad5));
                    }
                    if (!string.IsNullOrWhiteSpace(delem.Commentaar))
                    {
                        sb.Append($" /*");
                        sb.Append($"{ delem.Commentaar}".PadRight(pad6));
                        sb.Append($" */");
                    }
                    sb.AppendLine();
                }
                sb.AppendLine("#endif");
            }

            return(sb.ToString());
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Generates all "sys.h" lines for a given instance of CCOLElemListData.
        /// The function loops all elements in the Elements member.
        /// </summary>
        /// <param name="data">The instance of CCOLElemListData to use for generation</param>
        /// <param name="numberdefine">Optional: this string will be used as follows:
        /// - if it is null, lines are generated like this: #define ElemName #
        /// - if it is not null, it goes like this: #define ElemName (numberdefine + #)</param>
        /// <returns></returns>
        private string GetAllElementsSysHLines(CCOLElemListData data, string numberdefine = null, List <CCOLElement> extraElements = null)
        {
            var sb = new StringBuilder();

            var pad1  = data.DefineMaxWidth + $"{ts}#define  ".Length;
            var pad2  = data.Elements.Count.ToString().Length;
            int pad3  = data.CommentsMaxWidth;
            var index = 0;

            foreach (var elem in data.Elements)
            {
                if (elem.Dummy || Regex.IsMatch(elem.Define, @"[A-Z]+MAX"))
                {
                    continue;
                }

                sb.Append($"{ts}#define {elem.Define} ".PadRight(pad1));
                if (string.IsNullOrWhiteSpace(numberdefine))
                {
                    sb.Append($"{index}".PadLeft(pad2));
                }
                else
                {
                    sb.Append($"({numberdefine} + ");
                    sb.Append($"{index}".PadLeft(pad2));
                    sb.Append(")");
                }
                if (!string.IsNullOrWhiteSpace(elem.Commentaar))
                {
                    sb.Append($" /*");
                    sb.Append($"{elem.Commentaar}".PadRight(pad3));
                    sb.Append($" */");
                }
                sb.AppendLine();
                ++index;
            }
            var indexautom = index;

            if (data.Elements.Count > 0 && data.Elements.Any(x => x.Dummy))
            {
                sb.AppendLine("#if (!defined AUTOMAAT && !defined AUTOMAAT_TEST) || defined VISSIM");
                foreach (var elem in data.Elements)
                {
                    if (!elem.Dummy || Regex.IsMatch(elem.Define, @"[A-Z]+MAX"))
                    {
                        continue;
                    }

                    sb.Append($"{ts}#define {elem.Define} ".PadRight(pad1));
                    if (string.IsNullOrWhiteSpace(numberdefine))
                    {
                        sb.Append($"{indexautom}".PadLeft(pad2));
                    }
                    else
                    {
                        sb.Append($"({numberdefine} + ");
                        sb.Append($"{indexautom}".PadLeft(pad2));
                        sb.Append(")");
                    }
                    if (!string.IsNullOrWhiteSpace(elem.Commentaar))
                    {
                        sb.Append($" /*");
                        sb.Append($"{elem.Commentaar}".PadRight(pad3));
                        sb.Append($" */");
                    }
                    sb.AppendLine();
                    ++indexautom;
                }
                sb.Append($"{ts}#define {data.Elements.Last().Define} ".PadRight(pad1));
                if (string.IsNullOrWhiteSpace(numberdefine))
                {
                    sb.AppendLine($"{indexautom}".PadLeft(pad2));
                }
                else
                {
                    sb.Append($"({numberdefine} + ");
                    sb.Append($"{indexautom}".PadLeft(pad2));
                    sb.AppendLine(")");
                }
                sb.AppendLine("#else");
                sb.Append($"{ts}#define {data.Elements.Last().Define} ".PadRight(pad1));
                if (string.IsNullOrWhiteSpace(numberdefine))
                {
                    sb.AppendLine($"{index}".PadLeft(pad2));
                }
                else
                {
                    sb.Append($"({numberdefine} + ");
                    sb.Append($"{index}".PadLeft(pad2));
                    sb.AppendLine(")");
                }
                sb.AppendLine("#endif");
            }
            else if (data.Elements.Count > 0)
            {
                sb.Append($"{ts}#define {data.Elements.Last().Define} ".PadRight(pad1));
                if (string.IsNullOrWhiteSpace(numberdefine))
                {
                    sb.AppendLine($"{index}".PadLeft(pad2));
                }
                else
                {
                    sb.Append($"({numberdefine} + ");
                    sb.Append($"{index}".PadLeft(pad2));
                    sb.AppendLine(")");
                }
            }

            return(sb.ToString());
        }
Ejemplo n.º 16
0
        public string GenerateSourceFiles(ControllerModel c, string sourcefilepath)
        {
            if (Directory.Exists(sourcefilepath))
            {
                try
                {
                    CCOLGeneratorSettingsProvider.Default.Reset();
                    CCOLElementCollector.Reset();

                    _uspf  = CCOLGeneratorSettingsProvider.Default.GetPrefix("us");
                    _ispf  = CCOLGeneratorSettingsProvider.Default.GetPrefix("is");
                    _fcpf  = CCOLGeneratorSettingsProvider.Default.GetPrefix("fc");
                    _dpf   = CCOLGeneratorSettingsProvider.Default.GetPrefix("d");
                    _tpf   = CCOLGeneratorSettingsProvider.Default.GetPrefix("t");
                    _schpf = CCOLGeneratorSettingsProvider.Default.GetPrefix("sch");
                    _hpf   = CCOLGeneratorSettingsProvider.Default.GetPrefix("h");
                    _mpf   = CCOLGeneratorSettingsProvider.Default.GetPrefix("m");
                    _cpf   = CCOLGeneratorSettingsProvider.Default.GetPrefix("c");
                    _prmpf = CCOLGeneratorSettingsProvider.Default.GetPrefix("prm");

                    foreach (var pgen in PieceGenerators)
                    {
                        pgen.CollectCCOLElements(c);
                    }

                    _alleDetectoren = new List <DetectorModel>();
                    foreach (var fcm in c.Fasen)
                    {
                        foreach (var dm in fcm.Detectoren)
                        {
                            _alleDetectoren.Add(dm);
                        }
                    }
                    foreach (var dm in c.Detectoren)
                    {
                        _alleDetectoren.Add(dm);
                    }
                    foreach (var dm in c.SelectieveDetectoren)
                    {
                        _alleDetectoren.Add(dm);
                    }

                    var CCOLElementLists = CCOLElementCollector.CollectAllCCOLElements(c, PieceGenerators.OrderBy(x => x.ElementGenerationOrder).ToList());

                    CollectAllIO();

                    if (CCOLElementLists == null || CCOLElementLists.Length != 8)
                    {
                        throw new IndexOutOfRangeException("Error collecting CCOL elements from controller.");
                    }

                    foreach (var pl in TLCGenPluginManager.Default.ApplicationPlugins)
                    {
                        if ((pl.Item1 & TLCGenPluginElems.IOElementProvider) != TLCGenPluginElems.IOElementProvider)
                        {
                            continue;
                        }

                        var elemprov = pl.Item2 as ITLCGenElementProvider;
                        var elems    = elemprov?.GetAllItems();
                        if (elems == null)
                        {
                            continue;
                        }
                        foreach (var elem in elems)
                        {
                            var ccolElement = elem as CCOLElement;
                            if (ccolElement == null)
                            {
                                continue;
                            }
                            switch (ccolElement.Type)
                            {
                            case CCOLElementTypeEnum.Uitgang: CCOLElementLists[0].Elements.Add(ccolElement); break;

                            case CCOLElementTypeEnum.Ingang: CCOLElementLists[1].Elements.Add(ccolElement); break;

                            case CCOLElementTypeEnum.HulpElement: CCOLElementLists[2].Elements.Add(ccolElement); break;

                            case CCOLElementTypeEnum.GeheugenElement: CCOLElementLists[3].Elements.Add(ccolElement); break;

                            case CCOLElementTypeEnum.Timer: CCOLElementLists[4].Elements.Add(ccolElement); break;

                            case CCOLElementTypeEnum.Counter: CCOLElementLists[5].Elements.Add(ccolElement); break;

                            case CCOLElementTypeEnum.Schakelaar: CCOLElementLists[6].Elements.Add(ccolElement); break;

                            case CCOLElementTypeEnum.Parameter: CCOLElementLists[7].Elements.Add(ccolElement); break;
                            }
                        }
                    }

                    _uitgangen         = CCOLElementLists[0];
                    _ingangen          = CCOLElementLists[1];
                    _hulpElementen     = CCOLElementLists[2];
                    _geheugenElementen = CCOLElementLists[3];
                    _timers            = CCOLElementLists[4];
                    _counters          = CCOLElementLists[5];
                    _schakelaars       = CCOLElementLists[6];
                    _parameters        = CCOLElementLists[7];

                    foreach (var l in CCOLElementLists)
                    {
                        l.SetMax();
                    }

                    CCOLElementCollector.AddAllMaxElements(CCOLElementLists);

                    File.WriteAllText(Path.Combine(sourcefilepath, $"{c.Data.Naam}reg.c"), GenerateRegC(c), Encoding.Default);
                    _allFiles.Add($"{c.Data.Naam}reg.c");
                    if (!c.Data.NietGebruikenBitmap)
                    {
                        File.WriteAllText(Path.Combine(sourcefilepath, $"{c.Data.Naam}dpl.c"), GenerateDplC(c), Encoding.Default);
                    }
                    File.WriteAllText(Path.Combine(sourcefilepath, $"{c.Data.Naam}tab.c"), GenerateTabC(c), Encoding.Default);
                    _allFiles.Add($"{c.Data.Naam}tab.c");
                    File.WriteAllText(Path.Combine(sourcefilepath, $"{c.Data.Naam}sim.c"), GenerateSimC(c), Encoding.Default);
                    File.WriteAllText(Path.Combine(sourcefilepath, $"{c.Data.Naam}sys.h"), GenerateSysH(c), Encoding.Default);
                    _allFiles.Add($"{c.Data.Naam}sys.h");
                    if (c.RoBuGrover.ConflictGroepen?.Count > 0)
                    {
                        File.WriteAllText(Path.Combine(sourcefilepath, $"{c.Data.Naam}rgv.c"), GenerateRgvC(c), Encoding.Default);
                        _allFiles.Add($"{c.Data.Naam}rgv.c");
                    }
                    if (c.PTPData.PTPKoppelingen?.Count > 0)
                    {
                        File.WriteAllText(Path.Combine(sourcefilepath, $"{c.Data.Naam}ptp.c"), GeneratePtpC(c), Encoding.Default);
                        _allFiles.Add($"{c.Data.Naam}ptp.c");
                    }
                    if (c.PrioData.PrioIngreepType == Models.Enumerations.PrioIngreepTypeEnum.GeneriekePrioriteit &&
                        (c.PrioData.PrioIngrepen.Any() ||
                         c.PrioData.HDIngrepen.Any()))
                    {
                        File.WriteAllText(Path.Combine(sourcefilepath, $"{c.Data.Naam}prio.c"), GeneratePrioC(c), Encoding.Default);
                        _allFiles.Add($"{c.Data.Naam}prio.c");
                    }
                    if (c.HalfstarData.IsHalfstar)
                    {
                        File.WriteAllText(Path.Combine(sourcefilepath, $"{c.Data.Naam}hst.c"), GenerateHstC(c), Encoding.Default);
                        _allFiles.Add($"{c.Data.Naam}hst.c");
                    }
                    if (c.Data.GenererenEnkelCompilatieBestand)
                    {
                        File.WriteAllText(Path.Combine(sourcefilepath, $"{c.Data.Naam}regeling.c"), GenerateRegelingC(c), Encoding.Default);
                        _allFiles.Add($"{c.Data.Naam}regeling.c");
                    }
                    if (c.Data.PracticeOmgeving)
                    {
                        File.WriteAllText(Path.Combine(sourcefilepath, "ccolreg.txt"), GeneratePraticeCcolReg(c), Encoding.Default);
                        File.WriteAllText(Path.Combine(sourcefilepath, "ccolreg2.txt"), GeneratePraticeCcolReg2(c), Encoding.Default);
                    }
                    if (c.RISData.RISToepassen)
                    {
                        File.WriteAllText(Path.Combine(sourcefilepath, $"{c.Data.Naam}rissim.c"), GenerateRisSimC(c), Encoding.Default);
                    }

                    WriteAndReviseAdd(Path.Combine(sourcefilepath, $"{c.Data.Naam}reg.add"), c, GenerateRegAdd, GenerateRegAddHeader, Encoding.Default);
                    _allFiles.Add($"{c.Data.Naam}reg.add");
                    ReviseRegAdd(Path.Combine(sourcefilepath, $"{c.Data.Naam}reg.add"), c, Encoding.Default);
                    WriteAndReviseAdd(Path.Combine(sourcefilepath, $"{c.Data.Naam}tab.add"), c, GenerateTabAdd, GenerateTabAddHeader, Encoding.Default);
                    _allFiles.Add($"{c.Data.Naam}tab.add");
                    if (!c.Data.NietGebruikenBitmap)
                    {
                        WriteAndReviseAdd(Path.Combine(sourcefilepath, $"{c.Data.Naam}dpl.add"), c, GenerateDplAdd, GenerateDplAddHeader, Encoding.Default);
                    }
                    WriteAndReviseAdd(Path.Combine(sourcefilepath, $"{c.Data.Naam}sim.add"), c, GenerateSimAdd, GenerateSimAddHeader, Encoding.Default);
                    WriteAndReviseAdd(Path.Combine(sourcefilepath, $"{c.Data.Naam}sys.add"), c, GenerateSysAdd, GenerateSysAddHeader, Encoding.Default);
                    _allFiles.Add($"{c.Data.Naam}sys.add");
                    ReviseSysAdd(Path.Combine(sourcefilepath, $"{c.Data.Naam}sys.add"), c, Encoding.Default);
                    if (c.PrioData.PrioIngrepen.Count > 0 || c.PrioData.HDIngrepen.Count > 0)
                    {
                        if (c.PrioData.PrioIngreepType == Models.Enumerations.PrioIngreepTypeEnum.GeneriekePrioriteit)
                        {
                            WriteAndReviseAdd(Path.Combine(sourcefilepath, $"{c.Data.Naam}prio.add"), c, GeneratePrioAdd, GeneratePrioAddHeader, Encoding.Default);
                            _allFiles.Add($"{c.Data.Naam}prio.add");
                        }
                    }
                    if (c.HalfstarData.IsHalfstar)
                    {
                        WriteAndReviseAdd(Path.Combine(sourcefilepath, $"{c.Data.Naam}hst.add"), c, GenerateHstAdd, GenerateHstAddHeader, Encoding.Default);
                        _allFiles.Add($"{c.Data.Naam}hst.add");
                    }

                    CopySourceIfNeeded(c, "extra_func.c", sourcefilepath);
                    CopySourceIfNeeded(c, "extra_func.h", sourcefilepath);
                    CopySourceIfNeeded(c, "ccolfunc.c", sourcefilepath);
                    CopySourceIfNeeded(c, "ccolfunc.h", sourcefilepath);
                    CopySourceIfNeeded(c, "detectie.c", sourcefilepath);
                    CopySourceIfNeeded(c, "uitstuur.c", sourcefilepath);
                    CopySourceIfNeeded(c, "uitstuur.h", sourcefilepath);

                    if (c.Data.FixatieData.FixatieMogelijk)
                    {
                        CopySourceIfNeeded(c, "fixatie.c", sourcefilepath);
                        CopySourceIfNeeded(c, "fixatie.h", sourcefilepath);
                    }

                    if (c.PrioData.PrioIngrepen.Count > 0 || c.PrioData.HDIngrepen.Count > 0)
                    {
                        CopySourceIfNeeded(c, "extra_func_prio.c", sourcefilepath);
                        CopySourceIfNeeded(c, "extra_func_prio.h", sourcefilepath);
                    }

                    if (c.InterSignaalGroep.Nalopen.Any())
                    {
                        CopySourceIfNeeded(c, "gkvar.c", sourcefilepath);
                        CopySourceIfNeeded(c, "gkvar.h", sourcefilepath);
                        CopySourceIfNeeded(c, "nlvar.c", sourcefilepath);
                        CopySourceIfNeeded(c, "nlvar.h", sourcefilepath);
                        CopySourceIfNeeded(c, "nalopen.c", sourcefilepath);
                        CopySourceIfNeeded(c, "nalopen.h", sourcefilepath);
                    }

                    switch (c.Data.SynchronisatiesType)
                    {
                    case SynchronisatiesTypeEnum.SyncFunc when(c.InterSignaalGroep.Voorstarten.Any() || c.InterSignaalGroep.Gelijkstarten.Any()):
                        CopySourceIfNeeded(c, "syncfunc.c", sourcefilepath);

                        CopySourceIfNeeded(c, "syncvar.c", sourcefilepath);
                        CopySourceIfNeeded(c, "syncvar.h", sourcefilepath);
                        break;

                    case SynchronisatiesTypeEnum.RealFunc when(c.InterSignaalGroep.Voorstarten.Any() ||
                                                               c.InterSignaalGroep.Gelijkstarten.Any() ||
                                                               c.InterSignaalGroep.Nalopen.Any(x => x.MaximaleVoorstart.HasValue) ||
                                                               c.InterSignaalGroep.LateReleases.Any()):
                        CopySourceIfNeeded(c, "realfunc.c", sourcefilepath);

                        break;
                    }

                    if (c.PrioData.PrioIngreepType == Models.Enumerations.PrioIngreepTypeEnum.GeneriekePrioriteit &&
                        (c.PrioData.PrioIngrepen.Any() || c.PrioData.HDIngrepen.Any()))
                    {
                        CopySourceIfNeeded(c, "prio.c", sourcefilepath);
                        CopySourceIfNeeded(c, "prio.h", sourcefilepath);
                    }

                    if (c.RoBuGrover.ConflictGroepen.Any())
                    {
                        CopySourceIfNeeded(c, "rgv_overslag.c", sourcefilepath);
                        CopySourceIfNeeded(c, "rgvfunc.c", sourcefilepath);
                        CopySourceIfNeeded(c, "rgvvar.c", sourcefilepath);
                        CopySourceIfNeeded(c, "winmg.c", sourcefilepath);
                        CopySourceIfNeeded(c, "winmg.h", sourcefilepath);
                    }

                    if (c.HalfstarData.IsHalfstar)
                    {
                        CopySourceIfNeeded(c, "halfstar.c", sourcefilepath);
                        CopySourceIfNeeded(c, "halfstar.h", sourcefilepath);
                        CopySourceIfNeeded(c, "halfstar_prio.c", sourcefilepath);
                        CopySourceIfNeeded(c, "halfstar_prio.h", sourcefilepath);
                    }

                    if (c.Fasen.Any(x => x.WachttijdVoorspeller))
                    {
                        CopySourceIfNeeded(c, "wtv_testwin.c", sourcefilepath);
                    }

                    if (c.RISData.RISToepassen)
                    {
                        CopySourceIfNeeded(c, "risappl.c", sourcefilepath);
                        CopySourceIfNeeded(c, "extra_func_ris.c", sourcefilepath);
                        CopySourceIfNeeded(c, "extra_func_ris.h", sourcefilepath);
                    }

                    if (c.StarData.ToepassenStar)
                    {
                        CopySourceIfNeeded(c, "starfunc.c", sourcefilepath);
                        CopySourceIfNeeded(c, "starfunc.h", sourcefilepath);
                        CopySourceIfNeeded(c, "starvar.c", sourcefilepath);
                        CopySourceIfNeeded(c, "starvar.h", sourcefilepath);
                    }

                    foreach (var pl in PieceGenerators)
                    {
                        var fs = pl.GetSourcesToCopy();
                        if (fs != null)
                        {
                            foreach (var f in fs)
                            {
                                CopySourceIfNeeded(c, f, sourcefilepath);
                            }
                        }
                    }

                    if (Directory.Exists(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "SourceFilesToCopy\\")))
                    {
                        try
                        {
                            foreach (var f in Directory.EnumerateFiles(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "SourceFilesToCopy\\")))
                            {
                                try
                                {
                                    var lines = File.ReadAllLines(f);
                                    if (lines != null && lines.Length > 0 && lines[0].StartsWith("CONDITION="))
                                    {
                                        var copy = false;
                                        var cond = lines[0].Replace("CONDITION=", "");
                                        copy = cond switch
                                        {
                                            "ALWAYS" => true,
                                            "OV" => (c.PrioData.PrioIngrepen.Count > 0 || c.PrioData.HDIngrepen.Count > 0),
                                            "SYNC" => (c.InterSignaalGroep.Gelijkstarten.Count > 0 || c.InterSignaalGroep.Voorstarten.Count > 0),
                                            "FIXATIE" => (c.Data.FixatieData.FixatieMogelijk),
                                            "NALOPEN" => (c.InterSignaalGroep.Nalopen.Count > 0),
                                            "RGV" => (c.RoBuGrover.SignaalGroepInstellingen.Count > 0),
                                            _ => copy
                                        };

                                        if (!copy || File.Exists(Path.Combine(sourcefilepath, Path.GetFileName(f))))
                                        {
                                            continue;
                                        }

                                        var fileLines = new string[lines.Length - 1];
                                        Array.Copy(lines, 1, fileLines, 0, lines.Length - 1);
                                        File.WriteAllLines(Path.Combine(sourcefilepath, Path.GetFileName(f)), fileLines, Encoding.Default);
                                        _allFiles.Add(Path.GetFileName(f));
                                    }
                                }
                                catch
                                {
                                    // ignored
                                }
                            }
                        }
                        catch
                        {
                            // ignored
                        }
                    }

                    if (c.Data.GenererenIncludesLijst)
                    {
                        GenerateIncludesList(c, Path.Combine(sourcefilepath, $"{c.Data.Naam}_sources_list.txt"));
                    }
                }
                catch (Exception e)
                {
                    TLCGenDialogProvider.Default.ShowMessageBox(
                        "Er is een fout opgetreden tijdens genereren. " +
                        $"Controlleer of alle te genereren bestanden overschreven kunnen worden.\n\nOorspronkelijke foutmelding:\n{e.Message}", "Fout tijdens genereren", MessageBoxButton.OK);
                }

                return("CCOL source code gegenereerd");
            }
            return($"Map {sourcefilepath} niet gevonden. Niets gegenereerd.");
        }