Beispiel #1
0
        /// <summary>
        ///   Saves the graph.
        /// </summary>
        /// <param name = "filename">The filename.</param>
        /// <param name = "graph1">The graph1.</param>
        protected void SaveGraph(string filename, designGraph graph1)
        {
            StreamWriter graphWriter = null;

            graph1.name = Path.GetFileNameWithoutExtension(filename);
            graph1.checkForRepeatNames();
            removeNullWhiteSpaceEmptyLabels(graph1);
            try
            {
                graphWriter = new StreamWriter(filename);
                var s = SerializeGraphToXml(graph1);
                if (s != null)
                {
                    graphWriter.Write(s);
                }
            }
            catch (FileNotFoundException fnfe)
            {
                SearchIO.output("***Error Writing to File***");
                SearchIO.output(fnfe.ToString());
            }
            finally
            {
                if (graphWriter != null)
                {
                    graphWriter.Close();
                }
            }
        }
Beispiel #2
0
        public void graphDisplay_Enter(object sender, EventArgs e)
        {
            graph1.checkForRepeatNames();
            graph1.updateGraphControl(graphControl1, this.globalLabelsText);
            graph1.updateFromGraphControl(graphControl1);
            switch (Program.settings.defaultLayoutAlgorithm)
            {
            case defaultLayoutAlg.SpringEmbedder:
                Program.main.layoutSpringEmbedderItem_Click(sender, e); break;

            case defaultLayoutAlg.Tree:
                Program.main.layoutTreeItem_Click(sender, e); break;

            case defaultLayoutAlg.Random:
                Program.main.layoutRandomizerItem_Click(sender, e); break;

            case defaultLayoutAlg.Custom1:
                Program.main.customLayout0MenuItem_Click(sender, e); break;

            case defaultLayoutAlg.Custom2:
                Program.main.customLayout1MenuItem_Click(sender, e); break;

            case defaultLayoutAlg.Custom3:
                Program.main.customLayout2MenuItem_Click(sender, e); break;
            }
        }
Beispiel #3
0
        private new void SaveGraph(string filename, designGraph graph)
        {
            graph.name = Path.GetFileNameWithoutExtension(filename);

            if (graph.checkForRepeatNames())
            {
                SearchIO.output("Sorry, but you are not allowed to have repeat names. I have changed" +
                                " these names to be unique");
            }

            /* go build the browser page */
            string SaveString = BuildXAMLGraphPage(graph);

            /* 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(">", StringComparison.Ordinal),
                                           IgnorableSetup + "Tag=\"Graph\" ");
            /* remove the ending Page tag but put it back at the end. */
            SaveString = SaveString.Replace("</Page>", "");

            /* add the canvas properties. */
            /* add the graph data. */
            SaveString += "\n\n" + AddIgnorablePrefix(SerializeGraphToXml(graph)) + "\n\n";
            /* put the closing tag back on. */
            SaveString += "</Page>";
            try
            {
                File.WriteAllText(filename, SaveString);
                SearchIO.output("**** Graph successfully saved. ****", 2);
            }
            catch (Exception E)
            {
                SearchIO.output("File Access Exception" + E.Message, 2);
            }
        }
Beispiel #4
0
        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);
                }
            }
        }