예제 #1
0
        private string[] ProduceSubitemTexts(MyNodeConfig nodeConfig, MyObsoleteAttribute obsolete, out bool complete)
        {
            string author;
            string status;
            string summary;
            string labels = "";

            complete  = m_mainForm.Documentation.HasAuthor(nodeConfig.NodeType, out author);
            complete &= m_mainForm.Documentation.HasStatus(nodeConfig.NodeType, out status);
            complete &= m_mainForm.Documentation.HasSummary(nodeConfig.NodeType, out summary);

            if (obsolete != null)
            {
                status  = "Obsolete";
                summary = "Replaced by: " + MyProject.ShortenNodeTypeName(obsolete.ReplacedBy);
            }
            else if (!complete)
            {
                summary = "INCOMPLETE DOCUMENTATION! " + summary;
            }

            if ((nodeConfig.Labels != null) && (nodeConfig.Labels.Count > 0))
            {
                labels = EscapeAmpersands(string.Join(" ", nodeConfig.Labels.Select(label => "#" + label)));
            }

            author  = EscapeAmpersands(author);
            status  = EscapeAmpersands(status);
            summary = EscapeAmpersands(summary);

            string nodeName = MyProject.ShortenNodeTypeName(nodeConfig.NodeType);

            return(new string[] { nodeName, author, status, summary, labels });
        }
예제 #2
0
        private int CollectNodesAndUpdate(MyNodeGroup nodeGroup, Dictionary <int, MyNode> nodes, int topId)
        {
            foreach (MyParentInput inputNode in nodeGroup.GroupInputNodes)
            {
                nodes[inputNode.Id] = inputNode;
                inputNode.Parent    = nodeGroup;
                inputNode.Owner     = Owner;

                if (topId < inputNode.Id)
                {
                    topId = inputNode.Id;
                }
            }

            foreach (MyOutput outputNode in nodeGroup.GroupOutputNodes)
            {
                nodes[outputNode.Id] = outputNode;
                outputNode.Parent    = nodeGroup;
                outputNode.Owner     = Owner;

                if (topId < outputNode.Id)
                {
                    topId = outputNode.Id;
                }
            }

            foreach (MyNode node in nodeGroup.Children)
            {
                nodes[node.Id] = node;

                //parent link
                node.Parent = nodeGroup;
                node.Owner  = Owner;
                //topId collect
                if (topId < node.Id)
                {
                    topId = node.Id;
                }

                //task owner update
                if (node is MyWorkingNode)
                {
                    (node as MyWorkingNode).FinalizeTasksDeserialization();
                }

                if (node is MyNodeGroup)
                {
                    topId = CollectNodesAndUpdate(node as MyNodeGroup, nodes, topId);
                }

                //obsolete check
                MyObsoleteAttribute obsolete = node.GetType().GetCustomAttribute <MyObsoleteAttribute>(true);
                if (obsolete != null)
                {
                    string message = "You are using obsolete node type (" + node.GetType().Name + ") ";
                    if (obsolete.ReplacedBy != null)
                    {
                        message += "Use " + obsolete.ReplacedBy.Name + " instead.";
                    }
                    MyLog.WARNING.WriteLine(message);
                }
            }
            return(topId);
        }
        private void PopulateNodeListView()
        {
            HashSet <string> enabledNodes = new HashSet <string>();

            if (Properties.Settings.Default.ToolBarNodes != null)
            {
                foreach (string nodeTypeName in Properties.Settings.Default.ToolBarNodes)
                {
                    enabledNodes.Add(nodeTypeName);
                }
            }

            Dictionary <string, List <MyNodeConfig> > knownNodes = new Dictionary <string, List <MyNodeConfig> >();

            foreach (MyNodeConfig nc in MyConfiguration.KnownNodes.Values)
            {
                if (!nc.IsBasicNode && nc.CanBeAdded)
                {
                    if (!knownNodes.ContainsKey(nc.NodeType.Namespace))
                    {
                        knownNodes[nc.NodeType.Namespace] = new List <MyNodeConfig>();
                    }
                    knownNodes[nc.NodeType.Namespace].Add(nc);
                }
            }

            knownNodes["Worlds"] = new List <MyNodeConfig>();

            foreach (MyNodeConfig nc in MyConfiguration.KnownWorlds.Values)
            {
                if (!nc.IsBasicNode)
                {
                    knownNodes["Worlds"].Add(nc);
                }
            }

            int i = 0;

            nodeImageList.Images.Add(GeneratePaddedIcon(Properties.Resources.group));
            i++;
            nodeImageList.Images.Add(GeneratePaddedIcon(Properties.Resources.world));
            i++;

            List <string> nmspaces = knownNodes.Keys.ToList().OrderBy(x => x).ToList();

            foreach (string nmspace in nmspaces)
            {
                ListViewGroup group = new ListViewGroup(nmspace, nmspace.Replace("BrainSimulator.", ""));
                nodeListView.Groups.Add(group);

                List <MyNodeConfig> nodesInGroup = knownNodes[nmspace].OrderBy(x => x.NodeType.Name).ToList();;
                int row = 0;

                foreach (MyNodeConfig nc in nodesInGroup)
                {
                    string author;
                    string status;
                    string summary;

                    bool complete = m_mainForm.Documentation.HasAuthor(nc.NodeType, out author);
                    complete &= m_mainForm.Documentation.HasStatus(nc.NodeType, out status);
                    complete &= m_mainForm.Documentation.HasSummary(nc.NodeType, out summary);

                    MyObsoleteAttribute obsolete = nc.NodeType.GetCustomAttribute <MyObsoleteAttribute>(true);

                    if (obsolete != null)
                    {
                        status  = "Obsolete";
                        summary = "Replaced by: " + MyProject.ShortenNodeTypeName(obsolete.ReplacedBy);
                    }
                    else
                    {
                        if (!complete)
                        {
                            summary = "INCOMPLETE DOCUMENTATION! " + summary;
                        }
                        else
                        {
                            author  = author.Replace("&", "&&");
                            status  = status.Replace("&", "&&");
                            summary = summary.Replace("&", "&&");
                        }
                    }

                    ListViewItem item = new ListViewItem(
                        new string[4] {
                        MyProject.ShortenNodeTypeName(nc.NodeType), author, status, summary
                    });

                    if (row % 2 == 1)
                    {
                        item.BackColor = Color.FromArgb(245, 245, 245);
                    }

                    item.Tag     = nc;
                    item.Group   = group;
                    item.Checked = enabledNodes.Contains(nc.NodeType.Name);

                    // forbid to remove currently selected world
                    if (nc.NodeType == m_mainForm.Project.World.GetType())
                    {
                        item.BackColor   = Color.FromArgb(150, 200, 240); // (light gray-blue)
                        item.ToolTipText = "This world is being used by the current project (can't be deselected).";
                        // NOTE: the item's checkbox can't be disabled, we just override changes in nodeListView_ItemCheck()
                    }

                    if (obsolete != null)
                    {
                        item.ForeColor = SystemColors.GrayText;
                    }
                    else
                    {
                        if (!complete)
                        {
                            item.ForeColor = Color.Red;
                        }
                    }

                    if (nmspace != "Worlds")
                    {
                        item.ImageIndex = i;
                        nodeImageList.Images.Add(GeneratePaddedIcon(nc.SmallImage));
                        i++;
                    }
                    else
                    {
                        item.ImageIndex = 1;
                    }

                    nodeListView.Items.Add(item);
                    row++;
                }
            }

            nodeListView.GridLines = true;
        }
