public static NodeInfo Convert(FactScheme.Condition condition, Dictionary <string, List <string> > gramtab, List <string> segments) { var info = new NodeInfo(); info.Tag = condition; info.NodeNameProperty = "Условие схемы"; var argInfo1 = Medium.ConditionArgSection(condition.Arg1, "Arg1"); argInfo1.InputAdded += (object s, ConnectionEventArgs e) => { argInfo1.Data = e.SourceConnector.Tag; condition.Arg1 = (FactScheme.Argument)e.SourceConnector.Tag; }; var argInfo2 = Medium.ConditionArgSection(condition.Arg2, "Arg2"); argInfo2.InputAdded += (object s, ConnectionEventArgs e) => { argInfo2.Data = e.SourceConnector.Tag; condition.Arg2 = (FactScheme.Argument)e.SourceConnector.Tag; }; info.Sections.Add(argInfo1); info.Sections.Add(argInfo2); NodeInfo.SectionInfo[] args = { argInfo1, argInfo2 }; foreach (var arg in args) { arg.InputValidation += (object s, ConnectionEventArgs e) => { if (e.SourceConnector.Tag.GetType() != typeof(Argument)) { e.Valid = false; } }; } //toggle not\equal button var equalSection = new NodeInfo.SectionInfo(); var equalButton = new Button(); equalButton.Content = "="; equalButton.Click += (s, e) => { if (condition.Operation == ConditionOperation.EQ) { condition.Operation = ConditionOperation.NEQ; equalButton.Content = "≠"; } else { condition.Operation = ConditionOperation.EQ; equalButton.Content = "="; } }; equalSection.UIPanel = equalButton; if (condition.Operation == ConditionOperation.NEQ) { equalButton.Content = "≠"; } info.Sections.Add(equalSection); var contextSelectionPanels = new StackPanel(); var contextSelectionSection = new NodeInfo.SectionInfo(); //type selection var typeInfoSection = new NodeInfo.SectionInfo(); ComboBox typeCb = new ComboBox(); typeCb.ItemsSource = Enum.GetValues(typeof(ConditionType)); typeCb.Text = Locale.SCHEME_CONDITION_TYPE_SELECT; typeCb.SelectionChanged += (s, e) => { var selection = typeCb.SelectedItem; foreach (FrameworkElement control in contextSelectionPanels.Children) { if (control.Tag.ToString().Equals(selection.ToString())) { control.Visibility = Visibility.Visible; } else { control.Visibility = Visibility.Collapsed; } } condition.Type = (ConditionType)selection; }; typeCb.Margin = new Thickness(0, 3, 0, 3); typeInfoSection.UIPanel = typeCb; info.Sections.Add(typeInfoSection); //position selection var posCombo = new ComboBox(); posCombo.ItemsSource = Enum.GetValues(typeof(ConditionPosition)); posCombo.SelectionChanged += (s, e) => { condition.Data = ((ConditionPosition)posCombo.SelectedItem).ToString(); }; posCombo.Tag = ConditionType.POS; posCombo.Visibility = Visibility.Collapsed; posCombo.SelectedValue = condition.Data; contextSelectionPanels.Children.Add(posCombo); //contact selection var contactCombo = new ComboBox(); contactCombo.ItemsSource = Enum.GetValues(typeof(ConditionContact)); contactCombo.SelectionChanged += (s, e) => { condition.Data = ((ConditionContact)contactCombo.SelectedItem).ToString(); }; contactCombo.Visibility = Visibility.Collapsed; contactCombo.Tag = ConditionType.CONTACT; contactCombo.SelectedValue = condition.Data; contextSelectionPanels.Children.Add(contactCombo); //shared segment selection var segSelectionPanel = new ComboBox(); segSelectionPanel.Visibility = Visibility.Collapsed; segSelectionPanel.Tag = ConditionType.SEG; segSelectionPanel.ItemsSource = segments; segSelectionPanel.SelectionChanged += (s, e) => { condition.Data = (string)segSelectionPanel.SelectedItem; }; segSelectionPanel.SelectedValue = condition.Data; contextSelectionPanels.Children.Add(segSelectionPanel); //semantic (attr-to-attr comparison) selection var semSelectionPanel = new StackPanel(); semSelectionPanel.Visibility = Visibility.Collapsed; semSelectionPanel.Tag = ConditionType.SEM; ComboBox[] semSelectionArgs = new ComboBox[2]; string[] vals = condition.Data?.Split(';'); for (int i = 0; i < 2; i++) { int j = i; //damn closures semSelectionArgs[j] = new ComboBox(); semSelectionArgs[j].DisplayMemberPath = "Name"; if (args[i].Data != null) { semSelectionArgs[i].ItemsSource = ((FactScheme.Argument)args[i].Data).Attributes; } args[i].PropertyChanged += (s, e) => { if (e.PropertyName == "Data") { semSelectionArgs[j].ItemsSource = ((FactScheme.Argument)args[j].Data).Attributes; } }; semSelectionArgs[i].SelectionChanged += (s, e) => { condition.Data = String.Format("{0};{1}", semSelectionArgs[0].SelectedItem?.ToString(), semSelectionArgs[1].SelectedItem?.ToString()); }; semSelectionArgs[i].SelectedValue = vals?.Length > i ? vals[i] : null; semSelectionPanel.Children.Add(semSelectionArgs[i]); } contextSelectionPanels.Children.Add(semSelectionPanel); //syntactic (actants) selection var syntPanel = new StackPanel(); syntPanel.Visibility = Visibility.Collapsed; syntPanel.Tag = ConditionType.SYNT; var modelName = new TextBox(); var actantName = new TextBox(); string[] syntData = condition.Data?.Split(';'); string modelNameText = syntData?.Length > 0 ? syntData[0] : "ModelName"; modelName.Text = modelNameText; modelName.TextChanged += (s, e) => { condition.Data = String.Format("{0};{1}", modelName.Text, actantName.Text); }; string actantNameText = syntData?.Length > 1 ? syntData[1] : "ActantName"; actantName.Text = actantNameText; actantName.TextChanged += (s, e) => { condition.Data = String.Format("{0};{1}", modelName.Text, actantName.Text); }; syntPanel.Children.Add(modelName); syntPanel.Children.Add(actantName); contextSelectionPanels.Children.Add(syntPanel); //morph(gramtab) coherence selection var gramtabCombo = new ComboBox(); gramtabCombo.Tag = ConditionType.MORH; gramtabCombo.Visibility = Visibility.Collapsed; gramtabCombo.ItemsSource = gramtab.Keys; gramtabCombo.SelectionChanged += (s, e) => { condition.Data = (string)gramtabCombo.SelectedItem; }; gramtabCombo.SelectedValue = condition.Data; contextSelectionPanels.Children.Add(gramtabCombo); contextSelectionSection.UIPanel = contextSelectionPanels; info.Sections.Add(contextSelectionSection); typeCb.SelectedValue = condition.Type; info.FillColor = System.Windows.Media.Colors.Gold; return(info); }
private void addFnCatToolStripItem_Click(object sender, EventArgs e) { var fun = CurrentScheme.AddFunctor <FunctorCat>(); getCurrentNetworkView().AddNode(Medium.Convert(fun)); }
void NV_ConnectionRemoved(object sender, network.ConnectionEventArgs e) { Medium.RemoveSchemeConnection(e.SourceConnector, e.DestConnector); }
private void addSchemeConditionButton_Click(object sender, EventArgs e) { Condition cond = CurrentScheme.AddCondition(); getCurrentNetworkView().AddNode(Medium.Convert(cond, CurrentProject.Gramtab, CurrentProject.Segments)); }
private void openProjectDialog_FileOk(object sender, CancelEventArgs e) { Stream fstream = openProjectDialog.OpenFile(); var path = System.IO.Path.GetDirectoryName(openProjectDialog.FileName) + System.IO.Path.DirectorySeparatorChar; CurrentProject = new EditorProject(fstream, path); fstream.Close(); buildOntologyTree(CurrentProject.Ontology); buildDictionaryTree(CurrentProject.Dictionary); XElement xmarkup = CurrentProject.Markup; if (xmarkup != null) { foreach (var xscheme in xmarkup.Elements()) { var scheme = CurrentProject.Bank.Schemes.First(x => x.Name == xscheme.Attribute("name").Value); ElementHost host = initNVHost(scheme); network.NetworkView nv = host.Child as network.NetworkView; foreach (XElement xel in xscheme.Elements()) { network.Node node = null; System.Windows.Thickness margin = new System.Windows.Thickness(); if (xel.Attribute("type").Value == typeof(Argument).ToString()) { Argument arg = scheme.Arguments.First(x => x.Order == int.Parse(xel.Attribute("id").Value)); node = nv.AddNode(Medium.Convert(arg, CurrentProject.Dictionary)); } else if (xel.Attribute("type").Value == typeof(Result).ToString()) { Result res = scheme.Results.First(x => x.Name == xel.Attribute("id").Value); node = nv.AddNode(Medium.Convert(res)); } else if (xel.Attribute("type").Value == typeof(Functor).ToString()) { Functor f = scheme.Functors.First(x => x.CID == uint.Parse(xel.Attribute("id").Value)); node = nv.AddNode(Medium.Convert(f)); } else if (xel.Attribute("type").Value == typeof(Condition).ToString()) { Condition cond = scheme.Conditions.Find(x => x.ID == uint.Parse(xel.Attribute("id").Value)); node = nv.AddNode(Medium.Convert(cond, CurrentProject.Gramtab, CurrentProject.Segments)); } else { continue; } int left = int.Parse(xel.Attribute("left").Value); int top = int.Parse(xel.Attribute("top").Value); margin.Left = left; margin.Top = top; node.Margin = margin; } Medium.LoadViewFromScheme(nv, scheme); } } if (!CurrentProject.Bank.Schemes.Any()) { createScheme(); } //updateBankListView(); CurrentScheme = CurrentProject.Bank.Schemes[0]; bankListDataGrid.DataSource = CurrentProject.Bank.Schemes; schemeSegmentCombo.DataSource = CurrentProject.Segments; statusLabel.Text = Locale.STATUS_PROJECT_LOADED; }