Example #1
0
        private List <RouteGroup> GetBlockGroupsOfRoute(Route route)
        {
            if (route == null)
            {
                return(new List <RouteGroup>());
            }

            List <RouteGroup> grps = new List <RouteGroup>();

            foreach (var grp in GetFreeBlockGroups())
            {
                if (grp == null)
                {
                    continue;
                }

                foreach (var r0 in grp.Routes)
                {
                    if (r0 == route)
                    {
                        grps.Add(grp);
                        break;
                    }
                }
            }

            return(grps);
        }
Example #2
0
        private List <RouteGroup> GetFreeBlockGroups()
        {
            List <Route> busyRoutes = new List <Route>();

            foreach (var r in Ctx.Project.BlockRoutes)
            {
                if (r == null)
                {
                    continue;
                }
                if (r.IsBusy)
                {
                    busyRoutes.Add(r);
                }
            }

            List <RouteGroup> grps = new List <RouteGroup>();

            foreach (var grp in Ctx.Project.BlockRouteGroups)
            {
                if (grp == null)
                {
                    continue;
                }

                foreach (var r0 in grp.Routes)
                {
                    foreach (var r1 in busyRoutes)
                    {
                        if (Route.Cross(r0, r1, true))
                        {
                            goto Outer;
                        }
                    }
                }

                grps.Add(grp);

Outer:
                continue;
            }

            return(grps);
        }
Example #3
0
        public void SetRoute(Analyze.Route route, bool state)
        {
            if (route == null)
            {
                return;
            }

            var n = route.Count;

            var trackEntity = Ctx.TrackEntity;

            for (int idx = 1; idx < n - 1; ++idx)
            {
                var r = route[idx];
                if (r == null)
                {
                    continue;
                }

                if (trackEntity?.Viewer != null)
                {
                    string themeIcon = null;

                    var trackInfo = trackEntity.Track.Get(r.X, r.Y);
                    if (trackInfo != null)
                    {
                        var themeInfo = Theme?.Get(trackInfo.ThemeId);
                        if (themeInfo != null)
                        {
                            TrackCheckResult     checkResult = null;
                            TrackInformation.S88 s88item     = null;

                            var w        = Ctx.Dispatcher.Weaver;
                            var objItems = w.GetObject(trackInfo);
                            if (objItems != null && objItems.Count > 0)
                            {
                                s88item = objItems[0] as S88;
                                var checkFnc = w.GetCheckFnc(s88item, trackInfo);
                                if (checkFnc != null)
                                {
                                    checkResult = checkFnc();
                                }
                            }

                            if (checkResult == null)
                            {
                                if (state)
                                {
                                    if (Route.HasPoint(route, trackInfo.X, trackInfo.Y))
                                    {
                                        themeIcon = themeInfo.Off.Route;
                                    }
                                    else
                                    {
                                        themeIcon = themeInfo.Off.Default;
                                    }
                                }
                                else
                                {
                                    themeIcon = themeInfo.Off.Default;
                                }
                            }
                            else
                            {
                                bool rS88 = checkResult?.State != null && checkResult.State.Value;

                                if (rS88 && s88item != null)
                                {
                                    if (s88item.IsRouted)
                                    {
                                        themeIcon = themeInfo.Active.Route;
                                    }
                                    else
                                    {
                                        themeIcon = themeInfo.Active.Occ;
                                    }
                                }
                                else
                                {
                                    if (s88item != null && s88item.IsRouted)
                                    {
                                        themeIcon = themeInfo.Off.Route;
                                    }
                                    else
                                    {
                                        if (state && Route.HasPoint(route, trackInfo.X, trackInfo.Y))
                                        {
                                            themeIcon = themeInfo.Off.Route;
                                        }
                                        else
                                        {
                                            themeIcon = themeInfo.Off.Default;
                                        }
                                    }
                                }
                            }
                        }
                    }

                    if (!string.IsNullOrEmpty(themeIcon))
                    {
                        var x           = trackInfo.X;
                        var y           = trackInfo.Y;
                        var themeId     = trackInfo.ThemeId;
                        var orientation = trackInfo.Orientation;
                        var symbol      = themeIcon;

                        var isSwitch = RailwayEssentialCore.Globals.SwitchIds.Contains(themeId);

                        if (r.HasTurn && isSwitch)
                        {
                            var parts = symbol.Split(new[] { '-' }, StringSplitOptions.RemoveEmptyEntries);
                            if (parts.Length == 2)
                            {
                                symbol = parts[0] + "-t-" + parts[1];
                            }
                            else if (parts.Length == 1)
                            {
                                symbol = parts[0] + "-t";
                            }
                        }

                        Ctx.ExecuteJs($"changeSymbol({x}, {y}, {themeId}, \"{orientation}\", \"{symbol}\");");
                    }
                }
            }
        }