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); }
private void txtKGlobalVariables_LostFocus(object sender, RoutedEventArgs e) { var vars = DoubleCollectionConverter.Convert(txtKGlobalVariables.Text); var removedKVars = KVariables.Where(a => !vars.Contains(a)).ToList(); foreach (double a in removedKVars) { rule.L.globalVariables.Remove(a); rule.R.globalVariables.Remove(a); } KVariables = vars; var union = KVariables.Union(rule.L.globalVariables); txtLGlobalVariables_LostFocus(new TextBox { Text = DoubleCollectionConverter.Convert(new List <double>(union)) }, null); union = KVariables.Union(rule.R.globalVariables); txtRGlobalVariables_LostFocus(new TextBox { Text = DoubleCollectionConverter.Convert(new List <double>(union)) }, null); }
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; }
private void tbNumCalls_LostFocus(object sender, RoutedEventArgs e) { var numbers = DoubleCollectionConverter.Convert(tbNumCalls.Text); LindenmayerChooseProcess.numOfCalls = new int[numbers.Count]; for (var i = 0; i < numbers.Count; i++) { LindenmayerChooseProcess.numOfCalls[i] = (int)numbers[i]; } DisplayAndValidateNumCalls(); }
internal static Boolean ConstructFromString(string p, Shape displayShape, out AbstractController Controller) { try { var ctrlData = p.Split(new[] { ',' }, 2); var ctrlName = ctrlData[0]; var ctrlParams = DoubleCollectionConverter.Convert(ctrlData[1]).ToArray(); var ctrlType = Type.GetType("GraphSynth.GraphDisplay." + ctrlName, true); var constructor = ctrlType.GetConstructor(new[] { typeof(Shape), typeof(double[]) }); Controller = (AbstractController)constructor.Invoke(new object[] { displayShape, ctrlParams }); return(true); } catch { Controller = null; return(false); } }
public void txtRVariables_LostFocus(object sender, RoutedEventArgs e) { var senderTextBox = (TextBox)sender; var caretIndex = senderTextBox.CaretIndex; var origLength = senderTextBox.Text.Length; var lst = DoubleCollectionConverter.Convert(senderTextBox.Text); rule.R.globalVariables.Clear(); foreach (double d in lst) { rule.R.globalVariables.Add(d); } Update(); TextBoxHelper.SetCaret(senderTextBox, caretIndex, origLength); }
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); }
public void SetUp() { _doubleCollectionConverter = new DoubleCollectionConverter(); }
void UpdateBorder() { var startColor = GetColorFromString(BorderStartColor.Text); var endColor = GetColorFromString(BorderEndColor.Text); BorderStartColor.BackgroundColor = startColor; BorderEndColor.BackgroundColor = endColor; Shape borderShape = null; switch (BorderShapePicker.SelectedIndex) { case 0: borderShape = new Microsoft.Maui.Controls.Shapes.Rectangle(); break; case 1: borderShape = new RoundRectangle { CornerRadius = new CornerRadius(TopLeftCornerSlider.Value, TopRightCornerSlider.Value, BottomLeftCornerSlider.Value, BottomRightCornerSlider.Value) }; break; case 2: borderShape = new Ellipse(); break; } BorderView.StrokeShape = borderShape; BorderView.Stroke = new LinearGradientBrush { StartPoint = new Point(0, 0), EndPoint = new Point(1, 0), GradientStops = new GradientStopCollection { new Microsoft.Maui.Controls.GradientStop { Color = startColor, Offset = 0.0f }, new Microsoft.Maui.Controls.GradientStop { Color = endColor, Offset = 0.9f } } }; BorderView.StrokeThickness = BorderWidthSlider.Value; var borderDashArrayString = BorderDashArrayEntry.Text; if (string.IsNullOrEmpty(borderDashArrayString)) { BorderView.StrokeDashArray = new DoubleCollection(); } else { var doubleCollectionConverter = new DoubleCollectionConverter(); var doubleCollection = (DoubleCollection)doubleCollectionConverter.ConvertFromString(borderDashArrayString); BorderView.StrokeDashArray = doubleCollection; } BorderView.StrokeDashOffset = BorderDashOffsetSlider.Value; PenLineJoin borderLineJoin = PenLineJoin.Miter; switch (BorderLineJoinPicker.SelectedIndex) { case 0: borderLineJoin = PenLineJoin.Miter; break; case 1: borderLineJoin = PenLineJoin.Round; break; case 2: borderLineJoin = PenLineJoin.Bevel; break; } BorderView.StrokeLineJoin = borderLineJoin; PenLineCap borderLineCap = PenLineCap.Flat; switch (BorderLineCapPicker.SelectedIndex) { case 0: borderLineCap = PenLineCap.Flat; break; case 1: borderLineCap = PenLineCap.Round; break; case 2: borderLineCap = PenLineCap.Square; break; } BorderView.StrokeLineCap = borderLineCap; }
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); } } }
private void txtVariables_LostFocus(object sender, RoutedEventArgs e) { if (hyperarcs.Count == 0) { return; } var caretIndex = txtVariables.CaretIndex; var origLength = txtVariables.Text.Length; var oldVars = firstHyperArc.localVariables; var newVars = DoubleCollectionConverter.Convert(txtVariables.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 removedKVars = oldVars.Where(a => !newVars.Contains(a)).ToList(); foreach (double a in removedKVars) { Larc.localVariables.Remove(a); Rarc.localVariables.Remove(a); } var newLVars = new List <double>(Larc.localVariables.Union(newVars)); Larc.localVariables.Clear(); foreach (double a in newLVars) { Larc.localVariables.Add(a); } var newRVars = new List <double>(Rarc.localVariables.Union(newVars)); Rarc.localVariables.Clear(); foreach (double a in newRVars) { Rarc.localVariables.Add(a); } } else if (gui is RuleDisplay) { // this is a rule LHS or RHS var rW = ((RuleDisplay)gui).rW; hyperarc otherArc = null; otherArc = 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 (otherArc != null) { var KVars = new List <double>(otherArc.localVariables.Intersect(newVars)); otherArc = rW.graphGUIK.graph.hyperarcs.Find(b => string.Equals(b.name, firstHyperArc.name)); otherArc.localVariables.Clear(); foreach (double a in KVars) { otherArc.localVariables.Add(a); } } } firstHyperArc.localVariables.Clear(); foreach (double d in newVars) { firstHyperArc.localVariables.Add(d); } Update(); TextBoxHelper.SetCaret(txtVariables, caretIndex, origLength); }
public sealed override string ToString() { return(":" + GetType().Name + "," + DoubleCollectionConverter.Convert(parameters)); }
private void Update() { if (nodes.Count == 1) { txtName.IsEnabled = txtLabels.IsEnabled = txtVariables.IsEnabled = true; txtName.Text = firstNode.name; btnConfirm.Visibility = firstNode is ruleNode ? Visibility.Visible : Visibility.Hidden; txtLabels.Text = StringCollectionConverter.Convert(firstNode.localLabels); txtVariables.Text = DoubleCollectionConverter.Convert(firstNode.localVariables); txtNodeType.IsEnabled = true; if (gui is RuleDisplay) { txtNodeType.Text = ((ruleNode)firstNode).TargetType; } else { txtNodeType.Text = firstNode.GetType().ToString(); } txtBxPosX.Foreground = txtBxPosY.Foreground = txtBxPosZ.Foreground = Brushes.Black; txtBxPosX.Text = firstNode.X.ToString(); txtBxPosY.Text = firstNode.Y.ToString(); txtBxPosZ.Text = firstNode.Z.ToString(); if ((gui is RuleDisplay) && (gui == ((RuleDisplay)gui).rW.graphGUIL)) { chkContainsLocalLabels.IsChecked = ((ruleNode)firstNode).containsAllLocalLabels; chkStrictDegreeMatch.IsChecked = ((ruleNode)firstNode).strictDegreeMatch; chkNotExist.IsChecked = ((ruleNode)firstNode).NotExist; txtNegLabels.IsEnabled = true; txtNegLabels.Text = StringCollectionConverter.Convert(((ruleNode)firstNode).negateLabels); if (!stackNodeProps.Children.Contains(wrapRuleBools)) { stackNodeProps.Children.Add(wrapRuleBools); } if (!stackNodeProps.Children.Contains(gridRuleNegLabels)) { stackNodeProps.Children.Add(gridRuleNegLabels); } } else { stackNodeProps.Children.Remove(wrapRuleBools); stackNodeProps.Children.Remove(gridRuleNegLabels); } } else if (nodes.Count > 1) { txtName.Text = "<multiple nodes>"; txtLabels.Text = "<multiple nodes>"; txtVariables.Text = "<multiple nodes>"; txtName.IsEnabled = txtLabels.IsEnabled = txtVariables.IsEnabled = false; // expLocation.IsEnabled = false; var allSame = true; /***************** Node Type *************/ if (gui is RuleDisplay) { var aType = ((ruleNode)firstNode).TargetType; for (var i = 1; i < nodes.Count; i++) { if (aType != ((ruleNode)nodes[i]).TargetType) { allSame = false; break; } } if (allSame) { txtNodeType.IsEnabled = true; txtNodeType.Text = aType; } else { txtNodeType.IsEnabled = false; txtNodeType.Text = "<multiple types>"; } } else { var aType = firstNode.GetType(); for (var i = 1; i < nodes.Count; i++) { if (aType != nodes[i].GetType()) { allSame = false; break; } } if (allSame) { txtNodeType.IsEnabled = true; txtNodeType.Text = aType.ToString(); } else { txtNodeType.IsEnabled = false; txtNodeType.Text = "<multiple types>"; } } /***************** X-Position *************/ allSame = true; var pos = firstNode.X; for (var i = 1; i < nodes.Count; i++) { if (!pos.Equals(nodes[i].X)) { allSame = false; break; } } if (allSame) { txtBxPosX.Foreground = Brushes.Black; txtBxPosX.Text = pos.ToString(); } else { txtBxPosX.Foreground = Brushes.Gray; txtBxPosX.Text = "diff"; } /***************** Y-Position *************/ allSame = true; pos = firstNode.Y; for (var i = 1; i < nodes.Count; i++) { if (!pos.Equals(nodes[i].Y)) { allSame = false; break; } } if (allSame) { txtBxPosY.Foreground = Brushes.Black; txtBxPosY.Text = pos.ToString(); } else { txtBxPosY.Foreground = Brushes.Gray; txtBxPosY.Text = "diff"; } /***************** Z-Position *************/ allSame = true; pos = firstNode.Z; for (var i = 1; i < nodes.Count; i++) { if (!pos.Equals(nodes[i].Z)) { allSame = false; break; } } if (allSame) { txtBxPosZ.Foreground = Brushes.Black; txtBxPosZ.Text = pos.ToString(); } else { txtBxPosZ.Foreground = Brushes.Gray; txtBxPosZ.Text = "diff"; } if ((gui is RuleDisplay) && (gui == ((RuleDisplay)gui).rW.graphGUIL)) { allSame = true; var nBool = ((ruleNode)firstNode).containsAllLocalLabels; for (var i = 1; i < nodes.Count; i++) { if (nBool != ((ruleNode)nodes[i]).containsAllLocalLabels) { allSame = false; break; } } if (allSame) { chkContainsLocalLabels.IsChecked = nBool; } else { chkContainsLocalLabels.IsChecked = null; } allSame = true; nBool = ((ruleNode)firstNode).strictDegreeMatch; for (var i = 1; i < nodes.Count; i++) { if (nBool != ((ruleNode)nodes[i]).strictDegreeMatch) { allSame = false; break; } } if (allSame) { chkStrictDegreeMatch.IsChecked = nBool; } else { chkStrictDegreeMatch.IsChecked = null; } allSame = true; nBool = ((ruleNode)firstNode).NotExist; for (var i = 1; i < nodes.Count; i++) { if (nBool != ((ruleNode)nodes[i]).NotExist) { allSame = false; break; } } if (allSame) { chkNotExist.IsChecked = nBool; } else { chkNotExist.IsChecked = null; } txtNegLabels.IsEnabled = false; txtNegLabels.Text = "<multiple nodes>"; if (!stackNodeProps.Children.Contains(wrapRuleBools)) { stackNodeProps.Children.Add(wrapRuleBools); } if (!stackNodeProps.Children.Contains(gridRuleNegLabels)) { stackNodeProps.Children.Add(gridRuleNegLabels); } } else { stackNodeProps.Children.Remove(wrapRuleBools); stackNodeProps.Children.Remove(gridRuleNegLabels); } } }