public void DetectsCategoryFromNamespace()
        {
            var nodeConfig = new MyNodeConfig();
            nodeConfig.NodeType = typeof(TestType);

            Assert.Equal("(GoodAI.BrainSimulator)", CategorySortingHat.DetectCategoryName(nodeConfig));
        }
        public void DetectsCategoryFromGoodAiModulesNamespace()
        {
            var nodeConfig = new MyNodeConfig();
            nodeConfig.NodeType = typeof(FoobarType);

            Assert.Equal("(Foo)", CategorySortingHat.DetectCategoryName(nodeConfig));
        }
        private void AddNodeButton(MyNodeConfig nodeInfo, bool isTransform)
        {
            ToolStripItem newButton = isTransform ? new ToolStripMenuItem() : newButton = new ToolStripButton();
            ToolStripItemCollection items;

            newButton.Image = nodeInfo.SmallImage;
            newButton.Name = nodeInfo.NodeType.Name;
            newButton.ToolTipText = nodeInfo.NodeType.Name.Substring(2);
            newButton.MouseDown += addNodeButton_MouseDown;
            newButton.Tag = nodeInfo.NodeType;

            newButton.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
            newButton.ImageScaling = System.Windows.Forms.ToolStripItemImageScaling.None;
            newButton.ImageTransparentColor = System.Drawing.Color.Magenta;

            if (isTransform)
            {
                newButton.DisplayStyle = ToolStripItemDisplayStyle.ImageAndText;
                newButton.Text = newButton.ToolTipText;
                items = transformMenu.DropDownItems;
            }
            else
            {
                items = toolStrip1.Items;
                newButton.MouseUp += newButton_MouseUp;
            }

            if (items.Count > 0 && (items[items.Count - 1].Tag as Type).Namespace != nodeInfo.NodeType.Namespace)
            {
                items.Add(new ToolStripSeparator());
            }
            items.Add(newButton);
        }
Esempio n. 4
0
        internal void InitIcons(Assembly assembly)
        {
            if (!String.IsNullOrEmpty(SmallIcon))
            {
                SmallImage = MyResources.GetImageFromAssembly(assembly, SmallIcon);
            }

            if (SmallImage == null)
            {
                SmallImage = MyNodeConfig.GenerateDefaultImage(Name, false);
            }
        }
        private void AddNodeButton(MyNodeConfig nodeConfig)
        {
            var newButton = new ToolStripButton
            {
                ToolTipText = MyProject.ShortenNodeTypeName(nodeConfig.NodeType),
                DisplayStyle = ToolStripItemDisplayStyle.Image
            };

            newButton.MouseUp += newButton_MouseUp;

            ToolStripItemCollection targetItems = nodesToolStrip.Items;

            InnerAddNodeButtonOrMenuItem(newButton, nodeConfig, targetItems);
        }
Esempio n. 6
0
        protected MyNodeView(MyNodeConfig nodeInfo, GraphControl owner)
            : base("")
        {
            NodeInfo = nodeInfo;
            Owner = owner;

            m_icon = nodeInfo.BigImage;

            m_iconItem = new NodeImageItem(m_icon, 48, 48, false, false);
            m_iconItem.Tag = 0;
            m_descItem = new NodeLabelItem("");

            AddItem(m_iconItem);
            AddItem(m_descItem);
        }
Esempio n. 7
0
        protected MyNodeView(MyNodeConfig nodeConfig, GraphControl owner)
            : base("")
        {
            Owner = owner;

            Config = nodeConfig;

            m_icon = nodeConfig.BigImage;

            m_iconItem = new NodeImageItem(m_icon, 48, 48, false, false)
            {
                IsPassive = true,
                Tag = 0
            };
            m_descItem = new NodeLabelItem("")
            {
                IsPassive = true
            };

            AddItem(m_iconItem);
            AddItem(m_descItem);
        }
        public static string DetectCategoryName(MyNodeConfig nodeConfig)
        {
            string categoryName;

            if (nodeConfig is MyWorldConfig)
            {
                categoryName = "Worlds";
            }
            else if (nodeConfig.Labels != null && nodeConfig.Labels.Count > 0)
            {
                categoryName = nodeConfig.Labels[0];
            }
            else  // Fallback when there are no labels
            {
                string nameSpace = nodeConfig.NodeType.Namespace;
                if (string.IsNullOrEmpty(nameSpace))
                {
                    categoryName = "unknown";
                }
                else if (nameSpace.StartsWith("GoodAI.Modules."))  // TODO: consider using whenever namespace level >= 3
                {
                    categoryName = nameSpace.Split('.')[2];  // take the third namespace level
                }
                else if (nameSpace.LastIndexOf('.') > 0)
                {
                    categoryName = nameSpace.Substring(0, nameSpace.LastIndexOf('.'));  // strip the last level
                }
                else
                {
                    categoryName = nameSpace;
                }

                categoryName = string.Format("({0})", categoryName);  // indicate namespace-derived category
            }

            return categoryName;
        }
Esempio n. 9
0
 public MyUserInputView(MyNodeConfig nodeInfo, GraphControl owner)
     : base(nodeInfo, owner)
 {
 }
Esempio n. 10
0
        private void AddQuickToolBarItem(MyNodeConfig nodeConfig)
        {
            AddNodeButton(nodeConfig);

            Settings.Default.QuickToolBarNodes.Add(nodeConfig.NodeType.Name);
        }
