Beispiel #1
0
        /// <summary>
        /// Add a new connection between modules
        /// </summary>
        private void tbAddModuleConnection_Click(object sender, EventArgs e)
        {
            var connection = appState.Package.Railway.ModuleConnections.AddNew();
            var node       = new EntityNode(connection, null);

            moduleConnectionsRoot.Nodes.Add(node);
            tvItems.SelectedNode = node;
            UpdateAppTitle.Fire(this);
            ValidateRailway();
        }
Beispiel #2
0
        /// <summary>
        /// Add a new loc group
        /// </summary>
        private void tbAddLocGroup_Click(object sender, EventArgs e)
        {
            var group = appState.Package.Railway.LocGroups.AddNew();

            group.Description = Strings.NewLocGroupDescription;
            var node = new EntityNode(group, null);

            locGroupsRoot.Nodes.Add(node);
            tvItems.SelectedNode = node;
            UpdateAppTitle.Fire(this);
            ValidateRailway();
        }
Beispiel #3
0
        /// <summary>
        /// Edit the module contained in the given node (if any)
        /// </summary>
        private void EditModule(EntityNode node)
        {
            var module = (node != null) ? node.Entity as IModule : null;

            if (module != null)
            {
                using (var dialog = new EditModuleForm(appState, module, viewEditor.Context))
                {
                    dialog.ShowDialog(this);
                }
                viewEditor.ReloadView();
                ValidateRailway();
                UpdateAppTitle.Fire(this);
            }
        }
        /// <summary>
        /// Add the given entity to the tree.
        /// </summary>
        private void AddEntity(IEntity entity, TreeNode root, bool reloadAndValidate)
        {
            var node = new EntityNode(entity, contextMenus);

            root.Nodes.Add(node);
            using (selectionManager.BeginUpdate())
            {
                selectionManager.Clear();
                selectionManager.Add(entity);
            }
            if (reloadAndValidate)
            {
                viewEditor.ReloadModule();
                ValidateModule();
            }
            UpdateFormTitle.Fire(this);
        }
Beispiel #5
0
        /// <summary>
        /// Reload the package data into this control
        /// </summary>
        internal void ReloadModule(IModule module, ContextMenuStrip contextMenus, bool addModuleNode)
        {
            try
            {
                reloading = true;
                blocksRoot.Nodes.Clear();
                blockGroupsRoot.Nodes.Clear();
                junctionsRoot.Nodes.Clear();
                sensorsRoot.Nodes.Clear();
                signalsRoot.Nodes.Clear();
                edgesRoot.Nodes.Clear();
                routesRoot.Nodes.Clear();
                outputsRoot.Nodes.Clear();

                if (moduleNode != null)
                {
                    parent.Remove(moduleNode);
                    moduleNode = null;
                }

                if (module != null)
                {
                    var prefs = UserPreferences.Preferences;
                    if (addModuleNode)
                    {
                        moduleNode = new EntityNode(module, false, true)
                        {
                            Text = "Module"
                        };
                        parent.Insert(0, moduleNode);
                    }
                    blocksRoot.Nodes.AddRange(module.Blocks.Select(x => new EntityNode(x, contextMenus)).OrderBy(x => x.Text, NameWithNumbersComparer.Instance).ToArray());
                    blockGroupsRoot.Nodes.AddRange(module.BlockGroups.Select(x => new EntityNode(x, contextMenus)).OrderBy(x => x.Text, NameWithNumbersComparer.Instance).ToArray());
                    junctionsRoot.Nodes.AddRange(module.Junctions.Select(x => new EntityNode(x, contextMenus)).OrderBy(x => x.Text, NameWithNumbersComparer.Instance).ToArray());
                    sensorsRoot.Nodes.AddRange(module.Sensors.Select(x => new EntityNode(x, contextMenus)).OrderBy(x => x.Text, NameWithNumbersComparer.Instance).ToArray());
                    signalsRoot.Nodes.AddRange(module.Signals.Select(x => new EntityNode(x, contextMenus)).OrderBy(x => x.Text, NameWithNumbersComparer.Instance).ToArray());
                    edgesRoot.Nodes.AddRange(module.Edges.Select(x => new EntityNode(x, contextMenus)).OrderBy(x => x.Text, NameWithNumbersComparer.Instance).ToArray());
                    IEnumerable <IRoute> routes = module.Routes;
                    routes = prefs.SortRoutesByFrom ? routes.OrderBy(RouteSortByFrom) : routes.OrderBy(RouteSortByTo);
                    routesRoot.Nodes.AddRange(routes.Select(x => new EntityNode(x, contextMenus)).ToArray());
                    outputsRoot.Nodes.AddRange(module.Outputs.Select(x => new EntityNode(x, contextMenus)).OrderBy(x => x.Text, NameWithNumbersComparer.Instance).ToArray());

                    if (!prefs.EditBlocksOpen)
                    {
                        blocksRoot.Collapse();
                    }
                    else
                    {
                        blocksRoot.Expand();
                    }
                    if (!prefs.EditBlockGroupsOpen)
                    {
                        blockGroupsRoot.Collapse();
                    }
                    else
                    {
                        blockGroupsRoot.Expand();
                    }
                    if (!prefs.EditJunctionsOpen)
                    {
                        junctionsRoot.Collapse();
                    }
                    else
                    {
                        junctionsRoot.Expand();
                    }
                    if (!prefs.EditSensorsOpen)
                    {
                        sensorsRoot.Collapse();
                    }
                    else
                    {
                        sensorsRoot.Expand();
                    }
                    if (!prefs.EditSignalsOpen)
                    {
                        signalsRoot.Collapse();
                    }
                    else
                    {
                        signalsRoot.Expand();
                    }
                    if (!prefs.EditEdgesOpen)
                    {
                        edgesRoot.Collapse();
                    }
                    else
                    {
                        edgesRoot.Expand();
                    }
                    if (!prefs.EditRoutesOpen)
                    {
                        routesRoot.Collapse();
                    }
                    else
                    {
                        routesRoot.Expand();
                    }
                    if (!prefs.EditOutputsOpen)
                    {
                        outputsRoot.Collapse();
                    }
                    else
                    {
                        outputsRoot.Expand();
                    }
                }

                if (contextMenus != null)
                {
                    foreach (TreeNode node in parent)
                    {
                        node.ContextMenuStrip = contextMenus;
                    }
                }
            }
            finally
            {
                reloading = false;
            }
        }
