Esempio n. 1
1
        // use static factory methods!
        private GnuPlot(Table table)
        {
            try {
                // TODO avoid necessary write access in app directory
                using (FileStream fs = new FileStream (BinaryFile, FileMode.Create, FileAccess.Write))
                    using (BinaryWriter bw = new BinaryWriter (fs)) {
                        Table3D t3D = table as Table3D;
                        if (t3D != null)
                            WriteGnuPlotBinary (bw, t3D);
                        else
                            WriteGnuPlotBinary (bw, (Table2D)table);
                    }
            } catch (Exception ex) {
                throw new GnuPlotException ("Could not write binary data file.\n" + ex.Message);
            }
            try {
                StartProcess (table);
            } catch (System.ComponentModel.Win32Exception ex) {
                // from MSDN
                // These are the Win32 error code for file not found or access denied.
                const int ERROR_FILE_NOT_FOUND = 2;
                const int ERROR_ACCESS_DENIED = 5;

                switch (ex.NativeErrorCode) {
                case ERROR_FILE_NOT_FOUND:
                    throw new GnuPlotProcessException ("Could not find gnuplot executable path:\n" + exePath + "\n\n" + ex.Message);
                case ERROR_ACCESS_DENIED:
                    throw new GnuPlotProcessException ("Access denied, no permission to start gnuplot process!\n" + ex.Message);
                default:
                    throw new GnuPlotProcessException ("Unknown error. Could not start gnuplot process.\n" + ex.Message);
                }
            }
        }
Esempio n. 2
0
        void StartProcess(Table table)
        {
            if (string.IsNullOrEmpty (exePath))
                throw new GnuPlotProcessException ("gnuplot executable path is empty!");

            process = new Process ();
            process.StartInfo.FileName = exePath;
            process.StartInfo.WorkingDirectory = System.Environment.CurrentDirectory;

            // StartInfo.UseShellExecute must be false in order to use stream redirection
            process.StartInfo.UseShellExecute = false;
            // Could write temp script file but using standard input is more elegant and allows more functionality..
            process.StartInfo.RedirectStandardInput = true;

            // --persist without stdinput method didn't work on Windows - gnuplot window closes immediatly!?
            // --persist + using stdinput prints gnuplot commands into terminal text
            // process.StartInfo.Arguments = "--persist";

            // hide additional cmd window on Windows
            process.StartInfo.CreateNoWindow = true;

            process.EnableRaisingEvents = true;
            process.Exited += HandleProcessExited;

            process.Start ();

            stdInputStream = process.StandardInput;
            Table3D t = table as Table3D;
            if (t != null)
                ScriptGnuplot3D (stdInputStream, t);
            else
                ScriptGnuplot2D (stdInputStream, (Table2D)table);

            stdInputStream.Flush ();
        }
Esempio n. 3
0
 /// <summary>
 /// Gets existing GnuPlot object if there is one.
 /// </summary>
 /// <param name="table">
 /// The <see cref="Table"/> object.
 /// </param>
 /// <returns>
 /// The <see cref="GnuPlot"/> reference or null.
 /// </returns>
 public static GnuPlot GetExistingGnuPlot(Table table)
 {
     GnuPlot gnuPlot;
     gnupDict.TryGetValue (table, out gnuPlot);
     return gnuPlot;
 }
Esempio n. 4
0
 /// <summary>
 /// Create or close gnuplot for given table.
 /// </summary>
 /// <param name="table">
 /// A <see cref="Table"/>
 /// </param>
 public static void ToggleGnuPlot(Table table)
 {
     GnuPlot gnuPlot = GetExistingGnuPlot (table);
     if (gnuPlot == null) {
         gnuPlot = new GnuPlot (table);
         gnupDict.Add (table, gnuPlot);
     } else {
         gnuPlot.Quit ();
     }
 }
Esempio n. 5
0
        /// <summary>
        /// Plots into SVG file.
        /// As this merely redraws into export file, the current view from the plot window will be used.
        /// </summary>
        /// <param name="table">
        /// A <see cref="Table"/>
        /// </param>
        public static void CreateSVG(Table table, string svgPath)
        {
            GnuPlot gnuPlot = GetExistingGnuPlot (table);
            if (gnuPlot == null)
                throw new GnuPlotException ("Need existing gnuplot window.");

            // Test creating empty file in order to get possible exception.
            // Otherwise no easy way to get feedback from gnuplot error.
            // Sort of Unix command 'touch'.
            File.WriteAllText (svgPath, string.Empty);

            CreateSVG (gnuPlot.stdInputStream, svgPath);
        }
