예제 #1
0
        private static StackPanel ResultInfoPanel(FactScheme.Result result)
        {
            StackPanel stackPanel = new StackPanel();

            stackPanel.Margin = new Thickness(5);

            ComboBox cb = new ComboBox();

            cb.ItemsSource   = Enum.GetValues(typeof(FactScheme.ResultType));
            cb.SelectedValue = result.Type;

            stackPanel.Children.Add(cb);

            TextBlock editedArgName = new TextBlock();

            editedArgName.Text = result.Reference.Name;
            stackPanel.Children.Add(editedArgName);

            cb.SelectionChanged += (s, e) =>
            {
                if (e.AddedItems.Contains(FactScheme.ResultType.CREATE))
                {
                    result.Type = ResultType.CREATE;
                }
                else
                {
                    result.Type = ResultType.EDIT;
                }
            };

            return(stackPanel);
        }
예제 #2
0
        private void addResultMenuItem_Click(object sender, EventArgs e)
        {
            network.NetworkView nv = getCurrentNetworkView();
            if (nv == null)
            {
                return;
            }

            OntologyClass ontologyClass = menuItemToClass(sender as ToolStripMenuItem);
            Scheme        scheme        = (Scheme)schemesTabControl.SelectedTab.Tag;

            FactScheme.Result result = scheme.AddResult(ontologyClass);
            network.Node      node   = nv.AddNode(Medium.Convert(result), true);
        }
예제 #3
0
        public static NodeInfo Convert(FactScheme.Result result)
        {
            NodeInfo info = new NodeInfo();

            info.Tag = result;

            info.Header.NameChangeable = true;
            info.NodeNameProperty      = result.Name;
            info.PropertyChanged      += (sender, e) =>
            {
                if (e.PropertyName == "NodeNameProperty")
                {
                    result.Name = (sender as NodeInfo).NodeNameProperty;
                }
            };

            var resultInfo = new NodeInfo.SectionInfo();

            resultInfo.Data            = result;
            resultInfo.UIPanel         = ResultInfoPanel(result);
            resultInfo.IsInput         = true;
            resultInfo.InputValidation = (s, e) =>
            {
                var input = e.SourceConnector.ParentNode.Tag;
                if (input is Argument)
                {
                    if (result.Reference != ((Argument)input).Klass)
                    {
                        e.Valid = false;
                    }
                }
                else if (input is Result)
                {
                    if (result.Reference != ((Result)input).Reference)
                    {
                        e.Valid = false;
                    }
                }
                else
                {
                    e.Valid = false;
                }
            };
            info.Sections.Add(resultInfo);

            if (result.Reference is OntologyClass)
            {
                var attrs          = new List <OntologyNode.Attribute>((result.Reference as OntologyClass).OwnAttributes);
                var inheritedAttrs = (result.Reference as OntologyClass).InheritedAttributes.Select(i => i.Item1);
                foreach (var inheritedAttr in inheritedAttrs)
                {
                    attrs.Add(inheritedAttr as OntologyNode.Attribute);
                }

                foreach (var attr in attrs)
                {
                    var attrInfo = new NodeInfo.SectionInfo();
                    attrInfo.Data    = attr;
                    attrInfo.IsInput = true;
                    //attrInfo.IsOutput = true;
                    attrInfo.InputValidation += (s, e) =>
                    {
                        var src = e.SourceConnector.Tag;
                        var dst = e.DestConnector.Tag;
                        if (src == null || dst == null)
                        {
                            e.Valid = false;
                            return;
                        }
                        if (src is Argument && dst is OntologyNode.Attribute)
                        {
                            if (((Argument)src).Klass == null)
                            {
                                e.Valid = false;
                                return;
                            }
                            var parent = ((Argument)src).Klass.FindParent((string)((OntologyClass.Attribute)dst).Opt);
                            e.Valid = parent != null;
                            return;
                        }
                        if (src is OntologyNode.Attribute && dst is OntologyNode.Attribute)
                        {
                            if (((OntologyNode.Attribute)src).AttrType != ((OntologyNode.Attribute)dst).AttrType)
                            {
                                e.Valid = false;
                                return;
                            }
                            var attrType = ((OntologyNode.Attribute)src).AttrType;
                            if (attrType == OntologyNode.Attribute.AttributeType.DOMAIN || attrType == OntologyNode.Attribute.AttributeType.OBJECT)
                            {
                                e.Valid = ((OntologyNode.Attribute)src).Opt == ((OntologyNode.Attribute)dst).Opt;
                            }
                        }
                    };
                    FrameworkElement attrName;
                    if (attr.AttrType == OntologyNode.Attribute.AttributeType.OBJECT)
                    {
                        attrName = new Label();
                        ((Label)attrName).Content = attr.Name;
                    }
                    else if (attr.AttrType == OntologyNode.Attribute.AttributeType.DOMAIN)
                    {
                        attrName = new Elements.ResultDefaultDomainAttr();
                        var items         = new List <ComboBoxItem>();
                        var selectedIndex = 0;
                        if (!Ontology.Ontology.Domains.ContainsKey((string)(attr.Opt)))
                        {
                            var item = new ComboBoxItem();
                            item.Content = "domain doesnt exist";
                            items.Add(item);
                        }

                        else
                        {
                            for (int i = 0; i < Ontology.Ontology.Domains[(string)attr.Opt].Count; i++)
                            {
                                var domainValue = Ontology.Ontology.Domains[(string)attr.Opt][i];
                                var item        = new ComboBoxItem();
                                item.Content   = domainValue;
                                item.Selected += (s, e) => {
                                    if (result.Rules.ContainsKey(attr.Name))
                                    {
                                        result.Rules[attr.Name].Default = domainValue;
                                    }
                                    else
                                    {
                                        var rule = new Result.Rule(attr, domainValue);
                                        result.Rules[attr.Name] = rule;
                                    }
                                };
                                items.Add(item);
                                if (result.Rules.ContainsKey(attr.Name) && result.Rules[attr.Name].Default == domainValue)
                                {
                                    selectedIndex = i;
                                }
                            }
                        }
                        ((Elements.ResultDefaultDomainAttr)attrName).GetComboBox().ItemsSource   = items;
                        ((Elements.ResultDefaultDomainAttr)attrName).GetComboBox().SelectedIndex = selectedIndex;
                        ((Elements.ResultDefaultDomainAttr)attrName).Header = attr.Name;
                        if (result.Rules.ContainsKey(attr.Name))
                        {
                            ((Elements.ResultDefaultDomainAttr)attrName).GetComboBox().SelectedItem = result.Rules[attr.Name].Default;
                        }
                    }
                    else
                    {
                        attrName = new Elements.UserControl1();
                        ((Elements.UserControl1)attrName).Header = attr.Name;
                        if (result.Rules.ContainsKey(attr.Name))
                        {
                            ((Elements.UserControl1)attrName).GetTextBox().Text = result.Rules[attr.Name].Default;
                        }
                        ((Elements.UserControl1)attrName).GetTextBox().TextChanged += (s, e) =>
                        {
                            if (result.Rules.ContainsKey(attr.Name))
                            {
                                result.Rules[attr.Name].Default = ((TextBox)s).Text;
                            }
                            else
                            {
                                var rule = new Result.Rule(attr, ((TextBox)s).Text);
                                result.Rules[attr.Name] = rule;
                            }
                        };
                    }
                    attrInfo.UIPanel = attrName;
                    info.Sections.Add(attrInfo);
                }
            }

            info.FillColor = System.Windows.Media.Colors.LightSeaGreen;

            return(info);
        }