Beispiel #6
0
        /// <summary>
        /// Reload the package data into this control
        /// </summary>
        private void ReloadPackage()
        {
            try
            {
                reloading = true;
                tvItems.BeginUpdate();
                tvItems.SelectedNodes.Clear();
                activeLocsRoot.Nodes.Clear();
                locGroupsRoot.Nodes.Clear();
                activeModulesRoot.Nodes.Clear();
                moduleConnectionsRoot.Nodes.Clear();
                activeCommandStationsRoot.Nodes.Clear();
                inactiveLocsRoot.Nodes.Clear();
                inactiveModulesRoot.Nodes.Clear();
                inactiveCommandStationsRoot.Nodes.Clear();

                if (railwayNode != null)
                {
                    activeRoot.Nodes.Remove(railwayNode);
                    railwayNode = null;
                }

                var package = appState.Package;
                if (package != null)
                {
                    var railway = package.Railway;

                    railwayNode = new EntityNode(railway, false, true)
                    {
                        Text = "Railway"
                    };
                    activeRoot.Nodes.Insert(0, railwayNode);

                    foreach (var locRef in railway.Locs.OrderBy(x => x.ToString(), NameWithNumbersComparer.Instance))
                    {
                        ILoc loc;
                        if (locRef.TryResolve(out loc))
                        {
                            activeLocsRoot.Nodes.Add(new EntityRefNode <ILoc>(locRef, loc));
                        }
                    }
                    foreach (var group in railway.LocGroups.OrderBy(x => x.ToString(), NameWithNumbersComparer.Instance))
                    {
                        locGroupsRoot.Nodes.Add(new EntityNode(group, null));
                    }
                    foreach (var moduleRef in railway.Modules.OrderBy(x => x.ToString(), NameWithNumbersComparer.Instance))
                    {
                        IModule module;
                        if (moduleRef.TryResolve(out module))
                        {
                            activeModulesRoot.Nodes.Add(new EntityRefNode <IModule>(moduleRef, module));
                        }
                    }
                    foreach (var connection in railway.ModuleConnections.OrderBy(x => x.ToString(), NameWithNumbersComparer.Instance))
                    {
                        moduleConnectionsRoot.Nodes.Add(new EntityNode(connection, null));
                    }
                    foreach (var csRef in railway.CommandStations.OrderBy(x => x.ToString(), NameWithNumbersComparer.Instance))
                    {
                        ICommandStation cs;
                        if (csRef.TryResolve(out cs))
                        {
                            activeCommandStationsRoot.Nodes.Add(new EntityRefNode <ICommandStation>(csRef, cs));
                        }
                    }
                    activeLocsRoot.Expand();
                    locGroupsRoot.Expand();
                    activeModulesRoot.Expand();
                    moduleConnectionsRoot.Expand();
                    activeCommandStationsRoot.Expand();
                    foreach (var loc in package.GetLocs().OrderBy(x => x.ToString(), NameWithNumbersComparer.Instance))
                    {
                        if (!railway.Locs.ContainsId(loc.Id))
                        {
                            inactiveLocsRoot.Nodes.Add(new EntityNode(loc, true, false));
                        }
                    }
                    foreach (var module in package.GetModules().OrderBy(x => x.ToString(), NameWithNumbersComparer.Instance))
                    {
                        if (!railway.Modules.ContainsId(module.Id))
                        {
                            inactiveModulesRoot.Nodes.Add(new EntityNode(module, true, false));
                        }
                    }
                    foreach (var cs in package.GetCommandStations().OrderBy(x => x.ToString(), NameWithNumbersComparer.Instance))
                    {
                        if (!railway.CommandStations.ContainsId(cs.Id))
                        {
                            inactiveCommandStationsRoot.Nodes.Add(new EntityNode(cs, true, false));
                        }
                    }
                }

                activeRoot.Expand();
                tvItems.EndUpdate();
                UpdateSelectedGridObject();
                ValidateRailway();
                viewEditor.ReloadView();

                var prefs = UserPreferences.Preferences;
                if (!prefs.EditLocsOpen)
                {
                    activeLocsRoot.Collapse();
                }
                if (!prefs.EditLocGroupsOpen)
                {
                    locGroupsRoot.Collapse();
                }
                if (!prefs.EditModulesOpen)
                {
                    activeModulesRoot.Collapse();
                }
                if (!prefs.EditModuleConnectionsOpen)
                {
                    moduleConnectionsRoot.Collapse();
                }
                if (!prefs.EditCommandStationsOpen)
                {
                    activeCommandStationsRoot.Collapse();
                }
            }
            finally
            {
                reloading = false;
            }
        }