Esempio n. 6
0
    void OnExportTableAsCSVActionActivated(object sender, System.EventArgs e)
    {
        if (data.RomLoaded == false)
        {
            return;
        }

        Subaru.Tables.Table table = null;
        switch (CurrentUI)
        {
        case ActiveUI.View2D:
            table = dataView2DGtk.Selected;
            break;

        case ActiveUI.View3D:
            ErrorMsg("Error", "Creating CSV for 3D table not implemented yet.");
            return;
            //table = dataView3DGtk.Selected;
            //break;
        }
        if (table == null)
        {
            return;
        }

        string filenameSuggested = string.IsNullOrEmpty(table.Title) ? "table" : table.Title;

        filenameSuggested += ".csv";
        // TODO another var to remember export dir
        if (svgDirectory == null && data.Rom.Path != null)
        {
            svgDirectory = System.IO.Path.GetDirectoryName(data.Rom.Path);
        }

        var fc = new Gtk.FileChooserDialog("Export data as CSV file", this, FileChooserAction.Save, Gtk.Stock.Cancel, ResponseType.Cancel, Gtk.Stock.Save, ResponseType.Accept);

        try {
            FileFilter filter = new FileFilter();
            filter.Name = "CSV files";
            filter.AddPattern("*.csv");
            fc.AddFilter(filter);

            filter      = new FileFilter();
            filter.Name = "All files";
            filter.AddPattern("*");
            fc.AddFilter(filter);

            fc.DoOverwriteConfirmation = true;
            fc.SetCurrentFolder(svgDirectory);
            fc.CurrentName = filenameSuggested;
            if (fc.Run() == (int)ResponseType.Accept)
            {
                using (System.IO.StreamWriter sw = new System.IO.StreamWriter(fc.Filename, false, System.Text.Encoding.UTF8)) {
                    ((Table2D)table).WriteCSV(sw);
                }
            }
            // remember used dir
            svgDirectory = System.IO.Path.GetDirectoryName(fc.Filename);
        } catch (GnuPlotException ex) {
            ErrorMsg("Error creating CSV file", ex.Message);
        } catch (System.IO.IOException ex) {
            ErrorMsg("IO Exception", ex.Message);
        } catch (Exception ex) {
            // Access to path denied...
            ErrorMsg("Error", ex.Message);
        } finally {
            // Don't forget to call Destroy() or the FileChooserDialog window won't get closed.
            if (fc != null)
            {
                fc.Destroy();
            }
        }
    }
Esempio n. 7
0
    // depends on gnuplot
    void OnCreateSVGFileActionActivated(object sender, System.EventArgs e)
    {
        if (data.RomLoaded == false)
        {
            return;
        }

        Subaru.Tables.Table table = null;
        switch (CurrentUI)
        {
        case ActiveUI.View2D:
            table = dataView2DGtk.Selected;
            break;

        case ActiveUI.View3D:
            table = dataView3DGtk.Selected;
            break;
        }
        if (table == null)
        {
            return;
        }

        GnuPlot gnuPlot = GnuPlot.GetExistingGnuPlot(table);

        if (gnuPlot == null)
        {
            ErrorMsg("Error creating SVG export", "Need existing gnuplot window. Do a normal plot first.");
            return;
        }

        string filenameSuggested = string.IsNullOrEmpty(table.Title) ? "plot" : table.Title;

        filenameSuggested += ".svg";
        if (svgDirectory == null && data.Rom.Path != null)
        {
            svgDirectory = System.IO.Path.GetDirectoryName(data.Rom.Path);
        }

        var fc = new Gtk.FileChooserDialog("Export plot as SVG file", this, FileChooserAction.Save, Gtk.Stock.Cancel, ResponseType.Cancel, Gtk.Stock.Save, ResponseType.Accept);

        try {
            FileFilter filter = new FileFilter();
            filter.Name = "SVG files";
            filter.AddPattern("*.svg");
            fc.AddFilter(filter);

            filter      = new FileFilter();
            filter.Name = "All files";
            filter.AddPattern("*");
            fc.AddFilter(filter);

            fc.DoOverwriteConfirmation = true;
            fc.SetCurrentFolder(svgDirectory);
            fc.CurrentName = filenameSuggested;
            if (fc.Run() == (int)ResponseType.Accept)
            {
                GnuPlot.CreateSVG(table, fc.Filename);
            }
            // remember used dir
            svgDirectory = System.IO.Path.GetDirectoryName(fc.Filename);
        } catch (GnuPlotException ex) {
            ErrorMsg("Error creating SVG file", ex.Message);
        } catch (System.IO.IOException ex) {
            ErrorMsg("IO Exception", ex.Message);
        } catch (Exception ex) {
            // Access to path denied...
            ErrorMsg("Error", ex.Message);
        } finally {
            // Don't forget to call Destroy() or the FileChooserDialog window won't get closed.
            if (fc != null)
            {
                fc.Destroy();
            }
        }
    }
Esempio n. 8
0
        void MergeCommon(Table original, Table newTable)
        {
            // ref not possible because of properties
            original.Category = UpdateString (original.Category, newTable.Category);
            original.Title = UpdateString (original.Title, newTable.Title);
            original.Description = UpdateString (original.Description, newTable.Description);

            original.NameX = UpdateString (original.NameX, newTable.NameX);

            original.UnitX = UpdateString (original.UnitX, newTable.UnitX);
            original.UnitY = UpdateString (original.UnitY, newTable.UnitY);

            if (original.TableType != newTable.TableType)
                original.ChangeTypeToAndReload (newTable.TableType, romStream);
        }
Esempio n. 9
0
        static void ParseCommon(XElement el, Table table)
        {
            // allow null values here when attributes don't exist
            table.Category = (string)el.Attribute (X_category);
            table.Title = (string)el.Attribute (X_name);

            XAttribute attr = el.Attribute (X_address);
            if (attr != null)
                table.Location = ParseHexInt ((string)attr, attr);
        }