public void RestoreDisplayShapesOLD(XmlElement xmlShapes, List <node> nodes, List <arc> arcs) { foreach (node n in nodes) { foreach (XmlNode x in xmlShapes.ChildNodes) { var s = x.OuterXml; if (n.name.Equals(MyXamlHelpers.GetValue(s, "Tag"))) { dispatch.Invoke((ThreadStart) delegate { n.DisplayShape = new DisplayShape(s, ShapeRepresents.Node, n); }); break; } } } //if (arcs != null) //{ foreach (arc a in arcs) { foreach (XmlNode x in xmlShapes.ChildNodes) { var s = x.OuterXml; if (a.name.Equals(MyXamlHelpers.GetValue(s, "Tag"))) { dispatch.Invoke((ThreadStart) delegate { a.DisplayShape = new DisplayShape(s, ShapeRepresents.Arc, a); }); break; } } } }
private void SaveRule(string filename, grammarRule rule, designGraph graphK, CanvasProperty canvProp) { if (UserCancelled) { return; } progress = 3; rule.name = Path.GetFileNameWithoutExtension(filename); if (checkRule(rule)) { // progress is now at 13 string SaveString = null; dispatch.Invoke((ThreadStart) delegate { var xamlPage = BuildXAMLRulePage(rule, graphK, canvProp); SaveString = XamlWriter.Save(xamlPage); }); progress = 85; SaveString = MyXamlHelpers.CleanOutxNulls(SaveString); /* A little manipulation is needed to stick the GraphSynth objects within the page. * * The IgnorableSetup string ensures that XAML viewers ignore the following * * GraphSynth specific elements: the canvas data, and the graph data. This eff- * * ectively separates the topology and data of the graph from the graphic elements. */ SaveString = SaveString.Insert(SaveString.IndexOf(">"), IgnorableSetup + "Tag=\"Rule\" "); /* remove the ending Page tag but put it back at the end. */ SaveString = SaveString.Replace("</Page>", ""); /* add the canvas properties. */ if (canvProp != null) { dispatch.Invoke( (ThreadStart) delegate { SaveString += "\n\n" + AddIgnorablePrefix(CanvasProperty.SerializeCanvasToXml(canvProp)); }); } progress = 92; /* add the graph data. */ SaveString += "\n\n" + AddIgnorablePrefix(SerializeRuleToXml(rule)) + "\n\n"; /* put the closing tag back on. */ SaveString += "</Page>"; try { File.WriteAllText(filename, SaveString); } catch (Exception E) { if (!suppressWarnings) { progWindow.QueryUser("File Access Exception" + E.Message, 10000, "", "Cancel", false); } } progress = 100; if ((progWindow != null) && (!suppressWarnings)) { progWindow.QueryUser("\n **** Rule successfully saved. ****", 1000, "OK", "", false); } else { SearchIO.output("**** Rule successfully saved. ****", 2); } } }
private void SaveGraph(string filename, designGraph graph, CanvasProperty canvProp) { if (UserCancelled) { return; } progress = 5; graph.name = Path.GetFileNameWithoutExtension(filename); removeNullWhiteSpaceEmptyLabels(graph); if ((graph.checkForRepeatNames()) && !suppressWarnings) { progWindow.QueryUser("Sorry, but you are not allowed to have repeat names. I have changed" + " these names to be unique", 5000, "OK", "", false); } progress = 7; if (UserCancelled) { return; } progressEnd = 80; /* go build the browser page */ string SaveString = null; dispatch.Invoke((ThreadStart) delegate { var xamlPage = BuildXAMLGraphPage(graph, canvProp); progress = 80; SaveString = XamlWriter.Save(xamlPage); }); progress = 87; if (UserCancelled) { return; } SaveString = MyXamlHelpers.CleanOutxNulls(SaveString); /* A little manipulation is needed to stick the GraphSynth objects within the page. * * The IgnorableSetup string ensures that XAML viewers ignore the following * * GraphSynth specific elements: the canvas data, and the graph data. This eff- * * ectively separates the topology and data of the graph from the graphic elements. */ SaveString = SaveString.Insert(SaveString.IndexOf(">"), IgnorableSetup + "Tag=\"Graph\" "); /* remove the ending Page tag but put it back at the end. */ SaveString = SaveString.Replace("</Page>", ""); /* add the canvas properties. */ if (canvProp != null) { dispatch.Invoke( (ThreadStart) delegate { SaveString += "\n\n" + AddIgnorablePrefix(CanvasProperty.SerializeCanvasToXml(canvProp)); }); } progress = 95; if (UserCancelled) { return; } /* add the graph data. */ SaveString += "\n\n" + AddIgnorablePrefix(SerializeGraphToXml(graph)) + "\n\n"; if (UserCancelled) { return; } /* put the closing tag back on. */ SaveString += "</Page>"; try { File.WriteAllText(filename, SaveString); progress = 100; if ((progWindow != null) && !suppressWarnings) { progWindow.QueryUser("\n **** Graph successfully saved. ****", 1000, "OK", "", false); } else { SearchIO.output("**** Graph successfully saved. ****", 2); } } catch (Exception E) { if ((progWindow != null) && !suppressWarnings) { progWindow.QueryUser("File Access Exception" + E.Message, 10000, "", "Cancel", false); } else { SearchIO.output("File Access Exception" + E.Message, 2); } } }
private Canvas BuildGraphGUICanvas(designGraph graph, CanvasProperty cp) { var dtc = new DisplayTextConverter(); var ptc = new PositionTextConverter(); var saveCanvas = new Canvas { Background = cp.BackgroundColor, HorizontalAlignment = HorizontalAlignment.Stretch, VerticalAlignment = VerticalAlignment.Stretch, Height = cp.CanvasHeight / cp.ScaleFactor, Width = cp.CanvasWidth.Left / cp.ScaleFactor, RenderTransform = new MatrixTransform(1, 0, 0, -1, 0, cp.CanvasHeight / cp.ScaleFactor) }; if (UserCancelled) { return(null); } progress += 2; var canvString = XamlWriter.Save(saveCanvas); canvString = canvString.EndsWith("</Canvas>") ? canvString.Replace("</Canvas>", "") : canvString.Replace("/>", ">"); progress += 2; var progressStart = progress; var progStep = (double)(progressEnd - progressStart) / (graph.nodes.Count + graph.arcs.Count + graph.hyperarcs.Count); var step = 1; foreach (node n in graph.nodes) { if (n.DisplayShape == null) { GS1xCompatibility.UpdateNodeShape(n); } canvString += ((DisplayShape)n.DisplayShape).String; var nodeText = (FormattedText)dtc.Convert(new object[] { cp.ShowNodeName, cp.ShowNodeLabel, cp.NodeFontSize }, null, n, null); if (nodeText != null) { var textPos = (Point)ptc.Convert(new object[] { cp.NodeTextDistance, cp.NodeTextPosition, nodeText }, null, null, null); var tb = new TextBlock { FontSize = cp.NodeFontSize, Text = nodeText.Text, VerticalAlignment = VerticalAlignment.Center, HorizontalAlignment = HorizontalAlignment.Center, RenderTransform = new MatrixTransform(1, 0, 0, -1, n.DisplayShape.ScreenX + textPos.X, n.DisplayShape.ScreenY - textPos.Y) }; canvString += RemoveXAMLns(XamlWriter.Save(tb)); } if (UserCancelled) { return(null); } progress = progressStart + (int)(progStep * step++); } foreach (arc a in graph.arcs) { if (a.DisplayShape == null) { GS1xCompatibility.UpdateArcShape(a); } canvString += ((DisplayShape)a.DisplayShape).String; var arcText = (FormattedText)dtc.Convert(new object[] { cp.ShowArcName, cp.ShowArcLabel, cp.ArcFontSize }, null, a, null); if (arcText != null) { AbstractController ac; if ((a.DisplayShape != null) && (a.DisplayShape.Shape != null) && (((ArcShape)a.DisplayShape.Shape).Controller != null)) { ac = ((ArcShape)a.DisplayShape.Shape).Controller; } else { ac = new StraightArcController((Shape)a.DisplayShape.Shape); } var textPos = (Point)ptc.Convert(new object[] { cp.ArcTextDistance, cp.ArcTextPosition, arcText }, null, ac, null); var tb = new TextBlock { FontSize = cp.ArcFontSize, Text = arcText.Text, RenderTransform = new MatrixTransform(1, 0, 0, -1, textPos.X, textPos.Y) }; canvString += RemoveXAMLns(XamlWriter.Save(tb)); } } foreach (hyperarc h in graph.hyperarcs) { canvString += ((DisplayShape)h.DisplayShape).String; var hatext = (FormattedText)dtc.Convert(new object[] { cp.ShowHyperArcName, cp.ShowHyperArcLabel, cp.HyperArcFontSize }, null, h, null); if (hatext != null) { AbstractController ac; if ((h.DisplayShape != null) && (h.DisplayShape.Shape != null) && (((HyperArcShape)h.DisplayShape.Shape).Controller != null)) { ac = ((HyperArcShape)h.DisplayShape.Shape).Controller; } else { ac = new CircleHyperArcController((Shape)h.DisplayShape.Shape, new[] { 25.0 - 1.0 }); } var textPos = (Point)ptc.Convert(new object[] { cp.HyperArcTextDistance, cp.HyperArcTextPosition, hatext }, null, ac, null); var tb = new TextBlock { FontSize = cp.HyperArcFontSize, Text = hatext.Text, RenderTransform = new MatrixTransform(1, 0, 0, -1, textPos.X, textPos.Y) }; canvString += RemoveXAMLns(XamlWriter.Save(tb)); } if (UserCancelled) { return(null); } progress = progressStart + (int)(progStep * step++); } canvString += "</Canvas>"; return((Canvas)MyXamlHelpers.Parse(canvString)); }