示例#1
0
        ///convert factscheme argument into nv node
        ///
        public static NodeInfo Convert(FactScheme.Argument argument, Vocabularies.Vocabulary vocabulary = null)
        {
            NodeInfo info = new NodeInfo();

            info.Tag = argument;

            info.NodeNameProperty     = string.Format("arg{0} {1}", argument.Order, argument.Name);
            argument.PropertyChanged += (s, e) =>
            {
                if (e.PropertyName == "Order")
                {
                    info.NodeNameProperty = string.Format("arg{0} {1}", argument.Order, argument.Name);
                }
                //if (e.PropertyName == "")
            };

            if (argument.ArgType == ArgumentType.IOBJECT)
            {
                foreach (var attr in argument.Attributes)
                {
                    NodeInfo.SectionInfo attrInfo = new NodeInfo.SectionInfo();
                    attrInfo.Data     = attr;
                    attrInfo.IsInput  = false;
                    attrInfo.IsOutput = true;
                    var attrName = new Label();
                    attrName.Content = attr.Name;
                    attrName.ToolTip = (attr.AttrType == OntologyNode.Attribute.AttributeType.DOMAIN || attr.AttrType == OntologyNode.Attribute.AttributeType.OBJECT) ? attr.Opt : attr.AttrType;

                    attrInfo.UIPanel = attrName;
                    info.Sections.Add(attrInfo);
                }

                info.FillColor = System.Windows.Media.Colors.LightSkyBlue;
            }
            else
            {
                for (int i = 0; i < 2; i++) // $Class and $Value are 2 mandatory attributes
                {
                    var attr = argument.Attributes[i];
                    NodeInfo.SectionInfo attrInfo = new NodeInfo.SectionInfo();
                    attrInfo.Data     = attr;
                    attrInfo.IsInput  = false;
                    attrInfo.IsOutput = true;
                    var attrName = new Label();
                    attrName.Content = attr.Name;
                    attrName.ToolTip = (attr.AttrType == OntologyNode.Attribute.AttributeType.DOMAIN || attr.AttrType == OntologyNode.Attribute.AttributeType.OBJECT) ? attr.Opt : attr.AttrType;

                    attrInfo.UIPanel = attrName;
                    info.Sections.Add(attrInfo);
                }
                var plusInfo = new NodeInfo.SectionInfo();
                var plusBtn  = new Button();
                plusBtn.Content = "+";
                plusBtn.Click  += (s, e) =>
                {
                    var newAttr = new OntologyNode.Attribute(OntologyNode.Attribute.AttributeType.STRING, vocabulary.First().Name, true);
                    argument.Attributes.Add(newAttr);
                    info.Sections.Add(TerminVarAttrInfo(argument, newAttr, vocabulary, info));
                };
                plusInfo.UIPanel = plusBtn;
                info.Sections.Add(plusInfo);
                for (int i = 2; i < argument.Attributes.Count; i++)
                {
                    info.Sections.Add(TerminVarAttrInfo(argument, argument.Attributes[i], vocabulary, info));
                }
                info.FillColor = System.Windows.Media.Colors.DeepSkyBlue;
            }

            return(info);
        }
示例#2
0
        static NodeInfo.SectionInfo TerminVarAttrInfo(Argument argument, OntologyNode.Attribute attr, Vocabularies.Vocabulary vocabulary, NodeInfo nodeInfo)
        {
            NodeInfo.SectionInfo attrInfo = new NodeInfo.SectionInfo();
            attrInfo.Data     = attr;
            attrInfo.IsOutput = true;
            var attrName = new TerminAttribute();

            attrName.RemoveAttrButton.Click += (s, e) =>
            {
                Console.WriteLine("removed varattr");
                argument.Attributes.Remove(attr);
                nodeInfo.Sections.Remove(attrInfo);
                // re-render node
            };
            var vocList = vocabulary.ToList();

            attrName.AttrNameComboBox.ItemsSource       = vocList;
            attrName.AttrNameComboBox.SelectedIndex     = vocList.FindIndex(t => t.Name == attr.Name);
            attrName.AttrNameComboBox.SelectionChanged += (s, e) => {
                attr.Name = e.AddedItems[0].ToString();
            };
            attrName.ToolTip = attr.AttrType;

            attrInfo.UIPanel = attrName;
            return(attrInfo);
        }