public List <string> labelsFromText(string text) { List <string> labels = StringCollectionConverter.convert(text); labels.RemoveAt(0); return(labels); }
public graphWindow(designGraph dg, CanvasProperty canvasProperties, string filename, string title) { /* the following is common to all GS window types. */ InitializeComponent(); Owner = main; ShowInTaskbar = false; foreach (CommandBinding cb in main.CommandBindings) { CommandBindings.Add(cb); graphGUI.CommandBindings.Add(cb); } foreach (InputBinding ib in main.InputBindings) { InputBindings.Add(ib); graphGUI.InputBindings.Add(ib); } /***************************************************/ graph = graphGUI.graph = dg; graphGUI.ScrollOwner = scrollViewer1; canvasProps = canvasProperties ?? new CanvasProperty(); canvasProps.AddGUIToControl(graphGUI); AdoptWindowWideCanvasProperties(); this.filename = !string.IsNullOrEmpty(filename) ? filename : "Untitled"; Title = !string.IsNullOrEmpty(title) ? title : Path.GetFileNameWithoutExtension(this.filename); graphGUI.InitDrawGraph(); txtGlobalVariables.Text = DoubleCollectionConverter.Convert(graph.globalVariables); txtGlobalLabels.Text = StringCollectionConverter.Convert(graph.globalLabels); }
/* K Changes to Labels and Variables */ private void txtKGlobalLabels_LostFocus(object sender, RoutedEventArgs e) { var labels = StringCollectionConverter.Convert(txtKGlobalLabels.Text); var removedKLabels = KLabels.Where(a => !labels.Contains(a)).ToList(); foreach (string a in removedKLabels) { rule.L.globalLabels.Remove(a); rule.R.globalLabels.Remove(a); } KLabels = labels; var union = KLabels.Union(rule.L.globalLabels); main.property.RulePrpt.txtLGlobalLabels_LostFocus(new TextBox { Text = StringCollectionConverter.Convert( new List <string>(union)) }, null); union = KLabels.Union(rule.R.globalLabels); main.property.RulePrpt.txtRGlobalLabels_LostFocus(new TextBox { Text = StringCollectionConverter.Convert( new List <string>(union)) }, null); }
internal void Update(ruleSet RuleSet, ruleSetWindow rsW) { SelectedRuleSet = RuleSet; txtName.Text = rsW.Title; for (int i = 0; i < GSApp.settings.rulesets.GetLength(0); i++) { if (SelectedRuleSet.Equals(GSApp.settings.rulesets[i])) { txtName.Text += " (set to RuleSet #" + i + ")"; break; } } txtTriggerRuleNo.Text = SelectedRuleSet.TriggerRuleNum.ToString(); cmdChoiceMethod.SelectedIndex = cmdChoiceMethod.Items.IndexOf(SelectedRuleSet.choiceMethod); cmdInterimCandidates.SelectedIndex = cmdInterimCandidates.Items.IndexOf(SelectedRuleSet.interimCandidates); cmdFinalCandidates.SelectedIndex = cmdFinalCandidates.Items.IndexOf(SelectedRuleSet.finalCandidates); cmdAfterNormalCycle.SelectedIndex = cmdAfterNormalCycle.Items.IndexOf(SelectedRuleSet.generationAfterNormal); cmdChoiceSendsStop.SelectedIndex = cmdChoiceSendsStop.Items.IndexOf(SelectedRuleSet.generationAfterChoice); cmdNoOfCallsReached.SelectedIndex = cmdNoOfCallsReached.Items.IndexOf(SelectedRuleSet.generationAfterCycleLimit); cmdNoRulesRecognized.SelectedIndex = cmdNoRulesRecognized.Items.IndexOf(SelectedRuleSet.generationAfterNoRules); cmdTriggerRuleInvoked.SelectedIndex = cmdTriggerRuleInvoked.Items.IndexOf(SelectedRuleSet.generationAfterTriggerRule); txtRecognizeSourceFiles.Text = StringCollectionConverter.Convert(SelectedRuleSet.recognizeSourceFiles); txtApplySourceFiles.Text = StringCollectionConverter.Convert(SelectedRuleSet.applySourceFiles); }
private void numOfSteps_Changed() { if (checkForSeedAndRuleSets()) { int num, i = 0; int[] numOfCalls = new int[Program.settings.numOfRuleSets]; List <string> numbers = StringCollectionConverter.convert(this.numOfRandSteps.Text.Trim()); Boolean successfulEntry = true; this.numOfRandSteps.Text = "#steps"; foreach (string a in numbers) { if (i == Program.settings.numOfRuleSets) { if (DialogResult.Yes == MessageBox.Show("There are no rulesets to assign to " + a + ". Would you like to continue with current limits?", "More arguments than rulesets.", MessageBoxButtons.YesNo, MessageBoxIcon.Error)) { successfulEntry = true; break; } else { successfulEntry = false; break; } } if ((int.TryParse(a, out num)) && (num > 0) && (num <= Program.settings.maxRulesToApply)) { numOfCalls[i++] = num; } else if (DialogResult.Yes == MessageBox.Show("Unable to change \"" + a + "\" for Rule-Set #" + i + " into number greater than zero and less than or equal to " + Program.settings.maxRulesToApply + ". Do you approve of setting to the value of " + Program.settings.maxRulesToApply + "? (If no, this call will be cancelled.)", "Value not defined.", MessageBoxButtons.YesNo, MessageBoxIcon.Information)) { numOfCalls[i++] = Program.settings.maxRulesToApply; } else { successfulEntry = false; break; } } if (successfulEntry) { Boolean display = (DialogResult.Yes == MessageBox.Show("Would you like to see the graph " + "after each rule application?", "Display Interim Graphs", MessageBoxButtons.YesNo, MessageBoxIcon.Information)); Generation.randomChoose GenerationApproach = new Generation.randomChoose(Program.seed, Program.rulesets, numOfCalls, display, Program.settings.recompileRules, Program.settings.execDir, Program.settings.compiledparamRules); addAndShowSearchController(new searchProcessController(GenerationApproach), true); searchControls[searchControls.Count - 1].SendToBack(); } } }
private void Update() { txtFilename.Text = (string.IsNullOrWhiteSpace(ruleWin.filename)) ? ruleWin.Title : ruleWin.filename; txtFilename.PageRight(); /* updating L, K, and R global variables. */ ruleWin.txtLGlobalVariables.Text = txtLVariables.Text = DoubleCollectionConverter.Convert(rule.L.globalVariables); ruleWin.txtRGlobalVariables.Text = txtRVariables.Text = DoubleCollectionConverter.Convert(rule.R.globalVariables); var KVars = rule.R.globalVariables.Intersect(rule.L.globalVariables); var listKVars = new List <double>(); foreach (double x in KVars) { listKVars.Add(x); } ruleWin.txtKGlobalVariables.Text = DoubleCollectionConverter.Convert(listKVars); /* updating L, K, and R global labels. This involves an additional need to consider both order labels and * negating labels. */ ruleWin.txtLGlobalLabels.Text = txtLGlobalLabels.Text = StringCollectionConverter.Convert(rule.L.globalLabels); ruleWin.txtRGlobalLabels.Text = txtRGlobalLabels.Text = StringCollectionConverter.Convert(rule.R.globalLabels); /* the idea below was to change the way orderLabels appear but it lead to problems when switching * back and forth between ordered and unordered. It is repairable but truthfully, most rules do not have * a lot of labels. The host may build up a substantial amount, so this concept may be more appropriate * to graphDisplay and graph properties than rules. */ //if (rule.OrderedGlobalLabels) //{ // ruleWin.txtLGlobalLabels.Text = txtLGlobalLabels.Text // = txtLGlobalLabels.Text.Replace(", ", "-"); // ruleWin.txtRGlobalLabels.Text = txtRGlobalLabels.Text // = txtRGlobalLabels.Text.Replace(", ", "-"); // ruleWin.txtKGlobalLabels.Text = ""; //} //else //{ var listKLabels = new List <string>(rule.R.globalLabels.Intersect(rule.L.globalLabels)); ruleWin.txtKGlobalLabels.Text = StringCollectionConverter.Convert(listKLabels); //} txtLNegatingLabels.Text = StringCollectionConverter.Convert(rule.negateLabels); if (txtLNegatingLabels.Text.Length > 0) { ruleWin.txtLGlobalLabels.Text += " ~(" + txtLNegatingLabels.Text + ")"; } txtApplyFunctions.Text = StringCollectionConverter.Convert(rule.applyFunctions); txtRecognizeFunctions.Text = StringCollectionConverter.Convert(rule.recognizeFunctions); chkContainsAllGlobalLabels.IsChecked = rule.containsAllGlobalLabels; chkInduced.IsChecked = rule.induced; chkOrderedGlobalLabels.IsChecked = rule.OrderedGlobalLabels; chkSpanning.IsChecked = rule.spanning; chkTerminationRule.IsChecked = rule.termination; }
public void Generic_Converter_Throws_When_Given_Incompatible_Value() { IStringTemplateValueConverter converter = new StringCollectionConverter(); var shouldWork = converter.Convert(StringCollectionValues); Assert.Equal(ExpectedStringCollectionConcatenation, shouldWork); // sanity check Assert.Throws <NotSupportedException>(() => converter.Convert("whatever")); }
public string textFromNameAndLabels(string name, List <string> labels) { if (labels.Count > 0) { return(name + " (" + StringCollectionConverter.convert(labels) + ")"); } else { return(name); } }
private void txtNegLabels_LostFocus(object sender, RoutedEventArgs e) { var lststr = StringCollectionConverter.Convert(txtNegLabels.Text); ((ruleHyperarc)firstHyperArc).negateLabels.Clear(); foreach (string str in lststr) { ((ruleHyperarc)firstHyperArc).negateLabels.Add(str); } Update(); }
private void txtFreeArcLabels_LostFocus(object sender, RoutedEventArgs e) { var lststr = StringCollectionConverter.Convert(txtFreeArcLabels.Text.Replace("<any>", "")); selectedEmbeddingRule.freeArcLabels.Clear(); foreach (string str in lststr) { selectedEmbeddingRule.freeArcLabels.Add(str); } Update(); }
private void txtNeighborNegabels_LostFocus(object sender, RoutedEventArgs e) { var lststr = StringCollectionConverter.Convert(txtNeighborNegabels.Text.Replace("<none>", "")); selectedEmbeddingRule.neighborNodeNegabels.Clear(); foreach (string str in lststr) { selectedEmbeddingRule.neighborNodeNegabels.Add(str); } Update(); }
private void btnSaveToFile_Click(object sender, RoutedEventArgs e) { if (newSettings.numOfRuleSets < newSettings.defaultRSFileNames.Count) { newSettings.defaultRSFileNames.RemoveRange(newSettings.numOfRuleSets, newSettings.defaultRSFileNames.Count - newSettings.numOfRuleSets); } newSettings.DefaultRuleSets = StringCollectionConverter.Convert(newSettings.defaultRSFileNames); newSettings.saveNewSettings(); btnApplyInThisProcess.IsDefault = true; }
private void txtRecognizeSourceFiles_LostFocus(object sender, RoutedEventArgs e) { var lststr = StringCollectionConverter.Convert(txtRecognizeSourceFiles.Text); SelectedRuleSet.recognizeSourceFiles.Clear(); foreach (string s in lststr) { RuleParamCodeFiler.checkForRuleFile(SelectedRuleSet, SelectedRuleSet.recognizeSourceFiles, s); } txtRecognizeSourceFiles.Text = StringCollectionConverter.Convert(SelectedRuleSet.recognizeSourceFiles); }
/// <summary> /// Gets the save filename. /// </summary> /// <param name = "filter">The filter of file types.</param> /// <param name = "name">a starting name.</param> /// <param name = "dir">The directory</param> /// <returns></returns> public string GetSaveFilename(string filter, string name, string dir) { var fileChooser = new SaveFileDialog(); fileChooser.Title = "Save Active " + StringCollectionConverter.Convert(filter)[0] + " as ..."; fileChooser.InitialDirectory = dir; fileChooser.Filter = filter; fileChooser.FileName = name; fileChooser.CheckFileExists = false; string filename; try { if ((Boolean)fileChooser.ShowDialog(this)) { filename = fileChooser.FileName; if (string.IsNullOrWhiteSpace(filename)) { MessageBox.Show("Invalid file name", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } return(filename); } return(""); } catch (Exception exc) { try { /* this is wonky and strange, but the reason is that the SaveFileDialog * will crash if the FileName does not pass the filter. There is a bunch * of code that could be written to avoid this, such as parsing the filter, * but it seemed fine to just reset the FileName and try once more. */ fileChooser.FileName = ""; if ((Boolean)fileChooser.ShowDialog(this)) { filename = fileChooser.FileName; if (string.IsNullOrWhiteSpace(filename)) { MessageBox.Show("Invalid file name", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } return(filename); } return(""); } catch { ErrorLogger.Catch(exc); return(""); } } }
private void btnSaveAS_Click(object sender, RoutedEventArgs e) { if (newSettings.numOfRuleSets < newSettings.defaultRSFileNames.Count) { newSettings.defaultRSFileNames.RemoveRange(newSettings.numOfRuleSets, newSettings.defaultRSFileNames.Count - newSettings.numOfRuleSets); } newSettings.DefaultRuleSets = StringCollectionConverter.Convert(newSettings.defaultRSFileNames); newSettings.saveNewSettings(main.GetSaveFilename("GraphSynth config file (*.gsconfig)|*.gsconfig", "", GSApp.settings.WorkingDirAbsolute)); btnApplyInThisProcess.IsDefault = true; }
private void txtNegLabels_LostFocus(object sender, RoutedEventArgs e) { var caretIndex = txtNegLabels.CaretIndex; var origLength = txtNegLabels.Text.Length; var lststr = StringCollectionConverter.Convert(txtNegLabels.Text); ((ruleNode)firstNode).negateLabels.Clear(); foreach (string str in lststr) { ((ruleNode)firstNode).negateLabels.Add(str); } Update(); TextBoxHelper.SetCaret(txtNegLabels, caretIndex, origLength); }
public void txtLNegatingLabels_LostFocus(object sender, RoutedEventArgs e) { var senderTextBox = (TextBox)sender; var caretIndex = senderTextBox.CaretIndex; var origLength = senderTextBox.Text.Length; var lststr = StringCollectionConverter.Convert(senderTextBox.Text); rule.negateLabels.Clear(); foreach (string str in lststr) { rule.negateLabels.Add(str); } Update(); TextBoxHelper.SetCaret(senderTextBox, caretIndex, origLength); }
public void updateGraphControl(Netron.GraphLib.UI.GraphControl graphControl1, Label globalLabelsText) { if (this.globalLabels.Count > 0) { globalLabelsText.Text = StringCollectionConverter.convert(this.globalLabels); } else { globalLabelsText.Text = " "; } foreach (node n in nodes) { n.displayShape.Text = textForNode(n); /* make sure node is of right type - if not call the replacement function */ if ((n.nodeType != null) && (n.GetType() != typeof(GraphSynth.Representation.ruleNode)) && (n.GetType() != n.nodeType)) { replaceNodeWithInheritedType(n); } } foreach (arc a in arcs) { if (a.doublyDirected) { a.displayShape.LineEnd = ConnectionEnd.BothFilledArrow; } else if (a.directed) { a.displayShape.LineEnd = ConnectionEnd.RightFilledArrow; } else { a.displayShape.LineEnd = ConnectionEnd.NoEnds; } a.displayShape.Text = textForArc(a); /* make sure node is of right type - if not call the replacement function */ if ((a.arcType != null) && (a.GetType() != typeof(GraphSynth.Representation.ruleArc)) && (a.GetType() != a.arcType)) { replaceArcWithInheritedType(a, a.From, a.To); } } }
private void txtApplyFunctions_LostFocus(object sender, RoutedEventArgs e) { var senderTextBox = (TextBox)sender; var caretIndex = senderTextBox.CaretIndex; var origLength = senderTextBox.Text.Length; var lststr = StringCollectionConverter.Convert(senderTextBox.Text); rule.applyFunctions.Clear(); foreach (string str in lststr) { rule.applyFunctions.Add(str); } Update(); senderTextBox.Text += " "; TextBoxHelper.SetCaret(senderTextBox, caretIndex, origLength); RuleParamCodeFiler.checkForFunctions(false, rule, rule.applyFunctions); }
private void btnApplyInThisProcess_Click(object sender, RoutedEventArgs e) { if (newSettings.numOfRuleSets < newSettings.defaultRSFileNames.Count) { newSettings.defaultRSFileNames.RemoveRange(newSettings.numOfRuleSets, newSettings.defaultRSFileNames.Count - newSettings.numOfRuleSets); } newSettings.DefaultRuleSets = StringCollectionConverter.Convert(newSettings.defaultRSFileNames); var tempSettings = GSApp.settings; GSApp.settings = newSettings; SearchIO.defaultVerbosity = newSettings.DefaultVerbosity; try { newSettings.filer = new WPFFiler(newSettings.InputDirAbs, newSettings.OutputDirAbs, newSettings.RulesDirAbs); newSettings.LoadDefaultSeedAndRuleSets(); for (int i = 0; i < newSettings.numOfRuleSets; i++) { if (newSettings.rulesets[i] != null) { ((ruleSet)newSettings.rulesets[i]).RuleSetIndex = i; } } /* The following three command are a repeat from MainWindow.Startup.cs. */ main.setUpGraphElementAddButtons(); main.setUpGraphLayoutMenu(); main.setUpSearchProcessMenu(); } catch (Exception ee) { var msgResult = MessageBox.Show("Settings did not work because of the following error: " + ee + " Revert to Previous Settings?", "Error in Settings. Revert back?", MessageBoxButton.YesNo, MessageBoxImage.Warning); if (msgResult == MessageBoxResult.Yes || msgResult == MessageBoxResult.OK) { GSApp.settings = tempSettings; } return; } Close(); }
private void applyButton_Click(object sender, EventArgs e) { newSettings.stringOfRSFileNames = StringCollectionConverter.convert(newSettings.defaultRSFileNames); globalSettings tempSettings = Program.settings; Program.settings = newSettings; SearchIO.defaultVerbosity = newSettings.defaultVerbosity; try { newSettings.loadDefaultSeedAndRuleSets(); } catch (Exception ee) { if (DialogResult.Yes == MessageBox.Show("Settings did not work because of the following error: " + ee.ToString() + " Revert to Previous Settings?", "Error in Settings. Revert back?", MessageBoxButtons.YesNo, MessageBoxIcon.Warning)) { Program.settings = tempSettings; } return; } cancelButton_Click(sender, e); }
private void Update() { txtFilename.Text = (string.IsNullOrWhiteSpace(graphWin.filename)) ? graphWin.Title: graphWin.filename; txtFilename.PageRight(); if (GSApp.settings.seed == selectedGraph) { txtSeed.Text = "This is the current seed."; txtSeed.Height = double.NaN; } else { txtSeed.Text = ""; txtSeed.Height = 0.0; } graphWin.txtGlobalVariables.Text = txtVariables.Text = DoubleCollectionConverter.Convert(selectedGraph.globalVariables); graphWin.txtGlobalLabels.Text = txtGlobalLabels.Text = StringCollectionConverter.Convert(selectedGraph.globalLabels); }
protected IconShape(graphElement e, GraphGUI gd, object textDisplayData, double maxOpacity, double radiusMultiplier, double radiusAddition, object arcController) { GraphElement = e; if (textDisplayData == null) { textDisplayData = ""; } else { textDisplayData = textDisplayData.ToString().Split(new[] { ':' })[0]; } var tDDataList = StringCollectionConverter.Convert(textDisplayData.ToString()); double result; if ((tDDataList.Count > 1) && (double.TryParse(tDDataList[1], out result))) { DisplayTextDistance = result; } else { DisplayTextDistance = double.NaN; } if ((tDDataList.Count > 2) && (double.TryParse(tDDataList[2], out result))) { DisplayTextPosition = result; } else { DisplayTextPosition = double.NaN; } if ((tDDataList.Count > 3) && (double.TryParse(tDDataList[3], out result))) { FontSize = result; } else { FontSize = double.NaN; } var binding = new Binding { Source = gd, Mode = BindingMode.OneWay, Path = new PropertyPath(GraphGUI.ScaleFactorProperty) }; SetBinding(ScaleFactorProperty, binding); binding = new Binding { Converter = new IconOpacityConverter(this, maxOpacity, radiusMultiplier, radiusAddition), Source = gd, Mode = BindingMode.OneWay, Path = new PropertyPath(GraphGUI.MouseLocationProperty) }; SetBinding(StrokeOpacityProperty, binding); /* whether or not to show the text depends on various parameters */ var multiBinding = new MultiBinding { Converter = new DisplayTextConverter(), Mode = BindingMode.OneWay, ConverterParameter = GraphElement }; { binding = new Binding { Source = this, Path = new PropertyPath(ShowNameProperty) }; multiBinding.Bindings.Add(binding); binding = new Binding { Source = this, Path = new PropertyPath(ShowLabelsProperty) }; multiBinding.Bindings.Add(binding); binding = new Binding { Source = this, Path = new PropertyPath(FontSizeProperty) }; multiBinding.Bindings.Add(binding); } SetBinding(DisplayTextProperty, multiBinding); /* where is text to be shown? */ multiBinding = new MultiBinding { Converter = new PositionTextConverter(), ConverterParameter = arcController, Mode = BindingMode.OneWay }; { binding = new Binding { Source = this, Path = new PropertyPath(DisplayTextDistanceProperty) }; multiBinding.Bindings.Add(binding); binding = new Binding { Source = this, Path = new PropertyPath(DisplayTextPositionProperty) }; multiBinding.Bindings.Add(binding); binding = new Binding { Source = this, Path = new PropertyPath(DisplayTextProperty) }; multiBinding.Bindings.Add(binding); } SetBinding(TextPointProperty, multiBinding); }
private static void createApplyFunctionTemplate(string path, grammarRule rule, string funcName) { var r = new StreamReader(new FileStream(path, FileMode.Open, FileAccess.Read), Encoding.Default); var fileString = r.ReadToEnd(); /** find place to insert new function **/ var position = fileString.IndexOf("#region Parametric Application Rules", 0, StringComparison.Ordinal); while (fileString.IndexOf("#endregion", position + 1, StringComparison.Ordinal) > 0) { position = fileString.IndexOf("#endregion", position + 1, StringComparison.Ordinal); } /***************************************/ var sb = new StringBuilder(""); r.Close(); sb.Append("\n/* This is APPLY for the rule entitled: "); sb.Append(rule.name); sb.Append(" */"); sb.Append("\npublic void "); sb.Append(funcName); sb.Append( "(option opt, designGraph host, designGraph Rmapping, double[] parameters)\n{\n"); sb.Append("#region Define Mapped Elements\n"); sb.Append("/* the following variables are declared for your convenience. They are the mapped elements" + " of the L, K, and R elements\n" + " * in the host graph. The convention that is used is when the element is only in L, then the\n" + " * variable name is followed by \"_deleted\", when the element is only in R, then it is appended\n" + " * with \"_added\". If it is in both (in K), then no post-script is added. */\n"); for (int i = 0; i < rule.L.nodes.Count; i++) { var n = (ruleNode)rule.L.nodes[i]; if (n.NotExist) { continue; } var name = (rule.R.nodes.Any(rn => rn.name.Equals(n.name))) ? n.name : n.name + "_deleted"; var where = (rule.R.nodes.Any(rn => rn.name.Equals(n.name))) ? "K" : "L"; if (n.localLabels.Count > 0) { sb.Append("/* " + name + " is the node in " + where + " that has labels: " + StringCollectionConverter.Convert(n.localLabels) + ";"); } else { sb.Append("/* " + name + " is the node in " + where + " that has no labels;"); } if (n.negateLabels.Count > 0) { sb.Append(" has the negating labels: " + StringCollectionConverter.Convert(n.negateLabels) + ";"); } sb.Append("\n * is connected to: " + StringCollectionConverter.Convert(n.arcs.Select(a => a.name)) + ";"); sb.Append(" and is located at [" + n.X + ", " + n.Y + ", " + n.Z + "]. */\n"); sb.Append("var " + name + " = opt.nodes[" + i + "];\n\n"); } for (int i = 0; i < rule.R.nodes.Count; i++) { var n = (ruleNode)rule.R.nodes[i]; if (rule.L.nodes.Any(ln => ln.name.Equals(n.name))) { continue; } if (n.localLabels.Count > 0) { sb.Append("/* " + n.name + "_added is the node in R that has labels: " + StringCollectionConverter.Convert(n.localLabels) + ";"); } else { sb.Append("/* " + n.name + "_added is the node in R that has no labels;"); } sb.Append("\n * is connected to: " + StringCollectionConverter.Convert(n.arcs.Select(a => a.name)) + ";"); sb.Append(" and is located at [" + n.X + ", " + n.Y + ", " + n.Z + "]. */\n"); sb.Append("var " + n.name + "_added = Rmapping.nodes[" + i + "];\n\n"); } for (int i = 0; i < rule.L.arcs.Count; i++) { var a = (ruleArc)rule.L.arcs[i]; if (a.NotExist) { continue; } var name = (rule.R.arcs.Any(ra => ra.name.Equals(a.name))) ? a.name : a.name + "_deleted"; var where = (rule.R.arcs.Any(ra => ra.name.Equals(a.name))) ? "K" : "L"; if (a.localLabels.Count > 0) { sb.Append("/* " + name + " is the arc in " + where + " that has labels: " + StringCollectionConverter.Convert(a.localLabels) + ";"); } else { sb.Append("/* " + name + " is the arc in " + where + " that has no labels;"); } if (a.negateLabels.Count > 0) { sb.Append(" has the negating labels: " + StringCollectionConverter.Convert(a.negateLabels) + ";"); } var fromName = a.From == null ? "nothing" : a.From.name; var toName = a.To == null ? "nothing" : a.To.name; sb.Append("\n * and is connected from " + fromName + " to " + toName + ". */\n"); sb.Append("var " + name + " = opt.arcs[" + i + "];\n\n"); } for (int i = 0; i < rule.R.arcs.Count; i++) { var a = (ruleArc)rule.R.arcs[i]; if (rule.L.arcs.Any(ln => ln.name.Equals(a.name))) { continue; } if (a.localLabels.Count > 0) { sb.Append("/* " + a.name + "_added is the arc in R that has labels: " + StringCollectionConverter.Convert(a.localLabels) + ";"); } else { sb.Append("/* " + a.name + "_added is the arc in R that has no labels;"); } var fromName = a.From == null ? "nothing" : a.From.name; var toName = a.To == null ? "nothing" : a.To.name; sb.Append("\n * and is connected from " + fromName + " to " + toName + ". */\n"); sb.Append("var " + a.name + "_added = Rmapping.arcs[" + i + "];\n\n"); } for (int i = 0; i < rule.L.hyperarcs.Count; i++) { var ha = (ruleHyperarc)rule.L.hyperarcs[i]; if (ha.NotExist) { continue; } var name = (rule.R.hyperarcs.Any(ra => ra.name.Equals(ha.name))) ? ha.name : ha.name + "_deleted"; var where = (rule.R.hyperarcs.Any(ra => ra.name.Equals(ha.name))) ? "K" : "L"; if (ha.localLabels.Count > 0) { sb.Append("/* " + name + " is the hypearc in " + where + " that has labels: " + StringCollectionConverter.Convert(ha.localLabels) + ";"); } else { sb.Append("/* " + name + " is the hyperarc in " + where + " that no labels;"); } if (ha.negateLabels.Count > 0) { sb.Append(" has the negating labels: " + StringCollectionConverter.Convert(ha.negateLabels) + ";\n"); } sb.Append("\n * and is connected to: " + StringCollectionConverter.Convert(ha.nodes.Select(n => n.name)) + ". */\n"); sb.Append("var " + name + " = opt.hyperarcs[" + i + "];\n\n"); } for (int i = 0; i < rule.R.hyperarcs.Count; i++) { var a = (ruleHyperarc)rule.R.hyperarcs[i]; if (rule.L.hyperarcs.Any(ln => ln.name.Equals(a.name))) { continue; } if (a.localLabels.Count > 0) { sb.Append("/* " + a.name + "_added is the hyperarc in R that has labels: " + StringCollectionConverter.Convert(a.localLabels) + ";"); } else { sb.Append("/* " + a.name + "_added is the hyperarc in R that has no labels;"); } sb.Append("\n * and is connected to: " + StringCollectionConverter.Convert(a.nodes.Select(n => n.name)) + ". */\n"); sb.Append("var " + a.name + "_added = Rmapping.hyperarcs[" + i + "];\n\n"); } sb.Append("#endregion\n\n\n"); sb.Append("\n\n/* here is where the code for the APPLY function is to be located.\n"); sb.Append("* please modify host (or located nodes) with the input from parameters. */\n"); sb.Append("\n}\n"); fileString = fileString.Insert(position, sb.ToString()); var w = new StreamWriter(new FileStream(path, FileMode.Create, FileAccess.Write), Encoding.Default); w.Write(fileString); w.Flush(); w.Close(); }
public void updateGraphControl(Netron.GraphLib.UI.GraphControl graphControl1, Label globalLabelsText) { try { string defaultShapeKey = "8ED1469D-90B2-43ab-B000-4FF5C682F530"; Boolean isFixed = true; Random rnd = new Random(); #region Global Labels if (this.globalLabels.Count > 0) { globalLabelsText.Text = StringCollectionConverter.convert(this.globalLabels); } else { globalLabelsText.Text = " "; } #endregion #region display the nodes for (int i = nodes.Count - 1; i >= 0; i--) { node n = nodes[i]; #region if it has no displayShape if (n.displayShape == null) { if (n.shapekey == null) { n.shapekey = defaultShapeKey; } if (n.screenX == 0.0 && n.screenY == 0.0) { n.screenX = rnd.Next(50, graphControl1.Width - 100); n.screenY = rnd.Next(20, graphControl1.Height - 20); isFixed = false; } else { isFixed = true; } n.displayShape = graphControl1.AddShape(n.shapekey, new PointF(n.screenX, n.screenY)); /* if the prev. statement didn't take, it's likely the shapekey wasn't recognized. * there we try again with the default ShapeKey. */ if (n.displayShape == null) { n.displayShape = graphControl1.AddShape(defaultShapeKey, new PointF(n.screenX, n.screenY)); } } #endregion else if (!graphControl1.Shapes.Contains(n.displayShape)) { /* a shape is defined for the node but is not displayed */ n.displayShape = graphControl1.AddShape(n.displayShape); } n.displayShape.Text = textForNode(n); n.displayShape.IsFixed = isFixed; /* make sure node is of right type - if not call the replacement function */ if ((n.nodeType != null) && (n.GetType() != typeof(GraphSynth.Representation.ruleNode)) && (n.GetType() != n.nodeType)) { replaceNodeWithInheritedType(n); } } #endregion #region display the arcs for (int i = arcs.Count - 1; i >= 0; i--) { arc a = arcs[i]; node fromNode = a.From; node toNode = a.To; Connector fromConnect = null; Connector toConnect = null; if ((fromNode == null) || (fromNode.displayShape == null)) { a.fromConnector = 0; if (a.displayShape == null || a.displayShape.From.BelongsTo == null) { fromConnect = addNullShape(graphControl1, 0).Connectors[0]; } else { fromConnect = a.displayShape.From; } } else if ((a.fromConnector == -1) || (a.fromConnector >= fromNode.displayShape.Connectors.Count)) { a.fromConnector = rnd.Next(fromNode.displayShape.Connectors.Count); fromConnect = fromNode.displayShape.Connectors[a.fromConnector]; } else { fromConnect = fromNode.displayShape.Connectors[a.fromConnector]; } /* now repeat same process for To */ if ((toNode == null) || (toNode.displayShape == null)) { a.toConnector = 0; if (a.displayShape == null || a.displayShape.To.BelongsTo == null) { toConnect = addNullShape(graphControl1, 1).Connectors[0]; } else { toConnect = a.displayShape.To; } } else if ((a.toConnector == -1) || (a.toConnector >= toNode.displayShape.Connectors.Count)) { a.toConnector = rnd.Next(toNode.displayShape.Connectors.Count); toConnect = toNode.displayShape.Connectors[a.toConnector]; } else { toConnect = toNode.displayShape.Connectors[a.toConnector]; } if (((a.displayShape != null) && (!graphControl1.Connections.Contains(a.displayShape)) && ((a.displayShape.From == null) || (a.displayShape.To == null))) || ((a.displayShape == null) && (fromConnect == null) && (toConnect == null))) { removeArc(a); } else { if (a.displayShape == null) { a.displayShape = graphControl1.AddConnection(fromConnect, toConnect); } else if (!graphControl1.Connections.Contains(a.displayShape)) { a.displayShape = graphControl1.AddConnection(a.displayShape.From, a.displayShape.To); } /* a shape is defined for the node but is not displayed * Rectangular, Default, Bezier */ if (a.curveStyle != null) { a.displayShape.LinePath = a.curveStyle; } if (a.doublyDirected) { a.displayShape.LineEnd = ConnectionEnd.BothFilledArrow; } else if (a.directed) { a.displayShape.LineEnd = ConnectionEnd.RightFilledArrow; } else { a.displayShape.LineEnd = ConnectionEnd.NoEnds; } a.displayShape.Text = textForArc(a); a.displayShape.ShowLabel = true; } /* make sure node is of right type - if not call the replacement function */ if ((a.arcType != null) && (a.GetType() != typeof(GraphSynth.Representation.ruleArc)) && (a.GetType() != a.arcType)) { replaceArcWithInheritedType(a, fromNode, toNode); } } #endregion } catch (Exception e) { MessageBox.Show("There was an error displaying the graph. Please save work and re-open. (Error: " + e.ToString() + ")", "Error Displaying Graph", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void txtLabels_LostFocus(object sender, RoutedEventArgs e) { if (hyperarcs.Count == 0) { return; } MultiBindingExpression mbe; var caretIndex = txtLabels.CaretIndex; var origLength = txtLabels.Text.Length; var oldLabels = firstHyperArc.localLabels; var newLabels = StringCollectionConverter.Convert(txtLabels.Text); if ((gui is RuleDisplay) && (gui == ((RuleDisplay)gui).rW.graphGUIK)) { var rW = ((RuleDisplay)gui).rW; var Larc = rW.rule.L.hyperarcs.Find(b => string.Equals(b.name, firstHyperArc.name)); var Rarc = rW.rule.R.hyperarcs.Find(b => string.Equals(b.name, firstHyperArc.name)); var removedKLabels = oldLabels.Where(a => !newLabels.Contains(a)).ToList(); foreach (string a in removedKLabels) { Larc.localLabels.Remove(a); Rarc.localLabels.Remove(a); } var newLLabels = new List <string>(Larc.localLabels.Union(newLabels)); Larc.localLabels.Clear(); foreach (string a in newLLabels) { Larc.localLabels.Add(a); } var nI = ((HyperArcShape)Larc.DisplayShape.Shape).icon; mbe = BindingOperations.GetMultiBindingExpression(nI, IconShape.DisplayTextProperty); mbe.UpdateTarget(); var newRLabels = new List <string>(Rarc.localLabels.Union(newLabels)); Rarc.localLabels.Clear(); foreach (string a in newRLabels) { Rarc.localLabels.Add(a); } nI = ((HyperArcShape)Rarc.DisplayShape.Shape).icon; mbe = BindingOperations.GetMultiBindingExpression(nI, IconShape.DisplayTextProperty); mbe.UpdateTarget(); } else if (gui is RuleDisplay) { // this is a rule LHS or RHS var rW = ((RuleDisplay)gui).rW; hyperarc otherHyperArc = null; otherHyperArc = gui == rW.graphGUIL ? rW.rule.R.hyperarcs.Find(b => string.Equals(b.name, firstHyperArc.name)) : rW.rule.L.hyperarcs.Find(b => string.Equals(b.name, firstHyperArc.name)); if (otherHyperArc != null) { var Klabels = new List <string>(otherHyperArc.localLabels.Intersect(newLabels)); otherHyperArc = rW.graphGUIK.graph.hyperarcs.Find(b => string.Equals(b.name, firstHyperArc.name)); otherHyperArc.localLabels.Clear(); foreach (string a in Klabels) { otherHyperArc.localLabels.Add(a); } var nI = ((HyperArcShape)otherHyperArc.DisplayShape.Shape).icon; mbe = BindingOperations.GetMultiBindingExpression(nI, IconShape.DisplayTextProperty); mbe.UpdateTarget(); } } firstHyperArc.localLabels.Clear(); foreach (string a in newLabels) { firstHyperArc.localLabels.Add(a); } mbe = BindingOperations.GetMultiBindingExpression(hyperArcIcon, IconShape.DisplayTextProperty); mbe.UpdateTarget(); Update(); TextBoxHelper.SetCaret(txtLabels, caretIndex, origLength); }
private void Update() { if (hyperarcs.Count == 1) { txtName.IsEnabled = txtLabels.IsEnabled = txtVariables.IsEnabled = true; txtName.Text = firstHyperArc.name; if (firstHyperArc is ruleHyperarc) { btnConfirm.Visibility = Visibility.Visible; } else { btnConfirm.Visibility = Visibility.Hidden; } txtLabels.Text = StringCollectionConverter.Convert(firstHyperArc.localLabels); txtVariables.Text = DoubleCollectionConverter.Convert(firstHyperArc.localVariables); txtHyperArcType.IsEnabled = true; if (gui is RuleDisplay) { txtHyperArcType.Text = ((ruleHyperarc)firstHyperArc).TargetType; } else { txtHyperArcType.Text = firstHyperArc.GetType().ToString(); } if ((gui is RuleDisplay) && (gui == ((RuleDisplay)gui).rW.graphGUIL)) { chkContainsLocalLabels.IsChecked = ((ruleHyperarc)firstHyperArc).containsAllLocalLabels; chkStrictNodeCount.IsChecked = ((ruleHyperarc)firstHyperArc).strictNodeCountMatch; chkNotExist.IsChecked = ((ruleHyperarc)firstHyperArc).NotExist; txtNegLabels.IsEnabled = true; txtNegLabels.Text = StringCollectionConverter.Convert(((ruleHyperarc)firstHyperArc).negateLabels); if (!stackHyperArcProps.Children.Contains(wrapRuleBools)) { stackHyperArcProps.Children.Add(wrapRuleBools); } if (!stackHyperArcProps.Children.Contains(gridRuleNegLabels)) { stackHyperArcProps.Children.Add(gridRuleNegLabels); } } else { stackHyperArcProps.Children.Remove(wrapRuleBools); stackHyperArcProps.Children.Remove(gridRuleNegLabels); } } else { txtName.Text = "<multiple hyperarcs>"; txtLabels.Text = "<multiple hyperarcs>"; txtVariables.Text = "<multiple hyperarcs>"; txtName.IsEnabled = txtLabels.IsEnabled = txtVariables.IsEnabled = false; var allSame = true; if (gui is RuleDisplay) { var aType = ((ruleHyperarc)firstHyperArc).TargetType; for (var i = 1; i < hyperarcs.Count; i++) { if (aType != ((ruleHyperarc)hyperarcs[i]).TargetType) { allSame = false; break; } } if (allSame) { txtHyperArcType.IsEnabled = true; txtHyperArcType.Text = aType; } else { txtHyperArcType.IsEnabled = false; txtHyperArcType.Text = "<multiple types>"; } } else { var aType = firstHyperArc.GetType(); for (var i = 1; i < hyperarcs.Count; i++) { if (aType != hyperarcs[i].GetType()) { allSame = false; break; } } if (allSame) { txtHyperArcType.IsEnabled = true; txtHyperArcType.Text = aType.ToString(); } else { txtHyperArcType.IsEnabled = false; txtHyperArcType.Text = "<multiple types>"; } } if ((gui is RuleDisplay) && (gui == ((RuleDisplay)gui).rW.graphGUIL)) { allSame = true; var aBool = ((ruleHyperarc)firstHyperArc).containsAllLocalLabels; for (var i = 1; i < hyperarcs.Count; i++) { if (aBool != ((ruleHyperarc)hyperarcs[i]).containsAllLocalLabels) { allSame = false; break; } } if (allSame) { chkContainsLocalLabels.IsChecked = aBool; } else { chkContainsLocalLabels.IsChecked = null; } allSame = true; aBool = ((ruleHyperarc)firstHyperArc).strictNodeCountMatch; for (var i = 1; i < hyperarcs.Count; i++) { if (aBool != ((ruleHyperarc)hyperarcs[i]).strictNodeCountMatch) { allSame = false; break; } } if (allSame) { chkStrictNodeCount.IsChecked = aBool; } else { chkStrictNodeCount.IsChecked = null; } allSame = true; aBool = ((ruleHyperarc)firstHyperArc).NotExist; for (var i = 1; i < hyperarcs.Count; i++) { if (aBool != ((ruleHyperarc)hyperarcs[i]).NotExist) { allSame = false; break; } } if (allSame) { chkNotExist.IsChecked = aBool; } else { chkNotExist.IsChecked = null; } txtNegLabels.IsEnabled = false; txtNegLabels.Text = "<multiple hyperarcs>"; if (!stackHyperArcProps.Children.Contains(wrapRuleBools)) { stackHyperArcProps.Children.Add(wrapRuleBools); } if (!stackHyperArcProps.Children.Contains(gridRuleNegLabels)) { stackHyperArcProps.Children.Add(gridRuleNegLabels); } } else { stackHyperArcProps.Children.Remove(wrapRuleBools); stackHyperArcProps.Children.Remove(gridRuleNegLabels); } } }
public string nameFromText(string candidateName) { return(StringCollectionConverter.convert(candidateName)[0]); }
private void Update() { if (noRecursion) { return; } noRecursion = true; EnableProperties(); //free arc labels text if (selectedEmbeddingRule.freeArcLabels.Count == 0) { txtFreeArcLabels.Text = "<any>"; } else { txtFreeArcLabels.Text = StringCollectionConverter.Convert(selectedEmbeddingRule.freeArcLabels); } //free arc neg labels if (selectedEmbeddingRule.freeArcNegabels.Count == 0) { txtFreeArcNegabels.Text = "<none>"; } else { txtFreeArcNegabels.Text = StringCollectionConverter.Convert(selectedEmbeddingRule.freeArcNegabels); } //L node name if ((string.IsNullOrWhiteSpace(selectedEmbeddingRule.LNodeName)) || (!cmdLNodeName.Items.Contains(selectedEmbeddingRule.LNodeName))) { cmdLNodeName.SelectedItem = "<any>"; } else if (!selectedEmbeddingRule.LNodeName.Equals(cmdLNodeName.SelectedItem)) { cmdLNodeName.SelectedItem = selectedEmbeddingRule.LNodeName; } // neighbor node labels if (selectedEmbeddingRule.neighborNodeLabels.Count == 0) { txtNeighborLabels.Text = "<any>"; } else { txtNeighborLabels.Text = StringCollectionConverter.Convert(selectedEmbeddingRule.neighborNodeLabels); } // neighbor node negabels if (selectedEmbeddingRule.neighborNodeNegabels.Count == 0) { txtNeighborNegabels.Text = "<none>"; } else { txtNeighborNegabels.Text = StringCollectionConverter.Convert(selectedEmbeddingRule.neighborNodeNegabels); } // orginal direction if (cmdOriginalDirection.SelectedIndex != selectedEmbeddingRule.originalDirection + 1) { cmdOriginalDirection.SelectedIndex = selectedEmbeddingRule.originalDirection + 1; } //R node Name if ((string.IsNullOrWhiteSpace(selectedEmbeddingRule.RNodeName)) || (!cmdRNodeName.Items.Contains(selectedEmbeddingRule.RNodeName))) { cmdRNodeName.SelectedItem = "<null> (leave dangling)"; } else if (!selectedEmbeddingRule.RNodeName.Equals(cmdRNodeName.SelectedItem)) { cmdRNodeName.SelectedItem = selectedEmbeddingRule.RNodeName; } // allow duplication if (chkAllowDup.IsChecked != selectedEmbeddingRule.allowArcDuplication) { chkAllowDup.IsChecked = selectedEmbeddingRule.allowArcDuplication; } //new direction if (cmdNewDirection.SelectedIndex != selectedEmbeddingRule.newDirection + 1) { cmdNewDirection.SelectedIndex = selectedEmbeddingRule.newDirection + 1; } var s = eRulesListBox.SelectedIndex; listBoxBE.UpdateTarget(); eRulesListBox.SelectedIndex = s; noRecursion = false; }
public void initializeGraphControl(Netron.GraphLib.UI.GraphControl graphControl1, Label globalLabelsText) { Random rnd = new Random(); #region display the nodes for (int i = nodes.Count - 1; i >= 0; i--) { node n = nodes[i]; if (n.screenX == 0.0 && n.screenY == 0.0) { n.screenX = rnd.Next(50, graphControl1.Width - 100); n.screenY = rnd.Next(20, graphControl1.Height - 20); } List <string> shapeData = StringCollectionConverter.convert(n.shapekey); if (shapeData.Count == 0) { shapeData.Add(""); } n.displayShape = graphControl1.AddShape(shapeData[0], new PointF(n.screenX, n.screenY)); if (shapeData.Count > 1) { n.displayShape.ShapeColor = Color.FromArgb(int.Parse(shapeData[1])); n.displayShape.Width = float.Parse(shapeData[2]); n.displayShape.Height = float.Parse(shapeData[3]); } } #endregion #region display the arcs foreach (arc a in arcs) { node fromNode = a.From; node toNode = a.To; Connector fromConnect = null; Connector toConnect = null; if ((fromNode == null) || (fromNode.displayShape == null)) { a.fromConnector = 0; fromConnect = addNullShape(graphControl1, 0).Connectors[0]; } else if ((a.fromConnector == -1) || (a.fromConnector >= fromNode.displayShape.Connectors.Count)) { a.fromConnector = rnd.Next(fromNode.displayShape.Connectors.Count); fromConnect = fromNode.displayShape.Connectors[a.fromConnector]; } else { fromConnect = fromNode.displayShape.Connectors[a.fromConnector]; } /* now repeat same process for To */ if ((toNode == null) || (toNode.displayShape == null)) { a.toConnector = 0; toConnect = addNullShape(graphControl1, 1).Connectors[0]; } else if ((a.toConnector == -1) || (a.toConnector >= toNode.displayShape.Connectors.Count)) { a.toConnector = rnd.Next(toNode.displayShape.Connectors.Count); toConnect = toNode.displayShape.Connectors[a.toConnector]; } else { toConnect = toNode.displayShape.Connectors[a.toConnector]; } a.displayShape = graphControl1.AddConnection(fromConnect, toConnect); a.displayShape.ShowLabel = true; List <string> styleData = StringCollectionConverter.convert(a.styleKey); if (styleData.Count > 0) { a.displayShape.LinePath = styleData[0]; } if (styleData.Count > 1) { a.displayShape.LineColor = Color.FromArgb(int.Parse(styleData[1])); a.displayShape.LineWeight = (ConnectionWeight)int.Parse(styleData[2]); a.displayShape.LineStyle = (System.Drawing.Drawing2D.DashStyle) int.Parse(styleData[3]); } } #endregion this.updateGraphControl(graphControl1, globalLabelsText); }