/// <summary> /// Default ctor /// </summary> public RouteEventSetEditorForm(IRailway railway, IModule module, IRouteEventSet events) { this.railway = railway; this.module = module; InitializeComponent(); Initialize(events); }
/// <summary> /// Default ctor /// </summary> public DisconnectModuleMenuItem(IRailway railway, IModule module, ItemContext context) { this.railway = railway; this.module = module; this.context = context; Text = Strings.DisconnectModuleMenuItemText; }
/// <summary> /// Try to find all routes that span multiple modules /// </summary> private IEnumerable <IRouteState> ResolveInterModuleRoutes(IRailway railway, IEnumerable <IModule> modules) { var startRoutes = modules.SelectMany(x => x.Routes.Where(r => r.IsFromBlockToEdge())).ToList(); var result = startRoutes.SelectMany(startRoute => ResolveRoutesStartingWith(railway, startRoute)).ToList(); return(result); }
/// <summary> /// Connect to the given application state /// </summary> internal void Initialize(AppState appState, IRailway railway, ItemContext context) { this.appState = appState; this.railway = railway; this.context = context; ReloadNodes(); }
/// <summary> /// Default ctor /// </summary> public LocSetEditorForm(IRailway railway, IEntitySet3 <ILoc> locs) { this.locs = locs; InitializeComponent(); if (railway != null) { foreach (var loc in railway.GetLocs().Where(x => !locs.Contains(x)).OrderBy(x => x.Description)) { lbAll.Items.Add(loc); } foreach (var loc in locs.OrderBy(x => x.Description)) { lbSet.Items.Add(loc); } if (lbAll.Items.Count > 0) { lbAll.SelectedIndex = 0; } if (lbSet.Items.Count > 0) { lbSet.SelectedIndex = 0; } } UpdateComponents(); }
/// <summary> /// Select the command stations to choose from /// </summary> /// <param name="railway"></param> /// <returns></returns> protected virtual IEnumerable <ICommandStation> SelectCommandStations(IRailway railway) { return(railway.CommandStations.Select(x => { ICommandStation cs; return x.TryResolve(out cs) ? cs : null; }).Where(x => x != null)); }
/// <summary> /// Default ctor /// </summary> public BehaviorNode(IRailway railway, IRouteEventBehavior behavior) { this.railway = railway; AppliesTo = behavior.AppliesTo.Clone(true); StateBehavior = behavior.StateBehavior; SpeedBehavior = behavior.SpeedBehavior; UpdateText(); }
/// <summary> /// Default ctor /// </summary> public BehaviorNode(IRailway railway) { this.railway = railway; AppliesTo = new LocStandardPredicate(); StateBehavior = DefaultValues.DefaultRouteEventBehaviorStateBehavior; SpeedBehavior = DefaultValues.DefaultRouteEventBehaviorSpeedBehavior; UpdateText(); }
public StandardPredicateItem(ILocStandardPredicate entity, IRailway railway) : base(entity) { includes = new OrPredicatesItem(entity.Includes, railway); includes.Text = "Includes"; Nodes.Add(includes); excludes = new OrPredicatesItem(entity.Excludes, railway); excludes.Text = "Excludes"; Nodes.Add(excludes); }
/// <summary> /// Default ctor /// </summary> protected PredicatesPredicateItem(T entity, IRailway railway) : base(entity) { this.railway = railway; foreach (var p in entity.Predicates) { var node = p.Accept(Default <ItemBuilder> .Instance, railway); Nodes.Add(node); } }
/// <summary> /// Gets all resolved modules /// </summary> private static IEnumerable <IModule> ResolveModules(IRailway railway) { foreach (var moduleRef in railway.Modules) { IModule module; if (moduleRef.TryResolve(out module)) { yield return(module); } } }
/// <summary> /// Gets all resolved locomotives /// </summary> private static IEnumerable <ILoc> ResolveLocs(IRailway railway) { foreach (var locRef in railway.Locs) { ILoc loc; if (locRef.TryResolve(out loc)) { yield return(loc); } } }
/// <summary> /// Gets all locs (instead of loc references) contained in the given railway. /// </summary> public static IEnumerable <ILoc> GetLocs(this IRailway railway) { foreach (var locRef in railway.Locs) { ILoc loc; if (locRef.TryResolve(out loc)) { yield return(loc); } } }
/// <summary> /// Gets all modules (instead of module references) contained in the given railway. /// </summary> public static IEnumerable <IModule> GetModules(this IRailway railway) { foreach (var moduleRef in railway.Modules) { IModule module; if (moduleRef.TryResolve(out module)) { yield return(module); } } }
public void AddElementsToCanvas(Canvas canvas) { foreach (线路绘图工具.GraphicElement element in Elements) { canvas.Children.Add(element); if (element is IRailway) { IRailway ir = element as IRailway; ir.AddInsulation(); } } }
/// <summary> /// Add items for each positioned items /// </summary> private void AddModules(IRailway railway, VCItemContainer target) { foreach (var moduleRef in railway.Modules) { IModule module; if (moduleRef.TryResolve(out module)) { var item = new ModuleEditItem(moduleRef, module, false, true, Context); target.Items.Add(item, null); moduleRef.PositionChanged += (s, _) => target.LayoutItems(); } } }
/// <summary> /// Look for all partial routes that are an extension of the initial partial route. /// </summary> private static IEnumerable <PartialRoute> FindNextStep(IRailway railway, PartialRoute initial) { var edge = FindConnectedEdge(railway, initial.LastRoute); if (edge == null) { yield break; } foreach (var route in edge.Module.Routes.Where(route => route.From == edge)) { yield return(new PartialRoute(initial, route)); } }
/// <summary> /// Default ctor /// </summary> public RailwayEditItem(IRailway railway, ItemContext context) : base(railway, context) { modulesLayer = new PositionedItemContainer(); modulesLayer.SelectedItems.Changed += (s, _) => SelectionChanged.Fire(this); var selectHandler = new ItemSelectMouseHandler(modulesLayer, modulesLayer.MouseHandler); var moveHandler = new ItemMoveMouseHandler(modulesLayer, selectHandler); modulesLayer.MouseHandler = moveHandler; Items.Add(modulesLayer, new LayoutConstraints(FillDirection.Both)); AddModules(railway, modulesLayer); }
/// <summary> /// Lookup the edge (on the "other") module connected with the destination of the given route. /// </summary> /// <returns>Null if not found</returns> private static IEdge FindConnectedEdge(IRailway railway, IRoute route) { var edge = (IEdge)route.To; foreach (var conn in railway.ModuleConnections) { if (conn.EdgeA == edge) { return(conn.EdgeB); } if (conn.EdgeB == edge) { return(conn.EdgeA); } } return(null); }
public void AddElementsToCanvas(Canvas canvas) { InitLen(); foreach (线路绘图工具.GraphicElement element in Elements) { canvas.Children.Add(element); if (element is IRailway) { IRailway ir = element as IRailway; ir.AddInsulation(); } //else if(element is PSDoor) //{ // ((PSDoor)element).CreateDefaultGraphic(); //} } }
/// <summary> /// Default ctor /// </summary> internal ActionsEditorForm(IActionTriggerSource source, IRailway railway, GridContext gridContext) { this.gridContext = gridContext; InitializeComponent(); if (source != null) { AddAddAction("Loc function action", () => new LocFunctionAction()); AddAddAction("Initialize junction action", () => new InitializeJunctionAction()); AddAddAction("Play sound action", () => new PlaySoundAction()); tvItems.BeginUpdate(); foreach (var trigger in source.Triggers) { tvItems.Nodes.Add(new TriggerItem(trigger)); } tvItems.EndUpdate(); UpdateToolbar(); } }
/// <summary> /// Gets all resolved command stations /// </summary> private static IEnumerable <ICommandStation> ResolveCommandStations(IRailway railway, bool runInVirtualMode) { if (runInVirtualMode) { yield return(new VirtualCommandStation { Description = Strings.VirtualCommandStationDescription }); } else { foreach (var csRef in railway.CommandStations) { ICommandStation cs; if (csRef.TryResolve(out cs)) { yield return(cs); } } } }
public RailwayMessage(IRailway railway, IRailwayState state) { Type = TypeRailway; Description = railway.Description; var locs = new List <Loc>(); foreach (var loc in railway.Locs) { ILoc locEntity; if (loc.TryResolve(out locEntity)) { ILocState locState = null; if (state != null) { locState = state.LocStates[locEntity]; } locs.Add(new Loc(locEntity, locState)); } } Locs = locs.ToArray(); var blocks = new List <Block>(); foreach (var module in railway.Modules) { IModule moduleEntity; if (module.TryResolve(out moduleEntity)) { foreach (var block in moduleEntity.Blocks) { IBlockState blockState = null; if (state != null) { blockState = state.BlockStates[block]; } blocks.Add(new Block(block, blockState)); } } } Blocks = blocks.ToArray(); }
/// <summary> /// Try to find all routes starting with the given route. /// </summary> private IEnumerable <IRouteState> ResolveRoutesStartingWith(IRailway railway, IRoute route) { var partialRoutes = new List <PartialRoute>(); partialRoutes.Add(new PartialRoute(route)); var completed = new List <PartialRoute>(); var result = new List <IRouteState>(); while (partialRoutes.Any()) { // Take the first partial route var partialRoute = partialRoutes[0]; partialRoutes.RemoveAt(0); // Find all extended partial routes var nextPartialRoutes = FindNextStep(railway, partialRoute).ToList(); foreach (var nextPartialRoute in nextPartialRoutes) { if (nextPartialRoute.IsComplete) { // We've found a complete route if (!completed.Contains(nextPartialRoute)) { result.Add(nextPartialRoute.CreateRouteState(this)); } else { completed.Add(nextPartialRoute); } } else { // The next partial route needs "completion" partialRoutes.Add(nextPartialRoute); } } } return(result); }
/// <summary> /// Import all locs /// </summary> protected void ImportLocs(IPackage package, IRailway railway) { var lclist = Root.Element("lclist"); if (lclist == null) { return; } foreach (var lc in lclist.Elements("lc")) { var id = lc.GetAttributeValue("id", string.Empty); if (string.IsNullOrEmpty(id)) { Message("Loc found without an id"); continue; } if (locs.ContainsKey(id.ToLower())) { Message("Duplicate loc found ({0})", id); continue; } var addr = lc.GetIntAttributeValue("addr"); var entity = package.AddNewLoc(); railway.Locs.Add(entity); entity.Description = id; var addrType = (lc.GetAttributeValue("prot") == "M") ? AddressType.Motorola : AddressType.Dcc; entity.Address = new Address(addrType, null, addr); // Record locs[id.ToLower()] = entity; } }
/// <summary> /// Default ctor /// </summary> public LocEqualsMenuItem(ILoc loc, IRailway railway) { this.loc = loc; this.railway = railway; Text = loc.ToString(); }
/// <summary> /// Default ctor /// </summary> public LocGroupEqualsMenuItem(ILocGroup group, IRailway railway) { this.group = group; this.railway = railway; Text = group.ToString(); }
/// <summary> /// Default ctor /// </summary> public LocCanChangeDirectionMenuItem(IRailway railway) { this.railway = railway; Text = Strings.CanChangeDirectionPredicateText; }
/// <summary> /// Default ctor /// </summary> public LocTimeMenuItem(IRailway railway) { this.railway = railway; Text = Strings.TimePeriodText; }
/// <summary> /// Gets all address entities contained in the given railway. /// </summary> public static IEnumerable <IAddressEntity> GetAddressEntities(this IRailway railway) { return(railway.GetModules().SelectMany(x => x.GetAddressEntities()).Concat(railway.GetLocs())); }