예제 #4
0
        private void GenerateNodeList()
        {
            var enabledNodes = new HashSet <string>();

            if (Properties.Settings.Default.ToolBarNodes != null)
            {
                foreach (string nodeTypeName in Properties.Settings.Default.ToolBarNodes)
                {
                    enabledNodes.Add(nodeTypeName);
                }
            }

            var knownNodes = new Dictionary <string, List <MyNodeConfig> >();

            foreach (MyNodeConfig nodeConfig in MyConfiguration.KnownNodes.Values)
            {
                if (!nodeConfig.CanBeAdded || (nodeConfig.NodeType == null))
                {
                    continue;
                }

                string nameSpace = nodeConfig.NodeType.Namespace ?? "(unknown)";
                if (!knownNodes.ContainsKey(nameSpace))
                {
                    knownNodes[nameSpace] = new List <MyNodeConfig>();
                }

                knownNodes[nameSpace].Add(nodeConfig);
            }

            knownNodes["Worlds"] = new List <MyNodeConfig>();

            foreach (MyWorldConfig nodeConfig in MyConfiguration.KnownWorlds.Values)
            {
                knownNodes["Worlds"].Add(nodeConfig);
            }

            var categorizer = new CategorySortingHat();

            int i = 0;

            nodeImageList.Images.Add(GeneratePaddedIcon(Properties.Resources.group));
            i++;
            nodeImageList.Images.Add(GeneratePaddedIcon(Properties.Resources.world));
            i++;

            List <string> moduleNameSpaces = knownNodes.Keys.ToList().OrderBy(x => x).ToList();

            foreach (string nameSpace in moduleNameSpaces)
            {
                ListViewGroup group = new ListViewGroup(nameSpace, nameSpace.Replace("BrainSimulator.", ""));
                nodeListView.Groups.Add(group);

                List <MyNodeConfig> nodesInGroup = knownNodes[nameSpace].OrderBy(x => x.NodeType.Name).ToList();;

                foreach (MyNodeConfig nodeConfig in nodesInGroup)
                {
                    categorizer.AddNodeAndCategory(nodeConfig);

                    MyObsoleteAttribute obsolete = nodeConfig.NodeType.GetCustomAttribute <MyObsoleteAttribute>(true);

                    bool     complete;
                    string[] subitems = ProduceSubitemTexts(nodeConfig, obsolete, out complete);

                    ListViewItem item = new ListViewItem(subitems)
                    {
                        Tag     = nodeConfig,
                        Group   = @group,
                        Checked = enabledNodes.Contains(nodeConfig.NodeType.Name)
                    };

                    // forbid to remove currently selected world
                    if (nodeConfig.NodeType == m_mainForm.Project.World.GetType())
                    {
                        item.BackColor   = Color.FromArgb(150, 200, 240); // (light gray-blue)
                        item.ToolTipText = "This world is being used by the current project (can't be deselected).";
                        // NOTE: the item's checkbox can't be disabled, we just override changes in nodeListView_ItemCheck()
                    }

                    if (obsolete != null)
                    {
                        item.ForeColor = SystemColors.GrayText;
                    }
                    else
                    {
                        if (!complete)
                        {
                            item.ForeColor = Color.Red;
                        }
                    }

                    if (nameSpace != "Worlds")
                    {
                        item.ImageIndex = i;
                        nodeImageList.Images.Add(GeneratePaddedIcon(nodeConfig.SmallImage));
                        i++;
                    }
                    else
                    {
                        item.ImageIndex = 1;
                    }

                    m_nodeInfoItems.Add(new UiNodeInfo(item, nodeConfig, string.Join("|", subitems)));
                }
            }

            PopulateCategoryListView(categorizer);
        }