Esempio n. 11
0
        private static bool CanAcceptNode(IDataObject data, out MyNodeConfig nodeConfig)
        {
            nodeConfig = GetNodeConfigFromDropData(data);
            if (nodeConfig == null)
                return false;

            return !Settings.Default.QuickToolBarNodes.Contains(nodeConfig.NodeType.Name);
        }
Esempio n. 12
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};
        }
        private NodeCategory GetNodeCategory(MyNodeConfig nodeConfig)
        {
            string categoryName = DetectCategoryName(nodeConfig);

            NodeCategory nodeCategory = (MyConfiguration.KnownCategories.ContainsKey(categoryName))
                ? new NodeCategory(MyConfiguration.KnownCategories[categoryName])
                : new NodeCategory(categoryName);

            return nodeCategory;
        }
Esempio n. 14
0
        public int UpdateAfterDeserialization(int topId, MyProject parentProject)
        {
            if (topId < this.Id)
            {
                topId = this.Id;
            }

            this.Owner = parentProject;

            Dictionary<int, MyNode> nodes = new Dictionary<int,MyNode>();
            topId = CollectNodesAndUpdate(this, nodes, topId);

            parentProject.ReadOnly = false;

            MyNodeGroup.IteratorAction findUnknownAction = delegate(MyNode node)
            {
                if (!MyConfiguration.KnownNodes.ContainsKey(node.GetType()))
                {
                    MyLog.WARNING.WriteLine("Unknown node type in loaded project: " + node.GetType());
                    parentProject.ReadOnly = true;

                    try
                    {
                        MyNodeConfig nodeConfig = new MyNodeConfig()
                        {
                            NodeType = node.GetType(),
                            NodeTypeName = node.GetType().FullName
                        };

                        nodeConfig.InitIcons(Assembly.GetExecutingAssembly());
                        nodeConfig.AddObservers(Assembly.GetExecutingAssembly());

                        MyConfiguration.KnownNodes[nodeConfig.NodeType] = nodeConfig;
                    }
                    catch (Exception e)
                    {
                        MyLog.ERROR.WriteLine("Node type loading failed: " + e.Message);
                    }
                }
            };

            Iterate(true, findUnknownAction);

            foreach (MyConnectionProxy cp in m_connections)
            {
                try
                {
                    MyConnection connection = new MyConnection(nodes[cp.From], nodes[cp.To], cp.FromIndex, cp.ToIndex);
                    connection.Connect();
                }
                catch (Exception e)
                {
                    MyLog.ERROR.WriteLine("Error during connection deserialization: From id " + cp.From +" to id " + cp.To);
                }
            }

            return topId;
        }
        public void AddNodeAndCategory(MyNodeConfig nodeConfig)
        {
            m_nodes.Add(nodeConfig);  // TODO(Premek): adding nodes is not needed on some places

            m_categories.Add(GetNodeCategory(nodeConfig));
        }
 public MyVariableBranchView(MyNodeConfig nodeInfo, GraphControl owner) : base(nodeInfo, owner) { }
        private void InnerAddNodeButtonOrMenuItem(ToolStripItem newButton, MyNodeConfig nodeConfig,
            ToolStripItemCollection targetItems, bool addSeparators = false)
        {
            newButton.Image = nodeConfig.SmallImage;
            newButton.Name = nodeConfig.NodeType.Name;
            newButton.MouseDown += addNodeButton_MouseDown;
            newButton.Tag = nodeConfig.NodeType;

            newButton.ImageScaling = ToolStripItemImageScaling.None;
            newButton.ImageTransparentColor = System.Drawing.Color.Magenta;

            // separate buttons for nodes from different namespaces
            if (addSeparators && (targetItems.Count > 0))
            {
                var nodeType = targetItems[targetItems.Count - 1].Tag as Type;
                if ((nodeType != null) && (nodeType.Namespace != nodeConfig.NodeType.Namespace))
                {
                    targetItems.Add(new ToolStripSeparator());
                }
            }

            targetItems.Add(newButton);

            // TODO: Add undo here if we also want to undo non-model-related actions
        }
Esempio n. 18
0
 public UiNodeInfo(ListViewItem listViewItem, MyNodeConfig config,  string searchableText)
 {
     ListViewItem = listViewItem;
     Config = config;
     SearchableText = searchableText;
 }
Esempio n. 19
0
        private void AddQuickToolBarItem(MyNodeConfig nodeConfig)
        {
            AddNodeButton(nodeConfig);

            Settings.Default.QuickToolBarNodes.Add(nodeConfig.NodeType.Name);

            // TODO: Add undo here if we also want to undo non-model-related actions
        }
Esempio n. 20
0
 public DeviceInputView(MyNodeConfig nodeConfig, GraphControl owner)
     : base(nodeConfig, owner)
 {
 }
 public MyNodeGroupView(MyNodeConfig nodeInfo, GraphControl owner) : base(nodeInfo, owner) { }
        private void AddNodeButtonToCategoryMenu(MyNodeConfig nodeConfig)
        {
            ToolStripDropDownButton targetMenuButton =
                FindTargetMenuButton(CategorySortingHat.DetectCategoryName(nodeConfig));  // TODO: optimize with HashSet
            if (targetMenuButton == null)
                return;

            ToolStripItem newButton = new ToolStripMenuItem()
            {
                Text = MyProject.ShortenNodeTypeName(nodeConfig.NodeType),
                DisplayStyle = ToolStripItemDisplayStyle.ImageAndText
            };

            ToolStripItemCollection targetItems = targetMenuButton.DropDownItems;

            InnerAddNodeButtonOrMenuItem(newButton, nodeConfig, targetItems, addSeparators: true);
        }